all repos — mgba @ 2f2e5398719f9d6a78ae84fc241945b46839b01c

mGBA Game Boy Advance Emulator

src/gba/savedata.h (view raw)

  1/* Copyright (c) 2013-2015 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef GBA_SAVEDATA_H
  7#define GBA_SAVEDATA_H
  8
  9#include "util/common.h"
 10
 11struct VFile;
 12
 13enum SavedataType {
 14	SAVEDATA_AUTODETECT = -1,
 15	SAVEDATA_FORCE_NONE = 0,
 16	SAVEDATA_SRAM = 1,
 17	SAVEDATA_FLASH512 = 2,
 18	SAVEDATA_FLASH1M = 3,
 19	SAVEDATA_EEPROM = 4
 20};
 21
 22enum SavedataCommand {
 23	EEPROM_COMMAND_NULL = 0,
 24	EEPROM_COMMAND_PENDING = 1,
 25	EEPROM_COMMAND_WRITE = 2,
 26	EEPROM_COMMAND_READ_PENDING = 3,
 27	EEPROM_COMMAND_READ = 4,
 28
 29	FLASH_COMMAND_START = 0xAA,
 30	FLASH_COMMAND_CONTINUE = 0x55,
 31
 32	FLASH_COMMAND_ERASE_CHIP = 0x10,
 33	FLASH_COMMAND_ERASE_SECTOR = 0x30,
 34
 35	FLASH_COMMAND_NONE = 0,
 36	FLASH_COMMAND_ERASE = 0x80,
 37	FLASH_COMMAND_ID = 0x90,
 38	FLASH_COMMAND_PROGRAM = 0xA0,
 39	FLASH_COMMAND_SWITCH_BANK = 0xB0,
 40	FLASH_COMMAND_TERMINATE = 0xF0
 41};
 42
 43enum FlashStateMachine {
 44	FLASH_STATE_RAW = 0,
 45	FLASH_STATE_START = 1,
 46	FLASH_STATE_CONTINUE = 2,
 47};
 48
 49enum FlashManufacturer {
 50	FLASH_MFG_PANASONIC = 0x1B32,
 51	FLASH_MFG_SANYO = 0x1362
 52};
 53
 54enum {
 55	SAVEDATA_FLASH_BASE = 0x0E005555,
 56
 57	FLASH_BASE_HI = 0x5555,
 58	FLASH_BASE_LO = 0x2AAA
 59};
 60
 61struct GBASavedata {
 62	enum SavedataType type;
 63	uint8_t* data;
 64	enum SavedataCommand command;
 65	struct VFile* vf;
 66
 67	int mapMode;
 68	struct VFile* realVf;
 69
 70	int32_t readBitsRemaining;
 71	uint32_t readAddress;
 72	uint32_t writeAddress;
 73
 74	uint8_t* currentBank;
 75
 76	bool realisticTiming;
 77	unsigned settling;
 78	int dust;
 79
 80	enum FlashStateMachine flashState;
 81};
 82
 83void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf);
 84void GBASavedataDeinit(struct GBASavedata* savedata);
 85
 86void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf);
 87void GBASavedataUnmask(struct GBASavedata* savedata);
 88bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out);
 89void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type, bool realisticTiming);
 90
 91void GBASavedataInitFlash(struct GBASavedata* savedata, bool realisticTiming);
 92void GBASavedataInitEEPROM(struct GBASavedata* savedata);
 93void GBASavedataInitSRAM(struct GBASavedata* savedata);
 94
 95uint8_t GBASavedataReadFlash(struct GBASavedata* savedata, uint16_t address);
 96void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8_t value);
 97
 98uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata);
 99void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize);
100
101struct GBASerializedState;
102void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializedState* state, bool includeData);
103void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerializedState* state, bool includeData);
104
105#endif