From 5cd1248c3000ffc5893b427db12ae9234f1ef9f5 Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 21 Nov 2025 17:49:28 -0500 Subject: [PATCH] feat: Implement consumable item effects (Pineapple, Honeycomb) and consumption logic with error handling --- Items/all_items.asm | 28 +++++++++++++++++--------- Menu/menu.asm | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/Items/all_items.asm b/Items/all_items.asm index f95793a..547101e 100644 --- a/Items/all_items.asm +++ b/Items/all_items.asm @@ -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 } } diff --git a/Menu/menu.asm b/Menu/menu.asm index 104c8b7..2779ea0 100644 --- a/Menu/menu.asm +++ b/Menu/menu.asm @@ -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