Author Topic: SD2SNES mysteriously deleting save files  (Read 504 times)

0 Members and 1 Guest are viewing this topic.

Offline pidgezero_one

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
SD2SNES mysteriously deleting save files
« on: November 02, 2019, 08:49 PM »
This is a really weird problem. The Super Mario RPG randomizer is having an issue where entering one specific room in the game deletes the first save file. It only appears to happen to patched ROMs on SD2SNES (stock firmware and USB2SNES firmware, latest as of today, both old model SD2SNES and SD2SNES Pro models). It does not happen on SD2SNES with the original game, but also does not happen at all on emulators either in the original game or in the patched randomizer.

It is not specific to one certain seed or flagset in the randomizer, it is universal for SD2SNES users and has been reported by several players (while several emulator players have confirmed they are not having this issue).

We're sure this must be something that the randomizer patch is doing, but the randomizer is fairly simple in concept and we're stumped as to what could be causing it. It only seems to be one specific room (the Megasmilax room), and none of the in-game scripts running in this room are doing anything we can determine to be malignant (all of the commands used are also used in other rooms in the randomizer, there's no strange calls to memory that we can see, etc).

We're of course not going to ask anyone to debug the randomizer code, but rather are looking for some direction on what could be causing the SD2SNES to behave in this manner so that we can work around it somehow.

Full description of the problem:

https://youtu.be/hLMbKXhAPmU - upon entering the room with a single pipe, the save file is deleted. Another developer tested the sram by resetting as soon as he entered that room, and the save file had indeed been deleted (just so we're sure it isn't caused by re-entering the save box room).

This is the in-game script that runs upon entering the single pipe room:

There are no events that run upon going between the two rooms except this one.
(The 4 NPCs in the room's background scripts are all empty.)



Here is an IPS patch that will patch the US version of the game into a version of the randomizer that includes the problem:
https://drive.google.com/open?id=13u4XYtX_kVAXgpNpPtVl-DlCfUL428BI

Here is a SRAM that will work with the above IPS patch, that has a save file (this is directly outside the problem room):
https://drive.google.com/open?id=1BahEEus5zV7QZdR7p2b49anmjAEpJnPN

Here is the same SRAM, after entering that room:
https://drive.google.com/open?id=1wBO4SJ3ctVIsr9l7Vi6j0FCYMLkFrRzE

(this save ram was pulled from SD2SNES, not SD2SNES Pro, firmware 1.10.3)

I'm not going to pretend I know how a SRAM file should look before or after performing a single action, but if I compare the two versions of the save file in a hex editor, the results are pretty vastly different.
« Last Edit: November 02, 2019, 08:51 PM by pidgezero_one »

Offline DorkmasterFlek

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: SD2SNES mysteriously deleting save files
« Reply #1 on: November 02, 2019, 10:24 PM »
A fellow developer on this rando has mentioned that the SD2SNES firmware is using a CRC checksum to detect certain SA-1 games including SMRPG and actually change the SRAM saving functionality.  This is way over my head, but the CRC checksum would definitely be different every time with a randomizer.  Would this cause potential problems with the SRAM saving that might trigger something like this?

Offline redguy

  • Jr. Member
  • **
  • Posts: 55
  • Karma: +149/-0
    • View Profile
Re: SD2SNES mysteriously deleting save files
« Reply #2 on: November 06, 2019, 12:44 AM »
The problem is a MVN executed on the SA1 at instruction address $C0AAE1.  The destinations starts at $408000 which wraps the 32KB SA1 work RAM and overwrites the save slots that happen to be at the beginning.  It has something to do with the different state stored at $4F0-$4FF in SA1 work RAM as compared to the vanilla ROM.  That's probably a result of the ROM changes in the randomizer.  Maybe check that the boss or boss sprites change the randomizer makes on that screen are compatible.  I know next to nothing about SMRPG so that's all I can help with.

Both bsnes-plus and mesen-s also have the same failure.  Put a breakpoint on a write to $408000 "SA-1 Bus" in bsnes-plus to find it on the screen transition.

The match of the ROM CRC in firmware does not affect the running game's use of work RAM.

EDIT: Looks like newer versions of bsnes-plus implement the cart work RAM write protection feature which hides the bug.  That's probably why most emulators don't overwrite the save RAM region at the beginning of work RAM.  It's possible some of them may also NOP memory overflows rather than masking the address and having it wrap.
« Last Edit: November 06, 2019, 01:15 PM by redguy »

Offline DorkmasterFlek

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: SD2SNES mysteriously deleting save files
« Reply #3 on: November 06, 2019, 10:14 PM »
Yeah I suspected the CRC wouldn't affect it, but I didn't know for sure.  That is a really interesting detail about the emulators, that would explain why we've only seen this behaviour so far on the SD2SNES and the SNES Classic.  Thank you for that info, and for all your hard work on the SA-1 and Super FX support in the first place redguy!
« Last Edit: November 08, 2019, 04:02 PM by DorkmasterFlek »

Offline pidgezero_one

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: SD2SNES mysteriously deleting save files
« Reply #4 on: November 09, 2019, 04:49 AM »
Thanks Redguy, your mentioning of the sprites pointed us in the right direction. I found a bit in an NPC property in that room that wasn't being changed where it should have been, and now we seem to no longer be deleting save files.