7

Some BASIC language enhancements for Commodore 8-bit machines, such as the 1982 DOS Wedge, worked by patching the CHRGOT routine. Even though BASIC is in ROM, every byte that is fetched from a program is processed by a cascaded pair of functions which are copied to RAM, called CHRGET and CHRGOT. Patching CHRGOT so that it jumps to a routine elsewhere in ROM will allow arbitrary functionality will be added to the BASIC interpreter. Although Commodore BASIC V2 has better hooks available, the CHRGET/CHRGOT hook is common to nearly all Microsoft-derived versions of BASIC for the 6502, including AppleSoft.

Did any AppleSoft BASIC enhancements for the Apple install a CHRGOT hook, or did they all use either the Ampersand Hook (which is unique to Applesoft) or the Language Card (copying AppleSoft to RAM and running it from there)?

1
  • "every byte that is fetched from a program is processed by a cascaded pair of functions which are copied to ROM," Did you mean RAM here?
    – ecm
    Commented Feb 4, 2023 at 15:02

1 Answer 1

7

Yes, programmers occasionally patched CHRGOT. It wasn't a common tactic because there were better ways to add user-defined commands and functions, but you might choose to patch CHRGOT if you wanted to perform a function in the background.

I patched CHRGOT to add a type-ahead keyboard buffer, which was published in Nibble magazine's recurring "One-Liner Contest" in November 1986.

In a previous issue of Nibble magazine there was another utility that patched CHRGOT to add a print spooler that ran in the background, so that Applesoft programs didn't have to wait if the printer was busy.

(EDIT) Supercat's comments led to another example by David Bartley in 1981, archived from Apple Assembly Lines (Vol 2, Iss 3) with source code and comments at http://www.txbobsc.com/aal/1981/aal8112.html

4
  • Interesting. I've tried my hand at writing a CHRGOT patch to add support for hexadecimal constants prefixed by #. My routine makes FOR I=1 to 255:P=PEEK(-16336):NEXT run slightly slower, but allows the code to be rewritten as FOR I=1 to 255:P=PEEK(#C030):NEXT which runs 2.5x as fast.
    – supercat
    Commented Feb 3, 2023 at 21:23
  • I wouldn't be surprised if the slight performance cost of scanning every character could be more than offset for most practical programs by checking whether CHRGOT is being called from FIN not only when a # is processed, but also when a digit is encountered and, if so, using an efficient text-to-binary conversion routine, since the original loop spent more time in the text-to-decimal conversion than it spent on all other operations combined.
    – supercat
    Commented Feb 3, 2023 at 21:27
  • 2
    In 1981, David Bartley published in Apple Assembly Lines (Vol 2, Iss 3) a program to do exactly that: add hex constants in Applesoft! His article will interest you, and he's got nicely-commented source code, archived at txbobsc.com/aal/1981/aal8112.html Commented Feb 3, 2023 at 21:43
  • Interesting. I think you should add that article to your answer. My code hadn't considered the scenario where the digits DEF appear consecutively within a number, but steals control from the FIN routine when parsing a hex constant, stuffing the result into the floating-point accumulator, rather than trying to feed FIN a sequence of decimal digits.
    – supercat
    Commented Feb 3, 2023 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .