private void LoadDeck(string deck) { FileStream deckStream = new FileStream(deck, FileMode.Open); machine.RedirectDevice(MIXMachine.CARD_READER, deckStream); machine.LoadDeck(); deckStream.Close(); machine.RedirectDevice(MIXMachine.CARD_READER, null); }
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(); } } }