Skip to content

Commit

Permalink
GX work, GXData struct should be correct now
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Nov 2, 2024
1 parent d264788 commit 89c74d0
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 340 deletions.
5 changes: 4 additions & 1 deletion include/dolphin/gx/GX.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ extern "C" {
#endif

// Pack value into bitfield
#define GX_BITFIELD_SET(field, pos, size, value) (field) = __rlwimi((field), (value), 31 - (pos) - (size) + 1, (pos), (pos) + (size)-1)
#define GX_BITFIELD_SET(field, pos, size, value) \
(field) = \
(field & ~(((1 << (size)) - 1) << (31 - (pos) - (size) + 1))) | \
((int)(value) << (31 - (pos) - (size) + 1))
#define GX_BITFIELD_TRUNC(field, pos, size, value) (__rlwimi((field), (value), 0, (pos), (pos) + (size)-1))

#define GX_BITGET(field, pos, size) ((field) >> (31 - (pos) - (size) + 1) & ((1 << (size)) - 1))
Expand Down
1 change: 0 additions & 1 deletion include/dolphin/gx/GXEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,6 @@ typedef enum _GXMiscToken {
GX_MT_NULL = 0,
GX_MT_XF_FLUSH = 1,
GX_MT_DL_SAVE_CONTEXT = 2,
GX_MT_ABORT_WAIT_COPYOUT = 3,
} GXMiscToken;

// Transform memory types.
Expand Down
68 changes: 34 additions & 34 deletions include/dolphin/gx/GXInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,52 +80,52 @@ typedef struct _GXData {

// Texture regions
/* 0x208 */ GXTexRegion TexRegions0[GX_MAX_TEXMAP];
/* 0x288 */ GXTexRegion TexRegions1[GX_MAX_TEXMAP];
/* 0x308 */ GXTexRegion TexRegions2[GX_MAX_TEXMAP];
/* 0x288 */ GXTexRegion TexRegions1[4];
/* 0x2C8 */ u32 m2C8;
/* 0x2C8 */ u32 m2CC;

// Texture lookup table regions
/* 0x388 */ GXTlutRegion TlutRegions[GX_MAX_TLUT_ALL];
/* 0x4C8 */ GXTexRegionCallback texRegionCallback;
/* 0x4CC */ GXTlutRegionCallback tlutRegionCallback;
/* 0x2D0 */ GXTlutRegion TlutRegions[GX_MAX_TLUT_ALL];
/* 0x410 */ GXTexRegionCallback texRegionCallback;
/* 0x414 */ GXTlutRegionCallback tlutRegionCallback;

// Command processor vars
/* 0x4D0 */ GXAttrType nrmType;
/* 0x4D4 */ GXBool hasNrms;
/* 0x4D5 */ GXBool hasBiNrms;
/* 0x4D8 */ u32 projType;
/* 0x4DC */ f32 projMtx[6];
/* 0x418 */ GXAttrType nrmType;
/* 0x41C */ GXBool hasNrms;
/* 0x41D */ GXBool hasBiNrms;
/* 0x420 */ u32 projType;
/* 0x424 */ f32 projMtx[6];

// Viewport parms
/* 0x4F4 */ f32 vpLeft;
/* 0x4F8 */ f32 vpTop;
/* 0x4FC */ f32 vpWd;
/* 0x500 */ f32 vpHt;
/* 0x504 */ f32 vpNearz;
/* 0x508 */ f32 vpFarz;
/* 0x50C */ f32 zOffset;
/* 0x510 */ f32 zScale;
/* 0x43C */ f32 vpLeft;
/* 0x440 */ f32 vpTop;
/* 0x444 */ f32 vpWd;
/* 0x448 */ f32 vpHt;
/* 0x44C */ f32 vpNearz;
/* 0x450 */ f32 vpFarz;
/* 0x454 */ f32 zOffset;
/* 0x458 */ f32 zScale;

// Texture regs
/* 0x514 */ u32 tImage0[8];
/* 0x534 */ u32 tMode0[8];
/* 0x554 */ u32 texmapId[16];
/* 0x594 */ u32 tcsManEnab;
/* 0x598 */ u32 tevTcEnab;
/* 0x45C */ u32 tImage0[8];
/* 0x47C */ u32 tMode0[8];
/* 0x49C */ u32 texmapId[16];
/* 0x4DC */ u32 tcsManEnab;
/* 0x4E0 */ u32 tevTcEnab;

// Performance metrics
/* 0x59C */ GXPerf0 perf0;
/* 0x5A0 */ GXPerf1 perf1;
/* 0x5A4 */ u32 perfSel;
/* 0x4E4 */ GXPerf0 perf0;
/* 0x4E8 */ GXPerf1 perf1;
/* 0x4EC */ u32 perfSel;

// Flags
/* 0x5A8 */ GXBool inDispList;
/* 0x5A9 */ GXBool dlSaveContext;
/* 0x5AA */ GXBool abtWaitPECopy;
/* 0x5AB */ u8 dirtyVAT;
/* 0x5AC */ u32 dirtyState;
} GXData; // Size: 0x5B0

STATIC_ASSERT(sizeof(GXData) == 0x5B0);
/* 0x4F0 */ GXBool inDispList;
/* 0x4F1 */ GXBool dlSaveContext;
/* 0x4F2 */ u8 dirtyVAT;
/* 0x4F4 */ u32 dirtyState;
} GXData; // Size: 0x4F8

