Exemple #1
0
        public static async Task Main(string[] args)
        {
            if (Environment.GetEnvironmentVariable("MANAGED_DEBUGGER_WAIT") == "1")
            {
                HandleDebugger();
            }

            InitializeProcess();
            var bus = new Bus();

            InitializeFlags(bus);

            if (AppFlag.GetVariable("VM_TRACE"))
            {
                DeviceLoader.OnTrace += Console.WriteLine;
            }

            DeviceLoader.AutoGrub(bus.Add);

            InitializeMemory(bus, args);


            while (bus.State.halt == 0)
            {
                bus.cpu.Step();
                await Task.Delay(1).ConfigureAwait(false);
            }

            bus.Unload();
        }
Exemple #2
0
 public static void InitializeFlags(Bus bus)
 {
     /* @0x11 */
     bus.State.tc = AppFlag.GetVariable("VM_TRACE");
     /* @0x12 */
     bus.State.ec = AppFlag.GetVariable("VM_ERROR", true);
     /* @0x13 */
     bus.State.km = AppFlag.GetVariable("VM_KEEP_MEMORY");
     /* @0x14 */
     bus.State.fw = AppFlag.GetVariable("VM_MEM_FAST_WRITE");
 }
Exemple #3
0
        static DeviceLoader()
        {
            if (AppFlag.GetVariable("VM_TRACE"))
            {
                OnTrace += Console.WriteLine;
            }

            AssemblyLoadContext.Default.Resolving += (context, name) =>
            {
                var assemblyPath = $"./{name.Name}.dll";
                return(context.LoadFromAssemblyPath(assemblyPath));
            };
        }
Exemple #4
0
        public static void InitializeMemory(Bus bus, params string[] args)
        {
            if (bus.State.halt != 0)
            {
                return;
            }
            if (!args.Any())
            {
                bus.State.Load("<chip>", 0xB00B5000);
            }
            else
            {
                var nameFile = Path.Combine(Path.GetDirectoryName(args.First()), Path.GetFileNameWithoutExtension(args.First()));
                var file     = new FileInfo($"{nameFile}.dlx");
                var bios     = new FileInfo($"{nameFile}.bios");
                var pdb      = new FileInfo($"{nameFile}.pdb");

                if (AppFlag.GetVariable("VM_ATTACH_DEBUGGER") && pdb.Exists)
                {
                    bus.AttachDebugger(new Debugger(DebugSymbols.Open(File.ReadAllBytes(pdb.FullName))));
                }
                if (bios.Exists)
                {
                    var asm   = AncientAssembly.LoadFrom(bios.FullName);
                    var bytes = asm.GetILCode();
                    var meta  = asm.GetMetaILCode();
                    bus.State.Load("<bios>", CastFromBytes(bytes));
                    bus.State.LoadMeta(meta);
                }
                if (file.Exists)
                {
                    var asm   = AncientAssembly.LoadFrom(file.FullName);
                    var bytes = asm.GetILCode();
                    var meta  = asm.GetMetaILCode();
                    bus.State.Load("<exec>", CastFromBytes(bytes));
                    bus.State.LoadMeta(meta);
                }
                else
                {
                    bus.State.Load("<chip>", 0xB00B5000);
                }
            }
        }
Exemple #5
0
        public static async Task Main(string[] args)
        {
            if (AppFlag.GetVariable("MANAGED_DEBUGGER_WAIT"))
            {
                HandleDebugger();
            }

            InitializeProcess();
            var bus = new Bus();

            InitializeFlags(bus);

            if (AppFlag.GetVariable("VM_TRACE"))
            {
                DeviceLoader.OnTrace += Console.WriteLine;
            }

            Module.Boot(bus);
            InternalVMFunctions.Boot(bus);
            DeviceLoader.Boot(bus.Add);

            if (AppFlag.GetVariable("REPL"))
            {
                Console.WriteLine("@ Ancient VM Interactive @".Pastel(Color.Green));
                InteractiveConstruction(bus);
            }
            else
            {
                InitializeMemory(bus, args);
            }

            while (bus.State.halt == 0)
            {
                bus.cpu.Step();
            }
            bus.Unload();
        }