]> git.sur5r.net Git - cc65/blob - libsrc/osic1p/kbhit.s
c064fec476c6f73eb79d3baf3cf88b4621aa8a32
[cc65] / libsrc / osic1p / kbhit.s
1 ;
2 ; unsigned char kbhit (void);
3 ;
4
5         .export _kbhit
6         .include "osic1p.inc"
7
8 _kbhit:
9         lda     #%11111110      ; Select first keyboard row
10 scan:
11         sta     KBD             ; Select keyboard row
12         tax                     ; Save A
13         lda     KBD             ; Read keyboard columns
14         ora     #$01            ; Mask out lsb (Shift Lock), since we ignore it
15         cmp     #$FF            ; No keys pressed?
16         bne     keypressed
17         txa                     ; Restore A
18         sec                     ; Want to shift in ones
19         rol     a               ; Rotate row select to next bit position
20         cmp     #$FF            ; Done?
21         bne     scan            ; If not, continue
22         ldx     #$00            ; High byte of return is always zero
23         lda     #$00            ; Return false
24         rts
25 keypressed:
26         ldx     #$00            ; High byte of return is always zero
27         lda     #$01            ; Return true
28         rts