cpu/decoder - Unify code for ALU n ops

This commit is contained in:
madmaurice 2023-08-30 13:41:15 +02:00
parent 9bc6f935ac
commit a8edf40b96

View file

@ -97,6 +97,12 @@ void Cpu::executeInstruction()
aluop8(aluop, rhs); 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]; else if((op & 0xC6) == 0x04) // INC r; INC [HL]; DEC r; DEC [HL];
{ {
AluOp aluop = (op & 0x1) ? SUB : ADD; AluOp aluop = (op & 0x1) ? SUB : ADD;
@ -387,22 +393,6 @@ void Cpu::executeInstruction()
bus->write16(readPC16(), state.SP); mcycles = 5; break; bus->write16(readPC16(), state.SP); mcycles = 5; break;
case 0xF9: // LD SP, HL case 0xF9: // LD SP, HL
state.SP = state.HL; mcycles = 2; break; 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 case 0x3F: // CCF complement carry flag
state.carry = !state.carry; state.carry = !state.carry;
state.subtract = false; state.subtract = false;