N64 Programming/Compiling

The N64 is by no means resource limited, so writing software for it in C is perfectly reasonable. One thing you must keep in mind, though: coding for the N64 requires extensive knowledge of both C and MIPS R4K assembly. However, assembly will only have to be used in small routines that initialize the N64 (or handle exceptions). You also have to be familiar with the GNU toolchain (binutils and gcc namely).

Initial Steps
Choose a directory that you want the compiled binaries, set this to $PREFIX, and ensure that it exists. For example,

Next, set $GCC to the compiler you are going to use. For example,

Building binutils
Download the binutils source code (we will use version 2.35.1), and extract it.

Create an out-of-tree build directory, and change into it:

Then run the following commands:

Hopefully everything went well, and now you'll have a binutils package targeting MIPS. Move back to your working directory and now it is time to build GCC.

Compiling GCC
GCC needs to use some of the binaries that you compiled above, so do the following:

This will make GCC be able to find them.

As with binutils, download the the gcc source (we will use version 10.2.0) and extract it.

Create an out-of-tree build directory, and change into it:

Then run the following commands:

The mips64 toolchain should now be installed in your chosen $PREFIX/bin.

Coding examples
While coding C for the N64 is no different than any other platform (except that you don't have any libraries at your disposal), you may, at times, have to write to memory mapped registers. The following example (which utilizes DMA) demonstrates this:

You may also have to use inline assembly a fair bit. The function below sets a breakpoint on a region of memory:

Links

 * GCC 10.2.0
 * Binutils 2.35.1