![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
Saving: a record in flash that survives power cycles and re-uploads. More...
#include <stdint.h>Go to the source code of this file.
Namespaces | |
| namespace | save |
| Saved records: load, store, and the raw read/write underneath. | |
Functions | |
| constexpr uint32_t | save::magic (const char(&s)[5]) |
| Four characters as a magic number ("CHCR" -> 0x52434843). | |
| bool | save::available () |
| Whether saving works in this image. | |
| const void * | save::read (uint32_t magic, uint8_t version, uint16_t size, uint8_t *flag=nullptr) |
| Find the newest valid record. | |
| void * | save::buffer () |
| The page buffer to fill before write(): writing in place. | |
| bool | save::write (uint32_t magic, uint8_t version, uint16_t size, uint8_t flag=0) |
| Write what is in buffer() as a new record, to the older page. | |
| template<class T > | |
| bool | save::load (uint32_t magic, uint8_t version, T &data, uint8_t *flag=nullptr) |
| Load a struct from the newest valid record. | |
| template<class T > | |
| bool | save::store (uint32_t magic, uint8_t version, const T &data, uint8_t flag=0) |
| Save a struct as a new record. | |
Variables | |
| static const uint16_t | save::MAX_DATA = 256 - 12 |
| The most data a record holds: a 256-byte page less the header and CRC. | |
Saving: a record in flash that survives power cycles and re-uploads.
CHGame has no EEPROM. The bootloader erases only the flash pages a new sketch occupies, so the last two pages of the application region (0xF500, 0xF600) survive. A record is a header, the game's own data and a CRC; saves take turns between the pages, so a power cut in the middle of one loses only that save. Every game shares the two pages and tells its records apart by a magic number of its own (each game needs a different one). If the sketch grows into the pages, saving switches itself off rather than overwrite code: an image up to 50,432 B keeps both pages, up to 50,688 B one.