Esempio n. 1
0
        public void AssembleFromArgs(string[] args)
        {
            string inPath, outPath, error;

            string[] options;

            if (!TryReadArguments(args, out inPath, out outPath, out options, out error))
            {
                StdConsole.StdOutWriteLine(string.Format(c_ErrArguments, error));
                return;
            }

            StdConsole.StdOutWriteLine(string.Format(c_DescAssembler, inPath, outPath));

            List <byte> machineCode;
            string      errorMessage;

            if (TryAssemble(inPath, out machineCode, out errorMessage))
            {
                StdConsole.StdOutWriteLine(c_DescSuccess);
                if (TryWriteMachineCode(machineCode, Path.GetDirectoryName(inPath), outPath))
                {
                    StdConsole.StdOutWriteLine(c_DescFileWrittenPressKey);
                }
                else
                {
                    StdConsole.StdOutWriteLine(c_ErrWritingOutput);
                }
            }
            else
            {
                StdConsole.StdOutWriteLine(string.Format(c_ErrAssembling, errorMessage));
            }
        }
Esempio n. 2
0
        // default entry point
        private static void Main(string[] args)
        {
            StdConsole.ShowConsoleWindow();
            StdConsole.Clear();

            if (args == null || args.Length == 0)
            {
                StdConsole.StdOutWriteLine(c_ErrNoArguments);
                bool waitForKey = true;
                while (waitForKey)
                {
                    ConsoleKeyInfo cki = StdConsole.StdInReadKey();
                    switch (cki.KeyChar)
                    {
                    case '1':
#if DEBUG
                        args = new string[] { "-asm", "../../Examples/testconsole.asm" };
#else
                        args = new[] { "-asm", "../Examples/testconsole.asm" };
#endif
                        waitForKey = false;
                        break;

                    /*case '2':
                     * args = new string[] { "-disasm", "../Examples/testconsole.asm.bin" };
                     * waitForKey = false;
                     * break;*/
                    case '2':
#if DEBUG
                        args = new string[] { "-emu", "../../Examples/testconsole.asm.bin" };
#else
                        args = new[] { "-emu", "../Examples/testconsole.asm.bin" };
#endif
                        waitForKey = false;
                        break;

                    case '3':
                        args       = new[] { "-test" };
                        waitForKey = false;
                        break;

                    case '4':
                        StdConsole.HideConsoleWindow();
                        Environment.Exit(1);
                        break;
                    }
                }
            }

            if (args.Length > 0)
            {
                switch (args[0])
                {
                case "-asm":     // run assembler
                    Asm asm = new Asm();
                    asm.AssembleFromArgs(args);
                    StdConsole.StdInReadKey();
                    break;

                case "-disasm":     // run disassembler
                    Dsm disasm = new Dsm();
                    disasm.TryDisassemble(args);
                    StdConsole.StdInReadKey();
                    break;

                case "-emu":     // run emulator!
                    StdConsole.StdOutWriteLine("Starting emulator... ");
                    Emu e = new Emu();
                    e.SetArgs(args);
                    StdConsole.HideConsoleWindow();
                    e.Run();
                    break;

                case "-test":     // run assembly tests
                    StdConsole.StdOutWriteLine(Tests.Run());
                    StdConsole.StdInReadKey();
                    break;

                default:
                    // do nothing;
                    break;
                }
            }
        }