Clean up save related files

This commit is contained in:
DizzyEggg 2018-11-18 19:37:18 +01:00
parent 032dd251e6
commit 7ce3473b0e
13 changed files with 235 additions and 251 deletions

View File

@ -1,12 +1,15 @@
#ifndef GUARD_DECORATION_INVENTORY_H #ifndef GUARD_DECORATION_INVENTORY_H
#define GUARD_DECORATION_INVENTORY_H #define GUARD_DECORATION_INVENTORY_H
struct DecorationInventory {
struct DecorationInventory
{
u8 *items; u8 *items;
u8 size; u8 size;
}; };
extern struct DecorationInventory gDecorationInventories[]; extern struct DecorationInventory gDecorationInventories[];
void SetDecorationInventoriesPointers(void);
void ClearDecorationInventories(void); void ClearDecorationInventories(void);
s8 GetFirstEmptyDecorSlot(u8 idx); s8 GetFirstEmptyDecorSlot(u8 idx);
u8 CheckHasDecoration(u8); u8 CheckHasDecoration(u8);

View File

@ -30,6 +30,5 @@ void LoadPlayerBag(void);
void SavePlayerBag(void); void SavePlayerBag(void);
void ApplyNewEncryptionKeyToHword(u16 *hWord, u32 newKey); void ApplyNewEncryptionKeyToHword(u16 *hWord, u32 newKey);
void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey); void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey);
void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey);
#endif // GUARD_LOAD_SAVE_H #endif // GUARD_LOAD_SAVE_H

View File

@ -73,7 +73,7 @@ void SetFixedHoleWarpAsDestination(s16 x, s16 y);
void warp1_set_to_sav1w(void); void warp1_set_to_sav1w(void);
void sub_8084F2C(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void sub_8084F2C(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y);
void sub_8084F6C(u8 a1); void sub_8084F6C(u8 a1);
void sub_8084FAC(void); void sub_8084FAC(int unused);
const struct MapConnection *GetMapConnection(u8 dir); const struct MapConnection *GetMapConnection(u8 dir);
static bool8 SetDiveWarp(u8 dir, u16 x, u16 y); static bool8 SetDiveWarp(u8 dir, u16 x, u16 y);
bool8 SetDiveWarpEmerge(u16 x, u16 y); bool8 SetDiveWarpEmerge(u16 x, u16 y);

View File

@ -54,7 +54,12 @@ enum
SAVE_HALL_OF_FAME_ERASE_BEFORE // unused SAVE_HALL_OF_FAME_ERASE_BEFORE // unused
}; };
#define SECTION_ID_RECORDED_BATTLE 31 #define SECTOR_SAVE_SLOT_LENGTH 14
#define SECTOR_ID_HOF_1 28
#define SECTOR_ID_HOF_2 29
#define SECTOR_ID_TRAINER_HILL 30
#define SECTOR_ID_RECORDED_BATTLE 31
#define SECTORS_COUNT 32
extern u16 gLastWrittenSector; extern u16 gLastWrittenSector;
extern u32 gLastSaveCounter; extern u32 gLastSaveCounter;
@ -72,26 +77,6 @@ extern struct SaveSection gSaveDataBuffer;
void ClearSaveData(void); void ClearSaveData(void);
void Save_ResetSaveCounters(void); void Save_ResetSaveCounters(void);
bool32 SetDamagedSectorBits(u8 op, u8 bit);
u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location);
u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location);
u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size);
u8 TryWriteSector(u8 sector, u8 *data);
u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location);
u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location);
u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location);
u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location);
u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location);
u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location);
u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location);
u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location);
u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location);
u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location);
u8 GetSaveValidStatus(const struct SaveSectionLocation *location);
u8 sub_81530DC(u8 a1, u8 *data, u16 size);
u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section);
u16 CalculateChecksum(void *data, u16 size);
void UpdateSaveAddresses(void);
u8 HandleSavingData(u8 saveType); u8 HandleSavingData(u8 saveType);
u8 TrySavingData(u8 saveType); u8 TrySavingData(u8 saveType);
bool8 sub_8153380(void); bool8 sub_8153380(void);

View File

@ -1,7 +1,6 @@
#ifndef GUARD_SAVE_LOCATION_H #ifndef GUARD_SAVE_LOCATION_H
#define GUARD_SAVE_LOCATION_H #define GUARD_SAVE_LOCATION_H
bool32 sub_81AFCEC(void);
void TrySetMapSaveWarpStatus(void); void TrySetMapSaveWarpStatus(void);
void sub_81AFDA0(void); void sub_81AFDA0(void);
void sub_81AFDD0(void); void sub_81AFDD0(void);

View File

