-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypad_editor.asm
301 lines (266 loc) · 6.44 KB
/
keypad_editor.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
#include p18f87k22.inc
#include constants.inc
global editor_keypad
extern add_tiny_delay, enable_bit, player_gridhex
extern player_x, player_y, player_gridhex, draw_player
extern gamestate, editor_mode, final_hex, keypad_input
acs0 udata_acs ; reserve data space in access ram
tmp_gridvalue res 1
tmp_element res 1
keypad_editor code
editor_keypad
call keypad_input
call checkdown
rejoin
call keypad_input
call checkup
return
checkdown
; Checks for button-press-down for : 2,4,6,8,1. Calls second check to prevent
; microprocessor from registering multiple presses with enable bit.
; Also checks for A,B,C,D,#,0 but without second checks (not needed)
movff final_hex, PORTH ; UP
movlw 0xB7
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
bra second_check_up
btfsc STATUS, Z
return
movff final_hex, PORTH ; DOWN
movlw 0xBD
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
bra second_check_down
btfsc STATUS, Z
return
movff final_hex, PORTH ; RIGHT
movlw 0xDB
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
bra second_check_right
btfsc STATUS, Z
return
movff final_hex, PORTH ; LEFT
movlw 0x7B
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
bra second_check_left
btfsc STATUS, Z
return
movff final_hex, PORTH ; A button
movlw 0xE7
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
call destroy
btfsc STATUS, Z
return
movff final_hex, PORTH ; B button
movlw 0xEB
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
call place_wall
btfsc STATUS, Z
return
movff final_hex, PORTH ; C button
movlw 0xED
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
call place_item
btfsc STATUS, Z
return
movff final_hex, PORTH ; D button
movlw 0xEE
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
call place_goal
btfsc STATUS, Z
return
movff final_hex, PORTH ; # button
movlw 0xDE
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
call place_fire
btfsc STATUS, Z
return
movff final_hex, PORTH ; 0 button
movlw 0xBE
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
call set_gamestate1
btfsc STATUS, Z
return
movff final_hex, PORTH ; 7 button (currently redundant)
movlw 0x7D
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
bra second_check_1
btfsc STATUS, Z
return
return
checkup
; Resets enable bit to allow buttons to be pressed again
movff final_hex, PORTH
movlw 0xFF
xorwf final_hex, 0 ; subtract, store in W. Status bit Z 1 if same
btfsc STATUS, Z
movlw 0x04
btfsc STATUS, Z
movwf enable_bit
return
return
SecondChecks
second_check_up
movf STATUS, W
andwf enable_bit, 0 ; if TRUE AND TRUE, Z bit is 0 else 1
btfss STATUS, Z
call move_up
return
second_check_down
movf STATUS, W
andwf enable_bit, 0 ; if TRUE AND TRUE, Z bit is 0 else 1
btfss STATUS, Z
call move_down
return
second_check_right
movf STATUS, W
andwf enable_bit, 0 ; if TRUE AND TRUE, Z bit is 0 else 1
btfss STATUS, Z
call move_right
return
second_check_left
movf STATUS, W
andwf enable_bit, 0 ; if TRUE AND TRUE, Z bit is 0 else 1
btfss STATUS, Z
call move_left
return
second_check_1
movf STATUS, W
andwf enable_bit, 0 ; if TRUE AND TRUE, Z bit is 0 else 1
btfss STATUS, Z
call editor_mode
return
Movement
; Movement routines for the map editor. All movements ignore walls but NOT boundaries
; of the map. No collisions with walls, items, goals etc.
move_up
movlw 0x00
movwf enable_bit
movlw 0x07
addwf player_gridhex, F ; Store new position in F
movf player_gridhex, W ; Extract to W to check
movff PLUSW1, tmp_gridvalue ; Retrieve current map element after moving
movlw 0x0F
cpfseq tmp_gridvalue ; Compare if current map element is a boundary(0x0F)
bra continue_draw_up
bra undo_move_up
continue_draw_up
movlw 0x1B
addwf player_y, 1
call draw_player
return
undo_move_up
movlw 0x07
subwf player_gridhex, F ; since collided with boundary, move back
call draw_player
return
move_down
movlw 0x00
movwf enable_bit
movlw 0x07
subwf player_gridhex, F ; store new position in F
movf player_gridhex, W ; Extract to W to check
movff PLUSW1, tmp_gridvalue ; Retrieve current map element after moving
movlw 0x0F
cpfseq tmp_gridvalue ; Compare if current map element is a boundary(0x0F)
bra continue_draw_down
bra undo_move_down
continue_draw_down
movlw 0x1B
subwf player_y, 1
call draw_player
return
undo_move_down
movlw 0x07
addwf player_gridhex, F ; since collided with boundary, move back
call draw_player
return
move_left
movlw 0x00
movwf enable_bit
movlw 0x01
subwf player_gridhex, F ; store new position in F
movf player_gridhex, W ; Extract to W to check
movff PLUSW1, tmp_gridvalue ; Retrieve current map element after moving
movlw 0x0F
cpfseq tmp_gridvalue
bra continue_draw_left
bra undo_move_left
continue_draw_left
movlw 0x1B
subwf player_x, 1
call draw_player
return
undo_move_left
movlw 0x01
addwf player_gridhex, F
call draw_player
return
move_right
movlw 0x00
movwf enable_bit
movlw 0x01
addwf player_gridhex, F ; store new position in F
movf player_gridhex, W ; Extract to W to check
movff PLUSW1, tmp_gridvalue ; Retrieve current map element after moving
movlw 0x0F
cpfseq tmp_gridvalue
bra continue_draw_right
bra undo_move_right
continue_draw_right
movlw 0x1B
addwf player_x, 1
call draw_player
return
undo_move_right
movlw 0x01
subwf player_gridhex, F
call draw_player
return
Actions
; Actions performed by the map editor to place walls, items, goal(s) etc.
; Press button 1 to revert to play mode (gamestate 1).
destroy ; A button
movlw 0x00
movwf tmp_element
movf player_gridhex, W
movff tmp_element, PLUSW1
return
place_wall ; B button
movlw wall
movwf tmp_element
movf player_gridhex, W
movff tmp_element, PLUSW1
return
place_item ; C button
movlw item
movwf tmp_element
movf player_gridhex, W
movff tmp_element, PLUSW1
return
place_goal ; D button
movlw goal
movwf tmp_element
movf player_gridhex, W
movff tmp_element, PLUSW1
return
place_fire ; # button
movlw fire
movwf tmp_element
movf player_gridhex, W
movff tmp_element, PLUSW1
return
set_gamestate1 ; 0 button
movlw 0x01
movwf gamestate
return
end