Skip to content

Qt: Add Net Gate Functionality & Fix Chip Gate for non-JP versions of Battle Network 6#3568

Open
DeCoded-Void wants to merge 4 commits intomgba-emu:masterfrom
DeCoded-Void:master
Open

Qt: Add Net Gate Functionality & Fix Chip Gate for non-JP versions of Battle Network 6#3568
DeCoded-Void wants to merge 4 commits intomgba-emu:masterfrom
DeCoded-Void:master

Conversation

@DeCoded-Void
Copy link
Copy Markdown

  • Added "Net Gate" functionality for parity with Add Net Gate functionality shonumi/gbe-plus#87 .
  • Fixed an issue where the non-japanese versions of Mega Man Battle Network 6 are not getting the BattleChip Gate working as a result of qtitle changes, the ROM header was used to identify the game instead.
  • Changed chip insertion behavior to be "hotswapped" rather than being kept inserted.
  • Changes are only done in the qt end of things, battlechip.c and io related code is untouched.

This allows developers to create apps to easily interface with mGBA via TCP to insert chips in the chip gate.
Potential applications include: creating a wireless reader that reads real battlechips, using NFC tags to substitute as battle chips, phone/web app to use for chip selection, livestream chat to control inserted chips, etc.

Tested on Windows 11 64-bit with the windows:w64 build.

Screenshot 2025-08-22 091513

- Edited via QT Creator
- Added an additional vertical separator for the "Net Gate" section in "show advanced"
- "Inserted" was renamed to "Keep Inserted" to reflect new behavior
- By default, address and port strings are 127.0.0.1 and 2000
- Tooltips were added in gate options in Gate Type and Enable Net Gate checkbox

There may be some enum conflicts as a result of using a later version of qt, some affected enums were modified to work with the current branch of mGBA.
- Utilizes GBA memory to identify game version by using bytes from the ROM header

- Something in "qtitle" seems to have broken from 10.5 --> 11.0, I left a statement there which may correct it if there is preference for that instead. Since there isn't a member in QString for ASCII, fromLatin1 was used instead.

- As a result of the "qtitle" issue, the current master branch does not autoselect the gate and has caused the US version of MMBN6 to not work with the chip gate as a result of the chip gate providing the incorrect chip gate identifier to that version.

- Added behavior that allows for the chip name spinner to update when the Chip ID is changed

- Insertion behavior was modified since Battle Chips with the Chip Gate is intended to be hotswapped rather than being kept inserted. 

- In order to prevent the issue where swapped chips are not read while "Inserted" is checked, there is a momentary un-insert of the chip before the new chip is inserted and held.

- For the Net Gate functionality, the accepted bytes are for parity with shonumi/gbe-plus#87, The 0x80 byte is there as the starting byte for that. It is also used in mGBA to decide to accept the buffer or not.
- Added "onChipIdChanged", used to update the Chip Name spinner when Chip ID is manually changed
- Added Net Gate state (no persistence; initialized from UI at runtime)
- Default IP and Port is used from the UI file so it wasn't asserted in the header, it may be a good idea to have it here instead
@DeCoded-Void DeCoded-Void changed the title Add Net Gate Functionality & Fix Chip Gate for non-JP versions of Battle Network 6 Qt: Add Net Gate Functionality & Fix Chip Gate for non-JP versions of Battle Network 6 Aug 22, 2025
@endrift
Copy link
Copy Markdown
Member

endrift commented Sep 1, 2025

Please back out the "qtitle" fix. It was a trivial one line fix when done properly, so instead of complicating the review process I just went ahead and did it myself. I can review this properly afterwards.

@Rotockter
Copy link
Copy Markdown

any chance of getting the build ? for the live of me cant seam to build it myself

@endrift
Copy link
Copy Markdown
Member

endrift commented Mar 14, 2026

I'm still waiting on them backing out the change I asked for 6 months ago before I can review the rest of it.

@Rotockter
Copy link
Copy Markdown

Any tips for idiots try building mgba ? I tried to build his forked version with the net gate changes, but docker dont work because you cant get wsl to update and building with MSYS2 worked but the resulted mgba.exe with all dll's in the folder just wont start.

@DeCoded-Void
Copy link
Copy Markdown
Author

I'm still waiting on them backing out the change I asked for 6 months ago before I can review the rest of it.

Somehow didn't get the notif for the incoming change conflict resolution from the fork until the pr got a new comment.

@Rotockter Used the w64 docker image with wsl2 backend, you may need to enable virtualization in the bios.

