Libdragon

From N64brew Wiki
Jump to navigation Jump to search

Libdragon is an open-source SDK for Nintendo 64. It aims for a complete N64 programming experience while providing programmers with modern approach to programming and debugging. These are the main features:

  • Based on modern GCC (10.2) and Newlib, for a full C11 programming experience. A Docker container is available to quickly set up the programming environment.
  • The GCC toolchain is 64 bit capable to be able to use the full R4300 capabilities (commercial games and libultra are based on a 32-bit ABI and is not possible to use 64-bit registers and opcodes with it)
  • Can be developed with newer-generation emulators (cen64, Ares, Dillonb's n64, m64p) or development cartridges (64drive, EverDrive64).
  • In-ROM filesystem implementation for assets. Assets can be loaded with fopen("rom:/asset.dat") without having to do complex things to link them in.
  • Efficient interrupt-based timer library (also features a monotone 64-bit timer to avoid dealing with 32-bit overflows)
  • Graphics: easy-to-use API for 2D games, accelerated with RDP
  • Support for standard N64 controllers and memory paks.
  • Support for saving to flashes and EEPROMs (including a mini EEPROM filesystem to simplify serialization of structures).
  • Audio: advanced RSP-accelerated library, supporting up to 32 channels and streaming samples from ROM during playback for very low memory usage. Supports WAV files for sound effects and XM module format for background music. Can playback a 10-channel XM with < 3% CPU and < 10% RSP.
  • Debugging aids: console (printf goes to screen) exception screen, many asserts (so that you get a nice error screen instead of a console lockup), fprintf(stderr) are redirected to your PC console in emulators and to USB via compatible tools (UNFLoader, g64drive).
  • Support to read/write to SD cards in development kits (64drive, EverDrive64), simply with fopen("sd:/data.dat")
  • Simple and powerful Makefile-based build system for your ROMs and assets (n64.mk)

There is currently no support for 3D programming. An effort has recently started to implement 3D using the OpenGL 1.1 API.

To attempt some 3D programming, please use this "ugfx library" that is left as a non-merged pull request to gain visibility.

How to get started with Libdragon development

The easiest way is to use the ready-to-use Docker toolchain and related command line tool.

  1. Download one of the pre-built binaries of the libdragon CLI tool. If you're not into downloading pre-built binaries, follow the instructions in the README to use npm to install it.
  2. Run libdragon init in a new empty directory. This will download the docker image of the toolchain, a copy of libdragon itself and get things ready.
  3. Try to compile and run one of the libdragon examples. For instance, go into libdragon/examples/spritemap and run libdragon make

Hack away!

Licensing

Libdragon itself is licensed with the "Unlicense" license. This is the closest option to public domain release for jurisdictions where releasing a software into the public domain is not legally well defined or allowed.

The goal of libdragon has always been to provide a fully open source toolchain to do 100% legal homebrew development on the Nintendo 64 platform. Unfortunately, the goal is not fully met yet. When producing the final ROM, libdragon must include in the binary a small proprietary bootloader (IPL3). The copy used by libdragon has been extracted by commercial ROMs and is not officially licensed. There is a plan to replace this bootloader with open source code, but the work has not begun yet.

Also, if you are planning to distribute replication cartridges and what to stay on the completely safe side, make sure the cartridges you buy or mount contain an open source replacement of the CIC protection chip such as a MCU running the UltraCIC III open source firmware. Libdragon itself will work also with a real CIC 6102, but that contains a Nintendo firmware that would be used as unlicensed (and thus not fully legal).