emuforge

Development

You need the Rust toolchain that rust-toolchain.toml names. n64emu builds only for x86-64 for now, and is built and tested on Linux: the code heap of the recompilers (n64-jit) refuses to compile for other processors, as it does not flush their instruction caches.

cargo build --release
cargo test --workspace
tools/check.sh          # everything CI runs; before every push
tools/check.sh clippy   # only one of its parts: format, clippy, tests, licenses or markdown

tools/check.sh also needs two tools:

cargo install --locked cargo-deny
cargo install --locked --git https://github.com/emuforge/forge forge-docs

The RDP needs Vulkan

The console's RDP runs on Vulkan 1.1. The core, without a name, takes a device that runs on the CPU (Mesa's llvmpipe, mesa-vulkan-drivers on Debian), and never the first one that it finds. The app's GPU setting is Automatic by default: a discrete GPU, or else an integrated one, or else the CPU's device. The core reads no environment variable. These are for whoever runs it:

  • Tests: the core's own tests use a stand-in for the RDP and need no GPU. Those of the real RDP (real_rdp) and of the app's layer need a device of the CPU type, and print a note and pass without one. To cover the RDP, have llvmpipe there, and keep its tests on it and Mesa's shader cache apart:

    export VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json   # only llvmpipe is seen
    export MESA_SHADER_CACHE_DIR=$PWD/target/shader-cache          # not your own cache
    cargo test --workspace
    
  • A real GPU is chosen by its name, or a part of it that only one device has: GPU in the app's menu, gpu = in its settings.txt, or --gpu NAME in the developer program. The name that is wrong says which devices there are.

  • Pictures with no copy need the RDP and the window's OpenGL on the same device and driver, with VK_KHR_external_memory_fd and VK_KHR_external_semaphore_fd there and GL_EXT_memory_object_fd and GL_EXT_semaphore_fd in OpenGL (the RDP). llvmpipe cannot share, so on it, and under Xvfb, the picture is read back once.

The app

cargo build --release -p n64emu
target/release/n64emu GAME.z64

A game is a .z64, .n64 or .v64 file, or a .zip with one. --help has the keys and the options, which are forge's for every app. Saves, states, screenshots, settings.txt and controls.txt are in ~/.local/share/n64emu, or in --data-dir. Controller Paks are the player's own, in cards/, one for each port. The first start of a game can take some seconds while its security chip is found out. It is then kept in the game's save. Each game's hot code for the RSP's recompiler (hot/) and its list of the RDP's shaders (shaders/) are kept in ~/.local/share/n64emu, also with --data-dir, as forge-app does not give that folder to the emulator. They are compiled before the first frame.

The app and the lab take forge from its repository, at the commit that Cargo.toml pins.

To run it without a screen, for a test: xvfb-run -a target/release/n64emu GAME --frames 120 --screenshot-at 100, with WAYLAND_DISPLAY unset so that its window opens there.

The developer program

cargo build --release -p n64emu-dev
target/release/n64emu-dev --frames 600 --hashes GAME.z64
target/release/n64emu-dev program:rsp-rounds --cic 6102 --frames 3

It has no window and prints only numbers: how the game started, what the RCP did, the processor's stops, and with --hashes the hashes of the memory, the sound, the state and the picture after each frame. It never prints a value that a game read or wrote. The table at the top of apps/n64emu-dev/src/main.rs has all of its options, and an option that it does not know prints a short list of them. program:NAME runs one of the core's own test programs, and - reads the game from standard input. The options that are used the most:

