Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds SAVE_TYPE_ERROR_SCREEN #5188

Merged
merged 10 commits into from
Sep 22, 2024
1 change: 1 addition & 0 deletions include/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@
// Naming Screen
#define AUTO_LOWERCASE_KEYBOARD GEN_LATEST // Starting in GEN_6, after entering the first uppercase character, the keyboard switches to lowercase letters.

#define SAVE_TYPE_ERROR_SCREEN FALSE // When enabled, this shows an error message when the game is loaded on a cart without a flash chip or on an emulator with the wrong save type setting instead of crashing.
#endif // GUARD_CONFIG_GENERAL_H
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static void IntrDummy(void);

// Defined in the linker script so that the test build can override it.
extern void gInitialMainCB2(void);
extern void CB2_FlashNotDetectedScreen(void);

const u8 gGameVersion = GAME_VERSION;

Expand Down Expand Up @@ -114,7 +115,7 @@ void AgbMain()
gSoftResetDisabled = FALSE;

if (gFlashMemoryPresent != TRUE)
SetMainCallback2(NULL);
SetMainCallback2((SAVE_TYPE_ERROR_SCREEN) ? CB2_FlashNotDetectedScreen : NULL);

gLinkTransferringData = FALSE;

Expand Down
52 changes: 52 additions & 0 deletions src/save_failed_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,55 @@ static bool8 WipeSectors(u32 sectorBits)
else
return TRUE;
}

void CB2_FlashNotDetectedScreen(void)
{
static const struct WindowTemplate textWin[] =
{
{
.bg = 0,
.tilemapLeft = 3,
.tilemapTop = 2,
.width = 24,
.height = 16,
.paletteNum = 15,
.baseBlock = 1,
}
};

if (gMain.state)
return;

SetGpuReg(REG_OFFSET_DISPCNT, 0);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BG0CNT, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
DmaFill16(3, 0, VRAM, VRAM_SIZE);
DmaFill32(3, 0, OAM, OAM_SIZE);
DmaFill16(3, 0, PLTT, PLTT_SIZE);
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214);
DeactivateAllTextPrinters();
ResetTasks();
ResetPaletteFade();
LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20);
LoadPalette(gStandardMenuPalette, 0xF0, 0x20);
InitWindows(textWin);
DrawStdFrameWithCustomTileAndPalette(0, TRUE, 0x214, 0xE);
static const u8 saveFailedMessage[] =_(
"{COLOR RED}ERROR! {COLOR DARK_GRAY}Flash memory not detected!\n"
"\n"
"If playing on an emulator, set your\n"
"save type setting to\n"
"Flash 1Mb/128K and reload the ROM.\n"
"\n"
"If playing on hardware, your cart\n"
"does not have a working flash chip.");
SaveFailedScreenTextPrint(saveFailedMessage, 1, 0);
TransferPlttBuffer();
*(u16*)PLTT = RGB(17, 18, 31);
ShowBg(0);
gMain.state++;
}
Loading