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).
B271 | 164 010 | A4 0A | LDY &0A | |
B273 | 240 001 | F0 01 | BEQ 1 --> &B276 | |
B275 | 136 | 88 | DEY | |
B276 | 032 128 156 | 20 80 9C | JSR &9C80 Update BASIC Text pointer A (Add offset value & then reset offset to 1) | |
B279 | d | 100 008 | 64 08 | STZ &08 |
B27B | d | 100 009 | 64 09 | STZ &09 |
B27D | 166 024 | A6 18 | LDX &18 | |
B27F | 8 | 134 056 | 86 38 | STX &38 |
B281 | d7 | 100 055 | 64 37 | STZ &37 |
B283 | 164 012 | A4 0C | LDY &0C | |
B285 | 192 007 | C0 07 | CPY#&07 | |
B287 | ( | 240 040 | F0 28 | BEQ 40 --> &B2B1 |
B289 | 166 011 | A6 0B | LDX &0B | |
B28B | 032 093 142 | 20 5D 8E | JSR &8E5D Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B28E | 201 013 | C9 0D | CMP#&0D | |
B290 | 208 024 | D0 18 | BNE 24 --> &B2AA | |
B292 | 7 | 228 055 | E4 37 | CPX &37 |
B294 | 152 | 98 | TYA | |
B295 | 8 | 229 056 | E5 38 | SBC &38 |
B297 | 144 024 | 90 18 | BCC 24 --> &B2B1 | |
B299 | 032 093 142 | 20 5D 8E | JSR &8E5D Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B29C | 009 000 | 09 00 | ORA#&00 | |
B29E | 0 | 048 017 | 30 11 | BMI 17 --> &B2B1 |
B2A0 | 133 009 | 85 09 | STA &09 | |
B2A2 | 032 093 142 | 20 5D 8E | JSR &8E5D Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B2A5 | 133 008 | 85 08 | STA &08 | |
B2A7 | 032 093 142 | 20 5D 8E | JSR &8E5D Read character pointed to by &37-&38 and then increment the &37-&38 pointer | |
B2AA | 7 | 228 055 | E4 37 | CPX &37 |
B2AC | 152 | 98 | TYA | |
B2AD | 8 | 229 056 | E5 38 | SBC &38 |
B2AF | 176 218 | B0 DA | BCS -38 --> &B28B | |
B2B1 | ` | 096 | 60 | RTS |
B2B2 | 162 255 | A2 FF | LDX#&FF | |
B2B4 | ( | 134 040 | 86 28 | STX &28 |
B2B6 | 154 | 9A | TXS | |
B2B7 | 232 | E8 | INX | |
B2B8 | 160 000 | A0 00 | LDY#&00 | |
B2BA | 169 218 | A9 DA | LDA#&DA | |
B2BC | 032 244 255 | 20 F4 FF | JSR &FFF4 OSBYTE | |
B2BF | ~ | 169 126 | A9 7E | LDA#&7E |
B2C1 | 032 244 255 | 20 F4 FF | JSR &FFF4 OSBYTE | |
B2C4 | 7 | 032 055 178 | 20 37 B2 | JSR &B271 Obtain the ERL value |
B2C7 | d | 100 032 | 64 20 | STZ &20 |
B2C9 | 178 253 | B2 FD | LDA (&FD) | |
B2CB | 208 003 | D0 03 | BNE 3 --> &B2D0 | |
B2CD | 032 166 178 | 20 A6 B2 | JSR &B2E0 Reset 'ON ERROR' pointer to BASIC's default error handling routine | |
B2D0 | 165 022 | A5 16 | LDA &16 | |
B2D2 | 133 011 | 85 0B | STA &0B | |
B2D4 | 165 023 | A5 17 | LDA &17 | |
B2D6 | 133 012 | 85 0C | STA &0C | |
B2D8 | d | 100 010 | 64 0A | STZ &0A |
B2DA | 032 207 187 | 20 CF BB | JSR &BBFF Initialise Program start address, Stack pointer, *EDIT mode & REPEAT/FOR/GOSUB levels | |
B2A3 | L | 076 011 144 | 4C 0B 90 | JMP &90D0 Process next BASIC program statement |