Sinclair’s “Improved” 8K ROM

Author(s): Ian Logan
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v2 n12 (Volume 2, Issue 12)
Date: December 1981
Pages: 4-5

Sinclair Research first introduced its 8K ROM in March, 1981, coinciding with the ZX81’s launch in the UK. From the start the 8K ROM was a source of considerable embarrassment to Sinclair.

The old 8K ROM’s most obvious bug was that you had to POKE 16347,255 after each PAUSE statement. Soon a serious bug in the arithmetic routines became apparent. For example, the 8K ROM gave a number a little greater than 3 as the square root of 0.25. Among several other, less serious, bugs, my favorite is shown by:

  10 FOR A=225 TO 230
20 PRINT CHR$ A
30 NEXT A

The computer fails to suppress the leading space before the first keyword.

In June 1981, Sinclair replied to complaints about the 8K ROM, by saying that an improved version would be available in August, 1981. Soon after, they also said they had found a way to correct the faulty arithmetic. They were most reticent about the exact nature of the bug and even more so about how they could correct it.

So I was a little suprised in August when I can across my first ZX81 that could count correctly. At first I thought it must have an improved ROM. Instead Sinclair had fixed a printed circuit board on top of the Z80A itself.

On the board are a 74LS12 (triple NAND gate) and a 74LS27 (a triple NOR gate). The board is soldered to the pins ground, 5V, A0-A9, A11, A14, and most importantly, D6.

To my knowledge, Sinclair first showed their improved ROM at the PCW show in England in September. They did not announce its arrival; they just had improved ROMs in the machines on display. I presume all machines now being made contain the improved ROM, but are there some stocks of old ROMs being used up?

You can identify the improved ROM by entering PRINT PEEK 54. The improved ROM gives 136. The old 8K ROM gives 132.

Differences between the old and improved 8K ROMs–The main difference is the correction of the bugs. This entails some extra and deleted bytes, and generally relocating the routines in the upper half of the program. The INPUT routine now contains a CLEAR WORKSPACE instruction. The VARIABLE routine at 102F contains an alteration to the decoding, but I am not sure why.

The POKE 16437,255 bug–The old program attempted at 0F3D to keep bit 15 of FRAMES SET by using SET 7,(FRAMES-High). In theory, this should work, but the special case of FRAMES holding 8000h was overlooked. When the display is produced by the PAUSE routine, the first action is to decrement FRAMES. In this case bit 15 becomes RESET with dire results within the next 11 minutes.

The remedy is simply to use the instruction:

     LD   (FRAMES-High),+FF

(load constant FF hex) in the new routine.

The Arithmetic Bug–The 3 bytes at 1733-1735 should just not be in the old 8K ROM. They contain these instructions:

     LD   A,H
SUB L
LD H,A

and ruin the otherwise good arithmetic handling by unnecessarily subtracting the value of the L register from the H register. The improved ROM does not contain these bytes at all, so the arithmetic handling routine works fine.

So how does Sinclair’s add-on work? Here’s my hypothesis: By using the 3 NAND gates and the 3 NOR gates, it may decode the address lines of location 1735, and “push” D6 low in the M1 period.

This makes the Z80 believe that the instruction fetched from location 1735 is DAA rather than LD H,A. The H register is therefore unaltered and the arithmetic operation correct.

This nullifying of the 3 bytes is rather cunning and made possible only because the instruction at 1736 is XOR A (used to clear the A register).

Presumably the add-on circuit is active when locations 0035, 0735, and 1335 are being addressed. Fortunately, these locations are low with respect to D6. I still await confirmation of this work, but it seems probable.