From d0dfc758fc6684e765736c7aad7190328d3e145c Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 6 Oct 2017 18:33:35 -0400 Subject: decompile save_failed_screen.c --- src/save_failed_screen.c | 332 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100755 src/save_failed_screen.c (limited to 'src/save_failed_screen.c') diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c new file mode 100755 index 000000000..546342b9d --- /dev/null +++ b/src/save_failed_screen.c @@ -0,0 +1,332 @@ +#include "global.h" +#include "text.h" +#include "main.h" +#include "palette.h" +#include "gpu_regs.h" +#include "bg.h" +#include "task.h" +#include "window.h" +#include "menu.h" +#include "save.h" +#include "gba/flash_internal.h" + +#define MSG_WIN_TOP 12 +#define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) + +extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor *color, u8 speed, u8 *str); + +extern void (*gGameContinueCallback)(void); + +extern u32 gDamagedSaveSectors; + +extern u16 gUnknown_0203BCFC; +extern const u8 gUnknown_085B0E04[]; +extern const u8 gUnknown_085B0A80[]; +extern const u8 gUnknown_085B0C0C[]; +extern const u8 gUnknown_085EFDE4[]; + +extern const struct OamData gUnknown_085EFD80; // sClockOamData +extern const u8 gUnknown_085EFDAC[8][3]; // sClockFrames + +extern const struct BgTemplate gUnknown_085EFD88[]; +extern const struct WindowTemplate gUnknown_085EFD94[]; +extern struct WindowTemplate gUnknown_085EFD9C; +extern struct WindowTemplate gUnknown_085EFDA4; +extern struct SaveSection gSaveDataBuffer; +extern const u32 gUnknown_0850E87C[]; + +extern const u16 gUnknown_085B0A00[]; +extern const u16 gUnknown_085EFDC4[]; +extern const u16 gUnknown_0850FEFC[]; +extern const u16 gUnknown_0860F074[]; + +extern u8 gText_SaveFailedCheckingBackup[]; +extern u8 gText_BackupMemoryDamaged[]; +extern u8 gText_CheckCompleted[]; +extern u8 gText_SaveCompleteGameCannotContinue[]; +extern u8 gText_SaveCompletePressA[]; +extern u8 gText_GamePlayCannotBeContinued[]; + +extern void sub_8179454(void); + +extern u8 gDecompressionBuffer[]; + +struct Unk203BCFC +{ + u16 unk0; + u16 unk2; +}; + +extern struct Unk203BCFC gUnknown_0203BCFE; + +struct Unk203BD0E +{ + u8 unk0; + u8 unk1; +}; + +extern struct Unk203BD0E gUnknown_0203BD0E; + +void sub_8178FDC(void); +void sub_8179288(void); +void sub_8179390(void); +void sub_81793E0(void); +bool8 sub_81795AC(u32); +void sub_8179428(void); +bool8 sub_8179514(u16 sector); + +void sub_8178F44(u8 *text, u8 var1, u8 var2) +{ + struct TextColor color; + + color.fgColor = 0; + color.bgColor = 15; + color.shadowColor = 3; + AddTextPrinterParametrized2(gUnknown_0203BD0E.unk0, 1, var1 * 8, var2 * 8 + 1, 0, 0, &color, 0, text); +} + +void DoSaveFailedScreen(u8 saveType) +{ + SetMainCallback2(sub_8178FDC); + gUnknown_0203BCFC = saveType; + gUnknown_0203BCFE.unk0 = 0; + gUnknown_0203BCFE.unk2 = 0; + gUnknown_0203BD0E.unk0 = 0; + gUnknown_0203BD0E.unk1 = 0; +} + +void sub_8178FC8(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +void sub_8178FDC(void) +{ + switch(gMain.state) + { + case 0: + default: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + // how come this doesnt use the Dma manager? + DmaFill16(3, 0, VRAM, VRAM_SIZE); + DmaFill32(3, 0, OAM, OAM_SIZE); + DmaFill16(3, 0, PLTT, PLTT_SIZE); + LZ77UnCompVram(gUnknown_085B0E04, (void *)VRAM); + LZ77UnCompVram(gUnknown_085B0A80, (void *)(VRAM + 0x7000)); + LZ77UnCompVram(gUnknown_085B0C0C, (void *)(VRAM + 0x7800)); + LZ77UnCompVram(gUnknown_085EFDE4, (void *)(VRAM + 0x10020)); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_085EFD88, 3); + SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]); + CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800); + LoadBgTiles(0, gUnknown_0850E87C, 0x120, 0x214); + InitWindows(gUnknown_085EFD94); + // AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? + gUnknown_0203BD0E.unk0 = AddWindowWithoutTileMap(&gUnknown_085EFD9C); + SetWindowAttribute(gUnknown_0203BD0E.unk0, 7, (u32)&gDecompressionBuffer[0x2800]); + gUnknown_0203BD0E.unk1 = AddWindowWithoutTileMap(&gUnknown_085EFDA4); + SetWindowAttribute(gUnknown_0203BD0E.unk1, 7, (u32)&gDecompressionBuffer[0x3D00]); + DeactivateAllTextPrinters(); + ResetSpriteData(); + ResetTasks(); + ResetPaletteFade(); + LoadPalette(gUnknown_085B0A00, 0, 0x40); + LoadPalette(gUnknown_085EFDC4, 0x100, 0x20); + LoadPalette(gUnknown_0850FEFC, 0xE0, 0x20); + LoadPalette(gUnknown_0860F074, 0xF0, 0x20); + SetWindowBorderStyle(gUnknown_0203BD0E.unk0, FALSE, 0x214, 0xE); + SetWindowBorderStyle(gUnknown_0203BD0E.unk1, FALSE, 0x214, 0xE); + FillWindowPixelBuffer(gUnknown_0203BD0E.unk1, 0x11); // backwards? + FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + CopyWindowToVram(gUnknown_0203BD0E.unk1, 2); // again? + CopyWindowToVram(gUnknown_0203BD0E.unk0, 1); + sub_8178F44(gText_SaveFailedCheckingBackup, 1, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); + EnableInterrupts(1); + SetVBlankCallback(sub_8178FC8); + SetGpuReg(0, 0x1040); + ShowBg(0); + ShowBg(2); + ShowBg(3); + gMain.state++; + break; + case 1: + if(!UpdatePaletteFade()) + { + SetMainCallback2(sub_8179288); + SetVBlankCallback(sub_8179454); + } + break; + } +} + +void sub_8179288(void) +{ + u8 wipeTries = 0; + + gUnknown_0203BCFE.unk0 = TRUE; + + while (gDamagedSaveSectors != 0 && wipeTries < 3) + { + if (sub_81795AC(gDamagedSaveSectors) != FALSE) + { + FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + sub_8178F44(gText_BackupMemoryDamaged, 1, 0); + SetMainCallback2(sub_8179390); + return; + } + + FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + sub_8178F44(gText_CheckCompleted, 1, 0); + HandleSavingData(gUnknown_0203BCFC); + + if(gDamagedSaveSectors != 0) + { + FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + sub_8178F44(gText_SaveFailedCheckingBackup, 1, 0); + } + + wipeTries++; + } + + if(wipeTries == 3) + { + FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + sub_8178F44(gText_BackupMemoryDamaged, 1, 0); + } + else + { + FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + + if(gGameContinueCallback == NULL) + sub_8178F44(gText_SaveCompleteGameCannotContinue, 1, 0); + else + sub_8178F44(gText_SaveCompletePressA, 1, 0); + } + + SetMainCallback2(sub_81793E0); +} + +void sub_8179390(void) +{ + gUnknown_0203BCFE.unk0 = FALSE; + + if(gMain.newKeys & A_BUTTON) + { + FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + sub_8178F44(gText_GamePlayCannotBeContinued, 1, 0); + SetVBlankCallback(sub_8178FC8); + SetMainCallback2(sub_81793E0); + } +} + +void sub_81793E0(void) +{ + gUnknown_0203BCFE.unk0 = FALSE; + + if(gMain.newKeys & A_BUTTON) + { + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0); + SetVBlankCallback(sub_8178FC8); + SetMainCallback2(sub_8179428); + } +} + +void sub_8179428(void) +{ + if(!UpdatePaletteFade()) + { + if(gGameContinueCallback == NULL) // no callback exists, so do a soft reset. + { + DoSoftReset(); + } + else + { + SetMainCallback2((MainCallback)gGameContinueCallback); + gGameContinueCallback = NULL; + } + } +} + +void sub_8179454(void) +{ + unsigned int n = (gMain.vblankCounter2 >> 3) & 7; + + gMain.oamBuffer[0] = gUnknown_085EFD80; + gMain.oamBuffer[0].x = 112; + gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; + + if(gUnknown_0203BCFE.unk0 != FALSE) + { + gMain.oamBuffer[0].tileNum = gUnknown_085EFDAC[n][0]; + gMain.oamBuffer[0].matrixNum = (gUnknown_085EFDAC[n][2] << 4) | (gUnknown_085EFDAC[n][1] << 3); + } + else + { + gMain.oamBuffer[0].tileNum = 1; + } + + CpuFastCopy(gMain.oamBuffer, (void *)OAM, 4); + + if(gUnknown_0203BCFE.unk2) + gUnknown_0203BCFE.unk2--; +} + +bool8 sub_8179514(u16 sector) +{ + u32 *ptr = (u32 *)&gSaveDataBuffer; + u16 i; + + ReadFlash(sector, 0, (u8 *)ptr, 4096); + + for (i = 0; i < 0x400; i++, ptr++) + if (*ptr) + return TRUE; + + return FALSE; +} + +bool8 sub_8179554(u16 sector) +{ + u16 i, j; + bool8 failed = TRUE; + + for (i = 0; failed && i < 130; i++) + { + for (j = 0; j < 0x1000; j++) + ProgramFlashByte(sector, j, 0); + + failed = sub_8179514(sector); + } + + return failed; +} + +bool8 sub_81795AC(u32 sectorBits) +{ + u16 i; + + for (i = 0; i < 0x20; i++) + if ((sectorBits & (1 << i)) && !sub_8179554(i)) + sectorBits &= ~(1 << i); + + if (sectorBits == 0) + return FALSE; + else + return TRUE; +} -- cgit v1.2.3 From f383cb8354223de3d8a630800ebeffc470737960 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 6 Oct 2017 19:48:18 -0400 Subject: update labels --- src/save_failed_screen.c | 210 +++++++++++++++++++++++------------------------ 1 file changed, 105 insertions(+), 105 deletions(-) (limited to 'src/save_failed_screen.c') diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 546342b9d..666de5c95 100755 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -19,14 +19,14 @@ extern void (*gGameContinueCallback)(void); extern u32 gDamagedSaveSectors; -extern u16 gUnknown_0203BCFC; -extern const u8 gUnknown_085B0E04[]; -extern const u8 gUnknown_085B0A80[]; -extern const u8 gUnknown_085B0C0C[]; -extern const u8 gUnknown_085EFDE4[]; +extern u16 gSaveFailedType; +extern const u8 gBirchHelpGfx[]; +extern const u8 gBirchBagTilemap[]; +extern const u8 gBirchGrassTilemap[]; +extern const u8 gSaveFailedClockGfx[]; -extern const struct OamData gUnknown_085EFD80; // sClockOamData -extern const u8 gUnknown_085EFDAC[8][3]; // sClockFrames +extern const struct OamData gClockOamData; // sClockOamData +extern const u8 gClockFrames[8][3]; // sClockFrames extern const struct BgTemplate gUnknown_085EFD88[]; extern const struct WindowTemplate gUnknown_085EFD94[]; @@ -35,8 +35,8 @@ extern struct WindowTemplate gUnknown_085EFDA4; extern struct SaveSection gSaveDataBuffer; extern const u32 gUnknown_0850E87C[]; -extern const u16 gUnknown_085B0A00[]; -extern const u16 gUnknown_085EFDC4[]; +extern const u16 gBirchBagGrassPal[]; +extern const u16 gSaveFailedClockPal[]; extern const u16 gUnknown_0850FEFC[]; extern const u16 gUnknown_0860F074[]; @@ -47,64 +47,64 @@ extern u8 gText_SaveCompleteGameCannotContinue[]; extern u8 gText_SaveCompletePressA[]; extern u8 gText_GamePlayCannotBeContinued[]; -extern void sub_8179454(void); - extern u8 gDecompressionBuffer[]; -struct Unk203BCFC +struct ClockInfo { - u16 unk0; - u16 unk2; + bool16 clockRunning; + u16 debugTimer; // appears to be unused; it's only set to 0 and never used within the game. perhaps it was a volatile-like timer expected to be modified by an external tool? }; -extern struct Unk203BCFC gUnknown_0203BCFE; +extern struct ClockInfo gSaveFailedClockInfo; -struct Unk203BD0E +struct WindowIds { - u8 unk0; - u8 unk1; + u8 textWindowId; + u8 clockWindowId; }; -extern struct Unk203BD0E gUnknown_0203BD0E; +extern struct WindowIds gSaveFailedWindowIds; -void sub_8178FDC(void); -void sub_8179288(void); -void sub_8179390(void); -void sub_81793E0(void); -bool8 sub_81795AC(u32); -void sub_8179428(void); -bool8 sub_8179514(u16 sector); +static void CB2_SaveFailedScreen(void); +static void CB2_WipeSave(void); +static void CB2_GameplayCannotBeContinued(void); +static void CB2_FadeAndReturnToTitleScreen(void); +static void CB2_ReturnToTitleScreen(void); +static void VBlankCB_UpdateClockGraphics(void); +static bool8 VerifySectorWipe(u16 sector); +static bool8 WipeSectors(u32); -void sub_8178F44(u8 *text, u8 var1, u8 var2) +// although this is a general text printer, it's only used in this file. +static void SaveFailedScreenTextPrint(u8 *text, u8 var1, u8 var2) { struct TextColor color; color.fgColor = 0; color.bgColor = 15; color.shadowColor = 3; - AddTextPrinterParametrized2(gUnknown_0203BD0E.unk0, 1, var1 * 8, var2 * 8 + 1, 0, 0, &color, 0, text); + AddTextPrinterParametrized2(gSaveFailedWindowIds.textWindowId, 1, var1 * 8, var2 * 8 + 1, 0, 0, &color, 0, text); } void DoSaveFailedScreen(u8 saveType) { - SetMainCallback2(sub_8178FDC); - gUnknown_0203BCFC = saveType; - gUnknown_0203BCFE.unk0 = 0; - gUnknown_0203BCFE.unk2 = 0; - gUnknown_0203BD0E.unk0 = 0; - gUnknown_0203BD0E.unk1 = 0; + SetMainCallback2(CB2_SaveFailedScreen); + gSaveFailedType = saveType; + gSaveFailedClockInfo.clockRunning = FALSE; + gSaveFailedClockInfo.debugTimer = 0; + gSaveFailedWindowIds.textWindowId = 0; + gSaveFailedWindowIds.clockWindowId = 0; } -void sub_8178FC8(void) +static void VBlankCB(void) { LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); } -void sub_8178FDC(void) +static void CB2_SaveFailedScreen(void) { - switch(gMain.state) + switch (gMain.state) { case 0: default: @@ -126,10 +126,10 @@ void sub_8178FDC(void) DmaFill16(3, 0, VRAM, VRAM_SIZE); DmaFill32(3, 0, OAM, OAM_SIZE); DmaFill16(3, 0, PLTT, PLTT_SIZE); - LZ77UnCompVram(gUnknown_085B0E04, (void *)VRAM); - LZ77UnCompVram(gUnknown_085B0A80, (void *)(VRAM + 0x7000)); - LZ77UnCompVram(gUnknown_085B0C0C, (void *)(VRAM + 0x7800)); - LZ77UnCompVram(gUnknown_085EFDE4, (void *)(VRAM + 0x10020)); + LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM); + LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000)); + LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800)); + LZ77UnCompVram(gSaveFailedClockGfx, (void *)(VRAM + 0x10020)); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, gUnknown_085EFD88, 3); SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]); @@ -137,28 +137,28 @@ void sub_8178FDC(void) LoadBgTiles(0, gUnknown_0850E87C, 0x120, 0x214); InitWindows(gUnknown_085EFD94); // AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? - gUnknown_0203BD0E.unk0 = AddWindowWithoutTileMap(&gUnknown_085EFD9C); - SetWindowAttribute(gUnknown_0203BD0E.unk0, 7, (u32)&gDecompressionBuffer[0x2800]); - gUnknown_0203BD0E.unk1 = AddWindowWithoutTileMap(&gUnknown_085EFDA4); - SetWindowAttribute(gUnknown_0203BD0E.unk1, 7, (u32)&gDecompressionBuffer[0x3D00]); + gSaveFailedWindowIds.textWindowId = AddWindowWithoutTileMap(&gUnknown_085EFD9C); + SetWindowAttribute(gSaveFailedWindowIds.textWindowId, 7, (u32)&gDecompressionBuffer[0x2800]); + gSaveFailedWindowIds.clockWindowId = AddWindowWithoutTileMap(&gUnknown_085EFDA4); + SetWindowAttribute(gSaveFailedWindowIds.clockWindowId, 7, (u32)&gDecompressionBuffer[0x3D00]); DeactivateAllTextPrinters(); ResetSpriteData(); ResetTasks(); ResetPaletteFade(); - LoadPalette(gUnknown_085B0A00, 0, 0x40); - LoadPalette(gUnknown_085EFDC4, 0x100, 0x20); + LoadPalette(gBirchBagGrassPal, 0, 0x40); + LoadPalette(gSaveFailedClockPal, 0x100, 0x20); LoadPalette(gUnknown_0850FEFC, 0xE0, 0x20); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - SetWindowBorderStyle(gUnknown_0203BD0E.unk0, FALSE, 0x214, 0xE); - SetWindowBorderStyle(gUnknown_0203BD0E.unk1, FALSE, 0x214, 0xE); - FillWindowPixelBuffer(gUnknown_0203BD0E.unk1, 0x11); // backwards? - FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); - CopyWindowToVram(gUnknown_0203BD0E.unk1, 2); // again? - CopyWindowToVram(gUnknown_0203BD0E.unk0, 1); - sub_8178F44(gText_SaveFailedCheckingBackup, 1, 0); + SetWindowBorderStyle(gSaveFailedWindowIds.textWindowId, FALSE, 0x214, 0xE); + SetWindowBorderStyle(gSaveFailedWindowIds.clockWindowId, FALSE, 0x214, 0xE); + FillWindowPixelBuffer(gSaveFailedWindowIds.clockWindowId, 0x11); // backwards? + FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + CopyWindowToVram(gSaveFailedWindowIds.clockWindowId, 2); // again? + CopyWindowToVram(gSaveFailedWindowIds.textWindowId, 1); + SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); EnableInterrupts(1); - SetVBlankCallback(sub_8178FC8); + SetVBlankCallback(VBlankCB); SetGpuReg(0, 0x1040); ShowBg(0); ShowBg(2); @@ -166,92 +166,92 @@ void sub_8178FDC(void) gMain.state++; break; case 1: - if(!UpdatePaletteFade()) + if (!UpdatePaletteFade()) { - SetMainCallback2(sub_8179288); - SetVBlankCallback(sub_8179454); + SetMainCallback2(CB2_WipeSave); + SetVBlankCallback(VBlankCB_UpdateClockGraphics); } break; } } -void sub_8179288(void) +static void CB2_WipeSave(void) { u8 wipeTries = 0; - gUnknown_0203BCFE.unk0 = TRUE; + gSaveFailedClockInfo.clockRunning = TRUE; while (gDamagedSaveSectors != 0 && wipeTries < 3) { - if (sub_81795AC(gDamagedSaveSectors) != FALSE) + if (WipeSectors(gDamagedSaveSectors) != FALSE) { - FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); - sub_8178F44(gText_BackupMemoryDamaged, 1, 0); - SetMainCallback2(sub_8179390); + FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); + SetMainCallback2(CB2_GameplayCannotBeContinued); return; } - FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); - sub_8178F44(gText_CheckCompleted, 1, 0); - HandleSavingData(gUnknown_0203BCFC); + FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + SaveFailedScreenTextPrint(gText_CheckCompleted, 1, 0); + HandleSavingData(gSaveFailedType); - if(gDamagedSaveSectors != 0) + if (gDamagedSaveSectors != 0) { - FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); - sub_8178F44(gText_SaveFailedCheckingBackup, 1, 0); + FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); } wipeTries++; } - if(wipeTries == 3) + if (wipeTries == 3) { - FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); - sub_8178F44(gText_BackupMemoryDamaged, 1, 0); + FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); } else { - FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); - if(gGameContinueCallback == NULL) - sub_8178F44(gText_SaveCompleteGameCannotContinue, 1, 0); + if (gGameContinueCallback == NULL) + SaveFailedScreenTextPrint(gText_SaveCompleteGameCannotContinue, 1, 0); else - sub_8178F44(gText_SaveCompletePressA, 1, 0); + SaveFailedScreenTextPrint(gText_SaveCompletePressA, 1, 0); } - SetMainCallback2(sub_81793E0); + SetMainCallback2(CB2_FadeAndReturnToTitleScreen); } -void sub_8179390(void) +static void CB2_GameplayCannotBeContinued(void) { - gUnknown_0203BCFE.unk0 = FALSE; + gSaveFailedClockInfo.clockRunning = FALSE; - if(gMain.newKeys & A_BUTTON) + if (gMain.newKeys & A_BUTTON) { - FillWindowPixelBuffer(gUnknown_0203BD0E.unk0, 0x11); - sub_8178F44(gText_GamePlayCannotBeContinued, 1, 0); - SetVBlankCallback(sub_8178FC8); - SetMainCallback2(sub_81793E0); + FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0); + SetVBlankCallback(VBlankCB); + SetMainCallback2(CB2_FadeAndReturnToTitleScreen); } } -void sub_81793E0(void) +static void CB2_FadeAndReturnToTitleScreen(void) { - gUnknown_0203BCFE.unk0 = FALSE; + gSaveFailedClockInfo.clockRunning = FALSE; - if(gMain.newKeys & A_BUTTON) + if (gMain.newKeys & A_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0); - SetVBlankCallback(sub_8178FC8); - SetMainCallback2(sub_8179428); + SetVBlankCallback(VBlankCB); + SetMainCallback2(CB2_ReturnToTitleScreen); } } -void sub_8179428(void) +void CB2_ReturnToTitleScreen(void) { - if(!UpdatePaletteFade()) + if (!UpdatePaletteFade()) { - if(gGameContinueCallback == NULL) // no callback exists, so do a soft reset. + if (gGameContinueCallback == NULL) // no callback exists, so do a soft reset. { DoSoftReset(); } @@ -263,18 +263,18 @@ void sub_8179428(void) } } -void sub_8179454(void) +static void VBlankCB_UpdateClockGraphics(void) { unsigned int n = (gMain.vblankCounter2 >> 3) & 7; - gMain.oamBuffer[0] = gUnknown_085EFD80; + gMain.oamBuffer[0] = gClockOamData; gMain.oamBuffer[0].x = 112; gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; - if(gUnknown_0203BCFE.unk0 != FALSE) + if (gSaveFailedClockInfo.clockRunning != FALSE) { - gMain.oamBuffer[0].tileNum = gUnknown_085EFDAC[n][0]; - gMain.oamBuffer[0].matrixNum = (gUnknown_085EFDAC[n][2] << 4) | (gUnknown_085EFDAC[n][1] << 3); + gMain.oamBuffer[0].tileNum = gClockFrames[n][0]; + gMain.oamBuffer[0].matrixNum = (gClockFrames[n][2] << 4) | (gClockFrames[n][1] << 3); } else { @@ -283,11 +283,11 @@ void sub_8179454(void) CpuFastCopy(gMain.oamBuffer, (void *)OAM, 4); - if(gUnknown_0203BCFE.unk2) - gUnknown_0203BCFE.unk2--; + if (gSaveFailedClockInfo.debugTimer) + gSaveFailedClockInfo.debugTimer--; } -bool8 sub_8179514(u16 sector) +static bool8 VerifySectorWipe(u16 sector) { u32 *ptr = (u32 *)&gSaveDataBuffer; u16 i; @@ -301,7 +301,7 @@ bool8 sub_8179514(u16 sector) return FALSE; } -bool8 sub_8179554(u16 sector) +static bool8 WipeSector(u16 sector) { u16 i, j; bool8 failed = TRUE; @@ -311,18 +311,18 @@ bool8 sub_8179554(u16 sector) for (j = 0; j < 0x1000; j++) ProgramFlashByte(sector, j, 0); - failed = sub_8179514(sector); + failed = VerifySectorWipe(sector); } return failed; } -bool8 sub_81795AC(u32 sectorBits) +static bool8 WipeSectors(u32 sectorBits) { u16 i; for (i = 0; i < 0x20; i++) - if ((sectorBits & (1 << i)) && !sub_8179554(i)) + if ((sectorBits & (1 << i)) && !WipeSector(i)) sectorBits &= ~(1 << i); if (sectorBits == 0) -- cgit v1.2.3 From 35bb9b02e3089693e7c0424a9a1620ae5f7a1380 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 6 Oct 2017 20:26:53 -0400 Subject: ewram defines --- src/save_failed_screen.c | 77 +++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'src/save_failed_screen.c') diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 666de5c95..8536e541a 100755 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -19,7 +19,6 @@ extern void (*gGameContinueCallback)(void); extern u32 gDamagedSaveSectors; -extern u16 gSaveFailedType; extern const u8 gBirchHelpGfx[]; extern const u8 gBirchBagTilemap[]; extern const u8 gBirchGrassTilemap[]; @@ -49,21 +48,25 @@ extern u8 gText_GamePlayCannotBeContinued[]; extern u8 gDecompressionBuffer[]; -struct ClockInfo +// gSaveFailedClockInfo enum +enum { - bool16 clockRunning; - u16 debugTimer; // appears to be unused; it's only set to 0 and never used within the game. perhaps it was a volatile-like timer expected to be modified by an external tool? + CLOCK_RUNNING, + DEBUG_TIMER }; -extern struct ClockInfo gSaveFailedClockInfo; - -struct WindowIds +// gSaveFailedWindowIds enum +enum { - u8 textWindowId; - u8 clockWindowId; + TEXT_WIN_ID, + CLOCK_WIN_ID }; -extern struct WindowIds gSaveFailedWindowIds; +EWRAM_DATA u16 gSaveFailedType = {0}; +EWRAM_DATA u16 gSaveFailedClockInfo[2] = {0}; +EWRAM_DATA u8 gSaveFailedUnused1[12] = {0}; +EWRAM_DATA u8 gSaveFailedWindowIds[2] = {0}; +EWRAM_DATA u8 gSaveFailedUnused2[4] = {0}; static void CB2_SaveFailedScreen(void); static void CB2_WipeSave(void); @@ -82,17 +85,17 @@ static void SaveFailedScreenTextPrint(u8 *text, u8 var1, u8 var2) color.fgColor = 0; color.bgColor = 15; color.shadowColor = 3; - AddTextPrinterParametrized2(gSaveFailedWindowIds.textWindowId, 1, var1 * 8, var2 * 8 + 1, 0, 0, &color, 0, text); + AddTextPrinterParametrized2(gSaveFailedWindowIds[TEXT_WIN_ID], 1, var1 * 8, var2 * 8 + 1, 0, 0, &color, 0, text); } void DoSaveFailedScreen(u8 saveType) { SetMainCallback2(CB2_SaveFailedScreen); gSaveFailedType = saveType; - gSaveFailedClockInfo.clockRunning = FALSE; - gSaveFailedClockInfo.debugTimer = 0; - gSaveFailedWindowIds.textWindowId = 0; - gSaveFailedWindowIds.clockWindowId = 0; + gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; + gSaveFailedClockInfo[DEBUG_TIMER] = 0; + gSaveFailedWindowIds[TEXT_WIN_ID] = 0; + gSaveFailedWindowIds[CLOCK_WIN_ID] = 0; } static void VBlankCB(void) @@ -137,10 +140,10 @@ static void CB2_SaveFailedScreen(void) LoadBgTiles(0, gUnknown_0850E87C, 0x120, 0x214); InitWindows(gUnknown_085EFD94); // AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? - gSaveFailedWindowIds.textWindowId = AddWindowWithoutTileMap(&gUnknown_085EFD9C); - SetWindowAttribute(gSaveFailedWindowIds.textWindowId, 7, (u32)&gDecompressionBuffer[0x2800]); - gSaveFailedWindowIds.clockWindowId = AddWindowWithoutTileMap(&gUnknown_085EFDA4); - SetWindowAttribute(gSaveFailedWindowIds.clockWindowId, 7, (u32)&gDecompressionBuffer[0x3D00]); + gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(&gUnknown_085EFD9C); + SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); + gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(&gUnknown_085EFDA4); + SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); DeactivateAllTextPrinters(); ResetSpriteData(); ResetTasks(); @@ -149,12 +152,12 @@ static void CB2_SaveFailedScreen(void) LoadPalette(gSaveFailedClockPal, 0x100, 0x20); LoadPalette(gUnknown_0850FEFC, 0xE0, 0x20); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - SetWindowBorderStyle(gSaveFailedWindowIds.textWindowId, FALSE, 0x214, 0xE); - SetWindowBorderStyle(gSaveFailedWindowIds.clockWindowId, FALSE, 0x214, 0xE); - FillWindowPixelBuffer(gSaveFailedWindowIds.clockWindowId, 0x11); // backwards? - FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); - CopyWindowToVram(gSaveFailedWindowIds.clockWindowId, 2); // again? - CopyWindowToVram(gSaveFailedWindowIds.textWindowId, 1); + SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); + SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); + FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? + CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); EnableInterrupts(1); @@ -179,25 +182,25 @@ static void CB2_WipeSave(void) { u8 wipeTries = 0; - gSaveFailedClockInfo.clockRunning = TRUE; + gSaveFailedClockInfo[CLOCK_RUNNING] = TRUE; while (gDamagedSaveSectors != 0 && wipeTries < 3) { if (WipeSectors(gDamagedSaveSectors) != FALSE) { - FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); SetMainCallback2(CB2_GameplayCannotBeContinued); return; } - FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); SaveFailedScreenTextPrint(gText_CheckCompleted, 1, 0); HandleSavingData(gSaveFailedType); if (gDamagedSaveSectors != 0) { - FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); } @@ -206,12 +209,12 @@ static void CB2_WipeSave(void) if (wipeTries == 3) { - FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); } else { - FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); if (gGameContinueCallback == NULL) SaveFailedScreenTextPrint(gText_SaveCompleteGameCannotContinue, 1, 0); @@ -224,11 +227,11 @@ static void CB2_WipeSave(void) static void CB2_GameplayCannotBeContinued(void) { - gSaveFailedClockInfo.clockRunning = FALSE; + gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; if (gMain.newKeys & A_BUTTON) { - FillWindowPixelBuffer(gSaveFailedWindowIds.textWindowId, 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0); SetVBlankCallback(VBlankCB); SetMainCallback2(CB2_FadeAndReturnToTitleScreen); @@ -237,7 +240,7 @@ static void CB2_GameplayCannotBeContinued(void) static void CB2_FadeAndReturnToTitleScreen(void) { - gSaveFailedClockInfo.clockRunning = FALSE; + gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; if (gMain.newKeys & A_BUTTON) { @@ -271,7 +274,7 @@ static void VBlankCB_UpdateClockGraphics(void) gMain.oamBuffer[0].x = 112; gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; - if (gSaveFailedClockInfo.clockRunning != FALSE) + if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE) { gMain.oamBuffer[0].tileNum = gClockFrames[n][0]; gMain.oamBuffer[0].matrixNum = (gClockFrames[n][2] << 4) | (gClockFrames[n][1] << 3); @@ -283,8 +286,8 @@ static void VBlankCB_UpdateClockGraphics(void) CpuFastCopy(gMain.oamBuffer, (void *)OAM, 4); - if (gSaveFailedClockInfo.debugTimer) - gSaveFailedClockInfo.debugTimer--; + if (gSaveFailedClockInfo[DEBUG_TIMER]) + gSaveFailedClockInfo[DEBUG_TIMER]--; } static bool8 VerifySectorWipe(u16 sector) -- cgit v1.2.3 From 058fed1fd89d74182ec8bf6cca97a090496441e9 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 6 Oct 2017 20:35:29 -0400 Subject: oops --- src/save_failed_screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/save_failed_screen.c') diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 8536e541a..3f9219574 100755 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -250,7 +250,7 @@ static void CB2_FadeAndReturnToTitleScreen(void) } } -void CB2_ReturnToTitleScreen(void) +static void CB2_ReturnToTitleScreen(void) { if (!UpdatePaletteFade()) { -- cgit v1.2.3 From e38fd8347d2519551648c351d528cc3fee3924d4 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 6 Oct 2017 21:59:47 -0400 Subject: use rodata for save_failed_screen --- src/save_failed_screen.c | 127 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 18 deletions(-) (limited to 'src/save_failed_screen.c') diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 3f9219574..7a7c30388 100755 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -22,22 +22,11 @@ extern u32 gDamagedSaveSectors; extern const u8 gBirchHelpGfx[]; extern const u8 gBirchBagTilemap[]; extern const u8 gBirchGrassTilemap[]; -extern const u8 gSaveFailedClockGfx[]; - -extern const struct OamData gClockOamData; // sClockOamData -extern const u8 gClockFrames[8][3]; // sClockFrames - -extern const struct BgTemplate gUnknown_085EFD88[]; -extern const struct WindowTemplate gUnknown_085EFD94[]; -extern struct WindowTemplate gUnknown_085EFD9C; -extern struct WindowTemplate gUnknown_085EFDA4; -extern struct SaveSection gSaveDataBuffer; -extern const u32 gUnknown_0850E87C[]; - extern const u16 gBirchBagGrassPal[]; -extern const u16 gSaveFailedClockPal[]; extern const u16 gUnknown_0850FEFC[]; extern const u16 gUnknown_0860F074[]; +extern const u32 gUnknown_0850E87C[]; +extern struct SaveSection gSaveDataBuffer; extern u8 gText_SaveFailedCheckingBackup[]; extern u8 gText_BackupMemoryDamaged[]; @@ -68,6 +57,108 @@ EWRAM_DATA u8 gSaveFailedUnused1[12] = {0}; EWRAM_DATA u8 gSaveFailedWindowIds[2] = {0}; EWRAM_DATA u8 gSaveFailedUnused2[4] = {0}; +static const struct OamData sClockOamData = +{ + 160, // Y + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0 +}; + +static const struct BgTemplate gUnknown_085EFD88[3] = +{ + { + .bg = 0, + .charBaseIndex = 2, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0, + }, + { + .bg = 2, + .charBaseIndex = 0, + .mapBaseIndex = 14, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0, + }, + { + .bg = 3, + .charBaseIndex = 0, + .mapBaseIndex = 15, + .screenSize = 0, + .paletteMode = 0, + .priority = 3, + .baseTile = 0, + }, +}; + +static const struct WindowTemplate gUnknown_085EFD94[] = +{ + { + .priority = 255, + .tilemapLeft = 0, + .tilemapTop = 0, + .width = 0, + .height = 0, + .paletteNum = 0, + .baseBlock = 0, + } +}; + +static const struct WindowTemplate gUnknown_085EFD9C[] = +{ + { + .priority = 0, + .tilemapLeft = 1, + .tilemapTop = 13, + .width = 28, + .height = 6, + .paletteNum = 15, + .baseBlock = 1, + } +}; + +static const struct WindowTemplate gUnknown_085EFDA4[] = +{ + { + .priority = 0, + .tilemapLeft = 14, + .tilemapTop = 9, + .width = 2, + .height = 2, + .paletteNum = 15, + .baseBlock = 169, + } +}; + +static const u8 sClockFrames[8][3] = +{ + { 1, 0, 0 }, + { 5, 0, 0 }, + { 9, 0, 0 }, + { 5, 0, 1 }, + { 1, 0, 1 }, + { 5, 1, 1 }, + { 9, 1, 0 }, + { 5, 1, 0 }, +}; + +static const u8 gSaveFailedClockPal[] = INCBIN_U8("graphics/misc/clock_small.gbapal"); +static const u8 gSaveFailedClockGfx[] = INCBIN_U8("graphics/misc/clock_small.4bpp.lz"); + static void CB2_SaveFailedScreen(void); static void CB2_WipeSave(void); static void CB2_GameplayCannotBeContinued(void); @@ -140,9 +231,9 @@ static void CB2_SaveFailedScreen(void) LoadBgTiles(0, gUnknown_0850E87C, 0x120, 0x214); InitWindows(gUnknown_085EFD94); // AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? - gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(&gUnknown_085EFD9C); + gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C); SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); - gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(&gUnknown_085EFDA4); + gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4); SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); DeactivateAllTextPrinters(); ResetSpriteData(); @@ -270,14 +361,14 @@ static void VBlankCB_UpdateClockGraphics(void) { unsigned int n = (gMain.vblankCounter2 >> 3) & 7; - gMain.oamBuffer[0] = gClockOamData; + gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0].x = 112; gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE) { - gMain.oamBuffer[0].tileNum = gClockFrames[n][0]; - gMain.oamBuffer[0].matrixNum = (gClockFrames[n][2] << 4) | (gClockFrames[n][1] << 3); + gMain.oamBuffer[0].tileNum = sClockFrames[n][0]; + gMain.oamBuffer[0].matrixNum = (sClockFrames[n][2] << 4) | (sClockFrames[n][1] << 3); } else { -- cgit v1.2.3