all repos — mgba @ cec9e67d8824dca8cdf3745898596441ff770672

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