public OperationFactory RandomLiterals() { _byteLiteral = Rng.Byte(); _wordLiteral = Rng.Word(); _displacement = Rng.SByte(); return(this); }
private static void LiteralTest(PrimaryOpCode op, OpCode expected, int machineCycles = 2, int throttlingStates = 7) { var literal = Rng.Byte(); using (var fixture = new DecodeFixture(machineCycles, throttlingStates, op, literal)) { fixture.Expected.OpCode(expected).Operands(Operand.n).ByteLiteral(literal); } }
private static void TestByteLiteral(PrimaryOpCode op, OpCode excepted = OpCode.Input) { var literal = Rng.Byte(); using (var fixture = new DecodeFixture(3, 11, op, literal).ThrowOnGameboy()) { fixture.Expected.OpCode(excepted).Operands(Operand.A, Operand.n).ByteLiteral(literal); } }
private static void TestByteLiteral(GameBoyPrimaryOpCode op, Operand o0, Operand o1) { var n = Rng.Byte(); using (var fixture = new DecodeFixture(3, 10, op, n).OnlyGameboy()) { fixture.Expected.OpCode(OpCode.Load).Operands(o0, o1).ByteLiteral(n); } }
public void LD_mIXYd_n(Operand index) { var displacement = Rng.SByte(); var literal = Rng.Byte(); using (var fixture = new DecodeFixture(5, 19, index.GetZ80IndexPrefix(), PrimaryOpCode.LD_mHL_n, displacement, literal).ThrowUnlessZ80()) { fixture.Expected.OpCode(OpCode.Load).Operands(index, Operand.n).ByteLiteral(literal).Displacement(displacement); } }
public void When_reading_8bit_operands(Operand r) { using (var fixture = new ExecuteFixture()) { fixture.Operation.OpCode(OpCode.Load).RandomRegister(out var o).Operand2(r).RandomLiterals(); var value = Rng.Byte(); fixture.With(c => { switch (c.Operation.Operand2) { case Operand.mHL: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.Registers.HL))).Returns(value).Verifiable(); break; case Operand.mIXd: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.MockRegisters.Object.IX + c.Operation.Displacement))).Returns(value).Verifiable(); break; case Operand.mIYd: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.MockRegisters.Object.IY + c.Operation.Displacement))).Returns(value).Verifiable(); break; case Operand.mnn: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.Operation.WordLiteral))).Returns(value).Verifiable(); break; case Operand.mCl: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.Registers.C + 0xff00))).Returns(value).Verifiable(); break; case Operand.mnl: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.Operation.ByteLiteral + 0xff00))).Returns(value).Verifiable(); break; case Operand.mBC: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.Registers.BC))).Returns(value).Verifiable(); break; case Operand.mDE: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.Registers.DE))).Returns(value).Verifiable(); break; case Operand.mSP: c.Mmu.Setup(m => m.ReadByte(It.Is <ushort>(a => a == c.MockRegisters.Object.StackPointer))).Returns(value).Verifiable(); break; default: value = c.Operand8(c.Operation.Operand2); break; } }); fixture.Assert(c => c.Operand8(o).ShouldBe(value)); } }
private static void TransferRepeat(OpCode op, bool decrement, bool isOutput) { using (var fixture = new ExecuteFixture()) { const ushort HL = 100; // Change HL so we don't need to worry about overflow. var repeats = Rng.Byte(2, 10); fixture.Operation.OpCode(op); fixture.With(c => c.Registers.B = repeats, c => c.Registers.HL = HL); fixture.RuntimeTiming((repeats - 1) * 5, (repeats - 1) * 21); if (decrement) { if (isOutput) { fixture.With(c => c.Mmu.Setup(x => x.ReadByte(It.Is <ushort>(a => a <= HL && a > HL - repeats))).Returns <ushort>(a => (byte)(HL - a))); fixture.Assert(c => c.Mmu.Verify(x => x.ReadByte(It.Is <ushort>(a => a <= HL && a > HL - repeats)), Times.Exactly(repeats))); } else { fixture.Assert(c => c.Mmu.Verify(x => x.WriteByte(It.Is <ushort>(a => a <= HL && a > HL - repeats), It.Is <byte>(b => b < repeats)), Times.Exactly(repeats))); } } else { if (isOutput) { fixture.With(c => c.Mmu.Setup(x => x.ReadByte(It.Is <ushort>(a => a >= HL && a < HL + repeats))).Returns <ushort>(a => (byte)(a - HL))); fixture.Assert(c => c.Mmu.Verify(x => x.ReadByte(It.Is <ushort>(a => a >= HL && a < HL + repeats)), Times.Exactly(repeats))); } else { fixture.Assert(c => c.Mmu.Verify(x => x.WriteByte(It.Is <ushort>(a => a >= HL && a < HL + repeats), It.Is <byte>(b => b < repeats)), Times.Exactly(repeats))); } } if (isOutput) { fixture.Assert(c => c.Io.Verify(x => x.WriteByteToPort(c.Registers.C, It.Is <byte>(b => b > 0 && b <= repeats), It.Is <byte>(b => b < repeats)))); } else { fixture.With(c => c.Io.Setup(x => x.ReadByteFromPort(c.Registers.C, It.Is <byte>(b => b > 0 && b <= repeats))) .Returns <byte, byte>((p, b) => (byte)(b - 1))); fixture.Assert(c => c.Io.Verify(x => x.ReadByteFromPort(c.Registers.C, It.Is <byte>(b => b > 0 && b <= repeats)), Times.Exactly(repeats))); } fixture.Assert(c => c.Registers.B.ShouldBe((byte)0)); } }
public void Types_TryAll_NoException() { bool a = Rng.Bool(); ushort b = Rng.UInt16(); short c = Rng.Int16(); uint d = Rng.UInt32(); int e = Rng.Int32(); ulong f = Rng.UInt64(); long g = Rng.Int64(); float h = Rng.Single(); double i = Rng.Double(); byte j = Rng.Byte(); byte[] k = Rng.ByteArray(16); }
public void When_reading_and_writing_single_bytes() { var readBytes = new byte[Length]; var writtenBytes = new byte[Length]; for (ushort i = 0; i < Length; i++) { var b = Rng.Byte(); writtenBytes[i] = b; Subject.WriteByte(i, b); readBytes[i] = Subject.ReadByte(i); } readBytes.ShouldBe(writtenBytes); }
public ExecutionContext(AutoMock mock, Operation operation, int blockLength, GeneralPurposeRegisterState initialRegisters, AccumulatorAndFlagsRegisterState initialAccumulator) { InitialRegisters = initialRegisters; InitialAccumulator = initialAccumulator; Flags = mock.Mock <IFlagsRegister>(); Flags.SetupAllProperties(); var accumulator = new AccumulatorAndFlagsRegisterSet(Flags.Object); var registers = new GeneralPurposeRegisterSet(); registers.ResetToState(initialRegisters); accumulator.ResetToState(initialAccumulator); Operation = operation; BlockLength = blockLength; Registers = registers; Accumulator = accumulator; Alu = mock.Mock <IAlu>(); Mmu = mock.Mock <IMmu>(); Io = mock.Mock <IPeripheralManager>(); MockRegisters = mock.Mock <IRegisters>(); MockRegisters.SetupAllProperties(); MockRegisters.Object.IX = _IX = Rng.Word(); MockRegisters.Object.IY = _IY = Rng.Word(); MockRegisters.Object.IXl = Rng.Byte(); MockRegisters.Object.IXh = Rng.Byte(); MockRegisters.Object.IYl = Rng.Byte(); MockRegisters.Object.IYh = Rng.Byte(); MockRegisters.Object.I = Rng.Byte(); MockRegisters.Object.R = Rng.Byte(); MockRegisters.Object.StackPointer = InitialStackPointer = Rng.Word(); MockRegisters.Object.ProgramCounter = InitialProgramCounter = Rng.Word(); MockRegisters.Setup(x => x.GeneralPurposeRegisters).Returns(registers); MockRegisters.Setup(x => x.AccumulatorAndFlagsRegisters).Returns(accumulator); // Don't want the initialization calls hanging around for verification. Flags.ResetCalls(); MockRegisters.ResetCalls(); }