ti/kbd: widen char detection

no alpha yet.

ref #41
This commit is contained in:
Virgil Dupras 2019-11-08 14:58:29 -05:00
parent dca6ce4e8e
commit ca8b315e9d

View File

@ -7,8 +7,8 @@
; *** Code *** ; *** Code ***
; Wait for a digit to be pressed and sets the A register to the value (0-9) of ; Wait for a digit to be pressed and sets the A register ASCII value
; that digit. ; corresponding to that key press.
; ;
; This routine waits for a key to be pressed, but before that, it waits for ; 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 ; all keys to be de-pressed. It does that to ensure that two calls to
@ -22,78 +22,50 @@
; if the result isn't 0xff, at least one key is pressed. ; if the result isn't 0xff, at least one key is pressed.
kbdGetC: kbdGetC:
push bc push bc
push hl
; loop until a digit is pressed ; loop until a digit is pressed
.loop: .loop:
; When we check for digits, we go through all 3 groups containing them. ld hl, .dtbl
; for each group, we load the digit we check for in B and then test the ; we go through the 7 rows of the table
; bit for that key. If the bit is reset, our key is pressed. we can ld b, 7
; jump to the end, copy B into A and return. .inner:
ld a, (hl) ; group mask
; check group 2
ld a, 0xfb
call .get call .get
cp 0xff
ld b, '3' jr nz, .something
bit 1, a ; nothing for that group, let's scan the next group
jr z, .end ld a, 9
call addHL ; go to next row
ld b, '6' djnz .inner
bit 2, a ; found nothing, loop
jr z, .end jr .loop
.something:
ld b, '9' ; We have something on that row! Let's find out which char. Register A
bit 3, a ; currently contains a mask with the pressed char bit unset.
jr z, .end ld b, 8
inc hl
ld a, 0xf7 .findchar:
call .get rrca ; is next bit unset?
jr nc, .gotit ; yes? we have our char!
ld b, '2' inc hl
bit 1, a djnz .findchar
jr z, .end .gotit:
ld a, (hl)
ld b, '5' or a ; is char 0?
bit 2, a jr z, .loop ; yes? unsupported. loop.
jr z, .end
; wait until all keys are de-pressed
ld b, '8' push af ; --> lvl 1
bit 3, a .wait:
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 xor a
call .get call .get
inc a ; if a was 0xff, will become 0 (nz test) inc a ; if a was 0xff, will become 0 (nz test)
jr nz, .loop2 ; non-zero? something is pressed jr nz, .wait ; non-zero? something is pressed
; copy result into A pop af ; <-- lvl 1
ld a, b
pop hl
pop bc pop bc
ret ret
.get: .get:
@ -106,3 +78,14 @@ kbdGetC:
in a, (KBD_PORT) in a, (KBD_PORT)
ei ei
ret ret
; digits table. each row represents a group. first item is group mask.
; 0 means unsupported. no group 7 because it has no keys.
.dtbl:
.db 0xfe, 0, 0, 0, 0, 0, 0, 0, 0
.db 0xfd, 0x0d, '+' ,'-' ,'*', '/', '^', 0, 0
.db 0xfb, 0, '3', '6', '9', ')', 0, 0, 0
.db 0xf7, '.', '2', '5', '8', '(', 0, 0, 0
.db 0xef, '0', '1', '4', '7', ',', 0, 0, 0
.db 0xdf, 0, 0, 0, 0, 0, 0, 0, 0
.db 0xbf, 0, 0, 0, 0, 0, 0, 0, 0x7f