Skip to content

Commit

Permalink
Use XF register constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Jul 11, 2022
1 parent ad7dd60 commit 42a881f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions gxtest/cgx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void CGX_Init()

void CGX_SetViewport(float origin_x, float origin_y, float width, float height, float near, f32 far)
{
CGX_BEGIN_LOAD_XF_REGS(0x101a, 6);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETVIEWPORT, 6);
wgPipe->F32 = width * 0.5f;
wgPipe->F32 = -height * 0.5f;
wgPipe->F32 = (far - near) * 16777215.0f;
Expand All @@ -105,7 +105,7 @@ void CGX_LoadPosMatrixDirect(f32 mt[3][4], u32 index)
void CGX_LoadProjectionMatrixPerspective(float mtx[4][4])
{
// Untested
/* CGX_BEGIN_LOAD_XF_REGS(0x1020, 7);
/* CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETPROJECTION, 7);
wgPipe->F32 = mtx[0][0];
wgPipe->F32 = mtx[0][2];
wgPipe->F32 = mtx[1][1];
Expand All @@ -119,7 +119,7 @@ void CGX_LoadProjectionMatrixPerspective(float mtx[4][4])
void CGX_LoadProjectionMatrixOrthographic(float mtx[4][4])
{
// Untested
/* CGX_BEGIN_LOAD_XF_REGS(0x1020, 7);
/* CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETPROJECTION, 7);
wgPipe->F32 = mtx[0][0];
wgPipe->F32 = mtx[0][3];
wgPipe->F32 = mtx[1][1];
Expand Down
18 changes: 9 additions & 9 deletions gxtest/clipping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ void ClipTest()

CGX_LOAD_BP_REG(CGXDefault<TwoTevStageOrders>(0).hex);

CGX_BEGIN_LOAD_XF_REGS(0x1009, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETNUMCHAN, 1);
wgPipe->U32 = 1; // 1 color channel

LitChannel chan;
chan.hex = 0;
chan.matsource = MatSource::Vertex;
CGX_BEGIN_LOAD_XF_REGS(0x100e, 1); // color channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_COLOR, 1);
wgPipe->U32 = chan.hex;
CGX_BEGIN_LOAD_XF_REGS(0x1010, 1); // alpha channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_ALPHA, 1);
wgPipe->U32 = chan.hex;

CGX_LOAD_BP_REG(CGXDefault<TevStageCombiner::AlphaCombiner>(0).hex);
Expand Down Expand Up @@ -79,7 +79,7 @@ void ClipTest()
CGX_LOAD_BP_REG(tevreg.ra.hex);
CGX_LOAD_BP_REG(tevreg.bg.hex);

CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = 0; // 0 = enable clipping, 1 = disable clipping

bool expect_quad_to_be_drawn = true;
Expand Down Expand Up @@ -157,7 +157,7 @@ void ClipTest()
// Depth clipping tests
case 7: // Everything behind z=w plane, depth clipping enabled
case 8: // Everything behind z=w plane, depth clipping disabled
CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = step - 7; // 0 = enable clipping, 1 = disable clipping

test_quad.AtDepth(1.1);
Expand All @@ -166,7 +166,7 @@ void ClipTest()

case 9: // Everything in front of z=0 plane, depth clipping enabled
case 10: // Everything in front of z=0 plane, depth clipping disabled
CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = step - 9; // 0 = enable clipping, 1 = disable clipping

test_quad.AtDepth(-0.00001);
Expand All @@ -181,15 +181,15 @@ void ClipTest()
// number, which by IEEE would be non-zero but which in fact is
// treated as zero.
// In particular, the value by IEEE is -0.00000011920928955078125.
CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = step - 11; // 0 = enable clipping, 1 = disable clipping

test_quad.AtDepth(1.0000001);
break;

case 13: // One vertex behind z=w plane, depth clipping enabled
case 14: // One vertex behind z=w plane, depth clipping disabled
CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = step - 13; // 0 = enable clipping, 1 = disable clipping

test_quad.VertexTopLeft(-1.0f, 1.0f, 1.5f);
Expand All @@ -200,7 +200,7 @@ void ClipTest()
break;

case 15: // Three vertices with a very large value for z, depth clipping disabled
CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = 1; // 0 = enable clipping, 1 = disable clipping

test_quad.VertexTopLeft(-1.0f, 1.0f, 65537.f);
Expand Down
14 changes: 7 additions & 7 deletions gxtest/lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ void LightingTest()

CGX_LOAD_BP_REG(CGXDefault<TwoTevStageOrders>(0).hex);

CGX_BEGIN_LOAD_XF_REGS(0x1009, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETNUMCHAN, 1);
wgPipe->U32 = 1; // 1 color channel

LitChannel chan;
chan.hex = 0;
chan.matsource = MatSource::MatColorRegister;
chan.ambsource = AmbSource::AmbColorRegister;
chan.enablelighting = true;
CGX_BEGIN_LOAD_XF_REGS(0x100e, 1); // color channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_COLOR, 1);
wgPipe->U32 = chan.hex;
CGX_BEGIN_LOAD_XF_REGS(0x1010, 1); // alpha channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_ALPHA, 1);
wgPipe->U32 = chan.hex;

CGX_LOAD_BP_REG(CGXDefault<TevStageCombiner::AlphaCombiner>(0).hex);
Expand Down Expand Up @@ -62,13 +62,13 @@ void LightingTest()
CGX_LOAD_BP_REG(tevreg.ra.hex);
CGX_LOAD_BP_REG(tevreg.bg.hex);

CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
wgPipe->U32 = 0; // 0 = enable clipping, 1 = disable clipping
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = 0; // enable clipping

CGX_BEGIN_LOAD_XF_REGS(0x100a, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_AMBCOLOR, 1);
wgPipe->U32 = (ambcolor << 24) | 255;

CGX_BEGIN_LOAD_XF_REGS(0x100c, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_MATCOLOR, 1);
wgPipe->U32 = (matcolor << 24) | 255;

int test_x = 125, test_y = 25; // Somewhere within the viewport
Expand Down
8 changes: 4 additions & 4 deletions gxtest/rasterization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ void CoordinatePrecisionTest()

CGX_LOAD_BP_REG(CGXDefault<TwoTevStageOrders>(0).hex);

CGX_BEGIN_LOAD_XF_REGS(0x1009, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETNUMCHAN, 1);
wgPipe->U32 = 1; // 1 color channel

LitChannel chan;
chan.hex = 0;
chan.matsource = MatSource::Vertex;
CGX_BEGIN_LOAD_XF_REGS(0x100e, 1); // color channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_COLOR, 1);
wgPipe->U32 = chan.hex;
CGX_BEGIN_LOAD_XF_REGS(0x1010, 1); // alpha channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_ALPHA, 1);
wgPipe->U32 = chan.hex;

auto ac = CGXDefault<TevStageCombiner::AlphaCombiner>(0);
Expand Down Expand Up @@ -99,7 +99,7 @@ void CoordinatePrecisionTest()
// For this size, values of xpos from 0.583297729492 to 0.583328247070 will yield a covered
// pixel
float vp_width = 2.0e-5f;
CGX_BEGIN_LOAD_XF_REGS(0x101a, 6);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETVIEWPORT, 6);
wgPipe->F32 = vp_width;
wgPipe->F32 = -50.0f;
wgPipe->F32 = 16777215.0f;
Expand Down
16 changes: 8 additions & 8 deletions gxtest/tev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ void TevCombinerTest()

CGX_LOAD_BP_REG(CGXDefault<TwoTevStageOrders>(0).hex);

CGX_BEGIN_LOAD_XF_REGS(0x1009, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETNUMCHAN, 1);
wgPipe->U32 = 1; // 1 color channel

LitChannel chan;
chan.hex = 0;
chan.matsource = MatSource::Vertex;
CGX_BEGIN_LOAD_XF_REGS(0x100e, 1); // color channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_COLOR, 1);
wgPipe->U32 = chan.hex;
CGX_BEGIN_LOAD_XF_REGS(0x1010, 1); // alpha channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_ALPHA, 1);
wgPipe->U32 = chan.hex;

auto ac = CGXDefault<TevStageCombiner::AlphaCombiner>(0);
Expand Down Expand Up @@ -240,17 +240,17 @@ void KonstTest()

CGX_LOAD_BP_REG(CGXDefault<TwoTevStageOrders>(0).hex);

CGX_BEGIN_LOAD_XF_REGS(0x1009, 1);
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETNUMCHAN, 1);
wgPipe->U32 = 1; // 1 color channel

LitChannel chan;
chan.hex = 0;
chan.matsource = MatSource::MatColorRegister;
chan.ambsource = AmbSource::AmbColorRegister;
chan.enablelighting = false;
CGX_BEGIN_LOAD_XF_REGS(0x100e, 1); // color channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_COLOR, 1);
wgPipe->U32 = chan.hex;
CGX_BEGIN_LOAD_XF_REGS(0x1010, 1); // alpha channel 1
CGX_BEGIN_LOAD_XF_REGS(XFMEM_SETCHAN0_ALPHA, 1);
wgPipe->U32 = chan.hex;

auto genmode = CGXDefault<GenMode>();
Expand All @@ -264,8 +264,8 @@ void KonstTest()
ctrl.early_ztest = false;
CGX_LOAD_BP_REG(ctrl.hex);

CGX_BEGIN_LOAD_XF_REGS(0x1005, 1);
wgPipe->U32 = 0; // 0 = enable clipping, 1 = disable clipping
CGX_BEGIN_LOAD_XF_REGS(XFMEM_CLIPDISABLE, 1);
wgPipe->U32 = 0; // enable clipping

// Set up "konst" colors with recognizable values.
for (int i = 0; i < 4; ++i)
Expand Down

0 comments on commit 42a881f

Please sign in to comment.