1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 22:08:05 +11:00

ti/kbd: improve debouncing

Previously, on real hardware (emulator behaved fine), we would routinely
get repeat keys unless pressing the button very fast. This commit solves that.
This commit is contained in:
Virgil Dupras 2019-11-09 13:22:01 -05:00
parent 418af5f626
commit 9c37471780

View File

@ -126,13 +126,20 @@ kbdGetC:
ret ret
.debounce: .debounce:
; wait until all keys are de-pressed ; wait until all keys are de-pressed
; To avoid repeat keys, we require 64 subsequent polls to indicate all
; depressed keys
push af ; --> lvl 1 push af ; --> lvl 1
push bc ; --> lvl 2
.pressed:
ld b, 64
.wait: .wait:
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, .wait ; non-zero? something is pressed jr nz, .pressed ; non-zero? something is pressed
djnz .wait
pop bc ; <-- lvl 2
pop af ; <-- lvl 1 pop af ; <-- lvl 1
ret ret