From a255b093e9f42fdb89953a0b975831fd238b4d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Thu, 2 Feb 2017 22:54:34 +0100 Subject: [PATCH] Fix overflow flag for SBC. --- src/emulation.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/emulation.c b/src/emulation.c index 3276d1f..57bea36 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -804,13 +804,11 @@ emul_sbc(rk65c02emu_t *e, void *id, instruction_t *i) if (!(e->regs.P & P_CARRY)) res--; - if ((e->regs.A ^ res) & (arg ^ res) & 0x80) + if ((e->regs.A ^ res) & ((0xFF-arg) ^ res) & 0x80) e->regs.P |= P_SIGN_OVERFLOW; else e->regs.P &= ~P_SIGN_OVERFLOW; - printf("res is %x\n", res); - /* if the result does not fit into 8 bits then clear carry */ if (res & 0x8000) e->regs.P &= ~P_CARRY;