N64 Programming/Compiling - Wikibooks, Open Books For An Open ...
- Language
- Watch
- Edit
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).

Contents
|
Initial Steps
editChoose a directory that you want the compiled binaries, set this to $PREFIX, and ensure that it exists. For example,
exportPREFIX=/opt/n64 mkdir-p$PREFIXNext, set $GCC to the compiler you are going to use. For example,
exportGCC=gccBuilding binutils
editDownload 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:
mkdir-pbuild-binutils cdbuild-binutilsThen run the following commands:
../binutils-2.35.1/configure\ --target=mips64-elf--prefix=$PREFIX\ --program-prefix=mips64---with-cpu=vr4300\ --with-sysroot--disable-nls--disable-werror makeCC=$GCC makeinstallHopefully 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
editGCC needs to use some of the binaries that you compiled above, so do the following:
exportPATH=$PREFIX/bin:$PATHThis will make GCC be able to find them.
As with binutils, download the gcc source (we will use version 10.2.0) and extract it.
Create an out-of-tree build directory, and change into it:
mkdir-pbuild-gcc cdbuild-gccThen run the following commands:
../gcc-10.2.0/configure\ --target=mips64-elf--prefix=$PREFIX\ --program-prefix=mips64---with-arch=vr4300\ -with-languages=c,c++--disable-threads\ --disable-nls--without-headers makeall-gccCC=$GCC makeall-target-libgccCC=$GCC makeinstall-gcc makeinstall-target-libgccThe mips64 toolchain should now be installed in your chosen $PREFIX/bin.
Coding examples
editWhile 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:
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ** ** N64 DMA ** ** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ typedefstruct { /* Pointers to data */ void*ramp; void*romp; /* Filesizes (8-byte aligned) */ u32size_ramrom;/* RAM -> ROM */ u32size_romram;/* RAM <- ROM */ /* Status register */ u32status; }DMA_REG; /* DMA status flags */ enum { DMA_BUSY=0x00000001, DMA_ERROR=0x00000008 }; /* DMA registers ptr */ staticvolatileDMA_REG*dmaregs=(DMA_REG*)0xA4600000; /* Copy data from ROM to RAM */ intdma_write_ram(void*ram_ptr,void*rom_ptr,u32length) { /* Check that DMA is not busy already */ while(dmaregs->status&DMA_BUSY); /* Write addresses */ dmaregs->ramp=(u32)ram_ptr&0x00FFFFFF;/* ram pointer */ dmaregs->romp=(u32)rom_ptr&0x1FFFFFFF;/* rom pointer */ /* Write size */ dmaregs->size_romram=length-1; /* Wait for transfer to finish */ while(dmaregs->status&DMA_BUSY); /* Return size written */ returnlength&0xFFFFFFF8; }You may also have to use inline assembly a fair bit. The function below sets a breakpoint on a region of memory:
enum { BREAKPOINT_READ=1, BREAKPOINT_WRITE=2 }; /* Set breakpoint */ voidbp_set(u32addr,u8flags) { addr&=0x3FFFF8;/* assuming lower 4MB, also doubleword */ flags&=0x03;/* only lower two bits */ addr|=flags; asm("mtc0 %0, $18\n"/* WatchLo */ "mtc0 $zero, $19\n"/* WatchHi */ ::"r"(addr)); }Links
edit- GCC 10.2.0
- Binutils 2.35.1
Từ khóa » C N64
-
Nintendo 64 - Wikipedia
-
Nintendo 64 Controller - Wikipedia
-
Nintendo 64™ – Nintendo Switch Online For Nintendo Switch
-
Why Did The Nintendo 64 Controller Include Four C Buttons? - Quora
-
Classic N64 Controller, SAFFUN N64 Wired USB PC Game Pad ...
-
Hyperkin Controller Adapter For N64 Controller Compatible With ...
-
Nintendo 64 Controller - Conker Wiki - Fandom
-
N64 Nintendo 64 Console + UP TO 4 NEW CONTROLLERS ... - EBay
-
Nintendo 64 NTSC-U/C Video Game Consoles For Sale - EBay
-
How Do I Put The C Buttons From An N64 Game Onto A Keyboard? I ...
-
Cn64 (variation) - WormBase : Nematode Information Resource
-
Command & Conquer - Nintendo 64 Review - Ultra HDMI - HD