@ -10,6 +10,7 @@
#include "bg.h" #include "bg.h"
#include "text_window.h" #include "text_window.h"
#include "constants/songs.h" #include "constants/songs.h"
#include "constants/rgb.h"
extern const u8 gText_ClearAllSaveData[]; extern const u8 gText_ClearAllSaveData[];
extern const u8 gText_ClearingData[]; extern const u8 gText_ClearingData[];
@ -72,7 +73,7 @@ static const struct WindowTemplate sClearSaveYesNo[] =
void CB2_InitClearSaveDataScreen(void) void CB2_InitClearSaveDataScreen(void)
{ {
if(SetupClearSaveDataScreen()) if (SetupClearSaveDataScreen())
CreateTask(Task_DoClearSaveDataScreenYesNo, 0); CreateTask(Task_DoClearSaveDataScreenYesNo, 0);
} }
@ -86,18 +87,18 @@ static void Task_DoClearSaveDataScreenYesNo(u8 taskId)
static void Task_ClearSaveDataScreenYesNoChoice(u8 taskId) static void Task_ClearSaveDataScreenYesNoChoice(u8 taskId)
{ {
switch(Menu_ProcessInputNoWrapClearOnChoose()) switch (Menu_ProcessInputNoWrapClearOnChoose())
{ {
case 0: case 0:
FillWindowPixelBuffer(0, 17); FillWindowPixelBuffer(0, 17);
AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0); AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0);
gTasks[taskId].func = Task_ClearSaveData; gTasks[taskId].func = Task_ClearSaveData;
break; break;
case 1: case 1:
case -1: case -1:
PlaySE(SE_SELECT); PlaySE(SE_SELECT);
DestroyTask(taskId); DestroyTask(taskId);
SetMainCallback2(CB2_FadeAndDoReset); SetMainCallback2(CB2_FadeAndDoReset);
} }
} }
@ -125,55 +126,55 @@ static bool8 SetupClearSaveDataScreen(void)
switch(gMain.state) switch(gMain.state)
{ {
case 0: case 0:
default: default:
SetVBlankCallback(NULL); SetVBlankCallback(NULL);
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0); SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0); SetGpuReg(REG_OFFSET_BG0VOFS, 0);
SetGpuReg(REG_OFFSET_BG3HOFS, 0); SetGpuReg(REG_OFFSET_BG3HOFS, 0);
SetGpuReg(REG_OFFSET_BG3VOFS, 0); SetGpuReg(REG_OFFSET_BG3VOFS, 0);
SetGpuReg(REG_OFFSET_WIN0H, 0); SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0); SetGpuReg(REG_OFFSET_WIN0V, 0);
SetGpuReg(REG_OFFSET_WININ, 0); SetGpuReg(REG_OFFSET_WININ, 0);
SetGpuReg(REG_OFFSET_WINOUT, 0); SetGpuReg(REG_OFFSET_WINOUT, 0);
SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0); SetGpuReg(REG_OFFSET_BLDY, 0);
DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE);
DmaFill32(3, 0, (void *)OAM, OAM_SIZE); DmaFill32(3, 0, (void *)OAM, OAM_SIZE);
DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2);
ResetPaletteFade(); ResetPaletteFade();
gPlttBufferUnfaded[0] = 0x7fff; gPlttBufferUnfaded[0] = RGB_WHITE;
gPlttBufferFaded[0] = 0x7fff; gPlttBufferFaded[0] = RGB_WHITE;
gPlttBufferUnfaded[1] = 0x3945; gPlttBufferUnfaded[1] = RGB(5, 10, 14);
gPlttBufferFaded[1] = 0x3945; gPlttBufferFaded[1] = RGB(5, 10, 14);
for (i = 0; i < 0x10; i++) for (i = 0; i < 0x10; i++)
((u16 *)(VRAM + 0x20))[i] = 0x1111; ((u16 *)(VRAM + 0x20))[i] = 0x1111;
for (i = 0; i < 0x400; i++) for (i = 0; i < 0x400; i++)
((u16 *)(VRAM + 0xF000))[i] = 0x0001; ((u16 *)(VRAM + 0xF000))[i] = 0x0001;
ResetTasks(); ResetTasks();
ResetSpriteData(); ResetSpriteData();
ResetBgsAndClearDma3BusyFlags(0); ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates)); InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates));
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
ShowBg(0); ShowBg(0);
ShowBg(3); ShowBg(3);
SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDCNT, 0);
InitClearSaveDataScreenWindows(); InitClearSaveDataScreenWindows();
BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF); BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF);
EnableInterrupts(1); EnableInterrupts(INTR_FLAG_VBLANK);
SetVBlankCallback(VBlankCB); SetVBlankCallback(VBlankCB);
gMain.state = 1; gMain.state = 1;
break; break;
case 1: case 1:
UpdatePaletteFade(); UpdatePaletteFade();
if(!gPaletteFade.active) if(!gPaletteFade.active)
{ {
SetMainCallback2(MainCB); SetMainCallback2(MainCB);
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
} }
@ -182,18 +183,19 @@ static void CB2_FadeAndDoReset(void)
{ {
switch(gMain.state) switch(gMain.state)
{ {
case 0: case 0:
default: default:
BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF); BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF);
gMain.state = 1; gMain.state = 1;
break; break;
case 1: case 1:
UpdatePaletteFade(); UpdatePaletteFade();
if(!gPaletteFade.active) if(!gPaletteFade.active)
{ {
FreeAllWindowBuffers(); FreeAllWindowBuffers();
DoSoftReset(); DoSoftReset();
} }
break;
} }
} }

