2013-04-28 02:59:41 +00:00
|
|
|
#ifndef GBA_SAVEDATA_H
|
|
|
|
#define GBA_SAVEDATA_H
|
|
|
|
|
2014-04-03 06:50:20 +00:00
|
|
|
#include "common.h"
|
2013-04-28 02:59:41 +00:00
|
|
|
|
2014-07-16 09:08:54 +00:00
|
|
|
struct VFile;
|
|
|
|
|
2013-04-28 02:59:41 +00:00
|
|
|
enum SavedataType {
|
|
|
|
SAVEDATA_NONE = 0,
|
|
|
|
SAVEDATA_SRAM,
|
|
|
|
SAVEDATA_FLASH512,
|
|
|
|
SAVEDATA_FLASH1M,
|
|
|
|
SAVEDATA_EEPROM
|
|
|
|
};
|
|
|
|
|
2013-04-28 04:51:58 +00:00
|
|
|
enum SavedataCommand {
|
|
|
|
EEPROM_COMMAND_NULL = 0,
|
|
|
|
EEPROM_COMMAND_PENDING = 1,
|
|
|
|
EEPROM_COMMAND_WRITE = 2,
|
|
|
|
EEPROM_COMMAND_READ_PENDING = 3,
|
2013-09-24 06:04:15 +00:00
|
|
|
EEPROM_COMMAND_READ = 4,
|
|
|
|
|
|
|
|
FLASH_COMMAND_START = 0xAA,
|
|
|
|
FLASH_COMMAND_CONTINUE = 0x55,
|
|
|
|
|
|
|
|
FLASH_COMMAND_ERASE_CHIP = 0x10,
|
|
|
|
FLASH_COMMAND_ERASE_SECTOR = 0x30,
|
|
|
|
|
|
|
|
FLASH_COMMAND_NONE = 0,
|
|
|
|
FLASH_COMMAND_ERASE = 0x80,
|
|
|
|
FLASH_COMMAND_ID = 0x90,
|
|
|
|
FLASH_COMMAND_PROGRAM = 0xA0,
|
|
|
|
FLASH_COMMAND_SWITCH_BANK = 0xB0,
|
|
|
|
FLASH_COMMAND_TERMINATE = 0xF0
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FlashStateMachine {
|
|
|
|
FLASH_STATE_RAW = 0,
|
|
|
|
FLASH_STATE_START,
|
|
|
|
FLASH_STATE_CONTINUE
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FlashManufacturer {
|
|
|
|
FLASH_MFG_PANASONIC = 0x1B32,
|
|
|
|
FLASH_MFG_SANYO = 0x1362
|
2013-04-28 04:51:58 +00:00
|
|
|
};
|
|
|
|
|
2013-04-28 02:59:41 +00:00
|
|
|
enum {
|
2013-09-24 06:04:15 +00:00
|
|
|
SAVEDATA_FLASH_BASE = 0x0E005555,
|
|
|
|
|
|
|
|
FLASH_BASE_HI = 0x5555,
|
|
|
|
FLASH_BASE_LO = 0x2AAA
|
2013-04-28 02:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GBASavedata {
|
|
|
|
enum SavedataType type;
|
|
|
|
uint8_t* data;
|
2013-04-28 04:51:58 +00:00
|
|
|
enum SavedataCommand command;
|
2014-07-16 09:08:54 +00:00
|
|
|
struct VFile* vf;
|
2013-04-28 04:51:58 +00:00
|
|
|
|
|
|
|
int readBitsRemaining;
|
|
|
|
int readAddress;
|
|
|
|
int writeAddress;
|
|
|
|
int writePending;
|
|
|
|
int addressBits;
|
2013-09-24 06:04:15 +00:00
|
|
|
|
|
|
|
uint8_t* currentBank;
|
|
|
|
|
|
|
|
enum FlashStateMachine flashState;
|
2013-04-28 02:59:41 +00:00
|
|
|
};
|
|
|
|
|
2014-07-16 09:57:04 +00:00
|
|
|
void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf);
|
2013-04-28 02:59:41 +00:00
|
|
|
void GBASavedataDeinit(struct GBASavedata* savedata);
|
2014-08-04 08:11:46 +00:00
|
|
|
void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf);
|
2013-04-28 02:59:41 +00:00
|
|
|
|
|
|
|
void GBASavedataInitFlash(struct GBASavedata* savedata);
|
2013-04-28 03:25:31 +00:00
|
|
|
void GBASavedataInitEEPROM(struct GBASavedata* savedata);
|
2013-04-28 02:59:41 +00:00
|
|
|
void GBASavedataInitSRAM(struct GBASavedata* savedata);
|
|
|
|
|
2013-09-24 06:04:15 +00:00
|
|
|
uint8_t GBASavedataReadFlash(struct GBASavedata* savedata, uint16_t address);
|
|
|
|
void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8_t value);
|
2013-04-28 02:59:41 +00:00
|
|
|
|
2013-04-28 03:25:31 +00:00
|
|
|
uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata);
|
2013-04-28 04:51:58 +00:00
|
|
|
void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize);
|
2013-04-28 03:25:31 +00:00
|
|
|
|
2013-04-28 02:59:41 +00:00
|
|
|
#endif
|