diff options
| author | LagoLunatic <LagoLunatic@users.noreply.github.com> | 2024-11-07 14:24:48 -0500 |
|---|---|---|
| committer | LagoLunatic <LagoLunatic@users.noreply.github.com> | 2024-11-07 14:24:48 -0500 |
| commit | 04a5b59db5b460eab06c07bc6a44391fac5d0806 (patch) | |
| tree | 007e2af358aa1d9319facc3cf8230d102360984e /src/dolphin | |
| parent | 0492ca2b52485bc5ffcc0c495963e23ffc8415b4 (diff) | |
GX work
Diffstat (limited to 'src/dolphin')
| -rw-r--r-- | src/dolphin/gx/GXBump.c | 30 | ||||
| -rw-r--r-- | src/dolphin/gx/GXInit.c | 49 | ||||
| -rw-r--r-- | src/dolphin/gx/GXTransform.c | 66 |
3 files changed, 65 insertions, 80 deletions
diff --git a/src/dolphin/gx/GXBump.c b/src/dolphin/gx/GXBump.c index 8c1084df..8a5284b2 100644 --- a/src/dolphin/gx/GXBump.c +++ b/src/dolphin/gx/GXBump.c @@ -127,36 +127,22 @@ void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXInd } void GXSetIndTexOrder(GXIndTexStageID stage, GXTexCoordID coord, GXTexMapID map) { - GXData* data; - - if (map == 0xFF) { - map = GX_TEXMAP0; - } - - if (coord == 0xFF) { - coord = GX_TEXCOORD0; - } - switch (stage) { case GX_INDTEXSTAGE0: - data = __GXData; - GX_BITFIELD_SET(data->iref, 29, 3, map); - GX_BITFIELD_SET(data->iref, 26, 3, coord); + GX_BITFIELD_SET(__GXData->iref, 29, 3, map); + GX_BITFIELD_SET(__GXData->iref, 26, 3, coord); break; case GX_INDTEXSTAGE1: - data = __GXData; - GX_BITFIELD_SET(data->iref, 23, 3, map); - GX_BITFIELD_SET(data->iref, 20, 3, coord); + GX_BITFIELD_SET(__GXData->iref, 23, 3, map); + GX_BITFIELD_SET(__GXData->iref, 20, 3, coord); break; case GX_INDTEXSTAGE2: - data = __GXData; - GX_BITFIELD_SET(data->iref, 17, 3, map); - GX_BITFIELD_SET(data->iref, 14, 3, coord); + GX_BITFIELD_SET(__GXData->iref, 17, 3, map); + GX_BITFIELD_SET(__GXData->iref, 14, 3, coord); break; case GX_INDTEXSTAGE3: - data = __GXData; - GX_BITFIELD_SET(data->iref, 11, 3, map); - GX_BITFIELD_SET(data->iref, 8, 3, coord); + GX_BITFIELD_SET(__GXData->iref, 11, 3, map); + GX_BITFIELD_SET(__GXData->iref, 8, 3, coord); break; } diff --git a/src/dolphin/gx/GXInit.c b/src/dolphin/gx/GXInit.c index d05c8ab4..b9d3c126 100644 --- a/src/dolphin/gx/GXInit.c +++ b/src/dolphin/gx/GXInit.c @@ -4,37 +4,21 @@ char* __GXVersion = "<< Dolphin SDK - GX release build: Nov 10 2004 06:27:12 (0x2301) >>"; -static GXFifoObj FifoObj; - static GXData gxData; +static GXFifoObj FifoObj; + GXData* const __GXData = &gxData; GXTexRegion* __GXDefaultTexRegionCallback(const GXTexObj* obj, GXTexMapID id) { - GXTexFmt format; // r31 - GXBool isMipMap; // r3 + GXTexFmt format; format = GXGetTexObjFmt(obj); - isMipMap = GXGetTexObjMipMap(obj); - id = (GXTexMapID)(id % GX_MAX_TEXMAP); - - switch (format) { - case GX_TF_RGBA8: - // if (isMipMap) { - // return &__GXData->TexRegions2[id]; - // } - return &__GXData->TexRegions1[id]; - - case GX_TF_C4: - case GX_TF_C8: - case GX_TF_C14X2: - return &__GXData->TexRegions0[id]; - default: - if (isMipMap) { - return &__GXData->TexRegions1[id]; - } - return &__GXData->TexRegions0[id]; + if (format != GX_TF_C4 && format != GX_TF_C8 && format != GX_TF_C14X2) { + return &__GXData->TexRegions0[__GXData->nextTexRgn++ % GX_MAX_TEXMAP]; + } else { + return &__GXData->TexRegions1[__GXData->nextTexRgnCI++ % 4]; } } @@ -168,11 +152,6 @@ GXFifoObj* GXInit(void* base, u32 size) { GXSetCPUFifo(&FifoObj); GXSetGPFifo(&FifoObj); - if (!resetFuncRegistered) { - // OSRegisterResetFunction(&GXResetFuncInfo); - resetFuncRegistered = 1; - } - __GXPEInit(); EnableWriteGatherPipe(); @@ -280,7 +259,6 @@ GXFifoObj* GXInit(void* base, u32 size) { GFWriteBPCmd(0x67000000); - __GXSetIndirectMask(0); __GXSetTmemConfig(2); __GXInitGX(); @@ -289,7 +267,6 @@ GXFifoObj* GXInit(void* base, u32 size) { void __GXInitGX(void) { GXRenderModeObj* renderObj; - GXTexObj texObj; Mtx ident; GXColor clearColor = {64, 64, 64, 255}; GXColor ambColor = {0, 0, 0, 0}; @@ -395,19 +372,11 @@ void __GXInitGX(void) { GXSetChanMatColor(GX_COLOR1A1, matColor); GXInvalidateTexAll(); + __GXData->nextTexRgn = 0; + __GXData->nextTexRgnCI = 0; GXSetTexRegionCallback(__GXDefaultTexRegionCallback); GXSetTlutRegionCallback(__GXDefaultTlutRegionCallback); - GXInitTexObj(&texObj, DefaultTexData, 4, 4, GX_TF_IA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GXLoadTexObj(&texObj, GX_TEXMAP0); - GXLoadTexObj(&texObj, GX_TEXMAP1); - GXLoadTexObj(&texObj, GX_TEXMAP2); - GXLoadTexObj(&texObj, GX_TEXMAP3); - GXLoadTexObj(&texObj, GX_TEXMAP4); - GXLoadTexObj(&texObj, GX_TEXMAP5); - GXLoadTexObj(&texObj, GX_TEXMAP6); - GXLoadTexObj(&texObj, GX_TEXMAP7); - GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR0A0); GXSetTevOrder(GX_TEVSTAGE2, GX_TEXCOORD2, GX_TEXMAP2, GX_COLOR0A0); diff --git a/src/dolphin/gx/GXTransform.c b/src/dolphin/gx/GXTransform.c index 89037974..a8ca4c71 100644 --- a/src/dolphin/gx/GXTransform.c +++ b/src/dolphin/gx/GXTransform.c @@ -1,13 +1,12 @@ #include "dolphin/gx/GXTransform.h" #include "dolphin/gx/GX.h" -#include "dolphin/os/OS.h" - -void __GXSetMatrixIndex(); +#include "dolphin/gx/GXInit.h" static void Copy6Floats(register f32 src[6], register f32 dst[6]) { register f32 ps_0, ps_1, ps_2; // clang-format off +#ifdef __MWERKS__ asm { psq_l ps_0, 0(src), 0, 0 psq_l ps_1, 8(src), 0, 0 @@ -16,6 +15,7 @@ static void Copy6Floats(register f32 src[6], register f32 dst[6]) { psq_st ps_1, 8(dst), 0, 0 psq_st ps_2, 16(dst), 0, 0 } +#endif // clang-format on } @@ -23,6 +23,7 @@ static void WriteProjPS(const register f32 src[6], register volatile void* dst) register f32 ps_0, ps_1, ps_2; // clang-format off +#ifdef __MWERKS__ asm { psq_l ps_0, 0(src), 0, 0 psq_l ps_1, 8(src), 0, 0 @@ -31,6 +32,7 @@ static void WriteProjPS(const register f32 src[6], register volatile void* dst) psq_st ps_1, 0(dst), 0, 0 psq_st ps_2, 0(dst), 0, 0 } +#endif // clang-format on } @@ -42,8 +44,6 @@ void GXProject(f32 model_x, f32 model_y, f32 model_z, Mtx model_mtx, f32* proj_m f32 var_f28; f32 var_f31; - ASSERTMSG(proj_mtx != NULL && viewpoint != NULL && screen_x != NULL && screen_y != NULL && screen_z != NULL, "GXGet*: invalid null pointer"); - sp10[0] = (model_mtx[0][0] * model_x) + (model_mtx[0][1] * model_y) + (model_mtx[0][2] * model_z) + model_mtx[0][3]; sp10[1] = (model_mtx[1][0] * model_x) + (model_mtx[1][1] * model_y) + @@ -68,14 +68,9 @@ void GXProject(f32 model_x, f32 model_y, f32 model_z, Mtx model_mtx, f32* proj_m *screen_z = viewpoint[5] + (var_f31 * (var_f28 * (viewpoint[5] - viewpoint[4]))); } -void __GXSetProjection(void) { - GX_XF_LOAD_REGS(6, GX_XF_REG_PROJECTIONA); - WriteProjPS(__GXData->projMtx, (volatile void*)GXFIFO_ADDR); - GXFIFO.u32 = __GXData->projType; -} - void GXSetProjection(const Mtx44 proj, GXProjectionType type) { volatile void* fifo; + u32 reg; __GXData->projType = type; __GXData->projMtx[0] = proj[0][0]; @@ -91,28 +86,58 @@ void GXSetProjection(const Mtx44 proj, GXProjectionType type) { __GXData->projMtx[3] = proj[1][2]; } - __GXSetProjection(); + + reg = 0x00061020; + GX_WRITE_U8(0x10); + GX_WRITE_U32(reg); + GX_WRITE_XF_REG_F(32, __GXData->projMtx[0]); + GX_WRITE_XF_REG_F(33, __GXData->projMtx[1]); + GX_WRITE_XF_REG_F(34, __GXData->projMtx[2]); + GX_WRITE_XF_REG_F(35, __GXData->projMtx[3]); + GX_WRITE_XF_REG_F(36, __GXData->projMtx[4]); + GX_WRITE_XF_REG_F(37, __GXData->projMtx[5]); + GX_WRITE_XF_REG_2(38, __GXData->projType); __GXData->bpSentNot = GX_TRUE; } void GXSetProjectionv(f32* proj) { - __GXData->projType = proj[0] == 0.0f ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC; - Copy6Floats(&proj[1], __GXData->projMtx); - - __GXSetProjection(); + __GXData->projType = proj[0]; + __GXData->projMtx[0] = proj[1]; + __GXData->projMtx[1] = proj[2]; + __GXData->projMtx[2] = proj[3]; + __GXData->projMtx[3] = proj[4]; + __GXData->projMtx[4] = proj[5]; + __GXData->projMtx[5] = proj[6]; + + + GX_WRITE_U8(0x10); + GX_WRITE_U32(0x00061020); + GX_WRITE_XF_REG_F(32, __GXData->projMtx[0]); + GX_WRITE_XF_REG_F(33, __GXData->projMtx[1]); + GX_WRITE_XF_REG_F(34, __GXData->projMtx[2]); + GX_WRITE_XF_REG_F(35, __GXData->projMtx[3]); + GX_WRITE_XF_REG_F(36, __GXData->projMtx[4]); + GX_WRITE_XF_REG_F(37, __GXData->projMtx[5]); + GX_WRITE_XF_REG_2(38, __GXData->projType); __GXData->bpSentNot = GX_TRUE; } void GXGetProjectionv(f32* proj) { - *proj = (u32)__GXData->projType != GX_PERSPECTIVE ? 1.0f : 0.0f; - Copy6Floats(__GXData->projMtx, &proj[1]); + proj[0] = __GXData->projType; + proj[1] = __GXData->projMtx[0]; + proj[2] = __GXData->projMtx[1]; + proj[3] = __GXData->projMtx[2]; + proj[4] = __GXData->projMtx[3]; + proj[5] = __GXData->projMtx[4]; + proj[6] = __GXData->projMtx[5]; } static void WriteMTXPS4x3(register volatile void* dst, register const Mtx src) { register f32 ps_0, ps_1, ps_2, ps_3, ps_4, ps_5; // clang-format off +#ifdef __MWERKS__ asm { psq_l ps_0, 0(src), 0, 0 psq_l ps_1, 8(src), 0, 0 @@ -128,6 +153,7 @@ static void WriteMTXPS4x3(register volatile void* dst, register const Mtx src) { psq_st ps_4, 0(dst), 0, 0 psq_st ps_5, 0(dst), 0, 0 } +#endif // clang-format on } @@ -140,6 +166,7 @@ static void WriteMTXPS3x3(register volatile void* dst, register const Mtx src) { register f32 ps_0, ps_1, ps_2, ps_3, ps_4, ps_5; // clang-format off +#ifdef __MWERKS__ asm { psq_l ps_0, 0(src), 0, 0 lfs ps_1, 8(src) @@ -155,6 +182,7 @@ static void WriteMTXPS3x3(register volatile void* dst, register const Mtx src) { psq_st ps_4, 0(dst), 0, 0 stfs ps_5, 0(dst) } +#endif // clang-format on } @@ -172,6 +200,7 @@ static void WriteMTXPS4x2(register volatile void* dst, register const Mtx src) { register f32 ps_0, ps_1, ps_2, ps_3; // clang-format off +#ifdef __MWERKS__ asm { psq_l ps_0, 0(src), 0, 0 psq_l ps_1, 8(src), 0, 0 @@ -183,6 +212,7 @@ static void WriteMTXPS4x2(register volatile void* dst, register const Mtx src) { psq_st ps_2, 0(dst), 0, 0 psq_st ps_3, 0(dst), 0, 0 } +#endif // clang-format on } |