STATIC_ASSERT(sizeof(GXData) == 0x4F8);

extern GXData* const __GXData;

Expand Down
118 changes: 28 additions & 90 deletions src/dolphin/gx/GXInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ GXTexRegion* __GXDefaultTexRegionCallback(const GXTexObj* obj, GXTexMapID id) {

switch (format) {
case GX_TF_RGBA8:
if (isMipMap) {
return &__GXData->TexRegions2[id];
}
// if (isMipMap) {
// return &__GXData->TexRegions2[id];
// }
return &__GXData->TexRegions1[id];

case GX_TF_C4:
Expand Down Expand Up @@ -63,68 +63,15 @@ u16* __cpReg;
/* ############################################################################################## */
u32* __piReg;

BOOL __GXShutdown(BOOL final) {
u32 val;
u32 newPeCount;
OSTime newTime;

if (!final) {
if (!calledOnce) {
peCount = GXReadMEMReg(0x28, 0x27);
time = OSGetTime();
calledOnce = 1;
return FALSE;
}

newTime = OSGetTime();
newPeCount = GXReadMEMReg(0x28, 0x27);

if (newTime - time < 10) {
return FALSE;
}

if (newPeCount != peCount) {
peCount = newPeCount;
time = newTime;
return FALSE;
}

} else {
GXSetBreakPtCallback(NULL);
GXSetDrawSyncCallback(NULL);
GXSetDrawDoneCallback(NULL);

GX_WRITE_U32(0);
GX_WRITE_U32(0);
GX_WRITE_U32(0);
GX_WRITE_U32(0);
GX_WRITE_U32(0);
GX_WRITE_U32(0);
GX_WRITE_U32(0);
GX_WRITE_U32(0);

PPCSync();

GX_SET_CP_REG(1, 0);
GX_SET_CP_REG(2, 3);

__GXData->abtWaitPECopy = GX_TRUE;

__GXAbort();
}

return TRUE;
}

void __GXInitRevisionBits(void) {
inline void __GXInitRevisionBits(void) {
u32 i;
for (i = 0; i < 8; i++) {
FAST_FLAG_SET(__GXData->vatA[i], 1, 30, 33);
FAST_FLAG_SET(__GXData->vatB[i], 1, 31, 33);

GX_WRITE_U8(0x8);
GX_WRITE_U8(i | 0x80);
GX_WRITE_U32(__GXData->vatB[i]);
GXFIFO.u8 = 0x8;
GXFIFO.u8 = i | 0x80;
GXFIFO.u32 = __GXData->vatB[i];
}

{
Expand All @@ -137,14 +84,14 @@ void __GXInitRevisionBits(void) {
FAST_FLAG_SET(reg1, 1, 3, 1);
FAST_FLAG_SET(reg1, 1, 4, 1);
FAST_FLAG_SET(reg1, 1, 5, 1);
GX_WRITE_U8(0x10);
GX_WRITE_U32(0x1000);
GX_WRITE_U32(reg1);
GXFIFO.u8 = 0x10;
GXFIFO.u32 = 0x1000;
GXFIFO.u32 = reg1;

FAST_FLAG_SET(reg2, 1, 0, 1);
GX_WRITE_U8(0x10);
GX_WRITE_U32(0x1012);
GX_WRITE_U32(reg2);
GXFIFO.u8 = 0x10;
GXFIFO.u32 = 0x1012;
GXFIFO.u32 = reg2;
}

{
Expand All @@ -154,8 +101,7 @@ void __GXInitRevisionBits(void) {
FAST_FLAG_SET(reg, 1, 2, 1);
FAST_FLAG_SET(reg, 1, 3, 1);
FAST_FLAG_SET(reg, 0x58, 24, 8);
GX_WRITE_U8(0x61);
GX_WRITE_U32(reg);
GFWriteBPCmd(reg);
}
}

Expand Down Expand Up @@ -190,8 +136,6 @@ static u32 GXTexRegionAddrTable[] = {
0x80000, 0x10000, 0xA0000, 0x30000, 0x80000, 0x50000, 0xA0000, 0x70000,
};

static OSResetFunctionInfo GXResetFuncInfo = {__GXShutdown, OS_RESET_PRIO_GX};

static void EnableWriteGatherPipe() {
u32 hid2; // r31
hid2 = PPCMfhid2();
Expand All @@ -207,7 +151,6 @@ GXFifoObj* GXInit(void* base, u32 size) {
OSRegisterVersion(__GXVersion);
__GXData->inDispList = GX_FALSE;
__GXData->dlSaveContext = GX_TRUE;
__GXData->abtWaitPECopy = GX_TRUE;

__GXData->tcsManEnab = 0;
__GXData->tevTcEnab = 0;
Expand All @@ -226,7 +169,7 @@ GXFifoObj* GXInit(void* base, u32 size) {
GXSetGPFifo(&FifoObj);

if (!resetFuncRegistered) {
OSRegisterResetFunction(&GXResetFuncInfo);
// OSRegisterResetFunction(&GXResetFuncInfo);
resetFuncRegistered = 1;
}

Expand Down Expand Up @@ -292,14 +235,12 @@ GXFifoObj* GXInit(void* base, u32 size) {

val1 = (val2 / 2048) | 0x69000400;

GX_WRITE_U8(0x61);
GX_WRITE_U32(val1);
GFWriteBPCmd(val1);

__GXFlushTextureState();

val1 = (val2 / 4224) | 0x46000200;
GX_WRITE_U8(0x61);
GX_WRITE_U32(val1);
GFWriteBPCmd(val1);
}

__GXInitRevisionBits();
Expand All @@ -309,8 +250,8 @@ GXFifoObj* GXInit(void* base, u32 size) {
GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 8], GX_TEXCACHE_32K);
GXInitTexCacheRegion(&__GXData->TexRegions1[i], GX_FALSE, GXTexRegionAddrTable[i + 16],
GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 24], GX_TEXCACHE_32K);
GXInitTexCacheRegion(&__GXData->TexRegions2[i], GX_TRUE, GXTexRegionAddrTable[i + 32],
GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 40], GX_TEXCACHE_32K);
// GXInitTexCacheRegion(&__GXData->TexRegions2[i], GX_TRUE, GXTexRegionAddrTable[i + 32],
// GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 40], GX_TEXCACHE_32K);
}

for (i = 0; i < GX_MAX_TLUT; i++) {
Expand All @@ -325,22 +266,19 @@ GXFifoObj* GXInit(void* base, u32 size) {

FAST_FLAG_SET(__GXData->perfSel, 0, 4, 4);

GX_WRITE_U8(0x8);
GX_WRITE_U8(0x20);
GX_WRITE_U32(__GXData->perfSel);
GXFIFO.u8 = 0x8;
GXFIFO.u8 = 0x20;
GXFIFO.u32 = __GXData->perfSel;

GX_WRITE_U8(0x10);
GX_WRITE_U32(0x1006);
GX_WRITE_U32(0);
GXFIFO.u8 = 0x10;
GXFIFO.u32 = 0x1006;
GXFIFO.u32 = 0;

GX_WRITE_U8(0x61);
GX_WRITE_U32(0x23000000);
GFWriteBPCmd(0x23000000);

GX_WRITE_U8(0x61);
GX_WRITE_U32(0x24000000);
GFWriteBPCmd(0x24000000);

GX_WRITE_U8(0x61);
GX_WRITE_U32(0x67000000);
GFWriteBPCmd(0x67000000);

__GXSetIndirectMask(0);
__GXSetTmemConfig(2);
Expand Down
27 changes: 1 addition & 26 deletions src/dolphin/gx/GXMisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ void GXSetMisc(GXMiscToken token, u32 val) {
case GX_MT_DL_SAVE_CONTEXT:
__GXData->dlSaveContext = (val != 0);
break;

case GX_MT_ABORT_WAIT_COPYOUT:
__GXData->abtWaitPECopy = (val != 0);
break;
}
}

Expand Down Expand Up @@ -58,23 +54,7 @@ static void __GXAbortWait(u32 clocks) {
} while (time1 - time0 <= clocks / 4);
}

static void __GXAbortWaitPECopyDone(void) {
u32 peCnt0, peCnt1;

peCnt0 = GXReadMEMReg(0x28, 0x27);
do {
peCnt1 = peCnt0;
__GXAbortWait(32);

peCnt0 = GXReadMEMReg(0x28, 0x27);
} while (peCnt0 != peCnt1);
}

void __GXAbort(void) {
if (__GXData->abtWaitPECopy && GXGetGPFifo()) {
__GXAbortWaitPECopyDone();
}

__PIRegs[0x18 / 4] = 1;
__GXAbortWait(200);
__PIRegs[0x18 / 4] = 0;
Expand All @@ -83,12 +63,7 @@ void __GXAbort(void) {

void GXAbortFrame(void) {
__GXAbort();
if (GXGetGPFifo()) {
__GXCleanGPFifo();
__GXInitRevisionBits();
__GXData->dirtyState = 0;
GXFlush();
}
__GXCleanGPFifo();
}

/* ############################################################################################## */
Expand Down
Loading

0 comments on commit 89c74d0

Please sign in to comment.