mirror of
https://github.com/mre/mos6502.git
synced 2024-11-25 02:33:26 +00:00
remove get_byte_mut_ref method from Memory
This is the right thing to do, because the actual hardware will perform a read and then perform a write. This could have observable side effects on a real system
This commit is contained in:
parent
766143d52f
commit
131b0f312d
42
src/cpu.rs
42
src/cpu.rs
@ -103,10 +103,9 @@ impl CPU {
|
|||||||
self.registers.accumulator = val as i8;
|
self.registers.accumulator = val as i8;
|
||||||
}
|
}
|
||||||
(Instruction::ASL, OpInput::UseAddress(addr)) => {
|
(Instruction::ASL, OpInput::UseAddress(addr)) => {
|
||||||
CPU::shift_left_with_flags(
|
let mut operand: u8 = self.memory.get_byte(addr);
|
||||||
self.memory.get_byte_mut_ref(addr),
|
CPU::shift_left_with_flags(&mut operand, &mut self.registers.status);
|
||||||
&mut self.registers.status,
|
self.memory.set_byte(addr, operand);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(Instruction::BCC, OpInput::UseRelative(rel)) => {
|
(Instruction::BCC, OpInput::UseRelative(rel)) => {
|
||||||
@ -208,10 +207,9 @@ impl CPU {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(Instruction::DEC, OpInput::UseAddress(addr)) => {
|
(Instruction::DEC, OpInput::UseAddress(addr)) => {
|
||||||
CPU::decrement(
|
let mut operand: u8 = self.memory.get_byte(addr);
|
||||||
self.memory.get_byte_mut_ref(addr),
|
CPU::decrement(&mut operand, &mut self.registers.status);
|
||||||
&mut self.registers.status,
|
self.memory.set_byte(addr, operand);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(Instruction::DEY, OpInput::UseImplied) => {
|
(Instruction::DEY, OpInput::UseImplied) => {
|
||||||
@ -231,10 +229,9 @@ impl CPU {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(Instruction::INC, OpInput::UseAddress(addr)) => {
|
(Instruction::INC, OpInput::UseAddress(addr)) => {
|
||||||
CPU::increment(
|
let mut operand: u8 = self.memory.get_byte(addr);
|
||||||
self.memory.get_byte_mut_ref(addr),
|
CPU::increment(&mut operand, &mut self.registers.status);
|
||||||
&mut self.registers.status,
|
self.memory.set_byte(addr, operand);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
(Instruction::INX, OpInput::UseImplied) => {
|
(Instruction::INX, OpInput::UseImplied) => {
|
||||||
CPU::increment(&mut self.registers.index_x, &mut self.registers.status);
|
CPU::increment(&mut self.registers.index_x, &mut self.registers.status);
|
||||||
@ -282,10 +279,9 @@ impl CPU {
|
|||||||
self.registers.accumulator = val as i8;
|
self.registers.accumulator = val as i8;
|
||||||
}
|
}
|
||||||
(Instruction::LSR, OpInput::UseAddress(addr)) => {
|
(Instruction::LSR, OpInput::UseAddress(addr)) => {
|
||||||
CPU::shift_right_with_flags(
|
let mut operand: u8 = self.memory.get_byte(addr);
|
||||||
self.memory.get_byte_mut_ref(addr),
|
CPU::shift_right_with_flags(&mut operand, &mut self.registers.status);
|
||||||
&mut self.registers.status,
|
self.memory.set_byte(addr, operand);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(Instruction::ORA, OpInput::UseImmediate(val)) => {
|
(Instruction::ORA, OpInput::UseImmediate(val)) => {
|
||||||
@ -327,10 +323,9 @@ impl CPU {
|
|||||||
self.registers.accumulator = val as i8;
|
self.registers.accumulator = val as i8;
|
||||||
}
|
}
|
||||||
(Instruction::ROL, OpInput::UseAddress(addr)) => {
|
(Instruction::ROL, OpInput::UseAddress(addr)) => {
|
||||||
CPU::rotate_left_with_flags(
|
let mut operand: u8 = self.memory.get_byte(addr);
|
||||||
self.memory.get_byte_mut_ref(addr),
|
CPU::rotate_left_with_flags(&mut operand, &mut self.registers.status);
|
||||||
&mut self.registers.status,
|
self.memory.set_byte(addr, operand);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
(Instruction::ROR, OpInput::UseImplied) => {
|
(Instruction::ROR, OpInput::UseImplied) => {
|
||||||
// Accumulator mode
|
// Accumulator mode
|
||||||
@ -339,10 +334,9 @@ impl CPU {
|
|||||||
self.registers.accumulator = val as i8;
|
self.registers.accumulator = val as i8;
|
||||||
}
|
}
|
||||||
(Instruction::ROR, OpInput::UseAddress(addr)) => {
|
(Instruction::ROR, OpInput::UseAddress(addr)) => {
|
||||||
CPU::rotate_right_with_flags(
|
let mut operand: u8 = self.memory.get_byte(addr);
|
||||||
self.memory.get_byte_mut_ref(addr),
|
CPU::rotate_right_with_flags(&mut operand, &mut self.registers.status);
|
||||||
&mut self.registers.status,
|
self.memory.set_byte(addr, operand);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(Instruction::SBC, OpInput::UseImmediate(val)) => {
|
(Instruction::SBC, OpInput::UseImmediate(val)) => {
|
||||||
|
@ -69,10 +69,6 @@ impl Memory {
|
|||||||
self.bytes[address as usize]
|
self.bytes[address as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_byte_mut_ref(&mut self, address: u16) -> &mut u8 {
|
|
||||||
&mut self.bytes[address as usize]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_slice(&self, start: u16, diff: u16) -> &[u8] {
|
pub fn get_slice(&self, start: u16, diff: u16) -> &[u8] {
|
||||||
let orig: usize = start.into();
|
let orig: usize = start.into();
|
||||||
let end = orig + diff as usize;
|
let end = orig + diff as usize;
|
||||||
|
Loading…
Reference in New Issue
Block a user