]> git.sur5r.net Git - cc65/blob - libsrc/osic1p/kbhit.s
Added SER_ prefix. Whitespace cleanup
[cc65] / libsrc / osic1p / kbhit.s
1 ;
2 ; unsigned char kbhit (void);
3 ;
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
6 ; Reference Manual"
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.
11 ;
12
13         .export _kbhit
14         .include "osic1p.inc"
15         .include "extzp.inc"
16         .include "zeropage.inc"
17
18 _kbhit:
19         lda     #%11011111      ; Mask for only checking the column for the
20         sta     tmp1            ; ESC key in the first keyboard row.
21
22         lda     #%11111110      ; Mask for first keyboard row
23 scan:
24         sta     KBD             ; Select keyboard row
25         tax                     ; Save A
26         lda     KBD             ; Read keyboard columns
27         ora     tmp1            ; Mask out uninteresting keys (only relevant in
28                                 ; first row)
29         cmp     #$FF            ; No keys pressed?
30         bne     keypressed
31         lda     #$00            ; For remaining rows no keys masked
32         sta     tmp1
33         txa                     ; Restore A
34         sec                     ; Want to shift in ones
35         rol     a               ; Rotate row select to next bit position
36         cmp     #$FF            ; Done?
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
41         rts
42 keypressed:
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
47         rts