PRG-RAM (Battery-backed) initial value/initialization?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Yoshimaster96
Posts: 16
Joined: Sat Jan 09, 2016 5:30 pm

PRG-RAM (Battery-backed) initial value/initialization?

Post by Yoshimaster96 »

What is the initial value for battery-backed PRG-RAM? If it is undefined, how would one initialize it without overwriting save data?
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PRG-RAM (Battery-backed) initial value/initialization?

Post by rainwarrior »

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).
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PRG-RAM (Battery-backed) initial value/initialization?

Post by lidnariq »

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.
Post Reply