OptionsWhat they are for
--frames N, --seconds S, --gpu NAMEhow long it runs, and the RDP's device (without one, llvmpipe)
--hashes, --screenshot FRAME:PATHcomparing two builds frame by frame, and a picture for a person to look at
--region, --memory, --save, --cic, --own_startthe core's settings for developers, by the ids of their values
--no-rsp-jit, --rsp-jit-lockstepthe RSP's interpreter alone, or each block of its recompiler compared with the interpreter. Only the speed may differ
--exact-waits, --each-rsp-step, --no-leadthe exact way, without passing the processor's waits, without the RSP's lead, or with a stop at each of the RSP's steps. Only the speed may differ, and a check compares them
--quantum Ninexact: longer pieces for the RSP, to measure what they could give
--calls, --rsp-counts, --rsp-spins, --rdp-waits, --gpu-timescounters for speed work (the scheduler). They change nothing that comes out
--hot PATH, --shader-list PATH, --pace HZ, --pictures, --pictures-laterunning as the app does: hot code and shaders compiled ahead, the app's frame rate, and its pictures
--scale 1|2|4, --scaled-pictures, --screenshot-scaled FRAME:PATHthe render scale
--trace FROM-TOhashes of each part's calls, to find where two runs part
--registers, --accesses N, --exceptions, --chips, --unknown-*, and the options for RDRAM's guessesfinding what a boot code needs, by addresses, times and hashes only
--compare, --compare-frames, --own-start-wait, --own-start-trycomparing two starts
--isviewerIS-Viewer 64, for our test programs only, never for games

Comparing two starts

--compare own_start=always runs a game to its entry twice, with its own boot code and with our own start, which then waits as long as the first run took, and prints only where they differ:

n64emu-dev --own_start off --compare own_start=always GAME.z64
n64emu-dev --own_start off --compare own_start=always --compare-frames 600 GAME.z64
n64emu-dev --own_start off --compare own_start=always --own-start-try ri_error=5 GAME.z64

A line names a register (differs RI_REFRESH), or a range of a memory with the hashes of both (differs rdram 0x300+0x20 hash … …), and in a range of up to 64 bytes the addresses of the words that differ. It never prints a value of a register, of RDRAM, the ROM, IMEM, DMEM or the PIF, or an instruction, and neither may any other tool or log for this work: a value is found by trying a guess with --own-start-try (n64_pif::boot::OwnStart::try_value names the parts), and seeing whether the difference goes away. --compare-frames N compares both runs again after N frames. --own-start-wait CYCLES sets how long our start waits, so that --hashes of the two can be compared frame by frame.

--screenshot FRAME:PATH writes the picture after a frame as a PNG file, for a person to look at.

The lab

cargo build --release -p n64emu-lab
target/release/n64emu-lab identify GAME|FOLDER...
target/release/n64emu-lab sweep GAME|FOLDER... --jobs N --out DIR

It is forge's lab of stepped consoles, and help lists what it does. It runs only the releases in apps/n64emu-lab/games.tsv, each in a process of its own. identify gives the line's first field: the SHA-1 of the game's data in the console's byte order. Its RDP runs on a Vulkan device of the CPU type, so set MESA_SHADER_CACHE_DIR as for the tests.

This documentation

It is the Markdown in docs/, and emuforge.org makes the pages. The harness says how it is written.

Test programs

Other people's test programs run on n64emu-dev as closed boxes: their source is not where any rule of n64emu comes from. A program may run only when its license and everything that it bundles allow it, and when it boots with libdragon's own IPL3 (Unlicense): any other boot program could be the console maker's. tools/tests/ipl3.py checks that by hashes, and never shows a byte of a ROM.

export N64_TESTS=/path/to/tests       # outside the repository; nothing in it is committed
tools/tests/fetch.sh                  # downloads or builds them at the commits below
tools/tests/run.sh                    # runs them; --details also prints what they printed

