Game Boy Pak Reader & The Cartridge Header.

The board basics.

In a prior post, I presented my hardware project for a Game Boy cartridge reader. Since then, I had some time to write some code for it. I thought that a good start would be writing the routines for basic operations, like outputting address and data into the pins of the microcontroller, reading or writing a byte at a specific address, and setting up the serial port.

When I designed the board, I tried to make the interaction between hardware and software the best possible. To exemplify, the data pins on the cartridge are port C of the microcontroller, in a which way that D0-PINC0, D1-PINC1, D2-PINC2… ans so on. Still, the Addres bus followed the same standard, but as this bus is 16  bits wide, two ports(A and B) were used. This way, almost none manipulation is needed before writing bytes in the buses.

Atmel Studio 6 was used to write this code. This is AVR-GCC, C language for the Atmel microcontrollers. Arduino could be used with some adaptations, but I wanted to polish my microcontroller skills anyway. I try to explain the basics, but some basic knowledge in the language is needed. In any case, the code has comments to help understanding.

PORTC is the register for writing tin the port C, while PINC is the register for reading it. The Address bus is always a output, so the registers PINA and PINB don’t need to be read. We can see that still there are some other pins in the cartridge connector below.13

These pins are /WR, /RD, /CS, /RESET and SND. Well, I still have not seen any cartridge using the sound input(SND), and it is not necessary for dumping ROMs and this kind of thing. But is connected anyway if I ever need it. The other pins are explained below:

  • /WR: From ‘write’, it is used to write bytes to the cartridge. A low pulse in this pin is used to store bytes in the RAM or select banks.
  • /RD: Stands for ‘read’, this Pin is used connected to the /OE of the ROM. It instructs the cartridge to write the byte in the selected memory location to the data bus.
  • /RESET: You know what this means, just leave it always HIGH while in operation.
  • /CS(or /MREQ): It is the enable pin. But from which chip?Read notes below.

How I lost hours of my time below:

Note[1]:The Reset pin must be always in high state while the cartridge is being used. I did the mistake of leaving it low(confused some registers) and it cost me a lot of time to understand what was going on. Miraculously, some cartridges still worked while this was low, leading me to believe the problem was something else.

Note[2]:The /CS pin is the pin that enable the RAM, It is connected to the RAM only. The most significant address line (A16 )is connected to the /CS of the ROM. This means that any access to a location higher than $8000 disables the ROM. To use the RAM, is still necessary after the drop in the /CS line, to write a comand in the data bus to enable RAM access.

Hardware

I still don’t have built the newest version of the board, unfortunately I am still using the first version. You can see I red wire fixing a mistake that is not present in the last board.  There are no meaningful differences between this board and the files for download.

IMG_20151203_204155

Serial Port

The code for the serial port was no secret, just used some functions available in the datasheet of the microcontroller and added a queue to store the incoming bytes. The serial code still is kind of mistery. It is not needed to modify it for now. People have used the serial in Arduinos without knowing what happens in the background. See serial.h if you want to check or edit it.

The cartridge Header

Cameboy cartridges are not really easy to read, there is a logic of bank switching to read all the ROM and RAM. To make it worse, there are 4 different bank controllers and several sizes of ROMs and RAMs.

However, the first bank is read similarly for every cartridge. This bank starts at $0000 and ends at $3FFF. While all the other banks are switched in the area from $4000 to $7FFF. In the first bank, it is possible to find information about the cartridge.  For example:

This info can be found in this great document.
So, just by reading some bytes from the cartridge, we can know its hardware without opening it and looking for datasheets in internet.
Some code implementing this:

And with a script in python with the following code:

Done this, the cartridges could be read. Some examples:

Pokemon Silver Japanese:

Beast Wars(I did not know the name, it is a Japanese game):

Tetris:

Tamagotchi:

Project Folder

Not the most commented code ever. You can download the project here.

Conclusions

That is it. The hardware works. I had a lot of trouble because of simple mistakes, but I can remember each of them now. I hope not falling in these traps anymore.

Next goal? Start the bank switching code for at least the MBC1.

Thanks for reading. See you next post. o/

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

 

 

 

 

Robson Couto

Estudante de engenharia elétrica. As vezes parece gostar mais dos consoles antigos que dos jogos. Tem interesse em dominar bits, bytes e afins.

One thought on “Game Boy Pak Reader & The Cartridge Header.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*