From 3206332a7de868ecd175106dd2864a46d9a2739d Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 21 Jan 2018 16:17:31 -0600 Subject: [PATCH] Set carry if the right-most bit is 1 Don't consider the left-most bit --- src/mos6502.bits.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mos6502.bits.c b/src/mos6502.bits.c index 58c43d4..6d57aca 100644 --- a/src/mos6502.bits.c +++ b/src/mos6502.bits.c @@ -97,8 +97,17 @@ DEFINE_INST(lsr) { SET_RESULT(oper >> 1); - // MOS_NEGATIVE is intentionally not included here. - mos6502_modify_status(cpu, MOS_ZC, oper, result); + // Set ZERO if it should apply + mos6502_modify_status(cpu, MOS_ZERO, oper, result); + + // However, we handle carry a bit differently here. The carry bit + // should be 1 if oper & 0x1; that is, when we shift right, we want + // the right-most bit to be captured in carry, in just the same way + // we want the left-most bit to be captured in carry for ASL. + cpu->P &= ~MOS_CARRY; + if (oper & 0x1) { + cpu->P |= MOS_CARRY; + } if (cpu->eff_addr) { mos6502_set(cpu, cpu->eff_addr, result & 0xff);