-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.asm
More file actions
210 lines (145 loc) · 2.68 KB
/
input.asm
File metadata and controls
210 lines (145 loc) · 2.68 KB
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
;
; input.asm
;
define CAPS_SHIFT 0x01
define SYMBOL_SHIFT 0x02
define KEY_LEFT 0x05
define KEY_RIGHT 0x06
define KEY_UP 0x07
define KEY_DOWN 0x08
define BREAK 0x09
define DELETE 0x10
define ENTER 0x13
keylookup_norm
defb " ", SYMBOL_SHIFT, "MNB", ENTER ,"LKJHPOIUY09876"
defb "12345QWERTASDFG", CAPS_SHIFT, "ZXCV"
keylookup_lower
defb " ", SYMBOL_SHIFT, "mnb", ENTER ,"lkjhpoiuy09876"
defb "12345qwertasdfg", CAPS_SHIFT, "zxcv"
keylookup_caps
defb BREAK, SYMBOL_SHIFT, "MNB", ENTER ,"LKJHPOIUY"
defb DELETE, "9", KEY_RIGHT, KEY_UP, KEY_DOWN
defb "1234", KEY_LEFT, "QWERTASDFG", CAPS_SHIFT, "ZXCV"
keylookup_symshift
defb " ", SYMBOL_SHIFT, ".,*", ENTER ,"=+-^", 0x22, ";i][_)('&"
defb "!@#$%qwe<>~|\\{}", CAPS_SHIFT, ":", 0x60, "?/"
;
; Scans the keyboard for a single keypress.
; Accumulator contains flags as follows:
; Bit 0 : Allow mixed case.
; Bit 1 : Treat CS/SS as standalone keys, not modifiers
; Returns with carry flag set and key in accumulator if
; found, or carry flag clear if no key pressed.
;
scan_keys
push ix
push hl
push de
push bc
push af
ld bc, 0x7ffe
ld ix, v_keybuffer
key_row_read
in a, (c)
and 0x1f
ld (ix), a
inc ix
rrc b
ld a, b
cp 0x7f
jr nz, key_row_read
; Rows read into bitmap
pop af
ld ix, v_keybuffer
ld hl, keylookup_lower
; Store keyboard read flags in D
ld d, a
; Are we forcing upper case?
bit 0, d
jr nz, no_force_upcase
; Yes we are
ld hl, keylookup_norm
no_force_upcase
; Treat CS/SS as modifiers?
bit 1, d
jr nz, no_sym_pressed
; Yes, alter key lookup tables on this basis.
bit 0, (ix+7)
jr nz, no_caps_pressed
ld hl, keylookup_caps
no_caps_pressed
bit 1, (ix)
jr nz, no_sym_pressed
ld hl, keylookup_symshift
no_sym_pressed
ld b, 8
map_row_read
ld a, 0xff
ld c, b
ld b, 5
key_loop
bit 0, (ix)
jr nz, key_next
; Key found, lookup from table
ld a, (hl)
; Exit if we are treating modifier keys as standalone
bit 1, d
jr nz, key_return
; We're treating CS/SS as modifiers, so if these are pressed, continue
; scanning
cp CAPS_SHIFT
jr z, key_next
cp SYMBOL_SHIFT
jr z, key_next
; Else return with key in A
key_return
pop bc
pop de
pop hl
pop ix
scf
ret
key_next
ld a, 0xff
inc hl
srl (ix)
djnz key_loop
map_row_next
inc ix
ld b, c
djnz map_row_read
pop bc
cp 0xff
jr z, no_key
pop de
pop hl
pop ix
scf
ret
no_key
pop de
pop hl
pop ix
and a ; reset carry flag
ret
;
; Waits for a key press (and release)
; Returns the key pressed in A
;
get_key
push bc
ld b, a
get_key_scan
ld a, b
call scan_keys
jr nc, get_key_scan
ld b, a
debounce_key
xor a
in a, (0xfe)
and 0x1f
cp 0x1f
jr nz, debounce_key
ld a, b
pop bc
ret