diff --git a/engine/board/menu.asm b/engine/board/menu.asm index 28cabdb35..deed53cd6 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -1,5 +1,6 @@ BoardMenuScript:: opentext + callasm .Upkeep .display_menu callasm BoardMenu ifequal BOARDMENUITEM_DIE, .Die @@ -10,6 +11,17 @@ BoardMenuScript:: closetext end +.Upkeep: +; save after opentext to reanchor map first +; save before processing variables like wCurTurn due to BoardMenuScript reentry after game reset + farcall AutoSaveGameInOverworld + ld hl, wCurTurn + inc [hl] + ld hl, wTurnData + ld bc, wTurnDataEnd - wTurnData + xor a + jp ByteFill + .Die: callasm BoardMenu_Die iffalse BoardMenuScript diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index e039bac5f..8b77ae72e 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -110,6 +110,7 @@ CheckSpaceEffects: bit 5, [hl] ret +; on enter overworld loop StartMap: xor a ldh [hScriptVar], a @@ -120,8 +121,15 @@ StartMap: call ByteFill farcall InitCallReceiveDelay call ClearJoypad +; initialize board state + xor a + ld [wCurTurn], a + ld [wCurSpace], a ld a, BOARDEVENT_DISPLAY_MENU ldh [hCurBoardEvent], a +; fallthrough + +; on map reload (e.g. after battle), warps and connections EnterMap: xor a ld [wXYComparePointer], a diff --git a/ram/wram.asm b/ram/wram.asm index ad0232669..3d678a49c 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -2496,6 +2496,9 @@ wYCoord:: db wXCoord:: db wScreenSave:: ds SCREEN_META_WIDTH * SCREEN_META_HEIGHT +wCurSpace:: db +wCurTurn:: db + wCurMapDataEnd::