Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Chris Lomont's 6800/6809 assembler for his Robotron 2084 reverse engineering project, v0.1.");

            var options = ParseOptions(args);

            if (String.IsNullOrEmpty(options.SourceName))
            {
                Console.Error.WriteLine("Must have source filename");
                ShowHelp(Console.Out);
                return;
            }
            if (!File.Exists(options.SourceName))
            {
                Console.Error.WriteLine($"File {options.SourceName} does not exist");
                return;
            }


            var runInteractive = options.Interactive;

            var debugLength = 0xF000; // todo - allow entering page, show 256 on both sides of value

            //options.TestNum = 2;
            do
            {
                var asm = new Assembler();
                if (asm.Assemble(options.SourceName, Console.Out))
                {
                    //var rd = new RomDiff();
                    //rd.DiffRoms(asm.State, options.RomPath);

                    if (options.ShowChecksums)
                    {
                        Validator.ShowChecksums(asm.State);
                    }

                    Validator.CheckDifferences(
                        options.RomPath,
                        asm.State,
                        debugLength,
                        options.TestNum,
                        20);
                    if (!String.IsNullOrEmpty(options.OutputName))
                    {
                        File.WriteAllBytes(options.OutputName, asm.State.RomImage);
                        Console.WriteLine($"ROM file {options.OutputName} written");
                    }
                    if (!String.IsNullOrEmpty(options.SplitPath))
                    {
                        Splitter.Split(asm.State, options.SplitPath);
                    }
                }

                if (runInteractive)
                {
                    while (!Console.KeyAvailable)
                    {
                    }
                    var c = Console.ReadKey(true).KeyChar;
                    if (c == 'q' || c == 'Q')
                    {
                        runInteractive = false;
                    }
                    else if (c == '+')
                    {
                        debugLength += 256;
                    }
                    else if (c == '-' && debugLength > 256)
                    {
                        debugLength += 256;
                    }
                    else if ('1' <= c && c <= '9')
                    {
                        options.TestNum = c - '1' + 1;
                    }
                    else if (c == 'd')
                    {
                        Console.Write("Enter address: ");
                        var txt     = Console.ReadLine();
                        var address = Convert.ToUInt32(txt, 16);
                        debugLength = (int)address;
                    }
                    else if (c == '?')
                    {
                        Console.WriteLine("Test values: ");
                        foreach (var msg in Validator.Descriptions)
                        {
                            Console.WriteLine(msg);
                        }
                        Console.WriteLine();
                    }
                    else
                    {// todo help
                        //ShowHelp(Console.Error);
                        Console.WriteLine("press 'q' to quit");
                    }
                }
            } while (runInteractive);

            Console.WriteLine("Done...");
        }