run.sh gives each test one verdict: missing, refused (not libdragon's IPL3), could_not_start, failed, passed, record (our measurement programs) or no_verdict, and ends with run: finished. It exits 1 when a test failed and 3 when none failed but one could not start. Logs are in $N64_TESTS/logs/.

ProgramCommitLicenseWhat it bundlesResults from a consoleMay
nemu64-test9a8b9f7d94eeMITlibdragon's IPL3 r7 through nust64 0.4.1 (MIT; its three IPL3 files are the same git blobs as libdragon's r6 and r7). Rust crates. src/tests/arithmetic/nemu_port.rs ("Port Nemu's arithmetic tests over", code-generated from another test framework) and src/tests/rsp/op_vmov_vrcp.rs (said to use tables ported from ares, ISC)not stated; its Cargo.toml names tests that are unstable on hardwarerun, here and in CI. Those two files are never opened, and their tests' expected values are no source
snapper64release v1.0.0, b39ee7e2657dMITlibdragon preview with its IPL3 r10. 7,094 reference picturesyes: its README says that they are dumped on a consolerun, here and in CI
N64-CPU-Testsfca9f40600f3CC BY-SA 4.0data only: code, a first and a final memory state for each case. The source that made them is not publishedyes, the final states, by its READMEuse as data, with credit; it needs a loader of ours
rsp_inval_instrs25b99a467149Unlicenselibdragon. Its README: "does not contain or depend on any Nintendo code"its findings, by its READMErun when built here
SaveTest-N6474235925e30dUnlicenselibdragon. Its prebuilt savetest.z64 is from 2022, before libdragon had its own IPL3run on flashcarts, by its READMErun only when built again here; the prebuilt ROM is never used
RDP-Timing-Testsa81ced93b28dMITlibdragonsample_results.txt, from the author's consolerun when built here. It measures, and sends its numbers over a flashcart's USB
libdragon's tests/preview f26e1c16145eUnlicenselibdragon and the third-party code in it, whose licenses were not all checkednorun when built here; CI after those licenses are checked
n64-systemtest196f54211732MITas nemu64-testas nemu64-testnot needed: its README says that nemu64-test replaces it
n64_pi_dma_testfea460b063f6none foundyes, by its READMEnot used: no license

Five other collections of tests have boot code files of unknown origin, some of them named like the maker's (PeterLemon/N64, Dillonb/n64-tests, bigbass1997/n64-tests, N64-Cache-Emulation-Tests, n64-asm-timing): they are not used, and nothing of them is built or run. Repositories with an emulator's code in them are not used either.

Building. nemu64-test's own CI builds of that commit (GitHub run 34256763312) can be downloaded until 2026-12-07, and fetch.sh keeps them. After that it builds nemu64-test with its pinned Rust (nightly-2026-07-16 with rust-src) and nust64 0.4.1. snapper64 is its release. The programs made with libdragon need libdragon's toolchain and libdragon (preview f26e1c16145e) in $N64_INST. fetch.sh says what is missing, and installs nothing.

How they report. nemu64-test shows its results on the screen and writes the same text to IS-Viewer 64 (a 512-byte buffer at PI 13FF0020h, and a length register at 13FF0014h that prints it, by its README), to SummerCart64's USB, or to an emulator interface called emux, whichever it finds first. It ends with a line like Done! Tests: 262. Failed: 0. snapper64 waits for a button press, and shows its results in its menu. rsp_inval_instrs and SaveTest-N64 show theirs on the screen, and RDP-Timing-Tests sends numbers over USB.

What n64emu-dev needs

A proposal. The first item is built: n64emu-dev --isviewer (2026-12-01), as described here, for DMA and for the processor's own accesses. It is in no state. The others are not built yet.

  1. --isviewer: IS-Viewer 64 as a device in the cartridge's space: 512 bytes at 13FF0020h that read back what was written (nemu64-test looks for the device before it uses it; that it reads the buffer back is a guess), and a write to 13FF0014h that prints that many bytes of the buffer as lines that start with isviewer . run.sh reads its verdicts from those lines. Off by default: it prints what a program wrote, which n64emu-dev otherwise never does, so it is only for test programs and never for games in a sweep.
  2. emux, later: an interface for emulators that lets a test print, ask for full speed, and end the run with its own result. Its description is a page of n64brew that has not been saved yet.
  3. Buttons by frame, such as --press FRAME:A, so that snapper64 can start.
  4. SummerCart64's registers (optional): the unlock sequence, its identifier, its 8 KiB buffer and its USB command, printed like IS-Viewer text, so that a measurement program takes the same path as on the console. Without them, our programs fall back to IS-Viewer.
  5. N64-CPU-Tests need no ROM: a test of n64-vr4300 that reads $N64_TESTS/n64-cpu-tests, loads each case's code and first state, runs it until it returns to an address of ours, and compares the final state.

