MiSTer-devel / Saturn_MiSTer

Sega Saturn for MiSTer
51 stars 13 forks source link

Changing game corrupts save data #39

Open cathoderaydude opened 8 months ago

cathoderaydude commented 8 months ago

Expected behavior: A separate backup RAM file should be saved for each loaded CUE file. When I switch games, the core should switch backup RAM files to match the loaded disc

Actual behavior: The backup RAM file does not change when switching CUE files, even if I reset. This results in failed saves and data corruption.

Steps to reproduce: I have tested this with several games, I picked two for this example.

  1. Start the core and load Falcom Classics CUE file
  2. Play game briefly, then Save from ingame menu
  3. Save Backup RAM from MiSTer OSD
  4. "Falcom Classics[...].sav" appears in Saves/Saturn folder
  5. Reset or reboot system
  6. Boot Falcom Classics and go to Continue
  7. Saved game is present and works fine
  8. From the MiSTer OSD, change the CUE file to Castlevania - Symphony Of The Night
  9. Save Backup RAM in MiSTer OSD
  10. "Falcom Classics[...].sav" file modify date is updated in Saves/Saturn folder; no Castlevania .sav is created.
  11. Reach and use save point inside Castlevania
  12. Eject CUE file and reset Saturn from OSD
  13. Go to Memory Manager
  14. Files for both Falcom Classics and Castlevania appear
  15. Boot Castlevania again
  16. Castlevania cannot see its saved game

I also reproduced this with Falcom Classics + Duke Nukem 3D, except with the effect that neither game could save effectively. I could save and reload a game as long as the system stayed powered, but upon rebooting the MiSTer, both games became unable to see their saves, even though they both appeared to be present in the BIOS memory manager.

I also found that clearing the contents of backup RAM is impossible. Since no game is loaded when in the BIOS, there is no option to save backup RAM. I tried loading a game to populate the memory, then ejecting the CUE to access the BIOS, clearing memory, and then inserting the CUE again, but it "remembers" the data that was there before. I suspect this is because the following sequence of events is occurring:

  1. Load Falcom CUE
  2. Core loads Falcom.sav
  3. Eject CUE and reset
  4. Falcom data is still in memory, so it's visible in BIOS
  5. Clear memory from BIOS memory manager
  6. Insert Falcom CUE again
  7. Core auto-loads Falcom.sav, restoring the data we just tried to erase.
Kuba-J commented 8 months ago

A game save is created for each game separately when they are in separate folders. CD-based games should always be in separate folders.

cathoderaydude commented 8 months ago

That appears to fix everything, thanks. Would be good if this was in the readme, I had no idea the files needed to be in their own directories.

It's still odd that this sorta works. If it's not supposed to infer the name from the CUE alone then I'd expect it to not work at all without the right folder structure. Instead, it does seem to read the CUE name, but only the very first one that's inserted after the core is loaded, then it sticks with it.

I imagine more people than just me will get confused by this, since it looks like it's working at first. It'd be better if it either used the name of the CUE reliably, or didn't save anything at all if folders aren't present.

Kuba-J commented 8 months ago

it works the same way on the PSX, the games have to be in separate folders. If you only have all the games in one location core does not reset. It reads as if you have one game with multiple disks. Therefore, it is important that a game that has multiple disks is in one folder (e.g. Panzer Dragoon Saga )

cathoderaydude commented 8 months ago

Now I understand why it's like that, I forgot about multi-disc games. Thank you for explaining!

cathoderaydude commented 8 months ago

For what it's worth, the PSX core handles "all cues in one directory" pretty smoothly - it saves the memory card as the name of the enclosing folder, even if there's no subfolder, so you can dump everything straight in /games/PSX/, and it'll all save to PSX.sav. It's not ideal if you want per-game cards, but it works just like a shared memory card in a real machine, and I suspect if the Saturn core used the folder name instead of the file, sharing memory would work here too.

I did some more testing and found that if I loaded up a different set of games (Quake and Sonic Wings Special) from the same folder, even though it uses a single backup RAM file, both games can load their saves just fine, even after a reboot. That's what had me scratching my head before - even though I didn't want the games to share a memory file, it seemed like it ought to have worked anyway. Well, I think it was. The BIOS memory manager was showing the blocks for each of my saved games, so I knew they were being written to memory correctly, they just wouldn't read back.

Well, these games are working, so maybe Falcom Classics Xanadu in particular is the problem. For what it's worth, it does save a really big (321 block) file; maybe that's relevant. Thanks again.