mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-13 01:29:57 +00:00
Make SBC somewhat less broken.
This commit is contained in:
parent
436810b79f
commit
8e732f3b94
@ -800,7 +800,8 @@ emul_sbc(rk65c02emu_t *e, void *id, instruction_t *i)
|
||||
arg = instruction_data_read_1(e, (instrdef_t *) id, i);
|
||||
res = e->regs.A - arg;
|
||||
|
||||
if (e->regs.P & P_CARRY)
|
||||
/* if the carry flag is NOT set then "borrow" */
|
||||
if (!(e->regs.P & P_CARRY))
|
||||
res--;
|
||||
|
||||
if ((e->regs.A ^ res) & (arg ^ res) & 0x80)
|
||||
@ -808,11 +809,13 @@ emul_sbc(rk65c02emu_t *e, void *id, instruction_t *i)
|
||||
else
|
||||
e->regs.P &= ~P_SIGN_OVERFLOW;
|
||||
|
||||
/* if the result does not fit into 8 bits then set carry */
|
||||
if (res > 0xFF)
|
||||
e->regs.P |= P_CARRY;
|
||||
else
|
||||
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;
|
||||
else
|
||||
e->regs.P |= P_CARRY;
|
||||
|
||||
/* squash the result into accumulator's 8 bits, lol */
|
||||
e->regs.A = (uint8_t) res;
|
||||
|
Loading…
Reference in New Issue
Block a user