From a8edf40b96db58902b39aa249613b84b09d5779e Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Wed, 30 Aug 2023 13:41:15 +0200 Subject: [PATCH] cpu/decoder - Unify code for ALU n ops --- cpu/decoder.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/cpu/decoder.cpp b/cpu/decoder.cpp index 03e9eca..926e1af 100644 --- a/cpu/decoder.cpp +++ b/cpu/decoder.cpp @@ -97,6 +97,12 @@ void Cpu::executeInstruction() aluop8(aluop, rhs); } + else if((op & 0xC7) == 0xC6) // ADD n, ADC n, SUB n, SBC n, AND n, XOR n, OR n, CP n + { + AluOp aluop = (AluOp)((op >> 3) & 0x3); + aluop8(aluop, readPC8()); + mcycles = 2; + } else if((op & 0xC6) == 0x04) // INC r; INC [HL]; DEC r; DEC [HL]; { AluOp aluop = (op & 0x1) ? SUB : ADD; @@ -387,22 +393,6 @@ void Cpu::executeInstruction() bus->write16(readPC16(), state.SP); mcycles = 5; break; case 0xF9: // LD SP, HL state.SP = state.HL; mcycles = 2; break; - case 0xC6: // ADD n - aluop8(ADD, readPC8()); mcycles = 2; break; - case 0xD6: // SUB n - aluop8(SUB, readPC8()); mcycles = 2; break; - case 0xE6: // AND n - aluop8(AND, readPC8()); mcycles = 2; break; - case 0xF6: // OR n - aluop8(OR, readPC8()); mcycles = 2; break; - case 0xCE: // ADC n - aluop8(ADC, readPC8()); mcycles = 2; break; - case 0xDE: // SBC n - aluop8(SBC, readPC8()); mcycles = 2; break; - case 0xEE: // XOR n - aluop8(XOR, readPC8()); mcycles = 2; break; - case 0xFE: // CP n - aluop8(CP, readPC8()); mcycles = 2; break; case 0x3F: // CCF complement carry flag state.carry = !state.carry; state.subtract = false;