Esempio n. 1
0
 private static void ForEachRegister(Action <Register8Table> action)
 {
     for (Register8Table reg = Register8Table.B; reg <= Register8Table.A; reg++)
     {
         action(reg);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
     }
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
                }
            }
        }
Esempio n. 8
0
        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);
                }
            }
        }
Esempio n. 9
0
        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;
            }
        }
Esempio n. 10
0
        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;
            }
        }
Esempio n. 11
0
        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.");
                }
            }
        }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
 public void DoShiftRotate(ShiftRotateOperations shiftRotate, Register8Table reg)
 {
     _primarySet[reg] = DoShiftRotate(shiftRotate, _primarySet[reg]);
 }