rtc: persist RP5C01 battery RAM (battmem) in WinUAE-compatible nvram files#265
Merged
Conversation
The RP5C01's battery-backed registers (the 26 RAM nibbles behind battmem.resource, the alarm digits, and the 12/24 select) now persist across runs to a backing file ([machine] battmem, defaulting to battmem.nvram whenever an RP5C01 is fitted, "" for session-only), the way the real board's battery keeps them. This is where scsi.device stores its per-unit SCSI host settings, so an A3000's or A4091's remembered CD drives and transfer options survive a power cycle. The file is bit-compatible with the WinUAE/Amiberry .nvram layout (three 16-byte blocks: time digits + MODE/TEST/RESET as of the save, the alarm bank, the 13 combined RAM bytes), so backing files interchange between emulators. Only the battery payload loads back: the stored time never overrides the read-only (host- or rtc_time-driven) clock, and the stored MODE never overrides the power-on value ($8) every battclock probe matches on to identify the part. Changed battery state flushes when the guest writes MODE: every RAM access sequence brackets its nibble writes in a bank-select write and a bank restore (battmem.resource and Linux's nvram driver both do), so the restore is the transaction boundary -- the same shape as the Akiko NVRAM flushing on I2C STOP. Clock reads lock and unlock MODE too, so only writes that actually change battery state arm a flush. The backing-file binding rides in the save state like Akiko's, so a resumed run keeps persisting to the same file: STATE_VERSION 38 -> 39.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds persistent backing storage for the RP5C01 RTC’s battery-backed registers (“battmem”) via WinUAE/Amiberry-compatible .nvram files, enabling SCSI host settings and other battmem.resource payloads to survive across emulator runs and save-state resumes.
Changes:
- Implement RP5C01 battmem load/flush to a configurable
.nvramfile, with unit tests covering layout/compatibility and config behaviors. - Add
[machine] battmemconfiguration (defaulting tobattmem.nvramwhen an RP5C01 is fitted) and wire it into machine construction. - Bump save-state format version for the new RP5C01 state shape; document and gitignore
.nvramartifacts.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/savestate.rs | Bumps save-state version to account for added RP5C01 battmem binding fields. |
| src/rtc.rs | Implements RP5C01 battmem backing-file support (load/flush) and adds unit tests. |
| src/emulator.rs | Hooks config battmem path into machine build and logs persistence binding. |
| src/config.rs | Adds [machine] battmem parsing, defaulting rules, validation, and tests. |
| docs/guide/configuration.md | Documents the new battmem option and behavior. |
| copperline.example.toml | Adds commented example configuration for battmem. |
| .gitignore | Ignores *.nvram as a local run artifact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Clearing the dirty bit before the write meant a transient host error (full disk, missing directory, permissions) silently dropped the battery state: no later MODE write would retry, so nothing persisted until the guest changed a battery register again. Clear it only after the write lands; a failure leaves it armed and the next MODE write retries. Retries stay naturally rate-limited because only MODE writes while dirty attempt a flush.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The RP5C01's battery-backed registers -- the 26 RAM nibbles behind AmigaOS
battmem.resource, the alarm digits, and the 12/24 select -- now persist across runs to a backing file, the way the real A3000/A4000 board's battery keeps them. This is wherescsi.devicestores its per-unit SCSI host settings, so an A3000's or A4091's remembered CD drives and transfer/disconnect options survive a power cycle instead of reverting every run.[machine] battmem = "path", defaulting tobattmem.nvramin the working directory whenever an RP5C01 is fitted;battmem = ""keeps the battery registers session-only; naming a file on a machine with no RP5C01 is a loud config error..nvramfiles (verified against Amiberry'scia.cppand a real Amiberry A4000 file), so backing files interchange between emulators: three 16-byte blocks of one register per byte -- the time digits plus MODE/TEST/RESET as of the save, the alarm bank, and the 13 combined battery RAM bytes.rtc_time-driven) clock, and the stored MODE never overrides the power-on value: files park MODE at $9, and restoring that would break the power-on probe tell (MODE reads $8) AROS/battclock.resource identify the part by.battmem.resourceand Linux's nvram driver both do), so the restore is the transaction end -- the same shape as the Akiko NVRAM flushing on I2C STOP. Dirty is armed only by writes that actually change battery state, so clock reads locking/unlocking MODE never rewrite the file.STATE_VERSION38 -> 39.configuration.mdbattmem paragraph,copperline.example.toml;*.nvramgitignored as a local run artifact.Testing
cargo clippyandcargo fmt --checkclean.A4000-040-MMU.nvrambyte-for-byte, booted the A4000 profile headlessly with it -- it preloads (rtc: battery RAM (battmem) persisted to ...) and a boot that writes no battery state leaves the file byte-identical.