Try a better time slicing algorithm.
We keep a running timer since the last start, or reboot or pause and ensure we track it. At the same time, a different full speed mode is necessary. We run for up to 5 ms as long as the disk is spinning and restart all counters. This will go in some configuration. Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
30ac85b9c0
commit
9218eb671e
2 changed files with 28 additions and 3 deletions
|
@ -175,7 +175,15 @@ void QApple::closeEvent(QCloseEvent *)
|
|||
|
||||
void QApple::on_timer()
|
||||
{
|
||||
const qint64 elapsed = myElapsedTimer.restart();
|
||||
const qint64 target = myElapsedTimer.elapsed();
|
||||
const qint64 current = CpuGetEmulationTime_ms() - myCpuTimeReference;
|
||||
const qint64 elapsed = target - current;
|
||||
if (elapsed <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const qint64 full_speed_ms = 5;
|
||||
const double fUsecPerSec = 1.e6;
|
||||
const UINT nExecutionPeriodUsec = 1000 * elapsed;
|
||||
|
||||
|
@ -184,6 +192,7 @@ void QApple::on_timer()
|
|||
|
||||
const bool bVideoUpdate = false;
|
||||
|
||||
int count = 0;
|
||||
do
|
||||
{
|
||||
const DWORD uActualCyclesExecuted = CpuExecute(uCyclesToExecute, bVideoUpdate);
|
||||
|
@ -193,8 +202,14 @@ void QApple::on_timer()
|
|||
g_dwCyclesThisFrame -= dwClksPerFrame;
|
||||
myEmulator->updateVideo();
|
||||
}
|
||||
++count;
|
||||
}
|
||||
while (DiskIsSpinning() && (myElapsedTimer.elapsed() < target + full_speed_ms));
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
restartTimeCounters();
|
||||
}
|
||||
while (DiskIsSpinning());
|
||||
}
|
||||
|
||||
void QApple::stopTimer()
|
||||
|
@ -206,13 +221,19 @@ void QApple::stopTimer()
|
|||
}
|
||||
}
|
||||
|
||||
void QApple::restartTimeCounters()
|
||||
{
|
||||
myElapsedTimer.start();
|
||||
myCpuTimeReference = CpuGetEmulationTime_ms();
|
||||
}
|
||||
|
||||
void QApple::on_actionStart_triggered()
|
||||
{
|
||||
// always restart with the same timer gap that was last used
|
||||
myTimerID = startTimer(myMSGap, Qt::PreciseTimer);
|
||||
myElapsedTimer.start();
|
||||
actionPause->setEnabled(true);
|
||||
actionStart->setEnabled(false);
|
||||
restartTimeCounters();
|
||||
}
|
||||
|
||||
void QApple::on_actionPause_triggered()
|
||||
|
@ -244,6 +265,7 @@ void QApple::on_actionReboot_triggered()
|
|||
startEmulator(myEmulatorWindow);
|
||||
myEmulatorWindow->setWindowTitle(g_pAppTitle);
|
||||
myEmulator->updateVideo();
|
||||
restartTimeCounters();
|
||||
}
|
||||
|
||||
void QApple::on_actionBenchmark_triggered()
|
||||
|
@ -296,6 +318,7 @@ void QApple::on_actionOptions_triggered()
|
|||
|
||||
if (running)
|
||||
{
|
||||
// otherwise we would slow down later
|
||||
actionStart->trigger();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ private slots:
|
|||
private:
|
||||
|
||||
void stopTimer();
|
||||
void restartTimeCounters();
|
||||
|
||||
int myTimerID;
|
||||
Preferences myPreferences;
|
||||
|
@ -66,6 +67,7 @@ private:
|
|||
QMdiSubWindow * myEmulatorWindow;
|
||||
std::shared_ptr<QGamepad> myGamepad;
|
||||
Emulator * myEmulator;
|
||||
qint64 myCpuTimeReference;
|
||||
|
||||
int myMSGap;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue