# Writing driver for Nintendo Gamecube controller via USB



## bjurusik (Mar 7, 2003)

I just ordered a USB attachment so I can use my Gamecube controller with my Mac, but after searching the web I don't see any drivers for it, and I don't think it's just 'plug and play.'  So I was wondering where I can find some info on writing this kind of driver.  I searched Yahoo and found Apple's developer docs on the I/O Kit.  Is this where I start?  I scanned it quickly and saw some mention of kernel programming and C++.  I know C++, but not sure what kernel programming is.  If someone could point me in the right direction, I'd greatly appreciate it.


----------



## substrate (Mar 7, 2003)

The kernel is the actual core of the operating system. It's the lowest level guts of everything, normal users never directly use it. Instead they use utility programs that make calls to routines in the kernel.

As for help, I'm afraid that I have never programmed USB devices on MacOS X, but I can point you at some documentation as well as somebody elses project which has published source code.

<http://developer.apple.com/techpubs/macosx/Darwin/General/IOKitFundamentals/index.html>
<http://developer.apple.com/hardware/iokit/>
<http://sourceforge.net/cvs/?group_id=48717>

Good luck, post anything you learn here, or any interesting links you find. I want to hook up my bicycle trainer to my Macintosh eventually. I've developed the USB hardware but I've been too lazy to do the actual software bits on the MacOS or linux side.


----------



## bjurusik (Mar 8, 2003)

Last semester I took a course on IBM PC ASM ... aka Assembly Language.  Is kernel programming like Mac machine code, or is it higher level?


----------



## Captain Code (Mar 8, 2003)

Kernels and device drivers are generally written in PPC Assembly


----------



## substrate (Mar 8, 2003)

No, the kernel isn't normally written in PPC assembly, nor are drivers. Most of the kernel, whether it's the guts beneath MacOS X or the guts beneath linux are written in C or C++. There are sometimes very small segments of code which are written in native assembly.

Here's a link at Apple with some details.

http://developer.apple.com/techpubs/macosx/Darwin/General/
KernelProgramming/index.html


----------



## Captain Code (Mar 8, 2003)

From what I've read it usually is, or it certainly used to be.  Maybe the Darwin kernel isn't, but I don't know for sure.

Device drivers often are, such as for your video card.  I know there's a lot of low level system DLLs in Windows that definately use assembly.

That link only talks about how to program kernel extensions, which is different than the kernel itself.


----------



## bjurusik (Mar 8, 2003)

Well, I did a little more research and found some info on InputSprockets, apparently, this is what programmers used in OS 9 to write drivers.  After more research, I found that this has been replaced by the HID Manager.  I'm kind of lost by all this talk however ... like, what kind of file is a driver (in PB) and where does it go when I've created it, etc.  I've only taken classes in Java, ASM, and Data Structures (using C++), and I'm learning Cocoa slowly.  It doesn't seem like writing a driver for something like a game controller would be that hard.  I'm guessing it would be like what we did in my ASM class  to get input from a port. Write a for loop which continually checks the port, and when something happens it calls a table lookup.  However, say I wanted an application that I could map the various buttons to different keyboard strokes ... would this application also be the driver or would this be a seperate, standalone cocoa app?  Maybe I wouldn't even need to do any of this, possibly USB overdrive would work?


----------



## Rhino_G3 (Mar 10, 2003)

While I can't personaly vouch for the Darwin kernel I do know that the Linux kernel is written in C, not assembly.  The source is freely available.  Download it and take a look.

Anything that is extremely time dependant and in need of great optimization is usualy written in assembly.  Video card drivers are an excellent example of this.  

Heck,  the networking module in Quake 3 is written largely in assembly.  Id wanted the quickest, most efficient packet handling that they could get.


----------



## Ripcord (Mar 12, 2003)

Boy, what a lousy bunch of developers we are if we don't even know the difference between a kernel and the Colonel ...   

Much of Darwin and the Mach kernel (which is heavily based on BSD and nearly completely written in C or related/derivative languages) has also been "opened" by Apple and the sources are freely downloadable.  

See the Darwin page (http://developer.apple.com/darwin/ ) or the OpenDarwin projects page (http://www.opensource.apple.com/projects/darwin/6.0/projects.html )for a list of projects or modules in the OS and their downloadable code) for more info...

Rip


----------

