diff --git a/examples/hyperspace-roll/src/save.rs b/examples/hyperspace-roll/src/save.rs index ada5cf6a..a810a6c7 100644 --- a/examples/hyperspace-roll/src/save.rs +++ b/examples/hyperspace-roll/src/save.rs @@ -3,6 +3,7 @@ use agb::save::{Error, SaveManager}; use agb::Gba; static HIGH_SCORE: AtomicU32 = AtomicU32::new(0); +static SAVE_OFFSET: usize = 1; pub fn init_save(gba: &mut Gba) -> Result<(), Error> { gba.save.init_sram(); @@ -18,7 +19,7 @@ pub fn init_save(gba: &mut Gba) -> Result<(), Error> { save_high_score(&mut gba.save, 0)?; } else { let mut buffer = [0; 4]; - access.read(1, &mut buffer)?; + access.read(SAVE_OFFSET, &mut buffer)?; let high_score = u32::from_le_bytes(buffer); let score = if high_score > 100 { 0 } else { high_score }; @@ -35,8 +36,8 @@ pub fn load_high_score() -> u32 { pub fn save_high_score(save: &mut SaveManager, score: u32) -> Result<(), Error> { save.access()? - .prepare_write(1..5)? - .write(1, &score.to_le_bytes())?; + .prepare_write(SAVE_OFFSET..SAVE_OFFSET + 4)? + .write(SAVE_OFFSET, &score.to_le_bytes())?; HIGH_SCORE.store(score, Ordering::SeqCst); Ok(()) } diff --git a/examples/the-dungeon-puzzlers-lament/src/lib.rs b/examples/the-dungeon-puzzlers-lament/src/lib.rs index d4ccc8be..1d1770a4 100644 --- a/examples/the-dungeon-puzzlers-lament/src/lib.rs +++ b/examples/the-dungeon-puzzlers-lament/src/lib.rs @@ -121,8 +121,10 @@ pub fn entry(mut gba: agb::Gba) -> ! { oam: unmanaged, }; - let mut current_level = 0; - let mut maximum_level = save::load_max_level() as usize; + let saved_level = save::load_max_level() as usize; + + let mut current_level = saved_level; + let mut maximum_level = saved_level; loop { if current_level >= level::Level::num_levels() { current_level = 0; diff --git a/examples/the-dungeon-puzzlers-lament/src/save.rs b/examples/the-dungeon-puzzlers-lament/src/save.rs index 5923fa5c..398d9f49 100644 --- a/examples/the-dungeon-puzzlers-lament/src/save.rs +++ b/examples/the-dungeon-puzzlers-lament/src/save.rs @@ -5,6 +5,7 @@ use agb::{ }; static MAXIMUM_LEVEL: AtomicU32 = AtomicU32::new(0); +static SAVE_OFFSET: usize = 0xFF; pub fn init_save(gba: &mut Gba) -> Result<(), Error> { gba.save.init_sram(); @@ -20,7 +21,7 @@ pub fn init_save(gba: &mut Gba) -> Result<(), Error> { save_max_level(&mut gba.save, 0)?; } else { let mut buffer = [0; 4]; - access.read(1, &mut buffer)?; + access.read(SAVE_OFFSET, &mut buffer)?; let max_level = u32::from_le_bytes(buffer); if max_level > 100 { @@ -39,8 +40,8 @@ pub fn load_max_level() -> u32 { pub fn save_max_level(save: &mut SaveManager, level: u32) -> Result<(), Error> { save.access()? - .prepare_write(1..5)? - .write(1, &level.to_le_bytes())?; + .prepare_write(SAVE_OFFSET..SAVE_OFFSET + 4)? + .write(SAVE_OFFSET, &level.to_le_bytes())?; MAXIMUM_LEVEL.store(level, Ordering::SeqCst); Ok(()) }