Exemplo n.º 1
0
 public MemoryDisplay(ref DCPU CPU)
 {
     AsStack = false;
     InitializeComponent();
     this.CPU = CPU;
     wordsWide = 8;
 }
Exemplo n.º 2
0
 public M35FDWindow(M35FD M35FD, DCPU CPU)
 {
     InitializeComponent();
     this.M35FD = M35FD;
     this.CPU = CPU;
     this.Text = "M35FD #" + CPU.Devices.IndexOf(M35FD);
     ReloadImageList();
     ReloadImages += (s, e) =>
     {
         if (InvokeRequired)
             this.Invoke(new Action(ReloadImageList));
         else
             ReloadImageList();
     };
     if (M35FD.Disk != null)
     {
         imageNameLabel.Text = "[Unknown disk]";
         ejectButton.Enabled = true;
         insertDiskButton.Enabled = false;
     }
     else
     {
         imageNameLabel.Text = "[None loaded]";
         ejectButton.Enabled = false;
         insertDiskButton.Enabled = listBox1.SelectedIndex != -1;
     }
 }
Exemplo n.º 3
0
        public Debugger(ref DCPU CPU)
        {
            InitializeComponent();
            if (KnownCode == null)
                KnownCode = new Dictionary<ushort, string>();
            if (KnownLabels == null)
                KnownLabels = new Dictionary<ushort, string>();

            FixKeyConfig();

            this.KeyPreview = true;
            this.CPU = CPU;
            this.CPU.BreakpointHit += new EventHandler<BreakpointEventArgs>(CPU_BreakpointHit);
            this.CPU.InvalidInstruction += CpuOnInvalidInstruction;
            this.rawMemoryDisplay.CPU = this.CPU;
            this.stackDisplay.CPU = this.CPU;
            this.disassemblyDisplay1.CPU = this.CPU;
            foreach (Device d in CPU.Devices)
                listBoxConnectedDevices.Items.Add(d.FriendlyName);
            // Load device controllers
            DeviceControllers = new List<Type>();
            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                var types = asm.GetTypes().Where(t => typeof(DeviceController).IsAssignableFrom(t) && t.IsAbstract == false);
                foreach (var type in types)
                {
                    DeviceControllers.Add(type);
                }
            }
        }
Exemplo n.º 4
0
 public GenerickeyboardWindow(LEM1802 LEM1802, DCPU CPU, bool AssignKeyboard)
     : base(LEM1802, CPU, AssignKeyboard)
 {
     this.Text = "Generic Keyboard";
     this.Name = "test";
     this.takeScreenshotToolStripMenuItem.Enabled = false;
 }
Exemplo n.º 5
0
 public SPED3Window(SPED3 SPED3, DCPU CPU)
 {
     InitializeComponent();
     Text = "SPED-3 Display #" + CPU.Devices.IndexOf(SPED3);
     managedDevices = new Device[] { SPED3 };
     this.CPU = CPU;
     this.SPED3 = SPED3;
 }
Exemplo n.º 6
0
 public DisassemblyDisplay(ref DCPU CPU)
     : this()
 {
     InitializeComponent();
     this.CPU = CPU;
     this.MouseMove += new MouseEventHandler(DisassemblyDisplay_MouseMove);
     this.MouseDoubleClick += new MouseEventHandler(DisassemblyDisplay_MouseDoubleClick);
     EnableUpdates = true;
 }
