private void ParseOpcodes(CancellationToken token) { this.lastCycleTime = DateTime.Now; while (!token.IsCancellationRequested) { switch (input.ProcessInput()) { case KeypadKey.Pause: { this.isPaused = !isPaused; this.Paused?.Invoke(this.isPaused); break; } case KeypadKey.Stop: { return; } case KeypadKey.Restart: Cls(0); programCounter = ExecutionStartAddress; break; case KeypadKey.DelayPlus: currentCycleDelay += CycleDelayStep; DelayChanged?.Invoke(currentCycleDelay); break; case KeypadKey.DelayMinus: currentCycleDelay -= CycleDelayStep; currentCycleDelay = currentCycleDelay < DelayLowerBounds ? DelayLowerBounds : currentCycleDelay; DelayChanged?.Invoke(currentCycleDelay); break; } var currentTime = DateTime.Now; float dt = (currentTime - this.lastCycleTime).Ticks; if (!isPaused && dt > currentCycleDelay) { this.lastCycleTime = currentTime; } else { continue; } byte b1 = memory[programCounter]; byte b2 = memory[programCounter + 1]; programCounter += 2; var firstDigit = b1 >> 4; Instructions[firstDigit]((b1 << 8) | b2); if (soundTimer > 0) { soundTimer--; } if (delayTimer > 0) { delayTimer--; } } }
/// <summary> /// Raises the <see cref="DelayChanged" /> event. /// </summary> /// <seealso cref="EventArgs" /> protected virtual void OnDelayChanged() { DelayChanged?.Invoke(this, EventArgs.Empty); }