Expand description
GTE (COP2) access – PS1 Geometry Transformation Engine.
The GTE isn’t memory-mapped. It’s MIPS coprocessor 2, accessed via
a dedicated instruction class (MTC2/MFC2/CTC2/CFC2 to move
data between CPU and COP2 registers, COP2 cofun to run function
ops like RTPS/RTPT/MVMVA/NCDS).
This crate exposes two layers:
-
Low-level register macros:
write_data!,read_data!,write_control!,read_control!. Each takes a literal register index (0..31) so the assembler emits the correct immediate field. Use these when you need direct access for performance-sensitive paths. -
High-level operation wrappers: zero-argument inline functions for the common GTE commands with their typical options baked in (e.g.
ops::project_singleusessf=1, lm=0). On MIPS each compiles to a single 4-byte.word. On host they dispatch to a per-thread software GTE living in [host].
All function-op wrappers are unsafe fn – they assume the caller
has loaded the required input registers via the register macros.
§Same simulation, two backends
- On
target_arch = "mips"everything compiles down to direct coprocessor instructions, identical to writing the assembly by hand. - On host the macros and ops route through [
psx_gte_core::Gte] stored in athread_local!cell. The simulation is the bit-faithful one the emulator already runs against PCSX-Redux’s parity oracle, so editor previews match what the hardware draws.
§Example
use psx_gte::{ops::project_single, read_data, write_control, write_data};
unsafe {
write_control!(0, 0x0000_1000); // RT[0][0]=0x1000, RT[0][1]=0
// … fill in the rest of the rotation matrix and TR …
write_data!(0, (10 & 0xFFFF) | (20 << 16));
write_data!(1, 30);
project_single();
let sxy2: u32 = read_data!(14);
}Modules§
- encoding
- The COP2 instruction encodings the wrappers emit (
psx_hw::gte). GTE (COP2) instruction encodings. - lighting
- Up-to-3-directional-light rig, rendered via the GTE’s
hardware lighting pipeline (
NCCS/NCDS/NCSops). - math
- Fixed-point math types for GTE inputs/outputs.
- ops
- GTE function-op wrappers.
- regs
- GTE register accessors.
- scene
- Scene / camera / projection helpers.
- transform
- Composable 3D transform math.
Macros§
- mfc2
Deprecated - Renamed to
read_data!. - mtc2
Deprecated - Renamed to
write_data!. - read_
control - Read a GTE control register (
CFC2). Same load-delay concern asread_data!– emits a NOP after the CFC2 to give the result a cycle to commit to $8 before Rust’s compiler-inserted move-from-$8 runs. - read_
data - Read a GTE data register (
MFC2). Expands to a single MFC2 instruction with the register index baked into the.wordencoding, followed by a NOP that fills the one-cycle load-delay slot. - write_
control - Write a GTE control register (
CTC2). - write_
data - Write a GTE data register (
MTC2). Expands to a single MTC2 instruction.