From fb473e5eb43fad9e4fa57345f64923c51b26071b Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 16 Feb 2019 14:05:09 -0800 Subject: [PATCH] GBA Peripherals: Partial Beast Link Gate support --- include/mgba/gba/interface.h | 1 + res/chip-names-6.txt | 399 +++++++++++++++++++++++++++++ src/gba/core.c | 1 + src/gba/extra/battlechip.c | 41 ++- src/platform/qt/BattleChipView.cpp | 15 +- src/platform/qt/BattleChipView.ui | 3 - src/platform/qt/resources.qrc | 1 + 7 files changed, 455 insertions(+), 6 deletions(-) create mode 100644 res/chip-names-6.txt diff --git a/include/mgba/gba/interface.h b/include/mgba/gba/interface.h index 14eabc750..e620c108e 100644 --- a/include/mgba/gba/interface.h +++ b/include/mgba/gba/interface.h @@ -64,6 +64,7 @@ enum GBASIOBattleChipGateFlavor { GBA_FLAVOR_BATTLECHIP_GATE = 4, GBA_FLAVOR_PROGRESS_GATE = 5, GBA_FLAVOR_BEAST_LINK_GATE = 6, + GBA_FLAVOR_BEAST_LINK_GATE_US = 7, }; struct GBASIOBattlechipGate { diff --git a/res/chip-names-6.txt b/res/chip-names-6.txt new file mode 100644 index 000000000..2d8e0bacf --- /dev/null +++ b/res/chip-names-6.txt @@ -0,0 +1,399 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gba/core.c b/src/gba/core.c index 193d6970a..7d00f963c 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -535,6 +535,7 @@ static void _GBACoreSetPeripheral(struct mCore* core, int type, void* periph) { break; case mPERIPH_GBA_BATTLECHIP_GATE: GBASIOSetDriver(&gba->sio, periph, SIO_MULTI); + GBASIOSetDriver(&gba->sio, periph, SIO_NORMAL_32); break; default: return; diff --git a/src/gba/extra/battlechip.c b/src/gba/extra/battlechip.c index 259f958a5..75eb11bea 100644 --- a/src/gba/extra/battlechip.c +++ b/src/gba/extra/battlechip.c @@ -27,7 +27,8 @@ enum { enum { BATTLECHIP_OK = 0xFFC6, PROGRESS_GATE_OK = 0xFFC7, - BEAST_LINK_GATE_OK = 0xFFC8, + BEAST_LINK_GATE_OK = 0xFFC4, + BEAST_LINK_GATE_US_OK = 0xFF00, BATTLECHIP_CONTINUE = 0xFFFF, }; @@ -87,13 +88,29 @@ uint16_t GBASIOBattlechipGateWriteRegister(struct GBASIODriver* driver, uint32_t } void _battlechipTransfer(struct GBASIOBattlechipGate* gate) { - int32_t cycles = GBASIOCyclesPerTransfer[gate->d.p->multiplayerControl.baud][1]; + int32_t cycles; + if (gate->d.p->mode == SIO_NORMAL_32) { + cycles = GBA_ARM7TDMI_FREQUENCY / 0x40000; + } else { + cycles = GBASIOCyclesPerTransfer[gate->d.p->multiplayerControl.baud][1]; + } + mTimingDeschedule(&gate->d.p->p->timing, &gate->event); mTimingSchedule(&gate->d.p->p->timing, &gate->event, cycles); } void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cyclesLate) { struct GBASIOBattlechipGate* gate = user; + if (gate->d.p->mode == SIO_NORMAL_32) { + gate->d.p->p->memory.io[REG_SIODATA32_LO >> 1] = 0; + gate->d.p->p->memory.io[REG_SIODATA32_HI >> 1] = 0; + gate->d.p->normalControl.start = 0; + if (gate->d.p->normalControl.irq) { + GBARaiseIRQ(gate->d.p->p, IRQ_SIO); + } + return; + } + uint16_t cmd = gate->d.p->p->memory.io[REG_SIOMLT_SEND >> 1]; uint16_t reply = 0xFFFF; gate->d.p->p->memory.io[REG_SIOMULTI0 >> 1] = cmd; @@ -116,6 +133,9 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle case GBA_FLAVOR_BEAST_LINK_GATE: ok = BEAST_LINK_GATE_OK; break; + case GBA_FLAVOR_BEAST_LINK_GATE_US: + ok = BEAST_LINK_GATE_US_OK; + break; } switch (gate->state) { @@ -139,7 +159,18 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle case 0x537C: case 0x537D: case 0x537E: + case 0xB7D3: + case 0xB7D4: + case 0xB7D5: + case 0xB7D6: + case 0xB7D7: + case 0xB7D8: case 0xC4D8: + case 0xC4D9: + case 0xC4DA: + case 0xC4DB: + case 0xC4DC: + case 0xC4DD: case 0xD979: case 0xD97A: case 0xD97B: @@ -148,6 +179,12 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle case 0xD97E: reply = ok; break; + case 0x3545: + case 0x3546: + case 0x3547: + case 0x3548: + case 0x3549: + case 0x354A: case 0x424A: case 0x424B: case 0x424C: diff --git a/src/platform/qt/BattleChipView.cpp b/src/platform/qt/BattleChipView.cpp index d101c18f4..4f5206415 100644 --- a/src/platform/qt/BattleChipView.cpp +++ b/src/platform/qt/BattleChipView.cpp @@ -39,7 +39,16 @@ BattleChipView::BattleChipView(std::shared_ptr controller, QWidg }); connect(m_ui.gateBeastLink, &QAbstractButton::toggled, this, [this](bool on) { if (on) { - setFlavor(6); + char title[9]; + CoreController::Interrupter interrupter(m_controller); + mCore* core = m_controller->thread()->core; + title[8] = '\0'; + core->getGameCode(core, title); + if (title[7] == 'E' || title[7] == 'P') { + setFlavor(7); + } else { + setFlavor(6); + } } }); @@ -69,6 +78,10 @@ void BattleChipView::loadChipNames(int flavor) { QStringList chipNames; chipNames.append(tr("(None)")); + if (flavor == 7) { + flavor = 6; + } + QFile file(QString(":/res/chip-names-%1.txt").arg(flavor)); file.open(QIODevice::ReadOnly | QIODevice::Text); while (true) { diff --git a/src/platform/qt/BattleChipView.ui b/src/platform/qt/BattleChipView.ui index 63290a93c..ba95e455a 100644 --- a/src/platform/qt/BattleChipView.ui +++ b/src/platform/qt/BattleChipView.ui @@ -77,9 +77,6 @@ - - false - Beast &Link Gate diff --git a/src/platform/qt/resources.qrc b/src/platform/qt/resources.qrc index 475ab337c..ea08c5e39 100644 --- a/src/platform/qt/resources.qrc +++ b/src/platform/qt/resources.qrc @@ -6,5 +6,6 @@ ../../../res/no-cam.png ../../../res/chip-names-4.txt ../../../res/chip-names-5.txt + ../../../res/chip-names-6.txt