fix ADC bug where V is calculated with new A instead of old A
This commit is contained in:
parent
f16ab6cb6d
commit
5d36aeb885
3
cpu.c
3
cpu.c
@ -218,11 +218,12 @@ adc(uint8_t arg)
|
|||||||
uint16_t sum; // 16-bit sum makes it easier to determine carry flag
|
uint16_t sum; // 16-bit sum makes it easier to determine carry flag
|
||||||
|
|
||||||
sum = regs.a + arg + regs.status.carry;
|
sum = regs.a + arg + regs.status.carry;
|
||||||
regs.a = sum & 0xFF;
|
|
||||||
|
|
||||||
regs.status.carry = sum > 0xFF;
|
regs.status.carry = sum > 0xFF;
|
||||||
/* overflow flag formula: https://stackoverflow.com/a/29224684 */
|
/* overflow flag formula: https://stackoverflow.com/a/29224684 */
|
||||||
regs.status.overflow = (~(regs.a ^ arg) & (regs.a ^ sum) & 0x80) != 0;
|
regs.status.overflow = (~(regs.a ^ arg) & (regs.a ^ sum) & 0x80) != 0;
|
||||||
|
regs.a = sum & 0xFF;
|
||||||
|
|
||||||
STATUS_UPDATE_ZERO(regs.a);
|
STATUS_UPDATE_ZERO(regs.a);
|
||||||
STATUS_UPDATE_NEGATIVE(regs.a);
|
STATUS_UPDATE_NEGATIVE(regs.a);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user