top of page

The design has only two major components, an Amtel AVR ATtiny45 micro-controller (MCU)  and a XC9572 Xilinx complex programmable logic device (CPLD).

The Atmel micro-controller initializes and talks to the keyboard. The keyboard is put into the mode "scan code set 3", which is a simplified key mode where no extended codes are used which makes life easier. Also the key auto-repeat is disabled. Auto-repeat is handled by the spectrum so no need to use it on the keyboard end. The controller program translates the 127 possible AT key codes into spectrum keyboard column bits using a look-up table to map one to the other. See the AVR source code for details.

Finally the micro-controller writes serially the state of all 40 keyboard keys to the Xilinx programmable logic. The CPLD  which acts like a 40 bit memory device storing the key states of up or down and passing these to the spectrum when requested.

The most important thing the CPLD does, apart from storing the key information, is handling I/O reads from spectrum ! When the spectrum reads the keyboard using a z80 'IN' opcode the CPLD detects the IORGE with the Z80 /RD line going low, which is the signal for a keyboard read, and places onto D4 to D0 the state of the 'key bits' array. The bits are controlled by the A8 to A15 address lines. A8 to A15 enables a particular keyboard row and each of the D4 to D0 bits corresponds to a keyboard column. As the ULA is effectively 'isolated' from the specturm databus, the CPLD has effective priority, so it's data is read by the spectrum and there's no contention with the ULA.


The Advantage of this design

Why's this design different from others ? Well.. on the original Spectrum you could read more than one row of keys at a time by having more than one address line being low during a keyboard read. The big advantage of this CPLD approach is that it can simulate this behavior. So if both address line A8 and A10 are low, the CPLD will output the up/down key status of BOTH those rows onto the databus, just like you'd see happening with a real Spectrum.

 

Yet Another ZX-Spectrum AT Keyboard Interface

bottom of page