mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-23 07:30:31 +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);
|
arg = instruction_data_read_1(e, (instrdef_t *) id, i);
|
||||||
res = e->regs.A - arg;
|
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--;
|
res--;
|
||||||
|
|
||||||
if ((e->regs.A ^ res) & (arg ^ res) & 0x80)
|
if ((e->regs.A ^ res) & (arg ^ res) & 0x80)
|
||||||
@ -808,11 +809,13 @@ emul_sbc(rk65c02emu_t *e, void *id, instruction_t *i)
|
|||||||
else
|
else
|
||||||
e->regs.P &= ~P_SIGN_OVERFLOW;
|
e->regs.P &= ~P_SIGN_OVERFLOW;
|
||||||
|
|
||||||
/* if the result does not fit into 8 bits then set carry */
|
printf("res is %x\n", res);
|
||||||
if (res > 0xFF)
|
|
||||||
e->regs.P |= P_CARRY;
|
/* if the result does not fit into 8 bits then clear carry */
|
||||||
else
|
if (res & 0x8000)
|
||||||
e->regs.P &= ~P_CARRY;
|
e->regs.P &= ~P_CARRY;
|
||||||
|
else
|
||||||
|
e->regs.P |= P_CARRY;
|
||||||
|
|
||||||
/* squash the result into accumulator's 8 bits, lol */
|
/* squash the result into accumulator's 8 bits, lol */
|
||||||
e->regs.A = (uint8_t) res;
|
e->regs.A = (uint8_t) res;
|
||||||
|
Loading…
Reference in New Issue
Block a user