//public void AcceptUserProgram() //{ // int memoryLocation = 0; // string response; // do // User is still entering commands // { // //Keep accepting commands // Console.Write(memoryLocation + " ? "); // response = Console.ReadLine(); // string operation = response.Substring(0, 2); // string operand = response.Substring(2, 2); // memory.Add(new WordModel { MemoryLocation = memoryLocation++, Operation = operation, Operand = operand }); // } while (response != "9999"); // foreach (var word in memory) // { // RunCommand(word.Operation, word.Operand); // pc++; // } //} public static void RunProgram(this UVSimModel uvSim, List <string> program) { foreach (var instruction in program) { uvSim.RunCommand(instruction); } }
// Ben Thornhill public static void RunProgram(this UVSimModel uvSim) { //Changed so program will run untill a halt command or reaches end of memory while (uvSim.ProgramCounter != -666 && uvSim.ProgramCounter < uvSim.MemorySize) { string firstWord = uvSim.Memory[uvSim.ProgramCounter]; string secondWord = uvSim.Memory[uvSim.ProgramCounter + 1]; string fullInstruction = firstWord + secondWord; try { uvSim.RunCommand(fullInstruction); } catch { string firstWordWithoutBreakpoint = firstWord.Substring(0, 2) + "00"; uvSim.Memory[uvSim.ProgramCounter] = firstWordWithoutBreakpoint; throw; } uvSim.ProgramCounter += 2; } }