Skip to content
RetrogamingDeep Dive Published Updated 3 min readViews unavailable

Battery-Backed Save RAM and Real-Time Clocks: Persistent State Beyond Save States

How cartridge SRAM, flash, EEPROM, and RTC registers persist; how emulators serialize them; and why wall-clock policy, atomic writes, and testing matter.

Many cartridges preserve game state in battery-backed SRAM, EEPROM, or flash. Some also contain a real-time clock (RTC) that advances while the console is off. Emulators have to model both the memory protocol and persistence lifecycle. A generic save state captures an instant of emulator memory; it is not a substitute for the cartridge’s normal nonvolatile save.

Persistent media have different write behavior

SRAM may look like a directly mapped writable bank gated by mapper control bits. EEPROM uses a serial command protocol with address and data phases. Flash requires command sequences, erase units, busy behavior, and bit-transition constraints. Treating all of them as a flat byte array can make ordinary saves appear to work while erase, protection, or game-detection logic fails.

Cartridge metadata identifies expected save hardware and size, but database corrections may be needed for ambiguous dumps. Allocate exactly the supported media, initialize erased bytes to the hardware-defined value, and emulate write-enable and bank selection. Do not expand a save file silently to match a guessed board.

The emulator should write persistent data atomically: create a temporary file in the same directory, write and flush the complete representation, then rename it over the previous file. Keep a backup generation when practical. Crashing halfway through an in-place write should not destroy years of progress.

RTC state combines registers with an epoch

A cartridge RTC can expose seconds, minutes, hours, days, halt, carry, and latch semantics. For example, an MBC3-style clock latches a stable register snapshot when the game performs a documented transition. Returning a continuously changing host time on every register read ignores that protocol.

Persistence commonly stores the emulated RTC registers plus a host timestamp from the last successful save. On load, the emulator calculates elapsed time and advances the clock if it was not halted. The calculation must define behavior for host clock moving backward, suspend, timezone changes, leap handling, and overflow of the cartridge’s limited day counter.

A monotonic host clock is good for measuring time during one process but does not survive shutdown. Wall time survives but can be changed. Store enough metadata to detect negative or implausibly large deltas and let policy choose whether to clamp, warn, or reproduce the adjustment. Timezone should not affect a cartridge that counts elapsed seconds; converting through local civil time introduces daylight-saving errors.

Save files and save states interact

Loading an old save state rewinds emulated RAM and RTC registers. If the emulator immediately overwrites the normal battery file, it can roll back progress made after the state. Define whether states include persistent media, whether loading prompts before commit, and which state wins on shutdown. Hardcore or deterministic modes may deliberately restrict state use.

Netplay and movie recording need a shared RTC epoch and deterministic policy. Two peers using their local wall clocks can diverge even when CPU emulation is identical. Record RTC seed, timezone policy, save hash, core version, and relevant settings in the session metadata.

Test power and time, not only menu saves

Use a copy of a known save. Test in-game save, clean exit, forced process kill during write, restart, write protection, full media, old save-size import, RTC halt/unhalt, latch behavior, day overflow, host clock backward/forward, sleep, save-state load, and cross-version migration. Compare register traces with hardware documentation or diagnostic ROMs.

Persistence is correct when the game experiences the same memory protocol and clock semantics across power cycles. The host file is merely the storage vehicle; its atomicity, provenance, and conflict rules are part of emulation accuracy.

Related:

Sources:

Comments