Move Execution to SDLFrame for ease of use in debugger.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
f7c6dfc1b9
commit
405ea13ba2
3 changed files with 35 additions and 26 deletions
|
@ -27,8 +27,6 @@
|
||||||
#include "NTSC.h"
|
#include "NTSC.h"
|
||||||
#include "SaveState.h"
|
#include "SaveState.h"
|
||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
#include "Mockingboard.h"
|
|
||||||
#include "Speaker.h"
|
|
||||||
|
|
||||||
// comment out to test / debug init / shutdown only
|
// comment out to test / debug init / shutdown only
|
||||||
#define EMULATOR_RUN
|
#define EMULATOR_RUN
|
||||||
|
@ -50,27 +48,9 @@ namespace
|
||||||
return current.refresh_rate;
|
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
|
struct Data
|
||||||
{
|
{
|
||||||
common2::Speed * speed;
|
sa2::SDLFrame * frame;
|
||||||
SDL_mutex * mutex;
|
SDL_mutex * mutex;
|
||||||
common2::Timer * timer;
|
common2::Timer * timer;
|
||||||
};
|
};
|
||||||
|
@ -81,7 +61,7 @@ namespace
|
||||||
SDL_LockMutex(data->mutex);
|
SDL_LockMutex(data->mutex);
|
||||||
|
|
||||||
data->timer->tic();
|
data->timer->tic();
|
||||||
execute(*data->speed, interval);
|
data->frame->ExecuteOneFrame(interval);
|
||||||
data->timer->toc();
|
data->timer->toc();
|
||||||
|
|
||||||
SDL_UnlockMutex(data->mutex);
|
SDL_UnlockMutex(data->mutex);
|
||||||
|
@ -180,8 +160,6 @@ void run_sdl(int argc, const char * argv [])
|
||||||
const std::string globalTag = ". .";
|
const std::string globalTag = ". .";
|
||||||
std::string updateTextureTimerTag, refreshScreenTimerTag, cpuTimerTag, eventTimerTag;
|
std::string updateTextureTimerTag, refreshScreenTimerTag, cpuTimerTag, eventTimerTag;
|
||||||
|
|
||||||
common2::Speed speed(options.fixedSpeed);
|
|
||||||
|
|
||||||
if (options.multiThreaded)
|
if (options.multiThreaded)
|
||||||
{
|
{
|
||||||
refreshScreenTimerTag = "0 .";
|
refreshScreenTimerTag = "0 .";
|
||||||
|
@ -201,7 +179,7 @@ void run_sdl(int argc, const char * argv [])
|
||||||
Data data;
|
Data data;
|
||||||
data.mutex = mutex.get();
|
data.mutex = mutex.get();
|
||||||
data.timer = &cpuTimer;
|
data.timer = &cpuTimer;
|
||||||
data.speed = &speed;
|
data.frame = frame.get();
|
||||||
|
|
||||||
const SDL_TimerID timer = SDL_AddTimer(options.timerInterval, emulator_callback, &data);
|
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();
|
eventTimer.toc();
|
||||||
|
|
||||||
cpuTimer.tic();
|
cpuTimer.tic();
|
||||||
execute(speed, oneFrame);
|
frame->ExecuteOneFrame(oneFrame);
|
||||||
cpuTimer.toc();
|
cpuTimer.toc();
|
||||||
|
|
||||||
updateTextureTimer.tic();
|
updateTextureTimer.tic();
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
#include "Speaker.h"
|
#include "Speaker.h"
|
||||||
#include "SoundCore.h"
|
#include "SoundCore.h"
|
||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
|
#include "NTSC.h"
|
||||||
|
#include "CPU.h"
|
||||||
|
#include "Mockingboard.h"
|
||||||
|
|
||||||
#include "linux/paddle.h"
|
#include "linux/paddle.h"
|
||||||
#include "linux/keyboard.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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@ namespace sa2
|
||||||
|
|
||||||
void ProcessEvents(bool &quit);
|
void ProcessEvents(bool &quit);
|
||||||
|
|
||||||
|
void Execute(const DWORD uCycles);
|
||||||
|
void ExecuteOneFrame(const size_t msNextFrame);
|
||||||
|
|
||||||
virtual void UpdateTexture() = 0;
|
virtual void UpdateTexture() = 0;
|
||||||
virtual void RenderPresent() = 0;
|
virtual void RenderPresent() = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue