Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper handling of save files #30

Merged
merged 1 commit into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
************************************/
Expand Down Expand Up @@ -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),
Expand Down
15 changes: 13 additions & 2 deletions src/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct VJSettings
char CDBootPath[MAX_PATH];
char EEPROMPath[MAX_PATH];
char alpineROMPath[MAX_PATH];

char romName[MAX_PATH];
};

// BIOS types
Expand Down