From dca6ce4e8eadcef6c95fee5f900c9f38ab28fa12 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 8 Nov 2019 14:04:56 -0500 Subject: [PATCH] ti/kbd: begin GetC implementation For now, only digits are scanned. Lifted from my "tiseg7" example. ref #41 --- fonts/5x7.txt | 2 +- kernel/fnt/5x7.bin | Bin 665 -> 665 bytes kernel/ti/kbd.asm | 103 +++++++++++++++++++++++++++++++++++++----- recipes/ti84/glue.asm | 6 +-- 4 files changed, 94 insertions(+), 17 deletions(-) diff --git a/fonts/5x7.txt b/fonts/5x7.txt index 19fcd62..91ed358 100644 --- a/fonts/5x7.txt +++ b/fonts/5x7.txt @@ -148,7 +148,7 @@ ... . . - ... +.... . . . . ... diff --git a/kernel/fnt/5x7.bin b/kernel/fnt/5x7.bin index 58c741bbe5d353571a75b600cd04d6f470e7707e..178e5f64307d473af48167d66e7b5c80e4ebec41 100644 GIT binary patch delta 12 UcmbQqI+Jz6Tt>N#^L{e|03DJ9)Bpeg delta 12 UcmbQqI+Jz6Tt>c)^L{e|03AXE!~g&Q diff --git a/kernel/ti/kbd.asm b/kernel/ti/kbd.asm index e41e389..2a0b0cf 100644 --- a/kernel/ti/kbd.asm +++ b/kernel/ti/kbd.asm @@ -6,22 +6,103 @@ .equ KBD_PORT 0x01 ; *** Code *** + +; Wait for a digit to be pressed and sets the A register to the value (0-9) of +; that digit. +; +; This routine waits for a key to be pressed, but before that, it waits for +; all keys to be de-pressed. It does that to ensure that two calls to +; waitForKey only go through after two actual key presses (otherwise, the user +; doesn't have enough time to de-press the button before the next waitForKey +; routine registers the same key press as a second one). +; ; Sending 0xff to the port resets the keyboard, and then we have to send groups ; we want to "listen" to, with a 0 in the group bit. Thus, to know if *any* key ; is pressed, we send 0xff to reset the keypad, then 0x00 to select all groups, ; if the result isn't 0xff, at least one key is pressed. -waitForKey: - push af - - ld a, 0xff - out (KBD_PORT), a - ld a, 0x00 - out (KBD_PORT), a +kbdGetC: + push bc +; loop until a digit is pressed .loop: - in a, (KBD_PORT) - inc a ; if a was 0xff, will become 0 (z test) - jr z, .loop ; zero? nothing pressed + ; When we check for digits, we go through all 3 groups containing them. + ; for each group, we load the digit we check for in B and then test the + ; bit for that key. If the bit is reset, our key is pressed. we can + ; jump to the end, copy B into A and return. - pop af + ; check group 2 + ld a, 0xfb + call .get + + ld b, '3' + bit 1, a + jr z, .end + + ld b, '6' + bit 2, a + jr z, .end + + ld b, '9' + bit 3, a + jr z, .end + + ld a, 0xf7 + call .get + + ld b, '2' + bit 1, a + jr z, .end + + ld b, '5' + bit 2, a + jr z, .end + + ld b, '8' + bit 3, a + jr z, .end + + ; check group 4 + ld a, 0xef + call .get + + ld b, '0' + bit 0, a + jr z, .end + + ld b, '1' + bit 1, a + jr z, .end + + ld b, '4' + bit 2, a + jr z, .end + + ld b, '7' + bit 3, a + jr z, .end + + jr .loop ; nothing happened? loop + +.end: + ; loop until all keys are de-pressed +.loop2: + xor a + call .get + inc a ; if a was 0xff, will become 0 (nz test) + jr nz, .loop2 ; non-zero? something is pressed + + ; copy result into A + ld a, b + + pop bc + ret +.get: + ex af, af' + ld a, 0xff + di + out (KBD_PORT), a + ex af, af' + out (KBD_PORT), a + in a, (KBD_PORT) + ei ret diff --git a/recipes/ti84/glue.asm b/recipes/ti84/glue.asm index 0be9c54..6854dc4 100644 --- a/recipes/ti84/glue.asm +++ b/recipes/ti84/glue.asm @@ -30,7 +30,7 @@ .inc "ti/lcd.asm" .inc "ti/kbd.asm" .equ STDIO_RAMSTART LCD_RAMEND -.equ STDIO_GETC GetC +.equ STDIO_GETC kbdGetC .equ STDIO_PUTC lcdPutC .inc "stdio.asm" @@ -66,10 +66,6 @@ main: call shellInit jp shellLoop -GetC: - call waitForKey - jr boot - handleInterrupt: di push af