2 ; unsigned char kbhit (void);
4 ; The method to detect a pressed key is based on the documentation in
5 ; "Section 3 Programmed Key Functions" in "The Challenger Character Graphics
7 ; We only want to return true for characters that can be returned by cgetc(),
8 ; but not for keys like <Shift> or <Ctrl>. Therefore a special handling is
9 ; needed for the first row. This is implemented by a bit mask that is stored
10 ; in tmp1 and that is set to zero after the first round.
16 .include "zeropage.inc"
19 lda #%11011111 ; Mask for only checking the column for the
20 sta tmp1 ; ESC key in the first keyboard row.
22 lda #%11111110 ; Mask for first keyboard row
24 sta KBD ; Select keyboard row
26 lda KBD ; Read keyboard columns
27 ora tmp1 ; Mask out uninteresting keys (only relevant in
29 cmp #$FF ; No keys pressed?
31 lda #$00 ; For remaining rows no keys masked
34 sec ; Want to shift in ones
35 rol a ; Rotate row select to next bit position
37 bne scan ; If not, continue
38 lda #$00 ; Return false
39 tax ; High byte of return is also zero
40 sta CHARBUF ; No character in buffer
43 jsr INPUTC ; Get input character in A
44 sta CHARBUF ; Save in buffer
45 ldx #$00 ; High byte of return is always zero
46 lda #$01 ; Return true