From 2e97329250cf2a61c21184bd8b85daed74e5e307 Mon Sep 17 00:00:00 2001 From: cassidy Date: Thu, 2 Dec 2021 01:37:27 -0500 Subject: [PATCH] Refactor inventory code and add more labels Refactored highest sword, shield, and mail counting Refactored how heart pieces, heart containers, and crystals are counted Moved quickswap lock bit to high byte of InventoryTracking Fixed sword and shield item downgrade Added PreFluteLocations counter --- goalitem.asm | 4 +- inventory.asm | 261 +++++++++++++++++++++++----------------------- itemdowngrade.asm | 36 ++++--- newitems.asm | 21 ++-- quickswap.asm | 10 +- sram.asm | 31 ++++-- utilities.asm | 26 ++--- 7 files changed, 205 insertions(+), 184 deletions(-) diff --git a/goalitem.asm b/goalitem.asm index 9c7e900..474e86e 100644 --- a/goalitem.asm +++ b/goalitem.asm @@ -125,12 +125,12 @@ GetRequiredCrystalsInX: RTL ;-------------------------------------------------------------------------------- CheckEnoughCrystalsForGanon: - LDA CrystalsField : JSL CountBits ; the comparison is against 1 less + LDA CrystalCounter CMP.l NumberOfCrystalsRequiredForGanon RTL ;-------------------------------------------------------------------------------- CheckEnoughCrystalsForTower: - LDA CrystalsField : JSL CountBits ; the comparison is against 1 less + LDA CrystalCounter CMP.l NumberOfCrystalsRequiredForTower RTL diff --git a/inventory.asm b/inventory.asm index 08944f7..322f0a4 100644 --- a/inventory.asm +++ b/inventory.asm @@ -1,19 +1,19 @@ ;================================================================================ ; 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 +; InventoryTracking +; brmpnskf -------q +; 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" +; BowTracking ; Item Tracking Slot #2 ; bsp----- ; b = bow @@ -23,13 +23,13 @@ ; - ; - ; - -; q = quickswap lock +; - ;-------------------------------------------------------------------------------- ; ProcessMenuButtons: ; out: Carry - 0 = No Button, 1 = Yes Button ;-------------------------------------------------------------------------------- ProcessMenuButtons: - ;LDA #$FD : STA !INVENTORY_SWAP ; DEBUG MODE + ;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 @@ -57,12 +57,12 @@ RTL 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 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 !INVENTORY_SWAP_2 : AND #$C0 : CMP #$C0 : BNE .errorJump ; make sure we have both bows + 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 +++ @@ -72,18 +72,18 @@ RTL 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 + LDA BowEquipment : CMP.b #$03 : !BLT .errorJump : !SUB #$02 : STA BowEquipment BRA .errorJump2 ++ - LDA $7EF340 : !SUB #$01 : EOR #$02 : !ADD #$01 : STA $7EF340 ; swap bows + 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 !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 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 + @@ -91,11 +91,11 @@ RTL 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 + LDA InventoryTracking : 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 FluteEquipment : CMP #01 : BNE .toShovel ; not shovel - LDA !INVENTORY_SWAP : AND #$01 : BEQ .toFakeFlute ; check for real flute + LDA InventoryTracking : AND #$01 : BEQ .toFakeFlute ; check for real flute LDA #$03 ; set real flute BRA .fluteSuccess .toFakeFlute @@ -104,7 +104,7 @@ RTL .toShovel LDA #$01 ; set shovel .fluteSuccess - STA $7EF34C ; store set item + STA FluteEquipment ; store set item LDA.b #$20 : STA $012F ; menu select sound BRA .captured + @@ -112,7 +112,7 @@ RTL CLC RTL .midShovel - ; LDA #$01 : STA $7EF34C ; set shovel + ; LDA #$01 : STA FluteEquipment ; set shovel .error LDA.b #$3C : STA $012E ; error sound .captured @@ -127,13 +127,13 @@ 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 $7EF34F ; check bottle state + 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 $7EF35C-1, X ; check bottle + TAX : LDA BottleContents-1, X ; check bottle BNE + : LDX #$01 : + ; wrap if we reached the last bottle - TXA : STA $7EF34F ; set bottle index + TXA : STA BottleIndex ; set bottle index LDA.b #$20 : STA $012F ; menu select sound PLX .no_bottles @@ -204,47 +204,47 @@ FullInventoryExternal: AddInventory: PHA : PHX : PHP CPY.b #$0C : BNE + ; Blue Boomerang - LDA !INVENTORY_SWAP : ORA #$80 : STA !INVENTORY_SWAP + LDA InventoryTracking : ORA #$80 : STA InventoryTracking JMP .incrementCounts + CPY.b #$2A : BNE + ; Red Boomerang - LDA !INVENTORY_SWAP : ORA #$40 : STA !INVENTORY_SWAP + LDA InventoryTracking : ORA #$40 : STA InventoryTracking JMP .incrementCounts + CPY.b #$29 : BNE + ; Mushroom - LDA !INVENTORY_SWAP : ORA #$28 : STA !INVENTORY_SWAP + LDA InventoryTracking : ORA #$28 : STA InventoryTracking JMP .incrementCounts + CPY.b #$0D : BNE + ; Magic Powder - LDA !INVENTORY_SWAP : ORA #$10 : STA !INVENTORY_SWAP + LDA InventoryTracking : ORA #$10 : STA InventoryTracking JMP .incrementCounts + CPY.b #$13 : BNE + ; Shovel - LDA !INVENTORY_SWAP : ORA #$04 : STA !INVENTORY_SWAP + LDA InventoryTracking : ORA #$04 : STA InventoryTracking JMP .incrementCounts + CPY.b #$14 : BNE + ; Flute (Inactive) - LDA !INVENTORY_SWAP : ORA #$02 : STA !INVENTORY_SWAP + LDA InventoryTracking : ORA #$02 : STA InventoryTracking JMP .incrementCounts + CPY.b #$4A : BNE + ; Flute (Active) - LDA !INVENTORY_SWAP : ORA #$01 : STA !INVENTORY_SWAP + LDA InventoryTracking : ORA #$01 : STA InventoryTracking JMP .incrementCounts + CPY.b #$0B : BNE + ; Bow LDA ArrowMode : BNE +++ - LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 + LDA BowTracking : ORA #$80 : STA BowTracking +++ JMP .incrementCounts + CPY.b #$3A : BNE + ; Bow & Arrows - LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 + LDA BowTracking : ORA #$80 : STA BowTracking JMP .incrementCounts + CPY.b #$3B : BNE + ; Bow & Silver Arrows - LDA !INVENTORY_SWAP_2 : ORA #$40 : STA !INVENTORY_SWAP_2 + LDA BowTracking : ORA #$40 : STA BowTracking LDA ArrowMode : BNE +++ - LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 ; activate wood arrows when not in rupee bow + 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 !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 ; activate wood arrows in quick-swap + LDA BowTracking : ORA #$80 : STA BowTracking ; activate wood arrows in quick-swap +++ JMP .incrementCounts + CPY.b #$58 : BNE + ; Upgrade-Only Silver Arrows - LDA !INVENTORY_SWAP_2 : ORA #$40 : STA !INVENTORY_SWAP_2 + LDA BowTracking : ORA #$40 : STA BowTracking + .incrementCounts @@ -259,7 +259,6 @@ AddInventory: CPY.b #$37 : BNE + : JMP .itemCounts : + ; Pendant CPY.b #$38 : BNE + : JMP .itemCounts : + ; Pendant CPY.b #$39 : BNE + : JMP .itemCounts : + ; Pendant - CPY.b #$00 : BNE + : JMP .itemCounts : + ; Uncle Sword & Shield CPY.b #$04 : !BLT .isSword ; Swords - Skip Shop/Fairy Check for Swords CPY.b #$49 : BEQ .isSword @@ -353,7 +352,7 @@ AddInventory: JMP .fullItemCounts + CMP.b #$1A : BNE + ; Ganon's Tower LDA $7EF436 : !ADD #$08 : STA $7EF436 - LDA $7EF366 : AND #$04 : BNE ++ + LDA BigKeyField : AND #$04 : BNE ++ JSR .incrementGTowerPreBigKey ++ ;JMP .fullItemCounts @@ -362,16 +361,20 @@ AddInventory: ; == END INDOOR-ONLY SECTION .fullItemCounts - CPY.b #$3B : BNE + ; Skip Total Counts for Repeat Silver Arrows - LDA $7EF42A : BIT #$20 : BEQ + : BRA .itemCounts + ;CPY.b #$3B : BNE + ; Skip Total Counts for Repeat Silver Arrows + ; LDA $7EF42A : BIT #$20 : BEQ + : BRA .itemCounts + ;+ + + LDA BootsEquipment : BNE + ; Check for Boots + LDA PreBootsLocations : INC : STA PreBootsLocations ; Increment Pre Boots Counter + - LDA $7EF355 : BNE + ; Check for Boots - LDA $7EF432 : INC : STA $7EF432 ; Increment Pre Boots Counter + LDA MirrorEquipment : BNE + ; Check for Mirror + LDA PreMirrorLocations : INC : STA PreMirrorLocations ; Increment Pre Mirror Counter + - LDA $7EF353 : BNE + ; Check for Mirror - LDA $7EF433 : INC : STA $7EF433 ; Increment Pre Mirror Counter + LDA FluteEquipment : BNE + ; Check for Flute + LDA PreFluteLocations : INC : STA PreFluteLocations ; Increment Pre Mirror Counter + LDA $7EF423 : INC : STA $7EF423 ; Increment Item Total @@ -379,25 +382,32 @@ AddInventory: .itemCounts 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 @@ -436,10 +446,12 @@ AddInventory: + CPY.b #$21 : BNE + ; Bug Net JSR .incrementY JMP .done - + CPY.b #$22 : !BLT + ; Items $22 - $23 - CPY.b #$24 : !BGE + - JSR .incrementMail - 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 @@ -450,10 +462,10 @@ AddInventory: ;JSR .incrementHeartContainer JMP .done + CPY.b #$27 : BNE + ; 1 Bomb - JSR .maybeIncrementBombs + ;JSR .maybeIncrementBombs JMP .done + CPY.b #$28 : BNE + ; 3 Bombs - JSR .maybeIncrementBombs + ;JSR .maybeIncrementBombs JMP .done + CPY.b #$29 : BNE + ; Musoroom JSR .incrementY @@ -463,7 +475,7 @@ AddInventory: JSR .incrementY JMP .done + CPY.b #$31 : BNE + ; 10 Bombs - JSR .maybeIncrementBombs + ;JSR .maybeIncrementBombs JMP .done + CPY.b #$32 : BNE + ; Big Key JSR .incrementBigKey @@ -493,6 +505,7 @@ AddInventory: JSR .incrementY JMP .done + CPY.b #$49 : BNE + ; Fighter's Sword + LDX #$01 JSR .incrementSword JMP .done + CPY.b #$4A : BNE + ; Flute (Active) @@ -505,29 +518,33 @@ AddInventory: JMP .done + CPY.b #$4C : BNE + ; Bomb Capacity Upgrade JSR .incrementCapacity - JSR .maybeIncrementBombs + ;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 : !BLT + ; Items $51 - $54 - Capacity Upgrades CPY.b #$55 : !BGE + JSR .incrementCapacity JMP .done - + CPY.b #$58 : BNE + ; Upgrade-Only Sivler Arrows + + CPY.b #$58 : BNE + ; Upgrade-Only Silver Arrows JSR .incrementBow JMP .done + CPY.b #$5E : BNE + ; Progressive Sword + LDA SwordEquipment : TAX JSR .incrementSword JMP .done + CPY.b #$5F : BNE + ; Progressive Shield + LDA ShieldEquipment : TAX JSR .incrementShield JMP .done + CPY.b #$60 : BNE + ; Progressive Armor + LDA ArmorEquipment : TAX JSR .incrementMail JMP .done + CPY.b #$61 : BNE + ; Progressive Lifting Glove @@ -608,72 +625,58 @@ RTS 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 + LDA HighestSword + INC : STA $04 : CPX $04 : !BLT + ; don't increment unless we're getting a better sword + TXA : STA HighestSword + + RTS .incrementShield - ; CHECK FOR DUPLICATE SHIELDS - LDA $7EF422 : !ADD #$08 : AND #$18 : TAX - LDA $7EF422 : AND #$E7 : STA $7EF422 - TXA : ORA $7EF422 : STA $7EF422 + LDA HighestShield + INC : STA $04 : CPX $04 : !BLT + ; don't increment unless we're getting a better shield + TXA : STA HighestShield + + RTS .incrementBow - CPY.b #$3B : BNE ++ - LDA $7EF42A : BIT #$20 : BEQ + : RTS : + - ORA #$20 : STA $7EF42A - ++ + LDA BowEquipment : BNE .dontCount ; Don't increment Y item count for extra bows .incrementY - LDA $7EF421 : !ADD #$08 : STA $7EF421 + LDA YAItemCounter : !ADD #$08 : STA YAItemCounter +.dontCount RTS .incrementA - LDA $7EF421 : INC : AND #$07 : TAX - LDA $7EF421 : AND #$F8 : STA $7EF421 - TXA : ORA $7EF421 : STA $7EF421 + LDA YAItemCounter : INC : AND #$07 : TAX + LDA YAItemCounter : AND #$F8 : STA YAItemCounter + TXA : ORA YAItemCounter : STA YAItemCounter RTS .incrementPendant - LDA $7EF429 : INC : AND #$03 : TAX - LDA $7EF429 : AND #$FC : STA $7EF429 - TXA : ORA $7EF429 : STA $7EF429 - ; JSR .incrementBossSword + LDA PendantCounter : INC : STA PendantCounter RTS .incrementCapacity - %BottomHalf($7EF452) + LDA CapacityUpgrades : INC : STA CapacityUpgrades RTS .incrementHeartPiece - LDA $7EF448 : INC : AND #$1F : TAX - LDA $7EF448 : AND #$E0 : STA $7EF448 - TXA : ORA $7EF448 : STA $7EF448 + LDA HeartPieceCounter : INC : STA HeartPieceCounter RTS .incrementHeartContainer - %TopHalf($7EF429) + LDA HeartContainerCounter : INC : STA HeartContainerCounter RTS .incrementCrystal - LDA $7EF422 : INC : AND #$07 : TAX - LDA $7EF422 : AND #$F8 : STA $7EF422 - TXA : ORA $7EF422 : STA $7EF422 - ; JSR .incrementBossSword + LDA CrystalCounter : INC : STA CrystalCounter RTS .incrementMail - LDA $7EF424 : !ADD #$40 : STA $7EF424 + LDA HighestMail + INC : STA $04 : CPX $04 : !BLT + ; don't increment unless we're getting a better mail + TXA : STA HighestMail + + RTS .incrementKeyLong @@ -702,12 +705,12 @@ RTS TXA : ORA $7EF42A : STA $7EF42A RTS -.maybeIncrementBombs - LDA $7EF42A : AND #$80 : BNE + - LDA $7EF42A : ORA #$80 : STA $7EF42A - JSR .incrementY - + -RTS +;.maybeIncrementBombs +; LDA $7EF42A : AND #$80 : BNE + +; LDA $7EF42A : ORA #$80 : STA $7EF42A +; JSR .incrementY +; + +;RTS .incrementMap LDA $7EF428 : !ADD #$10 : STA $7EF428 @@ -718,7 +721,7 @@ RTS RTL .incrementBossSword - LDA $7EF359 + LDA SwordEquipment BNE + : - %TopHalf($7EF452) : RTS + CMP #$FF : BEQ - @@ -738,11 +741,11 @@ RTS ; Link_ReceiveItem_HUDRefresh: ;-------------------------------------------------------------------------------- Link_ReceiveItem_HUDRefresh: - LDA $7EF343 : BNE + ; skip if we have bombs - LDA $7EF370 : !ADD.l StartingMaxBombs : BEQ + ; skip if we can't 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 + 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 @@ -754,9 +757,9 @@ RTL ; HandleBombAbsorbtion: ;-------------------------------------------------------------------------------- HandleBombAbsorbtion: - STA $7EF375 ; thing we wrote over + STA BombsFiller ; thing we wrote over LDA $0303 : BNE + ; skip if we already have some item selected - LDA $7EF370 : !ADD.l StartingMaxBombs : BEQ + ; skip if we can't have bombs + 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 @@ -771,13 +774,13 @@ RTL 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 + LDA InventoryTracking : 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 + LDA BowTracking : 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 + LDA InventoryTracking : 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 + 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 @@ -831,8 +834,8 @@ 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 + LDA InventoryTracking : AND #$FC : ORA #$01 : STA InventoryTracking ; switch to the working flute + LDA.b #$03 : STA FluteEquipment ; upgrade primary inventory RTL ;-------------------------------------------------------------------------------- @@ -859,10 +862,10 @@ RTL ;-------------------------------------------------------------------------------- LoadKeys: LDA.l GenericKeys : BEQ + - LDA $7EF38B + LDA CurrentGenericKeys RTL + - LDA $7EF37C, X + LDA SewerKeys, X RTL ;-------------------------------------------------------------------------------- @@ -872,10 +875,10 @@ RTL SaveKeys: PHA LDA.l GenericKeys : BEQ + - PLA : STA $7EF38B + PLA : STA CurrentGenericKeys RTL + - PLA : STA $7EF37C, X + PLA : STA SewerKeys, X RTL ;-------------------------------------------------------------------------------- @@ -889,10 +892,10 @@ ClearOWKeys: JSL.l FakeWorldFix JSR.w FixBunnyOnExitToLightWorld LDA.l GenericKeys : BEQ + - PLA : LDA $7EF38B : STA $7EF36F + PLA : LDA CurrentGenericKeys : STA CurrentSmallKeys RTL + - PLA : STA $7EF36F + PLA : STA CurrentSmallKeys RTL ;-------------------------------------------------------------------------------- @@ -955,10 +958,10 @@ RTL ; InitializeBottles: ;-------------------------------------------------------------------------------- InitializeBottles: - STA $7EF35C, X ; thing we wrote over + STA BottleContents, X ; thing we wrote over PHA - LDA $7EF34F : BNE + - TXA : INC : STA $7EF34F ; write bottle index to menu properly + LDA BottleIndex : BNE + + TXA : INC : STA BottleIndex ; write bottle index to menu properly + PLA RTL @@ -1047,12 +1050,12 @@ RTL ; RemoveMushroom: ;-------------------------------------------------------------------------------- RemoveMushroom: - LDA !INVENTORY_SWAP : AND #$DF : STA !INVENTORY_SWAP ; remove the mushroom + LDA InventoryTracking : AND #$DF : STA InventoryTracking ; remove the mushroom AND #$10 : BEQ .empty ; check if we have powder - LDA.b #$02 : STA $7EF344 ; give powder if we have it + LDA.b #$02 : STA PowderEquipment ; give powder if we have it RTL .empty - LDA.b #$00 : STA $7EF344 ; clear the inventory slot if we don't have powder + LDA.b #$00 : STA PowderEquipment ; clear the inventory slot if we don't have powder RTL ;-------------------------------------------------------------------------------- @@ -1060,7 +1063,7 @@ RTL ; DrawMagicHeader: ;-------------------------------------------------------------------------------- DrawMagicHeader: - LDA $7EF37B : AND.w #$00FF : CMP.w #$0002 : BEQ .quarterMagic + LDA MagicConsumption : AND.w #$00FF : CMP.w #$0002 : BEQ .quarterMagic .halfMagic LDA.w #$28F7 : STA $7EC704 LDA.w #$2851 : STA $7EC706 @@ -1078,7 +1081,7 @@ RTL ;-------------------------------------------------------------------------------- ;FixShovelLock: ; LDA $037A : CMP #$01 : BEQ + ; skip if link is shoveling -; LDA $7EF34C ; load shovel/flute item ID +; LDA FluteEquipment ; load shovel/flute item ID ; + ; CMP #$00 ;RTL diff --git a/itemdowngrade.asm b/itemdowngrade.asm index 9d08af2..ebea4bc 100644 --- a/itemdowngrade.asm +++ b/itemdowngrade.asm @@ -17,10 +17,10 @@ ItemDowngradeFixMain: CPY.b #$0B : BEQ .isBow ; Bow CPY.b #$3A : BEQ .isBowAndArrows ; Bow - CPY.b #$49 : BEQ .isFightersSword ; Fighter's Sword - CPY.b #$01 : BEQ .isMasterSword ; Master Sword - CPY.b #$50 : BEQ .isMasterSword ; Master Sword (Safe) - CPY.b #$02 : BEQ .isTemperedSword ; Tempered Sword + CPY.b #$49 : BEQ .isSword ; Fighter's Sword + CPY.b #$01 : BEQ .isSword ; Master Sword + CPY.b #$50 : BEQ .isSword ; Master Sword (Safe) + CPY.b #$02 : BEQ .isSword ; Tempered Sword CPY.b #$3B : BEQ .isSilverArrowBow ; Silver Arrow Bow CPY.b #$2A : BEQ .isRedBoomerang ; Red Boomerang @@ -29,7 +29,9 @@ ItemDowngradeFixMain: CPY.b #$13 : BEQ .isShovel ; Shovel CPY.b #$29 : BEQ .isMushroom ; Mushroom - .done + CPY.b #$00 : BEQ .isUncleSwordShield ; Fighter's Sword & Shield + + .done STA [$00] ; thing we wrote over part 2 .dontWrite RTS @@ -56,18 +58,28 @@ RTS + PLA RTS - .isFightersSword - .isMasterSword - .isTemperedSword + .isSword PHA + LDA HighestSword : STA $04 TYA ; load sword item CMP.b #$49 : BNE + : LDA.b #$00 : + ; convert extra fighter's sword to normal one CMP.b #$50 : BNE + : LDA.b #$01 : + ; convert extra master sword to normal one - INC : CMP !HIGHEST_SWORD_LEVEL : !BGE + ; skip if highest is lower (this is an upgrade) - LDA !HIGHEST_SWORD_LEVEL : DEC ; convert to item id - TAY : PLA : LDA !HIGHEST_SWORD_LEVEL ; put sword id into the thing to write + INC : CMP $04 : !BGE + ; skip if highest is lower (this is an upgrade) + LDA $04 : DEC ; convert to item id + TAY : PLA : LDA $04 ; put sword id into the thing to write JMP .done + PLA JMP .done -;================================================================================ \ No newline at end of file + .isUncleSwordShield + PHA + LDA HighestSword + STA [$00] ; already set to 1 if we had no sword, always keep highest + LDA ShieldEquipment : BNE + ; keep our shield unless we have no shield + INC $00 + INC A + STA [$00] + + + PLA +RTS +;================================================================================ diff --git a/newitems.asm b/newitems.asm index f9fbb3c..d27836f 100755 --- a/newitems.asm +++ b/newitems.asm @@ -142,9 +142,6 @@ macro ValueShift() BRA ?start : ?end: endmacro ;-------------------------------------------------------------------------------- -!CHALLENGE_TIMER = "$7EF454" -!GOAL_COUNTER = "$7EF418" -;-------------------------------------------------------------------------------- ;carry clear if pass ;carry set if caught ;incsrc eventdata.asm @@ -170,7 +167,7 @@ ProcessEventItems: SEP #$10 ; set 8-bit index registers LDA GoalItemRequirement : BEQ ++ - LDA !GOAL_COUNTER : INC : STA !GOAL_COUNTER + LDA GoalCounter : INC : STA GoalCounter CMP GoalItemRequirement : !BLT ++ LDA TurnInGoalItems : BNE ++ JSL.l ActivateGoal @@ -192,7 +189,7 @@ AddReceivedItemExpandedGetItem: ;JSR.w ProcessEventItems : CPX.b #$00 : BEQ ++ ; ;JSL.l Main_ShowTextMessage_Alt - ; LDA !GOAL_COUNTER : INC : STA !GOAL_COUNTER + ; LDA GoalCounter : INC : STA GoalCounter ; LDA.b #$01 : STA $7F50XX ; JMP .done ;++ @@ -283,20 +280,20 @@ AddReceivedItemExpandedGetItem: JMP .done + CMP.b #$5B : BNE + ; Red Clock REP #$20 ; set 16-bit accumulator - LDA !CHALLENGE_TIMER : !ADD.l RedClockAmount : STA !CHALLENGE_TIMER - LDA !CHALLENGE_TIMER+2 : ADC.l RedClockAmount+2 : STA !CHALLENGE_TIMER+2 + LDA ChallengeTimer : !ADD.l RedClockAmount : STA ChallengeTimer + LDA ChallengeTimer+2 : ADC.l RedClockAmount+2 : STA ChallengeTimer+2 SEP #$20 ; set 8-bit accumulator JMP .done + CMP.b #$5C : BNE + ; Blue Clock REP #$20 ; set 16-bit accumulator - LDA !CHALLENGE_TIMER : !ADD.l BlueClockAmount : STA !CHALLENGE_TIMER - LDA !CHALLENGE_TIMER+2 : ADC.l BlueClockAmount+2 : STA !CHALLENGE_TIMER+2 + LDA ChallengeTimer : !ADD.l BlueClockAmount : STA ChallengeTimer + LDA ChallengeTimer+2 : ADC.l BlueClockAmount+2 : STA ChallengeTimer+2 SEP #$20 ; set 8-bit accumulator JMP .done + CMP.b #$5D : BNE + ; Green Clock REP #$20 ; set 16-bit accumulator - LDA !CHALLENGE_TIMER : !ADD.l GreenClockAmount : STA !CHALLENGE_TIMER - LDA !CHALLENGE_TIMER+2 : ADC.l GreenClockAmount+2 : STA !CHALLENGE_TIMER+2 + LDA ChallengeTimer : !ADD.l GreenClockAmount : STA ChallengeTimer + LDA ChallengeTimer+2 : ADC.l GreenClockAmount+2 : STA ChallengeTimer+2 SEP #$20 ; set 8-bit accumulator JMP .done + CMP.b #$5E : BNE + ; Progressive Sword @@ -323,7 +320,7 @@ AddReceivedItemExpandedGetItem: + CMP.b #$6C : BNE + ; Goal Collectable (Multi/Power Star) Alternate Graphic .multi_collect LDA GoalItemRequirement : BEQ ++ - LDA !GOAL_COUNTER : INC : STA !GOAL_COUNTER + LDA GoalCounter : INC : STA GoalCounter CMP GoalItemRequirement : !BLT ++ LDA TurnInGoalItems : BNE ++ JSL.l ActivateGoal diff --git a/quickswap.asm b/quickswap.asm index d23bddd..1331614 100644 --- a/quickswap.asm +++ b/quickswap.asm @@ -28,7 +28,7 @@ QuickSwap: BRA .store .special_swap - LDA BowTracking : ORA #$01 : STA BowTracking + LDA InventoryTracking+1 : ORA #$01 : STA InventoryTracking+1 CPX.b #$02 : BEQ + ; boomerang CPX.b #$01 : BEQ + ; bow CPX.b #$05 : BEQ + ; powder @@ -50,10 +50,10 @@ RTL RCode: LDX.w $0202 LDA.b $F2 : BIT #$20 : BNE ++ ; Still holding L from a previous frame - LDA BowTracking : AND #$FE : STA BowTracking + LDA InventoryTracking+1 : AND #$FE : STA InventoryTracking+1 BRA + ++ - LDA BowTracking : BIT #$01 : BEQ + + LDA InventoryTracking+1 : BIT #$01 : BEQ + RTS - + CPX.b #$14 : BNE + : LDX.b #$00 ;will wrap around to 1 @@ -65,10 +65,10 @@ RTS LCode: LDX.w $0202 LDA.b $F2 : BIT #$10 : BNE ++ ; Still holding R from a previous frame - LDA BowTracking : AND #$FE : STA BowTracking + LDA InventoryTracking+1 : AND #$FE : STA InventoryTracking+1 BRA + ++ - LDA BowTracking : BIT #$01 : BEQ + + LDA InventoryTracking+1 : BIT #$01 : BEQ + RTS - + CPX.b #$01 : BNE + : LDX.b #$15 ; will wrap around to $14 diff --git a/sram.asm b/sram.asm index cc30c26..016cee5 100644 --- a/sram.asm +++ b/sram.asm @@ -161,10 +161,10 @@ CurrentGenericKeys: skip 1 ; Generic small keys ;================================================================================ ; Tracking & Indicators ($7EF38C - $7EF3F0) ;-------------------------------------------------------------------------------- -InventoryTracking: skip 2 ; b r m p n s k f (bitfield) - ; b = Blue Boomerang | r = Red Boomerang | m = Mushroom Current - ; p = Magic Powder | n = Mushroom Past | s = Shovel - ; k = Inactive Flute | f = Active Flute +InventoryTracking: skip 2 ; b r m p n s k f - - - - - - - q (bitfield) + ; b = Blue Boomerang | r = Red Boomerang | m = Mushroom Current + ; p = Magic Powder | n = Mushroom Past | s = Shovel + ; k = Inactive Flute | f = Active Flute | q = Quickswap locked BowTracking: skip 2 ; b s p - - - - - (bitfield) ; b = Bow | s = Silver Arrows Upgrade | p = Second Progressive Bow ; The front end writes two distinct progressive bow items. p @@ -250,8 +250,7 @@ BigKeysBigChests: skip 1 ; k k k k c c c c (packed integers) ; k = Big Keys collected | c = Big Chests opened MapsCompasses: skip 1 ; m m m m c c c c (packed integers) ; m = Maps collected | c = Compasses collected -HeartPiecesPendants: skip 1 ; h h h h - - p p (packed integers) - ; h = Heart Pieces collected | p = Pendants collected +PendantCounter: skip 1 ; Number of pendants collected (integer) PreGTBKLocations: skip 1 ; Locations checked in GT before finding the big key ; b = Big Bomb Acquired | s = Silver Arrows Acquired ; c = GT locations collected before big key @@ -269,11 +268,12 @@ NMIFrames: skip 4 ; Frame counter incremented during NMI hook (32- ChestsOpened: skip 1 ; Number of chests opened. Doesn't count NPC, free standing items etc (integer) StatsLocked: skip 1 ; Set to $01 when goal is completed; game stops counting stats. MenuTime: skip 4 ; Total menu time in frames (32-bit integer) -HeartPieces: skip 1 ; Total number of heart pieces collected (integer) +HeartContainerCounter: skip 1 ; Total number of heart containers collected (integer) DeathCounter: skip 1 ; Number of deaths (integer) skip 1 ; Reserved FluteCounter: skip 1 ; Number of times fluted (integer) -skip 6 ; +skip 4 ; +RNGItem: skip 2 ; RNG Item SwordlessBosses: skip 1 ; Number of bosses killed without a sword (integer) FaerieRevivalCounter: skip 1 ; Number of faerie revivals (integer) ChallengeTimer: skip 4 ; Timer used for OHKO etc @@ -287,7 +287,9 @@ DamageCounter: skip 2 ; Damage taken by player (16-bit integer) MagicCounter: skip 2 ; Magic used by player (16-bit integer) HighestMail: skip 1 ; Highest mail level SmallKeyCounter: skip 1 ; Total Number of small keys collected (integer) -skip 48 ; Unused +HeartPieceCounter: skip 1 ; Total Number of heartpieces collected (integer) +CrystalCounter: skip 1 ; Total Number of crystals collected (integer) +skip 46 ; Unused ServiceSequence: skip 1 ; Service sequence value. See servicerequest.asL skip 49 ; Unused ; \ Dungeon locations checked counters (integers) @@ -466,7 +468,7 @@ assert TemperedGoldBosses = $7EF425, "TemperedGoldBosses labeled at incorrec assert FighterMasterBosses = $7EF426, "FighterMasterBosses labeled at incorrect address" assert BigKeysBigChests = $7EF427, "BigKeysBigChests labeled at incorrect address" assert MapsCompasses = $7EF428, "MapsCompasses labeled at incorrect address" -assert HeartPiecesPendants = $7EF429, "HeartPiecesPendants labeled at incorrect address" +assert PendantCounter = $7EF429, "PendantCounter labeled at incorrect address" assert PreGTBKLocations = $7EF42A, "PreGTBKLocations labeled at incorrect address" assert RupeesSpent = $7EF42B, "RupeesSpent labeled at incorrect address" assert SaveQuits = $7EF42D, "SaveQuits labeled at incorrect address" @@ -481,9 +483,10 @@ assert NMIFrames = $7EF43E, "NMIFrames labeled at incorrect address assert ChestsOpened = $7EF442, "ChestsOpened labeled at incorrect address" assert StatsLocked = $7EF443, "StatsLocked labeled at incorrect address" assert MenuTime = $7EF444, "MenuTime labeled at incorrect address" -assert HeartPieces = $7EF448, "HeartPieces labeled at incorrect address" +assert HeartContainerCounter = $7EF448, "HeartContainerCounter labeled at incorrect address" assert DeathCounter = $7EF449, "DeathCounter labeled at incorrect address" assert FluteCounter = $7EF44B, "FluteCounter labeled at incorrect address" +assert RNGItem = $7EF450, "FluteCounter labeled at incorrect address" assert SwordlessBosses = $7EF452, "SwordlessBosses labeled at incorrect address" assert FaerieRevivalCounter = $7EF453, "FaerieRevivalCounter labeled at incorrect address" assert ChallengeTimer = $7EF454, "ChallengeTimer labeled at incorrect address" @@ -492,10 +495,13 @@ assert BootsTime = $7EF45C, "BootsTime labeled at incorrect address assert FluteTime = $7EF460, "FluteTime labeled at incorrect address" assert MirrorTime = $7EF464, "MirrorTime labeled at incorrect address" assert ChestTurnCounter = $7EF468, "ChestTurnCounter labeled at incorrect address" +assert CapacityUpgrades = $7EF469, "CapacityUpgrades labeled at incorrect address" assert DamageCounter = $7EF46A, "DamageCounter labeled at incorrect address" assert MagicCounter = $7EF46C, "MagicCounter labeled at incorrect address" assert HighestMail = $7EF46E, "HighestMail labeled at incorrect address" assert SmallKeyCounter = $7EF46F, "SmallKeyCounter labeled at incorrect address" +assert HeartPieceCounter = $7EF470, "HeartPieceCounter labeled at incorrect address" +assert CrystalCounter = $7EF471, "CrystalCounter labeled at incorrect address" ;-------------------------------------------------------------------------------- assert ServiceSequence = $7EF4A0, "ServiceSequence labeled at incorrect address" ;-------------------------------------------------------------------------------- @@ -550,6 +556,9 @@ assert RomName = $7F1000, "RomName at incorrect address" ; ServiceSequence: 7ef419 -> 7ef418 (two bytes reserved) ; SwordsShields: 7ef422 -> swords using HighestSword ; PreMirrorLocations: 7ef432 -> 7ef434, PreBoots and PreMirror now 2 bytes +; Heart Pieces: 7ef429 -> 7ef470 +; Pendant counter: 7ef429, now an integer +; SwordlessBosses: 7ef452, now an integer ; ; DungeonLocations values and labels moved to block right before ChestKeys block ; starting at address 7ef472 diff --git a/utilities.asm b/utilities.asm index abadf53..349d317 100644 --- a/utilities.asm +++ b/utilities.asm @@ -627,19 +627,19 @@ RTL ; out: A(b) - sum of bits ; caller is responsible for setting 8-bit mode and preserving X and Y ;-------------------------------------------------------------------------------- -CountBits: - PHX - TAX ; Save a copy of value - LSR #4 ; Shift down hi nybble, Leave <3> in C - PHA ; And save <7:4> in Stack - TXA ; Recover value - AND.b #$07 ; Put out <2:0> in X - TAX ; And save in X - LDA.l NybbleBitCounts, X ; Fetch count for <2:0> - PLX ; get <7:4> - ADC.l NybbleBitCounts, X ; Add count for S & C - PLX -RTL +;CountBits: +; PHX +; TAX ; Save a copy of value +; LSR #4 ; Shift down hi nybble, Leave <3> in C +; PHA ; And save <7:4> in Stack +; TXA ; Recover value +; AND.b #$07 ; Put out <2:0> in X +; TAX ; And save in X +; LDA.l NybbleBitCounts, X ; Fetch count for <2:0> +; PLX ; get <7:4> +; ADC.l NybbleBitCounts, X ; Add count for S & C +; PLX +;RTL ; Look up table of bit counts in the values $00-$0F NybbleBitCounts: