Qt: Add Dolphin connector dialog

This commit is contained in:
Vicki Pfau 2021-02-14 22:10:33 -08:00
parent b1828dbc59
commit 2aac9da42b
8 changed files with 249 additions and 19 deletions

View File

@ -127,6 +127,7 @@ set(UI_FILES
BattleChipView.ui BattleChipView.ui
CheatsView.ui CheatsView.ui
DebuggerConsole.ui DebuggerConsole.ui
DolphinConnector.ui
FrameView.ui FrameView.ui
GIFView.ui GIFView.ui
IOViewer.ui IOViewer.ui
@ -155,6 +156,7 @@ set(GBA_SRC
BattleChipModel.cpp BattleChipModel.cpp
BattleChipUpdater.cpp BattleChipUpdater.cpp
BattleChipView.cpp BattleChipView.cpp
DolphinConnector.cpp
GBAOverride.cpp) GBAOverride.cpp)
set(GB_SRC set(GB_SRC

View File

@ -117,7 +117,9 @@ CoreController::CoreController(mCore* core, QObject* parent)
} }
controller->clearMultiplayerController(); controller->clearMultiplayerController();
#ifdef M_CORE_GBA
controller->detachDolphin(); controller->detachDolphin();
#endif
QMetaObject::invokeMethod(controller, "stopping"); QMetaObject::invokeMethod(controller, "stopping");
}; };
@ -362,14 +364,12 @@ mCacheSet* CoreController::graphicCaches() {
return m_cacheSet.get(); return m_cacheSet.get();
} }
bool CoreController::connectDolphin(uint32_t ipv4) { #ifdef M_CORE_GBA
bool CoreController::attachDolphin(const Address& address) {
if (platform() != mPLATFORM_GBA) { if (platform() != mPLATFORM_GBA) {
return false; return false;
} }
Address ipaddr; if (GBASIODolphinConnect(&m_dolphin, &address, 0, 0)) {
ipaddr.version = IPV4;
ipaddr.ipv4 = htonl(ipv4);
if (GBASIODolphinConnect(&m_dolphin, &ipaddr, 0, 0)) {
GBA* gba = static_cast<GBA*>(m_threadContext.core->board); GBA* gba = static_cast<GBA*>(m_threadContext.core->board);
GBASIOSetDriver(&gba->sio, &m_dolphin.d, SIO_JOYBUS); GBASIOSetDriver(&gba->sio, &m_dolphin.d, SIO_JOYBUS);
return true; return true;
@ -384,6 +384,7 @@ void CoreController::detachDolphin() {
} }
GBASIODolphinDestroy(&m_dolphin); GBASIODolphinDestroy(&m_dolphin);
} }
#endif
void CoreController::setOverride(std::unique_ptr<Override> override) { void CoreController::setOverride(std::unique_ptr<Override> override) {
Interrupter interrupter(this); Interrupter interrupter(this);

View File

@ -108,8 +108,9 @@ public:
void clearMultiplayerController(); void clearMultiplayerController();
MultiplayerController* multiplayerController() { return m_multiplayer; } MultiplayerController* multiplayerController() { return m_multiplayer; }
bool connectDolphin(uint32_t ipv4); #ifdef M_CORE_GBA
void detachDolphin(); bool isDolphinConnected() const { return !SOCKET_FAILED(m_dolphin.data); }
#endif
mCacheSet* graphicCaches(); mCacheSet* graphicCaches();
int stateSlot() const { return m_stateSlot; } int stateSlot() const { return m_stateSlot; }
@ -180,6 +181,9 @@ public slots:
void detachBattleChipGate(); void detachBattleChipGate();
void setBattleChipId(uint16_t id); void setBattleChipId(uint16_t id);
void setBattleChipFlavor(int flavor); void setBattleChipFlavor(int flavor);
bool attachDolphin(const Address& address);
void detachDolphin();
#endif #endif
void setAVStream(mAVStream*); void setAVStream(mAVStream*);

View File

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

View File

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

View File

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DolphinConnector</class>
<widget class="QDialog" name="DolphinConnector">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>306</width>
<height>119</height>
</rect>
</property>
<property name="windowTitle">
<string>Connect to Dolphin</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item row="0" column="0">
<widget class="QRadioButton" name="specLocal">
<property name="text">
<string>Local computer</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="specIPAddr">
<property name="text">
<string>IP address</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLineEdit" name="ipAddr">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="connect">
<property name="text">
<string>Connect</string>
</property>
<property name="icon">
<iconset theme="network-connect"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="disconnect">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Disconnect</string>
</property>
<property name="icon">
<iconset theme="network-disconnect"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="close">
<property name="text">
<string>Close</string>
</property>
<property name="icon">
<iconset theme="window-close"/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>close</sender>
<signal>clicked()</signal>
<receiver>DolphinConnector</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>256</x>
<y>119</y>
</hint>
<hint type="destinationlabel">
<x>152</x>
<y>72</y>
</hint>
</hints>
</connection>
<connection>
<sender>specIPAddr</sender>
<signal>toggled(bool)</signal>
<receiver>ipAddr</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>152</x>
<y>43</y>
</hint>
<hint type="destinationlabel">
<x>152</x>
<y>49</y>
</hint>
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

View File

@ -29,6 +29,7 @@
#include "DebuggerConsole.h" #include "DebuggerConsole.h"
#include "DebuggerConsoleController.h" #include "DebuggerConsoleController.h"
#include "Display.h" #include "Display.h"
#include "DolphinConnector.h"
#include "CoreController.h" #include "CoreController.h"
#include "FrameView.h" #include "FrameView.h"
#include "GBAApp.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 #ifdef USE_SQLITE3
void Window::selectROMInArchive() { void Window::selectROMInArchive() {
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), getFiltersArchive()); 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"); m_actions.addAction(tr("Load &patch..."), "loadPatch", this, &Window::selectPatch, "file");
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
m_actions.addAction(tr("Boot BIOS"), "bootBIOS", [this]() { m_actions.addAction(tr("Boot BIOS"), "bootBIOS", this, &Window::bootBIOS, "file");
setController(m_manager->loadBIOS(mPLATFORM_GBA, m_config->getOption("gba.bios")), QString());
}, "file");
#endif #endif
addGameAction(tr("Replace ROM..."), "replaceROM", this, &Window::replaceROM, "file"); addGameAction(tr("Replace ROM..."), "replaceROM", this, &Window::replaceROM, "file");
@ -1192,16 +1195,10 @@ void Window::setupMenu(QMenuBar* menubar) {
GBAApp::app()->newWindow(); GBAApp::app()->newWindow();
}, "file"); }, "file");
Action* dolphin = m_actions.addAction(tr("Connect to Dolphin"), "connectDolphin", [this]() { #ifdef M_CORE_GBA
CoreController::Interrupter interrupter; Action* dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openTView<DolphinConnector>(this), "file");
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");
m_platformActions.insert(mPLATFORM_GBA, dolphin); m_platformActions.insert(mPLATFORM_GBA, dolphin);
#endif
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
m_actions.addSeparator("file"); m_actions.addSeparator("file");

View File

@ -72,6 +72,7 @@ signals:
public slots: public slots:
void setController(CoreController* controller, const QString& fname); void setController(CoreController* controller, const QString& fname);
void selectROM(); void selectROM();
void bootBIOS();
#ifdef USE_SQLITE3 #ifdef USE_SQLITE3
void selectROMInArchive(); void selectROMInArchive();
void addDirToLibrary(); void addDirToLibrary();