Fix subtraction bug

This commit is contained in:
Tony Di Nucci 2019-04-20 12:54:54 +01:00
parent e6abdd2dd8
commit ade6eaec6d

View File

@ -95,8 +95,10 @@ namespace emu_6502 {
}
void MathsOpcodeHandlerContainer::sbc(Machine& machine, uint8_t value) {
// subtract is same as add negative value (i.e. add accumulator to the twos compliment of 'value')
adc(machine, (0xFF ^ value) + 1);
// subtract is same as add negative value (i.e. add accumulator to the twos compliment of 'value').
// an added complication here is that the inversion of the carry flag is used to indicate a borrow
uint8_t add = machine.get_cpu().get_ps().is_carry_set() ? 0 : 1;
adc(machine, (0xFF ^ value) + add);
}
void MathsOpcodeHandlerContainer::sbc_imm(Machine& machine) {