J3D debug work (#2949)

* J3D debug work

* Clean up JSystem GXColor ctors, remove a couple fakematches

* Update symbols.txt

* Fix res include syntax

* Remove fakematch that isn't necessary anymore

* Fix some Shield regressions
This commit is contained in:
LagoLunatic
2025-12-13 00:04:03 -05:00
committed by GitHub
parent 7e514502d2
commit 1b8ea3206d
24 changed files with 307 additions and 211 deletions
+80 -26
View File
@@ -14,17 +14,24 @@
struct J3DGXColorS10 : public GXColorS10 {
J3DGXColorS10() {}
#if PLATFORM_GCN
#if PLATFORM_GCN && __MWERKS__
J3DGXColorS10(J3DGXColorS10& other) { __memcpy(this, &other, sizeof(J3DGXColorS10)); }
#elif DEBUG
J3DGXColorS10(const J3DGXColorS10& other) {
GXColorS10 sp08 = other;
J3DGXColorS10* r31 = this;
__memcpy(r31, &sp08, sizeof(GXColorS10));
J3DGXColorS10* r30 = r31;
}
#else
J3DGXColorS10(J3DGXColorS10 const& other) { __memcpy(this, &other, sizeof(J3DGXColorS10)); }
J3DGXColorS10(const J3DGXColorS10& other) { __memcpy(this, &other, sizeof(J3DGXColorS10)); }
#endif
// TODO: In theory, this copy ctor should be non-const in GCN versions, as seen in TWW maps
J3DGXColorS10(GXColorS10 const& color) : GXColorS10(color) {}
J3DGXColorS10(const GXColorS10& color) : GXColorS10(color) {}
J3DGXColorS10& operator=(const GXColorS10& color) {
// FAKE match. __memcpy created issues in J3DTevBlockPatched::initialize
// Fakematch? Instruction order is wrong with __memcpy or GXColorS10::operator=
// Might be real as this matches on debug as well.
((u32*)this)[0] = ((u32*)&color)[0];
((u32*)this)[1] = ((u32*)&color)[1];
return *this;
@@ -37,20 +44,21 @@ struct J3DGXColorS10 : public GXColorS10 {
*/
struct J3DGXColor : public GXColor {
J3DGXColor() {}
// TODO: In theory, these copy ctors should be non-const in GCN versions, as seen in TWW maps
J3DGXColor(J3DGXColor const& other) { __memcpy(this, &other, sizeof(J3DGXColor)); }
J3DGXColor(GXColor const& color) : GXColor(color) {}
// making color a reference breaks J3DColorBlockLightOff::initialize et al
J3DGXColor& operator=(GXColor color) {
#if PLATFORM_GCN && __MWERKS__
J3DGXColor(J3DGXColor& other) { __memcpy(this, &other, sizeof(J3DGXColor)); }
#else
J3DGXColor(const J3DGXColor& other) { __memcpy(this, &other, sizeof(J3DGXColor)); }
#endif
J3DGXColor(const GXColor color) : GXColor(color) {}
J3DGXColor& operator=(const GXColor color) {
*(GXColor*)this = color;
return *this;
}
J3DGXColor& operator=(const J3DGXColor& other) {
r = other.r;
g = other.g;
b = other.b;
a = other.a;
GXColor::operator=(other);
return *this;
}
};
@@ -71,7 +79,9 @@ struct J3DNBTScale : public J3DNBTScaleInfo {
J3DNBTScale(J3DNBTScaleInfo const& info) {
mbHasScale = info.mbHasScale;
mScale = info.mScale;
mScale.x = info.mScale.x;
mScale.y = info.mScale.y;
mScale.z = info.mScale.z;
}
Vec* getScale() { return &mScale; }
@@ -139,7 +149,7 @@ struct J3DColorChan {
info.mDiffuseFn, info.mAttnFn, ambSrc);
}
void setColorChanInfo(J3DColorChanInfo const& info) {
// Bug: It compares info.mAmbSrc (an 8 bit integer) with 0xFFFF instead of 0xFF.
// !@bug: It compares info.mAmbSrc (an 8 bit integer) with 0xFFFF instead of 0xFF.
// This inline is only called by the default constructor J3DColorChan().
// The J3DColorChan(const J3DColorChanInfo&) constructor does not call this inline, and instead duplicates the
// same logic but without the bug.
@@ -165,6 +175,10 @@ struct J3DColorChan {
#endif
return AttnArr[(u32)(mColorChanID & (3 << 9)) >> 9];
}
J3DColorChan& operator=(const J3DColorChan& other) {
mColorChanID = other.mColorChanID;
return *this;
}
void load() const {
J3DGDWrite_u32(setChanCtrlMacro(getEnable(), (GXColorSrc)getAmbSrc(), (GXColorSrc)getMatSrc(), getLightMask(),
@@ -1453,6 +1467,10 @@ struct J3DZMode {
mZModeID = zModeID;
return *this;
}
J3DZMode& operator=(const J3DZMode& other) {
mZModeID = other.mZModeID;
return *this;
}
void setZModeInfo(const J3DZModeInfo& info) {
mZModeID = calcZModeID(info.field_0x0, info.field_0x1, info.field_0x2);
@@ -1487,7 +1505,7 @@ struct J3DZMode {
*/
struct J3DBlendInfo {
void operator=(J3DBlendInfo const& other) {
*(int*)&mType = *(int*)&other.mType;
__memcpy(this, &other, sizeof(J3DBlendInfo));
}
/* 0x0 */ u8 mType;
/* 0x1 */ u8 mSrcFactor;
@@ -1502,8 +1520,12 @@ extern const J3DBlendInfo j3dDefaultBlendInfo;
*
*/
struct J3DBlend : public J3DBlendInfo {
J3DBlend() : J3DBlendInfo(j3dDefaultBlendInfo) {}
J3DBlend(J3DBlendInfo const& info) : J3DBlendInfo(info) {}
J3DBlend() {
J3DBlendInfo::operator=(j3dDefaultBlendInfo);
}
J3DBlend(J3DBlendInfo const& info) {
J3DBlendInfo::operator=(info);
}
void setType(u8 i_type) { mType = i_type; }
void setSrcFactor(u8 i_factor) { mSrcFactor = i_factor; }
@@ -1630,6 +1652,10 @@ struct J3DIndTexOrderInfo {
/* 0x1 */ u8 mMap;
/* 0x2 */ u8 field_0x2;
/* 0x3 */ u8 field_0x3;
void operator=(J3DIndTexOrderInfo const& other) {
__memcpy(this, &other, sizeof(J3DIndTexOrderInfo));
}
}; // Size: 0x04
extern const J3DIndTexOrderInfo j3dDefaultIndTexOrderNull;
@@ -1639,12 +1665,21 @@ extern const J3DIndTexOrderInfo j3dDefaultIndTexOrderNull;
*
*/
struct J3DIndTexOrder : public J3DIndTexOrderInfo {
J3DIndTexOrder() : J3DIndTexOrderInfo(j3dDefaultIndTexOrderNull) {}
J3DIndTexOrder() {
J3DIndTexOrderInfo::operator=(j3dDefaultIndTexOrderNull);
}
J3DIndTexOrder& operator=(J3DIndTexOrder const& other) {
#if DEBUG
J3DIndTexOrderInfo::operator=(other);
#else
// Fakematch: Instruction order is wrong with __memcpy or J3DIndTexCoordScaleInfo::operator=
*(u32*)this = *(u32*)&other;
#endif
return *this;
}
J3DIndTexOrder(J3DIndTexOrderInfo const& info) : J3DIndTexOrderInfo(info) {}
J3DIndTexOrder(J3DIndTexOrderInfo const& info) {
J3DIndTexOrderInfo::operator=(info);
}
u8 getMap() const { return (GXTexMapID)mMap; }
u8 getCoord() const { return (GXTexCoordID)mCoord; }
}; // Size: 0x04
@@ -1657,7 +1692,10 @@ extern J3DIndTexMtxInfo const j3dDefaultIndTexMtxInfo;
*/
struct J3DIndTexMtx : public J3DIndTexMtxInfo {
J3DIndTexMtx() { *(J3DIndTexMtxInfo*)this = j3dDefaultIndTexMtxInfo; }
J3DIndTexMtx(J3DIndTexMtxInfo const& info) { *(J3DIndTexMtxInfo*)this = info; }
J3DIndTexMtx(const J3DIndTexMtxInfo& info) { *(J3DIndTexMtxInfo*)this = info; }
J3DIndTexMtx(const J3DIndTexMtx& other) {
__memcpy(this, &other, sizeof(J3DIndTexMtx));
}
~J3DIndTexMtx() {}
void load(u32 param_1) const {
J3DGDSetIndTexMtx((GXIndTexMtxID)(param_1 + GX_ITM_0), (Mtx3P)field_0x0, field_0x18);
@@ -1673,6 +1711,11 @@ struct J3DIndTexCoordScaleInfo {
/* 0x1 */ u8 mScaleT;
/* 0x2 */ u8 field_0x2;
/* 0x3 */ u8 field_0x3;
J3DIndTexCoordScaleInfo& operator=(const J3DIndTexCoordScaleInfo& other) {
__memcpy(this, &other, sizeof(J3DIndTexCoordScaleInfo));
return *this;
}
}; // Size: 0x4
extern const J3DIndTexCoordScaleInfo j3dDefaultIndTexCoordScaleInfo;
@@ -1682,15 +1725,26 @@ extern const J3DIndTexCoordScaleInfo j3dDefaultIndTexCoordScaleInfo;
*
*/
struct J3DIndTexCoordScale : public J3DIndTexCoordScaleInfo {
J3DIndTexCoordScale() : J3DIndTexCoordScaleInfo(j3dDefaultIndTexCoordScaleInfo) {}
J3DIndTexCoordScale(J3DIndTexCoordScaleInfo const& info) : J3DIndTexCoordScaleInfo(info) {}
J3DIndTexCoordScale() {
J3DIndTexCoordScaleInfo::operator=(j3dDefaultIndTexCoordScaleInfo);
}
J3DIndTexCoordScale(const J3DIndTexCoordScaleInfo& info) {
J3DIndTexCoordScaleInfo::operator=(info);
}
J3DIndTexCoordScale(const J3DIndTexCoordScale& other) {
__memcpy(this, &other, sizeof(J3DIndTexCoordScale));
}
~J3DIndTexCoordScale() {}
u8 getScaleS() { return mScaleS; }
u8 getScaleT() { return mScaleT; }
J3DIndTexCoordScale& operator=(const J3DIndTexCoordScale& other) {
//__memcpy(this, &other, sizeof(J3DIndTexCoordScaleInfo));
#if DEBUG
J3DIndTexCoordScaleInfo::operator=(other);
#else
// Fakematch: Instruction order is wrong with __memcpy or J3DIndTexCoordScaleInfo::operator=
*(u32*)this = *(u32*)&other;
#endif
return *this;
}
}; // Size: 0x4
+7 -5
View File
@@ -259,7 +259,9 @@ extern const J3DTevOrderInfo j3dDefaultTevOrderInfoNull;
*
*/
struct J3DTevOrder : public J3DTevOrderInfo {
J3DTevOrder() : J3DTevOrderInfo(j3dDefaultTevOrderInfoNull) {}
J3DTevOrder() {
J3DTevOrderInfo::operator=(j3dDefaultTevOrderInfoNull);
}
J3DTevOrder(const J3DTevOrderInfo& info) : J3DTevOrderInfo(info) {}
J3DTevOrderInfo& getTevOrderInfo() { return *this; }
@@ -269,6 +271,10 @@ struct J3DTevOrder : public J3DTevOrderInfo {
extern u8 j3dTevSwapTableTable[1024];
extern u8 const j3dDefaultTevSwapTableID;
inline u8 calcTevSwapTableID(u8 param_0, u8 param_1, u8 param_2, u8 param_3) {
return 0x40 * (u8)param_0 + 0x10 * (u8)param_1 + 4 * (u8)param_2 + param_3;
}
/**
* @ingroup jsystem-j3d
*
@@ -289,10 +295,6 @@ struct J3DTevSwapModeTable {
return *this;
}
u8 calcTevSwapTableID(u8 param_0, u8 param_1, u8 param_2, u8 param_3) {
return 0x40 * param_0 + 0x10 * param_1 + 4 * param_2 + param_3;
}
u8 getR() const { return *(&j3dTevSwapTableTable[mIdx * 4] + 0); }
u8 getG() const { return *(&j3dTevSwapTableTable[mIdx * 4] + 1); }
u8 getB() const { return *(&j3dTevSwapTableTable[mIdx * 4] + 2); }
+12 -11
View File
@@ -82,10 +82,7 @@ struct J3DTexCoordInfo {
/* 0x3 */ u8 pad;
J3DTexCoordInfo& operator=(const J3DTexCoordInfo& other) {
mTexGenType = other.mTexGenType;
mTexGenSrc = other.mTexGenSrc;
mTexGenMtx = other.mTexGenMtx;
pad = other.pad;
__memcpy(this, &other, sizeof(J3DTexCoordInfo));
return *this;
}
};
@@ -98,14 +95,14 @@ extern J3DTexCoordInfo const j3dDefaultTexCoordInfo[8];
*/
struct J3DTexCoord : public J3DTexCoordInfo {
J3DTexCoord() {
setTexCoordInfo(j3dDefaultTexCoordInfo[0]);
resetTexMtxReg();
J3DTexCoordInfo::operator=(j3dDefaultTexCoordInfo[0]);
mTexMtxReg = mTexGenMtx;
}
J3DTexCoord(J3DTexCoordInfo const& info) {
setTexCoordInfo(info);
resetTexMtxReg();
J3DTexCoord(const J3DTexCoordInfo& info) {
J3DTexCoordInfo::operator=(info);
mTexMtxReg = mTexGenMtx;
}
void setTexCoordInfo(J3DTexCoordInfo const& info) {
void setTexCoordInfo(const J3DTexCoordInfo& info) {
__memcpy(this, &info, sizeof(J3DTexCoordInfo));
}
@@ -116,8 +113,12 @@ struct J3DTexCoord : public J3DTexCoordInfo {
void setTexGenMtx(u8 param_1) { mTexGenMtx = param_1; }
void setTexMtxReg(u16 reg) { mTexMtxReg = reg; }
J3DTexCoord& operator=(const J3DTexCoord& other) {
// Fake match (__memcpy or = doesn't match)
#if DEBUG
J3DTexCoordInfo::operator=(other);
#else
// Fakematch: Instruction order is wrong with __memcpy or J3DTexCoordInfo::operator=
*(u32*)this = *(u32*)&other;
#endif
return *this;
}