Struct agb::save::SaveManager

source ·
#[non_exhaustive]
pub struct SaveManager {}
Expand description

Allows access to the cartridge’s save data.

Implementations§

source§

impl SaveManager

source

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?
examples/save.rs (line 16)
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(())
}
source

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.

source

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.

source

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.

source

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.

source

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?
examples/save.rs (line 17)
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(())
}
source

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.

Auto Trait Implementations§

§

impl RefUnwindSafe for SaveManager

§

impl Send for SaveManager

§

impl Sync for SaveManager

§

impl Unpin for SaveManager

§

impl UnwindSafe for SaveManager

Blanket Implementations§

§

impl<T> Any for Twhere T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for Twhere T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.