I think that there might be a bug in Mike Chambers' BCD adjustment inside adc():
Code:
//instruction handler functions
static void adc() {
penaltyop = 1;
value = getvalue();
result = (uint16_t)a + value + (uint16_t)(status & FLAG_CARRY);
carrycalc(result);
zerocalc(result);
overflowcalc(result, a, value);
signcalc(result);
#ifndef NES_CPU
if (status & FLAG_DECIMAL) {
clearcarry();
if ((a & 0x0F) > 0x09) {
a += 0x06;
}
if ((a & 0xF0) > 0x90) {
a += 0x60;
setcarry();
}
clockticks6502++;
}
#endif
saveaccum(result);
}
I believe that it always produces a BCD result, but ignores the
half-carry, and will produce the wrong result for something as simple as 9+9 (if I'm reading the code properly, it looks like it will give an answer of $12, regardless of mode). I don't have my compiler handy at the moment, but I think that I'm right.
What do you guys think would be the most efficient method to include the half-carry, especially for an eight-digit version of the same function? I don't consider myself to be a C expert, but it appears to be a bit weak in its handling of carries and half-carries. I know that it can be done, just not very efficiently, at least be me.
BTW, could you share the code that you used to implement the
read6502 and
write6502 external functions?
Thanks,
Mike