PRG-RAM (Battery-backed) initial value/initialization?
Moderator: Moderators
-
- Posts: 16
- Joined: Sat Jan 09, 2016 5:30 pm
PRG-RAM (Battery-backed) initial value/initialization?
What is the initial value for battery-backed PRG-RAM? If it is undefined, how would one initialize it without overwriting save data?
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: PRG-RAM (Battery-backed) initial value/initialization?
In general it has no reliable startup state. You should treat it as if it is random.
To check to see if it's been initialized, it's usual to write some sort of signature values somewhere and check that. If that signature is not present, assume the RAM is uninitialized and proceed wipe its contents (and write the signature).
You could use a CRC or something similar instead of a signature to check for data integrity, etc.
Sometimes it's also useful to have some sort of manual/debug override that forces it to use whatever's there despite failing a signature/CRC check. e.g. I think Chrono Trigger has a cheat code that can be used to load a corrupted save (can be used for some speedrun exploits).
To check to see if it's been initialized, it's usual to write some sort of signature values somewhere and check that. If that signature is not present, assume the RAM is uninitialized and proceed wipe its contents (and write the signature).
You could use a CRC or something similar instead of a signature to check for data integrity, etc.
Sometimes it's also useful to have some sort of manual/debug override that forces it to use whatever's there despite failing a signature/CRC check. e.g. I think Chrono Trigger has a cheat code that can be used to load a corrupted save (can be used for some speedrun exploits).
Re: PRG-RAM (Battery-backed) initial value/initialization?
RAMs usually power up with some pattern, plus a few random bits.
To prevent accidentally formatting over valid data, use some kind of validity marker. The more bits you use, the less likely it is to arise randomly. For example, Galaxian puts a copy of the author's name in RAM to detect warm boots, because the odds of that name arising randomly is minuscule.
Also consider protecting the actual save data itself with some kind of checksum.
To prevent accidentally formatting over valid data, use some kind of validity marker. The more bits you use, the less likely it is to arise randomly. For example, Galaxian puts a copy of the author's name in RAM to detect warm boots, because the odds of that name arising randomly is minuscule.
Also consider protecting the actual save data itself with some kind of checksum.