-
Notifications
You must be signed in to change notification settings - Fork 0
/
GhostBusterUNF.asm
658 lines (492 loc) · 16 KB
/
GhostBusterUNF.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
658
; ==============================================================================
pushpc
org $079B35 ; lended item code for shovel
JMP $AF3E ; Jump to byrna code ; QUAKE : JMP $A64B
org $1DFCB2
LDA #$90 ; number of frames it'll move out of the way
org $0FFD8A
JSL LendItem
org $1AFF1E
db #$10 ; npc is moved more to the left when coming from top
org $1DFD18 ; New digging game dude
JML NewDiggingDude
NOP #$03
DiggingReturn:
RTS
DiggingTimerDone:
org $0696DE ; new Poe Sprite (subtype)
JSL NewPoe
NOP #$02
org $1DFE4B
JML DustSpriteDraw ; LDA.b #$03 : STA $06
returnDraw:
org $1DFE6D
returnRTS:
org $07AF3E ; byrna ;org $07A64B ; quake medallion
JSL Vacuum
RTS
pullpc
; ==============================================================================
; New Item Use ( Vacuum )
LendItem:
{
JSL $07F1FA
STZ.w $1CDB ; set count to 00
STZ.w $1CF3 ; set numeric to 00
RTL
}
Vacuum:
{
;WTF IS THAT ?
;LDY.b #$0F
;--
;LDA.b #$00
;STA $0E40, Y
;DEY : BPL --
STZ.w $037A
STZ.w $0B7B
LDA.b $F0 : AND.b #$40 : BEQ .YNotPressed
STZ.b $26
STZ.b $68
STZ.b $69
STZ.b $6A
; put link into state 04 for item use (hookshot handle)
LDA.b #$04 : STA.w $037A
STA.w $0B7B
; Make some dust particles appears randomly in front of link and move towards link
; Use sprites because they're easier to work with
DEC.w $045F : BPL + ; Timer (If timer < 0)
LDA.b #$08 : STA.w $045F ; set timer back to 08
LDA.w $045E : CMP.b #$06 : BCS + ; if there is more than 6 dust sprite
INC.w $045E
LDA.b #$D5
JSL Sprite_SpawnDynamically ; never more than 6 at once
LDA #$1E : STA $012F
;$00 low x, $01 high x
;$02 low y, $03 high y
LDA.b #$02 : STA.w $0E30, Y ; subtype
LDA.b #$14 : STA.w $0E00, Y ; timer
LDA.b #$03 : STA.w $0E10, Y ; animtimer
LDA.b $2F : BNE .notUp
JSR vacuumup
BRA ++
.notUp
CMP #$02 : BNE .notDown
JSR vacuumdown
BRA ++
.notDown
CMP #$04 : BNE .notLeft
JSR vacuumleft
BRA ++
.notLeft
CMP #$06 : BNE .notRight
JSR vacuumright
.notRight
++
+
; gotta spawn it with an offset depending on direction
.YNotPressed
RTL
}
; ==============================================================================
vacuumup:
{
REP #$20
LDA.b $20 : SEC : SBC #$0020 : STA $00
JSL GetRandomInt : AND.w #$0007 : STA.b $02
LDA.b $22 : SEC : SBC #$0004 : CLC : ADC.b $02 : STA.b $02
SEP #$20
LDA.b $00 : STA.w $0D00, Y
LDA.b $01 : STA.w $0D20, Y
LDA.b $02 : STA.w $0D10, Y
LDA.b $03 : STA.w $0D30, Y
; Check if there's a ghost in front of link if so suck it in
; check all sprites
LDY.b #$0F
--
LDA.w $0E20, Y : CMP #$19 : BNE .notAPoe
LDA.w $0DD0, Y : CMP #$09 : BNE .spriteIsDead
; sprite is a poe and is not dead check if it's colliding
LDA.w $0D00, Y : STA $04 ; Y
LDA.w $0D20, Y : STA $05
LDA.w $0D10, Y : STA $06 ; X
LDA.w $0D30, Y : STA $07
REP #$20
LDA $20 ; Load player.Y position
CMP $04 : BCC .yishigher ; is it higher than sprite.Y
SEC : SBC #$0040 : CMP $04 : BCS .yislower
LDA $22 : SEC : SBC #$0008 : CMP $06 : BCS .xislower
LDA $22 : CLC : ADC #$0018 : CMP $06 : BCC .xishigher
; Collision happened here
SEP #$20
JSR CaptureGhost
.xishigher
.xislower
.yislower ; if link.Y was lower than Y+0x30 then no collision
.yishigher ; if link.Y was bigger then no collision
SEP #$20
.spriteIsDead
.notAPoe
DEY : BPL --
RTS
}
; ==============================================================================
vacuumdown:
{
REP #$20
LDA.b $20 : CLC : ADC #$0020 : STA $00
JSL GetRandomInt : AND.w #$0007 : STA.b $02
LDA.b $22 : SEC : SBC #$0004 : CLC : ADC.b $02 : STA.b $02
SEP #$20
LDA.b $00 : STA.w $0D00, Y
LDA.b $01 : STA.w $0D20, Y
LDA.b $02 : STA.w $0D10, Y
LDA.b $03 : STA.w $0D30, Y
; Check if there's a ghost in front of link if so suck it in
; check all sprites
LDY.b #$0F
--
LDA.w $0E20, Y : CMP #$19 : BNE .notAPoe
LDA.w $0DD0, Y : CMP #$09 : BNE .spriteIsDead
; sprite is a poe and is not dead check if it's colliding
LDA.w $0D00, Y : STA $04 ; Y
LDA.w $0D20, Y : STA $05
LDA.w $0D10, Y : STA $06 ; X
LDA.w $0D30, Y : STA $07
REP #$20
LDA $20 ; Load player.Y position
CMP $04 : BCS .yishigher ; is it higher than sprite.Y
CLC : ADC #$0050 : CMP $04 : BCC .yislower
LDA $22 : SEC : SBC #$0008 : CMP $06 : BCS .xislower
LDA $22 : CLC : ADC #$0018 : CMP $06 : BCC .xishigher
; Collision happened here
SEP #$20
JSR CaptureGhost
.xishigher
.xislower
.yislower ; if link.Y was lower than Y+0x30 then no collision
.yishigher ; if link.Y was bigger then no collision
SEP #$20
.spriteIsDead
.notAPoe
DEY : BPL --
RTS
}
; ==============================================================================
vacuumleft:
{
REP #$20
LDA.b $22 : SEC : SBC #$0020 : STA $00
JSL GetRandomInt : AND.w #$0007 : CLC : ADC #$0004 : STA.b $02
LDA.b $20 : CLC : ADC.b $02 : STA.b $02
SEP #$20
LDA.b $02 : STA.w $0D00, Y
LDA.b $03 : STA.w $0D20, Y
LDA.b $00 : STA.w $0D10, Y
LDA.b $01 : STA.w $0D30, Y
LDA.b #$08 : STA.w $0D50, X
; Check if there's a ghost in front of link if so suck it in
; check all sprites
LDY.b #$0F
--
LDA.w $0E20, Y : CMP #$19 : BNE .notAPoe
LDA.w $0DD0, Y : CMP #$09 : BNE .spriteIsDead
; sprite is a poe and is not dead check if it's colliding
LDA.w $0D00, Y : STA $04 ; Y
LDA.w $0D20, Y : STA $05
LDA.w $0D10, Y : STA $06 ; X
LDA.w $0D30, Y : STA $07
REP #$20
LDA $22 ; Load player.Y position
CMP $06 : BCC .yishigher ; is it higher than sprite.Y
SEC : SBC #$0040 : CMP $06 : BCS .yislower
LDA $20 : SEC : SBC #$0008 : CMP $04 : BCS .xislower
LDA $20 : CLC : ADC #$0018 : CMP $04 : BCC .xishigher
; Collision happened here
SEP #$20
JSR CaptureGhost
.xishigher
.xislower
.yislower ; if link.Y was lower than Y+0x30 then no collision
.yishigher ; if link.Y was bigger then no collision
SEP #$20
.spriteIsDead
.notAPoe
DEY : BPL --
RTS
}
; ==============================================================================
vacuumright:
{
REP #$20
LDA.b $22 : CLC : ADC #$0020 : STA $00
JSL GetRandomInt : AND.w #$0007 : CLC : ADC #$0004 : STA.b $02
LDA.b $20 : CLC : ADC.b $02 : STA.b $02
SEP #$20
LDA.b $02 : STA.w $0D00, Y
LDA.b $03 : STA.w $0D20, Y
LDA.b $00 : STA.w $0D10, Y
LDA.b $01 : STA.w $0D30, Y
LDA.b #$08 : STA.w $0D50, X
; Check if there's a ghost in front of link if so suck it in
; check all sprites
LDY.b #$0F
--
LDA.w $0E20, Y : CMP #$19 : BNE .notAPoe
LDA.w $0DD0, Y : CMP #$09 : BNE .spriteIsDead
; sprite is a poe and is not dead check if it's colliding
LDA.w $0D00, Y : STA $04 ; Y
LDA.w $0D20, Y : STA $05
LDA.w $0D10, Y : STA $06 ; X
LDA.w $0D30, Y : STA $07
REP #$20
LDA $22 ; Load player.Y position
CMP $06 : BCS .yishigher ; is it higher than sprite.Y
CLC : ADC #$0050 : CMP $06 : BCC .yislower
LDA $20 : SEC : SBC #$0008 : CMP $04 : BCS .xislower
LDA $20 : CLC : ADC #$0018 : CMP $04 : BCC .xishigher
; Collision happened here
SEP #$20
JSR CaptureGhost
.xishigher
.xislower
.yislower ; if link.Y was lower than Y+0x30 then no collision
.yishigher ; if link.Y was bigger then no collision
SEP #$20
.spriteIsDead
.notAPoe
DEY : BPL --
RTS
}
; ==============================================================================
CaptureGhost:
{
LDA.b #$18 : STA.w $0E10, Y ; reset timer
LDA.w $0DA0, Y : INC : STA.w $0DA0, Y : CMP.b #$08 : BCC .notCaptured
LDA #$2A : STA.w $012E
LDA.b #$06 : STA.w $0DD0, Y ; kill it for test code
LDA.b #$0F : STA.w $0DF0, Y
DEC.w $1CDB
INC $1CF3 ; Increase the count of ghost captured
LDA $1CF3
AND #$0F : CMP #$0A : BNE + ; have we reached 10? if so increase next nybble and set it back to 0
LDA.w $1CF3 : AND #$F0 : CLC : ADC #$10 : STA.w $1CF3
+
.notCaptured
RTS
}
; ==============================================================================
DustSpriteDraw:
{
LDA $0E30, X
CMP #$02 : BNE +++
PHB : PHK : PLB
JSR Sprite_Dust_Draw
LDA $0E10, X : BNE +
LDA.b #$03 : STA.w $0E10, X
INC.w $0DC0, X
+
LDA.b $2F : BNE .notUp
LDA.b #$12 : STA.w $0D40, X
BRA ++
.notUp
CMP #$02 : BNE .notDown
LDA.b #$EE : STA.w $0D40, X
BRA ++
.notDown
CMP #$04 : BNE .notLeft
LDA.b #$12 : STA.w $0D50, X
BRA ++
.notLeft
CMP #$06 : BNE .notRight
LDA.b #$EE : STA.w $0D50, X
.notRight
++
JSL Sprite_MoveLong
LDA.w $0E00, X : BNE +
STZ.w $0DD0, X
DEC.w $045E
+
PLB
; pop an RTS
PLA : PLA ; to end draw code
JML returnRTS ; to end sprite code
+++
LDA.b #$03 : STA $06
JML returnDraw
}
; ==============================================================================
; Sprite Draw code
; ==============================================================================
; Draw the tiles on screen with the data provided by the sprite maker editor
; ==============================================================================
Sprite_Dust_Draw:
{
JSL Sprite_PrepOamCoord
JSL Sprite_OAM_AllocateDeferToPlayer
LDA $0DC0, X : CLC : ADC $0D90, X : TAY;Animation Frame
LDA .start_index, Y : STA $06
PHX
LDX .nbr_of_tiles, Y ;amount of tiles -1
LDY.b #$00
.nextTile
PHX ; Save current Tile Index?
TXA : CLC : ADC $06 ; Add Animation Index Offset
PHA ; Keep the value with animation index offset?
ASL A : TAX
REP #$20
LDA $00 : CLC : ADC .x_offsets, X : STA ($90), Y
AND.w #$0100 : STA $0E
INY
LDA $02 : CLC : ADC .y_offsets, X : STA ($90), Y
CLC : ADC #$0010 : CMP.w #$0100
SEP #$20
BCC .on_screen_y
LDA.b #$F0 : STA ($90), Y ;Put the sprite out of the way
STA $0E
.on_screen_y
PLX ; Pullback Animation Index Offset (without the *2 not 16bit anymore)
INY
LDA .chr, X : STA ($90), Y
INY
LDA .properties, X : STA ($90), Y
PHY
TYA : LSR #2 : TAY
LDA .sizes, X : ORA $0F : STA ($92), Y ; store size in oam buffer
PLY : INY
PLX : DEX : BPL .nextTile
PLX
RTS
}
; ==============================================================================
; Sprite Draw Generated Data
; ==============================================================================
; This is where the generated Data for the sprite go
; ==============================================================================
.start_index
db $00, $01, $02, $03, $04, $05, $06, $07
.nbr_of_tiles
db 0, 0, 0, 0, 0, 0, 0, 0
.x_offsets
dw 0
dw 0
dw 0
dw 0
dw 4
dw 4
dw 4
dw 4
.y_offsets
dw 0
dw 0
dw 0
dw 0
dw 2
dw 4
dw 4
dw 4
.chr
db $86
db $86
db $86
db $86
db $8A
db $8B
db $9B
db $50
.properties
db $34
db $74
db $B4
db $F4
db $34
db $34
db $34
db $34
.sizes
db $02
db $02
db $02
db $02
db $00
db $00
db $00
db $00
; ==============================================================================
NewPoe:
{
LDA.w $0E30, X : CMP #$02 : BNE ++
; otherwise do not check for damage just float around waiting to be captured
LDA.w $0E10, X : BNE +
; if timer was equal 0 at some point set back ghost to normal state
STZ.w $0DA0, X ; will set back ghost to moving state
+
LDA.w $0DA0, X : BEQ +
; if it's not equal then ghost is being captured
; he's getting attracted to player
LDA #$08
JSL Sprite_ApplySpeedTowardsPlayer
+
REP #$20
LDA.w $0FD8 : CMP #$0AA0 : BCC .killghost
CMP #$0B70 : BCS .killghost
LDA.w $0FDA : CMP #$0A80 : BCC .killghost
CMP #$0B60 : BCS .killghost
SEP #$20
INC.w $0E80, X
RTL
++
;restore original code kinda
JSL Sprite_CheckDamageFromPlayer
JSL Sprite_CheckDamageToPlayer
INC.w $0E80, X
RTL
.killghost
SEP #$20
DEC.w $1CDB
STZ.w $0DD0, X
RTL
}
; ==============================================================================
NewDiggingDude:
{
LDA $04B4 : BEQ .timer_elapsed
BMI .timer_elapsed
LDA $1CDB : CMP #$04 : BCS +
INC.w $1CDB
LDA #$19
JSL Sprite_SpawnDynamically
LDA.b #$02 : STA.w $0E30, Y
REP #$20
JSL GetRandomInt : AND.w #$007F : CLC : ADC.w #$0AC0 : STA $02
JSL GetRandomInt : AND.w #$007F : CLC : ADC.w #$0AA0 : STA $00
SEP #$20
LDA $00 : STA $0D10, Y
LDA $01 : STA $0D30, Y
LDA $02 : STA $0D00, Y
LDA $03 : STA $0D20, Y
+
JML DiggingReturn
.timer_elapsed
LDA.b #$05 : STA $012C
INC $0D80, X
STZ.w $03FC
STZ.w $037A
STZ.w $0B7B
LDA $1CF3 : AND #$F0 : BNE .overTen ; Nbr of ghost in decimal
; "OK! Time's up, game over. Come back again. Good bye..."
;LDA.b #$8A : STA $1CF0
;LDA.b #$01 : JSR Sprite4_ShowMessageMinimal
%ShowUnconditionalMessage($18A)
JML DiggingReturn
.overTen
; do we already have the prize ?
%ShowUnconditionalMessage($18A)
LDA $7EF2AD : AND #$40 : BNE .alreadyhaveprize
LDY #$17
JSL Link_ReceiveItem
LDA $7EF2AD : ORA #$40 : STA $7EF2AD
.alreadyhaveprize
JML DiggingReturn
}
; ==============================================================================