View File

@ -521,7 +521,7 @@ static void Task_Hof_InitTeamSaveData(u8 taskId)
static void Task_Hof_TrySaveData(u8 taskId) static void Task_Hof_TrySaveData(u8 taskId)
{ {
gGameContinueCallback = CB2_DoHallOfFameScreenDontSaveData; gGameContinueCallback = CB2_DoHallOfFameScreenDontSaveData;
if (TrySavingData(3) == 0xFF && gDamagedSaveSectors != 0) if (TrySavingData(SAVE_HALL_OF_FAME) == 0xFF && gDamagedSaveSectors != 0)
{ {
UnsetBgTilemapBuffer(1); UnsetBgTilemapBuffer(1);
UnsetBgTilemapBuffer(3); UnsetBgTilemapBuffer(3);

View File

@ -6,14 +6,15 @@
#include "random.h" #include "random.h"
#include "malloc.h" #include "malloc.h"
#include "item.h" #include "item.h"
#include "overworld.h"
#include "decoration_inventory.h"
static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey);
extern void* gUnknown_0203CF5C; extern void* gUnknown_0203CF5C;
extern bool16 IdentifyFlash(void); extern bool16 IdentifyFlash(void);
extern void SetDecorationInventoriesPointers(void);
extern void ApplyNewEncryptionKeyToGameStats(u32 key);
extern void ApplyNewEncryptionKeyToBerryPowder(u32 key); extern void ApplyNewEncryptionKeyToBerryPowder(u32 key);
extern void sub_8084FAC(int unused);
#define SAVEBLOCK_MOVE_RANGE 128 #define SAVEBLOCK_MOVE_RANGE 128
@ -286,7 +287,7 @@ void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey)
*word ^= newKey; *word ^= newKey;
} }
void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey) static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey)
{ {
ApplyNewEncryptionKeyToGameStats(encryptionKey); ApplyNewEncryptionKeyToGameStats(encryptionKey);
ApplyNewEncryptionKeyToBagItems_(encryptionKey); ApplyNewEncryptionKeyToBagItems_(encryptionKey);

View File

@ -764,7 +764,7 @@ void sub_8084F6C(u8 a1)
SetWarpData(&gSaveBlock1Ptr->warp1, warp->group, warp->map, -1, warp->x, warp->y); SetWarpData(&gSaveBlock1Ptr->warp1, warp->group, warp->map, -1, warp->x, warp->y);
} }
void sub_8084FAC(void) void sub_8084FAC(int unused)
{ {
gSaveBlock1Ptr->warp1 = gSaveBlock1Ptr->warp2; gSaveBlock1Ptr->warp1 = gSaveBlock1Ptr->warp2;
} }

View File

