From ba62aca590cb54fa2021f8db856ebde8c82c726a Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 5 Aug 2023 11:53:14 +0100 Subject: [PATCH] add example for saving --- agb/examples/save.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 agb/examples/save.rs diff --git a/agb/examples/save.rs b/agb/examples/save.rs new file mode 100644 index 00000000..1cf30597 --- /dev/null +++ b/agb/examples/save.rs @@ -0,0 +1,29 @@ +#![no_std] +#![no_main] + +use agb::save::Error; + +extern crate alloc; +use alloc::vec::Vec; + +#[agb::entry] +fn main(mut gba: agb::Gba) -> ! { + test_save(gba).unwrap(); + panic!("example finished"); +} + +fn test_save(mut gba: agb::Gba) -> Result<(), Error> { + gba.save.init_sram(); + let mut access = gba.save.access()?; + + let mut is_save = 0; + access.read(0, core::slice::from_mut(&mut is_save))?; + + if is_save != 0 { + access + .prepare_write(0..128)? + .write(0, &(0..128).collect::>())?; + } + + Ok(()) +}