Feed on
Posts
Comments

Previously we were able to use 2 carts to communicate to each other to play Pong with a little mod and some code changes. This time as per some users request, we’ll be taking a look at adding a Gamecube receiver which will emulate a Gamecube controller. This could be useful if you wanted to play Gameboy games on the Game Boy Player or the Virtual Console / GC mode on the Wii.

(sneak peak) – Now available

After a quick check on what was out there already about the Gamecube controller interface, I came across the int03 site which gives us the controller pin out and that it’s a serial interface which is held high to 3.4V and is pulled low.

It looks like the Gamecube polls the controller which replies back with the button presses however the website mentioned that at first the Gamecube sends eight 0’s but they don’t appear to have the communication after that, how they reach the Gamecube requesting the controller state.

It looks like we’ll have to capture the initial communication with a logic analyser and also re-confirm their findings so I took apart my Gamecube controller and wired it up to take a look.


Firstly it seems like the Gamecube polls the controller at varying polling times, it may depend on whether you are in the system menu or could possibly depend on the game. We have a poll then 1ms later another poll which might be for debouncing and then 19ms after we have another 2 polls. On another instance we have the first two polls then a poll after 9ms and then the other 2 afterwards.

Lets have a closer look at the initial communication between them as there is quite a bit going on it seems.

It does appear that the GC requests 0x00, we have a stop bit (which also looks like a 1) and then the controller replies back with 0x09, 0x00, 0x20. What do these bytes do? I’m not sure, but it could be sending back something about the controller, what it might support, etc.

Next I assume the GC requests another byte because the next series of bytes looks to start off as the int03 website said the controller sends back (0x00, 0x80) but it seems to have 2 bytes more at the end.

Lastly the controller polling request does indeed match the int03 website and then the controller responses with key press data.

A quick look at the signal on the scope doesn’t look that great but let’s continue. We basically just have to read the 2 initial requests from the GC and send back the appropriate data and then it should keep polling for the controller update.

After some playing around, verifying on the logic analyser to get timings right, I was able to get reading and writing to work. It is achievable with the internal 8MHz oscillator but timing has to be just right so I went with a 16MHz crystal. At first I used an NPN transistor but the rise time of the data line was slow when the transistor was switched off so I went with an N mosfet which did the trick.

There are 2 little things I found while doing so, firstly if we don’t send back a controller update when the GC requests it, it goes back to sending the first 0x00 request which makes sense as the controller may have been unplugged. Secondly if the GC is reset, it also goes back to sending the first 0x00 request too, so we need a way to check for this.

When we receive a byte which reads 0x00, we know either the GC was first powered on, reset or perhaps we may be out of sync so we re-read the input until we see 0x00 again and if not we delay a little bit of time. This is more just to try and not land in the middle when GC is transmitting the first byte. As you can see, we use interrupts, so by the time we are out of the interrupt after reading 0x00, it may be too late to send the reply.

After we send our 3 byte reply, we wait to read the next byte (don’t care what it is) and send out 10 byte reply back. We wait a little bit so our pin change interrupt won’t be triggered by our-self and then turn the interrupt on.

When the interrupt is triggered, we check to see if the data in is low and go into reading the bytes quickly as there isn’t much time to read the first bit of data. After the 3 bytes are read, we send the controller data (actually we should probably do a quick check to see if the first byte is 0x00 before sending anything back), then delay a little bit like before.

When we aren’t interrupted, we just check if there are any packets waiting for us and if so, update the controller data respectively. The most time consuming part of this was getting the read and writing timing just right (you also have to add stop bits), both inside and outside the interrupt (as some things are skipped inside the interrupt).

Download Wireless_Gameboy_Controller_RX_Gamecube_v1.0

Leave a Reply