After some weeks of hard work, I finally have been able to get my LM80C to act like an 8-bits computer of the golden age. It can print text on screen, move a cursor and scroll the screen when typing. It looks like a real home computer of the ’80s.
But how have I reached this? With some code…
The last time I’ve posted something I wrote about my tests with sprites. I tried to move some sprites around the screen with some lines of BASIC. It was funny but I had to digit the commands into the terminal console and see the effects on the TV monitor. I wanted more. I wanted to digit and see what I’ve typed in directly on the screen, like in a real home computer of the ’80s. The limit I had was the BASIC interpreter I was using: it was developed to work on a terminal computer. A terminal computer is a machine that gets commands from a remote location, usually composed by a monitor and a keyboard (the “terminal”). This kind of systems were very common in the ’70s of the last century because they let a central computer to be shared between a lot of terminals where users wrote their codes and got their data. The personal computers made their first appearence during the second half of the ’70s: a user could have at his/her home a complete computer for his/her own needs, and for that they were also called “home computer”. A home computer was connected to a TV set and programs could be input through the built-in keyboard: text appeared directly on the screen and so did the output of the machine. You didn’t need a dedicated monitor. But the NASCOM BASIC I’m using on my LM80C was adapted to work on a terminal computer. So it gets the inputs from a serial line and outputs data to the same communication channel. You cannot make a form with text and semi-graphics chars, i.e., because you cannot position the cursor or get the already printed chars staying at some fixed points. So I thinked for a method that could be easily adapted to the interpreter. The easiest way I found was to add some code to the routine that echoes chars to the host computer: in fact, each char that is received by the host and need to be sent back to it or that is sent to the remote system by the interpreter passes through a serial buffer from which a routine fetches chars one by one. Every time that a char must be sent to the host it is collected and sent to the Z80 SIO: my mod simply get this char and print it on the video, too. It seems easy, but it isn’t. Since the TMS9918A doesn’t have HW support for a “cursor” (the position at which that next char will be printed on the video), I also had to write other pieces of code that keep track of the position of a special char that I used as a cursor. Another problem was the scrolling: when the cursor reaches the last cell in the bottom right of the video and the user types in another char the screen must scroll one row up. Same if the ENTER key is pressed and the cursor is at the last row. Solved these problems I also added some treats, too. Since I could make a typo when I was digiting my lists, I also added support for backspace: this means that if I press this key the cursor will go backwards 1 position to the left deleting the previsous char. Lastly, now we can clear the whole screen by entering the “CLS” (CLear Screen) command. Here is a little video that shows these adds in action:
Code is on my Github repository. In this last example I started to split the firmware in several modules, to keep separated the portions that are different and to group in a single file the routines for a specific thing. This way I can modify a module and re-use it in future releases of the firmware without the need to make the same changes each time I develop a new release of the firmware.