On Thursday, November 30, 2023 at 1:23:58 AM UTC-5, fadden wrote:
The error code, passed in the X register, is just the index of the start of the error
text (table at $d260). The error routine prints "?", then the error text, then "ERROR"
and a bell (from $d350). If the code was running, it prints the line number, and does
the Applesoft error handling.
So for example, SYNTAX ERROR is error code 16. $d260 + 16 = $d270, which is the string
"SYNTAX". The last letter has the high bit set (Dextral Character Inverted format, or
DCI), which is how the code knows when to stop printing characters.
Try this:
100 BASE = 53856: REM $D260
110 ERRCODE = 16: GOSUB 1000: REM SYNTAX ERROR
120 ERRCODE = 53: GOSUB 1000: REM ILLEGAL QUANTITY
130 END
1000 PTR = BASE + ERRCODE
1010 L = PEEK (PTR): IF L > = 128 THEN PRINT CHR$ (L - 128);: PRINT " ERROR": RETURN
1020 PRINT CHR$ (L);:PTR = PTR + 1: GOTO 1010
Wow, that makes a lot more sense in BASIC. I'm use to an ASCII code 0 terminator for
strings, so setting the high bit is new to me. But it is more efficient because it saves
one character. It's also more efficient than using a length byte at the beginning.
Yeah, this is just what I was looking for. This is so much better than an IF/THEN for each
error code in every BASIC program.
I thought I was getting good at reading 6502 assembly, but the Applesoft source code is a
little harder. I guess Bill Gates wrote it. Haha.
Thank you so much for translating!
The error code, passed in the X register, is just the index of the start
of the error text (table at $d260). The error routine prints "?", then
the error text, then "ERROR" and a bell (from $d350). If the code was running, it prints the line number, and does the Applesoft error handling.
So for example, SYNTAX ERROR is error code 16. $d260 + 16 = $d270, which
is the string "SYNTAX". The last letter has the high bit set (Dextral Character Inverted format, or DCI), which is how the code knows when to
stop printing characters.
Try this:
100 BASE = 53856: REM $D260
110 ERRCODE = 16: GOSUB 1000: REM SYNTAX ERROR
120 ERRCODE = 53: GOSUB 1000: REM ILLEGAL QUANTITY
130 END
1000 PTR = BASE + ERRCODE
1010 L = PEEK (PTR): IF L > = 128 THEN PRINT CHR$ (L - 128);: PRINT " ERROR": RETURN
1020 PRINT CHR$ (L);:PTR = PTR + 1: GOTO 1010
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 11:39:07 |
Calls: | 10,387 |
Calls today: | 2 |
Files: | 14,060 |
Messages: | 6,416,701 |