-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.s
475 lines (404 loc) · 9.9 KB
/
keyboard.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
.include "include/ascii.i"
.include "include/hardware.i"
.include "include/scancodes.i"
.section .text
.align 2
.global keyboardinit
.global conputmcuchar
.global testcongetstr
.global testcongetchar
keyboardinit: move.b #0x05, CR26C94+BASEPD | enable tx and rx
move.b #0b00010011, MRX26C94+BASEPD | 8 bit, no parity
move.b #0x07, MRX26C94+BASEPD | 1 stop bit
move.b #0xbb, CSR26C94+BASEPD | 38.4kbaud
move.b #6,%d0
bsr conputmcuchar
clr.w leftshifton
clr.w rightshifton
clr.w capslockon
clr.w controlon
rts
| put the char in d0
conputmcuchar: btst.b #3,SR26C94+BASEPD | busy sending last char?
beq conputmcuchar | yes, look again
move.b %d0,TXFIFO26C94+BASEPD | put that byte
rts
| get a str in a0
testcongetstr: movem.l %d0-%d1/%a0,-(%sp)
clr.w %d1 | set the length to 0
getstrloop: bsr testcongetchar | get a char in a
cmp.b #ASC_CR,%d0 | cr?
beq getstrout | if it is, then out
cmp.b #ASC_LF,%d0 | lf?
beq getstrout | if it is, then out
cmp.b #ASC_BS,%d0 | backspace pressed?
beq getstrbs | handle backspace
cmp.b #ASC_SP,%d0 | less then space ...
blo getstrloop | ... ignore, and get another
btst.b #7,%d0 | top bit set?
bne getstrloop | .... ignore (cursor etc)
move.b %d0,(%a0)+ | add it to string
addq.w #1,%d1 | increment the number of chars
getstrecho: bsr conputchar | echo it
bra getstrloop | get more
getstrout: move.b #0,(%a0)+ | add a null
movea.l #newlinemsg,%a0 | tidy up ...
bsr conputstr | ... with a newline
movem.l (%sp)+,%d0-%d1/%a0
rts
getstrbs: tst.w %d1 | see if the char count is 0
beq getstrloop | do nothing if already zero
subq.w #1,%d1 | reduce count by 1
move.b #0,(%a0) | null the current char
suba.l #1,%a0 | move the pointer back 1
move.b #ASC_BS,%d0 | move cursor back one
bsr conputchar
move.b #ASC_SP,%d0 | then erase and move forward
bsr conputchar
move.b #ASC_BS,%d0 | then back one again
bsr conputchar
bra getstrloop | echo the bs and charry on
| get a char in d0 - guaranteed to have high byte 0
testcongetchar: btst.b #0,SR26C94+BASEPD | chars?
beq testcongetchar | no chars yet
clr.w %d0 | clear the top byte as well
move.b RXFIFO26C94+BASEPD,%d0 | chars?
bsr mapscancode | translate to ascii
tst.b %d0 | printable?
beq testcongetchar | back for more
rts
| translate scancode in a register, returning the ascii a - if no char is
| needed then a is zero
mapscancode: movem.l %d1/%a0,-(%sp)
move.w #1,%d1 | default to key up
btst.b #7,%d0 | key going up or down?
beq keydown | down
clr.w %d1 | 0 for up
keydown: andi.b #0x7f,%d0 | mask out the up/down
cmp.b #KEY_L_SHIFT,%d0 | left shift?
beq asciilshift
cmp.b #KEY_R_SHIFT,%d0 | right shift?
beq asciirshift
cmp.b #KEY_CAPS_LOCK,%d0 | caps lock?
beq asciicapslock
cmp.b #KEY_CTRL,%d0 | control?
beq asciicontrol
tst.w %d1 | key direction?
bne printablekey | down, so convert it
nonprintable: clr.b %d0 | non printable char, 0, set zero
mapscancodeo: movem.l (%sp)+,%d1/%a0
rts | otherwise we are done
asciilshift: move.w %d1,leftshifton | set left shift pressed flag
bra nonprintable | done
asciirshift: move.w %d1,rightshifton | set right shift pressed flag
bra nonprintable | done
asciicapslock: move.w %d1,capslockon | set caps lock pressed flag
bra nonprintable | done
asciicontrol: move.w %d1,controlon | set control prssed flag
bra nonprintable | done
printablekey: movea.l #unshiftmap,%a0 | assume we are not shifting
tst.w controlon | check control first
bne 3f
tst.w leftshifton | check for left shift down
bne 4f | is it?
tst.w rightshifton | check for right shift down
bne 4f | is it?
1: move.b (%d0.w,%a0),%d0 | find ascii value
tst.w capslockon | check for caps lock on
beq 2f | is it?
bsr toupper | otherwise uppercase the letter
2: bra mapscancodeo | cleanup
3: movea.l #controlmap,%a0 | controling, use alternate table
bra 1b | get key
4: movea.l #shiftmap,%a0 | shifting, use alternate table
bra 1b | get key
.section .bss
.align 2
leftshifton: .space 2
rightshifton: .space 2
capslockon: .space 2
controlon: .space 2
.section .rodata
.align 2
unshiftmap:
| row 0
.byte ASC_ESC | escape
.byte ASC_NUL | unwired
.byte ASC_F1 | f1
.byte ASC_F2 | f2
.byte ASC_F3 | f3
.byte ASC_F4 | f4
.byte ASC_F5 | f5
.byte ASC_NUL | unwired
.byte ASC_F6 | f6
.byte ASC_NUL | blank
.byte ASC_F7 | f7
.byte ASC_F8 | f8
.byte ASC_F9 | f9
.byte ASC_F10 | f10
.byte ASC_HELP | help
.byte ASC_NUL | unused
| row 1
.ascii "~"
.ascii "1"
.ascii "2"
.ascii "3"
.ascii "4"
.ascii "5"
.ascii "6"
.ascii "7"
.ascii "8"
.ascii "9"
.ascii "0"
.ascii "-"
.ascii "="
.ascii "\\"
.byte ASC_UP | cursor up
.byte ASC_NUL | unused
| row 2
.byte ASC_HT | tab
.ascii "q"
.ascii "w"
.ascii "e"
.ascii "r"
.ascii "t"
.ascii "y"
.ascii "u"
.ascii "i"
.ascii "o"
.ascii "p"
.ascii "["
.ascii "]"
.byte ASC_CR | replaced: return
.byte ASC_LEFT | cursor left
.byte ASC_NUL | unused
| row 3
.byte ASC_NUL | caps lock
.ascii "a"
.ascii "s"
.ascii "d"
.ascii "f"
.ascii "g"
.ascii "h"
.ascii "j"
.ascii "k"
.ascii "l"
.ascii "|"
.ascii "\""
.byte ASC_NUL | blank
.byte ASC_DEL | delete
.byte ASC_RIGHT | cursor right
.byte ASC_NUL | unused
| row 4
.byte ASC_NUL | blank
.ascii "z"
.ascii "x"
.ascii "c"
.ascii "v"
.ascii "b"
.ascii "n"
.ascii "m"
.ascii ","
.ascii "."
.ascii "/"
.byte ASC_NUL | unwired
.byte ASC_SP
.byte ASC_BS | backspace
.byte ASC_DOWN | cursor down
.byte ASC_NUL | unused
| row 5 (meta)
.byte ASC_NUL | right shift
.byte ASC_NUL | right alt
.byte ASC_NUL | right amiga
.byte ASC_NUL | ctrl
.byte ASC_NUL | left shift
.byte ASC_NUL | left alt
.byte ASC_NUL | left amiga
shiftmap:
| row 0
.byte ASC_ESC | escape
.byte ASC_NUL | unwired
.byte ASC_F1 | f1
.byte ASC_F2 | f2
.byte ASC_F3 | f3
.byte ASC_F4 | f4
.byte ASC_F5 | f5
.byte ASC_NUL | unwired
.byte ASC_F6 | f6
.byte ASC_NUL | blank
.byte ASC_F7 | f7
.byte ASC_F8 | f8
.byte ASC_F9 | f9
.byte ASC_F10 | f10
.byte ASC_BREAK | help
.byte ASC_NUL | unused
| row 1
.ascii "`"
.ascii "!"
.ascii "@"
.ascii " "
.ascii "$"
.ascii "%"
.ascii "^"
.ascii "&"
.ascii "*"
.ascii "("
.ascii ")"
.ascii "_"
.ascii "+"
.ascii "|"
.byte ASC_UP | cursor up
.byte ASC_NUL | unused
| row 2
.byte ASC_HT | tab
.ascii "Q"
.ascii "W"
.ascii "E"
.ascii "R"
.ascii "T"
.ascii "Y"
.ascii "U"
.ascii "I"
.ascii "O"
.ascii "P"
.ascii "{"
.ascii "}"
.byte ASC_CR | replaced: return
.byte ASC_LEFT | cursor up
.byte ASC_NUL | unused
| row 3
.byte ASC_NUL | caps lock
.ascii "A"
.ascii "S"
.ascii "D"
.ascii "F"
.ascii "G"
.ascii "H"
.ascii "J"
.ascii "K"
.ascii "L"
.ascii ":"
.ascii "\""
.byte ASC_NUL | blank
.byte ASC_DEL | delete
.byte ASC_RIGHT | cursor right
.byte ASC_NUL | unused
| row 4
.byte ASC_NUL | blank
.ascii "Z"
.ascii "X"
.ascii "C"
.ascii "V"
.ascii "B"
.ascii "N"
.ascii "M"
.ascii "<"
.ascii ">"
.ascii "?"
.byte ASC_NUL | unwired
.byte ASC_SP
.byte ASC_BS | backspace
.byte ASC_DOWN | cursor down
.byte ASC_NUL | unused
| row 5 (meta)
.byte ASC_NUL | right shift
.byte ASC_NUL | right alt
.byte ASC_NUL | right amiga
.byte ASC_NUL | ctrl
.byte ASC_NUL | left shift
.byte ASC_NUL | left alt
.byte ASC_NUL | left amiga
controlmap:
| row 0
.byte ASC_ESC | escape
.byte ASC_NUL | unwired
.byte ASC_F1 | f1
.byte ASC_F2 | f2
.byte ASC_F3 | f3
.byte ASC_F4 | f4
.byte ASC_F5 | f5
.byte ASC_NUL | unwired
.byte ASC_F6 | f6
.byte ASC_NUL | blank
.byte ASC_F7 | f7
.byte ASC_F8 | f8
.byte ASC_F9 | f9
.byte ASC_F10 | f10
.byte ASC_HELP | help
.byte ASC_NUL | unused
| row 1
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_RS | '^'
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_US | '_'
.byte ASC_NUL | unused
.byte ASC_FS | '\'
.byte ASC_UP | cursor up
.byte ASC_NUL | unused
| row 2
.byte ASC_HT | tab
.byte ASC_DC1 | 'Q'
.byte ASC_ETB | 'W'
.byte ASC_ENQ | 'E'
.byte ASC_DC2 | 'R'
.byte ASC_DC4 | 'T'
.byte ASC_EM | 'Y'
.byte ASC_NAK | 'U'
.byte ASC_HT | 'I'
.byte ASC_SI | 'O'
.byte ASC_DLE | 'P'
.byte ASC_ESC | '['
.byte ASC_GS | ']'
.byte ASC_CR | return
.byte ASC_LEFT | cursor up
.byte ASC_NUL | unused
| row 3
.byte ASC_NUL | caps lock
.byte ASC_SOH | 'A'
.byte ASC_DC3 | 'S'
.byte ASC_EOT | 'D'
.byte ASC_ACK | 'F'
.byte ASC_BEL | 'G'
.byte ASC_BS | 'H'
.byte ASC_LF | 'J'
.byte ASC_VT | 'K'
.byte ASC_FF | 'L'
.byte ASC_NUL | unused
.byte ASC_US | '''
.byte ASC_NUL | blank
.byte ASC_DEL | delete
.byte ASC_RIGHT | cursor right
.byte ASC_NUL | unused
| row 4
.byte ASC_NUL | blank
.byte ASC_SUB | 'Z'
.byte ASC_CAN | 'X'
.byte ASC_ETX | 'C'
.byte ASC_SYN | 'V'
.byte ASC_STX | 'B'
.byte ASC_SO | 'N'
.byte ASC_CR | 'M'
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unused
.byte ASC_NUL | unwired
.byte ASC_NUL
.byte ASC_NUL | backspace
.byte ASC_DOWN | cursor down
.byte ASC_NUL | unused
| row 5 (meta)
.byte ASC_NUL | right shift
.byte ASC_NUL | right alt
.byte ASC_NUL | right amiga
.byte ASC_NUL | ctrl
.byte ASC_NUL | left shift
.byte ASC_NUL | left alt
.byte ASC_NUL | left amiga