Rev 291 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
261 | ddp | 1 | .EQU KEY_ESC =$76 |
2 | .EQU KEY_ENTER =$5A |
||
3 | .EQU KEY_UP =$75 |
||
4 | .EQU KEY_DOWN =$72 |
||
5 | .EQU KEY_LEFT =$6B |
||
6 | .EQU KEY_RIGHT =$74 |
||
7 | .EQU KEY_PAGEUP =$7D |
||
8 | .EQU KEY_PAGEDOWN =$7A |
||
9 | .EQU KEY_HOME =$6C |
||
10 | .EQU KEY_END =$69 |
||
352 | ddp | 11 | .EQU KEY_SPACE =$29 |
261 | ddp | 12 | .EQU KEY_F1 =$05 |
13 | .EQU KEY_NUMLOCK =$77 |
||
14 | .EQU KEY_CAPSLOCK =$58 |
||
15 | .EQU KEY_SCROLLLOCK =$7E |
||
16 | .EQU KEY_Y =$35 |
||
17 | |||
18 | .EQU PS2K_BIT_PARITY =0 |
||
19 | .EQU PS2K_BIT_EXTKEY =1 ; ���.��� |
||
20 | .EQU PS2K_BIT_RELEASE=2 ; ���᪠��� |
||
290 | ddp | 21 | .EQU PS2K_BIT_ACKBIT =3 ; ����砭�� ��।�� |
261 | ddp | 22 | .EQU PS2K_BIT_TX =7 ; ��।�� |
23 | .EQU PS2K_BIT_READY =7 |
||
24 | |||
25 | .MACRO PS2K_DATALINE_UP |
||
26 | CBI DDRD,6 |
||
27 | SBI PORTD,6 |
||
28 | .ENDMACRO |
||
29 | |||
30 | .MACRO PS2K_DATALINE_DOWN |
||
31 | CBI PORTD,6 |
||
32 | SBI DDRD,6 |
||
33 | .ENDMACRO |
||
34 | |||
35 | .MACRO PS2K_CLOCKLINE_UP |
||
36 | CBI DDRE,4 |
||
37 | SBI PORTE,4 |
||
38 | .ENDMACRO |
||
39 | |||
40 | .MACRO PS2K_CLOCKLINE_DOWN |
||
41 | CBI PORTE,4 |
||
42 | SBI DDRE,4 |
||
43 | .ENDMACRO |
||
44 | ; |
||
45 | ;-------------------------------------- |
||
46 | ; |
||
47 | .DSEG |
||
48 | PS2K_BIT_COUNT: .BYTE 1 |
||
49 | PS2K_DATA: .BYTE 1 |
||
50 | PS2K_RAW_READY: .BYTE 1 |
||
51 | PS2K_RAW_CODE: .BYTE 1 |
||
52 | PS2K_SKIP: .BYTE 1 |
||
53 | PS2K_FLAGS: .BYTE 1 |
||
54 | PS2K_KEY_FLAGS: .BYTE 1 |
||
55 | PS2K_KEY_CODE: .BYTE 1 |
||
56 | PS2K_TIMEOUT: .BYTE 2 |
||
57 | .CSEG |
||
58 | ; |
||
59 | ;-------------------------------------- |
||
60 | ; |
||
61 | PS2K_INIT: |
||
62 | |||
63 | IN TEMP,EICRB |
||
64 | ORI TEMP,(1<<ISC41)|(0<<ISC40) |
||
65 | OUT EICRB,TEMP |
||
66 | IN TEMP,EIMSK |
||
67 | ORI TEMP,(1<<INT4) |
||
68 | OUT EIMSK,TEMP |
||
69 | |||
70 | LDI TEMP,(0<<CS02)|(1<<CS01)|(0<<CS00) ; clk/8 |
||
71 | OUT TCCR0,TEMP |
||
72 | |||
73 | STS PS2K_FLAGS,NULL |
||
74 | STS PS2K_BIT_COUNT,NULL |
||
75 | STS PS2K_SKIP,NULL |
||
76 | STS PS2K_KEY_FLAGS,NULL |
||
77 | |||
78 | RET |
||
79 | ; |
||
80 | ;-------------------------------------- |
||
81 | ; |
||
82 | TIM0_OVF: |
||
83 | PS2K_DATALINE_UP |
||
84 | PUSH TEMP |
||
85 | IN TEMP,SREG |
||
86 | PUSH TEMP |
||
87 | IN TEMP,TIMSK |
||
88 | CBR TEMP,(1<<TOIE0) |
||
89 | OUT TIMSK,TEMP |
||
90 | POP TEMP |
||
91 | OUT SREG,TEMP |
||
92 | POP TEMP |
||
93 | PS2K_CLOCKLINE_UP |
||
94 | RETI |
||
95 | ; |
||
96 | ;-------------------------------------- |
||
97 | ; |
||
98 | EXT_INT4: |
||
99 | PUSH TEMP |
||
100 | IN TEMP,SREG |
||
101 | PUSH TEMP |
||
102 | PUSH COUNT |
||
103 | PUSH DATA |
||
104 | LDS DATA,PS2K_DATA |
||
105 | LDS COUNT,PS2K_BIT_COUNT |
||
106 | LDS TEMP,PS2K_FLAGS |
||
107 | SBRC TEMP,PS2K_BIT_TX |
||
108 | RJMP INT4TX_0 |
||
109 | |||
110 | CPI COUNT,9 |
||
111 | BREQ INT4RX9 |
||
112 | CPI COUNT,10 |
||
113 | BRCC INT4RXS |
||
114 | TST COUNT |
||
115 | BRNE INT4RX1 |
||
116 | ;start bit |
||
117 | SBIC PIND,6 ; data line |
||
118 | RJMP INT4RX_CLR_D |
||
119 | CBR TEMP,(1<<PS2K_BIT_PARITY) |
||
120 | INC COUNT |
||
121 | RJMP INT4_EXIT |
||
122 | ;data bits |
||
123 | INT4RX1:LSR DATA |
||
124 | SBIS PIND,6 ; data line |
||
125 | RJMP INT4RX2 |
||
126 | ORI DATA,0B10000000 |
||
127 | EOR TEMP,ONE |
||
128 | INT4RX2:INC COUNT |
||
129 | RJMP INT4_EXIT |
||
130 | ;parity bit |
||
131 | INT4RX9:SBIC PIND,6 ; data line |
||
132 | EOR TEMP,ONE |
||
133 | SBRS TEMP,PS2K_BIT_PARITY |
||
134 | RJMP INT4RX_CLR_D |
||
135 | INC COUNT |
||
136 | RJMP INT4_EXIT |
||
137 | ;stop bit |
||
138 | INT4RXS:SBIS PIND,6 ; data line |
||
139 | RJMP INT4RX_CLR_D |
||
140 | |||
141 | STS PS2K_RAW_READY,COUNT |
||
142 | STS PS2K_RAW_CODE,DATA |
||
143 | PS2K_CLOCKLINE_DOWN |
||
144 | LDI COUNT,$80 |
||
145 | OUT TCNT0,COUNT ;Tclk*8*128=~92us |
||
146 | LDI COUNT,(1<<TOV0) |
||
147 | OUT TIFR,COUNT |
||
148 | IN COUNT,TIMSK |
||
149 | ORI COUNT,(1<<TOIE0) |
||
150 | OUT TIMSK,COUNT |
||
151 | |||
152 | LDS COUNT,PS2K_SKIP |
||
153 | TST COUNT |
||
154 | BRNE INT4RX_SKIP |
||
155 | |||
156 | CPI DATA,$E1 |
||
157 | BREQ INT4RX_E1 |
||
158 | CPI DATA,$AA |
||
159 | BREQ INT4RX_CLR_F |
||
160 | CPI DATA,$AB |
||
161 | BREQ INT4RX_AB |
||
162 | CPI DATA,$EE |
||
163 | BREQ INT4RX_CLR_F |
||
164 | CPI DATA,$FA |
||
165 | BREQ INT4RX_CLR_F |
||
166 | CPI DATA,$FE |
||
167 | BREQ INT4RX_CLR_F |
||
168 | CPI DATA,$E0 |
||
169 | BREQ INT4RX_E0 |
||
170 | CPI DATA,$F0 |
||
171 | BREQ INT4RX_F0 |
||
172 | |||
173 | SBR TEMP,(1<<PS2K_BIT_READY) |
||
174 | STS PS2K_KEY_FLAGS,TEMP |
||
175 | STS PS2K_KEY_CODE,DATA |
||
176 | RJMP INT4RX_CLR_F |
||
177 | |||
178 | INT4RX_E0: |
||
179 | SBR TEMP,(1<<PS2K_BIT_EXTKEY) |
||
180 | RJMP INT4RX_CLR_D |
||
181 | |||
182 | INT4RX_F0: |
||
183 | SBR TEMP,(1<<PS2K_BIT_RELEASE) |
||
184 | RJMP INT4RX_CLR_D |
||
185 | |||
186 | INT4RX_SKIP: |
||
187 | DEC COUNT |
||
188 | STS PS2K_SKIP,COUNT |
||
189 | BRNE INT4RX_CLR_D |
||
190 | LDS DATA,PS2K_KEY_CODE |
||
191 | CPI DATA,$7E |
||
192 | BRNE INT4RX_CLR_D |
||
193 | LDI TEMP,(1<<PS2K_BIT_READY)|(1<<PS2K_BIT_RELEASE)|(1<<PS2K_BIT_EXTKEY) |
||
194 | STS PS2K_KEY_FLAGS,TEMP |
||
195 | RJMP INT4RX_CLR_F |
||
196 | |||
197 | INT4RX_AB: |
||
198 | STS PS2K_KEY_CODE,NULL |
||
199 | LDI COUNT,1 |
||
200 | STS PS2K_SKIP,COUNT |
||
201 | RJMP INT4RX_CLR_F |
||
202 | |||
203 | INT4RX_E1: |
||
204 | LDI TEMP,(1<<PS2K_BIT_READY)|(1<<PS2K_BIT_EXTKEY) |
||
205 | STS PS2K_KEY_FLAGS,TEMP |
||
206 | LDI DATA,$7E |
||
207 | STS PS2K_KEY_CODE,DATA |
||
208 | LDI COUNT,7 |
||
209 | STS PS2K_SKIP,COUNT |
||
210 | |||
211 | INT4RX_CLR_F: |
||
212 | CLR TEMP |
||
213 | INT4RX_CLR_D: |
||
214 | CLR DATA |
||
215 | CLR COUNT |
||
216 | RJMP INT4_EXIT |
||
217 | ;------- |
||
218 | INT4TX_0: |
||
219 | CPI COUNT,9 |
||
220 | BREQ INT4TX9 |
||
221 | CPI COUNT,10 |
||
222 | BREQ INT4TXS |
||
223 | CPI COUNT,11 |
||
224 | BRCC INT4TXA |
||
225 | TST COUNT |
||
226 | BRNE INT4TX1 |
||
227 | ;start bit |
||
228 | SBR TEMP,(1<<PS2K_BIT_PARITY) |
||
229 | INC COUNT |
||
230 | RJMP INT4_EXIT |
||
231 | ;data bits |
||
232 | INT4TX1:ROR DATA |
||
233 | BRCC INT4TX2 |
||
234 | PS2K_DATALINE_UP |
||
235 | EOR TEMP,ONE |
||
236 | INC COUNT |
||
237 | RJMP INT4_EXIT |
||
238 | INT4TX2:PS2K_DATALINE_DOWN |
||
239 | INC COUNT |
||
240 | RJMP INT4_EXIT |
||
241 | ;parity bit |
||
242 | INT4TX9:SBRC TEMP,PS2K_BIT_PARITY |
||
243 | RJMP INT4TXP |
||
244 | PS2K_DATALINE_DOWN |
||
245 | INC COUNT |
||
246 | RJMP INT4_EXIT |
||
247 | INT4TXP:PS2K_DATALINE_UP |
||
248 | INC COUNT |
||
249 | RJMP INT4_EXIT |
||
250 | ;stop bit |
||
251 | INT4TXS:PS2K_DATALINE_UP |
||
252 | INC COUNT |
||
253 | RJMP INT4_EXIT |
||
290 | ddp | 254 | ;����� ࠭�� ������ ack-bit, �� CHRV ����� ;) |
255 | ; ��� ���� ⠪�� ����������, ����� �� �뤠�� ��� ���. |
||
256 | INT4TXA:;CLR TEMP |
||
257 | ;SBIS PIND,6 ; data line |
||
261 | ddp | 258 | LDI TEMP,(1<<PS2K_BIT_ACKBIT) |
259 | CLR DATA |
||
260 | CLR COUNT |
||
261 | |||
262 | INT4_EXIT: |
||
263 | STS PS2K_BIT_COUNT,COUNT |
||
264 | STS PS2K_DATA,DATA |
||
265 | STS PS2K_FLAGS,TEMP |
||
266 | POP DATA |
||
267 | POP COUNT |
||
268 | POP TEMP |
||
269 | OUT SREG,TEMP |
||
270 | POP TEMP |
||
271 | RETI |
||
272 | ; |
||
273 | ;-------------------------------------- |
||
274 | ;out: DATA == ᪠�-��� ������ |
||
275 | ; TEMP.PS2K_BIT_EXTKEY == ���.��� |
||
276 | WAITKEY:CALL RANDOM |
||
277 | LDS TEMP,PS2K_KEY_FLAGS |
||
278 | SBRS TEMP,PS2K_BIT_READY |
||
279 | RJMP WAITKEY |
||
280 | STS PS2K_KEY_FLAGS,NULL |
||
281 | SBRC TEMP,PS2K_BIT_RELEASE |
||
282 | RJMP WAITKEY |
||
283 | LDS DATA,PS2K_KEY_CODE |
||
284 | RET |
||
285 | ; |
||
286 | ;-------------------------------------- |
||
287 | ;out: sreg.Z == clr - �뫮 ����⨥ (��⮯����) |
||
288 | ; DATA == ᪠�-��� ������ |
||
289 | ; TEMP.PS2K_BIT_EXTKEY == ���.��� |
||
290 | INKEY: CALL RANDOM |
||
291 | LDS TEMP,PS2K_KEY_FLAGS |
||
292 | SBRS TEMP,PS2K_BIT_READY |
||
293 | RJMP INKEY9 |
||
294 | STS PS2K_KEY_FLAGS,NULL |
||
295 | SBRC TEMP,PS2K_BIT_RELEASE |
||
296 | RJMP INKEY9 |
||
297 | LDS DATA,PS2K_KEY_CODE |
||
298 | CLZ |
||
299 | RET |
||
300 | |||
301 | INKEY9: SEZ |
||
302 | RET |
||
303 | ; |
||
304 | ;-------------------------------------- |
||
305 | ;in: DATA |
||
306 | ;out: sreg.Z - CLR == ok; SET == timeout |
||
307 | PS2K_SEND_BYTE: |
||
308 | PS2K_DATALINE_UP |
||
309 | IN TEMP,TIMSK |
||
310 | CBR TEMP,(1<<TOIE0) |
||
311 | OUT TIMSK,TEMP |
||
312 | PS2K_CLOCKLINE_UP |
||
313 | CLR TEMP |
||
314 | PS2K_SEND0: |
||
315 | SBIS PINE,4 ; clock line |
||
316 | RJMP PS2K_SEND_BYTE |
||
317 | DEC TEMP |
||
318 | BRNE PS2K_SEND0 |
||
319 | |||
320 | CLI |
||
321 | PS2K_CLOCKLINE_DOWN |
||
290 | ddp | 322 | PS2K_DATALINE_DOWN |
261 | ddp | 323 | STS PS2K_DATA,DATA |
324 | LDI TEMP,(1<<PS2K_BIT_TX) |
||
325 | STS PS2K_FLAGS,TEMP |
||
326 | STS PS2K_BIT_COUNT,NULL |
||
327 | STS PS2K_SKIP,NULL |
||
328 | STS PS2K_KEY_FLAGS,NULL |
||
329 | STS PS2K_RAW_READY,NULL |
||
330 | SEI |
||
331 | DELAY_US 100 |
||
332 | PS2K_DATALINE_DOWN |
||
290 | ddp | 333 | DELAY_US 500 |
261 | ddp | 334 | LDIZ PS2K_TIMEOUT |
335 | LDIW 15 |
||
336 | CALL SET_TIMEOUT_MS |
||
337 | PS2K_CLOCKLINE_UP |
||
338 | PS2K_SEND1: |
||
339 | LDS TEMP,PS2K_FLAGS |
||
340 | ANDI TEMP,(1<<PS2K_BIT_ACKBIT) |
||
341 | BRNE PS2K_SEND2 |
||
342 | LDIZ PS2K_TIMEOUT |
||
343 | CALL CHECK_TIMEOUT_MS |
||
344 | BRCC PS2K_SEND1 |
||
345 | PS2K_DATALINE_UP |
||
346 | SEZ |
||
347 | PS2K_SEND2: |
||
348 | RET |
||
349 | ; |
||
350 | ;-------------------------------------- |
||
351 | ;out: sreg.Z - CLR == ok; SET == timeout |
||
352 | ; DATA == byte |
||
353 | PS2K_RECEIVE_BYTE: |
||
354 | STS PS2K_RAW_READY,NULL |
||
355 | LDIZ PS2K_TIMEOUT |
||
356 | LDIW 20 |
||
357 | CALL SET_TIMEOUT_MS |
||
358 | |||
359 | PS2K_RXBYTE1: |
||
360 | LDS TEMP,PS2K_RAW_READY |
||
361 | TST TEMP |
||
362 | BRNE PS2K_RXBYTE2 |
||
363 | LDIZ PS2K_TIMEOUT |
||
364 | CALL CHECK_TIMEOUT_MS |
||
365 | BRCC PS2K_RXBYTE1 |
||
366 | CLR DATA |
||
367 | SEZ |
||
368 | RET |
||
369 | |||
370 | PS2K_RXBYTE2: |
||
371 | LDS DATA,PS2K_RAW_CODE |
||
372 | RET |
||
373 | ; |
||
374 | ;-------------------------------------- |
||
375 | ; |
||
376 | .EQU PS2K_DETECT_TEMP=0 |
||
377 | ; |
||
378 | PS2K_DETECT_KBD: |
||
379 | GETMEM 1 |
||
380 | PS2K_CLOCKLINE_UP |
||
381 | LDIZ MLMSG_KBD_DETECT*2 |
||
382 | RCALL PRINTMLSTR |
||
383 | |||
384 | STS PS2K_RAW_READY,NULL |
||
385 | LDIZ PS2K_TIMEOUT |
||
386 | LDIW 500 |
||
387 | CALL SET_TIMEOUT_MS |
||
388 | PS2K_DETECT_K1: |
||
389 | LDS TEMP,PS2K_RAW_READY |
||
390 | TST TEMP |
||
391 | BRNE PS2K_DETECT_K2 |
||
392 | LDIZ PS2K_TIMEOUT |
||
393 | CALL CHECK_TIMEOUT_MS |
||
394 | BRCC PS2K_DETECT_K1 |
||
395 | RJMP PS2K_DETECT_K3 |
||
396 | PS2K_DETECT_K2: |
||
397 | LDS DATA,PS2K_RAW_CODE |
||
398 | RCALL HEXBYTE_FOR_DUMP |
||
399 | PS2K_DETECT_K3: |
||
400 | |||
401 | LDI DATA,$FF |
||
402 | RCALL PS2K_DETECT_SEND |
||
403 | ; BRNE PS2K_DETECT_K6 |
||
404 | STS PS2K_RAW_READY,NULL |
||
405 | LDIZ PS2K_TIMEOUT |
||
406 | LDIW 1000 |
||
407 | CALL SET_TIMEOUT_MS |
||
408 | PS2K_DETECT_K4: |
||
409 | LDS TEMP,PS2K_RAW_READY |
||
410 | TST TEMP |
||
411 | BRNE PS2K_DETECT_K5 |
||
412 | LDIZ PS2K_TIMEOUT |
||
413 | CALL CHECK_TIMEOUT_MS |
||
414 | BRCC PS2K_DETECT_K4 |
||
415 | RCALL PS2K_DETECT_NORESPONSE |
||
416 | RJMP PS2K_DETECT_K6 |
||
417 | PS2K_DETECT_K5: |
||
418 | LDS DATA,PS2K_RAW_CODE |
||
419 | RCALL HEXBYTE_FOR_DUMP |
||
420 | CPI DATA,$AA |
||
421 | BREQ PS2K_DETECT_K6 |
||
422 | RCALL PS2K_DETECT_UNWANTED |
||
423 | |||
424 | PS2K_DETECT_K6: |
||
425 | LDI DATA,$F2 |
||
426 | RCALL PS2K_DETECT_SEND |
||
427 | BRNE PS2K_DETECT_K7 |
||
428 | LDI DATA,$AB |
||
429 | RCALL PS2K_DETECT_RECEIVE |
||
430 | BRNE PS2K_DETECT_K7 |
||
431 | LDI DATA,$83 |
||
432 | RCALL PS2K_DETECT_RECEIVE |
||
433 | PS2K_DETECT_K7: |
||
434 | LDI DATA,$F0 |
||
435 | RCALL PS2K_DETECT_SEND |
||
436 | BRNE PS2K_DETECT_K8 |
||
437 | LDI DATA,$02 |
||
438 | RCALL PS2K_DETECT_SEND |
||
439 | PS2K_DETECT_K8: |
||
440 | LDI DATA,$F3 |
||
441 | RCALL PS2K_DETECT_SEND |
||
442 | BRNE PS2K_DETECT_K9 |
||
443 | LDI DATA,$00 |
||
444 | RCALL PS2K_DETECT_SEND |
||
445 | LDIZ MSG_READY*2+3 |
||
446 | CALL PRINTSTRZ |
||
447 | PS2K_DETECT_K9: |
||
448 | FREEMEM 1 |
||
449 | RET |
||
450 | ; |
||
451 | PS2K_DETECT_SEND: |
||
452 | RCALL HEXBYTE_FOR_DUMP |
||
453 | RCALL PS2K_SEND_BYTE |
||
454 | BREQ PS2K_DETECT_TXFAIL |
||
455 | RCALL PS2K_RECEIVE_BYTE |
||
456 | BREQ PS2K_DETECT_NORESPONSE |
||
457 | RCALL HEXBYTE_FOR_DUMP |
||
458 | CPI DATA,$FA |
||
459 | BRNE PS2K_DETECT_UNWANTED |
||
460 | RET |
||
461 | ; |
||
462 | PS2K_DETECT_RECEIVE: |
||
463 | STH PS2K_DETECT_TEMP,DATA |
||
464 | RCALL PS2K_RECEIVE_BYTE |
||
465 | BREQ PS2K_DETECT_NORESPONSE |
||
466 | RCALL HEXBYTE_FOR_DUMP |
||
467 | LDH TEMP,PS2K_DETECT_TEMP |
||
468 | CP DATA,TEMP |
||
469 | BRNE PS2K_DETECT_UNWANTED |
||
470 | RET |
||
471 | ; |
||
472 | PS2K_DETECT_TXFAIL: |
||
473 | LDIZ MLMSG_TXFAIL*2 |
||
474 | RJMP PS2K_DETECT_XXFAIL |
||
475 | PS2K_DETECT_UNWANTED: |
||
476 | LDIZ MLMSG_UNWANTED*2 |
||
477 | RJMP PS2K_DETECT_XXFAIL |
||
478 | PS2K_DETECT_NORESPONSE: |
||
479 | LDIZ MLMSG_NORESPONSE*2 |
||
480 | PS2K_DETECT_XXFAIL: |
||
481 | CALL PRINTMLSTR |
||
482 | CLZ |
||
483 | RET |
||
484 | ; |
||
485 | ;-------------------------------------- |
||
486 | ; |