Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

Module regs

Module regs 

Source
Expand description

GTE register accessors.

These are macros, not functions, because the GTE register index is encoded as a 5-bit immediate field in the instruction – you can’t pass it as a runtime value without either stamping 32 separate functions or generating code at build time. Macros keep the call site readable (write_data!(0, value)) while letting the assembler emit the exact encoding.

Every macro emits a hand-built .word rather than the mnemonic (mtc2, mfc2, ctc2, cfc2). The mipsel-sony-psx LLVM target gates the coprocessor-2 instruction class behind a CPU feature that isn’t enabled, so passing the mnemonic through the assembler fails with “instruction requires a CPU feature not currently enabled”. Emitting the raw 32-bit encoding sidesteps that gate; the hardware still decodes it the same way.

Encoding (per PSX-SPX, “MIPS Coprocessor 2 Opcodes”):

  bits 31..26 = 0x12 (COP2)
  bits 25..21 = rs           -- 0=MFC2, 2=CFC2, 4=MTC2, 6=CTC2
  bits 20..16 = rt           -- CPU general-purpose register
  bits 15..11 = rd           -- COP2 data/control register index
  bits 10..0  = 0

We pin the CPU-side register to $t0 ($8) via in("$8") / out("$8") operands, so the encoding becomes opcode_base | 8<<16 | rd<<11. The compiler is responsible for shuttling values into/out of $t0, which keeps call sites unobstructed.

Register index tables (mirroring emulator-core::gte):

Data regsPurpose
0..=5V0, V1, V2 input vectors (packed XY / Z)
6RGBC
7OTZ (output average Z)
8IR0 (scalar accumulator)
9..=11IR1, IR2, IR3 (vector accumulators)
12..=15SXY FIFO (12..=14 slots, 15 = SXYP push)
16..=19SZ FIFO (16=SZ0 oldest … 19=SZ3 newest)
20..=22RGB FIFO
24MAC0
25..=27MAC1, MAC2, MAC3
28 / 29IRGB (write) / ORGB (read) 5:5:5 view
30 / 31LZCS / LZCR
Control regsPurpose
0..=4RT rotation matrix
5..=7TR translation
8..=12LLM light-direction matrix
13..=15BK background colour (light bias)
16..=20LCM light-colour matrix
21..=23FC far colour
24 / 25OFX / OFY screen offsets
26H projection plane
27 / 28DQA / DQB depth-cue coefficients
29 / 30ZSF3 / ZSF4 AVSZ weights
31FLAG (error/saturation bits)

Functions§

pack_xy
Helper: pack two i16 values into one u32 for MTC2/CTC2 of XY-pair registers (V0 X/Y, SXY slots, rotation matrix rows, …).
unpack_xy
Inverse of pack_xy – split a packed word back into two i16s.