Libretro: Better auto detection of save types when not found in gbaover

This commit is contained in:
retro-wertz 2018-06-22 08:42:10 +08:00 committed by Rafael Kitover
parent 7337341166
commit c1f281b7ba
2 changed files with 80 additions and 58 deletions

View File

@ -182,53 +182,65 @@ uint8_t *utilLoad(const char *file, bool (*accept)(const char *), uint8_t *data,
return image;
}
void utilGBAFindSave(const uint8_t *data, const int size)
void utilGBAFindSave(const int size)
{
uint32_t *p = (uint32_t *)data;
uint32_t *end = (uint32_t *)(data + size);
int saveType = 0;
int flashSize = 0x10000;
bool rtcFound = false;
bool rtcFound_ = false;
int detectedSaveType = 0;
int flashSize_ = 0x8000;
uint32_t *p = (uint32_t *)&rom[0];
uint32_t *end = (uint32_t *)(&rom[0] + size);
while(p < end) {
uint32_t d = READ32LE(p);
while (p < end) {
uint32_t d = READ32LE(p);
if(d == 0x52504545) {
if(memcmp(p, "EEPROM_", 7) == 0) {
if(saveType == 0)
saveType = 3;
}
} else if (d == 0x4D415253) {
if(memcmp(p, "SRAM_", 5) == 0) {
if(saveType == 0)
saveType = 1;
}
} else if (d == 0x53414C46) {
if(memcmp(p, "FLASH1M_", 8) == 0) {
if(saveType == 0) {
saveType = 2;
flashSize = 0x20000;
if (d == 0x52504545) {
if (memcmp(p, "EEPROM_", 7) == 0) {
if (detectedSaveType == 0 || detectedSaveType == 4) {
detectedSaveType = 1;
}
}
} else if (d == 0x4D415253) {
if (memcmp(p, "SRAM_", 5) == 0) {
if (detectedSaveType == 0 || detectedSaveType == 1
|| detectedSaveType == 4) {
detectedSaveType = 2;
}
}
} else if (d == 0x53414C46) {
if (memcmp(p, "FLASH1M_", 8) == 0) {
if (detectedSaveType == 0) {
detectedSaveType = 3;
flashSize_ = 0x20000;
}
} else if (memcmp(p, "FLASH512_", 9) == 0) {
if (detectedSaveType == 0) {
detectedSaveType = 3;
flashSize_ = 0x10000;
}
} else if (memcmp(p, "FLASH", 5) == 0) {
if (detectedSaveType == 0) {
detectedSaveType = 4;
flashSize_ = 0x10000;
}
}
} else if (d == 0x52494953) {
if (memcmp(p, "SIIRTC_V", 8) == 0) {
rtcFound_ = true;
}
}
} else if(memcmp(p, "FLASH", 5) == 0) {
if(saveType == 0) {
saveType = 2;
flashSize = 0x10000;
}
}
} else if (d == 0x52494953) {
if(memcmp(p, "SIIRTC_V", 8) == 0)
rtcFound = true;
p++;
}
// if no matches found, then set it to NONE
if (detectedSaveType == 0) {
detectedSaveType = 5;
}
if (detectedSaveType == 4) {
detectedSaveType = 3;
}
p++;
}
// if no matches found, then set it to NONE
if(saveType == 0) {
saveType = 5;
}
rtcEnable(rtcFound);
cpuSaveType = saveType;
flashSetSize(flashSize);
cpuSaveType = detectedSaveType;
rtcEnabled = rtcFound_;
flashSize = flashSize_;
}
void utilUpdateSystemColorMaps(bool lcd)

View File

@ -43,7 +43,6 @@ static retro_environment_t environ_cb;
static float sndFiltering = 0.5f;
static bool sndInterpolation = true;
static bool enableRtc = false;
static bool can_dupe = false;
int emulating = 0;
static int retropad_layout = 0;
@ -408,15 +407,32 @@ static const ini_t gbaover[256] = {
{"Zoku Bokura no Taiyou - Taiyou Shounen Django (Japan)", "U32J", 0, 0, 1, 0, 0}
};
static int romSize = 0;
static void load_image_preferences(void)
{
const char *savetype[] = {
"AUTO",
"EEPROM",
"SRAM",
"FLASH",
"SENSOR+EEPROM",
"NONE"
};
char buffer[5];
buffer[0] = rom[0xac];
buffer[1] = rom[0xad];
buffer[2] = rom[0xae];
buffer[3] = rom[0xaf];
buffer[4] = 0;
cpuSaveType = 0;
flashSize = 0x8000;
rtcEnabled = false;
mirroringEnable = false;
if (log_cb)
log_cb(RETRO_LOG_INFO, "GameID in ROM is: %s\n", buffer);
@ -435,33 +451,30 @@ static void load_image_preferences(void)
if (log_cb)
log_cb(RETRO_LOG_INFO, "Found ROM in vba-over list.\n");
enableRtc = gbaover[found_no].rtcEnabled;
rtcEnabled = gbaover[found_no].rtcEnabled;
if (gbaover[found_no].flashSize != 0)
flashSize = gbaover[found_no].flashSize;
else
flashSize = 65536;
cpuSaveType = gbaover[found_no].saveType;
mirroringEnable = gbaover[found_no].mirroringEnabled;
}
if (!cpuSaveType/* && !found*/) {
utilGBAFindSave(romSize);
}
if (log_cb) {
log_cb(RETRO_LOG_INFO, "RTC = %d.\n", enableRtc);
log_cb(RETRO_LOG_INFO, "RTC = %d.\n", rtcEnabled);
log_cb(RETRO_LOG_INFO, "flashSize = %d.\n", flashSize);
log_cb(RETRO_LOG_INFO, "cpuSaveType = %d.\n", cpuSaveType);
log_cb(RETRO_LOG_INFO, "cpuSaveType = %s.\n", savetype[cpuSaveType]);
log_cb(RETRO_LOG_INFO, "mirroringEnable = %d.\n", mirroringEnable);
}
}
static void gba_init(void)
{
cpuSaveType = 0;
flashSize = 0x10000;
enableRtc = false;
mirroringEnable = false;
#ifdef FRONTEND_SUPPORTS_RGB565
systemColorDepth = 16;
systemRedShift = 11;
@ -483,9 +496,8 @@ static void gba_init(void)
if (flashSize == 0x10000 || flashSize == 0x20000)
flashSetSize(flashSize);
rtcEnabled = enableRtc;
if (enableRtc)
rtcEnable(enableRtc);
rtcEnable(rtcEnabled);
rtcEnableRumble(!rtcEnabled);
doMirroring(mirroringEnable);
@ -496,8 +508,6 @@ static void gba_init(void)
CPUReset();
soundReset();
uint8_t* state_buf = (uint8_t*)malloc(2000000);
serialize_size = CPUWriteState(state_buf, 2000000);
free(state_buf);
@ -887,7 +897,7 @@ bool retro_load_game(const struct retro_game_info *game)
update_variables();
update_input_descriptors();
int romSize = CPULoadRomData((const char*)game->data, game->size);
romSize = CPULoadRomData((const char*)game->data, game->size);
if (!romSize)
return false;