@endrift Adding this info in case it results in breaking changes or requires further research as a separate issue, it was work done after this pr:

Ended up getting a PIO (Programable In Out) implementation working on a physical GBA to have a rp2040 microcontroller to act as the chip gate. The GBA's clock and SO pin helped with framing as well as serve as interrupt triggers on the microcontroller's end. The weird values that seem to increment and decrement surprisingly helped with making sure I was reading the data correctly.

There would be phantom disconnects in BN6 requiring a reset in the emu. BN6 was the only game I have seen where it would respond with the "resync command" directly after confirmation (8FFF), where the game will ease its way into the indefinite communication loop. The state machine could break at this point but it'll fix itself once a resync is forced (in this case, passing the title screen and triggering a battle). This behavior doesn't seem to be present for my BN4 and BN5 copies.

The games seem to also have no problem with being probed with different Chip Gate IDs until the game sees the one it likes. For the microcontroller implementation, I'd test each flavor 5 times indefinitely until we get the 8FFF response where the MCU will remember the previous accepted flavor so it will attempt to use it as the first flavor the next time the GBA triggers the communication again. It's a workaround, but the results were consistent when it came to handling BN6 US and JP versions on real hardware, so the user doesn't have to do any sort of manual intervention and it seems instantaneous because this all happens before the title screen fully fades in.

@Rotockter
Copy link
Copy Markdown

I cant update wsl it always fails and internet dont give me any solution for that. so cant use docker. cant you upload one of ya test builds of the fork ?

kinda got interrested in this through a youtube short seeing first time the battle gate. currently i got mgba running in gamenative on android with your 2022 lua code that seam to only be for BN 4-5. Sending the 3 byte code from my pc worked on my ayn thor running Battle Network 4.5 through gamenative with the script.

Its only realy convoluted to set everytime with: "open mgba, run BN4.5, open battle gate, restart bn4.5, open script window, find and load script, go fullscreen"

i wonder if you can autostart battle gate in the background. sadly the script net gate wont work without opening battel gate window.

goal is to make one of my micro controllers (esp32 etc) read out battle chips and sent to my any thor. struggeling with getting a connector working for the battle chips pcb contacts. buying edge connector didnt helped. now tinkering with 3d printing and paper clips.

@DeCoded-Void
Copy link
Copy Markdown
Author

DeCoded-Void commented Mar 16, 2026

The lua script is not a proper implementation because of it being made with the per frame limitation in that script. Communication with the accessory can't be done in a per frame basis with scripting alone, so the window is necessary to keep the emulated connection alive. The lua script just edits the "end result" per frame rather than simulate the actual peripheral interaction itself.

The current PR here was intended keeping things as high level as possible (in this case, mgba qt/gui) for accessibility since the lower level implementation is not feature complete, but already handles most of the time-sensitive related communication (assuming additional work in the future is going to be done to expand it for multiplayer capabilities, additional scripting abilities, etc.)

That does consequently mean that mGBA would still require its chip gate gui to remain open if you'd want to interface with it using an external/middleman program with this.

A dirty build was made based off of the fork to test its viability near the time of the pr for devs and hobbists working on chip gate related ideas to test, but it's unstable (leading to manual patching or workaround fixes, handling breaking changes to scripting API, etc.) Haven't recompiled it since then.

For chip gate related projects in the way you describe, gbe+ is recommended for the time being.

Although the "netgate" isn't really a set standard, hobbyists and collectors that do their own ways to do chip insertions from existing projects were able to get them working in the dirty build and gbe+ within a few minutes including:

  • Wireless capabilities (via esp8266/32 or pico w)
  • NFC stickers + readers to act as chips
  • Live chat or secondary actor simulating chip insertions
  • Macropad related projects
  • Mobile Webapp
  • GBA multiboot homebrew program for the GBA to act as a chipgate itself --> communicate with PC via serial/uart --> network packet to the emu

You can use pogo pins or these instead of paperclips if you want to use a microcontroller to read chips since they lower the risk of damaging chip pins.

@Rotockter
Copy link
Copy Markdown

seams like mgba 0.10.5 in software render mode and your script are the only things that run in windows emulation on the android ayn thor. I would like to use gbe+ but that does run extreamly slow in windows emulation(1 frame per 20 sec).
development/nightly version mgba 0.11 sadly does not run in windows emulation at all on android.
sadly there is no android gba emulator with battlechip gate with netgate.

