-
Notifications
You must be signed in to change notification settings - Fork 53
/
newitems.asm
1160 lines (1039 loc) · 32.5 KB
/
newitems.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
;================================================================================
; New Item Handlers
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; Service Indexes
; 0x00 - 0x04 - chests
; 0xF0 - freestanding heart / powder / mushroom / bonkable
; 0xF1 - freestanding heart 2 / boss heart / npc
; 0xF3 - tablet/pedestal
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
GetAnimatedSpriteGfxFile:
CMP.b #$0C : BNE +
LDY.b #$5C : JML GetAnimatedSpriteGfxFile_return
+
CMP.b #$23 : BNE +
LDY.b #$5D : JML GetAnimatedSpriteGfxFile_return
+
CMP.b #$48 : BNE +
LDY.b #$60 : JML GetAnimatedSpriteGfxFile_return
+
CMP.b #$24 : !BGE +
LDY.b #$5B : JML GetAnimatedSpriteGfxFile_return
+
CMP.b #$37 : !BGE +
LDY.b #$5C : JML GetAnimatedSpriteGfxFile_return
+
CMP.b #$39 : !BGE +
LDY.b #$5D : JML GetAnimatedSpriteGfxFile_return
+
LDY.b #$32
JML GetAnimatedSpriteGfxFile_return
GetAnimatedSpriteBufferPointer_table:
; Original data:
dw $09C0, $0030, $0060, $0090, $00C0, $0300, $0318, $0330
dw $0348, $0360, $0378, $0390, $0930, $03F0, $0420, $0450
dw $0468, $0600, $0630, $0660, $0690, $06C0, $06F0, $0720 ; disassembly (incorrectly?) says this is $0270
dw $0750, $0768, $0900, $0930, $0960, $0990, $09F0, $0000
dw $00F0, $0A20, $0A50, $0660, $0600, $0618, $0630, $0648
dw $0678, $06D8, $06A8, $0708, $0738, $0768, $0960, $0900
dw $03C0, $0990, $09A8, $09C0, $09D8, $0A08, $0A38, $0600
dw $0630
; New data:
dw $0600, $0630, $0660, $0690 ; 50 Bombs / 70 Arrows / Half Magic / Quarter Magic
dw $06C0, $06F0, $8520 ; +5/+10 Bomb Arrows
;#$4x
dw $0750 ; +10 Arrows
dw $0900 ; Upgrade-Only Silver Arrows
dw $09D8 ; Unused
dw $0930, $0960, $0990, $09C0 ; Lvl 1/2/3/4 Sword (Freestanding)
dw $09F0 ; Null-Item
dw $09C0 ; Clock
dw $0A20 ; Triforce
dw $0A50 ; Power Star
GetAnimatedSpriteBufferPointer:
;PHB : PHK : PLB
LDA.b Scrap00 : ADC.l GetAnimatedSpriteBufferPointer_table, X
;PLB
RTL
macro ProgrammableItemLogic(index)
LDA.l ProgrammableItemLogicPointer_<index> : BNE ?jump
LDA.l ProgrammableItemLogicPointer_<index>+1 : BNE ?jump
LDA.l ProgrammableItemLogicPointer_<index>+2 : BNE ?jump
BRA ?end
?jump:
JSL.l ProgrammableItemLogicJump_<index>
?end:
endmacro
;--------------------------------------------------------------------------------
;carry clear if pass
;carry set if caught
;incsrc eventdata.asm
ProcessEventItems:
LDA.b Scrap00 : PHA
LDA.b Scrap01 : PHA
LDA.b Scrap02 : PHA
PHY : PHP
PHB : LDA.b #$AF : PHA : PLB
LDA.w ItemReceiptID
CMP.b #$E0 : BNE +
REP #$30 ; set 16-bit accumulator & index registers
LDA.l RNGItem : ASL : TAX
LDA.l EventDataOffsets, X : !ADD #EventDataTable : STA.b Scrap00
SEP #$20 ; set 8-bit accumulator
LDA.b #$AF : STA.b Scrap02
JSL.l LoadDialogAddressIndirect
LDA.l RNGItem : INC : STA.l RNGItem
SEP #$10 ; set 8-bit index registers
REP #$20 ; set 16-bit accumulator
LDA.l GoalItemRequirement : BEQ ++
LDA.l GoalCounter : INC : STA.l GoalCounter
CMP.l GoalItemRequirement : BCC ++
LDA.l TurnInGoalItems : AND.w #$00FF : BNE ++
JSL.l ActivateGoal
++
SEP #$20 ; set 8-bit accumulator
LDX.b #$01 : BRA .done
+
LDX.b #$00
.done
PLB
PLP : PLY
PLA : STA.b Scrap02
PLA : STA.b Scrap01
PLA : STA.b Scrap00
RTS
;--------------------------------------------------------------------------------
AddReceivedItemExpanded:
JSR.w ResolveReceipt
PHB : PHK
JML AddReceivedItem+2
AddReceivedItemExpandedGetItem:
PHX : PHB
LDA.w ItemReceiptID
JSL.l FreeDungeonItemNotice
JSR ItemBehavior
SEP #$30
PLB : PLX
LDA.w ItemReceiptMethod : CMP.b #$01 ; thing we wrote over
RTL
ItemBehavior:
REP #$30
AND #$00FF : ASL : TAX
SEP #$20
JMP.w (ItemReceipts_behavior,X)
.skip
RTS
.blue_boomerang
LDA.l InventoryTracking : ORA.b #$80
BRA .store_inventory_tracking
.red_boomerang
LDA.l InventoryTracking : ORA.b #$40
BRA .store_inventory_tracking
.mushroom
LDA.l InventoryTracking : ORA.b #$28
BRA .store_inventory_tracking
.powder
LDA.l InventoryTracking : ORA.b #$10
BRA .store_inventory_tracking
.flute_inactive
LDA.l InventoryTracking : ORA.b #$02
BRA .store_inventory_tracking
.flute_active
LDA.l InventoryTracking : ORA.b #$01
BRA .store_inventory_tracking
.shovel
LDA.l InventoryTracking : ORA.b #$04
.store_inventory_tracking
STA.l InventoryTracking
RTS
.sword_shield
SEP #$10
LDX.b #$01
JSR .increment_sword
JSR .increment_shield
RTS
.master_sword
SEP #$10
LDX.b #$02
JSR .increment_sword
RTS
.tempered_sword
SEP #$10
LDX.b #$03
JSR .increment_sword
RTS
.gold_sword
SEP #$10
LDX.b #$04
JSR .increment_sword
RTS
.fighter_shield
SEP #$10
LDA.w ShopPurchaseFlag : BNE ..shop_shield
-
LDX.b #$01
JSR .increment_shield
RTS
..shop_shield
LDA.l InventoryTable_properties,X : BIT.b #$02 : BNE -
RTS
.red_shield
SEP #$10
LDA.w ShopPurchaseFlag : BNE ..shop_shield
-
LDX.b #$02
JSR .increment_shield
RTS
..shop_shield
LDA.l InventoryTable_properties,X : BIT.b #$02 : BNE -
RTS
.mirror_shield
SEP #$10
LDX.b #$03
JSR .increment_shield
REP #$10
RTS
.blue_mail
SEP #$10
LDX.b #$01
JSR .increment_mail
REP #$10
RTS
.red_mail
SEP #$10
LDX.b #$02
JSR .increment_mail
REP #$10
RTS
.fighter_sword
SEP #$10
LDX.b #$01
JSR .increment_sword
REP #$10
RTS
.prog_sword
SEP #$10
LDA.l SwordEquipment : INC : TAX
JSR .increment_sword
REP #$10
RTS
.prog_shield
SEP #$10
LDA.l ShieldEquipment : INC : TAX
JSR .increment_shield
REP #$10
RTS
.prog_mail
SEP #$10
LDA.l ArmorEquipment : INC : TAX
JSR .increment_mail
REP #$10
RTS
.bow
BIT #$40 : BNE .silversbow
LDA.b #$01 : STA.l BowEquipment
RTS
.silversbow
LDA.l BowTracking : ORA.b #$40 : STA.l BowTracking
LDA.l SilverArrowsUseRestriction : BNE +
LDA.b #03 : STA.l BowEquipment ; set bow to silver
+
LDA.b #$01 : STA.l BowEquipment
RTS
.dungeon_compass
REP #$20
LDA.w DungeonID : CMP.w #$0003 : BCC ..hc_sewers
TAX
LDA.l DungeonItemMasks,X : TAY
ORA.l CompassField : STA.l CompassField
JMP.w .increment_compass
..hc_sewers
LDA.w #$C000 : TAY
ORA.l CompassField : STA.l CompassField
JMP.w .increment_compass
.dungeon_bigkey
REP #$20
LDA.w DungeonID : CMP.w #$0003 : BCC ..hc_sewers
TAX
LDA.l DungeonItemMasks,X : ORA.l BigKeyField : STA.l BigKeyField
JMP.w .increment_bigkey
..hc_sewers
LDA.w #$C000 : ORA.l BigKeyField : STA.l BigKeyField
JMP.w .increment_bigkey
.dungeon_map
REP #$20
LDA.w DungeonID : CMP.w #$0003 : BCC ..hc_sewers
TAX
LDA.l DungeonItemMasks,X : TAY
ORA.l MapField : STA.l MapField
JMP.w .increment_map
..hc_sewers
LDA.w #$C000 : TAY
ORA.l MapField : STA.l MapField
JMP.w .increment_map
.bow_and_arrows
LDA.l BowTracking : BIT.b #$40 : BEQ .no_silvers
LDA.l SilverArrowsUseRestriction : BNE .no_silvers
LDA.l CurrentArrows : BEQ +
LDA.b #04 : STA.l BowEquipment
BRA .store_bow
+
LDA.b #$03
BRA .store_bow
.no_silvers
LDA.l CurrentArrows : BEQ +
LDA.b #02
BRA .store_bow
+
LDA.b #$01
.store_bow
STA.l BowEquipment
RTS
.silver_bow
LDA.b #$40 : ORA.l BowTracking : STA.l BowTracking
LDA.l SilverArrowsUseRestriction : BNE .noequip
LDA.l SilverArrowsAutoEquip : AND.b #$01 : BEQ .noequip
LDA.l CurrentArrows : BNE + ; check arrows
LDA.b #$03 : BRA ++ ; bow without arrow
+
LDA.b #$04 ; bow with arrow
++
STA.l BowEquipment
.noequip
RTS
.bombs_50
LDA.b #50 : STA.l BombCapacity ; upgrade bombs
LDA.b #50 : STA.l BombsFiller ; fill bombs
RTS
.arrows_70
LDA.b #70 : STA.l ArrowCapacity ; upgrade arrows
LDA.b #70 : STA.l ArrowsFiller ; fill arrows
RTS
.magic_2
LDA.l MagicConsumption : CMP.b #$02 : !BGE +
INC : STA.l MagicConsumption ; upgrade magic
+
LDA.b #$80 : STA.l MagicFiller ; fill magic
RTS
.magic_4
LDA.b #$02 : STA.l MagicConsumption ; upgrade magic
LDA.b #$80 : STA.l MagicFiller ; fill magic
RTS
.master_sword_safe
SEP #$10
LDA.l SwordEquipment : CMP.b #$02 : !BGE + ; skip if we have a better sword
LDA.b #$02 : STA.l SwordEquipment ; set master sword
+
LDX.b #$02
JSR .increment_sword
RTS
.bombs_5
LDA.l BombCapacity : !ADD.b #$05 : STA.l BombCapacity ; upgrade bombs +5
LDA.l Upgrade5BombsRefill : STA.l BombsFiller ; fill bombs
RTS
.bombs_10
LDA.l BombCapacity : !ADD.b #$0A : STA.l BombCapacity ; upgrade bombs +10
LDA.l Upgrade10BombsRefill : STA.l BombsFiller ; fill bombs
RTS
.arrows_5
LDA.l ArrowCapacity : !ADD.b #$05 : STA.l ArrowCapacity ; upgrade arrows +5
LDA.l Upgrade5ArrowsRefill : STA.l ArrowsFiller ; fill arrows
RTS
.arrows_10
LDA.l ArrowCapacity : !ADD.b #$0A : STA.l ArrowCapacity ; upgrade arrows +10
LDA.l Upgrade10ArrowsRefill : STA.l ArrowsFiller ; fill arrows
RTS
.programmable_1
%ProgrammableItemLogic(1)
RTS
.programmable_2
%ProgrammableItemLogic(2)
RTS
.programmable_3
%ProgrammableItemLogic(3)
RTS
.silver_arrows
LDA.l BowTracking : ORA.b #$40 : STA.l BowTracking
LDA.l SilverArrowsUseRestriction : BNE ++
LDA.l SilverArrowsAutoEquip : AND.b #$01 : BEQ ++
LDA.l BowEquipment : BEQ ++ : CMP.b #$03 : !BGE +
!ADD.b #$02 : STA.l BowEquipment ; switch to silver bow
+
++
LDA.l ArrowMode : BEQ +
LDA.b #$01 : STA.l ArrowsFiller
+
RTS
.single_arrow
LDA.l ArrowMode : BEQ +
LDA.l CurrentArrows : INC : STA.l CurrentArrows ; Should be sole write to this address
LDA.b #$01 : STA.l UpdateHUDFlag ; in retro/rupee bow mode.
+
RTS
.rupoor
REP #$20 : LDA.l CurrentRupees : !SUB RupoorDeduction : STA.l CurrentRupees : SEP #$20 ; Take 1 rupee
RTS
.null
RTS
.red_clock
REP #$20 ; set 16-bit accumulator
LDA.l ChallengeTimer : !ADD.l RedClockAmount : STA.l ChallengeTimer
LDA.l ChallengeTimer+2 : ADC.l RedClockAmount+2 : STA.l ChallengeTimer+2
SEP #$20 ; set 8-bit accumulator
RTS
.blue_clock
REP #$20 ; set 16-bit accumulator
LDA.l ChallengeTimer : !ADD.l BlueClockAmount : STA.l ChallengeTimer
LDA.l ChallengeTimer+2 : ADC.l BlueClockAmount+2 : STA.l ChallengeTimer+2
SEP #$20 ; set 8-bit accumulator
RTS
.green_clock
REP #$20 ; set 16-bit accumulator
LDA.l ChallengeTimer : !ADD.l GreenClockAmount : STA.l ChallengeTimer
LDA.l ChallengeTimer+2 : ADC.l GreenClockAmount+2 : STA.l ChallengeTimer+2
SEP #$20 ; set 8-bit accumulator
RTS
.triforce
JSL.l ActivateGoal
RTS
.goal_item
REP #$20 ; set 16-bit accumulator
LDA.l GoalItemRequirement : BEQ +
LDA.l GoalCounter : INC : STA.l GoalCounter
CMP.w GoalItemRequirement : BCC +
LDA.l TurnInGoalItems : AND.w #$00FF : BNE +
JSL.l ActivateGoal
+
SEP #$20 ; set 8-bit accumulator
RTS
.request_F0
JSL.l ItemGetServiceRequest_F0
RTS
.request_F1
JSL.l ItemGetServiceRequest_F1
RTS
.request_F2
JSL.l ItemGetServiceRequest_F2
RTS
.request_async
; JSL.l ItemGetServiceRequest
RTS
.free_map
REP #$20
LSR
AND.w #$000F : ASL : TAX
LDA.w DungeonItemIDMap,X : TAX
LDA.l DungeonItemMasks,X : TAY
ORA.l MapField : STA.l MapField
SEP #$20
JMP.w .increment_map
.hc_map
REP #$20
LDA.w #$C000 : TAY
ORA.l MapField : STA.l MapField
JMP.w .increment_map
.free_compass
REP #$20
LSR
AND.w #$000F : ASL : TAX
LDA.w DungeonItemIDMap,X : TAX
LDA.l DungeonItemMasks,X : TAY
ORA.l CompassField : STA.l CompassField
SEP #$20
JMP.w .increment_compass
.hc_compass
REP #$20
LDA.w #$C000 : TAY
ORA.l CompassField : STA.l CompassField
SEP #$20
JMP.w .increment_compass
.free_bigkey
REP #$20
LSR
AND.w #$000F : ASL : TAX
LDA.w DungeonItemIDMap,X : TAX
LDA.l DungeonItemMasks,X : ORA.l BigKeyField : STA.l BigKeyField
SEP #$20
JMP.w .increment_bigkey
.hc_bigkey
LDA.b #$C0 : ORA.l BigKeyField+1 : STA.l BigKeyField+1
JMP.w .increment_bigkey
.free_smallkey
REP #$20
LSR
AND.w #$000F : TAX
ASL : CMP.w DungeonID : BEQ .same_dungeon
LDA.l DungeonKeys,X : INC : STA.l DungeonKeys,X
RTS
.same_dungeon
SEP #$20
LDA.l CurrentSmallKeys : INC : STA.l CurrentSmallKeys : STA.l DungeonKeys,X
RTS
.same_dungeon_hc
SEP #$20
LDA.l CurrentSmallKeys : INC : STA.l CurrentSmallKeys
LDA.l SewerKeys : INC
STA.l SewerKeys : STA.l HyruleCastleKeys
RTS
.hc_smallkey
LDA.w DungeonID : CMP.b #$03 : BCC .same_dungeon_hc
LDA.l HyruleCastleKeys : INC : STA.l HyruleCastleKeys
LDA.l SewerKeys : INC : STA.l SewerKeys
RTS
.generic_smallkey
LDA.l GenericKeys : BEQ .normal
LDA.l CurrentSmallKeys : INC
STA.l CurrentGenericKeys : STA.l CurrentSmallKeys
RTS
.normal
LDA.w DungeonID : BMI +
LDA.l CurrentSmallKeys : INC : STA.l CurrentSmallKeys
RTS
+
RTS
.increment_sword
LDA.l HighestSword
INC : STA.b Scrap04 : CPX.b Scrap04 : BCC + ; don't increment unless we're getting a better sword
TXA : STA.l HighestSword
+
RTS
.increment_shield
LDA.l HighestShield
INC : STA.b Scrap04 : CPX.b Scrap04 : BCC + ; don't increment unless we're getting a better shield
TXA : STA.l HighestShield
+
RTS
.increment_mail
LDA.l HighestMail
INC : STA.b Scrap04 : CPX.b Scrap04 : BCC + ; don't increment unless we're getting a better mail
TXA : STA.l HighestMail
+
RTS
.increment_bigkey
SEP #$20
LDA.l StatsLocked : BNE +
LDA.l BigKeysBigChests
CLC : ADC.b #$10
STA.l BigKeysBigChests
+
RTS
.increment_map
SEP #$20
LDA.l StatsLocked : BNE +
LDA.l MapsCompasses
CLC : ADC.b #$10
STA.l MapsCompasses
JSL.l MaybeFlagMapTotalPickup
+
RTS
.increment_compass
SEP #$20
LDA.l StatsLocked : BNE +
LDA.l MapsCompasses : INC : AND.b #$0F : TAX
LDA.l MapsCompasses : AND.b #$F0 : STA.l MapsCompasses
TXA : ORA.l MapsCompasses : STA.l MapsCompasses
JSL MaybeFlagCompassTotalPickup
+
RTS
.pendant
SEP #$20
LSR
SEC : SBC.b #$37
TAX
LDA.w PendantMasks,X : AND.l PendantsField : BNE +
LDA.l PendantCounter : INC : STA.l PendantCounter
+
RTS
.dungeon_crystal
SEP #$20
LDA.l CrystalCounter : INC : STA.l CrystalCounter
RTS
.free_crystal
REP #$20
LSR
AND.w #$000F : TAX
LDA.w #$0000
SEC
-
ROL
DEX
BPL -
SEP #$20
TAX
AND.l CrystalsField : BNE +
TXA
ORA.l CrystalsField : STA.l CrystalsField
LDA.l CrystalCounter : INC : STA.l CrystalCounter
+
.done
RTS
ResolveReceipt:
PHA : PHX
PHK : PLB
JSL.l PreItemGet
LDA.w ItemReceiptID
.get_item
JSL.l AttemptItemSubstitution
JSR.w HandleBowTracking
JSR.w ResolveLootID
.have_item
STA.w ItemReceiptID
JSR IncrementItemCounters
PLX : PLA
RTS
ResolveLootIDLong:
PHY
JSR.w ResolveLootID
PLY
RTL
ResolveLootID:
; In: A - Loot ID
; Out: A - Resolved Loot ID
; Caller is responsible for running AttemptItemSubstitution prior if applicable.
PHX : PHB
PHK : PLB
.get_item
TAY
REP #$30
AND.w #$00FF : ASL : TAX
TYA
JMP.w (ItemReceipts_resolution,X)
.have_item
SEP #$30
PLB : PLX
RTS
.skip
JMP.w .have_item
.bottles
SEP #$30
JSR.w CountBottles : CMP.l BottleLimit : BCC +
LDA.l BottleLimitReplacement
JMP.w .get_item
+
TYA
JMP.w .have_item
.magic
SEP #$20
LDA.l MagicConsumption : TAX
LDA.w .magic_ids,X
JMP.w .have_item
..ids
db $4E, $4F, $4F
.prog_sword
SEP #$20
LDA.l HighestSword
CMP.l ProgressiveSwordLimit : BCC +
LDA.l ProgressiveSwordReplacement
JMP.w .get_item
+
TAX
LDA.w .prog_sword_ids,X
JMP.w .have_item
..ids
db $49, $50, $02, $03, $03
.shields
SEP #$20
LDA.l HighestShield
CMP.l ProgressiveShieldLimit : BCC +
LDA.l ProgressiveShieldReplacement
JMP.w .get_item
+
TAX
LDA.w .shields_ids,X
JMP.w .have_item
..ids
db $04, $05, $06, $06
.armor
SEP #$20
LDA.l HighestMail
CMP.l ProgressiveArmorLimit : BCC +
LDA.l ProgressiveArmorReplacement
JMP.w .get_item
+
TAX
LDA.w .armor_ids,X
JMP.w .have_item
..ids
db $22, $23, $23
.gloves
SEP #$20
LDA.l GloveEquipment : TAX
LDA.w .gloves_ids,X
JMP.w .have_item
..ids
db $1B, $1C, $1C
.progressive_bow
; For non-chest progressive bows we assign the tracking bits to SpriteMetaData,X
; (where X is that sprite's slot) so the bit can be set on pickup.
SEP #$30
LDA.l BowEquipment : INC : LSR : CMP.l ProgressiveBowLimit : BCC +
LDA.l ProgressiveBowReplacement
JMP.w .get_item
+
LDA.w ItemReceiptMethod : CMP.b #$01 : BEQ +
LDX.w CurrentSpriteSlot
LDA.b #$10 : STA.w SpriteMetaData,X
+
LDA.l BowEquipment : TAX
LDA.w .bows_ids,X
JMP.w .get_item
.progressive_bow_2
SEP #$30
LDA.l BowEquipment : INC : LSR : CMP.l ProgressiveBowLimit : BCC +
LDA.l ProgressiveBowReplacement
JMP.w .get_item
+
LDA.w ItemReceiptMethod : CMP.b #$01 : BEQ +
LDX.w CurrentSpriteSlot
LDA.b #$20 : STA.w SpriteMetaData,X
+
LDA.l BowEquipment : TAX
LDA.w .bows_ids,X
JMP.w .get_item
.bows
..ids
db $3A, $3B, $3B, $3B, $3B
.null_chest
; JSL ChestItemServiceRequest
JMP.w .have_item
.rng_single
JSL.l GetRNGItemSingle : STA.l ScratchBufferV+6
XBA : JSR.w MarkRNGItemSingle
LDA.b #$FF : STA.l RNGLockIn ; clear lock-in
LDA.l ScratchBufferV+6 : JMP.w .get_item
.rng_multi
JSL.l GetRNGItemMulti : STA.l ScratchBufferV+6
LDA.b #$FF : STA.l RNGLockIn ; clear lock-in
LDA.l ScratchBufferV+6 : JMP.w .get_item
;--------------------------------------------------------------------------------
DungeonItemMasks:
; these are dungeon correlations to $7EF364 - $7EF369 so it knows where to store compasses, etc
; sewers and castle get 2 bits active so that they can share their items elegantly
dw $C000, $C000, $2000, $1000, $0800, $0400, $0200, $0100
dw $0080, $0040, $0020, $0010, $0008, $0004, $4B8B, $20AB ; last two can be re-used
; caves
dw $9CCE, $0390, $2F82, $AD03, $02E9, $01C9, $06D0, $72A5
dw $A548, $4873, $01A0, $D8AD, $C902, $D020, $A002, $9802
dw $E48D, $DA02, $D8AC, $D002, $A215, $BD08, $84E2, $0085
dw $E3BD, $8584, $A901, $857E, $B902, $857A, $0087, $0A98
dw $BDAA, $84E2, $0085, $E3BD, $8584, $A901, $857E, $B902
dw $857A, $0230, $0087, $1FC0, $02D0, $5664, $04A9, $4BC0
dw $06F0, $1EC0, $0AD0, $02A9, $790F, $7EF3, $798F, $7EF3
dw $1BC0, $04F0, $1CC0, $07D0, $1B22, $1BEE, $0182, $A201
dw $C004, $F037, $A20C, $C001, $F038, $A206, $C002, $D039
dw $8A14, $0007, $0087, $00EE, $2902, $C907, $D007, $A906
dw $8F04, $F3C7, $C07E, $D022, $A70A, $D000, $A904, $8701
dw $8000, $C0C9, $F025, $C008, $F032, $C004, $D033, $AE11
dw $040C, $20C2, $C6BD, $0785, $8700, $E200, $8220, $00B0
dw $3EC0, $0AD0, $082C, $1003, $A905, $8D02, $0309, $20C0
dw $44D0
;--------------------------------------------------------------------------------
BottleListExpanded:
db $16, $2B, $2C, $2D, $3D, $3C, $48
PotionListExpanded:
db $2E, $2F, $30, $FF, $0E
;--------------------------------------------------------------------------------
HandleBowTracking:
; In: A - Item Receipt ID
PHA
CMP.b #$64 : BEQ .prog_one
CMP.b #$65 : BEQ .prog_two
CMP.b #$0B : BEQ .vanilla_bow
CMP.b #$3A : BEQ .vanilla_bow
CMP.b #$3B : BEQ .vanilla_bow
PLA
RTS
.prog_one
LDA.b #$10
BRA .done
.prog_two
LDA.b #$20
BRA .done
.vanilla_bow
; A non-chest progressive bow will always have been resolved to a vanilla bow ID
; at this point.
LDA.w ItemReceiptMethod : CMP.b #$01 : BEQ +
LDX.w CurrentSpriteSlot
LDA.w SpriteMetaData,X : BEQ .done
BRA .done
+
LDA.b #$00
.done
ORA.b #$80 : ORA.l BowTracking
STA.l BowTracking
PLA
RTS
;--------------------------------------------------------------------------------
;Return BowEquipment but also draw silver arrows if you have the upgrade even if you don't have the bow
CheckHUDSilverArrows:
LDA.l ArrowMode : BNE .rupee_bow
LDA.l BowEquipment : TAX : BEQ .nobow
JSL.l DrawHUDArrows_normal
TXA
RTL
.rupee_bow
LDA.l BowEquipment : TAX
JSL.l DrawHUDArrows_rupee_arrows
TXA
RTL
.nobow
JSL.l DrawHUDArrows_silverscheck
TXA
RTL
;--------------------------------------------------------------------------------
DrawHUDArrows:
.rupee_arrows
LDA.l CurrentArrows : BEQ .none ; assuming silvers will increment this. if we go with something else, reorder these checks
TXA : BNE +
.silverscheck
LDA.l BowTracking : AND.b #$40 : BNE .silver
BRA .wooden
+ CMP.b #03 : !BGE .silver
.wooden
LDA.b #$A7 : STA.l HUDTileMapBuffer+$20 ; draw wooden arrow marker
LDA.b #$20 : STA.l HUDTileMapBuffer+$21
LDA.b #$A9 : STA.l HUDTileMapBuffer+$22
LDA.b #$20 : STA.l HUDTileMapBuffer+$23
.skip
RTL
.normal
TXA
CMP.b #$03 : BCS .silver
BRA .wooden
.silver
LDA.b #$86 : STA.l HUDTileMapBuffer+$20 ; draw silver arrow marker
LDA.b #$24 : STA.l HUDTileMapBuffer+$21
LDA.b #$87 : STA.l HUDTileMapBuffer+$22
LDA.b #$24 : STA.l HUDTileMapBuffer+$23
RTL
.none
LDA.b #$7F : STA.l HUDTileMapBuffer+$20 ; draw no arrow marker
LDA.b #$24 : STA.l HUDTileMapBuffer+$21
LDA.b #$7F : STA.l HUDTileMapBuffer+$22
LDA.b #$24 : STA.l HUDTileMapBuffer+$23
RTL
;--------------------------------------------------------------------------------
GetRNGItemSingle:
PHY
LDA.l RNGLockIn : CMP.b #$FF : BEQ + : TAX : XBA : LDA.l RNGSingleItemTable, X : RTL : +
LDX.b #$00
.single_reroll
JSL.l GetRandomInt : AND.b #$7F ; select random value
INX : CPX.b #$7F : BCC + : LDA.b #$00 : BRA +++ : + ; default to 0 if too many attempts
CMP.l RNGSingleTableSize : !BGE .single_reroll
+++
STA.l ScratchBufferV ; put our index value here
LDX.b #$00
TAY
.recheck
TYA
JSR.w CheckSingleItem : BEQ .single_unused ; already used
LDA.l ScratchBufferV : INC ; increment index
CMP.l RNGSingleTableSize : BCC +++ : LDA.b #$00 : +++ ; rollover index if needed
STA.l ScratchBufferV ; store index
INX : TAY : TXA : CMP.l RNGSingleTableSize : BCC .recheck
LDA.b #$5A ; everything is gone, default to null item - MAKE THIS AN OPTION FOR THIS AND THE OTHER ONE
BRA .single_done
.single_unused
LDA.l ScratchBufferV
.single_done
TAX : LDA.l RNGSingleItemTable, X
XBA : LDA.l ScratchBufferV : STA.l RNGLockIn : XBA
PLY
RTL
;--------------------------------------------------------------------------------
CheckSingleItem:
LSR #3 : TAX
LDA.l RNGItem, X : STA.l ScratchBufferV+2 ; load value to temporary
PHX
LDA.l ScratchBufferV : AND.b #$07 : TAX ; load 0-7 part into X
LDA.l ScratchBufferV+2
---
CPX.b #$00 : BEQ +++
LSR
DEX
BRA ---
+++
PLX
AND.b #$01
RTS
;--------------------------------------------------------------------------------
MarkRNGItemSingle:
LSR #3 : STA.l ScratchBufferV+1 : TAX
LDA.l RNGItem, X
STA.l ScratchBufferV+2
LDA.l ScratchBufferV : AND.b #$07 : TAX ; load 0-7 part into X
LDA.b #01
---
CPX.b #$00 : BEQ +++
ASL
DEX
BRA ---
+++
PHA
LDA.l ScratchBufferV+1 : TAX
PLA
ORA.l ScratchBufferV+2
STA.l RNGItem, X
RTS
;--------------------------------------------------------------------------------
GetRNGItemMulti:
LDA.l RNGLockIn : CMP.b #$FF : BEQ + : TAX : XBA : LDA.l RNGMultiItemTable, X : RTL : +
LDX.b #$00