From 1107dff9fa64f9ecf830709e3910b24e3640386c Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 26 Jul 2023 19:29:34 +0300 Subject: [PATCH] Implement pause/resume --- include/emulator.hpp | 6 +++++- src/emulator.cpp | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/emulator.hpp b/include/emulator.hpp index d738aef3..b6662331 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -59,7 +59,8 @@ class Emulator { static constexpr u32 width = 400; static constexpr u32 height = 240 * 2; // * 2 because 2 screens ROMType romType = ROMType::None; - bool running = true; + bool running = false; // Is the emulator running a game? + bool programRunning = false; // Is the emulator program itself running? #ifdef PANDA3DS_ENABLE_HTTP_SERVER HttpServer httpServer; @@ -89,6 +90,9 @@ class Emulator { void run(); void runFrame(); + void resume(); // Resume the emulator + void pause(); // Pause the emulator + bool loadROM(const std::filesystem::path& path); bool loadNCSD(const std::filesystem::path& path, ROMType type); bool loadELF(const std::filesystem::path& path); diff --git a/src/emulator.cpp b/src/emulator.cpp index bcca5ffa..e04f073d 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -75,6 +75,8 @@ Emulator::Emulator() } } + running = false; + programRunning = false; reset(ReloadOption::NoReload); } @@ -114,7 +116,9 @@ void Emulator::step() {} void Emulator::render() {} void Emulator::run() { - while (running) { + programRunning = true; + + while (programRunning) { runFrame(); HIDService& hid = kernel.getServiceManager().getHID(); @@ -125,7 +129,7 @@ void Emulator::run() { switch (event.type) { case SDL_QUIT: printf("Bye :(\n"); - running = false; + programRunning = false; return; case SDL_KEYDOWN: @@ -344,8 +348,12 @@ void Emulator::run() { } } +// Only resume if a ROM is properly loaded +void Emulator::resume() { running = (romType != ROMType::None); } +void Emulator::pause() { running = false; } + void Emulator::runFrame() { - if (romType != ROMType::None) { + if (running) { #ifdef PANDA3DS_ENABLE_HTTP_SERVER httpServer.processActions(); #endif @@ -408,6 +416,7 @@ bool Emulator::loadROM(const std::filesystem::path& path) { romType = ROMType::None; } + resume(); // Start the emulator return success; }