{
}
-void update_keyboard(void)
+static uint8_t update_keyboard(void) __naked
{
- /* We need this assembler code because it is much faster, of course */
- /* TODO: make it naked? */
+ /*
+ * This is run 50 time a second so we do it in asm and also return
+ * 0 if nothing changed. That allows us to avoid the main tty
+ * processing on most interrupt events which saves us a lot of
+ * clocks.
+ */
__asm
ld hl,#_keybuf
ld c, #0xFE
ld b, #0x7f
- ld e, #8 ; 8 keyboard ports, 7FFE, BFFE, DFFE and so on
+ ld de, #8 ; 8 keyboard ports, 7FFE, BFFE, DFFE and so on
+ ; D to 0 for no change found
read_halfrow:
in a, (c)
-; and #0
cpl
- ld(hl), a
+ cp (hl)
+ jr z,nochange
+ inc d ; there 8 ports so we cannot overflow
+ ld (hl), a
+ nochange:
rrc b
inc hl
dec e
jr nz, read_halfrow
+ ld l,d
+ ret
__endasm;
}
{
int i;
- update_keyboard();
-
newkey = 0;
+ /* Nothing changed - no processing required */
+ if (!update_keyboard())
+ return;
+
for (i = 0; i < 8; i++) {
int n;
uint8_t key = keybuf[i] ^ keymap[i];