From Spectrum
Jump to navigation Jump to search

Here's a collection of random tidbits just to make the development of the Spectranet easier.

On RST8 traps - Garry Lancaster

Okay, well here's what I do (my method is based on the IF1 method).

  1. Save current AF & HL (this possibly isn't necessary, but other devices might need these values for their hook codes, so probably a good idea).
  2. Get the byte at the current return address, which is the error/hook code value. This may be in the ROM, so I call the BASIC ROM routine at $007b (LD A,(HL); RET) to do it.
  3. Store this at ERR_NR. Then check if it's a code you need to worry about. For new commands, I look for:
         * $0b (Nonsense in BASIC)
         * $0e (Invalid Filename)
         * $17 (Invalid stream)
         * $12 (Bad device - SE BASIC produces this)

I also check for non-error hook codes at this point, but your $3ffe/$3fff trap sounds a better solution for you.

  1. If the error code didn't match, I restore AF/HL and perform the same operations as the original RST8 routine; job done.
  2. If the error code did match, I discard the saved AF/HL and save the contents of ERR_NR & CH_ADD (which were the "best guess" at the error condition from the original BASIC ROM).
  3. Next, you need to "rewind" CH_ADD to the start of the line & remove fp values from it, before attempting to scan it yourself (see the IF1 disassembly for how to do this - I pretty much just copied this bit!)
  4. Scan the line for your own syntax. If this wasn't one of your new commands, restore CH_ADD & ERR_NR and then perform the remaining operations in the original RST8 routine; job done.
  5. If this was one of your commands, but a syntax error, set ERR_NR and CH_ADD to flag up the error condition appropriately, then do the remaining RST8 operations; job done.
  6. If syntax was okay, set ERR_NR to $ff (no error).
  7. Check if syntax-checking or runtime (bit 7 of FLAGS is set at runtime).
  8. If syntax-checking, set SP to the contents of ERR_SP, then jump to BASIC_STMT_NEXT ($1bf4) in the BASIC ROM. Job done.
  9. Finally, you get to run your command
  10. If anything went wrong, set the error code at ERR_NR, and perform the remaining RST8 operations; job done.
  11. If it actually worked, set SP to the contents of ERR_SP, then jump to BASIC_STMT_R_1 ($1b7d) in the BASIC ROM. Finished!

One final point. If your command succeeded at runtime, it's nice to check for the BREAK key and cause error $14 (L - BREAK into program) if pressed.