Exemple #1
0
        public void DisplayConsole(ConsoleDevice con)
        {
            Show();
            string tabName = con.ID.ToString("X2");

            if (tabControl.TabPages.ContainsKey(tabName))
            {
                // Display existing tab.
                tabControl.SelectTab(tabName);
            }
            else
            {
                // Add a new tab.
                var tab = new TabPage(tabName)
                {
                    Tag  = con,
                    Name = tabName,
                    Text = $"{con.ID:X2}\\{con.Name}"
                };
                var tb = new TextBox
                {
                    Name       = "consoleTB",
                    Multiline  = true,
                    Dock       = DockStyle.Fill,
                    Font       = new Font("Courier New", 10f),
                    ReadOnly   = true,
                    ScrollBars = ScrollBars.Both
                };
                tb.DoubleBuffer(true);
                con.OutputByteWritten += UpdateDisplay;
                tab.Controls.Add(tb);
                tabControl.TabPages.Add(tab);
                tabControl.SelectTab(tab);
            }
        }
Exemple #2
0
        private void UpdateDisplayWithLine(ConsoleDevice sender, string s)
        {
            if (InvokeRequired)
            {
                Invoke(new Action(() => UpdateDisplayWithLine(sender, s)));
                return;
            }
            var selectedTab = tabControl.SelectedTab;

            if (selectedTab.Tag == sender)
            {
                selectedTab.Controls["consoleTB"].Text += s;
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // Create memory and load the program and arguments (if present).
            _mem = new MemoryController();
            if (args.Length >= 1)
            {
                _mem.LoadProgram(args[0], args.Skip(1));
            }
            else if (args.Length == 1)
            {
                _mem.LoadProgram(args[0]);
            }

            InterruptHandler interruptHandler = new InterruptHandler(_mem);

            _mappedDevices = new List <IMemoryMappedDevice>();

            // Create a memory mapped console device.
            ConsoleDevice consoleDevice = new ConsoleDevice(_mem, interruptHandler, 1048448, 128);

            _mappedDevices.Add(consoleDevice);

            KeyboardDevice keyboardDevice = new KeyboardDevice(_mem, interruptHandler, 1048319, 128);

            _mappedDevices.Add(keyboardDevice);

            DisplayDevices(_mem, _mappedDevices, interruptHandler);

            Console.WriteLine();
            Console.WriteLine("Ready. Press enter to begin...");
            Console.ReadLine();
            Console.Clear();

            // Start the keyboard device.
            keyboardDevice.StartDevice();
            _mem.DebugWrite();
            // Create the CPU and start it running.
            _cpu = new CPU(_mem, interruptHandler);
            _cpu.Run();

            Console.ReadLine();
        }
Exemple #4
0
        private void UpdateDisplay(ConsoleDevice sender, byte b)
        {
            if (InvokeRequired)
            {
                Invoke(new Action(() => UpdateDisplay(sender, b)));
                return;
            }
            var selectedTab = tabControl.SelectedTab;

            if (selectedTab.Tag == sender)
            {
                if (b == '\n')
                {
                    selectedTab.Controls["consoleTB"].Text += "\r\n";
                }
                else
                {
                    selectedTab.Controls["consoleTB"].Text += ((char)b).ToString();
                }
            }
        }
Exemple #5
0
        private void createButton_Click(object sender, EventArgs e)
        {
            byte?id = GetID();

            if (!id.HasValue)
            {
                MessageBox.Show("Enter an ID for the device to create.", "Create device", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                idTB.Focus();
                return;
            }

            var      devname   = nameTB.Text.Trim();
            string   devtype   = typeCB.Text.ToLower();
            IODevice newDevice = null;

            switch (devtype)
            {
            case "file":
                // Need to get file path for this guy. Show special dialog for creating file device.
                // Let's just use a built-in file browser dialog for now.
                var fileBrowserDlg = new OpenFileDialog
                {
                    Title           = $"Choose path for file device 0x{id.Value:X} (\"{devname}\")",
                    CheckFileExists = false
                };
                if (fileBrowserDlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                string path = fileBrowserDlg.FileName;
                try
                {
                    newDevice = new FileDevice(id.Value, path);
                }
                catch (System.IO.IOException ex)
                {
                    MessageBox.Show(ex.Message, "Error creating file device", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                break;

            case "console":
                // No special options needed for this type of device? simply create it
                newDevice = new ConsoleDevice(id.Value);

                break;

            case "graphics":
                // Not implemented yet.
                return;

            //break;

            default:
                MessageBox.Show($"\"{typeCB.Text}\" is not a valid device type.", "Create device", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                typeCB.Focus();
                return;
            }

            if (devname.Length > 0)
            {
                newDevice.Name = nameTB.Text;
            }
            try
            {
                Machine.AddDevice(id.Value, newDevice);
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show($"Could not add the device to the machine:\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            AddDeviceToList(newDevice);
            ((MainForm)Owner).UpdateIODevices(this, null);
        }