diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index be9172e51..0914042d8 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -127,6 +127,7 @@ set(UI_FILES BattleChipView.ui CheatsView.ui DebuggerConsole.ui + DolphinConnector.ui FrameView.ui GIFView.ui IOViewer.ui @@ -155,6 +156,7 @@ set(GBA_SRC BattleChipModel.cpp BattleChipUpdater.cpp BattleChipView.cpp + DolphinConnector.cpp GBAOverride.cpp) set(GB_SRC diff --git a/src/platform/qt/CoreController.cpp b/src/platform/qt/CoreController.cpp index 6091c70c0..8db5609de 100644 --- a/src/platform/qt/CoreController.cpp +++ b/src/platform/qt/CoreController.cpp @@ -117,7 +117,9 @@ CoreController::CoreController(mCore* core, QObject* parent) } controller->clearMultiplayerController(); +#ifdef M_CORE_GBA controller->detachDolphin(); +#endif QMetaObject::invokeMethod(controller, "stopping"); }; @@ -362,14 +364,12 @@ mCacheSet* CoreController::graphicCaches() { return m_cacheSet.get(); } -bool CoreController::connectDolphin(uint32_t ipv4) { +#ifdef M_CORE_GBA +bool CoreController::attachDolphin(const Address& address) { if (platform() != mPLATFORM_GBA) { return false; } - Address ipaddr; - ipaddr.version = IPV4; - ipaddr.ipv4 = htonl(ipv4); - if (GBASIODolphinConnect(&m_dolphin, &ipaddr, 0, 0)) { + if (GBASIODolphinConnect(&m_dolphin, &address, 0, 0)) { GBA* gba = static_cast(m_threadContext.core->board); GBASIOSetDriver(&gba->sio, &m_dolphin.d, SIO_JOYBUS); return true; @@ -384,6 +384,7 @@ void CoreController::detachDolphin() { } GBASIODolphinDestroy(&m_dolphin); } +#endif void CoreController::setOverride(std::unique_ptr override) { Interrupter interrupter(this); diff --git a/src/platform/qt/CoreController.h b/src/platform/qt/CoreController.h index 3b92ed4e1..1442adc9a 100644 --- a/src/platform/qt/CoreController.h +++ b/src/platform/qt/CoreController.h @@ -108,8 +108,9 @@ public: void clearMultiplayerController(); MultiplayerController* multiplayerController() { return m_multiplayer; } - bool connectDolphin(uint32_t ipv4); - void detachDolphin(); +#ifdef M_CORE_GBA + bool isDolphinConnected() const { return !SOCKET_FAILED(m_dolphin.data); } +#endif mCacheSet* graphicCaches(); int stateSlot() const { return m_stateSlot; } @@ -180,6 +181,9 @@ public slots: void detachBattleChipGate(); void setBattleChipId(uint16_t id); void setBattleChipFlavor(int flavor); + + bool attachDolphin(const Address& address); + void detachDolphin(); #endif void setAVStream(mAVStream*); diff --git a/src/platform/qt/DolphinConnector.cpp b/src/platform/qt/DolphinConnector.cpp new file mode 100644 index 000000000..fb026ea24 --- /dev/null +++ b/src/platform/qt/DolphinConnector.cpp @@ -0,0 +1,65 @@ +/* Copyright (c) 2013-2021 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "DolphinConnector.h" + +#include "CoreController.h" +#include "Window.h" +#include "utils.h" + +using namespace QGBA; + +DolphinConnector::DolphinConnector(Window* window, QWidget* parent) + : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint) + , m_window(window) +{ + m_ui.setupUi(this); + + connect(window, &QObject::destroyed, this, &QWidget::close); + connect(m_ui.connect, &QAbstractButton::clicked, this, &DolphinConnector::attach); + connect(m_ui.disconnect, &QAbstractButton::clicked, this, &DolphinConnector::detach); + + updateAttached(); +} + +void DolphinConnector::attach() { + QHostAddress qaddress; + Address address; + if (m_ui.specLocal->isChecked()) { + qaddress.setAddress("127.0.0.1"); + } else if (m_ui.specIPAddr->isChecked()) { + if (!qaddress.setAddress(m_ui.ipAddr->text())) { + return; + } + + } + if (!m_window->controller()) { + m_window->bootBIOS(); + if (!m_window->controller() || m_window->controller()->platform() != mPLATFORM_GBA) { + return; + } + } + + convertAddress(&qaddress, &address); + CoreController::Interrupter interrupter(m_window->controller()); + m_window->controller()->attachDolphin(address); + + updateAttached(); +} + +void DolphinConnector::detach() { + if (m_window->controller()) { + m_window->controller()->detachDolphin(); + } + updateAttached(); +} + +void DolphinConnector::updateAttached() { + bool attached = m_window->controller() && m_window->controller()->isDolphinConnected(); + m_ui.connect->setDisabled(attached); + m_ui.disconnect->setEnabled(attached); + m_ui.specLocal->setDisabled(attached); + m_ui.specIPAddr->setDisabled(attached); +} diff --git a/src/platform/qt/DolphinConnector.h b/src/platform/qt/DolphinConnector.h new file mode 100644 index 000000000..9b4c00132 --- /dev/null +++ b/src/platform/qt/DolphinConnector.h @@ -0,0 +1,33 @@ +/* Copyright (c) 2013-2021 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#pragma once + +#include "ui_DolphinConnector.h" + +namespace QGBA { + +class Window; + +class DolphinConnector : public QDialog { +Q_OBJECT + +public: + DolphinConnector(Window* window, QWidget* parent = nullptr); + +public slots: + void attach(); + void detach(); + +private slots: + void updateAttached(); + +private: + Ui::DolphinConnector m_ui; + + Window* m_window; +}; + +} diff --git a/src/platform/qt/DolphinConnector.ui b/src/platform/qt/DolphinConnector.ui new file mode 100644 index 000000000..d44b6f9d5 --- /dev/null +++ b/src/platform/qt/DolphinConnector.ui @@ -0,0 +1,127 @@ + + + DolphinConnector + + + + 0 + 0 + 306 + 119 + + + + Connect to Dolphin + + + + QLayout::SetFixedSize + + + + + Local computer + + + true + + + buttonGroup + + + + + + + IP address + + + buttonGroup + + + + + + + false + + + + + + + + + Connect + + + + + + + + + + false + + + Disconnect + + + + + + + + + + Close + + + + + + + + + + + + + + close + clicked() + DolphinConnector + close() + + + 256 + 119 + + + 152 + 72 + + + + + specIPAddr + toggled(bool) + ipAddr + setEnabled(bool) + + + 152 + 43 + + + 152 + 49 + + + + + + + + diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index d353fc9ac..52a47041f 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -29,6 +29,7 @@ #include "DebuggerConsole.h" #include "DebuggerConsoleController.h" #include "Display.h" +#include "DolphinConnector.h" #include "CoreController.h" #include "FrameView.h" #include "GBAApp.h" @@ -327,6 +328,10 @@ void Window::selectROM() { } } +void Window::bootBIOS() { + setController(m_manager->loadBIOS(mPLATFORM_GBA, m_config->getOption("gba.bios")), QString()); +} + #ifdef USE_SQLITE3 void Window::selectROMInArchive() { QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), getFiltersArchive()); @@ -1097,9 +1102,7 @@ void Window::setupMenu(QMenuBar* menubar) { m_actions.addAction(tr("Load &patch..."), "loadPatch", this, &Window::selectPatch, "file"); #ifdef M_CORE_GBA - m_actions.addAction(tr("Boot BIOS"), "bootBIOS", [this]() { - setController(m_manager->loadBIOS(mPLATFORM_GBA, m_config->getOption("gba.bios")), QString()); - }, "file"); + m_actions.addAction(tr("Boot BIOS"), "bootBIOS", this, &Window::bootBIOS, "file"); #endif addGameAction(tr("Replace ROM..."), "replaceROM", this, &Window::replaceROM, "file"); @@ -1192,16 +1195,10 @@ void Window::setupMenu(QMenuBar* menubar) { GBAApp::app()->newWindow(); }, "file"); - Action* dolphin = m_actions.addAction(tr("Connect to Dolphin"), "connectDolphin", [this]() { - CoreController::Interrupter interrupter; - if (m_controller) { - interrupter.interrupt(m_controller); - } else { - setController(m_manager->loadBIOS(mPLATFORM_GBA, m_config->getOption("gba.bios")), QString()); - } - m_controller->connectDolphin(0x0100007F); - }, "file"); +#ifdef M_CORE_GBA + Action* dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openTView(this), "file"); m_platformActions.insert(mPLATFORM_GBA, dolphin); +#endif #ifndef Q_OS_MAC m_actions.addSeparator("file"); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 790af9ff6..90f9dbab5 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -72,6 +72,7 @@ signals: public slots: void setController(CoreController* controller, const QString& fname); void selectROM(); + void bootBIOS(); #ifdef USE_SQLITE3 void selectROMInArchive(); void addDirToLibrary();