Friday, November 20, 2009

Programming games for Nintendo WII part 1

The first thing that you need to start Wii programming is to get the proper development tool. You will need the DevkitPPC witch is the part of the DevkitPro toolchain used for Wii and Gamecube development. These guides describe setting up such a system.

Installing devkitPPC forWindows

  • Go to this page and download the latest Windows installer.
  • Let it install to the C:\devkitPro\ to make it easier to follow the tutorial for now.
  • When installing it, you can deselect devkitARM and devkitPSP
  • Click next until it finishes installing

Setup your project folder

  • Under no circumstances should you place projects within the devkitPro folder. The windows updater can and will overwrite/delete your files.
  • Create a new folder outside the devkitPro folder, c:\projects\wii for example. This path should not contain spaces.
  • Copy the folder C:\devkitPro\examples\wii\template\ to this new directory and rename it to "helloworld" so that the full path is c:\projects\wii\helloworld\

Compile the Hello World Example

  • Assuming you installed Programmer's Notepad through the installer, double click the .pnproj file in your new project.
  • Click on Tools->make or use the ALT+1 key combination
  • The output window at the bottom will show the build progress
Note: If you are having trouble compiling some programs under Windows Vista (eg. libogc cvs), try unsetting PLATFORM variable. (in msys shell, "unset PLATFORM")

Run the Hello World Example on the emulator

  • Now, browse to the helloworld folder. There should be a helloworld.dol file here now.
  • Run the hellworld.dol in an emulator. As of 31-Mar-2009, emulators for the Wii are not 100% compatible and feature complete. Dolphin can successfully run some homebrew. See the Dolphin page for more information. Another emulator is Gcube. Gcube does not run homebrew compiled in Wii mode, but can run homebrew if compiled for the GameCube mode. See the Gcube page for more information.

Run the Hello World Example on the Wii using wiiload

  • For this to work, you need to have the Homebrew Channel installed on your Wii and a way to access the Wii via TCP.
  • Get wiiload.exe from the Homebrew Channel archive (should be in wiiload\win32) and copy it to C:\devkitPro\msys\bin.
  • Set the environment variable WIILOAD to something like "tcp:" (replace the IP with your Wii's IP). This can be done via Control Panel -> System -> Advanced -> Environment Variables. Then restart windows.
  • Start the Homebrew Channel on your Wii.
  • Click on Tools -> run or use the ALT+R key combination.
  • The output window at the bottom will show the upload progress (so does the Homebrew Channel) and the example will be started on your Wii when it's done. 

Installing devkitPPC for Linux

Installing through the repositories

It may be possible to install devkitPPC via your linux distro repositories. Try searching for devkitPPC MYDISTRO [1].
If you are using Ubuntu or Debian, there is a repository with .deb files maintained by UCLM university.
1. Add to sources.list file the lines
deb ./
deb ./
deb-src ./
2. Execute sudo apt-get update
3. Execute sudo apt-get install devkitpro-ppc
The files will be installed at /opt/devkitPro with read-only permission. You can do a copy of the examples directory in your user space and then compile and run in the normal way.
cp -r /opt/devkitPro/examples/ .
cd examples/wii/template
make run

Installing devkitPPC from DevkitPro packages

A premade archive of these files (organized according to the directory structure below) is available here
Note: The US mirror for DevkitPPC can be slow, so you might have to switch to a European one.
Note: Extract the files from the devkitPPC tarball using "tar -xvjf " to preserve symlinks, etc...
  • Create a folder for devkitpro and extract everything into it such that you have this directory structure:
  libogc (extract the libfat tar under this directory as well)
  • Edit ~/.bashrc and add
export DEVKITPRO=/path/to/devkitpro # replace this by your actual path
  • Optionally, find out your Wii's IP with the homebrew channel and add
export WIILOAD=tcp: # replace this by your Wii's IP
  • Restart your terminal or type
source ~/.bashrc

Compiling a Hello World

  • Enter devkitpro/wii-examples/template and simply type
  • To run the example on your Wii, start the homebrew channel and type
make run
VoilĂ ! You just compiled your first Wii program!

Compiling Insight Debugger

A custom version of the Insight graphical debugger is included as part of the DevkitPro package, however currently there are no linux binaries available. In order to successfully compile the source under linux, you need to run the following sequence of commands from the directory where you unpacked the source:
for f in `find`; do dos2unix ${f}; done
./configure --target=powerpc-gekko
make install prefix=/directory/to/install/to

Using DDD (GNU Data Display Debugger)

An alternative to Insight is DDD
It has the advantage that you won't have to compile it on linux
For instance to install it on ubuntu just use the following command:
sudo apt-get install ddd
Then you use ddd with powerpc-gecko-gdb with the following:
ddd --debugger path-to-powerpc-gecko-gdb
And finally you can use the console at the bottom to connect to your wii and load the symbols as you would using gdb from the console
For instructions on how to use gdb or insight for remote debugging, see Remote Debugging with GDB

Installing devkitPPC for Mac OS X


  • First make sure you have Xcode tools 3 (note that this requires Leopard) or above installed then go here and download the latest Mac distro (actually we don't have the latest release as pkg. Try the higher release with a pkg. If you see the latest release with a pkg, please remove this). Also download gcube emulator for mac.
  • Double-click the devkitPPC.pkg and follow the set-up instructions then log out and back in or restart.

Compile the Hello World Example

  • Launch Xcode
  • Select "New project..." from the File menu
  • Select "devkitPPC Wii Project"
  • Name your project, and pick a place to save it
  • Hit "Build"
  • The completed .dol file will (by default) be found in build/Development

Run the Hello World Example

  • To run the file again open Terminal and type “gcube ~/Desktop/WiiBrew/devkitPPC\GameCube\Project/build/Development/devkitPPC” no quotes obviously.
  • The resulting dol should be compatible with the Twilight Hack. Unfortunately dols compiled with CVS libogc and future stable releases will not be compatible with Gcube.

Some Code snippets

libogc provides a jump back to the loader through the standard libc exit function. exit(0) will immediately return, all other values will display a console screen with the exit code.
  • Add this in your main while loop, under "VIDEO_WaitVSync()":
int buttonsDown = PAD_ButtonsHeld(0);
if( (buttonsDown & PAD_TRIGGER_Z) && (buttonsDown & PAD_BUTTON_START)) {

No comments:

Post a Comment