I'm attempting to create the MOS6502's ADC instruction in Java. More specifically the ADC decimal instruction, which uses BCD integer representation instead of 2's complement representation. This instruction is being modified to only be concerned with adding 8-bit numbers, not 16-bit like the normal instruction would.
I have the following code below that works successfully for adding 1+1 but outputs a 0 when attempting to add $49 (73) and 1 together, I'm not sure why this is happening.
In these tests, the carry bit is always set to 0.
private int adcDecimal(int a, int op)
{
System.out.println("[CPU] ADC-Decimal: " + a + " + " + op + " + " + getCarryBit());
int tmp;
int result;
tmp = (a & 0x0f) + (op & 0x0f) + getCarryBit();
if((tmp & 0xff) > 9)
tmp += 6;
result = (tmp & 0x0f);
result &= 0xff;
setCarryFlag(tmp > 7);
setZeroFlag(result == 0);
setOverflowFlag(false);
negativeFlag = (result & 0x80) != 0;
System.out.println("[CPU] ADC-Decimal result: " + result);
return result;
}