cpu/decoder - Fix DAA

This commit is contained in:
madmaurice 2023-09-09 15:42:46 +02:00
parent 9c20befc60
commit 7bc272afb6

View file

@ -371,16 +371,18 @@ void Cpu::executeInstruction()
case 0x27: // DAA
{
u16 corr = 0;
if (state.halfcarry || ((state.A & 0x0F) > 0x9))
corr |= 0x06;
if ((state.A & 0xF0) > 0x90)
if (state.halfcarry || (!state.subtract && (state.A & 0x0F) > 0x9))
corr |= 0x06;
if (state.carry || (!state.subtract && state.A > 0x99))
{
corr |= 0x60;
state.carry = true;
}
u32 res16 = (u16)state.A + (state.subtract ? (-corr) : corr);
state.A = (u8)res16;
state.halfcarry = false;
state.zero = (state.A == 0);
state.carry = (res16 & 0x100);
}
break;
case 0x2F: // CPL Complement accumulator