diff --git a/src/gba/extra/battlechip.c b/src/gba/extra/battlechip.c index 3af871432..2899347fd 100644 --- a/src/gba/extra/battlechip.c +++ b/src/gba/extra/battlechip.c @@ -24,6 +24,7 @@ enum { BATTLECHIP_CONTINUE = 0xFFFF, }; +static bool GBASIOBattlechipGateInit(struct GBASIODriver* driver); static bool GBASIOBattlechipGateLoad(struct GBASIODriver* driver); static uint16_t GBASIOBattlechipGateWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); @@ -31,7 +32,7 @@ static void _battlechipTransfer(struct GBASIOBattlechipGate* gate); static void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cyclesLate); void GBASIOBattlechipGateCreate(struct GBASIOBattlechipGate* gate) { - gate->d.init = NULL; + gate->d.init = GBASIOBattlechipGateInit; gate->d.deinit = NULL; gate->d.load = GBASIOBattlechipGateLoad; gate->d.unload = NULL; @@ -42,6 +43,12 @@ void GBASIOBattlechipGateCreate(struct GBASIOBattlechipGate* gate) { gate->event.priority = 0x80; } +bool GBASIOBattlechipGateInit(struct GBASIODriver* driver) { + struct GBASIOBattlechipGate* gate = (struct GBASIOBattlechipGate*) driver; + gate->chipId = 0; + return true; +} + bool GBASIOBattlechipGateLoad(struct GBASIODriver* driver) { struct GBASIOBattlechipGate* gate = (struct GBASIOBattlechipGate*) driver; gate->index = BATTLECHIP_INDEX_END; diff --git a/src/platform/qt/BattleChipView.cpp b/src/platform/qt/BattleChipView.cpp new file mode 100644 index 000000000..af9a0a9eb --- /dev/null +++ b/src/platform/qt/BattleChipView.cpp @@ -0,0 +1,36 @@ +/* Copyright (c) 2013-2019 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 "BattleChipView.h" + +#include "CoreController.h" + +using namespace QGBA; + +BattleChipView::BattleChipView(std::shared_ptr controller, QWidget* parent) + : QDialog(parent) + , m_controller(controller) +{ + m_ui.setupUi(this); + + connect(m_ui.chipId, static_cast(&QSpinBox::valueChanged), m_ui.inserted, [this]() { + m_ui.inserted->setChecked(Qt::Checked); + insertChip(true); + }); + connect(m_ui.inserted, &QAbstractButton::toggled, this, &BattleChipView::insertChip); + connect(controller.get(), &CoreController::stopping, this, &QWidget::close); +} + +BattleChipView::~BattleChipView() { + m_controller->detachBattleChipGate(); +} + +void BattleChipView::insertChip(bool inserted) { + if (inserted) { + m_controller->setBattleChipId(m_ui.chipId->value()); + } else { + m_controller->setBattleChipId(0); + } +} \ No newline at end of file diff --git a/src/platform/qt/BattleChipView.h b/src/platform/qt/BattleChipView.h new file mode 100644 index 000000000..564f1f8b0 --- /dev/null +++ b/src/platform/qt/BattleChipView.h @@ -0,0 +1,36 @@ +/* Copyright (c) 2013-2019 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 + +#include + +#include + +#include "ui_BattleChipView.h" + +namespace QGBA { + +class CoreController; + +class BattleChipView : public QDialog { +Q_OBJECT + +public: + BattleChipView(std::shared_ptr controller, QWidget* parent = nullptr); + ~BattleChipView(); + +public slots: + void insertChip(bool); + +private: + Ui::BattleChipView m_ui; + + std::shared_ptr m_controller; +}; + +} \ No newline at end of file diff --git a/src/platform/qt/BattleChipView.ui b/src/platform/qt/BattleChipView.ui new file mode 100644 index 000000000..5143c9d41 --- /dev/null +++ b/src/platform/qt/BattleChipView.ui @@ -0,0 +1,45 @@ + + + BattleChipView + + + + 0 + 0 + 217 + 100 + + + + BattleChip Gate + + + + + + Inserted + + + + + + + Chip ID + + + + + + + 1 + + + 65535 + + + + + + + + diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index b9c7d0ed8..8cf30dbc8 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -102,7 +102,6 @@ set(SOURCE_FILES OverrideView.cpp PaletteView.cpp PlacementControl.cpp - PrinterView.cpp RegisterView.cpp ROMInfo.cpp RotatedHeaderView.cpp @@ -124,6 +123,7 @@ set(UI_FILES AboutScreen.ui ArchiveInspector.ui AssetTile.ui + BattleChipView.ui CheatsView.ui DebuggerConsole.ui GIFView.ui @@ -147,10 +147,12 @@ set(UI_FILES VideoView.ui) set(GBA_SRC + BattleChipView.cpp GBAOverride.cpp) set(GB_SRC - GBOverride.cpp) + GBOverride.cpp + PrinterView.cpp) set(QT_LIBRARIES) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5") diff --git a/src/platform/qt/CoreController.cpp b/src/platform/qt/CoreController.cpp index e4f12087b..c5e8850ec 100644 --- a/src/platform/qt/CoreController.cpp +++ b/src/platform/qt/CoreController.cpp @@ -672,8 +672,8 @@ void CoreController::exportSharkport(const QString& path) { #endif } -void CoreController::attachPrinter() { #ifdef M_CORE_GB +void CoreController::attachPrinter() { if (platform() != PLATFORM_GB) { return; } @@ -703,11 +703,9 @@ void CoreController::attachPrinter() { }; Interrupter interrupter(this); GBSIOSetDriver(&gb->sio, &m_printer.d.d); -#endif } void CoreController::detachPrinter() { -#ifdef M_CORE_GB if (platform() != PLATFORM_GB) { return; } @@ -715,18 +713,44 @@ void CoreController::detachPrinter() { GB* gb = static_cast(m_threadContext.core->board); GBPrinterDonePrinting(&m_printer.d); GBSIOSetDriver(&gb->sio, nullptr); -#endif } void CoreController::endPrint() { -#ifdef M_CORE_GB if (platform() != PLATFORM_GB) { return; } Interrupter interrupter(this); GBPrinterDonePrinting(&m_printer.d); -#endif } +#endif + +#ifdef M_CORE_GBA +void CoreController::attachBattleChipGate() { + if (platform() != PLATFORM_GBA) { + return; + } + Interrupter interrupter(this); + clearMultiplayerController(); + GBASIOBattlechipGateCreate(&m_battlechip); + m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_BATTLECHIP_GATE, &m_battlechip); +} + +void CoreController::detachBattleChipGate() { + if (platform() != PLATFORM_GBA) { + return; + } + Interrupter interrupter(this); + m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_BATTLECHIP_GATE, nullptr); +} + +void CoreController::setBattleChipId(uint16_t id) { + if (platform() != PLATFORM_GBA) { + return; + } + Interrupter interrupter(this); + m_battlechip.chipId = id; +} +#endif void CoreController::setAVStream(mAVStream* stream) { Interrupter interrupter(this); diff --git a/src/platform/qt/CoreController.h b/src/platform/qt/CoreController.h index 9d9537c6c..b7a740626 100644 --- a/src/platform/qt/CoreController.h +++ b/src/platform/qt/CoreController.h @@ -25,6 +25,10 @@ #include #endif +#ifdef M_CORE_GBA +#include +#endif + struct mCore; namespace QGBA { @@ -129,9 +133,17 @@ public slots: void importSharkport(const QString& path); void exportSharkport(const QString& path); +#ifdef M_CORE_GB void attachPrinter(); void detachPrinter(); void endPrint(); +#endif + +#ifdef M_CORE_GBA + void attachBattleChipGate(); + void detachBattleChipGate(); + void setBattleChipId(uint16_t id); +#endif void setAVStream(mAVStream*); void clearAVStream(); @@ -222,6 +234,10 @@ private: CoreController* parent; } m_printer; #endif + +#ifdef M_CORE_GBA + GBASIOBattlechipGate m_battlechip; +#endif }; } diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index f5df80bd6..a49f3075f 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -21,6 +21,7 @@ #include "AboutScreen.h" #include "AudioProcessor.h" +#include "BattleChipView.h" #include "CheatsView.h" #include "ConfigController.h" #include "CoreController.h" @@ -1350,6 +1351,31 @@ void Window::setupMenu(QMenuBar* menubar) { addControlledAction(solarMenu, setSolar, QString("luminanceLevel.%1").arg(QString::number(i))); } +#ifdef M_CORE_GB + QAction* gbPrint = new QAction(tr("Game Boy Printer..."), emulationMenu); + connect(gbPrint, &QAction::triggered, [this]() { + PrinterView* view = new PrinterView(m_controller); + openView(view); + m_controller->attachPrinter(); + + }); + addControlledAction(emulationMenu, gbPrint, "gbPrint"); + m_gameActions.append(gbPrint); +#endif + +#ifdef M_CORE_GBA + QAction* bcGate = new QAction(tr("BattleChip Gate..."), emulationMenu); + connect(bcGate, &QAction::triggered, [this]() { + BattleChipView* view = new BattleChipView(m_controller); + openView(view); + m_controller->attachBattleChipGate(); + + }); + addControlledAction(emulationMenu, bcGate, "bcGate"); + m_gbaActions.append(bcGate); + m_gameActions.append(bcGate); +#endif + QMenu* avMenu = menubar->addMenu(tr("Audio/&Video")); m_shortcutController->addMenu(avMenu); QMenu* frameMenu = avMenu->addMenu(tr("Frame size")); @@ -1495,18 +1521,6 @@ void Window::setupMenu(QMenuBar* menubar) { addControlledAction(avMenu, stopVL, "stopVL"); m_gameActions.append(stopVL); -#ifdef M_CORE_GB - QAction* gbPrint = new QAction(tr("Game Boy Printer..."), avMenu); - connect(gbPrint, &QAction::triggered, [this]() { - PrinterView* view = new PrinterView(m_controller); - openView(view); - m_controller->attachPrinter(); - - }); - addControlledAction(avMenu, gbPrint, "gbPrint"); - m_gameActions.append(gbPrint); -#endif - avMenu->addSeparator(); m_videoLayers = avMenu->addMenu(tr("Video layers")); m_shortcutController->addMenu(m_videoLayers, avMenu);