-
Encoding examples
08/05/2019 at 02:59 • 0 commentsSPACE key on PS/2 keyboard return scancode of 0x29 (41 in decimal). In Zeddies the SPACE is at line 0 (KB0) of row 7 (A15)
Then the 41th positon in vector PS2Keymap[ ] contains the value 0x07
Backspace has a PS/2 scancode of 0x66 (102) and is a good example of the use of the modifier. On the Zeddies the corresponding key is SHIFT + '0' (ROBOUT). Key 0 itself is at line 0 of row 4. Then the 102th entry in vector PS2Keymap[ ] has the value of 04 for the '0' key plus 128 that is the 7th bit for the encoded value.
Arrow keys are extended PS/2 codes but are also mapped as SHIFT plus the values for keys 5 to 8.
... if (EXT==true) { // extended set EXT=false; switch (code) { case _PS2_UP: m=0x80 | _7; break; // Caps Shift bit + map code for ZX key 7 case _PS2_DOWN: m=0x80 | _6; break; case _PS2_LEFT: m=0x80 | _5; break; case _PS2_RIGHT: m=0x80 | _8; break; case _PS2_KPENT: m=_ENT ; break; // Enter key case _PS2_LCONTROL: m=_SYMB ; break; // Enter key ... ...
The function Update_matrix( ) uses this value to SET or RESET a bit on the keyboard matrix depending upon the reception of a 'break' code previously.
void Update_matrix( char m){ uint8_t line= m & 0x07; uint8_t row= (m>>3) & 0x07; if (BRK==true) { BRK=false; Keymap[line]|=(1<<row); // set bits to break if (m & 0x80) Keymap[0]|=(1<<0); // if bit 7 is set then set Caps Shift bit at row=0, line=0 if (m & 0x40) Keymap[7]|=(1<<1); // if bit 6 is set then set Symbol Shift bit at row=1, line=7 } else { Keymap[line]&=~(1<<row); // reset bits to make if (m & 0x80) Keymap[0]&=~(1<<0); // if bit 7 is set then reset Caps Shift bit at row=0, line=0 if (m & 0x40) Keymap[7]&=~(1<<1); // if bit 6 is set then reset Symbol Shift bit at row=1, line=7 }
-
Key mapping
08/04/2019 at 01:25 • 0 commentsZeddies 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.