From 62f31f8dd54e3d460958a8b8bf15b9ad5b7f601c Mon Sep 17 00:00:00 2001 From: tgsm Date: Sun, 17 Nov 2024 11:27:08 -0600 Subject: [PATCH 1/3] Decompile unk_020921A4 -> check save app --- asm/include/unk_020921A4.inc | 49 --- asm/unk_020921A4.s | 604 --------------------------- include/application/check_savedata.h | 12 + include/unk_020921A4.h | 8 - main.lsf | 2 +- src/application/check_savedata.c | 355 ++++++++++++++++ src/title_screen.c | 4 +- 7 files changed, 370 insertions(+), 664 deletions(-) delete mode 100644 asm/include/unk_020921A4.inc delete mode 100644 asm/unk_020921A4.s create mode 100644 include/application/check_savedata.h delete mode 100644 include/unk_020921A4.h create mode 100644 src/application/check_savedata.c diff --git a/asm/include/unk_020921A4.inc b/asm/include/unk_020921A4.inc deleted file mode 100644 index 0ad9b31db9..0000000000 --- a/asm/include/unk_020921A4.inc +++ /dev/null @@ -1,49 +0,0 @@ -#include -#pragma once -.public RegisterMainOverlay -.public TextFlags_SetCanTouchSpeedUpPrint -.public LoadFontPal0 -.public OverlayManager_CreateAndGetData -.public OverlayManager_GetData -.public OverlayManager_FreeData -.public OverlayManager_GetArgs -.public NewMsgDataFromNarc -.public DestroyMsgData -.public ReadMsgDataIntoString -.public LoadUserFrameGfx1 -.public LoadUserFrameGfx2 -.public DrawFrameAndWindow2 -.public BeginNormalPaletteFade -.public IsPaletteFadeFinished -.public sub_0200FBF4 -.public Main_SetVBlankIntrCB -.public Main_SetHBlankIntrCB -.public SetKeyRepeatTimers -.public CreateHeap -.public DestroyHeap -.public FreeToHeap -.public BgConfig_Alloc -.public SetBothScreensModesAndDisable -.public InitBgFromTemplate -.public FreeBgTilemapBuffer -.public ToggleBgLayer -.public BG_ClearCharDataRange -.public BG_SetMaskColor -.public BgClearTilemapBufferAndCommit -.public AddWindow -.public RemoveWindow -.public FillWindowPixelRect -.public ResetAllTextPrinters -.public TextPrinterCheckActive -.public AddTextPrinterParameterized -.public GfGfx_SetBanks -.public GfGfx_DisableEngineAPlanes -.public GfGfx_DisableEngineBPlanes -.public GfGfx_BothDispOn -.public String_New -.public String_Delete -.public Save_GetStatusFlags -.public memset -.public gApplication_MainMenu -.public gSystem -.public gApp_MainMenu diff --git a/asm/unk_020921A4.s b/asm/unk_020921A4.s deleted file mode 100644 index 0ae381087b..0000000000 --- a/asm/unk_020921A4.s +++ /dev/null @@ -1,604 +0,0 @@ -#include "constants/easy_chat.h" -#include "constants/items.h" -#include "constants/maps.h" -#include "constants/moves.h" -#include "constants/species.h" - .include "asm/macros.inc" - .include "unk_020921A4.inc" - .include "global.inc" - - .text - - thumb_func_start sub_020921A4 -sub_020921A4: ; 0x020921A4 - push {r3, r4, r5, lr} - mov r2, #2 - add r5, r0, #0 - mov r0, #3 - mov r1, #0x56 - lsl r2, r2, #0x10 - bl CreateHeap - add r0, r5, #0 - mov r1, #0x40 - mov r2, #0x56 - bl OverlayManager_CreateAndGetData - mov r1, #0 - mov r2, #0x40 - add r4, r0, #0 - bl memset - mov r0, #0x56 - str r0, [r4] - mov r0, #0 - str r0, [r4, #4] - add r0, r5, #0 - bl OverlayManager_GetArgs - ldr r0, [r0, #8] - str r0, [r4, #0x34] - mov r0, #1 - bl TextFlags_SetCanTouchSpeedUpPrint - mov r0, #1 - pop {r3, r4, r5, pc} - thumb_func_end sub_020921A4 - - thumb_func_start sub_020921E4 -sub_020921E4: ; 0x020921E4 - push {r4, r5, r6, lr} - add r5, r1, #0 - bl OverlayManager_GetData - ldr r1, [r5] - add r6, r0, #0 - mov r4, #0 - cmp r1, #0 - beq _02092200 - cmp r1, #1 - beq _0209225A - cmp r1, #2 - beq _02092268 - b _0209227C -_02092200: - add r0, r4, #0 - add r1, r4, #0 - bl sub_0200FBF4 - mov r0, #1 - add r1, r4, #0 - bl sub_0200FBF4 - add r0, r4, #0 - add r1, r0, #0 - bl Main_SetVBlankIntrCB - add r0, r4, #0 - add r1, r0, #0 - bl Main_SetHBlankIntrCB - bl GfGfx_DisableEngineAPlanes - bl GfGfx_DisableEngineBPlanes - mov r2, #1 - lsl r2, r2, #0x1a - ldr r1, [r2] - ldr r0, _02092280 ; =0xFFFFE0FF - and r1, r0 - str r1, [r2] - ldr r2, _02092284 ; =0x04001000 - ldr r1, [r2] - and r0, r1 - str r0, [r2] - mov r0, #4 - mov r1, #8 - bl SetKeyRepeatTimers - add r0, r6, #0 - bl sub_020922B8 - add r0, r6, #0 - bl sub_020923CC - bl GfGfx_BothDispOn - mov r0, #1 - str r0, [r5] - b _0209227C -_0209225A: - bl sub_02092428 - cmp r0, #1 - bne _0209227C - mov r0, #2 - str r0, [r5] - b _0209227C -_02092268: - bl sub_02092414 - add r0, r6, #0 - bl sub_02092378 - add r0, r4, #0 - add r1, r0, #0 - bl Main_SetVBlankIntrCB - mov r4, #1 -_0209227C: - add r0, r4, #0 - pop {r4, r5, r6, pc} - .balign 4, 0 -_02092280: .word 0xFFFFE0FF -_02092284: .word 0x04001000 - thumb_func_end sub_020921E4 - - .public gApp_MainMenu - - thumb_func_start sub_02092288 -sub_02092288: ; 0x02092288 - push {r3, r4, r5, lr} - add r5, r0, #0 - bl OverlayManager_GetData - ldr r4, [r0] - mov r0, #0 - bl TextFlags_SetCanTouchSpeedUpPrint - add r0, r5, #0 - bl OverlayManager_FreeData - add r0, r4, #0 - bl DestroyHeap - ldr r0, _020922B0 ; =FS_OVERLAY_ID(OVY_74) - ldr r1, _020922B4 ; =gApp_MainMenu - bl RegisterMainOverlay - mov r0, #1 - pop {r3, r4, r5, pc} - .balign 4, 0 -_020922B0: .word FS_OVERLAY_ID(OVY_74) -_020922B4: .word gApp_MainMenu - thumb_func_end sub_02092288 - - thumb_func_start sub_020922B8 -sub_020922B8: ; 0x020922B8 - push {r4, r5, lr} - sub sp, #0x5c - ldr r5, _02092364 ; =_02108250 - add r4, r0, #0 - add r3, sp, #0x34 - mov r2, #5 -_020922C4: - ldmia r5!, {r0, r1} - stmia r3!, {r0, r1} - sub r2, r2, #1 - bne _020922C4 - add r0, sp, #0x34 - bl GfGfx_SetBanks - ldr r0, [r4] - bl BgConfig_Alloc - add r3, sp, #0x24 - ldr r5, _02092368 ; =_02108224 - str r0, [r4, #0x18] - add r2, r3, #0 - ldmia r5!, {r0, r1} - stmia r3!, {r0, r1} - ldmia r5!, {r0, r1} - stmia r3!, {r0, r1} - add r0, r2, #0 - bl SetBothScreensModesAndDisable - ldr r5, _0209236C ; =_02108234 - add r3, sp, #8 - ldmia r5!, {r0, r1} - add r2, r3, #0 - stmia r3!, {r0, r1} - ldmia r5!, {r0, r1} - stmia r3!, {r0, r1} - ldmia r5!, {r0, r1} - stmia r3!, {r0, r1} - ldr r0, [r5] - mov r1, #0 - str r0, [r3] - ldr r0, [r4, #0x18] - add r3, r1, #0 - bl InitBgFromTemplate - ldr r0, [r4, #0x18] - mov r1, #0 - bl BgClearTilemapBufferAndCommit - mov r1, #0 - str r1, [sp] - ldr r0, [r4] - ldr r2, _02092370 ; =0x000001E2 - str r0, [sp, #4] - ldr r0, [r4, #0x18] - mov r3, #2 - bl LoadUserFrameGfx2 - mov r1, #0 - str r1, [sp] - ldr r0, [r4] - ldr r2, _02092374 ; =0x000001D9 - str r0, [sp, #4] - ldr r0, [r4, #0x18] - mov r3, #3 - bl LoadUserFrameGfx1 - ldr r2, [r4] - mov r0, #0 - mov r1, #0x20 - bl LoadFontPal0 - mov r0, #0 - ldr r3, [r4] - mov r1, #0x20 - add r2, r0, #0 - bl BG_ClearCharDataRange - mov r0, #0 - add r1, r0, #0 - bl BG_SetMaskColor - mov r0, #4 - mov r1, #0 - bl BG_SetMaskColor - add sp, #0x5c - pop {r4, r5, pc} - .balign 4, 0 -_02092364: .word _02108250 -_02092368: .word _02108224 -_0209236C: .word _02108234 -_02092370: .word 0x000001E2 -_02092374: .word 0x000001D9 - thumb_func_end sub_020922B8 - - thumb_func_start sub_02092378 -sub_02092378: ; 0x02092378 - push {r4, lr} - add r4, r0, #0 - mov r0, #0 - add r1, r0, #0 - bl ToggleBgLayer - mov r0, #1 - mov r1, #0 - bl ToggleBgLayer - mov r0, #2 - mov r1, #0 - bl ToggleBgLayer - mov r0, #3 - mov r1, #0 - bl ToggleBgLayer - mov r0, #4 - mov r1, #0 - bl ToggleBgLayer - mov r0, #5 - mov r1, #0 - bl ToggleBgLayer - mov r0, #6 - mov r1, #0 - bl ToggleBgLayer - mov r0, #7 - mov r1, #0 - bl ToggleBgLayer - ldr r0, [r4, #0x18] - mov r1, #0 - bl FreeBgTilemapBuffer - ldr r0, [r4, #0x18] - bl FreeToHeap - pop {r4, pc} - thumb_func_end sub_02092378 - - thumb_func_start sub_020923CC -sub_020923CC: ; 0x020923CC - push {r4, lr} - sub sp, #8 - add r4, r0, #0 - ldr r3, [r4] - mov r0, #1 - mov r1, #0x1b - mov r2, #0xe5 - bl NewMsgDataFromNarc - str r0, [r4, #0x1c] - bl ResetAllTextPrinters - mov r0, #0 - str r0, [r4, #0xc] - add r1, r4, #0 - ldr r0, [r4, #0x18] - ldr r2, _02092410 ; =_0210821C - add r1, #0x20 - bl AddWindow - mov r0, #0xd8 - str r0, [sp] - mov r0, #0x20 - mov r2, #0 - add r4, #0x20 - str r0, [sp, #4] - add r0, r4, #0 - mov r1, #0xf - add r3, r2, #0 - bl FillWindowPixelRect - add sp, #8 - pop {r4, pc} - nop -_02092410: .word _0210821C - thumb_func_end sub_020923CC - - thumb_func_start sub_02092414 -sub_02092414: ; 0x02092414 - push {r4, lr} - add r4, r0, #0 - add r0, #0x20 - bl RemoveWindow - ldr r0, [r4, #0x1c] - bl DestroyMsgData - pop {r4, pc} - .balign 4, 0 - thumb_func_end sub_02092414 - - thumb_func_start sub_02092428 -sub_02092428: ; 0x02092428 - push {r4, r5, lr} - sub sp, #0xc - add r4, r0, #0 - ldr r1, [r4, #4] - mov r5, #0 - cmp r1, #6 - bls _02092438 - b _02092562 -_02092438: - add r1, r1, r1 - add r1, pc - ldrh r1, [r1, #6] - lsl r1, r1, #0x10 - asr r1, r1, #0x10 - add pc, r1 -_02092444: ; jump table - .short _02092452 - _02092444 - 2 ; case 0 - .short _0209246A - _02092444 - 2 ; case 1 - .short _020924DC - _02092444 - 2 ; case 2 - .short _02092508 - _02092444 - 2 ; case 3 - .short _02092516 - _02092444 - 2 ; case 4 - .short _02092542 - _02092444 - 2 ; case 5 - .short _02092560 - _02092444 - 2 ; case 6 -_02092452: - ldr r0, [r4, #0x34] - bl Save_GetStatusFlags - str r0, [r4, #0x3c] - cmp r0, #0 - bne _02092464 - mov r0, #6 - str r0, [r4, #4] - b _02092562 -_02092464: - mov r0, #1 - str r0, [r4, #4] - b _02092562 -_0209246A: - mov r1, #2 - str r1, [r4, #4] - ldr r0, [r4, #0x3c] - add r2, r0, #0 - tst r2, r1 - beq _02092482 - mov r1, #3 - bic r0, r1 - str r0, [r4, #0x3c] - mov r0, #1 - str r0, [r4, #8] - b _02092562 -_02092482: - mov r2, #1 - add r3, r0, #0 - tst r3, r2 - beq _02092492 - eor r0, r2 - str r0, [r4, #0x3c] - str r5, [r4, #8] - b _02092562 -_02092492: - mov r2, #8 - tst r2, r0 - beq _020924A4 - mov r1, #0xc - bic r0, r1 - str r0, [r4, #0x3c] - mov r0, #5 - str r0, [r4, #8] - b _02092562 -_020924A4: - mov r2, #4 - add r3, r0, #0 - tst r3, r2 - beq _020924B4 - eor r0, r2 - str r0, [r4, #0x3c] - str r2, [r4, #8] - b _02092562 -_020924B4: - mov r2, #0x20 - tst r2, r0 - beq _020924C6 - mov r1, #0x30 - bic r0, r1 - str r0, [r4, #0x3c] - mov r0, #3 - str r0, [r4, #8] - b _02092562 -_020924C6: - mov r2, #0x10 - add r3, r0, #0 - tst r3, r2 - beq _020924D6 - eor r0, r2 - str r0, [r4, #0x3c] - str r1, [r4, #8] - b _02092562 -_020924D6: - mov r0, #6 - str r0, [r4, #4] - b _02092562 -_020924DC: - ldr r1, _02092568 ; =0x00006C21 - add r0, r5, #0 - bl BG_SetMaskColor - ldr r1, _02092568 ; =0x00006C21 - mov r0, #4 - bl BG_SetMaskColor - mov r0, #6 - mov r1, #1 - str r0, [sp] - str r1, [sp, #4] - ldr r0, [r4] - add r2, r1, #0 - str r0, [sp, #8] - add r0, r5, #0 - add r3, r0, #0 - bl BeginNormalPaletteFade - mov r0, #3 - str r0, [r4, #4] - b _02092562 -_02092508: - bl IsPaletteFadeFinished - cmp r0, #1 - bne _02092562 - mov r0, #4 - str r0, [r4, #4] - b _02092562 -_02092516: - ldr r1, [r4, #8] - add r2, r5, #0 - mov r3, #4 - bl sub_0209256C - cmp r0, #1 - bne _02092562 - mov r0, #6 - str r0, [sp] - mov r0, #1 - str r0, [sp, #4] - ldr r0, [r4] - str r0, [sp, #8] - add r0, r5, #0 - add r1, r0, #0 - add r2, r0, #0 - add r3, r0, #0 - bl BeginNormalPaletteFade - mov r0, #5 - str r0, [r4, #4] - b _02092562 -_02092542: - bl IsPaletteFadeFinished - cmp r0, #1 - bne _02092562 - add r0, r5, #0 - add r1, r0, #0 - bl BG_SetMaskColor - mov r0, #4 - add r1, r5, #0 - bl BG_SetMaskColor - mov r0, #1 - str r0, [r4, #4] - b _02092562 -_02092560: - mov r5, #1 -_02092562: - add r0, r5, #0 - add sp, #0xc - pop {r4, r5, pc} - .balign 4, 0 -_02092568: .word 0x00006C21 - thumb_func_end sub_02092428 - - thumb_func_start sub_0209256C -sub_0209256C: ; 0x0209256C - push {r4, r5, r6, r7, lr} - sub sp, #0xc - add r5, r0, #0 - ldr r0, [r5, #0xc] - add r7, r1, #0 - add r4, r3, #0 - mov r6, #0 - cmp r0, #0 - beq _02092588 - cmp r0, #1 - beq _020925F0 - cmp r0, #2 - beq _0209260C - b _02092628 -_02092588: - mov r0, #0xd8 - str r0, [sp] - mov r0, #0x20 - str r0, [sp, #4] - add r0, r5, #0 - add r0, #0x20 - mov r1, #0xf - add r2, r6, #0 - add r3, r6, #0 - bl FillWindowPixelRect - add r0, r5, #0 - ldr r2, _02092630 ; =0x000001E2 - add r0, #0x20 - add r1, r6, #0 - mov r3, #2 - bl DrawFrameAndWindow2 - mov r0, #1 - ldr r1, [r5] - lsl r0, r0, #0xa - bl String_New - str r0, [r5, #0x14] - ldr r0, [r5, #0x1c] - ldr r2, [r5, #0x14] - add r1, r7, #0 - bl ReadMsgDataIntoString - add r3, r6, #0 - str r3, [sp] - str r4, [sp, #4] - str r3, [sp, #8] - add r0, r5, #0 - ldr r2, [r5, #0x14] - add r0, #0x20 - mov r1, #1 - bl AddTextPrinterParameterized - str r0, [r5, #0x10] - cmp r4, #0 - bne _020925E8 - ldr r0, [r5, #0x14] - bl String_Delete - ldr r0, [r5, #0xc] - add r0, r0, #1 - str r0, [r5, #0xc] -_020925E8: - ldr r0, [r5, #0xc] - add r0, r0, #1 - str r0, [r5, #0xc] - b _02092628 -_020925F0: - ldr r0, [r5, #0x10] - lsl r0, r0, #0x18 - lsr r0, r0, #0x18 - bl TextPrinterCheckActive - cmp r0, #0 - bne _02092628 - ldr r0, [r5, #0x14] - bl String_Delete - ldr r0, [r5, #0xc] - add r0, r0, #1 - str r0, [r5, #0xc] - b _02092628 -_0209260C: - cmp r2, #0 - bne _02092622 - ldr r0, _02092634 ; =gSystem - ldr r1, [r0, #0x48] - mov r0, #1 - tst r0, r1 - bne _02092622 - ldr r0, _02092638 ; =gSystem + 0x40 - ldrh r0, [r0, #0x24] - cmp r0, #0 - beq _02092628 -_02092622: - mov r0, #0 - str r0, [r5, #0xc] - mov r6, #1 -_02092628: - add r0, r6, #0 - add sp, #0xc - pop {r4, r5, r6, r7, pc} - nop -_02092630: .word 0x000001E2 -_02092634: .word gSystem -_02092638: .word gSystem + 0x40 - thumb_func_end sub_0209256C - - .rodata - -_0210821C: - .byte 0x00, 0x02, 0x13, 0x1B, 0x04, 0x01 - .short 0x016D -_02108224: - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 -_02108234: - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -_02108250: - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .public gApplication_MainMenu -gApplication_MainMenu: - .word sub_020921A4, sub_020921E4, sub_02092288, 0xFFFFFFFF diff --git a/include/application/check_savedata.h b/include/application/check_savedata.h new file mode 100644 index 0000000000..e5ce332c86 --- /dev/null +++ b/include/application/check_savedata.h @@ -0,0 +1,12 @@ +#ifndef POKEHEARTGOLD_APPLICATION_CHECK_SAVEDATA_H +#define POKEHEARTGOLD_APPLICATION_CHECK_SAVEDATA_H + +#include "overlay_manager.h" + +extern const OVY_MGR_TEMPLATE gApplication_CheckSave; + +BOOL CheckSavedataApp_Init(OVY_MANAGER *manager, int *state); +BOOL CheckSavedataApp_Main(OVY_MANAGER *manager, int *state); +BOOL CheckSavedataApp_Exit(OVY_MANAGER *manager, int *state); + +#endif // POKEHEARTGOLD_APPLICATION_CHECK_SAVEDATA_H diff --git a/include/unk_020921A4.h b/include/unk_020921A4.h deleted file mode 100644 index 21d305d28d..0000000000 --- a/include/unk_020921A4.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef POKEHEARTGOLD_UNK_020921A4_H -#define POKEHEARTGOLD_UNK_020921A4_H - -#include "overlay_manager.h" - -extern const OVY_MGR_TEMPLATE gApplication_MainMenu; - -#endif // POKEHEARTGOLD_UNK_020921A4_H diff --git a/main.lsf b/main.lsf index 7a027de07d..f534a4e702 100644 --- a/main.lsf +++ b/main.lsf @@ -305,7 +305,7 @@ Static main Object src/move_relearner.o Object asm/unk_02091880.o Object src/application/delete_savedata.o - Object asm/unk_020921A4.o + Object src/application/check_savedata.o Object src/save_data_read_error.o Object src/save_data_write_error.o Object asm/unk_02092B04.o diff --git a/src/application/check_savedata.c b/src/application/check_savedata.c new file mode 100644 index 0000000000..1a9376b9fc --- /dev/null +++ b/src/application/check_savedata.c @@ -0,0 +1,355 @@ +#include "application/check_savedata.h" + +#include + +#include "global.h" + +#include "msgdata/msg.naix" +#include "msgdata/msg/msg_0229.h" + +#include "bg_window.h" +#include "font.h" +#include "list_menu_2d.h" +#include "main.h" +#include "msgdata.h" +#include "render_text.h" +#include "render_window.h" +#include "sound_02004A44.h" +#include "system.h" +#include "text.h" +#include "unk_02005D10.h" +#include "unk_0200FA24.h" + +typedef enum CheckSavedataApp_MainState { + MAINSTATE_CHECK_SAVE_FLAGS, + MAINSTATE_GET_ERROR_MESSAGE, + MAINSTATE_FADE_IN, + MAINSTATE_WAIT_FOR_FADE_IN, + MAINSTATE_PRINT_ERROR_MESSAGE_FADE_OUT, + MAINSTATE_WAIT_FOR_FADE_OUT, + MAINSTATE_EXIT, +} CheckSavedataApp_MainState; + +typedef enum CheckSavedataApp_PrintState { + PRINTSTATE_PRINT_TEXT, + PRINTSTATE_WAIT_FOR_PRINTER, + PRINTSTATE_EXIT, +} CheckSavedataApp_PrintState; + +typedef struct CheckSavedataApp_Data { + HeapID heapId; + CheckSavedataApp_MainState mainState; + u32 msgNum; + CheckSavedataApp_PrintState printState; + u32 textPrinterId; + String *textString; + BgConfig *bgConfig; + MsgData *msgData; + Window window; + u32 unk30; // unused + SaveData *savedata; + u32 unk38; // unused + u32 saveStatusFlags; +} CheckSavedataApp_Data; + +static const WindowTemplate sCheckSave_WindowTemplate = { + .bgId = GF_BG_LYR_MAIN_0, + .left = 2, + .top = 19, + .width = 27, + .height = 4, + .palette = 1, + .baseTile = 0x16D, +}; + +static const GraphicsModes sCheckSave_GraphicsModes = { + .dispMode = GX_DISPMODE_GRAPHICS, + .bgMode = GX_BGMODE_0, + .subMode = GX_BGMODE_0, + ._2d3dMode = GX_BG0_AS_2D, +}; + +static const BgTemplate sCheckSave_BgTemplate = { + .x = 0, + .y = 0, + .bufferSize = 0x800, + .baseTile = 0, + .size = GF_BG_SCR_SIZE_256x256, + .colorMode = GX_BG_COLORMODE_16, + .screenBase = GX_BG_SCRBASE_0x0000, + .charBase = GX_BG_CHARBASE_0x18000, + .bgExtPltt = GX_BG_EXTPLTT_01, + .priority = 1, + .areaOver = GX_BG_AREAOVER_XLU, + .mosaic = FALSE, +}; + +static const GraphicsBanks sCheckSave_GraphicsBanks = { + .bg = GX_VRAM_BG_256_AB, + .bgextpltt = GX_VRAM_BGEXTPLTT_NONE, + .subbg = GX_VRAM_SUB_BG_NONE, + .subbgextpltt = GX_VRAM_SUB_BGEXTPLTT_NONE, + .obj = GX_VRAM_OBJ_NONE, + .objextpltt = GX_VRAM_OBJEXTPLTT_NONE, + .subobj = GX_VRAM_SUB_OBJ_NONE, + .subobjextpltt = GX_VRAM_SUB_OBJEXTPLTT_NONE, + .tex = GX_VRAM_TEX_NONE, + .texpltt = GX_VRAM_TEXPLTT_NONE, +}; + +const OVY_MGR_TEMPLATE gApplication_CheckSave = { + .init = CheckSavedataApp_Init, + .exec = CheckSavedataApp_Main, + .exit = CheckSavedataApp_Exit, + .ovy_id = FS_OVERLAY_ID_NONE, +}; + +static void CheckSavedataApp_SetupBgConfig(CheckSavedataApp_Data *data); +static void CheckSavedataApp_FreeBgConfig(CheckSavedataApp_Data *data); +static void CheckSavedataApp_SetupTextAndWindow(CheckSavedataApp_Data *data); +static void CheckSavedataApp_FreeTextAndWindow(CheckSavedataApp_Data *data); +static BOOL CheckSavedataApp_DoMainTask(CheckSavedataApp_Data *data); +static BOOL CheckSavedataApp_PrintMessage(CheckSavedataApp_Data *data, u32 msgNum, BOOL skipWaitingForAPress, u32 textSpeed); + +BOOL CheckSavedataApp_Init(OVY_MANAGER *manager, int *state) { + CreateHeap(HEAP_ID_3, HEAP_ID_DELETE_SAVEDATA, 0x20000); + + CheckSavedataApp_Data *data = OverlayManager_CreateAndGetData(manager, sizeof(CheckSavedataApp_Data), HEAP_ID_DELETE_SAVEDATA); + memset(data, 0, sizeof(CheckSavedataApp_Data)); + data->heapId = HEAP_ID_DELETE_SAVEDATA; + data->mainState = MAINSTATE_CHECK_SAVE_FLAGS; + UnkStruct_02111868_sub *args = OverlayManager_GetArgs(manager); + data->savedata = args->saveData; + + TextFlags_SetCanTouchSpeedUpPrint(TRUE); + + return TRUE; +} + +BOOL CheckSavedataApp_Main(OVY_MANAGER *manager, int *state) { + CheckSavedataApp_Data *data = OverlayManager_GetData(manager); + BOOL ret = FALSE; + + enum { + STATE_SETUP, + STATE_MAIN_TASK, + STATE_EXIT, + }; + + switch (*state) { + case STATE_SETUP: + sub_0200FBF4(PM_LCD_TOP, 0); + sub_0200FBF4(PM_LCD_BOTTOM, 0); + + Main_SetVBlankIntrCB(NULL, NULL); + Main_SetHBlankIntrCB(NULL, NULL); + + GfGfx_DisableEngineAPlanes(); + GfGfx_DisableEngineBPlanes(); + GX_SetVisiblePlane(GX_PLANEMASK_NONE); + GXS_SetVisiblePlane(GX_PLANEMASK_NONE); + + SetKeyRepeatTimers(4, 8); + + CheckSavedataApp_SetupBgConfig(data); + CheckSavedataApp_SetupTextAndWindow(data); + + GfGfx_BothDispOn(); + + *state = STATE_MAIN_TASK; + break; + case STATE_MAIN_TASK: + if (CheckSavedataApp_DoMainTask(data) == TRUE) { + *state = STATE_EXIT; + } + break; + case STATE_EXIT: + CheckSavedataApp_FreeTextAndWindow(data); + CheckSavedataApp_FreeBgConfig(data); + + Main_SetVBlankIntrCB(NULL, NULL); + ret = TRUE; + break; + } + + return ret; +} + +BOOL CheckSavedataApp_Exit(OVY_MANAGER *manager, int *state) { + CheckSavedataApp_Data *data = OverlayManager_GetData(manager); + HeapID heapId = data->heapId; + + TextFlags_SetCanTouchSpeedUpPrint(FALSE); + + OverlayManager_FreeData(manager); + DestroyHeap(heapId); + + FS_EXTERN_OVERLAY(OVY_74); + extern const OVY_MGR_TEMPLATE gApp_MainMenu; + RegisterMainOverlay(FS_OVERLAY_ID(OVY_74), &gApp_MainMenu); + + return TRUE; +} + +static void CheckSavedataApp_SetupBgConfig(CheckSavedataApp_Data *data) { + GraphicsBanks banks = sCheckSave_GraphicsBanks; + GfGfx_SetBanks(&banks); + + data->bgConfig = BgConfig_Alloc(data->heapId); + + GraphicsModes modes = sCheckSave_GraphicsModes; + SetBothScreensModesAndDisable(&modes); + + BgTemplate template = sCheckSave_BgTemplate; + InitBgFromTemplate(data->bgConfig, GF_BG_LYR_MAIN_0, &template, GX_BGMODE_0); + BgClearTilemapBufferAndCommit(data->bgConfig, GF_BG_LYR_MAIN_0); + LoadUserFrameGfx2(data->bgConfig, GF_BG_LYR_MAIN_0, 0x1E2, 2, 0, data->heapId); + LoadUserFrameGfx1(data->bgConfig, GF_BG_LYR_MAIN_0, 0x1D9, 3, 0, data->heapId); + LoadFontPal0(GF_PAL_LOCATION_MAIN_BG, GF_PAL_SLOT_1_OFFSET, data->heapId); + BG_ClearCharDataRange(GF_BG_LYR_MAIN_0, 32, 0, data->heapId); + BG_SetMaskColor(GF_BG_LYR_MAIN_0, RGB_BLACK); + BG_SetMaskColor(GF_BG_LYR_SUB_0, RGB_BLACK); +} + +static void CheckSavedataApp_FreeBgConfig(CheckSavedataApp_Data *data) { + ToggleBgLayer(GF_BG_LYR_MAIN_0, GF_PLANE_TOGGLE_OFF); + ToggleBgLayer(GF_BG_LYR_MAIN_1, GF_PLANE_TOGGLE_OFF); + ToggleBgLayer(GF_BG_LYR_MAIN_2, GF_PLANE_TOGGLE_OFF); + ToggleBgLayer(GF_BG_LYR_MAIN_3, GF_PLANE_TOGGLE_OFF); + ToggleBgLayer(GF_BG_LYR_SUB_0, GF_PLANE_TOGGLE_OFF); + ToggleBgLayer(GF_BG_LYR_SUB_1, GF_PLANE_TOGGLE_OFF); + ToggleBgLayer(GF_BG_LYR_SUB_2, GF_PLANE_TOGGLE_OFF); + ToggleBgLayer(GF_BG_LYR_SUB_3, GF_PLANE_TOGGLE_OFF); + + FreeBgTilemapBuffer(data->bgConfig, GF_BG_LYR_MAIN_0); + FreeToHeap(data->bgConfig); +} + +static void CheckSavedataApp_SetupTextAndWindow(CheckSavedataApp_Data *data) { + data->msgData = NewMsgDataFromNarc(MSGDATA_LOAD_LAZY, NARC_msgdata_msg, NARC_msg_msg_0229_bin, data->heapId); + ResetAllTextPrinters(); + + data->printState = PRINTSTATE_PRINT_TEXT; + + AddWindow(data->bgConfig, &data->window, &sCheckSave_WindowTemplate); + FillWindowPixelRect(&data->window, 0xF, 0, 0, 216, 32); +} + +static void CheckSavedataApp_FreeTextAndWindow(CheckSavedataApp_Data *data) { + RemoveWindow(&data->window); + DestroyMsgData(data->msgData); +} + +static BOOL CheckSavedataApp_DoMainTask(CheckSavedataApp_Data *data) { + BOOL ret = FALSE; + + switch (data->mainState) { + case MAINSTATE_CHECK_SAVE_FLAGS: + data->saveStatusFlags = Save_GetStatusFlags(data->savedata); + if (data->saveStatusFlags == 0) { + data->mainState = MAINSTATE_EXIT; + } else { + data->mainState = MAINSTATE_GET_ERROR_MESSAGE; + } + break; + case MAINSTATE_GET_ERROR_MESSAGE: + data->mainState = MAINSTATE_FADE_IN; + if (data->saveStatusFlags & (1 << 1)) { + data->saveStatusFlags &= ~((1 << 1) | (1 << 0)); + // "The save file will be erased due to corruption or damage." + data->msgNum = msg_0229_00001; + } else if (data->saveStatusFlags & (1 << 0)) { + data->saveStatusFlags ^= (1 << 0); + // "The save file is corrupted. The previous save file will be loaded." + data->msgNum = msg_0229_00000; + } else if (data->saveStatusFlags & (1 << 3)) { + data->saveStatusFlags &= ~((1 << 3) | (1 << 2)); + // "The Battle Hall record has been erased." + data->msgNum = msg_0229_00005; + } else if (data->saveStatusFlags & (1 << 2)) { + data->saveStatusFlags ^= (1 << 2); + // "The most recent Battle Hall record is corrupted. The previously saved record will be loaded instead." + data->msgNum = msg_0229_00004; + } else if (data->saveStatusFlags & (1 << 5)) { + data->saveStatusFlags &= ~((1 << 5) | (1 << 4)); + // "A Battle Video appears to have been erased." + data->msgNum = msg_0229_00003; + } else if (data->saveStatusFlags & (1 << 4)) { + data->saveStatusFlags ^= (1 << 4); + // "The most recent Battle Video is corrupted. The previously saved Battle Video will be loaded instead." + data->msgNum = msg_0229_00002; + } else { + data->mainState = MAINSTATE_EXIT; + } + break; + case MAINSTATE_FADE_IN: + BG_SetMaskColor(GF_BG_LYR_MAIN_0, RGB(1, 1, 27)); + BG_SetMaskColor(GF_BG_LYR_SUB_0, RGB(1, 1, 27)); + BeginNormalPaletteFade(0, 1, 1, RGB_BLACK, 6, 1, data->heapId); + data->mainState = MAINSTATE_WAIT_FOR_FADE_IN; + break; + case MAINSTATE_WAIT_FOR_FADE_IN: + if (IsPaletteFadeFinished() == TRUE) { + data->mainState = MAINSTATE_PRINT_ERROR_MESSAGE_FADE_OUT; + } + break; + case MAINSTATE_PRINT_ERROR_MESSAGE_FADE_OUT: + if (CheckSavedataApp_PrintMessage(data, data->msgNum, FALSE, 4) == TRUE) { + BeginNormalPaletteFade(0, 0, 0, RGB_BLACK, 6, 1, data->heapId); + data->mainState = MAINSTATE_WAIT_FOR_FADE_OUT; + } + break; + case MAINSTATE_WAIT_FOR_FADE_OUT: + if (IsPaletteFadeFinished() == TRUE) { + BG_SetMaskColor(GF_BG_LYR_MAIN_0, RGB_BLACK); + BG_SetMaskColor(GF_BG_LYR_SUB_0, RGB_BLACK); + data->mainState = MAINSTATE_GET_ERROR_MESSAGE; + } + break; + case MAINSTATE_EXIT: + ret = TRUE; + break; + } + + return ret; +} + +static BOOL CheckSavedataApp_PrintMessage(CheckSavedataApp_Data *data, u32 msgNum, BOOL skipWaitingForAPress, u32 textSpeed) { + BOOL ret = FALSE; + + switch (data->printState) { + case PRINTSTATE_PRINT_TEXT: + FillWindowPixelRect(&data->window, 0xF, 0, 0, 216, 32); + DrawFrameAndWindow2(&data->window, FALSE, 0x1E2, 2); + + data->textString = String_New(1024, data->heapId); + ReadMsgDataIntoString(data->msgData, msgNum, data->textString); + data->textPrinterId = AddTextPrinterParameterized(&data->window, 1, data->textString, 0, 0, textSpeed, NULL); + + if (textSpeed == TEXT_SPEED_INSTANT) { + String_Delete(data->textString); + + // Skip waiting for the text printer to finish since the speed here was instant + data->printState++; + } + + data->printState++; + break; + case PRINTSTATE_WAIT_FOR_PRINTER: + if (TextPrinterCheckActive(data->textPrinterId)) { + break; + } + + String_Delete(data->textString); + data->printState++; + break; + case PRINTSTATE_EXIT: + if (skipWaitingForAPress || (gSystem.newKeys & PAD_BUTTON_A) || gSystem.touchNew != 0) { + data->printState = PRINTSTATE_PRINT_TEXT; + ret = TRUE; + } + break; + } + + return ret; +} diff --git a/src/title_screen.c b/src/title_screen.c index 35c9a2caae..af2110b1be 100644 --- a/src/title_screen.c +++ b/src/title_screen.c @@ -5,6 +5,7 @@ #include "constants/sndseq.h" #include "constants/species.h" +#include "application/check_savedata.h" #include "application/delete_savedata.h" #include "demo/title/titledemo.naix" #include "msgdata/msg.naix" @@ -30,7 +31,6 @@ #include "unk_0200FA24.h" #include "unk_02020B8C.h" #include "unk_02026E30.h" -#include "unk_020921A4.h" #ifdef HEARTGOLD #define TITLE_SCREEN_SPECIES SPECIES_HO_OH @@ -245,7 +245,7 @@ static BOOL TitleScreen_Exit(OVY_MANAGER *man, int *state) { switch (exitMode) { default: case TITLESCREEN_EXIT_MENU: - RegisterMainOverlay(FS_OVERLAY_ID_NONE, &gApplication_MainMenu); + RegisterMainOverlay(FS_OVERLAY_ID_NONE, &gApplication_CheckSave); break; case TITLESCREEN_EXIT_CLEARSAVE: RegisterMainOverlay(FS_OVERLAY_ID_NONE, &gApplication_DeleteSave); From 620b4aa46e60fbe64d8fb6c5d02ed6aa306ec69a Mon Sep 17 00:00:00 2001 From: tgsm Date: Sun, 17 Nov 2024 11:38:45 -0600 Subject: [PATCH 2/3] application/delete_savedata: Use UnkStruct_02111868_sub for args --- src/application/delete_savedata.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/application/delete_savedata.c b/src/application/delete_savedata.c index c3742fda6b..be43c1e42d 100644 --- a/src/application/delete_savedata.c +++ b/src/application/delete_savedata.c @@ -8,6 +8,7 @@ #include "bg_window.h" #include "font.h" #include "list_menu_2d.h" +#include "main.h" #include "msgdata.h" #include "render_window.h" #include "sound_02004A44.h" @@ -32,12 +33,6 @@ typedef enum DeleteSavedataApp_PrintState { PRINTSTATE_EXIT, } DeleteSavedataApp_PrintState; -// FIXME: Unknown size, this struct may be something we already have -typedef struct DeleteSavedataApp_Args { - u8 unk0[8]; - SaveData *savedata; -} DeleteSavedataApp_Args; - typedef struct DeleteSavedataApp_Data { HeapID heapId; DeleteSavedataApp_MainState mainState; @@ -131,8 +126,8 @@ BOOL DeleteSavedataApp_Init(OVY_MANAGER *manager, int *state) { memset(data, 0, sizeof(DeleteSavedataApp_Data)); data->heapId = HEAP_ID_DELETE_SAVEDATA; data->mainState = MAINSTATE_ASK_TO_DELETE; - DeleteSavedataApp_Args *args = OverlayManager_GetArgs(manager); - data->savedata = args->savedata; + UnkStruct_02111868_sub *args = OverlayManager_GetArgs(manager); + data->savedata = args->saveData; return TRUE; } From 8c1e82b15b3ca91c6d775ce0a65a393e3978fe46 Mon Sep 17 00:00:00 2001 From: tgsm Date: Sun, 17 Nov 2024 12:39:57 -0600 Subject: [PATCH 3/3] application/check_savedata: Resolve review comment --- src/application/check_savedata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/application/check_savedata.c b/src/application/check_savedata.c index 1a9376b9fc..0276ec1f78 100644 --- a/src/application/check_savedata.c +++ b/src/application/check_savedata.c @@ -47,7 +47,7 @@ typedef struct CheckSavedataApp_Data { MsgData *msgData; Window window; u32 unk30; // unused - SaveData *savedata; + SaveData *saveData; u32 unk38; // unused u32 saveStatusFlags; } CheckSavedataApp_Data; @@ -119,7 +119,7 @@ BOOL CheckSavedataApp_Init(OVY_MANAGER *manager, int *state) { data->heapId = HEAP_ID_DELETE_SAVEDATA; data->mainState = MAINSTATE_CHECK_SAVE_FLAGS; UnkStruct_02111868_sub *args = OverlayManager_GetArgs(manager); - data->savedata = args->saveData; + data->saveData = args->saveData; TextFlags_SetCanTouchSpeedUpPrint(TRUE); @@ -245,7 +245,7 @@ static BOOL CheckSavedataApp_DoMainTask(CheckSavedataApp_Data *data) { switch (data->mainState) { case MAINSTATE_CHECK_SAVE_FLAGS: - data->saveStatusFlags = Save_GetStatusFlags(data->savedata); + data->saveStatusFlags = Save_GetStatusFlags(data->saveData); if (data->saveStatusFlags == 0) { data->mainState = MAINSTATE_EXIT; } else {