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