fixed a bug in BIT and correctly setting N,Z at some locations

This commit is contained in:
Daniel Bauer
2019-12-27 19:43:38 +01:00
parent 069c6a0fd6
commit 678c6d0092
2 changed files with 5 additions and 5 deletions

View File

@@ -34,7 +34,7 @@ lazy_static! {
} }
fn main() -> Result<(), Error> { fn main() -> Result<(), Error> {
simple_logger::init_with_level(Level::Debug).unwrap(); simple_logger::init_with_level(Level::Info).unwrap();
let mut bus = MemoryBus::new(); let mut bus = MemoryBus::new();
let cartridge = Path::new("test_roms/nestest.nes"); let cartridge = Path::new("test_roms/nestest.nes");

View File

@@ -24,7 +24,7 @@ impl Registers {
y: 0, y: 0,
sp: 0x00FD, sp: 0x00FD,
pc: 0x0000, pc: 0x0000,
flags: 0x0034, flags: 0b00100100,
} }
} }
} }
@@ -173,7 +173,7 @@ impl CPU {
fn set_flag_nz(&mut self, val: Byte) { fn set_flag_nz(&mut self, val: Byte) {
self.set_flag(ZERO, val == 0); self.set_flag(ZERO, val == 0);
self.set_flag(NEGATIVE, (val & 0x80) == 0); self.set_flag(NEGATIVE, (val & NEGATIVE) > 0);
} }
pub fn get_flag(&self, flag: Byte) -> Byte { pub fn get_flag(&self, flag: Byte) -> Byte {
@@ -488,8 +488,8 @@ impl CPU {
// the zeroflag is set to the result of operand AND accumulator. // the zeroflag is set to the result of operand AND accumulator.
fn op_BIT<T: Memory>(&mut self, bus: &T, addr: Word) -> bool { fn op_BIT<T: Memory>(&mut self, bus: &T, addr: Word) -> bool {
let val = self.readb(bus, addr); let val = self.readb(bus, addr);
self.set_flag(OVERFLOW, (val & OVERFLOW) == 1); self.set_flag(OVERFLOW, (val & OVERFLOW) > 1);
self.set_flag(NEGATIVE, (val & NEGATIVE) == 1); self.set_flag(NEGATIVE, (val & NEGATIVE) > 1);
self.set_flag(ZERO, (val & self.regs.a) == 0); self.set_flag(ZERO, (val & self.regs.a) == 0);
false false
} }