private SystemExecutionState ExecuteLine(string line, ImlacSystem system) { SystemExecutionState next = SystemExecutionState.Debugging; if (line.StartsWith("#")) { // Comments start with "#", just ignore them } else if (line.StartsWith("@")) { // A line beginning with an "@" indicates a script to execute. string scriptFile = line.Substring(1); next = ExecuteScript(system, scriptFile); } else { string[] args = null; DebuggerCommand command = GetDebuggerCommandFromCommandString(line, out args); if (command == null) { // Not a command. Console.WriteLine("Invalid command."); } else { next = InvokeConsoleMethod(command, args, system); } } return(next); }
public SystemExecutionState Prompt(ImlacSystem system) { SystemExecutionState next = SystemExecutionState.Debugging; try { system.PrintProcessorStatus(); // Get the command string from the prompt. string command = _consolePrompt.Prompt().Trim(); if (string.IsNullOrEmpty(command)) { // Repeat the last command command = _lastCommand; Console.WriteLine(">> {0}", command); } next = ExecuteLine(command, system); _lastCommand = command; } catch (Exception e) { Console.WriteLine( "Error: {0}", e.InnerException != null ? e.InnerException.Message : e.Message); } return(next); }
public TTY(ImlacSystem system) { _system = system; _dataChannel = new NullDataChannel(); Reset(); }
public SystemExecutionState ExecuteScript(ImlacSystem system, string scriptFile) { SystemExecutionState state = SystemExecutionState.Halted; using (StreamReader sr = new StreamReader(scriptFile)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { Console.WriteLine(line); state = ExecuteLine(line, system); } } } return(state); }
public InterruptFacility(ImlacSystem system) { _system = system; }
public Keyboard(ImlacSystem system) { _system = system; Reset(); }
private SystemExecutionState InvokeConsoleMethod(DebuggerCommand command, string[] args, ImlacSystem system) { MethodInfo method = null; // // Find the method that matches the arg count we were passed // (i.e. handle overloaded commands). // That this only matches on argument count is somewhat of a kluge... // foreach (MethodInfo m in command.Methods) { ParameterInfo[] paramInfo = m.GetParameters(); if (args == null && paramInfo.Length == 0 || paramInfo.Length == args.Length) { // found a match method = m; break; } } if (method == null) { // invalid argument count. throw new ArgumentException(String.Format("Invalid argument count to command.")); } ParameterInfo[] parameterInfo = method.GetParameters(); object[] invokeParams; if (args == null) { invokeParams = null; } else { invokeParams = new object[parameterInfo.Length]; } int argIndex = 0; for (int paramIndex = 0; paramIndex < parameterInfo.Length; paramIndex++) { ParameterInfo p = parameterInfo[paramIndex]; if (p.ParameterType.IsEnum) { // // This is an enumeration type. // See if we can find an enumerant that matches the argument. // FieldInfo[] fields = p.ParameterType.GetFields(); foreach (FieldInfo f in fields) { if (!f.IsSpecialName && args[argIndex].ToLower() == f.Name.ToLower()) { invokeParams[paramIndex] = f.GetRawConstantValue(); break; } } if (invokeParams[paramIndex] == null) { // no match, provide possible values StringBuilder sb = new StringBuilder(String.Format("Invalid value for parameter {0}. Possible values are:", paramIndex)); foreach (FieldInfo f in fields) { if (!f.IsSpecialName) { sb.AppendFormat("{0} ", f.Name); } } sb.AppendLine(); throw new ArgumentException(sb.ToString()); } argIndex++; } else if (p.ParameterType.IsArray) { // // If a function takes an array type, i should do something here, yeah. // argIndex++; } else { if (p.ParameterType == typeof(bool)) { invokeParams[paramIndex] = bool.Parse(args[argIndex++]); } else if (p.ParameterType == typeof(uint)) { invokeParams[paramIndex] = TryParseUint(args[argIndex++]); } else if (p.ParameterType == typeof(ushort)) { invokeParams[paramIndex] = TryParseUshort(args[argIndex++]); } else if (p.ParameterType == typeof(string)) { invokeParams[paramIndex] = args[argIndex++]; } else if (p.ParameterType == typeof(char)) { invokeParams[paramIndex] = (char)args[argIndex++][0]; } else if (p.ParameterType == typeof(float)) { invokeParams[paramIndex] = float.Parse(args[argIndex++]); } else { throw new ArgumentException(String.Format("Unhandled type for parameter {0}, type {1}", paramIndex, p.ParameterType)); } } } // // If we've made it THIS far, then we were able to parse all the commands into what they should be. // Invoke the method on the object instance associated with the command. // return((SystemExecutionState)method.Invoke(command.Instance, invokeParams)); }
public PaperTapeReader(ImlacSystem system) { _system = system; }
public AddressableClock(ImlacSystem system) { _system = system; Reset(); }