Clean up save_failed_screen
This commit is contained in:
@@ -29,6 +29,11 @@ struct SaveSectionOffsets
|
|||||||
u16 size;
|
u16 size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Each 4 KiB flash sector contains 3968 bytes of actual data followed by a 128 byte footer
|
||||||
|
#define SECTOR_DATA_SIZE 3968
|
||||||
|
#define SECTOR_FOOTER_SIZE 128
|
||||||
|
#define SECTOR_SIZE (SECTOR_DATA_SIZE + SECTOR_FOOTER_SIZE)
|
||||||
|
|
||||||
// Emerald changes this definition to be the sectors per slot.
|
// Emerald changes this definition to be the sectors per slot.
|
||||||
#define NUM_SECTORS_PER_SLOT 16
|
#define NUM_SECTORS_PER_SLOT 16
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location);
|
|||||||
|
|
||||||
// Divide save blocks into individual chunks to be written to flash sectors
|
// Divide save blocks into individual chunks to be written to flash sectors
|
||||||
|
|
||||||
// Each 4 KiB flash sector contains 3968 bytes of actual data followed by a 128 byte footer
|
|
||||||
#define SECTOR_DATA_SIZE 3968
|
|
||||||
#define SECTOR_FOOTER_SIZE 128
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sector Layout:
|
* Sector Layout:
|
||||||
*
|
*
|
||||||
|
|||||||
+49
-60
@@ -25,25 +25,25 @@ extern const u8 gText_SaveCompleteGameCannotContinue[];
|
|||||||
extern const u8 gText_SaveCompletePressA[];
|
extern const u8 gText_SaveCompletePressA[];
|
||||||
extern const u8 gText_GamePlayCannotBeContinued[];
|
extern const u8 gText_GamePlayCannotBeContinued[];
|
||||||
|
|
||||||
// gSaveFailedClockInfo enum
|
// sClockInfo enum
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
CLOCK_RUNNING,
|
CLOCK_RUNNING,
|
||||||
DEBUG_TIMER
|
DEBUG_TIMER
|
||||||
};
|
};
|
||||||
|
|
||||||
// gSaveFailedWindowIds enum
|
// sWindowIds enum
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TEXT_WIN_ID,
|
TEXT_WIN_ID,
|
||||||
CLOCK_WIN_ID
|
CLOCK_WIN_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
EWRAM_DATA u16 gSaveFailedType = {0};
|
static EWRAM_DATA u16 sSaveFailedType = {0};
|
||||||
EWRAM_DATA u16 gSaveFailedClockInfo[2] = {0};
|
static EWRAM_DATA u16 sClockInfo[2] = {0};
|
||||||
EWRAM_DATA u8 gSaveFailedUnused1[12] = {0};
|
static EWRAM_DATA u8 sUnused1[12] = {0};
|
||||||
EWRAM_DATA u8 gSaveFailedWindowIds[2] = {0};
|
static EWRAM_DATA u8 sWindowIds[2] = {0};
|
||||||
EWRAM_DATA u8 gSaveFailedUnused2[4] = {0};
|
static EWRAM_DATA u8 sUnused2[4] = {0};
|
||||||
|
|
||||||
static const struct OamData sClockOamData =
|
static const struct OamData sClockOamData =
|
||||||
{
|
{
|
||||||
@@ -93,20 +93,9 @@ static const struct BgTemplate sBgTemplates[3] =
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct WindowTemplate gUnknown_085EFD94[] =
|
static const struct WindowTemplate sDummyWindowTemplate[] = { DUMMY_WIN_TEMPLATE };
|
||||||
{
|
|
||||||
{
|
|
||||||
.bg = 255,
|
|
||||||
.tilemapLeft = 0,
|
|
||||||
.tilemapTop = 0,
|
|
||||||
.width = 0,
|
|
||||||
.height = 0,
|
|
||||||
.paletteNum = 0,
|
|
||||||
.baseBlock = 0,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct WindowTemplate gUnknown_085EFD9C[] =
|
static const struct WindowTemplate sWindowTemplate_Text[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
.bg = 0,
|
.bg = 0,
|
||||||
@@ -119,7 +108,7 @@ static const struct WindowTemplate gUnknown_085EFD9C[] =
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct WindowTemplate gUnknown_085EFDA4[] =
|
static const struct WindowTemplate sWindowTemplate_Clock[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
.bg = 0,
|
.bg = 0,
|
||||||
@@ -157,24 +146,24 @@ static bool8 VerifySectorWipe(u16 sector);
|
|||||||
static bool8 WipeSectors(u32);
|
static bool8 WipeSectors(u32);
|
||||||
|
|
||||||
// Although this is a general text printer, it's only used in this file.
|
// Although this is a general text printer, it's only used in this file.
|
||||||
static void SaveFailedScreenTextPrint(const u8 *text, u8 var1, u8 var2)
|
static void SaveFailedScreenTextPrint(const u8 *text, u8 x, u8 y)
|
||||||
{
|
{
|
||||||
u8 color[3];
|
u8 color[3];
|
||||||
|
|
||||||
color[0] = 0;
|
color[0] = TEXT_COLOR_TRANSPARENT;
|
||||||
color[1] = 15;
|
color[1] = TEXT_DYNAMIC_COLOR_6;
|
||||||
color[2] = 3;
|
color[2] = TEXT_COLOR_LIGHT_GREY;
|
||||||
AddTextPrinterParameterized4(gSaveFailedWindowIds[TEXT_WIN_ID], 1, var1 * 8, var2 * 8 + 1, 0, 0, color, 0, text);
|
AddTextPrinterParameterized4(sWindowIds[TEXT_WIN_ID], 1, x * 8, y * 8 + 1, 0, 0, color, 0, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoSaveFailedScreen(u8 saveType)
|
void DoSaveFailedScreen(u8 saveType)
|
||||||
{
|
{
|
||||||
SetMainCallback2(CB2_SaveFailedScreen);
|
SetMainCallback2(CB2_SaveFailedScreen);
|
||||||
gSaveFailedType = saveType;
|
sSaveFailedType = saveType;
|
||||||
gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE;
|
sClockInfo[CLOCK_RUNNING] = FALSE;
|
||||||
gSaveFailedClockInfo[DEBUG_TIMER] = 0;
|
sClockInfo[DEBUG_TIMER] = 0;
|
||||||
gSaveFailedWindowIds[TEXT_WIN_ID] = 0;
|
sWindowIds[TEXT_WIN_ID] = 0;
|
||||||
gSaveFailedWindowIds[CLOCK_WIN_ID] = 0;
|
sWindowIds[CLOCK_WIN_ID] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VBlankCB(void)
|
static void VBlankCB(void)
|
||||||
@@ -210,17 +199,17 @@ static void CB2_SaveFailedScreen(void)
|
|||||||
LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM);
|
LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM);
|
||||||
LZ77UnCompVram(gBirchBagTilemap, (void *)(BG_SCREEN_ADDR(14)));
|
LZ77UnCompVram(gBirchBagTilemap, (void *)(BG_SCREEN_ADDR(14)));
|
||||||
LZ77UnCompVram(gBirchGrassTilemap, (void *)(BG_SCREEN_ADDR(15)));
|
LZ77UnCompVram(gBirchGrassTilemap, (void *)(BG_SCREEN_ADDR(15)));
|
||||||
LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020));
|
LZ77UnCompVram(sSaveFailedClockGfx, (void *)(OBJ_VRAM0 + 0x20));
|
||||||
ResetBgsAndClearDma3BusyFlags(0);
|
ResetBgsAndClearDma3BusyFlags(0);
|
||||||
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
|
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
|
||||||
SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]);
|
SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]);
|
||||||
CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800);
|
CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800);
|
||||||
LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214);
|
LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214);
|
||||||
InitWindows(gUnknown_085EFD94);
|
InitWindows(sDummyWindowTemplate);
|
||||||
gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C);
|
sWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(sWindowTemplate_Text);
|
||||||
SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]);
|
SetWindowAttribute(sWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]);
|
||||||
gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4);
|
sWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(sWindowTemplate_Clock);
|
||||||
SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]);
|
SetWindowAttribute(sWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]);
|
||||||
DeactivateAllTextPrinters();
|
DeactivateAllTextPrinters();
|
||||||
ResetSpriteData();
|
ResetSpriteData();
|
||||||
ResetTasks();
|
ResetTasks();
|
||||||
@@ -229,12 +218,12 @@ static void CB2_SaveFailedScreen(void)
|
|||||||
LoadPalette(sSaveFailedClockPal, 0x100, 0x20);
|
LoadPalette(sSaveFailedClockPal, 0x100, 0x20);
|
||||||
LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20);
|
LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20);
|
||||||
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
|
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
|
||||||
DrawStdFrameWithCustomTileAndPalette(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE);
|
DrawStdFrameWithCustomTileAndPalette(sWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE);
|
||||||
DrawStdFrameWithCustomTileAndPalette(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE);
|
DrawStdFrameWithCustomTileAndPalette(sWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE);
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], PIXEL_FILL(1)); // backwards?
|
FillWindowPixelBuffer(sWindowIds[CLOCK_WIN_ID], PIXEL_FILL(1)); // backwards?
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
FillWindowPixelBuffer(sWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
||||||
CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again?
|
CopyWindowToVram(sWindowIds[CLOCK_WIN_ID], 2); // again?
|
||||||
CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1);
|
CopyWindowToVram(sWindowIds[TEXT_WIN_ID], 1);
|
||||||
SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0);
|
SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0);
|
||||||
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
||||||
EnableInterrupts(1);
|
EnableInterrupts(1);
|
||||||
@@ -259,25 +248,25 @@ static void CB2_WipeSave(void)
|
|||||||
{
|
{
|
||||||
u8 wipeTries = 0;
|
u8 wipeTries = 0;
|
||||||
|
|
||||||
gSaveFailedClockInfo[CLOCK_RUNNING] = TRUE;
|
sClockInfo[CLOCK_RUNNING] = TRUE;
|
||||||
|
|
||||||
while (gDamagedSaveSectors != 0 && wipeTries < 3)
|
while (gDamagedSaveSectors != 0 && wipeTries < 3)
|
||||||
{
|
{
|
||||||
if (WipeSectors(gDamagedSaveSectors) != FALSE)
|
if (WipeSectors(gDamagedSaveSectors))
|
||||||
{
|
{
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
FillWindowPixelBuffer(sWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
||||||
SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0);
|
SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0);
|
||||||
SetMainCallback2(CB2_GameplayCannotBeContinued);
|
SetMainCallback2(CB2_GameplayCannotBeContinued);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
FillWindowPixelBuffer(sWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
||||||
SaveFailedScreenTextPrint(gText_CheckCompleted, 1, 0);
|
SaveFailedScreenTextPrint(gText_CheckCompleted, 1, 0);
|
||||||
HandleSavingData(gSaveFailedType);
|
HandleSavingData(sSaveFailedType);
|
||||||
|
|
||||||
if (gDamagedSaveSectors != 0)
|
if (gDamagedSaveSectors != 0)
|
||||||
{
|
{
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
FillWindowPixelBuffer(sWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
||||||
SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0);
|
SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,12 +275,12 @@ static void CB2_WipeSave(void)
|
|||||||
|
|
||||||
if (wipeTries == 3)
|
if (wipeTries == 3)
|
||||||
{
|
{
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
FillWindowPixelBuffer(sWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
||||||
SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0);
|
SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
FillWindowPixelBuffer(sWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
||||||
|
|
||||||
if (gGameContinueCallback == NULL)
|
if (gGameContinueCallback == NULL)
|
||||||
SaveFailedScreenTextPrint(gText_SaveCompleteGameCannotContinue, 1, 0);
|
SaveFailedScreenTextPrint(gText_SaveCompleteGameCannotContinue, 1, 0);
|
||||||
@@ -304,11 +293,11 @@ static void CB2_WipeSave(void)
|
|||||||
|
|
||||||
static void CB2_GameplayCannotBeContinued(void)
|
static void CB2_GameplayCannotBeContinued(void)
|
||||||
{
|
{
|
||||||
gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE;
|
sClockInfo[CLOCK_RUNNING] = FALSE;
|
||||||
|
|
||||||
if (JOY_NEW(A_BUTTON))
|
if (JOY_NEW(A_BUTTON))
|
||||||
{
|
{
|
||||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
FillWindowPixelBuffer(sWindowIds[TEXT_WIN_ID], PIXEL_FILL(1));
|
||||||
SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0);
|
SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0);
|
||||||
SetVBlankCallback(VBlankCB);
|
SetVBlankCallback(VBlankCB);
|
||||||
SetMainCallback2(CB2_FadeAndReturnToTitleScreen);
|
SetMainCallback2(CB2_FadeAndReturnToTitleScreen);
|
||||||
@@ -317,7 +306,7 @@ static void CB2_GameplayCannotBeContinued(void)
|
|||||||
|
|
||||||
static void CB2_FadeAndReturnToTitleScreen(void)
|
static void CB2_FadeAndReturnToTitleScreen(void)
|
||||||
{
|
{
|
||||||
gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE;
|
sClockInfo[CLOCK_RUNNING] = FALSE;
|
||||||
|
|
||||||
if (JOY_NEW(A_BUTTON))
|
if (JOY_NEW(A_BUTTON))
|
||||||
{
|
{
|
||||||
@@ -351,7 +340,7 @@ static void VBlankCB_UpdateClockGraphics(void)
|
|||||||
gMain.oamBuffer[0].x = 112;
|
gMain.oamBuffer[0].x = 112;
|
||||||
gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;
|
gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;
|
||||||
|
|
||||||
if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE)
|
if (sClockInfo[CLOCK_RUNNING])
|
||||||
{
|
{
|
||||||
gMain.oamBuffer[0].tileNum = sClockFrames[n][0];
|
gMain.oamBuffer[0].tileNum = sClockFrames[n][0];
|
||||||
gMain.oamBuffer[0].matrixNum = (sClockFrames[n][2] << 4) | (sClockFrames[n][1] << 3);
|
gMain.oamBuffer[0].matrixNum = (sClockFrames[n][2] << 4) | (sClockFrames[n][1] << 3);
|
||||||
@@ -363,8 +352,8 @@ static void VBlankCB_UpdateClockGraphics(void)
|
|||||||
|
|
||||||
CpuFastCopy(gMain.oamBuffer, (void *)OAM, 4);
|
CpuFastCopy(gMain.oamBuffer, (void *)OAM, 4);
|
||||||
|
|
||||||
if (gSaveFailedClockInfo[DEBUG_TIMER])
|
if (sClockInfo[DEBUG_TIMER])
|
||||||
gSaveFailedClockInfo[DEBUG_TIMER]--;
|
sClockInfo[DEBUG_TIMER]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool8 VerifySectorWipe(u16 sector)
|
static bool8 VerifySectorWipe(u16 sector)
|
||||||
@@ -372,7 +361,7 @@ static bool8 VerifySectorWipe(u16 sector)
|
|||||||
u32 *ptr = (u32 *)&gSaveDataBuffer;
|
u32 *ptr = (u32 *)&gSaveDataBuffer;
|
||||||
u16 i;
|
u16 i;
|
||||||
|
|
||||||
ReadFlash(sector, 0, (u8 *)ptr, 4096);
|
ReadFlash(sector, 0, (u8 *)ptr, SECTOR_SIZE);
|
||||||
|
|
||||||
for (i = 0; i < 0x400; i++, ptr++)
|
for (i = 0; i < 0x400; i++, ptr++)
|
||||||
if (*ptr)
|
if (*ptr)
|
||||||
@@ -388,7 +377,7 @@ static bool8 WipeSector(u16 sector)
|
|||||||
|
|
||||||
for (i = 0; failed && i < 130; i++)
|
for (i = 0; failed && i < 130; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < 0x1000; j++)
|
for (j = 0; j < SECTOR_SIZE; j++)
|
||||||
ProgramFlashByte(sector, j, 0);
|
ProgramFlashByte(sector, j, 0);
|
||||||
|
|
||||||
failed = VerifySectorWipe(sector);
|
failed = VerifySectorWipe(sector);
|
||||||
@@ -401,7 +390,7 @@ static bool8 WipeSectors(u32 sectorBits)
|
|||||||
{
|
{
|
||||||
u16 i;
|
u16 i;
|
||||||
|
|
||||||
for (i = 0; i < 0x20; i++)
|
for (i = 0; i < SECTORS_COUNT; i++)
|
||||||
if ((sectorBits & (1 << i)) && !WipeSector(i))
|
if ((sectorBits & (1 << i)) && !WipeSector(i))
|
||||||
sectorBits &= ~(1 << i);
|
sectorBits &= ~(1 << i);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user