diff --git a/.vscode/settings.json b/.vscode/settings.json index 92ac7dc63..75bf50fa0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -28,6 +28,8 @@ "thpplayer.h": "c", "thpvideodecode.h": "c", "thpaudio.h": "c", - "ai.h": "c" + "ai.h": "c", + "gx.h": "c", + "gxenum.h": "c" } } \ No newline at end of file diff --git a/include/Dolphin/hw_regs.h b/include/Dolphin/hw_regs.h index a4966852d..6944edbd8 100644 --- a/include/Dolphin/hw_regs.h +++ b/include/Dolphin/hw_regs.h @@ -8,6 +8,8 @@ extern "C" { #endif // ifdef __cplusplus +#define HW_REG(reg, type) *(volatile type*)(u32)(reg) // generic HW_REG macro (please do not use this) + /////// HARDWARE REGISTERS /////// // Video Interface registers. vu16 __VIRegs[59] AT_ADDRESS(0xCC002000); diff --git a/include/Dolphin/os.h b/include/Dolphin/os.h index f3dc98881..fc78dcc89 100644 --- a/include/Dolphin/os.h +++ b/include/Dolphin/os.h @@ -126,8 +126,6 @@ void __OSSystemCallVectorEnd(); void OSFillFPUContext(OSContext*); extern u32 __OSFpscrEnableBits; /** TODO: find a wrapper for this. Symbol is defined in OSError.c. */ -#define HW_REG(reg, type) *(volatile type*)(u32)(reg) - u8 GameChoice AT_ADDRESS(OS_BASE_CACHED | 0x30E3); volatile int __OSTVMode AT_ADDRESS(OS_BASE_CACHED | 0xCC); diff --git a/src/JSystem/J3D/J3DShape.cpp b/src/JSystem/J3D/J3DShape.cpp index d7797745c..3dd9e3f48 100644 --- a/src/JSystem/J3D/J3DShape.cpp +++ b/src/JSystem/J3D/J3DShape.cpp @@ -49,24 +49,24 @@ */ void J3DShape::initialize() { - _04 = nullptr; - mId = 0xFFFF; - _0A = 0; - mFlags = 0; - _10 = 0.0f; - _14.set(0.0f, 0.0f, 0.0f); - _20.set(0.0f, 0.0f, 0.0f); - _30 = nullptr; - _38 = nullptr; - _3C = nullptr; - mVtxData = nullptr; - mDrawMtxData = nullptr; - mFlagList = nullptr; - mTree1 = nullptr; - mTree2 = nullptr; - _60 = &j3dDefaultViewNo; - mMode = 0; - _48 = 0; + mMaterial = nullptr; + mId = 0xFFFF; + mMtxGroupNum = 0; + mFlags = 0; + mRadius = 0.0f; + mMin.set(0.0f, 0.0f, 0.0f); + mMax.set(0.0f, 0.0f, 0.0f); + mVtxDesc = nullptr; + mShapeMtx = nullptr; + mShapeDraw = nullptr; + mVtxData = nullptr; + mDrawMtxData = nullptr; + mFlagList = nullptr; + mTree1 = nullptr; + mTree2 = nullptr; + mCurrentViewNumber = reinterpret_cast(&j3dDefaultViewNo); + mMode = 0; + _48 = 0; } /* @@ -74,10 +74,10 @@ void J3DShape::initialize() * Address: 800608C0 * Size: 000078 */ -void J3DShape::calcNBTScale(const Vec& p1, float (*p2)[3][3], float (*p3)[3][3]) +void J3DShape::calcNBTScale(const Vec& p1, Mtx33 p2[3], Mtx33 p3[3]) { - for (u16 i = 0; i < _0A; i++) { - _38[i]->calcNBTScale(p1, p2, p3); + for (u16 i = 0; i < mMtxGroupNum; i++) { + mShapeMtx[i]->calcNBTScale(p1, p2[0], ***p3); } } @@ -89,8 +89,8 @@ void J3DShape::calcNBTScale(const Vec& p1, float (*p2)[3][3], float (*p3)[3][3]) int J3DShape::countBumpMtxNum() const { int count = 0; - for (u16 i = 0; i < _0A; i++) { - count += _38[i]->getUseMtxNum(); + for (u16 i = 0; i < mMtxGroupNum; i++) { + count += mShapeMtx[i]->getUseMtxNum(); } return count; } @@ -102,8 +102,8 @@ int J3DShape::countBumpMtxNum() const */ bool J3DShape::isSameVcdVatCmd(J3DShape* other) { - u8* otherVatCmd = other->_2C; - u8* thisVatCmd = _2C; + u8* otherVatCmd = other->mVcdVatCmd; + u8* thisVatCmd = mVcdVatCmd; // TODO: is the 0xC0 a sizeof? for (int i = 0; i < 0xC0; i++) { if (otherVatCmd[i] != thisVatCmd[i]) { @@ -368,11 +368,11 @@ void J3DShape::makeVcdVatCmd() OSDisableScheduler(); GDCurrentDL displayList; // TODO: Is 0xC0 a sizeof something? - GDInitGDLObj(&displayList, _2C, 0xC0); + GDInitGDLObj(&displayList, mVcdVatCmd, 0xC0); __GDCurrentDL = &displayList; - GDSetVtxDescv(_30); + GDSetVtxDescv(mVtxDesc); makeVtxArrayCmd(); - J3DGDSetVtxAttrFmtv(GX_VTXFMT0, mVtxData->_14, mMode); + J3DGDSetVtxAttrFmtv(GX_VTXFMT0, mVtxData->mVtxAttrFmtList, mMode); GDPadCurr32(); GDFlushCurrToMem(); __GDCurrentDL = nullptr; @@ -431,22 +431,12 @@ void J3DShape::makeVcdVatCmd() */ void J3DShape::loadPreDrawSetting() const { - if (sOldVcdVatCmd != _2C) { + if (sOldVcdVatCmd != mVcdVatCmd) { // TODO: Is 0xC0 a sizeof? - GXCallDisplayList(_2C, 0xC0); - sOldVcdVatCmd = _2C; + GXCallDisplayList(mVcdVatCmd, 0xC0); + sOldVcdVatCmd = mVcdVatCmd; } - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0x30; - GXWGFifo.u32 = _40; - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0x40; - GXWGFifo.u32 = _44; - GXWGFifo.u8 = 0x10; - GXWGFifo.u16 = 0x0001; - GXWGFifo.u16 = 0x1018; - GXWGFifo.u32 = _40; - GXWGFifo.u32 = _44; + mCurrentMtx.load(); /* stwu r1, -0x10(r1) @@ -501,21 +491,21 @@ void J3DShape::loadPreDrawSetting() const */ void J3DShape::drawFast() const { - // if (sOldVcdVatCmd != _2C) { - // GXCallDisplayList(_2C, 0xC0); - // sOldVcdVatCmd = _2C; + // if (sOldVcdVatCmd != mVcdVatCmd) { + // GXCallDisplayList(mVcdVatCmd, 0xC0); + // sOldVcdVatCmd = mVcdVatCmd; // } // if (sEnvelopeFlag != 0 && _48 == 0) { // GXWGFifo.u8 = 0x08; // GXWGFifo.u8 = 0x30; - // GXWGFifo.u32 = _40; + // GXWGFifo.u32 = mCurrentMtx; // GXWGFifo.u8 = 0x08; // GXWGFifo.u8 = 0x40; // GXWGFifo.u32 = _44; // GXWGFifo.u8 = 0x10; // GXWGFifo.u16 = 0x0001; // GXWGFifo.u16 = 0x1018; - // GXWGFifo.u32 = _40; + // GXWGFifo.u32 = mCurrentMtx; // GXWGFifo.u32 = _44; // } // J3DShapeMtx::sCurrentPipeline = mFlags >> 2 & 7; @@ -757,22 +747,12 @@ void J3DShape::drawFast() const void J3DShape::draw() const { sOldVcdVatCmd = nullptr; - if (_2C != sOldVcdVatCmd) { + if (mVcdVatCmd != sOldVcdVatCmd) { // TODO: Is 0xC0 a sizeof? - GXCallDisplayList(_2C, 0xC0); - sOldVcdVatCmd = _2C; + GXCallDisplayList(mVcdVatCmd, 0xC0); + sOldVcdVatCmd = mVcdVatCmd; } - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0x30; - GXWGFifo.u32 = _40; - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0x40; - GXWGFifo.u32 = _44; - GXWGFifo.u8 = 0x10; - GXWGFifo.u16 = 0x0001; - GXWGFifo.u16 = 0x1018; - GXWGFifo.u32 = _40; - GXWGFifo.u32 = _44; + mCurrentMtx.load(); drawFast(); /* stwu r1, -0x10(r1) @@ -850,36 +830,22 @@ void GXWriteU8U16U16U32U32(u8 p1, u16 p2, u16 p3, u32 p4, u32 p5) void J3DShape::simpleDraw() const { sOldVcdVatCmd = nullptr; - if (sOldVcdVatCmd != _2C) { - GXCallDisplayList(_2C, 0xC0); - sOldVcdVatCmd = _2C; + if (sOldVcdVatCmd != mVcdVatCmd) { + GXCallDisplayList(mVcdVatCmd, 0xC0); + sOldVcdVatCmd = mVcdVatCmd; } - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0x30; - GXWGFifo.u32 = _40; - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0x40; - GXWGFifo.u32 = _44; - J3DShapeMtx::sCurrentPipeline = mFlags >> 2 & 7; - GXWGFifo.u8 = 0x10; - GXWGFifo.u16 = 0x0001; - GXWGFifo.u16 = 0x1018; - GXWGFifo.u32 = _40; - GXWGFifo.u32 = _44; - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0xA0; - GXWGFifo.u32 = j3dSys._10C & 0x7FFFFFFF; + mCurrentMtx.load(); if (mMode == 0) { - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0xA1; - GXWGFifo.u32 = j3dSys._110 & 0x7FFFFFFF; + GXWGFifo.u8 = 0x08; + GXWGFifo.u8 = 0xA1; + // GXWGFifo.u32 = j3dSys.mVtxNorm & 0x7FFFFFFF; } - GXWGFifo.u8 = 0x08; - GXWGFifo.u8 = 0xA2; - GXWGFifo.u32 = j3dSys._114 & 0x7FFFFFFF; - for (u32 i = 0; i < _0A; i++) { - if (_3C[i] != nullptr) { - _3C[i]->draw(); + GXWGFifo.u8 = 0x08; + GXWGFifo.u8 = 0xA2; + // GXWGFifo.u32 = j3dSys.mVtxColor & 0x7FFFFFFF; + for (u32 i = 0; i < mMtxGroupNum; i++) { + if (mShapeDraw[i] != nullptr) { + mShapeDraw[i]->draw(); } } /* @@ -991,41 +957,39 @@ void J3DShape::simpleDraw() const */ void J3DShape::simpleDrawCache() const { - if (sOldVcdVatCmd != _2C) { - GXCallDisplayList(_2C, 0xC0); - sOldVcdVatCmd = _2C; + if (sOldVcdVatCmd != mVcdVatCmd) { + GXCallDisplayList(mVcdVatCmd, 0xC0); + sOldVcdVatCmd = mVcdVatCmd; } if (sEnvelopeFlag && _48 == 0) { - GXWriteU8U8U32(0x08, 0x30, _40); - GXWriteU8U8U32(0x08, 0x40, _44); - GXWriteU8U16U16U32U32(0x10, 0x0001, 0x1018, _40, _44); - // HW_REG(GXFIFO_ADDR, u8) = 0x08; - // HW_REG(GXFIFO_ADDR, u8) = 0x30; - // HW_REG(GXFIFO_ADDR, u32) = _40; - // HW_REG(GXFIFO_ADDR, u8) = 0x08; - // HW_REG(GXFIFO_ADDR, u8) = 0x40; - // HW_REG(GXFIFO_ADDR, u32) = _44; - // HW_REG(GXFIFO_ADDR, u8) = 0x10; - // HW_REG(GXFIFO_ADDR, u16) = 1; - // HW_REG(GXFIFO_ADDR, u16) = 0x1018; - // HW_REG(GXFIFO_ADDR, u32) = _40; - // HW_REG(GXFIFO_ADDR, u32) = _44; + mCurrentMtx.load(); + // GXWGFifo.u8 = 0x08; + // GXWGFifo.u8 = 0x30; + // GXWGFifo.u32 = mCurrentMtx; + // GXWGFifo.u8 = 0x08; + // GXWGFifo.u8 = 0x40; + // GXWGFifo.u32 = _44; + // GXWGFifo.u8 = 0x10; + // GXWGFifo.u16 = 1; + // GXWGFifo.u16 = 0x1018; + // GXWGFifo.u32 = mCurrentMtx; + // GXWGFifo.u32 = _44; } - GXWriteU8U8U32(0x08, 0xA0, j3dSys._10C & 0x7FFFFFFF); - // HW_REG(GXFIFO_ADDR, u8) = 0x08; - // HW_REG(GXFIFO_ADDR, u8) = 0xA0; - // HW_REG(GXFIFO_ADDR, u32) = j3dSys._10C & 0x7FFFFFFF; + // GXWriteU8U8U32(0x08, 0xA0, j3dSys.mVtxPos & 0x7FFFFFFF); + // GXWGFifo.u8= 0x08; + // GXWGFifo.u8= 0xA0; + // GXWGFifo.u32= j3dSys._10C & 0x7FFFFFFF; if (mMode == 0) { - HW_REG(GXFIFO_ADDR, u8) = 0x08; - HW_REG(GXFIFO_ADDR, u8) = 0xA1; - HW_REG(GXFIFO_ADDR, u32) = j3dSys._110 & 0x7FFFFFFF; + GXWGFifo.u8 = 0x08; + GXWGFifo.u8 = 0xA1; + // GXWGFifo.u32= j3dSys.mVtxNorm & 0x7FFFFFFF; } - HW_REG(GXFIFO_ADDR, u8) = 0x08; - HW_REG(GXFIFO_ADDR, u8) = 0xA2; - HW_REG(GXFIFO_ADDR, u32) = j3dSys._114 & 0x7FFFFFFF; - for (u16 i = 0; i < _0A; ++i) { - if (_3C[i] != nullptr) { - _3C[i]->draw(); + GXWGFifo.u8 = 0x08; + GXWGFifo.u8 = 0xA2; + // GXWGFifo.u32= j3dSys.mVtxColor & 0x7FFFFFFF; + for (u16 i = 0; i < mMtxGroupNum; ++i) { + if (mShapeDraw[i] != nullptr) { + mShapeDraw[i]->draw(); } } /*