public void TestNOP() { var registers = Mock.Of <IRegisters>(); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.NOP, new byte[] { 0, 0, 0 }); var operation = sut[Opcodes.NOP]; operation(instruction, registers, bus); }
public void TestJDoesNotPerformJMPWhenTheParameterIsZero() { var registers = Mock.Of <IRegisters>(); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.J, new byte[] { 0x0, 0xcd, 0xab }); var operation = sut[Opcodes.J]; operation(instruction, registers, bus); Mock.Get(registers).VerifySet(r => r.PC = 0xabcd, Times.Never); }
public void TestSPR() { var registers = Mock.Of <IRegisters>(); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var operation = sut[Opcodes.SPR]; var parameters = new byte[] { 0, 0x10, 0x20 }; var instruction = new Instruction(Opcodes.SPR, parameters); operation(instruction, registers, bus); Mock.Get(bus).Verify(b => b.SendCommandToGPU(GPUCommands.SPR, parameters)); }
public void TestJMP() { var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.JMP, new byte[] { 0x00, 0xcd, 0xab }); var bus = new Mock <IBus>(); var registers = new Mock <IRegisters>(); var operation = sut[Opcodes.JMP]; operation(instruction, registers.Object, bus.Object); registers.VerifySet(r => r.PC = 0xABCD); }
public void TSTISetsZeroFlag() { var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(new short[16]); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.TSTI, new byte[] { 0x0a, 0x00, 0x00 }); var operation = sut[Opcodes.TSTI]; operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetZeroFlag(true)); }
public void TSTIUnsetsNegativeFlag() { var registers = Mock.Of <IRegisters>(); var gp = new short[16]; gp[0] = unchecked ((short)0xffff); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.TSTI, new byte[] { 0x00, 0x00, 0x0f }); var operation = sut[Opcodes.TSTI]; operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetNegativeFlag(false)); }
public void TestPUSHF() { var registers = Mock.Of <IRegisters>(); Mock.Get(registers).SetupGet(r => r.SP).Returns(0xabcd); Mock.Get(registers).SetupGet(r => r.FLAGS).Returns(0b10101010); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var operation = sut[Opcodes.PUSHF]; var instruction = new Instruction(Opcodes.PUSHF, new byte[] { 0, 0, 0 }); operation(instruction, registers, bus); Mock.Get(bus).Verify(b => b.Write(0xabcd, 0b10101010)); Mock.Get(registers).Verify(r => r.IncrementSP()); }
public void TestCMPISetsOverflowFlagToFalse() { var gp = new short[16]; gp[2] = 0x1; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var operation = sut[Opcodes.CMPI]; var instruction = new Instruction(Opcodes.CMPI, new byte[] { 0x2, 0, 0 }); operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetOverflowFlag(false)); }
public void TestMOV() { unchecked { var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.MOV, new byte[] { 0xab, 0, 0 }); var bus = new Mock <IBus>(); var gp = new short[16]; gp[0x0a] = (short)0xdead; var registers = new Mock <IRegisters>(); registers.Setup(r => r.GP).Returns(gp); var operation = sut[Opcodes.MOV]; operation(instruction, registers.Object, bus.Object); gp[0x0b].Should().Be((short)0xdead); } }
public void TestADDISetsCarryFlag() { var gp = new short[16]; gp[1] = 1; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instructrion = new Instruction(Opcodes.ADDI, new byte[] { 0x1, 0xff, 0xff }); var operation = sut[Opcodes.ADDI]; operation(instructrion, registers, bus); Mock.Get(registers).Verify(r => r.SetCarryFlag(true)); }
public void TestXORSetsZeroFlag() { var gp = new short[16]; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.XOR, new byte[] { 0x10, 0, 0 }); var operation = sut[Opcodes.XOR]; operation(instruction, registers, bus); gp[0].Should().Be(0); Mock.Get(registers).Verify(r => r.SetZeroFlag(true)); Mock.Get(registers).Verify(r => r.SetNegativeFlag(false)); }
public void TestCMPISetsNegativeFlagToFalseWhenTheResultIsPositive() { var gp = new short[16]; gp[2] = 2; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var operation = sut[Opcodes.CMPI]; var instruction = new Instruction(Opcodes.CMPI, new byte[] { 0x2, 0x01, 0x0 }); operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetNegativeFlag(false)); }
public void TestADDSetsCarryFlag() { var gp = new short[16]; gp[2] = unchecked ((short)0xffff); gp[4] = 1; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.ADD, new byte[] { 0x42, 0, 0 }); var operation = sut[Opcodes.ADD]; operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetCarryFlag(true)); }
public void TestORSetsNegativeFlag(int operand1, int operand2, bool flag) { var gp = new short[16]; gp[2] = (short)operand1; gp[4] = (short)operand2; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.OR, new byte[] { 0x42, 0, 0 }); var operation = sut[Opcodes.OR]; operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetNegativeFlag(flag)); }
public void TestSTM() { unchecked { var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.STM, new byte[] { 0x2, 0xcd, 0xab }); var bus = new Mock <IBus>(); var registers = new Mock <IRegisters>(); var gp = new short[16]; short value = (short)0xdead; gp[0x2] = value; registers.Setup(r => r.GP).Returns(gp); var operation = sut[Opcodes.STM]; operation(instruction, registers.Object, bus.Object); bus.Verify(b => b.Write(0xabcd, (short)0xdead)); } }
public void TestSHRSetsTheZeroFlag(short operand1, byte operand2, bool flag) { var gp = new short[16]; gp[2] = operand1; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var operation = sut[Opcodes.SHR]; var instruction = new Instruction(Opcodes.SHR, new byte[] { 0x2, operand2, 0 }); operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetZeroFlag(flag)); }
public void TestSUBSetsOverflowFlag() { var gp = new short[16]; gp[2] = 0x1; gp[4] = 0x7fff; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.SUB, new byte[] { 0x42, 0, 0 }); var operation = sut[Opcodes.SUB]; operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetOverflowFlag(true)); }
public void TestADDSetsNegativeFlag() { var gp = new short[16]; gp[2] = 0; gp[4] = -1; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.ADD, new byte[] { 0x42, 0, 0 }); var operation = sut[Opcodes.ADD]; operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetNegativeFlag(true)); gp[2].Should().Be(-1); }
public void TestMUL2SetsCarryFlag() { var gp = new short[16]; gp[2] = 0x2000; gp[4] = 0x0100; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.MUL2, new byte[] { 0x42, 0x08, 0 }); var operation = sut[Opcodes.MUL2]; operation(instruction, registers, bus); Mock.Get(registers).Verify(r => r.SetCarryFlag(true)); }
public void TestMUL2() { var gp = new short[16]; gp[2] = 2; gp[4] = 3; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.MUL2, new byte[] { 0x42, 0x08, 0 }); var operation = sut[Opcodes.MUL2]; operation(instruction, registers, bus); gp[8].Should().Be(6); }
public void TestDiv2SetsZeroFlag() { var gp = new short[16]; gp[2] = 0; gp[4] = 5; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.DIV2, new byte[] { 0x42, 0x08, 0 }); var operation = sut[Opcodes.DIV2]; operation(instruction, registers, bus); gp[8].Should().Be(0); Mock.Get(registers).Verify(r => r.SetZeroFlag(true)); }
public void TestRET() { var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.SP).Returns(0); var bus = Mock.Of <IBus>(); Mock.Get(bus).Setup(b => b.Read16(0)).Returns(unchecked ((short)0xabcd)); var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.RET, new byte[] { 0, 0, 0 }); var operation = sut[Opcodes.RET]; operation(instruction, registers, bus); //Decrease SP by 2 Mock.Get(registers).Verify(r => r.DecrementSP()); //set PC to [SP] Mock.Get(registers).VerifySet(r => r.PC = 0xabcd); }
public void TestLDM() { unchecked { var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.LDM, new byte[] { 0x1, 0xcd, 0xab }); var bus = new Mock <IBus>(); bus.Setup(b => b.Read16(It.IsAny <ushort>())).Returns((short)0xdead); var gp = new short[16]; var registers = new Mock <IRegisters>(); registers.Setup(r => r.GP).Returns(gp); var operation = sut[Opcodes.LDM]; operation(instruction, registers.Object, bus.Object); bus.Verify(b => b.Read16(0xabcd)); gp[0x1].Should().Be((short)0xdead); } }
public void TestLDI() { var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.LDI, new byte[] { 0xa, 0xcd, 0xab }); var bus = new Mock <IBus>(); var registers = new Mock <IRegisters>(); var gp = new short[16]; registers.Setup(r => r.GP).Returns(gp); var operation = sut[Opcodes.LDI]; operation(instruction, registers.Object, bus.Object); unchecked { gp[0xa].Should().Be((short)0xabcd); } }
public void TestSHL2() { var gp = new short[16]; gp[2] = 2; gp[4] = 1; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); var bus = Mock.Of <IBus>(); var sut = new InstructionsetFactory().CreateInstructionset(); var operation = sut[Opcodes.SHL2]; var instruction = new Instruction(Opcodes.SHL2, new byte[] { 0x42, 0, 0 }); operation(instruction, registers, bus); gp[2].Should().Be(4); Mock.Get(registers).Verify(r => r.SetZeroFlag(false)); Mock.Get(registers).Verify(r => r.SetNegativeFlag(false)); }
public void TestCall() { unchecked { var sut = new InstructionsetFactory().CreateInstructionset(); var instruction = new Instruction(Opcodes.CALL, new byte[] { 0, 0xcd, 0xab }); var bus = new Mock <IBus>(); var registers = new Mock <IRegisters>(); registers.Setup(r => r.PC).Returns(0xeeee); registers.Setup(r => r.SP).Returns(0xff00); var operation = sut[Opcodes.CALL]; operation(instruction, registers.Object, bus.Object); //store pc to [sp] bus.Verify(b => b.Write(0xff00, (short)0xeeee)); //inc sp by 2 registers.Verify(r => r.IncrementSP()); //set pc to 0xabcd registers.VerifySet(r => r.PC = 0xabcd); } }
public void TestPOP() { var gp = new short[16]; var registers = Mock.Of <IRegisters>(); Mock.Get(registers).Setup(r => r.GP).Returns(gp); Mock.Get(registers).SetupGet(r => r.SP).Returns(0xabcd); var bus = Mock.Of <IBus>(); Mock.Get(bus).Setup(b => b.Read16(It.IsAny <ushort>())).Returns(unchecked ((short)0xdead)); var sut = new InstructionsetFactory().CreateInstructionset(); var operation = sut[Opcodes.POP]; var instruction = new Instruction(Opcodes.POP, new byte[] { 0x02, 0, 0 }); operation(instruction, registers, bus); //SP-- Mock.Get(registers).Verify(r => r.DecrementSP()); //RX = Read16(SP) Mock.Get(bus).Verify(b => b.Read16(0xabcd)); gp[2].Should().Be(unchecked ((short)0xdead)); }