Exemplo n.º 7
0
 public GenericKeyboardWindow(GenericKeyboard Keyboard, DCPU CPU)
     : base()
 {
     InitializeComponent();
     this.CPU = CPU;
     this.Keyboard = Keyboard;
     managedDevices = new Device[] { Keyboard };
     this.KeyDown += new KeyEventHandler(GenericKeyboardWindow_KeyDown);
     this.KeyUp += new KeyEventHandler(GenericKeyboardWindow_KeyUp);
     this.MouseDown += new MouseEventHandler(GenericKeyboardWindow_MouseDown);
     this.label1.MouseDown += new MouseEventHandler(GenericKeyboardWindow_MouseDown);
     this.label1.Text = "Generic Keyboard #" + CPU.Devices.IndexOf(Keyboard);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Assigns a LEM to the window.  If AssignKeyboard is true, it will search for a keyboard
        /// in the given CPU and assign it to this window as well.
        /// </summary>
        public LEM1802Window(LEM1802 LEM1802, DCPU CPU, bool AssignKeyboard)
            : base()
        {
            InitializeComponent();
            this.iad = new InvalidateAsyncDelegate(InvalidateAsync);
            startRecordingToolStripMenuItem.Tag = false;
            // Set up drawing
            this.SetStyle(ControlStyles.AllPaintingInWmPaint |
              ControlStyles.UserPaint | ControlStyles.Opaque, true);

            // Take a screen
            this.CPU = CPU;
            Screen = LEM1802;
            managedDevices = new Device[] { Screen };
            ScreenIndex = CPU.Devices.IndexOf(Screen);

            Keyboard = null;

            // Take a keyboard
            if (AssignKeyboard)
            {
                for (int i = 0; i < CPU.Devices.Count; i++)
                {
                    if (AssignedKeyboards.Contains(i))
                        continue;
                    if (CPU.Devices[i] is GenericKeyboard)
                    {
                        Keyboard = CPU.Devices[i] as GenericKeyboard;
                        managedDevices = managedDevices.Concat(new Device[] { Keyboard }).ToArray();
                        AssignedKeyboards.Add(i);
                        KeyboardIndex = i;
                        this.detatchKeyboardToolStripMenuItem.Visible = true;
                        break;
                    }
                }
            }
            this.KeyDown += new KeyEventHandler(LEM1802Window_KeyDown);
            this.KeyUp += new KeyEventHandler(LEM1802Window_KeyUp);
            if (this.Keyboard == null)
            {
                this.DragEnter += new DragEventHandler(LEM1802Window_DragEnter);
                this.DragDrop += new DragEventHandler(LEM1802Window_DragDrop);
                this.AllowDrop = true;
            }
            timer = new System.Threading.Timer(delegate(object o)
                {
                    InvalidateAsync();
                }, null, 16, 16); // 60 Hz
            InitClientSize();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Assigns a LEM to the window.  If AssignKeyboard is true, it will search for a keyboard
        /// in the given CPU and assign it to this window as well.
        /// </summary>
        public LEM1802Window(LEM1802 LEM1802, DCPU CPU, bool AssignKeyboard)
        {
            InitializeComponent();
            // Set up drawing
            this.SetStyle(ControlStyles.AllPaintingInWmPaint |
              ControlStyles.UserPaint | ControlStyles.Opaque, true);

            // Take a screen
            Screen = LEM1802;
            ScreenIndex = CPU.Devices.IndexOf(Screen);

            Keyboard = null;

            // Take a keyboard
            if (AssignKeyboard)
            {
                for (int i = 0; i < CPU.Devices.Count; i++)
                {
                    if (AssignedKeyboards.Contains(i))
                        continue;
                    if (CPU.Devices[i] is GenericKeyboard)
                    {
                        Keyboard = CPU.Devices[i] as GenericKeyboard;
                        AssignedKeyboards.Add(i);
                        KeyboardIndex = i;
                        break;
                    }
                }
                this.KeyDown += new KeyEventHandler(LEM1802Window_KeyDown);
                this.KeyUp += new KeyEventHandler(LEM1802Window_KeyUp);
            }
            timer = new System.Threading.Timer(delegate(object o)
                {
                    InvalidateAsync();
                }, null, 16, 16); // 60 Hz
            FormClosing += new FormClosingEventHandler(LEM1802Window_FormClosing);
            InitClientSize();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            DisplaySplash();
            string testFile = null;
            List<string> TestCases = new List<string>();
            // Interpret arguments
            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg.StartsWith("-"))
                {
                    switch (arg)
                    {
                        case "--help":
                        case "-?":
                        case "-h":
                        case "/?":
                        case "/h":
                            DisplayHelp();
                            break;
                    }
                }
                else
                {
                    if (testFile == null)
                        testFile = arg;
                    else
                    {
                        switch (arg)
                        {
                            case "run":
                                TestCases.AddRange(args[++i].Split(','));
                                break;
                            case "debug":
                                TestCases.AddRange(args[++i].Split(','));
                                break;
                            default:
                                return;
                        }
                    }
                }
            }
            if (testFile == null)
            {
                Console.WriteLine("No test file specified.");
                return;
            }
            DCPU CPU = new DCPU();
            List<UnitTest> Tests = new List<UnitTest>();
            List<PreReq> PreReqs = new List<PreReq>();
            using (Stream stream = File.OpenRead(testFile))
            {
                byte[] lengthData = new byte[4];
                stream.Read(lengthData, 0, 4);
                int length = BitConverter.ToInt32(lengthData, 0);
                byte[] section1 = new byte[length];
                stream.Read(section1, 0, section1.Length);

                lengthData = new byte[4];
                stream.Read(lengthData, 0, 4);
                length = BitConverter.ToInt32(lengthData, 0);
                byte[] section2 = new byte[length];
                stream.Read(section2, 0, section2.Length);

                lengthData = new byte[4];
                stream.Read(lengthData, 0, 4);
                length = BitConverter.ToInt32(lengthData, 0);
                byte[] section3 = new byte[length];
                stream.Read(section3, 0, section3.Length);

                string testDefs = Encoding.ASCII.GetString(section1);
                for (int i = 0; i < section2.Length; i += 2)
                    CPU.Memory[i / 2] = (ushort)(section2[i] << 16 | section2[i + 1]);
                // TODO: Listing

                string[] defs = testDefs.Split('\n');
                foreach (var test in defs)
                {
                    string[] parts = test.Split(' ');
                    if (test.StartsWith("PREREQ "))
                    {
                        PreReq pre = new PreReq();
                        pre.Address = ushort.Parse(parts[1], NumberStyles.HexNumber);
                        pre.IncludedTests = parts[2].Split(',');
                        if (PreReqs.Count != 0)
                            PreReqs[PreReqs.Count - 1].EndAddress = (ushort)(pre.Address - 1);
                        PreReqs.Add(pre);
                    }
                    else if (test.StartsWith("TEST "))
                    {
                        string[] range = parts[1].Split('-');
                        UnitTest uTest = new UnitTest(parts[2], ushort.Parse(range[0], NumberStyles.HexNumber));
                        uTest.EndAddress = ushort.Parse(range[1], NumberStyles.HexNumber);
                        Tests.Add(uTest);
                    }
                }
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.Clear();
            Console.TreatControlCAsInput = true;

            Console.WriteLine("Pickles DCPU-16 Debugger     Copyright Drew DeVault 2012");
            Console.WriteLine("Use \"help\" for assistance.");

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                var types = asm.GetTypes().Where(t => typeof(Device).IsAssignableFrom(t) && t.IsAbstract == false);
                foreach (var type in types)
                    PossibleDevices.Add((Device)Activator.CreateInstance(type));
            }

            string input;
            CPU = new DCPU();
            CPU.BreakpointHit += CPU_BreakpointHit;
            CPU.InvalidInstruction += CPU_InvalidInstruction;
            CPU.IsRunning = false;
            LastTick = DateTime.Now;
            ClockTimer = new System.Threading.Timer(FetchExecute, null, 10, Timeout.Infinite);
            while (true)
            {
                Console.Write(">");
                string originalInput = ReadLineEnableShortcuts().Trim();
                ParseInput(originalInput);
                if (originalInput.ToLower() == "quit" || originalInput.ToLower() == "q")
                    break;
            }
        }
