1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-01 03:18:05 +11:00

kbd: simplify code

This commit is contained in:
Virgil Dupras 2019-07-21 16:58:16 -04:00
parent 77d805ea0f
commit 52e5f5b5bf

View File

@ -8,15 +8,23 @@
; 0 when nothing was typed. ; 0 when nothing was typed.
; KBD_FETCHKC ; KBD_FETCHKC
; *** Consts ***
.equ KBD_KC_BREAK 0xf0
.equ KBD_KC_EXT 0xe0
.equ KBD_KC_LSHIFT 0x12
.equ KBD_KC_RSHIFT 0x59
; *** Variables *** ; *** Variables ***
.equ KBD_SKIP_NEXT KBD_RAMSTART ; Set to previously received scan code
; Pointer to a routine that fetches the last typed keyword in A. Should return .equ KBD_PREV_KC KBD_RAMSTART
; 0 when nothing was typed. ; Whether Shift key is pressed
.equ KBD_RAMEND KBD_SKIP_NEXT+1 .equ KBD_SHIFT_ON KBD_PREV_KC+1
.equ KBD_RAMEND KBD_SHIFT_ON+1
kbdInit: kbdInit:
xor a xor a
ld (KBD_SKIP_NEXT), a ld (KBD_PREV_KC), a
ld (KBD_SHIFT_ON), a
ret ret
kbdGetC: kbdGetC:
@ -26,20 +34,24 @@ kbdGetC:
; scan code not zero, maybe we have something. ; scan code not zero, maybe we have something.
; Do we need to skip it? ; Do we need to skip it?
push af ; <| ex af, af' ; save fetched KC
ld a, (KBD_SKIP_NEXT) ;| ld a, (KBD_PREV_KC)
or a ; | ; If F0 (break code) or E0 (extended code), we skip this code
jr nz, .skip ; | cp KBD_KC_BREAK
pop af ; <| jr z, .skip
cp KBD_KC_EXT
jr z, .skip
ex af, af' ; restore saved KC
ld (KBD_PREV_KC), a
cp 0x80 cp 0x80
jr nc, .outOfBounds jr nc, .outOfBounds
; No need to skip, code within bounds, we have something! Let's see if ; No need to skip, code within bounds, we have something! Let's see if
; there's a ASCII code associated to it. ; there's a ASCII code associated to it.
push hl ; <| push hl ; --> lvl 1
ld hl, kbdScanCodes ; | ld hl, kbdScanCodes
call addHL ; | call addHL
ld a, (hl) ; | ld a, (hl)
pop hl ; <| pop hl ; <-- lvl 1
or a or a
jp z, unsetZ ; no code. Keep A at 0, but unset Z jp z, unsetZ ; no code. Keep A at 0, but unset Z
; We have something! ; We have something!
@ -47,21 +59,11 @@ kbdGetC:
ret ret
.outOfBounds: .outOfBounds:
; A scan code over 0x80 is out of bounds. Ignore. ; A scan code over 0x80 is out of bounds. Ignore.
; If F0 (break code) or E0 (extended code), we also skip the next code
cp 0xf0
jr z, .skipNext
cp 0xe0
jr z, .skipNext
xor a
jp unsetZ
.skipNext:
ld (KBD_SKIP_NEXT), a
xor a xor a
jp unsetZ jp unsetZ
.skip: .skip:
pop af ; equilibrate stack
xor a xor a
ld (KBD_SKIP_NEXT), a ld (KBD_PREV_KC), a
jp unsetZ jp unsetZ
.nothing: .nothing:
; We have nothing. Before we go further, we'll wait a bit to give our ; We have nothing. Before we go further, we'll wait a bit to give our