pokeemerald/include/save.h

115 lines
3.2 KiB
C
Raw Normal View History

2017-09-03 14:13:01 +02:00
#ifndef GUARD_SAVE_H
#define GUARD_SAVE_H
2021-10-29 04:54:41 +02:00
// Each 4 KiB flash sector contains 3968 bytes of actual data followed by a 128 byte footer.
// Only 12 bytes of the footer are used.
2021-02-24 20:53:32 +01:00
#define SECTOR_DATA_SIZE 3968
#define SECTOR_FOOTER_SIZE 128
#define SECTOR_SIZE (SECTOR_DATA_SIZE + SECTOR_FOOTER_SIZE)
#define NUM_SAVE_SLOTS 2
2017-09-03 14:13:01 +02:00
2022-08-05 16:31:50 +02:00
// If the sector's signature field is not this value then the sector is either invalid or empty.
#define SECTOR_SIGNATURE 0x8012025
2021-10-29 04:54:41 +02:00
#define SPECIAL_SECTOR_SENTINEL 0xB39D
#define SECTOR_ID_SAVEBLOCK2 0
#define SECTOR_ID_SAVEBLOCK1_START 1
#define SECTOR_ID_SAVEBLOCK1_END 4
#define SECTOR_ID_PKMN_STORAGE_START 5
#define SECTOR_ID_PKMN_STORAGE_END 13
#define NUM_SECTORS_PER_SLOT 14
// Save Slot 1: 0-13; Save Slot 2: 14-27
#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
#define NUM_HOF_SECTORS 2
#define SAVE_STATUS_EMPTY 0
#define SAVE_STATUS_OK 1
#define SAVE_STATUS_CORRUPT 2
#define SAVE_STATUS_NO_FLASH 4
#define SAVE_STATUS_ERROR 0xFF
// Special sector id value for certain save functions to
// indicate that no specific sector should be used.
#define FULL_SAVE_SLOT 0xFFFF
2017-09-03 14:13:01 +02:00
// SetDamagedSectorBits states
enum
{
ENABLE,
DISABLE,
CHECK // unused
};
// Do save types
enum
{
2018-02-15 23:54:34 +01:00
SAVE_NORMAL,
2021-10-29 04:54:41 +02:00
SAVE_LINK, // Link / Battle Frontier
SAVE_EREADER, // deprecated in Emerald
2018-02-15 23:54:34 +01:00
SAVE_HALL_OF_FAME,
SAVE_OVERWRITE_DIFFERENT_FILE,
SAVE_HALL_OF_FAME_ERASE_BEFORE // unused
2017-09-03 14:13:01 +02:00
};
2021-10-29 04:54:41 +02:00
// A save sector location holds a pointer to the data for a particular sector
// and the size of that data. Size cannot be greater than SECTOR_DATA_SIZE.
struct SaveSectorLocation
{
void *data;
u16 size;
};
2017-11-13 18:07:23 +01:00
2021-10-29 04:54:41 +02:00
struct SaveSector
{
u8 data[SECTOR_DATA_SIZE];
u8 unused[SECTOR_FOOTER_SIZE - 12]; // Unused portion of the footer
u16 id;
u16 checksum;
2022-08-05 16:31:50 +02:00
u32 signature;
2021-10-29 04:54:41 +02:00
u32 counter;
}; // size is SECTOR_SIZE (0x1000)
2022-08-05 16:31:50 +02:00
#define SECTOR_SIGNATURE_OFFSET offsetof(struct SaveSector, signature)
#define SECTOR_COUNTER_OFFSET offsetof(struct SaveSector, counter)
2020-01-12 21:27:37 +01:00
extern u16 gLastWrittenSector;
extern u32 gLastSaveCounter;
extern u16 gLastKnownGoodSector;
extern u32 gDamagedSaveSectors;
extern u32 gSaveCounter;
2021-10-29 04:54:41 +02:00
extern struct SaveSector *gFastSaveSector;
extern u16 gIncrementalSectorId;
extern u16 gSaveFileStatus;
extern void (*gGameContinueCallback)(void);
2021-10-29 04:54:41 +02:00
extern struct SaveSectorLocation gRamSaveSectorLocations[];
2021-10-29 04:54:41 +02:00
extern struct SaveSector gSaveDataBuffer;
2017-09-03 14:13:01 +02:00
void ClearSaveData(void);
2018-02-15 23:54:34 +01:00
void Save_ResetSaveCounters(void);
2017-10-07 00:33:35 +02:00
u8 HandleSavingData(u8 saveType);
2017-11-13 18:07:23 +01:00
u8 TrySavingData(u8 saveType);
2021-10-29 04:54:41 +02:00
bool8 LinkFullSave_Init(void);
bool8 LinkFullSave_WriteSector(void);
bool8 LinkFullSave_ReplaceLastSector(void);
2022-08-05 16:31:50 +02:00
bool8 LinkFullSave_SetLastSectorSignature(void);
2021-10-29 04:54:41 +02:00
bool8 WriteSaveBlock2(void);
bool8 WriteSaveBlock1Sector(void);
u8 LoadGameSave(u8 saveType);
u16 GetSaveBlocksPointersBaseOffset(void);
u32 TryReadSpecialSaveSector(u8 sector, u8 *dst);
u32 TryWriteSpecialSaveSector(u8 sector, u8 *src);
2021-10-29 04:54:41 +02:00
void Task_LinkFullSave(u8 taskId);
2017-09-03 14:13:01 +02:00
2019-03-02 09:18:08 +01:00
// save_failed_screen.c
void DoSaveFailedScreen(u8 saveType);
2017-09-03 15:39:33 +02:00
#endif // GUARD_SAVE_H