2015-02-03 07:52:37 +00:00
|
|
|
/* Copyright (c) 2013-2015 Jeffrey Pfau
|
2014-12-03 08:39:06 +00:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-04-28 02:59:41 +00:00
|
|
|
#ifndef GBA_SAVEDATA_H
|
|
|
|
#define GBA_SAVEDATA_H
|
|
|
|
|
2014-10-12 01:18:47 +00:00
|
|
|
#include "util/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 {
|
2015-01-12 08:59:48 +00:00
|
|
|
SAVEDATA_AUTODETECT = -1,
|
|
|
|
SAVEDATA_FORCE_NONE = 0,
|
2015-03-21 08:12:39 +00:00
|
|
|
SAVEDATA_SRAM = 1,
|
|
|
|
SAVEDATA_FLASH512 = 2,
|
|
|
|
SAVEDATA_FLASH1M = 3,
|
|
|
|
SAVEDATA_EEPROM = 4
|
2013-04-28 02:59:41 +00:00
|
|
|
};
|
|
|
|
|
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,
|
2015-03-21 08:12:39 +00:00
|
|
|
FLASH_STATE_START = 1,
|
|
|
|
FLASH_STATE_CONTINUE = 2,
|
2013-09-24 06:04:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum FlashManufacturer {
|
|
|
|
FLASH_MFG_PANASONIC = 0x1B32,
|
|
|
|
FLASH_MFG_SANYO = 0x1362
|
2013-04-28 04:51:58 +00:00
|
|
|
};
|
|
|
|
|
2015-07-07 07:30:10 +00:00
|
|
|
enum SavedataDirty {
|
|
|
|
SAVEDATA_DIRT_NEW = 1,
|
|
|
|
SAVEDATA_DIRT_SEEN = 2
|
|
|
|
};
|
|
|
|
|
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;
|
2014-08-05 06:46:33 +00:00
|
|
|
|
|
|
|
int mapMode;
|
2014-08-05 05:24:43 +00:00
|
|
|
struct VFile* realVf;
|
2013-04-28 04:51:58 +00:00
|
|
|
|
2015-03-21 08:12:39 +00:00
|
|
|
int32_t readBitsRemaining;
|
|
|
|
uint32_t readAddress;
|
|
|
|
uint32_t writeAddress;
|
2013-09-24 06:04:15 +00:00
|
|
|
|
|
|
|
uint8_t* currentBank;
|
|
|
|
|
2015-03-28 10:25:46 +00:00
|
|
|
bool realisticTiming;
|
|
|
|
unsigned settling;
|
|
|
|
int dust;
|
|
|
|
|
2015-07-07 07:30:10 +00:00
|
|
|
enum SavedataDirty dirty;
|
|
|
|
uint32_t dirtAge;
|
|
|
|
|
2013-09-24 06:04:15 +00:00
|
|
|
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-05 05:24:43 +00:00
|
|
|
|
2014-08-04 08:11:46 +00:00
|
|
|
void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf);
|
2014-08-05 05:24:43 +00:00
|
|
|
void GBASavedataUnmask(struct GBASavedata* savedata);
|
2014-08-05 06:37:37 +00:00
|
|
|
bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out);
|
2015-03-28 10:25:46 +00:00
|
|
|
void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type, bool realisticTiming);
|
2013-04-28 02:59:41 +00:00
|
|
|
|
2015-03-28 10:25:46 +00:00
|
|
|
void GBASavedataInitFlash(struct GBASavedata* savedata, bool realisticTiming);
|
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
|
|
|
|
2015-07-07 07:30:10 +00:00
|
|
|
void GBASavedataClean(struct GBASavedata* savedata, uint32_t frameCount);
|
|
|
|
|
2015-03-21 08:12:39 +00:00
|
|
|
struct GBASerializedState;
|
|
|
|
void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializedState* state, bool includeData);
|
|
|
|
void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerializedState* state, bool includeData);
|
|
|
|
|
2013-04-28 02:59:41 +00:00
|
|
|
#endif
|