diff --git a/cpu/decoder.cpp b/cpu/decoder.cpp index 73587f2..a68cf39 100644 --- a/cpu/decoder.cpp +++ b/cpu/decoder.cpp @@ -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