Exemplo n.º 12
0
 public static ulong Evaluate(string expression, DCPU cpu)
 {
     expression = expression.Trim();
     // Check for parenthesis
     while (expression.SafeContains('[') && expression.SafeContains(']'))
     {
         var startIndex = -1;
         var endIndex = -1;
         var depth = 0;
         for (int i = 0; i < expression.Length; i++)
         {
             if (expression[i] == '[')
             {
                 if (startIndex == -1)
                     startIndex = i;
                 depth++;
             }
             if (expression[i] == ']')
             {
                 depth--;
                 if (depth == 0)
                 {
                     endIndex = i;
                     break;
                 }
             }
         }
         var subexpression = expression.Substring(startIndex + 1, endIndex - startIndex - 1);
         var result = cpu.Memory[(ushort)Evaluate(subexpression, cpu)];
         expression = expression.Remove(startIndex, endIndex - startIndex + 1);
         expression = expression.Insert(startIndex, result.ToString());
     }
     if (HasOperators(expression))
     {
         // Recurse
         var parts = SplitExpression(expression);
         if (parts[0] == "" && parts[1] == "-") // Negate
             return (ulong)-(long)Evaluate(parts[2], cpu);
         if (parts[0] == "" && parts[1] == "~") // NOT
             return ~Evaluate(parts[2], cpu);
         switch (parts[1]) // Evaluate
         {
             case "+":
                 return Evaluate(parts[0], cpu)
                        +
                        Evaluate(parts[2], cpu);
             case "-":
                 return Evaluate(parts[0], cpu)
                        -
                        Evaluate(parts[2], cpu);
             case "*":
                 return Evaluate(parts[0], cpu)
                        *
                        Evaluate(parts[2], cpu);
             case "/":
                 return Evaluate(parts[0], cpu)
                        /
                        Evaluate(parts[2], cpu);
             case "%":
                 return Evaluate(parts[0], cpu)
                        %
                        Evaluate(parts[2], cpu);
             case "<<":
                 return Evaluate(parts[0], cpu)
                        <<
                        (int)Evaluate(parts[2], cpu);
             case ">>":
                 return Evaluate(parts[0], cpu)
                        >>
                        (int)Evaluate(parts[2], cpu);
             case "<":
                 return Evaluate(parts[0], cpu)
                        <
                        Evaluate(parts[2], cpu) ? 1UL : 0UL;
             case "<=":
                 return Evaluate(parts[0], cpu)
                        <=
                        Evaluate(parts[2], cpu) ? 1UL : 0UL;
             case ">":
                 return Evaluate(parts[0], cpu)
                        >
                        Evaluate(parts[2], cpu) ? 1UL : 0UL;
             case ">=":
                 return Evaluate(parts[0], cpu)
                        >=
                        Evaluate(parts[2], cpu) ? 1UL : 0UL;
             case "==":
                 return Evaluate(parts[0], cpu)
                        ==
                        Evaluate(parts[2], cpu) ? 1UL : 0UL;
             case "!=":
                 return Evaluate(parts[0], cpu)
                        !=
                        Evaluate(parts[2], cpu) ? 1UL : 0UL;
             case "&":
                 return Evaluate(parts[0], cpu)
                        &
                        Evaluate(parts[2], cpu);
             case "^":
                 return Evaluate(parts[0], cpu)
                        ^
                        Evaluate(parts[2], cpu);
             case "|":
                 return Evaluate(parts[0], cpu)
                        |
                        Evaluate(parts[2], cpu);
             case "&&":
                 return (Evaluate(parts[0], cpu) == 1
                        &&
                        Evaluate(parts[2], cpu) == 1) ? 1UL : 0UL;
             case "||":
                 return (Evaluate(parts[0], cpu) == 1
                        ||
                        Evaluate(parts[2], cpu) == 1) ? 1UL : 0UL;
         }
     }
     else
     {
         // Interpret value
         if (expression.StartsWith("0x") || expression.StartsWith("$") || expression.EndsWith("h")) // Hex
             return Convert.ToUInt64(expression, 16);
         else if (expression.StartsWith("0b") || expression.StartsWith("%") || expression.EndsWith("b")) // Binary
             return Convert.ToUInt64(expression, 2);
         else if (expression.StartsWith("0o")) // Octal
             return Convert.ToUInt64(expression, 8);
         else
         {
             // Check for number
             bool number = true;
             for (int i = 0; i < expression.Length; i++)
                 if (!char.IsNumber(expression[i]))
                     number = false;
             if (number) // Decimal
                 return Convert.ToUInt64(expression);
             else
             {
                 // Look up reference, it's a register or something
                 switch (expression.ToUpper())
                 {
                     case "A":
                         return cpu.A;
                     case "B":
                         return cpu.B;
                     case "C":
                         return cpu.C;
                     case "X":
                         return cpu.X;
                     case "Y":
                         return cpu.Y;
                     case "Z":
                         return cpu.Z;
                     case "I":
                         return cpu.I;
                     case "J":
                         return cpu.J;
                     case "PC":
                         return cpu.PC;
                     case "SP":
                         return cpu.SP;
                     case "EX":
                         return cpu.EX;
                     case "IA":
                         return cpu.IA;
                     default:
                         foreach (var kvp in Debugger.KnownLabels)
                         {
                             if (kvp.Value.ToLower() == expression.ToLower())
                             {
                                 return kvp.Key;
                             }
                         }
                         break;
                 }
                 throw new KeyNotFoundException("Symbol not found: " + expression + ".");
             }
         }
     }
     throw new InvalidOperationException("Invalid expression");
 }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            ConfigFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            ConfigFilePath = Path.Combine(ConfigFilePath, ".lettuce");
            Configuration = ConfigurationManager.LoadConfiguration(ConfigFilePath);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            }

            // Enumerate loaded devices from plugins and Tomato
            List<Device> PossibleDevices = new List<Device>();
            GenericKeyboard kb = new GenericKeyboard();
            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                var types = asm.GetTypes().Where(t => typeof(Device).IsAssignableFrom(t) && t.IsAbstract == false);
                foreach (var type in types)
                {
                    PossibleDevices.Add((Device)Activator.CreateInstance(type));
                }
            }

            CPU = new DCPU();
            string binFile = null;
            bool littleEndian = false, pairKeyboards = true;
            List<Device> devices = new List<Device>();
            CPU.IsRunning = false;
            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg.StartsWith("-"))
                {
                    switch (arg)
                    {
                        case "--no-wait":
                        case "--nowait":
                            CPU.IsRunning = true;
                            break;
                        case "-c":
                        case "--connect":
                            if (i + 1 == args.Length || args[i + 1].StartsWith("-"))
                            {
                                Console.Error.WriteLine("Missing argument at --connect");
                                break;
                            }
                            bool gotWrongParam = false;
                            string deviceID = args[++i];
                            string[] ids = deviceID.Split(',');
                            foreach (var dID in ids)
                            {
                                uint id;
                                bool foundDevice = false;

                                if (uint.TryParse(dID, NumberStyles.HexNumber, null, out id))
                                {
                                    foreach (Device d in PossibleDevices)
                                    {
                                        if (d.DeviceID == id)
                                        {
                                            devices.Add((Device) Activator.CreateInstance(d.GetType()));
                                            foundDevice = true;
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (Device d in PossibleDevices)
                                    {
                                        if (d.GetType().Name.ToLower() == dID.ToLower())
                                        {
                                            devices.Add((Device)Activator.CreateInstance(d.GetType()));
                                            foundDevice = true;
                                        }
                                    }
                                }
                                if (!foundDevice)
                                {
                                    Console.Error.WriteLine("Device '" + dID + "' could not be found, continuing..");
                                    gotWrongParam = true;
                                }
                            }
                            if (gotWrongParam)
                                return;
                            break;
                        case "--skip-pairing":
                            pairKeyboards = false;
                            break;
                        case "--listing":
                            var file = args[++i];
                            if(!File.Exists(file))
                            {
                                Console.Error.WriteLine("Could not find listing-file: " + file);
                                return;
                            }
                            Debugger.LoadOrganicListing(file);
                            break;
                        case "--little-endian":
                            littleEndian = true;
                            break;
                        case "--list-devices":
                            Console.WriteLine("Got {0} devices:", PossibleDevices.Count);
                            foreach (var device in PossibleDevices)
                            {
                                Console.WriteLine("ID: 0x{0:X}, Name: {1}", device.DeviceID, device.GetType().Name);
                            }
                            return;
                        case "--disable-auto-arrange":
                            EnableAutomaticArrangement = false;
                            break;
                        case "--help":
                            Console.WriteLine("Lettuce - a graphical debugger for DCPU-16 programs");
                            Console.WriteLine("Options:");
                            Console.WriteLine("\t--no-wait             Starts debugging immediately.");
                            Console.WriteLine("\t--connect [Devices]   A comma-seperated list of devices to connect");
                            Console.WriteLine("\t                      For example: --connect 0x40E41D9D,M35FD");
                            Console.WriteLine("\t                      See also: --list-devices");
                            Console.WriteLine("\t--list-devices        Lists all available devices and exits.");
                            Console.WriteLine("\t--skip-pairing");
                            Console.WriteLine("\t--listing [File.lst]  Loads File.lst to make debugging easier.");
                            Console.WriteLine("\t--little-endian       Switches to little-endian mode.");
                            Console.WriteLine("\t--help                Outputs this and exits.");
                            return;
                    }
                }
                else
                {
                    if (binFile == null)
                        binFile = arg;
                    else
                        Debugger.LoadOrganicListing(args[i]);
                }
            }
            if (binFile == null)
            {
                var mc = new MemoryConfiguration();
                var result = mc.ShowDialog();
                if (result == DialogResult.Cancel)
                    return;
                if (result == DialogResult.OK)
                {
                    binFile = mc.FileName;
                    littleEndian = mc.LittleEndian;
                }
            }
            if (devices.Count == 0)
            {
                var hwc = new HardwareConfiguration();
                var result = hwc.ShowDialog();
                if (result == DialogResult.Cancel)
                    return;
                foreach (var device in hwc.SelectedDevices)
                    devices.Add(device);
            }
            // Inject custom UITypeEditor into M35FD
            TypeDescriptor.AddAttributes(typeof(ushort[]),
                new EditorAttribute(typeof(M35FDTypeEditor), typeof(UITypeEditor)));

            if (!string.IsNullOrEmpty(binFile))
            {
                lastbinFilepath = binFile;
                // Load binary file
                List<ushort> data = new List<ushort>();
                using (Stream stream = File.OpenRead(binFile))
                {
                    for (int i = 0; i < stream.Length; i += 2)
                    {
                        byte a = (byte)stream.ReadByte();
                        byte b = (byte)stream.ReadByte();
                        if (littleEndian)
                            data.Add((ushort)(a | (b << 8)));
                        else
                            data.Add((ushort)(b | (a << 8)));
                    }
                }
                CPU.FlashMemory(data.ToArray());
            }
            else
                CPU.IsRunning = false;
            foreach (var device in devices)
                CPU.ConnectDevice(device);

            debugger = new Debugger(ref CPU);
            if (EnableAutomaticArrangement)
            {
                debugger.StartPosition = FormStartPosition.Manual;
                if (RuntimeInfo.IsMacOSX)
                    debugger.Location = new Point(0, 22);
                else
                    debugger.Location = new Point(0, 0);
            }
            debugger.ResetLayout();
            debugger.Show();

            screenLocation.Y = debugger.Location.Y + 4;
            screenLocation.X = debugger.Location.X + debugger.Width + 5;

            foreach (Device d in CPU.Devices)
            {
                if (d is LEM1802)
                    AddWindow(new LEM1802Window(d as LEM1802, CPU, pairKeyboards));
                else if (d is SPED3)
                    AddWindow(new SPED3Window(d as SPED3, CPU));
                else if (d is M35FD)
                    AddWindow(new M35FDWindow(d as M35FD, CPU));
            }

            // Run again for extra keyboards
            for (int i = 0; i < CPU.Devices.Count; i++)
            {
                if (CPU.Devices[i] is GenericKeyboard && !LEM1802Window.AssignedKeyboards.Contains(i))
                    AddWindow(new GenericKeyboardWindow(CPU.Devices[i] as GenericKeyboard, CPU));
            }

            debugger.Focus();
            LastTick = DateTime.Now;
            timer = new System.Threading.Timer(FetchExecute, null, 10, Timeout.Infinite);
            Application.Run(debugger);
            timer.Dispose();
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            RuntimeInfo.GatherInfo();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            }

            // Enumerate loaded devices from plugins and Tomato
            List<Device> PossibleDevices = new List<Device>();
            GenericKeyboard kb = new GenericKeyboard();
            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                var types = asm.GetTypes().Where(t => typeof(Device).IsAssignableFrom(t) && t.IsAbstract == false);
                foreach (var type in types)
                {
                    PossibleDevices.Add((Device)Activator.CreateInstance(type));
                }
            }

            CPU = new DCPU();
            string binFile = null;
            bool littleEndian = false;
            List<Device> devices = new List<Device>();
            CPU.IsRunning = false;
            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg.StartsWith("-"))
                {
                    switch (arg)
                    {
                        case "--no-wait":
                        case "--nowait":
                            CPU.IsRunning = true;
                            break;
                        case "-c":
                        case "--connect":
                            string deviceID = args[++i];
                            string[] ids = deviceID.Split(',');
                            foreach (var dID in ids)
                            {
                                uint id;
                                if (uint.TryParse(dID, NumberStyles.HexNumber, null, out id))
                                {
                                    foreach (Device d in PossibleDevices)
                                    {
                                        if (d.DeviceID == id)
                                            devices.Add((Device)Activator.CreateInstance(d.GetType()));
                                    }
                                }
                                else
                                {
                                    foreach (Device d in PossibleDevices)
                                    {
                                        if (d.GetType().Name.ToLower() == dID.ToLower())
                                            devices.Add((Device)Activator.CreateInstance(d.GetType()));
                                    }
                                }
                            }
                            break;
                        case "--listing":
                            Debugger.LoadOrganicListing(args[++i]);
                            break;
                    }
                }
                else
                {
                    if (binFile == null)
                        binFile = arg;
                    else
                        Debugger.LoadOrganicListing(args[i]);
                }
            }
            if (binFile == null)
            {
                MemoryConfiguration mc = new MemoryConfiguration();
                if (mc.ShowDialog() == DialogResult.OK)
                {
                    binFile = mc.FileName;
                    littleEndian = mc.LittleEndian;
                }
            }
            if (devices.Count == 0)
            {
                HardwareConfiguration hwc = new HardwareConfiguration();
                hwc.ShowDialog();
                foreach (var device in hwc.SelectedDevices)
                    devices.Add(device);
            }
            if (!string.IsNullOrEmpty(binFile))
            {
                lastbinFilepath = binFile;
                // Load binary file
                List<ushort> data = new List<ushort>();
                using (Stream stream = File.OpenRead(binFile))
                {
                    for (int i = 0; i < stream.Length; i += 2)
                    {
                        byte a = (byte)stream.ReadByte();
                        byte b = (byte)stream.ReadByte();
                        if (littleEndian)
                            data.Add((ushort)(a | (b << 8)));
                        else
                            data.Add((ushort)(b | (a << 8)));
                    }
                }
                CPU.FlashMemory(data.ToArray());
            }
            else
                CPU.IsRunning = false;
            foreach (var device in devices)
                CPU.ConnectDevice(device);

            debugger = new Debugger(ref CPU);
            debugger.StartPosition = FormStartPosition.Manual;
            debugger.Location = new Point(0, 0);
            debugger.ResetLayout();
            debugger.Show();

            screenLocation.Y = debugger.Location.Y + 4;
            screenLocation.X = debugger.Location.X + debugger.Width + 5;

            int keyboardCount = 0;
            foreach (Device d in CPU.Devices)
                if (d is LEM1802)
                    AddWindow(new LEM1802Window(d as LEM1802, CPU, true));
                else if (d is GenericKeyboard)
                    keyboardCount++;

            int remaining = keyboardCount - LEM1802Window.AssignedKeyboards.Count();
            for(;remaining > 0; remaining--)
                AddWindow(new GenerickeyboardWindow(null, CPU, true));

            debugger.Focus();
            LastTick = DateTime.Now;
            timer = new System.Threading.Timer(FetchExecute, null, 10, Timeout.Infinite);
            Application.Run(debugger);
            timer.Dispose();
        }
