mirror of
https://github.com/pevans/erc-c.git
synced 2025-02-11 14:30:40 +00:00
Rework overflow logic, and add missing handling
This commit is contained in:
parent
0ccabda71e
commit
6653da3c20
@ -23,7 +23,14 @@ DEFINE_INST(adc)
|
|||||||
MOS_CARRY_BIT();
|
MOS_CARRY_BIT();
|
||||||
|
|
||||||
vm_8bit result = cpu->A + oper + carry;
|
vm_8bit result = cpu->A + oper + carry;
|
||||||
MOS_CHECK_NVZ(cpu->A, result);
|
MOS_CHECK_NZ(result);
|
||||||
|
|
||||||
|
cpu->P &= ~MOS_OVERFLOW;
|
||||||
|
if (((cpu->A ^ oper) & 0x80) &&
|
||||||
|
((cpu->A ^ result) & 0x80)
|
||||||
|
) {
|
||||||
|
cpu->P |= MOS_OVERFLOW;
|
||||||
|
}
|
||||||
|
|
||||||
// Carry has different meanings in different contexts... in ADC,
|
// Carry has different meanings in different contexts... in ADC,
|
||||||
// carry is set if the result requires a ninth bit (the carry bit!)
|
// carry is set if the result requires a ninth bit (the carry bit!)
|
||||||
@ -75,6 +82,13 @@ DEFINE_INST(adc_dec)
|
|||||||
// are decimal in hexadecimal form.
|
// are decimal in hexadecimal form.
|
||||||
vm_8bit result = ((modsum / 10) << 4) | (modsum % 10);
|
vm_8bit result = ((modsum / 10) << 4) | (modsum % 10);
|
||||||
|
|
||||||
|
cpu->P &= ~MOS_OVERFLOW;
|
||||||
|
if (((cpu->A ^ sum) & 0x80) &&
|
||||||
|
((cpu->A ^ result) & 0x80)
|
||||||
|
) {
|
||||||
|
cpu->P |= MOS_OVERFLOW;
|
||||||
|
}
|
||||||
|
|
||||||
// As you can see, decimal comports a different meaning for the
|
// As you can see, decimal comports a different meaning for the
|
||||||
// carry bit than its binary version
|
// carry bit than its binary version
|
||||||
cpu->P &= ~MOS_CARRY;
|
cpu->P &= ~MOS_CARRY;
|
||||||
@ -242,8 +256,8 @@ DEFINE_INST(sbc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cpu->P &= ~MOS_OVERFLOW;
|
cpu->P &= ~MOS_OVERFLOW;
|
||||||
if ((cpu->A & 0x80) != (oper & 0x80) &&
|
if (((cpu->A ^ oper) & 0x80) &&
|
||||||
(cpu->A & 0x80) != (result8 & 0x80)
|
((cpu->A ^ result8) & 0x80)
|
||||||
) {
|
) {
|
||||||
cpu->P |= MOS_OVERFLOW;
|
cpu->P |= MOS_OVERFLOW;
|
||||||
}
|
}
|
||||||
@ -298,5 +312,15 @@ DEFINE_INST(sbc_dec)
|
|||||||
vm_8bit result = ((diff / 10) << 4) | (diff % 10);
|
vm_8bit result = ((diff / 10) << 4) | (diff % 10);
|
||||||
MOS_CHECK_Z(result);
|
MOS_CHECK_Z(result);
|
||||||
|
|
||||||
|
// This is a bit of an odd sequence... but overflow in decimal is a
|
||||||
|
// bit odd to begin with. I ended up replicating the behavior of
|
||||||
|
// AppleWin here.
|
||||||
|
cpu->P &= ~MOS_OVERFLOW;
|
||||||
|
if (((cpu->A ^ diff) & 0x80) &&
|
||||||
|
((cpu->A ^ result) & 0x80)
|
||||||
|
) {
|
||||||
|
cpu->P |= MOS_OVERFLOW;
|
||||||
|
}
|
||||||
|
|
||||||
cpu->A = result;
|
cpu->A = result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user