/// <summary> /// Uses the configured instruction timings to sync real time to the CPU. /// </summary> /// <param name="timings">The timings.</param> public void SyncToTimings(InstructionTimings timings) { // Check if we need to call the sync event. _cyclesSinceLastEventSync += timings.MachineCycles; if (_cyclesSinceLastEventSync > CyclesPerSyncEvent) { TimingSync?.Invoke(new InstructionTimings(_cyclesSinceLastEventSync)); _timer.Block((long)(_ticksPerCycle * _cyclesSinceLastEventSync)); _cyclesSinceLastEventSync = _cyclesSinceLastEventSync - CyclesPerSyncEvent; } }
/// <summary> /// Notifies the instruction timer that the CPU has accepted the halt and is halted. /// I.e. we'll need to stop waiting for instruction blocks to trigger timing sync events and generate our own fake ones. /// </summary> public void NotifyHalt() { _isHalted = true; Task.Run(async() => { var blockFor = (long)_ticksPerCycle * CyclesPerSyncEvent; while (_isHalted) { // Don't use the HPT here as it uses too much CPU. await Task.Delay(new TimeSpan(blockFor)).ConfigureAwait(false); TimingSync?.Invoke(new InstructionTimings(CyclesPerSyncEvent)); } }); }