gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Using GBA as a gamecube controller

#82250 - KeithE - Thu May 04, 2006 7:53 pm

Has anyone here written a program that would allow the GBA to be used as a gamecube controller when plugged in to the gamecube with the gamecube/gba cable? What I'm looking for is something that would make the gamecube think that the GBA is just a normal gamecube controller that will work with any gamecube game.

I was thinking this would be a good project for me to work on, but I figured I might as well ask to see if anyone has already done it.

[EDIT] - I just found a previous post on this topic - http://forum.gbadev.org/viewtopic.php?t=7316 [/EDIT]

It would of course not be able to trigger the analog sticks or the X,Y, or Z buttons. However, if I get a flash cartridge with an accelerometer in it, then I could turn a GBA into a tilt controller for the gamecube by mapping the accelerometer output to the analog stick.

#82267 - tepples - Thu May 04, 2006 10:03 pm

KeithE wrote:
However, if I get a flash cartridge with an accelerometer in it

If you can get the rest of your controller working, your best option in this case is to make the a multiboot program and then pak-swap to WarioWare: Twisted! or another tilt-sensitive game.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#82319 - edwdig - Fri May 05, 2006 5:21 am

tepples wrote:
If you can get the rest of your controller working, your best option in this case is to make the a multiboot program and then pak-swap to WarioWare: Twisted! or another tilt-sensitive game.


WarioWare is sensitive to rotation, not tilt. You've only got 1 axis of sensitivity.

#82320 - tepples - Fri May 05, 2006 6:23 am

Which GBA game is sensitive to 2-axis analog tilt? (And no I don't mean a Wiimote duct-taped to a GBA either.)
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#82332 - keldon - Fri May 05, 2006 9:28 am

tepples wrote:
Which GBA game is sensitive to 2-axis analog tilt? (And no I don't mean a Wiimote duct-taped to a GBA either.)


What about kirby tilt and tumble (if it exists). I'm sure there's a kirby/pokemon game that does.

#82344 - tepples - Fri May 05, 2006 12:57 pm

keldon wrote:
What about kirby tilt and tumble (if it exists).

Kirby Tilt n Tumble is a Game Boy Color game. The GBA in GBA mode is not compatible with GBC carts. In addition, Kirby Tilt n Tumble uses a digital tilt sensor, which returns the same on-off types of states that a +Control Pad returns.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#82392 - KeithE - Fri May 05, 2006 10:59 pm

Yoshi topsy turvy has a dual-axis tilt sensor that I might be able to use.

#82720 - KeithE - Mon May 08, 2006 11:07 pm

I just got started on this project, and I'm already stuck.

I wrote a little program that puts the GBA into JOY BUS mode and waits until a command is received from the gamecube. Once it receives a command, it displays it on the screen. So, I plugged the GBA into the gamecube using a Nintendo link cable, turned on the GBA, turned on the gamecube, and waited.

The receive complete flag never went high. I was expecting it to go high when the gamecube sent a command to the GBA to tell it to identify itself.

Here is my code. Would anyone be willing to suggest what to try next? Thanks.

Code:
#include <mygba.h>
#define R_RCNT  *(volatile u16*) 0x4000134
#define R_JOYCNT *(volatile u16*) 0x4000140

int RX_COMPLETE();

int main(void)
{
   ham_Init();
   ham_InitText(0);
   // select JOY BUS mode by setting 2 MSBs of R_RCNT to 1
   R_RCNT = 0xC000;

   ham_DrawText(0,0,"%d",RX_COMPLETE());
   ham_DrawText(0,1,"WAITING");

   while (RX_COMPLETE() == 0);  // loop while RX is not complete
   
   // this point is reached when RX is complete
   ham_DrawText(0,0,"%d",RX_COMPLETE()); // show that RX is complete
   ham_DrawText(0,1,"%d",REG_JOYRE_H); // draw contents of JOY BUS receive register
   ham_DrawText(0,2,"%d",REG_JOYRE_H); // draw contents of JOY BUS receive register
   
   while(TRUE)
   {
   }

   return 0;
}

// this returns 1 when the receive complete flag goes HI
int RX_COMPLETE(){
    int out;
    if(0x2 & R_JOYCNT) out = 1;
    else out = 0;
    return out;
}

#83098 - thegamefreak0134 - Fri May 12, 2006 9:20 pm

For that last function, don't you need brackets around the if/else statement? If not (my C++ is a little (a lot) rusty) then I don't know what to say.
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#83100 - KeithE - Fri May 12, 2006 9:29 pm

Thanks, but it needs brackets only if the statement consists of more than 1 line.

See this reference: http://www.acm.uiuc.edu/webmonkeys/book/c_guide/1.6.html#if

#83176 - KeithE - Sat May 13, 2006 7:22 pm

Well, I don't think I'm going to be able to use the JOY BUS mode of the gba for this project.

Based on the GBATEK documentation, the only JOY BUS commands the GBA understands are 0x00, 0xFF, 0x14, and 0x15. It looks like it responds automatically to those commands. I don't see any way to determine what command was sent, other than those four. From the reading I've done, it looks like the gamecube sends 0x00 to read the device ID, and sends a 3 byte command 0x40, 0x03, 0x00 to read the controller button status. See http://www.gc-linux.org/docs/yagcd/index.html for the GCN documentation, specifically sections 9.1, 9.2, and 5.8. So the reason the code listing above never left the while loop is that the gamecube never sent 0x14 or 0x15.

Since it doesn't look like the GBA in JOY BUS mode understands anything besides 0x00, 0xFF, 0x14, and 0x15, I won't be able to determine that the gamecube has requested the controller button status, and I also won't be able to respond to the device ID with 0x0900 to indicate a GC controller instead of 0x0004 which indicates a GBA.

So, my feeling right now is that I'll have to write a program that puts the serial port into general purpose mode, and determine what commands were sent by interpreting SI according to the JOY BUS protocol. Then to send data, I'll have to drive SO according to the JOY BUS protocol.

Does anyone have any other suggestions? Have I interpreted the GBA and GCN specs correctly?

#110244 - Masked - Mon Nov 27, 2006 6:25 am

Sorry to bump an old topic, but I was wondering if there was any more progress made with this. I've been looking into the same thing and ran into the same problems. Does the GBA just respond to the 0x00 JOY BUS command automatically?

#110285 - KeithE - Mon Nov 27, 2006 3:26 pm

Yes, the GBA does respond automatically to the 0x00 JOY BUS command when it is in JOY BUS mode.

I confirmed this by putting the GBA into JOY BUS mode, and reading the R_RCNT register repeatedly several thousand times, triggered by SI going low. I saved the reads into an array, then saved the array to SRAM so I could look at the data afterwards. Looking at the data, I could see the gamecube sending 0x00, and the GBA responding with 0x0004.

I tried putting the GBA serial port in general purpose mode with all lines as inputs and doing the same thing, but I never saw any commands sent from the gamecube in that case. I guess I'll need to do some sluething with an oscilloscope to make any more progress.

Also, I noticed when looking at the captured JOY BUS mode data that the timing is very tight. It is going to be very difficult to make a program that can interpret a command and respond to it quick enough.

Let me know if you have any more questions about the work I've done. I'm happy that someone else is looking into it - maybe you'll make some more progress.