private static void ForEachRegister(Action <Register8Table> action) { for (Register8Table reg = Register8Table.B; reg <= Register8Table.A; reg++) { action(reg); } }
private void LD_Test(Register8Table trgReg, Register8Table srcReg) { var ob = OpcodeByte.New(x: 1, z: (byte)srcReg, y: (byte)trgReg); var cpuZ80 = ExecuteTest(ob, (cpu) => cpu.Registers[srcReg] = Value); cpuZ80.Registers[trgReg].Should().Be(Value); }
private static void ExecuteTest(byte x, byte extension, bool bitValue, Func <Register8Table, byte, byte> calcExpected, bool expectedZero, Register8Table reg, int bit) { var ob = OpcodeByte.New(x: x, z: (byte)reg, y: (byte)bit); var model = ExecuteTest(ob, (byte)(bitValue ? 0xFF : 0), (cpu) => { if (extension == IX) { cpu.Registers.IX = Address; } if (extension == IY) { cpu.Registers.IY = Address; } }, extension); var expectedValue = calcExpected(reg, (byte)bit); if (reg != Register8Table.HL && x != 1 /*bit*/) { model.Cpu.Registers[reg].Should().Be(expectedValue, "bit: " + bit + " reg: " + reg.ToString()); } model.Memory.Assert(ExpectedAddress, expectedValue); model.Cpu.Registers.Flags.Z.Should().Be(expectedZero); }
private void TestMathOperation(MathOperations mathOp, byte expectedValue, byte expectedValueA, Action <RegisterFlags, Register8Table> assertFlags, bool carry) { for (Register8Table reg = Register8Table.B; reg <= Register8Table.A; reg++) { if (reg == Register8Table.HL) { continue; } var cpu = ExecuteTest(mathOp, reg, (m) => { m.Cpu.Registers.Flags.C = carry; m.Cpu.Registers[reg] = Value; }); if (reg == Register8Table.A) { cpu.Registers.A.Should().Be(expectedValueA); } else { cpu.Registers.A.Should().Be(expectedValue); cpu.Registers[reg].Should().Be(Value); } assertFlags(cpu.Registers.Flags, reg); } }
private static void ForEachRegister(Action <Register8Table> action) { for (Register8Table reg = Register8Table.B; reg <= Register8Table.A; reg++) { if (reg == Register8Table.HL) { continue; } action(reg); } }
private static ushort CreateValue(byte bit, Register8Table reg, bool bitValue) { var regValue = (1 << bit); //if (!bitValue) regValue = ~regValue; switch (reg) { case Register8Table.B: case Register8Table.D: case Register8Table.H: regValue <<= 8; break; } return((ushort)regValue); }
private void TestAll(bool bitValue) { for (Register8Table reg = Register8Table.B; reg <= Register8Table.A; reg++) { if (reg == Register8Table.HL) { continue; } for (byte bit = 0; bit < 8; bit++) { var value = CreateValue(bit, reg, bitValue); var cpu = ExecuteTest(bit, reg, (m) => FillRegister(m.Cpu, reg, value)); AssertRegisters(cpu, reg, value); } } }
private void TestAll() { for (Register8Table trgReg = Register8Table.B; trgReg <= Register8Table.A; trgReg++) { if (trgReg == Register8Table.HL) { continue; } for (Register8Table srcReg = Register8Table.B; srcReg <= Register8Table.A; srcReg++) { if (srcReg == Register8Table.HL) { continue; } LD_Test(trgReg, srcReg); } } }
private void FillRegister(CpuZ80 cpu, Register8Table reg, ushort value) { switch (reg) { case Register8Table.B: case Register8Table.C: cpu.FillRegisters(bc: value); break; case Register8Table.D: case Register8Table.E: cpu.FillRegisters(de: value); break; case Register8Table.H: case Register8Table.L: cpu.FillRegisters(hl: value); break; case Register8Table.A: cpu.FillRegisters(a: (byte)value); break; } }
private void AssertRegisters(CpuZ80 cpu, Register8Table reg, ushort value) { switch (reg) { case Register8Table.B: case Register8Table.C: cpu.AssertRegisters(pc: 2, bc: value); break; case Register8Table.D: case Register8Table.E: cpu.AssertRegisters(pc: 2, de: value); break; case Register8Table.H: case Register8Table.L: cpu.AssertRegisters(pc: 2, hl: value); break; case Register8Table.A: cpu.AssertRegisters(pc: 2, a: (byte)value); break; } }
public byte this[Register8Table register] { get { switch (register) { case Register8Table.B: return(B); case Register8Table.C: return(C); case Register8Table.D: return(D); case Register8Table.E: return(E); case Register8Table.H: return(H); case Register8Table.L: return(L); case Register8Table.A: return(A); default: throw new InvalidOperationException(); } } set { switch (register) { case Register8Table.B: B = value; break; case Register8Table.C: C = value; break; case Register8Table.D: D = value; break; case Register8Table.E: E = value; break; case Register8Table.H: H = value; break; case Register8Table.L: L = value; break; case Register8Table.A: A = value; break; default: throw new InvalidOperationException("Invalid Register index."); } } }
private static CpuZ80 ExecuteTest(MathOperations mathOp, Register8Table register, Action <SimulationModel> fnPreTest) { var ob = OpcodeByte.New(x: 2, z: (byte)register, y: (byte)mathOp); return(ExecuteTest(ob, fnPreTest)); }
private static CpuZ80 ExecuteTest(byte bit, Register8Table register, Action <SimulationModel> fnPreTest) { var ob = OpcodeByte.New(x: 3, y: bit, z: (byte)register); return(ExecuteTest(ob, fnPreTest)); }
public void DoShiftRotate(ShiftRotateOperations shiftRotate, Register8Table reg) { _primarySet[reg] = DoShiftRotate(shiftRotate, _primarySet[reg]); }