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 enum SavedataCommand command;
59 struct VFile* vf;
60
61 int readBitsRemaining;
62 int readAddress;
63 int writeAddress;
64 int writePending;
65 int addressBits;
66
67 uint8_t* currentBank;
68
69 enum FlashStateMachine flashState;
70};
71
72void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf);
73void GBASavedataDeinit(struct GBASavedata* savedata);
74
75void GBASavedataInitFlash(struct GBASavedata* savedata);
76void GBASavedataInitEEPROM(struct GBASavedata* savedata);
77void GBASavedataInitSRAM(struct GBASavedata* savedata);
78
79uint8_t GBASavedataReadFlash(struct GBASavedata* savedata, uint16_t address);
80void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8_t value);
81
82uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata);
83void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize);
84
85#endif