Hi.
I'm currently debugging my CPU using the nestest ROM.
According to the ROM output, all addressing modes have issue with the SBC instruction.
However, I just cannot see what's wrong with it, having spent about 2 hours rewriting and rewriting it.
I'd appreciate it if anybody could give me some pointers on where it may be going wrong.
Thank you.
I'm currently debugging my CPU using the nestest ROM.
According to the ROM output, all addressing modes have issue with the SBC instruction.
However, I just cannot see what's wrong with it, having spent about 2 hours rewriting and rewriting it.
I'd appreciate it if anybody could give me some pointers on where it may be going wrong.
Thank you.
Code:
carry = ~P & 0x1;
// Perform the SBC.
newA = A - operand - carry;
// if the sign bit is incorrect, set the overflow flag.
if ((~(A ^ operand) & (A ^ operand) & 0x80) != 0) {
P |= 0x40;
}
// if overflow occurs, clear the carry flag.
if (newA >= 0) {
P |= 0x1;
}
A = newA & 0xFF;
// The zero and negative flags.
if (A == 0) {
P |= 0x2;
}
if ((A & 0x80) == 1) {
P |= 0x80;
}
// Perform the SBC.
newA = A - operand - carry;
// if the sign bit is incorrect, set the overflow flag.
if ((~(A ^ operand) & (A ^ operand) & 0x80) != 0) {
P |= 0x40;
}
// if overflow occurs, clear the carry flag.
if (newA >= 0) {
P |= 0x1;
}
A = newA & 0xFF;
// The zero and negative flags.
if (A == 0) {
P |= 0x2;
}
if ((A & 0x80) == 1) {
P |= 0x80;
}