my paperclip solution as pins works so far, but the connection seam not to be fool proof and sometimes pins dont connect even then touching the contacts, like old gba cartridges into gameboy fails.
not sure how to use your suggested pins.
Also sounds like alot more people tried tinkering with this as i found so far. any links to other existing projects/information ?

@DeCoded-Void
Copy link
Copy Markdown
Author

Yes, for the most part, a lot of undocumented information of the battlechips is discussed and collaborated on in the MegaMan Battle Network Collectors community discord: https://discord.gg/Wa98sZza4g

There are members that have worked on or are currently working on battlechip related projects (chip reproduction, chip gate accessory research, disassembled chip gate board pics, code snippets, pcb schematics, etc.) so they can point you to someone or an existing message on there that may be able to answer some of the niche questions surrounding them.

Connectors were one of the hurdles for diy related projects, the ones used for the original accessory weren't the best quality leading to some collectors requiring to disassemble and bending connectors back on them. There is a worry about connectors scratching pins on the chips because of how scalped the original chips are.

@zarcha has a pogo pin implementation of the connector and is using an arduino nano:
image
Link-Analyzer-Firmware - There is a shim programmed for it that allows it to be used with GBE+. That part currently undocumented atm, but confirmed to be working. It currently has some compatibility to the recently released Battle Chip Stadium emulation. It's spring loaded so contacts with pins are consistent.

@BlaXun has worked on an NFC implementation to substitute for chip reading

The 6 position spring contact connector linked above is what I currently use because of board assembly costs as a limitation. Using this for the implementation described in the pr with a few prototypes that can be used on that and physical hardware:
image image
image

Interlinking some publicly available info/documentation around this that can be helpful for contributors here, since search engines are getting more unreliable lately:

  • GBE+ dev's Battle Chip Gate Blog: Shonumi's Blog
  • Physical disassembly of battle chips: Dip Chip Creation Guide
  • Battlechip 3D model & PCB related resources: Megaman Exe Chip Project
  • @goodtofufriday 's bridged pin spreadsheet - Google Sheets
  • @zarcha 's memory address findings for the eeproms on bn6 link navi chips: Google Doc
  • Chip Gate Homebrew: forums.therockmanexezone.com This is multiboot capable, an rp2040/rp2350 microcontroller is usable as the middleman that keeps communication alive on the gba's end and able to forward chip inserts declared by it though your choice of protocol (ex: netgate), effectively letting a physical gba act as a chipgate itself.
  • Open Net Battle: Github Repo - A community-made engine that have done some work on software based tools for planned support for the chips. A wip tool targeted for the project can be usable with the GBE+ implementation.

Copy link
Copy Markdown
Member

@endrift endrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concerns with this implementation are largely stylistic. Please adhere to existing style throughout and don't change nearby style either.

One major change I'd like is that the actual server logic should be pulled out into C code that's usable across implementations and operates directly on GBASIOBattlechipGate instances. The UI will need to synchronize with it, but it would let this be used with other frontends if we want to add that. mGBA already includes TCP server code, so you can see how to do it in gdb-stub.c. It will complicate the integration, but it's more forward-thinking in the process. I'm actually not sure it makes sense to allow both the view and a server to both be operating on the chip deck at the same time, so we might want to make it just disable the controls while it's operating.

There are also changes that were made here for reasons that aren't obvious to me, so please elaborate on why those were changed.

As for the Qt Designer changes I'm asking you to revert, I know you didn't do those manually; the Qt 6 version of Designer does them automatically. However, I'm maintaining the older Qt 5 style for now since it works with Qt 6 already and allows it to compile with older versions of Qt 5 as well.

#include "GBAApp.h"
#include "ShortcutController.h"
#include "Window.h"
#include <mgba/internal/gba/gba.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a blank line between the C++ header and the C header include blocks

#include <QSettings>
#include <QStringList>

#include <QTcpServer>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be merged and sorted into the include block above.

