pub struct SaveData { /* private fields */ }
Expand description
Allows reading and writing of save media.
Implementations§
source§impl SaveData
impl SaveData
sourcepub fn media_info(&self) -> &'static MediaInfo
pub fn media_info(&self) -> &'static MediaInfo
Returns the media info underlying this accessor.
sourcepub fn media_type(&self) -> MediaType
pub fn media_type(&self) -> MediaType
Returns the save media type being used.
sourcepub fn sector_size(&self) -> usize
pub fn sector_size(&self) -> usize
Returns the sector size of the save media. It is generally optimal to write data in blocks that are aligned to the sector size.
sourcepub fn read(&mut self, offset: usize, buffer: &mut [u8]) -> Result<(), Error>
pub fn read(&mut self, offset: usize, buffer: &mut [u8]) -> Result<(), Error>
Copies data from the save media to a buffer.
If an error is returned, the contents of the buffer are unpredictable.
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 verify(&mut self, offset: usize, buffer: &[u8]) -> Result<bool, Error>
pub fn verify(&mut self, offset: usize, buffer: &[u8]) -> Result<bool, Error>
Verifies that a given block of memory matches the save media.
sourcepub fn align_range(&self, range: Range<usize>) -> Range<usize>
pub fn align_range(&self, range: Range<usize>) -> Range<usize>
Returns a range that contains all sectors the input range overlaps.
This can be used to calculate which blocks would be erased by a call
to prepare_write
sourcepub fn prepare_write(
&mut self,
range: Range<usize>
) -> Result<SavePreparedBlock<'_>, Error>
pub fn prepare_write( &mut self, range: Range<usize> ) -> Result<SavePreparedBlock<'_>, Error>
Prepares a given span of offsets for writing.
This will erase any data in any sector overlapping the input range. To
calculate which offset ranges would be affected, use the
align_range
function.
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(())
}