Convert Retron5 save files to and from files that can be used by the RetroPie and other emulators
I have a bunch of cartridges from retro videogame systems like the NES, SNES, Gameboy, etc. and I was worried about losing my old save files as the 30 year old batteries powering the cartridges slowly die.
I got a Retron5 because it seemed like the least expensive machine that can read a large number of different cartridge types, and one of its little-known features is that it can copy save game data from a cartridge to an SD card and back again.
But the data is in a proprietary format, so I'm tied to the Retron5 and if it dies then I'm back to square one.
This script will convert this proprietary format into the more common format used by other emulators such as those included with the RetroPie, and also back again to load emulator saves onto a real cartridge.
So I can back up my save files, and also swap out those dying batteries and put my save files back onto the cartridges to last another 30 years: https://www.youtube.com/watch?v=k7Xb6ucFcfU
This script requires Python 3, which you can find here: https://www.python.org/downloads/
If you're using a Mac, you may want to install it via homebrew: https://docs.python-guide.org/starting/install3/osx/
Someone else wrote a similar program for Windows a few years ago: https://www.retro5.net/viewtopic.php?f=5&t=257 but I have a Mac. Apparently it can run under Wine, but I wanted to write something I could run natively.
Convert Retron5 save to emulator:
./retron5.py -i retron-saves-in/The\ Legend\ of\ Zelda\ -\ Oracle\ of\ Seasons\ \(U\)\ \[C\]\[\!\].sav -o emulator-saves-out/ -d
Convert emulator save to Retron5:
./retron5.py -i emulator-saves-in/The\ Legend\ of\ Zelda\ -\ Oracle\ of\ Seasons\ \(U\)\ \[C\]\[\!\].srm -o retron-saves-out/ -t -d
Start by creating a save on your cartridge
Put the cartridge and an SD card into your Retron5
Select "SD Card" for the save data location
Copy the cartridge save data to the SD card
Copy the save file from the SD card onto your computer, and run
./retron5.py -i retron-saves-in/The\ Legend\ of\ Zelda\ -\ Oracle\ of\ Seasons\ \(U\)\ \[C\]\[\!\].sav -o emulator-saves-out/ -d
Copy the outputted file onto your RetroPie (or however you're running your emulator), in the same directory as your ROM file and with the same name (but the .srm
extension)
Load up the ROM on your RetroPie (other other emulator) and you'll see the same save data!
Now we can update our save on the RetroPie (or other emulator)
Then copy it from the RetroPie (or other emulator) over to our computer
Then run
./retron5.py -i emulator-saves-in/The\ Legend\ of\ Zelda\ -\ Oracle\ of\ Seasons\ \(U\)\ \[C\]\[\!\].srm -o retron-saves-out/ -t -d
We can then copy the outputted file to our SD card and put the SD card and cartridge into the Retron5. We need to make sure the file has the name the Retron5 expects for this game, and with the .sav
extension. You can check which name the Retron5 expects by writing out the save data from the cartridge using the steps above.
On the Retron5 we select to copy the save data to the cartridge
And now our updated save game is available on the original cartridge!
The Retron5 save format is described here: https://www.retro5.net/viewtopic.php?f=5&t=67&start=10
And specifically the file format is:
typedef struct
{
uint32_t magic;
uint16_t fmtVer;
uint16_t flags;
uint32_t origSize;
uint32_t packedSize;
uint32_t dataOffset;
uint32_t crc32;
uint8_t data[0];
} t_retronDataHdr;
It's a header and then a bunch of compressed data, so to unpack the file we need to read past the header and then uncompress the data. There's a few values in the header, like the original size and CRC32 (checksum) of the original data, that we can use to make sure that nothing has been corrupted.