if (id < 0) {
return;
connect(m_ui.chipName, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this](int idx) {
if (idx < 0) return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the existing style guide--no single line blocks.

Comment on lines +58 to +63
if (idx < 0) return;
const auto keys = m_model.chipNames().keys();
if (idx >= 0 && idx < keys.size()) {
bool blocked = m_ui.chipId->blockSignals(true);
m_ui.chipId->setValue(keys[idx]);
m_ui.chipId->blockSignals(blocked);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified:

Suggested change
if (idx < 0) return;
const auto keys = m_model.chipNames().keys();
if (idx >= 0 && idx < keys.size()) {
bool blocked = m_ui.chipId->blockSignals(true);
m_ui.chipId->setValue(keys[idx]);
m_ui.chipId->blockSignals(blocked);
auto keys = m_model.chipNames().keys();
if (idx < 0 || idx >= keys.size()) {
return;
}
QSignalBlocker blocker(m_ui.chipId);
m_ui.chipId->setValue(keys[idx]);

Though if I may ask, why are we blocking signals here now?

Comment on lines +68 to +73
connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &BattleChipView::onChipIdChanged);
connect(m_ui.insert, &QAbstractButton::clicked, this, &BattleChipView::reinsert);
connect(m_ui.add, &QAbstractButton::clicked, this, &BattleChipView::addChip);
connect(m_ui.remove, &QAbstractButton::clicked, this, &BattleChipView::removeChip);
connect(m_ui.save, &QAbstractButton::clicked, this, &BattleChipView::saveDeck);
connect(m_ui.load, &QAbstractButton::clicked, this, &BattleChipView::loadDeck);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow existing convention. Do not do inline alignment, and especially don't change existing code just to match a convention you added.

Comment on lines +167 to +169
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;Beast Link Gate&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Usable with &lt;span style=&quot; font-style:italic;&quot;&gt;Rockman EXE 6&lt;/span&gt;, including support for &lt;span style=&quot; font-style:italic;&quot;&gt;Mega Man Battle Network 6&lt;/span&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto about tooltips.

Comment on lines +233 to +235
<property name="toolTip">
<string>&lt;p&gt;&lt;b&gt;Net Gate&lt;/b&gt; - Sends Battle Chip data to mGBA over TCP.&lt;/p&gt; &lt;p&gt;It can be used with an external service/app that opens a TCP socket to submit Chip IDs.&lt;/p&gt; &lt;p style=&quot;margin:0&quot;&gt;&lt;b&gt;Protocol (3 bytes)&lt;/b&gt;:&lt;/p&gt;&lt;span style=&quot;font-family:'Courier New';&quot;&gt;&lt;ol style=&quot;margin:0; padding-left:1.2em&quot;&gt; &lt;li&gt;&lt;tt&gt;0x80&lt;/tt&gt;&lt;/li&gt; &lt;li&gt;&lt;tt&gt;CHIP_ID_HI&lt;/tt&gt;&lt;/li&gt; &lt;li&gt;&lt;tt&gt;CHIP_ID_LO&lt;/tt&gt;&lt;/li&gt; &lt;/ol&gt;&lt;/span&gt;</string>
</property>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto about tooltips

<number>5</number>
</property>
<property name="placeholderText">
<string>1-65535</string>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string>1-65535</string>
<string>1 &ndash; 65535</string>

Comment on lines +273 to +275
<property name="placeholderText">
<string>e.g., 127.0.0.1</string>
</property>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure a placeholder is useful here when there's already a default.

Comment on lines -228 to +302
<set>QDialogButtonBox::Close|QDialogButtonBox::Reset</set>
<set>QDialogButtonBox::StandardButton::Close|QDialogButtonBox::StandardButton::Reset</set>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

@endrift
Copy link
Copy Markdown
Member

endrift commented Mar 16, 2026

It also seems to have merge conflicts, so please rebase it and fix those.

@DeCoded-Void
Copy link
Copy Markdown
Author

A lot of kludges on my end.

Some of the rationale behind some of it is handling potential user misconfiguration (ex: user blanking out defaults without changing them before attempting to start the qt server) and trying to handle certain quirks in the game like where if the chipId is immediately switched in the state machine, the game could ignore that insert.

Going to be refactoring according to the style guide and suggestions and to make sure my interpretation is correct.

I definitely do want it to work so users will still be able to use mgba's current chip gate gui, while also being able to use multiple clients at the same time (ex: being able to remotely send chips while the user also locally is able to do it themselves). A potential issue may pop up is with overfeeding data and handling how and what to prioritize on the network end of things.

@endrift
Copy link
Copy Markdown
Member

endrift commented Mar 17, 2026

If you want to allow multiple different sources of inputs it sounds like all the more reason to have a central object for coordinating the state that multiple things can plug into and synchronize with.

FYI, I might not merge anything for 0.11 as I'm winding down, depending on how much of a change this is, but I am interested in pulling it into 0.12 once it's cleaned up

@endrift endrift added this to the mGBA 0.12.0 milestone Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants