public void IOManagerTests_WriteToIODevice_Success()
        {
            IOManager io = new IOManager(100);

            Device d1 = new Device()
            {
                Id = 1
            };
            Device d2 = new Device()
            {
                Id = 2
            };

            io.AddIODevice(80, d1);
            io.AddIODevice(82, d2);

            MicroSimulator micro = new MicroSimulator(
                new VirtualMemory(new string[] { }),
                io
                );

            micro.WriteToMemory(80, "F3");
            micro.WriteToMemory(82, "08");

            Console.WriteLine(d1);
            Console.WriteLine(d2);

            Assert.AreEqual("Device[Id: 1, Data: 243]", d1.ToString());
            Assert.AreEqual("Device[Id: 2, Data: 8]", d2.ToString());

            Console.WriteLine(micro.ReadFromMemory(80));
            Console.WriteLine(micro.ReadFromMemory(82));
        }
Beispiel #2
0
        public void ASCIIDisplayTests_ReadFromMicro_Success()
        {
            VirtualMemory vm = new VirtualMemory(new string[] {
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000"
            });

            IOManager manager = new IOManager(100);

            MicroSimulator micro = new MicroSimulator(vm, manager);

            Console.WriteLine("Starting State:");
            Console.Write(vm);
            Console.WriteLine(manager);
            Console.WriteLine(micro);

            ASCII_Display display = new ASCII_Display(5, true);

            manager.AddIODevice(5, display);

            Console.WriteLine("\nAfter adding ASCII Display:");
            Console.WriteLine(manager);

            Console.WriteLine($"\nIO Device: {display}");

            Assert.AreEqual("00", display.ReadFromPort(5));

            display.WriteInPort(5, "48");
            display.WriteInPort(6, "6F");
            display.WriteInPort(7, "6C");
            display.WriteInPort(8, "61");

            Console.WriteLine(display);

            string h = micro.ReadFromMemory(5);
            string o = micro.ReadFromMemory(6);
            string l = micro.ReadFromMemory(7);
            string a = micro.ReadFromMemory(8);

            Assert.AreEqual("48", h);
            Assert.AreEqual("6F", o);
            Assert.AreEqual("6C", l);
            Assert.AreEqual("61", a);

            Console.WriteLine($"\nContent read in Hex: {h} {o} {l} {a}");
        }
Beispiel #3
0
        public void DataMovOperationsTests_PUSH_Success()
        {
            //init
            micro.StackPointer = 100;
            micro.MicroRegisters.SetRegisterValue(2, "FF");
            MCInstructionF2 i1         = new MCInstructionF2(3, "00100", "010", null);
            ushort          SPNewValue = 99;

            //execute
            InstructionSetExe.ExecuteInstruction(i1, micro);

            Assert.AreEqual(SPNewValue, micro.StackPointer);
            Assert.AreEqual("FF", micro.ReadFromMemory(micro.StackPointer));
        }
Beispiel #4
0
        public void FlowControlOperationsTests_CALL_Success()
        {
            //init
            // CALL address {F3}
            // SP <- SP - 2
            // mem[SP] <- PC
            // PC <- address

            ushort expectedSPVal = 98;

            string addressOfCall = UnitConverter.ByteToBinary(33);

            byte initialValueOfPC = 12;

            micro.StackPointer   = 100;
            micro.ProgramCounter = initialValueOfPC;

            // address: 2
            MCInstructionF3 i1 = new MCInstructionF3(30, "11110", addressOfCall);

            // execute
            InstructionSetExe.ExecuteInstruction(i1, micro);

            Assert.AreEqual(expectedSPVal, micro.StackPointer);

            // expected data in Address: 33
            Assert.AreEqual(UnitConverter.ByteToHex(initialValueOfPC), micro.ReadFromMemory(micro.StackPointer));

            // program counter should be equal to 98
            Assert.AreEqual(UnitConverter.BinaryToByte(addressOfCall), micro.ProgramCounter);
        }
Beispiel #5
0
        public void IOHexKeyboardTests_ReadFromMicro_Success()
        {
            VirtualMemory vm = new VirtualMemory(new string[] {
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000"
            });

            IOManager manager = new IOManager(100);

            MicroSimulator micro = new MicroSimulator(vm, manager);

            Console.WriteLine("Initial State:");
            Console.Write(vm);
            Console.WriteLine(manager);
            Console.WriteLine(micro);

            IOHexKeyboard kb = new IOHexKeyboard(5);

            manager.AddIODevice(5, kb);

            Console.WriteLine("\nAfter adding IO Hex Keyboard:");
            Console.WriteLine(manager);

            Console.WriteLine($"\nIO Device: {kb}");

            Assert.AreEqual("00", kb.ReadFromPort(5));

            kb.KeyPress("A");
            kb.KeyPress("A");
            kb.KeyPress("A");
            kb.KeyPress("F");
            kb.KeyPress("A");

            Console.WriteLine(kb);

            string contentHex = micro.ReadFromMemory(5);

            Assert.AreEqual("A1", contentHex);

            Console.WriteLine($"\nContent read in Hex: {contentHex}");
        }
