GBA Peripherals: Add BattleChip Gate dummy interface
Vicki Pfau vi@endrift.com
Mon, 11 Feb 2019 21:40:45 -0800
8 files changed,
200 insertions(+),
20 deletions(-)
M
src/gba/extra/battlechip.c
→
src/gba/extra/battlechip.c
@@ -24,6 +24,7 @@ BATTLECHIP_OK = 0xFFC6,
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;@@ -40,6 +41,12 @@
gate->event.context = gate; gate->event.callback = _battlechipTransferEvent; 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) {
A
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<CoreController> controller, QWidget* parent) + : QDialog(parent) + , m_controller(controller) +{ + m_ui.setupUi(this); + + connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&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); + } +}
A
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 <QDialog> + +#include <memory> + +#include <mgba/core/interface.h> + +#include "ui_BattleChipView.h" + +namespace QGBA { + +class CoreController; + +class BattleChipView : public QDialog { +Q_OBJECT + +public: + BattleChipView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr); + ~BattleChipView(); + +public slots: + void insertChip(bool); + +private: + Ui::BattleChipView m_ui; + + std::shared_ptr<CoreController> m_controller; +}; + +}
A
src/platform/qt/BattleChipView.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BattleChipView</class> + <widget class="QDialog" name="BattleChipView"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>217</width> + <height>100</height> + </rect> + </property> + <property name="windowTitle"> + <string>BattleChip Gate</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="1" column="1"> + <widget class="QCheckBox" name="inserted"> + <property name="text"> + <string>Inserted</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Chip ID</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QSpinBox" name="chipId"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>65535</number> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui>
M
src/platform/qt/CMakeLists.txt
→
src/platform/qt/CMakeLists.txt
@@ -102,7 +102,6 @@ ObjView.cpp
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 @@ TileView.ui
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")
M
src/platform/qt/CoreController.cpp
→
src/platform/qt/CoreController.cpp
@@ -672,8 +672,8 @@ vf->close(vf);
#endif } -void CoreController::attachPrinter() { #ifdef M_CORE_GB +void CoreController::attachPrinter() { if (platform() != PLATFORM_GB) { return; }@@ -703,11 +703,9 @@ QMetaObject::invokeMethod(qPrinter->parent, "imagePrinted", Q_ARG(const QImage&, image));
}; 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 @@ Interrupter interrupter(this);
GB* gb = static_cast<GB*>(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 + +#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);
M
src/platform/qt/CoreController.h
→
src/platform/qt/CoreController.h
@@ -25,6 +25,10 @@ #ifdef M_CORE_GB
#include <mgba/internal/gb/sio/printer.h> #endif +#ifdef M_CORE_GBA +#include <mgba/gba/interface.h> +#endif + struct mCore; namespace QGBA {@@ -129,9 +133,17 @@
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();@@ -221,6 +233,10 @@ struct QGBPrinter {
GBPrinter d; CoreController* parent; } m_printer; +#endif + +#ifdef M_CORE_GBA + GBASIOBattlechipGate m_battlechip; #endif };
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -21,6 +21,7 @@ #endif
#include "AboutScreen.h" #include "AudioProcessor.h" +#include "BattleChipView.h" #include "CheatsView.h" #include "ConfigController.h" #include "CoreController.h"@@ -1350,6 +1351,31 @@ });
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"));@@ -1494,18 +1520,6 @@ m_controller->endVideoLog();
}); 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"));