From 7b94929a881c1e18e2d0a34ca65618027e18c239 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Fri, 13 Apr 2018 16:41:20 +0100 Subject: [PATCH] - Move saves to user defined RetroArch save directory - Change save names to: .srm [cartridge EEPROM] .cdrom.srm [JagCD EEPROM] --- libretro.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- src/eeprom.c | 15 +++++++++++++-- src/settings.h | 2 ++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/libretro.c b/libretro.c index 05229f0..2d4f640 100644 --- a/libretro.c +++ b/libretro.c @@ -231,6 +231,25 @@ static void update_input(void) } +static void extract_basename(char *buf, const char *path, size_t size) +{ + const char *base = strrchr(path, '/'); + if (!base) + base = strrchr(path, '\\'); + if (!base) + base = path; + + if (*base == '\\' || *base == '/') + base++; + + strncpy(buf, base, size - 1); + buf[size - 1] = '\0'; + + char *ext = strrchr(buf, '.'); + if (ext) + *ext = '\0'; +} + /************************************ * libretro implementation ************************************/ @@ -361,7 +380,34 @@ bool retro_load_game(const struct retro_game_info *info) check_variables(); - //strcpy(vjs.EEPROMPath, "/path/to/eeproms/"); // battery saves + // Get eeprom path info + // > Handle Windows nonsense... + char slash; +#if defined(_WIN32) + slash = '\\'; +#else + slash = '/'; +#endif + // > Get save path + vjs.EEPROMPath[0] = '\0'; + const char *save_dir = NULL; + if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_dir) && save_dir) + { + if (strlen(save_dir) > 0) + { + sprintf(vjs.EEPROMPath, "%s%c", save_dir, slash); + } + } + // > Get ROM name + if (info->path != NULL) + { + extract_basename(vjs.romName, info->path, sizeof(vjs.romName)); + } + else + { + vjs.romName[0] = '\0'; + } + JaguarInit(); // set up hardware memcpy(jagMemSpace + 0xE00000, (vjs.biosType == BT_K_SERIES ? jaguarBootROM : jaguarBootROM2), diff --git a/src/eeprom.c b/src/eeprom.c index 3542546..dfd5187 100644 --- a/src/eeprom.c +++ b/src/eeprom.c @@ -68,10 +68,21 @@ void EepromInit(void) WriteLog("EEPROM: Memory Track device detected...\n"); return; } + + /* Get EEPROM file names */ + if (strlen(vjs.romName) > 0) + { + sprintf(eeprom_filename, "%s%s.srm", vjs.EEPROMPath, vjs.romName); + sprintf(cdromEEPROMFilename, "%s%s.cdrom.srm", vjs.EEPROMPath, vjs.romName); + } + else + { + // Use old CRC fallback... + sprintf(eeprom_filename, "%s%08X.srm", vjs.EEPROMPath, (unsigned int)jaguarMainROMCRC32); + sprintf(cdromEEPROMFilename, "%s%08X.cdrom.srm", vjs.EEPROMPath, (unsigned int)jaguarMainROMCRC32); + } /* Handle regular cartridge EEPROM */ - sprintf(eeprom_filename, "%s%08X.eeprom", vjs.EEPROMPath, (unsigned int)jaguarMainROMCRC32); - sprintf(cdromEEPROMFilename, "%scdrom.eeprom", vjs.EEPROMPath); fp = fopen(eeprom_filename, "rb"); if (fp) diff --git a/src/settings.h b/src/settings.h index 81e5a5a..426f58b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -37,6 +37,8 @@ struct VJSettings char CDBootPath[MAX_PATH]; char EEPROMPath[MAX_PATH]; char alpineROMPath[MAX_PATH]; + + char romName[MAX_PATH]; }; // BIOS types