]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/kscnkey.s
Combine the existing include files, move zp space out of crt0.s
[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         k_scnkey
8         .importzp       tpi2, ktab1, ktab2, ktab3, ktab4
9
10         .include        "cbm510.inc"
11
12
13 .proc   k_scnkey
14
15         lda     #$FF
16         sta     ModKey
17         sta     NorKey
18         lda     #$00
19         sta     KbdScanBuf
20         ldy     #tpiPortB
21         sta     (tpi2),y
22         ldy     #tpiPortA
23         sta     (tpi2),y
24         jsr     Poll
25         and     #$3F
26         eor     #$3F
27         bne     L1
28         jmp     NoKey
29
30 L1:     lda     #$FF
31         ldy     #tpiPortA
32         sta     (tpi2),y
33         asl     a
34         ldy     #tpiPortB
35         sta     (tpi2),y
36         jsr     Poll
37         pha
38         sta     ModKey
39         ora     #$30
40         bne     L3              ; Branch always
41
42 L2:     jsr     Poll
43 L3:     ldx     #$05
44         ldy     #$00
45 L4:     lsr     a
46         bcc     L5
47         inc     KbdScanBuf
48         dex
49         bpl     L4
50         sec
51         ldy     #tpiPortB
52         lda     (tpi2),y
53         rol     a
54         sta     (tpi2),y
55         ldy     #tpiPortA
56         lda     (tpi2),y
57         rol     a
58         sta     (tpi2),y
59         bcs     L2
60         pla
61         bcc     NoKey           ; Branch always
62
63 L5:     ldy     KbdScanBuf
64         sty     NorKey
65         pla
66         asl     a
67         asl     a
68         asl     a
69         bcc     L6
70         bmi     L7
71         lda     (ktab2),y               ; Shifted normal key
72         ldx     GrafMode
73         beq     L8
74         lda     (ktab3),y               ; Shifted key in graph mode
75         bne     L8
76
77 L6:     lda     (ktab4),y               ; Key with ctrl pressed
78         bne     L8
79 L7:     lda     (ktab1),y               ; Normal key
80 L8:     tax
81         cpx     #$FF                    ; Valid key?
82         beq     Done
83         cpy     LastIndex
84         beq     Repeat
85         ldx     #$13
86         stx     RepeatDelay
87         ldx     KeyIndex
88         cpx     #$09
89         beq     NoKey
90         cpy     #$59
91         bne     PutKey
92         cpx     #$08
93         beq     NoKey
94         sta     KeyBuf,x
95         inx
96         bne     PutKey
97
98 NoKey:  ldy     #$FF
99 Done:   sty     LastIndex
100 End:    lda     #$7F
101         ldy     #tpiPortA
102         sta     (tpi2),y
103         ldy     #tpiPortB
104         lda     #$FF
105         sta     (tpi2),y
106         rts
107
108 Repeat: dec     RepeatDelay
109         bpl     End
110         inc     RepeatDelay
111         dec     RepeatCount
112         bpl     End
113         inc     RepeatCount
114         ldx     KeyIndex
115         bne     End
116
117 PutKey: sta     KeyBuf,x
118         inx
119         stx     KeyIndex
120         ldx     #$03
121         stx     RepeatCount
122         bne     Done
123
124 .endproc
125
126
127 ; Poll the keyboard port until it's stable
128
129 .proc   Poll
130         ldy     #tpiPortC
131 L1:     lda     (tpi2),y
132         sta     KeySave
133         lda     (tpi2),y
134         cmp     KeySave
135         bne     L1
136         rts
137 .endproc
138
139
140 .bss
141
142 KeySave:        .res    1
143
144