So, I’m getting very good at these long pauses eh?

Having described a lot about the keyboard in the last intermission post, thought it only fair that a “definitive” description should be added… with a grid.

Now there are many ways to craft a keyboard and a scanning mechanism but the simplest and cheapest (and thus the basis of Sinclair’s machines) is a simple grid with horizontal “traces” and vertical ones. If a key is depressed these “connect” and you can electrically identify the key pressed. This mechanism is not great because while you can guarantee to identify two keys reliably you cannot guarantee to reliably identify three. Why?

Imagine you have two wires running horizontally and two wires running vertically. For UK people think of a “Noughts and Crosses” board. For US people think of a “Tic-Tac-Toe” board. For anyone else you probably know one of those two terms. Imagine at each crossing there is a key and when you press a key the wires connect at those points.

Imagine you press the top left key. How can we find it? Let’s send electricity into the top horizontal wire and let’s look where it comes out? The left vertical wire because they’ve been connected. If we send electricity into the bottom horizontal wire, nothing comes out! Great!

Now let’s press top left and top right. Again we put electricity in the top wire, but now it comes out of both vertical wires! Ah yes that’s two keys. Again nothing comes out if we put electricity into the bottom wire.

What about pressing both the left keys? Well the top wire is connected to the left wire, not the right, we know top left. The bottom wire is ALSO connected to the left not the right so again the left wire gets the signal and we know bottom left has been pressed.

Top left and bottom right? Well now the top wire is connected to the left producing a signal there and the bottom wire is connected to the right and produces a signal there.

Now the tough one… We press top left, top right and bottom left… We put electricity into top wire and it comes out the left and right. Good. We put electricity into the bottom wire and it comes out of the left and right. Not good. Those two keys in the left have bridged the top and bottom wires. Imagine following from the left hand side on the bottom wire. You find the bottom left key so you can go vertically up that wire or you can continue to the right. Imagine you do both at the same time. So you go up and you find the top left key connected. Now you can continue up AND right along the top wire. You do both and going right you find the top right key down and you can go up AND right again. If you think of going up beyond the keys producing signals then hey presto despite the bottom right key NOT being down when you signal the bottom row you get signals out of the left and right. Electrically all four keys are “pressed” in this simplistic grid.

The 8×5 ZX Spectrum grid is actually well understood – 8 rows correspond with “half rows” of the ZX Spectrums 4 rows of 10 keys, and if you think along lines of “starting at zero” with zero being least significant bit the logical ordering starts with CAPS SHIFT to V, then A to G, Q to T, 1 to 5, then 0 to 6, P to Y, ENTER to H and finally SPACE to B – bit zero is always the “outside” key on the physical machine.

Electrically the ZX Spectrum Next has 16 extra keys implemented as two extra columns. These are not mapped in an obvious fashion to the Next registers $B0 and $B1, but being part of the same grid as the original 40 keys they interact with that grid. So let’s say you press Q and A, first keys in two different rows. Easy for the ULA to handle per normal. Now let’s add GRAPH. On the keyboard schematic this is in line with the A thus we have three corners of a square. So this means we trigger the fourth corner which is INV VIDEO.

To help show what is happening, here is the grid:

ULA rowbit 0bit 1bit 2bit 3bit 4extra 1extra 2
$FECAPSZXCVEXTEND
$B1 bit 0
Up
$B0 bit 3
$FDASDFGCAPS LOCK
$B1 bit 1
GRAPH
$B1 bit 2
$FBQWERTTRUE VID
$B1 bit 3
INV VID
$B1 bit 4
$F712345BREAK
$B1 bit 5
EDIT
$B1 bit 6
$EF09876;
$B0 bit 7

$B0 bit 6
$DFPOIUY,
$B0 bit 5
.
$B0 bit 4
$BFENTERLKJHDELETE
$B1 bit 7
Right
$B0 bit 0
$7FSPACESYMBOLMNBLeft
$B0 bit 1
Down
$B0 bit 2

In the non default mode where the extra “16” keys (16 without duplicated shift keys) are NOT translated to corresponding 8×5 keystrokes these the implications of three (or more) key interference is somewhat straightforward, but in the default mode a “ghost” extra key will leak onto the ULA grid as two keys.

Now a little treat. I have here a little tool which I call a “keyboard playground”. This reads the ZX Spectrum Next keyboard (with the extra keys “divorced” from the ULA grid) and shows you the status of all “56” keys on the ZX Spectrum Next keyboard. This originally used ULA graphics but it has more recently been re-written to use the ZX Spectrum Next “tilemap mode”. Simply unzip the file “zxkeyplay.nex”, copy it to your ZX Spectrum Next SD card and and you can explorer how certain combinations of keys can be “ghosted”. Alternatively you could inject it into the image of an SD card (e.g. with “hdfmonkey”) and use it on an emulator like CSpect or ZEsarUX and explore how the host keyboard maps to the ZX Spectrum Next emulation. Maybe you even might like to plug a PS/2 keyboard into the ZX Spectrum Next and see how that is mapped.

Little anecdote: Back in the day whenever possible I used to select “Sinclair” or “Sinclair Interface 2” as my joystick type in games. I personally did not own one of these interfaces, so how did I play? Well Sinclair decided to hook the two ports up in such a way that when the ULA scanned row $F7 the signals for one joystick would be sent back, and row $EF meant the other port signals would be sent back. The physical layout burned into my brain is left (1 and/or 6), right, down, up, fire (5 and/or 0). Technically this isn’t QUITE the same as how the joysticks worked but because most games only read one or other of the two key rows (I want to say most read the row 0 to 6) the effect was the same, and being just one keyboard row none of these keys interfere.

Intermission #4 – More ZX Spectrum Next keyboard