Beispiel #6
0
        public void ASCIIDisplayTests_TestPorts_Read_Write()
        {
            VirtualMemory vm = new VirtualMemory(new string[] {
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000"
            });

            IOManager manager = new IOManager(100);

            MicroSimulator micro = new MicroSimulator(vm, manager);

            Console.WriteLine("Starting State:");
            Console.Write(vm);
            Console.WriteLine(manager);
            Console.WriteLine(micro);

            ushort        start_port = 5;
            ASCII_Display display    = new ASCII_Display(start_port, true);//Starting port

            manager.AddIODevice(start_port, display);

            Console.WriteLine("\nAfter adding ASCII Display:");
            Console.WriteLine(manager);

            Console.WriteLine($"\nIO Device: {display}");

            Assert.AreEqual("00", display.ReadFromPort(5));

            //Write To Valid port range
            Assert.IsTrue(display.WriteInPort(5, "48"));
            Assert.IsTrue(display.WriteInPort(6, "6F"));
            Assert.IsTrue(display.WriteInPort(7, "6C"));
            Assert.IsTrue(display.WriteInPort(8, "61"));

            Console.WriteLine(display);


            //Verify that it wrote to memory correctly
            Assert.AreEqual(display.ReadFromPort(5), micro.ReadFromMemory(5));


            //Reading from invalid before Port Range
            var ex = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(4));

            Assert.AreEqual(ex.Message, "Invalid port \n");

            var ex3 = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(13));

            Assert.AreEqual(ex3.Message, "Invalid port \n");

            //Maximum Port Number
            var ex1 = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(short.MaxValue));

            Assert.AreEqual(ex1.Message, "Invalid port \n");

            //Minimum Port Number
            var ex2 = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(short.MinValue));

            Assert.AreEqual(ex2.Message, "Invalid port \n");


            //Writing into invalid Ports

            //Positive before valid range
            Assert.AreEqual(display.WriteInPort(4, "X"), false);

            //Positive after valid range
            Assert.AreEqual(display.WriteInPort(13, "X"), false);

            //Maximum Port Number
            Assert.AreEqual(display.WriteInPort(short.MaxValue, "X"), false);

            //Negative Port Number
            Assert.AreEqual(display.WriteInPort(short.MinValue, "X"), false);
        }
Beispiel #7
0
        public void ASCIIDisplayTests_TestPorts_Read()
        {
            VirtualMemory vm = new VirtualMemory(new string[] {
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000",
                "0000"
            });

            IOManager manager = new IOManager(100);

            MicroSimulator micro = new MicroSimulator(vm, manager);

            Console.WriteLine("Starting State:");
            Console.Write(vm);
            Console.WriteLine(manager);
            Console.WriteLine(micro);

            ASCII_Display display = new ASCII_Display(5, true);

            manager.AddIODevice(5, display);

            Console.WriteLine("\nAfter adding ASCII Display:");
            Console.WriteLine(manager);

            Console.WriteLine($"\nIO Device: {display}");

            display.WriteInPort(5, "48");
            display.WriteInPort(6, "6F");
            display.WriteInPort(7, "6C");
            display.WriteInPort(8, "61");

            Console.WriteLine(display);

            string h = micro.ReadFromMemory(5);
            string o = micro.ReadFromMemory(6);
            string l = micro.ReadFromMemory(7);
            string a = micro.ReadFromMemory(8);

            Assert.AreEqual("48", h);
            Assert.AreEqual("6F", o);
            Assert.AreEqual("6C", l);
            Assert.AreEqual("61", a);

            Console.WriteLine($"\nContent read in Hex: {h} {o} {l} {a}");

            //Verify that it wrote to memory correctly
            Assert.AreEqual(display.ReadFromPort(5), micro.ReadFromMemory(5));

            //Reading from invalid before Port Range
            var ex = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(4));

            Assert.AreEqual(ex.Message, "Invalid port \n");

            var ex3 = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(15));

            Assert.AreEqual(ex3.Message, "Invalid port \n");

            //Maximum Port Number
            var ex1 = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(short.MaxValue));

            Assert.AreEqual(ex1.Message, "Invalid port \n");

            //Minimum Port Number
            var ex2 = Assert.ThrowsException <ArgumentException>(() => display.ReadFromPort(short.MinValue));

            Assert.AreEqual(ex2.Message, "Invalid port \n");
        }