From 45eef35f728198a518affe1796920c6d51bb8d81 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sat, 23 Sep 2023 19:53:32 -0400 Subject: [PATCH] More J3DMatBlock progress with terrible alignment hacks (and some real fixes too) --- include/JSystem/J3DGraphBase/J3DMatBlock.h | 5 ++--- include/JSystem/J3DGraphBase/J3DTevs.h | 6 +----- include/global.h | 3 +++ src/JSystem/J3DGraphBase/J3DMatBlock.cpp | 17 ++++++++--------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/JSystem/J3DGraphBase/J3DMatBlock.h b/include/JSystem/J3DGraphBase/J3DMatBlock.h index e9df1d45d..bf1b23604 100644 --- a/include/JSystem/J3DGraphBase/J3DMatBlock.h +++ b/include/JSystem/J3DGraphBase/J3DMatBlock.h @@ -760,9 +760,8 @@ struct J3DIndTexCoordScale { ~J3DIndTexCoordScale(); J3DIndTexCoordScale(); - /* 0x0 */ u8 mScaleS; + /* 0x0 */ u8 mScaleS __attribute__((aligned(4))); /* 0x1 */ u8 mScaleT; - u8 pad[2]; }; struct J3DIndTexMtx { @@ -800,7 +799,7 @@ public: virtual void setIndTexCoordScale(u32, J3DIndTexCoordScale); virtual void setIndTexCoordScale(u32, J3DIndTexCoordScale const*); virtual J3DIndTexCoordScale * getIndTexCoordScale(u32); - virtual ~J3DIndBlock(); + virtual ~J3DIndBlock() {} }; class J3DIndBlockFull : public J3DIndBlock { diff --git a/include/JSystem/J3DGraphBase/J3DTevs.h b/include/JSystem/J3DGraphBase/J3DTevs.h index 0b29af869..6d7311c88 100644 --- a/include/JSystem/J3DGraphBase/J3DTevs.h +++ b/include/JSystem/J3DGraphBase/J3DTevs.h @@ -39,17 +39,13 @@ struct J3DIndTevStage { }; struct J3DTevOrderInfo { - /* 0x0 */ u8 mTexCoord; + /* 0x0 */ u8 mTexCoord __attribute__((aligned(2))); /* 0x1 */ u8 mTexMap; /* 0x2 */ u8 mColorChan; - /* 0x3 */ u8 field_0x3; // Maybe padding }; struct J3DTevOrder : public J3DTevOrderInfo { J3DTevOrder(); - J3DTevOrder(const J3DTevOrderInfo& info) { - *(J3DTevOrderInfo*)this = info; - } u8 getTexMap() { return mTexMap; } }; diff --git a/include/global.h b/include/global.h index 30b845f1b..331f7ed49 100644 --- a/include/global.h +++ b/include/global.h @@ -24,6 +24,9 @@ #define _SDA2_BASE_(dummy) 0 #ifndef IN_VSCODE_EDITOR +#ifndef offsetof +#define offsetof(type, member) ((size_t) & (((type*)0)->member)) +#endif #define GLUE(a, b) a##b #define GLUE2(a, b) GLUE(a, b) #define STATIC_ASSERT(cond) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1] diff --git a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp index b057620ca..686e38483 100644 --- a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp +++ b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp @@ -1008,7 +1008,7 @@ void J3DTevBlock16::setTevKColorSel(u32 i, const u8* pNum) { /* 802EA3C0-802EA3CC .text getTevKColorSel__13J3DTevBlock16FUl */ u8 J3DTevBlock16::getTevKColorSel(u32 i) { - return mTevKAlphaSel[i]; + return mTevKColorSel[i]; } /* 802EA3CC-802EA3D8 .text setTevKAlphaSel__13J3DTevBlock16FUlUc */ @@ -1038,7 +1038,7 @@ void J3DTevBlock16::setTevStageNum(const u8* pNum) { /* 802EA408-802EA410 .text getTevStageNum__13J3DTevBlock16CFv */ u8 J3DTevBlock16::getTevStageNum() const { - /* Nonmatching */ + return mTevStageNum; } /* 802EA410-802EA44C .text setTevStage__13J3DTevBlock16FUl11J3DTevStage */ @@ -1098,7 +1098,7 @@ J3DIndTevStage * J3DTevBlock16::getIndTevStage(u32 i) { /* 802EA578-802EA580 .text getTexNoOffset__13J3DTevBlock16CFv */ u32 J3DTevBlock16::getTexNoOffset() const { - /* Nonmatching */ + return mTexNoOffset; } /* 802EA580-802EA588 .text getTevRegOffset__13J3DTevBlock16CFv */ @@ -1118,7 +1118,7 @@ J3DTevBlock16::~J3DTevBlock16() { /* 802EA5EC-802EA5F4 .text setTexNoOffset__11J3DTevBlockFUl */ void J3DTevBlock::setTexNoOffset(u32 i) { - /* Nonmatching */ + mTexNoOffset = i; } /* 802EA5F4-802EA5F8 .text ptrToIndex__12J3DTevBlock4Fv */ @@ -1208,7 +1208,7 @@ void J3DTevBlock4::setTevKColorSel(u32 i, const u8* pNum) { /* 802EA7AC-802EA7B8 .text getTevKColorSel__12J3DTevBlock4FUl */ u8 J3DTevBlock4::getTevKColorSel(u32 i) { - return mTevKAlphaSel[i]; + return mTevKColorSel[i]; } /* 802EA7B8-802EA7C4 .text setTevKAlphaSel__12J3DTevBlock4FUlUc */ @@ -1238,7 +1238,7 @@ void J3DTevBlock4::setTevStageNum(const u8* pNum) { /* 802EA7F4-802EA7FC .text getTevStageNum__12J3DTevBlock4CFv */ u8 J3DTevBlock4::getTevStageNum() const { - /* Nonmatching */ + return mTevStageNum; } /* 802EA7FC-802EA838 .text setTevStage__12J3DTevBlock4FUl11J3DTevStage */ @@ -1298,7 +1298,7 @@ J3DIndTevStage * J3DTevBlock4::getIndTevStage(u32 i) { /* 802EA964-802EA96C .text getTexNoOffset__12J3DTevBlock4CFv */ u32 J3DTevBlock4::getTexNoOffset() const { - /* Nonmatching */ + return mTexNoOffset; } /* 802EA96C-802EA974 .text getTevRegOffset__12J3DTevBlock4CFv */ @@ -1403,7 +1403,7 @@ void J3DTevBlock2::setTevKColorSel(u32 i, const u8* pNum) { /* 802EAB90-802EAB9C .text getTevKColorSel__12J3DTevBlock2FUl */ u8 J3DTevBlock2::getTevKColorSel(u32 i) { - return mTevKAlphaSel[i]; + return mTevKColorSel[i]; } /* 802EAB9C-802EABA8 .text setTevKAlphaSel__12J3DTevBlock2FUlUc */ @@ -2208,7 +2208,6 @@ J3DIndTexCoordScale * J3DIndBlockFull::getIndTexCoordScale(u32 i) { /* 802EBBA4-802EBC40 .text __dt__15J3DIndBlockFullFv */ J3DIndBlockFull::~J3DIndBlockFull() { - /* Nonmatching */ } /* 802EBC40-802EBC44 .text patchTexNo__11J3DTevBlockFv */