forked from KatDevsGames/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
inventory.asm
1185 lines (1070 loc) · 35.5 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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;================================================================================
; Inventory Updates
;================================================================================
; InventoryTracking
; brmpnskf ------oq
; b = blue boomerang | -
; r = red boomerang | -
; m = mushroom current | -
; p = magic powder | -
; n = mushroom past | -
; s = shovel | -
; k = fake flute | o = any bomb acquired from item location
; f = working flute | q = quickswap locked
;--------------------------------------------------------------------------------
; BowTracking
; Item Tracking Slot #2
; bsp-----
; b = bow
; s = silver arrow bow
; p = 2nd progressive bow
; -
; -
; -
; -
; -
;--------------------------------------------------------------------------------
; ProcessMenuButtons:
; out: Carry - 0 = No Button, 1 = Yes Button
;--------------------------------------------------------------------------------
ProcessMenuButtons:
;LDA #$FD : STA InventoryTracking ; DEBUG MODE
;LDA $F6 : BIT #$20 : BNE .l_pressed ; check for P1 L-button
LDA $F4 : BIT #$40 : BNE .y_pressed ; check for P1 Y-button
BIT #$20 : BNE .sel_pressed ; check for P1 Select button
LDA $F0 : BIT #$20 : BNE .sel_held
.sel_unheld
LDA HudFlag : AND #$20 : BEQ +
LDA HudFlag : AND #$DF : STA HudFlag ; select is released, unset hud flag
LDA $1B : BEQ + ; skip if outdoors
LDA.b #$20 : STA $012F ; menu select sound
+
JSL.l ResetEquipment
+
.sel_held
CLC ; no buttons
RTL
.sel_pressed
LDA HudFlag : ORA #$20 : STA HudFlag ; set hud flag
LDA.b #$20 : STA $012F ; menu select sound
JSL.l ResetEquipment
RTL
.y_pressed ; Note: used as entry point by quickswap code. Must preserve X.
LDA.b #$10 : STA $0207
LDA $0202 ; check selected item
CMP #$02 : BNE + ; boomerang
LDA InventoryTracking : AND #$C0 : CMP #$C0 : BNE .errorJump ; make sure we have both boomerangs
LDA BoomerangEquipment : EOR #$03 : STA BoomerangEquipment ; swap blue & red boomerang
LDA.b #$20 : STA $012F ; menu select sound
JMP .captured
+ CMP #$01 : BNE + ; bow
LDA BowTracking : AND #$C0 : CMP #$C0 : BNE .errorJump ; make sure we have both bows
PHX : LDX.b #$00 ; scan ancilla table for arrows
-- : CPX.b #$0A : !BGE ++
LDA $0C4A, X : CMP.b #$09 : BNE +++
PLX : BRA .errorJump2 ; found an arrow, don't allow the swap
+++
INX : BRA -- : ++
PLX
LDA.l SilverArrowsUseRestriction : BEQ ++
LDA $A0 : ORA $A1 : BEQ ++ ; not in ganon's room in restricted mode
LDA BowEquipment : CMP.b #$03 : !BLT .errorJump : !SUB #$02 : STA BowEquipment
BRA .errorJump2
++
LDA BowEquipment : !SUB #$01 : EOR #$02 : !ADD #$01 : STA BowEquipment ; swap bows
LDA.b #$20 : STA $012F ; menu select sound
JMP .captured
+ BRA +
.errorJump
BRA .errorJump2
+ CMP #$05 : BNE + ; powder
LDA InventoryTracking : AND #$30 : CMP #$30 : BNE .errorJump ; make sure we have mushroom & magic powder
LDA PowderEquipment : EOR #$03 : STA PowderEquipment ; swap mushroom & magic powder
LDA.b #$20 : STA $012F ; menu select sound
JMP .captured
+ BRA +
.errorJump2
BRA .error
+ CMP #$0D : BNE + ; flute
LDA $037A : CMP #$01 : BEQ .midShovel ; inside a shovel animation, force the shovel & make error sound
LDA InventoryTracking : BIT #$04 : BEQ .error ; make sure we have shovel
AND #$03 : BEQ .error ; make sure we have one of the flutes
LDA FluteEquipment : CMP #01 : BNE .toShovel ; not shovel
LDA InventoryTracking : AND #$01 : BEQ .toFakeFlute ; check for real flute
LDA #$03 ; set real flute
BRA .fluteSuccess
.toFakeFlute
LDA #$02 ; set fake flute
BRA .fluteSuccess
.toShovel
LDA #$01 ; set shovel
.fluteSuccess
STA FluteEquipment ; store set item
LDA.b #$20 : STA $012F ; menu select sound
BRA .captured
+
CMP #$10 : BNE .error : JSL.l ProcessBottleMenu : BRA .captured : +
CLC
RTL
.midShovel
; LDA #$01 : STA FluteEquipment ; set shovel
.error
LDA.b #$3C : STA $012E ; error sound
.captured
SEC
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
;ProcessBottleMenu:
;--------------------------------------------------------------------------------
ProcessBottleMenu:
; LDA $F6 : AND #$30 : CMP.b #$30 : BEQ .double_shoulder_pressed
; LDA $F4 : AND #$40 : BEQ .y_not_pressed ; skip if Y is not down
; .double_shoulder_pressed
LDA BottleIndex ; check bottle state
BEQ .no_bottles ; skip if we have no bottles
PHX
INC : CMP #$05 : !BLT + : LDA #$01 : + ;increment and wrap 1-4
TAX : LDA BottleContents-1, X ; check bottle
BNE + : LDX #$01 : + ; wrap if we reached the last bottle
TXA : STA BottleIndex ; set bottle index
LDA.b #$20 : STA $012F ; menu select sound
PLX
.no_bottles
LDA #$00 ; pretend like the controller state was 0 from the overridden load
RTL
; .y_not_pressed
; LDA $F4 : AND.b #$0C ; thing we wrote over - load controller state
;RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
;OpenBottleMenu:
;--------------------------------------------------------------------------------
OpenBottleMenu:
LDA $F6 : AND #$40 : BEQ .x_not_pressed ; skip if X is not down
LDA.b #$10 : STA $0207 ; set 16 frame cool off
LDA.b #$20 : STA $012F ; make menu sound
LDA.b #$07 : STA $0200 ; thing we wrote over - opens bottle menu
.x_not_pressed
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
;CloseBottleMenu:
;--------------------------------------------------------------------------------
CloseBottleMenu:
LDA $F6 : AND #$40 : BEQ .x_not_pressed ; skip if X is not down
LDA.b #$10 : STA $0207 ; set 16 frame cool off
LDA.b #$20 : STA $012F ; make menu sound
INC $0200 ; return to normal menu
STZ $0205
LDA #$00
RTL
.x_not_pressed
LDA $F4 : AND.b #$0C ; thing we wrote over (probably)
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; AddInventory:
;--------------------------------------------------------------------------------
macro TopHalf(address)
LDA <address> : !ADD #$10 : STA <address>
endmacro
macro BottomHalf(address)
PHA : PHX
LDA <address> : INC : AND #$0F : TAX
LDA <address> : AND #$F0 : STA <address>
TXA : ORA <address> : STA <address>
PLX : PLA
endmacro
;--------------------------------------------------------------------------------
;FullInventoryExternal:
; LDA StatsLocked : BEQ + : RTL : +
; PHA : PHX : PHP : JMP AddInventory_fullItemCounts
;--------------------------------------------------------------------------------
FullInventoryExternal:
LDA StatsLocked : BEQ + : RTL : +
PHA : PHX : PHP : JMP AddInventory_incrementCounts
;--------------------------------------------------------------------------------
AddInventory:
PHA : PHX : PHP
LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ +
BRL .incrementCounts
+
CPY.b #$0C : BNE + ; Blue Boomerang
LDA InventoryTracking : ORA #$80 : STA InventoryTracking
JMP .incrementCounts
+ CPY.b #$2A : BNE + ; Red Boomerang
LDA InventoryTracking : ORA #$40 : STA InventoryTracking
JMP .incrementCounts
+ CPY.b #$29 : BNE + ; Mushroom
LDA InventoryTracking : ORA #$28 : STA InventoryTracking
JMP .incrementCounts
+ CPY.b #$0D : BNE + ; Magic Powder
LDA InventoryTracking : ORA #$10 : STA InventoryTracking
JMP .incrementCounts
+ CPY.b #$13 : BNE + ; Shovel
LDA InventoryTracking : ORA #$04 : STA InventoryTracking
JMP .incrementCounts
+ CPY.b #$14 : BNE + ; Flute (Inactive)
LDA InventoryTracking : ORA #$02 : STA InventoryTracking
JMP .incrementCounts
+ CPY.b #$4A : BNE + ; Flute (Active)
LDA InventoryTracking : ORA #$01 : STA InventoryTracking
JMP .incrementCounts
+ CPY.b #$0B : BNE + ; Bow
LDA ArrowMode : BNE +++
LDA BowTracking : ORA #$80 : STA BowTracking
+++
JMP .incrementCounts
+ CPY.b #$3A : BNE + ; Bow & Arrows
LDA BowTracking : ORA #$80 : STA BowTracking
JMP .incrementCounts
+ CPY.b #$3B : BNE + ; Bow & Silver Arrows
LDA BowTracking : ORA #$40 : STA BowTracking
LDA ArrowMode : BNE +++
LDA BowTracking : ORA #$80 : STA BowTracking ; activate wood arrows when not in rupee bow
+++
JMP .incrementCounts
+ CPY.b #$43 : BNE + ; Single arrow
LDA ArrowMode : BEQ +++
LDA BowTracking : ORA #$80 : STA BowTracking ; activate wood arrows in quick-swap
+++
JMP .incrementCounts
+ CPY.b #$58 : BNE + ; Upgrade-Only Silver Arrows
LDA BowTracking : ORA #$40 : STA BowTracking
+
.incrementCounts
LDA StatsLocked : BEQ + : JMP .done : +
LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ +
BRL .dungeonCounts
+
; don't count any of this stuff
CPY.b #$20 : BNE + : JMP .itemCounts : + ; Crystal
CPY.b #$26 : BNE + : JMP .itemCounts : + ; Heart Piece Completion Heart
LDA.l !SHOP_ENABLE_COUNT : BNE ++
CPY.b #$2E : BNE + : JMP .itemCounts : + ; Red Potion (Refill)
CPY.b #$2F : BNE + : JMP .itemCounts : + ; Green Potion (Refill)
CPY.b #$30 : BNE + : JMP .itemCounts : + ; Blue Potion (Refill)
++
CPY.b #$37 : BNE + : JMP .itemCounts : + ; Pendant
CPY.b #$38 : BNE + : JMP .itemCounts : + ; Pendant
CPY.b #$39 : BNE + : JMP .itemCounts : + ; Pendant
CPY.b #$04 : !BLT .isSword ; Swords - Skip Shop/Fairy Check for Swords
CPY.b #$49 : BEQ .isSword
CPY.b #$50 : BEQ .isSword
CPY.b #$5E : BEQ .isSword
BRA +
.isSword
JMP .dungeonCounts
+
CPY.b #$3B : BNE + : JMP .dungeonCounts : + ; Silver Arrow Bow - Skip Shop/Fairy Check for Silver Arrow Bow
LDA $1B : BNE + : JMP .dungeonCounts : + ; skip shop check if outdoors
LDA $02E9 : CMP.b #$01 : BEQ ++ ; skip shop check for chests
PHP : REP #$20 ; set 16-bit accumulator
LDA $048E
CMP.w #274 : BNE + : JMP .shop : + ; dark world death mountain shop, ornamental shield shop
CMP.w #271 : BNE + : JMP .shop : + ; villiage of outcasts shop, lumberjack shop, lake hylia shop, dark world magic shop
CMP.w #272 : BNE + : JMP .shop : + ; red shield shop
CMP.w #284 : BNE + : JMP .shop : + ; bomb shop
CMP.w #265 : BNE + : JMP .shop : + ; potion shop - commented this out because it's easier to just block potion refills because this one interferes with the powder item being counted
CMP.w #287 : BNE + : LDA.b $A9 : CMP.w #$0201 : BNE + ; kakariko shop
JMP .shop : + LDA.b $A0
CMP.w #255 : BNE + : LDA.b $A9 : BNE + ; light world death mountain shop
JMP .shop : + LDA.b $A0
CMP.w #276 : BNE + : LDA.b $A9 : CMP.w #$0200 : BNE + ; waterfall fairy
JMP .shop : + LDA.b $A0
CMP.w #277 : BNE + : JMP .shop : + ; upgrade fairy (shop)
CMP.w #278 : BNE + : JMP .shop : + ; pyramid fairy
PLP : BRA ++
.shop
PLP
LDA.l !SHOP_ENABLE_COUNT : BNE ++
JMP .done
++
.dungeonCounts
LDA !MULTIWORLD_RECEIVING_ITEM : CMP #$01 : BNE +
JMP .fullItemCounts
+
LDA $1B : BNE + : JMP .fullItemCounts : +
SEP #$20 ; Set 8-bit Accumulator
LDA $040C ; get dungeon id
BNE +
INC #2 ; treat sewers as HC
+ CMP #$FF : BEQ .fullItemCounts
CMP.l BallNChainDungeon : BNE +
CPY.b #$32 : BNE +
JMP .done
+ LSR : TAX : LDA DungeonLocationsChecked, X : INC : STA DungeonLocationsChecked, X
CPX.b #$0D : BNE +
LDA BigKeyField : AND #$04 : BNE ++
JSR .incrementGTowerPreBigKey
++
+
; == END INDOOR-ONLY SECTION
.fullItemCounts
LDA !MULTIWORLD_RECEIVING_ITEM : CMP #$01 : BEQ ++
LDA BootsEquipment : BNE + ; Check for Boots
REP #$20
LDA PreBootsLocations : INC : STA PreBootsLocations ; Increment Pre Boots Counter
SEP #$20
+
LDA MirrorEquipment : BNE + ; Check for Mirror
REP #$20
LDA PreMirrorLocations : INC : STA PreMirrorLocations ; Increment Pre Mirror Counter
SEP #$20
+
LDA FluteEquipment : BNE + ; Check for Mirror
REP #$20
LDA PreFluteLocations : INC : STA PreFluteLocations ; Increment Pre Mirror Counter
SEP #$20
+
REP #$20
LDA TotalItemCounter : INC : STA TotalItemCounter ; Increment Item Total
SEP #$20
++
.itemCounts
LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ +
BRL .done
+
CPY.b #$00 : BNE + ; Fighter's Sword & Fighter's Shield
LDX #$01
JSR .incrementSword
JSR .incrementShield
JMP .done
+ CPY.b #$01 : BNE + ; Master Sword
LDX #$02
JSR .incrementSword
JMP .done
+ CPY.b #$02 : BNE + ; Tempered Sword
LDX #$03
JSR .incrementSword
JMP .done
+ CPY.b #$03 : BNE + ; Golden Sword
LDX #$04
JSR .incrementSword
JMP .done
+ CPY.b #$04 : BNE + ; Fighter's Shield
LDX #$01
JSR .incrementShield
JMP .done
+ CPY.b #$05 : BNE + ; Red Shield
LDX #$02
JSR .incrementShield
JMP .done
+ CPY.b #$06 : BNE + ; Mirror Shield
LDX #$03
JSR .incrementShield
JMP .done
+ CPY.b #$07 : !BLT + ; Items $07 - $0D
CPY.b #$0E : !BGE +
JSR .incrementY
JMP .done
+ CPY.b #$14 : BNE + ; Flute (Inactive) - LEAVE THIS ABOVE THE 0F-16 CONDITION - kkat
JSR .stampFlute
JSR .incrementY
JMP .done
+ CPY.b #$0F : !BLT + ; Items $0F - $16
CPY.b #$17 : !BGE +
JSR .incrementY
JMP .done
+ CPY.b #$17 : BNE + ; Heart Piece
JSR .incrementHeartPiece
JMP .done
+ CPY.b #$18 : !BLT + ; Items $18 - $19
CPY.b #$1A : !BGE +
JSR .incrementY
JMP .done
+ CPY.b #$1A : BNE + ; Magic Mirror
JSR .stampMirror
JSR .incrementY
JMP .done
+ CPY.b #$1D : BNE + ; Book of Mudora - LEAVE THIS ABOVE THE 1B-1F CONDITION - kkat
JSR .incrementY
JMP .done
+ CPY.b #$1B : !BLT + ; Items $1B - $1F
CPY.b #$20 : !BGE +
JSR .incrementA
JMP .done
+ CPY.b #$20 : BNE + ; Crystal
JSR .incrementCrystal
JSR .setDungeonCompletion
JMP .done
+ CPY.b #$21 : BNE + ; Bug Net
JSR .incrementY
JMP .done
+ CPY.b #$22 : BNE + ; Blue Mail
LDX #$01
JSR .incrementMail
+ CPY.b #$23 : BNE + ; Red Mail
LDX #$02
JSR .incrementMail
+ CPY.b #$24 : BNE + ; Small Key
JSR .incrementKey
JMP .done
+ CPY.b #$25 : BNE + ; Compass
JSL MaybeFlagCompassTotalPickup
JSR .incrementCompass
JMP .done
+ CPY.b #$26 : BNE + ; Liar Heart (Container)
;JSR .incrementHeartContainer
JMP .done
+ CPY.b #$27 : BNE + ; 1 Bomb
JSR .maybeIncrementBombs
JMP .done
+ CPY.b #$28 : BNE + ; 3 Bombs
JSR .maybeIncrementBombs
JMP .done
+ CPY.b #$29 : BNE + ; Mushroom
JSR .incrementY
JMP .done
+ CPY.b #$2A : !BLT + ; Items $2A - $2D
CPY.b #$2E : !BGE +
JSR .incrementY
JMP .done
+ CPY.b #$31 : BNE + ; 10 Bombs
JSR .maybeIncrementBombs
JMP .done
+ CPY.b #$32 : BNE + ; Big Key
JSR .incrementBigKey
JMP .done
+ CPY.b #$33 : BNE + ; Map
JSR .incrementMap
JMP .done
+ CPY.b #$37 : !BLT + ; Items $37 - $39 - Pendants
CPY.b #$3A : !BGE +
JSR .incrementPendant
JSR .setDungeonCompletion
JMP .done
+ CPY.b #$3A : !BLT + ; Items $3A - $3B - Bow & Silver Arrows
CPY.b #$3C : !BGE +
JSR .incrementBow
JMP .done
+ CPY.b #$3C : BNE + ; Bottle w/Bee
JSR .incrementY
JMP .done
+ CPY.b #$3D : BNE + ; Bottle w/Fairy
JSR .incrementY
JMP .done
+ CPY.b #$3E : !BLT + ; Items $3E - $3F - Heart Containers
CPY.b #$40 : !BGE +
JSR .incrementHeartContainer
JMP .done
+ CPY.b #$48 : BNE + ; Bottle w/Gold Bee
JSR .incrementY
JMP .done
+ CPY.b #$49 : BNE + ; Fighter's Sword
LDX #$01
JSR .incrementSword
JMP .done
+ CPY.b #$4A : BNE + ; Flute (Active)
JSR .stampFlute
JSR .incrementY
JMP .done
+ CPY.b #$4B : BNE + ; Pegasus Boots
JSR .stampBoots
JSR .incrementA
JMP .done
+ CPY.b #$4C : BNE + ; 50 Bomb Capacity Upgrade
JSR .incrementCapacity
JSR .maybeIncrementBombs
JMP .done
+ CPY.b #$4D : !BLT + ; Items $4D - $4F - Capacity Upgrades
CPY.b #$50 : !BGE +
JSR .incrementCapacity
JMP .done
+ CPY.b #$50 : BNE + ; Master Sword (Safe)
LDX #$02
JSR .incrementSword
JMP .done
+ CPY.b #$51 : BNE + ; 5 Bomb Capacity Upgrade
LDX #$02
JSR .maybeIncrementBombs
JMP .done
+ CPY.b #$52 : BNE + ; 10 Bomb Capacity Upgrade
LDX #$02
JSR .maybeIncrementBombs
JMP .done
+ CPY.b #$51 : !BLT + ; Items $51 - $54 - Capacity Upgrades
CPY.b #$55 : !BGE +
JSR .incrementCapacity
JMP .done
+ CPY.b #$58 : BNE + ; Upgrade-Only Silver Arrows
JSR .incrementBow
JMP .done
+ CPY.b #$5E : BNE + ; Progressive Sword
LDA SwordEquipment : INC : TAX
JSR .incrementSword
JMP .done
+ CPY.b #$5F : BNE + ; Progressive Shield
LDA ShieldEquipment : INC : TAX
JSR .incrementShield
JMP .done
+ CPY.b #$60 : BNE + ; Progressive Armor
LDA ArmorEquipment : INC : TAX
JSR .incrementMail
JMP .done
+ CPY.b #$61 : BNE + ; Progressive Lifting Glove
JSR .incrementA
JMP .done
+ CPY.b #$64 : !BLT + ; Items $64 & $65 - Progressive Bow
CPY.b #$66 : !BGE +
JSR .incrementBow
JMP .done
+ CPY.b #$70 : !BLT + ; Items $70 - $7F - Free Maps
CPY.b #$80 : !BGE +
JSR .incrementMap
JMP .done
+ CPY.b #$80 : !BLT + ; Items $80 - $8F - Free Compasses
CPY.b #$90 : !BGE +
JSL MaybeFlagCompassTotalPickup
JSR .incrementCompass
JMP .done
+ CPY.b #$90 : !BLT + ; Items $90 - $9F - Free Big Keys
CPY.b #$A0 : !BGE +
JSR .incrementBigKey
JMP .done
+ CPY.b #$A0 : !BLT + ; Items $A0 - $AF - Free Small Keys
CPY.b #$B0 : !BGE +
JSR .incrementKey
JMP .done
+
.done
PLP : PLX : PLA
RTL
; WHICH BEE IS BOTTLED?
; MAKE SURE FAIRY FOUNTAINS DON'T FUCK THE COUNTS UP
.stampSword
REP #$20 ; set 16-bit accumulator
LDA SwordTime : BNE +
LDA SwordTime+2 : BNE +
LDA NMIFrames : STA SwordTime
LDA NMIFrames+2 : STA SwordTime+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.stampBoots
REP #$20 ; set 16-bit accumulator
LDA BootsTime : BNE +
LDA BootsTime+2 : BNE +
LDA NMIFrames : STA BootsTime
LDA NMIFrames+2 : STA BootsTime+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.stampFlute
REP #$20 ; set 16-bit accumulator
LDA FluteTime : BNE +
LDA FluteTime+2 : BNE +
LDA NMIFrames : STA FluteTime
LDA NMIFrames+2 : STA FluteTime+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.stampMirror
REP #$20 ; set 16-bit accumulator
LDA MirrorTime : BNE +
LDA MirrorTime+2 : BNE +
LDA NMIFrames : STA MirrorTime
LDA NMIFrames+2 : STA MirrorTime+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.incrementSword
JSR .stampSword
LDA HighestSword
INC : STA $04 : CPX $04 : !BLT + ; don't increment unless we're getting a better sword
TXA : STA HighestSword
+
RTS
.incrementShield
LDA HighestShield
INC : STA $04 : CPX $04 : !BLT + ; don't increment unless we're getting a better shield
TXA : STA HighestShield
+
RTS
.incrementBow
LDA BowEquipment : BNE .dontCount ; Don't increment Y item count for extra bows
.incrementY
LDA YAItemCounter : !ADD #$08 : STA YAItemCounter
.dontCount
RTS
.incrementA
LDA YAItemCounter : INC : AND #$07 : TAX
LDA YAItemCounter : AND #$F8 : STA YAItemCounter
TXA : ORA YAItemCounter : STA YAItemCounter
RTS
.incrementPendant
LDA PendantCounter : INC : STA PendantCounter
RTS
.incrementCapacity
LDA CapacityUpgrades : INC : STA CapacityUpgrades
RTS
.incrementHeartPiece
LDA HeartPieceCounter : INC : STA HeartPieceCounter
RTS
.incrementHeartContainer
LDA HeartContainerCounter : INC : STA HeartContainerCounter
RTS
.incrementCrystal
LDA CrystalCounter : INC : STA CrystalCounter
RTS
.incrementMail
LDA HighestMail
INC : STA $04 : CPX $04 : !BLT + ; don't increment unless we're getting a better mail
TXA : STA HighestMail
+
RTS
.incrementKeyLong
JSR .incrementKey
RTL
.incrementKey
LDA SmallKeyCounter : INC : STA SmallKeyCounter
RTS
.incrementCompass
%BottomHalf(MapsCompasses)
RTS
.incrementBigKey
%TopHalf(BigKeysBigChests)
RTS
.incrementGTowerPreBigKey
LDA PreGTBKLocations : INC : STA PreGTBKLocations
RTS
.maybeIncrementBombs
LDA InventoryTracking+1 : AND #$02 : BNE +
LDA InventoryTracking+1 : ORA #$02 : STA InventoryTracking+1
JSR .incrementY
+
RTS
.incrementMap
%TopHalf(MapsCompasses)
RTS
.incrementBossSwordLong
JSR .incrementBossSword
RTL
.incrementBossSword
LDA SwordEquipment
BNE + : -
LDA SwordlessBossKills : INC : STA SwordlessBossKills
RTS
+ CMP #$FF : BEQ -
+ CMP #$01 : BNE +
%TopHalf(SwordBossKills) : RTS
+ CMP #$02 : BNE +
%BottomHalf(SwordBossKills) : RTS
+ CMP #$03 : BNE +
%TopHalf(SwordBossKills+1) : RTS
+ CMP #$04 : BNE +
%BottomHalf(SwordBossKills+1)
+
RTS
.setDungeonCompletion
LDX $040C : BMI +
REP #$20 ; 16 bit
LDA.l DungeonMask, X
ORA DungeonsCompleted : STA DungeonsCompleted
SEP #$20 ; 8 bit
+
RTS
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; Link_ReceiveItem_HUDRefresh:
;--------------------------------------------------------------------------------
Link_ReceiveItem_HUDRefresh:
LDA BombsEquipment : BNE + ; skip if we have bombs
LDA BombCapacityUpgrades : !ADD.l StartingMaxBombs : BEQ + ; skip if we can't have bombs
LDA BombsFiller : BEQ + ; skip if we are filling no bombs
DEC : STA BombsFiller ; decrease bomb fill count
LDA.b #$01 : STA BombsEquipment ; increase actual bomb count
+
JSL.l HUD_RefreshIconLong ; thing we wrote over
JSL.l PostItemGet
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; HandleBombAbsorbtion:
;--------------------------------------------------------------------------------
HandleBombAbsorbtion:
STA BombsFiller ; thing we wrote over
LDA $0303 : BNE + ; skip if we already have some item selected
LDA BombCapacityUpgrades : !ADD.l StartingMaxBombs : BEQ + ; skip if we can't have bombs
LDA.b #$04 : STA $0202 ; set selected item to bombs
LDA.b #$01 : STA $0303 ; set selected item to bombs
JSL.l HUD_RebuildLong
+
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; AddYMarker:
;--------------------------------------------------------------------------------
;!JAR_STATUS = "$7F5030";
AddYMarker:
LDA $0202 : AND.w #$FF ; load item value
CMP.w #$02 : BNE + ; boomerang
LDA InventoryTracking : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$01 : BNE + ; bow
LDA BowTracking : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$05 : BNE + ; powder
LDA InventoryTracking : AND.w #$30 : CMP.w #$30 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$0D : BNE + ; flute
LDA 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
;SEP #$20 : LDA !JAR_STATUS : INC : AND.b #$01 : STA !JAR_STATUS : REP #$20 : BEQ .drawXBubble
LDA $0207 : AND.w #$0020 : BNE .drawXBubble
.drawYBubble
LDA.w #$3D4F
BRA .drawTile
.drawXBubble
JSR MakeCircleBlue
LDA.w #$2D3E
.drawTile
STA $FFC4, Y
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; MakeCircleBlue
; this is horrible, make it better
;--------------------------------------------------------------------------------
MakeCircleBlue:
LDA $FFC0, Y : AND.w #$EFFF : STA $FFC0, Y
LDA $FFC2, Y : AND.w #$EFFF : STA $FFC2, Y
LDA $FFFE, Y : AND.w #$EFFF : STA $FFFE, Y
LDA $0004, Y : AND.w #$EFFF : STA $0004, Y
LDA $003E, Y : AND.w #$EFFF : STA $003E, Y
LDA $0044, Y : AND.w #$EFFF : STA $0044, Y
LDA $0080, Y : AND.w #$EFFF : STA $0080, Y
LDA $0082, Y : AND.w #$EFFF : STA $0082, Y
LDA $FFBE, Y : AND.w #$EFFF : STA $FFBE, Y
LDA $FFC4, Y : AND.w #$EFFF : STA $FFC4, Y
LDA $0084, Y : AND.w #$EFFF : STA $0084, Y
LDA $007E, Y : AND.w #$EFFF : STA $007E, Y
RTS
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; UpgradeFlute:
;--------------------------------------------------------------------------------
UpgradeFlute:
LDA InventoryTracking : AND #$FC : ORA #$01 : STA InventoryTracking ; switch to the working flute
LDA.b #$03 : STA FluteEquipment ; upgrade primary inventory
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; CheckKeys:
;--------------------------------------------------------------------------------
CheckKeys:
LDA.l GenericKeys : BEQ + : RTL : +
LDA $040C : CMP.b #$FF
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; DrawKeyIcon:
;--------------------------------------------------------------------------------
DrawKeyIcon:
LDA $04 : AND.w #$00FF : CMP.w #$0090 : BNE + : LDA.w #$007F : + : ORA.w #$2400 : STA $7EC764
LDA $05 : AND.w #$00FF : ORA.w #$2400 : STA $7EC766
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; LoadKeys:
;--------------------------------------------------------------------------------
LoadKeys:
LDA.l GenericKeys : BEQ +
LDA CurrentGenericKeys
RTL
+
LDA DungeonKeys, X
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; SaveKeys:
;--------------------------------------------------------------------------------
SaveKeys:
PHA
LDA.l GenericKeys : BEQ +
PLA : STA CurrentGenericKeys
RTL
+
PLA : STA DungeonKeys, X
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; ClearOWKeys:
;--------------------------------------------------------------------------------
ClearOWKeys:
PHA
JSL.l TurtleRockEntranceFix
JSL.l FakeWorldFix
JSR.w FixBunnyOnExitToLightWorld
LDA.l GenericKeys : BEQ +
PLA : LDA CurrentGenericKeys : STA CurrentSmallKeys
RTL
+
PLA : STA CurrentSmallKeys
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; GetWitchLootOAMTableIndex
; in: A - Loot ID
; out: A - Loot OAM Table Index
; check if this is even still referenced anywhere
;--------------------------------------------------------------------------------
;GetWitchLootOAMTableIndex:
; PHX
; PHB : PHK : PLB
; ;--------
; TAX : LDA .gfxSlots, X ; look up item gfx
; PLB : PLX
;RTL
;
;;DATA - Loot Identifier to Sprite ID
;{
; .gfxSlots
; db $FF, $FF, $FF, $FF, $05, $06, $FF, $0C
; db $0B, $0D, $0A, $07, $13, $0E, $FF, $FF
;
; db $FF, $FF, $FF, $FF, $FF, $09, $FF, $FF
; db $08, $FF, $FF, $10, $11, $12, $FF, $FF
;
; db $FF, $FF, $03, $04, $FF, $FF, $02, $FF
; db $FF, $FF, $14, $15, $17, $16, $15, $17
;
; db $16, $0F, $FF, $FF, $FF, $FF, $FF, $FF
; db $FF, $FF, $FF, $FF, $FF, $FF, $02, $02
;
; db $FF, $FF, $FF, $FF, $01, $FF, $FF, $FF
; db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
;}
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; PrepItemScreenBigKey:
;--------------------------------------------------------------------------------
PrepItemScreenBigKey:
STZ $02
STZ $03
REP #$30 ; thing we wrote over - set 16-bit accumulator
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; LoadPowder:
;--------------------------------------------------------------------------------
LoadPowder:
JSL.l Sprite_SpawnDynamically ; thing we wrote over
LDA.l WitchItem_Player : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID
%GetPossiblyEncryptedItem(WitchItem, SpriteItemValues)
STA $0DA0, Y ; Store item type
JSL.l PrepDynamicTile
STA $7F505E
LDA #$00
STA $7F505F
STA $7F5060
STA $7F5061
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; InitializeBottles:
;--------------------------------------------------------------------------------
InitializeBottles:
STA BottleContents, X ; thing we wrote over
PHA
LDA BottleIndex : BNE +
TXA : INC : STA BottleIndex ; write bottle index to menu properly
+
PLA
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; DrawPowder:
;--------------------------------------------------------------------------------
!REDRAW = "$7F5000"
;--------------------------------------------------------------------------------
DrawPowder:
LDA $02DA : BNE .defer ; defer if link is buying a potion
LDA.l !REDRAW : BEQ +
LDA.l WitchItem_Player : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID
LDA $0DA0, X ; Retrieve stored item type
JSL.l PrepDynamicTile
LDA #$00 : STA.l !REDRAW ; reset redraw flag
BRA .defer
+
; this fights with the shopkeep code, so had to move the powder draw there when potion shop is custom
LDA !SHOP_TYPE : CMP.b #$FF : BNE .defer
LDA $0DA0, X ; Retrieve stored item type
JSL.l DrawDynamicTile
.defer
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; LoadMushroom:
;--------------------------------------------------------------------------------
LoadMushroom:
LDA.b #$00 : STA $0DC0, X ; thing we wrote over
.justGFX
;LDA MushroomItem
;JSL.l PrepDynamicTile
PHA
LDA #$01 : STA !REDRAW
LDA $5D : CMP #$14 : BEQ .skip ; skip if we're mid-mirror
LDA #$00 : STA !REDRAW
LDA.l MushroomItem_Player : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID
%GetPossiblyEncryptedItem(MushroomItem, SpriteItemValues)
STA $0E80, X ; Store item type
JSL.l PrepDynamicTile
.skip