The VI and the RDP's command interface
The VI makes the picture's signal from a frame buffer in RDRAM. The RDP draws into such buffers, from commands that it fetches through its
command interface (the DPC). n64emu's core has the registers, the time and the fetching of commands. What the VI's filters and the RDP do
to the dots is the RDP's crate, which is a port. Code: crates/n64emu-core/src/vi.rs and dpc.rs.
The VI
Source: n64brew's Video Interface page.
How it works on the console
The VI makes the television's signal from a frame buffer in RDRAM. The game tells it where the buffer starts (VI_ORIGIN), how wide it
is (VI_WIDTH), and whether its dots are 16 bits (5 bits each of red, green and blue, and one of coverage, with two more in the ninth bits)
or 32 bits (VI_CTRL's type). The same registers make NTSC, PAL and MPAL: how long a line is (H_TOTAL), how many half lines a field has
(V_TOTAL), and where the picture is in them (H_VIDEO, V_VIDEO).
- It scales. X_SCALE and Y_SCALE say how far it moves in the buffer for each dot and line of the signal, so a buffer of 320 dots can
fill the width of a television.
- It filters, as VI_CTRL says: it smooths the edges of shapes with the coverage that the RDP wrote (antialiasing), takes the middle of
three neighbours at those edges (the divot filter), can undo the RDP's dithering of a 16-bit buffer, and has a gamma curve for the
television, with a little noise against bands.
- Interlacing: with an odd number of half lines and serration on, the two fields of a frame are half a line apart, so that a game can
show twice as many lines.
- It interrupts the processor when the line in VI_V_INTR begins, and VI_V_CURRENT says which line it is on.
- Its output goes to a video DAC on the board, 28 bits multiplexed four ways over a bus of 7 bits, at about 12.3 million dots a second
(the page).
In n64emu, the lines, fields, interrupts and time are the core's (below). The scaling and the filters are the RDP's crate, which is
a port (the picture).
Its clock
The page says how many of the VI's clocks the colour carrier of the television's standard has: 13.6 for NTSC and MPAL, 11.2 for PAL.
The carriers' frequencies are television standards and not facts about this console. They are from what an agent knew from its training, and were not
compared with the standards: 315/88 MHz, 4.43361875 MHz and 3.57561149 MHz. So the VI's clock is 48.68 MHz, 49.66 MHz and 48.63 MHz. Each is a
fraction of whole numbers of the console's ticks, with the remainder kept, so no time is lost.
Lines and fields
- A line has H_TOTAL + 1 clocks. The second line of a field has the leap's length when that is longer, with the leap pattern from its lowest
bit (both guesses: the page says "the second scanline of vsync", and nothing of the bit order). A line is never shorter than 256 clocks, a limit of ours.
- A field has (V_TOTAL + 1) half lines. When that is odd, fields alternate: the even one has a line more, and VI_V_CURRENT's lowest bit is the
field. This is the page's description, also for which values are counted.
- The interrupt comes as the line of VI_V_INTR begins. With fields of half lines and the lowest bit 0, it comes one line earlier in the odd
field, also on the even one's last line for 0, as the page describes. Writing VI_V_CURRENT clears it.
- While the VI is off, there are lines but no line counter or interrupt (the page: no signal). The memory is refreshed at each line, which the
page says for the length of lines before the VI is set up. That it is so while the VI is off is a guess.
- A change to H_TOTAL or V_TOTAL counts from the next line, which is a guess. VI_V_VIDEO counts from the next field, as the page says.
Frames and pictures
A frame of the core is one field, and it ends where the picture ends: as the line of VI_V_VIDEO's end begins, or with the field if that is
not in it. So the game's work after that, in its vertical blank, is in the next frame, with the newer buttons.
- Each frame ends after a bounded time. While the VI is off, a frame is as long as the region's usual field. With the VI on, it is never longer
than 50 ms of the console's time, and a field shorter than 5 ms does not end a frame. Both limits are ours, so that each call of
run_frame
returns. The longest field that the registers allow has 43 ms.
- The picture is made when it is asked for, and changes nothing, so frames without one leave the same state. It is one field, with its own
rows, and depends on nothing but RDRAM, the registers and the number of the field.
Weaver puts two together for an app, outside of the console.
- The RDP's crate gets the registers for the whole field. It has no registers that change by line. VI_V_VIDEO is as it was when the field
began, as the page says. All others are as they are when the picture ends, which is a guess. So a game that changes a register in the middle
of a field, such as VI_ORIGIN for a split screen, is shown with the last value for all of it. The page says that some can be changed in a
horizontal blank.
- When the VI shows nothing, the picture is black: 640 by 240 dots, or 640 by 288 on PAL.
What the VI reads
For the memory's model, the VI reads each line that it shows, as many bytes as are shown, scaled. How many more lines its filters read is not
known, so it is one. See Memory and the bus.
The RDP's command interface
Sources: n64brew's Reality Display Processor/Interface for the registers, and Appendix A of US patent 6,331,856 (which the owner allowed)
for the formats of the few commands that the model of time looks at. The patent's text also names the bits of the status register.
Registers
DPC_START, DPC_END, DPC_CURRENT, DPC_STATUS and the four counters, at 04100000 and as the RSP's COP0 registers 8 to 15. They repeat every 32 bytes.
- Writing DPC_START makes a transfer wait, and writing DPC_END starts it, or continues the one that runs or ran, when none waits. While one
runs, the one that waits begins after it. Its registers show the waiting one, and DPC_CURRENT the running one (the page).
- A transfer whose end is before where it is does nothing, a guess.
- FREEZE stops fetching and starting commands. A command that started goes on (a guess). FLUSH ends the transfer and the one that
waits. What is in the buffer stays (a guess).
- The counters: DPC_CLOCK counts the RCP's cycles from when it was cleared. The others count the cycles in which commands run, the pipeline is
busy (from the first fetch to a full sync), and textures are loaded. Each can be cleared.
- In DPC_STATUS, the meaning of DMA_BUSY, CBUF_READY and GCLK is not on the page. Here they are a transfer that has something left, room in the
buffer, and the same as PIPE_BUSY, all guesses.
How commands are fetched and run
- Commands are fetched in batches of up to 16 words into a buffer of 128 words, both guesses (
COMMAND_BATCH, COMMAND_BUFFER). A batch comes from
RDRAM through the memory's model, or from DMEM at 8 bytes a cycle (a guess).
- Commands from DMEM are copied when DPC_END is written, as the RSP's crate gives DMEM as it is then. What the RSP writes later does not change
them, which is a guess. A program that looks at DPC_CURRENT before it uses that memory again does not depend on it.
- A command starts when all its words are in the buffer and the one before is done. Its length comes from the RDP's crate.
- How long it takes is a model of ours, and no measurement: a cycle for each word, a dot a cycle in the RDP's one-cycle mode, two in its
two-cycle mode, and four dots a cycle when it fills or copies, with 4 cycles for each line. Shapes are cut off at the scissor box. A full sync
takes 64 cycles more. Loads count 16 bits for each texel. All of these are in
timing.rs.
- What a command does can be seen from its start on, a guess, as the dots are written in its time on the console.
- A full sync sets the DP interrupt when it is done, at a time that only this model decides. It never depends on the GPU.
Nothing here runs until something could tell. The interface is run up to the time before any use of RDRAM or its channel, before its
registers are read or written, and before the RSP reads them. Only a full sync is an event, and it is found ahead: if no full sync is in the
buffer, none can be done before all commands that are there now.
The GPU
The RDP's crate does the work on a GPU, whenever it can. So before anything reads what the commands since the last finish could write, or
writes what they could use, the core calls finish. Every access to RDRAM goes through one place (memory.rs), so this cannot be forgotten.
A test runs the same random programs with a GPU that does each command at once and with one that does nothing until finish, and the states are the same.
Sources
| Page or document | What was used | What was not, and why |
| n64brew, Video Interface | all registers, lines, fields, interrupts, the leap, what is latched | the values that it gives for high resolution, which it "learnt from Factor 5 games", a game's code, so not used. Libultra's and libdragon's choice of V_INTR is only an example there |
| n64brew, Reality Display Processor/Interface | the registers, transfers, FREEZE, FLUSH, counters, the warning about full syncs | |
| n64brew, Reality Display Processor/Commands, Pipeline, Hazards | not opened | not needed. Lengths of commands come from the RDP's crate |
| US 6,331,856, Appendix A | the formats of triangles, rectangles, loads, the scissor box, other modes and the full sync | |
| US 6,331,856, its text | what the bits of the status register are about | |
What we need and could not find: how long the RDP takes for anything, how many lines the VI reads, its fetches' times, and how long a
command waits in the buffer.