/// <summary> /// Loads the machine program from a binary file. /// </summary> /// <remarks>The first word represents the origin.</remarks> /// <param name="filename">Full path to the file</param> public void LoadFromBinaryFile(string filename) { Data.Clear(); FileStream fs = File.OpenRead(filename); BinaryReader r = new BinaryReader(fs); bool org = true; ushort currentAddress = 0; while (fs.Position < fs.Length) { ushort v = r.ReadUInt16(); if (org) { org = false; currentAddress = v; Data.PC = v; continue; } Data[currentAddress++] = v; } r.Close(); fs.Close(); Data.Commit(); Data.History.Clear(); }
/// <summary> /// Runs the currently loaded program. /// </summary> /// <returns>RuntimeException object representing the cause of the program termination.</returns> public RuntimeException Run() { while (true) { try { Processor.Step(); } catch (RuntimeException e) { if (e is NormalTerminationRuntimeException) { var testingIO = Processor.IODevice as TestingIODevice; if (testingIO != null) { if (!testingIO.IsOutputOk()) { return(new ExpectedOutputMismatchRuntimeException()); } } } return(e); } Data.Commit(); } }
/// <summary> /// Runs the currently loaded program. /// </summary> /// <returns>RuntimeException object representing the cause of the program termination.</returns> public RuntimeException Run() { while (true) { try { Processor.Step(); } catch (RuntimeException e) { return(e); } Data.Commit(); } }
public void LoadFromLines(string[] lines) { Data.Clear(); bool org = true; ushort currentAddress = 0; foreach (string s in lines) { ushort v = ushort.Parse(s, System.Globalization.NumberStyles.HexNumber); if (org) { org = false; currentAddress = v; Data.PC = v; continue; } Data[currentAddress++] = v; } Data.Commit(); Data.History.Clear(); }