Match RSP update functions and rdpParseGBI (#97)

* Match rspParseGBI

* Match rdpParseGBI

* Match rspUpdate

* Match rspParseGBI_Setup

* Match rspFrameComplete
This commit is contained in:
cadmic
2024-05-06 11:59:13 -07:00
committed by GitHub
parent 57d9f7bdf4
commit 3bfdcb485f
8 changed files with 844 additions and 29 deletions
+4 -4
View File
@@ -15,10 +15,10 @@ typedef struct _GXRenderModeObj {
/* 0x10 */ u16 viHeight;
/* 0x14 */ VIXFBMode xFBmode;
/* 0x18 */ u8 field_rendering;
/* 0x?? */ u8 aa;
/* 0x?? */ u8 sample_pattern[12][2];
/* 0x?? */ u8 vfilter[7];
} GXRenderModeObj;
/* 0x19 */ u8 aa;
/* 0x1A */ u8 sample_pattern[12][2];
/* 0x32 */ u8 vfilter[7];
} GXRenderModeObj; // size = 0x3C
typedef struct _GXColor {
u8 r;
+19 -3
View File
@@ -3,6 +3,7 @@
#include "dolphin.h"
#include "emulator/rdp.h"
#include "emulator/rsp.h"
#include "emulator/xlObject.h"
#define FRAME_SYNC_TOKEN 0x7D00
@@ -286,7 +287,7 @@ typedef struct Frame {
/* 0x0008C */ u32 nMode;
/* 0x00090 */ u32 aMode[FMT_COUNT];
/* 0x000B8 */ Viewport viewport;
/* 0x000C8 */ FrameBuffer aBuffer[4];
/* 0x000C8 */ FrameBuffer aBuffer[FBT_COUNT];
/* 0x00118 */ u32 nOffsetDepth0;
/* 0x0011C */ u32 nOffsetDepth1;
/* 0x00120 */ s32 nWidthLine;
@@ -386,9 +387,24 @@ bool frameBeginOK(Frame* pFrame);
bool frameBegin(Frame* pFrame, s32 nCountVertex);
bool frameEnd(Frame* pFrame);
bool frameDrawReset(Frame* pFrame, s32 nFlag);
bool frameSetBuffer(Frame* pFrame, FrameBufferType eType);
bool frameSetFill(Frame* pFrame, bool bFill);
bool frameSetSize(Frame* pFrame, FrameSize eSize, s32 nSizeX, s32 nSizeY);
bool frameFixMatrixHint(Frame* pFrame, u32 nAddressFloat, u32 nAddressFixed);
bool frameSetMode(Frame* pFrame, FrameModeType eType, u32 nMode);
bool frameGetMode(Frame* pFrame, FrameModeType eType, u32* pnMode);
bool frameSetMatrix(Frame* pFrame, Mtx44 matrix, FrameMatrixType eType, bool bLoad, bool bPush, s32 nAddressN64);
bool frameGetMatrix(Frame* pFrame, Mtx44 matrix, FrameMatrixType eType, bool bPull);
bool frameLoadVertex(Frame* pFrame, void* pBuffer, s32 iVertex0, s32 nCount);
bool frameCullDL(Frame* pFrame, s32 nVertexStart, s32 nVertexEnd);
bool frameLoadTLUT(Frame* pFrame, s32 nCount, s32 iTile);
bool frameLoadTMEM(Frame* pFrame, FrameLoadType eType, s32 iTile);
bool frameSetLightCount(Frame* pFrame, s32 nCount);
bool frameSetLight(Frame* pFrame, s32 iLight, s8* pData);
bool frameSetLookAt(Frame* pFrame, s32 iLookAt, s8* pData);
bool frameSetViewport(Frame* pFrame, s16* pData);
bool frameResetUCode(Frame* pFrame, RspUCodeType eType);
bool frameSetBuffer(Frame* pFrame, FrameBufferType eType);
bool frameFixMatrixHint(Frame* pFrame, s32 nAddressFloat, s32 nAddressFixed);
bool frameSetMatrixHint(Frame* pFrame, FrameMatrixProjection eProjection, s32 nAddressFloat, s32 nAddressFixed,
f32 rNear, f32 rFar, f32 rFOVY, f32 rAspect, f32 rScale);
bool frameInvalidateCache(Frame* pFrame, s32 nOffset0, s32 nOffset1);
+3 -2
View File
@@ -2,9 +2,9 @@
#define _RDP_H
#include "dolphin.h"
#include "emulator/rsp.h"
#include "emulator/xlObject.h"
// __anon_0x52CD0
typedef struct Rdp {
/* 0x00 */ s32 nBIST;
/* 0x04 */ s32 nStatus;
@@ -20,7 +20,8 @@ typedef struct Rdp {
/* 0x2C */ s32 nClockTMEM;
} Rdp; // size = 0x30
s32 rdpEvent(Rdp* pRDP, s32 nEvent, void* pArgument);
bool rdpParseGBI(Rdp* pRDP, u64** ppnGBI, RspUCodeType eTypeUCode);
bool rdpEvent(Rdp* pRDP, s32 nEvent, void* pArgument);
extern _XL_OBJECTTYPE gClassRDP;
+10 -10
View File
@@ -19,7 +19,7 @@ typedef enum __anon_0x581E7 {
RUT_UNKNOWN = 4,
} __anon_0x581E7;
typedef enum __anon_0x60B3F {
typedef enum RspUCodeType {
RUT_NONE = -1,
RUT_TURBO = 0,
RUT_SPRITE2D = 1,
@@ -35,7 +35,7 @@ typedef enum __anon_0x60B3F {
RUT_AUDIO1 = 11,
RUT_AUDIO2 = 12,
RUT_JPEG = 13,
} __anon_0x60B3F;
} RspUCodeType;
// __anon_0x44829
typedef enum RspUpdateMode {
@@ -43,7 +43,7 @@ typedef enum RspUpdateMode {
RUM_IDLE = 1,
} RspUpdateMode;
typedef struct __anon_0x575BD {
typedef struct RspTask {
/* 0x00 */ s32 nType;
/* 0x04 */ s32 nFlag;
/* 0x08 */ s32 nOffsetBoot;
@@ -60,19 +60,19 @@ typedef struct __anon_0x575BD {
/* 0x34 */ s32 nLengthMBI;
/* 0x38 */ s32 nOffsetYield;
/* 0x3C */ s32 nLengthYield;
} __anon_0x575BD; // size = 0x40
} RspTask; // size = 0x40
typedef struct __anon_0x57890 {
typedef struct RspYield {
/* 0x00 */ s32 iDL;
/* 0x04 */ bool bValid;
/* 0x08 */ struct __anon_0x575BD task;
/* 0x08 */ RspTask task;
/* 0x48 */ s32 nCountVertex;
/* 0x4C */ __anon_0x60B3F eTypeUCode;
/* 0x4C */ RspUCodeType eTypeUCode;
/* 0x50 */ u32 n2TriMult;
/* 0x54 */ u32 nVersionUCode;
/* 0x58 */ s32 anBaseSegment[16];
/* 0x98 */ u64* apDL[16];
} __anon_0x57890; // size = 0xD8
} RspYield; // size = 0xD8
typedef struct __anon_0x57AB1 {
/* 0x00 */ f32 aRotations[2][2];
@@ -119,7 +119,7 @@ typedef struct __anon_0x58107 {
// __anon_0x5845E
typedef struct Rsp {
/* 0x0000 */ s32 nMode;
/* 0x0004 */ struct __anon_0x57890 yield;
/* 0x0004 */ RspYield yield;
/* 0x00DC */ u32 nTickLast;
/* 0x00E0 */ s32 (*pfUpdateWaiting)(void);
/* 0x00E4 */ u32 n2TriMult;
@@ -200,7 +200,7 @@ typedef struct Rsp {
/* 0x3914 */ s32 nAddressRDRAM;
/* 0x3918 */ struct tXL_LIST* pListUCode;
/* 0x391C */ s32 nCountVertex;
/* 0x3920 */ enum __anon_0x60B3F eTypeUCode;
/* 0x3920 */ RspUCodeType eTypeUCode;
/* 0x3924 */ u32 nVersionUCode;
/* 0x3928 */ s32 anBaseSegment[16];
/* 0x3968 */ u64* apDL[16];
+6 -6
View File
@@ -621,7 +621,7 @@ static bool frameCheckTriangleDivide(Frame* pFrame, Primitive* pPrimitive);
bool frameDrawTriangle_C3T3(Frame* pFrame, Primitive* pPrimitive) {
u32 pad[20];
if (gpSystem->eTypeROM == SRT_ZELDA1 && pPrimitive->nCount == 3 && (pFrame->aMode[4] & 0xC00) == 0xC00) {
if (gpSystem->eTypeROM == SRT_ZELDA1 && 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) ||
@@ -863,7 +863,7 @@ bool frameEnd(Frame* pFrame) {
pFrame->nCountFrames++;
gbFrameValid = true;
if (pFrame->aBuffer[0].nAddress != 0) {
if (pFrame->aBuffer[FBT_DEPTH].nAddress != 0) {
pData = &sTempZBuf;
GXSetTexCopySrc(0, 0, GC_FRAME_WIDTH, GC_FRAME_HEIGHT);
@@ -1454,7 +1454,7 @@ bool frameHackCIMG_Zelda2(Frame* pFrame, FrameBuffer* pBuffer, u64* pnGBI, u32 n
u32* pGBI;
s32 pad[2];
if (pBuffer->nAddress == pFrame->aBuffer[0].nAddress) {
if (pBuffer->nAddress == pFrame->aBuffer[FBT_DEPTH].nAddress) {
pFrame->nHackCount += 1;
}
@@ -1541,7 +1541,7 @@ bool frameHackCIMG_Zelda(Frame* pFrame, FrameBuffer* pBuffer, u64* pnGBI, u32 nC
}
}
if (pBuffer->nAddress == pFrame->aBuffer[0].nAddress && pBuffer->nWidth == N64_FRAME_WIDTH) {
if (pBuffer->nAddress == pFrame->aBuffer[FBT_DEPTH].nAddress && pBuffer->nWidth == N64_FRAME_WIDTH) {
low2 = pnGBI[1];
high2 = pnGBI[1] >> 32;
if (high2 == 0xFD10013F) {
@@ -2529,13 +2529,13 @@ bool frameSetLookAt(Frame* pFrame, s32 iLookAt, s8* pData) {
bool frameSetBuffer(Frame* pFrame, FrameBufferType eType) {
if (((u32)(eType - 2) > 1) && (eType == FBT_DEPTH)) {
pFrame->nOffsetDepth0 = pFrame->aBuffer[0].nAddress & 0x03FFFFFF;
pFrame->nOffsetDepth0 = pFrame->aBuffer[FBT_DEPTH].nAddress & 0x03FFFFFF;
pFrame->nOffsetDepth1 = pFrame->nOffsetDepth0 + 0x257FC;
}
return true;
}
bool frameFixMatrixHint(Frame* pFrame, u32 nAddressFloat, u32 nAddressFixed) {
bool frameFixMatrixHint(Frame* pFrame, s32 nAddressFloat, s32 nAddressFixed) {
s32 iHint;
s32 iHintTest;
+592
View File
File diff suppressed because it is too large Load Diff
+209 -3
View File
@@ -1,5 +1,6 @@
#include "emulator/rsp.h"
#include "emulator/cpu.h"
#include "emulator/frame.h"
#include "emulator/ram.h"
#include "emulator/rdp.h"
#include "emulator/rsp_jumptables.h"
@@ -47,10 +48,15 @@ void* jtbl_800EE338[29] = {
&lbl_80072998, &lbl_80072948, &lbl_80072948, &lbl_80072948, &lbl_8007293C,
};
#ifndef NON_MATCHING
// rspParseGBI
void* jtbl_800EE3AC[11] = {
&lbl_80072AC0, &lbl_80072AC0, &lbl_80072AC0, &lbl_80072AD4, &lbl_80072AE8, &lbl_80072AC0,
&lbl_80072AD4, &lbl_80072AC0, &lbl_80072AD4, &lbl_80072AC0, &lbl_80072AD4,
};
#else
void* jtbl_800EE3AC[11] = {0};
#endif
void* jtbl_800EE3D8[13] = {
&lbl_80075608, &lbl_8007600C, &lbl_8007600C, &lbl_8007600C, &lbl_80075630, &lbl_8007600C, &lbl_8007600C,
@@ -313,10 +319,12 @@ const f32 D_80136074 = 1.52587890625e-05;
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspSetGeometryMode1.s")
static bool rspParseGBI_F3DEX1(Rsp* pRSP, u64** ppnGBI, bool* pbDone);
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspParseGBI_F3DEX1.s")
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspGeometryMode.s")
static bool rspParseGBI_F3DEX2(Rsp* pRSP, u64** ppnGBI, bool* pbDone);
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspParseGBI_F3DEX2.s")
// Matches but data doesn't
@@ -446,15 +454,147 @@ static bool rspLoadMatrix(Rsp* pRSP, s32 nAddress, Mtx44 matrix) {
}
#endif
inline bool rspSetDL(Rsp* pRSP, s32 nOffsetRDRAM, bool bPush) {
s32 nAddress;
s32* pDL;
nAddress = SEGMENT_ADDRESS(pRSP, nOffsetRDRAM);
if (!ramGetBuffer(SYSTEM_RAM(pRSP->pHost), &pDL, nAddress, NULL)) {
return false;
}
if (bPush && ++pRSP->iDL >= ARRAY_COUNT(pRSP->apDL)) {
return false;
}
pRSP->apDL[pRSP->iDL] = (u64*)pDL;
return true;
}
inline bool rspPopDL(Rsp* pRSP) {
if (pRSP->iDL == 0) {
return false;
} else {
pRSP->iDL--;
return true;
}
}
static bool rspFindUCode(Rsp* pRSP, RspTask* pTask);
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspFindUCode.s")
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspSaveYield.s")
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspLoadYield.s")
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspParseGBI_Setup.s")
static bool rspParseGBI_Setup(Rsp* pRSP, RspTask* pTask) {
s32 iSegment;
if (pRSP->yield.bValid) {
pRSP->yield.bValid = false;
}
pRSP->nGeometryMode = 0;
pRSP->iDL = 0;
if (!rspSetDL(pRSP, pTask->nOffsetMBI & 0x7FFFFF, false)) {
return false;
}
for (iSegment = 0; iSegment < ARRAY_COUNT(pRSP->anBaseSegment); iSegment++) {
pRSP->anBaseSegment[iSegment] = 0;
}
if (!rspFindUCode(pRSP, pTask)) {
return false;
}
if (pRSP->eTypeUCode != RUT_ZSORT || pRSP->nPass == 1) {
if (!frameBegin(SYSTEM_FRAME(pRSP->pHost), pRSP->nCountVertex)) {
return false;
}
}
PAD_STACK();
return true;
}
// Matches but data doesn't
#ifndef NON_MATCHING
static bool rspParseGBI(Rsp* pRSP, bool* pbDone, s32 nCount);
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspParseGBI.s")
#else
static bool rspParseGBI(Rsp* pRSP, bool* pbDone, s32 nCount) {
bool bDone;
s32 nStatus;
u64* pDL;
Cpu* pCPU;
pCPU = SYSTEM_CPU(pRSP->pHost);
bDone = false;
while (!bDone) {
pDL = pRSP->apDL[pRSP->iDL];
switch (pRSP->eTypeUCode) {
case RUT_TURBO:
case RUT_SPRITE2D:
case RUT_FAST3D:
case RUT_F3DEX1:
case RUT_S2DEX1:
case RUT_L3DEX1:
nStatus = rspParseGBI_F3DEX1(pRSP, &pRSP->apDL[pRSP->iDL], &bDone);
break;
case RUT_ZSORT:
case RUT_F3DEX2:
case RUT_S2DEX2:
case RUT_L3DEX2:
nStatus = rspParseGBI_F3DEX2(pRSP, &pRSP->apDL[pRSP->iDL], &bDone);
break;
default:
return false;
}
if (nStatus == 0) {
pRSP->apDL[pRSP->iDL] = pDL;
if (!rdpParseGBI(SYSTEM_RDP(pRSP->pHost), &pRSP->apDL[pRSP->iDL], pRSP->eTypeUCode)) {
if (!rspPopDL(pRSP)) {
bDone = true;
}
}
}
if (nCount == -1) {
if (pCPU->nRetrace != pCPU->nRetraceUsed) {
break;
}
} else if (nCount != 0) {
if (--nCount == 0) {
break;
}
}
}
if (pRSP->eTypeUCode == RUT_ZSORT) {
if (pRSP->nPass == 1) {
pRSP->nPass = 2;
} else {
pRSP->nPass = 1;
}
} else {
pRSP->nPass = 2;
}
if (bDone) {
pRSP->nMode |= 8;
}
if (pbDone != NULL) {
*pbDone = bDone;
}
return true;
}
#endif
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspPut8.s")
@@ -476,8 +616,74 @@ static bool rspLoadMatrix(Rsp* pRSP, s32 nAddress, Mtx44 matrix) {
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspEnableABI.s")
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspFrameComplete.s")
bool rspFrameComplete(Rsp* pRSP) {
if (pRSP->yield.bValid) {
OSReport(D_800EE27C);
}
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspUpdate.s")
pRSP->nMode |= 4;
return true;
}
bool rspUpdate(Rsp* pRSP, RspUpdateMode eMode) {
RspTask* pTask;
bool bDone;
s32 nCount = 0;
Frame* pFrame = SYSTEM_FRAME(pRSP->pHost);
if ((pRSP->nMode & 4) && (pRSP->nMode & 8)) {
if (pRSP->nMode & 0x10) {
gNoSwapBuffer = true;
pRSP->nMode |= 0x20;
}
if (!frameEnd(pFrame)) {
return false;
}
pRSP->nMode &= ~0xC;
}
if (!(pRSP->nStatus & 1)) {
if (pRSP->nMode & 0x20) {
pRSP->nMode &= ~0x30;
pRSP->nStatus |= 0x201;
xlObjectEvent(pRSP->pHost, 0x1000, (void*)5);
xlObjectEvent(pRSP->pHost, 0x1000, (void*)10);
} else {
if (pRSP->nMode & 2) {
if (frameBeginOK(pFrame) && eMode == RUM_IDLE) {
pRSP->nMode &= ~0x2;
pRSP->nMode |= 0x10;
pTask = (RspTask*)((u8*)pRSP->pDMEM + 0xFC0);
if (!rspParseGBI_Setup(pRSP, pTask)) {
return false;
}
} else {
return true;
}
}
if (eMode == RUM_IDLE) {
nCount = -1;
}
if (nCount != 0) {
if (rspParseGBI(pRSP, &bDone, nCount)) {
if (bDone) {
pRSP->nMode &= ~0x10;
pRSP->nStatus |= 0x201;
xlObjectEvent(pRSP->pHost, 0x1000, (void*)5);
xlObjectEvent(pRSP->pHost, 0x1000, (void*)10);
}
} else {
__cpuBreak(SYSTEM_CPU(pRSP->pHost));
}
pRSP->nTickLast = OSGetTick();
}
}
}
return true;
}
#pragma GLOBAL_ASM("asm/non_matchings/rsp/rspEvent.s")
+1 -1
View File
@@ -26,7 +26,7 @@ bool videoPut32(Video* pVideo, u32 nAddress, s32* pData) {
case 0x4:
pVideo->nAddress = *pData & 0xFFFFFF;
pFrame = SYSTEM_FRAME(pVideo->pHost);
pBuffer = &pFrame->aBuffer[2];
pBuffer = &pFrame->aBuffer[FBT_COLOR_SHOW];
if (!ramGetBuffer(SYSTEM_RAM(pVideo->pHost), &pRAM, pVideo->nAddress, NULL)) {
return false;