From 079341f102f1ded4211196c148df420a5a56344c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 24 Oct 2024 11:44:21 +0200 Subject: [PATCH] take this a bit further --- src/frontend/qt_sdl/EmuThread.cpp | 60 ++++++++++++++++++++++++++++--- src/frontend/qt_sdl/EmuThread.h | 10 +++++- src/frontend/qt_sdl/Window.cpp | 49 +++++-------------------- 3 files changed, 73 insertions(+), 46 deletions(-) diff --git a/src/frontend/qt_sdl/EmuThread.cpp b/src/frontend/qt_sdl/EmuThread.cpp index 9a7ea6cb..7c3e1a91 100644 --- a/src/frontend/qt_sdl/EmuThread.cpp +++ b/src/frontend/qt_sdl/EmuThread.cpp @@ -595,6 +595,36 @@ void EmuThread::handleMessages() emuInstance->nds->Start(); bootResult = 1; break; + + case msg_InsertCart: + bootResult = 0; + if (!emuInstance->loadROM(msg.param.value(), false)) + break; + + bootResult = 1; + break; + + case msg_EjectCart: + emuInstance->ejectCart(); + break; + + case msg_InsertGBACart: + bootResult = 0; + if (!emuInstance->loadGBAROM(msg.param.value())) + break; + + bootResult = 1; + break; + + case msg_InsertGBAAddon: + bootResult = 0; + emuInstance->loadGBAAddon(msg.param.value()); + bootResult = 1; + break; + + case msg_EjectGBACart: + emuInstance->ejectCart(); + break; } msgSemaphore.release(); @@ -681,11 +711,10 @@ bool EmuThread::emuIsActive() return emuActive; } -int EmuThread::bootROM(QStringList filename) +int EmuThread::bootROM(const QStringList& filename) { - sendMessage(msg_EmuPause); sendMessage({.type = msg_BootROM, .param = filename}); - waitMessage(2); + waitMessage(); if (!bootResult) return bootResult; @@ -696,9 +725,8 @@ int EmuThread::bootROM(QStringList filename) int EmuThread::bootFirmware() { - sendMessage(msg_EmuPause); sendMessage(msg_BootFirmware); - waitMessage(2); + waitMessage(); if (!bootResult) return bootResult; @@ -707,6 +735,28 @@ int EmuThread::bootFirmware() return bootResult; } +int EmuThread::insertCart(const QStringList& filename, bool gba) +{ + MessageType msgtype = gba ? msg_InsertGBACart : msg_InsertCart; + + sendMessage({.type = msgtype, .param = filename}); + waitMessage(); + return bootResult; +} + +void EmuThread::ejectCart(bool gba) +{ + sendMessage(gba ? msg_EjectGBACart : msg_EjectCart); + waitMessage(); +} + +int EmuThread::insertGBAAddon(int type) +{ + sendMessage({.type = msg_InsertGBAAddon, .param = type}); + waitMessage(); + return bootResult; +} + void EmuThread::updateRenderer() { if (videoRenderer != lastVideoRenderer) diff --git a/src/frontend/qt_sdl/EmuThread.h b/src/frontend/qt_sdl/EmuThread.h index 612f7920..a21cc511 100644 --- a/src/frontend/qt_sdl/EmuThread.h +++ b/src/frontend/qt_sdl/EmuThread.h @@ -71,6 +71,11 @@ public: msg_BootROM, msg_BootFirmware, + msg_InsertCart, + msg_EjectCart, + msg_InsertGBACart, + msg_InsertGBAAddon, + msg_EjectGBACart, }; struct Message @@ -100,8 +105,11 @@ public: void emuFrameStep(); void emuReset(); - int bootROM(QStringList filename); + int bootROM(const QStringList& filename); int bootFirmware(); + int insertCart(const QStringList& filename, bool gba); + void ejectCart(bool gba); + int insertGBAAddon(int type); bool emuIsRunning(); bool emuIsActive(); diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 6f2f86a9..c267eb85 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -1330,56 +1330,35 @@ void MainWindow::onBootFirmware() void MainWindow::onInsertCart() { - emuThread->emuPause(); - QStringList file = pickROM(false); if (file.isEmpty()) + return; + + if (!emuThread->insertCart(file, false)) { - emuThread->emuUnpause(); return; } - if (!emuInstance->loadROM(file, false)) - { - emuThread->emuUnpause(); - return; - } - - emuThread->emuUnpause(); - updateCartInserted(false); } void MainWindow::onEjectCart() { - emuThread->emuPause(); - - emuInstance->ejectCart(); - - emuThread->emuUnpause(); - + emuThread->ejectCart(false); updateCartInserted(false); } void MainWindow::onInsertGBACart() { - emuThread->emuPause(); - QStringList file = pickROM(true); if (file.isEmpty()) + return; + + if (!emuThread->insertCart(file, true)) { - emuThread->emuUnpause(); return; } - if (!emuInstance->loadGBAROM(file)) - { - emuThread->emuUnpause(); - return; - } - - emuThread->emuUnpause(); - updateCartInserted(true); } @@ -1388,23 +1367,13 @@ void MainWindow::onInsertGBAAddon() QAction* act = (QAction*)sender(); int type = act->data().toInt(); - emuThread->emuPause(); - - emuInstance->loadGBAAddon(type); - - emuThread->emuUnpause(); - + emuThread->insertGBAAddon(type); updateCartInserted(true); } void MainWindow::onEjectGBACart() { - emuThread->emuPause(); - - emuInstance->ejectGBACart(); - - emuThread->emuUnpause(); - + emuThread->ejectCart(true); updateCartInserted(true); }