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

The save: magic, version, checksum, and defaults when anything is off. More...

#include <snes.h>
#include <snes/sram.h>
#include <snes/debug.h>
#include "game.h"
#include "save.h"

Functions

static void defaults (void)
 The values a fresh game starts with.
void saveLoad (void)
 Read the record; whatever is there, the globals end up valid.
u8 saveRecord (u16 time)
 Note a won round and write the record.

Variables

u16 save_best
 Best time in frames, or SAVE_NONE.
u8 save_rec [8]
 The record as it sits in RAM.
u8 save_status
 What saveLoad() found.
u8 save_wins
 Rounds won, capped at 255.

Detailed Description

The save: magic, version, checksum, and defaults when anything is off.

Record (8 bytes): 'S' 'D' | version | best (u16, little-endian) | wins | 0 | checksum of the seven bytes before. The record is flat bytes, never a struct dumped as is: no padding or endianness to depend on, and a layout change is a version bump.

Function Documentation

◆ defaults()

void defaults ( void )
static

The values a fresh game starts with.

◆ saveLoad()

void saveLoad ( void )

Read the record; whatever is there, the globals end up valid.

< the cartridge declares no SRAM: the defaults, nothing is written

< no record (blank SRAM): the defaults

< frames on the clock: 30 s at 60 Hz

< a record whose version, checksum or content is wrong: the defaults

< a valid record was read

◆ saveRecord()

u8 saveRecord ( u16 time)

Note a won round and write the record.

Returns
1 if time beat the best.

< frames on the clock: 30 s at 60 Hz

Variable Documentation

◆ save_best

u16 save_best

Best time in frames, or SAVE_NONE.

◆ save_rec

u8 save_rec[8]

The record as it sits in RAM.

◆ save_status

u8 save_status

What saveLoad() found.

◆ save_wins

u8 save_wins

Rounds won, capped at 255.