Skip to content

Commit

Permalink
allow sram size mismatch (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Jun 10, 2021
1 parent 993503d commit cdfb97c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/States.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,17 +495,23 @@ void States::loadSRAM(libretro::Core* core)
void* data = util::loadFile(_logger, sramPath, &fileSize);
if (data != NULL)
{
void* memory = core->getMemoryData(RETRO_MEMORY_SAVE_RAM);
if (fileSize == sramSize)
{
void* memory = core->getMemoryData(RETRO_MEMORY_SAVE_RAM);
memcpy(memory, data, sramSize);
_logger->info(TAG "Loaded %lu bytes of Save RAM from disk", fileSize);
}
else if (fileSize <= sramSize)
{
_logger->warn(TAG "Loaded %lu bytes of Save RAM from disk, wanted %lu", fileSize, sramSize);
}
else
{
_logger->error(TAG "Save RAM size mismatch, wanted %lu, got %lu from disk", sramSize, fileSize);
_logger->warn(TAG "Loaded %lu bytes of Save RAM from disk, truncated from %lu", sramSize, fileSize);
fileSize = sramSize;
}

memcpy(memory, data, fileSize);

if (_saveInterval > 0)
_lastSaveData = data;
else
Expand Down

0 comments on commit cdfb97c

Please sign in to comment.