diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index a66396bb..4c0d3798 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -77,6 +77,8 @@ EmuInstance::EmuInstance(int inst) : deleting(false), baseROMDir = ""; baseROMName = ""; baseAssetName = ""; + nextCart = nullptr; + changeCart = false; gbaSave = nullptr; gbaCartType = -1; @@ -120,7 +122,7 @@ EmuInstance::EmuInstance(int inst) : deleting(false), mpAudioMode = globalCfg.GetInt("MP.AudioMode"); nds = nullptr; - //updateConsole(nullptr); + //updateConsole(); audioInit(); inputInit(); @@ -1217,23 +1219,22 @@ void EmuInstance::setDateTime() time.time().hour(), time.time().minute(), time.time().second()); } -bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs) noexcept +bool EmuInstance::updateConsole() noexcept { // update the console type consoleType = globalCfg.GetInt("Emu.ConsoleType"); // Let's get the cart we want to use; - // if we wnat to keep the cart, we'll eject it from the existing console first. + // if we want to keep the cart, we'll eject it from the existing console first. std::unique_ptr nextndscart; - if (std::holds_alternative(_ndsargs)) + if (!changeCart) { // If we want to keep the existing cart (if any)... nextndscart = nds ? nds->EjectCart() : nullptr; - _ndsargs = {}; } - else if (const auto ptr = std::get_if>(&_ndsargs)) + else { - nextndscart = std::move(*ptr); - _ndsargs = {}; + nextndscart = std::move(nextCart); + changeCart = false; } if (auto* cartsd = dynamic_cast(nextndscart.get())) @@ -1388,12 +1389,14 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs) noexcept } renderLock.unlock(); + loadCheats(); + return true; } void EmuInstance::reset() { - updateConsole(Keep {}); + updateConsole(); if (consoleType == 1) ejectGBACart(); @@ -1457,7 +1460,7 @@ void EmuInstance::reset() bool EmuInstance::bootToMenu() { // Keep whatever cart is in the console, if any. - if (!updateConsole(Keep {})) + if (!updateConsole()) // Try to update the console, but keep the existing cart. If that fails... return false; @@ -1912,7 +1915,10 @@ bool EmuInstance::loadROM(QStringList filepath, bool reset) if (reset) { - if (!updateConsole(std::move(cart))) + nextCart = std::move(cart); + changeCart = true; + + if (!updateConsole()) { QMessageBox::critical(mainWindow, "melonDS", "Failed to load the DS ROM."); return false; @@ -1931,13 +1937,20 @@ bool EmuInstance::loadROM(QStringList filepath, bool reset) } else { - assert(nds != nullptr); - nds->SetNDSCart(std::move(cart)); + if (emuIsActive()) + { + nds->SetNDSCart(std::move(cart)); + loadCheats(); + } + else + { + nextCart = std::move(cart); + changeCart = true; + } } cartType = 0; ndsSave = std::make_unique(savname); - loadCheats(); return true; // success } @@ -1946,9 +1959,16 @@ void EmuInstance::ejectCart() { ndsSave = nullptr; - unloadCheats(); - - nds->EjectCart(); + if (emuIsActive()) + { + nds->EjectCart(); + unloadCheats(); + } + else + { + nextCart = nullptr; + changeCart = true; + } cartType = -1; baseROMDir = ""; diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index fbee4bf4..35943492 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -120,7 +120,7 @@ public: // return: empty string = setup OK, non-empty = error message QString verifySetup(); - bool updateConsole(UpdateConsoleNDSArgs&& ndsargs) noexcept; + bool updateConsole() noexcept; void enableCheats(bool enable); melonDS::ARCodeFile* getCheatFile(); @@ -261,6 +261,8 @@ private: std::string baseROMDir; std::string baseROMName; std::string baseAssetName; + bool changeCart; + std::unique_ptr nextCart; int gbaCartType; std::string baseGBAROMDir; diff --git a/src/frontend/qt_sdl/EmuThread.cpp b/src/frontend/qt_sdl/EmuThread.cpp index 1592c481..a7feffce 100644 --- a/src/frontend/qt_sdl/EmuThread.cpp +++ b/src/frontend/qt_sdl/EmuThread.cpp @@ -109,7 +109,7 @@ void EmuThread::run() Config::Table& globalCfg = emuInstance->getGlobalConfig(); u32 mainScreenPos[3]; - //emuInstance->updateConsole(nullptr); + //emuInstance->updateConsole(); // No carts are inserted when melonDS first boots mainScreenPos[0] = 0; diff --git a/src/frontend/qt_sdl/EmuThread.h b/src/frontend/qt_sdl/EmuThread.h index f28c0604..9fa95f3e 100644 --- a/src/frontend/qt_sdl/EmuThread.h +++ b/src/frontend/qt_sdl/EmuThread.h @@ -33,9 +33,6 @@ #include "NDSCart.h" #include "GBACart.h" -using Keep = std::monostate; -using UpdateConsoleNDSArgs = std::variant>; -using UpdateConsoleGBAArgs = std::variant>; namespace melonDS { class NDS;