Submitted by Steve Fewell
Description:
This code is executed everytime a BRK instruction (i.e. a BASIC, or OS, error message is issued), as the address in the
BRK vector (&202-&203) is set to point to this code when the BASIC language is initiated.
Therefore, this routine will be executed when an error occurs within BASIC (i.e. 'Type mismatch', 'Mistake', 'Escape' and
'Missing #') or when an error occurs in the OS (or another ROM), i.e. 'Bad String', 'Bad command'.
On entry locations &FD-&FE point to the byte after the BRK instruction (i.e. the error number) and this number will
be followed by the actual error message.
Set the OPT flag (location &28) to #&FF - ?
Reset the stack pointer to #&FF to discard any stack storage / routine return addresses that are no longer required
(there aren't required as the Error handler will pass control to the ON ERROR code - and ignore the current position in
the program).
Set X and Y to zero (as required by the OSBYTE calls below).
Call the Operating System OSBYTE call &DA to abandon any expected items that were still to be read by the VDU queue.
Call the Operating System OSBYTE call &7E to acknowledge the detection of an escape condition (this flushes the buffers
and closes any open EXEC files).
B237 | 164 010 | A4 0A | LDY &0A | |
B239 | 240 001 | F0 01 | BEQ 1 --> &B23C | |
B23B | 136 | 88 | DEY | |
B23C | 032 188 155 | 20 BC 9B | JSR &9BBC Update BASIC Text pointer A (Add offset value & then reset offset to 1) | |
B23F | d | 100 008 | 64 08 | STZ &08 |
B241 | d | 100 009 | 64 09 | STZ &09 |
B243 | 166 024 | A6 18 | LDX &18 | |
B245 | 8 | 134 056 | 86 38 | STX &38 |
B247 | d7 | 100 055 | 64 37 | STZ &37 |
B249 | 164 012 | A4 0C | LDY &0C | |
B24B | 192 007 | C0 07 | CPY#&07 | |
B24D | ( | 240 040 | F0 28 | BEQ 40 --> &B277 |
B24F | 166 011 | A6 0B | LDX &0B | |
B251 | 032 160 141 | 20 A0 8D | JSR &8DA0 Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B254 | 201 013 | C9 0D | CMP#&0D | |
B256 | 208 024 | D0 18 | BNE 24 --> &B270 | |
B258 | 7 | 228 055 | E4 37 | CPX &37 |
B25A | 152 | 98 | TYA | |
B25B | 8 | 229 056 | E5 38 | SBC &38 |
B25D | 144 024 | 90 18 | BCC 24 --> &B277 | |
B25F | 032 160 141 | 20 A0 8D | JSR &8DA0 Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B262 | 009 000 | 09 00 | ORA#&00 | |
B264 | 0 | 048 017 | 30 11 | BMI 17 --> &B277 |
B266 | 133 009 | 85 09 | STA &09 | |
B268 | 032 160 141 | 20 A0 8D | JSR &8DA0 Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B26B | 133 008 | 85 08 | STA &08 | |
B26D | 032 160 141 | 20 A0 8D | JSR &8DA0 Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B270 | 7 | 228 055 | E4 37 | CPX &37 |
B272 | 152 | 98 | TYA | |
B273 | 8 | 229 056 | E5 38 | SBC &38 |
B275 | 176 218 | B0 DA | BCS -38 --> &B251 | |
B277 | ` | 096 | 60 | RTS |
B278 | 162 255 | A2 FF | LDX#&FF | |
B27A | ( | 134 040 | 86 28 | STX &28 |
B27C | 154 | 9A | TXS | |
B27D | 232 | E8 | INX | |
B27E | 160 000 | A0 00 | LDY#&00 | |
B280 | 169 218 | A9 DA | LDA#&DA | |
B282 | 032 244 255 | 20 F4 FF | JSR &FFF4 OSBYTE | |
B285 | ~ | 169 126 | A9 7E | LDA#&7E |
B287 | 032 244 255 | 20 F4 FF | JSR &FFF4 OSBYTE | |
B28A | 7 | 032 055 178 | 20 37 B2 | JSR &B237 Obtain the ERL value |
B28D | d | 100 032 | 64 20 | STZ &20 |
B28F | 178 253 | B2 FD | LDA (&FD) | |
B291 | 208 003 | D0 03 | BNE 3 --> &B296 | |
B293 | 032 166 178 | 20 A6 B2 | JSR &B2A6 Reset 'ON ERROR' pointer to BASIC's default error handling routine | |
B296 | 165 022 | A5 16 | LDA &16 | |
B298 | 133 011 | 85 0B | STA &0B | |
B29A | 165 023 | A5 17 | LDA &17 | |
B29C | 133 012 | 85 0C | STA &0C | |
B29E | d | 100 010 | 64 0A | STZ &0A |
B2A0 | 032 207 187 | 20 CF BB | JSR &BBCF Initialise Program start address, Stack pointer, *EDIT mode & REPEAT/FOR/GOSUB levels | |
B2A3 | L | 076 011 144 | 4C 0B 90 | JMP &900B Process next BASIC program statement |