OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Super FX save: a boot counter that survives the power switch, in Game Pak RAM. More...

#include <snes.h>
#include <snes/sram.h>
#include <snes/superfx.h>

Classes

struct  SaveBlock
 The saved block: the magic word, then the counter. More...

Macros

#define SAVE_AT   0xE000
 Game Pak RAM byte offset of the save block: above two 16 KB framebuffers.
#define SAVE_MAGIC   0x5F5A
 Marks a block this program wrote.

Functions

int main (void)

Variables

SaveBlock found
 What the battery held at power-on (read before anything is written).
u16 gsu_present
 gsuIsPresent() at boot: 1 on a Super FX cartridge
u16 had_save
 1 when found carried the magic word (a previous run saved here)
SaveBlock now
 What this run wrote back.

Detailed Description

Super FX save: a boot counter that survives the power switch, in Game Pak RAM.

A Super FX cartridge has one RAM, the GSU's Game Pak RAM at $70:0000: the chip draws into it, and when the board has a battery it is also the save memory (header type $15, USE_SRAM := 1; its size is declared at $FFBD, GSU_RAM_KB). The sram module addresses it like any other save memory — this example is memory/save_game's call sequence on a Super FX board, with the GSU stopped the whole time.

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 RAM powered up with, so the magic decides, not a zero). It adds one, saves, and prints both. Power-cycle: the screen shows one more. The block sits at $E000, above the two 16 KB framebuffers a game would use (chips/superfx_game_skeleton) — a game that presents frames must keep its save out of them.

SNES Concepts
  • Game Pak RAM is the GSU's work RAM and the battery-backed save memory
  • The save block must not overlap the framebuffers the GSU draws into
  • A magic word tells a saved block from power-on garbage
What to Observe
  • "FOUND" is the saved counter (or "NONE" on a fresh cart), "NOW" is FOUND + 1
  • Switch the console off and on: NOW increments by one each time
  • "GSU PRESENT" confirms the header and the chip agree (gsuIsPresent)
Modules Used
console, dma, background, text, sram, superfx
See also
sram.h, superfx.h, memory/save_game, chips/sa1_save

Macro Definition Documentation

◆ SAVE_AT

#define SAVE_AT   0xE000

Game Pak RAM byte offset of the save block: above two 16 KB framebuffers.

◆ SAVE_MAGIC

#define SAVE_MAGIC   0x5F5A

Marks a block this program wrote.

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ found

SaveBlock found

What the battery held at power-on (read before anything is written).

◆ gsu_present

u16 gsu_present

gsuIsPresent() at boot: 1 on a Super FX cartridge

◆ had_save

u16 had_save

1 when found carried the magic word (a previous run saved here)

◆ now

SaveBlock now

What this run wrote back.