feat: Implement consumable item effects (Pineapple, Honeycomb) and consumption logic with error handling

This commit is contained in:
scawful
2025-11-21 17:49:28 -05:00
parent 117dd70d2c
commit 5cd1248c30
2 changed files with 67 additions and 9 deletions

View File

@@ -1,4 +1,6 @@
; Inherits Free Space from Bank07
org $07FA80
!RAM_MAGIC = $7EF36E
incsrc "Items/bottle_net.asm"
; Starts Expanded Bank 0x2B
@@ -42,36 +44,44 @@ Link_ConsumeMagicBagItem:
Link_Banana:
{
LDA.l CURHP : CMP.w MAXHP : BCS +
LDA.l CURHP : CMP.w MAXHP : BCS .full
LDA.l CURHP : CLC : ADC.b #$10 : STA.l CURHP
LDA.b #$0D : STA.w $012F ; HUD Heart SFX
+
RTS
SEC : RTS
.full
CLC : RTS
}
Link_Pineapple:
{
RTS
LDA.l !RAM_MAGIC : CMP.b #$80 : BCS .full
LDA.b #$80 : STA.l !RAM_MAGIC
SEC : RTS
.full
CLC : RTS
}
Link_RockMeat:
{
RTS
CLC : RTS
}
Link_Seashells:
{
RTS
CLC : RTS
}
Link_Honeycombs:
{
RTS
LDA.l CURHP : CMP.w MAXHP : BCS .full
LDA.l CURHP : CLC : ADC.b #$10 : STA.l CURHP
SEC : RTS
.full
CLC : RTS
}
Link_DekuSticks:
{
RTS
CLC : RTS
}
}

View File

@@ -499,6 +499,7 @@ Menu_MagicBag:
REP #$10
LDX.w Menu_MagicBagCursorPositions, Y
JSR Menu_DrawCursor
JSR MagicBag_ConsumeItem
JSR Submenu_Return
LDA.b #$22 : STA.w $0116
@@ -515,6 +516,53 @@ Menu_MagicBagCursorPositions:
dw menu_offset(12,10) ; honeycombs
dw menu_offset(12,14) ; deku sticks
MagicBag_ConsumeItem:
{
; Check for A button press
LDA.b $F6 : BIT.b #$80 : BEQ .exit
REP #$30
; Calculate SRAM address for current item (4 bytes per entry)
LDA.w $020B : ASL #2 : TAX
LDA.l .sram_addresses, X : STA $00
LDA.l .sram_addresses+2, X : STA $02
SEP #$30
; Handle Consumption
PHB : LDA $02 : PHA : PLB
LDA ($00) : BEQ .error_dbr
; Call Handler
JSL Link_ConsumeMagicBagItem
BCC .failed_use_dbr
; Success -> Decrement
LDA ($00) : DEC A : STA ($00)
PLB
; Sound
LDA.b #$35 : STA.w $012F
BRA .exit
.failed_use_dbr
PLB
.error_dbr
; Error Sound
LDA.b #$3C : STA.w $012E
BRA .exit
.exit
RTS
.sram_addresses
dd Bananas
dd Pineapples
dd RockMeat
dd Seashells
dd Honeycomb
dd DekuSticks
}
; =========================================================
; 0D MENU SONG MENU