From 78bd2b0849f357f0d2fbbb8e1e69e50d630dd9b0 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Wed, 31 Jan 2018 15:26:57 -0500 Subject: move save rodata to source and use saveblock chunk macros --- src/save.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'src/save.c') diff --git a/src/save.c b/src/save.c index 023ca6870..138ec7cce 100644 --- a/src/save.c +++ b/src/save.c @@ -4,13 +4,67 @@ #include "constants/game_stat.h" #include "task.h" +// for the chunk declarations +extern struct SaveBlock2 gSaveblock2; +extern struct SaveBlock1 gSaveblock1; +extern struct PokemonStorage gPokemonStorage; + extern struct SaveSectionLocation gRamSaveSectionLocations[0xE]; extern u8 gDecompressionBuffer[]; extern u32 gFlashMemoryPresent; extern u16 gUnknown_03006294; extern bool8 gSoftResetDisabled; -extern const struct SaveSectionOffsets gSaveSectionOffsets[0xE]; +// 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: + * + * Sectors 0 - 13: Save Slot 1 + * Sectors 14 - 27: Save Slot 2 + * Sectors 28 - 29: Hall of Fame + * Sectors 30 - 31: e-Reader battle tower data, maybe? (note: depreciated in Emerald US) + * + * There are two save slots for saving the player's game data. We alternate between + * them each time the game is saved, so that if the current save slot is corrupt, + * we can load the previous one. We also rotate the sectors in each save slot + * so that the same data is not always being written to the same sector. This + * might be done to reduce wear on the flash memory, but I'm not sure, since all + * 14 sectors get written anyway. + */ + +// (u8 *)structure was removed from the first statement of the macro in Emerald. +// This is because malloc is used to allocate addresses so storing the raw +// addresses should not be done in the offsets information. +#define SAVEBLOCK_CHUNK(structure, chunkNum) \ +{ \ + chunkNum * SECTOR_DATA_SIZE, \ + min(sizeof(structure) - chunkNum * SECTOR_DATA_SIZE, SECTOR_DATA_SIZE) \ +} \ + +const struct SaveSectionOffsets gSaveSectionOffsets[] = +{ + SAVEBLOCK_CHUNK(gSaveblock2, 0), + + SAVEBLOCK_CHUNK(gSaveblock1, 0), + SAVEBLOCK_CHUNK(gSaveblock1, 1), + SAVEBLOCK_CHUNK(gSaveblock1, 2), + SAVEBLOCK_CHUNK(gSaveblock1, 3), + + SAVEBLOCK_CHUNK(gPokemonStorage, 0), + SAVEBLOCK_CHUNK(gPokemonStorage, 1), + SAVEBLOCK_CHUNK(gPokemonStorage, 2), + SAVEBLOCK_CHUNK(gPokemonStorage, 3), + SAVEBLOCK_CHUNK(gPokemonStorage, 4), + SAVEBLOCK_CHUNK(gPokemonStorage, 5), + SAVEBLOCK_CHUNK(gPokemonStorage, 6), + SAVEBLOCK_CHUNK(gPokemonStorage, 7), + SAVEBLOCK_CHUNK(gPokemonStorage, 8), +}; extern void DoSaveFailedScreen(u8); // save_failed_screen extern void LoadSerializedGame(void); // load_save -- cgit v1.2.3 From a998cba4f03b34c147acb78d4b70766a50346afe Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Wed, 31 Jan 2018 15:53:38 -0500 Subject: depreciate depreciate --- src/save.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/save.c') diff --git a/src/save.c b/src/save.c index 138ec7cce..0c35c3795 100644 --- a/src/save.c +++ b/src/save.c @@ -27,7 +27,7 @@ extern bool8 gSoftResetDisabled; * Sectors 0 - 13: Save Slot 1 * Sectors 14 - 27: Save Slot 2 * Sectors 28 - 29: Hall of Fame - * Sectors 30 - 31: e-Reader battle tower data, maybe? (note: depreciated in Emerald US) + * Sectors 30 - 31: e-Reader battle tower data, maybe? (note: deprecated in Emerald US) * * There are two save slots for saving the player's game data. We alternate between * them each time the game is saved, so that if the current save slot is corrupt, -- cgit v1.2.3 From eb6aed50e56f36ce416f7ecc8edfacea1da61bf1 Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Wed, 31 Jan 2018 16:12:46 -0600 Subject: Update save.c with recorded battle sector --- src/save.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/save.c') diff --git a/src/save.c b/src/save.c index 0c35c3795..8d77e801a 100644 --- a/src/save.c +++ b/src/save.c @@ -27,7 +27,8 @@ extern bool8 gSoftResetDisabled; * Sectors 0 - 13: Save Slot 1 * Sectors 14 - 27: Save Slot 2 * Sectors 28 - 29: Hall of Fame - * Sectors 30 - 31: e-Reader battle tower data, maybe? (note: deprecated in Emerald US) + * Sector 30: e-Reader/Mystery Gift Stuff (note: e-Reader is deprecated in Emerald US) + * Sector 31: Recorded Battle * * There are two save slots for saving the player's game data. We alternate between * them each time the game is saved, so that if the current save slot is corrupt, -- cgit v1.2.3