-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathReadInput.s
More file actions
410 lines (293 loc) · 9.55 KB
/
ReadInput.s
File metadata and controls
410 lines (293 loc) · 9.55 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
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
PLANE_PLAYER_WIDTH: equ 21
PLANE_PLAYER_HEIGHT: equ 31
PLANE_PLAYER_PIXELS_PER_MOV: equ 3
PLAYER_SIDE_MOVEMENT_CENTER: equ 128
PLAYER_SIDE_MOVEMENT_LIMIT: equ 20
PLAYER_SIDE_MOVEMENT_INTERMEDIATE: equ 10
KEYBOARD: equ 0
JOYSTICK: equ 1
ReadInput:
; read keyboard
ld a, 8 ; 8th line
call BIOS_SNSMAT ; Read Data Of Specified Line From Keyboard Matrix
ld e, a ; save value
push de
;ld a, e
bit 1, e ; 1st bit (HOME key)
call z, .pause
pop de
; if (Player_Controls_Enabled == 0) ret
ld a, (Player_Controls_Enabled)
or a
ret z
; if (Player_Tnput == KEYBOARD) readKeyboard; else readJoystick;
ld a, (Player_Tnput)
or a ; cp KEYBOARD
jp z, .readKeyboard
.readJoystick:
ld a, 1 ; read button A of joystick 1
call BIOS_GTTRIG
call nz, .shot
ld a, 3 ; read button B of joystick 1
call BIOS_GTTRIG
call nz, .bomb
ld a, 1 ; read direction of joystick 1
call BIOS_GTSTCK
ld e, a ; save value
ld c, 0 ; control variable to check left/right press
or a
jp z, .skipJoystickDirections ; if joystick status is 0 (no direction), skip checking directions
cp 7 ; joystick left
call z, .playerLeft
ld a, e
cp 3 ; joystick right
call z, .playerRight
ld a, e
cp 2 ; joystick up-right
call z, .playerUpRight
ld a, e
cp 4 ; joystick down-right
call z, .playerDownRight
ld a, e
cp 6 ; joystick down-left
call z, .playerDownLeft
ld a, e
cp 8 ; joystick up-left
call z, .playerUpLeft
.skipJoystickDirections:
; if neither left nor right pressed, slowly return Player_SideMovementCounter to 0
ld a, c
or a
call z, .playerNotPressedLeftRight
ld a, e
cp 1 ; joystick up
call z, .playerUp
ld a, e
cp 5 ; joystick down
call z, .playerDown
ret
.readKeyboard:
push de
bit 0, e ; 0th bit (space bar)
call z, .shot
pop de
push de
bit 3, e ; 3rd bit (DELETE key)
call z, .bomb
pop de
ld c, 0 ; control variable to check left/right press
; ld a, e
bit 4, e ; 4th bit (key left)
call z, .playerLeft
; ld a, e
bit 7, e ; 7th bit (key right)
call z, .playerRight
; if neither left nor right pressed, slowly return Player_SideMovementCounter to 0
ld a, c
or a
call z, .playerNotPressedLeftRight
; ld a, e
bit 5, e ; 5th bit (key up)
call z, .playerUp
; ld a, e
bit 6, e ; 6th bit (key down)
call z, .playerDown
ret
.playerLeft:
ld a, (Player_X)
sub PLANE_PLAYER_PIXELS_PER_MOV
cp 6
ret c
ld (Player_X), a
ld c, 1
ld a, (Player_SideMovementCounter)
cp PLAYER_SIDE_MOVEMENT_CENTER - PLAYER_SIDE_MOVEMENT_LIMIT
ret z
dec a
ld (Player_SideMovementCounter), a
; ; clear 7th bit (key right)
; ld a, e
; or 1000 0000b
; ld e, a
ret
.playerRight:
ld a, (Player_X)
add PLANE_PLAYER_PIXELS_PER_MOV
cp 255 - PLANE_PLAYER_WIDTH
ret nc
ld (Player_X), a
ld c, 1
ld a, (Player_SideMovementCounter)
cp PLAYER_SIDE_MOVEMENT_CENTER + PLAYER_SIDE_MOVEMENT_LIMIT
ret z
inc a
ld (Player_SideMovementCounter), a
; ; clear 4th bit (key left)
; ld a, e
; or 0001 0000b
; ld e, a
ret
.playerUpRight:
call .playerUp
call .playerRight
ret
.playerDownRight:
call .playerDown
call .playerRight
ret
.playerDownLeft:
call .playerDown
call .playerLeft
ret
.playerUpLeft:
call .playerUp
call .playerLeft
ret
.playerNotPressedLeftRight:
; if (Player_SideMovementCounter == 128) ret
ld a, (Player_SideMovementCounter)
cp 128
ret z
;If A < N, then S and P/V are different.
;A >= N, then S and P/V are the same.
; call m,label ;calls if S flag is set
; call p,label ;calls if S flag is reset
; call pe,label ;calls if P/V is set
; call po,label ;calls if P/V is reset
; if (Player_SideMovementCounter < 128) Player_SideMovementCounter++
jp c, .playerNotPressedLeftRight.lessThan ; if (a < n)
; else if (Player_SideMovementCounter > 128) Player_SideMovementCounter-- (== 128 has been blocked before)
jp nc, .playerNotPressedLeftRight.greaterThan ; if (a >= n)
ret ; TODO: WARNING: this line will never be reached
.playerNotPressedLeftRight.lessThan:
inc a
ld (Player_SideMovementCounter), a
ret
.playerNotPressedLeftRight.greaterThan:
dec a
ld (Player_SideMovementCounter), a
ret
.playerUp:
ld a, (Player_Y_Static)
sub PLANE_PLAYER_PIXELS_PER_MOV
ret c
ld (Player_Y_Static), a
ld a, (Player_Y)
sub PLANE_PLAYER_PIXELS_PER_MOV
ld (Player_Y), a
ret
.playerDown:
ld a, (Player_Y_Static)
add PLANE_PLAYER_PIXELS_PER_MOV
cp 191 - PLANE_PLAYER_HEIGHT
ret nc
ld (Player_Y_Static), a
ld a, (Player_Y)
add PLANE_PLAYER_PIXELS_PER_MOV
ld (Player_Y), a
ret
.shot:
; get next shot struct addr
ld hl, (NextShot_Struct_Addr)
call PlayerShot_Init
;ld a, 100 ; volume
ld a, SFX_SHOT ; number of sfx in the bank
ld c, 15 ; sound priority
call PlaySfx
ret
.bomb:
; if(Player_BombActive != 0) return;
ld a, (Player_BombActive)
or a
ret nz
; if(Player_BombsNumber == 0) return;
ld a, (Player_BombsNumber)
or a
ret z
; --- Init player bomb
; Player_BombActive = 1;
ld a, 1
ld (Player_BombActive), a
; Player_BombsNumber--;
ld hl, Player_BombsNumber
dec (hl)
; Player_Bomb_Y = 192 + VerticalScroll;
ld a, (VerticalScroll)
ld b, 192
add b
ld (Player_Bomb_Y), a
ld a, 192
ld (Player_Bomb_Y_Static), a
; reset all enemy shots
ld hl, EnemyShot_0_Struct
call EnemyShot_Reset
ld hl, EnemyShot_1_Struct
call EnemyShot_Reset
ld hl, EnemyShot_2_Struct
call EnemyShot_Reset
ld hl, EnemyShot_3_Struct
call EnemyShot_Reset
ld hl, EnemyShot_4_Struct
call EnemyShot_Reset
ld hl, EnemyShot_5_Struct
call EnemyShot_Reset
ld hl, EnemyShot_6_Struct
call EnemyShot_Reset
; ---- set SPRPAT data for player bomb (overwrite enemy shots sprite, as there are no enemy shots when player bomb is active)
; set MegaROM page for Sprite Patterns data
ld a, SPRITE_PATTERNS_DATA_MEGAROM_PAGE
; ld (Seg_P8000_SW), a
call Set_and_Save_MegaROM_Page
ld a, 0000 0001 b
ld hl, SPRPAT + (32 * 10) ; Sprite pattern #10
call SetVdp_Write
ld c, PORT_0
ld hl, SpritePattern_PlayerShot_Fat
; 32x outi
call OUTI_x32
; outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
; outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
; ---- set SPRCOL data for player bomb (sprites #24 to #30 of SPRATR)
ld a, 0000 0001 b
ld hl, SPRCOL + (16 * 24) ; Sprite color #24
call SetVdp_Write
ld c, PORT_0
ld a, 13 ; color
ld b, 7 * 16 ; 7 sprites
.loop_10:
out (c), a
; dec b
; jp nz, .loop_10
djnz .loop_10
ret
.pause:
; restore default palette (one blue color is constantly being changed)
ld hl, PaletteData_0
call LoadPalette
.pause_loop:
; do pause animation
call PauseAnimation
; check if HOME key was released
ld a, 8 ; 8th line
call BIOS_SNSMAT ; Read Data Of Specified Line From Keyboard Matrix
bit 1, a ; 1st bit (HOME key)
jp z, .pause_loop
.pause_endloop:
; do pause animation
call PauseAnimation
; check if HOME key was pressed again (end pause)
ld a, 8 ; 8th line
call BIOS_SNSMAT ; Read Data Of Specified Line From Keyboard Matrix
bit 1, a ; 1st bit (HOME key)
jp nz, .pause_endloop
.pause_loop_1:
; do pause animation
call PauseAnimation
; check if HOME key was released again
ld a, 8 ; 8th line
call BIOS_SNSMAT ; Read Data Of Specified Line From Keyboard Matrix
bit 1, a ; 1st bit (HOME key)
jp z, .pause_loop_1
; end pause
call EndPauseAnimation
ret