1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-15 17:30:06 +00:00
cc65/libsrc/osic1p/kbhit.s
Stephan Mühlstrasser 222668c016 Implemented a one-character buffer for kbhit() and cgetc().
If kbhit() detects that a key is pressed, it fetches and
buffers the character. If cgetc() detects a buffered character,
this one is returned instead of fetching one with the PROM
routine.
2015-02-21 20:24:58 +01:00

32 lines
1.1 KiB
ArmAsm

;
; unsigned char kbhit (void);
;
.export _kbhit
.include "osic1p.inc"
_kbhit:
lda #%11111110 ; Select first keyboard row
scan:
sta KBD ; Select keyboard row
tax ; Save A
lda KBD ; Read keyboard columns
ora #$01 ; Mask out lsb (Shift Lock), since we ignore it
cmp #$FF ; No keys pressed?
bne keypressed
txa ; Restore A
sec ; Want to shift in ones
rol a ; Rotate row select to next bit position
cmp #$FF ; Done?
bne scan ; If not, continue
lda #$00 ; Return false
tax ; High byte of return is also zero
sta CHARBUF ; No character in buffer
rts
keypressed:
jsr INPUTC ; Get input character in A
sta CHARBUF ; Save in buffer
ldx #$00 ; High byte of return is always zero
lda #$01 ; Return true
rts