Crates.io | agbrs_flash |
lib.rs | agbrs_flash |
version | 0.4.0 |
source | src |
created_at | 2022-08-20 02:51:08.065103 |
updated_at | 2024-06-17 00:35:45.335839 |
description | Crate for persisting game data to a GBA cartridge using Rust |
homepage | |
repository | https://github.com/kouta-kun/agbrs_flash |
max_upload_size | |
id | 649015 |
size | 41,693 |
agbrs_flash is a crate that allows for persisting game data to a GBA cartridge flash chip. Currently it only supports 1M cartridges and it auto-identifies the resulting ROM as such.
It makes use of postcard to serialize the object and store it in the flash memory.
#![no_main]
#![no_std]
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use serde::{Serialize, Deserialize};
extern crate alloc;
#[derive(Serialize, Deserialize)]
struct TestObject {
pub id: usize,
pub text: String,
}
#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
agbrs_flash::MEMORY.init();
let have_struct = agbrs_flash::MEMORY.have_structure();
agb::println!("Have structure? {}", have_struct);
if !have_struct {
agbrs_flash::MEMORY.write_structure(&TestObject {
id: 1,
text: "Hello World!".to_string(),
});
agb::println!("Restart to see the stored data")
} else {
let obj: TestObject = agbrs_flash::MEMORY.read_structure().unwrap();
agb::println!("id: {} text: {}", obj.id, obj.text);
}
loop{}
}