]> git.sur5r.net Git - cc65/blob - libsrc/lynx/kbhit.s
Adjusted C declarations to the changed static driver names.
[cc65] / libsrc / lynx / kbhit.s
1 ;
2 ; Karri Kaksonen, Harry Dodgson 2006-01-06
3 ;
4 ; unsigned char kbhit (void);
5 ;
6
7         .export         _kbhit
8         .export         KBEDG
9         .export         KBSTL
10         .import         return1
11
12 ; --------------------------------------------------------------------------
13 ; The Atari Lynx has a very small keyboard - only 3 keys
14 ; Opt1, Opt2 and Pause.
15 ; But the designers have decided that pressing Pause and Opt1 at the
16 ; same time means Restart and pressing Pause and Opt2 means Flip screen.
17
18 ; For "easter egg" use I have also included all three keys pressed '?'
19 ; and Opt1 + Opt2 pressed '3'.
20 ; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
21
22         .data
23 KBTMP:          .byte   0
24 KBPRV:          .byte   0
25 KBEDG:          .byte   0
26 KBSTL:          .byte   0
27 KBDEB:          .byte   0
28 KBNPR:          .byte   0
29
30         .code
31 _kbhit:
32         lda     $FCB0           ; Read the Opt buttons
33         and     #$0c
34         sta     KBTMP
35         lda     $FCB1           ; Read Pause
36         and     #1
37         ora     KBTMP           ; 0000210P
38         tax
39         and     KBPRV
40         sta     KBSTL           ; for multibutton
41         txa
42         and     KBDEB
43         sta     KBEDG           ; for just depressed
44         txa
45         and     KBNPR
46         sta     KBDEB           ; for debouncing
47         txa
48         eor     #$ff
49         sta     KBNPR           ; inverted previous ones pressed
50         stx     KBPRV
51         lda     KBEDG
52         beq     @L1
53         jmp     return1         ; Key hit
54
55 @L1:    tax                     ; No new keys hit
56         rts