Initial GX work

This commit is contained in:
Phillip Stephens 2023-10-01 02:03:23 -07:00
parent 919e53661f
commit bd5314a8d2
9 changed files with 755 additions and 16 deletions

View File

@ -194,15 +194,13 @@ __GXDefaultTlutRegionCallback:
/* 80375128 00372088 28 03 00 14 */ cmplwi r3, 0x14
/* 8037512C 0037208C 41 80 00 0C */ blt lbl_80375138
/* 80375130 00372090 38 60 00 00 */ li r3, 0
/* 80375134 00372094 48 00 00 14 */ b sub_80375148
/* 80375134 00372094 48 00 00 14 */ b lbl_80375148
lbl_80375138:
/* 80375138 00372098 54 63 20 36 */ slwi r3, r3, 4
/* 8037513C 0037209C 80 02 CE 08 */ lwz r0, __GXData@sda21(r2)
/* 80375140 003720A0 38 63 02 D0 */ addi r3, r3, 0x2d0
/* 80375144 003720A4 7C 60 1A 14 */ add r3, r0, r3
.global sub_80375148
sub_80375148:
lbl_80375148:
/* 80375148 003720A8 4E 80 00 20 */ blr
.global GXInit

View File

@ -884,6 +884,25 @@ typedef enum _GXVCachePerf {
} GXVCachePerf;
typedef enum _GXFBClamp {
GX_CLAMP_NONE = 0,
GX_CLAMP_TOP = 1,
GX_CLAMP_BOTTOM = 2,
} GXFBClamp;
typedef enum _GXCopyMode {
GX_COPY_PROGRESSIVE = 0,
GX_COPY_INTLC_EVEN = 2,
GX_COPY_INTLC_ODD = 3,
} GXCopyMode;
typedef enum _GXAlphaReadMode {
GX_READ_00 = 0,
GX_READ_FF = 1,
GX_READ_NONE = 2,
} _GXAlphaReadMode;
#ifdef __cplusplus
}
#endif

View File

@ -25,7 +25,7 @@ void GXSetArray(GXAttr attr, const void* data, u8 stride);
#endif
void GXInvalidateVtxCache(void);
static inline void GXSetTexCoordGen(GXTexCoordID dst_coord, GXTexGenType func,
static void GXSetTexCoordGen(GXTexCoordID dst_coord, GXTexGenType func,
GXTexGenSrc src_param, u32 mtx) {
GXSetTexCoordGen2(dst_coord, func, src_param, mtx, GX_FALSE, GX_PTIDENTITY);
}

View File

@ -20,7 +20,7 @@ void GXSetPixelFmt(GXPixelFmt pix_fmt, GXZFmt16 z_fmt);
void GXSetDither(GXBool dither);
void GXSetDstAlpha(GXBool enable, u8 alpha);
// ? GXSetFieldMask();
// ? GXSetFieldMode();
void GXSetFieldMode(u8 field_mode, u8 half_aspect_ratio);
#ifdef __cplusplus
}

View File

