public void StartSystem() { state = GBSystemState.Running; var frameInput = new KeyState(); while (state != GBSystemState.Stopped) { if (frameInput.IsPauseToggled) { TogglePause(); } if (frameInput.IsFrameLimitToggled) { ToggleFrameSpeed(); } if (state == GBSystemState.Paused) { continue; } Profiler.GetInstance().Restart("Main CPU"); frameTimer.Start(); cpu.RunFor(video.TimeToNextVBlank()); if (isFocused) { frameInput = inputHandler.PollInput(); input.UpdateInput(frameInput); } cpu.RunFor(video.TimeToTopOfLCD()); while (frameTimer.ElapsedSeconds() < SpeedLimits[frameLimitIndex]) { } GBMonitor.CPUTime = Profiler.GetInstance().StopAndGetTimeAsFrameTimePercent("Main CPU"); } }