User Tools

Site Tools


super_mario_64:fast3d_display_list_commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
super_mario_64:fast3d_display_list_commands [2018/05/07 01:25]
trenavix [01: G_MTX]
super_mario_64:fast3d_display_list_commands [2022/05/31 02:34] (current)
David [B2: G_RDPHALF_CONT]
Line 1: Line 1:
 ====== Fast3D Display List Commands ====== ====== Fast3D Display List Commands ======
-The Fast3D display list commands are microcode that are passed to the RSP for rendering.  ​The are all 8 bytes long.+The Fast3D display list commands are microcode that are passed to the RSP for rendering.  ​They are all 8 bytes long.
  
 ===== Fast3D Commands ===== ===== Fast3D Commands =====
Line 29: Line 29:
 Takes a block of memory from an address and puts it in the location pointed to by an index and an offset. Takes a block of memory from an address and puts it in the location pointed to by an index and an offset.
  
-''​03 ​[<color #​ff1010>​nn</​color>​] ​[<color #ff7f27>oo</​color>​] [<color #00a2e8>ii</​color>​] [<color #​A946F2>​aa aa aa aa</​color>​]''​+''​03 [<color #ff7f27>ii</​color>​] [<color #ff1010>nnnn</​color>​] [<color #​A946F2>​aa aa aa aa</​color>​]''​
  
-| <color #ff1010>n</​color>​ | (((//Size in bytes of memory to be moved//) >> 3)+1)*8 ​+| <color #ff7f27>i</​color>​ | Index into table of DMEM addresses ​
-| <color #ff7f27>o</​color>​ | Offset from indexed base address (*8) | +| <color #ff1010>n</​color>​ | Size in bytes of memory to be moved |
-| <color #​00a2e8>​i</​color>​ | Index into table of DMEM addresses ​|+
 | <color #​A946F2>​a</​color>​ | Segmented address of memory | | <color #​A946F2>​a</​color>​ | Segmented address of memory |
  
-<color #00a2e8>​**i**</​color>​ is an index into a table of addresses of DMEM. Given enumerations for <color #00a2e8>​**i**</​color>​ are: +<color #ff7f27>​**i**</​color>​ is an index into a table of addresses of DMEM. Given enumerations for <color #ff7f27>​**i**</​color>​ are:
-  * <color #​22b14c>​G_MV_MMTX</​color>​ = 2 +
-  * <color #​22b14c>​G_MV_PMTX</​color>​ = 6 +
-  * <color #​22b14c>​G_MV_VIEWPORT</​color>​ = 8 +
-  * <color #​22b14c>​G_MV_LIGHT</​color>​ = 10 +
-  * <color #​22b14c>​G_MV_POINT</​color>​ = 12 +
-  * <color #​22b14c>​G_MV_MATRIX</​color>​ = 14+
  
-Note however that only <color #22b14c>VIEWPORT</​color>​<color #22b14c>LIGHT</​color>​, and <color #22b14c>MATRIX</​color> ​are used by any of the macros given to programmers.+  * <color #22b14c>G_MV_VIEWPORT</​color> ​= 0x80 
 +  * <color #22b14c>G_MV_LOOKATY</​color> ​= 0x82 
 +  * <color #22b14c>G_MV_LOOKATX</​color> ​= 0x84 
 +  * <color #​22b14c>​G_MV_L0</​color>​ = 0x86 
 +  * <color #​22b14c>​G_MV_L1</​color>​ = 0x88 
 +  * <color #​22b14c>​G_MV_L2</​color>​ = 0x8a 
 +  * <color #​22b14c>​G_MV_L3</​color>​ = 0x8c 
 +  * <color #​22b14c>​G_MV_L4</​color>​ = 0x8e 
 +  * <color #​22b14c>​G_MV_L5</​color>​ = 0x90 
 +  * <color #​22b14c>​G_MV_L6</​color>​ = 0x92 
 +  * <color #​22b14c>​G_MV_L7</​color>​ = 0x94 
 +  * <color #​22b14c>​G_MV_TXTATT</​color>​ = 0x96
  
-Note: In Super Mario 64, this is mainly used to load vector lighting ambient/​diffuse RGBA values.\\  +Note: <color #​22b14c>​G_MV_TXTATT</​color>​ is not used by any of the macros given to programmers. 
-Example: Loads diffuse RGBA from 0x0 in Segment 0x0E; loads ambient ​RGBA from 0x08 in Segment 0x0E + 
-  03 86 00 10 0E 00 00 00 +In Super Mario 64, this is mainly used to load vector lighting ambient/​diffuse RGBA values. 
-  03 88 00 10 0E 00 00 08+  
 +The ambient ​light is loaded using G_MV_L1 (0x88), and the segment address points to 8 bytes defining the ambient color RGB value. 
 + 
 +  03 88 00 10 0E 00 00 00 // This loads the ambient light from segment address 0x0E000000. 
 +   
 +  At address 0x0E000000:​ 
 +  FF FF FF 00 FF FF FF 00 // Sets the ambient color to be white. The zeroes here don't matter. 
 +   
 +  Note 1: The last 4 bytes should match the first 4 since it is a copy of the RGB color. 
 +  Note 2: The 4th and 8th bytes are just padding; they don't represent the alpha value. 
 + 
 +The diffuse light is loaded using G_MV_L0 (0x86), and the segment address points to 16 bytes defining the color RGB value and normalized direction that the light is coming from. 
 + 
 +  03 86 00 10 0E 00 00 08 // This loads the diffuse light from segment address 0x0E000008. 
 +   
 +  At address 0x0E000008:​ 
 +  7F 7F 7F 00 7F 7F 7F 00 // Sets the diffuse light color to be gray. 
 +  28 28 28 00 00 00 00 00 // SM64 usually sets the normalized direction as (0x28, 0x28, 0x28) 
 +   
 +  Note: All the zeroes here are for padding, since diffuse lights are 16-byte aligned. 
 + 
 +The normalized direction is calculated using the following formula: 
 +  First calculate variable '​d'​ as: d = 127/​square_root(x*x + y*y + z*z) 
 +  Then the normalized direction is: Xn = x*d; Yn = y*d; Zn = z*d 
 +   
 +  Note: Xn, Yn, and Zn should be signed bytes.
  
 ---- ----
Line 80: Line 109:
  
 ---- ----
 +==== B2: G_RDPHALF_CONT ====
 +Acts as an indicator that the command continues with the given lower word. This is used only when operators longer than 64bits are in use.
  
 +Note: When this command gets executed, it will immediately send all the previous data (from RDPHALF_1 and/or RDPHALF_2) to the RDP.
 +
 +''​B2 00 00 00 [<color #​ff7f27>​CC CC CC CC</​color>​]''​
 +
 +| <color #​ff7f27>​C</​color>​ | Continued value of lower word. |
 +
 +----
 ==== B3: G_RDPHALF_2 ==== ==== B3: G_RDPHALF_2 ====
 This opcode sets the low half of the generic RDP word. This opcode sets the low half of the generic RDP word.
Line 94: Line 132:
 This opcode sets the higher half of the generic RDP word. This opcode sets the higher half of the generic RDP word.
  
-''​E1 00 00 00 [<color #​22b14c>​hh hh hh hh</​color>​]''​+''​B4 00 00 00 [<color #​22b14c>​hh hh hh hh</​color>​]''​
  
 | <color #​22b14c>​h</​color>​ | New value of high word | | <color #​22b14c>​h</​color>​ | New value of high word |
Line 100: Line 138:
 **Note:** the referenced function also generates opcode B3. See the section on B3 for info on that. **Note:** the referenced function also generates opcode B3. See the section on B3 for info on that.
  
----- 
-==== B5: G_QUAD ==== 
-Renders one quad according to the vertices inside the vertex buffer 
- 
-''​B5 [<color darkred>​AA</​color>​] [<color darkgreen>​BB</​color>​] [<color darkblue>​CC</​color>​] 00 [<color red>​DD</​color>​] [<color green>​EE</​color>​] [<color blue>​FF</​color>​]''​ 
- 
-| <color darkred>​A</​color>​ | First vertex to use for the quad (* 0x0A) | 
-| <color darkgreen>​B</​color>​ | Second vertex to use for the quad (* 0x0A) | 
-| <color darkblue>​C</​color>​ | Third vertex to use for the quad (* 0x0A) | 
-| <color red>​D</​color>​ | Fourth vertex to use for the quad (* 0x0A) | 
-| <color green>​E</​color>​ | Fifth vertex to use for the quad (* 0x0A) | 
-| <color blue>​F</​color>​ | Sixth vertex to use for the quad (* 0x0A) | 
- 
-Example: Render a quad using the vertex data specified at the vertex buffer positions 0, 1 (0x0A / 0x0A), 2 (0x14 / 0x0A), 0, 2 (0x14 / 0x0A) and 3 (0x1E / 0x0A). 
-  B5 00 0A 14 00 00 14 1E 
- 
-Note: This has been proven to not be functional in F3D 1.0 (ie SM64), so avoid usage. Treated as NOP on angrylion'​s and real hardware. May only be functional on F3DEX and F3DEX2. 
 ---- ----
  
Line 246: Line 267:
 Loads a new 32-bit value data to the location specified by index and offset. Loads a new 32-bit value data to the location specified by index and offset.
  
-''​DB <color #00a2e8>ii</​color>​ <color #22b14c>oo oo</​color>​ <color #​A946F2>​dd dd dd dd</​color>''​ +''​BC <color #22b14c>oo oo</​color>​ <color #00a2e8>ii</​color>​ <color #​A946F2>​dd dd dd dd</​color>''​ 
-| <color #00a2e8>i</​color>​ | Index into DMEM pointer table(?​) ​+| <color #22b14c>o</​color>​ | Offset from the indexed base address ​
-| <color #22b14c>o</​color>​ | Offset from the indexed base address(?​) ​|+| <color #00a2e8>i</​color>​ | Index into DMEM pointer table |
 | <color #​A946F2>​d</​color>​ | New 32-bit value | | <color #​A946F2>​d</​color>​ | New 32-bit value |
  
Line 266: Line 287:
  
 ==== BD: G_POPMTX ==== ==== BD: G_POPMTX ====
-Pops num matrices ​from the stack specified by modelview matrix ​stack.+Pops a matrix ​from the stack.
  
-''​D8380002 <color #​00a2e8>​aaaaaaaa</​color>​''​ +''​BD000000 00 00 00 00''​
- +
-| <color #​00a2e8>​a</​color>​ | The number of matrices to pop |+
  
 +Removes the top matrix from the matrix stack in dmem
 ---- ----
  
Line 311: Line 331:
  
 ''​E4 [<color darkred>​xx x</​color>​][<​color darkgreen>​y yy</​color>​] 0[<color darkblue>​I</​color>​] [<color red>XX X</​color>​][<​color green>Y YY</​color>​]''​\\ ''​E4 [<color darkred>​xx x</​color>​][<​color darkgreen>​y yy</​color>​] 0[<color darkblue>​I</​color>​] [<color red>XX X</​color>​][<​color green>Y YY</​color>​]''​\\
-''​B3 00 00 00 [<color #​BF9F00>​SS SS</​color>​] [<color #​8F3F10>​TT TT</​color>​]''​\\ +''​B3 00 00 00 [<color #​BF9F00>​SS SS</​color>​] [<color #​8F3F10>​TT TT</​color>​]'' ​(RDPHalf_2)\\ 
-''​B2 00 00 00 [<color #​3F3FFF>​DD DD</​color>​] [<color darkcyan>​EE EE</​color>​]''​+''​B2 00 00 00 [<color #​3F3FFF>​DD DD</​color>​] [<color darkcyan>​EE EE</​color>​]'' ​(RDPHalf_Cont)
  
 | <color darkred>​xxx</​color>​ | Lower-right corner X coordinate | | <color darkred>​xxx</​color>​ | Lower-right corner X coordinate |
Line 330: Line 350:
  
 ''​E5 [<color darkred>​xx x</​color>​][<​color darkgreen>​y yy</​color>​] 0[<color darkblue>​I</​color>​] [<color red>XX X</​color>​][<​color green>Y YY</​color>​]''​\\ ''​E5 [<color darkred>​xx x</​color>​][<​color darkgreen>​y yy</​color>​] 0[<color darkblue>​I</​color>​] [<color red>XX X</​color>​][<​color green>Y YY</​color>​]''​\\
-''​B3 00 00 00 [<color #​BF9F00>​SS SS</​color>​] [<color #​8F3F10>​TT TT</​color>​]''​\\ +''​B3 00 00 00 [<color #​BF9F00>​SS SS</​color>​] [<color #​8F3F10>​TT TT</​color>​]'' ​(RDPHalf_2)\\ 
-''​B2 00 00 00 [<color #​3F3FFF>​DD DD</​color>​] [<color darkcyan>​EE EE</​color>​]''​+''​B2 00 00 00 [<color #​3F3FFF>​DD DD</​color>​] [<color darkcyan>​EE EE</​color>​]'' ​(RDPHalf_Cont)
  
 | <color darkred>​xxx</​color>​ | Lower-right corner X coordinate | | <color darkred>​xxx</​color>​ | Lower-right corner X coordinate |
Line 423: Line 443:
  
 All of the parameters are signed 9-bit numbers, with range -256 ≤ k ≤ 255. All of the parameters are signed 9-bit numbers, with range -256 ≤ k ≤ 255.
 +
 +----
 +
 +Conceptually the equations for converting from YUV to RGB are:
 +| <color #​ff3333>​R</​color>​ | C0 * (Y - 16) + C1 * V |
 +| <color #​33ff33>​G</​color>​ | C0 * (Y - 16) - C2 * U - C3 * V |
 +| <color #​3333ff>​B</​color>​ | C0 * (Y - 16) + C4 * U |
 +
 +The K terms in G_SETCONVERT come from these C terms.
 +| **K0** | C1 / C0 |
 +| **K1** | C2 / C0 |
 +| **K2** | C3 / C0 |
 +| **K3** | C4 / C0 |
 +| **K4** | 16 + 16 / (C0 - 1.0) |
 +| **K5** | C0 - 1.0 |
 +
 +In the hardware, the color conversion is done in two stages. In the texture filter (TF), the following equation is performed:
 +| R’ | Y + **K0** * V |
 +| G’ | Y + **K1** * U + **K2** * V |
 +| B’ | Y + **K3** * U |
 +
 +In the color combiner, the following equations are performed to get the RGB color:
 +| <color #​ff3333>​R</​color>​ | (R’ - **K4**) * **K5** + R’ |
 +| <color #​33ff33>​G</​color>​ | (G’ - **K4**) * **K5** + G’ |
 +| <color #​3333ff>​B</​color>​ | (B’ - **K4**) * **K5** + B’ |
 +
 +Typical Values for YUV to RGB conversion:
 +  K0 = 175
 +  K1 = -43
 +  K2 = -89
 +  K3 = 222
 +  K4 = 114
 +  K5 = 42
 +
 +
 ---- ----
  
Line 428: Line 483:
 Sets the scissoring rectangle. Sets the scissoring rectangle.
  
-''​ED [<color #​00a2e8>​xx x</​color>​][<​color #​22b14c>​y yy</​color>​] [<color #​ff7f27>​m</​color>​][<color #​ed1c24>​vv v</​color>​][<​color #​B755FF>​w ww</​color>​]''​+''​ED [<color #​00a2e8>​xx x</​color>​][<​color #​22b14c>​y yy</​color>​] ​0[<color #​ff7f27>​m</​color>​] [<color #​ed1c24>​vv v</​color>​][<​color #​B755FF>​w ww</​color>​]''​
  
 | <color #​00a2e8>​x</​color>​ | Upper-left X coordinate of rectangle | | <color #​00a2e8>​x</​color>​ | Upper-left X coordinate of rectangle |
Line 484: Line 539:
 Sets the texture coordinates and size Sets the texture coordinates and size
  
-''​F2 ​00 00 00 00 [<color darkred>​WW W</​color>​][<​color ​darkgreen>H HH</​color>​]''​+''​F2 [<color darkred>SS S</​color>​][<​color darkgreen>​T TT</​color>​] 0[<color #​00a2e8>​I</​color>​] [<color purple>WW W</​color>​][<​color ​darkcyan>H HH</​color>​]''​
  
 +| <color darkred>​SSS</​color>​ | Upper-left corner of texture to load, S-axis |
 +| <color darkgreen>​TTT</​color>​ | Upper-left corner of texture to load, T-axis |
 +| <color #​00a2e8>​I</​color>​ | Tile descriptor to load into |
 | <color darkred>​W</​color>​ | (width - 1) << 2 | | <color darkred>​W</​color>​ | (width - 1) << 2 |
-| <color darkgreen>​H</​color>​ | (hieght ​- 1) << 2 |+| <color darkgreen>​H</​color>​ | (height ​- 1) << 2 |
  
 Examples: Examples:
Line 558: Line 616:
 | <color #​3F3FFF>​pppp</​color>​ | Which palette to use for colors (if relevant) | | <color #​3F3FFF>​pppp</​color>​ | Which palette to use for colors (if relevant) |
 | <color orange>​cc</​color>​ | Clamp and Mirror flags for the T axis | | <color orange>​cc</​color>​ | Clamp and Mirror flags for the T axis |
-| <color darkred>​aaaa</​color>​ | Sets how much of T axis is shown before ​wrapping ​|+| <color darkred>​aaaa</​color>​ | T mask (Sets how much of T axis is shown before ​clamping) ​|
 | <color darkblue>​ssss</​color>​ | Sets the amount to shift T axis values after perspective division | | <color darkblue>​ssss</​color>​ | Sets the amount to shift T axis values after perspective division |
 | <color darkgreen>​dd</​color>​ | Clamp and Mirror flags for the S axis | | <color darkgreen>​dd</​color>​ | Clamp and Mirror flags for the S axis |
-| <color #​8F3F10>​bbbb</​color>​ | Sets how much of S axis is shown before ​wrapping ​|+| <color #​8F3F10>​bbbb</​color>​ | S mask (Sets how much of S axis is shown before ​clamping) ​|
 | <color darkcyan>​uuuu</​color>​ | Sets the amount to shift S axis values after perspective division | | <color darkcyan>​uuuu</​color>​ | Sets the amount to shift S axis values after perspective division |
  
Line 576: Line 634:
 | 2 | 16-bit | RGBA, IA, and YUV | | 2 | 16-bit | RGBA, IA, and YUV |
 | 3 | 32-bit | RGBA | | 3 | 32-bit | RGBA |
 +
 +|wraps/​wrapt modes||
 +| 0 | Wrap/No mirror |
 +| 1 | Mirror |
 +| 2 | Clamp |
 +
 +|shifts/​shiftt modes||
 +| 0-10 | >> shift |
 +| 11-15 | << (shift-10) |
  
 Or simply ​ Or simply ​
Line 776: Line 843:
 The location is usually some place set as the framebuffer to show (which is not handled by display lists), but oftentimes will be set to a depth buffer. This is usually done to fill (aka clear) the depth buffer in fill mode. The location is usually some place set as the framebuffer to show (which is not handled by display lists), but oftentimes will be set to a depth buffer. This is usually done to fill (aka clear) the depth buffer in fill mode.
  
 +===== Fast3D DMEM Map =====
 +|0x000|Program data from compiler ​        ​|0x110 bytes|
 +|0x110|RSP GFX State                      |0x050 bytes|
 +|0x160|RSP Memory segment table           ​|0x040 bytes|
 +|0x1A0|Lights ​                            ​|0x180 bytes|
 +|0x320|Viewport ​                          ​|0x010 bytes|
 +|0x330|Fog factors ​                       |0x006 bytes|
 +|0x336|padding ​                           |0x002 bytes|
 +|0x338|Display list stack                 ​|0x028 bytes|
 +|0x360|Modelview matrix top of stack      |0x040 bytes|
 +|0x3A0|Projection Matrix top of stack     ​|0x040 bytes|
 +|0x3E0|MP Matrix (Modelview * Projection) |0x040 bytes|
 +|0x420|Points buffer ​                     |0x280 bytes|
 +|0x6A0|Input (display list)               ​|0x140 bytes|
 +|0x7E0|Input (data) ​                      ​|0x100 bytes|
 +|0x8E0|setup tmp                          |0x060 bytes|
 +|0x940|clip tmp                           ​|0x0A0 bytes|
 +|0x9E0|Output to RDP                      |0x400 bytes|
 +|0xDE0|Scratch space                      |0x1E0 bytes|
 +|0xFC0|Task ​                              ​|0x040 bytes|
 +
 +===== Fast3D RSP Register Assignment =====
 +|return ​    ​|$31||
 +|return_save|$30||
 +|rsp_state ​ |$29||
 +|dlcount ​   |$28||
 +|dinp       ​|$27|Pointer to current display list command in the input buffer in DMEM|
 +|inp        |$26|Pointer to the current command block in RDRAM|
 +|gfx0       ​|$25|Display list command high word|
 +|gfx1       ​|$24|Display list command low word|
 +|outp       ​|$23||
 +|in_bufp ​   |$22||
 +|zero       |$0 ||
 + 
 ---- ----
 ===== References ===== ===== References =====
Line 785: Line 886:
   * http://​wiki.spinout182.com/​w/​F3DEX2   * http://​wiki.spinout182.com/​w/​F3DEX2
   * http://​wiki.cloudmodding.com/​oot/​F3DZEX/​Opcode_Details   * http://​wiki.cloudmodding.com/​oot/​F3DZEX/​Opcode_Details
 +  * http://​ultra64.ca/​files/​documentation/​silicon-graphics/​SGI_RDP_Command_Summary.pdf
 +  * https://​www.docdroid.net/​NXMlF3s/​grucode.pdf
super_mario_64/fast3d_display_list_commands.1525656354.txt.gz · Last modified: 2018/05/07 01:25 by trenavix