-
Notifications
You must be signed in to change notification settings - Fork 0
/
redefine.asm
447 lines (408 loc) · 9.49 KB
/
redefine.asm
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
; REDEFINE KEYS
;----------------------------------------------
@top_line: equ &30
@line_gap: equ &0c
@left_align: equ &18
@right_align: equ &88
@pause: equ &0a
@end_pause: equ &2d
redefine.msg:
dm " LEFT:"
db eof
dm " RIGHT:"
db eof
dm " UP:"
db eof
dm " DOWN/DROP:"
db eof
dm "ROTATE RIGHT:"
db eof
dm " ROTATE LEFT:"
db eof
redefine.offsets:
db 7-Left,7-Right,7-Up,7-Down,7-RotateC,7-RotateAC
redefine.keyvals: ; Temporary list of keyvalues, to check not duplicating
db 0,0,0,0,0,0
;Key no. > 0 1 2 3 4 5 6 7
;Key row \/
;0. 1 2 3 4 5 ESC TAB CAPS
;1. Q W E R T F7 F8 F9
;2. A S D F G F4 F5 F6
;3. SHIFT Z X C V F1 F2 F3
;4. 0 9 8 7 6 - + DEL
;5. P O I U Y = " F0
;6. ENTER L K J H ; : EDIT
;7. SPACE SYMBL M N B , . INV
;8. CTRL UP DOWN LEFT RIGHT
;----------------------------------------------
redefine.k_scanHL:
; Steve Taylor's key scan routine.
; Read 8 keydefinitions at HL (see table), output C with each respective bit set if key pressed.
; Used for reading keys stored from redefine keys routine.
ld bc,&800 ; Repeat for each of 8 rows
@k_scan1:
@get_row_number:
ld a,(hl)
inc hl
ld e,a
for 3,srl e
ld d,0
push hl
ld hl,@key_addresses ; Get port number from key_addresses table
add hl,de
ld d,a
push bc
@get_key_port_half: ; Get lower 5 bits from keyboard port
ld c,KeyboardReg
ld b,(hl)
in a,(c)
and %00011111
ld e,a
@get_status_port_half: ; Get upper 3 bits from status port
ld c,StatusReg
in a,(c)
and %11100000
@merge_inputs: ; merge two together
or e
cpl
ld e,a
pop bc
pop hl
ld a,d
and %00000111
jr z,@k_scan3
@k_scan2: ; Rotate input into destination bit position
rr e
dec a
jr nz,@k_scan2
@k_scan3: ; Rotate into main output C
rr e
rl c
djnz @k_scan1 ; Repeat for each key
ret ; Return C with output
@key_addresses: db &f7,&fb,&fd,&fe,&ef,&df,&bf,&7f,&ff ; List of ports to read for keypresses
;----------------------------------------------
keys.redefine:
; Assume redefined keys override predefined keys, so any keys are fine.
push af
call @+clear_lower
call @+reset
@setup_loop:
ld b,6 ; Six keys to redefine
ld iy,keys.redef ; Output to keys.redef table
ld ix,redefine.offsets ; List of offsets to store keys in keys.redef table
ld hl,redefine.msg ; Message to print
ex af,af'
ld a,@top_line ; Set top print line
ex af,af'
@redef_key:
push bc
@print_challenge: ; Print key input message
push af
ld a,orange*&11
call font.set_colA
pop af
@set_x_print_pos:
ld e,@left_align
ex af,af'
ld d,a
ex af,af'
xor a
call font.print_stringHLDE
push hl
@scan_loop: ; Scan for key pressed
ld hl,@key_addresses+8
ld d,9
@scan_ports: ; Collect keyrow inputs from both registers
ld b,(hl)
ld c,StatusReg
in a,(c)
cpl
and %11100000
ld e,a
ld c,KeyboardReg
in a,(c)
cpl
and %00011111
or e
ld b,8 ; Loop through each bit to see if set
@keyscanloop:
rlca
jr c,@+next
djnz @-keyscanloop
dec hl ; If nothing pressed, move to next keyrow to test
dec d
jr nz,@-scan_ports
jr @-scan_loop
@next:
call @+allocate ; Allocate pressed key
jr z,@-scan_loop ; If key already allocated keep scanning
call @+print_key ; Print confirmation feedback
push de
xor a
ld b,9
@clear_loop:
ld (de),a
inc de
djnz @-clear_loop
pop de
@move_loop:
ld a,(hl)
cp eof
jp z,@+next
ld (de),a
inc hl
inc de
jp @-move_loop
@next:
ld b,@pause
call house.wait_B_frames_im2
pop hl
pop bc
dec b
jp nz,@-redef_key
ld b,@end_pause
call house.wait_B_frames_im2
call house.clear_screens
pop af
ret
@clear_lower:
; Clear lower part of screen
ld hl,38*128
ld de,38*128+1
ld (hl),0
ld bc,(192-38)*128-1
ldir
ret
@reset:
; Clear store address and redef table
@reset_store_addr: ; Reset table of keys positions
ld hl,attract.keys.pos
ld (redefine.store_addr+1),hl
@clear_redef_table: ; Clear keycodes table
ld hl,keys.redef
ld de,keys.redef+1
ld (hl),255
ld bc,8-1
ldir
@clear_keyvalue_table: ; Clear temporary store of used keys
ld hl,redefine.keyvals
ld (redefine.keyvals.pos+1),hl
ld de,redefine.keyvals+1
ld (hl),0
ld bc,6-1
ldir
ret
@allocate:
; Translate D into keyvalue
@translate_input:
ld a,d
dec a
for 3,add a
dec b
or b
@test_escape:
cp 5 ; Test escape as single undefinable key
ret z
@check_keyvalue: ; If keyvalue already used, return
ld hl,redefine.keyvals
ld b,6
@loop:
cp (hl)
ret z
inc hl
djnz @-loop
@store_keyvalue: ; Put current keyvalue into table of used values
redefine.keyvals.pos: ld hl,0
ld (hl),a
inc hl
ld (redefine.keyvals.pos+1),hl
@store_keycode: ; Set iy offset to store to correct position
ld e,a
ld a,(ix)
inc ix
ld (@+offset+2),a
ld a,e
@offset: ld (iy+0),a
cp 255 ; Return NZ
ret
@print_key:
; Print the new definition message
push af
ld a,white*&11
call font.set_colA
pop af
@find_msg:
add a
ld l,a
ld h,0
ld de,redefine.key_msg.table
add hl,de
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
@find_print_pos:
push hl
ld e,@right_align
ex af,af'
ld d,a
add @line_gap ; Next line down
ex af,af'
xor a
call font.print_stringHLDE
@store_msg: ; store defined name
redefine.store_addr: ld hl,attract.keys.pos
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld (redefine.store_addr+1),hl
pop hl
ret
;----------------------------------------------
redefine.key_msg.table:
; Lookup table so when key is pressed it can be printed
dw Msg1,Msg2,Msg3,Msg4,Msg5,MsgEsc,MsgTab,MsgCaps,MsgQ,MsgW,MsgE,MsgR,MsgT,MsgF7,MsgF8,MsgF9
dw MsgA,MsgS,MsgD,MsgF,MsgG,MsgF4,MsgF5,MsgF6,MsgSh,MsgZ,MsgX,MsgC,MsgV,MsgF1,MsgF2,MsgF3
dw Msg0,Msg9,Msg8,Msg7,Msg6,MsgMinus,MsgPlus,MsgDel,MsgP,MsgO,MsgI,MsgU,MsgY,MsgEqu,MsgQuote,MsgF0
dw MsgEnter,MsgL,MsgK,MsgJ,MsgH,MsgSemi,MsgColon,MsgEdit,MsgSpace,MsgSym,MsgM,MsgN,MsgB,MsgComma,MsgFStop,MsgInv
dw MsgCtrl,MsgUp,MsgDown,MsgLeft,MsgRight
Msg1: dm "1"
db eof
Msg2: dm "2"
db eof
Msg3: dm "3"
db eof
Msg4: dm "4"
db eof
Msg5: dm "5"
db eof
MsgEsc: dm "ESCAPE"
db eof
MsgTab: dm "TAB"
db eof
MsgCaps: dm "CAPS"
db eof
MsgQ: dm "Q"
db eof
MsgW: dm "W"
db eof
MsgE: dm "E"
db eof
MsgR: dm "R"
db eof
MsgT: dm "T"
db eof
MsgF7: dm "F7"
db eof
MsgF8: dm "F8"
db eof
MsgF9: dm "F9"
db eof
MsgA: dm "A"
db eof
MsgS: dm "S"
db eof
MsgD: dm "D"
db eof
MsgF: dm "F"
db eof
MsgG: dm "G"
db eof
MsgF4: dm "F4"
db eof
MsgF5: dm "F5"
db eof
MsgF6: dm "F6"
db eof
MsgSh: dm "SHIFT"
db eof
MsgZ: dm "Z"
db eof
MsgX: dm "X"
db eof
MsgC: dm "C"
db eof
MsgV: dm "V"
db eof
MsgF1: dm "F1"
db eof
MsgF2: dm "F2"
db eof
MsgF3: dm "F3"
db eof
Msg0: dm "0"
db eof
Msg9: dm "9"
db eof
Msg8: dm "8"
db eof
Msg7: dm "7"
db eof
Msg6: dm "6"
db eof
MsgMinus: dm "-"
db eof
MsgPlus: dm "PLUS"
db eof
MsgDel: dm "DELETE"
db eof
MsgP: dm "P"
db eof
MsgO: dm "O"
db eof
MsgI: dm "I"
db eof
MsgU: dm "U"
db eof
MsgY: dm "Y"
db eof
MsgEqu: dm "EQUALS"
db eof
MsgQuote: db 34
db eof
MsgF0: dm "F0"
db eof
MsgEnter: dm "ENTER"
db eof
MsgL: dm "L"
db eof
MsgK: dm "K"
db eof
MsgJ: dm "J"
db eof
MsgH: dm "H"
db eof
MsgSemi: dm "SEMICOLON"
db eof
MsgColon: dm ":"
db eof
MsgEdit: dm "EDIT"
db eof
MsgSpace: dm "SPACE"
db eof
MsgSym: dm "SYMBOL"
db eof
MsgM: dm "M"
db eof
MsgN: dm "N"
db eof
MsgB: dm "B"
db eof
MsgComma: dm ","
db eof
MsgFStop: dm "."
db eof
MsgInv: dm "INV"
db eof
MsgCtrl: dm "CONTROL"
db eof
MsgUp: dm "UP"
db eof
MsgDown: dm "DOWN"
db eof
MsgLeft: dm "LEFT"
db eof
MsgRight: dm "RIGHT"
db eof