public void VBlank(bool draw_frame)
{
TheDisplay.PollKeyboard(TheCIA1.KeyMatrix, TheCIA1.RevMatrix, ref joykey);
if (TheDisplay.QuitRequested)
{
quit_thyself = true;
}
// Poll the joysticks.
TheCIA1.Joystick1 = poll_joystick(0);
TheCIA1.Joystick2 = poll_joystick(1);
if (GlobalPrefs.ThePrefs.JoystickSwap)
{
byte tmp = TheCIA1.Joystick1;
TheCIA1.Joystick1 = TheCIA1.Joystick2;
TheCIA1.Joystick2 = tmp;
}
// Joystick keyboard emulation.
if (TheDisplay.SwapJoysticks)
TheCIA1.Joystick1 &= joykey;
else
TheCIA1.Joystick2 &= joykey;
// Count TOD clocks.
TheCIA1.CountTOD();
TheCIA2.CountTOD();
// Output a frag.
// TheSID.VBlank();
if (have_a_break)
{
return;
}
// Update the window if needed.
frame++;
if (draw_frame)
{
// Perform the actual screen update exactly at the
// beginning of an interval for the smoothest video.
TheDisplay.Update();
frameTimer.Stop();
// Compute the speed index and show it in the speedometer.
double elapsed_time = (double)frameTimer.ElapsedMicroseconds;
double speed_index = 20000.0 / elapsed_time * 100.0;
//System.Diagnostics.Debug.WriteLine(speed_index);
// Limit speed to 100% if desired
/*
if ((speed_index > 100.0) && GlobalPrefs.ThePrefs.LimitSpeed)
{
int sleeptime = (int)((20000 - elapsed_time) / 1000.0);
Thread.Sleep(sleeptime);
speed_index = 100.0;
}
*/
emulationSpeed = emulationSpeed * 0.99f + ((float) speed_index) * 0.01f;
frameTimer.Reset();
frameTimer.Start();
}
}