-
Notifications
You must be signed in to change notification settings - Fork 1
/
redefinekeys.asm
132 lines (103 loc) · 2.48 KB
/
redefinekeys.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
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
.module REDEF
redefinekeys:
ld hl,dfile+$2b5 ; stash content at bottom of screen
ld de,offscreenmap+$2b5
ld bc,3*33
ldir
ld hl,REDEFDATA._pkf ; install 'press key for:' text
ld de,dfile+$2bf
ld bc,14
ldir
xor a ; clear key line
ld hl,dfile+$300
ld de,dfile+$301
ld (hl),a
ld bc,16
ldir
ld hl,REDEFDATA._upk ; input table index 0
call _redeffit
ld hl,REDEFDATA._dnk
call _redeffit
ld hl,REDEFDATA._lfk
call _redeffit
ld hl,REDEFDATA._rtk
call _redeffit
ld hl,REDEFDATA._frk
call _redeffit
ld hl,(fire-2) ; copy fire button definition to title screen input states
ld (begin-2),hl
ld hl,offscreenmap+$2b5 ; restore bottom of screen
ld de,dfile+$2b5
ld bc,3*33
ldir
ret
_redeffit:
ld a,(hl) ; input state array index
ld (REDEFDATA._ipindex),a
inc hl
sla a
sla a
ld de,inputstates ; inputstates must not straddle a page
add a,e
ld e,a
inc de
ld (REDEFDATA._keyaddress),de ; the input data we're altering
ld de,dfile+$306 ; copy key text to screen
ld bc,5
ldir
_redefloop:
call framesync
call getcolbit
cp $ff
jr z,_redefloop
xor $ff ; flip bits to create column mask
ld c,a ; column mask in c, port num in b from getcolbit
ld hl,inputstates+1
ld de,(REDEFDATA._keyaddress)
_testNext:
and a
sbc hl,de ; done when we are about to check the current input state
jr z,_oktogo
add hl,de ; otherwise check to see if port/mask combo is already used
ld a,(hl)
inc hl
cp b
jr nz,nomatchport
ld a,(hl)
cp c
jr nz,nomatchport
ld b,4 ; combo already used, warn user
-: call framesync
ld e,b
call invertscreen
ld b,e
djnz {-}
call _redefnokey
jr _redefloop
nomatchport:
inc hl
inc hl
inc hl
jr _testNext
_oktogo:
ld hl,(REDEFDATA._keyaddress)
ld (hl),b
inc hl
ld (hl),c
_redefnokey:
call framesync
call getcolbit
cp $ff
jr nz,_redefnokey
ret
getcolbit:
ld bc,$fefe
-: in a,(c) ; byte will have a 0 bit if a key is pressed
or $e0
cp $ff
ret nz
rlc b
jr c,{-}
ret