<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://spectrum.alioth.net/doc/index.php?action=history&amp;feed=atom&amp;title=Tidbits</id>
	<title>Tidbits - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://spectrum.alioth.net/doc/index.php?action=history&amp;feed=atom&amp;title=Tidbits"/>
	<link rel="alternate" type="text/html" href="https://spectrum.alioth.net/doc/index.php?title=Tidbits&amp;action=history"/>
	<updated>2026-05-07T16:42:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://spectrum.alioth.net/doc/index.php?title=Tidbits&amp;diff=65&amp;oldid=prev</id>
		<title>Winston: New page: 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 ...</title>
		<link rel="alternate" type="text/html" href="https://spectrum.alioth.net/doc/index.php?title=Tidbits&amp;diff=65&amp;oldid=prev"/>
		<updated>2008-03-29T22:35:05Z</updated>

		<summary type="html">&lt;p&gt;New page: Here&amp;#039;s a collection of random tidbits just to make the development of the Spectranet easier.  == On RST8 traps - Garry Lancaster ==  Okay, well here&amp;#039;s what I do (my method is based on the ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Here's a collection of random tidbits just to make the development of the Spectranet easier.&lt;br /&gt;
&lt;br /&gt;
== On RST8 traps - Garry Lancaster ==&lt;br /&gt;
&lt;br /&gt;
Okay, well here's what I do (my method is based on the IF1 method).&lt;br /&gt;
&lt;br /&gt;
# Save current AF &amp;amp; HL (this possibly isn't necessary, but other devices might need these values for their hook codes, so probably a good idea).&lt;br /&gt;
# 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.&lt;br /&gt;
# Store this at ERR_NR. Then check if it's a code you need to worry about. For new commands, I look for:&lt;br /&gt;
          * $0b (Nonsense in BASIC)&lt;br /&gt;
          * $0e (Invalid Filename)&lt;br /&gt;
          * $17 (Invalid stream)&lt;br /&gt;
          * $12 (Bad device - SE BASIC produces this)&lt;br /&gt;
I also check for non-error hook codes at this point, but your $3ffe/$3fff trap sounds a better solution for you.&lt;br /&gt;
# If the error code didn't match, I restore AF/HL and perform the same operations as the original RST8 routine; job done.&lt;br /&gt;
# If the error code did match, I discard the saved AF/HL and save the contents of ERR_NR &amp;amp; CH_ADD (which were the &amp;quot;best guess&amp;quot; at the error condition from the original BASIC ROM).&lt;br /&gt;
# Next, you need to &amp;quot;rewind&amp;quot; CH_ADD to the start of the line &amp;amp; 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!)&lt;br /&gt;
# Scan the line for your own syntax. If this wasn't one of your new commands, restore CH_ADD &amp;amp; ERR_NR and then perform the remaining operations in the original RST8 routine; job done.&lt;br /&gt;
# 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.&lt;br /&gt;
# If syntax was okay, set ERR_NR to $ff (no error).&lt;br /&gt;
# Check if syntax-checking or runtime (bit 7 of FLAGS is set at runtime).&lt;br /&gt;
# If syntax-checking, set SP to the contents of ERR_SP, then jump to BASIC_STMT_NEXT ($1bf4) in the BASIC ROM. Job done.&lt;br /&gt;
# Finally, you get to run your command&lt;br /&gt;
# If anything went wrong, set the error code at ERR_NR, and perform the remaining RST8 operations; job done.&lt;br /&gt;
# 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!&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[Category:Spectranet]]&lt;/div&gt;</summary>
		<author><name>Winston</name></author>
	</entry>
</feed>