Measurement programs on the console

Small programs of ours measure what no document says, on a console with a SummerCart64 flashcart. They are in tools/console/. They never read, save, print or show the PIF's ROM, PIF RAM, IMEM, or anything else of the console maker's. Each source file says so, and names the addresses that it touches. A result is that console's, and nothing is a measurement before it was run there.

Building needs no N64 toolchain: clang and ld.lld 19 (MIPS III, big-endian) and python3.

tools/tests/fetch.sh libdragon-ipl3   # libdragon's prebuilt IPL3 files, into $N64_TESTS
tools/console/build.sh m1             # target/console/m1.z64

The ROM is libdragon's prebuilt production IPL3 (release r10; its md5 sum is the one in libdragon's boot/README.md), then our ELF file at a 256-byte boundary. libdragon's README says that its prebuilt IPL3 files are signed for CIC 6102, that the IPL3 loads the ELF's segments and jumps to it, and that it leaves boot flags in the first 16 bytes of DMEM (the amount of memory, and the ROM, TV, reset and console types). The IPL3 is not in this repository. The build refuses any other IPL3, and a program that uses the FPU by itself (clang 19 did that for 64-bit integers in C).

Starting it on the console. SummerCart64's documentation (commit a1e7996d2cbe): sc64deployer upload ROM puts a ROM into the cart, and its bootloader starts it, with the CIC seed found from the ROM's IPL3. Its state reset sets the CIC to 6102/7101, which fits libdragon's IPL3, and its README says that it switches the region by itself. So no boot program of the flashcart's own is needed beyond that bootloader, which is the cart's default. --direct skips it, so that the console's own boot checks the IPL3: that is for later measurements of what an IPL3 sees at its start. Not known: whether a PAL console (7101) takes libdragon's IPL3 as it is, as the documents that were read speak of 6102 only.

Results come back over USB first. The program unlocks SummerCart64's registers, puts its text in the cart's 8 KiB buffer and gives the USB write command. It sends the same text every two seconds, and shows it on the screen. On the computer, sc64deployer debug prints it, or:

tools/console/receive.py --device /dev/ttyUSB0 --out m1-console.txt   # stops at a complete record
tools/console/decode.py m1-console.txt                                # names and values

receive.py needs only Python's standard library, and reads the cart's packets as its 03_usb_interface.md describes them. It cannot run while sc64deployer has the device open. Without a SummerCart64, the programs write the text to IS-Viewer 64 instead, for emulators.

The record is a list of 32-bit words. Its first word starts with 4E36h, followed by a byte for the program and one for the format (4E360101h is program 1, format 1). Each line has a number, three words and a CRC-8 of them (polynomial 07h), and the last line, FF, has the number of words and a CRC-32 of all of them:

00 4E360101 WWWWWWWW WWWWWWWW CC
01 WWWWWWWW WWWWWWWW WWWWWWWW CC
...
FF 00000022 RRRRRRRR 00000000 CC

Without USB, a photo of the screen works too: the screen shows only these lines, in a font of our own whose 0, 8, B and D look different, inside the part of the picture that a TV shows. Type the lines into a file, and decode.py says which line has a wrong checksum, so that only that line is read again.

Program 1 (m1): PRId, FCR0, MI_VERSION and libdragon's boot flags, which name the console and its TV type. Then the time of one load, in Count ticks, at three phases (0, 1 or 2 NOPs after Count is read): from the data cache, after the line is put out of the cache, and uncached. Each case runs 64 times, with interrupts off, and the least, the most and the sum are kept. A hit's time is the baseline to subtract. It ran on a console with a SummerCart64 on 2026-12-01: the record came over USB, and every copy and checksum agreed. Its record is tools/console/records/m1-2026-12-01.txt, and program 2's is m2-2026-12-01.txt beside it.

Program 2 (m2) measures what we most wanted to know first, in groups. Its record is sent again after each group, so a group that never ends still leaves the ones before it, and decode.py says where a record stops. The groups that cannot hang run first, with the VI off so that it does not compete for RDRAM, and every wait in them has a time limit:

