Commit 37b5238c authored by Libretro-Admin's avatar Libretro-Admin
Browse files

First stab at implementing persistent data buffer -

Unfortunately, a lot remains:
- SA1, SuperFX and BSX all seem to be modifying Memory.ROM at runtime.
We would have to first undo this before we can rely on the persistent
data buffer codepath to work correctly for games of this type.
parent 84f656b7
Pipeline #29669 passed with stages
in 6 minutes and 19 seconds
This diff is collapsed.
......@@ -609,6 +609,14 @@ void retro_set_input_state(retro_input_state_t cb) { input_cb = cb; }
void retro_set_environment(retro_environment_t cb)
{
static const struct retro_system_content_info_override content_overrides[] = {
{
"smc|fig|sfc|gd3|gd7|dx2|bsx|swc", /* extensions */
false, /* need_fullpath */
true /* persistent_data */
},
{ NULL, false, false }
};
static const struct retro_controller_description port_1[] = {
{ "SNES Joypad", RETRO_DEVICE_JOYPAD },
{ "SNES Mouse", RETRO_DEVICE_MOUSE },
......@@ -635,6 +643,9 @@ void retro_set_environment(retro_environment_t cb)
libretro_set_core_options(environ_cb);
environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
/* Request a persistent content data buffer */
environ_cb(RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE,
(void*)content_overrides);
}
void retro_get_system_info(struct retro_system_info *info)
......@@ -1411,7 +1422,9 @@ static void init_descriptors(void)
bool retro_load_game(const struct retro_game_info *game)
{
int loaded;
bool persistent_data = false;
struct retro_memory_map map;
const struct retro_game_info_ext *info_ext = NULL;
init_descriptors();
memorydesc_c = 0;
......@@ -1422,7 +1435,11 @@ bool retro_load_game(const struct retro_game_info *game)
/* Hack. S9x cannot do stuff from RAM. <_< */
memstream_set_buffer((uint8_t*)game->data, (uint64_t)game->size);
loaded = LoadROM();
if (environ_cb(RETRO_ENVIRONMENT_GET_GAME_INFO_EXT, &info_ext) &&
info_ext->persistent_data)
persistent_data = true;
loaded = LoadROM(persistent_data, (uint8_t*)game->data, game->size);
if (!loaded)
{
const char *const err_msg = "ROM loading failed.";
......
......@@ -566,11 +566,16 @@ void Deinit (void)
if (Memory.ROM)
{
Memory.ROM -= 0x8000;
free(Memory.ROM);
if (!Memory.PersistentData)
{
Memory.ROM -= 0x8000;
free(Memory.ROM);
}
Memory.ROM = NULL;
}
Memory.PersistentData = false;
if(Settings.SPC7110 || Settings.SPC7110RTC)
{
S9xFreeSPC7110();
......@@ -742,27 +747,36 @@ static int ScoreLoROM (uint32 calculated_size, uint8 * rom, bool8 skip_header, i
return (score);
}
static uint32 HeaderRemove (uint32 size, int32 * headerCount, uint8 *buf)
static uint32 FileLoader_persistent(uint8 *buffer, int32 maxsize)
{
uint32 calc_size = (size / 0x2000) * 0x2000;
/* <- ROM size without header */
/* ** Memory.HeaderCount */
/* ** Memory.ROMFilename */
uint64_t size = maxsize;
uint32 calc_size = (size / 0x2000) * 0x2000;
Memory.HeaderCount = 0;
if (size - calc_size == 512)
{
memmove(buf, buf + 512, calc_size);
(*headerCount)++;
size -= 512;
Memory.ROM = buffer + 512;
size = maxsize - 512;
Memory.HeaderCount++;
}
else
Memory.ROM = buffer;
return (size);
return size;
}
static uint32 FileLoader (uint8 *buffer, int32 maxsize)
{
uint32 calc_size;
/* <- ROM size without header */
/* ** Memory.HeaderCount */
/* ** Memory.ROMFilename */
uint8 *ptr;
uint64_t size = 0;
STREAM fp = OPEN_STREAM();
......@@ -770,13 +784,20 @@ static uint32 FileLoader (uint8 *buffer, int32 maxsize)
if (!fp)
return (0);
ptr = buffer;
size = READ_STREAM(ptr, (uint64_t)(
size = READ_STREAM(buffer, (uint64_t)(
maxsize + 0x200), fp);
CLOSE_STREAM(fp);
return HeaderRemove(size, &Memory.HeaderCount, ptr);
calc_size = (size / 0x2000) * 0x2000;
if (size - calc_size == 512)
{
memmove(buffer, buffer + 512, calc_size);
Memory.HeaderCount++;
size -= 512;
}
return size;
}
static uint32 caCRC32 (uint8 *array, uint32 size, uint32 crc32)
......@@ -789,14 +810,13 @@ static uint32 caCRC32 (uint8 *array, uint32 size, uint32 crc32)
return (~crc32);
}
bool8 LoadROM (void)
bool8 LoadROM (bool8 persistent_data, uint8_t *rom_data, size_t rom_size)
{
int hi_score, lo_score, retry_count;
int hi_score, lo_score;
bool8 interleaved, tales;
uint8 * RomHeader;
int32 totalFileSize;
retry_count = 0;
int retry_count = 0;
memset(Memory.ROM, 0, MAX_ROM_SIZE);
memset(&Multi, 0, sizeof(Multi));
......@@ -805,7 +825,17 @@ again:
Memory.CalculatedSize = 0;
Memory.ExtendedFormat = NOPE;
totalFileSize = FileLoader(Memory.ROM, MAX_ROM_SIZE);
if (persistent_data)
{
Memory.PersistentData = true;
totalFileSize = FileLoader_persistent(rom_data, rom_size);
}
else
{
totalFileSize = FileLoader(Memory.ROM, MAX_ROM_SIZE);
Memory.PersistentData = false;
}
if (!totalFileSize)
{
S9xMessage(S9X_MSG_ERROR, S9X_CATEGORY_ROM,
......@@ -854,10 +884,8 @@ again:
if (Memory.ExtendedFormat != NOPE)
{
int swappedhirom, swappedlorom;
swappedhirom = ScoreHiROM(Memory.CalculatedSize, Memory.ROM, FALSE, 0x400000);
swappedlorom = ScoreLoROM(Memory.CalculatedSize, Memory.ROM, FALSE, 0x400000);
int swappedhirom = ScoreHiROM(Memory.CalculatedSize, Memory.ROM, FALSE, 0x400000);
int swappedlorom = ScoreLoROM(Memory.CalculatedSize, Memory.ROM, FALSE, 0x400000);
/* set swapped here */
if (max(swappedlorom, swappedhirom) >= max(lo_score, hi_score))
......@@ -872,7 +900,7 @@ again:
}
interleaved = FALSE;
tales = FALSE;
tales = FALSE;
interleaved = Settings.ForceInterleaved || Settings.ForceInterleaved2 || Settings.ForceInterleaveGD24;
......
......@@ -266,6 +266,7 @@ typedef struct
uint32 ROMChecksum;
uint32 ROMComplementChecksum;
uint32 ROMCRC32;
bool8 PersistentData;
bool8 HiROM;
bool8 LoROM;
......@@ -279,7 +280,7 @@ typedef struct
bool8 Init (void);
void Deinit (void);
bool8 LoadROM (void);
bool8 LoadROM (bool8 persistent_data, uint8_t *rom_data, size_t rom_size);
bool8 LoadMultiCart (const char *cartA, const char *cartB);
bool8 LoadSufamiTurbo (const char *cartA, const char *cartB);
bool8 LoadSameGame (const char *cartA, const char *cartB);
......
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