Hi everyone
Here is a screenshot of the nestest.nes rom completed in my emulator
As you can see, many of the tests fail, but the test numbers that are indicated are mostly all just general failiures, such as "SBC # Failiure", so it's difficult to track down exactly what is wrong. I'll start with the first error, 73. This is listed here as an SBC # Faliure. Here is my SBC instruction as it stands at the moment.
Assuming all the various addressing modes are correct, the only problem i can think of is that the overflow being set for a signed underflow as well. (ie should only be set if the result is more that 127 and not less than -128 as well? Im not sure...). I really can't see the problem here, can anyone else spot any problems with this code?
thanks
Here is a screenshot of the nestest.nes rom completed in my emulator
As you can see, many of the tests fail, but the test numbers that are indicated are mostly all just general failiures, such as "SBC # Failiure", so it's difficult to track down exactly what is wrong. I'll start with the first error, 73. This is listed here as an SBC # Faliure. Here is my SBC instruction as it stands at the moment.
Code:
void NesMainClass::_SBC(u8 toSub, int cycles)
{
cpuCycles += cycles;
// Store the A register
u8 beforeSub = regs->A;
// Do the subtraction
regs->A -= toSub;
// Subtract one more if carry is clear
if (!TestBit(regs->P, FLAG_C))
regs->A--;
// Is the Negative/Sign bit set?
regs->P = (TestBit(regs->A, 7)) ?
SET_N_FLAG : CLR_N_FLAG;
// Is the result zero?
regs->P = (regs->A == 0) ?
SET_Z_FLAG : CLR_Z_FLAG;
// Was there a borrow
regs->P = (beforeSub - toSub >= 0) ?
SET_C_FLAG : CLR_C_FLAG;
// The Overflow flag works by indicating whether there was a sign overflow
// i.e The result was outside the range of -128 to 127
regs->P = (regs->A > 127 || (s8)beforeSub + TestBit(regs->P, FLAG_C) -1 - (s8)toSub < -128) ?
SET_V_FLAG : CLR_V_FLAG;
}
{
cpuCycles += cycles;
// Store the A register
u8 beforeSub = regs->A;
// Do the subtraction
regs->A -= toSub;
// Subtract one more if carry is clear
if (!TestBit(regs->P, FLAG_C))
regs->A--;
// Is the Negative/Sign bit set?
regs->P = (TestBit(regs->A, 7)) ?
SET_N_FLAG : CLR_N_FLAG;
// Is the result zero?
regs->P = (regs->A == 0) ?
SET_Z_FLAG : CLR_Z_FLAG;
// Was there a borrow
regs->P = (beforeSub - toSub >= 0) ?
SET_C_FLAG : CLR_C_FLAG;
// The Overflow flag works by indicating whether there was a sign overflow
// i.e The result was outside the range of -128 to 127
regs->P = (regs->A > 127 || (s8)beforeSub + TestBit(regs->P, FLAG_C) -1 - (s8)toSub < -128) ?
SET_V_FLAG : CLR_V_FLAG;
}
Assuming all the various addressing modes are correct, the only problem i can think of is that the overflow being set for a signed underflow as well. (ie should only be set if the result is more that 127 and not less than -128 as well? Im not sure...). I really can't see the problem here, can anyone else spot any problems with this code?
thanks