diff --git a/source/frontends/sdl/main.cpp b/source/frontends/sdl/main.cpp index 3ee70ce6..bccf8e90 100644 --- a/source/frontends/sdl/main.cpp +++ b/source/frontends/sdl/main.cpp @@ -27,8 +27,6 @@ #include "NTSC.h" #include "SaveState.h" #include "Interface.h" -#include "Mockingboard.h" -#include "Speaker.h" // comment out to test / debug init / shutdown only #define EMULATOR_RUN @@ -50,27 +48,9 @@ namespace return current.refresh_rate; } - void execute(common2::Speed speed, const size_t next) - { - if (g_nAppMode == MODE_RUNNING) - { - const size_t cyclesToExecute = speed.getCyclesTillNext(next * 1000); - - const bool bVideoUpdate = true; - const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame(); - - const DWORD executedCycles = CpuExecute(cyclesToExecute, bVideoUpdate); - - g_dwCyclesThisFrame = (g_dwCyclesThisFrame + executedCycles) % dwClksPerFrame; - GetCardMgr().GetDisk2CardMgr().UpdateDriveState(executedCycles); - MB_PeriodicUpdate(executedCycles); - SpkrUpdate(executedCycles); - } - } - struct Data { - common2::Speed * speed; + sa2::SDLFrame * frame; SDL_mutex * mutex; common2::Timer * timer; }; @@ -81,7 +61,7 @@ namespace SDL_LockMutex(data->mutex); data->timer->tic(); - execute(*data->speed, interval); + data->frame->ExecuteOneFrame(interval); data->timer->toc(); SDL_UnlockMutex(data->mutex); @@ -180,8 +160,6 @@ void run_sdl(int argc, const char * argv []) const std::string globalTag = ". ."; std::string updateTextureTimerTag, refreshScreenTimerTag, cpuTimerTag, eventTimerTag; - common2::Speed speed(options.fixedSpeed); - if (options.multiThreaded) { refreshScreenTimerTag = "0 ."; @@ -201,7 +179,7 @@ void run_sdl(int argc, const char * argv []) Data data; data.mutex = mutex.get(); data.timer = &cpuTimer; - data.speed = &speed; + data.frame = frame.get(); const SDL_TimerID timer = SDL_AddTimer(options.timerInterval, emulator_callback, &data); @@ -274,7 +252,7 @@ void run_sdl(int argc, const char * argv []) eventTimer.toc(); cpuTimer.tic(); - execute(speed, oneFrame); + frame->ExecuteOneFrame(oneFrame); cpuTimer.toc(); updateTextureTimer.tic(); diff --git a/source/frontends/sdl/sdlframe.cpp b/source/frontends/sdl/sdlframe.cpp index 0bc24e47..0bffcfee 100644 --- a/source/frontends/sdl/sdlframe.cpp +++ b/source/frontends/sdl/sdlframe.cpp @@ -11,6 +11,9 @@ #include "Speaker.h" #include "SoundCore.h" #include "Interface.h" +#include "NTSC.h" +#include "CPU.h" +#include "Mockingboard.h" #include "linux/paddle.h" #include "linux/keyboard.h" @@ -403,4 +406,29 @@ namespace sa2 } } + void SDLFrame::Execute(const DWORD cyclesToExecute) + { + const bool bVideoUpdate = true; + const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame(); + + const DWORD executedCycles = CpuExecute(cyclesToExecute, bVideoUpdate); + + g_dwCyclesThisFrame = (g_dwCyclesThisFrame + executedCycles) % dwClksPerFrame; + GetCardMgr().GetDisk2CardMgr().UpdateDriveState(executedCycles); + MB_PeriodicUpdate(executedCycles); + SpkrUpdate(executedCycles); + } + + void SDLFrame::ExecuteOneFrame(const size_t msNextFrame) + { + // when running in adaptive speed + // the value msNextFrame is only a hint for when the next frame will arrive + if (g_nAppMode == MODE_RUNNING) + { + const size_t cyclesToExecute = mySpeed.getCyclesTillNext(msNextFrame * 1000); + Execute(cyclesToExecute); + } + // else do nothing, it is either paused, debugged or stepped + } + } diff --git a/source/frontends/sdl/sdlframe.h b/source/frontends/sdl/sdlframe.h index 5d600f63..a455af5a 100644 --- a/source/frontends/sdl/sdlframe.h +++ b/source/frontends/sdl/sdlframe.h @@ -24,6 +24,9 @@ namespace sa2 void ProcessEvents(bool &quit); + void Execute(const DWORD uCycles); + void ExecuteOneFrame(const size_t msNextFrame); + virtual void UpdateTexture() = 0; virtual void RenderPresent() = 0;