Esempio n. 1
0
        static void Main(string[] args)
        {
            var mach = new MIXMachine();

            mach.LoadROM(new List <List <int> >()
            {
                new List <int>()
                {
                    1, 31, 16, 2, 3, 8
                },
                new List <int>()
                {
                    1, 31, 16, 2, 11, 8
                },
                new List <int>()
                {
                    1, 31, 16, 0, 11, 8
                },
                new List <int>()
                {
                    1, 31, 16, 0, 5, 8
                },
                new List <int>()
                {
                    0, 31, 16, 4, 5, 8
                }
            }
                         , 2000);
            mach.RunInstruction(2000);
            return;
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Dictionary <string, string> aliases = new Dictionary <string, string>();

            aliases.Add("-d", "--deck");
            aliases.Add("-b", "--binary");
            aliases.Add("-?", "--help");
            aliases.Add("-h", "--help");

            Dictionary <string, string> cmdLine = CommandLineHelper.SplitCommandLine(Environment.CommandLine, aliases, true);

            if (cmdLine.Count == 0)
            {
                Console.WriteLine("This is MIX v0.1, (c) 2009 George Tryfonas\nAn mplementation of the machine described by Don Knuth.\n\nType '?' or 'help' at the prompt for instructions.\n");
                MIXController c = new MIXController();
                c.Interface();
            }
            else
            {
                Stream stream;

                MIXMachine machine = new MIXMachine();
                string     inFile  = GetInputFile(cmdLine);
                if (string.IsNullOrEmpty(inFile))
                {
                    stream = Console.OpenStandardInput();
                }
                else
                {
                    stream = new FileStream(inFile, FileMode.Open);
                }

                if (cmdLine.ContainsKey("--deck"))
                {
                    machine.RedirectDevice(MIXMachine.CARD_READER, stream);
                    machine.LoadDeck();
                }
                else if (cmdLine.ContainsKey("--binary"))
                {
                    IFormatter        formatter = new BinaryFormatter();
                    MIXWord           startLoc  = (MIXWord)formatter.Deserialize(stream);
                    List <MemoryCell> data      = (List <MemoryCell>)formatter.Deserialize(stream);

                    machine.LoadImage(data);
                    machine.PC = startLoc;
                    machine.Run();
                }
            }
        }
Esempio n. 3
0
        public void Interface()
        {
            string input = "";

            while (true)
            {
                // Get next command
                Console.Write("> ");
                input = Console.ReadLine();
                var commands = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                if (commands.Length > 0)
                {
                    switch (commands[0].Trim().ToLower())
                    {
                    case "?":
                    case "help":
                        Help(commands.Skip(1).ToArray());
                        break;

                    case "reboot":
                        Console.WriteLine("Rebooting...");
                        machine     = new MIXMachine();
                        symbolTable = new Dictionary <string, MIXWord>();
                        Console.WriteLine("Done.");
                        break;

                    case "quit":
                    case "exit":
                        Console.WriteLine("Bye.");
                        Environment.Exit(0);
                        break;

                    case "load":
                        int w = LoadImage(commands[1]);
                        Console.WriteLine(string.Format("Loaded {0} word(s). PC set to {1}", w, machine.PC));
                        break;

                    case "loaddeck":
                        LoadDeck(commands[1]);
                        break;

                    case "verbose":
                        verbose = !verbose;
                        break;

                    case "show":
                        Show(commands.Skip(1).ToArray());
                        break;

                    case "set":
                        Set(commands.Skip(1).ToArray());
                        break;

                    case "clear":
                        Clear(commands.Skip(1).ToArray());
                        break;

                    case "step":
                        Console.WriteLine(string.Format("PC: {1} - Executing: {0}", GetDisassembly(machine.Memory[machine.PC]), machine.PC));
                        machine.Step();
                        if (verbose)
                        {
                            ShowAllState();
                        }
                        Console.WriteLine("Done.");
                        break;

                    case "go":
                    case "run":
                        Console.WriteLine("Executing...");
                        machine.Run();
                        if (verbose)
                        {
                            ShowAllState();
                        }
                        Console.WriteLine("Done.");
                        break;

                    case "redir":
                    case "redirect":
                        Redirect(commands.Skip(1).ToArray());
                        break;

                    default:
                        Console.Error.WriteLine("Unknown command.");
                        break;
                    }
                }
            }
        }
Esempio n. 4
0
 public MIXController()
 {
     machine     = new MIXMachine();
     verbose     = false;
     symbolTable = new Dictionary <string, MIXWord>();
 }