SA-1 save: a boot counter that survives the power switch, in BW-RAM.
On an SA-1 cartridge the battery-backed memory is not the LoROM SRAM at $70:0000 but the SA-1's BW-RAM, seen by the SNES CPU at $40:0000 and writable only once SBWE ($2226) is set — which crt0 does on an SA-1 build. The sram module addresses it for you: this example is the same call sequence as memory/save_game, on the other memory.
It keeps one number: how many times the console has been switched on. At boot it reads the counter and a magic word; a matching magic means a previous run saved here (a fresh cart reads whatever the chip powered up with, so the magic decides, not a zero). It adds one, saves, and prints both the value it found and the value it wrote. Power-cycle: the screen shows one more. That is the whole test — and the one a console session needs (docs/HARDWARE_VERIFICATION.md, row 25).
- SNES Concepts
- SA-1 BW-RAM as the save memory: $40:0000 for the SNES CPU, SBWE first
- A magic word tells a saved block from power-on garbage
- The sram module is the same API on LoROM, HiROM, SA-1 and Super FX carts
- What to Observe
- "FOUND" is the saved counter (or "NONE" on a fresh cart), "NOW" is FOUND + 1; both printed as decimal
- Switch the console off and on: NOW increments by one each time
- "SA-1 READY" confirms the coprocessor booted (sa1IsReady)
- Modules Used
- console, dma, background, text, sa1, sram
- See also
- sram.h, sa1.h, memory/save_game, chips/superfx_save