1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-06-01 05:41:27 +00:00

Fix overflow flag for SBC.

This commit is contained in:
Radosław Kujawa 2017-02-02 22:54:34 +01:00
parent 1b936f087e
commit a255b093e9

View File

@ -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;