Browse Source

ti/kbd: begin GetC implementation

For now, only digits are scanned. Lifted from my "tiseg7" example.

ref #41
pull/75/head
Virgil Dupras 4 years ago
parent
commit
dca6ce4e8e
4 changed files with 92 additions and 15 deletions
  1. +1
    -1
      fonts/5x7.txt
  2. BIN
      kernel/fnt/5x7.bin
  3. +90
    -9
      kernel/ti/kbd.asm
  4. +1
    -5
      recipes/ti84/glue.asm

+ 1
- 1
fonts/5x7.txt View File

@@ -148,7 +148,7 @@
...
.
.
...
....
. .
. .
...


BIN
kernel/fnt/5x7.bin View File


+ 90
- 9
kernel/ti/kbd.asm View File

@@ -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
kbdGetC:
push bc

; loop until a digit is pressed
.loop:
; 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.

; 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
ld a, 0x00
ex af, af'
out (KBD_PORT), a

.loop:
in a, (KBD_PORT)
inc a ; if a was 0xff, will become 0 (z test)
jr z, .loop ; zero? nothing pressed

pop af
ei
ret

+ 1
- 5
recipes/ti84/glue.asm View File

@@ -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


Loading…
Cancel
Save