private void TurnOn(bool useState) { _dcpu16 = new TomatoDcpu16Adapter(new DCPU()); _dcpu16StateManager = new Dcpu16StateManager(_dcpu16); Firmware cpuFirmware = null; foreach (var device in vessel.Parts.SelectMany(i => i.Modules.OfType<IDevice>())) { var firmware = device as Firmware; if (firmware != null) { if (firmware.part == part) { _devices.Add(firmware); Connect(_dcpu16, firmware); cpuFirmware = firmware; } } else { _devices.Add(device); Connect(_dcpu16, device); } Debug.Log(String.Format("[Ketchup] Connected CPU to {0}", device.FriendlyName)); } if (useState && !String.IsNullOrEmpty(_dcpu16State)) { _dcpu16StateManager.Load(_dcpu16State); } else { if (cpuFirmware != null) { cpuFirmware.OnInterrupt(); } } _isPowerOn = true; }
private void TurnOff() { _isPowerOn = false; _isHalted = false; _pcAtHalt = 0; _dcpu16 = null; _dcpu16StateManager = null; foreach (var device in _devices) { device.OnDisconnect(); } _devices.Clear(); _clockRates.RemoveAll(i => true); _clockRateIndex = 0; }