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).
- 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).
- 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.
- 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.
- If the error code didn't match, I restore AF/HL and perform the same operations as the original RST8 routine; job done.
- 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).
- 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!)
- 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.
- 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.
- If syntax was okay, set ERR_NR to $ff (no error).
- Check if syntax-checking or runtime (bit 7 of FLAGS is set at runtime).
- If syntax-checking, set SP to the contents of ERR_SP, then jump to BASIC_STMT_NEXT ($1bf4) in the BASIC ROM. Job done.
- Finally, you get to run your command
- If anything went wrong, set the error code at ERR_NR, and perform the remaining RST8 operations; job done.
- 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.