SNES SRAM (Save RAM) Functions. More...
#include <snes/types.h>Go to the source code of this file.
Macros | |
| #define | SRAM_SIZE_16KB 0x04 |
| 16KB SRAM (128Kbit) | |
| #define | SRAM_SIZE_2KB 0x01 |
| 2KB SRAM (16Kbit) | |
| #define | SRAM_SIZE_32KB 0x05 |
| 32KB SRAM (256Kbit) | |
| #define | SRAM_SIZE_4KB 0x02 |
| 4KB SRAM (32Kbit) | |
| #define | SRAM_SIZE_8KB 0x03 |
| 8KB SRAM (64Kbit) - Most common | |
| #define | SRAM_SIZE_NONE 0x00 |
| No SRAM (0KB) | |
Functions | |
| u8 | sramChecksum (u8 *data, u16 size) |
| Calculate simple checksum. | |
| void | sramClear (u16 size) |
| Clear SRAM to zero. | |
| void | sramLoad (u8 *data, u16 size) |
| Load data from SRAM. | |
| void | sramLoadOffset (u8 *data, u16 size, u16 offset) |
| Load data from SRAM at offset. | |
| void | sramSave (u8 *data, u16 size) |
| Save data to SRAM. | |
| void | sramSaveOffset (u8 *data, u16 size, u16 offset) |
| Save data to SRAM at offset. | |
SNES SRAM (Save RAM) Functions.
Functions for saving and loading game data to battery-backed SRAM.
SRAM (Static RAM) on SNES cartridges is battery-backed RAM that persists when the console is powered off. It's used for save games.
SRAM is mapped at bank $70, addresses $0000-$7FFF (32KB max). Most games use 2KB-8KB of SRAM.
To enable SRAM, your ROM header (hdr.asm) must set:
| #define SRAM_SIZE_16KB 0x04 |
16KB SRAM (128Kbit)
| #define SRAM_SIZE_2KB 0x01 |
2KB SRAM (16Kbit)
| #define SRAM_SIZE_32KB 0x05 |
32KB SRAM (256Kbit)
| #define SRAM_SIZE_4KB 0x02 |
4KB SRAM (32Kbit)
| #define SRAM_SIZE_8KB 0x03 |
8KB SRAM (64Kbit) - Most common
| #define SRAM_SIZE_NONE 0x00 |
No SRAM (0KB)
Calculate simple checksum.
Calculates a simple 8-bit checksum of data. Use this to verify save data integrity.
| data | Pointer to data |
| size | Number of bytes |
| void sramClear | ( | u16 | size | ) |
Load data from SRAM at offset.
Like sramLoad() but reads from a specific offset within SRAM. Useful for multiple save slots.
| data | Pointer to destination buffer in Work RAM |
| size | Number of bytes to load |
| offset | Starting offset in SRAM (0-32767) |
Save data to SRAM.
Copies data from Work RAM to battery-backed SRAM. The data will persist when the console is powered off.
| data | Pointer to data in Work RAM to save |
| size | Number of bytes to save (max 32KB) |
Save data to SRAM at offset.
Like sramSave() but writes to a specific offset within SRAM. Useful for multiple save slots.
| data | Pointer to data in Work RAM to save |
| size | Number of bytes to save |
| offset | Starting offset in SRAM (0-32767) |