summaryrefslogtreecommitdiff
path: root/libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp
diff options
context:
space:
mode:
authorTakaRikka <38417346+TakaRikka@users.noreply.github.com>2022-04-26 23:28:35 -0700
committerGitHub <noreply@github.com>2022-04-26 23:28:35 -0700
commit07c5152e5acff18c08a92b3c773583ae0114c5f4 (patch)
treea478a239c49a0efa6e8ee0d64adb223f7803d0ab /libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp
parent589cc12296ae7253c62655859a5eef92ee42dbaf (diff)
parent907e734ae71372f61e466a6941e7d369a0994ab6 (diff)
Merge pull request #193 from magcius/j3dsys
more J3D work
Diffstat (limited to 'libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp')
-rw-r--r--libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp87
1 files changed, 64 insertions, 23 deletions
diff --git a/libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp b/libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp
index befab13ce8..6da5f00bcd 100644
--- a/libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp
+++ b/libs/JSystem/J3DGraphBase/J3DShapeDraw.cpp
@@ -4,46 +4,85 @@
//
#include "JSystem/J3DGraphBase/J3DShapeDraw.h"
+#include "JSystem/JKernel/JKRHeap.h"
#include "dol2asm.h"
+#include "dolphin/os/OSCache.h"
#include "dolphin/gx/GX.h"
#include "dolphin/types.h"
-
-//
-// Forward References:
-//
-
-extern "C" void countVertex__12J3DShapeDrawFUl();
-extern "C" void addTexMtxIndexInDL__12J3DShapeDrawFUlUlUl();
-extern "C" void __ct__12J3DShapeDrawFPCUcUl();
-extern "C" void draw__12J3DShapeDrawCFv();
-extern "C" void __dt__12J3DShapeDrawFv();
+#include "MSL_C/MSL_Common/Src/string.h"
//
// External References:
//
-SECTION_INIT void memcpy();
+extern "C" void countVertex__12J3DShapeDrawFUl();
extern "C" void* __nwa__FUli();
extern "C" void __dl__FPv();
-extern "C" void DCStoreRange();
extern "C" void _savegpr_18();
extern "C" void _restgpr_18();
-//
-// Declarations:
-//
-
/* 80314924-80314974 30F264 0050+00 1/1 0/0 0/0 .text countVertex__12J3DShapeDrawFUl */
-#pragma push
-#pragma optimization_level 0
-#pragma optimizewithasm off
-asm void J3DShapeDraw::countVertex(u32 param_0) {
- nofralloc
-#include "asm/JSystem/J3DGraphBase/J3DShapeDraw/countVertex__12J3DShapeDrawFUl.s"
+u32 J3DShapeDraw::countVertex(u32 stride) {
+ u32 count = 0;
+ u32 dlStart = (u32)getDisplayList();
+ for (u8* dl = (u8*)dlStart; ((u32)dl - dlStart) < getDisplayListSize();) {
+ if (*dl != 0xA0 && *dl != 0x98)
+ break;
+ u16 vtxNum = *((u16*)(dl + 1));
+ count += vtxNum;
+ dl += stride * vtxNum;
+ dl += 3;
+ }
+ return count;
}
-#pragma pop
+#ifdef NONMATCHING
/* 80314974-80314ABC 30F2B4 0148+00 0/0 1/1 0/0 .text addTexMtxIndexInDL__12J3DShapeDrawFUlUlUl */
+void J3DShapeDraw::addTexMtxIndexInDL(u32 stride, u32 attrOffs, u32 valueBase) {
+ u32 byteNum = countVertex(stride);
+ u32 newSize = ALIGN_NEXT(mDisplayListSize + byteNum, 0x20);
+ u8* newDLStart = new (0x20) u8[newSize];
+ u8* oldDLStart = getDisplayList();
+ u8* oldDL = oldDLStart;
+ u8* newDL = newDLStart;
+ for (; (oldDL - oldDLStart) < mDisplayListSize;) {
+ // Copy command
+ u8 h = *oldDL;
+ *newDL++ = h;
+
+ if (h != 0xA0 && h != 0x98)
+ break;
+
+ // Copy count
+ // regalloc (I suspect there's a way to shove this in a u16 temp without an mr)
+ u32 vtxNum = *((u16*)(oldDL + 1));
+ *((u16*)newDL) = vtxNum;
+ newDL += 2;
+
+ for (s32 i = 0; i < (u16)vtxNum; i++) {
+ // mul arg swap
+ u8* oldDLVtx = (&oldDL[stride * i + 3]);
+ u8 pnmtxidx = *oldDLVtx;
+ memcpy(newDL, oldDLVtx, attrOffs);
+ u8* newDL1 = &newDL[attrOffs];
+ *newDL1++ = valueBase + pnmtxidx;
+ memcpy(newDL1, oldDLVtx + attrOffs, stride - attrOffs);
+ newDL = newDL1 + (stride - attrOffs);
+ }
+
+ oldDL += stride * vtxNum;
+ oldDL += 3;
+ }
+
+ u32 realSize = ALIGN_NEXT((u32)newDL - (u32)newDLStart, 0x20);
+ for (; (newDL - newDLStart) < newSize; newDL++)
+ *newDL = 0;
+ mDisplayListSize = realSize;
+ mDisplayList = newDLStart;
+ DCStoreRange(newDLStart, mDisplayListSize);
+}
+#else
+
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -53,6 +92,8 @@ asm void J3DShapeDraw::addTexMtxIndexInDL(u32 param_0, u32 param_1, u32 param_2)
}
#pragma pop
+#endif
+
/* 80314ABC-80314AD4 30F3FC 0018+00 0/0 1/1 0/0 .text __ct__12J3DShapeDrawFPCUcUl */
J3DShapeDraw::J3DShapeDraw(u8 const* displayList, u32 displayListSize) {
mDisplayList = (void*)displayList;