예제 #1
0
파일: BoardReader.cs 프로젝트: embix/TIS100
        public static void Load(string filename, Board board)
        {
            foreach (var line in File.ReadLines(filename)) {
                // Trim and split the line
                var split = line.Trim()
                                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                // Ignore blank lines
                if (split.Length == 0) {
                    continue;
                }

                // Get name, x, y, and type
                if (split.Length != 4) {
                    throw new Exception("Expected [name] [x] [y] [type] instead of: " + line);
                }

                var name = split[0];

                int x, y;
                if (!Int32.TryParse(split[1], out x) || !Int32.TryParse(split[2], out y)) {
                    throw new Exception("Expected integers for [x] and [y] instead of: " + split[1] + " " + split[2]);
                }

                var chip = Instantiate(split[3]);

                // Install the chip
                var point = new Point(x, y);
                board.Name(name, point);
                board.Install(chip, point);
            }
        }
예제 #2
0
 private static void SetProgram(Board board, string chipName, string assembly)
 {
     if (chipName != "") {
         var chip = board.GetChip(chipName) as AssemblyChip;
         // TODO: Null anti pattern here
         if (chip != null) {
             chip.Operations = Compiler.Compile(assembly.ToString());
         } else {
             throw new Exception(string.Format("Unable to set program for: {0}", chipName));
         }
     }
 }
예제 #3
0
파일: Program.cs 프로젝트: embix/TIS100
        static void Main(string[] args)
        {
            if (args.Length != 2) {
                Console.WriteLine("Usage: TIS100.exe <asm filename> <board filename>");
                return;
            }

            var board = new Board();
            BoardReader.Load(args[1], board);
            AssemblyReader.Load(args[0], board);
            board.ExecuteUntilBlocked();
        }
예제 #4
0
        public static void Load(string filename, Board board)
        {
            var chipName = "";
            var assembly = new StringBuilder();

            foreach (var line in File.ReadLines(filename)) {
                var trimmed = line.Trim();

                if (trimmed.StartsWith("@")) {
                    SetProgram(board, chipName, assembly.ToString());
                    chipName = trimmed;
                    assembly.Clear();
                } else if (chipName != "") {
                    assembly.AppendLine(line);
                }
            }

            SetProgram(board, chipName, assembly.ToString());
        }