Beispiel #1
0
        private static void Transfer(OpCode op, bool decrement, bool isOutput)
        {
            using (var fixture = new ExecuteFixture())
            {
                fixture.Operation.OpCode(op);

                if (isOutput)
                {
                    fixture.With(c => c.Mmu.Setup(x => x.ReadByte(c.Registers.HL)).Returns(c.Byte).Verifiable());
                    fixture.Assert(c => c.Io.Verify(x => x.WriteByteToPort(c.Registers.C, c.InitialRegisters.B, c.Byte)));
                }
                else
                {
                    fixture.With(c => c.Io.Setup(x => x.ReadByteFromPort(c.Registers.C, c.InitialRegisters.B)).Returns(c.Byte).Verifiable());
                    fixture.Assert(c => c.Mmu.Verify(x => x.WriteByte(c.InitialRegisters.HL, c.Byte)));
                }


                fixture.Assert(c => c.Registers.B.ShouldBe(unchecked ((byte)(c.InitialRegisters.B - 1))));
                fixture.AssertFlags(c => c.Registers.B, subtract: true, setResult: true);

                if (decrement)
                {
                    fixture.Assert(c => c.Registers.HL.ShouldBe(unchecked ((ushort)(c.InitialRegister16(Operand.HL) - 1))));
                }
                else
                {
                    fixture.Assert(c => c.Registers.HL.ShouldBe(unchecked ((ushort)(c.InitialRegister16(Operand.HL) + 1))));
                }
            }
        }
Beispiel #2
0
 private static void FlagAflection(OpCode op, bool?sign = null, bool?zero     = null, bool?halfCarry = null,
                                   bool?parityOverflow  = null, bool?subtract = null, bool?carry     = null)
 {
     using (var fixture = new ExecuteFixture())
     {
         fixture.Operation.OpCode(op);
         fixture.AssertFlags(c => c.Accumulator.A, sign, zero, halfCarry, parityOverflow, subtract, carry);
     }
 }
Beispiel #3
0
 public void NegateOnesComplement()
 {
     using (var fixture = new ExecuteFixture())
     {
         fixture.Operation.OpCode(OpCode.NegateOnesComplement);
         fixture.Assert(c => c.Accumulator.A.ShouldBe((byte)~c.InitialAccumulator.A));
         fixture.AssertFlags(c => c.Accumulator.A, halfCarry: true, subtract: true);
     }
 }
Beispiel #4
0
        private static void TestCallAssign(OpCode op, Expression <Func <IAlu, byte, byte> > f, bool alternativeFlags = false)
        {
            using (var fixture = new ExecuteFixture())
            {
                fixture.Operation.OpCode(op).RandomRegister(out var o).RandomLiterals().UseAlternativeFlagAffection(alternativeFlags);
                fixture.With(c => c.Alu.Setup(c.Alu8Call(f, o)).Returns(c.Byte).Verifiable());
                fixture.Assert(c => c.Operand8(o).ShouldBe(c.Byte));

                if (alternativeFlags)
                {
                    fixture.AssertFlags(zero: false, sign: false);
                }
            }
        }
Beispiel #5
0
        public void Transfer(OpCode op, bool decrement, bool overflow)
        {
            using (var fixture = new ExecuteFixture())
            {
                fixture.Operation.OpCode(op);
                fixture.With(c => c.Registers.BC = (ushort)(overflow ? 2 : 1));
                fixture.Assert(c => c.Mmu.Verify(x => x.TransferByte(c.InitialRegisters.HL, c.InitialRegisters.DE)),
                               c => c.Registers.BC.ShouldBe((ushort)(overflow ? 1 : 0)));

                if (decrement)
                {
                    fixture.Assert(c => c.Registers.HL.ShouldBe(unchecked ((ushort)(c.InitialRegisters.HL - 1))),
                                   c => c.Registers.DE.ShouldBe(unchecked ((ushort)(c.InitialRegisters.DE - 1))));
                }
                else
                {
                    fixture.Assert(c => c.Registers.HL.ShouldBe(unchecked ((ushort)(c.InitialRegisters.HL + 1))),
                                   c => c.Registers.DE.ShouldBe(unchecked ((ushort)(c.InitialRegisters.DE + 1))));
                }

                fixture.AssertFlags(halfCarry: false, parityOverflow: overflow, subtract: false);
            }
        }