all repos — mgba @ 7bb5e29a984c2d509b072eafddc78ec712426c5a

mGBA Game Boy Advance Emulator

src/gba/gba-savedata.h (view raw)

 1#ifndef GBA_SAVEDATA_H
 2#define GBA_SAVEDATA_H
 3
 4#include "common.h"
 5
 6struct VFile;
 7
 8enum SavedataType {
 9	SAVEDATA_NONE = 0,
10	SAVEDATA_SRAM,
11	SAVEDATA_FLASH512,
12	SAVEDATA_FLASH1M,
13	SAVEDATA_EEPROM
14};
15
16enum SavedataCommand {
17	EEPROM_COMMAND_NULL = 0,
18	EEPROM_COMMAND_PENDING = 1,
19	EEPROM_COMMAND_WRITE = 2,
20	EEPROM_COMMAND_READ_PENDING = 3,
21	EEPROM_COMMAND_READ = 4,
22
23	FLASH_COMMAND_START = 0xAA,
24	FLASH_COMMAND_CONTINUE = 0x55,
25
26	FLASH_COMMAND_ERASE_CHIP = 0x10,
27	FLASH_COMMAND_ERASE_SECTOR = 0x30,
28
29	FLASH_COMMAND_NONE = 0,
30	FLASH_COMMAND_ERASE = 0x80,
31	FLASH_COMMAND_ID = 0x90,
32	FLASH_COMMAND_PROGRAM = 0xA0,
33	FLASH_COMMAND_SWITCH_BANK = 0xB0,
34	FLASH_COMMAND_TERMINATE = 0xF0
35};
36
37enum FlashStateMachine {
38	FLASH_STATE_RAW = 0,
39	FLASH_STATE_START,
40	FLASH_STATE_CONTINUE
41};
42
43enum FlashManufacturer {
44	FLASH_MFG_PANASONIC = 0x1B32,
45	FLASH_MFG_SANYO = 0x1362
46};
47
48enum {
49	SAVEDATA_FLASH_BASE = 0x0E005555,
50
51	FLASH_BASE_HI = 0x5555,
52	FLASH_BASE_LO = 0x2AAA
53};
54
55struct GBASavedata {
56	enum SavedataType type;
57	uint8_t* data;
58	const char* filename;
59	enum SavedataCommand command;
60	struct VFile* vf;
61
62	int readBitsRemaining;
63	int readAddress;
64	int writeAddress;
65	int writePending;
66	int addressBits;
67
68	uint8_t* currentBank;
69
70	enum FlashStateMachine flashState;
71};
72
73void GBASavedataInit(struct GBASavedata* savedata, const char* filename);
74void GBASavedataDeinit(struct GBASavedata* savedata);
75
76void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type);
77
78void GBASavedataInitFlash(struct GBASavedata* savedata);
79void GBASavedataInitEEPROM(struct GBASavedata* savedata);
80void GBASavedataInitSRAM(struct GBASavedata* savedata);
81
82uint8_t GBASavedataReadFlash(struct GBASavedata* savedata, uint16_t address);
83void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8_t value);
84
85uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata);
86void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize);
87
88#endif