-
Notifications
You must be signed in to change notification settings - Fork 53
/
inventory.asm
774 lines (699 loc) · 25.8 KB
/
inventory.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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
;================================================================================
; Inventory Updates
;================================================================================
;--------------------------------------------------------------------------------
; ProcessMenuButtons:
; out: Carry - 0 = No Button, 1 = Yes Button
;--------------------------------------------------------------------------------
ProcessMenuButtons:
LDA.b Joy1A_New : BIT.b #$40 : BNE .y_pressed ; check for P1 Y-button
BIT.b #$20 : BNE .sel_pressed ; check for P1 Select button
LDA.b Joy1A_All : BIT.b #$20 : BNE .sel_held
.sel_unheld
LDA.l HudFlag : AND.b #$60 : BEQ +
LDA.b #$00 : STA.l HudFlag
JSL.l MaybePlaySelectSFX
+
JSL.l ResetEquipment
+
.sel_held
CLC ; no buttons
RTL
.sel_pressed
LDA.l HUDDungeonItems : BIT.b #$0C : BNE +
LDA.b #$40
BRA .store_flag
+
LDA.b #$60
.store_flag
STA.l HudFlag
JSL.l MaybePlaySelectSFX
JSL.l ResetEquipment
RTL
.y_pressed ; Note: used as entry point by quickswap code. Must preserve X.
LDA.b #$10 : STA.w MenuBlink
LDA.w ItemCursor ; check selected item
CMP.b #$02 : BNE + ; boomerang
LDA.l InventoryTracking : AND.b #$C0 : CMP.b #$C0 : BNE .errorJump ; make sure we have both boomerangs
LDA.l BoomerangEquipment : EOR.b #$03 : STA.l BoomerangEquipment ; swap blue & red boomerang
LDA.b #$20 : STA.w SFX3 ; menu select sound
JMP .captured
+ CMP.b #$01 : BNE + ; bow
LDA.l BowTracking : AND.b #$C0 : CMP.b #$C0 : BNE .errorJump ; make sure we have both bows
PHX : LDX.b #$00 ; scan ancilla table for arrows
-- : CPX.b #$0A : !BGE ++
LDA.w AncillaID, X : CMP.b #$09 : BNE +++
PLX : BRA .errorJump2 ; found an arrow, don't allow the swap
+++
INX : BRA -- : ++
PLX
LDA.l SilverArrowsUseRestriction : BEQ ++
LDA.b RoomIndex : ORA.b RoomIndex+1 : BEQ ++ ; not in ganon's room in restricted mode
LDA.l BowEquipment : CMP.b #$03 : !BLT .errorJump : !SUB #$02 : STA.l BowEquipment
BRA .errorJump2
++
LDA.l BowEquipment : !SUB #$01 : EOR.b #$02 : !ADD #$01 : STA.l BowEquipment ; swap bows
LDA.b #$20 : STA.w SFX3 ; menu select sound
JMP .captured
+ BRA +
.errorJump
BRA .errorJump2
+ CMP.b #$05 : BNE + ; powder
LDA.l InventoryTracking : AND.b #$30 : CMP.b #$30 : BNE .errorJump ; make sure we have mushroom & magic powder
LDA.l PowderEquipment : EOR.b #$03 : STA.l PowderEquipment ; swap mushroom & magic powder
LDA.b #$20 : STA.w SFX3 ; menu select sound
JMP .captured
+ BRA +
.errorJump2
BRA .error
+ CMP.b #$0D : BNE + ; flute
LDA.w UseY2 : CMP.b #$01 : BEQ .midShovel ; inside a shovel animation, force the shovel & make error sound
LDA.l InventoryTracking : BIT.b #$04 : BEQ .error ; make sure we have shovel
AND.b #$03 : BEQ .error ; make sure we have one of the flutes
LDA.l FluteEquipment : CMP.b #01 : BNE .toShovel ; not shovel
LDA.l InventoryTracking : AND.b #$01 : BEQ .toFakeFlute ; check for real flute
LDA.b #$03 ; set real flute
BRA .fluteSuccess
.toFakeFlute
LDA.b #$02 ; set fake flute
BRA .fluteSuccess
.toShovel
LDA.b #$01 ; set shovel
.fluteSuccess
STA.l FluteEquipment ; store set item
LDA.b #$20 : STA.w SFX3 ; menu select sound
BRA .captured
+
CMP.b #$10 : BNE .error : JSL.l ProcessBottleMenu : BRA .captured : +
CLC
RTL
.midShovel
.error
LDA.b #$3C : STA.w SFX2 ; error sound
.captured
SEC
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
;ProcessBottleMenu:
;--------------------------------------------------------------------------------
ProcessBottleMenu:
LDA.l BottleIndex ; check bottle state
BEQ .no_bottles ; skip if we have no bottles
PHX
INC : CMP.b #$05 : !BLT + : LDA.b #$01 : + ;increment and wrap 1-4
TAX : LDA.l BottleContents-1, X ; check bottle
BNE + : LDX.b #$01 : + ; wrap if we reached the last bottle
TXA : STA.l BottleIndex ; set bottle index
LDA.b #$20 : STA.w SFX3 ; menu select sound
PLX
.no_bottles
LDA.b #$00 ; pretend like the controller state was 0 from the overridden load
RTL
;--------------------------------------------------------------------------------
;OpenBottleMenu:
;--------------------------------------------------------------------------------
OpenBottleMenu:
LDA.b Joy1B_New : AND.b #$40 : BEQ .x_not_pressed ; skip if X is not down
LDA.b #$10 : STA.w MenuBlink ; set 16 frame cool off
LDA.b #$20 : STA.w SFX3 ; make menu sound
LDA.b #$07 : STA.w SubModuleInterface ; thing we wrote over - opens bottle menu
.x_not_pressed
RTL
;--------------------------------------------------------------------------------
;CloseBottleMenu:
;--------------------------------------------------------------------------------
CloseBottleMenu:
LDA.b Joy1B_New : AND.b #$40 : BEQ .x_not_pressed ; skip if X is not down
LDA.b #$10 : STA.w MenuBlink ; set 16 frame cool off
LDA.b #$20 : STA.w SFX3 ; make menu sound
INC.w SubModuleInterface ; return to normal menu
STZ.w BottleMenuCounter
LDA.b #$00
RTL
.x_not_pressed
LDA.b Joy1A_New : AND.b #$0C ; thing we wrote over (probably)
RTL
;--------------------------------------------------------------------------------
; AddInventory:
;--------------------------------------------------------------------------------
AddInventory:
; In: Y - Receipt ID
; Uses $0B-$0D for long absolute addressing
PHA : PHX : PHY : PHP : PHB
PHK : PLB
LDA.b #$7E : STA.b Scrap0D
LDA.l StatsLocked : BNE .done
REP #$30
TYA : AND.w #$00FF : ASL : TAX
SEP #$20
LDA.w InventoryTable_properties,X : BIT.b #$01 : BEQ .done
JSR.w ShopCheck : BCS .done
JSR.w DungeonIncrement : BCS .done
JSR.w IncrementByOne
JSR.w StampItem
JSR.w IncrementYAItems
REP #$30
LDA.l TotalItemCounter : INC : TAY
LDA.l BootsEquipment : AND.w #$00FF : BNE +
TYA : STA.l PreBootsLocations
+
LDA.l MirrorEquipment : AND.w #$00FF : BNE +
TYA : STA.l PreMirrorLocations
+
LDA.l FluteEquipment : AND.w #$00FF : BNE +
TYA : STA.l PreFluteLocations
+
TYA
STA.l TotalItemCounter
.done
SEP #$30
PLB : PLP : PLY : PLX : PLA
RTL
ShopCheck:
; In: X - Receipt ID << 1
; TODO: If we write all shops, we can use the ShopPurchase flag instead of this
PHX
LDA.b IndoorsFlag : BEQ .count
LDA.w ItemReceiptMethod : CMP.b #$01 : BEQ .count
LDA.w InventoryTable_properties,X : BIT.b #$02 : BNE .count
REP #$20
LDA.b RoomIndex
CMP.w #274 : BEQ .nocount ; dark world death mountain shop, ornamental shield shop
CMP.w #271 : BEQ .nocount ; villiage of outcasts shop, lumberjack shop, lake hylia shop, dark world magic shop
CMP.w #272 : BEQ .nocount ; red shield shop
CMP.w #284 : BEQ .nocount ; bomb shop
CMP.w #287 : BEQ .nocount ; kakariko shop
CMP.w #255 : BEQ .nocount ; light world death mountain shop
CMP.w #276 : BEQ .nocount ; waterfall fairy
CMP.w #277 : BEQ .nocount ; upgrade fairy (shop)
CMP.w #278 : BEQ .nocount ; pyramid fairy
SEP #$20
.count
CLC
PLX
RTS
.nocount
SEP #$21
PLX
RTS
DungeonIncrement:
; In: X - Receipt ID << 1
PHX
LDA.w InventoryTable_properties,X : BIT.b #$40 : BEQ +
JSL.l CountChestKeyLong
+
SEP #$10
LDA.b IndoorsFlag : BEQ .done
LDA.w DungeonID : BMI .done
CMP.l BallNChainDungeon : BNE +
CPY.b #$32 : BEQ .ballchain_bigkey
+
CMP.b #$04 : BCS +
LDA.l SewersLocations : INC : STA.l SewersLocations : STA.l HCLocations
BRA .done
+
LSR : TAX
LDA.l DungeonLocationsChecked, X : INC : STA.l DungeonLocationsChecked, X
CPX.b #$0D : BNE +
LDA.l BigKeyField : BIT.b #$04 : BNE ++
LDA.l PreGTBKLocations : INC : STA.l PreGTBKLocations
++
+
.done
REP #$11
PLX
RTS
.ballchain_bigkey
REP #$10
PLX
SEC
RTS
StampItem:
REP #$30
LDA.w InventoryTable_stamp,X : BEQ .skip
STA.b Scrap0B
LDA.b [Scrap0B] : BNE .skip
INC.b Scrap0B : INC.b Scrap0B
LDA.b [Scrap0B] : BNE .skip
LDA.l NMIFrames+2 : STA.b [Scrap0B]
DEC.b Scrap0B : DEC.b Scrap0B
LDA.l NMIFrames : STA.b [Scrap0B]
.skip
SEP #$20
RTS
IncrementYAItems:
PHX
LDA.w InventoryTable_properties,X
BIT.b #$10 : BNE .bomb_check
BIT.b #$20 : BNE .bow_check
BIT.b #$04 : BEQ .not_y
.y_item
LDA.l YAItemCounter : !ADD #$08 : STA.l YAItemCounter
BRA .done
.not_y
BIT.b #$08 : BEQ .done
.a_item
LDA.l YAItemCounter : INC : AND.b #$07 : TAX
LDA.l YAItemCounter : AND.b #$F8 : STA.l YAItemCounter
TXA : ORA.l YAItemCounter : STA.l YAItemCounter
.done
PLX
RTS
.bow_check
LDA.l BowEquipment : BNE +
BRA .y_item
.bomb_check
LDA.l InventoryTracking+1 : BIT.b #$02 : BNE +
ORA.b #$02 : STA.l InventoryTracking+1
BRA .y_item
+
PLX
RTS
IncrementByOne:
PHX
REP #$20
LDA.w InventoryTable_stat,X : BEQ .skip
STA.b Scrap0B
SEP #$21
LDA.b #$00 : ADC.b [Scrap0B] : STA.b [Scrap0B]
.skip
SEP #$20
PLX
RTS
IncrementBossSword:
PHX
LDA.l StatsLocked : BNE .done
LDA.l SwordEquipment : CMP.b #$FF : BNE +
BRA .none
+
ASL : TAX
JMP.w (.vectors,X)
.vectors
dw .none
dw .fighter
dw .master
dw .tempered
dw .golden
.none
LDA.l SwordlessBossKills : INC : STA.l SwordlessBossKills
.done
PLX
RTL
.fighter
LDA.l SwordBossKills
CLC : ADC.b #$10
STA.l SwordBossKills
PLX
RTL
.master
LDA.l SwordBossKills : INC : AND.b #$0F : TAX
LDA.l SwordBossKills : AND.b #$F0 : STA.l SwordBossKills
TXA : ORA.l SwordBossKills : STA.l SwordBossKills
PLX
RTL
.tempered
LDA.l SwordBossKills+1
CLC : ADC.b #$10
STA.l SwordBossKills+1
PLX
RTL
.golden
LDA.l SwordBossKills+1 : INC : AND.b #$0F : TAX
LDA.l SwordBossKills+1 : AND.b #$F0 : STA.l SwordBossKills+1
TXA : ORA.l SwordBossKills+1 : STA.l SwordBossKills+1
PLX
RTL
;--------------------------------------------------------------------------------
IncrementFinalSword:
PHX
REP #$20
LDA.w RoomIndex : BNE .done
SEP #$20
LDA.l SwordEquipment : CMP.b #$FF : BNE +
BRA IncrementBossSword_none
+
ASL : TAX
JMP.w (IncrementBossSword_vectors,X)
.done
SEP #$20
PLX
RTL
;--------------------------------------------------------------------------------
Link_ReceiveItem_HUDRefresh:
LDA.l BombsEquipment : BNE + ; skip if we have bombs
LDA.l BombCapacity : BEQ + ; skip if we can't have bombs
LDA.l BombsFiller : BEQ + ; skip if we are filling no bombs
DEC : STA.l BombsFiller ; decrease bomb fill count
LDA.b #$01 : STA.l BombsEquipment ; increase actual bomb count
+
JSL.l HUD_RefreshIconLong ; thing we wrote over
LDA.b #$01 : STA.l UpdateHUDFlag
JSL.l PostItemGet
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; HandleBombAbsorbtion:
;--------------------------------------------------------------------------------
HandleBombAbsorbtion:
STA.l BombsFiller ; thing we wrote over
LDA.w CurrentYItem : BNE + ; skip if we already have some item selected
LDA.l BombCapacity : BEQ + ; skip if we can't have bombs
LDA.b #$04 : STA.w ItemCursor ; set selected item to bombs
LDA.b #$01 : STA.w CurrentYItem ; set selected item to bombs
JSL.l HUD_RebuildLong
LDA.b #$01 : STA.l UpdateHUDFlag
+
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; AddYMarker:
;--------------------------------------------------------------------------------
AddYMarker:
LDA.w ItemCursor : AND.w #$FF ; load item value
CMP.w #$02 : BNE + ; boomerang
LDA.l InventoryTracking : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$01 : BNE + ; bow
LDA.l BowTracking : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$05 : BNE + ; powder
LDA.l InventoryTracking : AND.w #$30 : CMP.w #$30 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$0D : BNE + ; flute
LDA.l InventoryTracking : BIT.w #$04 : BEQ .drawNormal ; make sure we have shovel
AND.w #$03 : BNE .drawYBubble ; make sure we have one of the flutes
BRA .drawNormal
+ CMP.w #$10 : BEQ .drawJarMarker
.drawNormal
LDA.w #$7C60
BRA .drawTile
.drawJarMarker
LDA.w MenuBlink : AND.w #$0020 : BNE .drawXBubble
.drawYBubble
LDA.w #$3D4F
BRA .drawTile
.drawXBubble
JSR MakeCircleBlue
LDA.w #$2D3E
.drawTile
STA.w $FFC4, Y
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; MakeCircleBlue
; this is horrible, make it better
;--------------------------------------------------------------------------------
MakeCircleBlue:
LDA.w $FFC0, Y : AND.w #$EFFF : STA.w $FFC0, Y
LDA.w $FFC2, Y : AND.w #$EFFF : STA.w $FFC2, Y
LDA.w $FFFE, Y : AND.w #$EFFF : STA.w $FFFE, Y
LDA.w $0004, Y : AND.w #$EFFF : STA.w $0004, Y
LDA.w $003E, Y : AND.w #$EFFF : STA.w $003E, Y
LDA.w $0044, Y : AND.w #$EFFF : STA.w $0044, Y
LDA.w $0080, Y : AND.w #$EFFF : STA.w $0080, Y
LDA.w $0082, Y : AND.w #$EFFF : STA.w $0082, Y
LDA.w $FFBE, Y : AND.w #$EFFF : STA.w $FFBE, Y
LDA.w $FFC4, Y : AND.w #$EFFF : STA.w $FFC4, Y
LDA.w $0084, Y : AND.w #$EFFF : STA.w $0084, Y
LDA.w $007E, Y : AND.w #$EFFF : STA.w $007E, Y
RTS
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; UpgradeFlute:
;--------------------------------------------------------------------------------
UpgradeFlute:
LDA.l InventoryTracking : AND.b #$FC : ORA.b #$01 : STA.l InventoryTracking ; switch to the working flute
LDA.b #$03 : STA.l FluteEquipment ; upgrade primary inventory
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; CheckKeys:
;--------------------------------------------------------------------------------
CheckKeys:
LDA.l GenericKeys : BEQ + : RTL : +
LDA.w DungeonID : CMP.b #$FF
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; DrawKeyIcon:
;--------------------------------------------------------------------------------
DrawKeyIcon:
LDA.b Scrap04 : AND.w #$00FF : CMP.w #$0090 : BNE + : LDA.w #$007F : + : ORA.w #$2400 : STA.l HUDKeyDigits
LDA.b Scrap05 : AND.w #$00FF : ORA.w #$2400 : STA.l HUDTileMapBuffer+$66
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; LoadKeys:
;--------------------------------------------------------------------------------
LoadKeys:
LDA.l GenericKeys : BEQ +
LDA.l CurrentGenericKeys
RTL
+
LDA.l DungeonKeys, X
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; SaveKeys:
;--------------------------------------------------------------------------------
SaveKeys:
PHA
LDA.l GenericKeys : BEQ +
PLA : STA.l CurrentGenericKeys
RTL
+
PLA : STA.l DungeonKeys, X
CPX.b #$00 : BNE +
STA.l HyruleCastleKeys ; copy HC to sewers
+
CPX.b #$01 : BNE +
STA.l SewerKeys ; copy sewers to HC
+
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; ClearOWKeys:
;--------------------------------------------------------------------------------
ClearOWKeys:
PHA
JSL.l TurtleRockEntranceFix
JSL.l FakeWorldFix
JSL.l FixBunnyOnExitToLightWorld
LDA.l GenericKeys : BEQ +
PLA : LDA.l CurrentGenericKeys : STA.l CurrentSmallKeys
RTL
+
PLA : STA.l CurrentSmallKeys
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; PrepItemScreenBigKey:
;--------------------------------------------------------------------------------
PrepItemScreenBigKey:
STZ.b Scrap02
STZ.b Scrap03
REP #$30 ; thing we wrote over - set 16-bit accumulator
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; LoadPowder:
;--------------------------------------------------------------------------------
LoadPowder:
PHX
JSL.l Sprite_SpawnDynamically ; thing we wrote over
%GetPossiblyEncryptedItem(WitchItem, SpriteItemValues)
JSL.l AttemptItemSubstitution
JSL.l ResolveLootIDLong
STA.w SpriteID, Y
TYX
JSL.l PrepDynamicTile_loot_resolved
PLX
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; InitializeBottles:
;--------------------------------------------------------------------------------
InitializeBottles:
STA.l BottleContents, X ; thing we wrote over
PHA
LDA.l BottleIndex : BNE +
TXA : INC : STA.l BottleIndex ; write bottle index to menu properly
+
PLA
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; DrawPowder:
;--------------------------------------------------------------------------------
DrawPowder:
LDA.w ItemReceiptPose : BNE .defer ; defer if link is buying a potion
LDA.l RedrawFlag : BEQ +
; LDA.w SpriteAuxTable, X ; Retrieve stored item type
JSL.l PrepDynamicTile_loot_resolved
LDA.b #$00 : STA.l RedrawFlag ; reset redraw flag
BRA .defer
+
LDA.w SpriteID, X ; Retrieve stored item type
JSL.l DrawDynamicTile
.defer
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; LoadMushroom:
;--------------------------------------------------------------------------------
LoadMushroom:
LDA.b #$00 : STA.w SpriteGFXControl, X ; thing we wrote over
.justGFX
PHA
LDA.b #$01 : STA.l RedrawFlag
LDA.b LinkState : CMP.b #$14 : BEQ .skip ; skip if we're mid-mirror
LDA.b #$00 : STA.l RedrawFlag
%GetPossiblyEncryptedItem(MushroomItem, SpriteItemValues)
JSL.l AttemptItemSubstitution
JSR.w ResolveLootID
STA.w SpriteID,X
JSL.l PrepDynamicTile
.skip
PLA
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; DrawMushroom:
;--------------------------------------------------------------------------------
DrawMushroom:
PHA : PHY
LDA.l RedrawFlag : BEQ .skipInit ; skip init if already ready
JSL.l LoadMushroom_justGFX
BRA .done ; don't draw on the init frame
.skipInit
LDA.w SpriteID, X ; Retrieve stored item type
JSL.l DrawDynamicTile
.done
PLY : PLA
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; CollectPowder:
;--------------------------------------------------------------------------------
CollectPowder:
LDY.w SpriteID, X ; Retrieve stored item type
BNE +
; if for any reason the item value is 0 reload it, just in case
%GetPossiblyEncryptedItem(WitchItem, SpriteItemValues) : TAY
+
STZ.w ItemReceiptMethod ; item from NPC
JSL.l Link_ReceiveItem
JSL.l ItemSet_Powder
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; RemoveMushroom:
;--------------------------------------------------------------------------------
RemoveMushroom:
LDA.l InventoryTracking : AND.b #$DF : STA.l InventoryTracking ; remove the mushroom
AND.b #$10 : BEQ .empty ; check if we have powder
LDA.b #$02 : STA.l PowderEquipment ; give powder if we have it
RTL
.empty
LDA.b #$00 : STA.l PowderEquipment ; clear the inventory slot if we don't have powder
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; DrawMagicHeader:
;--------------------------------------------------------------------------------
DrawMagicHeader:
LDA.l MagicConsumption : AND.w #$00FF : CMP.w #$0002 : BEQ .quarterMagic
.halfMagic
LDA.w #$28F7 : STA.l HUDTileMapBuffer+$04
LDA.w #$2851 : STA.l HUDTileMapBuffer+$06
LDA.w #$28FA : STA.l HUDTileMapBuffer+$08
RTL
.quarterMagic
LDA.w #$28F7 : STA.l HUDTileMapBuffer+$04
LDA.w #$2800 : STA.l HUDTileMapBuffer+$06
LDA.w #$2801 : STA.l HUDTileMapBuffer+$08
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; SpawnShovelGamePrizeSFX:
;--------------------------------------------------------------------------------
SpawnShovelGamePrizeSFX:
STA.l MiniGameTime ; thing we wrote over
PHA
LDA.b #$1B : STA.w SFX3 ; play puzzle sound
PLA
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; SpawnChestGamePrizeSFX:
;--------------------------------------------------------------------------------
SpawnChestGamePrizeSFX:
CPX.b #$07 : BNE .normal
LDA.b RoomIndex : CMP.b #$06 : BNE .normal
.prize
LDA.b #$1B : STA.w SFX3 : RTL ; play puzzle sound
.normal
LDA.b #$0E : STA.w SFX3 ; play chest sound
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; SpawnShovelItem:
;--------------------------------------------------------------------------------
SpawnShovelItem:
LDA.b #$01 : STA.l RedrawFlag
LDA.w YButtonOverride : BEQ +
JSL DiggingGameGuy_AttemptPrizeSpawn
JMP .skip
+
LDA.w TileActDig : AND.b #$01 : BNE + : JMP .skip : + ; corner dig fix
PHY : PHP
PHB : PHK : PLB
SEP #$30 ; set 8-bit accumulator and index registers
LDA.b IndoorsFlag : BEQ + : JMP .no_drop : + ; skip if indoors
LDA.b OverworldIndex : CMP.b #$2A : BEQ .no_drop ; don't drop in the haunted grove
CMP.b #$68 : BEQ .no_drop ; don't drop in the digging game area
JSL GetRandomInt : BIT.b #$03 : BNE .no_drop ; drop with 1/4 chance
LSR #2 : TAX ; clobber lower 2 bis - we have 64 slots now
LDA.l ShovelSpawnTable, X ; look up the drop on the table
;most of this part below is copied from the digging game
STA.l MiniGameTime
JSL Sprite_SpawnDynamically
LDX.b #$00
LDA.b LinkDirection : CMP.b #$04 : BEQ + : INX : +
LDA.l .x_speeds, X : STA.w SpriteVelocityX, Y
LDA.b #$00 : STA.w SpriteVelocityY, Y
LDA.b #$18 : STA.w SpriteVelocityZ, Y
LDA.b #$FF : STA.w EnemyStunTimer, Y
LDA.b #$30 : STA.w SpriteTimerE, Y
LDA.b LinkPosX : !ADD.l .x_offsets, X
AND.b #$F0 : STA.w SpritePosXLow, Y
LDA.b LinkPosX+1 : ADC.b #$00 : STA.w SpritePosXHigh, Y
LDA.b LinkPosY : !ADD.b #$16 : AND.b #$F0 : STA.w SpritePosYLow, Y
LDA.b LinkPosY+1 : ADC.b #$00 : STA.w SpritePosYHigh, Y
LDA.b #$00 : STA.w SpriteLayer, Y
TYX
LDA.b #$30 : JSL Sound_SetSfx3PanLong
.no_drop
PLB
PLP : PLY
.skip
RTL
;DATA - Shovel Spawn Information
{
.x_speeds
db $F0
db $10
.x_offsets
db $00
db $13
}
;--------------------------------------------------------------------------------
MaybePlaySelectSFX:
LDA.w DungeonID : BMI .not_dungeon
.play
LDA.b #$20 : STA.w SFX3 ; menu select sound
RTL
.not_dungeon
LDA.l HUDDungeonItems : BIT.b #$13 : BEQ .dont_play
BIT.b #$0C : BEQ .dont_play
BRA .play
.dont_play
RTL