Make RomData indexable.

This commit is contained in:
Lyle Mantooth 2022-06-05 15:57:02 -04:00
parent d1d4e31738
commit 1c752e5bbd
Signed by: IslandUsurper
GPG key ID: 6DB52EAE123A5789

View file

@ -1,6 +1,6 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::iter; use std::iter;
use std::ops::Range; use std::ops::{Index, IndexMut, Range};
use anyhow::bail; use anyhow::bail;
@ -245,11 +245,6 @@ impl RomData {
self.set_patch_bytes(flag_idx..(flag_idx + 1)); self.set_patch_bytes(flag_idx..(flag_idx + 1));
} }
pub fn patch_bytes(&mut self, address: usize, patch_data: Vec<u8>) {
self.rom_data
.splice(address..(address + patch_data.len()), patch_data);
}
pub fn patch_data(&mut self, patch: &Patch) { pub fn patch_data(&mut self, patch: &Patch) {
self.set_rom_bytes( self.set_rom_bytes(
&patch.patch_data, &patch.patch_data,
@ -296,3 +291,17 @@ impl RomData {
} }
} }
} }
impl Index<usize> for RomData {
type Output = u8;
fn index(&self, index: usize) -> &u8 {
&self.rom_data[index]
}
}
impl IndexMut<usize> for RomData {
fn index_mut(&mut self, index: usize) -> &mut u8 {
&mut self.rom_data[index]
}
}