public VirtualMachine(Assembly file) { Assembly = file; Register = new RegisterCollection(this); Stack = new Stack(); ScanInstructions(); PortMappedDeviceManager.ScanDevices(); InterruptTable.ScanHandlers(); ErrorTable.Add(0x1, "The Register is protected"); //ToDo: add ErrorAttribute to Instructions }
public void Run(byte[] raw, int startAddress = 0) { //ToDo: implement custom file format var r = new BinaryReader(new MemoryStream(raw)); Register.Subscribe(Registers.IPR, _ => { r.BaseStream.Position = _; }); Register.Subscribe(Registers.ERR, _ => { Console.WriteLine("An Error has occured: Error-code: 0x{0:x}: {1}", _, ErrorTable.GetExplanation(_)); }); if (startAddress != 0) { Register.SetValue(Registers.IPR, startAddress); } while (Register[Registers.IPR] < raw.Length) { ParseInstruction(r); } }