- mixware.zip
- Examples
- easter.mixal
- maximum.mixal
- perms.mixal
- perms-input.deck
- primes.mixal
- MIX
- MIXAsm
- MIXLib
- MIXWare.pdf
- MIXWare.sln
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MIXLib;
using MIXLib.Util;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace MIX
{
class Program
{
private static string GetInputFile(Dictionary<string, string> cmdLine)
{
var a = cmdLine.Keys.Where(cl => !cl.StartsWith("-") && !cl.StartsWith("/"));
if (a.Count() > 0)
return a.First();
return 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();
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software developer (mainly in C# and T-SQL) for a project management company in Athens, Greece. I have been working with computers since early 1987. I am adept at Pascal, C, C++, Java (my MSc was sponsored by Sun Microsystems), Lisp, Scheme, F#, C# VB.Net, Perl and some others that are too obscure to mention. When I want a quick and dirty solution to a programming problem I use a functional language, such as Haskell, Scheme or, more recently, F#.
I also play the keyboards and compose music.
---------------------------------------------------------
MSc Distributed Systems and Networks - University of Kent at Canterbury
BEng Computer Systems Engineering - University of Kent at Canterbury