Vertex and Polygon Commands

This chapter explains the various commands used to send verticies to the 3D hardware in order to construct polygons. On top of this theres also basic lighting, materials, and texture mapping attributes. The DS 3D hardware natively supports constructing both triangles and quadrilaterals (which should not self intersect or have concavities).

Usage Overview

Verticies, as well as edges and polygons are to be constructed on the 3D hardware in the following manner:

  1. Set Polygon attributes

  2. Start a vertex list, where the parameter passed to the start command dictates the type of polygons you wish to construct (Seperated or Connected, Tris or Quads)

  3. For each vertex, set relevant vertex attributes in any order. Setting any coordinate of the vertex position sends it to the 3D hardware. Attributes that are left unset will use the values of the previous vertex.

  4. End the vertex list.

Notice here that the 3D hardware does not natively support index lists for constructing polygons, only a vertex list that constructs either seperated or connected “strips” of primitives. Another quirk of the 3D hardware is that the last step is optional, as vertex lists are automatically ended when a new one begins or the geometry and rendering engine buffers are swapped. It may still be useful however to manually end it for debugging purposes and the sake of “Completeness”.

Vertex List Commands

Commands used to start and end vertex lists, as well as commands which can only be used once per vertex list.

Start Vertex List: Port 0x04000500, Index 0x40, 1 Parameter

Parameter definition:

Bit(s)Description
0Primitive Type (0 = triangle, 1 = quadrilateral)
1Primitive Topology (0 = seperated, 1 = strips)

End Vertex List: Port 0x04000504, Index 0x41, 0 Parameters

Ends a vertex list, as previously discussed this command is optional, and only require for the sake of debugging

Polygon Attributes: Port 0x040004A4, Index 0x29, 1 Parameter

Sets various miscallenous attributes for polygons created by the next vertex list.

Parameter definition:

Bit(s)Description
0Enable Light 0
1Enable Light 1
2Enable Light 2
3Enable Light 3
4-5Polygon Mode (0 = Modulation, 1=Decal, 2=Toon, 3=Shadow)
6Render Backface
7Render Frontface
8-10Unused
11Set new depth for translucent pixels
12Render Far-Plane intersecting polygons
13Render 1-Dot polygons behind 1-Dot depth
14Depth test (0 = less than, 1 = equal)
15Enable Fog
16-20Alpha (0 = Wireframe, 1..30 = Translucent, 31 = Solid)
21-23Unused
24-29Polygon ID
30-31Unused

Notes: If a polygon attribute command is sent while a vertex list is ongoing, it will be deffered until next time a vertex list is begun. (Repeated calls will not stack, only the last written one will be used) Changes in lighting related attributes will not change until a new normal vector is set/calculated.

Vertex Attribute Commands

These are the commands for various attributes which can be applied to a vertex.

Set Vertex Color: Port 0x04000480, Index 0x20, 1 Parameter

Sets the vertex color used for the next vertex.

Parameter definition:

Bit(s)Description
0-4Red
5-9Green
10-14Blue
15-31Unused

Set Normal Vector: Port 0x04000484, Index 0x21, 1 Parameter

Sets the “normal vector” used for the next vertex. In reality this will use the currently set light parameters to calculate a new vertex color.

Parameter definition:

Bit(s)Description
0-9Vertex X coordinate (sign + 9 bit fraction)
10-19Vertex Y coordinate (sign + 9 bit fraction)
20-29Vertex Z coordinate (sign + 9 bit fraction)
30-31Unused

Set Texture Coordinates: Port 0x04000488, Index 0x22, 1 Parameter

Sets the UV / ST coordinates for the next vertex. 16 units = 1 texel

Parameter definition:

Bit(s)Description
0-15S/U coordinate (signed, 4 bit fraction)
16-31T/V coordinate (signed, 4 bit fraction)

Set Texture Parameters: Port 0x040004A8, Index 0x2A, 1 Parameter

Binds a texture to the upcoming verticies, along with various texture attributes.

Parameter definition:

Bit(s)Description
0-15Texture VRAM offset (in steps of 8)
16Repeat Horizontally (0 = Clamp, 1 = Repeat)
17Repeat Vertically (0 = Clamp, 1 = Repeat)
18Flip on horizontal repeat (see notes.)
19Flip on Vertical repeat (see notes.)
20-22Horizontal size (see notes.)
23-25Vertical size (see notes.)
26-28Texture Format (see notes.)
29Set color 0 to transparent
30-31Texture Coordinate transformation mode (see notes.)

