Cal Moody

Go back

Enabling M29W128GH GBA flashcarts to be reflashed on a Nintendo DS

Adding support to GBABF for flashing an arbitrary GBA flashcart, but really I just wanted to update my custom Apotris cartridge.

Published on Dec 29, 2024

Overview

Earlier this year, I added support to the Gameboy Advance cartridge flashing software GBABF for a specific type of chip that I had in a flashcart. In this post I will talk about my motivations for this short project as well as the challenges I encountered along the way. If you are trying to do something similar, this post might be of some help to you.

Context

In late 2022, insideGadgets produced a limited-run physical release of the fantastic block stacking GBA game Apotris. This game fills a niche in the Gameboy Advance space due to the lack of a solid Tetris entry for the GBA. Tetris Worlds is not considered to be a strong entry, not to mention lacking many modern features. Tetris DX for the Gameboy Color is generally considered a much superior game to Worlds, but if you are a big fan of the Gameboy Micro (as I am), then you are out of luck because the Gameboy Micro doesn't have the hardware to support the Gameboy Color catalog.

I found Apotris while checking to see if anyone had made a better GBA Tetris, with the full intention of making one myself if I didn't find one. Apotris had just been released back then, and I was immediately stoked with what I found – great controls, great music, and all compatible with the Gameboy Micro. Shortly thereafter in late 2022, when insideGadgets produced a limited-run physical release of the game, it was a no-brainer to purchase a cart.

Apotris flashcart chip Apotris flashcart internals showing the m29w128gh chip.

The v4 Release

Fast-forward to 2024 – the Apotris team had been hard at work making a new version 4 with all kinds of cool features, and I wanted to be sure I would be able to upgrade my physical cart to the new version. Unfortunately, this was going to require a relatively expensive piece of hardware that plugs into your computer and allows you to read/write to your Gameboy cartridges, which is useful for other things like backing up your saves. I didn't want to buy another one-off gadget if avoidable, so I started researching other options.

R4 and GBABF

Turns out, the Nintendo DS (which many folks have just lying around) has arbitrary code execution exploits, and a Gameboy cartridge slot! The folks in the Apotris discord recommended that I try upgrading the flashcart with a program called GBABF(GBA Bootleg Flasher) which you can run on an unmodified Nintendo DS if you have an R4 flashcart (less than $20 on eBay). I picked one up and loaded my flashcart in, and hit the flash button – and everything worked first try! Don't believe me? Of course not, nothing is ever that easy, and if it were, I wouldn't have much to write here.

Adding Support

GBABF didn't have support built in for the specific chip in my flash cart, which means I was unable to write the new v4 ROM to the cart's memory. Fortunately, GBABF is open source, which enabled me to analyze how it supported other chips. A quick peek inside my flashcart showed me that it was rocking a M29W128GH chip – the next step was to find the datasheets for this particular chip.

For the unfamiliar, datasheets are a treasure trove of knowledge from the manufacturer on any given piece of hardware. If you have a technical question on some part you are working with, odds are the datasheet will be of some use to you.

With the datasheet in hand, I was able to map the read/write instructions into GBABF's code, create a dev build, and loaded that onto the Nintendo DS. Unfortunately, I didn't have a spare cartridge to work with, so I knew that once I flashed it for the first time there was no going back. I was determined to get this working, so I pushed ahead.

There was a tricky sequence of pointer arithmetic and memory alignment happening in the core writeFlash() function that I was having difficulty understanding, and it being all the rage at the time, I decided to give ChatGPT a go at explaining where the bug was. Perhaps unsurprisingly, it led me on a wild goose chase of plausible explanations that ultimately I had to have explained to me by the GBABF maintainer.

This is a lesson in the dangers of plausibility – little lies can easily hide in a sea of truth spoken with confidence.

Summary

After some helpful back-and-forth reviewing, my code was merged and the ability to upgrade the official Apotris flashcart was now available for everyone else.

There are dozens of us. Dozens!