Some Assembly Required
Ben Eater demonstrated how Microsoft BASIC can write to the LCD of a 6502 CPU-based breadboard computer by modifying its source code.
Many engineers share a common experience in which they awake one day in a cold sweat only to realize that even after many years of working with them, they have no idea how computers actually work at a low level. An engineer is not the sort to just let something like this slide, so it is often the beginning of a new educational journey. This journey can take many forms, but given the tremendous complexity of modern computers and processors, people commonly start with older technology so that they are not completely overwhelmed.
Ben Eater, the master of perfectly trimmed and routed wires, has been building breadboard computers based on the 6502 CPU for educational purposes, and has been sharing that knowledge with everyone else who is interested for several years now. And as the growth of Eater’s list of videos attests to, there is a lot to learn. After successfully free-running a processor for the first time, one will then want to learn to run a stored program, add I/O, and, well, do just about everything else a computer can do as well.
Eater previously developed a slick little 6502 breadboard computer from just a few chips that runs an early version of Microsoft BASIC. Pretty cool, but the only way to interact with BASIC is via a serial connection to a modern computer. But since the computer has a small LCD display, it would be way more interesting to actually use that for I/O. So that is exactly what Eater demonstrated how to do in a new tutorial video that was just released.
As a first step, Eater demonstrated the quick and easy way to do this. When working with a 6502, hardware is memory mapped. This means that you can simply store a value in “memory” (or read a value, for that matter) to modify the behavior of attached hardware components. In the case of this breadboard computer, the LCD is connected to the system bus through a 6522 Versatile Interface Adapter chip.
This made it possible to simply issue a series of POKE commands in BASIC to initialize the display and print characters to it. But BASIC is a very slow interpreted language, so the results left much to be desired. If you have a long string of text to display, you would need to kick back a while and wait for each letter to be slowly written to the LCD.
But of course BASIC itself is not written in BASIC, but rather in assembly language. That means it is possible to modify the BASIC source code to include new assembly routines that can handle the job far more quickly. And it is not especially difficult to do this, either — at least if you are familiar with 6502 assembly language.
The key to the update involved adding a couple new tokens to the BASIC source code — these are the commands that the interpreter can recognize, like PRINT or GOTO. In this case, the tokens were used to send either commands to execute, or characters to print. Each token points to an assembly routine, and these essentially do the same thing as the slow BASIC code Eater previously wrote, just with a different syntax.
As expected, this modified version of BASIC wrote to the display much faster than POKEs ever could. At present the routine can only accept a single character at a time to print, which is not ideal. But Eater is considering how the routine might process strings, so keep your eyes open for future videos.