Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jerry Penner Newsgroups: comp.sys.apple2.programmer Subject: Re: Using Applesoft Internal Error Messages in a BASIC Error Handler Date: Thu, 30 Nov 2023 11:00:24 -0700 Organization: A noiseless patient Spider Lines: 74 Message-ID: References: <010cc230-427a-485e-9a90-bcd294ba96b5n@googlegroups.com> <95461d63-9b7a-47b8-b433-c31432d43d24n@googlegroups.com> <249c977a-9c90-4b82-8996-16a65fc8a368n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="db290eb942428b345874e51af455347e"; logging-data="1536706"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/doTb9xFqwS/jHgDCat00T" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cancel-Lock: sha1:U7cRdz3TnUmCEym4SKjFQraAzos= sha1:aAe8mWpKAp9XWXGRmAHkig2HH20= Xref: csiph.com comp.sys.apple2.programmer:6129 Bill Chatfield writes: > 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! Here's another way to see the errors: 10 ONERR GOTO 1000 20 REM make line 30 have your error of choice 30 NEXT 1000 PTR = 53856 + PEEK (222) 1005 POKE 216,0 1010 FOR X = 0 TO 1 STEP 0 1020 C = PEEK (PTR): PTR = PTR + 1: X = C > = 128 1030 PRINT CHR$ (C - 128 * (C > = 128)); 1040 NEXT 1050 PRINT " ERROR IN LINE " PEEK (218) + PEEK (219) * 256 Try different things for line 30: ]30 ASDF ]RUN SYNTAX ERROR IN LINE 30 ]30 NEXT ]RUN NEXT WITHOUT FOR ERROR IN LINE 30 ]30 X = 1 / 0 ]RUN DIVISION BY ZERO ERROR IN LINE 30 ]30 POKE 0,256 ]RUN ILLEGAL QUANTITY ERROR IN LINE 30 -- -- Jerry jerry+a2 at jpen.ca