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