Skip to content

Commit

Permalink
take this a bit further
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Oct 24, 2024
1 parent 82f38f0 commit 079341f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 42 deletions.
60 changes: 55 additions & 5 deletions src/frontend/qt_sdl/EmuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/frontend/qt_sdl/EmuThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class EmuThread : public QThread

msg_BootROM,
msg_BootFirmware,
msg_InsertCart,
msg_EjectCart,
msg_InsertGBACart,
msg_InsertGBAAddon,
msg_EjectGBACart,
};

struct Message
Expand Down Expand Up @@ -100,8 +105,11 @@ class EmuThread : public QThread
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();
Expand Down
41 changes: 5 additions & 36 deletions src/frontend/qt_sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,56 +1330,35 @@ void MainWindow::onBootFirmware()

void MainWindow::onInsertCart()
{
emuThread->emuPause();

QStringList file = pickROM(false);
if (file.isEmpty())
{
emuThread->emuUnpause();
return;
}

if (!emuInstance->loadROM(file, false))
if (!emuThread->insertCart(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())
{
emuThread->emuUnpause();
return;
}

if (!emuInstance->loadGBAROM(file))
if (!emuThread->insertCart(file, true))
{
emuThread->emuUnpause();
return;
}

emuThread->emuUnpause();

updateCartInserted(true);
}

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

Expand Down

0 comments on commit 079341f

Please sign in to comment.