@ -3,7 +3,7 @@
#include "dolphin/gx/GXVert.h"
typedef struct GXLightObj_ {
typedef struct GXLightObjInt {
u32 padding[3];
u32 color;
float a0;
@ -18,7 +18,7 @@ typedef struct GXLightObj_ {
float nx;
float ny;
float nz;
} GXLightObj_;
} GXLightObjInt;
#define XF_LIGHT_BASE 0x0600
#define XF_LIGHT_SIZE 0x10
@ -28,11 +28,334 @@ typedef struct GXLightObj_ {
#define GX_WRITE_U8(v) (GXWGFifo.u8 = v)
#define GX_WRITE_U32(v) (GXWGFifo.u32 = v)
typedef struct GXData {
u16 cpSRreg;
u16 cpCRreg;
typedef struct __GXData_struct {
u16 vNumNot;
u16 bpSentNot;
u16 vNum;
u16 vLim;
u32 cpEnable;
u32 cpStatus;
u32 cpClr;
u32 vcdLo;
u32 vcdHi;
u32 vatA[8];
u32 vatB[8];
u32 vatC[8];
u32 lpSize;
u32 matIdxA;
u32 matIdxB;
u32 indexBase[4];
u32 indexStride[4];
u32 ambColor[2];
u32 matColor[2];
u32 suTs0[8];
u32 suTs1[8];
u32 suScis0;
u32 suScis1;
u32 tref[8];
u32 iref;
u32 bpMask;
u32 IndTexScale0;
u32 IndTexScale1;
u32 tevc[16];
u32 teva[16];
u32 tevKsel[8];
u32 cmode0;
u32 cmode1;
u32 zmode;
u32 peCtrl;
u32 cpDispSrc;
u32 cpDispSize;
u32 cpDispStride;
u32 cpDisp;
u32 cpTexSrc;
u32 cpTexSize;
u32 cpTexStride;
u32 cpTex;
GXBool cpTexZ;
u32 genMode;
GXTexRegion TexRegions[8];
GXTexRegion TexRegionsCI[4];
u32 nextTexRgn;
u32 nextTexRgnCI;
GXTlutRegion TlutRegions[20];
GXTexRegion* (*texRegionCallback)(GXTexObj*, GXTexMapID);
GXTlutRegion* (*tlutRegionCallback)(u32);
GXAttrType nrmType;
GXBool hasNrms;
GXBool hasBiNrms;
u32 projType;
f32 projMtx[6];
f32 vpLeft;
f32 vpTop;
f32 vpWd;
f32 vpHt;
f32 vpNearz;
f32 vpFarz;
u8 fgRange;
f32 fgSideX;
u32 tImage0[8];
u32 tMode0[8];
u32 texmapId[16];
u32 tcsManEnab;
u32 tevTcEnab;
GXPerf0 perf0;
GXPerf1 perf1;
u32 perfSel;
GXBool inDispList;
GXBool dlSaveContext;
u8 dirtyVAT;
u32 dirtyState;
} GXData;
extern GXData* __GXData;
extern GXData* gx;
// #define gx __GXData
void __GXInitGX();
#define GX_REG_ASSERT(c) ASSERTMSG(c, "GX Internal: Register field out of range")
#define GX_FLAG_SET(regOrg, newFlag, regName) \
do { \
GX_REG_ASSERT(!((newFlag) & ~((1 << (regName##_SIZE)) - 1))); \
(regOrg) = (((u32)(regOrg) & ~(regName##_MASK)) | \
(((u32)(newFlag) << (regName##_SHIFT)) & (regName##_MASK))); \
} while (0)
#define GX_GENMODE_ID 0
#define GX_GENMODE_REG_ID_SIZE 8
#define GX_GENMODE_REG_ID_SHIFT 24
#define GX_GENMODE_REG_ID_MASK 0xff000000
#define GX_GENMODE_GET_REG_ID(genMode) \
((((u32)(genMode)) & GX_GENMODE_REG_ID_MASK) >> GX_GENMODE_REG_ID_SHIFT)
#define GX_BPMASK_ID 15
#define GX_BPMASK_REG_ID_SIZE 8
#define GX_BPMASK_REG_ID_SHIFT 24
#define GX_BPMASK_REG_ID_MASK 0xff000000
#define GX_LPSIZE_ID 34
#define GX_LPSIZE_REG_ID_SIZE 8
#define GX_LPSIZE_REG_ID_SHIFT 24
#define GX_LPSIZE_REG_ID_MASK 0xff000000
#define TEV_COLOR_ENV_REG_ID_SIZE 8
#define TEV_COLOR_ENV_REG_ID_SHIFT 24
#define TEV_COLOR_ENV_REG_ID_MASK 0xff000000
#define TEV_ALPHA_ENV_REG_ID_SIZE 8
#define TEV_ALPHA_ENV_REG_ID_SHIFT 24
#define TEV_ALPHA_ENV_REG_ID_MASK 0xff000000
#define TEV_COLOR_ENV_0_ID 0x000000c0
#define TEV_ALPHA_ENV_0_ID 0x000000c1
#define TEV_COLOR_ENV_1_ID 0x000000c2
#define TEV_ALPHA_ENV_1_ID 0x000000c3
#define TEV_COLOR_ENV_2_ID 0x000000c4
#define TEV_ALPHA_ENV_2_ID 0x000000c5
#define TEV_COLOR_ENV_3_ID 0x000000c6
#define TEV_ALPHA_ENV_3_ID 0x000000c7
#define TEV_COLOR_ENV_4_ID 0x000000c8
#define TEV_ALPHA_ENV_4_ID 0x000000c9
#define TEV_COLOR_ENV_5_ID 0x000000ca
#define TEV_ALPHA_ENV_5_ID 0x000000cb
#define TEV_COLOR_ENV_6_ID 0x000000cc
#define TEV_ALPHA_ENV_6_ID 0x000000cd
#define TEV_COLOR_ENV_7_ID 0x000000ce
#define TEV_ALPHA_ENV_7_ID 0x000000cf
#define TEV_COLOR_ENV_8_ID 0x000000d0
#define TEV_ALPHA_ENV_8_ID 0x000000d1
#define TEV_COLOR_ENV_9_ID 0x000000d2
#define TEV_ALPHA_ENV_9_ID 0x000000d3
#define TEV_COLOR_ENV_A_ID 0x000000d4
#define TEV_ALPHA_ENV_A_ID 0x000000d5
#define TEV_COLOR_ENV_B_ID 0x000000d6
#define TEV_ALPHA_ENV_B_ID 0x000000d7
#define TEV_COLOR_ENV_C_ID 0x000000d8
#define TEV_ALPHA_ENV_C_ID 0x000000d9
#define TEV_COLOR_ENV_D_ID 0x000000da
#define TEV_ALPHA_ENV_D_ID 0x000000db
#define TEV_COLOR_ENV_E_ID 0x000000dc
#define TEV_ALPHA_ENV_E_ID 0x000000dd
#define TEV_COLOR_ENV_F_ID 0x000000de
#define TEV_ALPHA_ENV_F_ID 0x000000df
#define TEV_KSEL_REG_ID_SIZE 8
#define TEV_KSEL_REG_ID_SHIFT 24
#define TEV_KSEL_REG_ID_MASK 0xff000000
#define TEV_KSEL_0_ID 0x000000f6
#define TEV_KSEL_1_ID 0x000000f7
#define TEV_KSEL_2_ID 0x000000f8
#define TEV_KSEL_3_ID 0x000000f9
#define TEV_KSEL_4_ID 0x000000fa
#define TEV_KSEL_5_ID 0x000000fb
#define TEV_KSEL_6_ID 0x000000fc
#define TEV_KSEL_7_ID 0x000000fd
#define RAS_IREF_ID 39
#define RAS_IREF_REG_ID_SIZE 8
#define RAS_IREF_REG_ID_SHIFT 24
#define RAS_IREF_REG_ID_MASK 0xff000000
#define RAS_TREF0_ID 40
#define RAS_TREF_REG_ID_SIZE 8
#define RAS_TREF_REG_ID_SHIFT 24
#define RAS_TREF_REG_ID_MASK 0xff000000
#define SU_TS0_REG_ID_SIZE 8
#define SU_TS0_REG_ID_SHIFT 24
#define SU_TS0_REG_ID_MASK 0xff000000
#define SU_TS1_REG_ID_SIZE 8
#define SU_TS1_REG_ID_SHIFT 24
#define SU_TS1_REG_ID_MASK 0xff000000
#define SU_SCIS0_ID 0x00000020
#define SU_SCIS1_ID 0x00000021
#define SU_SCIS0_REG_ID_SIZE 8
#define SU_SCIS0_REG_ID_SHIFT 24
#define SU_SCIS0_REG_ID_MASK 0xff000000
#define SU_SCIS1_REG_ID_SIZE 8
#define SU_SCIS1_REG_ID_SHIFT 24
#define SU_SCIS1_REG_ID_MASK 0xff000000
#define SU_SSIZE0_ID 0x00000030
#define SU_TSIZE0_ID 0x00000031
#define SU_SSIZE1_ID 0x00000032
#define SU_TSIZE1_ID 0x00000033
#define SU_SSIZE2_ID 0x00000034
#define SU_TSIZE2_ID 0x00000035
#define SU_SSIZE3_ID 0x00000036
#define SU_TSIZE3_ID 0x00000037
#define SU_SSIZE4_ID 0x00000038
#define SU_TSIZE4_ID 0x00000039
#define SU_SSIZE5_ID 0x0000003a
#define SU_TSIZE5_ID 0x0000003b
#define SU_SSIZE6_ID 0x0000003c
#define SU_TSIZE6_ID 0x0000003d
#define SU_SSIZE7_ID 0x0000003e
#define SU_TSIZE7_ID 0x0000003f
#define GX_ZMODE_ID 64
#define GX_ZMODE_REG_ID_SIZE 8
#define GX_ZMODE_REG_ID_SHIFT 24
#define GX_ZMODE_REG_ID_MASK 0xff000000
#define GX_CMODE0_ID 65
#define GX_CMODE0_REG_ID_SIZE 8
#define GX_CMODE0_REG_ID_SHIFT 24
#define GX_CMODE0_REG_ID_MASK 0xff000000
#define GX_CMODE1_ID 66
#define GX_CMODE1_REG_ID_SIZE 8
#define GX_CMODE1_REG_ID_SHIFT 24
#define GX_CMODE1_REG_ID_MASK 0xff000000
#define PE_CONTROL_ID 67
#define PE_CONTROL_REG_ID_SIZE 8
#define PE_CONTROL_REG_ID_SHIFT 24
#define PE_CONTROL_REG_ID_MASK 0xff000000
#define PE_COPY_CMD_GAMMA_SIZE 2
#define PE_COPY_CMD_GAMMA_SHIFT 7
#define PE_COPY_CMD_GAMMA_MASK 0x00000180
#define GEN_MODE_REG_ID_SIZE 8
#define GEN_MODE_REG_ID_SHIFT 24
#define GEN_MODE_REG_ID_MASK 0xff000000
#define GX_OPCODE_INDEX_SIZE 3
#define GX_OPCODE_INDEX_SHIFT 0
#define GX_OPCODE_INDEX_MASK 0x00000007
#define GX_OPCODE_CMD_SHIFT 3
#define GX_OPCODE(index, cmd) \
((((u32)(index)) << GX_OPCODE_INDEX_SHIFT) | (((u32)(cmd)) << GX_OPCODE_CMD_SHIFT))
#ifdef _DEBUG
#define GX_WRITE_RA_REG(reg) \
{ \
GX_WRITE_U8(GX_OPCODE(1, 12)); \
GX_WRITE_U32((reg)); \
__gxVerif->rasRegs[GX_GENMODE_GET_REG_ID(reg)] = reg; \
}
#else
#define GX_WRITE_RA_REG(reg) \
{ \
GX_WRITE_U8(GX_OPCODE(1, 12)); \
GX_WRITE_U32((reg)); \
}
#endif
#define CP_STREAM_REG_INDEX_SIZE 4
#define CP_STREAM_REG_INDEX_SHIFT 0
#define CP_STREAM_REG_INDEX_MASK 0x0000000f
#define CP_STREAM_REG_ADDR_SIZE 4
#define CP_STREAM_REG_ADDR_SHIFT 4
#define CP_STREAM_REG_ADDR_MASK 0x000000f0
#define CP_STREAM_REG(index, addr) \
((((unsigned long)(index)) << CP_STREAM_REG_INDEX_SHIFT) | \
(((unsigned long)(addr)) << CP_STREAM_REG_ADDR_SHIFT))
#ifdef _DEBUG
#define GX_WRITE_CP_STRM_REG(addr, vtxfmt, data) \
{ \
s32 regAddr; \
GX_WRITE_U8(GX_OPCODE(0, 1)); \
GX_WRITE_U8(CP_STREAM_REG((vtxfmt), (addr))); \
GX_WRITE_U32((data)); \
regAddr = (vtxfmt)-GX_POS_MTX_ARRAY + GX_VA_POS; \
if ((addr) == 10) { \
if (regAddr >= 0 && regAddr < 4) \
gx->indexBase[regAddr] = (data); \
} else if ((addr) == 11) { \
if (regAddr >= 0 && regAddr < 4) \
gx->indexStride[regAddr] = (data); \
} \
}
#else
#define GX_WRITE_CP_STRM_REG(addr, vtxfmt, data) \
{ \
GX_WRITE_U8(GX_OPCODE(0, 1)); \
GX_WRITE_U8(CP_STREAM_REG((vtxfmt), (addr))); \
GX_WRITE_U32((data)); \
}
#endif
#define PE_REFRESH_REG_ID_SIZE 8
#define PE_REFRESH_REG_ID_SHIFT 24
#define PE_REFRESH_REG_ID_MASK 0xff000000
#define PE_REFRESH_INTERVAL_SHIFT 0
#define PE_REFRESH_ENABLE_SHIFT 9
#define PE_REFRESH_TOTAL_SIZE 32
#define PE_REFRESH(interval, enable, rid) \
((((u32)(interval)) << PE_REFRESH_INTERVAL_SHIFT) | \
(((u32)(enable)) << PE_REFRESH_ENABLE_SHIFT) | (((u32)(rid)) << PE_REFRESH_REG_ID_SHIFT))
#define TX_REFRESH_REG_ID_SIZE 8
#define TX_REFRESH_REG_ID_SHIFT 24
#define TX_REFRESH_REG_ID_MASK 0xff000000
#define TX_REFRESH_INTERVAL_SHIFT 0
#define TX_REFRESH_ENABLE_SHIFT 10
#define TX_REFRESH_TOTAL_SIZE 32
#define TX_REFRESH(interval, enable, rid) \
((((u32)(interval)) << TX_REFRESH_INTERVAL_SHIFT) | \
(((u32)(enable)) << TX_REFRESH_ENABLE_SHIFT) | (((u32)(rid)) << TX_REFRESH_REG_ID_SHIFT))
#define GX_VAT_REG_A_UNK_SIZE 1
#define GX_VAT_REG_A_UNK_SHIFT 30
#define GX_VAT_REG_A_UNK_MASK 0x40000000
#define GX_VAT_REG_B_UNK_SIZE 1
#define GX_VAT_REG_B_UNK_SHIFT 31
#define GX_VAT_REG_B_UNK_MASK 0x80000000
#endif // _DOLPHIN_GXPRIV

View File

@ -101,6 +101,14 @@ typedef struct _GXTlutRegion {
u32 dummy[4];
} GXTlutRegion;
typedef struct _GXVtxAttrFmtList {
// total size: 0x10
GXAttr attr; // offset 0x0, size 0x4
GXCompCnt cnt; // offset 0x4, size 0x4
GXCompType type; // offset 0x8, size 0x4
u8 frac; // offset 0xC, size 0x1
} GXVtxAttrFmtList;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,47 @@
#ifndef _DOLPHIN_GXVERIFY
#define _DOLPHIN_GXVERIFY
#include <dolphin/types.h>
typedef enum {
GX_WARN_NONE,
GX_WARN_SEVERE,
GX_WARN_MEDIUM,
GX_WARN_ALL,
} GXWarningLevel;
#ifdef _DEBUG
extern void GXSetVerifyLevel(GXWarningLevel level);
#else
#define GXSetVerifyLevel(level) ((void)0)
#endif
typedef void (*GXVerifyCallback)(GXWarningLevel level, u32 id, const char* msg);
typedef struct __GXVerifyData {
GXVerifyCallback cb; // offset 0x0, size 0x4
GXWarningLevel verifyLevel; // offset 0x4, size 0x4
u32 xfRegs[80]; // offset 0x8, size 0x140
u32 xfMtx[256]; // offset 0x148, size 0x400
u32 xfNrm[96]; // offset 0x548, size 0x180
u32 xfDMtx[256]; // offset 0x6C8, size 0x400
u32 xfLight[128]; // offset 0xAC8, size 0x200
u32 rasRegs[256]; // offset 0xCC8, size 0x400
u8 xfRegsDirty[80]; // offset 0x10C8, size 0x50
u8 xfMtxDirty[256]; // offset 0x1118, size 0x100
u8 xfNrmDirty[96]; // offset 0x1218, size 0x60
u8 xfDMtxDirty[256]; // offset 0x1278, size 0x100
u8 xfLightDirty[128]; // offset 0x1378, size 0x80
} GXVerifyData;
#ifdef _DEBUG
GXVerifyCallback GXSetVerifyCallback(GXVerifyCallback cb);
#else
#define GXSetVerifyCallback(cb) ((GXVerifyCallback)0)
#endif
#ifdef __cplusplus
}
#endif
#endif // _DOLPHIN_GXVERIFY

346
src/Dolphin/gx/GXInit.c Normal file
View File

@ -0,0 +1,346 @@
#include "dolphin/gx.h"
#include "dolphin/gx/GXPriv.h"
#include "dolphin/gx/GXVerify.h"
#include "dolphin/os.h"
extern void __GXFifoInit();
extern void __GXPEInit();
static GXData gxData;
GXData* gx = &gxData;
extern GXVerifyData* __gxVerif;
GXFifoObj FifoObj;
#ifdef _DEBUG
GXBool __GXinBegin = FALSE;
#endif
volatile void* __piReg = NULL;
volatile void* __cpReg = NULL;
volatile void* __peReg = NULL;
volatile void* __memReg = NULL;
asm BOOL IsWriteGatherBufferEmpty(void) {
// clang-format off
nofralloc;
sync;
mfspr r3, WPAR;
andi. r3, r3, 1;
blr;
// clang-format on
}
static void EnableWriteGatherPipe() {
u32 hid2; // r31
hid2 = PPCMfhid2();
PPCMtwpar(OSUncachedToPhysical((void*)GXFIFO_ADDR));
hid2 |= 0x40000000;
PPCMthid2(hid2);
}
static void DisableWriteGatherPipe() {
u32 hid2;
hid2 = PPCMfhid2();
hid2 &= ~0x40000000;
PPCMthid2(hid2);
}
static GXTexRegion* __GXDefaultTexRegionCallback(const GXTexObj* t_obj, GXTexMapID) {
GXTexFmt fmt; // r31
fmt = GXGetTexObjFmt(t_obj);
if (fmt != GX_TF_C4 && fmt != GX_TF_C8 && fmt != GX_TF_C14X2) {
return &gx->TexRegions[(gx->nextTexRgn++) & 7];
}
return &gx->TexRegionsCI[(gx->nextTexRgnCI++) & 3];
}
static GXTlutRegion* __GXDefaultTlutRegionCallback(u32 idx) {
if (idx >= 20) {
return 0;
}
return &gx->TlutRegions[idx];
}
void __GXDefaultVerifyCallback(GXWarningLevel level, u32 id, const char* msg) {
OSReport("Level %1d, Warning %3d: %s\n", level, id, msg);
}
GXFifoObj* GXInit(void* base, u32 size) {
u32 i; // r31
u32 reg;
u32 freqBase;
gx->inDispList = FALSE;
gx->dlSaveContext = TRUE;
#ifdef _DEBUG
__GXinBegin = FALSE;
#endif
gx->tcsManEnab = FALSE;
gx->tevTcEnab = FALSE;
gx->vNum = 0;
__piReg = (void*)OSPhysicalToUncached((void*)0xC003000);
__cpReg = (void*)OSPhysicalToUncached((void*)0xC000000);
__peReg = (void*)OSPhysicalToUncached((void*)0xC001000);
__memReg = (void*)OSPhysicalToUncached((void*)0xC004000);
__GXFifoInit();
GXInitFifoBase(&FifoObj, base, size);
GXSetCPUFifo(&FifoObj);
GXSetGPFifo(&FifoObj);
__GXPEInit();
EnableWriteGatherPipe();
gx->genMode = 0;
GX_FLAG_SET(gx->genMode, GX_GENMODE_ID, GX_GENMODE_REG_ID);
gx->bpMask = 255;
GX_FLAG_SET(gx->bpMask, GX_BPMASK_ID, GX_BPMASK_REG_ID);
gx->lpSize = 0;
GX_FLAG_SET(gx->lpSize, GX_LPSIZE_ID, GX_LPSIZE_REG_ID);
for (i = 0; i < 16; ++i) {
gx->tevc[i] = 0;
gx->teva[i] = 0;
gx->tref[i / 2] = 0;
gx->texmapId[i] = GX_TEXMAP_NULL;
GX_FLAG_SET(gx->tevc[i], TEV_COLOR_ENV_0_ID + i * 2, TEV_COLOR_ENV_REG_ID);
GX_FLAG_SET(gx->teva[i], TEV_ALPHA_ENV_0_ID + i * 2, TEV_ALPHA_ENV_REG_ID);
GX_FLAG_SET(gx->tevKsel[i / 2], TEV_KSEL_0_ID + i / 2, TEV_KSEL_REG_ID);
GX_FLAG_SET(gx->tref[i / 2], RAS_TREF0_ID + i / 2, RAS_TREF_REG_ID);
}
gx->iref = 0;
GX_FLAG_SET(gx->iref, RAS_IREF_ID, RAS_IREF_REG_ID);
for (i = 0; i < 8; ++i) {
gx->suTs0[i] = 0;
gx->suTs0[i] = 0;
GX_FLAG_SET(gx->suTs0[i], SU_SSIZE0_ID + i * 2, SU_TS0_REG_ID);
GX_FLAG_SET(gx->suTs1[i], SU_TSIZE0_ID + i * 2, SU_TS1_REG_ID);
}
GX_FLAG_SET(gx->suScis0, SU_SCIS0_ID, SU_SCIS0_REG_ID);
GX_FLAG_SET(gx->suScis1, SU_SCIS1_ID, SU_SCIS1_REG_ID);
GX_FLAG_SET(gx->cmode0, GX_CMODE0_ID, GX_CMODE0_REG_ID);
GX_FLAG_SET(gx->cmode1, GX_CMODE1_ID, GX_CMODE1_REG_ID);
GX_FLAG_SET(gx->zmode, GX_ZMODE_ID, GX_ZMODE_REG_ID);
GX_FLAG_SET(gx->peCtrl, PE_CONTROL_ID, PE_CONTROL_REG_ID);
GX_FLAG_SET(gx->cpTex, GX_GM_1_0, PE_COPY_CMD_GAMMA);
gx->dirtyState = 0;
gx->dirtyVAT = FALSE;
__gxVerif->verifyLevel = GX_WARN_ALL;
GXSetVerifyCallback(__GXDefaultVerifyCallback);
for (i = 0; i < 256; ++i) {
GX_FLAG_SET(__gxVerif->rasRegs[i], 0xFF, GEN_MODE_REG_ID);
}
memset(__gxVerif->xfRegsDirty, 0, sizeof(__gxVerif->xfRegsDirty));
memset(__gxVerif->xfMtxDirty, 0, sizeof(__gxVerif->xfMtxDirty));
memset(__gxVerif->xfNrmDirty, 0, sizeof(__gxVerif->xfNrmDirty));
memset(__gxVerif->xfLightDirty, 0, sizeof(__gxVerif->xfLightDirty));
freqBase = OS_BUS_CLOCK / 500;
__GXFlushTextureState();
reg = TX_REFRESH(freqBase / 2048, 1, 105);
GX_WRITE_RA_REG(reg);
__GXFlushTextureState();
reg = PE_REFRESH(freqBase / 4224, 1, 70);
GX_WRITE_RA_REG(reg);
for (i = 0; i < GX_MAX_VTXFMT; i++) {
GX_FLAG_SET(gx->vatA[i], 1, GX_VAT_REG_A_UNK);
GX_FLAG_SET(gx->vatB[i], 1, GX_VAT_REG_B_UNK);
GX_WRITE_CP_STRM_REG(8, (s32)i, gx->vatB[i]);
}
__GXSetTmemConfig(0);
__GXInitGX();
return &FifoObj;
}
void __GXInitGX() {
GXRenderModeObj* rmode; // r31
float identity_mtx[3][4]; // r1+0x2C
GXColor clear = {64, 64, 64, 255}; // r1+0x28
GXColor black = {0, 0, 0, 0}; // r1+0x24
GXColor white = {255, 255, 255, 255}; // r1+0x20
u32 i; // r30
switch (VIGetTvFormat()) {
case VI_NTSC:
rmode = &GXNtsc480IntDf;
break;
case VI_PAL:
rmode = &GXPal528IntDf;
break;
case VI_EURGB60:
rmode = &GXEurgb60Hz480IntDf;
break;
case VI_MPAL:
rmode = &GXMpal480IntDf;
break;
default:
#line 0x415
ASSERTMSG(0, "GXInit: invalid TV format");
rmode = &GXNtsc480IntDf;
break;
}
GXSetCopyClear(clear, GX_MAX_Z24);
GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
GXSetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX2x4, GX_TG_TEX1, GX_IDENTITY);
GXSetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_TEX2, GX_IDENTITY);
GXSetTexCoordGen(GX_TEXCOORD3, GX_TG_MTX2x4, GX_TG_TEX3, GX_IDENTITY);
GXSetTexCoordGen(GX_TEXCOORD4, GX_TG_MTX2x4, GX_TG_TEX4, GX_IDENTITY);
GXSetTexCoordGen(GX_TEXCOORD5, GX_TG_MTX2x4, GX_TG_TEX5, GX_IDENTITY);
GXSetTexCoordGen(GX_TEXCOORD6, GX_TG_MTX2x4, GX_TG_TEX6, GX_IDENTITY);
GXSetTexCoordGen(GX_TEXCOORD7, GX_TG_MTX2x4, GX_TG_TEX7, GX_IDENTITY);
GXSetNumTexGens(1);
GXClearVtxDesc();
GXInvalidateVtxCache();
for (i = GX_VA_POS; i <= GX_LIGHT_ARRAY; i++) {
GXSetArray((GXAttr)i, (void*)gx, 0);
}
GXSetLineWidth(6, GX_TO_ZERO);
GXSetPointSize(6, GX_TO_ZERO);
GXEnableTexOffsets(GX_TEXCOORD0, GX_DISABLE, GX_DISABLE);
GXEnableTexOffsets(GX_TEXCOORD1, GX_DISABLE, GX_DISABLE);
GXEnableTexOffsets(GX_TEXCOORD2, GX_DISABLE, GX_DISABLE);
GXEnableTexOffsets(GX_TEXCOORD3, GX_DISABLE, GX_DISABLE);
GXEnableTexOffsets(GX_TEXCOORD4, GX_DISABLE, GX_DISABLE);
GXEnableTexOffsets(GX_TEXCOORD5, GX_DISABLE, GX_DISABLE);
GXEnableTexOffsets(GX_TEXCOORD6, GX_DISABLE, GX_DISABLE);
GXEnableTexOffsets(GX_TEXCOORD7, GX_DISABLE, GX_DISABLE);
identity_mtx[0][0] = 1.0f;
identity_mtx[0][1] = 0.0f;
identity_mtx[0][2] = 0.0f;
identity_mtx[0][3] = 0.0f;
identity_mtx[1][0] = 0.0f;
identity_mtx[1][1] = 1.0f;
identity_mtx[1][2] = 0.0f;
identity_mtx[1][3] = 0.0f;
identity_mtx[2][0] = 0.0f;
identity_mtx[2][1] = 0.0f;
identity_mtx[2][2] = 1.0f;
identity_mtx[2][3] = 0.0f;
GXLoadPosMtxImm(identity_mtx, GX_PNMTX0);
GXLoadNrmMtxImm(identity_mtx, GX_PNMTX0);
GXSetCurrentMtx(GX_PNMTX0);
GXLoadTexMtxImm(identity_mtx, GX_IDENTITY, GX_MTX3x4);
GXLoadTexMtxImm(identity_mtx, GX_PTIDENTITY, GX_MTX3x4);
GXSetViewport(0.0f, 0.0f, rmode->fbWidth, rmode->xfbHeight, 0.0f, 1.0f);
GXSetCoPlanar(GX_DISABLE);
GXSetCullMode(GX_CULL_BACK);
GXSetClipMode(GX_CLIP_ENABLE);
GXSetScissor(0, 0, rmode->fbWidth, rmode->efbHeight);
GXSetScissorBoxOffset(0, 0);
GXSetNumChans(0);
GXSetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE,
GX_AF_NONE);
GXSetChanAmbColor(GX_COLOR0A0, black);
GXSetChanMatColor(GX_COLOR0A0, white);
GXSetChanCtrl(GX_COLOR1A1, GX_DISABLE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE,
GX_AF_NONE);
GXSetChanAmbColor(GX_COLOR1A1, black);
GXSetChanMatColor(GX_COLOR1A1, white);
GXInvalidateTexAll();
gx->nextTexRgn = 0;
gx->nextTexRgnCI = 0;
GXSetTexRegionCallback(__GXDefaultTexRegionCallback);
GXSetTlutRegionCallback(__GXDefaultTlutRegionCallback);
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);
GXSetTevOrder(GX_TEVSTAGE3, GX_TEXCOORD3, GX_TEXMAP3, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE4, GX_TEXCOORD4, GX_TEXMAP4, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE5, GX_TEXCOORD5, GX_TEXMAP5, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE6, GX_TEXCOORD6, GX_TEXMAP6, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE7, GX_TEXCOORD7, GX_TEXMAP7, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE8, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE9, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE10, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE11, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE12, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE13, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE14, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE15, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
GXSetNumTevStages(1);
GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE);
GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
GXSetZTexture(GX_ZT_DISABLE, GX_TF_Z8, 0);
for (i = GX_TEVSTAGE0; i < GX_MAX_TEVSTAGE; i++) {
GXSetTevKColorSel((GXTevStageID)i, GX_TEV_KCSEL_1_4);
GXSetTevKAlphaSel((GXTevStageID)i, GX_TEV_KASEL_1);
GXSetTevSwapMode((GXTevStageID)i, GX_TEV_SWAP0, GX_TEV_SWAP0);
}
GXSetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA);
GXSetTevSwapModeTable(GX_TEV_SWAP1, GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA);
GXSetTevSwapModeTable(GX_TEV_SWAP2, GX_CH_GREEN, GX_CH_GREEN, GX_CH_GREEN, GX_CH_ALPHA);
GXSetTevSwapModeTable(GX_TEV_SWAP3, GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA);
for (i = GX_TEVSTAGE0; i < GX_MAX_TEVSTAGE; i++) {
GXSetTevDirect((GXTevStageID)i);
}
GXSetNumIndStages(0);
GXSetIndTexCoordScale(GX_INDTEXSTAGE0, GX_ITS_1, GX_ITS_1);
GXSetIndTexCoordScale(GX_INDTEXSTAGE1, GX_ITS_1, GX_ITS_1);
GXSetIndTexCoordScale(GX_INDTEXSTAGE2, GX_ITS_1, GX_ITS_1);
GXSetIndTexCoordScale(GX_INDTEXSTAGE3, GX_ITS_1, GX_ITS_1);
GXSetFog(GX_FOG_NONE, 0.0f, 1.0f, 0.1f, 1.0f, black);
GXSetFogRangeAdj(GX_DISABLE, 0, 0);
GXSetBlendMode(GX_BM_NONE, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
GXSetColorUpdate(GX_ENABLE);
GXSetAlphaUpdate(GX_ENABLE);
GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GXSetZCompLoc(GX_TRUE);
GXSetDither(GX_ENABLE);
GXSetDstAlpha(GX_DISABLE, 0);
GXSetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
GXSetFieldMask(GX_ENABLE, GX_ENABLE);
GXSetFieldMode((GXBool)(rmode->field_rendering),
((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
GXSetDispCopySrc(0, 0, rmode->fbWidth, rmode->efbHeight);
GXSetDispCopyDst(rmode->fbWidth, rmode->efbHeight);
GXSetDispCopyYScale((f32)(rmode->xfbHeight) / (f32)(rmode->efbHeight));
GXSetCopyClamp((GXFBClamp)(GX_CLAMP_TOP | GX_CLAMP_BOTTOM));
GXSetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter);
GXSetDispCopyGamma(GX_GM_1_0);
GXSetDispCopyFrame2Field(GX_COPY_PROGRESSIVE);
GXClearBoundingBox();
GXPokeColorUpdate(GX_TRUE);
GXPokeAlphaUpdate(GX_TRUE);
GXPokeDither(GX_FALSE);
GXPokeBlendMode(GX_BM_NONE, GX_BL_ZERO, GX_BL_ONE, GX_LO_SET);
GXPokeAlphaMode(GX_ALWAYS, 0);
GXPokeAlphaRead(GX_READ_FF);
GXPokeDstAlpha(GX_DISABLE, 0);
GXPokeZMode(GX_TRUE, GX_ALWAYS, GX_TRUE);
GXSetGPMetric(GX_PERF0_NONE, GX_PERF1_NONE);
GXClearGPMetric();
}

View File

@ -263,9 +263,7 @@ void GXLoadLightObjImm(GXLightObj* lt_obj, GXLightID light) {
GX_WRITE_U8(16);
GX_WRITE_U32(addr | (XF_LIGHT_SIZE - 1) << 16);
PushLight(obj, (void*)GX_FIFO_ADDR);
__GXData->cpCRreg = 1;
__GXData->bpSentNot = 1;
}
void GXSetChanAmbColor(GXChannelID chan, GXColor color) {
}
void GXSetChanAmbColor(GXChannelID chan, GXColor color) {}