Refactor 16bit bus read write

This commit is contained in:
2021-10-15 19:18:00 -05:00
parent 891a72ad73
commit f9d5cfaa02
2 changed files with 23 additions and 22 deletions
+11 -1
View File
@@ -1,3 +1,4 @@
use crate::utils::{join_bytes};
use crate::rom::ROM;
pub enum MemoryMap {
@@ -46,7 +47,6 @@ impl Bus {
Ok(rom) => rom,
_ => ROM::from_bytes(&[0; 0xFFFF])
};
game_rom.print_content(Some(0x102));
Self {
data: [0; 0x10000],
game_rom,
@@ -62,7 +62,17 @@ impl Bus {
}
}
pub fn read_16bit(&self, address: u16) -> u16 {
join_bytes(self.read(address + 1), self.read(address))
}
pub fn write(&mut self, address: u16, data: u8) {
self.data[address as usize] = data;
}
pub fn write_16bit(&mut self, address: u16, data: u16) {
let bytes = data.to_be_bytes();
self.write(address, bytes[1]);
self.write(address + 1, bytes[0]);
}
}