N64 programming (libdragon)
-
calima
- Posts: 1789
- Joined: Tue Oct 06, 2015 10:16 am
Re: N64 programming (libdragon)
The latter has a vertical line on top of the island, looks like misaligned texcoords.
-
BMBx64
- Posts: 25
- Joined: Thu May 25, 2017 7:27 am
Re: N64 programming (libdragon)
Yeah you are right, im not sure if it was a mistake on the emulator, on real harware seems fine.calima wrote:The latter has a vertical line on top of the island, looks like misaligned texcoords.
ADDED RDP NOISE
Another color combiner, provides some kind of TV noise, works on rectangles and triangles, added 2 options.
1) Partial

2) Complete

The last one is compatible with RGB scale and alpha, so you could replicate the interferences of the Goldeneye watch for example.
I believe is pretty similar to some special effects of Sin & Punishment, like on the evade move, some emulators wont replicate this effect.

Here can be seen better, however the dots are transparent instead of black, i will keep researching..

--
I have changed the way some function works, now you can set 1CYCLE or 2CYCLE with:
- rdp_texture_cycle( num ); // 0 = 1cycle, 1 = 2cycle
However 2cycle still doesnt works, but will be useful when 3D is added.
Other functions such as:
- rdp_additive_blending
- rdp_intensify
- rdp_color
- rdp_noise
Has been improved, previously you could call them without setting RDP to 1cycle, but they did a call to set other modes for that, in 3D i believe most of the time the RDP will be in 1cycle or 2cycle mode, so now they just do a color combiner set and must be called after setting the RDP into cycle mode.
-
Drew Sebastino
- Formerly Espozo
- Posts: 3496
- Joined: Mon Sep 15, 2014 4:35 pm
- Location: Richmond, Virginia
Re: N64 programming (libdragon)
I'm really loving all the niche effects that you're adding.
Honestly though, that second gif makes it look like it could be useful for water splashes or shattered glass or something of that nature.
-
Erockbrox
- Posts: 397
- Joined: Sun Nov 23, 2014 12:16 pm
Re: N64 programming (libdragon)
So I'm reading this thread and trying to understand what everything is here.
Is this a game engine that you are making for the N-64? Or is there a programming library for the N-64 called libdragon and you are just developing code with it to create cool special effects that can be used by a homebrewer to make new N-64 games?
Is this a game engine that you are making for the N-64? Or is there a programming library for the N-64 called libdragon and you are just developing code with it to create cool special effects that can be used by a homebrewer to make new N-64 games?
-
BMBx64
- Posts: 25
- Joined: Thu May 25, 2017 7:27 am
Re: N64 programming (libdragon)
Yeah a bit of both things.
Libdragon is a library for programming on N64, however is really limited, at the point sprite flip was not even possible, so ive started improving it/adding new features.
Then i made a tool for converting textures and a tile engine.
Im moving soon to libn64, the lib of Marathon (author of CEN64), im working with Krom to port most of the RDP features to libn64, we have a rdp.c for all the internal RDP calls and rdp_functions.c for more user friendly functions (libdragon style).
Krom is working on the 3D lib which will be pretty cool, right now all the math is done by the CPU and drawn by the RDP, once everything is ported and its stable will be moved to the RSP for more speed.

