Esempio n. 1
0
        public void PowerOn()
        {
            // Start the computer with the control until poiting at the first control word
            this.ControlUnit.OnControlStateUpdated();

            ConsoleKeyInfo key;
            ValueFormat    displayFormat = ValueFormat.Binary;

            while (true)
            {
                // Left modules
                this.Clock.OutputState();
                Mar.OutputState(displayFormat);
                Ram.OutputState(displayFormat);
                Rom.OutputState(displayFormat);
                Ir.OutputState(displayFormat);
                IrParam.OutputState(displayFormat);

                // BUS
                this.Bus.OutputState();

                // Right modules
                ProgramCounter.OutputState(displayFormat);
                A.OutputState(displayFormat);
                Alu.OutputState(displayFormat);
                B.OutputState(displayFormat);
                Flags.OutputState(displayFormat);
                Out.OutputState(displayFormat);

                // Control Unit (bottom)
                ControlUnit.OutputState();

                // User keys
                Console.SetCursorPosition(0, 23);
                Console.Write(String.Format("[S]tep - [N]ext Ins - [R]un - Clock {0}hz [+-] - Rese[t] - [D]isplay - E[x]it", this.Clock.FrequencyHz));


                // Step the system
                if (this.Clock.ClockMode == IClock.Mode.Stepped ||
                    (this.Clock.ClockMode == IClock.Mode.Running && Console.KeyAvailable))
                {
                    key = Console.ReadKey(true);

                    int freq;

                    switch (key.Key)
                    {
                    case ConsoleKey.S:
                        this.Clock.ClockMode = IClock.Mode.Stepped;
                        this.Clock.Step();
                        break;

                    case ConsoleKey.R:
                        this.Clock.ClockMode = IClock.Mode.Running;
                        break;

                    case ConsoleKey.N:
                        this.Clock.ClockMode = IClock.Mode.Stepped;
                        this.Clock.Step();
                        while (this.ControlUnit.MicrostepCounter.Value != 3 && !this.Clock.IsHalted)
                        {
                            Thread.Sleep(1);
                            this.Clock.Step();
                        }
                        break;

                    case ConsoleKey.Add:
                        freq = this.Clock.FrequencyHz;
                        if (freq <= 20)
                        {
                            freq++;
                        }
                        else if (freq <= 100)
                        {
                            freq += 5;
                        }
                        else
                        {
                            freq += 50;
                        }
                        if (freq > 500)
                        {
                            freq = 500;
                        }
                        this.Clock.FrequencyHz = freq;
                        break;

                    case ConsoleKey.Subtract:
                        freq = this.Clock.FrequencyHz;
                        if (freq <= 20)
                        {
                            freq--;
                        }
                        else if (freq <= 100)
                        {
                            freq -= 5;
                        }
                        else
                        {
                            freq -= 50;
                        }
                        if (freq < 1)
                        {
                            freq = 1;
                        }
                        this.Clock.FrequencyHz = freq;
                        break;

                    case ConsoleKey.T:
                        Reset();
                        break;

                    case ConsoleKey.D:
                        switch (displayFormat)
                        {
                        case ValueFormat.Hex:
                            displayFormat = ValueFormat.Decimal;
                            break;

                        case ValueFormat.Decimal:
                            displayFormat = ValueFormat.Binary;
                            break;

                        case ValueFormat.Binary:
                            displayFormat = ValueFormat.Hex;
                            break;
                        }
                        break;

                    case ConsoleKey.X:
                        return;
                    }

                    if (this.Clock.ClockMode == IClock.Mode.Stepped)
                    {
                        if (key.Key == ConsoleKey.S)
                        {
                        }
                    }
                    else if (this.Clock.ClockMode == IClock.Mode.Running)
                    {
                    }
                }

                if (this.Clock.ClockMode == IClock.Mode.Running)
                {
                    if (Clock.IsHalted)
                    {
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Thread.Sleep(1000 / this.Clock.FrequencyHz);
                    }
                    this.Clock.Step();
                }
            }
        }
Esempio n. 2
0
 public void LoadMicrocode(string bank0RomFile, string bank1RomFile, string bank2RomFile)
 {
     ControlUnit.LoadMicrocode(bank0RomFile, bank1RomFile, bank2RomFile);
 }