Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
        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));
        }
Esempio n. 15
0
        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));
            }
        }
Esempio n. 16
0
        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));
        }
Esempio n. 17
0
        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));
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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));
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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));
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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);
            }
        }
Esempio n. 24
0
        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);
            }
        }
Esempio n. 25
0
        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));
        }
Esempio n. 26
0
        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);
            }
        }
Esempio n. 27
0
        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));
        }