1
0
mirror of https://github.com/mre/mos6502.git synced 2024-06-13 15:29:33 +00:00

implement BIT

This commit is contained in:
Johannes Muenzel 2014-10-25 19:39:36 -04:00
parent acc31f9858
commit 32b1fa5f4b

View File

@ -87,6 +87,28 @@ impl Machine {
self.add_with_carry(val);
},
(instruction::BIT, instruction::UseAddress(addr)) => {
let a: u8 = self.registers.accumulator as u8;
let m: u8 = self.memory.get_byte(addr);
let res = a & m;
// The zero flag is set based on the result of the 'and'.
let is_zero = 0 == res;
// The N flag is set to bit 7 of the byte from memory.
let bit7 = 0 != (0x80 & res);
// The V flag is set to bit 6 of the byte from memory.
let bit6 = 0 != (0x40 & res);
self.registers.status.set_with_mask(
PS_ZERO | PS_NEGATIVE | PS_OVERFLOW,
Status::new(StatusArgs { zero: is_zero,
negative: bit7,
overflow: bit6,
..StatusArgs::none() } ));
}
(instruction::BMI, instruction::UseRelative(rel)) => {
let addr = self.registers.program_counter
+ AddressDiff(rel as i32);