Skip to content
Snippets Groups Projects
Verified Commit 1dcaecde authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: added write and read unsafe

parent 06bd16df
No related branches found
No related tags found
1 merge request!31System state save
Pipeline #3295 failed
......@@ -498,23 +498,58 @@ impl Mmu {
}
}
/// Reads a byte from a certain memory address, without the typical
/// Game Boy verifications, allowing deep read of values.
pub fn read_unsafe(&mut self, addr: u16) -> u8 {
match addr {
_ => self.read(addr),
}
}
/// Writes a byte to a certain memory address without the typical
/// Game Boy verification process. This allows for faster memory
/// access in registers and other memory areas that are typically
/// inaccessible.
pub fn write_unsafe(&mut self, addr: u16, value: u8) {
match addr {
_ => self.write(addr, value),
}
}
pub fn read_many(&mut self, addr: u16, count: u16) -> Vec<u8> {
let mut data: Vec<u8> = vec![];
for index in 0..count {
let byte = self.read(addr + index);
data.push(byte);
}
data
}
pub fn write_many(&mut self, addr: u16, data: &[u8]) {
for (index, byte) in data.iter().enumerate() {
self.write(addr + index as u16, *byte)
}
}
pub fn read_many(&mut self, addr: u16, count: u16) -> Vec<u8> {
pub fn read_many_unsafe(&mut self, addr: u16, count: u16) -> Vec<u8> {
let mut data: Vec<u8> = vec![];
for index in 0..count {
let byte = self.read(addr + index);
let byte = self.read_unsafe(addr + index);
data.push(byte);
}
data
}
pub fn write_many_unsafe(&mut self, addr: u16, data: &[u8]) {
for (index, byte) in data.iter().enumerate() {
self.write_unsafe(addr + index as u16, *byte)
}
}
pub fn write_boot(&mut self, addr: u16, buffer: &[u8]) {
self.boot[addr as usize..addr as usize + buffer.len()].clone_from_slice(buffer);
}
......
......@@ -791,7 +791,7 @@ impl State for BeesCore {
// The loading of the registers should be done in a much
// more manual way like SameBoy does here
// https://github.com/LIJI32/SameBoy/blob/7e6f1f866e89430adaa6be839aecc4a2ccabd69c/Core/save_state.c#L673
gb.mmu().read_many(0xff00, 128).try_into().unwrap(),
gb.mmu().read_many_unsafe(0xff00, 128).try_into().unwrap(),
);
core.ram.fill_buffer(gb.mmu().ram());
core.vram.fill_buffer(gb.ppu().vram_device());
......@@ -831,7 +831,7 @@ impl State for BeesCore {
// The registers should be handled in a more manual manner
// to avoid unwanted side effects
// https://github.com/LIJI32/SameBoy/blob/7e6f1f866e89430adaa6be839aecc4a2ccabd69c/Core/save_state.c#L1003
gb.mmu().write_many(0xff00, &self.io_registers);
gb.mmu().write_many_unsafe(0xff00, &self.io_registers);
gb.mmu().set_ram(self.ram.buffer.to_vec());
gb.ppu().set_vram(&self.vram.buffer);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment