Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Pigarus SRAM glitch

Reply to topic
Author Message
  • Joined: 01 Feb 2014
  • Posts: 406
Reply with quote
Pigarus SRAM glitch
Post Posted: Fri Dec 07, 2018 4:53 pm
On some screenshots in the competition thread law81 runs over at the elotrolado forum, I noticed a glitchy results screen for 5 minutes mode. I never experienced this in Emulicious or on my SMS 1 + Everdrive combo, where it all works flawlessly. I did notice the same behaviour when using the emulator TwoMBit, though.

Since the glitch only seems to appear in 5 minutes mode, it is my theory that the emulator (or the flashcart used) only supports 8KB of SMS SRAM (only as much as is needed to play commercial software from back in the day). IMO, that means that the recording, once it passes into the second 8KB of the SRAM bank, is mirrored into the first part and overwrites the highscores.

Does anyone know more about SRAM behaviour and can confirm this theory?

More importantly, is there anything I can do differently in the code to avoid the glitch? If not, I'm considering adding an option to deactivate the recordings, so people with incompatible setups can at least use the highscore save feature.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12483
  • Location: London
Reply with quote
Post Posted: Fri Dec 07, 2018 5:37 pm
Last edited by Maxim on Sat Dec 08, 2018 10:16 am; edited 1 time in total
You can detect the SRAM size by writing to known addresses and then reading back at mirrored addresses.

It's common to write a marker at the start of SRAM, assuming it's set to random values if you don't find it. You then blank it all and write your marker at 0. You can then read back from 8KB and see if your marker is there; repeat at other likely addresses (e.g. 4KB). And of course check if it's at 0, to decide if SRAM exists at all.

If you can write the replay data with RLE then it's very likely you will fit it in 8KB, unless the player manages to change the pressed buttons on average more than 8 times per second for the whole 5 minutes.
  View user's profile Send private message Visit poster's website
  • Joined: 01 Feb 2014
  • Posts: 406
Reply with quote
Post Posted: Fri Dec 07, 2018 6:38 pm
Maxim wrote
It's common to write a marker at the start of SRAM, assuming it's set to random values of you don't find it. You then blank it all and write your marker at 0. You can then read back from 8KB and see if your marker is there; repeat at other likely addresses (e.g. 4KB). And of course check if it's at 0, to decide if SRAM exists at all.


I actually already have a marker in place at 0, to check if I have initialized the sram. I wipe it and reset highscores to defaults if it‘s not found. I‘ll try what you suggest and hope I can fix the glitch that way.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2298
Reply with quote
Post Posted: Sat Dec 08, 2018 7:25 pm
isn't there an option to set SRAM size on the emulator?
The point is that it might be wrongly emulating a game cart with only 8 KB in there so, to emulate that correctly, it will ignore the highest address' bit (and it would then wrap)
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12483
  • Location: London
Reply with quote
Post Posted: Sun Dec 09, 2018 8:36 am
Since we don't have feature headers on SMS ROMs, there's no indication of the correct SRAM size. No games take advantage of this to detect when they have the "wrong" size available, so emulators can just give games as much as possible, or try to detect what is used, but assuming 8KB is definitely wrong.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2298
Reply with quote
Post Posted: Sun Dec 09, 2018 10:54 am
yeah - my point is: you don't need to update your game if there's a problem in an emulator - eventually it's the emulator author that has to update his program!
  View user's profile Send private message Visit poster's website
  • Joined: 01 Feb 2014
  • Posts: 406
Reply with quote
Post Posted: Sun Dec 09, 2018 12:06 pm
I'm not really concerned about emulator users. So far, the glitch has only shown in a single, fairly obscure one. Additionally, there are plenty of alternatives for the users.

What bothers me is that the glitch seems to appear on some flashcarts too. Personally, I have never seen it (using the Master Everdrive), but some screenshots and videos found online suggest it happens occasionally. Altering the code so replays are deactivated if not enough sram is present seems like a possible solution.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12483
  • Location: London
Reply with quote
Post Posted: Sun Dec 09, 2018 3:58 pm
I suggest you detect the size and then write RLE as you go - bitmask + 0 for new buttons pressed and then increment the counter while the bitmask is unchanged. (There are other options for encoding more efficiently but this is fairly simple.) Then stop when you run out of space. This will allow it to work on any carts limited to 8KB without losing the functionality, and also enables cartmods of 8KB games. Or maybe you don't want to encourage that?
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2298
Reply with quote
Post Posted: Sun Dec 09, 2018 6:41 pm
Kagesan wrote
What bothers me is that the glitch seems to appear on some flashcarts too.


I missed that completely. Which flashcarts? Homemade? If so, they may be well 8 KB total (in a single bank)... on the fly RLE encoding might be a good solution in any case. The two highest bits can be even used to signal if a length byte follows or if it's just a single/two/three frames.
You won't even need such a slightly more complex solution, likely.
  View user's profile Send private message Visit poster's website
  • Joined: 01 Feb 2014
  • Posts: 406
Reply with quote
Post Posted: Mon Dec 10, 2018 4:57 pm
sverx wrote
Which flashcarts?

Research so far has shown that the glitch appears on homemade carts (which is to be expected) and on chinese Everdrive clones like the Jack Diy (which is surprising).

I have a few days off next week, maybe I'll find the time to fix it then.

Maxim wrote
Or maybe you don't want to encourage that?

No, I don't really want to encourage that. Besides, I am currently looking into the possibility of producing a physical edition, and a fully working replay feature would be a great selling point for that.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!