forked from KatDevsGames/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 6
/
inventory.asm
1215 lines (1093 loc) · 35 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
;================================================================================
!INVENTORY_SWAP = "$7EF38C"
; Item Tracking Slot
; brmpnskf
; b = blue boomerang
; r = red boomerang
; m = mushroom current
; p = magic powder
; n = mushroom past
; s = shovel
; k = fake flute
; f = working flute
;--------------------------------------------------------------------------------
!INVENTORY_SWAP_2 = "$7EF38E"
; 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 !INVENTORY_SWAP ; 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 !HUD_FLAG : AND #$20 : BEQ +
LDA !HUD_FLAG : AND #$DF : STA !HUD_FLAG ; 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
;.l_pressed
;JSL.l SpawnAngryCucco
;RTL
.sel_pressed
LDA !HUD_FLAG : ORA #$20 : STA !HUD_FLAG ; 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 !INVENTORY_SWAP : AND #$C0 : CMP #$C0 : BNE .errorJump ; make sure we have both boomerangs
LDA $7EF341 : EOR #$03 : STA $7EF341 ; swap blue & red boomerang
LDA.b #$20 : STA $012F ; menu select sound
BRL .captured
+ CMP #$01 : BNE + ; bow
LDA !INVENTORY_SWAP_2 : 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 $7EF340 : CMP.b #$03 : !BLT .errorJump : !SUB #$02 : STA $7EF340
BRA .errorJump2
++
LDA $7EF340 : !SUB #$01 : EOR #$02 : !ADD #$01 : STA $7EF340 ; swap bows
LDA.b #$20 : STA $012F ; menu select sound
BRL .captured
+ BRA +
.errorJump
BRA .errorJump2
+ CMP #$05 : BNE + ; powder
LDA !INVENTORY_SWAP : AND #$30 : CMP #$30 : BNE .errorJump ; make sure we have mushroom & magic powder
LDA $7EF344 : EOR #$03 : STA $7EF344 ; swap mushroom & magic powder
LDA.b #$20 : STA $012F ; menu select sound
BRL .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 !INVENTORY_SWAP : BIT #$04 : BEQ .error ; make sure we have shovel
AND #$03 : BEQ .error ; make sure we have one of the flutes
LDA $7EF34C : CMP #01 : BNE .toShovel ; not shovel
LDA !INVENTORY_SWAP : 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 $7EF34C ; 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 $7EF34C ; set shovel
.error
LDA.b #$3C : STA $012E ; error sound
.captured
SEC
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
;ProcessBottleMenu:
;--------------------------------------------------------------------------------
ProcessBottleMenu:
LDA $F4 : AND #$40 : BEQ .y_not_pressed ; skip if Y is not down
LDA $7EF34F ; 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 $7EF35C-1, X ; check bottle
BNE + : LDX #$01 : + ; wrap if we reached the last bottle
TXA : STA $7EF34F ; 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:
;--------------------------------------------------------------------------------
!LOCK_STATS = "$7EF443"
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 !LOCK_STATS : BEQ + : RTL : +
; PHA : PHX : PHP : JMP AddInventory_fullItemCounts
;--------------------------------------------------------------------------------
FullInventoryExternal:
LDA !LOCK_STATS : BEQ + : RTL : +
PHA : PHX : PHP : JMP AddInventory_incrementCounts
;--------------------------------------------------------------------------------
!SHAME_CHEST = "$7EF416" ; ---s ----
AddInventory:
PHA : PHX : PHP
LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ +
BRL .incrementCounts
+
CPY.b #$0C : BNE + ; Blue Boomerang
LDA !INVENTORY_SWAP : ORA #$80 : STA !INVENTORY_SWAP
BRL .incrementCounts
+ CPY.b #$2A : BNE + ; Red Boomerang
LDA !INVENTORY_SWAP : ORA #$40 : STA !INVENTORY_SWAP
BRL .incrementCounts
+ CPY.b #$29 : BNE + ; Mushroom
LDA !INVENTORY_SWAP : ORA #$28 : STA !INVENTORY_SWAP
BRL .incrementCounts
+ CPY.b #$0D : BNE + ; Magic Powder
LDA !INVENTORY_SWAP : ORA #$10 : STA !INVENTORY_SWAP
BRL .incrementCounts
+ CPY.b #$13 : BNE + ; Shovel
LDA !INVENTORY_SWAP : ORA #$04 : STA !INVENTORY_SWAP
BRL .incrementCounts
+ CPY.b #$14 : BNE + ; Flute (Inactive)
LDA !INVENTORY_SWAP : ORA #$02 : STA !INVENTORY_SWAP
BRL .incrementCounts
+ CPY.b #$4A : BNE + ; Flute (Active)
LDA !INVENTORY_SWAP : ORA #$01 : STA !INVENTORY_SWAP
BRL .incrementCounts
+ CPY.b #$0B : BNE + ; Bow
LDA ArrowMode : BNE +++
LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2
+++
BRL .incrementCounts
+ CPY.b #$3A : BNE + ; Bow & Arrows
LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2
BRL .incrementCounts
+ CPY.b #$3B : BNE + ; Bow & Silver Arrows
LDA !INVENTORY_SWAP_2 : ORA #$40 : STA !INVENTORY_SWAP_2
LDA ArrowMode : BNE +++
LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 ; activate wood arrows when not in rupee bow
+++
BRL .incrementCounts
+ CPY.b #$43 : BNE + ; Single arrow
LDA ArrowMode : BEQ +++
LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 ; activate wood arrows in quick-swap
+++
BRL .incrementCounts
+ CPY.b #$58 : BNE + ; Upgrade-Only Silver Arrows
LDA !INVENTORY_SWAP_2 : ORA #$40 : STA !INVENTORY_SWAP_2
+
.incrementCounts
CPY.b #$6A : BEQ + ; Skip !LOCK_STATS for Triforce. so that it counts towards the stat.
LDA !LOCK_STATS : BEQ + : BRL .done : +
LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ +
BRL .dungeonCounts
+
; don't count any of this stuff
CPY.b #$20 : BNE + : BRL .itemCounts : + ; Crystal
CPY.b #$26 : BNE + : BRL .itemCounts : + ; Heart Piece Completion Heart
CPY.b #$37 : BNE + : BRL .itemCounts : + ; Pendant
CPY.b #$38 : BNE + : BRL .itemCounts : + ; Pendant
CPY.b #$39 : BNE + : BRL .itemCounts : + ; Pendant
CPY.b #$00 : BNE + : BRL .itemCounts : + ; Uncle Sword & Shield
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
BRL .dungeonCounts
+
CPY.b #$3B : BNE + : BRL .dungeonCounts : + ; Silver Arrow Bow - Skip Shop/Fairy Check for Silver Arrow Bow
LDA $1B : BEQ ++ ; 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 + : BRL .shop : + ; dark world death mountain shop, ornamental shield shop
CMP.w #271 : BNE + : BRL .shop : + ; villiage of outcasts shop, lumberjack shop, lake hylia shop, dark world magic shop
CMP.w #272 : BNE + : BRL .shop : + ; red shield shop
CMP.w #284 : BNE + : BRL .shop : + ; bomb shop
CMP.w #265 : BNE + : BRL .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 + : BRL .shop : + ; kakariko shop
CMP.w #255 : BNE + : BRL .shop : + ; light world death mountain shop
CMP.w #276 : BNE + : BRL .shop : + ; waterfall fairy
CMP.w #277 : BNE + : BRL .shop : + ; upgrade fairy (shop)
CMP.w #278 : BNE + : BRL .shop : + ; pyramid fairy
PLP : BRA ++
.shop
PLP
LDA.l !SHOP_ENABLE_COUNT : BNE ++
BRL .done
++
.dungeonCounts
LDA !MULTIWORLD_RECEIVING_ITEM : CMP #$01 : BNE +
BRL .fullItemCounts
+
LDA $1B : BNE + : BRL .fullItemCounts : +
; ==BEGIN INDOOR-ONLY SECTION
;REP #$20 ; Set 16-bit Accumulator
;LDA $A0 ; load room ID
;CMP.w #$0010 : BNE + ; Ganon Fall Room - I think this got taken out
;!SHAME_CHEST = "$7EF416" ; ---s ----
;LDA !SHAME_CHEST : ORA.w #$0010 : STA !SHAME_CHEST
;+
SEP #$20 ; Set 8-bit Accumulator
LDA $040C ; get dungeon id
BNE +
INC #2 ; treat sewers as HC
+ CMP #$FF : BEQ .fullItemCounts
CMP.b #$02 : BNE +
CPY.b #$32 : BNE + ; Check if Big key is for Sewers/Hyrule Castle
PHA
LDA.b #$C0 : ORA $7EF367 : STA $7EF367 ; Big Key 2
PLA
+
CMP.l BallNChainDungeon : BNE +
CPY.b #$32 : BNE +
BRL .done
+ LSR : TAX : LDA $7EF4BF, X : INC : STA $7EF4BF, X
CPX.b #$0D : BNE +
LDA $7EF366 : AND #$04 : BNE ++
JSR .incrementGTowerPreBigKey
++
+
; == END INDOOR-ONLY SECTION
.fullItemCounts
;LDA !MULTIWORLD_ITEM_PLAYER_ID : BNE +
; CPY.b #$3B : BNE + ; Skip Total Counts for Repeat Silver Arrows
; LDA $7EF42A : BIT #$20 : BEQ + : BRA .itemCounts
;+
LDA !MULTIWORLD_RECEIVING_ITEM : CMP #$01 : BEQ ++
LDA $7EF355 : BNE + ; Check for Boots
REP #$20
LDA $7EF432 : INC : STA $7EF432 ; Increment Pre Boots Counter
SEP #$20
+
LDA $7EF353 : BNE + ; Check for Mirror
REP #$20
LDA $7EF468 : INC : STA $7EF468 ; Increment Pre Mirror Counter
SEP #$20
+
REP #$20
LDA $7EF423 : INC : STA $7EF423 ; Increment Item Total
SEP #$20
++
.itemCounts
LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ +
BRL .done
+
CPY.b #$00 : BNE + ; Fighter's Sword & Fighter's Shield
JSR .incrementSword
JSR .incrementShield
BRL .done
+ CPY.b #$01 : BNE + ; Master Sword
JSR .incrementSword
BRL .done
+ CPY.b #$02 : BNE + ; Tempered Sword
JSR .incrementSword
BRL .done
+ CPY.b #$03 : BNE + ; Golden Sword
JSR .incrementSword
BRL .done
+ CPY.b #$04 : BNE + ; Fighter's Shield
JSR .incrementShield
BRL .done
+ CPY.b #$05 : BNE + ; Red Shield
JSR .incrementShield
BRL .done
+ CPY.b #$06 : BNE + ; Mirror Shield
JSR .incrementShield
BRL .done
+ CPY.b #$07 : !BLT + ; Items $07 - $0D
CPY.b #$0E : !BGE +
JSR .incrementY
BRL .done
+ CPY.b #$14 : BNE + ; Flute (Inactive) - LEAVE THIS ABOVE THE 0F-16 CONDITION - kkat
JSR .stampFlute
JSR .incrementY
BRL .done
+ CPY.b #$0F : !BLT + ; Items $0F - $16
CPY.b #$17 : !BGE +
JSR .incrementY
BRL .done
+ CPY.b #$17 : BNE + ; Heart Piece
JSR .incrementHeartPiece
BRL .done
+ CPY.b #$18 : !BLT + ; Items $18 - $19
CPY.b #$1A : !BGE +
JSR .incrementY
BRL .done
+ CPY.b #$1A : BNE + ; Magic Mirror
JSR .stampMirror
JSR .incrementY
BRL .done
+ CPY.b #$1D : BNE + ; Book of Mudora - LEAVE THIS ABOVE THE 1B-1F CONDITION - kkat
JSR .incrementY
BRL .done
+ CPY.b #$1B : !BLT + ; Items $1B - $1F
CPY.b #$20 : !BGE +
JSR .incrementA
BRL .done
+ CPY.b #$20 : BNE + ; Crystal
JSR .incrementCrystal
JSR .setDungeonCompletion
BRL .done
+ CPY.b #$21 : BNE + ; Bug Net
JSR .incrementY
BRL .done
+ CPY.b #$22 : !BLT + ; Items $22 - $23
CPY.b #$24 : !BGE +
JSR .incrementMail
BRL .done
+ CPY.b #$24 : BNE + ; Small Key
JSR .incrementKey
BRL .done
+ CPY.b #$25 : BNE + ; Compass
JSR .incrementCompass
BRL .done
+ CPY.b #$26 : BNE + ; Liar Heart (Container)
;JSR .incrementHeartContainer
BRL .done
+ CPY.b #$27 : BNE + ; 1 Bomb
JSR .maybeIncrementBombs
BRL .done
+ CPY.b #$28 : BNE + ; 3 Bombs
JSR .maybeIncrementBombs
BRL .done
+ CPY.b #$29 : BNE + ; Musoroom
JSR .incrementY
BRL .done
+ CPY.b #$2A : !BLT + ; Items $2A - $2D
CPY.b #$2E : !BGE +
JSR .incrementY
BRL .done
+ CPY.b #$31 : BNE + ; 10 Bombs
JSR .maybeIncrementBombs
BRL .done
+ CPY.b #$32 : BNE + ; Big Key
JSR .incrementBigKey
BRL .done
+ CPY.b #$33 : BNE + ; Map
JSR .incrementMap
BRL .done
+ CPY.b #$37 : !BLT + ; Items $37 - $39 - Pendants
CPY.b #$3A : !BGE +
JSR .incrementPendant
JSR .setDungeonCompletion
BRL .done
+ CPY.b #$3A : !BLT + ; Items $3A - $3B - Bow & Silver Arrows
CPY.b #$3C : !BGE +
JSR .incrementBow
BRL .done
+ CPY.b #$3C : BNE + ; Bottle w/Bee
JSR .incrementY
BRL .done
+ CPY.b #$3D : BNE + ; Bottle w/Fairy
JSR .incrementY
BRL .done
+ CPY.b #$3E : !BLT + ; Items $3E - $3F - Heart Containers
CPY.b #$40 : !BGE +
JSR .incrementHeartContainer
BRL .done
+ CPY.b #$48 : BNE + ; Bottle w/Gold Bee
JSR .incrementY
BRL .done
+ CPY.b #$49 : BNE + ; Fighter's Sword
JSR .incrementSword
BRL .done
+ CPY.b #$4A : BNE + ; Flute (Active)
JSR .stampFlute
JSR .incrementY
BRL .done
+ CPY.b #$4B : BNE + ; Pegasus Boots
JSR .stampBoots
JSR .incrementA
BRL .done
+ CPY.b #$4C : BNE + ; Bomb Capacity Upgrade
JSR .incrementCapacity
JSR .maybeIncrementBombs
BRL .done
+ CPY.b #$4D : !BLT + ; Items $4D - $4F - Capacity Upgrades
CPY.b #$50 : !BGE +
JSR .incrementCapacity
BRL .done
+ CPY.b #$50 : BNE + ; Master Sword (Safe)
JSR .incrementSword
BRL .done
+ CPY.b #$51 : !BLT + ; Items $51 - $54 - Capacity Upgrades
CPY.b #$55 : !BGE +
JSR .incrementCapacity
BRL .done
+ CPY.b #$58 : BNE + ; Upgrade-Only Sivler Arrows
JSR .incrementBow
BRL .done
+ CPY.b #$5E : BNE + ; Progressive Sword
JSR .incrementSword
BRL .done
+ CPY.b #$5F : BNE + ; Progressive Shield
JSR .incrementShield
BRL .done
+ CPY.b #$60 : BNE + ; Progressive Armor
JSR .incrementMail
BRL .done
+ CPY.b #$61 : BNE + ; Progressive Lifting Glove
JSR .incrementA
BRL .done
+ CPY.b #$64 : !BLT + ; Items $64 & $65 - Progressive Bow
CPY.b #$66 : !BGE +
JSR .incrementBow
BRL .done
+ CPY.b #$70 : !BLT + ; Items $70 - $7F - Free Maps
CPY.b #$80 : !BGE +
JSR .incrementMap
BRL .done
+ CPY.b #$80 : !BLT + ; Items $80 - $8F - Free Compasses
CPY.b #$90 : !BGE +
JSR .incrementCompass
BRL .done
+ CPY.b #$90 : !BLT + ; Items $90 - $9F - Free Big Keys
CPY.b #$A0 : !BGE +
JSR .incrementBigKey
BRL .done
+ CPY.b #$A0 : !BLT + ; Items $A0 - $AF - Free Small Keys
CPY.b #$B0 : !BGE +
JSR .incrementKey
BRL .done
+
.done
PLP : PLX : PLA
RTL
; WHICH BEE IS BOTTLED?
; MAKE SURE FAIRY FOUNTAINS DON'T FUCK THE COUNTS UP
!NMI_TIME = "$7EF43E"
!SWORD_TIME = "$7EF458"
!BOOTS_TIME = "$7EF45C"
!FLUTE_TIME = "$7EF460"
!MIRROR_TIME = "$7EF464"
.stampSword
REP #$20 ; set 16-bit accumulator
LDA !SWORD_TIME : BNE +
LDA !SWORD_TIME+2 : BNE +
LDA !NMI_TIME : STA !SWORD_TIME
LDA !NMI_TIME+2 : STA !SWORD_TIME+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.stampBoots
REP #$20 ; set 16-bit accumulator
LDA !BOOTS_TIME : BNE +
LDA !BOOTS_TIME+2 : BNE +
LDA !NMI_TIME : STA !BOOTS_TIME
LDA !NMI_TIME+2 : STA !BOOTS_TIME+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.stampFlute
REP #$20 ; set 16-bit accumulator
LDA !FLUTE_TIME : BNE +
LDA !FLUTE_TIME+2 : BNE +
LDA !NMI_TIME : STA !FLUTE_TIME
LDA !NMI_TIME+2 : STA !FLUTE_TIME+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.stampMirror
REP #$20 ; set 16-bit accumulator
LDA !MIRROR_TIME : BNE +
LDA !MIRROR_TIME+2 : BNE +
LDA !NMI_TIME : STA !MIRROR_TIME
LDA !NMI_TIME+2 : STA !MIRROR_TIME+2
+
SEP #$20 ; set 8-bit accumulator
RTS
.incrementSword
; CHECK FOR DUPLICATE SWORDS
JSR .stampSword
TYA ; load sword item
CMP.b #$50 : BNE + : LDA.b #$01 : + ; convert extra master sword to normal one
CMP.b #$49 : BNE + : LDA.b #$00 : + ; convert extra fighter sword to normal one
INC : CMP !HIGHEST_SWORD_LEVEL : !BLT + ; skip if highest is higher
PHA
LDA !HIGHEST_SWORD_LEVEL : AND #$F8 : ORA 1,s : STA !HIGHEST_SWORD_LEVEL
PLA
+
LDA $7EF422 : !ADD #$20 : STA $7EF422 ; increment sword counter
RTS
.incrementShield
; CHECK FOR DUPLICATE SHIELDS
LDA $7EF422 : !ADD #$08 : AND #$18 : TAX
LDA $7EF422 : AND #$E7 : STA $7EF422
TXA : ORA $7EF422 : STA $7EF422
RTS
.incrementBow
CPY.b #$3B : BNE ++
LDA $7EF42A : BIT #$20 : BEQ + : RTS : +
ORA #$20 : STA $7EF42A
++
.incrementY
LDA $7EF421 : !ADD #$08 : STA $7EF421
RTS
.incrementA
LDA $7EF421 : INC : AND #$07 : TAX
LDA $7EF421 : AND #$F8 : STA $7EF421
TXA : ORA $7EF421 : STA $7EF421
RTS
.incrementPendant
LDA $7EF429 : INC : AND #$03 : TAX
LDA $7EF429 : AND #$FC : STA $7EF429
TXA : ORA $7EF429 : STA $7EF429
; JSR .incrementBossSword
RTS
.incrementCapacity
%BottomHalf($7EF452)
RTS
.incrementHeartPiece
LDA $7EF448 : INC : AND #$1F : TAX
LDA $7EF448 : AND #$E0 : STA $7EF448
TXA : ORA $7EF448 : STA $7EF448
RTS
.incrementHeartContainer
%TopHalf($7EF429)
RTS
.incrementCrystal
LDA $7EF422 : INC : AND #$07 : TAX
LDA $7EF422 : AND #$F8 : STA $7EF422
TXA : ORA $7EF422 : STA $7EF422
; JSR .incrementBossSword
RTS
.incrementMail
LDA $7EF46A : !ADD #$40 : STA $7EF46A
RTS
.incrementKeyLong
JSR .incrementKey
RTL
.incrementKey
PHA : PHX
LDA $7EF46A : INC : AND #$3F : TAX
LDA $7EF46A : AND #$C0 : STA $7EF46A
TXA : ORA $7EF46A : STA $7EF46A
PLX : PLA
RTS
.incrementCompass
%BottomHalf($7EF428)
RTS
.incrementBigKey
LDA $7EF427 : !ADD #$10 : STA $7EF427
RTS
.incrementGTowerPreBigKey
LDA $7EF42A : INC : AND #$1F : TAX
LDA $7EF42A : AND #$E0 : STA $7EF42A
TXA : ORA $7EF42A : STA $7EF42A
RTS
.maybeIncrementBombs
LDA $7EF42A : AND #$80 : BNE +
LDA $7EF42A : ORA #$80 : STA $7EF42A
JSR .incrementY
+
RTS
.incrementMap
LDA $7EF428 : !ADD #$10 : STA $7EF428
RTS
.incrementBossSwordLong
JSR .incrementBossSword
RTL
.incrementBossSword
LDA $7EF359
BNE + : -
%TopHalf($7EF452) : RTS
+ CMP #$FF : BEQ -
+ CMP #$01 : BNE +
%TopHalf($7EF425) : RTS
+ CMP #$02 : BNE +
%BottomHalf($7EF425) : RTS
+ CMP #$03 : BNE +
%TopHalf($7EF426) : RTS
+ CMP #$04 : BNE +
%BottomHalf($7EF426)
+
RTS
.setDungeonCompletion
LDA $040C
CMP #$FF : BEQ +
LSR : AND #$0F : CMP #$08 : !BGE ++
JSR .valueShift
ORA $7EF46B : STA $7EF46B
BRA +
++
!SUB #$08
JSR .valueShift
BIT.b #$C0 : BEQ +++ : LDA.b #$C0 : +++ ; Make Hyrule Castle / Sewers Count for Both
ORA $7EF46C : STA $7EF46C
+
RTS
.valueShift
PHX
TAX : LDA.b #$01
-
CPX #$00 : BEQ +
ASL
DEX
BRA -
+
PLX
RTS
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; Link_ReceiveItem_HUDRefresh:
;--------------------------------------------------------------------------------
Link_ReceiveItem_HUDRefresh:
LDA $7EF343 : BNE + ; skip if we have bombs
LDA $7EF375 : BEQ + ; skip if we are filling no bombs
DEC : STA $7EF375 ; decrease bomb fill count
LDA.b #$01 : STA $7EF343 ; increase actual bomb count
+
JSL.l HUD_RefreshIconLong ; thing we wrote over
JSL.l PostItemGet
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; HandleBombAbsorbtion:
;--------------------------------------------------------------------------------
HandleBombAbsorbtion:
STA $7EF375 ; thing we wrote over
LDA $0303 : BNE + ; skip if we already have some item selected
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 !INVENTORY_SWAP : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$01 : BNE + ; bow
LDA !INVENTORY_SWAP_2 : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$05 : BNE + ; powder
LDA !INVENTORY_SWAP : AND.w #$30 : CMP.w #$30 : BEQ .drawYBubble : BRA .drawNormal
+ CMP.w #$0D : BNE + ; flute
LDA !INVENTORY_SWAP : 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 !INVENTORY_SWAP : AND #$FC : ORA #$01 : STA !INVENTORY_SWAP ; switch to the working flute
LDA.b #$03 : STA $7EF34C ; 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 $7EF38B
RTL
+
LDA $7EF37C, X
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; SaveKeys:
;--------------------------------------------------------------------------------
SaveKeys:
PHA
LDA.l GenericKeys : BEQ +
PLA : STA $7EF38B
RTL
+
PLA : STA $7EF37C, X
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; ClearOWKeys:
;--------------------------------------------------------------------------------
ClearOWKeys:
PHA
JSL.l TurtleRockEntranceFix
JSL.l FakeWorldFix
JSR.w FixBunnyOnExitToLightWorld
LDA.l GenericKeys : BEQ +
PLA : LDA $7EF38B : STA $7EF36F
RTL
+
PLA : STA $7EF36F
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
%GetPossiblyEncryptedPlayerID(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 $7EF35C, X ; thing we wrote over
PHA
LDA $7EF34F : BNE +
TXA : INC : STA $7EF34F ; write bottle index to menu properly
+
PLA
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; DrawPowder:
;--------------------------------------------------------------------------------
!REDRAW = "$7F5000"
;--------------------------------------------------------------------------------
DrawPowder:
; this fights with the shopkeep code, so had to move the powder draw there
LDA $02DA : BNE .defer ; defer if link is buying a potion
LDA.l !REDRAW : BEQ +
%GetPossiblyEncryptedPlayerID(WitchItem_Player) : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID
LDA $0DA0, X ; Retrieve stored item type
JSL.l PrepDynamicTile