Saturday, July 10, 2021

Reading a Game Boy Tetris cartridge

I saw a small rectangular PCB on the sidewalk not far from my house. It looked interesting. I left it for a couple of days in case someone lost it and returned for it. A web search showed it was the PCB from a Game Boy cartridge. Eventually, I took the PCB home, and made it a challenge to extract the data from it with only the tools I had at home and without harming the PCB (so, no soldering).

This PCB was from a ROM-only cartridge, 32K in size (I was able to identify it from the part number and photos online as likely to be Tetris), so it should have been particularly easy to read. The protocol is described here.

While the Game Boy cartridges run at 5V, the only microcontroller I had available with enough GPIOs  and ready to use was an stm32f103c "black pill" which runs at 3.3V. Fortunately, it has a number of 5V-tolerant GPIOs, so there was some hope that I could run the cartridge at 5V and read it with the microcontroller.

The Game Boy I didn't have a cartridge connector, but fortunately the PCB had plated through-holes on all but two of the lines, and they fit my breadboard jumper wires very nicely. I used test clips for the remaining two lines (VCC and A0). After some detours due to connection mistakes and a possibly faulty breadboard or GPIO, I ended up with this simple setup (what a mess on the breadboard!).

1. Connect D0-D7 on the cartridge to 5V-tolerant inputs, connect A0-A14 on the cartridge to outputs, ground GND, A15 and RD (CS and RS were not connected to anything on the cartridge), and connect VCC to a power supply (it turned out that all my worries about 3.3V/5V were unnecessary: supplying 3.3V, 4.5V or 5V all worked equally well). 

2. Write a 15-bit address to A0-A14. Wait a microsecond (this could be shaved down, but why bother?). Read the byte from D0-D7. Increment address. Repeat. Check the header and ROM checksums when done. Arduino code is here.  (I just copied and pasted the output of that into a text file which I then processed with a simple Python script.)

It works! I now have a working Tetris in an emulator, dumped from a random PCB that had been lying on the sidewalk through torrential rains!

I've played many versions of Tetris. This one plays very nicely.

Some technical notes:

  • I got advice from someone to set pulldown on the D0-D7 lines. Turns out that makes no difference.
  • Cartridges that are more than 32K would need some bank switching code.

No comments: