Prevent crashing on debug

This commit is contained in:
Franco Colmenarez 2021-10-22 09:56:54 -05:00
parent 707e9d76e1
commit d655442b9a
2 changed files with 6 additions and 6 deletions

View File

@ -76,7 +76,7 @@ impl Bus {
} }
pub fn read_16bit(&self, address: u16) -> u16 { pub fn read_16bit(&self, address: u16) -> u16 {
join_bytes(self.read(address + 1), self.read(address)) join_bytes(self.read(address.wrapping_add(1)), self.read(address))
} }
pub fn write(&mut self, address: u16, data: u8) { pub fn write(&mut self, address: u16, data: u8) {
@ -105,6 +105,6 @@ impl Bus {
pub fn write_16bit(&mut self, address: u16, data: u16) { pub fn write_16bit(&mut self, address: u16, data: u16) {
let bytes = data.to_le_bytes(); let bytes = data.to_le_bytes();
self.write(address, bytes[0]); self.write(address, bytes[0]);
self.write(address + 1, bytes[1]); self.write(address.wrapping_add(1), bytes[1]);
} }
} }

View File

@ -227,9 +227,9 @@ impl OpcodeParameterBytes {
pub fn from_address(address: u16, bus: &Bus)-> OpcodeParameterBytes { pub fn from_address(address: u16, bus: &Bus)-> OpcodeParameterBytes {
OpcodeParameterBytes( OpcodeParameterBytes(
bus.read(address), bus.read(address),
bus.read(address + 1), bus.read(address.wrapping_add(1)),
bus.read(address + 2), bus.read(address.wrapping_add(2)),
bus.read(address + 3), bus.read(address.wrapping_add(3)),
) )
} }
@ -872,7 +872,7 @@ impl CPU {
// self.log(parameter_bytes); // self.log(parameter_bytes);
self.increment_cycles(cycles); self.increment_cycles(cycles);
self.exec(opcode, bus); self.exec(opcode, bus);
self.increment_exec_calls_count(); // self.increment_exec_calls_count();
} }
pub fn exec(&mut self, opcode: Opcode, bus: &mut Bus) { pub fn exec(&mut self, opcode: Opcode, bus: &mut Bus) {