Exemplo n.º 15
0
        public override void Render(IGameContext gameContext, IRenderContext renderContext)
        {
            if (this.m_DCPU != null)
            {
                this.m_DCPU.Execute((int)(100000 * gameContext.GameTime.ElapsedGameTime.TotalSeconds));
            }

            this.m_TextureCounter++;
            if (this.m_TextureCounter >= 5 * 30)
            {
                this.m_TextureCounter = 0;
            }

            var textureCounter = this.m_TextureCounter / 30;

            this.AboveTextureIndex = 12 + textureCounter;
            this.BelowTextureIndex = 12 + textureCounter;
            this.LeftTextureIndex = 12 + textureCounter;
            this.RightTextureIndex = 12 + textureCounter;
            this.FrontTextureIndex = 12 + textureCounter;
            this.BackTextureIndex = 12 + textureCounter;

            base.Render(gameContext, renderContext);

            if (this.m_Spawned)
            {
                return;
            }

            this.m_DCPU = new DCPU();

            foreach (var connection in this.Connections)
            {
                connection.PrepareDevice();
                this.m_DCPU.ConnectDevice(connection.TomatoDevice);
            }

            var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Mir.test.bin");
            var program = new ushort[stream.Length / 2];
            for (var i = 0; i < program.Length; i++)
            {
                var left = (byte)stream.ReadByte();
                var right = (byte)stream.ReadByte();
                var value = (ushort)(right | (left << 8));
                program[i] = value;
            }

            this.m_DCPU.FlashMemory(program);

            this.m_Spawned = true;
        }
Exemplo n.º 16
0
 public TomatoDcpu16Adapter(DCPU dcpu16)
 {
     _dcpu16 = dcpu16;
 }