src/gba/gba-savedata.h (view raw)
1#ifndef GBA_SAVEDATA_H
2#define GBA_SAVEDATA_H
3
4#include "util/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 enum SavedataCommand command;
59 struct VFile* vf;
60
61 int mapMode;
62 struct VFile* realVf;
63
64 int readBitsRemaining;
65 int readAddress;
66 int writeAddress;
67 int writePending;
68 int addressBits;
69
70 uint8_t* currentBank;
71
72 enum FlashStateMachine flashState;
73};
74
75void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf);
76void GBASavedataDeinit(struct GBASavedata* savedata);
77
78void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf);
79void GBASavedataUnmask(struct GBASavedata* savedata);
80bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out);
81
82void GBASavedataInitFlash(struct GBASavedata* savedata);
83void GBASavedataInitEEPROM(struct GBASavedata* savedata);
84void GBASavedataInitSRAM(struct GBASavedata* savedata);
85
86uint8_t GBASavedataReadFlash(struct GBASavedata* savedata, uint16_t address);
87void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8_t value);
88
89uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata);
90void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize);
91
92#endif