Jump to content





Dealer Demo, part 9: Strings are things

Posted by Atari_Ace, 12 September 2018 · 74 views

forth

We continue with decompiling Dealer Demo at $175D, seeing -TRAILING, (.") (PDOTQ), and then a handful of words leading to the word ERROR which decompiles incorrectly.
 
Looking closely, we see that the .WORD PDOTQ precedes strings in the listing, which are represented as a count, followed by the string contents.  The code to decompile such a string manually is easy to implement, since we built most of the infrastructure already to decompile Forth name fields, namely:

sub cstr_buf {
  my ($buff, $addr, $size) = @_;
  my $count = unpack "C", substr($buff, 0, 1);
  my $string = get_string(substr($buff, 1, $count));
  $string = sprintf "%s.BYTE %d,%s", get_label($addr), $count, $string;
  $count += 1;
  multi_buf($buff, $addr, $count, $string);
  $count;
}
sub cstr {
  my ($buff, $addr, $size) = read_img(@_);
  cstr_buf($buff, $addr, $size);
}
To decompile automatically, we can insert this snippet into forth_buf:
    if (get_cstrq($val)) {
      $i += cstr_buf(substr($buff, $i), $addr + $i, $size - $i);
    }
where get_cstrq is:
sub get_cstrq {
  return $_[0] == 0x179c; # PDOTQ
}
We can apply this to the ERROR word to test that the code works as advertised, e.g. invoking dealerdemo.pl 1a1c yields:
1A1C: 9C 17             .WORD PDOTQ
1A1E: 04 20 20          .BYTE 4,'  ? '
1A21: 3F 20
Let's keep decompiling up through the word FORTH, which has .WORD DODOE, which we discussed last time, and then up through ABORT.
 
Among these words, what differences do we see?
  • EXPECT is implemented significantly differently.  The Dealer Demo version is much shorter and simpler than the fig-Forth assembly version.  The fig-Forth version has extra code to handle back spaces and carriage returns which are done elsewhere in the Dealer Demo kernel.
  • The null word (literally ascii 0), is largely the same, except it uses BSCR 1 - AND instead of 0 BSCR U/ DROP.  The fig-Forth screen listing uses 7 AND unconditionally and has BSCR (blocks per screen) equal to 8, so it more closely follows the Dealer Demo listing.  However, in the Dealer Demo, BSCR is one, so these gymnastics to figure out where to read the character from isn't really needed.
  • The word UPPER is dropped from Dealer Demo. This kernel (as are all Atari Forth kernels) is case sensitive so it isn't used.
  • ERROR is modified slightly before calling QUIT.  Instead of always leaving IN and BLK on the data stack, we omit IN if reading from disk.  Since QUIT doesn't use this data, this presumably is left for debugging reasons.
  • ABORT and QUIT use slightly different strings than the fig-Forth listing.  ABORT ends with SEMIS, which isn't really needed since QUIT doesn't return.  ABORT also calls some future word at $863A instead of CR, probably to run some Dealer Demo specific initialization.
Calling Invoking -refs in our tool shows CREAT, ERROR, WORD, ABORT and QUIT forward references can now be fixed up.  CREATE was the missing word used in colon and constant definitions, so we now have largely filled in all the words that implement compilation.
 
I think that's enough for today.  Our decompilation tool is now complete, we just need to keep applying it until we've cranked through the rest of the disk.  The next post (or maybe two) should complete the kernel (which ends at byte $259f), and the post after that will describe the assembler (which ends at $2be4).
 

Attached Files






November 2018

S M T W T F S
    123
45678910
11121314151617
18 192021222324
252627282930 

Tags

Categories