Factor common code to change AppMode.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-03-14 11:31:00 +00:00
parent 5230a6a558
commit 32c200d65c
3 changed files with 27 additions and 18 deletions

View file

@ -229,21 +229,21 @@ namespace sa2
if (ImGui::Button("Step")) if (ImGui::Button("Step"))
{ {
g_nAppMode = MODE_STEPPING; frame->ChangeMode(MODE_STEPPING);
frame->Execute(myStepCycles); frame->Execute(myStepCycles);
} }
ImGui::SameLine(); ImGui::SameLine();
ImGui::PushItemWidth(150); ImGui::PushItemWidth(150);
ImGui::DragInt("cycles", &myStepCycles, 0.2f, 0, 32, "%d"); ImGui::DragInt("cycles", &myStepCycles, 0.2f, 0, 256, "%d");
ImGui::PopItemWidth(); ImGui::PopItemWidth();
if ((ImGui::SameLine(), ImGui::Button("Run"))) if ((ImGui::SameLine(), ImGui::Button("Run")))
{ {
g_nAppMode = MODE_RUNNING; frame->ChangeMode(MODE_RUNNING);
} }
if ((ImGui::SameLine(), ImGui::Button("Pause"))) if ((ImGui::SameLine(), ImGui::Button("Pause")))
{ {
g_nAppMode = MODE_PAUSED; frame->ChangeMode(MODE_PAUSED);
} }
ImGui::SameLine(); ImGui::Text("%016llu - %04X", g_nCumulativeCycles, regs.pc); ImGui::SameLine(); ImGui::Text("%016llu - %04X", g_nCumulativeCycles, regs.pc);

View file

@ -332,20 +332,8 @@ namespace sa2
} }
case SDLK_PAUSE: case SDLK_PAUSE:
{ {
switch (g_nAppMode) const AppMode_e newMode = (g_nAppMode == MODE_RUNNING) ? MODE_PAUSED : MODE_RUNNING;
{ ChangeMode(newMode);
case MODE_RUNNING:
g_nAppMode = MODE_PAUSED;
SoundCore_SetFade(FADE_OUT);
break;
case MODE_PAUSED:
case MODE_DEBUG:
g_nAppMode = MODE_RUNNING;
SoundCore_SetFade(FADE_IN);
mySpeed.reset();
break;
}
GetFrame().FrameRefreshStatus(DRAW_TITLE);
break; break;
} }
case SDLK_CAPSLOCK: case SDLK_CAPSLOCK:
@ -431,4 +419,23 @@ namespace sa2
// else do nothing, it is either paused, debugged or stepped // else do nothing, it is either paused, debugged or stepped
} }
void SDLFrame::ChangeMode(const AppMode_e mode)
{
if (mode != g_nAppMode)
{
g_nAppMode = mode;
switch (g_nAppMode)
{
case MODE_RUNNING:
SoundCore_SetFade(FADE_IN);
mySpeed.reset();
break;
default:
SoundCore_SetFade(FADE_OUT);
break;
}
FrameRefreshStatus(DRAW_TITLE);
}
}
} }

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "Common.h"
#include "frontends/common2/commonframe.h" #include "frontends/common2/commonframe.h"
#include "frontends/common2/speed.h" #include "frontends/common2/speed.h"
#include <SDL.h> #include <SDL.h>
@ -26,6 +27,7 @@ namespace sa2
void Execute(const DWORD uCycles); void Execute(const DWORD uCycles);
void ExecuteOneFrame(const size_t msNextFrame); void ExecuteOneFrame(const size_t msNextFrame);
void ChangeMode(const AppMode_e mode);
virtual void UpdateTexture() = 0; virtual void UpdateTexture() = 0;
virtual void RenderPresent() = 0; virtual void RenderPresent() = 0;