]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/kscnkey.s
d29845d026cba1383713a4b879668db3b18edb40
[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        "zeropage.inc"
11         .include        "io.inc"
12         .include        "page3.inc"
13
14
15 .proc   k_scnkey
16
17         lda     #$FF
18         sta     ModKey
19         sta     NorKey
20         lda     #$00
21         sta     KbdScanBuf
22         ldy     #tpiPortB
23         sta     (tpi2),y
24         ldy     #tpiPortA
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     #tpiPortA
34         sta     (tpi2),y
35         asl     a
36         ldy     #tpiPortB
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     KbdScanBuf
50         dex
51         bpl     L4
52         sec
53         ldy     #tpiPortB
54         lda     (tpi2),y
55         rol     a
56         sta     (tpi2),y
57         ldy     #tpiPortA
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     KbdScanBuf
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     GrafMode
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     LastIndex
86         beq     Repeat
87         ldx     #$13
88         stx     RepeatDelay
89         ldx     KeyIndex
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     LastIndex
102 End:    lda     #$7F
103         ldy     #tpiPortA
104         sta     (tpi2),y
105         ldy     #tpiPortB
106         lda     #$FF
107         sta     (tpi2),y
108         rts
109
110 Repeat: dec     RepeatDelay
111         bpl     End
112         inc     RepeatDelay
113         dec     RepeatCount
114         bpl     End
115         inc     RepeatCount
116         ldx     KeyIndex
117         bne     End
118
119 PutKey: sta     KeyBuf,x
120         inx
121         stx     KeyIndex
122         ldx     #$03
123         stx     RepeatCount
124         bne     Done
125
126 .endproc
127
128
129 ; Poll the keyboard port until it's stable
130
131 .proc   Poll
132         ldy     #tpiPortC
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 .bss
143
144 KeySave:        .res    1
145
146