From 1a090efea59eafbc85648118537797193a56dab4 Mon Sep 17 00:00:00 2001 From: cadmic Date: Tue, 8 Oct 2024 12:21:05 -0700 Subject: [PATCH] Make progress on projection-matrix-handling frame functions (#60) * Fix Frame offset comments * Make progress on frameLoadVertex * More progress on project matrix usages * Use GXFogType * Name frameDrawSetupFog functions * Remove nLensBuffer --- config/oot-e/symbols.txt | 8 +- config/oot-j/symbols.txt | 8 +- config/oot-u/symbols.txt | 8 +- include/emulator/frame.h | 55 ++++--- src/emulator/frame.c | 287 ++++++++++++++++++++++++++++--------- src/revolution/mtx/mtx44.c | 6 +- 6 files changed, 258 insertions(+), 114 deletions(-) diff --git a/config/oot-e/symbols.txt b/config/oot-e/symbols.txt index d3a6d6d..2bfa162 100644 --- a/config/oot-e/symbols.txt +++ b/config/oot-e/symbols.txt @@ -643,8 +643,8 @@ frameUpdateCache = .text:0x800499A8; // type:function size:0x254 frameLoadTile = .text:0x80049BFC; // type:function size:0x424 fn_8004A020 = .text:0x8004A020; // type:function size:0x2F4 fn_8004A314 = .text:0x8004A314; // type:function size:0x388 -fn_8004A69C = .text:0x8004A69C; // type:function size:0x200 -fn_8004A89C = .text:0x8004A89C; // type:function size:0x200 +frameDrawSetupFog_StarFox = .text:0x8004A69C; // type:function size:0x200 +frameDrawSetupFog_Default = .text:0x8004A89C; // type:function size:0x200 ZeldaDrawFrame = .text:0x8004AA9C; // type:function size:0x324 ZeldaGreyScaleConvert = .text:0x8004ADC0; // type:function size:0x3D8 fn_8004B198 = .text:0x8004B198; // type:function size:0x320 @@ -1487,9 +1487,9 @@ PSMTXTransApply = .text:0x8009CED8; // type:function size:0x4C PSMTXScale = .text:0x8009CF24; // type:function size:0x28 PSMTXMultVec = .text:0x8009CF4C; // type:function size:0x54 C_MTXOrtho = .text:0x8009CFA0; // type:function size:0x98 -fn_8009D008 = .text:0x8009D038; // type:function size:0x34 +PSMTX44Identity = .text:0x8009D038; // type:function size:0x34 PSMTX44Concat = .text:0x8009D06C; // type:function size:0x104 -fn_8009D140 = .text:0x8009D170; // type:function size:0x64 +PSMTXTranspose = .text:0x8009D170; // type:function size:0x64 PSMTX44MultVecNoW = .text:0x8009D1D4; // type:function size:0x54 __GXDefaultTexRegionCallback = .text:0x8009D228; // type:function size:0xF4 scope:local __GXDefaultTlutRegionCallback = .text:0x8009D31C; // type:function size:0x24 scope:local diff --git a/config/oot-j/symbols.txt b/config/oot-j/symbols.txt index de7f7d7..569d067 100644 --- a/config/oot-j/symbols.txt +++ b/config/oot-j/symbols.txt @@ -643,8 +643,8 @@ frameUpdateCache = .text:0x800499A8; // type:function size:0x254 frameLoadTile = .text:0x80049BFC; // type:function size:0x424 fn_8004A020 = .text:0x8004A020; // type:function size:0x2F4 fn_8004A314 = .text:0x8004A314; // type:function size:0x388 -fn_8004A69C = .text:0x8004A69C; // type:function size:0x200 -fn_8004A89C = .text:0x8004A89C; // type:function size:0x200 +frameDrawSetupFog_StarFox = .text:0x8004A69C; // type:function size:0x200 +frameDrawSetupFog_Default = .text:0x8004A89C; // type:function size:0x200 ZeldaDrawFrame = .text:0x8004AA9C; // type:function size:0x324 ZeldaGreyScaleConvert = .text:0x8004ADC0; // type:function size:0x3D8 fn_8004B198 = .text:0x8004B198; // type:function size:0x320 @@ -1487,9 +1487,9 @@ PSMTXTransApply = .text:0x8009CEA8; // type:function size:0x4C PSMTXScale = .text:0x8009CEF4; // type:function size:0x28 PSMTXMultVec = .text:0x8009CF1C; // type:function size:0x54 C_MTXOrtho = .text:0x8009CF70; // type:function size:0x98 -fn_8009D008 = .text:0x8009D008; // type:function size:0x34 +PSMTX44Identity = .text:0x8009D008; // type:function size:0x34 PSMTX44Concat = .text:0x8009D03C; // type:function size:0x104 -fn_8009D140 = .text:0x8009D140; // type:function size:0x64 +PSMTXTranspose = .text:0x8009D140; // type:function size:0x64 PSMTX44MultVecNoW = .text:0x8009D1A4; // type:function size:0x54 __GXDefaultTexRegionCallback = .text:0x8009D1F8; // type:function size:0xF4 scope:local __GXDefaultTlutRegionCallback = .text:0x8009D2EC; // type:function size:0x24 scope:local diff --git a/config/oot-u/symbols.txt b/config/oot-u/symbols.txt index 6a3e76f..ba23dd9 100644 --- a/config/oot-u/symbols.txt +++ b/config/oot-u/symbols.txt @@ -643,8 +643,8 @@ frameUpdateCache = .text:0x800499C4; // type:function size:0x254 frameLoadTile = .text:0x80049C18; // type:function size:0x424 fn_8004A020 = .text:0x8004A03C; // type:function size:0x2F4 fn_8004A314 = .text:0x8004A330; // type:function size:0x388 -fn_8004A69C = .text:0x8004A6B8; // type:function size:0x200 -fn_8004A89C = .text:0x8004A8B8; // type:function size:0x200 +frameDrawSetupFog_StarFox = .text:0x8004A6B8; // type:function size:0x200 +frameDrawSetupFog_Default = .text:0x8004A8B8; // type:function size:0x200 ZeldaDrawFrame = .text:0x8004AAB8; // type:function size:0x324 ZeldaGreyScaleConvert = .text:0x8004ADDC; // type:function size:0x3D8 fn_8004B198 = .text:0x8004B1B4; // type:function size:0x320 @@ -1487,9 +1487,9 @@ PSMTXTransApply = .text:0x8009CEB4; // type:function size:0x4C PSMTXScale = .text:0x8009CF00; // type:function size:0x28 PSMTXMultVec = .text:0x8009CF28; // type:function size:0x54 C_MTXOrtho = .text:0x8009CF7C; // type:function size:0x98 -fn_8009D008 = .text:0x8009D014; // type:function size:0x34 +PSMTX44Identity = .text:0x8009D014; // type:function size:0x34 PSMTX44Concat = .text:0x8009D048; // type:function size:0x104 -fn_8009D140 = .text:0x8009D14C; // type:function size:0x64 +PSMTXTranspose = .text:0x8009D14C; // type:function size:0x64 PSMTX44MultVecNoW = .text:0x8009D1B0; // type:function size:0x54 __GXDefaultTexRegionCallback = .text:0x8009D204; // type:function size:0xF4 scope:local __GXDefaultTlutRegionCallback = .text:0x8009D2F8; // type:function size:0x24 scope:local diff --git a/include/emulator/frame.h b/include/emulator/frame.h index 6d2ae09..0256c0d 100644 --- a/include/emulator/frame.h +++ b/include/emulator/frame.h @@ -293,26 +293,26 @@ typedef struct Frame { /* 0x000B0 */ u32 nMode; /* 0x000B4 */ u32 aMode[FMT_COUNT]; /* 0x000DC */ Viewport viewport; - /* 0x000FC */ FrameBuffer aBuffer[FBT_COUNT]; + /* 0x000EC */ FrameBuffer aBuffer[FBT_COUNT]; /* 0x0013C */ u32 nOffsetDepth0; /* 0x00140 */ u32 nOffsetDepth1; /* 0x00144 */ s32 nWidthLine; /* 0x00148 */ f32 rDepth; /* 0x0014C */ f32 rDelta; - /* 0x00154 */ FrameDrawFunc aDraw[4]; + /* 0x00150 */ FrameDrawFunc aDraw[4]; /* 0x00160 */ s32 nCountLight; /* 0x00164 */ Light aLight[8]; - /* 0x00360 */ LookAt lookAt; + /* 0x00344 */ LookAt lookAt; /* 0x00378 */ s32 nCountVertex; - /* 0x00390 */ Vertex aVertex[80]; - /* 0x00C44 */ TextureMemory TMEM; + /* 0x0037C */ Vertex aVertex[80]; + /* 0x00C40 */ TextureMemory TMEM; /* 0x01C40 */ void* aPixelData; /* 0x01C44 */ void* aColorData; /* 0x01C48 */ s32 nBlocksPixel; - /* 0x01C54 */ s32 nBlocksMaxPixel; - /* 0x01C4C */ s32 nBlocksColor; - /* 0x01C58 */ s32 nBlocksMaxColor; - /* 0x01C50 */ s32 nBlocksTexture; + /* 0x01C4C */ s32 nBlocksMaxPixel; + /* 0x01C50 */ s32 nBlocksColor; + /* 0x01C54 */ s32 nBlocksMaxColor; + /* 0x01C58 */ s32 nBlocksTexture; /* 0x01C5C */ s32 nBlocksMaxTexture; /* 0x01C60 */ u32 anPackPixel[48]; /* 0x01D20 */ u32 anPackColor[320]; @@ -327,10 +327,10 @@ typedef struct Frame { /* 0x3E370 */ s32 iTileLoad; /* 0x3E374 */ u32 n2dLoadTexType; /* 0x3E378 */ s32 nLastX0; - /* 0x3E380 */ s32 nLastY0; - /* 0x3E384 */ s32 nLastX1; - /* 0x3E388 */ s32 nLastY1; - /* 0x3E3A8 */ Tile aTile[8]; + /* 0x3E37C */ s32 nLastY0; + /* 0x3E380 */ s32 nLastX1; + /* 0x3E384 */ s32 nLastY1; + /* 0x3E388 */ Tile aTile[8]; /* 0x3E4E8 */ s32 anSizeX[FS_COUNT]; /* 0x3E4F0 */ s32 anSizeY[FS_COUNT]; /* 0x3E4F8 */ s32 iHintMatrix; @@ -341,24 +341,23 @@ typedef struct Frame { /* 0x3E548 */ s32 iHintHack; /* 0x3E54C */ FrameMatrixProjection eTypeProjection; /* 0x3E550 */ Mtx44 aMatrixModel[10]; - /* 0x3E590 */ Mtx44 matrixProjection; - /* 0x3E5D0 */ Mtx44 matrixProjectionExtra; - /* 0x3E610 */ MatrixHint aMatrixHint[64]; - /* 0x3EF10 */ Mtx44 unknown; - /* 0x3EF10 */ Mtx44 unknown2; - s32 pad2[0x12]; // 1 Mtx44 + 2 floats? - /* 0x3F212 */ u8 primLODmin; - /* 0x3F214 */ u8 primLODfrac; - /* 0x3F218 */ u8 lastTile; - /* 0x3F21C */ u8 iTileDrawn; - /* 0x3F220 */ GXColor aColor[FCT_COUNT]; + /* 0x3E7D0 */ Mtx44 matrixProjection; + /* 0x3E810 */ Mtx44 matrixProjectionExtra; + /* 0x3E850 */ MatrixHint aMatrixHint[64]; + /* 0x3F150 */ Mtx44 unknown; + /* 0x3F190 */ Mtx44 unknown2; + /* 0x3F1D0 */ Mtx44 unknown3; + /* 0x3F210 */ f32 unk_3F210; // rNear + /* 0x3F214 */ f32 unk_3F214; // rFar + /* 0x3F218 */ u8 primLODmin; + /* 0x3F219 */ u8 primLODfrac; + /* 0x3F21A */ u8 lastTile; + /* 0x3F21B */ u8 iTileDrawn; + /* 0x3F21C */ GXColor aColor[FCT_COUNT]; /* 0x3F230 */ u32 nModeVtx; - - //! TODO: find which of these members got removed /* 0x3F234 */ u16* nTempBuffer; /* 0x3F238 */ u16* nCopyBuffer; - /* 0x3F23C */ u32* nLensBuffer; - // /* 0x3F008 */ u16* nCameraBuffer; + /* 0x3F23C */ u8* nCameraBuffer; } Frame; // size = 0x3F240 extern _XL_OBJECTTYPE gClassFrame; diff --git a/src/emulator/frame.c b/src/emulator/frame.c index 74854dc..b9ee1cd 100644 --- a/src/emulator/frame.c +++ b/src/emulator/frame.c @@ -250,6 +250,9 @@ static u32 gHackCreditsColor; bool gNoSwapBuffer; static bool snScissorChanged; +// TODO: identify this +static s32 lbl_8025D07C; + // .bss static u32 sConstantBufAddr[6] ATTRIBUTE_ALIGN(32); static u16 sTempZBuf[N64_FRAME_WIDTH * N64_FRAME_HEIGHT / 16][4][4] ATTRIBUTE_ALIGN(32); @@ -749,11 +752,155 @@ static bool frameLoadTile(Frame* pFrame, FrameTexture** ppTexture, s32 iTileCode // fn_8004A020 -// fn_8004A314 +static inline void fn_8004A314_inline(Mtx44 mtx, f32 a[4], f32 d) { + f32 length; + + a[0] = (d * mtx[0][2]) + mtx[0][3]; + a[1] = (d * mtx[1][2]) + mtx[1][3]; + a[2] = (d * mtx[2][2]) + mtx[2][3]; + a[3] = (d * mtx[3][2]) + mtx[3][3]; + + length = sqrt(SQ(a[0]) + SQ(a[1]) + SQ(a[2])); + + a[0] /= length; + a[1] /= length; + a[2] /= length; + a[3] /= length; +} + +void fn_8004A314(Frame* pFrame) { + Mtx44 sp28; + f32 sp18[4]; + f32 sp8[4]; + + f32 temp_f1_2; + f32 temp_f2_4; + f32 temp; + + if (pFrame->matrixProjection[0][3] != 0.0f || pFrame->matrixProjection[1][3] != 0.0f || + pFrame->matrixProjection[2][3] != 0.0f) { + PSMTXTranspose(pFrame->matrixProjection, sp28); + PSMTX44Identity(pFrame->unknown2); + PSMTX44Identity(pFrame->unknown3); + + pFrame->unknown2[2][0] = -sp28[3][0]; + pFrame->unknown2[2][1] = -sp28[3][1]; + pFrame->unknown2[2][2] = -sp28[3][2]; + pFrame->unknown2[2][3] = -sp28[3][3]; + + if (sp28[3][0] != 0.0f) { + pFrame->unknown3[2][2] = -sp28[2][0] / sp28[3][0]; + } else if (sp28[3][1] != 0.0f) { + pFrame->unknown3[2][2] = -sp28[2][1] / sp28[3][1]; + } else { + pFrame->unknown3[2][2] = -sp28[2][2] / sp28[3][2]; + } + + pFrame->unknown3[2][3] = -((pFrame->unknown3[2][2] * pFrame->unknown2[2][3]) - sp28[2][3]); + pFrame->unknown3[3][2] = -1.0f; + pFrame->unknown3[3][3] = 0.0f; + + pFrame->unknown3[1][2] = 1.0f; + pFrame->unknown2[1][0] = sp28[1][0] - pFrame->unknown2[2][0]; + pFrame->unknown2[1][1] = sp28[1][1] - pFrame->unknown2[2][1]; + pFrame->unknown2[1][2] = sp28[1][2] - pFrame->unknown2[2][2]; + pFrame->unknown2[1][3] = sp28[1][3] - pFrame->unknown2[2][3]; + + pFrame->unknown3[0][2] = 1.0f; + pFrame->unknown2[0][0] = sp28[0][0] - pFrame->unknown2[2][0]; + pFrame->unknown2[0][1] = sp28[0][1] - pFrame->unknown2[2][1]; + pFrame->unknown2[0][2] = sp28[0][2] - pFrame->unknown2[2][2]; + pFrame->unknown2[0][3] = sp28[0][3] - pFrame->unknown2[2][3]; + + PSMTXTranspose(pFrame->unknown2, pFrame->unknown2); + PSMTXTranspose(pFrame->unknown3, pFrame->unknown); + + fn_8004A314_inline(pFrame->unknown, sp18, -1.0f); + fn_8004A314_inline(pFrame->unknown, sp8, 1.0f); + + temp_f1_2 = sp8[3] * 0.1f; + temp_f2_4 = sp18[3] + temp_f1_2; + + pFrame->unknown3[2][2] = temp_f1_2 / temp_f2_4; + pFrame->unknown3[2][3] = temp_f1_2 * sp18[3] / temp_f2_4; + + pFrame->unk_3F210 = sp18[3]; + pFrame->unk_3F214 = -sp8[3]; + pFrame->eTypeProjection = FMP_PERSPECTIVE; + } else { + memcpy(pFrame->unknown2, pFrame->matrixProjection, sizeof(Mtx44)); + PSMTX44Identity(pFrame->unknown3); + memcpy(pFrame->unknown, pFrame->unknown3, sizeof(Mtx44)); + pFrame->unknown3[2][2] = -0.25f; + pFrame->unknown3[2][3] = -0.5f; + pFrame->unk_3F210 = 1.0f; + pFrame->unk_3F214 = 0.0f; + pFrame->eTypeProjection = FMP_ORTHOGRAPHIC; + } +} + +// frameDrawSetupFog_StarFox -// fn_8004A69C +bool frameDrawSetupFog_Default(Frame* pFrame) { + GXColor color; + GXFogType nFogType; + f32 rNear; + f32 rFar; + f32 rMultiplier; + f32 rOffset; + f32 rStart; + f32 rEnd; + f32 var_f6; + + rMultiplier = (s16)(pFrame->aMode[0] >> 16); + rOffset = (s16)(pFrame->aMode[0] & 0xFFFF); + + rFar = pFrame->unk_3F210; + rNear = pFrame->unk_3F214; + color = pFrame->aColor[FCT_FOG]; + nFogType = GX_FOG_EXP; + + if ((rOffset == rMultiplier) && (0.0f == rOffset)) { + GXSetFog(GX_FOG_NONE, color, 0.0f, 0.0f, 0.0f, 1000.0f); + return true; + } + var_f6 = -rOffset; + rStart = pFrame->unknown[3][2] / ((var_f6 / rMultiplier) - (pFrame->unknown[2][2] / pFrame->unknown[2][3])); + var_f6 = (249.0f + var_f6) / rMultiplier; + if (rStart < rNear) { + rStart = rNear; + } + if (rStart > rFar) { + rStart = rFar; + } + if (var_f6 > 1.2f) { + nFogType = GX_FOG_EXP; + rStart = -rOffset / rMultiplier; + rEnd = (rMultiplier + rOffset) / 256.0f; + rEnd = 1.0f - rEnd; + rEnd = rEnd * (rFar - rNear) + rNear; + } else { + if (var_f6 > 1.0f) { + var_f6 = 1.0f; + } + rEnd = pFrame->unknown[3][2] / (var_f6 - (pFrame->unknown[2][2] / pFrame->unknown[2][3])); + if (rEnd < rNear) { + rEnd = rNear; + } + if (rEnd > rFar) { + rEnd = rFar; + } + } -// fn_8004A89C + rNear *= 0.1f; + if (((pFrame->aMode[FMT_OTHER0] >> 26) & 3) == 1 || (pFrame->aMode[FMT_OTHER0] >> 30) == 3 || + ((pFrame->aMode[FMT_OTHER0] >> 22) & 3) == 3) { + GXSetFog(nFogType, color, rStart, rEnd, rNear, rFar); + } else { + GXSetFog(GX_FOG_NONE, color, 0.0f, 0.0f, 0.0f, 1000.0f); + } + return true; +} // matches but data doesn't //! TODO: make sFrameObj a static variable in the function @@ -929,10 +1076,10 @@ static void frameDrawSyncCallback(u16 nToken) { } } -bool fn_8004BF58(Frame* arg0) { +bool fn_8004BF58(Frame* pFrame) { GXColor color; - frameDrawSetup2D(arg0); + frameDrawSetup2D(pFrame); GXSetZMode(GX_DISABLE, GX_ALWAYS, GX_DISABLE); GXSetZCompLoc(GX_TRUE); GXSetColorUpdate(GX_ENABLE); @@ -1279,8 +1426,16 @@ static bool frameDrawSetupSP(Frame* pFrame, s32* pnColors, bool* pbFlag, s32 nVe if ((pFrame->nFlag & 0x40000) && (pFrame->nMode & 0x04000000)) { pFrame->nFlag &= ~0x40000; memcpy(matrix44, pFrame->matrixProjection, sizeof(Mtx44)); - eTypeProjection = pFrame->eTypeProjection == FMP_PERSPECTIVE ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC; - lbl_8025D098 = (pFrame->aMode[FMT_OTHER0] & 0xC00) == 0xC00 && eTypeProjection == GX_PERSPECTIVE; + if (pFrame->eTypeProjection == FMP_PERSPECTIVE) { + eTypeProjection = GX_PERSPECTIVE; + if ((pFrame->aMode[FMT_OTHER0] & 0xC00) == 0xC00) { + matrix44[2][3] = -((0.1f * (0.015f * pFrame->unk_3F214)) - matrix44[2][3]); + } + } else { + eTypeProjection = GX_ORTHOGRAPHIC; + } + lbl_8025D098 = eTypeProjection; + GXSetProjection(matrix44, eTypeProjection); pFrame->nMode &= ~0x40000000; } @@ -1503,9 +1658,16 @@ static bool frameDrawSetupDP(Frame* pFrame, s32* pnColors, bool* pbFlag, s32 ver pFrame->nFlag &= ~0x20; if ((pFrame->aMode[FMT_GEOMETRY] & 0x10)) { switch (gpSystem->eTypeROM) { + case NFXJ: + case NFXE: + case NFXP: + if (!frameDrawSetupFog_StarFox(pFrame)) { + return false; + } case CZLJ: - case NZSJ: - if (!frameDrawSetupFog_Zelda1(pFrame)) { + case CZLE: + case NZLP: + if (!frameDrawSetupFog_Default(pFrame)) { return false; } break; @@ -1974,20 +2136,6 @@ static bool frameCheckTriangleDivide(Frame* pFrame, Primitive* pPrimitive) { #pragma GLOBAL_ASM("asm/non_matchings/frame/frameDrawTriangle_C3T3.s") #else bool frameDrawTriangle_C3T3(Frame* pFrame, Primitive* pPrimitive) { - u32 pad[20]; - - if (gpSystem->eTypeROM == CZLJ && pPrimitive->nCount == 3 && (pFrame->aMode[FMT_OTHER0] & 0xC00) == 0xC00) { - Mtx44Ptr pMatrix = pFrame->aMatrixModel[pFrame->iMatrixModel]; - Vertex* vtx = &pFrame->aVertex[pPrimitive->anData[0]]; - if ((vtx->rSum == 53.0f && pMatrix[3][0] == -3080.0f && pMatrix[3][2] == 6067.0f) || - (pMatrix[3][0] == -31.0f && pMatrix[3][2] == 1669.0f)) { - if (pMatrix[3][0] == -31.0f && pMatrix[3][2] == 1669.0f) { - gHackCreditsColor = true; - } - return true; - } - } - if (pFrame->nModeVtx != 0x17) { GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_DIRECT); @@ -2402,23 +2550,6 @@ static bool frameDrawRectTexture(Frame* pFrame, Rectangle* pRectangle) { f32 rT1; s32 pad; - if (gpSystem->eTypeROM == NN6J) { - if (pRectangle->nX0 == 0 && pRectangle->nY0 == 0 && pRectangle->nX1 == 1208 && pRectangle->nY1 == 20) { - if (pFrame->aBuffer[FBT_IMAGE].nAddress != 0x3B5000 && pFrame->aBuffer[FBT_IMAGE].nAddress != 0x3DA800 && - !pFrame->bBackBufferDrawn) { - ZeldaDrawFrameNoBlend(pFrame, pFrame->nTempBuffer); - pFrame->bBackBufferDrawn = true; - nCounter = 0; - } - } - if (pFrame->bBackBufferDrawn == true) { - nCounter += 1; - if (nCounter < 40) { - return true; - } - } - } - if (sSpecialZeldaHackON) { return true; } @@ -2437,19 +2568,6 @@ static bool frameDrawRectTexture(Frame* pFrame, Rectangle* pRectangle) { rY0 = (pRectangle->nY0 + 3) >> 2; rY1 = (pRectangle->nY1 + 3) >> 2; - // TODO: regalloc hacks - // (void)pRectangle->nY0; - // if (gpSystem->eTypeROM == CZLJ) { - // if (pRectangle->nX0 == 816 && pRectangle->nY0 == 560) { - // if (gnCountMapHack < 0 && ++gnCountMapHack == 0) { - // gnCountMapHack = 1; - // } else if (gnCountMapHack > 0) { - // gnCountMapHack--; - // return true; - // } - // } - // } - if (pRectangle->bFlip) { rS0 = pRectangle->rS; rT0 = pRectangle->rT; @@ -2470,9 +2588,6 @@ static bool frameDrawRectTexture(Frame* pFrame, Rectangle* pRectangle) { } rDepth = 0.0f; - if (pFrame->bOverrideDepth) { - rDepth = -1001.0; - } if (pFrame->nModeVtx != 0xF) { GXClearVtxDesc(); @@ -3254,8 +3369,7 @@ bool frameEvent(Frame* pFrame, s32 nEvent, void* pArgument) { case 0x1003: pFrame->nTempBuffer = NULL; pFrame->nCopyBuffer = NULL; - pFrame->nLensBuffer = NULL; - // pFrame->nCameraBuffer = NULL; + pFrame->nCameraBuffer = NULL; if (!frameEvent_UnknownInline2(pFrame)) { return false; @@ -3609,6 +3723,7 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { f32 colorT; f32 rS; f32 rT; + Vec3f vec; f32 arNormal[3]; f32 arPosition[3]; Vertex* pVertex; @@ -3628,7 +3743,6 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { f32 rDiffuse; f32 rInverseW; f32 rInverseLength; - Vec3f vec; f32 distance; pnData8 = pBuffer; @@ -3642,13 +3756,15 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { // TODO: volatile hacks if (!(*(volatile u32*)&pFrame->nMode & 0x400000)) { if (!(pFrame->nMode & 0x08000000)) { - fn_8004A314(); + fn_8004A314(pFrame); pFrame->nMode |= 0x08000000; } - PSMTX44Concat(matrixModel, pFrame->matrixProjectionExtra, pFrame->matrixView); + PSMTX44Concat(matrixModel, pFrame->unknown2, pFrame->matrixView); pFrame->nMode |= 0x400000; } + matrixView = pFrame->matrixView; + if (pFrame->aMode[FMT_GEOMETRY] & 0x20) { nLight = pFrame->nCountLight; nTexGen = pFrame->aMode[FMT_GEOMETRY] & 0x180; @@ -3659,6 +3775,7 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { if (!pLight->bTransformed || !(pFrame->nMode & 0x200000)) { PSMTX44MultVecNoW(matrixModel, &pLight->rVecOrigTowards, &vec); rInverseLength = sqrt(SQ(vec.x) + SQ(vec.y) + SQ(vec.z)); + rInverseLength = 1.0f / rInverseLength; pLight->rVectorX = vec.x * rInverseLength; pLight->rVectorY = vec.y * rInverseLength; pLight->rVectorZ = vec.z * rInverseLength; @@ -3683,6 +3800,7 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { mag = SQ(pFrame->lookAt.rS.x) + SQ(pFrame->lookAt.rS.y) + SQ(pFrame->lookAt.rS.z); if (mag > 0.0f) { rInverseLength = sqrt(mag); + rInverseLength = 1.0f / rInverseLength; pFrame->lookAt.rS.x *= rInverseLength; pFrame->lookAt.rS.y *= rInverseLength; pFrame->lookAt.rS.z *= rInverseLength; @@ -3691,6 +3809,7 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { mag = SQ(pFrame->lookAt.rT.x) + SQ(pFrame->lookAt.rT.y) + SQ(pFrame->lookAt.rT.z); if (mag > 0.0f) { rInverseLength = sqrt(mag); + rInverseLength = 1.0f / rInverseLength; pFrame->lookAt.rT.x *= rInverseLength; pFrame->lookAt.rT.y *= rInverseLength; pFrame->lookAt.rT.z *= rInverseLength; @@ -3725,24 +3844,49 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { iLight = nLight; pLight = &aLight[iLight]; - if (gpSystem->eTypeROM == NFXJ) { - while ((rColorR = pLight->rColorR) + (rColorG = pLight->rColorG) + (rColorB = pLight->rColorB) == - 0.0f) { - pLight++; - } - pLight = &aLight[iLight]; - } else { + if (!(gpSystem->eTypeROM == NFXJ || gpSystem->eTypeROM == NFXE || gpSystem->eTypeROM == NFXP)) { rColorR = pLight->rColorR; rColorG = pLight->rColorG; rColorB = pLight->rColorB; + } else { + rColorR = aLight[7].rColorR; + rColorG = aLight[7].rColorG; + rColorB = aLight[7].rColorB; + + if (lbl_8025D07C == 0 && 20.0 == rColorR && 30.0 == rColorG && 50.0 == rColorB) { + lbl_8025D07C = 1; + } else if (lbl_8025D07C != 0) { + if (rColorR < 20.0 && rColorG < 30.0 && rColorB < 50.0) { + s32 temp_r16; + u8 sp38[10][3] = { + {0x14, 0x1E, 0x32}, {0x12, 0x1B, 0x2F}, {0x10, 0x18, 0x28}, {0x0E, 0x15, 0x23}, + {0x0C, 0x12, 0x1E}, {0x0A, 0x0F, 0x19}, {0x08, 0x0C, 0x14}, {0x06, 0x09, 0x0F}, + {0x04, 0x06, 0x0A}, {0x02, 0x03, 0x05}, + }; + + temp_r16 = 10 - (((s32)rColorR + 1) / 2); + if (temp_r16 == 10) { + temp_r16 = 9; + } + rColorR = sp38[temp_r16][0]; + rColorG = sp38[temp_r16][1]; + rColorB = sp38[temp_r16][2]; + } else if (rColorR > 20.0 && rColorG > 30.0 && rColorB >= 50.0) { + lbl_8025D07C = 0; + } + } + pLight = &aLight[iLight]; } while (--iLight >= 0) { pLight--; if ((pFrame->aMode[1] & 0x800) && pLight->kc != 0.0f) { + // TODO: fake? + s16 coordX = pLight->coordX; + distance = sqrtf(SQ(pLight->coordX - arPosition[0]) + SQ(pLight->coordY - arPosition[1]) + SQ(pLight->coordZ - arPosition[2])); - pLight->rVectorX = (pLight->coordX - arPosition[0]) / distance; + pLight->rVectorX = (coordX - arPosition[0]) / distance; pLight->rVectorY = (pLight->coordY - arPosition[1]) / distance; pLight->rVectorZ = (pLight->coordZ - arPosition[2]) / distance; rDiffuse = (pLight->rVectorX * arNormal[0] + pLight->rVectorY * arNormal[1] + @@ -3821,6 +3965,9 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { if (nTexGen == 0) { s16tof32Scaled32Pair(&pnData16[4], &pVertex->rS); + if (gpSystem->eTypeROM == NSMJ && pFrame->bBlurOn && pVertex->rS == 0.0) { + pVertex->rS -= 2.0; + } } pVertex++; @@ -3828,7 +3975,7 @@ bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount) { pnData16 += 0x8; } - if (gpSystem->eTypeROM = NSMJ && pFrame->bBlurOn) { + if (gpSystem->eTypeROM == NSMJ && pFrame->bBlurOn) { pFrame->bBlurOn = false; } diff --git a/src/revolution/mtx/mtx44.c b/src/revolution/mtx/mtx44.c index 26bf833..09a3ce0 100644 --- a/src/revolution/mtx/mtx44.c +++ b/src/revolution/mtx/mtx44.c @@ -28,8 +28,7 @@ void C_MTXOrtho(Mtx44 mtx, f32 t, f32 b, f32 l, f32 r, f32 n, f32 f) { mtx[3][3] = 1.0f; } -//! TODO: name this -void fn_8009D008(Mtx44 m, Mtx44* src, Mtx44* dst) { +void PSMTX44Identity(const register Mtx44 m) { f32 one = 1.0f; f32 zero = 0.0f; @@ -122,8 +121,7 @@ ASM void PSMTX44Concat(const register Mtx44 mA, const register Mtx44 mB, registe #endif // clang-format on } -//! TODO: name this -ASM void fn_8009D140(Mtx44 m, Mtx44* src, Mtx44* dst){ +ASM void PSMTXTranspose(const register Mtx44 src, register Mtx44 dst){ #ifdef __MWERKS__ // clang-format off nofralloc