0
|
1 ********************************************************************
|
|
2 * KeyDrv - Keyboard Driver for CoCo 3
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Ed. Comments Who YY/MM/DD
|
|
7 * ------------------------------------------------------------------
|
|
8 * 4 L2 Upgrade distribution version
|
|
9 * Annotations by Robert Gault RG 98/10/10
|
|
10
|
|
11 nam KeyDrv
|
|
12 ttl Keyboard Driver for CoCo 3
|
|
13
|
|
14 * Disassembled 98/09/09 09:02:10 by Disasm v1.6 (C) 1988 by RML
|
|
15
|
|
16 ifp1
|
|
17 use defsfile
|
|
18 endc
|
|
19
|
|
20 tylg set Systm+Objct
|
|
21 atrv set ReEnt+rev
|
|
22 rev set $01
|
|
23 edition equ 4
|
|
24
|
|
25 mod eom,name,tylg,atrv,start,size
|
|
26 size equ .
|
|
27
|
|
28 name fcs /KeyDrv/
|
|
29 fcb edition
|
|
30
|
|
31 start lbra Init init/term; CLRB RTS
|
|
32 lbra Term
|
|
33 lbra FuncKeys test for keys F1, F2
|
|
34
|
|
35 ReadKys ldu <D.CCMem CC3IO global memory $1000
|
|
36 ldx #PIA0Base base address of PIA#1
|
|
37 clrb
|
|
38 comb
|
|
39 stb $02,x clear all strobe lines
|
|
40 ldb ,x read PIA#1
|
|
41 comb bit values 0=off 1=on
|
|
42 andb #%00001111 keep only buttons
|
|
43 bne L0059 branch if button pushed; error routine
|
|
44 clr $02,x enable all strobe lines
|
|
45 lda ,x read PIA#1
|
|
46 coma
|
|
47 anda #%01111111 mask only the joystick conparator
|
|
48 beq L0042 branch if no keys pressed
|
|
49 pshs dp
|
|
50 tfr u,d
|
|
51 tfr a,dp set DP to the address in regU
|
|
52 bsr L005C evaluate the found key matrix
|
|
53 puls dp return to system DP
|
|
54 bpl L005B valid key
|
|
55 L0042 clra regA would have been the found key
|
|
56 ldb <G.CapLok,u CapsLock/SysRq key down flag
|
|
57 bne L0056
|
|
58 clr <G.KTblLC,u Key table entry# last checked (1-3)
|
|
59 coma
|
|
60 comb
|
|
61 sta <G.LKeyCd,u last keyboard code
|
|
62 sta <G.2Key1,u 2nd key table storage; $FF=none
|
|
63 std <G.2Key2,u format (Row/Column)
|
|
64 L0056 clr <G.CapLok,u see above
|
|
65 L0059 ldb #$FF
|
|
66 L005B rts
|
|
67
|
|
68 L005C ldx #PIA0Base base value of PIA#1
|
|
69 clra
|
|
70 clrb
|
|
71 std <G.ShftDn shift/CTRL flag; 0=NO $FF=YES
|
|
72 std <G.KeyFlg PIA bits/ALT flag
|
|
73 * %00000111-Column # (Output, 0-7)
|
|
74 * %00111000-Row # (Input, 0-6)
|
|
75 coma
|
|
76 comb set primary key table
|
|
77 std <G.Key1 key 1&2 flags $FF=none
|
|
78 sta <G.Key3 key 3 ²
|
|
79 deca ie. lda #%11111110
|
|
80 sta $02,x strobe one column
|
|
81 L006E lda ,x read PIA#1
|
|
82 coma
|
|
83 anda #$7F keep only keys, bit 0=off 1=on
|
|
84 beq L0082
|
|
85 ldb #$FF preset counter to -1
|
|
86 L0077 incb
|
|
87 lsra bit test regA
|
|
88 bcc L007E no key so branch
|
|
89 lbsr L010E convert column/row to matrix value and store it
|
|
90 L007E cmpb #$06 max counter
|
|
91 bcs L0077 loop if more bits to test
|
|
92 L0082 inc <G.KeyFlg counter; used here for column
|
|
93 orcc #Carry bit marker; disable strobe
|
|
94 rol $02,x shift to next column
|
|
95 bcs L006E not finished with columns so loop
|
|
96 lbsr L0166 simultaneous check; recover key matrix value
|
|
97 bmi L00F5 invalid so go
|
|
98 cmpa <G.LKeyCd last keyboard code
|
|
99 bne L0095
|
|
100 inc <G.KySame same key flag ?counter?
|
|
101 L0095 sta <G.LKeyCd setup for last key pressed
|
|
102 beq L00B5
|
|
103 suba #$1A the key value (matrix) of Z
|
|
104 bhi L00B5 not a letter so go
|
|
105 adda #$1A restore regA
|
|
106 ldb <G.CntlDn CTRL flag
|
|
107 bne L00E0 CTRL is down so go
|
|
108 adda #$40 convert to ASCII value; all caps
|
|
109 ldb <G.ShftDn shift key flag
|
|
110 ldy <G.CurDev get current device static memory pointer
|
|
111 eorb <$21,y caps lock and keyboard mouse flags
|
|
112 andb #$01 test caps flag
|
|
113 bne L00E0 not shifted so go
|
|
114 adda #$20 convert to ASCII lower case
|
|
115 bra L00E0
|
|
116 * key is not a letter; this routine is not based on some underlining principle of
|
|
117 * the keyboard hardware. It is also a function of the decode table at $1DC,pcr.
|
|
118 L00B5 ldb #$03
|
|
119 mul regB = (key#-26) times 3
|
|
120 lda <G.ShftDn shift key flag
|
|
121 beq L00BF not shifted so go
|
|
122 incb
|
|
123 bra L00C5
|
|
124 L00BF lda <G.CntlDn CTRL flag
|
|
125 beq L00C5
|
|
126 addb #$02
|
|
127 L00C5 ldx <G.CurDev point regX to device’s static memory
|
|
128 lda <$22,x key sense flag
|
|
129 beq L00D0 not set so go
|
|
130 cmpb #$11 spacebar
|
|
131 ble L00F3 must be an arrow so go
|
|
132 L00D0 cmpb #$4C SHIFTed ALT key
|
|
133 blt L00D8 not ALT, CTRL, F1, F2, or SHIFT so go
|
|
134 inc <G.AltDwn flag special keys (ALT,CTRL)
|
|
135 subb #$06
|
|
136 L00D8 leax >L01DC,pcr decode table
|
|
137 lda b,x
|
|
138 bmi L00F6 if regA = $81 - $84
|
|
139 * several entries to this routine from any key press; regA is already ASCII
|
|
140 L00E0 ldb <G.AltDwn was ALT flagged?
|
|
141 beq L00F0 no so go
|
|
142 cmpa #$3F ?
|
|
143 bls L00EE # or code
|
|
144 cmpa #$5B [
|
|
145 bcc L00EE capital letter so go
|
|
146 ora #$20 convert to lower case
|
|
147 L00EE ora #$80 set for ALT characters
|
|
148 L00F0 andcc #^Negative not negative
|
|
149 rts
|
|
150 L00F3 orcc #Negative set negative
|
|
151 L00F5 rts
|
|
152 L00F6 inc <G.CapLok caps lock/SysRq
|
|
153 inc <G.Clear one shot caps lock/SysRq
|
|
154 bra L00F0
|
|
155 L00FC pshs b,a convert column into power of 2
|
|
156 clrb
|
|
157 orcc #Carry
|
|
158 inca
|
|
159 L0102 rolb
|
|
160 deca
|
|
161 bne L0102
|
|
162 bra L0108 WHY IS THIS HERE??
|
|
163 L0108 orb <G.KySns previous value of column
|
|
164 stb <G.KySns
|
|
165 puls pc,b,a
|
|
166 L010E pshs b,a
|
|
167 cmpb #$03 is it row 3?
|
|
168 bne L011C
|
|
169 lda <G.KeyFlg get column #
|
|
170 cmpa #$03 is it column 3?; ie up arrow
|
|
171 blt L011C if lt must be a letter
|
|
172 bsr L00FC its a non letter so bsr
|
|
173 L011C lslb B*8 8 keys per row
|
|
174 lslb
|
|
175 lslb
|
|
176 addb <G.KeyFlg add in the column #
|
|
177 cmpb #$33 ALT
|
|
178 bne L012B
|
|
179 inc <G.AltDwn ALT down flag
|
|
180 ldb #$04
|
|
181 bra L0108
|
|
182 L012B cmpb #$34 CTRL
|
|
183 bne L0135
|
|
184 inc <G.CntlDn CTRL down flag
|
|
185 ldb #$02
|
|
186 bra L0108
|
|
187 L0135 cmpb #$37 shift key
|
|
188 bne L013F
|
|
189 com <G.ShftDn shift down flag
|
|
190 ldb #$01
|
|
191 bra L0108
|
|
192 * check how many key (1-3) are currently being pressed
|
|
193 L013F pshs x
|
|
194 leax <$2D,u 1st key table
|
|
195 bsr L014A
|
|
196 puls x
|
|
197 puls pc,b,a
|
|
198 L014A pshs a
|
|
199 lda ,x
|
|
200 bpl L0156
|
|
201 stb ,x
|
|
202 ldb #$01
|
|
203 puls pc,a
|
|
204 L0156 lda $01,x
|
|
205 bpl L0160
|
|
206 stb $01,x
|
|
207 ldb #$02
|
|
208 puls pc,a
|
|
209 L0160 stb $02,x
|
|
210 ldb #$03
|
|
211 puls pc,a
|
|
212 * simlutaneous key test
|
|
213 L0166 pshs y,x,b
|
|
214 ldb <G.KTblLC key table entry#
|
|
215 beq L019D
|
|
216 leax <$2A,u point to 2nd key table
|
|
217 pshs b
|
|
218 L0171 leay <$2D,u 1st key table
|
|
219 ldb #$03
|
|
220 lda ,x get key#1
|
|
221 bmi L018F go if invalid? (no key)
|
|
222 L017A cmpa ,y is it a match?
|
|
223 bne L0184 go if not a matched key
|
|
224 clr ,y
|
|
225 com ,y set value to $FF
|
|
226 bra L018F
|
|
227 L0184 leay $01,y
|
|
228 decb
|
|
229 bne L017A
|
|
230 lda #$FF
|
|
231 sta ,x
|
|
232 dec <G.KTblLC key table entry#
|
|
233 L018F leax $01,x
|
|
234 dec ,s column counter
|
|
235 bne L0171
|
|
236 leas $01,s
|
|
237 ldb <G.KTblLC key table entry (can test for 3 simul keys)
|
|
238 beq L019D
|
|
239 bsr L01C4
|
|
240 L019D leax <$2D,u 1st key table
|
|
241 lda #$03
|
|
242 L01A2 ldb ,x+
|
|
243 bpl L01B5
|
|
244 deca
|
|
245 bne L01A2
|
|
246 ldb <G.KTblLc key table entry (can test for 3 simul keys)
|
|
247 beq L01C0
|
|
248 decb
|
|
249 leax <$2A,u 2nd key table
|
|
250 lda b,x
|
|
251 bra L01BE
|
|
252 L01B5 tfr b,a
|
|
253 leax <$2A,u 2nd key table
|
|
254 bsr L014A
|
|
255 stb <G.KTblLC
|
|
256 L01BE puls pc,y,x,b
|
|
257 L01C0 orcc #Negative flag negative
|
|
258 puls pc,y,x,b
|
|
259 L01C4 leax <$2A,u
|
|
260 bsr L01CF
|
|
261 leax $01,x
|
|
262 bsr L01CF
|
|
263 leax -$01,x
|
|
264 L01CF lda ,x
|
|
265 bpl L01DB
|
|
266 ldb $01,x
|
|
267 bmi L01DB
|
|
268 sta $01,x
|
|
269 stb ,x
|
|
270 L01DB rts
|
|
271 * These seem to be special key combination values; 3 per key in ASCII
|
|
272 *L01DC fcb @,shift@,nul
|
|
273 * fcb up,shifted,CTRL
|
|
274 * fcb down, shifted, CTRLed
|
|
275 * fcb left, shifted, CTRLed
|
|
276 * fcb right, shifted, CTRLed
|
|
277 * fcb spacebar, spacebar, spacebar
|
|
278 * fcb ’0,’0,$81 signal shiftlock change
|
|
279 * fcb ’1,’!,’|
|
|
280 * fcb ’2,’”,null
|
|
281 * fcb ’3,’#,’~
|
|
282 * fcb ’4,’$,null
|
|
283 * fcb ’5,’%,null
|
|
284 * fcb ’6,’&,null
|
|
285 * fcb ’7,’’,’^
|
|
286 * fcb ’8,’(,’[
|
|
287 * fcb ’9,’),’]
|
|
288 * fcb ’:,’*,null
|
|
289 * fcb ’;,’+,DEL
|
|
290 * fcb ’,,’<,’{
|
|
291 * fcb ’-,’=,’_
|
|
292 * fcb ’.,’>,’}
|
|
293 * fcb ’/,’?,’\
|
|
294 * fcb ENTER,ENTER,ENTER
|
|
295 * I think these are for ALT
|
|
296 * fcb $82,$83,$84
|
|
297 * fcb ENQ,BREAK,ESC
|
|
298 * the next I think are for the F1 and F2 keys
|
|
299 * fcb ’1,’3,’5
|
|
300 * fcb ’2,’4,’6
|
|
301 L01DC fdb $4060,$000c,$1c13,$0a1a,$1208,$1810,$0919,$1120
|
|
302 fdb $2020,$3030,$8131,$217c,$3222,$0033,$237e,$3424
|
|
303 fdb $0035,$2500,$3626,$0037,$275e,$3828,$5b39,$295d
|
|
304 fdb $3a2a,$003b,$2b7f,$2c3c,$7b2d,$3d5f,$2e3e,$7d2f
|
|
305 fdb $3f5c,$0d0d,$0d82,$8384,$0503,$1b31,$3335,$3234
|
|
306 fcb $36
|
|
307
|
|
308 Init
|
|
309 Term clrb
|
|
310 rts
|
|
311
|
|
312 FuncKeys ldu <D.CCMem
|
|
313 ldx #PIA0Base
|
|
314 clra
|
|
315 ldb #%11011111 strob column #6 PIA#1
|
|
316 stb $02,x
|
|
317 ldb ,x read PIA#1
|
|
318 bitb #%01000000 test for F1 function key
|
|
319 bne L0240
|
|
320 inca flag F1
|
|
321 L0240 ldb #%10111111 strobe column #7 PIA#1
|
|
322 stb $02,x
|
|
323 ldb ,x read PIA#1
|
|
324 bitb #%01000000 test for F2 function key
|
|
325 bne L024C
|
|
326 ora #$04 flag F2
|
|
327 L024C rts
|
|
328
|
|
329 emod
|
|
330 eom equ *
|
|
331 end
|
|
332
|
|
333
|