take this a bit further

This commit is contained in:
Arisotura 2024-10-24 11:44:21 +02:00
parent 82f38f0b7a
commit 079341f102
3 changed files with 73 additions and 46 deletions

View File

@ -595,6 +595,36 @@ void EmuThread::handleMessages()
emuInstance->nds->Start();
bootResult = 1;
break;
case msg_InsertCart:
bootResult = 0;
if (!emuInstance->loadROM(msg.param.value<QStringList>(), false))
break;
bootResult = 1;
break;
case msg_EjectCart:
emuInstance->ejectCart();
break;
case msg_InsertGBACart:
bootResult = 0;
if (!emuInstance->loadGBAROM(msg.param.value<QStringList>()))
break;
bootResult = 1;
break;
case msg_InsertGBAAddon:
bootResult = 0;
emuInstance->loadGBAAddon(msg.param.value<int>());
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)

View File

@ -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();

View File

@ -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);
}