Close

Key mapping

A project log for Tek V2

Version 2 of PS/2 keyboard adapter for Zeddies

danjovicdanjovic 08/04/2019 at 01:250 Comments

Zeddies use a matrix keyboard of 8 rows by 5 columns. Rows are tied to address lines A8 to A15 while rows are read in data lines D0 to D4.

Firmware uses a vector with 8 entries. Each entry corresponds to one address line A8..A15 set down.
char Keymap[Keymap_Size] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

Keys are encoded using 3 bits for lines and 3 bits for row. Two remaining bits can be used as modifiers (Shift on ZX80/81 and  Caps Shift/Symbol Shift on Speccy).


/*
   ZX spectrum keyboard matrix map codes
   bit  7   6   5   4   3   2   1   0
        CS  SS  r2  r1  r0  l2  l1  l0  

   r0..r2 is row [0..4]   mapping bits D0 to D4
   l0..l2 is line [0..7]  mapping address lines A8 to A15

   CS Caps Shift for composed keys (like directional keys)
   SS Symbol Shift for composed keys  
   
*/


PS/2 keyboard send a scancode (0x??) for each key pressed. When that key is released the scancode is preceeded by a 'break' code (0xE0 0x?? ). Some keys are preceeded by an 'extend' code (0xF0 0x??) and when released the 'break' code is sent, then the 'extend' code also sent and finally the scancode (0xE0 0xF0 ox??)

The scancode is used as an entry to a table which returns the modifier/row/line code an used to RESET a bit in the Keymap[] vector. If a 'break' code have been previously received the bit is SET in the vector.

Discussions