Notes:

Texture size is calculated as (8 << N) pixels where N is the specified size. Meaning possible resulting values are 8,16,32,64,128,256,512,1024.

Texture flipping on repeats requires that repeats are on.

When a Texture is clamped, the outmost edge pixels are stretched across any out of bounds pixels.

The various Texture Formats are as follows:

IndexDescription
0No texture
1A315 Translucent Texture
24-Color Paletted texture
316-Color Paletted texture
4256-Color Paletted texture
5Compressed Texture
6A513 Translucent texture;
7Bitmap Texture (R5G5B5)

Texture Coordinate Transformation Modes:

IndexDescription
0No transformation
1Texture Coordinate Source
2Normal Source
3Vertex Source

Set Texture Color Palette: Port 0x040004AC, Index 0x2B, 1 Parameter

Set the color palette used for the currently binded texture. Ignored by non-palette based textures.

Parameter Definition:

Bit(s)Description
0-12Texture Palette VRAM offset (see notes.)
13-31Ignored

Notes: When using 4-color paletted textures the offset is calculated in steps of 8. In any other cases it’s steps of 16.

Diffuse/Ambient Properties: Port 0x040004C0, index 0x30, 1 Parameter

Sets the Diffused/Ambient properties for the next vertex.

Parameter definition:

Bit(s)Description
0-4Diffuse Reflection (Red channel)
5-9Diffuse Reflection (Green channel)
10-14Diffuse Refletcion (Blue channel)
15Set Diffuse reflection as vertex color (0 = No, 1 = Yes)
16-20Ambient Reflection (Red Channel)
21-25Ambient Reflection (Green channel)
26-30Ambient Reflection (Blue channel)
31Unused

Specular/Emissive Properties: Port 0x040004C4, index 0x31, 1 Parameter

Sets the Specular/Emissive properties for the next vertex.

Parameter definition:

Bit(s)Description
0-4Specular Reflection (Red channel)
5-9Specular Reflection (Green channel)
10-14Specular Refletcion (Blue channel)
15Use shininess table (0 = No, 1 = Yes, see chapter on other commands for shininess table details)
16-20Emission (Red Channel)
21-25Emission (Green channel)
26-30Emission (Blue channel)
31Unused

Vertex Position Commands

All of these commands send a new vertex to the geometry engine once executes. Unless stated otherwise, the vertex coordinates will be a 16bit signed integer with a 12bit fraction. (i.e Range is +7.99 to -8.00)

Position Set (16-bit): Port 0x0400048C, Index 0x23, 2 Parameters

Set all coordinates of the next vertex at once.

Parameter Definition:

ParameterBit(s)Description
10-15Vertex X coordinate
116-31Vertex Y coordinate
20-15Vertex Z coordinate
216-31Unused

Position Set (10-bit): Port 0x04000490, Index 0x24, 1 Parameter

Set all coordinates of the next vertex at once, but with less accuracy.

Parameter Definition:

Bit(s)Description
0-9Vertex X coordinate (signed, 6 bit fraction)
10-19Vertex Y coordinate (signed, 6 bit fraction)
20-29Vertex Z coordinate (signed, 6 bit fraction)
30-31Unused

Position Set XY: Port 0x04000494, Index 0x25, 1 Parameter

Set X and Y coordinate of the next vertex.

Parameter Definition:

Bit(s)Description
0-15Vertex X coordinate
16-31Vertex Y coordinate

Position Set XZ: Port 0x04000498, Index 0x26, 1 Parameter

Set X and Z coordinate of the next vertex.

Parameter Definition:

Bit(s)Description
0-15Vertex X coordinate
16-31Vertex Z coordinate

Position Set YZ: Port 0x0400049C, Index 0x27, 1 Parameter

Set Y and Z coordinate of the next vertex.

Parameter Definition:

Bit(s)Description
0-15Vertex Y coordinate
16-31Vertex Z coordinate

Position Set Relative: Port 0x040004A0, Index 0x28, 1 Parameter

Set all coordinates of the next vertex at once, but relative to the last vertex.

Parameter Definition:

Bit(s)Description
0-9Vertex X coordinate (signed, 12 bit fraction, see notes.)
10-19Vertex Y coordinate (signed, 12 bit fraction, see notes.)
20-29Vertex Z coordinate (signed, 12 bit fraction, see notes.)
30-31Unused

Note: As the value is smaller than the fraction, the relative range is very small (+-0.125)