emuforge

The hardware

This page is the whole Nintendo 64 at a glance. Each page after it says how one part of the real console works, how n64emu emulates it, where its facts are from, and what is missing or a guess. To see how all parts run together in n64emu, start with the architecture. The facts here are from NEC's manual of the VR4300 and from n64brew.dev's pages, which each page names.

The console

The Nintendo 64 has two large chips and a few small ones:

PartWhat it isIts clockPage
The VR4300NEC's 64-bit MIPS processor (MIPS III), with a floating point unit, caches of 16 KB for instructions and 8 KB for data, a TLB of 32 entries and a timer. It runs the game93.75 MHzthe processor, floating point
The RCPthe Reality Co-Processor: everything else of the console's logic, in one chip. The processor reaches all memory and devices through it62.5 MHzbelow
the RSP, in the RCPa second processor for the game's own small programs (microcode), with 4 KB for its program (IMEM), 4 KB for data (DMEM), and a vector unit of eight lanes of 16 bitsthe RCP'sthe RSP
the RDP, in the RCPdraws triangles and rectangles into RDRAM, with textures from its own 4 KB (TMEM)the RCP'sthe RDP, its command interface
the MI, RI, VI, AI, PI and SI, in the RCPthe interfaces: interrupts and modes of the memory (MI), RDRAM (RI), the picture (VI), sound (AI), the cartridge's bus (PI) and the serial bus to the PIF (SI)the RCP'smemory and the bus, the VI, PI, SI and AI
RDRAMthe only main memory: 4 MB in two chips, or 8 MB with the Expansion Pak. Each byte has a ninth bit, which the RDP and the VI use for coverage at the edges of shapesits ownmemory and the bus
The PIFa small chip with its own program and 64 bytes of RAM. It starts the console, talks to the controllers over the joybus, and checks the cartridge's security chipcontrollers and the PIF
The cartridgethe game's ROM on the parallel bus, often with SRAM or FlashRAM for saves, or with EEPROM and a clock on the joybus, and a security chip (CIC)cartridges, the security chip
Controllersa stick and 14 buttons, the D-pad's four among them, with a slot for a pak: the Controller Pak keeps saves, and the Rumble Pak shakescontrollers and the PIF

How they are joined:

   the VR4300 (93.75 MHz) ── SysAD ──┐
                                     │
   ┌─────────────────────── the RCP (62.5 MHz) ────────────────────────┐
   │  the RSP (IMEM, DMEM) ──commands──► the RDP (TMEM)                │
   │      │ DMA                             │ draws                    │
   │  MI   RI ─────────── RDRAM, 4 or 8 MB with ninth bits ────────────┤
   │  VI ── reads a frame buffer, filters it ──► the video DAC ──► TV  │
   │  AI ── reads samples ──────────────────────► the audio DAC        │
   │  PI ── the parallel bus ──► the cartridge: ROM, SRAM, FlashRAM    │
   │  SI ── the serial bus ───► the PIF ── joybus ──► 4 controllers    │
   │                                       └───────► EEPROM, clock     │
   └───────────────────────────────────────────────────────────────────┘
  • Everything goes through RDRAM. The processor, the RSP's DMA, the RDP, the VI, the AI, the PI and the SI all read and write the same memory, one at a time, so they wait for each other there (who gets the memory).
  • The processor sees every part as memory, at fixed physical addresses (the map). Its own TLB and segments put them where a program wants them.
  • Each interface raises one interrupt in the MI, and the MI's one line goes to the processor (the MI).

A frame, step by step

What a typical game does for each picture, as n64brew's pages of the VR4300, the RSP's and the RDP's interfaces and the AI describe it:

  1. The processor runs the game: it reads the controllers through the SI and the PIF, and writes lists of what to draw and of sound to make, in RDRAM.
  2. It starts the RSP: a DMA brings a microcode into IMEM and its data into DMEM, and the processor clears the RSP's halt bit.
  3. The RSP turns the lists into commands for the RDP: it transforms and lights the points of the shapes with its vector unit, and gives the commands to the RDP through its command interface, from DMEM or from RDRAM. Most games make their sound with another microcode, which mixes the samples into a buffer in RDRAM.
  4. The RDP loads textures into TMEM, and draws each shape into a frame buffer in RDRAM, with its depth and coverage. A full sync tells the processor that it is done.
  5. The VI reads the frame buffer that the game points it to, line by line, scales it, smooths the edges with the coverage in the ninth bits, and sends it to the television. Its interrupt comes at a line that the game chooses, so that the game knows where the picture is.
  6. The AI plays the sound buffer while the next one is made. Its interrupt comes when a buffer begins, so that the game can give it the next one in time.

In n64emu each of these parts runs only when something could see it, in one order of time (architecture).

How a game starts

  1. The console's own boot program, from the PIF's ROM, runs on the processor, and copies the cartridge's boot code (IPL3, 4 KB from the ROM's start) into DMEM.
  2. The security chip gives the PIF a seed. The boot code checks the game's first megabyte with it, sets up RDRAM, copies the game to it, and jumps there.
  3. The game tells the PIF that its boot has ended within about 5 seconds, or the PIF stops it.

n64emu has none of the console maker's programs. It starts at the state in which the PIF's program would leave the boot code, finds the seed by trying each one with the game's own boot code, and for the games with the 6105 chip does what their boot code would leave itself (starting a game).

The pages

PageWhat is in it
The processorthe VR4300's pipeline, caches, TLB, exceptions and times. A store and a long division, step by step
Floating point arithmeticwhat the floating point unit gives, NaNs, rounding, and what was measured on a console
Memory and the busthe map, how the RCP takes each size of access, RDRAM's chips and how long they take, the ninth bits, and the MI
The RSPthe second processor, which is a port: its memories, its registers, a DMA step by step, and its recompiler
The RDP and the VI's filtersdrawing on Vulkan, which is a port, the picture, the render scale, and pictures shared with the window
The VI and the RDP's command interfacethe picture's signal: lines, fields and frames, and how commands reach the RDP
PI, SI and AIthe cartridge's bus with its DMA, the serial bus, and sound. A DMA from the cartridge step by step
Cartridgesfile formats, the header, ROM, SRAM and FlashRAM, and how the kind of save is found
Controllers and the PIFthe joybus and its devices, paks, EEPROM, the clock, the security chips, and how a game starts

The scheduler is about n64emu and not the console: who runs when, and how long each call into a part runs. Status has the state of each part.

From commit 9ba9172cfa64. Edit this page