Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Generation I Glitch Discussion

How did a glitch item delete my save file? - Page 1

How did a glitch item delete my save file?

Posted by: jfb1337
Date: 2017-03-26 12:36:57
I was trying to build an 8F script on VC Blue, and accidentally created a glitch item (think it was 0x86). Without really thinking, I clicked on it, and my game crashed into a stripey screen. But when I restarted, the save file was gone - it didn't give any error message or anything, the continue option was just removed from the menu. As far as I'm aware, this can only happen when the player name gets corrupted in SRAM with no terminator. What happened here? Is there any point where the game opens SRAM without closing it? Or did the glitch item open SRAM by itself? This has happened to me before when I used 8F without the correct setup and must have hit an rst 38, but I've also done that before without my save file deleting.

Re: How did a glitch item delete my save file?

Posted by: ISSOtm
Date: 2017-03-26 13:06:31
SRAM is open when a value $XA (X being any hex digit) is "written" to address range $0000 - $1FFF). This may happen either by writing such a value directly, or incrementing / decrementing a value in ROM. Example : incrementing the byte at $0060 (which is a $D9) will unlock SRAM.

If SRAM is overwritten with junk afterwards, the game may either think the save file is corrupted or simply doesn't exist.
You can get your Pokémon back if you perform the SRAM glitch (without the "Clear saved data ?" part, of course :P), they just will be considered traded Pokémon.
Just make sure never to power off too late : if you get a "the save is destroyed !" message you CAN try again, don't delete saved data.
If you can load your file but cannot access the Pokémon menu afterwards it's over :/

Re: How did a glitch item delete my save file?

Posted by: jfb1337
Date: 2017-06-17 20:18:29
I think I have a hypothesis on what could have happened, but haven't tested this: The item in question could have had a super glitch name, which causes things to be copied stuff from CD6D to CF4B. But if there were NO 0x50 bytes in this range, this would cause it to eventually start reading from where it was written to, causing the entire memory to be hosed, until it wraps around to ROM in which 0x50 byte gets found since it can't be overwritten. This corrupts both the stack and the OAM procedure, either of which can cause unpredictable code to run, which is likely to hit an rst38, possibly after happening to open SRAM, causing it to be hosed.

Re: How did a glitch item delete my save file?

Posted by: ISSOtm
Date: 2017-06-18 07:36:49
The Super Glitch name could have wrecked the whole RAM, especially if you didn't even USE it the item to corrupt everything. Yeah, it could have jumped to a routine that clears SRAM, for example. But if that's what happened, well you've been quite unlucky. FeelsBadMan

Re: How did a glitch item delete my save file?

Posted by: Torchickens
Date: 2017-06-18 08:41:11

I was trying to build an 8F script on VC Blue, and accidentally created a glitch item (think it was 0x86). Without really thinking, I clicked on it, and my game crashed into a stripey screen. But when I restarted, the save file was gone - it didn't give any error message or anything, the continue option was just removed from the menu. As far as I'm aware, this can only happen when the player name gets corrupted in SRAM with no terminator. What happened here? Is there any point where the game opens SRAM without closing it? Or did the glitch item open SRAM by itself? This has happened to me before when I used 8F without the correct setup and must have hit an rst 38, but I've also done that before without my save file deleting.


I think I have a hypothesis on what could have happened, but haven't tested this: The item in question could have had a super glitch name, which causes things to be copied stuff from CD6D to CF4B. But if there were NO 0x50 bytes in this range, this would cause it to eventually start reading from where it was written to, causing the entire memory to be hosed, until it wraps around to ROM in which 0x50 byte gets found since it can't be overwritten. This corrupts both the stack and the OAM procedure, either of which can cause unpredictable code to run, which is likely to hit an rst38, possibly after happening to open SRAM, causing it to be hosed.


This is exactly what happens. For this reasons it's always a good idea to only do menu scrolling with the B button and to only select unterminated name glitch items when a 0x50 tile is on the screen.

Re: How did a glitch item delete my save file?

Posted by: camper
Date: 2017-06-18 21:29:17
I think it's much easier to have your save wiped in the VC version.

Re: How did a glitch item delete my save file?

Posted by: TheZZAZZGlitch
Date: 2017-06-19 02:00:02
Yeah, save wipes with rst 38 crashes are really common on VC (I once erased my save by accident too).
This makes me think that the VC doesn't emulate SRAM locking at all.

People tend to corrupt their saves because they save right before trying out glitches, for safety. But this actually causes the game to switch to SRAM bank 1, which contains save data. So if some wrong code manages to later unlock SRAM (which might not be even necessary, since it always seems unlocked on VC) and overwrite its contents, the save data is gone.

It's a good idea to view any non-glitch Pokemon's stats before doing anything potentially game-crashing. This causes the game to switch to SRAM bank 0, which doesn't contain any important data. So even if something goes wrong and SRAM is overwritten, nothing bad will happen. The bad code would have needed to not only unlock the SRAM somehow, but also switch to bank 1/2, which is highly unlikely.

Re: How did a glitch item delete my save file?

Posted by: Torchickens
Date: 2017-06-19 08:21:05
Hmm, I don't know if it is something unrelated but when I use the offgao memory editor on VC Yellow and Red A000-BFFF appears to be filled with FF, which may suggest that the SRAM is locked.

Me too though, save wipes seem to be a lot more common to me on VC (which is why I thank Wack0 for encouraging me to switch to custom firmware to restore save files).

Re: How did a glitch item delete my save file?

Posted by: jfb1337
Date: 2017-06-19 15:13:40
Come to think about it I've never had a save wipe on BGB except when I deliberately opened SRAM to try to get a save wipe, but I've had at least 3 or 4 save wipes on VC. So it's possible that SRAM isn't properly or at all.

I just checked with my offgao mem editor and A000-BFFF was all FF. But when I looked at a sprite to open bank 0, and checked again and there was data there. From A858 onwards was alternating 00 39, and before that was actual data.
Then I saved, and it was back to all FF again.
Then I manually opened SRAM by incrementing a byte ending in 9 somewhere in ROM, and there was data up until B524 after which was 0039, which was also there before A598. I tried manually opening and closing it a few times, which seemed to work as expected, though one time it seemed to take 2 attempts to actually get it to close: could be something interesting (closing SRAM sometimes fails??) or could just be that I didn't actually write something when I thought I did. Edit: Most likely explanations is just that I wrote to the wrong part of ROM. Anyway, my thumb is now tired from holding the select button so much.

Re: How did a glitch item delete my save file?

Posted by: ISSOtm
Date: 2017-06-20 05:14:56
The area of ROM that enables SRAM is 0000-1FFF. Might explain.

Re: How did a glitch item delete my save file?

Posted by: Crystal_
Date: 2017-06-20 19:23:18
The thing is, VC is far more prone to being corrupted due to the fact that unknown opcodes or invalid stops don't halt the game like they do in a real GB/C. So in VC the game will usually run around for longer, and is more likely to corrupt (open) SRAM or to trigger a fatal rst 38 in the process. That said, a rst 38 shouldn't be able to change the SRAM bank so as TheZZAZZGlitch said making sure that SRAM bank 0 is loaded before doing anything dangerous is a good idea.