]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/kscnkey.s
Minor style fix.
[cc65] / libsrc / cbm510 / kscnkey.s
1 ;
2 ; Ullrich von Bassewitz, 13.09.2001
3 ;
4 ; Keyboard polling stuff for the 510.
5 ;
6
7         .export         scnkey
8         .importzp       tpi2, ktab1, ktab2, ktab3, ktab4
9         .importzp       keyidx, keybuf, keyscanbuf, keysave, modkey, norkey
10         .importzp       graphmode, lastidx, rptdelay, rptcount
11
12         .include        "cbm510.inc"
13
14
15 .proc   scnkey
16
17         lda     #$FF
18         sta     modkey
19         sta     norkey
20         lda     #$00
21         sta     keyscanbuf
22         ldy     #TPI::PRB
23         sta     (tpi2),y
24         ldy     #TPI::PRA
25         sta     (tpi2),y
26         jsr     Poll
27         and     #$3F
28         eor     #$3F
29         bne     L1
30         jmp     NoKey
31
32 L1:     lda     #$FF
33         ldy     #TPI::PRA
34         sta     (tpi2),y
35         asl     a
36         ldy     #TPI::PRB
37         sta     (tpi2),y
38         jsr     Poll
39         pha
40         sta     modkey
41         ora     #$30
42         bne     L3              ; Branch always
43
44 L2:     jsr     Poll
45 L3:     ldx     #$05
46         ldy     #$00
47 L4:     lsr     a
48         bcc     L5
49         inc     keyscanbuf
50         dex
51         bpl     L4
52         sec
53         ldy     #TPI::PRB
54         lda     (tpi2),y
55         rol     a
56         sta     (tpi2),y
57         ldy     #TPI::PRA
58         lda     (tpi2),y
59         rol     a
60         sta     (tpi2),y
61         bcs     L2
62         pla
63         bcc     NoKey           ; Branch always
64
65 L5:     ldy     keyscanbuf
66         sty     norkey
67         pla
68         asl     a
69         asl     a
70         asl     a
71         bcc     L6
72         bmi     L7
73         lda     (ktab2),y               ; Shifted normal key
74         ldx     graphmode
75         beq     L8
76         lda     (ktab3),y               ; Shifted key in graph mode
77         bne     L8
78
79 L6:     lda     (ktab4),y               ; Key with ctrl pressed
80         bne     L8
81 L7:     lda     (ktab1),y               ; Normal key
82 L8:     tax
83         cpx     #$FF                    ; Valid key?
84         beq     Done
85         cpy     lastidx
86         beq     Repeat
87         ldx     #$13
88         stx     rptdelay
89         ldx     keyidx
90         cpx     #$09
91         beq     NoKey
92         cpy     #$59
93         bne     PutKey
94         cpx     #$08
95         beq     NoKey
96         sta     keybuf,x
97         inx
98         bne     PutKey
99
100 NoKey:  ldy     #$FF
101 Done:   sty     lastidx
102 End:    lda     #$7F
103         ldy     #TPI::PRA
104         sta     (tpi2),y
105         ldy     #TPI::PRB
106         lda     #$FF
107         sta     (tpi2),y
108         rts
109
110 Repeat: dec     rptdelay
111         bpl     End
112         inc     rptdelay
113         dec     rptcount
114         bpl     End
115         inc     rptcount
116         ldx     keyidx
117         bne     End
118
119 PutKey: sta     keybuf,x
120         inx
121         stx     keyidx
122         ldx     #$03
123         stx     rptcount
124         bne     Done
125
126 .endproc
127
128
129 ; Poll the keyboard port until it's stable
130
131 .proc   Poll
132         ldy     #TPI::PRC
133 L1:     lda     (tpi2),y
134         sta     keysave
135         lda     (tpi2),y
136         cmp     keysave
137         bne     L1
138         rts
139 .endproc
140
141
142
143