-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweapon.asm
657 lines (519 loc) · 10.1 KB
/
weapon.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
draw_weapon
ld a, (weapon_active)
and a
ret z
ld a, (weapon_frame)
srl a
srl a
add a
ld c, a
ld b, 0
ld hl, (weapon_type)
add hl, bc
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; hl now pointing to frame specific info
ld (last_drawn_weapon_frame), hl
ex de, hl
ld ixh, d
ld ixl, e ; store this pointer in ix
ld a, (weapon_y)
add (ix + 3)
ld l, a
ld h, 0
add hl, hl
ld de, (scr_addr_table)
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
ld l, a
ld a, (weapon_x)
srl a
add (ix + 2)
ld c, a
ld b, 0
add hl, bc ; hl has screen address
; save ix and hl here so we don't need to calc again when erasing
ld a, (hidden_screen_base_address)
cp 0xc0
jr nz, store_weapon_with_80
ld (save_weapon_address_c0), hl
ld (save_weapon_pointer_c0), ix
jr draw_weapon_entry2
store_weapon_with_80
ld (save_weapon_address_80), hl
ld (save_weapon_pointer_80), ix
draw_weapon_entry2
ld b, (ix + 1) ; b has height
ld e, (ix + 6)
ld d, (ix + 7)
push de ; sprite routine to call
ld de, (ix + 4) ; de has graphics
ret ; draw sprite
erase_weapon
ld a, (hidden_screen_base_address)
cp 0xc0
jr nz, erase_weapon_with_80
ld hl, (save_weapon_address_c0)
ld de, (save_weapon_pointer_c0)
jr eraseweaponx
erase_weapon_with_80
ld hl, (save_weapon_address_80)
ld de, (save_weapon_pointer_80)
eraseweaponx
ld a, h
or l
ret z ; stop here if not yet set
ld ixh, d
ld ixl, e
call draw_weapon_entry2
ld a, (weapon_active)
and a
ret nz
jr reset_weapon2
kill_weapon_with_80
ld (save_weapon_address_80), hl
ret
reset_weapon
xor a
ld (weapon_active), a
reset_weapon2
ld hl, 0
ld (save_weapon_address_c0), hl
ld (save_weapon_address_80), hl
ret
fire_weapon
ld a, (weapon_active)
and a
ret nz
ld a, (fire_delay)
and a
jr z, can_fire
dec a
ld (fire_delay), a
ret
can_fire
ld e, sound_spell
call play_sfx
ld a, fire_decay
ld (weapon_active), a
ld a, (player_x)
ld (weapon_x), a
ld a, (player_y)
ld (weapon_y), a
ld a, (fire_direction)
ld de, 0x0000
bit player_left_bit, a
jr z, fire_right
ld d, -fire_horizontal_speed
fire_right
bit player_right_bit, a
jr z, fire_down
ld d, fire_horizontal_speed
fire_down
bit player_down_bit, a
jr z, fire_up
ld e, fire_vertical_speed
fire_up
bit player_up_bit, a
jr z, fire_checked
ld e, -fire_vertical_speed
fire_checked
ld a, d
or e
jr nz, something_fired
ld d, fire_horizontal_speed
something_fired
ld a, d
ld (weapon_x_inc), a
ld a, e
ld (weapon_y_inc), a
ret
move_weapon
ld a, (weapon_active)
and a
ret z
dec a
ld (weapon_active), a
and a
jr nz, move_weapon_2
ld a, 2
ld (fire_delay), a
move_weapon_2
ld a, (weapon_rotates)
and a
jr z, rotate_weapon
ld a, (weapon_x_inc) ; knights weapon faces direction of motion
and a
jr z, weapon_vertical
cp fire_horizontal_speed
jr z, weapon_moving_right
ld a, (weapon_y_inc) ; weapon moving left
and a
jr z, wml
cp fire_vertical_speed
jr z, wmdl
xor a
jr now_move_weapon
wml
ld a, 1 * 4
jr now_move_weapon
wmdl
ld a, 2 * 4
jr now_move_weapon
weapon_vertical
ld a, (weapon_y_inc)
cp fire_vertical_speed
jr z, wv1
ld a, 7 * 4
jr now_move_weapon
wv1
ld a, 3 * 4
jr now_move_weapon
weapon_moving_right
ld a, (weapon_y_inc) ; weapon moving left
and a
jr z, wmr
cp fire_vertical_speed
jr z, wmdr
ld a, 6 * 4
jr now_move_weapon
wmr
ld a, 5 * 4
jr now_move_weapon
wmdr
ld a, 4 * 4
jr now_move_weapon
rotate_weapon
ld a, (weapon_frame)
inc a
and 0x1f ; valid frames: 0 -> 31
now_move_weapon
ld (weapon_frame), a
ld a, (weapon_x_inc)
ld b, a
ld a, (weapon_x)
add b
ld (weapon_x), a
ld b, a ; b has updated weapon_x
ld a, (weapon_y_inc)
and a
ld c, a
ld a, (weapon_y)
add c
ld (weapon_y), a
ld c, a ; c has updated weapon_y
ld a, (min_x)
ld d, a
cp b
jr nc, bounce_weapon_x
ld a, (max_x)
ld d, a
cp b
jr nc, check_weapon_y
bounce_weapon_x
ld a, (weapon_x_inc)
neg
ld (weapon_x_inc), a
ld e, a
ld a, d
ld (weapon_x), a
ld a, e
and a
jr z, check_weapon_y
push bc
ld e, sound_spell_bounce
call play_sfx
pop bc
check_weapon_y
ld a, (min_y)
ld d, a
cp c
jr nc, bounce_weapon_y
ld a, (max_y)
ld d, a
cp c
ret nc
bounce_weapon_y
ld a, (weapon_y_inc)
neg
ld (weapon_y_inc), a
ld a, d
ld (weapon_y), a
play_bounce_sfx
ld e, sound_spell_bounce
jp play_sfx
weapon2
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc de
dec l
GET_NEXT_SCR_LINE
djnz weapon2
ret
weapon3
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc de
dec l
dec l
GET_NEXT_SCR_LINE
djnz weapon3
ret
weapon4
ld c, h
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc de
dec l
dec l
dec l
ld h, c
GET_NEXT_SCR_LINE
djnz weapon4
ret
check_weapon_hit
ld ix, (last_drawn_weapon_frame)
ld b, (ix + 2)
ld a, (weapon_x)
add b
ld h, a
ld c, (ix + 3)
ld a, (weapon_y)
add c
ld l, a ; h = weapon x, l = weapon y
ld d, (ix + 0)
ld e, (ix + 1) ; d weapon width, e = weapon height
ld ix, sprite1
call check_weapon_hitting_sprite
ld ix, sprite2
call check_weapon_hitting_sprite
ld ix, sprite3
check_weapon_hitting_sprite ; h = weapon x, l = weapon y, d = weapon width, e = weapon height, ix = sprite
ld a, (weapon_active)
and a
ret z
ld a, (ix + spr_state)
cp state_active
ret nz
push hl
push de
ld a, h
srl d
add d
ld c, a
ld a, (ix + 0)
ld b, (ix + 5)
srl b
add b
sub c
bit 7, a
jr z, not_neg_x_weapon
neg
not_neg_x_weapon
sla b
dec b
cp b
jr nc, end_weapon_hit_check
ld a, l
srl e
add e
ld c, a
ld a, (ix + 1)
ld b, (ix + 6)
srl b
add b
sub c
bit 7, a
jr z, not_neg_y_weapon
neg
not_neg_y_weapon
sla b
dec b
cp b
jr nc, end_weapon_hit_check
call kill_sprite
ld a, 1
ld (weapon_active), a
end_weapon_hit_check
pop de
pop hl
ret
weapon_type
defw spell_data
weapon_x
defb 0x38
weapon_y
defb 0x80
weapon_active
defb 0x00
weapon_x_inc
defb 0x00
weapon_y_inc
defb 0x00
weapon_frame
defb 0x00
weapon_rotates
defb 0x00
fire_delay
defb 0x00
last_drawn_weapon_frame
defw 0x00
save_weapon_address_c0
defw 0x00
save_weapon_pointer_c0
defw 0x00
save_weapon_address_80
defw 0x00
save_weapon_pointer_80
defw 0x00
sword_data
defw sword_frame7, sword_frame6
defw sword_frame5, sword_frame4
defw sword_frame3, sword_frame2
defw sword_frame1, sword_frame0
spell_data
defw spell_frame3, spell_frame2
defw spell_frame1, spell_frame0
defw spell_frame3, spell_frame2
defw spell_frame1, spell_frame0
axe_data
defw axe_frame7, axe_frame6
defw axe_frame5, axe_frame4
defw axe_frame3, axe_frame2
defw axe_frame1, axe_frame0
sword_frame0
defb 0x02, 0x10 ; width, height
defb 0x01, 0x00 ; offset x, offset y
defw weapon_sword_0 ; graphics data
defw weapon2 ; draw routine
sword_frame1
defb 0x03, 0x0b
defb 0x00, 0x03
defw weapon_sword_1
defw weapon3
sword_frame2
defb 0x04, 0x06
defb 0x00, 0x06
defw weapon_sword_2
defw weapon4
sword_frame3
defb 0x03, 0x0b
defb 0x00, 0x03
defw weapon_sword_3
defw weapon3
sword_frame4
defb 0x02, 0x10
defb 0x01, 0x00
defw weapon_sword_4
defw weapon2
sword_frame5
defb 0x03, 0x0b
defb 0x00, 0x02
defw weapon_sword_5
defw weapon3
sword_frame6
defb 0x04, 0x06
defb 0x00, 0x04
defw weapon_sword_6
defw weapon4
sword_frame7
defb 0x03, 0x0b
defb 0x00, 0x02
defw weapon_sword_7
defw weapon3
spell_frame0
defb 0x04, 0x0e
defb 0x00, 0x00
defw weapon_spell_0
defw weapon4
spell_frame1
defb 0x04, 0x0e
defb 0x00, 0x00
defw weapon_spell_1
defw weapon4
spell_frame2
defb 0x04, 0x0e
defb 0x00, 0x00
defw weapon_spell_2
defw weapon4
spell_frame3
defb 0x04, 0x0e
defb 0x00, 0x00
defw weapon_spell_3
defw weapon4
axe_frame0
defb 0x04, 0x07
defb 0x00, 0x04
defw weapon_axe_0
defw weapon4
axe_frame1
defb 0x04, 0x0b
defb 0x00, 0x02
defw weapon_axe_1
defw weapon4
axe_frame2
defb 0x02, 0x10
defb 0x01, 0x00
defw weapon_axe_2
defw weapon2
axe_frame3
defb 0x03, 0x0e
defb 0x00, 0x02
defw weapon_axe_3
defw weapon3
axe_frame4
defb 0x04, 0x07
defb 0x00, 0x04
defw weapon_axe_4
defw weapon4
axe_frame5
defb 0x04, 0x0b
defb 0x00, 0x04
defw weapon_axe_5
defw weapon4
axe_frame6
defb 0x02, 0x10
defb 0x01, 0x00
defw weapon_axe_6
defw weapon2
axe_frame7
defb 0x03, 0x0e
defb 0x00, 0x00
defw weapon_axe_7
defw weapon3