public void TestInstructionSet_184()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            computer.memory.virtualAddressSpace[0].value = 184;
            computer.memory.virtualAddressSpace[1].value = 10;

            human.loader.Step(computer);

            Assert.AreEqual(10, computer.cPU.GetRegisters().GetRegister((int)(BlackICE2.X86Registers.RegisterPointers.ACCUMULATOR), 0)[0]);
        }
        public void TestInstructionSet_106()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            computer.memory.virtualAddressSpace[0].value = 106;
            computer.memory.virtualAddressSpace[1].value = 91;

            human.loader.Step(computer);

            Assert.AreEqual(91, computer.memory.virtualAddressSpace[31].value);
        }
        public void TestInstructionSet_232()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            computer.memory.virtualAddressSpace[0].value = 232;
            computer.memory.virtualAddressSpace[1].value = 1;

            human.loader.Step(computer);

            Assert.AreEqual(0, computer.memory.virtualAddressSpace[31].value); // Test the stack (saved IP value). This is 2, because that's the ToSkip() value of CALL.
            Assert.AreEqual(2, computer.cPU.GetRegisters().GetRegister((int)(BlackICE2.X86Registers.RegisterPointers.INSTRUCTION_POINTER), 0)[0]); // Test the JMP (IP value).
        }
        public void TestInstructionSet_195()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            computer.memory.virtualAddressSpace[31].value = 0; // Saved IP value.

            computer.cPU.GetRegisters().DecrementStackPointer(); // Push stack pointer up.

            computer.memory.virtualAddressSpace[0].value = 195;

            human.loader.Step(computer);

            Assert.AreEqual(1, computer.cPU.GetRegisters().GetRegister((int)(BlackICE2.X86Registers.RegisterPointers.INSTRUCTION_POINTER), 0)[0]); // Test the IP has been set back to the saved value. This is 1, because that's the ToSkip() value of RET.
            Assert.AreEqual(0, computer.memory.virtualAddressSpace[31].value); // Test the saved IP value has been popped.
        }
        public void TestInstructionSet_233()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            // todo - This is not the best test we could really do. It checks for '2' because that's the ToSkip() parameter count for the JMP instruction, being set in the IP.
            // To make it better, maybe you could JMP to actual instructions further down in memory, but this would require you to use actual instructions, making this unit test dependent on other unit tests.
            // Aa NOP instruction/test, for example, would suffice.

            computer.memory.virtualAddressSpace[0].value = 233;
            computer.memory.virtualAddressSpace[1].value = 1;

            human.loader.Step(computer);

            Assert.AreEqual(2, computer.cPU.GetRegisters().GetRegister((int)(BlackICE2.X86Registers.RegisterPointers.INSTRUCTION_POINTER), 0)[0]);
        }
        public void TestInstructionSet_89()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            computer.cPU.GetRegisters().SetRegister((int)(BlackICE2.X86Registers.RegisterPointers.ACCUMULATOR), 0, new byte[] { 88 }); // Store value to MOV in EAX.

            computer.memory.virtualAddressSpace[0].value = 89;
            computer.memory.virtualAddressSpace[1].value = 195;

            human.loader.Step(computer);

            Assert.AreEqual(88, computer.cPU.GetRegisters().GetRegister((int)(BlackICE2.X86Registers.RegisterPointers.BASE), 0)[0]);
        }
        public void TestInstructionSet_58()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            computer.memory.virtualAddressSpace[31].value = 74; // Stack value to POP.

            computer.cPU.GetRegisters().DecrementStackPointer(); // Push stack pointer up.

            computer.memory.virtualAddressSpace[0].value = 58;

            human.loader.Step(computer);

            Assert.AreEqual(74, computer.cPU.GetRegisters().GetRegister((int)(BlackICE2.X86Registers.RegisterPointers.ACCUMULATOR), 0)[0]);
        }
        public void TestInterpreter_Program1()
        {
            BlackICE2.Computer computer = new BlackICE2.Computer();
            computer.cPU = new BlackICE2.X86CPU(computer);
            computer.memory = new BlackICE2.Memory();

            BlackICE2.Human human = new BlackICE2.Human();

            List<string> listing = new List<string>();
            listing.Add("mov eax, 10");
            listing.Add("call @@myfunction");
            listing.Add("inc eax");
            listing.Add("push eax");
            listing.Add("inc eax");
            listing.Add("pop eax");
            listing.Add("@@myfunction");
            listing.Add("mov ebx, eax");
            listing.Add("push 77");
            listing.Add("inc eax");
            listing.Add("pop eax");
            listing.Add("ret");

            BlackICE2.Program program = human.CreateProgram(computer, listing);

            Assert.AreEqual(program.codeSegment.Item1[0], 184);
            Assert.AreEqual(program.codeSegment.Item2[0], 0);

            Assert.AreEqual(program.codeSegment.Item1[1], 10);
            Assert.AreEqual(program.codeSegment.Item2[1], 0);

            Assert.AreEqual(program.codeSegment.Item1[2], 232);
            Assert.AreEqual(program.codeSegment.Item2[2], 1);

            Assert.AreEqual(program.codeSegment.Item1[3], 8);
            Assert.AreEqual(program.codeSegment.Item2[3], 1);

            Assert.AreEqual(program.codeSegment.Item1[4], 40);
            Assert.AreEqual(program.codeSegment.Item2[4], 2);

            Assert.AreEqual(program.codeSegment.Item1[5], 50);
            Assert.AreEqual(program.codeSegment.Item2[5], 3);

            Assert.AreEqual(program.codeSegment.Item1[6], 40);
            Assert.AreEqual(program.codeSegment.Item2[6], 4);

            Assert.AreEqual(program.codeSegment.Item1[7], 58);
            Assert.AreEqual(program.codeSegment.Item2[7], 5);

            Assert.AreEqual(program.codeSegment.Item1[8], 89);
            Assert.AreEqual(program.codeSegment.Item2[8], 7);

            Assert.AreEqual(program.codeSegment.Item1[9], 195);
            Assert.AreEqual(program.codeSegment.Item2[9], 7);

            Assert.AreEqual(program.codeSegment.Item1[10], 106);
            Assert.AreEqual(program.codeSegment.Item2[10], 8);

            Assert.AreEqual(program.codeSegment.Item1[11], 77);
            Assert.AreEqual(program.codeSegment.Item2[11], 8);

            Assert.AreEqual(program.codeSegment.Item1[12], 40);
            Assert.AreEqual(program.codeSegment.Item2[12], 9);

            Assert.AreEqual(program.codeSegment.Item1[13], 58);
            Assert.AreEqual(program.codeSegment.Item2[13], 10);

            Assert.AreEqual(program.codeSegment.Item1[14], 195);
            Assert.AreEqual(program.codeSegment.Item2[14], 11);
        }