; This is the the projection matrix we start with: ; 1/2w 0 ox/2w + 1/2 -ox/2w ; 0 -1/2h -oy/2h + 1/2 oy/2h ; 0 0 1 0 ; 0 0 1 0 ; To get rid of the +1/2 in the combined matrix we ; subtract the w-row/2 from the x- and y-rows. ; ; The z-row is then set to [0 0 0 1] such that multiplication ; by XYZscale gives [0 0 0 zScale]. After perspective division ; and addition of XYZoffset we then get zScale/w + zShift for z. ; ; XYZScale scales xy to the resolution and z by zScale. ; XYZOffset translates xy to the GS coordinate system (where ; [2048, 2048] is the center of the frame buffer) and adds zShift to z. ; 1 fog (no fog) ; 2 clip (no clip/cull) ; 4 trilist (strip) ; 8 true clip (cull) SUB.z VF28, VF28, VF28 LOI 0.5 ; set z row SUB.z VF29, VF29, VF29 LQ.xyw VF28, vuSDmat0(VI00) ; set z row SUB.z VF30, VF30, VF30 LQ.xyw VF29, vuSDmat1(VI00) ; set z row ADDw.z VF31, VF00, VF00 LQ.xyw VF30, vuSDmat2(VI00) ; set z row SUB.w VF02, VF02, VF02 LQ.xyw VF31, vuSDmat3(VI00) MULi.w VF21, VF28, I ILW.x VI02, vuSDVUSwitch(VI00) ; w/2 MULi.w VF22, VF29, I LQ.xyz VF02, vuSDoffXoffYzShift(VI00) ; w/2 -- load shift MULi.w VF23, VF30, I IADDIU VI03, VI00, 2 ; w/2 MULi.w VF25, VF31, I LQ.xyz VF05, vuSDcamWcamHzScale(VI00) ; w/2 -- load scale SUBw.xy VF28, VF28, VF21 IAND VI03, VI02, VI03 ; xy - w/2 SUBw.xy VF29, VF29, VF22 LQ.xy VF03, vuSDrealOffset(VI00) ; xy - w/2 -- load offset SUBw.xy VF30, VF30, VF23 IBEQ VI03, VI00, SwitchNoClip ; xy - w/2 SUBw.xy VF31, VF31, VF25 IADDIU VI05, VI00, 4 ; xy - w/2 SwitchClipping: MUL.xy VF28, VF28, VF05 IAND VI05, VI02, VI05 ; scale xyz MUL.xy VF29, VF29, VF05 IADDIU VI06, VI00, 8 ; scale xyz MUL.xy VF30, VF30, VF05 IADDIU VI12, VI00, ExpandBuffer1 ; scale xyz MUL.xyz VF31, VF31, VF05 IBEQ VI05, VI00, SwitchTSCLip ; scale xyz ADD.xy VF02, VF02, VF03 IAND VI06, VI02, VI06 ; apply offset to shift SwitchTLCLip: NOP IADDIU VI13, VI00, XExpandBuffer2 NOP IADD VI14, VI00, VI12 NOP IBEQ VI06, VI00, SwithSystemExit NOP IADDIU VI15, VI00, TLCullRender NOP B SwithSystemExit NOP IADDIU VI15, VI00, TLClipRender SwitchTSCLip: NOP IADDIU VI13, VI00, XExpandBuffer2 NOP IADD VI14, VI00, VI12 NOP IBEQ VI06, VI00, SwithSystemExit NOP IADDIU VI15, VI00, TSCullRender NOP B SwithSystemExit NOP IADDIU VI15, VI00, TSClipRender SwitchNoClip: MUL.xy VF28, VF28, VF05 IADDIU VI04, VI00, 1 MUL.xy VF29, VF29, VF05 IAND VI04, VI02, VI04 MUL.xy VF30, VF30, VF05 IADDIU VI12, VI00, ExpandBuffer1 MUL.xyz VF31, VF31, VF05 IADDIU VI13, VI00, ExpandBuffer2 ADD.xy VF02, VF02, VF03 IBEQ VI04, VI00, SwitchNoFog NOP IADD VI14, VI00, VI12 NOP B SwithSystemExit NOP IADDIU VI15, VI00, FoggedRender SwitchNoFog: NOP IADDIU VI15, VI00, GenericRender SwithSystemExit: NOP ISW.y VI15, vuSDVUSwitch(VI00)