From 809e6ca7c61b404fb07ce0ffbb6339750d9e25e5 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 20 Jan 2018 23:47:02 -0600 Subject: [PATCH] Overflow should simply be bit 6's value --- src/mos6502.bits.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mos6502.bits.c b/src/mos6502.bits.c index 8df4317..66bb4ab 100644 --- a/src/mos6502.bits.c +++ b/src/mos6502.bits.c @@ -51,7 +51,19 @@ DEFINE_INST(asl) */ DEFINE_INST(bit) { - mos6502_modify_status(cpu, MOS_NVZ, oper, oper); + // We're just relying on the modify_status function to do negative + // and zero; we also need to do overflow, but overflow is checked in + // a slightly different way with BIT... + mos6502_modify_status(cpu, MOS_NZ, oper, oper); + + // Normally, overflow is handled by checking if bit 7 flipped from 0 + // to 1 or vice versa, and that's done by comparing the result to + // the operand. But in the case of BIT, all we want to know is if + // bit 6 is high. + cpu->P &= ~MOS_OVERFLOW; + if (oper & 0x40) { + cpu->P |= MOS_OVERFLOW; + } } /*