Libn64 is pretty fast and have thread support.
Regarding libdragon ive done some fixes.
PALETTE FIX
A palette can be selected now from 0 to 15 on 4bit textures using:
rdp_select_palette( uint8_t pal );
4BIT TEXTURE WORKAROUND
Textures of 64x64x4bit can be used now (full 2KB), for some reason when the texture takes 2KB overwrittes the TLUT area, and the texture won't show, however if we set palette 2 or higher that data remains untouched.
This makes the trick (edited..):
uint16_t palette_0[16] = { 0,16641,33553,42009,25369,16913,25097,8449,50465,34089,25633,17177,8721,769,513,265 };
rdp_select_palette(2);
rdp_load_palette(2,15,palette_0); // upload starting TMEM on palette 2, 16 colors upload (0-15), point to the palette struct
This function can upload individual palettes.
I did once again a Goldenaxe scroll test but this time with 64x64x4bit textures.
x= 0 - 232 fps
x= 194 - 212 fps
x= 974 - 204 fps
x= 1552 - 222 fps
I think if all the textures shares the same palette this could be faster than a 64x32x16bit texture, both are very close in terms of performance.
DOWNLOAD (64x64 test)
https://mega.nz/#!ZkhVRb7K!UejX0KrNIPeK ... u5heYgGLDU
FUNCTION RENAMES AND OTHER CHANGES
Some functions has been renamed using the internal names of n64 or has been changed to match the work done on libn64 for easier code migration.
As for example all these functions:
rdp_enable_1primitive(1); // enable
rdp_enable_tlut(1);
rdp_enable_texture_copy();
rdp_enable_1primitive(0); // disable
rdp_enable_tlut(0);
Works like this:
rdp_texture_copy( ATOMIC_PRIM | EN_TLUT );
Or if you dont want to enable anything else than copy mode, this overwrittes the previous command:
rdp_texture_copy(0);
The define list for the 64bit commands comes on the examples of Fire & Tlut on github, but i could provide a more detailed one if anyone is interested.
Examples and lib has been updated on github:
https://github.com/conker64/libdragon
Libdragon is a library for programming on N64, however is really limited, at the point sprite flip was not even possible, so ive started improving it/adding new features.
Then i made a tool for converting textures and a tile engine.
Im moving soon to libn64, the lib of Marathon (author of CEN64), im working with Krom to port most of the RDP features to libn64, we have a rdp.c for all the internal RDP calls and rdp_functions.c for more user friendly functions (libdragon style).
Krom is working on the 3D lib which will be pretty cool, right now all the math is done by the CPU and drawn by the RDP, once everything is ported and its stable will be moved to the RSP for more speed.

Libn64 is pretty fast and have thread support.
Regarding libdragon ive done some fixes.
PALETTE FIX
A palette can be selected now from 0 to 15 on 4bit textures using:
rdp_select_palette( uint8_t pal );
4BIT TEXTURE WORKAROUND
Textures of 64x64x4bit can be used now (full 2KB), for some reason when the texture takes 2KB overwrittes the TLUT area, and the texture won't show, however if we set palette 2 or higher that data remains untouched.
This makes the trick (edited..):
uint16_t palette_0[16] = { 0,16641,33553,42009,25369,16913,25097,8449,50465,34089,25633,17177,8721,769,513,265 };
rdp_select_palette(2);
rdp_load_palette(2,15,palette_0); // upload starting TMEM on palette 2, 16 colors upload (0-15), point to the palette struct
This function can upload individual palettes.
I did once again a Goldenaxe scroll test but this time with 64x64x4bit textures.
x= 0 - 232 fps
x= 194 - 212 fps
x= 974 - 204 fps
x= 1552 - 222 fps
I think if all the textures shares the same palette this could be faster than a 64x32x16bit texture, both are very close in terms of performance.
DOWNLOAD (64x64 test)
https://mega.nz/#!ZkhVRb7K!UejX0KrNIPeK ... u5heYgGLDU
FUNCTION RENAMES AND OTHER CHANGES
Some functions has been renamed using the internal names of n64 or has been changed to match the work done on libn64 for easier code migration.
As for example all these functions:
rdp_enable_1primitive(1); // enable
rdp_enable_tlut(1);
rdp_enable_texture_copy();
rdp_enable_1primitive(0); // disable
rdp_enable_tlut(0);
Works like this:
rdp_texture_copy( ATOMIC_PRIM | EN_TLUT );
Or if you dont want to enable anything else than copy mode, this overwrittes the previous command:
rdp_texture_copy(0);
The define list for the 64bit commands comes on the examples of Fire & Tlut on github, but i could provide a more detailed one if anyone is interested.
Examples and lib has been updated on github:
https://github.com/conker64/libdragon
-
mikejmoffitt
- Posts: 1353
- Joined: Sun May 27, 2012 8:43 pm
Re: N64 programming (libdragon)
You should make a pull request against the master libdragon repo for your changes.
-
BMBx64
- Posts: 25
- Joined: Thu May 25, 2017 7:27 am
Re: N64 programming (libdragon)
Hi, since libn64 is taking a while i decided to take another look at libdragon and fix, clean, add new content.
There was a bug when disabling AA (320x240) on NTSC, at first i though it was a libdragon fault but when setting 0x00003302 directly to VI status the bug remains, seems like a bad combination that the hardware dislikes, so the more closer solution is 0x00003202 (AA RESAMPLE).