GroupWhat
0PRId, FCR0, MI_VERSION, libdragon's boot flags, Status, and a check of our exception handler with one SYSCALL
1CACHE Index_Write_Back_Invalidate, Hit_Write_Back_Invalidate, Hit_Write_Back and Hit_Invalidate on clean and dirty lines, after memory was changed uncached: is the line written back?
3SB, SH, LB and LH at each offset of VI_ORIGIN, with the VI off. Its bits 23-0 read back what was written, and with VI_CTRL's type 0 nothing uses it
5SP DMA of 8, 128 and 4096 bytes into DMEM, and PI DMA of 128 and 512 bytes from the cartridge, until each one's busy bits clear, with the PI's settings that the boot left
6The AI playing silence at DACRATE 1103 and 599, each with two lengths. decode.py works out whether a sample lasts DACRATE + 1 or DACRATE clocks of the VI from the ratio of the times, without either clock's rate
7Count read 0 to 7 NOPs after a write of 0, and Cause's IP7 when Count is written equal to Compare, one below it and one above it, after a write of 0 to Cause, and after Compare is written again

The groups that could hang the console come last, after the screen is on:

GroupWhatWhy it could hang
217 floating point cases: infinities and signalling NaNs converted between S and D, 0/0 and sqrt(-1) (the default NaN), quiet NaNs in ABS and NEG, C.EQ.S with a signalling NaN, a denormal number divided by 0, -2^53 to L, a denormal result with FS, and 1/0 as a control. Each case has its result's bits, FCR31, and the exceptions that it tookthe unimplemented operation exception cannot be turned off, so our own handler at 80000180h counts each exception and goes on after the instruction
4The ninth bits, read in MI's EBus mode: one byte with bit 7 set at each of 8 offsets (which bit is which byte's), then bytes 7Fh and 80h written as 8, 16, 32 and 64 bits and as a cache line, and by a PI DMA and an SP DMAthe mode changes every access of the processor to RDRAM. The reading sequence is put into the instruction cache first, and waits until MI_MODE shows that the mode is off again
8One SD and one LD on VI_X_SCALE and VI_Y_SCALE64-bit accesses to RCP registers are not described

The screen shows the record 16 lines at a time, and the next 16 every four seconds.

What the owner installs

Nothing is installed without the owner's word. Each step says what it allows and how it is undone.

  1. sc64deployer (GPL-3.0), from SummerCart64's release v2.20.2: unpack sc64-deployer-linux-v2.20.2.tar.gz into a folder of its own. It is not installed anywhere. Its documentation says that it refuses firmware that it does not support: ./sc64deployer list shows whether it finds the cart. Undo: delete the folder.
  2. Access to the cart's serial device. SummerCart64's build guide says that on Linux it is /dev/ttyUSBx, with the ftdi_sio and usbserial modules. Either sudo usermod -aG dialout USER and a new login, which allows every serial device (undo: sudo gpasswd -d USER dialout), or a udev rule for this device only, with the vendor and product that lsusb shows for it (undo: delete the rule and run sudo udevadm control --reload).
  3. Optional, for the tests made with libdragon: libdragon's toolchain, as its wiki's "Installing libdragon" says: sudo dpkg -i gcc-toolchain-mips64-x86_64.deb from its toolchain-continuous-prerelease release (it installs into /opt/libdragon and sets N64_INST in /etc/profile.d), then libdragon at preview f26e1c16145e with its ./build.sh. Undo: sudo dpkg -r with the package's name (dpkg-deb -f FILE Package), and remove /opt/libdragon.
  4. Optional, to build nemu64-test after 2026-12-07: rustup toolchain install nightly-2026-07-16 --profile minimal --component rust-src --component rustfmt and cargo +stable install nust64 --version 0.4.1 --locked. Undo: rustup toolchain uninstall nightly-2026-07-16 and cargo uninstall nust64.

From commit 9ba9172cfa64. Edit this page