Exemplo n.º 1
0
        // -= Move =-
        // MOV DST VALUE
        // Gets next memory address for DST
        // Moves value in next memory address to DST
        public override void Execute(Mainboard mainboard)
        {
            mainboard.GetCPU().IncrementPC();
            mainboard.GetCPU().FetchInstruction(mainboard.GetRAM());
            CPURegister dst = mainboard.GetCPU().GetRegister(mainboard.GetCPU().GetInstruction());

            mainboard.GetCPU().IncrementPC();
            mainboard.GetCPU().FetchInstruction(mainboard.GetRAM());
            byte src = mainboard.GetCPU().GetInstruction();

            byte result = (byte)(dst.GetByteValue() + src);

            mainboard.GetCPU().SetRegister(dst.GetRegisterID(), result);
        }
Exemplo n.º 2
0
        public void Think(Mainboard mainboard)
        {
            FetchInstruction(mainboard.GetRAM());
            ExecuteInstruction(mainboard);

            IncrementPC();
        }
Exemplo n.º 3
0
        // -= Addition =-
        // ADD DST SRC
        // Gets next memory address for DST
        // Gets next memory address for SRC
        // Adds SRC to DST
        public override void Execute(Mainboard mainboard)
        {
            mainboard.GetCPU().IncrementPC();
            mainboard.GetCPU().FetchInstruction(mainboard.GetRAM());
            CPURegister dst = mainboard.GetCPU().GetRegister(mainboard.GetCPU().GetInstruction());

            mainboard.GetCPU().IncrementPC();
            mainboard.GetCPU().FetchInstruction(mainboard.GetRAM());
            CPURegister src = mainboard.GetCPU().GetRegister(mainboard.GetCPU().GetInstruction());

            byte[] dstValue = dst.GetValue();

            Maths.AddArray(ref dstValue, dstValue.Length, src.GetValue()[0]);

            mainboard.GetCPU().SetRegister(dst.GetRegisterID(), dstValue);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            mainboard.GetRAM().FillData();

            while (running)
            {
                mainboard.Cycle();
            }
        }
Exemplo n.º 5
0
        // -= Interrupt =-
        // INT CODE [Register]
        // Gets next memory address for CODE
        // If interrupt requires, gets memory address for Register
        public override void Execute(Mainboard mainboard)
        {
            mainboard.GetCPU().IncrementPC();
            mainboard.GetCPU().FetchInstruction(mainboard.GetRAM());
            byte interrupt = mainboard.GetCPU().GetInstruction();

            switch (interrupt)
            {
            case 0xFF: Console.ReadKey(); break;     // HALT

            case 0x0A:
                mainboard.GetCPU().IncrementPC();
                mainboard.GetCPU().FetchInstruction(mainboard.GetRAM());
                byte register = mainboard.GetCPU().GetInstruction();
                Console.WriteLine(mainboard.GetCPU().GetRegister(register).GetIntValue()); break;     // Print register value

            case 0x80: break;
            }
        }