This is a timely break to report on my recent investigations about the ZX Spectrum Next keyboard.
Recently the ZX Spectrum Next team released a new distribution of the “SYSTEM/NEXT” package, calling it “22.09”.
One interesting component of this is that Core version 3.01.10 is now part of an official distro and the release notes mentions “PS/2 keyboard now emulates the full size 8×7 zx next membrane”.
What is this?
The 40-key keyboard on the original Sinclair ZX Spectrum is effectively a grid of 8 rows of 5 keys, each row being one half row of physical keys. Keys produce potentially up to SEVEN different effects on the original models, with usually only 5 “legends” printed on the keyboard. For example the ‘J’ key can produce a lower case J in lower case mode, upper case J in caps mode (or holding the CAPS SHIFT key), a ‘-‘ (minus) sign when holding symbol shift, a “user defined graphic” character in graphics mode, the keyword “LOAD” in keyword mode, the keyword “VAL” in extended mode, or the keyword “VAL$” in extended mode while holding the symbol shift key.
From the ZX Spectrum+ onwards there have been additional keys, but these were effectively just “shortcuts”, like the “DELETE” key actually triggering CAPS SHIFT and 0 (zero), and so on. By default the same shortcuts are implemented on the ZX Spectrum Next.
During the development of the core, versions 3.01.04 and 3.01.05 gradually introduced the ability to read the additional 16 keys directly and to optionally disable the translation of these keys to the classic 8 by 5 grid. The core grid is scanned as before via the ULA port, and two Next Registers have been added to be able to read the additional keys directly.
There is a great ZX Spectrum Next Assembly Developer Guide that includes reference to the decoding, but unfortunately some the fine details are incorrect at the time of writing. The error is that the guide says that bits are zero if pressed and one if not, matching ULA keyboard behaviour. I believe this was briefly the case but the “final” implementation in 3.01.05 reversed this so that the extra keys were 1 in the next register if pressed, and 0 if not. The author is aware and at some point will be fixing the document.
The now released 3.01.10 core means that if you use a PS/2 keyboard (e.g. if you have a board only development system, or just prefer using a PS/2 keyboard with a ZX Spectrum Next) you can also use dedicated keys.
Here is a table which should be everything you would need for the additional keys (we won’t go over the 40 standard keys).
Next Reg 176 ($B0) | Next Key | Classic ZX Key | PS/2 Documented Key (US) | UK Layout PS/2 Key | Comment |
Bit 7 (128) | ; | SYMBOL+O | ; : | ; : | |
Bit 6 (64) | “ | SYMBOL+P | ‘ “ | ‘ @ | NOTE: Unshifted PS/2 key!! |
Bit 5 (32) | , | SYMBOL+N | , < | , < | |
Bit 4 (16) | . | SYMBOL+. | . > | . > | |
Bit 3 (8) | Up Arrow | CAPS+7 | Up Arrow | Up Arrow | |
Bit 2 (4) | Down Arrow | CAPS+6 | Down Arrow | Down Arrow | |
Bit 1 (2) | Left Arrow | CAPS+5 | Left Arrow | Left Arrow | |
Bit 0 (1) | Right Arrow | CAPS+8 | Right Arrow | Right Arrow | |
Next Reg 177 ($B1) | Next Key | Classic ZX Key | PS/2 Documented Key (US) | UK Layout PS/2 Key | Comment |
Bit 7 (128) | DELETE | CAPS+0 | Backspace | Backspace | |
Bit 6 (64) | EDIT | CAPS+1 | ` ~ | ` ¬ | The key left of ‘1’ |
Bit 5 (32) | BREAK | CAPS+SPACE | Escape | Escape | |
Bit 4 (16) | INV VIDEO | CAPS+3 | \ | | # ~ | US: Right of ] UK: Right of ‘ |
Bit 3 (8) | TRUE VIDEO | CAPS+2 | Tab | Tab | |
Bit 2 (4) | GRAPH | CAPS+9 | Right Alt | Alt Gr | Right of space bar |
Bit 1 (2) | CAPS LOCK | CAPS+2 | Caps Lock | Caps Lock | |
Bit 0 (1) | EXTEND MODE | CAPS+SYMBOL | Left Alt | Alt | Left of space bar |
In addition to this on a PS/2 keyboard either shift key works as CAPS SHIFT and either control (ctrl) key works as SYMBOL SHIFT.
These two next registers are always populated. However as mentioned by default these keys are also mapped to the regular 8 by 5 matrix ULA keyboard ports. This can be disabled by setting bit 4 (16) of the ULA Control register 104 ($68).
While we’re “documenting” the keyboard might as well list where you might find other single symbols on a ZX Spectrum Keyboard.
Character | ZX Spectrum | Comment |
! | SYMBOL+1 | |
@ | SYMBOL+2 | US keyboard influence? |
# | SYMBOL+3 | US keyboard influence? |
$ | SYMBOL+4 | |
% | SYMBOL+5 | |
& | SYMBOL+6 | Not 7 as might expect from modern keyboards |
‘ | SYMBOL+7 | |
( | SYMBOL+8 | Not 9 as might expect from modern keyboards |
) | SYMBOL+9 | Not 0 as might expect from modern keyboards |
_ | SYMBOL+0 | |
< | SYMBOL+R | |
> | SYMBOL+T | |
; | SYMBOL+O | Also has dedicated key on ZX Spectrum+ and beyond |
“ | SYMBOL+P | Also has dedicated key on ZX Spectrum+ and beyond |
[ | EXTEND (CAPS+SYMBOL) SYMBOL+Y | |
] | EXTEND (CAPS+SYMBOL) SYMBOL+U | |
© | EXTEND (CAPS+SYMBOL) SYMBOL+P | |
^ | SYMBOL+H | ZX character is a full arrow not just a carat |
– | SYMBOL+J | |
+ | SYMBOL+K | |
= | SYMBOL+L | |
~ | EXTEND (CAPS+SYMBOL) SYMBOL+A | |
| | EXTEND (CAPS+SYMBOL) SYMBOL+S | |
\ | EXTEND (CAPS+SYMBOL) SYMBOL+D | |
{ | EXTEND (CAPS+SYMBOL) SYMBOL+F | |
} | EXTEND (CAPS+SYMBOL) SYMBOL+G | |
: | SYMBOL+Z | |
£ | SYMBOL+X | |
? | SYMBOL+C | |
/ | SYMBOL+V | |
* | SYMBOL+B | |
, | SYMBOL+N | Also has dedicated key on ZX Spectrum+ and beyond |
. | SYMBOL+M | Also has dedicated key on ZX Spectrum+ and beyond |
Unless you drop into “48K mode” this should be enough to type in anything on the ZX Spectrum Next.