Introduction
MIPS leaves coprocessor 2 to the chip maker: the architecture defines only the instructions that move data to and from it, and a command space the coprocessor interprets. On the PlayStation coprocessor 2 is the GTE, the Geometry Transformation Engine: a fixed-point vector unit that does the 3D transformation, lighting and depth cueing the PlayStation's graphics need. This page follows Martin Korth's nocash PSX specifications (the GTE chapter, “GTE Opcode Summary”), which the decoder was checked against; the explorer decodes the GTE only for the PlayStation CPU variant.
Moving data in and out
The GTE has 32 data registers and 32 control registers. A program loads vectors with lwc2 and mtc2, sets up
matrices with ctc2, runs a command and reads the results with mfc2, cfc2 and swc2
A GTE read has a load delay slot like any MIPS I coprocessor read.
| Instruction | Encoding | What it does |
|---|---|---|
mfc2 rt, rd | 010010 00000 rt rd 0 | Copy data register rd to rt. (MIPS32 adds a select field: mfc2 rt, rd, sel.) |
cfc2 rt, rd | 010010 00010 rt rd 0 | Copy control register rd to rt. |
mtc2 rt, rd | 010010 00100 rt rd 0 | Copy rt to data register rd. |
ctc2 rt, rd | 010010 00110 rt rd 0 | Copy rt to control register rd. |
dmfc2 rt, rd, sel | 010010 00001 rt rd 0 sel | MIPS III and later: copy a 64-bit coprocessor 2 register. Not on the PlayStation. |
dmtc2 rt, rd, sel | 010010 00101 rt rd 0 sel | MIPS III and later: write one. |
Loads and stores of GTE data registers: lwc2 rt, offset(base) and swc2, on the
loads and stores page; the explorer names the register in the detail line.
The command word
A GTE command is a coprocessor 2 instruction with bit 25 set; the other 25 bits are the command:
| Bits | Field | Meaning |
|---|---|---|
| 31–25 | 0100101: COP2 with the command bit. | |
| 24–20 | fake command | Ignored by the hardware (the PlayStation tools put a number here). The decoder accepts any value. |
| 19 | sf | Shift fraction: 1 shifts the results right by 12 bits (the fixed-point format of the vectors). |
| 18–17 | mx | MVMVA only: the matrix to multiply by: 0 rotation, 1 light, 2 colour, 3 reserved. |
| 16–15 | v | MVMVA only: the vector: 0 V0, 1 V1, 2 V2, 3 IR (the vector in IR1 to IR3). |
| 14–13 | cv | MVMVA only: the vector to add: 0 TR (translation), 1 BK (background colour), 2 FC (far colour, a hardware quirk), 3 none. |
| 12–11, 9–6 | Always zero. | |
| 10 | lm | Limit: 1 clamps IR1 to IR3 to 0 to 7FFF, 0 to −8000 to 7FFF. |
| 5–0 | command | The command number, below. |
A command is written rtps sf=1, lm=0: the mnemonic and the two bits; MVMVA also names the matrix, vector and translation.
The commands other than MVMVA must have zero in bits 18–13; the explorer decodes them anyway and marks the word unpredictable.
The commands
The cycle counts are from the nocash specification.
| Command | Number | Cycles | What it does |
|---|---|---|---|
rtps | 01 | 15 | Perspective transformation of one vector (V0). |
nclip | 06 | 8 | Normal clipping: the sign of the area of the screen triangle SXY0, SXY1, SXY2 into MAC0. |
op | 0C | 6 | Outer product of the rotation matrix diagonal and IR. |
dpcs | 10 | 8 | Depth cue of one colour (RGBC). |
intpl | 11 | 8 | Interpolate between IR and the far colour by IR0. |
mvmva | 12 | 8 | Multiply a vector by a matrix and add a translation vector, as mx, v, cv say. |
ncds | 13 | 19 | Normal colour depth cue, single vector. |
cdp | 14 | 13 | Colour depth cue. |
ncdt | 16 | 44 | Normal colour depth cue, three vectors. |
nccs | 1B | 17 | Normal colour colour, single vector. |
cc | 1C | 11 | Colour colour. |
ncs | 1E | 14 | Normal colour, single vector. |
nct | 20 | 30 | Normal colour, three vectors. |
sqr | 28 | 5 | Square of the vector IR. |
dcpl | 29 | 8 | Depth cue colour light. |
dpct | 2A | 17 | Depth cue of three colours (RGB0, RGB1, RGB2). |
avsz3 | 2D | 5 | Average of three Z values (SZ1, SZ2, SZ3) into OTZ, the ordering-table depth. |
avsz4 | 2E | 6 | Average of four Z values (SZ0 to SZ3) into OTZ. |
rtpt | 30 | 23 | Perspective transformation of three vectors (V0, V1, V2): a whole triangle. |
gpf | 3D | 5 | General purpose interpolation. |
gpl | 3E | 5 | General purpose interpolation with a base. |
ncct | 3F | 39 | Normal colour colour, three vectors. |
The GTE registers
| Number | Data registers |
|---|---|
| 0–5 | VXY0, VZ0, VXY1, VZ1, VXY2, VZ2: the three input vectors (16-bit x, y, z). |
| 6–7 | RGBC (colour and code), OTZ (the average Z). |
| 8–11 | IR0, IR1, IR2, IR3: the 16-bit intermediate results. |
| 12–15 | SXY0, SXY1, SXY2, SXYP: the screen coordinate FIFO. |
| 16–19 | SZ0, SZ1, SZ2, SZ3: the screen Z FIFO. |
| 20–23 | RGB0, RGB1, RGB2, RES1: the colour FIFO and a reserved register. |
| 24–27 | MAC0, MAC1, MAC2, MAC3: the accumulators. |
| 28–31 | IRGB, ORGB (the colour conversion registers), LZCS, LZCR (the leading-zero count). |
| Number | Control registers |
|---|---|
| 0–4 | RT11RT12, RT13RT21, RT22RT23, RT31RT32, RT33: the rotation matrix. |
| 5–7 | TRX, TRY, TRZ: the translation vector. |
| 8–12 | L11L12, L13L21, L22L23, L31L32, L33: the light matrix. |
| 13–15 | RBK, GBK, BBK: the background colour. |
| 16–20 | LR1LR2, LR3LG1, LG2LG3, LB1LB2, LB3: the light colour matrix. |
| 21–23 | RFC, GFC, BFC: the far colour. |
| 24–25 | OFX, OFY: the screen offset. |
| 26 | H: the projection plane distance. |
| 27–28 | DQA, DQB: the depth cueing parameters. |
| 29–30 | ZSF3, ZSF4: the Z scale factors for AVSZ3 and AVSZ4. |
| 31 | FLAG: the error bits (overflow and saturation) of the last command. |
The nocash specification numbers the control registers 32 to 63; ctc2 and cfc2 use the number minus 32.
Not described
Known, not yet covered
- Reference: what each command computes in full (the exact fixed-point formulas, the saturation and the FLAG bits, the rounding of the division in RTPS). The page says what the command is for and how it is encoded.
- Viewer: the PlayStation PS-X EXE format that holds this code is not read yet.
Unknown
- Reference: the behaviour of a GTE command with its reserved bits set; the hardware ignores them, but this is from the specification only.
Links
Reference
- Playstation Specifications – the GTE chapters: overview, registers, opcode summary and each command