diff --git a/game/src/core/state_indexes.asm b/game/src/core/state_indexes.asm index 19f0d92..d83db9d 100644 --- a/game/src/core/state_indexes.asm +++ b/game/src/core/state_indexes.asm @@ -4,6 +4,9 @@ SECTION "State Machine Indexes", WRAM0[$C480] W_CoreStateIndex:: ds 1 W_CoreSubStateIndex:: ds 1 +SECTION "Transport Option State Indexes", WRAM0[$C57A] +W_TransportOptionSubSubSubStateIndex:: ds 1 + SECTION "Naming Screen State Indexes", WRAM0[$C580] W_NamingScreenSubSubStateIndex:: ds 1 diff --git a/game/src/pausemenu/core.asm b/game/src/pausemenu/core.asm index 1a449cc..9c71f8e 100644 --- a/game/src/pausemenu/core.asm +++ b/game/src/pausemenu/core.asm @@ -5,10 +5,16 @@ SECTION "Pause Menu Vars 1", WRAM0[$C490] W_PauseMenuPerserveSCX:: ds 1 W_PauseMenuPerserveSCY:: ds 1 +SECTION "Pause Menu Vars 2", WRAM0[$C562] +W_PauseMenuSelectedOption:: ds 1 + DEF W_TransportOptionAAvailable EQU $C576 DEF W_TransportOptionBAvailable EQU $C577 DEF W_TransportOptionCAvailable EQU $C578 +SECTION "Pause Menu Vars 3", WRAM0[$C579] +W_SelectedTransportOption:: ds 1 + SECTION "Pause Menu State Machine 1", ROMX[$4000], BANK[$06] PauseMenuStateMachine:: ld a, [W_CoreSubStateIndex] @@ -18,17 +24,19 @@ PauseMenuStateMachine:: dw $4116 ;02 dw PauseMenuMappingState ;03 dw PauseMenuInputHandlerState ;04 + ; Exit states. dw $41AE ;05 dw $41D3 ;06 dw PauseMenuDoNothingState ;07 dw $41FC ;08 dw PauseMenuExitState ;09 - dw $496F ;0A - dw $496F ;0B - dw $496F ;0C - dw $496F ;0D - dw $496F ;0E - dw $496F ;0F + dw PauseMenuPlaceholderState ;0A + dw PauseMenuPlaceholderState ;0B + dw PauseMenuPlaceholderState ;0C + dw PauseMenuPlaceholderState ;0D + dw PauseMenuPlaceholderState ;0E + dw PauseMenuPlaceholderState ;0F + ; Option 1 (Medawatch) states. dw PauseMenuPrepareFadeOutState ;10 dw PauseMenuFadeOutState ;11 dw $425D ;12 @@ -39,12 +47,13 @@ PauseMenuStateMachine:: dw $42DE ;17 dw $4304 ;18 dw PauseMenuOpenMedawatchMenuState ;19 - dw $496F ;1A - dw $496F ;1B - dw $496F ;1C - dw $496F ;1D - dw $496F ;1E - dw $496F ;1F + dw PauseMenuPlaceholderState ;1A + dw PauseMenuPlaceholderState ;1B + dw PauseMenuPlaceholderState ;1C + dw PauseMenuPlaceholderState ;1D + dw PauseMenuPlaceholderState ;1E + dw PauseMenuPlaceholderState ;1F + ; Option 2 (Item) states. dw PauseMenuCanOpenItemMenuCheckState ;20 dw PauseMenuPrepareFadeOutState ;21 dw PauseMenuFadeOutState ;22 @@ -56,27 +65,29 @@ PauseMenuStateMachine:: dw $42DE ;28 dw $4304 ;29 dw PauseMenuOpenItemMenuState ;2A - dw $496F ;2B - dw $496F ;2C - dw $496F ;2D - dw $496F ;2E - dw $496F ;2F + dw PauseMenuPlaceholderState ;2B + dw PauseMenuPlaceholderState ;2C + dw PauseMenuPlaceholderState ;2D + dw PauseMenuPlaceholderState ;2E + dw PauseMenuPlaceholderState ;2F + ; Option 3 (Transport) states. dw TransportMenuInitState ;30 dw $43A7 ;31 - dw $43D1 ;32 - dw $4418 ;33 - dw $4483 ;34 - dw $44B6 ;35 - dw $44FE ;36 - dw $452D ;37 - dw $4540 ;38 - dw $496F ;39 - dw $496F ;3A - dw $496F ;3B - dw $496F ;3C - dw $496F ;3D - dw $496F ;3E - dw $496F ;3F + dw TransportMenuCheckInventoryState ;32 + dw TransportMenuMappingState ;33 + dw TransportMenuInputHandlerState ;34 + dw TransportMenuExitState ;35 + dw TransportMenuCheckIfSelectedOptionAvailableState ;36 + dw TransportMenuOptionUnavailableState ;37 + dw TransportMenuLoadOptionStateMachineState ;38 + dw PauseMenuPlaceholderState ;39 + dw PauseMenuPlaceholderState ;3A + dw PauseMenuPlaceholderState ;3B + dw PauseMenuPlaceholderState ;3C + dw PauseMenuPlaceholderState ;3D + dw PauseMenuPlaceholderState ;3E + dw PauseMenuPlaceholderState ;3F + ; Option 4 (Save) states. dw PauseMenuPrepareFadeOutState ;40 dw PauseMenuFadeOutState ;41 dw $425D ;42 @@ -86,20 +97,21 @@ PauseMenuStateMachine:: dw PauseMenuClearScrollPositionState ;46 dw $42DE ;47 dw $4304 ;48 - dw $490E ;49 - dw $496F ;4A - dw $496F ;4B - dw $496F ;4C - dw $496F ;4D - dw $496F ;4E - dw $496F ;4F - dw $4918 ;50 - dw $4935 ;51 - dw $496F ;52 - dw $496F ;53 - dw $4918 ;54 - dw $4952 ;55 - dw $496F ;56 + dw PauseMenuOpenSaveScreenState ;49 + dw PauseMenuPlaceholderState ;4A + dw PauseMenuPlaceholderState ;4B + dw PauseMenuPlaceholderState ;4C + dw PauseMenuPlaceholderState ;4D + dw PauseMenuPlaceholderState ;4E + dw PauseMenuPlaceholderState ;4F + ; Message display states. + dw PauseMenuPrepareMessageBoxState ;50 + dw PauseMenuDisplayMessageState ;51 + dw PauseMenuPlaceholderState ;52 + dw PauseMenuPlaceholderState ;53 + dw PauseMenuPrepareMessageBoxState ;54 + dw PauseMenuDisplaySaveDisabledMessageState ;55 + dw PauseMenuPlaceholderState ;56 PauseMenuFadeOutState:: cbcallindex $35 @@ -168,7 +180,7 @@ PauseMenuInputHandlerState:: call ScheduleSoundEffect ld a, 1 call $4A00 ; PauseMenuMaintainCursorAnimation1 - ld a, [$C562] + ld a, [W_PauseMenuSelectedOption] ld hl, .table ld b, 0 ld c, a @@ -177,7 +189,7 @@ PauseMenuInputHandlerState:: ld [W_CoreSubStateIndex], a ; Everything between here and the final ret of this function (as in the next 8 lines) is new (as in not present in M3). - ld a, [$C562] + ld a, [W_PauseMenuSelectedOption] cp 3 ret nz ld a, [$C66F] @@ -321,3 +333,229 @@ TransportMenuInitState:: ld a, 0 cbcallindex $B2 jp IncSubStateIndex + +SECTION "Pause Menu State Machine 7", ROMX[$43D1], BANK[$06] +TransportMenuCheckInventoryState:: + ld a, 1 + ld [$C4D9], a + ld hl, W_TransportOptionAAvailable + ld bc, 8 + call memclr + +.checkTransportOptionA + ld a, $A + cbcall IsItemInInventory + or a + jr nz, .checkTransportOptionB + ld a, 1 + ld [W_TransportOptionAAvailable], a + +.checkTransportOptionB + ld a, $C + cbcall IsItemInInventory + or a + jr nz, .checkTransportOptionC + ld a, 1 + ld [W_TransportOptionBAvailable], a + +.checkTransportOptionC + ld a, $B + cbcall IsItemInInventory + or a + jr nz, .nextState + ld a, 1 + ld [W_TransportOptionCAvailable], a + +.nextState + jp IncSubStateIndex + +TransportMenuMappingState:: + ld a, 1 + ld [$C4D9], a + ld bc, $200 + ld e, $7E + ld a, 0 + cbcall DecompressAttribmap0ScrollAdjusted + ld bc, $200 + ld e, $7E + ld a, 0 + cbcall DecompressTilemap0ScrollAdjusted + ld bc, $401 + ld e, $7F + ld a, [W_TransportOptionAAvailable] + or a + jr z, .hideOptionA + ld e, $80 + +.hideOptionA + ld a, 0 + cbcall DecompressTilemap0ScrollAdjusted + ld bc, $403 + ld e, $7F + ld a, [W_TransportOptionBAvailable] + or a + jr z, .hideOptionB + ld e, $81 + +.hideOptionB + ld a, 0 + cbcall DecompressTilemap0ScrollAdjusted + ld bc, $405 + ld e, $7F + ld a, [W_TransportOptionCAvailable] + or a + jr z, .hideOptionC + ld e, $82 + +.hideOptionC + ld a, 0 + cbcall DecompressTilemap0ScrollAdjusted + jp IncSubStateIndex + +TransportMenuInputHandlerState:: + ld a, 1 + ld [$C4D9], a + call $4B3F + xor a + call $4B88 + ldh a, [H_JPInputChanged] + and M_JPInputB + jp z, .bNotPressed + ld bc, 1 + ld a, 7 + call CGBLoadSingleBGPPaletteIndex + ld a, 1 + ld [W_CGBPaletteStagedBGP], a + jp IncSubStateIndex + +.bNotPressed + ldh a, [H_JPInputChanged] + and M_JPInputA + ret z + ld a, 1 + call $4B88 + ld a, $36 + ld [W_CoreSubStateIndex], a + ret + +TransportMenuExitState:: + ld a, 1 + ld [$C4D9], a + ld a, 2 + ld [$C4EE], a + ld a, $A + ld [$C4EF], a + ld a, 0 + ld [$C4F0], a + ld a, 7 + ld [$C4F1], a + ld a, 0 + cbcallindex $B3 + cbcallindex $23 + ld a, 1 + ld [$C498], a + ld bc, 2 + ld a, 7 + call CGBLoadSingleBGPPaletteIndex + ld a, 1 + ld [W_CGBPaletteStagedBGP], a + ld a, 6 + call ScheduleSoundEffect + ld a, 4 + ld [W_CoreSubStateIndex], a + ret + +TransportMenuCheckIfSelectedOptionAvailableState:: + ld a, 1 + ld [$C4D9], a + ld a, [W_SelectedTransportOption] + ld hl, W_TransportOptionAAvailable + ld b, 0 + ld c, a + add hl, bc + ld a, [hl] + or a + jr nz, .optionAvailable + + ld a, 7 + call ScheduleSoundEffect + ld a, $20 + ld [$C48A], a + jp IncSubStateIndex + +.optionAvailable + ld a, 5 + call ScheduleSoundEffect + xor a + ld [W_TransportOptionSubSubSubStateIndex], a + ld a, $38 + ld [W_CoreSubStateIndex], a + ret + +TransportMenuOptionUnavailableState:: + ld a, 1 + ld [$C4D9], a + ld a, [$C48A] + dec a + ld [$C48A], a + ret nz + ld a, $34 + ld [W_CoreSubStateIndex], a + ret + +TransportMenuLoadOptionStateMachineState:: + ld a, 1 + ld [$C4D9], a + ld a, [W_SelectedTransportOption] + rst 0 + dw $454F + dw $46F2 + dw $487B + +SECTION "Pause Menu State Machine 8", ROMX[$490E], BANK[$06] +PauseMenuOpenSaveScreenState:: + ld a, $C + ld [W_CoreStateIndex], a + xor a + ld [W_CoreSubStateIndex], a + ret + +PauseMenuPrepareMessageBoxState:: + ld a, 1 + ld [$C4D9], a + ld bc, 2 + ld a, 7 + call CGBLoadSingleBGPPaletteIndex + ld a, 1 + ld [W_CGBPaletteStagedBGP], a + cbcall InitiateMainScript + jp IncSubStateIndex + +PauseMenuDisplayMessageState:: + ld a, 1 + ld [$C4D9], a + ld bc, $29 + ld a, 1 + cbcall MainScriptLoopHelper + ld a, [W_MainScriptExitMode] + or a + ret z + ld a, 4 + ld [W_CoreSubStateIndex], a + ret + +PauseMenuDisplaySaveDisabledMessageState:: + ld a, 1 + ld [$C4D9], a + ld bc, $23 + ld a, 1 + cbcall MainScriptLoopHelper + ld a, [W_MainScriptExitMode] + or a + ret z + ld a, 4 + ld [W_CoreSubStateIndex], a + ret + +PauseMenuPlaceholderState:: + ret diff --git a/game/src/pausemenu/items.asm b/game/src/pausemenu/items.asm index 5b25e55..48db86c 100644 --- a/game/src/pausemenu/items.asm +++ b/game/src/pausemenu/items.asm @@ -6,4 +6,34 @@ W_CurrentPageItemSelectionIndex:: ds 1 W_CurrentItemPage:: ds 1 SECTION "Inventory", WRAMX[$DE18], BANK[$05] ; 5:D918 in M3 -W_Inventory:: ds $5E +W_Inventory:: ds $4C + +SECTION "Item Helper Functions", ROMX[$5834], BANK[$15] +IsItemInInventory:: + ld [$C4EE], a + ld a, BANK(W_Inventory) + rst 8 + ld de, W_Inventory + ld c, $26 + +.loop + ld a, [de] + cp $80 + jr c, .itemNotFound + and $7F + ld b, a + ld a, [$C4EE] + cp b + jr z, .itemFound + inc de + inc de + dec c + jr nz, .loop + +.itemNotFound + ld a, 1 + ret + +.itemFound + xor a + ret diff --git a/game/src/version/kabuto/wrappers.asm b/game/src/version/kabuto/wrappers.asm index d163dc4..b47fcde 100644 --- a/game/src/version/kabuto/wrappers.asm +++ b/game/src/version/kabuto/wrappers.asm @@ -74,7 +74,7 @@ CrossBankFunctionTable:: dbw $15, $55DF ; 44 dbw $15, $560D ; 45 dbw $15, $5693 ; 46 - dbw $15, $5834 ; 47 + cbpointer IsItemInInventory ; 47 dbw $15, $5857 ; 48 dbw $15, $58A6 ; 49 dbw $15, $58FE ; 4A diff --git a/game/src/version/kuwagata/wrappers.asm b/game/src/version/kuwagata/wrappers.asm index 3ac335c..9cb7bc4 100644 --- a/game/src/version/kuwagata/wrappers.asm +++ b/game/src/version/kuwagata/wrappers.asm @@ -74,7 +74,7 @@ CrossBankFunctionTable:: dbw $15, $55DF ; 44 dbw $15, $560D ; 45 dbw $15, $5693 ; 46 - dbw $15, $5834 ; 47 + cbpointer IsItemInInventory ; 47 dbw $15, $5857 ; 48 dbw $15, $58A6 ; 49 dbw $15, $58FE ; 4A