Commit daf50fcd authored by retro-wertz's avatar retro-wertz Committed by Rafael Kitover
Browse files

Libretro: Remove workaround for save file handling

For the most part, save types should now be identified during rom loading and then allow libretro to correctly use flash or eeprom save types and save size.
parent c1f281b7
...@@ -11,13 +11,7 @@ int eepromByte = 0; ...@@ -11,13 +11,7 @@ int eepromByte = 0;
int eepromBits = 0; int eepromBits = 0;
int eepromAddress = 0; int eepromAddress = 0;
#ifdef __LIBRETRO__
// Workaround for broken-by-design GBA save semantics
extern uint8_t libretro_save_buf[0x20000 + 0x2000];
uint8_t* eepromData = libretro_save_buf + 0x20000;
#else
uint8_t eepromData[0x2000]; uint8_t eepromData[0x2000];
#endif
uint8_t eepromBuffer[16]; uint8_t eepromBuffer[16];
bool eepromInUse = false; bool eepromInUse = false;
...@@ -36,11 +30,7 @@ variable_desc eepromSaveData[] = { ...@@ -36,11 +30,7 @@ variable_desc eepromSaveData[] = {
void eepromInit() void eepromInit()
{ {
#ifdef __LIBRETRO__
memset(eepromData, 255, 0x2000);
#else
memset(eepromData, 255, sizeof(eepromData)); memset(eepromData, 255, sizeof(eepromData));
#endif
} }
void eepromReset() void eepromReset()
...@@ -122,10 +112,9 @@ int eepromRead(uint32_t /* address */) ...@@ -122,10 +112,9 @@ int eepromRead(uint32_t /* address */)
return 0; return 0;
} }
case EEPROM_READDATA2: { case EEPROM_READDATA2: {
int data = 0;
int address = eepromAddress << 3; int address = eepromAddress << 3;
int mask = 1 << (7 - (eepromBits & 7)); int mask = 1 << (7 - (eepromBits & 7));
data = (eepromData[address + eepromByte] & mask) ? 1 : 0; int data = (eepromData[address + eepromByte] & mask) ? 1 : 0;
eepromBits++; eepromBits++;
if ((eepromBits & 7) == 0) if ((eepromBits & 7) == 0)
eepromByte++; eepromByte++;
......
...@@ -6,13 +6,12 @@ ...@@ -6,13 +6,12 @@
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
extern void eepromSaveGame(uint8_t*& data); extern void eepromSaveGame(uint8_t*& data);
extern void eepromReadGame(const uint8_t*& data, int version); extern void eepromReadGame(const uint8_t*& data, int version);
extern uint8_t* eepromData;
#else // !__LIBRETRO__ #else // !__LIBRETRO__
extern void eepromSaveGame(gzFile _gzFile); extern void eepromSaveGame(gzFile _gzFile);
extern void eepromReadGame(gzFile _gzFile, int version); extern void eepromReadGame(gzFile _gzFile, int version);
extern void eepromReadGameSkip(gzFile _gzFile, int version); extern void eepromReadGameSkip(gzFile _gzFile, int version);
extern uint8_t eepromData[0x2000];
#endif #endif
extern uint8_t eepromData[0x2000];
extern int eepromRead(uint32_t address); extern int eepromRead(uint32_t address);
extern void eepromWrite(uint32_t address, uint8_t value); extern void eepromWrite(uint32_t address, uint8_t value);
extern void eepromInit(); extern void eepromInit();
......
...@@ -18,12 +18,7 @@ ...@@ -18,12 +18,7 @@
#define FLASH_PROGRAM 8 #define FLASH_PROGRAM 8
#define FLASH_SETBANK 9 #define FLASH_SETBANK 9
#ifdef __LIBRETRO__
extern uint8_t libretro_save_buf[0x20000 + 0x2000];
uint8_t* flashSaveMemory = libretro_save_buf;
#else
uint8_t flashSaveMemory[FLASH_128K_SZ]; uint8_t flashSaveMemory[FLASH_128K_SZ];
#endif
int flashState = FLASH_READ_ARRAY; int flashState = FLASH_READ_ARRAY;
int flashReadState = FLASH_READ_ARRAY; int flashReadState = FLASH_READ_ARRAY;
...@@ -58,11 +53,7 @@ static variable_desc flashSaveData3[] = { ...@@ -58,11 +53,7 @@ static variable_desc flashSaveData3[] = {
void flashInit() void flashInit()
{ {
#ifdef __LIBRETRO__
memset(flashSaveMemory, 0xff, 0x20000);
#else
memset(flashSaveMemory, 0xff, sizeof(flashSaveMemory)); memset(flashSaveMemory, 0xff, sizeof(flashSaveMemory));
#endif
} }
void flashReset() void flashReset()
......
...@@ -8,13 +8,12 @@ ...@@ -8,13 +8,12 @@
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
extern void flashSaveGame(uint8_t*& data); extern void flashSaveGame(uint8_t*& data);
extern void flashReadGame(const uint8_t*& data, int); extern void flashReadGame(const uint8_t*& data, int);
extern uint8_t* flashSaveMemory;
#else #else
extern void flashSaveGame(gzFile _gzFile); extern void flashSaveGame(gzFile _gzFile);
extern void flashReadGame(gzFile _gzFile, int version); extern void flashReadGame(gzFile _gzFile, int version);
extern void flashReadGameSkip(gzFile _gzFile, int version); extern void flashReadGameSkip(gzFile _gzFile, int version);
extern uint8_t flashSaveMemory[FLASH_128K_SZ];
#endif #endif
extern uint8_t flashSaveMemory[FLASH_128K_SZ];
extern uint8_t flashRead(uint32_t address); extern uint8_t flashRead(uint32_t address);
extern void flashWrite(uint32_t address, uint8_t byte); extern void flashWrite(uint32_t address, uint8_t byte);
extern void flashDelayedWrite(uint32_t address, uint8_t byte); extern void flashDelayedWrite(uint32_t address, uint8_t byte);
......
...@@ -186,7 +186,7 @@ void utilGBAFindSave(const int size) ...@@ -186,7 +186,7 @@ void utilGBAFindSave(const int size)
{ {
bool rtcFound_ = false; bool rtcFound_ = false;
int detectedSaveType = 0; int detectedSaveType = 0;
int flashSize_ = 0x8000; int flashSize_ = 0x10000;
uint32_t *p = (uint32_t *)&rom[0]; uint32_t *p = (uint32_t *)&rom[0];
uint32_t *end = (uint32_t *)(&rom[0] + size); uint32_t *end = (uint32_t *)(&rom[0] + size);
...@@ -204,6 +204,7 @@ void utilGBAFindSave(const int size) ...@@ -204,6 +204,7 @@ void utilGBAFindSave(const int size)
if (detectedSaveType == 0 || detectedSaveType == 1 if (detectedSaveType == 0 || detectedSaveType == 1
|| detectedSaveType == 4) { || detectedSaveType == 4) {
detectedSaveType = 2; detectedSaveType = 2;
flashSize_ = 0x8000;
} }
} }
} else if (d == 0x53414C46) { } else if (d == 0x53414C46) {
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment