July 17, 2026

(Further) Extending MS-BASIC (6502) – Part 1

Further extending?

Well, yes … provided you’ve built Ben Eater’s 6502 breadboard computer and followed his videos on first getting MS-BASIC running on it, then hacking it to add custom commands and, finally (at least of this writing) reverse engineering it to add more ambitious extensions.

After I had done the above, I wanted to add several more custom MS-BASIC commands to make driving the LCD easier and more flexible. Adding things like defining custom characters, scrolling, cursor repositioning and so on. And in doing this, I quickly ran into a problem …

It turns out that the “token table” (that’s where all the BASIC keywords are defined), is limited to a maximum of 256 characters (0-255). And 90% of that space is already used by the standard BASIC commands. Adding commands beyond that … crashes MS-BASIC the moment it tries to evaluate a keyword.

So, that’s what this “further” thing is about. This post (“Part 1”) will cover extending the size of the token table, so we can add more custom commands than is currently possible. A subsequent (“Part 2”) will cover my additional custom commands for manipulating the LCD screen, as well as some examples of their use. And, now that part is written, it seems I’ll need a part three to cover the actual 6502 assembly code behind the custom commands as part 2 ran way longer than planned.

Extending the TOKEN Table

Once I had figured out that the TOKEN table was both limited in size, and almost full, I searched around a bit to see if anyone else had run into the same problem.

I found this, which doubles the size of the token table, and went about implementing it, conditionally (for the IMDLABS build/define/label). The author, Alexander Sharikhin, was doing it for their own W65C02S version of basic, but it fits nicely here.

If you want to make this change to your version of MS-BASIC there are a few ways to go about it:

  • Follow the steps on the linked page, and then find a spot to store the byte for “EXTRA_TABLE_FLAG” (I put it in page zero, via zeropage.s).
  • Copy program.s and zeropage.s from my MS-BASIC project to yours, and then replace “IMDLABS” in both files with whatever BASIC version (symbol) you want to use (e.g., EATER).
  • Download the code from/fork my version of MS-BASIC, build that and run it (it’ll be imdlabs.bin). Note that this version requires that you’ve done the 4-bit LCD conversion!

With this done … there is now plenty of space in the token table for adding new commands; something I will take full advantage of in the next post …