Game Boys may be old tech, but they still provide challenges to modern hackers. [Dhole] has come up with a cartridge emulator which uses an STMicroelectronics STM32F4 discovery board to do all the work. Until now, most flash cartridges used programmable logic devices, either CPLDs or FPGAs to handle the high-speed logic requirements. [Alex] proved that a microcontroller could emulate a cartridge by using an Arduino to display the “Nintendo” Game Boy boot logo. The Arduino wasn’t fast enough to actually handle high-speed accesses required for game play.
[Dhole] kicked the speed up by moving to the ARM Cortex-M4 based 168 MHz STM32F4. The F4’s 70 GPIO pins can run via internal peripherals at up to 100MHz, which is plenty to handle the 1MHz clock speed of the Game Boy’s bus. Logic levels are an issue, as the STM32 uses 3.3V logic while the Game Boy is a 5V device. Thankfully the STM32’s inputs are 5V tolerant, so things worked just fine.
Simple Game Boy cartridges like Tetris were able to directly map a ROM device into the Game Boys memory space. More complex titles used Memory Block Controller (MBC) chips to map sections of ROM and perform other duties. There were several MBC chips used for various titles, but [Dhole] can emulate MBC1, which is compatible with the largest code base.
One of the coolest tricks [Dhole] implemented was displaying a custom boot logo. The Game Boy used the “Nintendo” logo as a method of copyright protection. If a cartridge didn’t have the logo, the Game Boy wouldn’t run. The logo is actually read twice – once to check the copyright info, and once to display it on the screen. By telling the emulator to change the data available at those addresses after the first read, any graphic can be displayed.
If you’re wondering what a cartridge emulator would be useful for (other than pirating games), you should check out [Jeff Frohwein’s] Gameboy Dev page! [Jeff] has been involved in Game Boy development since the early days. There are literally decades of demos and homebrew games out there for the Game Boy and various derivatives. .
Oh, we need a modern microcontroller clocked at 168 MHz to be able to cope with a 8080 clone clocked at 4,19 MHz which translates to rougly 1 MHz bus speed? Well, that is a great achievement.
“The first thing I noticed is that the CLK is at 1MHz…” He didn’t even bother to dig up a Z80 instruction set. Seriously, people – when you start analyzing something that is very well descripted, start by reading. It can save you A LOT OF TIME.
Believe it or not, a CPLD is really a better way to achieve this than an OP microcontroller.
I can explain why a guy would go this route in one sentance:
A person only knows how to effectively use that which they are familiar with.
…That said, i don’t know this guy’s background (I didn’t ACTUALLY read OP or watch the vid).
But I do the same “overkill” approach everyday.
I brew K cups… (dude, that’s like $1mil USD/lb!)
I drive a car to work… (dude, walking saves the environment!)
I use a computer… (Dude, that dude online uses a Z80 for spreadsheets… You’re a money waster!)
For some of us, myself included, I look at that old brick from my childhood in my closet and look at this little online gem and see that I can build one with parts in hand, and the knowledge that I’ve got. Sure a XYZ works better, but this is HaD… Not EE monthly!
…Did you get lost?
But like Taylor Swift sings “the haters gonna hate, hate, hate…)
Still, that board costs 15€. Most CPLD/FPGA dev kits are massively more expensive. For a one-off this may just be the right thing to do.
Digi-key sells FPGA/CPLD eval board for $25 US and. They are not “massively more” expensive. These boards have onboard programmer, so they are ready to go.
These days with $10-$20 for 10 PCB proto service from China, you won’t need high volume. Just need to make your own break out boards if you can’t find it cheap enough.
If someone have to start out and build this from chips may it be STM32F4xx or CPLD/FPGA, he/she pretty much have to deal with TQFP either way.
On eBay, you can get those boards for under $10.
You can indeed find cheap CPLD boards on eBay (FPGA boards are a little more expensive), but without storage (RAM or ROM) at that price, and this project needs memory to emulate a game cartridge. The STM32F4 is probably more cost effective for small volumes. For large volumes you want ASICs.
Totally agreed. Many micro dev-boards that are WAY overkill for this are super-simple to program, and cost like $5, including just about everything that’s needed. It’s a great tradeoff, and takes a lot less time to get working. For a 1-off, or even 100-off project, it’s orders of magnitude cheaper and simpler. I am working on a ESP32 cart (https://github.com/konsumer/dkart) that will eventually be able to do wifi & bluetooth. It’s mega-overkill, but you can get the ready-made boards for under $5, and they can be programmed by a less tech-person in arduino IDE. Even without wifi, it’s not really a problem if it’s way overpowered when it’s that cheap & simple. I would not be able to make that on a FPGA/CPLD for cheaper, and certainly not faster (dev-time) and certainly not with wifi & bluetooth.
it all depends on your definition of better
cpld/fpga might be cheaper if you want to bang out 10K units, maybe more elegant, and timings will look nicer. cpld is certainly NOT easier, faster to implement, or cheaper in one offs
A CPLD is fast enough to handle the bus protocol, but then you’d need an external memory chip for the cartridge image, as well as an external CPU for the SD card interface. I don’t see how this is a simpler or better solution than a single CPU that can do everything. And really, who cares that it’s running at 168 MHz ?
The microcontroller is slightly power-hungry. If you power it from the battery pack in Gameboy, then the batteries will deplete almost 20% faster.
Use sleep mode and let bus control signals wake up the CPU ?
Well, you may save power almost 50% of time by letting it sleep for the low state of CLK.
You say that like a CPLD or FPGA wouldn’t be power-hungry… (which really depends on which CPLD/FPGA gets used)
5V-tolerant CPLDs and FPGAs tend to be older, which means they also tend to be a little power-hungry as well.
Or run the ARM at a slower speed.
@dutado
There comes a stage in any hobby where you know enough to do stuff, but aren’t entirely clear on what resources are already available and how to utilize them. There comes a stage after that where you know what info is out there, but don’t yet know enough to know how little you know, and thus how much you need those resources.
Or maybe he’s just one of those people who likes reinventing wheels. vOv
You are “à côté de la plaque”.
He is emulating a the cartridge (not the gameboy itself), which is emulating a Flash/Rom memory. Those memories needs for the gameboy to respond under the millisecond.
Not easy man to acheive that with under 16MHz GPIO.
This is a really nice hack. Superbly documented! I love stuff like this :-)
Great hack :)
I wonder how essential the use of a 168Mhz ARM is for this. Could the cartridge emulation be done with a slower uC as well…
May be a slower ARM. Having a 32-bit chip with wider GPIO than 8-bit would help reducing # of I/O cycles for fetching the address bus. Large memory (especially RAM) is so much cheaper on the ARM chips too.
Why can’t this be done with an Arduino? Arduinos are pretty capable with a 16Mhz Arduino, the gameboy uses a simple 1Mhz Z80