Exemplo n.º 1
0
        public GraphicalClient(GraphicalComputer computer)
        {
            InitializeComponent();

            Computer = computer;

            // create the images
            computer.RenderImage  = new Bitmap(DisplayRectangle.Width, DisplayRectangle.Height);
            computer.DisplayImage = new Bitmap(DisplayRectangle.Width, DisplayRectangle.Height);
            // and the graphics handle
            computer.Graphics = Graphics.FromImage(computer.RenderImage);

            // and the rendering tools
            computer.Brush = new SolidBrush(Color.Black);
            computer.Pen   = new Pen(Color.Black);
            computer.Font  = new Font(FontFamily.GenericSansSerif, 16);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes a program via the graphical client. returns true if there were no errors
        /// </summary>
        /// <param name="exe">the code to execute</param>
        private static int RunGraphical(Executable exe, string[] args, bool fsf)
        {
            // create the computer
            using (GraphicalComputer computer = new GraphicalComputer())
            {
                try
                {
                    // initialize program
                    computer.Initialize(exe, args);
                }
                catch (MemoryAllocException ex)
                {
                    Console.Error.WriteLine(ex.Message);
                    return((int)AsmLnkErrorExt.MemoryAllocError);
                }

                // set private flags
                computer.FSF = fsf;

                // this usage is just going for raw speed, so enable OTRF
                computer.OTRF = true;

                // create the console client
                using (GraphicalClient graphics = new GraphicalClient(computer))
                {
                    // begin execution
                    graphics.ShowDialog();

                    // if there was an error
                    if (computer.Error != ErrorCode.None)
                    {
                        // print error message
                        Console.Error.WriteLine($"\n\nError Encountered: ({computer.Error}) {ErrorCodeToString.Get(computer.Error)}");
                        // return execution error code
                        return(ExecErrorReturnCode);
                    }
                    // otherwise use return value
                    else
                    {
                        return(computer.ReturnValue);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static unsafe int Main(string[] args)
        {
            try
            {
                if (!BitConverter.IsLittleEndian)
                {
                    Console.Error.WriteLine(
                        @"(Uhoh!! Looks like this platform isn't little-endian!
Most everything in CSX64 assumes little-endian,
so most of it won't work on this system!
)");
                    return(-1);
                }

                // ------------------------------------- //

                // set up initilization thingys for graphical stuff
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // run statics fom client sources
                GraphicalComputer.InitStatics();

                // ------------------------------------- //

                cmdln_pack dat = new cmdln_pack();

                if (!dat.parse(args))
                {
                    return(0);
                }

                // ------------------------------------- //

                // perform the action
                switch (dat.action)
                {
                case ProgramAction.ExecuteConsole:

                {
                    if (dat.pathspec.Count == 0)
                    {
                        Console.Error.WriteLine("Expected a file to execute"); return(0);
                    }

                    Executable exe = new Executable();
                    int        res = LoadExecutable(dat.pathspec[0], exe);

                    return(res != 0 ? res : RunConsole(exe, dat.pathspec.ToArray(), dat.fsf, dat.time));
                }

                case ProgramAction.ExecuteGraphical:

                {
                    if (dat.pathspec.Count == 0)
                    {
                        Console.Error.WriteLine("Expected a file to execute"); return(0);
                    }

                    Executable exe = new Executable();
                    int        res = LoadExecutable(dat.pathspec[0], exe);

                    return(res != 0 ? res : RunGraphical(exe, dat.pathspec.ToArray(), dat.fsf));
                }

                case ProgramAction.ExecuteConsoleScript:

                {
                    if (dat.pathspec.Count == 0)
                    {
                        Console.Error.WriteLine("Expected a file to assemble, link, and execute"); return(0);
                    }

                    AddPredefines();
                    Executable exe = new Executable();

                    int res = Link(exe, new List <string>()
                        {
                            dat.pathspec[0]
                        }, dat.entry_point ?? "main", dat.rootdir);

                    return(res != 0 ? res : RunConsole(exe, dat.pathspec.ToArray(), dat.fsf, dat.time));
                }

                case ProgramAction.ExecuteConsoleMultiscript:

                {
                    if (dat.pathspec.Count == 0)
                    {
                        Console.Error.WriteLine("Expected 1+ files to assemble, link, and execute"); return(0);
                    }

                    AddPredefines();
                    Executable exe = new Executable();

                    int res = Link(exe, dat.pathspec, dat.entry_point ?? "main", dat.rootdir);

                    return(res != 0 ? res : RunConsole(exe, new string[] { "<script>" }, dat.fsf, dat.time));
                }

                case ProgramAction.Assemble:

                {
                    if (dat.pathspec.Count == 0)
                    {
                        Console.Error.WriteLine("Expected 1+ files to assemble"); return(0);
                    }

                    AddPredefines();
                    ObjectFile obj = new ObjectFile();

                    // if no explicit output is provided, batch process each pathspec
                    if (dat.output == null)
                    {
                        foreach (string path in dat.pathspec)
                        {
                            int res = Assemble(path, obj);
                            if (res != 0)
                            {
                                return(res);
                            }

                            res = SaveObjectFile(Path.ChangeExtension(path, ".o"), obj);
                            if (res != 0)
                            {
                                return(res);
                            }
                        }
                        return(0);
                    }
                    // otherwise, we're expecting only one input with a named output
                    else
                    {
                        if (dat.pathspec.Count != 1)
                        {
                            Console.Error.WriteLine("Assembler with an explicit output expected only one input"); return(0);
                        }

                        int res = Assemble(dat.pathspec[0], obj);
                        return(res != 0 ? res : SaveObjectFile(dat.output, obj));
                    }
                }

                case ProgramAction.Link:

                {
                    if (dat.pathspec.Count == 0)
                    {
                        Console.Error.WriteLine("Linker expected 1+ files to link"); return(0);
                    }

                    AddPredefines();
                    Executable exe = new Executable();

                    int res = Link(exe, dat.pathspec, dat.entry_point ?? "main", dat.rootdir);
                    return(res != 0 ? res : SaveExecutable(dat.output ?? "a.out", exe));
                }
                }                 // end switch

                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"UNHANDLED EXCEPTION:\n{ex}");
                return(-666);
            }
        }