1
0
mirror of https://github.com/mre/mos6502.git synced 2025-01-03 15:30:32 +00:00

Merge pull request #23 from amw-zero/ark-and

Implement AND instruction
This commit is contained in:
Andrew Keeton 2014-11-06 19:19:35 -05:00
commit 690907f1c4

View File

@ -88,6 +88,14 @@ impl Machine {
self.add_with_carry(val);
}
(instruction::AND, instruction::UseImmediate(val)) => {
self.and(val as i8);
}
(instruction::AND, instruction::UseAddress(addr)) => {
let val = self.memory.get_byte(addr) as i8;
self.and(val as i8);
}
(instruction::ASL, instruction::UseImplied) => {
// Accumulator mode
let mut val = self.registers.accumulator as u8;
@ -459,6 +467,11 @@ impl Machine {
}
}
fn and(&mut self, value: i8) {
let a_after = self.registers.accumulator & value;
self.load_accumulator(a_after);
}
// TODO: Implement binary-coded decimal
fn subtract_with_carry(&mut self, value: i8) {
if self.registers.status.contains(PS_DECIMAL_MODE) {
@ -628,6 +641,35 @@ fn add_with_carry_test() {
assert_eq!(machine.registers.status.contains(PS_OVERFLOW), true);
}
#[test]
fn and_test() {
let mut machine = Machine::new();
machine.registers.accumulator = 0;
machine.and(-1);
assert_eq!(machine.registers.accumulator, 0);
assert_eq!(machine.registers.status.contains(PS_ZERO), true);
assert_eq!(machine.registers.status.contains(PS_NEGATIVE), false);
machine.registers.accumulator = -1;
machine.and(0);
assert_eq!(machine.registers.accumulator, 0);
assert_eq!(machine.registers.status.contains(PS_ZERO), true);
assert_eq!(machine.registers.status.contains(PS_NEGATIVE), false);
machine.registers.accumulator = -1;
machine.and(0x0f);
assert_eq!(machine.registers.accumulator, 0x0f);
assert_eq!(machine.registers.status.contains(PS_ZERO), false);
assert_eq!(machine.registers.status.contains(PS_NEGATIVE), false);
machine.registers.accumulator = -1;
machine.and(-128);
assert_eq!(machine.registers.accumulator, -128);
assert_eq!(machine.registers.status.contains(PS_ZERO), false);
assert_eq!(machine.registers.status.contains(PS_NEGATIVE), true);
}
#[test]
fn subtract_with_carry_test() {
let mut machine = Machine::new();