Old Code

I was rummaging around in a box of old stuff, and came across a typed-out bit of BASIC I wrote for my ZX-81. I know it was the ZX-81 because of the code structure…

See, BASIC on the ZX-81 was pretty primitive. For example, while it understood arrays there was no ‘data’, ‘read’, or ‘restore’ functionality. So you had to do things the hard way and line-by-line define the array on runtime:

10 DIM A$(2,10)
20 LET A$(1)="data"
30 LET A$(2)="more data" 

It also had a hard time chaining commands, so while an IF / THEN could do a mathematical operation

10 IF A=B THEN LET C=C+1

it generally couldn’t run a second command based on the evaluation. So you needed to:

10 IF A=B THEN GOSUB 100

100 PRINT "I did a thing!"
110 RETURN

Anyway, back to the ancient typed code. What this bit of code apparently does (I don’t have a ZX-81, and the tokenized input method of keyboard modifiers is nightmarish – and they preserved that in the emulators) is display “TRON” in the movie font on the screen in the low-res 64×43 mode.

Based on this I’m guessing this was written in 1982 after I saw TRON in the theater, which means I was 13.

It’s interesting to me to see the thought process of 13 year old me; the machine had 1K of RAM, so I was doing tricks to maximize that space.

The ZX-81 has a PLOT X,Y function which will put a dot on the screen in that spot, and while it would have been totally acceptable in the early 80’s to write a ton of PLOT commands, it would be too large for the 1K of RAM – so what I did was:

10 DIM D$(13,64)

And then did 13 variations of

20 LET D$(1)="111111111111100111111111100000000111100000010000000011111"

Each of these is stepped through and each position of the string was evaluated to plot a point in that position for each of the 13 lines that made up the logo on the screen.

100 FOR I=1 TO 13
110 FOR P=1 TO 64
120 IF D$(I,P)="1" THEN GOSUB 1000
130 NEXT P
140 NEXT I

1000 PLOT P,I+13
1010 RETURN

I’m guessing as the code doesn’t define “fast” mode, that this whole display process would have taken like 10-15 seconds. The ZX-81 was so primitive that that process for both the screen draws and processing reduced the Z80 CPU’s processing speed by two thirds – so you could put it into “fast” mode where it stopped worrying about the screen and just did work, and then updated the screen at the end.

This would have been before I had a cassette deck that I could use to record programs on, so this would have been written out on green-bar printer paper, typed in, debugged, and then the final version typed out on my IBM Selectric typewriter for later readability.

Interestingly, because of the limited space, nothing I wrote for the ZX-81 is commented – a major faux pas in the modern day. I just have to analyze the code and “figure it out” when I stumble over something from this era. 🙂

Listening to "Joyride" by Dream Fiend