@ -490,7 +490,7 @@ bool32 MoveRecordedBattleToSaveData(void)
static bool32 TryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst, struct SaveSection *saveBuffer) static bool32 TryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst, struct SaveSection *saveBuffer)
{ {
if (TryCopySpecialSaveSection(SECTION_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1) if (TryCopySpecialSaveSection(SECTOR_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1)
return FALSE; return FALSE;
memcpy(dst, saveBuffer, sizeof(struct RecordedBattleSave)); memcpy(dst, saveBuffer, sizeof(struct RecordedBattleSave));

View File

@ -1,15 +1,23 @@
#include "global.h" #include "global.h"
#include "gba/flash_internal.h" #include "gba/flash_internal.h"
#include "save.h" #include "save.h"
#include "constants/game_stat.h"
#include "task.h" #include "task.h"
#include "decompress.h" #include "decompress.h"
#include "load_save.h" #include "load_save.h"
#include "overworld.h" #include "overworld.h"
#include "main.h"
#include "constants/game_stat.h"
static u16 CalculateChecksum(void *data, u16 size);
static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section);
static u8 GetSaveValidStatus(const struct SaveSectionLocation *location);
static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location);
static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location);
static u8 TryWriteSector(u8 sector, u8 *data);
static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location);
// for the chunk declarations // for the chunk declarations
extern bool8 gSoftResetDisabled;
extern u32 gUnknown_0203CF5C; extern u32 gUnknown_0203CF5C;
// Divide save blocks into individual chunks to be written to flash sectors // Divide save blocks into individual chunks to be written to flash sectors
@ -24,7 +32,7 @@ extern u32 gUnknown_0203CF5C;
* Sectors 0 - 13: Save Slot 1 * Sectors 0 - 13: Save Slot 1
* Sectors 14 - 27: Save Slot 2 * Sectors 14 - 27: Save Slot 2
* Sectors 28 - 29: Hall of Fame * Sectors 28 - 29: Hall of Fame
* Sector 30: e-Reader/Mystery Gift Stuff (note: e-Reader is deprecated in Emerald US) * Sector 30: Trainer Hill
* Sector 31: Recorded Battle * Sector 31: Recorded Battle
* *
* There are two save slots for saving the player's game data. We alternate between * There are two save slots for saving the player's game data. We alternate between
@ -105,7 +113,7 @@ void Save_ResetSaveCounters(void)
gDamagedSaveSectors = 0; gDamagedSaveSectors = 0;
} }
bool32 SetDamagedSectorBits(u8 op, u8 bit) static bool32 SetDamagedSectorBits(u8 op, u8 bit)
{ {
bool32 retVal = FALSE; bool32 retVal = FALSE;
@ -126,7 +134,7 @@ bool32 SetDamagedSectorBits(u8 op, u8 bit)
return retVal; return retVal;
} }
u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) static u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location)
{ {
u32 retVal; u32 retVal;
u16 i; u16 i;
@ -142,11 +150,11 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location)
gLastKnownGoodSector = gLastWrittenSector; // backup the current written sector before attempting to write. gLastKnownGoodSector = gLastWrittenSector; // backup the current written sector before attempting to write.
gLastSaveCounter = gSaveCounter; gLastSaveCounter = gSaveCounter;
gLastWrittenSector++; gLastWrittenSector++;
gLastWrittenSector = gLastWrittenSector % 0xE; // array count save sector locations gLastWrittenSector = gLastWrittenSector % SECTOR_SAVE_SLOT_LENGTH; // array count save sector locations
gSaveCounter++; gSaveCounter++;
retVal = 1; retVal = 1;
for (i = 0; i < 0xE; i++) for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
HandleWriteSector(i, location); HandleWriteSector(i, location);
if (gDamagedSaveSectors != 0) // skip the damaged sector. if (gDamagedSaveSectors != 0) // skip the damaged sector.
@ -160,7 +168,7 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location)
return retVal; return retVal;
} }
u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location)
{ {
u16 i; u16 i;
u16 sector; u16 sector;
@ -168,8 +176,8 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location)
u16 size; u16 size;
sector = a1 + gLastWrittenSector; sector = a1 + gLastWrittenSector;
sector %= 0xE; sector %= SECTOR_SAVE_SLOT_LENGTH;
sector += 0xE * (gSaveCounter % 2); sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
data = location[a1].data; data = location[a1].data;
size = location[a1].size; size = location[a1].size;
@ -189,7 +197,7 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location)
return TryWriteSector(sector, gFastSaveSection->data); return TryWriteSector(sector, gFastSaveSection->data);
} }
u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size) static u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size)
{ {
u16 i; u16 i;
struct SaveSection *section = &gSaveDataBuffer; struct SaveSection *section = &gSaveDataBuffer;
@ -206,7 +214,7 @@ u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size)
return TryWriteSector(sector, section->data); return TryWriteSector(sector, section->data);
} }
u8 TryWriteSector(u8 sector, u8 *data) static u8 TryWriteSector(u8 sector, u8 *data)
{ {
if (ProgramFlashSectorAndVerify(sector, data) != 0) // is damaged? if (ProgramFlashSectorAndVerify(sector, data) != 0) // is damaged?
{ {
@ -220,20 +228,20 @@ u8 TryWriteSector(u8 sector, u8 *data)
} }
} }
u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused static u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused
{ {
gFastSaveSection = &gSaveDataBuffer; gFastSaveSection = &gSaveDataBuffer;
gLastKnownGoodSector = gLastWrittenSector; gLastKnownGoodSector = gLastWrittenSector;
gLastSaveCounter = gSaveCounter; gLastSaveCounter = gSaveCounter;
gLastWrittenSector++; gLastWrittenSector++;
gLastWrittenSector = gLastWrittenSector % 0xE; gLastWrittenSector %= SECTOR_SAVE_SLOT_LENGTH;
gSaveCounter++; gSaveCounter++;
gUnknown_03006208 = 0; gUnknown_03006208 = 0;
gDamagedSaveSectors = 0; gDamagedSaveSectors = 0;
return 0; return 0;
} }
u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused static u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused
{ {
gFastSaveSection = &gSaveDataBuffer; gFastSaveSection = &gSaveDataBuffer;
gLastKnownGoodSector = gLastWrittenSector; gLastKnownGoodSector = gLastWrittenSector;
@ -243,7 +251,7 @@ u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ev
return 0; return 0;
} }
u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location) static u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location)
{ {
u8 retVal; u8 retVal;
@ -267,7 +275,7 @@ u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location)
return retVal; return retVal;
} }
u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location) static u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location)
{ {
u8 retVal = 1; u8 retVal = 1;
@ -282,7 +290,7 @@ u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location)
return retVal; return retVal;
} }
u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location)
{ {
u16 i; u16 i;
u16 sector; u16 sector;
@ -291,8 +299,8 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location)
u8 status; u8 status;
sector = a1 + gLastWrittenSector; sector = a1 + gLastWrittenSector;
sector %= 0xE; sector %= SECTOR_SAVE_SLOT_LENGTH;
sector += 0xE * (gSaveCounter % 2); sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
data = location[a1].data; data = location[a1].data;
size = location[a1].size; size = location[a1].size;
@ -356,13 +364,13 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location)
} }
} }
u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location) static u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location)
{ {
u16 sector; u16 sector;
sector = a1 + gLastWrittenSector; // no sub 1? sector = a1 + gLastWrittenSector; // no sub 1?
sector %= 0xE; sector %= SECTOR_SAVE_SLOT_LENGTH;
sector += 0xE * (gSaveCounter % 2); sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25)) if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25))
{ {
@ -379,13 +387,13 @@ u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location)
} }
} }
u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location) static u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location)
{ {
u16 sector; u16 sector;
sector = a1 + gLastWrittenSector - 1; sector = a1 + gLastWrittenSector - 1;
sector %= 0xE; sector %= SECTOR_SAVE_SLOT_LENGTH;
sector += 0xE * (gSaveCounter % 2); sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), ((u8 *)gFastSaveSection)[sizeof(struct UnkSaveSection)])) if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), ((u8 *)gFastSaveSection)[sizeof(struct UnkSaveSection)]))
{ {
@ -402,13 +410,13 @@ u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location)
} }
} }
u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location) static u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location)
{ {
u16 sector; u16 sector;
sector = a1 + gLastWrittenSector - 1; // no sub 1? sector = a1 + gLastWrittenSector - 1; // no sub 1?
sector %= 0xE; sector %= SECTOR_SAVE_SLOT_LENGTH;
sector += 0xE * (gSaveCounter % 2); sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25)) if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25))
{ {
@ -425,7 +433,7 @@ u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location)
} }
} }
u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location) static u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location)
{ {
u8 retVal; u8 retVal;
gFastSaveSection = &gSaveDataBuffer; gFastSaveSection = &gSaveDataBuffer;
@ -442,14 +450,14 @@ u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location)
return retVal; return retVal;
} }
u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location) static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location)
{ {
u16 i; u16 i;
u16 checksum; u16 checksum;
u16 v3 = 0xE * (gSaveCounter % 2); u16 v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
u16 id; u16 id;
for (i = 0; i < 0xE; i++) for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
{ {
DoReadFlashWholeSection(i + v3, gFastSaveSection); DoReadFlashWholeSection(i + v3, gFastSaveSection);
id = gFastSaveSection->id; id = gFastSaveSection->id;
@ -468,7 +476,7 @@ u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location)
return 1; return 1;
} }
u8 GetSaveValidStatus(const struct SaveSectionLocation *location) static u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
{ {
u16 i; u16 i;
u16 checksum; u16 checksum;
@ -480,7 +488,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
u8 saveSlot2Status; u8 saveSlot2Status;
// check save slot 1. // check save slot 1.
for (i = 0; i < 0xE; i++) for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
{ {
DoReadFlashWholeSection(i, gFastSaveSection); DoReadFlashWholeSection(i, gFastSaveSection);
if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE) if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE)
@ -511,9 +519,9 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
securityPassed = FALSE; securityPassed = FALSE;
// check save slot 2. // check save slot 2.
for (i = 0; i < 0xE; i++) for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
{ {
DoReadFlashWholeSection(i + 0xE, gFastSaveSection); DoReadFlashWholeSection(i + SECTOR_SAVE_SLOT_LENGTH, gFastSaveSection);
if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE) if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE)
{ {
securityPassed = TRUE; securityPassed = TRUE;
@ -543,24 +551,16 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
if ((saveSlot1Counter == -1 && saveSlot2Counter == 0) || (saveSlot1Counter == 0 && saveSlot2Counter == -1)) if ((saveSlot1Counter == -1 && saveSlot2Counter == 0) || (saveSlot1Counter == 0 && saveSlot2Counter == -1))
{ {
if ((unsigned)(saveSlot1Counter + 1) < (unsigned)(saveSlot2Counter + 1)) if ((unsigned)(saveSlot1Counter + 1) < (unsigned)(saveSlot2Counter + 1))
{
gSaveCounter = saveSlot2Counter; gSaveCounter = saveSlot2Counter;
}
else else
{
gSaveCounter = saveSlot1Counter; gSaveCounter = saveSlot1Counter;
}
} }
else else
{ {
if (saveSlot1Counter < saveSlot2Counter) if (saveSlot1Counter < saveSlot2Counter)
{
gSaveCounter = saveSlot2Counter; gSaveCounter = saveSlot2Counter;
}
else else
{
gSaveCounter = saveSlot1Counter; gSaveCounter = saveSlot1Counter;
}
} }
return 1; return 1;
} }
@ -593,7 +593,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
return 2; return 2;
} }
u8 sub_81530DC(u8 a1, u8 *data, u16 size) static u8 sub_81530DC(u8 a1, u8 *data, u16 size)
{ {
u16 i; u16 i;
struct SaveSection *section = &gSaveDataBuffer; struct SaveSection *section = &gSaveDataBuffer;
@ -618,13 +618,13 @@ u8 sub_81530DC(u8 a1, u8 *data, u16 size)
} }
} }
u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section) static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section)
{ {
ReadFlash(sector, 0, section->data, sizeof(struct SaveSection)); ReadFlash(sector, 0, section->data, sizeof(struct SaveSection));
return 1; return 1;
} }
u16 CalculateChecksum(void *data, u16 size) static u16 CalculateChecksum(void *data, u16 size)
{ {
u16 i; u16 i;
u32 checksum = 0; u32 checksum = 0;
@ -635,7 +635,7 @@ u16 CalculateChecksum(void *data, u16 size)
return ((checksum >> 16) + checksum); return ((checksum >> 16) + checksum);
} }
void UpdateSaveAddresses(void) static void UpdateSaveAddresses(void)
{ {
int i = 0; int i = 0;
@ -668,7 +668,7 @@ u8 HandleSavingData(u8 saveType)
switch (saveType) switch (saveType)
{ {
case SAVE_HALL_OF_FAME_ERASE_BEFORE: // deletes HOF before overwriting HOF completely. unused case SAVE_HALL_OF_FAME_ERASE_BEFORE: // deletes HOF before overwriting HOF completely. unused
for (i = 0xE * 2 + 0; i < 32; i++) for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++)
EraseFlashSector(i); EraseFlashSector(i);
case SAVE_HALL_OF_FAME: // hall of fame. case SAVE_HALL_OF_FAME: // hall of fame.
if (GetGameStat(GAME_STAT_ENTERED_HOF) < 999) if (GetGameStat(GAME_STAT_ENTERED_HOF) < 999)
@ -676,8 +676,8 @@ u8 HandleSavingData(u8 saveType)
SaveSerializedGame(); SaveSerializedGame();
save_write_to_flash(0xFFFF, gRamSaveSectionLocations); save_write_to_flash(0xFFFF, gRamSaveSectionLocations);
tempAddr = gDecompressionBuffer; tempAddr = gDecompressionBuffer;
HandleWriteSectorNBytes(0x1C, tempAddr, 0xF80); HandleWriteSectorNBytes(SECTOR_ID_HOF_1, tempAddr, 0xF80);
HandleWriteSectorNBytes(0x1D, tempAddr + 0xF80, 0xF80); HandleWriteSectorNBytes(SECTOR_ID_HOF_2, tempAddr + 0xF80, 0xF80);
break; break;
case SAVE_NORMAL: // normal save. also called by overwriting your own save. case SAVE_NORMAL: // normal save. also called by overwriting your own save.
default: default:
@ -692,7 +692,7 @@ u8 HandleSavingData(u8 saveType)
for(i = 0; i < 5; i++) for(i = 0; i < 5; i++)
sav12_xor_get(i, gRamSaveSectionLocations); sav12_xor_get(i, gRamSaveSectionLocations);
break; break;
// support for Ereader was removed in Emerald. // Support for Ereader was removed in Emerald.
/* /*
case EREADER_SAVE: // used in mossdeep "game corner" before/after battling old man e-reader trainer case EREADER_SAVE: // used in mossdeep "game corner" before/after battling old man e-reader trainer
SaveSerializedGame(); SaveSerializedGame();
@ -700,7 +700,7 @@ u8 HandleSavingData(u8 saveType)
break; break;
*/ */
case SAVE_OVERWRITE_DIFFERENT_FILE: case SAVE_OVERWRITE_DIFFERENT_FILE:
for (i = (0xE * 2 + 0); i < 32; i++) for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++)
EraseFlashSector(i); // erase HOF. EraseFlashSector(i); // erase HOF.
SaveSerializedGame(); SaveSerializedGame();
save_write_to_flash(0xFFFF, gRamSaveSectionLocations); save_write_to_flash(0xFFFF, gRamSaveSectionLocations);
@ -710,7 +710,7 @@ u8 HandleSavingData(u8 saveType)
return 0; return 0;
} }
u8 TrySavingData(u8 saveType) // TrySave u8 TrySavingData(u8 saveType)
{ {
if (gFlashMemoryPresent != TRUE) if (gFlashMemoryPresent != TRUE)
{ {
@ -744,7 +744,7 @@ bool8 sub_8153380(void) // trade.s save
bool8 sub_81533AC(void) // trade.s save bool8 sub_81533AC(void) // trade.s save
{ {
u8 retVal = sub_81529D4(0xE, gRamSaveSectionLocations); u8 retVal = sub_81529D4(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations);
if (gDamagedSaveSectors) if (gDamagedSaveSectors)
DoSaveFailedScreen(0); DoSaveFailedScreen(0);
if (retVal == 0xFF) if (retVal == 0xFF)
@ -755,7 +755,7 @@ bool8 sub_81533AC(void) // trade.s save
u8 sub_81533E0(void) // trade.s save u8 sub_81533E0(void) // trade.s save
{ {
sub_8152A34(0xE, gRamSaveSectionLocations); sub_8152A34(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations);
if (gDamagedSaveSectors) if (gDamagedSaveSectors)
DoSaveFailedScreen(0); DoSaveFailedScreen(0);
return 0; return 0;
@ -763,7 +763,7 @@ u8 sub_81533E0(void) // trade.s save
u8 sub_8153408(void) // trade.s save u8 sub_8153408(void) // trade.s save
{ {
sub_8152CAC(0xE, gRamSaveSectionLocations); sub_8152CAC(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations);
if (gDamagedSaveSectors) if (gDamagedSaveSectors)
DoSaveFailedScreen(0); DoSaveFailedScreen(0);
return 0; return 0;
@ -840,8 +840,8 @@ u16 sub_815355C(void)
return 0; return 0;
UpdateSaveAddresses(); UpdateSaveAddresses();
GetSaveValidStatus(gRamSaveSectionLocations); GetSaveValidStatus(gRamSaveSectionLocations);
v3 = 0xE * (gSaveCounter % 2); v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
for (i = 0; i < 14; i++) for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
{ {
DoReadFlashWholeSection(i + v3, gFastSaveSection); DoReadFlashWholeSection(i + v3, gFastSaveSection);
if (gFastSaveSection->id == 0) if (gFastSaveSection->id == 0)
@ -859,7 +859,7 @@ u32 TryCopySpecialSaveSection(u8 sector, u8* dst)
s32 size; s32 size;
u8* savData; u8* savData;
if (sector != 30 && sector != 31) if (sector != SECTOR_ID_TRAINER_HILL && sector != SECTOR_ID_RECORDED_BATTLE)
return 0xFF; return 0xFF;
ReadFlash(sector, 0, (u8 *)&gSaveDataBuffer, sizeof(struct SaveSection)); ReadFlash(sector, 0, (u8 *)&gSaveDataBuffer, sizeof(struct SaveSection));
if (*(u32*)(&gSaveDataBuffer.data[0]) != 0xB39D) if (*(u32*)(&gSaveDataBuffer.data[0]) != 0xB39D)

View File

@ -17,12 +17,12 @@
#define MSG_WIN_TOP 12 #define MSG_WIN_TOP 12
#define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) #define CLOCK_WIN_TOP (MSG_WIN_TOP - 4)
extern u8 gText_SaveFailedCheckingBackup[]; extern const u8 gText_SaveFailedCheckingBackup[];
extern u8 gText_BackupMemoryDamaged[]; extern const u8 gText_BackupMemoryDamaged[];
extern u8 gText_CheckCompleted[]; extern const u8 gText_CheckCompleted[];
extern u8 gText_SaveCompleteGameCannotContinue[]; extern const u8 gText_SaveCompleteGameCannotContinue[];
extern u8 gText_SaveCompletePressA[]; extern const u8 gText_SaveCompletePressA[];
extern u8 gText_GamePlayCannotBeContinued[]; extern const u8 gText_GamePlayCannotBeContinued[];
// gSaveFailedClockInfo enum // gSaveFailedClockInfo enum
enum enum
@ -155,8 +155,8 @@ static void VBlankCB_UpdateClockGraphics(void);
static bool8 VerifySectorWipe(u16 sector); 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(u8 *text, u8 var1, u8 var2) static void SaveFailedScreenTextPrint(const u8 *text, u8 var1, u8 var2)
{ {
u8 color[3]; u8 color[3];
@ -187,72 +187,70 @@ static void CB2_SaveFailedScreen(void)
{ {
switch (gMain.state) switch (gMain.state)
{ {
case 0: case 0:
default: default:
SetVBlankCallback(NULL); SetVBlankCallback(NULL);
SetGpuReg(REG_OFFSET_DISPCNT, 0); SetGpuReg(REG_OFFSET_DISPCNT, 0);
SetGpuReg(REG_OFFSET_BG3CNT, 0); SetGpuReg(REG_OFFSET_BG3CNT, 0);
SetGpuReg(REG_OFFSET_BG2CNT, 0); SetGpuReg(REG_OFFSET_BG2CNT, 0);
SetGpuReg(REG_OFFSET_BG1CNT, 0); SetGpuReg(REG_OFFSET_BG1CNT, 0);
SetGpuReg(REG_OFFSET_BG0CNT, 0); SetGpuReg(REG_OFFSET_BG0CNT, 0);
SetGpuReg(REG_OFFSET_BG3HOFS, 0); SetGpuReg(REG_OFFSET_BG3HOFS, 0);
SetGpuReg(REG_OFFSET_BG3VOFS, 0); SetGpuReg(REG_OFFSET_BG3VOFS, 0);
SetGpuReg(REG_OFFSET_BG2HOFS, 0); SetGpuReg(REG_OFFSET_BG2HOFS, 0);
SetGpuReg(REG_OFFSET_BG2VOFS, 0); SetGpuReg(REG_OFFSET_BG2VOFS, 0);
SetGpuReg(REG_OFFSET_BG1HOFS, 0); SetGpuReg(REG_OFFSET_BG1HOFS, 0);
SetGpuReg(REG_OFFSET_BG1VOFS, 0); SetGpuReg(REG_OFFSET_BG1VOFS, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0); SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0); SetGpuReg(REG_OFFSET_BG0VOFS, 0);
// how come this doesnt use the Dma manager? DmaFill16(3, 0, VRAM, VRAM_SIZE);
DmaFill16(3, 0, VRAM, VRAM_SIZE); DmaFill32(3, 0, OAM, OAM_SIZE);
DmaFill32(3, 0, OAM, OAM_SIZE); DmaFill16(3, 0, PLTT, PLTT_SIZE);
DmaFill16(3, 0, PLTT, PLTT_SIZE); LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM);
LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM); LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000));
LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000)); LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800));
LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800)); LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020));
LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020)); ResetBgsAndClearDma3BusyFlags(0);
ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, gUnknown_085EFD88, 3);
InitBgsFromTemplates(0, gUnknown_085EFD88, 3); 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(gUnknown_085EFD94); gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C);
// AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]);
gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C); gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4);
SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]);
gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4); DeactivateAllTextPrinters();
SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); ResetSpriteData();
DeactivateAllTextPrinters(); ResetTasks();
ResetSpriteData(); ResetPaletteFade();
ResetTasks(); LoadPalette(gBirchBagGrassPal, 0, 0x40);
ResetPaletteFade(); LoadPalette(sSaveFailedClockPal, 0x100, 0x20);
LoadPalette(gBirchBagGrassPal, 0, 0x40); LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20);
LoadPalette(sSaveFailedClockPal, 0x100, 0x20); LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20); SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE);
LoadPalette(gUnknown_0860F074, 0xF0, 0x20); SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE);
SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards?
SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11);
FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again?
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1);
CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0);
CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0);
SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); EnableInterrupts(1);
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); SetVBlankCallback(VBlankCB);
EnableInterrupts(1); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
SetVBlankCallback(VBlankCB); ShowBg(0);
SetGpuReg(0, 0x1040); ShowBg(2);
ShowBg(0); ShowBg(3);
ShowBg(2); gMain.state++;
ShowBg(3); break;
gMain.state++; case 1:
break; if (!UpdatePaletteFade())
case 1: {
if (!UpdatePaletteFade()) SetMainCallback2(CB2_WipeSave);
{ SetVBlankCallback(VBlankCB_UpdateClockGraphics);
SetMainCallback2(CB2_WipeSave); }
SetVBlankCallback(VBlankCB_UpdateClockGraphics); break;
}
break;
} }
} }
@ -346,7 +344,7 @@ static void CB2_ReturnToTitleScreen(void)
static void VBlankCB_UpdateClockGraphics(void) static void VBlankCB_UpdateClockGraphics(void)
{ {
unsigned int n = (gMain.vblankCounter2 >> 3) & 7; u32 n = (gMain.vblankCounter2 >> 3) & 7;
gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0] = sClockOamData;
gMain.oamBuffer[0].x = 112; gMain.oamBuffer[0].x = 112;

View File

@ -9,21 +9,18 @@
static bool32 IsCurMapInLocationList(const u16 *list) static bool32 IsCurMapInLocationList(const u16 *list)
{ {
s32 i;
u16 locSum = (gSaveBlock1Ptr->location.mapGroup << 8) + (gSaveBlock1Ptr->location.mapNum); u16 locSum = (gSaveBlock1Ptr->location.mapGroup << 8) + (gSaveBlock1Ptr->location.mapNum);
// im sure it was written a different way, but for the love of christ I cant figure out how to write it different where it still matches. for (i = 0; list[i] != 0xFFFF; i++)
if (*list != 0xFFFF)
{ {
u16 termValue = 0xFFFF; if (list[i] == locSum)
const u16 *localList; return TRUE;
for (localList = list; *localList != termValue; localList++)
if (*localList == locSum)
return TRUE;
} }
return FALSE; return FALSE;
} }
// TODO: Not require a packed u16 array for these lists
static const u16 sSaveLocationPokeCenterList[] = static const u16 sSaveLocationPokeCenterList[] =
{ {
MAP_OLDALE_TOWN_POKEMON_CENTER_1F, MAP_OLDALE_TOWN_POKEMON_CENTER_1F,
@ -72,7 +69,7 @@ static bool32 IsCurMapPokeCenter(void)
return IsCurMapInLocationList(sSaveLocationPokeCenterList); return IsCurMapInLocationList(sSaveLocationPokeCenterList);
} }
static const u16 sSaveLocationReloadLocList[] = // there's only 1 location, and it's presumed its for the save reload feature for battle tower static const u16 sSaveLocationReloadLocList[] = // There's only 1 location, and it's presumed its for the save reload feature for battle tower.
{ {
MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY, MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY,
0xFFFF, 0xFFFF,
@ -83,13 +80,13 @@ static bool32 IsCurMapReloadLocation(void)
return IsCurMapInLocationList(sSaveLocationReloadLocList); return IsCurMapInLocationList(sSaveLocationReloadLocList);
} }
// nulled out list. unknown what this would have been // Nulled out list. Unknown what this would have been.
static const u16 sUnknown_0861440E[] = static const u16 sUnknown_0861440E[] =
{ {
0xFFFF, 0xFFFF,
}; };
bool32 sub_81AFCEC(void) static bool32 sub_81AFCEC(void)
{ {
return IsCurMapInLocationList(sUnknown_0861440E); return IsCurMapInLocationList(sUnknown_0861440E);
} }