diff --git a/asm/include/unk_02091CDC.inc b/asm/include/unk_02091CDC.inc deleted file mode 100644 index 67e259042c..0000000000 --- a/asm/include/unk_02091CDC.inc +++ /dev/null @@ -1,55 +0,0 @@ -#include -#pragma once -.public CreateYesNoMenu -.public Handle2dMenuInput_DeleteOnFinish -.public LoadFontPal0 -.public sub_02004AD8 -.public sub_02005AF8 -.public StopBGM -.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 WaitingIcon_New -.public sub_0200F450 -.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 DoScheduledBgGpuUpdates -.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_DeleteAllData -.public OS_ResetSystem -.public memset -.public gApplication_DeleteSave -.public gSystem diff --git a/asm/unk_02091CDC.s b/asm/unk_02091CDC.s deleted file mode 100644 index 60d529d05f..0000000000 --- a/asm/unk_02091CDC.s +++ /dev/null @@ -1,621 +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_02091CDC.inc" - .include "global.inc" - - .text - - thumb_func_start App_DeleteSave_Init -App_DeleteSave_Init: ; 0x02091CDC - 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, #0x38 - mov r2, #0x56 - bl OverlayManager_CreateAndGetData - mov r1, #0 - mov r2, #0x38 - 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, #0x30] - mov r0, #1 - pop {r3, r4, r5, pc} - .balign 4, 0 - thumb_func_end App_DeleteSave_Init - - thumb_func_start App_DeleteSave_Exec -App_DeleteSave_Exec: ; 0x02091D18 - push {r3, r4, r5, r6, lr} - sub sp, #0xc - add r5, r1, #0 - bl OverlayManager_GetData - ldr r1, [r5] - add r4, r0, #0 - mov r6, #0 - cmp r1, #3 - bhi _02091E20 - add r1, r1, r1 - add r1, pc - ldrh r1, [r1, #6] - lsl r1, r1, #0x10 - asr r1, r1, #0x10 - add pc, r1 -_02091D38: ; jump table - .short _02091D40 - _02091D38 - 2 ; case 0 - .short _02091DCE - _02091D38 - 2 ; case 1 - .short _02091DDC - _02091D38 - 2 ; case 2 - .short _02091E02 - _02091D38 - 2 ; case 3 -_02091D40: - mov r0, #0x3f - lsl r0, r0, #4 - add r1, r6, #0 - bl StopBGM - add r0, r6, #0 - bl sub_02005AF8 - add r0, r6, #0 - bl sub_02004AD8 - add r0, r6, #0 - add r1, r0, #0 - bl sub_0200FBF4 - mov r0, #1 - add r1, r6, #0 - bl sub_0200FBF4 - add r0, r6, #0 - add r1, r0, #0 - bl Main_SetVBlankIntrCB - add r0, r6, #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, _02091E28 ; =0xFFFFE0FF - and r1, r0 - str r1, [r2] - ldr r2, _02091E2C ; =0x04001000 - ldr r1, [r2] - and r0, r1 - str r0, [r2] - mov r0, #4 - mov r1, #8 - bl SetKeyRepeatTimers - add r0, r4, #0 - bl sub_02091E60 - add r0, r4, #0 - bl sub_02091F78 - ldr r0, _02091E30 ; =sub_02091E54 - add r1, r4, #0 - bl Main_SetVBlankIntrCB - bl GfGfx_BothDispOn - 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, r6, #0 - add r3, r0, #0 - bl BeginNormalPaletteFade - mov r0, #1 - str r0, [r5] - b _02091E20 -_02091DCE: - bl IsPaletteFadeFinished - cmp r0, #1 - bne _02091E20 - mov r0, #2 - str r0, [r5] - b _02091E20 -_02091DDC: - bl sub_02091FD4 - cmp r0, #1 - bne _02091E20 - mov r0, #6 - str r0, [sp] - mov r0, #1 - str r0, [sp, #4] - ldr r0, [r4] - str r0, [sp, #8] - add r0, r6, #0 - add r1, r0, #0 - add r2, r0, #0 - add r3, r0, #0 - bl BeginNormalPaletteFade - mov r0, #3 - str r0, [r5] - b _02091E20 -_02091E02: - bl IsPaletteFadeFinished - cmp r0, #1 - bne _02091E20 - add r0, r4, #0 - bl sub_02091FC0 - add r0, r4, #0 - bl sub_02091F24 - add r0, r6, #0 - add r1, r0, #0 - bl Main_SetVBlankIntrCB - mov r6, #1 -_02091E20: - add r0, r6, #0 - add sp, #0xc - pop {r3, r4, r5, r6, pc} - nop -_02091E28: .word 0xFFFFE0FF -_02091E2C: .word 0x04001000 -_02091E30: .word sub_02091E54 - thumb_func_end App_DeleteSave_Exec - - thumb_func_start App_DeleteSave_Exit -App_DeleteSave_Exit: ; 0x02091E34 - push {r3, r4, r5, lr} - add r5, r0, #0 - bl OverlayManager_GetData - ldr r4, [r0] - add r0, r5, #0 - bl OverlayManager_FreeData - add r0, r4, #0 - bl DestroyHeap - mov r0, #0 - bl OS_ResetSystem - mov r0, #1 - pop {r3, r4, r5, pc} - thumb_func_end App_DeleteSave_Exit - - thumb_func_start sub_02091E54 -sub_02091E54: ; 0x02091E54 - ldr r3, _02091E5C ; =DoScheduledBgGpuUpdates - ldr r0, [r0, #0x14] - bx r3 - nop -_02091E5C: .word DoScheduledBgGpuUpdates - thumb_func_end sub_02091E54 - - thumb_func_start sub_02091E60 -sub_02091E60: ; 0x02091E60 - push {r4, r5, lr} - sub sp, #0x5c - ldr r5, _02091F0C ; =_021081E4 - add r4, r0, #0 - add r3, sp, #0x34 - mov r2, #5 -_02091E6C: - ldmia r5!, {r0, r1} - stmia r3!, {r0, r1} - sub r2, r2, #1 - bne _02091E6C - add r0, sp, #0x34 - bl GfGfx_SetBanks - ldr r0, [r4] - bl BgConfig_Alloc - add r3, sp, #0x24 - ldr r5, _02091F10 ; =_021081B8 - str r0, [r4, #0x14] - 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, _02091F14 ; =_021081C8 - 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, #0x14] - add r3, r1, #0 - bl InitBgFromTemplate - ldr r0, [r4, #0x14] - mov r1, #0 - bl BgClearTilemapBufferAndCommit - mov r1, #0 - str r1, [sp] - ldr r0, [r4] - ldr r2, _02091F18 ; =0x000001E2 - str r0, [sp, #4] - ldr r0, [r4, #0x14] - mov r3, #2 - bl LoadUserFrameGfx2 - mov r1, #0 - str r1, [sp] - ldr r0, [r4] - ldr r2, _02091F1C ; =0x000001D9 - str r0, [sp, #4] - ldr r0, [r4, #0x14] - 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 - ldr r1, _02091F20 ; =0x00006C21 - mov r0, #0 - bl BG_SetMaskColor - ldr r1, _02091F20 ; =0x00006C21 - mov r0, #4 - bl BG_SetMaskColor - add sp, #0x5c - pop {r4, r5, pc} - .balign 4, 0 -_02091F0C: .word _021081E4 -_02091F10: .word _021081B8 -_02091F14: .word _021081C8 -_02091F18: .word 0x000001E2 -_02091F1C: .word 0x000001D9 -_02091F20: .word 0x00006C21 - thumb_func_end sub_02091E60 - - thumb_func_start sub_02091F24 -sub_02091F24: ; 0x02091F24 - 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, #0x14] - mov r1, #0 - bl FreeBgTilemapBuffer - ldr r0, [r4, #0x14] - bl FreeToHeap - pop {r4, pc} - thumb_func_end sub_02091F24 - - thumb_func_start sub_02091F78 -sub_02091F78: ; 0x02091F78 - push {r4, lr} - sub sp, #8 - add r4, r0, #0 - ldr r3, [r4] - mov r0, #1 - mov r1, #0x1b - mov r2, #7 - bl NewMsgDataFromNarc - str r0, [r4, #0x18] - bl ResetAllTextPrinters - mov r0, #0 - str r0, [r4, #8] - add r1, r4, #0 - ldr r0, [r4, #0x14] - ldr r2, _02091FBC ; =_021081A8 - add r1, #0x1c - bl AddWindow - mov r0, #0xd8 - str r0, [sp] - mov r0, #0x20 - mov r2, #0 - add r4, #0x1c - str r0, [sp, #4] - add r0, r4, #0 - mov r1, #0xf - add r3, r2, #0 - bl FillWindowPixelRect - add sp, #8 - pop {r4, pc} - nop -_02091FBC: .word _021081A8 - thumb_func_end sub_02091F78 - - thumb_func_start sub_02091FC0 -sub_02091FC0: ; 0x02091FC0 - push {r4, lr} - add r4, r0, #0 - add r0, #0x1c - bl RemoveWindow - ldr r0, [r4, #0x18] - bl DestroyMsgData - pop {r4, pc} - .balign 4, 0 - thumb_func_end sub_02091FC0 - - thumb_func_start sub_02091FD4 -sub_02091FD4: ; 0x02091FD4 - push {r3, r4, r5, lr} - sub sp, #8 - add r4, r0, #0 - ldr r1, [r4, #4] - mov r5, #0 - cmp r1, #6 - bhi _020920CC - add r1, r1, r1 - add r1, pc - ldrh r1, [r1, #6] - lsl r1, r1, #0x10 - asr r1, r1, #0x10 - add pc, r1 -_02091FEE: ; jump table - .short _02091FFC - _02091FEE - 2 ; case 0 - .short _02092026 - _02091FEE - 2 ; case 1 - .short _02092046 - _02091FEE - 2 ; case 2 - .short _02092070 - _02091FEE - 2 ; case 3 - .short _02092090 - _02091FEE - 2 ; case 4 - .short _020920B0 - _02091FEE - 2 ; case 5 - .short _020920C2 - _02091FEE - 2 ; case 6 -_02091FFC: - add r1, r5, #0 - mov r2, #1 - mov r3, #4 - bl sub_020920E0 - cmp r0, #1 - bne _020920CC - mov r0, #1 - str r0, [sp] - ldr r0, [r4] - ldr r1, _020920D4 ; =_021081B0 - str r0, [sp, #4] - ldr r0, [r4, #0x14] - ldr r2, _020920D8 ; =0x000001D9 - mov r3, #3 - bl CreateYesNoMenu - str r0, [r4, #0x2c] - mov r0, #1 - str r0, [r4, #4] - b _020920CC -_02092026: - ldr r0, [r4, #0x2c] - ldr r1, [r4] - bl Handle2dMenuInput_DeleteOnFinish - cmp r0, #0 - beq _0209203A - sub r1, r5, #2 - cmp r0, r1 - beq _02092040 - b _020920CC -_0209203A: - mov r0, #2 - str r0, [r4, #4] - b _020920CC -_02092040: - mov r0, #6 - str r0, [r4, #4] - b _020920CC -_02092046: - mov r1, #1 - add r2, r1, #0 - mov r3, #4 - bl sub_020920E0 - cmp r0, #1 - bne _020920CC - mov r0, #1 - str r0, [sp] - ldr r0, [r4] - ldr r1, _020920D4 ; =_021081B0 - str r0, [sp, #4] - ldr r0, [r4, #0x14] - ldr r2, _020920D8 ; =0x000001D9 - mov r3, #3 - bl CreateYesNoMenu - str r0, [r4, #0x2c] - mov r0, #3 - str r0, [r4, #4] - b _020920CC -_02092070: - ldr r0, [r4, #0x2c] - ldr r1, [r4] - bl Handle2dMenuInput_DeleteOnFinish - cmp r0, #0 - beq _02092084 - sub r1, r5, #2 - cmp r0, r1 - beq _0209208A - b _020920CC -_02092084: - mov r0, #4 - str r0, [r4, #4] - b _020920CC -_0209208A: - mov r0, #6 - str r0, [r4, #4] - b _020920CC -_02092090: - mov r1, #2 - mov r2, #1 - add r3, r5, #0 - bl sub_020920E0 - cmp r0, #1 - bne _020920CC - add r0, r4, #0 - ldr r1, _020920DC ; =0x000001E2 - add r0, #0x1c - bl WaitingIcon_New - str r0, [r4, #0x34] - mov r0, #5 - str r0, [r4, #4] - b _020920CC -_020920B0: - ldr r0, [r4, #0x30] - bl Save_DeleteAllData - ldr r0, [r4, #0x34] - bl sub_0200F450 - mov r0, #6 - str r0, [r4, #4] - b _020920CC -_020920C2: - ldr r0, [r4, #0x14] - add r1, r5, #0 - bl BgClearTilemapBufferAndCommit - mov r5, #1 -_020920CC: - add r0, r5, #0 - add sp, #8 - pop {r3, r4, r5, pc} - nop -_020920D4: .word _021081B0 -_020920D8: .word 0x000001D9 -_020920DC: .word 0x000001E2 - thumb_func_end sub_02091FD4 - - thumb_func_start sub_020920E0 -sub_020920E0: ; 0x020920E0 - push {r4, r5, r6, r7, lr} - sub sp, #0xc - add r5, r0, #0 - ldr r0, [r5, #8] - add r7, r1, #0 - add r4, r3, #0 - mov r6, #0 - cmp r0, #0 - beq _020920FC - cmp r0, #1 - beq _02092164 - cmp r0, #2 - beq _02092180 - b _02092194 -_020920FC: - mov r0, #0xd8 - str r0, [sp] - mov r0, #0x20 - str r0, [sp, #4] - add r0, r5, #0 - add r0, #0x1c - mov r1, #0xf - add r2, r6, #0 - add r3, r6, #0 - bl FillWindowPixelRect - add r0, r5, #0 - ldr r2, _0209219C ; =0x000001E2 - add r0, #0x1c - 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, #0x10] - ldr r0, [r5, #0x18] - ldr r2, [r5, #0x10] - 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, #0x10] - add r0, #0x1c - mov r1, #1 - bl AddTextPrinterParameterized - str r0, [r5, #0xc] - cmp r4, #0 - bne _0209215C - ldr r0, [r5, #0x10] - bl String_Delete - ldr r0, [r5, #8] - add r0, r0, #1 - str r0, [r5, #8] -_0209215C: - ldr r0, [r5, #8] - add r0, r0, #1 - str r0, [r5, #8] - b _02092194 -_02092164: - ldr r0, [r5, #0xc] - lsl r0, r0, #0x18 - lsr r0, r0, #0x18 - bl TextPrinterCheckActive - cmp r0, #0 - bne _02092194 - ldr r0, [r5, #0x10] - bl String_Delete - ldr r0, [r5, #8] - add r0, r0, #1 - str r0, [r5, #8] - b _02092194 -_02092180: - cmp r2, #0 - bne _0209218E - ldr r0, _020921A0 ; =gSystem - ldr r1, [r0, #0x48] - mov r0, #1 - tst r0, r1 - beq _02092194 -_0209218E: - mov r0, #0 - str r0, [r5, #8] - mov r6, #1 -_02092194: - add r0, r6, #0 - add sp, #0xc - pop {r4, r5, r6, r7, pc} - nop -_0209219C: .word 0x000001E2 -_020921A0: .word gSystem - thumb_func_end sub_020920E0 - - .rodata - - .balign 4, 0 -_021081A8: - .byte 0x00, 0x02, 0x13, 0x1B, 0x04, 0x01 - .short 0x016D -_021081B0: - .byte 0x00, 0x19, 0x0D, 0x06, 0x04, 0x01 - .short 0x0155 -_021081B8: - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -_021081C8: - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 -_021081E4: - .byte 0x03, 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, 0x00, 0x00, 0x00, 0x00 - - .public gApplication_DeleteSave -gApplication_DeleteSave: - .word App_DeleteSave_Init, App_DeleteSave_Exec, App_DeleteSave_Exit, 0xFFFFFFFF diff --git a/include/application/delete_savedata.h b/include/application/delete_savedata.h new file mode 100644 index 0000000000..b5ccb3c7cc --- /dev/null +++ b/include/application/delete_savedata.h @@ -0,0 +1,12 @@ +#ifndef POKEHEARTGOLD_APPLICATION_DELETE_SAVEDATA_H +#define POKEHEARTGOLD_APPLICATION_DELETE_SAVEDATA_H + +#include "overlay_manager.h" + +extern const OVY_MGR_TEMPLATE gApplication_DeleteSave; + +BOOL DeleteSavedataApp_Init(OVY_MANAGER *manager, int *state); +BOOL DeleteSavedataApp_Main(OVY_MANAGER *manager, int *state); +BOOL DeleteSavedataApp_Exit(OVY_MANAGER *manager, int *state); + +#endif diff --git a/include/heap.h b/include/heap.h index 0bc09e079d..972c0b8cc5 100644 --- a/include/heap.h +++ b/include/heap.h @@ -32,6 +32,7 @@ typedef enum HeapID { HEAP_ID_OV36 = 75, HEAP_ID_OAKS_SPEECH = 80, HEAP_ID_CERTIFICATES = 82, + HEAP_ID_DELETE_SAVEDATA = 86, HEAP_ID_89 = 89, HEAP_ID_ALPH_PUZZLE = 97, HEAP_ID_MIC_TEST = 98, diff --git a/include/unk_02091CDC.h b/include/unk_02091CDC.h deleted file mode 100644 index cae6ff4974..0000000000 --- a/include/unk_02091CDC.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef POKEHEARTGOLD_UNK_02091CDC_H -#define POKEHEARTGOLD_UNK_02091CDC_H - -#include "overlay_manager.h" - -extern const OVY_MGR_TEMPLATE gApplication_DeleteSave; - -#endif // POKEHEARTGOLD_UNK_02091CDC_H diff --git a/main.lsf b/main.lsf index bd53fee527..7a027de07d 100644 --- a/main.lsf +++ b/main.lsf @@ -304,7 +304,7 @@ Static main Object src/location_gmm_dat.o Object src/move_relearner.o Object asm/unk_02091880.o - Object asm/unk_02091CDC.o + Object src/application/delete_savedata.o Object asm/unk_020921A4.o Object src/save_data_read_error.o Object src/save_data_write_error.o diff --git a/src/application/delete_savedata.c b/src/application/delete_savedata.c new file mode 100644 index 0000000000..c3742fda6b --- /dev/null +++ b/src/application/delete_savedata.c @@ -0,0 +1,373 @@ +#include "application/delete_savedata.h" + +#include "global.h" + +#include "msgdata/msg.naix" +#include "msgdata/msg/msg_0007.h" + +#include "bg_window.h" +#include "font.h" +#include "list_menu_2d.h" +#include "msgdata.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 DeleteSavedataApp_MainState { + MAINSTATE_ASK_TO_DELETE, + MAINSTATE_HANDLE_INPUT, + MAINSTATE_ASK_TO_CONFIRM, + MAINSTATE_HANDLE_CONFIRMATION, + MAINSTATE_PRINT_DELETING_MESSAGE, + MAINSTATE_DELETE_DATA, + MAINSTATE_EXIT, +} DeleteSavedataApp_MainState; + +typedef enum DeleteSavedataApp_PrintState { + PRINTSTATE_PRINT_TEXT, + PRINTSTATE_WAIT_FOR_PRINTER, + 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; + DeleteSavedataApp_PrintState printState; + u32 textPrinterId; + String *textString; + BgConfig *bgConfig; + MsgData *msgData; + Window window; + struct ListMenu2D *yesNoMenu; + SaveData *savedata; + WaitingIcon *waitingIcon; +} DeleteSavedataApp_Data; + +static const WindowTemplate sDeleteSave_WindowTemplate2 = { + .bgId = GF_BG_LYR_MAIN_0, + .left = 25, + .top = 13, + .width = 6, + .height = 4, + .palette = 1, + .baseTile = 0x155, +}; + +static const WindowTemplate sDeleteSave_WindowTemplate1 = { + .bgId = GF_BG_LYR_MAIN_0, + .left = 2, + .top = 19, + .width = 27, + .height = 4, + .palette = 1, + .baseTile = 0x16D, +}; + +static const GraphicsModes sDeleteSave_GraphicsModes = { + .dispMode = GX_DISPMODE_GRAPHICS, + .bgMode = GX_BGMODE_0, + .subMode = GX_BGMODE_0, + ._2d3dMode = GX_BG0_AS_2D, +}; + +static const BgTemplate sDeleteSave_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 sDeleteSave_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_DeleteSave = { + .init = DeleteSavedataApp_Init, + .exec = DeleteSavedataApp_Main, + .exit = DeleteSavedataApp_Exit, + .ovy_id = FS_OVERLAY_ID_NONE, +}; + +extern void sub_02005AF8(u32 a0); + +static void DeleteSavedataApp_OnVBlank(DeleteSavedataApp_Data *data); +static void DeleteSavedataApp_SetupBgConfig(DeleteSavedataApp_Data *data); +static void DeleteSavedataApp_FreeBgConfig(DeleteSavedataApp_Data *data); +static void DeleteSavedataApp_SetupTextAndWindow(DeleteSavedataApp_Data *data); +static void DeleteSavedataApp_FreeTextAndWindow(DeleteSavedataApp_Data *data); +static BOOL DeleteSavedataApp_DoMainTask(DeleteSavedataApp_Data *data); +static BOOL DeleteSavedataApp_PrintMessage(DeleteSavedataApp_Data *data, u32 msgNum, BOOL skipWaitingForAPress, u32 textSpeed); + +BOOL DeleteSavedataApp_Init(OVY_MANAGER *manager, int *state) { + CreateHeap(HEAP_ID_3, HEAP_ID_DELETE_SAVEDATA, 0x20000); + + DeleteSavedataApp_Data *data = OverlayManager_CreateAndGetData(manager, sizeof(DeleteSavedataApp_Data), HEAP_ID_DELETE_SAVEDATA); + 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; + + return TRUE; +} + +BOOL DeleteSavedataApp_Main(OVY_MANAGER *manager, int *state) { + DeleteSavedataApp_Data *data = OverlayManager_GetData(manager); + BOOL ret = FALSE; + + enum { + STATE_SETUP, + STATE_WAIT_FOR_FADE_IN, + STATE_DELETE_SAVE, + STATE_EXIT, + }; + + switch (*state) { + case STATE_SETUP: + StopBGM(SEQ_GS_POKEMON_THEME, 0); + sub_02005AF8(0); + sub_02004AD8(0); + + sub_0200FBF4(0, 0); + sub_0200FBF4(1, 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); + + DeleteSavedataApp_SetupBgConfig(data); + DeleteSavedataApp_SetupTextAndWindow(data); + + Main_SetVBlankIntrCB((GFIntrCB)DeleteSavedataApp_OnVBlank, data); + + GfGfx_BothDispOn(); + + BeginNormalPaletteFade(0, 1, 1, RGB_BLACK, 6, 1, data->heapId); + + *state = STATE_WAIT_FOR_FADE_IN; + break; + case STATE_WAIT_FOR_FADE_IN: + if (IsPaletteFadeFinished() == TRUE) { + *state = STATE_DELETE_SAVE; + } + break; + case STATE_DELETE_SAVE: + if (DeleteSavedataApp_DoMainTask(data) == TRUE) { + BeginNormalPaletteFade(0, 0, 0, RGB_BLACK, 6, 1, data->heapId); + *state = STATE_EXIT; + } + break; + case STATE_EXIT: + if (IsPaletteFadeFinished() == TRUE) { + DeleteSavedataApp_FreeTextAndWindow(data); + DeleteSavedataApp_FreeBgConfig(data); + + Main_SetVBlankIntrCB(NULL, NULL); + ret = TRUE; + } + break; + } + + return ret; +} + +BOOL DeleteSavedataApp_Exit(OVY_MANAGER *manager, int *state) { + DeleteSavedataApp_Data *data = OverlayManager_GetData(manager); + HeapID heapId = data->heapId; + + OverlayManager_FreeData(manager); + + DestroyHeap(heapId); + + OS_ResetSystem(0); + + return TRUE; +} + +static void DeleteSavedataApp_OnVBlank(DeleteSavedataApp_Data *data) { + DoScheduledBgGpuUpdates(data->bgConfig); +} + +static void DeleteSavedataApp_SetupBgConfig(DeleteSavedataApp_Data *data) { + GraphicsBanks banks = sDeleteSave_GraphicsBanks; + GfGfx_SetBanks(&banks); + + data->bgConfig = BgConfig_Alloc(data->heapId); + + GraphicsModes modes = sDeleteSave_GraphicsModes; + SetBothScreensModesAndDisable(&modes); + + BgTemplate template = sDeleteSave_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(1, 1, 27)); + BG_SetMaskColor(GF_BG_LYR_SUB_0, RGB(1, 1, 27)); +} + +static void DeleteSavedataApp_FreeBgConfig(DeleteSavedataApp_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 DeleteSavedataApp_SetupTextAndWindow(DeleteSavedataApp_Data *data) { + data->msgData = NewMsgDataFromNarc(MSGDATA_LOAD_LAZY, NARC_msgdata_msg, NARC_msg_msg_0007_bin, data->heapId); + ResetAllTextPrinters(); + + data->printState = PRINTSTATE_PRINT_TEXT; + + AddWindow(data->bgConfig, &data->window, &sDeleteSave_WindowTemplate1); + FillWindowPixelRect(&data->window, 0xF, 0, 0, 216, 32); +} + +static void DeleteSavedataApp_FreeTextAndWindow(DeleteSavedataApp_Data *data) { + RemoveWindow(&data->window); + DestroyMsgData(data->msgData); +} + +static BOOL DeleteSavedataApp_DoMainTask(DeleteSavedataApp_Data *data) { + BOOL ret = FALSE; + + switch (data->mainState) { + case MAINSTATE_ASK_TO_DELETE: + // "Delete all saved data?" + if (DeleteSavedataApp_PrintMessage(data, msg_0007_00000, TRUE, 4) == TRUE) { + data->yesNoMenu = CreateYesNoMenu(data->bgConfig, &sDeleteSave_WindowTemplate2, 0x1D9, 3, 1, data->heapId); + data->mainState = MAINSTATE_HANDLE_INPUT; + } + break; + case MAINSTATE_HANDLE_INPUT: { + u32 result = Handle2dMenuInput_DeleteOnFinish(data->yesNoMenu, data->heapId); + switch (result) { + case LIST_NO_MULTIPLE_SCROLL: + data->mainState = MAINSTATE_ASK_TO_CONFIRM; + break; + case LIST_CANCEL: + data->mainState = MAINSTATE_EXIT; + break; + } + break; + } + case MAINSTATE_ASK_TO_CONFIRM: + // "Once data has been deleted, there is no way to recover it. [...]" + if (DeleteSavedataApp_PrintMessage(data, msg_0007_00001, TRUE, 4) == TRUE) { + data->yesNoMenu = CreateYesNoMenu(data->bgConfig, &sDeleteSave_WindowTemplate2, 0x1D9, 3, 1, data->heapId); + data->mainState = MAINSTATE_HANDLE_CONFIRMATION; + } + break; + case MAINSTATE_HANDLE_CONFIRMATION: { + u32 result = Handle2dMenuInput_DeleteOnFinish(data->yesNoMenu, data->heapId); + switch (result) { + case LIST_NO_MULTIPLE_SCROLL: + data->mainState = MAINSTATE_PRINT_DELETING_MESSAGE; + break; + case LIST_CANCEL: + data->mainState = MAINSTATE_EXIT; + break; + } + break; + } + case MAINSTATE_PRINT_DELETING_MESSAGE: + // "Deleting all data. Don't turn off the power." + if (DeleteSavedataApp_PrintMessage(data, msg_0007_00002, TRUE, TEXT_SPEED_INSTANT) == TRUE) { + data->waitingIcon = WaitingIcon_New(&data->window, 0x1E2); + data->mainState = MAINSTATE_DELETE_DATA; + } + break; + case MAINSTATE_DELETE_DATA: + Save_DeleteAllData(data->savedata); + sub_0200F450(data->waitingIcon); + data->mainState = MAINSTATE_EXIT; + break; + case MAINSTATE_EXIT: + BgClearTilemapBufferAndCommit(data->bgConfig, GF_BG_LYR_MAIN_0); + ret = TRUE; + break; + } + + return ret; +} + +static BOOL DeleteSavedataApp_PrintMessage(DeleteSavedataApp_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)) { + data->printState = PRINTSTATE_PRINT_TEXT; + ret = TRUE; + } + break; + } + + return ret; +} diff --git a/src/title_screen.c b/src/title_screen.c index 8b3a85dadd..35c9a2caae 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/delete_savedata.h" #include "demo/title/titledemo.naix" #include "msgdata/msg.naix" #include "msgdata/msg/msg_0719.h" @@ -29,7 +30,6 @@ #include "unk_0200FA24.h" #include "unk_02020B8C.h" #include "unk_02026E30.h" -#include "unk_02091CDC.h" #include "unk_020921A4.h" #ifdef HEARTGOLD