mirror of
https://github.com/mre/mos6502.git
synced 2024-11-28 07:49:19 +00:00
commit
a6c59c3ff1
@ -291,6 +291,14 @@ impl Machine {
|
||||
&mut self.registers.status);
|
||||
}
|
||||
|
||||
(Instruction::ORA, OpInput::UseImmediate(val)) => {
|
||||
self.inclusive_or(val);
|
||||
}
|
||||
(Instruction::ORA, OpInput::UseAddress(addr)) => {
|
||||
let val = self.memory.get_byte(addr);
|
||||
self.inclusive_or(val);
|
||||
}
|
||||
|
||||
(Instruction::PHA, OpInput::UseImplied) => {
|
||||
// Push accumulator
|
||||
let val = self.registers.accumulator as u8;
|
||||
@ -701,6 +709,11 @@ impl Machine {
|
||||
self.load_accumulator(a_after);
|
||||
}
|
||||
|
||||
fn inclusive_or(&mut self, val: u8) {
|
||||
let a_after = self.registers.accumulator | (val as i8);
|
||||
self.load_accumulator(a_after);
|
||||
}
|
||||
|
||||
fn push_on_stack(&mut self, val: u8) {
|
||||
let addr = self.registers.stack_pointer.to_address();
|
||||
self.memory.set_byte(addr, val);
|
||||
@ -1239,3 +1252,33 @@ fn exclusive_or_test() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inclusive_or_test() {
|
||||
let mut machine = Machine::new();
|
||||
|
||||
for a_before in range(0u8, 255u8) {
|
||||
for val in range(0u8, 255u8) {
|
||||
machine.execute_instruction(
|
||||
(Instruction::LDA, OpInput::UseImmediate(a_before))
|
||||
);
|
||||
|
||||
machine.inclusive_or(val);
|
||||
|
||||
let a_after = a_before | val;
|
||||
assert_eq!(machine.registers.accumulator, a_after as i8);
|
||||
|
||||
if a_after == 0 {
|
||||
assert!(machine.registers.status.contains(PS_ZERO));
|
||||
} else {
|
||||
assert!(!machine.registers.status.contains(PS_ZERO));
|
||||
}
|
||||
|
||||
if (a_after as i8) < 0 {
|
||||
assert!(machine.registers.status.contains(PS_NEGATIVE));
|
||||
} else {
|
||||
assert!(!machine.registers.status.contains(PS_NEGATIVE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user