Added load_sprite, this function load textures from the cartridge and takes care of the CPU cache, it writes back to the RAM, so the RDP can draw them properly.
Flush_strategy is pointless now and was removed, when enabled this function was intented to write back to RAM each time a texture was loaded on TMEM instead of only once (when loaded from the cartridge), if a texture data have to be changed on the fly data_cache_hit_writeback_invalidate can be used.
Lib and examples on the same place:
https://github.com/conker64/libdragon
Sorry mikejmoffitt i missed your message
There was a bug when disabling AA (320x240) on NTSC, at first i though it was a libdragon fault but when setting 0x00003302 directly to VI status the bug remains, seems like a bad combination that the hardware dislikes, so the more closer solution is 0x00003202 (AA RESAMPLE).

Added load_sprite, this function load textures from the cartridge and takes care of the CPU cache, it writes back to the RAM, so the RDP can draw them properly.
Flush_strategy is pointless now and was removed, when enabled this function was intented to write back to RAM each time a texture was loaded on TMEM instead of only once (when loaded from the cartridge), if a texture data have to be changed on the fly data_cache_hit_writeback_invalidate can be used.
Lib and examples on the same place:
https://github.com/conker64/libdragon
Sorry mikejmoffitt i missed your message
-
WaterGlass
- Posts: 1
- Joined: Sat Nov 16, 2024 9:43 pm
Re: Nintendo 64 / N64 programming (Libdragon)
Due to many people coming here and inquiring about Nintendo 64 / N64 Development & Programming, and this thread being very out of date, there have been leaps and strides within the community for this console, notably on maintaining, developing, and furthering the Libdragon SDK https://libdragon.dev, of which I will discuss below:
TL/DR: Libdragon updates since 2017/2018, when this thread originated: Homebrew SDK, Public Domain, 2D & 3D, Audio and Controller support, OpenGL 1.1
A preview of what has been created within the N64 community, from Dec. 2022, can be viewed here: https://www.youtube.com/watch?v=IptOoeUDzps
The 5th Annual N64brew Game Jam is currently underway, from Oct - Dec. 2024. Winners announced afterwards. The theme for this year is "mini-games" and is one big collection, created by the community, and only utilizing Libdragon & Tiny3D regarding workflow and Development.
To see previous N64Brew Gam Jam entries, see: https://n64brew.dev/wiki/Category:Game_Jams
Many of the new features of Libdragon, since intial development, and since last posting in this thread (2018), are as follows:
Notably these are the main features of Libdragon (Stable Changelog: https://github.com/DragonMinded/libdrag ... -Changelog, as of November 2024:
3D graphics
The short of it, is as follows:
SummerCart64 is a custom made cartridge (commonly referred as a flashcart) that allows you to develop and play games on the N64 console. It is the first N64 flashcart that is feature complete and completely open source.
With fast I/O, integrated support in libdragon / libcart / UNFLoader, and well documented API, testing your homebrew on real hardware was never this easy before!
SummerCart64 employs features not available in other N64 flashcarts, like 64DD hardware emulation, automatic save backup during gameplay, or ability to behave like a stock game pak with direct mode, making it the best choice for both players and game developers.
A complete Feature list is detailed below:
SummerCart64 Features:
SummerCart64 features
Hardware specification
Input / Output:
TL/DR: Libdragon updates since 2017/2018, when this thread originated: Homebrew SDK, Public Domain, 2D & 3D, Audio and Controller support, OpenGL 1.1
A preview of what has been created within the N64 community, from Dec. 2022, can be viewed here: https://www.youtube.com/watch?v=IptOoeUDzps
The 5th Annual N64brew Game Jam is currently underway, from Oct - Dec. 2024. Winners announced afterwards. The theme for this year is "mini-games" and is one big collection, created by the community, and only utilizing Libdragon & Tiny3D regarding workflow and Development.
To see previous N64Brew Gam Jam entries, see: https://n64brew.dev/wiki/Category:Game_Jams
Many of the new features of Libdragon, since intial development, and since last posting in this thread (2018), are as follows:
Notably these are the main features of Libdragon (Stable Changelog: https://github.com/DragonMinded/libdrag ... -Changelog, as of November 2024:
- Based on modern GCC (version 14) 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 (Ares) and development cartridges (64drive, EverDrive64, SummerCart64).
Support both vanilla N64 and iQue Player (Chinese variant). It is possible to run ROMs built with libdragon on iQue without modifying the source code.
- Comprehensive RDP library called rdpq that offers both low-level access and very high-level blitting functions.
Support for drawing sprites of arbitrary sizes and arbitrary pixel formats. Rdpq takes care of handling TMEM limits transparently and efficiently.
Support for sprite zooming and rotation. Rotated sprites are transparently drawn via triangles instead of rectangles.
Support for all RDP pixel formats, including palettized ones.
Very simple render mode configuration, that allows for full RDP graphic effects including custom color combiner and blender.
Comprehensive mksprite tool, that converts from PNG format, includes optional state-of-the-art color quantizer and dithering.
Transparent compression of graphics for minimal ROM size
- Advanced RSP-accelerated mixer library, supporting up to 32 channels and streaming samples from ROM during playback for very low memory usage.
Supports WAV files for sound effects
Supports streaming of uncompressed or VADPCM-compressed WAV files for music.
Supports playing of XM modules (FastTracker, MilkyTracker, OpenMPT). Can playback a 10-channel XM with < 3% CPU and < 10% RSP.
Supports playing of YM modules (Arkos Tracker 2)
- 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.
SD card access (fopen("sd://asset.dat")) on all available flashcarts.
- Asset library for fast, transparent compression support for data files, including your custom ones. Automatically integrated in conversion tools for graphics.
Three different compression algorithms with increasing compression ratio (and decreasing decompression speed). Currently based on LZ4, Aplib, Shrinkler. Compression ratios competitive with gzip and xz, at higher decompression speeds.
Optimized decompression routines in MIPS assembly that run in parallel with DMA for maximum speed.
Support for streaming decompression based on the fopen() interface.
- Clear error screens with symbolized stack traces in case of crashes.
Codebase is filled with assertions, so that you get a nice error screen instead of a console lockup.
Printf-debugging via debugf() which are redirected to your PC console in emulators and to USB via compatible tools (UNFLoader, g64drive).
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).
Improved boot using open-source IPL3 bootcode, which boots ROMs up to 5x faster and allows for compressed game code (using libdragon compression library).
3D graphics
- Allow for easily plugging in 3D graphics pipelines, that can potentially even coexist in the same scene.
Included in libdragon: full OpenGL 1.1 port, together with custom N64 extensions for using RDP-specific features.
Third-party: Tiny3D, a high-performance native 3D pipeline.
Both OpenGL and Tiny3D import model files from Blender via the GLTF format, and feature also an animation system with skinning support.
a MPEG1 RSP-accelerated movie player, for high-quality FMVs.
Expected performance for FMV: 320x240 movie at 800 Kbit/s at 20 fps
Very simple to use also for render-to-texture scenarios, where a movie is played back as part of a 3D scene or as background in a 2D game.
Dynamic library support (DSO, sometimes called “overlays”) for dynamically loading and unloading part of game code and data. This is implemented using the standard dlopen() / dlsym().
Support for Opus audio compression for ultra-compressed music streaming.
Same state-of-the-art audio algorithm that is currently mainstream on PCs.
Compression ratios around 15:1 for audio files. Around 3-5 minutes of mono audio per Megabyte of ROM, depending on quality.
RSP-accelerated for realtime playback. 18-20% of CPU usage for mono streams, which makes it feasible for menus or not resource-intensive games, well suited also for speech at very high compression ratio, would allow for a fully talkie game, and much more.
These features will eventually land to trunk, but you can start playing with them even today. Go the preview branch doc https://github.com/DragonMinded/libdrag ... iew-branch for more information.
The short of it, is as follows:
SummerCart64 is a custom made cartridge (commonly referred as a flashcart) that allows you to develop and play games on the N64 console. It is the first N64 flashcart that is feature complete and completely open source.
With fast I/O, integrated support in libdragon / libcart / UNFLoader, and well documented API, testing your homebrew on real hardware was never this easy before!
SummerCart64 employs features not available in other N64 flashcarts, like 64DD hardware emulation, automatic save backup during gameplay, or ability to behave like a stock game pak with direct mode, making it the best choice for both players and game developers.
A complete Feature list is detailed below:
SummerCart64 Features:
SummerCart64 features
- Enough space for your ROMs
Flashcart embeds 64 MiB of fast SDRAM memory, with additional 14 MiB available from the flash memory, totaling up to 78 MiB - more than biggest known retail ROMs.
Blazing fast I/O
Both microSD card slot and USB port operate at peak speed of ~23.8 MiB/s. Even largest retail ROMs (64 MiB) can be loaded in just couple of seconds.
Never lose your progress
Every known save type found in the retail games is supported. Saves are automatically flushed to the microSD card (or via USB with PC app attached) during gameplay - no reset button press is necessary!
Complete 64DD hardware emulation built-in
Forget about 64DD ROM conversions - SummerCart64 can play disk dumps directly! Combo games (N64 cartridge + 64DD disk) and multi-disk 64DD games are also supported.
Every region is welcome
SummerCart64 supports every N64 console regardless of its region. NTSC/PAL switching is done automatically and last detected region is stored inside NVRAM.
Run games with ease
Browse, run and manage your game library right on the N64 console with the N64FlashcartMenu - a dedicated menu software for the SummerCart64.
Full control of boot process
Direct mode makes testing possible without any interference from the bootloader embedded into SummerCart64, perfect for trying out custom IPL3 replacements giving you control right after N64 boots up.
Dedicated terminal PC app
Powerful, and yet simple, sc64deployer app greatly enhances developer user experience.
Outstanding developer features
- Dedicated PC app for loading ROMs and debug terminal access.
Simple, command based, communication protocol - both on the USB and N64 side.
microSD card interface with simple, block based, protocol.
Fast USB interface with well documented protocol.
8 kiB buffer for general use with microSD card or USB interface.
Native support for microSD card and USB interface in the libdragon.
libcart support.
UNFLoader support - both in the PC app and USB library.
IS-Viewer 64 debug interface support in the hardware.
With freedom in mind
Hardware specification
Input / Output:
- N64 cartridge edge connector
microSD card slot (~23.8 MiB/s peak, cards up to 2 TB are supported)
USB Type-C receptacle (~23.8 MiB/s peak)
Programmable push button on the back
Status LED
- 64 MiB SDRAM
16 MiB QSPI Flash (last 2 MiB is reserved for internal use)
8 kiB buffer in the FPGA
64 byte battery-backed NVRAM in the RTC
CIC emulation
- Automatic region switch
Fully programmable seed/checksum values
Supports booting directly from the 64DD IPL
- EEPROM 4 kbit
EEPROM 16 kbit
SRAM 256 kbit
SRAM 3x256 kbit
FlashRAM 1 Mbit
SRAM 1 Mbit
Automatic writeback after ~1 second to the microSD card or USB interface
- 64DD (N64 Disk Drive) - disk access to/from microSD card or USB interface
IS-Viewer 64 (movable base address, fixed 64 kiB buffer size, debug printf only)
- Real time clock
CR2032 RTC backup battery
Embedded N64 bootloader capable of loading menu binary from the microSD card and displaying error messages
Option to disable embedded N64 bootloader (direct mode)
Firmware updatable via USB interface
Seamless power switching between USB and N64