Struct agb::save::SaveManager
source · #[non_exhaustive]pub struct SaveManager {}
Expand description
Allows access to the cartridge’s save data.
Implementations§
source§impl SaveManager
impl SaveManager
sourcepub fn init_sram(&mut self)
pub fn init_sram(&mut self)
Declares that the ROM uses battery backed SRAM/FRAM.
Battery Backed SRAM is generally very fast, but limited in size compared to flash chips.
This creates a marker in the ROM that allows emulators to understand what save type the Game Pak uses, and configures the save manager to use the given save type.
Only one init_*
function may be called in the lifetime of the program.
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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::<Vec<_>>())?;
}
Ok(())
}
sourcepub fn init_flash_64k(&mut self)
pub fn init_flash_64k(&mut self)
Declares that the ROM uses 64KiB flash memory.
Flash save media is generally very slow to write to and relatively fast to read from. It is the only real option if you need larger save data.
This creates a marker in the ROM that allows emulators to understand what save type the Game Pak uses, and configures the save manager to use the given save type.
Only one init_*
function may be called in the lifetime of the program.
sourcepub fn init_flash_128k(&mut self)
pub fn init_flash_128k(&mut self)
Declares that the ROM uses 128KiB flash memory.
Flash save media is generally very slow to write to and relatively fast to read from. It is the only real option if you need larger save data.
This creates a marker in the ROM that allows emulators to understand what save type the Game Pak uses, and configures the save manager to use the given save type.
Only one init_*
function may be called in the lifetime of the program.
sourcepub fn init_eeprom_512b(&mut self)
pub fn init_eeprom_512b(&mut self)
Declares that the ROM uses 512 bytes EEPROM memory.
EEPROM is generally pretty slow and also very small. It’s mainly used in Game Paks because it’s cheap.
This creates a marker in the ROM that allows emulators to understand what save type the Game Pak uses, and configures the save manager to use the given save type.
Only one init_*
function may be called in the lifetime of the program.
sourcepub fn init_eeprom_8k(&mut self)
pub fn init_eeprom_8k(&mut self)
Declares that the ROM uses 8 KiB EEPROM memory.
EEPROM is generally pretty slow and also very small. It’s mainly used in Game Paks because it’s cheap.
This creates a marker in the ROM that allows emulators to understand what save type the Game Pak uses, and configures the save manager to use the given save type.
Only one init_*
function may be called in the lifetime of the program.
sourcepub fn access(&mut self) -> Result<SaveData, Error>
pub fn access(&mut self) -> Result<SaveData, Error>
Creates a new accessor to the save data.
You must have initialized the save manager beforehand to use a specific type of media before calling this method.
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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::<Vec<_>>())?;
}
Ok(())
}
sourcepub fn access_with_timer(&mut self, timer: Timer) -> Result<SaveData, Error>
pub fn access_with_timer(&mut self, timer: Timer) -> Result<SaveData, Error>
Creates a new accessor to the save data that uses the given timer for timeouts.
You must have initialized the save manager beforehand to use a specific type of media before calling this method.