Mystery RAM
One of the notable things about the ZX81 is the tiny amount of RAM — just 1K1 in the base configuration. When you take off system housekeeping and the screen memory, that only leaves a few hundred bytes for both programs and data. While you could squeeze some impressive things into that space, for most practical use you’d need to add an external 16K RAM pack.
In order to get the full 80s experience, I found a modern kit version on eBay. Before assembling and installing it, I wanted to make sure I could measure the amount of RAM in the machine, in order to do a before-and-after comparison and check that it was working. That’s where things got weird.
The ZX81 maps its ROM into the first 16k of address space, and RAM after this. The variable RAMTOP
defaults to the highest writable address:
PRINT PEEK 16388+256*PEEK 16389
On my machine, this reports 17,408 (216 + 1024), as expected. However, I also came across this old forum post with the following test program:
10 FOR N=16640 TO 65536 STEP 256 20 POKE N,0 30 IF PEEK N<>0 THEN GOTO 50 40 NEXT N 50 PRINT "MEMORY SIZE ";(N/1024)-16;"K"
This looks reasonable — it just tries to write to higher and higher addresses, and check that the value read back matches the one written. I ran it to get a second opinion, and it reported 16k. What was going on?
When I first got my ZX81, it came with a couple of the original, hand-written guarantee cards, one of which had the model number as “16kb”, so I wondered if I had some kind of unusual internal upgrade. However, opening it up confirmed that it was the normal configuration with a pair of 4 kilobit 2114-compatible static RAM chips. The pinout on these chips — in particular, the ten address bits — also provides the explanation of the above behaviour.
The ZX81 is mapping the second 16K of its address space to a 14 bit address to the RAM. If there’s 16K of actual RAM available, all of this works as expected. However, if you only have 1K, it just ignores the top four bits. The 16K address space maps to sixteen copies of the same 1K of RAM. This is easy to confirm by POKEing a value to, say, 17000, and then PEEKing 18024 to confirm the same value comes back.
One of the nice things about playing around with old hardware is that it’s simple enough that, when something odd happens, you can figure out why. More than that, it provides a window into the thinking and priorities behind the design. The ZX81 was laser focussed on simplicity and low cost, and the approach to RAM reflects that, providing headroom for expansion without adding any additional hardware or software. It’s not what you’d expect in a modern system, but that’s what makes it fun.
-
For comparison, that’s about a third of the size of the plain text version of this post. [back]