]> git.sur5r.net Git - cc65/blob - libsrc/lynx/cgetc.s
Fixed _textcolor definition.
[cc65] / libsrc / lynx / cgetc.s
1 ;
2 ; Karri Kaksonen, Harry Dodgson 2006-01-07
3 ;
4 ; char cgetc (void);
5 ;
6
7         .export         _cgetc
8         .import         _kbhit
9         .import         KBEDG
10         .import         KBSTL
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 _cgetc:
23         lda     KBSTL
24         ora     KBEDG
25         bne     @L1
26         jsr     _kbhit          ; Check for char available
27         tax                             ; Test result
28         bra     _cgetc
29 @L1:
30         ldx     #0
31         and     #1
32         beq     @L6
33         lda     KBEDG           ; Pause button is pressed
34         and     #$0c
35         beq     @L3
36         ora     KBSTL
37 @L2:
38         bit     #$04
39         beq     @L4                     ; Pause + Opt 1 = Reset
40         bit     #$08
41         beq     @L5                     ; Pause + Opt 2 = Flip
42         lda     #'?'                    ; All buttons pressed
43         rts
44 @L3:
45         lda     KBSTL           ; Pause alone was the last placed button
46         and     #$0c
47         bne     @L2
48         lda     #'P'                    ; Pause pressed
49         rts
50 @L4:
51         lda     #'R'                    ; Reset pressed
52         rts
53 @L5:
54         lda     #'F'                    ; Flip pressed
55         rts
56 @L6:
57         lda     KBEDG           ; No Pause pressed
58         ora     KBSTL
59         bit     #$08
60         beq     @L8
61         bit     #$04
62         beq     @L7
63         lda     #'3'                    ; opt 1 + opt 2 pressed
64         rts
65 @L7:
66         lda     #'1'                    ; opt 1 pressed
67         rts
68 @L8:
69         lda     #'2'                    ; opt 2 pressed
70         rts