diff --git a/include/dolphin/gx/GXBump.h b/include/dolphin/gx/GXBump.h index 07f933f7..9f111ee3 100644 --- a/include/dolphin/gx/GXBump.h +++ b/include/dolphin/gx/GXBump.h @@ -16,6 +16,8 @@ void GXSetIndTexOrder(GXIndTexStageID stage, GXTexCoordID coord, GXTexMapID map) void GXSetNumIndStages(u8 num); void GXSetTevDirect(GXTevStageID stage); void GXSetTevIndWarp(GXTevStageID tevStage, GXIndTexStageID texStage, GXBool, GXBool, GXIndTexMtxID mtxID); // Might be incorrect +void __GXFlushTextureState(); +void __GXUpdateBPMask(); #ifdef __cplusplus }; diff --git a/include/dolphin/gx/GXInit.h b/include/dolphin/gx/GXInit.h index 3a076df8..990f99cd 100644 --- a/include/dolphin/gx/GXInit.h +++ b/include/dolphin/gx/GXInit.h @@ -127,7 +127,7 @@ typedef struct _GXData { STATIC_ASSERT(sizeof(GXData) == 0x4F8); -extern GXData* const __GXData; +extern GXData* const gx; // Define register addresses. #define GX_CP_ADDR (0x0C000000) @@ -151,14 +151,14 @@ extern vu16* __memReg; #define GX_SET_PI_REG(offset, val) (*(vu32*)((vu32*)(__piReg) + (offset)) = val) inline void GXSetWasteFlags() { - GXData* data = __GXData; + GXData* data = gx; data->dirtyState |= GX_DIRTY_SU_TEX | GX_DIRTY_BP_MASK; data->bpSentNot = 0; } static inline void set_x2(u16 value) { - __GXData->bpSentNot = value; + gx->bpSentNot = value; } #ifdef __cplusplus diff --git a/include/dolphin/gx/GXTexture.h b/include/dolphin/gx/GXTexture.h index 9e3739fc..6da79b70 100644 --- a/include/dolphin/gx/GXTexture.h +++ b/include/dolphin/gx/GXTexture.h @@ -38,7 +38,7 @@ GXTlutRegionCallback GXSetTlutRegionCallback(GXTlutRegionCallback callback); void GXSetTexCoordScaleManually(GXTexCoordID coord, GXBool enable, u16 s_scale, u16 t_scale); void GXSetTexCoordBias(GXTexCoordID coord, GXBool s_enable, GXBool t_enable); -void __SetSURegs(); +void __SetSURegs(u32 texImgIndex, u32 setUpRegIndex); void __GXSetSUTexRegs(); void __GXSetTmemConfig(u32); diff --git a/include/dolphin/vi/vi.h b/include/dolphin/vi/vi.h index a5bb9b9c..bcfec495 100644 --- a/include/dolphin/vi/vi.h +++ b/include/dolphin/vi/vi.h @@ -137,6 +137,7 @@ void* VIGetCurrentFrameBuffer(); void VISetBlack(BOOL); u32 VIGetRetraceCount(); u32 VIGetDTVStatus(); +u32 VIGetTvFormat(); vu16 __VIRegs[59] AT_ADDRESS(0xCC002000); diff --git a/src/dolphin/gx/GXAttr.c b/src/dolphin/gx/GXAttr.c index 724710e9..dcf31717 100644 --- a/src/dolphin/gx/GXAttr.c +++ b/src/dolphin/gx/GXAttr.c @@ -4,90 +4,90 @@ static inline void SETVCDATTR(GXAttr name, GXAttrType type) { switch (name) { case GX_VA_PNMTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_POSMTXIDX_ST, GX_CP_VCD_LO_POSMTXIDX_END); + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_POSMTXIDX_ST, GX_CP_VCD_LO_POSMTXIDX_END); break; case GX_VA_TEX0MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX0MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX0MTXIDX_ST, GX_CP_VCD_LO_TEX0MTXIDX_END); break; case GX_VA_TEX1MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX1MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX1MTXIDX_ST, GX_CP_VCD_LO_TEX1MTXIDX_END); break; case GX_VA_TEX2MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX2MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX2MTXIDX_ST, GX_CP_VCD_LO_TEX2MTXIDX_END); break; case GX_VA_TEX3MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX3MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX3MTXIDX_ST, GX_CP_VCD_LO_TEX3MTXIDX_END); break; case GX_VA_TEX4MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX4MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX4MTXIDX_ST, GX_CP_VCD_LO_TEX4MTXIDX_END); break; case GX_VA_TEX5MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX5MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX5MTXIDX_ST, GX_CP_VCD_LO_TEX5MTXIDX_END); break; case GX_VA_TEX6MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX6MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX6MTXIDX_ST, GX_CP_VCD_LO_TEX6MTXIDX_END); break; case GX_VA_TEX7MTXIDX: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_TEX7MTXIDX_ST, + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_TEX7MTXIDX_ST, GX_CP_VCD_LO_TEX7MTXIDX_END); break; case GX_VA_POS: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_POS_ST, GX_CP_VCD_LO_POS_END); + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_POS_ST, GX_CP_VCD_LO_POS_END); break; case GX_VA_NRM: if (type != GX_NONE) { - __GXData->hasNrms = TRUE; - __GXData->hasBiNrms = FALSE; - __GXData->nrmType = type; + gx->hasNrms = TRUE; + gx->hasBiNrms = FALSE; + gx->nrmType = type; } else { - __GXData->hasNrms = FALSE; + gx->hasNrms = FALSE; } break; case GX_VA_NBT: if (type != GX_NONE) { - __GXData->hasBiNrms = TRUE; - __GXData->hasNrms = FALSE; - __GXData->nrmType = type; + gx->hasBiNrms = TRUE; + gx->hasNrms = FALSE; + gx->nrmType = type; } else { - __GXData->hasBiNrms = FALSE; + gx->hasBiNrms = FALSE; } break; case GX_VA_CLR0: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_CLRDIF_ST, GX_CP_VCD_LO_CLRDIF_END); + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_CLRDIF_ST, GX_CP_VCD_LO_CLRDIF_END); break; case GX_VA_CLR1: - GX_SET_REG(__GXData->vcdLo, type, GX_CP_VCD_LO_CLRSPEC_ST, GX_CP_VCD_LO_CLRSPEC_END); + GX_SET_REG(gx->vcdLo, type, GX_CP_VCD_LO_CLRSPEC_ST, GX_CP_VCD_LO_CLRSPEC_END); break; case GX_VA_TEX0: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX0COORD_ST, GX_CP_VCD_HI_TEX0COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX0COORD_ST, GX_CP_VCD_HI_TEX0COORD_END); break; case GX_VA_TEX1: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX1COORD_ST, GX_CP_VCD_HI_TEX1COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX1COORD_ST, GX_CP_VCD_HI_TEX1COORD_END); break; case GX_VA_TEX2: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX2COORD_ST, GX_CP_VCD_HI_TEX2COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX2COORD_ST, GX_CP_VCD_HI_TEX2COORD_END); break; case GX_VA_TEX3: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX3COORD_ST, GX_CP_VCD_HI_TEX3COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX3COORD_ST, GX_CP_VCD_HI_TEX3COORD_END); break; case GX_VA_TEX4: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX4COORD_ST, GX_CP_VCD_HI_TEX4COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX4COORD_ST, GX_CP_VCD_HI_TEX4COORD_END); break; case GX_VA_TEX5: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX5COORD_ST, GX_CP_VCD_HI_TEX5COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX5COORD_ST, GX_CP_VCD_HI_TEX5COORD_END); break; case GX_VA_TEX6: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX6COORD_ST, GX_CP_VCD_HI_TEX6COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX6COORD_ST, GX_CP_VCD_HI_TEX6COORD_END); break; case GX_VA_TEX7: - GX_SET_REG(__GXData->vcdHi, type, GX_CP_VCD_HI_TEX7COORD_ST, GX_CP_VCD_HI_TEX7COORD_END); + GX_SET_REG(gx->vcdHi, type, GX_CP_VCD_HI_TEX7COORD_ST, GX_CP_VCD_HI_TEX7COORD_END); break; } } @@ -96,13 +96,13 @@ void GXSetVtxDesc(GXAttr name, GXAttrType type) { SETVCDATTR(name, type); // Set normal data type if enabled - if (__GXData->hasNrms || __GXData->hasBiNrms) { - GX_BITFIELD_SET(__GXData->vcdLo, 19, 2, __GXData->nrmType); + if (gx->hasNrms || gx->hasBiNrms) { + GX_BITFIELD_SET(gx->vcdLo, 19, 2, gx->nrmType); } else { - GX_BITFIELD_SET(__GXData->vcdLo, 19, 2, 0); + GX_BITFIELD_SET(gx->vcdLo, 19, 2, 0); } - __GXData->dirtyState |= GX_DIRTY_VCD; + gx->dirtyState |= GX_DIRTY_VCD; } void GXSetVtxDescv(GXVtxDescList* list) { @@ -111,37 +111,37 @@ void GXSetVtxDescv(GXVtxDescList* list) { } // Set normal data type if enabled - if (__GXData->hasNrms || __GXData->hasBiNrms) { - GX_BITFIELD_SET(__GXData->vcdLo, 19, 2, __GXData->nrmType); + if (gx->hasNrms || gx->hasBiNrms) { + GX_BITFIELD_SET(gx->vcdLo, 19, 2, gx->nrmType); } else { - GX_BITFIELD_SET(__GXData->vcdLo, 19, 2, 0); + GX_BITFIELD_SET(gx->vcdLo, 19, 2, 0); } - __GXData->dirtyState |= GX_DIRTY_VCD; + gx->dirtyState |= GX_DIRTY_VCD; } static void __GXXfVtxSpecs(void) { u32 normCount, colorCount, texCount; - normCount = __GXData->hasBiNrms ? 2 : (__GXData->hasNrms ? 1 : 0); + normCount = gx->hasBiNrms ? 2 : (gx->hasNrms ? 1 : 0); // Both fields in one access - colorCount = 33 - __cntlzw((__GXData->vcdLo & (0xf << 0xd)) >> 0xd); + colorCount = 33 - __cntlzw((gx->vcdLo & (0xf << 0xd)) >> 0xd); colorCount /= 2; // equivalent to /=2 and >>= 1 // All 16 assigned bits in VCD_Hi - texCount = 33 - __cntlzw((__GXData->vcdHi & (0xffff << 0)) >> 0); + texCount = 33 - __cntlzw((gx->vcdHi & (0xffff << 0)) >> 0); texCount /= 2; // equivalent to /=2 and >>= 1 GX_XF_LOAD_REG(GX_XF_REG_INVERTEXSPEC, (colorCount) | (normCount << 2) | (texCount << 4)); - __GXData->bpSentNot = GX_TRUE; + gx->bpSentNot = GX_TRUE; return; } void __GXSetVCD(void) { - GX_CP_LOAD_REG(GX_CP_REG_VCD_LO, __GXData->vcdLo); - GX_CP_LOAD_REG(GX_CP_REG_VCD_HI, __GXData->vcdHi); + GX_CP_LOAD_REG(GX_CP_REG_VCD_LO, gx->vcdLo); + GX_CP_LOAD_REG(GX_CP_REG_VCD_HI, gx->vcdHi); __GXXfVtxSpecs(); } @@ -156,15 +156,15 @@ void __GXCalculateVLim(void) { u32 vcdHiReg; s32 compCnt; - if (__GXData->vNum == 0) { + if (gx->vNum == 0) { return; } - vcdLoReg = __GXData->vcdLo; - vcdHiReg = __GXData->vcdHi; + vcdLoReg = gx->vcdLo; + vcdHiReg = gx->vcdHi; // GXCompCnt bit of normal parameters - compCnt = __GXData->vatA[GX_VTXFMT0]; + compCnt = gx->vatA[GX_VTXFMT0]; compCnt = (compCnt & 0x200) >> 9; vlim = GX_GET_REG(vcdLoReg, GX_CP_VCD_LO_POSMTXIDX_ST, GX_CP_VCD_LO_POSMTXIDX_END); @@ -192,7 +192,7 @@ void __GXCalculateVLim(void) { vlim += tbl2[GX_GET_REG(vcdHiReg, GX_CP_VCD_HI_TEX6COORD_ST, GX_CP_VCD_HI_TEX6COORD_END)]; vlim += tbl2[GX_GET_REG(vcdHiReg, GX_CP_VCD_HI_TEX7COORD_ST, GX_CP_VCD_HI_TEX7COORD_END)]; - __GXData->vLim = vlim; + gx->vLim = vlim; } void GXGetVtxDesc(int param_0, GXAttrType* param_1) { @@ -200,78 +200,78 @@ void GXGetVtxDesc(int param_0, GXAttrType* param_1) { switch (param_0) { case 0: - local_38 = __GXData->vcdLo & 1; + local_38 = gx->vcdLo & 1; break; case 1: - local_38 = (__GXData->vcdLo & 2) >> 1; + local_38 = (gx->vcdLo & 2) >> 1; break; case 2: - local_38 = (__GXData->vcdLo & 4) >> 2; + local_38 = (gx->vcdLo & 4) >> 2; break; case 3: - local_38 = (__GXData->vcdLo & 8) >> 3; + local_38 = (gx->vcdLo & 8) >> 3; break; case 4: - local_38 = (__GXData->vcdLo & 0x10) >> 4; + local_38 = (gx->vcdLo & 0x10) >> 4; break; case 5: - local_38 = (__GXData->vcdLo & 0x20) >> 5; + local_38 = (gx->vcdLo & 0x20) >> 5; break; case 6: - local_38 = (__GXData->vcdLo & 0x40) >> 6; + local_38 = (gx->vcdLo & 0x40) >> 6; break; case 7: - local_38 = (__GXData->vcdLo & 0x80) >> 7; + local_38 = (gx->vcdLo & 0x80) >> 7; break; case 8: - local_38 = (__GXData->vcdLo & 0x100) >> 8; + local_38 = (gx->vcdLo & 0x100) >> 8; break; case 9: - local_38 = (__GXData->vcdLo & 0x600) >> 9; + local_38 = (gx->vcdLo & 0x600) >> 9; break; case 10: - if (__GXData->hasNrms != 0) { - local_38 = (__GXData->vcdLo & 0x1800) >> 11; + if (gx->hasNrms != 0) { + local_38 = (gx->vcdLo & 0x1800) >> 11; } else { local_38 = 0; } break; case 0x19: - if (__GXData->hasBiNrms != 0) { - local_38 = (__GXData->vcdLo & 0x1800) >> 11; + if (gx->hasBiNrms != 0) { + local_38 = (gx->vcdLo & 0x1800) >> 11; } else { local_38 = 0; } break; case 11: - local_38 = (__GXData->vcdLo & 0x6000) >> 13; + local_38 = (gx->vcdLo & 0x6000) >> 13; break; case 12: - local_38 = (__GXData->vcdLo & 0x18000) >> 15; + local_38 = (gx->vcdLo & 0x18000) >> 15; break; case 13: - local_38 = (__GXData->vcdHi & 3); + local_38 = (gx->vcdHi & 3); break; case 14: - local_38 = (__GXData->vcdHi & 0xC) >> 2; + local_38 = (gx->vcdHi & 0xC) >> 2; break; case 15: - local_38 = (__GXData->vcdHi & 0x30) >> 4; + local_38 = (gx->vcdHi & 0x30) >> 4; break; case 16: - local_38 = (__GXData->vcdHi & 0xC0) >> 6; + local_38 = (gx->vcdHi & 0xC0) >> 6; break; case 17: - local_38 = (__GXData->vcdHi & 0x300) >> 8; + local_38 = (gx->vcdHi & 0x300) >> 8; break; case 18: - local_38 = (__GXData->vcdHi & 0xC00) >> 10; + local_38 = (gx->vcdHi & 0xC00) >> 10; break; case 19: - local_38 = (__GXData->vcdHi & 0x3000) >> 12; + local_38 = (gx->vcdHi & 0x3000) >> 12; break; case 20: - local_38 = (__GXData->vcdHi & 0xC000) >> 14; + local_38 = (gx->vcdHi & 0xC000) >> 14; break; default: local_38 = 0; @@ -297,12 +297,12 @@ void GXGetVtxDescv(GXVtxDescList* attrPtr) { } void GXClearVtxDesc(void) { - __GXData->vcdLo = 0; - GX_BITFIELD_SET(__GXData->vcdLo, 0x15, 2, GX_DIRECT); - __GXData->vcdHi = 0; - __GXData->hasNrms = FALSE; - __GXData->hasBiNrms = FALSE; - __GXData->dirtyState |= GX_DIRTY_VCD; + gx->vcdLo = 0; + GX_BITFIELD_SET(gx->vcdLo, 0x15, 2, GX_DIRECT); + gx->vcdHi = 0; + gx->hasNrms = FALSE; + gx->hasBiNrms = FALSE; + gx->dirtyState |= GX_DIRTY_VCD; } /* ############################################################################################## */ @@ -381,14 +381,14 @@ static inline void SETVAT(u32* vatA, u32* vatB, u32* vatC, GXAttr attr, GXCompCn } void GXSetVtxAttrFmt(GXVtxFmt format, GXAttr attr, GXCompCnt count, GXCompType type, u8 frac) { - u32* vA = (u32*)&__GXData->vatA[format]; - u32* vB = (u32*)&__GXData->vatB[format]; - u32* vC = &__GXData->vatC[format]; + u32* vA = (u32*)&gx->vatA[format]; + u32* vB = (u32*)&gx->vatB[format]; + u32* vC = &gx->vatC[format]; SETVAT(vA, vB, vC, attr, count, type, frac); - __GXData->dirtyState |= GX_DIRTY_VAT; - __GXData->dirtyVAT |= (u8)(1 << (u8)format); + gx->dirtyState |= GX_DIRTY_VAT; + gx->dirtyVAT |= (u8)(1 << (u8)format); } void GXSetVtxAttrFmtv(GXVtxFmt format, GXVtxAttrFmtList* list) { @@ -396,32 +396,32 @@ void GXSetVtxAttrFmtv(GXVtxFmt format, GXVtxAttrFmtList* list) { u32* vatB; u32* vatC; - vatA = (u32*)&__GXData->vatA[format]; - vatB = (u32*)&__GXData->vatB[format]; - vatC = &__GXData->vatC[format]; + vatA = (u32*)&gx->vatA[format]; + vatB = (u32*)&gx->vatB[format]; + vatC = &gx->vatC[format]; for (; list->mAttrib != GX_VA_NULL; list++) { SETVAT(vatA, vatB, vatC, list->mAttrib, list->mCompCnt, list->mCompType, list->mCompShift); } - __GXData->dirtyState |= GX_DIRTY_VAT; - __GXData->dirtyVAT |= (u8)(1 << (u8)format); + gx->dirtyState |= GX_DIRTY_VAT; + gx->dirtyVAT |= (u8)(1 << (u8)format); } void __GXSetVAT(void) { u32 i = 0; - u32 dirtyVAT = __GXData->dirtyVAT; + u32 dirtyVAT = gx->dirtyVAT; do { if (dirtyVAT & (1)) { - GX_CP_LOAD_REG(GX_CP_REG_VAT_GRP0 | i, __GXData->vatA[i]); - GX_CP_LOAD_REG(GX_CP_REG_VAT_GRP1 | i, __GXData->vatB[i]); - GX_CP_LOAD_REG(GX_CP_REG_VAT_GRP2 | i, __GXData->vatC[i]); + GX_CP_LOAD_REG(GX_CP_REG_VAT_GRP0 | i, gx->vatA[i]); + GX_CP_LOAD_REG(GX_CP_REG_VAT_GRP1 | i, gx->vatB[i]); + GX_CP_LOAD_REG(GX_CP_REG_VAT_GRP2 | i, gx->vatC[i]); } dirtyVAT >>= 1; i++; } while (dirtyVAT != 0); - __GXData->dirtyVAT = 0; + gx->dirtyVAT = 0; } static u8 GetFracForNrm(int param_0) { @@ -502,9 +502,9 @@ void GXGetVtxAttrFmt(GXVtxFmt param_0, int param_1, GXCompCnt* param_2, GXCompTy } */ #endif - tmp_1 = (GXCompCnt*)&__GXData->vatA[param_0]; - tmp_2 = (GXCompCnt*)&__GXData->vatB[param_0]; - tmp_3 = &__GXData->vatC[param_0]; + tmp_1 = (GXCompCnt*)&gx->vatA[param_0]; + tmp_2 = (GXCompCnt*)&gx->vatB[param_0]; + tmp_3 = &gx->vatC[param_0]; switch (param_1) { case 9: @@ -717,35 +717,35 @@ void GXSetTexCoordGen2(GXTexCoordID id, GXTexGenType type, GXTexGenSrc src, u32 switch (id) { case GX_TEXCOORD0: - GX_SET_REG(__GXData->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX0_ST, GX_XF_MTXIDX0_TEX0_END); + GX_SET_REG(gx->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX0_ST, GX_XF_MTXIDX0_TEX0_END); break; case GX_TEXCOORD1: - GX_SET_REG(__GXData->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX1_ST, GX_XF_MTXIDX0_TEX1_END); + GX_SET_REG(gx->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX1_ST, GX_XF_MTXIDX0_TEX1_END); break; case GX_TEXCOORD2: - GX_SET_REG(__GXData->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX2_ST, GX_XF_MTXIDX0_TEX2_END); + GX_SET_REG(gx->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX2_ST, GX_XF_MTXIDX0_TEX2_END); break; case GX_TEXCOORD3: - GX_SET_REG(__GXData->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX3_ST, GX_XF_MTXIDX0_TEX3_END); + GX_SET_REG(gx->matIdxA, texMtxIdx, GX_XF_MTXIDX0_TEX3_ST, GX_XF_MTXIDX0_TEX3_END); break; case GX_TEXCOORD4: - GX_SET_REG(__GXData->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX4_ST, GX_XF_MTXIDX1_TEX4_END); + GX_SET_REG(gx->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX4_ST, GX_XF_MTXIDX1_TEX4_END); break; case GX_TEXCOORD5: - GX_SET_REG(__GXData->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX5_ST, GX_XF_MTXIDX1_TEX5_END); + GX_SET_REG(gx->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX5_ST, GX_XF_MTXIDX1_TEX5_END); break; case GX_TEXCOORD6: - GX_SET_REG(__GXData->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX6_ST, GX_XF_MTXIDX1_TEX6_END); + GX_SET_REG(gx->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX6_ST, GX_XF_MTXIDX1_TEX6_END); break; default: - GX_SET_REG(__GXData->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX7_ST, GX_XF_MTXIDX1_TEX7_END); + GX_SET_REG(gx->matIdxB, texMtxIdx, GX_XF_MTXIDX1_TEX7_ST, GX_XF_MTXIDX1_TEX7_END); break; } __GXSetMatrixIndex(id + 1); } void GXSetNumTexGens(u8 count) { - GX_SET_REG(__GXData->genMode, count, GX_BP_GENMODE_NUMTEX_ST, GX_BP_GENMODE_NUMTEX_END); + GX_SET_REG(gx->genMode, count, GX_BP_GENMODE_NUMTEX_ST, GX_BP_GENMODE_NUMTEX_END); GX_XF_LOAD_REG(GX_XF_REG_NUMTEX, count); - __GXData->dirtyState |= GX_DIRTY_GEN_MODE; + gx->dirtyState |= GX_DIRTY_GEN_MODE; } diff --git a/src/dolphin/gx/GXBump.c b/src/dolphin/gx/GXBump.c index 8a5284b2..8e0c8e44 100644 --- a/src/dolphin/gx/GXBump.c +++ b/src/dolphin/gx/GXBump.c @@ -26,7 +26,7 @@ void GXSetTevIndirect(GXTevStageID tevStage, GXIndTexStageID texStage, GXIndTexF GXFIFO.u8 = 0x61; GXFIFO.s32 = field; - __GXData->bpSentNot = 0; + gx->bpSentNot = 0; } void GXSetIndTexMtx(GXIndTexMtxID mtxID, f32 offset[6], s8 scale_exp) { @@ -82,7 +82,7 @@ void GXSetIndTexMtx(GXIndTexMtxID mtxID, f32 offset[6], s8 scale_exp) { GXFIFO.u8 = 0x61; GXFIFO.s32 = field; - __GXData->bpSentNot = 0; + gx->bpSentNot = 0; } void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXIndTexScale scaleT) { @@ -90,7 +90,7 @@ void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXInd switch (texStage) { case GX_INDTEXSTAGE0: - data = __GXData; + data = gx; GX_BITFIELD_SET(data->IndTexScale0, 28, 4, scaleS); GX_BITFIELD_SET(data->IndTexScale0, 24, 4, scaleT); GX_BITFIELD_SET(data->IndTexScale0, 0, 8, 0x25); @@ -98,7 +98,7 @@ void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXInd GXFIFO.s32 = data->IndTexScale0; break; case GX_INDTEXSTAGE1: - data = __GXData; + data = gx; GX_BITFIELD_SET(data->IndTexScale0, 20, 4, scaleS); GX_BITFIELD_SET(data->IndTexScale0, 16, 4, scaleT); GX_BITFIELD_SET(data->IndTexScale0, 0, 8, 0x25); @@ -106,7 +106,7 @@ void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXInd GXFIFO.s32 = data->IndTexScale0; break; case GX_INDTEXSTAGE2: - data = __GXData; + data = gx; GX_BITFIELD_SET(data->IndTexScale1, 28, 4, scaleS); GX_BITFIELD_SET(data->IndTexScale1, 24, 4, scaleT); GX_BITFIELD_SET(data->IndTexScale1, 0, 8, 0x26); @@ -114,7 +114,7 @@ void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXInd GXFIFO.s32 = data->IndTexScale1; break; case GX_INDTEXSTAGE3: - data = __GXData; + data = gx; GX_BITFIELD_SET(data->IndTexScale1, 20, 4, scaleS); GX_BITFIELD_SET(data->IndTexScale1, 16, 4, scaleT); GX_BITFIELD_SET(data->IndTexScale1, 0, 8, 0x26); @@ -123,36 +123,36 @@ void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXInd break; } - __GXData->bpSentNot = 0; + gx->bpSentNot = 0; } void GXSetIndTexOrder(GXIndTexStageID stage, GXTexCoordID coord, GXTexMapID map) { switch (stage) { case GX_INDTEXSTAGE0: - GX_BITFIELD_SET(__GXData->iref, 29, 3, map); - GX_BITFIELD_SET(__GXData->iref, 26, 3, coord); + GX_BITFIELD_SET(gx->iref, 29, 3, map); + GX_BITFIELD_SET(gx->iref, 26, 3, coord); break; case GX_INDTEXSTAGE1: - GX_BITFIELD_SET(__GXData->iref, 23, 3, map); - GX_BITFIELD_SET(__GXData->iref, 20, 3, coord); + GX_BITFIELD_SET(gx->iref, 23, 3, map); + GX_BITFIELD_SET(gx->iref, 20, 3, coord); break; case GX_INDTEXSTAGE2: - GX_BITFIELD_SET(__GXData->iref, 17, 3, map); - GX_BITFIELD_SET(__GXData->iref, 14, 3, coord); + GX_BITFIELD_SET(gx->iref, 17, 3, map); + GX_BITFIELD_SET(gx->iref, 14, 3, coord); break; case GX_INDTEXSTAGE3: - GX_BITFIELD_SET(__GXData->iref, 11, 3, map); - GX_BITFIELD_SET(__GXData->iref, 8, 3, coord); + GX_BITFIELD_SET(gx->iref, 11, 3, map); + GX_BITFIELD_SET(gx->iref, 8, 3, coord); break; } GXFIFO.u8 = 0x61; - GXFIFO.s32 = __GXData->iref; + GXFIFO.s32 = gx->iref; GXSetWasteFlags(); } void GXSetNumIndStages(u8 num) { - GXData* data = __GXData; + GXData* data = gx; GX_BITFIELD_SET(data->genMode, 13, 3, num); data->dirtyState |= GX_DIRTY_BP_MASK | GX_DIRTY_GEN_MODE; } @@ -165,7 +165,7 @@ void GXSetTevDirect(GXTevStageID stage) { void __GXUpdateBPMask(void) {} void __GXSetIndirectMask(u32 mask) { - GXData* data = __GXData; + GXData* data = gx; GX_BITFIELD_SET(data->bpMask, 24, 8, mask); GXFIFO.u8 = 0x61; @@ -175,6 +175,6 @@ void __GXSetIndirectMask(u32 mask) { void __GXFlushTextureState(void) { GXFIFO.u8 = 0x61; - GXFIFO.s32 = __GXData->bpMask; - __GXData->bpSentNot = 0; + GXFIFO.s32 = gx->bpMask; + gx->bpSentNot = 0; } diff --git a/src/dolphin/gx/GXDisplayList.c b/src/dolphin/gx/GXDisplayList.c index eaebb628..e8a170fa 100644 --- a/src/dolphin/gx/GXDisplayList.c +++ b/src/dolphin/gx/GXDisplayList.c @@ -7,11 +7,11 @@ #include "dolphin/gx/GX.h" void GXCallDisplayList(void* list, u32 nbytes) { - if (__GXData->dirtyState != 0) { + if (gx->dirtyState != 0) { __GXSetDirtyState(); } - if (*(u32*)__GXData == 0) { + if (*(u32*)gx == 0) { __GXSendFlushPrim(); } diff --git a/src/dolphin/gx/GXDraw.c b/src/dolphin/gx/GXDraw.c index 22311b3b..a4bf2824 100644 --- a/src/dolphin/gx/GXDraw.c +++ b/src/dolphin/gx/GXDraw.c @@ -1,5 +1,6 @@ #include "dolphin/gx/GXDraw.h" #include "dolphin/gx/GX.h" +#include "math.h" static GXVtxDescList vcd[27]; static GXVtxAttrFmtList vat[27]; @@ -68,4 +69,4 @@ void GXDrawCylinder(u8 numEdges) { GXEnd(); RestoreVertState(); -} \ No newline at end of file +} diff --git a/src/dolphin/gx/GXFifo.c b/src/dolphin/gx/GXFifo.c index 7ff20556..6cf71457 100644 --- a/src/dolphin/gx/GXFifo.c +++ b/src/dolphin/gx/GXFifo.c @@ -1,6 +1,7 @@ #include "dolphin/gx/GXFifo.h" #include "dolphin/gx/GX.h" #include "dolphin/os/OS.h" +#include "dolphin/base/PPCArch.h" static void GXInitFifoLimits(GXFifoObj* fifo, u32 hi_watermark, u32 lo_watermark); @@ -36,8 +37,8 @@ static void GXUnderflowHandler() { static void GXBreakPointHandler(OSContext* context) { OSContext bpContext; - FAST_FLAG_SET(__GXData->cpEnable, 0, 5, 1); - GX_SET_CP_REG(1, __GXData->cpEnable); + FAST_FLAG_SET(gx->cpEnable, 0, 5, 1); + GX_SET_CP_REG(1, gx->cpEnable); if (BreakPointCB) { OSClearContext(&bpContext); @@ -49,17 +50,17 @@ static void GXBreakPointHandler(OSContext* context) { } static void GXCPInterruptHandler(s16 p1, OSContext* context) { - __GXData->cpStatus = GX_GET_CP_REG(0); + gx->cpStatus = GX_GET_CP_REG(0); - if ((__GXData->cpEnable >> 3 & 1) && (__GXData->cpStatus >> 1 & 1)) { + if ((gx->cpEnable >> 3 & 1) && (gx->cpStatus >> 1 & 1)) { GXUnderflowHandler(); } - if ((__GXData->cpEnable >> 2 & 1) && (__GXData->cpStatus >> 0 & 1)) { + if ((gx->cpEnable >> 2 & 1) && (gx->cpStatus >> 0 & 1)) { GXOverflowHandler(); } - if ((__GXData->cpEnable >> 5 & 1) && (__GXData->cpStatus >> 4 & 1)) { + if ((gx->cpEnable >> 5 & 1) && (gx->cpStatus >> 4 & 1)) { GXBreakPointHandler(context); } } @@ -163,11 +164,11 @@ void GXSetGPFifo(GXFifoObj* fifo) { __GXWriteFifoIntEnable(0, 0); __GXFifoLink(0); } - reg = __GXData->cpEnable; + reg = gx->cpEnable; GX_BITFIELD_SET(reg, 0x1e, 1, 0); GX_BITFIELD_SET(reg, 0x1a, 1, 0); GX_SET_CP_REG(1, reg); - GX_SET_CP_REG(1, __GXData->cpEnable); + GX_SET_CP_REG(1, gx->cpEnable); __GXWriteFifoIntReset(1, 1); __GXFifoReadEnable(); OSRestoreInterrupts(interrupts); @@ -198,12 +199,12 @@ void __GXSaveCPUFifoAux(GXFifoObj* fifo) { void GXGetGPStatus(GXBool* overhi, GXBool* underlow, GXBool* readIdle, GXBool* cmdIdle, GXBool* brkpt) { - __GXData->cpStatus = GX_GET_CP_REG(0); - *overhi = __GXData->cpStatus & 1; - *underlow = (__GXData->cpStatus >> 1) & 1; - *readIdle = (__GXData->cpStatus >> 2) & 1; - *cmdIdle = (__GXData->cpStatus >> 3) & 1; - *brkpt = (__GXData->cpStatus >> 4) & 1; + gx->cpStatus = GX_GET_CP_REG(0); + *overhi = gx->cpStatus & 1; + *underlow = (gx->cpStatus >> 1) & 1; + *readIdle = (gx->cpStatus >> 2) & 1; + *cmdIdle = (gx->cpStatus >> 3) & 1; + *brkpt = (gx->cpStatus >> 4) & 1; } void* GXGetFifoBase(GXFifoObj* fifo) { @@ -232,13 +233,13 @@ void __GXFifoInit(void) { } void __GXFifoReadEnable(void) { - FAST_FLAG_SET(__GXData->cpEnable, 1, 0, 1); - GX_SET_CP_REG(1, __GXData->cpEnable); + FAST_FLAG_SET(gx->cpEnable, 1, 0, 1); + GX_SET_CP_REG(1, gx->cpEnable); } void __GXFifoReadDisable(void) { - FAST_FLAG_SET(__GXData->cpEnable, 0, 0, 1); - GX_SET_CP_REG(1, __GXData->cpEnable); + FAST_FLAG_SET(gx->cpEnable, 0, 0, 1); + GX_SET_CP_REG(1, gx->cpEnable); } void __GXFifoLink(u8 link) { @@ -248,20 +249,20 @@ void __GXFifoLink(u8 link) { } else { b = 0; } - FAST_FLAG_SET(__GXData->cpEnable, b, 4, 1); - GX_SET_CP_REG(1, __GXData->cpEnable); + FAST_FLAG_SET(gx->cpEnable, b, 4, 1); + GX_SET_CP_REG(1, gx->cpEnable); } void __GXWriteFifoIntEnable(u32 p1, u32 p2) { - FAST_FLAG_SET(__GXData->cpEnable, p1, 2, 1); - FAST_FLAG_SET(__GXData->cpEnable, (u8)p2, 3, 1); - GX_SET_CP_REG(1, __GXData->cpEnable); + FAST_FLAG_SET(gx->cpEnable, p1, 2, 1); + FAST_FLAG_SET(gx->cpEnable, (u8)p2, 3, 1); + GX_SET_CP_REG(1, gx->cpEnable); } void __GXWriteFifoIntReset(u32 p1, u32 p2) { - FAST_FLAG_SET(__GXData->cpClr, p1, 0, 1); - FAST_FLAG_SET(__GXData->cpClr, (u8)p2, 1, 1); - GX_SET_CP_REG(2, __GXData->cpClr); + FAST_FLAG_SET(gx->cpClr, p1, 0, 1); + FAST_FLAG_SET(gx->cpClr, (u8)p2, 1, 1); + GX_SET_CP_REG(2, gx->cpClr); } void __GXCleanGPFifo(void) { diff --git a/src/dolphin/gx/GXFrameBuf.c b/src/dolphin/gx/GXFrameBuf.c index 3cedf7e6..26273306 100644 --- a/src/dolphin/gx/GXFrameBuf.c +++ b/src/dolphin/gx/GXFrameBuf.c @@ -227,33 +227,33 @@ GXRenderModeObj GXEurgb60Hz480IntDf = { }; void GXSetDispCopySrc(u16 left, u16 top, u16 width, u16 height) { - __GXData->cpDispSrc = 0; - GX_BITFIELD_SET(__GXData->cpDispSrc, 22, 10, left); - GX_BITFIELD_SET(__GXData->cpDispSrc, 12, 10, top); - GX_BITFIELD_SET(__GXData->cpDispSrc, 0, 8, 73); - - __GXData->cpDispSize = 0; - GX_BITFIELD_SET(__GXData->cpDispSize, 22, 10, width - 1); - GX_BITFIELD_SET(__GXData->cpDispSize, 12, 10, height - 1); - GX_BITFIELD_SET(__GXData->cpDispSize, 0, 8, 74); + gx->cpDispSrc = 0; + GX_BITFIELD_SET(gx->cpDispSrc, 22, 10, left); + GX_BITFIELD_SET(gx->cpDispSrc, 12, 10, top); + GX_BITFIELD_SET(gx->cpDispSrc, 0, 8, 73); + + gx->cpDispSize = 0; + GX_BITFIELD_SET(gx->cpDispSize, 22, 10, width - 1); + GX_BITFIELD_SET(gx->cpDispSize, 12, 10, height - 1); + GX_BITFIELD_SET(gx->cpDispSize, 0, 8, 74); } void GXSetTexCopySrc(u16 left, u16 top, u16 width, u16 height) { - __GXData->cpTexSrc = 0; - GX_BITFIELD_SET(__GXData->cpTexSrc, 22, 10, left); - GX_BITFIELD_SET(__GXData->cpTexSrc, 12, 10, top); - GX_BITFIELD_SET(__GXData->cpTexSrc, 0, 8, 0x49); - __GXData->cpTexSize = 0; - GX_BITFIELD_SET(__GXData->cpTexSize, 22, 10, width - 1); - GX_BITFIELD_SET(__GXData->cpTexSize, 12, 10, height - 1); - GX_BITFIELD_SET(__GXData->cpTexSize, 0, 8, 0x4A); + gx->cpTexSrc = 0; + GX_BITFIELD_SET(gx->cpTexSrc, 22, 10, left); + GX_BITFIELD_SET(gx->cpTexSrc, 12, 10, top); + GX_BITFIELD_SET(gx->cpTexSrc, 0, 8, 0x49); + gx->cpTexSize = 0; + GX_BITFIELD_SET(gx->cpTexSize, 22, 10, width - 1); + GX_BITFIELD_SET(gx->cpTexSize, 12, 10, height - 1); + GX_BITFIELD_SET(gx->cpTexSize, 0, 8, 0x4A); } void GXSetDispCopyDst(u16 arg0, u16 arg1) { s32 val = (s32)((arg0 << 1) & 0xFFFE) >> 5; - __GXData->cpDispStride = 0; - GX_BITFIELD_SET(__GXData->cpDispStride, 22, 10, val); - GX_BITFIELD_SET(__GXData->cpDispStride, 0, 8, 0x4D); + gx->cpDispStride = 0; + GX_BITFIELD_SET(gx->cpDispStride, 22, 10, val); + GX_BITFIELD_SET(gx->cpDispStride, 0, 8, 0x4D); } void GXSetTexCopyDst(u16 width, u16 height, GXTexFmt format, GXBool useMIPmap) { @@ -261,7 +261,7 @@ void GXSetTexCopyDst(u16 width, u16 height, GXTexFmt format, GXBool useMIPmap) { u32 value; u8 depthRelated; - __GXData->cpTexZ = GX_NONE; + gx->cpTexZ = GX_NONE; depthRelated = format & 0xf; if (format == GX_TF_Z16) { @@ -274,34 +274,34 @@ void GXSetTexCopyDst(u16 width, u16 height, GXTexFmt format, GXBool useMIPmap) { case GX_TF_IA4: case GX_TF_IA8: case GX_CTF_A8: - GX_SET_REG(__GXData->cpTex, 3, 15, 16); + GX_SET_REG(gx->cpTex, 3, 15, 16); break; default: - GX_SET_REG(__GXData->cpTex, 2, 15, 16); + GX_SET_REG(gx->cpTex, 2, 15, 16); break; } - __GXData->cpTexZ = (format & 0x10) == 0x10; + gx->cpTexZ = (format & 0x10) == 0x10; value = depthRelated >> 3; - GX_SET_REG(__GXData->cpTex, value, 28, 28); + GX_SET_REG(gx->cpTex, value, 28, 28); depthRelated &= 7; __GetImageTileCount(format, width, height, &sp20, &sp1C, &sp18); - __GXData->cpTexStride = GX_NONE; - GX_SET_REG(__GXData->cpTexStride, sp20 * sp18, 22, 31); - GX_SET_REG(__GXData->cpTexStride, 0x4D, 0, 7); + gx->cpTexStride = GX_NONE; + GX_SET_REG(gx->cpTexStride, sp20 * sp18, 22, 31); + GX_SET_REG(gx->cpTexStride, 0x4D, 0, 7); - GX_SET_REG(__GXData->cpTex, useMIPmap, 22, 22); - GX_SET_REG(__GXData->cpTex, depthRelated, 25, 27); + GX_SET_REG(gx->cpTex, useMIPmap, 22, 22); + GX_SET_REG(gx->cpTex, depthRelated, 25, 27); } void GXSetDispCopyFrame2Field(GXCopyMode arg0) { - GX_BITFIELD_SET(__GXData->cpDisp, 18, 2, arg0); - GX_BITFIELD_SET(__GXData->cpTex, 18, 2, 0); + GX_BITFIELD_SET(gx->cpDisp, 18, 2, arg0); + GX_BITFIELD_SET(gx->cpTex, 18, 2, 0); } // clang-format off @@ -313,10 +313,10 @@ void GXSetDispCopyFrame2Field(GXCopyMode arg0) { void GXSetCopyClamp(GXFBClamp clamp) { u8 isTop = (clamp & GX_CLAMP_TOP) == GX_CLAMP_TOP; u8 isBottom = (clamp & GX_CLAMP_BOTTOM) == GX_CLAMP_BOTTOM; - __GXData->cpDisp = __rlwimi(__GXData->cpDisp, isTop, 0, 31, 31); - __GXData->cpDisp = __rlwimi(__GXData->cpDisp, isBottom, 1, 30, 30); - __GXData->cpTex = __rlwimi(__GXData->cpTex, isTop, 0, 31, 31); - __GXData->cpTex = __rlwimi(__GXData->cpTex, isBottom, 1, 30, 30); + gx->cpDisp = __rlwimi(gx->cpDisp, isTop, 0, 31, 31); + gx->cpDisp = __rlwimi(gx->cpDisp, isBottom, 1, 30, 30); + gx->cpTex = __rlwimi(gx->cpTex, isTop, 0, 31, 31); + gx->cpTex = __rlwimi(gx->cpTex, isBottom, 1, 30, 30); } static u32 __GXGetNumXfbLines(u32 height, u32 scale) { @@ -396,11 +396,11 @@ u32 GXSetDispCopyYScale(f32 vertScale) { GX_SET_REG(reg, scale, 23, 31); GX_SET_REG(reg, 0x4E, 0, 7); GX_BP_LOAD_REG(reg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; - GX_SET_REG(__GXData->cpDisp, check, 21, 21); + GX_SET_REG(gx->cpDisp, check, 21, 21); - height = (__GXData->cpDispSize >> 10 & 0x3FF) + 1; + height = (gx->cpDispSize >> 10 & 0x3FF) + 1; return __GXGetNumXfbLines(height, scale); } @@ -426,7 +426,7 @@ void GXSetCopyClear(GXColor color, u32 clear_z) { GXFIFO.u8 = 0x61; GXFIFO.u32 = r6; - __GXData->bpSentNot = 0; + gx->bpSentNot = 0; } void GXSetCopyFilter(GXBool useAA, u8 samplePattern[12][2], GXBool doVertFilt, u8 vFilt[7]) { @@ -509,11 +509,11 @@ void GXSetCopyFilter(GXBool useAA, u8 samplePattern[12][2], GXBool doVertFilt, u GX_BP_LOAD_REG(unk1); GX_BP_LOAD_REG(unk2); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetDispCopyGamma(GXGamma gamma) { - GX_BITFIELD_SET(__GXData->cpDisp, 23, 2, gamma); + GX_BITFIELD_SET(gx->cpDisp, 23, 2, gamma); } void GXCopyDisp(void* dest, GXBool doClear) { @@ -522,28 +522,28 @@ void GXCopyDisp(void* dest, GXBool doClear) { GXBool check; if (doClear) { - reg = __GXData->zmode; + reg = gx->zmode; GX_SET_REG(reg, 1, 31, 31); GX_SET_REG(reg, 7, 28, 30); GX_BP_LOAD_REG(reg); - reg = __GXData->cmode0; + reg = gx->cmode0; GX_SET_REG(reg, 0, 31, 31); GX_SET_REG(reg, 0, 30, 30); GX_BP_LOAD_REG(reg); } check = GX_FALSE; - if ((doClear || (__GXData->peCtrl & 0x7) == 3) && (__GXData->peCtrl >> 6 & 0x1) == 1) { + if ((doClear || (gx->peCtrl & 0x7) == 3) && (gx->peCtrl >> 6 & 0x1) == 1) { check = GX_TRUE; - reg = __GXData->peCtrl; + reg = gx->peCtrl; GX_SET_REG(reg, 0, 25, 25); GX_BP_LOAD_REG(reg); } - GX_BP_LOAD_REG(__GXData->cpDispSrc); - GX_BP_LOAD_REG(__GXData->cpDispSize); - GX_BP_LOAD_REG(__GXData->cpDispStride); + GX_BP_LOAD_REG(gx->cpDispSrc); + GX_BP_LOAD_REG(gx->cpDispSize); + GX_BP_LOAD_REG(gx->cpDispStride); newDest = (u32)dest & 0x3FFFFFFF; reg = 0; @@ -551,21 +551,21 @@ void GXCopyDisp(void* dest, GXBool doClear) { GX_SET_REG(reg, 0x4B, 0, 7); GX_BP_LOAD_REG(reg); - GX_SET_REG(__GXData->cpDisp, doClear, 20, 20); - GX_SET_REG(__GXData->cpDisp, 1, 17, 17); - GX_SET_REG(__GXData->cpDisp, 0x52, 0, 7); - GX_BP_LOAD_REG(__GXData->cpDisp); + GX_SET_REG(gx->cpDisp, doClear, 20, 20); + GX_SET_REG(gx->cpDisp, 1, 17, 17); + GX_SET_REG(gx->cpDisp, 0x52, 0, 7); + GX_BP_LOAD_REG(gx->cpDisp); if (doClear) { - GX_BP_LOAD_REG(__GXData->zmode); - GX_BP_LOAD_REG(__GXData->cmode0); + GX_BP_LOAD_REG(gx->zmode); + GX_BP_LOAD_REG(gx->cmode0); } if (check) { - GX_BP_LOAD_REG(__GXData->peCtrl); + GX_BP_LOAD_REG(gx->peCtrl); } - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXCopyTex(void* dest, GXBool doClear) { @@ -575,20 +575,20 @@ void GXCopyTex(void* dest, GXBool doClear) { GXBool check; if (doClear) { - reg = __GXData->zmode; + reg = gx->zmode; GX_SET_REG(reg, 1, 31, 31); GX_SET_REG(reg, 7, 28, 30); GX_BP_LOAD_REG(reg); - reg = __GXData->cmode0; + reg = gx->cmode0; GX_SET_REG(reg, 0, 31, 31); GX_SET_REG(reg, 0, 30, 30); GX_BP_LOAD_REG(reg); } check = GX_FALSE; - reg2 = __GXData->peCtrl; - if (__GXData->cpTexZ && (reg2 & 0x7) != 3) { + reg2 = gx->peCtrl; + if (gx->cpTexZ && (reg2 & 0x7) != 3) { check = GX_TRUE; GX_SET_REG(reg2, 3, 29, 31); } @@ -602,9 +602,9 @@ void GXCopyTex(void* dest, GXBool doClear) { GX_BP_LOAD_REG(reg2); } - GX_BP_LOAD_REG(__GXData->cpTexSrc); - GX_BP_LOAD_REG(__GXData->cpTexSize); - GX_BP_LOAD_REG(__GXData->cpTexStride); + GX_BP_LOAD_REG(gx->cpTexSrc); + GX_BP_LOAD_REG(gx->cpTexSize); + GX_BP_LOAD_REG(gx->cpTexStride); newDest = (u32)dest & 0x3FFFFFFF; reg = 0; @@ -612,21 +612,21 @@ void GXCopyTex(void* dest, GXBool doClear) { GX_SET_REG(reg, 0x4B, 0, 7); GX_BP_LOAD_REG(reg); - GX_SET_REG(__GXData->cpTex, doClear, 20, 20); - GX_SET_REG(__GXData->cpTex, 0, 17, 17); - GX_SET_REG(__GXData->cpTex, 0x52, 0, 7); - GX_BP_LOAD_REG(__GXData->cpTex); + GX_SET_REG(gx->cpTex, doClear, 20, 20); + GX_SET_REG(gx->cpTex, 0, 17, 17); + GX_SET_REG(gx->cpTex, 0x52, 0, 7); + GX_BP_LOAD_REG(gx->cpTex); if (doClear) { - GX_BP_LOAD_REG(__GXData->zmode); - GX_BP_LOAD_REG(__GXData->cmode0); + GX_BP_LOAD_REG(gx->zmode); + GX_BP_LOAD_REG(gx->cmode0); } if (check) { - GX_BP_LOAD_REG(__GXData->peCtrl); + GX_BP_LOAD_REG(gx->peCtrl); } - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXClearBoundingBox(void) { diff --git a/src/dolphin/gx/GXGeometry.c b/src/dolphin/gx/GXGeometry.c index a6de9560..94c2594a 100644 --- a/src/dolphin/gx/GXGeometry.c +++ b/src/dolphin/gx/GXGeometry.c @@ -7,7 +7,7 @@ #include "dolphin/gx/GX.h" void __GXSetDirtyState(void) { - u32 dirtyFlags = __GXData->dirtyState; + u32 dirtyFlags = gx->dirtyState; if (dirtyFlags & GX_DIRTY_SU_TEX) { __GXSetSUTexRegs(); @@ -33,11 +33,11 @@ void __GXSetDirtyState(void) { __GXCalculateVLim(); } - __GXData->dirtyState = 0; + gx->dirtyState = 0; } void GXBegin(GXPrimitive type, GXVtxFmt fmt, u16 vert_num) { - GXData* data = __GXData; + GXData* data = gx; u32 dirtyFlags = data->dirtyState; if (data->dirtyState != 0) { @@ -65,10 +65,10 @@ void GXBegin(GXPrimitive type, GXVtxFmt fmt, u16 vert_num) { __GXCalculateVLim(); } - __GXData->dirtyState = 0; + gx->dirtyState = 0; } - if (*(u32*)__GXData == 0) { + if (*(u32*)gx == 0) { __GXSendFlushPrim(); } @@ -78,20 +78,20 @@ void GXBegin(GXPrimitive type, GXVtxFmt fmt, u16 vert_num) { void __GXSendFlushPrim(void) { u32 i; - u32 sz = __GXData->vNum * __GXData->vLim; + u32 sz = gx->vNum * gx->vLim; GXFIFO.u8 = 0x98; - GXFIFO.u16 = __GXData->vNum; + GXFIFO.u16 = gx->vNum; for (i = 0; i < sz; i += 4) { GXFIFO.s32 = 0; } - __GXData->bpSentNot = 1; + gx->bpSentNot = 1; } void GXSetLineWidth(u8 width, GXTexOffset offsets) { - GXData* data = __GXData; + GXData* data = gx; GX_BITFIELD_SET(data->lpSize, 24, 8, width); GX_BITFIELD_SET(data->lpSize, 13, 3, offsets); @@ -101,7 +101,7 @@ void GXSetLineWidth(u8 width, GXTexOffset offsets) { } void GXSetPointSize(u8 size, GXTexOffset offsets) { - GXData* data = __GXData; + GXData* data = gx; GX_BITFIELD_SET(data->lpSize, 16, 8, size); GX_BITFIELD_SET(data->lpSize, 10, 3, offsets); @@ -111,7 +111,7 @@ void GXSetPointSize(u8 size, GXTexOffset offsets) { } void GXEnableTexOffsets(GXTexCoordID coord, GXBool line, GXBool point) { - GXData* data = __GXData; + GXData* data = gx; GX_BITFIELD_SET(data->suTs0[coord], 13, 1, line); GX_BITFIELD_SET(data->suTs0[coord], 12, 1, point); @@ -123,7 +123,7 @@ void GXEnableTexOffsets(GXTexCoordID coord, GXBool line, GXBool point) { void GXSetCullMode(GXCullMode mode) { GXData* data; GXCullMode mode2; - data = __GXData; + data = gx; mode2 = (mode >> 1) & 1; GX_BITFIELD_SET(mode2, 30, 1, mode); @@ -133,7 +133,7 @@ void GXSetCullMode(GXCullMode mode) { } void GXSetCoPlanar(GXBool enable) { - GXData* data = __GXData; + GXData* data = gx; GX_BITFIELD_SET(data->genMode, 12, 1, enable); GXFIFO.u8 = 0x61; @@ -144,6 +144,6 @@ void GXSetCoPlanar(GXBool enable) { void __GXSetGenMode(void) { GXFIFO.u8 = 0x61; - GXFIFO.u32 = __GXData->genMode; - __GXData->bpSentNot = 0; + GXFIFO.u32 = gx->genMode; + gx->bpSentNot = 0; } diff --git a/src/dolphin/gx/GXInit.c b/src/dolphin/gx/GXInit.c index b9d3c126..db232c22 100644 --- a/src/dolphin/gx/GXInit.c +++ b/src/dolphin/gx/GXInit.c @@ -1,6 +1,7 @@ #include "dolphin/gx/GX.h" #include "dolphin/os/OS.h" #include "dolphin/vi/vi.h" +#include "dolphin/base/PPCArch.h" char* __GXVersion = "<< Dolphin SDK - GX release build: Nov 10 2004 06:27:12 (0x2301) >>"; @@ -8,7 +9,7 @@ static GXData gxData; static GXFifoObj FifoObj; -GXData* const __GXData = &gxData; +GXData* const gx = &gxData; GXTexRegion* __GXDefaultTexRegionCallback(const GXTexObj* obj, GXTexMapID id) { GXTexFmt format; @@ -16,9 +17,9 @@ GXTexRegion* __GXDefaultTexRegionCallback(const GXTexObj* obj, GXTexMapID id) { format = GXGetTexObjFmt(obj); if (format != GX_TF_C4 && format != GX_TF_C8 && format != GX_TF_C14X2) { - return &__GXData->TexRegions0[__GXData->nextTexRgn++ % GX_MAX_TEXMAP]; + return &gx->TexRegions0[gx->nextTexRgn++ % GX_MAX_TEXMAP]; } else { - return &__GXData->TexRegions1[__GXData->nextTexRgnCI++ % 4]; + return &gx->TexRegions1[gx->nextTexRgnCI++ % 4]; } } @@ -26,7 +27,7 @@ GXTlutRegion* __GXDefaultTlutRegionCallback(u32 tlut) { if (tlut >= 0x14) { return NULL; } else { - return &__GXData->TlutRegions[tlut]; + return &gx->TlutRegions[tlut]; } } @@ -50,12 +51,12 @@ u32* __piReg; 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); + FAST_FLAG_SET(gx->vatA[i], 1, 30, 33); + FAST_FLAG_SET(gx->vatB[i], 1, 31, 33); GXFIFO.u8 = 0x8; GXFIFO.u8 = i | 0x80; - GXFIFO.u32 = __GXData->vatB[i]; + GXFIFO.u32 = gx->vatB[i]; } { @@ -133,11 +134,11 @@ GXFifoObj* GXInit(void* base, u32 size) { u32 pad2; // for stack matching OSRegisterVersion(__GXVersion); - __GXData->inDispList = GX_FALSE; - __GXData->dlSaveContext = GX_TRUE; + gx->inDispList = GX_FALSE; + gx->dlSaveContext = GX_TRUE; - __GXData->tcsManEnab = 0; - __GXData->tevTcEnab = 0; + gx->tcsManEnab = 0; + gx->tevTcEnab = 0; GXSetMisc(GX_MT_XF_FLUSH, 0); @@ -155,54 +156,54 @@ GXFifoObj* GXInit(void* base, u32 size) { __GXPEInit(); EnableWriteGatherPipe(); - __GXData->genMode = 0; - FAST_FLAG_SET(__GXData->genMode, 0, 24, 8); + gx->genMode = 0; + FAST_FLAG_SET(gx->genMode, 0, 24, 8); - __GXData->bpMask = 255; - FAST_FLAG_SET(__GXData->bpMask, 0xF, 24, 8); + gx->bpMask = 255; + FAST_FLAG_SET(gx->bpMask, 0xF, 24, 8); - __GXData->lpSize = 0; - FAST_FLAG_SET(__GXData->lpSize, 34, 24, 8); + gx->lpSize = 0; + FAST_FLAG_SET(gx->lpSize, 34, 24, 8); for (i = 0; i < GX_MAX_TEVSTAGE; i++) { - __GXData->tevc[i] = 0; - __GXData->teva[i] = 0; - __GXData->tref[i / 2] = 0; - __GXData->texmapId[i] = GX_TEXMAP_NULL; - - FAST_FLAG_SET(__GXData->tevc[i], 0xC0 + i * 2, 24, 8); - FAST_FLAG_SET(__GXData->teva[i], 0xC1 + i * 2, 24, 8); - FAST_FLAG_SET(__GXData->tevKsel[i / 2], 0xF6 + i / 2, 24, 8); - FAST_FLAG_SET(__GXData->tref[i / 2], 0x28 + i / 2, 24, 8); + gx->tevc[i] = 0; + gx->teva[i] = 0; + gx->tref[i / 2] = 0; + gx->texmapId[i] = GX_TEXMAP_NULL; + + FAST_FLAG_SET(gx->tevc[i], 0xC0 + i * 2, 24, 8); + FAST_FLAG_SET(gx->teva[i], 0xC1 + i * 2, 24, 8); + FAST_FLAG_SET(gx->tevKsel[i / 2], 0xF6 + i / 2, 24, 8); + FAST_FLAG_SET(gx->tref[i / 2], 0x28 + i / 2, 24, 8); } - __GXData->iref = 0; - FAST_FLAG_SET(__GXData->iref, 0x27, 24, 8); + gx->iref = 0; + FAST_FLAG_SET(gx->iref, 0x27, 24, 8); for (i = 0; i < GX_MAXCOORD; i++) { - __GXData->suTs0[i] = 0; - __GXData->suTs1[i] = 0; + gx->suTs0[i] = 0; + gx->suTs1[i] = 0; - FAST_FLAG_SET(__GXData->suTs0[i], 0x30 + i * 2, 24, 8); - FAST_FLAG_SET(__GXData->suTs1[i], 0x31 + i * 2, 24, 8); + FAST_FLAG_SET(gx->suTs0[i], 0x30 + i * 2, 24, 8); + FAST_FLAG_SET(gx->suTs1[i], 0x31 + i * 2, 24, 8); } - FAST_FLAG_SET(__GXData->suScis0, 0x20, 24, 8); - FAST_FLAG_SET(__GXData->suScis1, 0x21, 24, 8); + FAST_FLAG_SET(gx->suScis0, 0x20, 24, 8); + FAST_FLAG_SET(gx->suScis1, 0x21, 24, 8); - FAST_FLAG_SET(__GXData->cmode0, 0x41, 24, 8); - FAST_FLAG_SET(__GXData->cmode1, 0x42, 24, 8); + FAST_FLAG_SET(gx->cmode0, 0x41, 24, 8); + FAST_FLAG_SET(gx->cmode1, 0x42, 24, 8); - FAST_FLAG_SET(__GXData->zmode, 0x40, 24, 8); - FAST_FLAG_SET(__GXData->peCtrl, 0x43, 24, 8); + FAST_FLAG_SET(gx->zmode, 0x40, 24, 8); + FAST_FLAG_SET(gx->peCtrl, 0x43, 24, 8); - FAST_FLAG_SET(__GXData->cpTex, 0, 7, 2); + FAST_FLAG_SET(gx->cpTex, 0, 7, 2); - __GXData->zScale = 1.6777216E7f; - __GXData->zOffset = 0.0f; + gx->zScale = 1.6777216E7f; + gx->zOffset = 0.0f; - __GXData->dirtyState = 0; - __GXData->dirtyVAT = 0; + gx->dirtyState = 0; + gx->dirtyVAT = 0; { u32 val1; @@ -225,29 +226,29 @@ GXFifoObj* GXInit(void* base, u32 size) { __GXInitRevisionBits(); for (i = 0; i < GX_MAX_TEXMAP; i++) { - GXInitTexCacheRegion(&__GXData->TexRegions0[i], GX_FALSE, GXTexRegionAddrTable[i], + GXInitTexCacheRegion(&gx->TexRegions0[i], GX_FALSE, GXTexRegionAddrTable[i], GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 8], GX_TEXCACHE_32K); - GXInitTexCacheRegion(&__GXData->TexRegions1[i], GX_FALSE, GXTexRegionAddrTable[i + 16], + GXInitTexCacheRegion(&gx->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); } for (i = 0; i < GX_MAX_TLUT; i++) { - GXInitTlutRegion(&__GXData->TlutRegions[i], 0xC0000 + 0x2000 * i, GX_TLUT_256); + GXInitTlutRegion(&gx->TlutRegions[i], 0xC0000 + 0x2000 * i, GX_TLUT_256); } for (i = 0; i < GX_MAX_BIGTLUT; i++) { - GXInitTlutRegion(&__GXData->TlutRegions[i + 16], 0xE0000 + 0x8000 * i, GX_TLUT_1K); + GXInitTlutRegion(&gx->TlutRegions[i + 16], 0xE0000 + 0x8000 * i, GX_TLUT_1K); } GX_SET_CP_REG(3, 0); - FAST_FLAG_SET(__GXData->perfSel, 0, 4, 4); + FAST_FLAG_SET(gx->perfSel, 0, 4, 4); GXFIFO.u8 = 0x8; GXFIFO.u8 = 0x20; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; GXFIFO.u8 = 0x10; GXFIFO.u32 = 0x1006; @@ -311,7 +312,7 @@ void __GXInitGX(void) { GXInvalidateVtxCache(); for (i = GX_VA_POS; i <= GX_LIGHT_ARRAY; i++) { - GXSetArray((GXAttr)i, __GXData, 0); + GXSetArray((GXAttr)i, gx, 0); } for (i = 0; i < GX_MAX_VTXFMT; i++) { @@ -372,8 +373,8 @@ void __GXInitGX(void) { GXSetChanMatColor(GX_COLOR1A1, matColor); GXInvalidateTexAll(); - __GXData->nextTexRgn = 0; - __GXData->nextTexRgnCI = 0; + gx->nextTexRgn = 0; + gx->nextTexRgnCI = 0; GXSetTexRegionCallback(__GXDefaultTexRegionCallback); GXSetTlutRegionCallback(__GXDefaultTlutRegionCallback); diff --git a/src/dolphin/gx/GXLight.c b/src/dolphin/gx/GXLight.c index a90c2a21..3ab5e37c 100644 --- a/src/dolphin/gx/GXLight.c +++ b/src/dolphin/gx/GXLight.c @@ -171,7 +171,7 @@ void GXLoadLightObjImm(GXLightObj* obj, GXLightID light) { GX_XF_LOAD_REG_HDR(addr | (0x10 - 1) << 16); PushLight(pObj, (void*)GXFIFO_ADDR); - __GXData->bpSentNot = 1; + gx->bpSentNot = 1; } void GXSetChanAmbColor(GXChannelID channel, GXColor color) { @@ -181,22 +181,22 @@ void GXSetChanAmbColor(GXChannelID channel, GXColor color) { switch (channel) { case GX_COLOR0: - reg = __GXData->ambColor[GX_COLOR0]; + reg = gx->ambColor[GX_COLOR0]; reg = GX_SET_TRUNC(reg, GXCOLOR_AS_U32(color), 0, 23); colorID = GX_COLOR0; break; case GX_COLOR1: - reg = __GXData->ambColor[GX_COLOR1]; + reg = gx->ambColor[GX_COLOR1]; reg = GX_SET_TRUNC(reg, GXCOLOR_AS_U32(color), 0, 23); colorID = GX_COLOR1; break; case GX_ALPHA0: - reg = __GXData->ambColor[GX_COLOR0]; + reg = gx->ambColor[GX_COLOR0]; reg = GX_SET_TRUNC(reg, color.a, 24, 31); colorID = GX_COLOR0; break; case GX_ALPHA1: - reg = __GXData->ambColor[GX_COLOR1]; + reg = gx->ambColor[GX_COLOR1]; reg = GX_SET_TRUNC(reg, color.a, 24, 31); colorID = GX_COLOR1; break; @@ -213,8 +213,8 @@ void GXSetChanAmbColor(GXChannelID channel, GXColor color) { } GX_XF_LOAD_REG(GX_XF_REG_AMBIENT0 + colorID, reg); - __GXData->bpSentNot = GX_TRUE; - __GXData->ambColor[colorID] = reg; + gx->bpSentNot = GX_TRUE; + gx->ambColor[colorID] = reg; } void GXSetChanMatColor(GXChannelID channel, GXColor color) { @@ -223,22 +223,22 @@ void GXSetChanMatColor(GXChannelID channel, GXColor color) { switch (channel) { case GX_COLOR0: - reg = __GXData->matColor[GX_COLOR0]; + reg = gx->matColor[GX_COLOR0]; reg = GX_SET_TRUNC(reg, GXCOLOR_AS_U32(color), 0, 23); colorID = GX_COLOR0; break; case GX_COLOR1: - reg = __GXData->matColor[GX_COLOR1]; + reg = gx->matColor[GX_COLOR1]; reg = GX_SET_TRUNC(reg, GXCOLOR_AS_U32(color), 0, 23); colorID = GX_COLOR1; break; case GX_ALPHA0: - reg = __GXData->matColor[GX_COLOR0]; + reg = gx->matColor[GX_COLOR0]; reg = GX_SET_TRUNC(reg, color.a, 24, 31); colorID = GX_COLOR0; break; case GX_ALPHA1: - reg = __GXData->matColor[GX_COLOR1]; + reg = gx->matColor[GX_COLOR1]; reg = GX_SET_TRUNC(reg, color.a, 24, 31); colorID = GX_COLOR1; break; @@ -255,14 +255,14 @@ void GXSetChanMatColor(GXChannelID channel, GXColor color) { } GX_XF_LOAD_REG(GX_XF_REG_MATERIAL0 + colorID, reg); - __GXData->bpSentNot = GX_TRUE; - __GXData->matColor[colorID] = reg; + gx->bpSentNot = GX_TRUE; + gx->matColor[colorID] = reg; } void GXSetNumChans(u8 count) { - GX_SET_REG(__GXData->genMode, count, 25, 27); + GX_SET_REG(gx->genMode, count, 25, 27); GX_XF_LOAD_REG(GX_XF_REG_NUMCOLORS, count); - __GXData->dirtyState |= GX_DIRTY_GEN_MODE; + gx->dirtyState |= GX_DIRTY_GEN_MODE; } void GXSetChanCtrl(GXChannelID channel, GXBool doEnable, GXColorSrc ambSrc, GXColorSrc matSrc, @@ -290,5 +290,5 @@ void GXSetChanCtrl(GXChannelID channel, GXBool doEnable, GXColorSrc ambSrc, GXCo GX_XF_LOAD_REG(GX_XF_REG_ALPHA1CNTRL, reg); } - __GXData->bpSentNot = GX_TRUE; + gx->bpSentNot = GX_TRUE; } diff --git a/src/dolphin/gx/GXMisc.c b/src/dolphin/gx/GXMisc.c index b0a144e5..c09b515d 100644 --- a/src/dolphin/gx/GXMisc.c +++ b/src/dolphin/gx/GXMisc.c @@ -3,6 +3,7 @@ #include "dolphin/os/OSInterrupt.h" #include "dolphin/os/OSReset.h" #include "dolphin/os/OSTime.h" +#include "dolphin/base/PPCArch.h" static void GXTokenInterruptHandler(__OSInterrupt interrupt, OSContext* context); static void GXFinishInterruptHandler(__OSInterrupt interrupt, OSContext* pContext); @@ -13,23 +14,23 @@ void GXSetMisc(GXMiscToken token, u32 val) { break; case GX_MT_XF_FLUSH: - __GXData->vNum = val; - __GXData->vNumNot = !__GXData->vNum; - __GXData->bpSentNot = GX_TRUE; + gx->vNum = val; + gx->vNumNot = !gx->vNum; + gx->bpSentNot = GX_TRUE; - if (__GXData->vNum) { - __GXData->dirtyState |= GX_DIRTY_VCD; + if (gx->vNum) { + gx->dirtyState |= GX_DIRTY_VCD; } break; case GX_MT_DL_SAVE_CONTEXT: - __GXData->dlSaveContext = (val != 0); + gx->dlSaveContext = (val != 0); break; } } void GXFlush(void) { - if (__GXData->dirtyState) { + if (gx->dirtyState) { __GXSetDirtyState(); } @@ -101,8 +102,8 @@ void GXDrawDone(void) { void GXPixModeSync(void) { GXFIFO.u8 = 0x61; - GXFIFO.u32 = __GXData->peCtrl; - __GXData->bpSentNot = 0; + GXFIFO.u32 = gx->peCtrl; + gx->bpSentNot = 0; } void GXPokeAlphaMode(GXCompare comp, u8 threshold) { diff --git a/src/dolphin/gx/GXPerf.c b/src/dolphin/gx/GXPerf.c index b8099a94..5ff6d6a5 100644 --- a/src/dolphin/gx/GXPerf.c +++ b/src/dolphin/gx/GXPerf.c @@ -2,7 +2,7 @@ #include "dolphin/gx/GX.h" void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { - switch (__GXData->perf0) { + switch (gx->perf0) { case GX_PERF0_VERTICES: case GX_PERF0_CLIP_VTX: case GX_PERF0_CLIP_CLKS: @@ -53,7 +53,7 @@ void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { break; } - switch (__GXData->perf1) { + switch (gx->perf1) { case GX_PERF1_TEXELS: case GX_PERF1_TX_IDLE: case GX_PERF1_TX_REGS: @@ -75,10 +75,10 @@ void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { case GX_PERF1_VC_STREAMBUF_LOW: case GX_PERF1_VC_ALL_STALLS: case GX_PERF1_VERTICES: - FAST_FLAG_SET(__GXData->perfSel, 0, 4, 4); + FAST_FLAG_SET(gx->perfSel, 0, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_FIFO_REQ: @@ -92,9 +92,9 @@ void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { break; } - __GXData->perf0 = perf0; + gx->perf0 = perf0; - switch (__GXData->perf0) { + switch (gx->perf0) { case GX_PERF0_VERTICES: GXFIFO.u8 = 0x10; GXFIFO.u32 = 0x1006; @@ -231,9 +231,9 @@ void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { break; } - __GXData->perf1 = perf1; + gx->perf1 = perf1; - switch (__GXData->perf1) { + switch (gx->perf1) { case GX_PERF1_TEXELS: GFWriteBPCmd(0x67000042); break; @@ -266,52 +266,52 @@ void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { break; case GX_PERF1_VC_ELEMQ_FULL: - FAST_FLAG_SET(__GXData->perfSel, 2, 4, 4); + FAST_FLAG_SET(gx->perfSel, 2, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_VC_MISSQ_FULL: - FAST_FLAG_SET(__GXData->perfSel, 3, 4, 4); + FAST_FLAG_SET(gx->perfSel, 3, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_VC_MEMREQ_FULL: - FAST_FLAG_SET(__GXData->perfSel, 4, 4, 4); + FAST_FLAG_SET(gx->perfSel, 4, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_VC_STATUS7: - FAST_FLAG_SET(__GXData->perfSel, 5, 4, 4); + FAST_FLAG_SET(gx->perfSel, 5, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_VC_MISSREP_FULL: - FAST_FLAG_SET(__GXData->perfSel, 6, 4, 4); + FAST_FLAG_SET(gx->perfSel, 6, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_VC_STREAMBUF_LOW: - FAST_FLAG_SET(__GXData->perfSel, 7, 4, 4); + FAST_FLAG_SET(gx->perfSel, 7, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_VC_ALL_STALLS: - FAST_FLAG_SET(__GXData->perfSel, 9, 4, 4); + FAST_FLAG_SET(gx->perfSel, 9, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_VERTICES: - FAST_FLAG_SET(__GXData->perfSel, 8, 4, 4); + FAST_FLAG_SET(gx->perfSel, 8, 4, 4); GXFIFO.u8 = 8; GXFIFO.u8 = 32; - GXFIFO.u32 = __GXData->perfSel; + GXFIFO.u32 = gx->perfSel; break; case GX_PERF1_FIFO_REQ: @@ -331,7 +331,7 @@ void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { break; } - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXClearGPMetric(void) { @@ -340,9 +340,9 @@ void GXClearGPMetric(void) { #pragma scheduling off void GXReadXfRasMetric(u32* xfWaitIn, u32* xfWaitOut, u32* rasBusy, u32* clocks) { - *rasBusy = GXReadCPReg(32, 33); - *clocks = GXReadCPReg(34, 35); - *xfWaitIn = GXReadCPReg(36, 37); - *xfWaitOut = GXReadCPReg(38, 39); + // *rasBusy = GXReadCPReg(32, 33); + // *clocks = GXReadCPReg(34, 35); + // *xfWaitIn = GXReadCPReg(36, 37); + // *xfWaitOut = GXReadCPReg(38, 39); } #pragma scheduling reset diff --git a/src/dolphin/gx/GXPixel.c b/src/dolphin/gx/GXPixel.c index f3448bc3..d692ba33 100644 --- a/src/dolphin/gx/GXPixel.c +++ b/src/dolphin/gx/GXPixel.c @@ -47,7 +47,7 @@ void GXSetFog(GXFogType type, f32 startz, f32 endz, f32 nearz, f32 farz, GXColor expB--; } - a = tmpA / (1 << expB + 1); + a = tmpA / (1 << (expB + 1)); magB = 8388638.0f * tmpB; shiftB = expB + 1; c = tmpC; @@ -84,7 +84,7 @@ void GXSetFog(GXFogType type, f32 startz, f32 endz, f32 nearz, f32 farz, GXColor GX_BP_LOAD_REG(fogParamReg3); GX_BP_LOAD_REG(fogColorReg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetFogRangeAdj(GXBool enable, u16 center, GXFogAdjTable* table) { @@ -110,12 +110,12 @@ void GXSetFogRangeAdj(GXBool enable, u16 center, GXFogAdjTable* table) { GX_SET_REG(fogRangeReg, GX_BP_REG_FOGRANGE, 0, 7); GX_BP_LOAD_REG(fogRangeReg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetBlendMode(GXBlendMode type, GXBlendFactor src_factor, GXBlendFactor dst_factor, GXLogicOp op) { - u32 blendModeReg = __GXData->cmode0; + u32 blendModeReg = gx->cmode0; GX_SET_REG(blendModeReg, type == GX_BM_SUBTRACT, GX_BP_BLENDMODE_SUBTRACT_ST, GX_BP_BLENDMODE_SUBTRACT_END); GX_SET_REG(blendModeReg, type, GX_BP_BLENDMODE_ENABLE_ST, GX_BP_BLENDMODE_ENABLE_END); @@ -128,44 +128,44 @@ void GXSetBlendMode(GXBlendMode type, GXBlendFactor src_factor, GXBlendFactor ds GX_BP_BLENDMODE_DSTFACTOR_END); GX_BP_LOAD_REG(blendModeReg); - __GXData->cmode0 = blendModeReg; + gx->cmode0 = blendModeReg; - __GXData->bpSentNot = FALSE; + gx->bpSentNot = FALSE; } void GXSetColorUpdate(GXBool updateEnable) { - u32 blendModeReg = __GXData->cmode0; + u32 blendModeReg = gx->cmode0; GX_SET_REG(blendModeReg, updateEnable, GX_BP_BLENDMODE_COLOR_UPDATE_ST, GX_BP_BLENDMODE_COLOR_UPDATE_END); GX_BP_LOAD_REG(blendModeReg); - __GXData->cmode0 = blendModeReg; - __GXData->bpSentNot = GX_FALSE; + gx->cmode0 = blendModeReg; + gx->bpSentNot = GX_FALSE; } void GXSetAlphaUpdate(GXBool updateEnable) { - u32 blendModeReg = __GXData->cmode0; + u32 blendModeReg = gx->cmode0; GX_SET_REG(blendModeReg, updateEnable, GX_BP_BLENDMODE_ALPHA_UPDATE_ST, GX_BP_BLENDMODE_ALPHA_UPDATE_END); GX_BP_LOAD_REG(blendModeReg); - __GXData->cmode0 = blendModeReg; - __GXData->bpSentNot = GX_FALSE; + gx->cmode0 = blendModeReg; + gx->bpSentNot = GX_FALSE; } void GXSetZMode(GXBool compareEnable, GXCompare func, GXBool updateEnable) { - u32 zModeReg = __GXData->zmode; + u32 zModeReg = gx->zmode; GX_SET_REG(zModeReg, compareEnable, GX_BP_ZMODE_TEST_ENABLE_ST, GX_BP_ZMODE_TEST_ENABLE_END); GX_SET_REG(zModeReg, func, GX_BP_ZMODE_COMPARE_ST, GX_BP_ZMODE_COMPARE_END); GX_SET_REG(zModeReg, updateEnable, GX_BP_ZMODE_UPDATE_ENABLE_ST, GX_BP_ZMODE_UPDATE_ENABLE_END); GX_BP_LOAD_REG(zModeReg); - __GXData->zmode = zModeReg; - __GXData->bpSentNot = GX_FALSE; + gx->zmode = zModeReg; + gx->bpSentNot = GX_FALSE; } void GXSetZCompLoc(GXBool beforeTex) { - GX_SET_REG(__GXData->peCtrl, beforeTex, GX_BP_ZCONTROL_BEFORE_TEX_ST, + GX_SET_REG(gx->peCtrl, beforeTex, GX_BP_ZCONTROL_BEFORE_TEX_ST, GX_BP_ZCONTROL_BEFORE_TEX_END); - GX_BP_LOAD_REG(__GXData->peCtrl); - __GXData->bpSentNot = GX_FALSE; + GX_BP_LOAD_REG(gx->peCtrl); + gx->bpSentNot = GX_FALSE; } void GXSetPixelFmt(GXPixelFmt pixelFmt, GXZFmt16 zFmt) { @@ -173,45 +173,45 @@ void GXSetPixelFmt(GXPixelFmt pixelFmt, GXZFmt16 zFmt) { static u32 p2f[GX_PF_MAX] = {GX_PF_RGB8_Z24, GX_PF_RGBA6_Z24, GX_PF_RGB565_Z16, GX_PF_Z24, GX_PF_Y8, GX_PF_Y8, GX_PF_Y8, GX_PF_U8}; - const u32 zControlRegOld = __GXData->peCtrl; + const u32 zControlRegOld = gx->peCtrl; - GX_SET_REG(__GXData->peCtrl, p2f[pixelFmt], GX_BP_ZCONTROL_PIXEL_FMT_ST, + GX_SET_REG(gx->peCtrl, p2f[pixelFmt], GX_BP_ZCONTROL_PIXEL_FMT_ST, GX_BP_ZCONTROL_PIXEL_FMT_END); - GX_SET_REG(__GXData->peCtrl, zFmt, GX_BP_ZCONTROL_Z_FMT_ST, GX_BP_ZCONTROL_Z_FMT_END); + GX_SET_REG(gx->peCtrl, zFmt, GX_BP_ZCONTROL_Z_FMT_ST, GX_BP_ZCONTROL_Z_FMT_END); - if (zControlRegOld != __GXData->peCtrl) { - GX_BP_LOAD_REG(__GXData->peCtrl); + if (zControlRegOld != gx->peCtrl) { + GX_BP_LOAD_REG(gx->peCtrl); isZ16 = (pixelFmt == GX_PF_RGB565_Z16) ? GX_TRUE : GX_FALSE; - GX_SET_REG(__GXData->genMode, isZ16, GX_BP_GENMODE_MULTISAMPLE_ST, + GX_SET_REG(gx->genMode, isZ16, GX_BP_GENMODE_MULTISAMPLE_ST, GX_BP_GENMODE_MULTISAMPLE_END); - __GXData->dirtyState |= GX_DIRTY_GEN_MODE; + gx->dirtyState |= GX_DIRTY_GEN_MODE; } if (p2f[pixelFmt] == GX_PF_Y8) { - GX_SET_REG(__GXData->cmode1, pixelFmt - GX_PF_Y8, GX_BP_DSTALPHA_YUV_FMT_ST, + GX_SET_REG(gx->cmode1, pixelFmt - GX_PF_Y8, GX_BP_DSTALPHA_YUV_FMT_ST, GX_BP_DSTALPHA_YUV_FMT_END); - GX_SET_REG(__GXData->cmode1, GX_BP_REG_DSTALPHA, 0, 7); - GX_BP_LOAD_REG(__GXData->cmode1); + GX_SET_REG(gx->cmode1, GX_BP_REG_DSTALPHA, 0, 7); + GX_BP_LOAD_REG(gx->cmode1); } - __GXData->bpSentNot = FALSE; + gx->bpSentNot = FALSE; } void GXSetDither(GXBool dither) { - u32 blendModeReg = __GXData->cmode0; + u32 blendModeReg = gx->cmode0; GX_SET_REG(blendModeReg, dither, GX_BP_BLENDMODE_DITHER_ST, GX_BP_BLENDMODE_DITHER_END); GX_BP_LOAD_REG(blendModeReg); - __GXData->cmode0 = blendModeReg; - __GXData->bpSentNot = GX_FALSE; + gx->cmode0 = blendModeReg; + gx->bpSentNot = GX_FALSE; } void GXSetDstAlpha(GXBool enable, u8 alpha) { - u32 dstAlpha = __GXData->cmode1; + u32 dstAlpha = gx->cmode1; GX_SET_REG(dstAlpha, alpha, GX_BP_DSTALPHA_ALPHA_ST, GX_BP_DSTALPHA_ALPHA_END); GX_SET_REG(dstAlpha, enable, GX_BP_DSTALPHA_ENABLE_ST, GX_BP_DSTALPHA_ENABLE_END); GX_BP_LOAD_REG(dstAlpha); - __GXData->cmode1 = dstAlpha; - __GXData->bpSentNot = GX_FALSE; + gx->cmode1 = dstAlpha; + gx->bpSentNot = GX_FALSE; } void GXSetFieldMask(GXBool enableEven, GXBool enableOdd) { @@ -221,13 +221,13 @@ void GXSetFieldMask(GXBool enableEven, GXBool enableOdd) { GX_SET_REG(fieldMaskReg, GX_BP_REG_FIELDMASK, 0, 7); GX_BP_LOAD_REG(fieldMaskReg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetFieldMode(GXBool texLOD, GXBool adjustAR) { - GX_SET_REG(__GXData->lpSize, adjustAR, GX_BP_LINEPTWIDTH_ADJUST_ST, + GX_SET_REG(gx->lpSize, adjustAR, GX_BP_LINEPTWIDTH_ADJUST_ST, GX_BP_LINEPTWIDTH_ADJUST_END); - GX_BP_LOAD_REG(__GXData->lpSize); + GX_BP_LOAD_REG(gx->lpSize); __GXFlushTextureState(); GX_BP_LOAD_REG(GX_BP_REG_FIELDMODE << 24 | texLOD); diff --git a/src/dolphin/gx/GXTev.c b/src/dolphin/gx/GXTev.c index 3cecde99..b3c2946a 100644 --- a/src/dolphin/gx/GXTev.c +++ b/src/dolphin/gx/GXTev.c @@ -47,28 +47,28 @@ void GXSetTevOp(GXTevStageID stage, GXTevMode mode) { alpha = &TEVAOpTableST1[mode]; } - tevReg = __GXData->tevc[stage]; + tevReg = gx->tevc[stage]; tevReg = (*color & ~0xFF000000) | (tevReg & 0xFF000000); GFWriteBPCmd(tevReg); - __GXData->tevc[stage] = tevReg; + gx->tevc[stage] = tevReg; - tevReg = __GXData->teva[stage]; + tevReg = gx->teva[stage]; tevReg = (*alpha & ~0xFF00000F) | (tevReg & 0xFF00000F); GFWriteBPCmd(tevReg); - __GXData->teva[stage] = tevReg; + gx->teva[stage] = tevReg; - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevColorIn(GXTevStageID stage, GXTevColorArg a, GXTevColorArg b, GXTevColorArg c, GXTevColorArg d) { u32 tevReg; - tevReg = __GXData->tevc[stage]; + tevReg = gx->tevc[stage]; FAST_FLAG_SET(tevReg, a, 12, 4); FAST_FLAG_SET(tevReg, b, 8, 4); @@ -77,15 +77,15 @@ void GXSetTevColorIn(GXTevStageID stage, GXTevColorArg a, GXTevColorArg b, GXTev GFWriteBPCmd(tevReg); - __GXData->tevc[stage] = tevReg; - __GXData->bpSentNot = GX_FALSE; + gx->tevc[stage] = tevReg; + gx->bpSentNot = GX_FALSE; } void GXSetTevAlphaIn(GXTevStageID stage, GXTevAlphaArg a, GXTevAlphaArg b, GXTevAlphaArg c, GXTevAlphaArg d) { u32 tevReg; - tevReg = __GXData->teva[stage]; + tevReg = gx->teva[stage]; FAST_FLAG_SET(tevReg, a, 13, 3); FAST_FLAG_SET(tevReg, b, 10, 3); @@ -94,15 +94,15 @@ void GXSetTevAlphaIn(GXTevStageID stage, GXTevAlphaArg a, GXTevAlphaArg b, GXTev GFWriteBPCmd(tevReg); - __GXData->teva[stage] = tevReg; - __GXData->bpSentNot = GX_FALSE; + gx->teva[stage] = tevReg; + gx->bpSentNot = GX_FALSE; } void GXSetTevColorOp(GXTevStageID stage, GXTevOp op, GXTevBias bias, GXTevScale scale, GXBool doClamp, GXTevRegID outReg) { u32 tevReg; - tevReg = __GXData->tevc[stage]; + tevReg = gx->tevc[stage]; FAST_FLAG_SET(tevReg, op & 1, 18, 1); if (op <= GX_TEV_SUB) { @@ -117,15 +117,15 @@ void GXSetTevColorOp(GXTevStageID stage, GXTevOp op, GXTevBias bias, GXTevScale FAST_FLAG_SET(tevReg, outReg, 22, 2); GFWriteBPCmd(tevReg); - __GXData->tevc[stage] = tevReg; - __GXData->bpSentNot = GX_FALSE; + gx->tevc[stage] = tevReg; + gx->bpSentNot = GX_FALSE; } void GXSetTevAlphaOp(GXTevStageID stage, GXTevOp op, GXTevBias bias, GXTevScale scale, GXBool doClamp, GXTevRegID outReg) { u32 tevReg; - tevReg = __GXData->teva[stage]; + tevReg = gx->teva[stage]; FAST_FLAG_SET(tevReg, op & 1, 18, 1); if (op <= GX_TEV_SUB) { @@ -140,8 +140,8 @@ void GXSetTevAlphaOp(GXTevStageID stage, GXTevOp op, GXTevBias bias, GXTevScale FAST_FLAG_SET(tevReg, outReg, 22, 2); GFWriteBPCmd(tevReg); - __GXData->teva[stage] = tevReg; - __GXData->bpSentNot = GX_FALSE; + gx->teva[stage] = tevReg; + gx->bpSentNot = GX_FALSE; } void GXSetTevColor(GXTevRegID reg, GXColor color) { @@ -159,7 +159,7 @@ void GXSetTevColor(GXTevRegID reg, GXColor color) { GX_BP_LOAD_REG(bg); GX_BP_LOAD_REG(bg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevColorS10(GXTevRegID reg, GXColorS10 color) { @@ -178,7 +178,7 @@ void GXSetTevColorS10(GXTevRegID reg, GXColorS10 color) { GX_BP_LOAD_REG(bg); GX_BP_LOAD_REG(bg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevKColor(GXTevKColorID id, GXColor color) { @@ -199,13 +199,13 @@ void GXSetTevKColor(GXTevKColorID id, GXColor color) { GX_BP_LOAD_REG(ra); GX_BP_LOAD_REG(bg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevKColorSel(GXTevStageID stage, GXTevKColorSel sel) { u32* reg; - reg = &__GXData->tevKsel[stage >> 1]; + reg = &gx->tevKsel[stage >> 1]; if (stage & 1) { GX_SET_REG(*reg, sel, 13, 17); @@ -215,13 +215,13 @@ void GXSetTevKColorSel(GXTevStageID stage, GXTevKColorSel sel) { GX_BP_LOAD_REG(*reg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevKAlphaSel(GXTevStageID stage, GXTevKAlphaSel sel) { u32* reg; - reg = &__GXData->tevKsel[stage >> 1]; + reg = &gx->tevKsel[stage >> 1]; if (stage & 1) { GX_SET_REG(*reg, sel, 8, 12); @@ -231,36 +231,36 @@ void GXSetTevKAlphaSel(GXTevStageID stage, GXTevKAlphaSel sel) { GX_BP_LOAD_REG(*reg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevSwapMode(GXTevStageID stage, GXTevSwapSel rasSel, GXTevSwapSel texSel) { - u32* reg = &__GXData->teva[stage]; + u32* reg = &gx->teva[stage]; GX_SET_REG(*reg, rasSel, 30, 31); GX_SET_REG(*reg, texSel, 28, 29); GX_BP_LOAD_REG(*reg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevSwapModeTable(GXTevSwapSel table, GXTevColorChan red, GXTevColorChan green, GXTevColorChan blue, GXTevColorChan alpha) { u32* reg; - reg = &__GXData->tevKsel[table << 1]; + reg = &gx->tevKsel[table << 1]; GX_SET_REG(*reg, red, 30, 31); GX_SET_REG(*reg, green, 28, 29); GX_BP_LOAD_REG(*reg); - reg = &__GXData->tevKsel[(table << 1) + 1]; + reg = &gx->tevKsel[(table << 1) + 1]; GX_SET_REG(*reg, blue, 30, 31); GX_SET_REG(*reg, alpha, 28, 29); GX_BP_LOAD_REG(*reg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetAlphaCompare(GXCompare comp0, u8 ref0, GXAlphaOp op, GXCompare comp1, u8 ref1) { @@ -274,7 +274,7 @@ void GXSetAlphaCompare(GXCompare comp0, u8 ref0, GXAlphaOp op, GXCompare comp1, GX_BP_LOAD_REG(reg); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetZTexture(GXZTexOp op, GXTexFmt format, u32 bias) { @@ -310,7 +310,7 @@ void GXSetZTexture(GXZTexOp op, GXTexFmt format, u32 bias) { GX_BP_LOAD_REG(val2); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetTevOrder(GXTevStageID stage, GXTexCoordID coord, GXTexMapID map, GXChannelID color) { @@ -320,18 +320,18 @@ void GXSetTevOrder(GXTevStageID stage, GXTexCoordID coord, GXTexMapID map, GXCha u32 tempMap; u32 tempCoord; - reg = &__GXData->tref[stage / 2]; - __GXData->texmapId[stage] = map; + reg = &gx->tref[stage / 2]; + gx->texmapId[stage] = map; tempMap = map & ~0x100; tempMap = (tempMap >= GX_MAX_TEXMAP) ? GX_TEXMAP0 : tempMap; if (coord >= GX_MAXCOORD) { tempCoord = GX_TEXCOORD0; - __GXData->tevTcEnab = __GXData->tevTcEnab & ~(1 << stage); + gx->tevTcEnab = gx->tevTcEnab & ~(1 << stage); } else { tempCoord = coord; - __GXData->tevTcEnab = __GXData->tevTcEnab | (1 << stage); + gx->tevTcEnab = gx->tevTcEnab | (1 << stage); } if (stage & 1) { @@ -349,12 +349,12 @@ void GXSetTevOrder(GXTevStageID stage, GXTexCoordID coord, GXTexMapID map, GXCha GX_BP_LOAD_REG(*reg); - __GXData->bpSentNot = GX_FALSE; - __GXData->dirtyState |= 1; + gx->bpSentNot = GX_FALSE; + gx->dirtyState |= 1; } void GXSetNumTevStages(u8 count) { - GX_SET_REG(__GXData->genMode, count - 1, 18, 21); + GX_SET_REG(gx->genMode, count - 1, 18, 21); - __GXData->dirtyState |= 0x4; + gx->dirtyState |= 0x4; } diff --git a/src/dolphin/gx/GXTexture.c b/src/dolphin/gx/GXTexture.c index c1b11189..beb0dbfa 100644 --- a/src/dolphin/gx/GXTexture.c +++ b/src/dolphin/gx/GXTexture.c @@ -1,5 +1,6 @@ #include "dolphin/gx/GXTexture.h" #include "dolphin/gx/GX.h" +#include "string.h" #define GET_TILE_COUNT(a, b) (((a) + (1 << (b)) - 1) >> (b)) @@ -297,21 +298,21 @@ void GXLoadTexObjPreLoaded(GXTexObj* obj, GXTexRegion* region, GXTexMapID map) { GX_BP_LOAD_REG(internalObj->texture_address); if ((internalObj->texture_flags & 2) == 0) { - GXTlutObj* tlut = (GXTlutObj*)__GXData->tlutRegionCallback(internalObj->tlut_name); + GXTlutObj* tlut = (GXTlutObj*)gx->tlutRegionCallback(internalObj->tlut_name); GX_SET_REG(tlut->address, GXTexTlutIds[map], 0, 7); GX_BP_LOAD_REG(tlut->address); } - __GXData->tImage0[map] = internalObj->texture_size; - __GXData->tMode0[map] = internalObj->texture_filter; + gx->tImage0[map] = internalObj->texture_size; + gx->tMode0[map] = internalObj->texture_filter; - __GXData->dirtyState |= GX_DIRTY_SU_TEX; - __GXData->bpSentNot = GX_FALSE; + gx->dirtyState |= GX_DIRTY_SU_TEX; + gx->bpSentNot = GX_FALSE; } void GXLoadTexObj(GXTexObj* obj, GXTexMapID map) { - GXTexRegion* ret = (GXTexRegion*)__GXData->texRegionCallback(obj, map); + GXTexRegion* ret = (GXTexRegion*)gx->texRegionCallback(obj, map); GXLoadTexObjPreLoaded(obj, ret, map); } @@ -330,7 +331,7 @@ void GXInitTlutObj(GXTlutObj* obj, void* table, GXTlutFmt format, u16 numEntries void GXLoadTlut(GXTlutObj* obj, u32 tlut_name) { GXTlutObj* internal = (GXTlutObj*)obj; - GXTlutRegion* ret = (GXTlutRegion*)__GXData->tlutRegionCallback(tlut_name); + GXTlutRegion* ret = (GXTlutRegion*)gx->tlutRegionCallback(tlut_name); u32 reg; __GXFlushTextureState(); @@ -413,14 +414,14 @@ void GXInvalidateTexAll(void) { } GXTexRegionCallback GXSetTexRegionCallback(GXTexRegionCallback callback) { - GXTexRegionCallback prev = __GXData->texRegionCallback; - __GXData->texRegionCallback = callback; + GXTexRegionCallback prev = gx->texRegionCallback; + gx->texRegionCallback = callback; return prev; } GXTlutRegionCallback GXSetTlutRegionCallback(GXTlutRegionCallback callback) { - GXTlutRegionCallback prev = __GXData->tlutRegionCallback; - __GXData->tlutRegionCallback = callback; + GXTlutRegionCallback prev = gx->tlutRegionCallback; + gx->tlutRegionCallback = callback; return prev; } @@ -432,22 +433,22 @@ void __SetSURegs(u32 texImgIndex, u32 setUpRegIndex) { u16 a1, a2; GXBool b, c; - a1 = GX_GET_REG(__GXData->tImage0[texImgIndex], 22, 31); - a2 = (__GXData->tImage0[texImgIndex] & (0x3ff << 10)) >> 10; + a1 = GX_GET_REG(gx->tImage0[texImgIndex], 22, 31); + a2 = (gx->tImage0[texImgIndex] & (0x3ff << 10)) >> 10; - GX_SET_REG(__GXData->suTs0[setUpRegIndex], a1, 16, 31); - GX_SET_REG(__GXData->suTs1[setUpRegIndex], a2, 16, 31); + GX_SET_REG(gx->suTs0[setUpRegIndex], a1, 16, 31); + GX_SET_REG(gx->suTs1[setUpRegIndex], a2, 16, 31); - b = GX_GET_REG(__GXData->tMode0[texImgIndex], 30, 31) == 1; - c = GX_GET_REG(__GXData->tMode0[texImgIndex], 28, 29) == 1; + b = GX_GET_REG(gx->tMode0[texImgIndex], 30, 31) == 1; + c = GX_GET_REG(gx->tMode0[texImgIndex], 28, 29) == 1; - GX_SET_REG(__GXData->suTs0[setUpRegIndex], b, 15, 15); - GX_SET_REG(__GXData->suTs1[setUpRegIndex], c, 15, 15); + GX_SET_REG(gx->suTs0[setUpRegIndex], b, 15, 15); + GX_SET_REG(gx->suTs1[setUpRegIndex], c, 15, 15); - GX_BP_LOAD_REG(__GXData->suTs0[setUpRegIndex]); - GX_BP_LOAD_REG(__GXData->suTs1[setUpRegIndex]); + GX_BP_LOAD_REG(gx->suTs0[setUpRegIndex]); + GX_BP_LOAD_REG(gx->suTs1[setUpRegIndex]); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } #pragma dont_inline on @@ -458,38 +459,38 @@ void __GXSetSUTexRegs(void) { u32 c; u32 d; u32 stackFiller; - if (__GXData->tcsManEnab != 0xff) { - a = GX_GET_REG(__GXData->genMode, 18, 21) + 1; - b = GX_GET_REG(__GXData->genMode, 13, 15); + if (gx->tcsManEnab != 0xff) { + a = GX_GET_REG(gx->genMode, 18, 21) + 1; + b = GX_GET_REG(gx->genMode, 13, 15); for (i = 0; i < b; i++) { switch (i) { case 0: - c = GX_GET_REG(__GXData->iref, 29, 31); - d = GX_GET_REG(__GXData->iref, 26, 28); + c = GX_GET_REG(gx->iref, 29, 31); + d = GX_GET_REG(gx->iref, 26, 28); break; case 1: - c = GX_GET_REG(__GXData->iref, 23, 25); - d = GX_GET_REG(__GXData->iref, 20, 22); + c = GX_GET_REG(gx->iref, 23, 25); + d = GX_GET_REG(gx->iref, 20, 22); break; case 2: - c = GX_GET_REG(__GXData->iref, 17, 19); - d = GX_GET_REG(__GXData->iref, 14, 16); + c = GX_GET_REG(gx->iref, 17, 19); + d = GX_GET_REG(gx->iref, 14, 16); break; case 3: - c = GX_GET_REG(__GXData->iref, 11, 13); - d = GX_GET_REG(__GXData->iref, 8, 10); + c = GX_GET_REG(gx->iref, 11, 13); + d = GX_GET_REG(gx->iref, 8, 10); break; } - if (!(__GXData->tcsManEnab & (1 << d))) { + if (!(gx->tcsManEnab & (1 << d))) { __SetSURegs(c, d); } } for (i = 0; i < a; i++) { - u32* g = &__GXData->tref[i / 2]; + u32* g = &gx->tref[i / 2]; - c = __GXData->texmapId[i] & ~0x100; + c = gx->texmapId[i] & ~0x100; if (i & 1) { d = GX_GET_REG(*g, 14, 16); @@ -497,7 +498,7 @@ void __GXSetSUTexRegs(void) { d = GX_GET_REG(*g, 26, 28); } - if (c != 0xff && !(__GXData->tcsManEnab & (1 << d)) && __GXData->tevTcEnab & (1 << i)) { + if (c != 0xff && !(gx->tcsManEnab & (1 << d)) && gx->tevTcEnab & (1 << i)) { __SetSURegs(c, d); } } diff --git a/src/dolphin/gx/GXTransform.c b/src/dolphin/gx/GXTransform.c index a8ca4c71..dba3024d 100644 --- a/src/dolphin/gx/GXTransform.c +++ b/src/dolphin/gx/GXTransform.c @@ -71,66 +71,66 @@ void GXProject(f32 model_x, f32 model_y, f32 model_z, Mtx model_mtx, f32* proj_m void GXSetProjection(const Mtx44 proj, GXProjectionType type) { volatile void* fifo; u32 reg; - __GXData->projType = type; + gx->projType = type; - __GXData->projMtx[0] = proj[0][0]; - __GXData->projMtx[2] = proj[1][1]; - __GXData->projMtx[4] = proj[2][2]; - __GXData->projMtx[5] = proj[2][3]; + gx->projMtx[0] = proj[0][0]; + gx->projMtx[2] = proj[1][1]; + gx->projMtx[4] = proj[2][2]; + gx->projMtx[5] = proj[2][3]; if (type == GX_ORTHOGRAPHIC) { - __GXData->projMtx[1] = proj[0][3]; - __GXData->projMtx[3] = proj[1][3]; + gx->projMtx[1] = proj[0][3]; + gx->projMtx[3] = proj[1][3]; } else { - __GXData->projMtx[1] = proj[0][2]; - __GXData->projMtx[3] = proj[1][2]; + gx->projMtx[1] = proj[0][2]; + gx->projMtx[3] = proj[1][2]; } 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; + GX_WRITE_XF_REG_F(32, gx->projMtx[0]); + GX_WRITE_XF_REG_F(33, gx->projMtx[1]); + GX_WRITE_XF_REG_F(34, gx->projMtx[2]); + GX_WRITE_XF_REG_F(35, gx->projMtx[3]); + GX_WRITE_XF_REG_F(36, gx->projMtx[4]); + GX_WRITE_XF_REG_F(37, gx->projMtx[5]); + GX_WRITE_XF_REG_2(38, gx->projType); + + gx->bpSentNot = GX_TRUE; } void GXSetProjectionv(f32* proj) { - __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->projType = proj[0]; + gx->projMtx[0] = proj[1]; + gx->projMtx[1] = proj[2]; + gx->projMtx[2] = proj[3]; + gx->projMtx[3] = proj[4]; + gx->projMtx[4] = proj[5]; + gx->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; + GX_WRITE_XF_REG_F(32, gx->projMtx[0]); + GX_WRITE_XF_REG_F(33, gx->projMtx[1]); + GX_WRITE_XF_REG_F(34, gx->projMtx[2]); + GX_WRITE_XF_REG_F(35, gx->projMtx[3]); + GX_WRITE_XF_REG_F(36, gx->projMtx[4]); + GX_WRITE_XF_REG_F(37, gx->projMtx[5]); + GX_WRITE_XF_REG_2(38, gx->projType); + gx->bpSentNot = GX_TRUE; } void GXGetProjectionv(f32* proj) { - 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]; + proj[0] = gx->projType; + proj[1] = gx->projMtx[0]; + proj[2] = gx->projMtx[1]; + proj[3] = gx->projMtx[2]; + proj[4] = gx->projMtx[3]; + proj[5] = gx->projMtx[4]; + proj[6] = gx->projMtx[5]; } static void WriteMTXPS4x3(register volatile void* dst, register const Mtx src) { @@ -192,7 +192,7 @@ void GXLoadNrmMtxImm(Mtx mtx, u32 id) { } void GXSetCurrentMtx(u32 id) { - GX_SET_REG(__GXData->matIdxA, id, GX_XF_MTXIDX0_GEOM_ST, GX_XF_MTXIDX0_GEOM_END); + GX_SET_REG(gx->matIdxA, id, GX_XF_MTXIDX0_GEOM_ST, GX_XF_MTXIDX0_GEOM_END); __GXSetMatrixIndex(GX_VA_PNMTXIDX); } @@ -243,16 +243,16 @@ void __GXSetViewport(void) { f32 a, b, c, d, e, f; f32 near, far; - a = __GXData->vpWd / 2; - b = -__GXData->vpHt / 2; - d = __GXData->vpLeft + (__GXData->vpWd / 2) + 342.0f; - e = __GXData->vpTop + (__GXData->vpHt / 2) + 342.0f; + a = gx->vpWd / 2; + b = -gx->vpHt / 2; + d = gx->vpLeft + (gx->vpWd / 2) + 342.0f; + e = gx->vpTop + (gx->vpHt / 2) + 342.0f; - near = __GXData->vpNearz * __GXData->zScale; - far = __GXData->vpFarz * __GXData->zScale; + near = gx->vpNearz * gx->zScale; + far = gx->vpFarz * gx->zScale; c = far - near; - f = far + __GXData->zOffset; + f = far + gx->zOffset; GX_XF_LOAD_REGS(5, GX_XF_REG_SCALEX); GXFIFO.f32 = a; @@ -264,18 +264,18 @@ void __GXSetViewport(void) { } void GXSetViewport(f32 left, f32 top, f32 width, f32 height, f32 nearZ, f32 farZ) { - __GXData->vpLeft = left; - __GXData->vpTop = top; - __GXData->vpWd = width; - __GXData->vpHt = height; - __GXData->vpNearz = nearZ; - __GXData->vpFarz = farZ; + gx->vpLeft = left; + gx->vpTop = top; + gx->vpWd = width; + gx->vpHt = height; + gx->vpNearz = nearZ; + gx->vpFarz = farZ; __GXSetViewport(); - __GXData->bpSentNot = GX_TRUE; + gx->bpSentNot = GX_TRUE; } void GXGetViewportv(f32* p) { - Copy6Floats(&__GXData->vpLeft, p); + Copy6Floats(&gx->vpLeft, p); } void GXSetScissor(u32 left, u32 top, u32 width, u32 height) { @@ -285,25 +285,25 @@ void GXSetScissor(u32 left, u32 top, u32 width, u32 height) { y1 = top + 342; x1 = left + 342; - GX_SET_REG(__GXData->suScis0, y1, GX_BP_SCISSORTL_TOP_ST, GX_BP_SCISSORTL_TOP_END); - GX_SET_REG(__GXData->suScis0, x1, GX_BP_SCISSORTL_LEFT_ST, GX_BP_SCISSORTL_LEFT_END); + GX_SET_REG(gx->suScis0, y1, GX_BP_SCISSORTL_TOP_ST, GX_BP_SCISSORTL_TOP_END); + GX_SET_REG(gx->suScis0, x1, GX_BP_SCISSORTL_LEFT_ST, GX_BP_SCISSORTL_LEFT_END); y2 = y1 + height - 1; x2 = (x1 + width) - 1; - GX_SET_REG(__GXData->suScis1, y2, GX_BP_SCISSORBR_BOT_ST, GX_BP_SCISSORBR_BOT_END); - GX_SET_REG(__GXData->suScis1, x2, GX_BP_SCISSORBR_RIGHT_ST, GX_BP_SCISSORBR_RIGHT_END); + GX_SET_REG(gx->suScis1, y2, GX_BP_SCISSORBR_BOT_ST, GX_BP_SCISSORBR_BOT_END); + GX_SET_REG(gx->suScis1, x2, GX_BP_SCISSORBR_RIGHT_ST, GX_BP_SCISSORBR_RIGHT_END); - GX_BP_LOAD_REG(__GXData->suScis0); - GX_BP_LOAD_REG(__GXData->suScis1); - __GXData->bpSentNot = FALSE; + GX_BP_LOAD_REG(gx->suScis0); + GX_BP_LOAD_REG(gx->suScis1); + gx->bpSentNot = FALSE; } void GXGetScissor(u32* left, u32* top, u32* width, u32* height) { - u32 y1 = (__GXData->suScis0 & 0x0007FF) >> 0; - u32 x1 = (__GXData->suScis0 & 0x7FF000) >> 12; - u32 y2 = (__GXData->suScis1 & 0x0007FF) >> 0; - u32 x2 = (__GXData->suScis1 & 0x7FF000) >> 12; + u32 y1 = (gx->suScis0 & 0x0007FF) >> 0; + u32 x1 = (gx->suScis0 & 0x7FF000) >> 12; + u32 y2 = (gx->suScis1 & 0x0007FF) >> 0; + u32 x2 = (gx->suScis1 & 0x7FF000) >> 12; *left = x1 - 0x156; *top = y1 - 0x156; @@ -324,23 +324,23 @@ void GXSetScissorBoxOffset(s32 x, s32 y) { GX_SET_REG(cmd, GX_BP_REG_SCISSOROFFSET, 0, 7); GX_BP_LOAD_REG(cmd); - __GXData->bpSentNot = GX_FALSE; + gx->bpSentNot = GX_FALSE; } void GXSetClipMode(GXClipMode mode) { GX_XF_LOAD_REG(GX_XF_REG_CLIPDISABLE, mode); - __GXData->bpSentNot = GX_TRUE; + gx->bpSentNot = GX_TRUE; } void __GXSetMatrixIndex(GXAttr index) { // Tex4 and after is stored in XF MatrixIndex1 if (index < GX_VA_TEX4MTXIDX) { - GX_CP_LOAD_REG(GX_CP_REG_MTXIDXA, __GXData->matIdxA); - GX_XF_LOAD_REG(GX_XF_REG_MATRIXINDEX0, __GXData->matIdxA); + GX_CP_LOAD_REG(GX_CP_REG_MTXIDXA, gx->matIdxA); + GX_XF_LOAD_REG(GX_XF_REG_MATRIXINDEX0, gx->matIdxA); } else { - GX_CP_LOAD_REG(GX_CP_REG_MTXIDXB, __GXData->matIdxB); - GX_XF_LOAD_REG(GX_XF_REG_MATRIXINDEX1, __GXData->matIdxB); + GX_CP_LOAD_REG(GX_CP_REG_MTXIDXB, gx->matIdxB); + GX_XF_LOAD_REG(GX_XF_REG_MATRIXINDEX1, gx->matIdxB); } - __GXData->bpSentNot = GX_TRUE; + gx->bpSentNot = GX_TRUE; }