private static void TestRepeat(OpCode op, bool decrement) { using (var fixture = new ExecuteFixture()) { const ushort HL = 100; // Change HL so we don't need to worry about overflow. var repeats = Rng.Word(2, 10); fixture.Operation.OpCode(op); fixture.With(c => c.Registers.BC = repeats, c => c.Registers.HL = HL); fixture.RuntimeTiming((repeats - 1) * 5, (repeats - 1) * 21); if (decrement) { 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.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))); } fixture.Assert(c => c.Alu.Verify(x => x.Compare(c.Accumulator.A, It.Is <byte>(b => b < repeats)))); fixture.Assert(c => c.Registers.BC.ShouldBe((ushort)0)); } }
public void TransferRepeat(OpCode op, bool decrement) { var repeats = Rng.Word(2, 10); using (var fixture = new ExecuteFixture()) { fixture.Operation.OpCode(op); fixture.RuntimeTiming((repeats - 1) * 5, (repeats - 1) * 21); const ushort HL = 100, DE = 1000; // Avoiding overflows. fixture.With(c => c.Registers.BC = repeats, c => c.Registers.HL = HL, c => c.Registers.DE = DE); if (decrement) { fixture.Assert(c => c.Mmu.Verify(x => x.TransferByte(It.Is <ushort>(b => b > HL - repeats && b <= HL), It.Is <ushort>(b => b > DE - repeats && b <= DE)), Times.Exactly(repeats))); fixture.Assert(c => c.Registers.HL.ShouldBe((ushort)(HL - repeats)), c => c.Registers.DE.ShouldBe((ushort)(DE - repeats))); } else { fixture.Assert(c => c.Mmu.Verify(x => x.TransferByte(It.Is <ushort>(b => b >= HL && b < HL + repeats), It.Is <ushort>(b => b >= DE && b < DE + repeats)), Times.Exactly(repeats))); fixture.Assert(c => c.Registers.HL.ShouldBe((ushort)(HL + repeats)), c => c.Registers.DE.ShouldBe((ushort)(DE + repeats))); } fixture.Assert(c => c.Registers.BC.ShouldBe((ushort)0)); } }
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)); } }