3D Geometry Engine
The Geometry Engine on the Nintendo DS is the hardware responsible for taking in 3D Graphics Commands and coverting them to verticies and polygons which can be rendered by the Rendering Engine. It’s jobs include performing various matrix multiplications involving vertex positions, vertex colors, light vectors, etc.
Readable Matricies
The Geometry provides access to the final directional matrix and screen space transformation matrix. (as in, position matricies * projection matrix) Reading these requires the geometry engine to be disabled via bit 27 in the GXSTAT
register.
Clip Matrix (0x4000640..=0x400067F, 16 words, R)
Read the 4x4 “Clip matrix” with cells going from row 0 column 0, row by row.
Read Directional Matrix (0x4000680..=0x40006A3, 9 words, R)
Read the “top left” 3x3 segment of the directional matrix with cells going from row 0 column 0, row by row.
3D Command FIFO
The Geometry engine is heavily based upon a Command FIFO and PIPE used to transfer vertex lists, bind textures, set viewport, modify matricies, etc. The FIFO can be directly accessed by writing command numbers and parameters to memory location 0x4000400
or indirectly by writing parameters to the corresponding “Command Ports” at various memory locations from0x4000440..=0x40005FF
.
Using the FIFO indirectly
The simpler and more user friendly method of interacting with the FIFO is via the “Command Ports”, where parameters are written to the corresponding memory address for a given command. The command + parameter combo is automatically sent down the FIFO to the 3D hardware once every parameter has been sent. For commands that don’t have any parameters one may simply write any value to the port.
Using the FIFO directly
When using the FIFO directly, commands are sent by first writing a “Command word” containing up to 4 packed command indicies. Followed by writing the parameters for each command in order. If the last command does not have a parameter, 0 must be written as a dummy parameter in order for the hardware to accept a new “command word”. When trying to specify invalid command indicies they will be treated the same as command index 0. (no command, no parameters) This way of using the fifo is better suited to transferring large chunks of commands, such as via DMA.
“Command word” definition
Bit(s) | Description |
---|---|
0-7 | Command Index 0 |
8-15 | Command Index 1 |
16-23 | Command Index 2 |
24-31 | Command Index 3 |
Notes:
When packing multiple commands you may not leave zeroed indicies (indicating no command) in between non-zeroed indicies. Meaning that when sending one command the top 24 bits must be zero, when sending 2 commands the top 16 bits must be zero, and when sending 3 commands the top 8 bits must be zero.