core: sysbus: Boxed memory optimization

Former-commit-id: d845ceadcef463b2d66f5fb3cee2b6fbc752c286
This commit is contained in:
Michel Heily 2019-12-31 20:59:02 +02:00
parent 1a5903c09c
commit 1de287713a

View file

@ -79,35 +79,29 @@ impl BoxedMemory {
impl Bus for BoxedMemory { impl Bus for BoxedMemory {
fn read_32(&self, addr: Addr) -> u32 { fn read_32(&self, addr: Addr) -> u32 {
(&self.mem[addr as usize..]) self.read_16(addr) as u32 | (self.read_16(addr + 2) as u32) << 16
.read_u32::<LittleEndian>()
.unwrap()
} }
fn read_16(&self, addr: Addr) -> u16 { fn read_16(&self, addr: Addr) -> u16 {
(&self.mem[addr as usize..]) self.read_8(addr) as u16 | (self.read_8(addr+1) as u16) << 8
.read_u16::<LittleEndian>()
.unwrap()
} }
fn read_8(&self, addr: Addr) -> u8 { fn read_8(&self, addr: Addr) -> u8 {
(&self.mem[addr as usize..])[0] self.mem[addr as usize]
} }
fn write_32(&mut self, addr: Addr, value: u32) { fn write_32(&mut self, addr: Addr, value: u32) {
(&mut self.mem[addr as usize..]) self.write_16(addr, (value & 0xffff) as u16);
.write_u32::<LittleEndian>(value) self.write_16(addr + 2, (value >> 16) as u16);
.unwrap()
} }
fn write_16(&mut self, addr: Addr, value: u16) { fn write_16(&mut self, addr: Addr, value: u16) {
(&mut self.mem[addr as usize..]) self.write_8(addr, (value & 0xff) as u8);
.write_u16::<LittleEndian>(value) self.write_8(addr + 1, ((value >> 8) & 0xff) as u8);
.unwrap()
} }
fn write_8(&mut self, addr: Addr, value: u8) { fn write_8(&mut self, addr: Addr, value: u8) {
(&mut self.mem[addr as usize..]).write_u8(value).unwrap() self.mem[addr as usize] = value;
} }
} }