From f6cc3607df1f6bde46f147a10c6e7d46b6a9655b Mon Sep 17 00:00:00 2001 From: aerinon Date: Mon, 22 Feb 2021 14:48:10 -0700 Subject: [PATCH] Refactored Potion shop hooks to allow old behaviors --- hooks.asm | 28 +++++++++++++++++----------- inventory.asm | 7 ++++--- shopkeeper.asm | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/hooks.asm b/hooks.asm index 9e58cfb..26c0654 100755 --- a/hooks.asm +++ b/hooks.asm @@ -1189,11 +1189,14 @@ JSL.l DrawMushroom org $05EE97 ; <- 2EE97 - sprite_mushroom.asm : 81 NOP #14 ;-------------------------------------------------------------------------------- -org $05F529 ; <- 2F52C - sprite_potion_shop.asm -JSL SpritePrep_ShopKeeper -LDX #$0 -JSR $F539 ; <- powder spawn here -RTS +org $06C09C ; <- - bank06.asm : 1885 (JSL SpritePrep_PotionShopLong) +JSL SpritePrep_ShopKeeper_PotionShop + +org $05F521 +SpritePrep_PotionShopLong: + +org $05F539 +SpawnMagicPowder: ;-------------------------------------------------------------------------------- org $05F568 ; <- 2F568 - sprite_potion_shop.asm LDA #$b0 : STA $0D00, Y : LDA #$90 : STA $0D10, Y ; manually set position of powder item @@ -1201,12 +1204,15 @@ LDA #$21 : STA $0D20, Y : LDA #$12 : STA $0D30, Y JMP $F61D ;-------------------------------------------------------------------------------- org $05F633 ; <- 2F633 - sprite_potion_shop.asm -LDA $0E80, X : BNE + -JSL Sprite_ShopKeeperPotion ;; TODO: i don't remember prices being set on top of the player -JSR $F893 ; <- witch behavior here -RTS : + -JSR $F644 ; <- powder behavior here -RTS +JSL Sprite_ShopKeeperPotion : RTS : NOP ;; TODO: i don't remember prices being set on top of the player +PotionShopkeeperJumpTable: + +org $05F893 ; <- witch behavior here +Sprite_WitchAssistant: + +org $05F644 ; <- powder behavior here +Sprite_MagicPowderItem: + ;-------------------------------------------------------------------------------- org $05EB1D ; <- 2EB1D - sprite_bottle_vendor.asm : 158 JSL.l Multiworld_BottleVendor_GiveBottle diff --git a/inventory.asm b/inventory.asm index 37d39cd..041d61d 100644 --- a/inventory.asm +++ b/inventory.asm @@ -989,7 +989,6 @@ RTL !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 + LDA.l WitchItem_Player : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID @@ -998,8 +997,10 @@ DrawPowder: LDA #$00 : STA.l !REDRAW ; reset redraw flag BRA .defer + -; LDA $0DA0, X ; Retrieve stored item type -; JSL.l DrawDynamicTile + ; this fights with the shopkeep code, so had to move the powder draw there when potion shop is custom + LDA !SHOP_TYPE : CMP.b #$FF : BNE .defer + LDA $0DA0, X ; Retrieve stored item type + JSL.l DrawDynamicTile .defer RTL ;-------------------------------------------------------------------------------- diff --git a/shopkeeper.asm b/shopkeeper.asm index f789078..526ac26 100644 --- a/shopkeeper.asm +++ b/shopkeeper.asm @@ -128,6 +128,19 @@ dw $0230, $0231, $0202, $0203, $0212, $0213, $0222, $0223, $0232, $0233 .digit_offsets dw 4, 0, -4, -8 ;-------------------------------------------------------------------------------- +SpritePrep_ShopKeeper_PotionShop: + JSL SpritePrep_ShopKeeper + LDA.l !SHOP_TYPE : CMP.b #$FF : BNE + + JSL SpritePrep_PotionShopLong + RTL + + LDX #$0 + PHK : PEA.w .jslrtsreturn-1 + PEA.w $05f527 ; an rtl address - 1 in Bank05 + JML SpawnMagicPowder + .jslrtsreturn + RTL + + SpritePrep_ShopKeeper: PHX : PHY : PHP @@ -252,7 +265,9 @@ SpritePrep_ShopKeeper: PLP : PLY : PLX LDA.l !SHOP_TYPE : CMP.b #$FF : BNE + - PLA : PLA : PLA + LDA $A0 : CMP.b #$09 : BNE ++ + RTL + ++ PLA : PLA : PLA INC $0BA0, X LDA $0E40, X JML.l ShopkeeperFinishInit @@ -381,6 +396,16 @@ Shopkeeper_UploadVRAMTiles: PLA : STA $4301 ; restore DMA parameters PLA : STA $4300 ; restore DMA parameters RTS +;-------------------------------------------------------------------------------- +ShopkepeerPotion_CallOriginal: + PLA : PLA : PLA + LDA.b #PotionShopkeeperJumpTable>>16 : PHA + LDA.b #PotionShopkeeperJumpTable>>8 : PHA + LDA.b #PotionShopkeeperJumpTable : PHA + LDA $0E80, X + JML.l UseImplicitRegIndexedLocalJumpTable +;-------------------------------------------------------------------------------- + ;-------------------------------------------------------------------------------- Shopkepeer_CallOriginal: PLA : PLA : PLA @@ -394,12 +419,28 @@ Shopkepeer_CallOriginal: ;!SHOP_CAPACITY = "$7F5020" ;!SCRATCH_TEMP_X = "$7F5021" Sprite_ShopKeeperPotion: + LDA.l !SHOP_TYPE : CMP.b #$FF : BNE + : JMP.w ShopkepeerPotion_CallOriginal : + + TXA : BEQ + + PHK : PEA.w .jslrtsreturn2-1 + PEA.w $05f527 ; an rtl address - 1 in Bank05 + JML Sprite_MagicPowderItem + .jslrtsreturn2 + RTL + + + PHB : PHK : PLB ;; we can just call the default shopkeeper but the potion shopkeeper refills your health LDA $A0 : CMP.b #$09 : BNE + JSR.w Shopkeeper_DrawItems JSR.w Shopkeeper_SetupHitboxes + PLB + + LDA $0E80, X : BNE + + PHK : PEA.w .jslrtsreturn-1 + PEA.w $05f527 ; an rtl address - 1 in Bank05 + JML Sprite_WitchAssistant + .jslrtsreturn + + RTL Sprite_ShopKeeper: