mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-07 20:11:46 -04:00
Add C versions of all ASM blocks (except THP)
This commit is contained in:
@@ -1326,7 +1326,6 @@ set(DUSK_FILES
|
||||
src/dusk/extras.c
|
||||
src/dusk/extras.cpp
|
||||
src/dusk/globals.cpp
|
||||
src/dusk/J3DTransforms_C.cpp
|
||||
#src/dusk/m_Do_ext_dusk.cpp
|
||||
src/dusk/dvd_emu.cpp
|
||||
src/dolphin/os/OSContext.cpp
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "JSystem/J3DGraphAnimator/J3DCluster.h"
|
||||
#include "JSystem/J3DGraphAnimator/J3DMtxBuffer.h"
|
||||
#include <dolphin/types.h>
|
||||
#include <cstring>
|
||||
|
||||
class J3DModel;
|
||||
class J3DAnmCluster;
|
||||
@@ -115,6 +116,8 @@ inline void J3DFillZero32B(__REGISTER void* param_0, __REGISTER u32 param_1) {
|
||||
addi param_0, param_0, 0x20
|
||||
bdnz lbl_8032D948
|
||||
}
|
||||
#else
|
||||
memset(param_0, 0, param_1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ struct J3DTextureSRTInfo {
|
||||
/* 0x10 */ f32 mTranslationY;
|
||||
|
||||
bool operator==(J3DTextureSRTInfo&) const;
|
||||
inline void operator=(J3DTextureSRTInfo const& other) {
|
||||
#ifdef __MWERKS__
|
||||
inline void operator=(J3DTextureSRTInfo const& other) {
|
||||
__REGISTER const f32* src = &other.mScaleX;
|
||||
__REGISTER f32* dst = &mScaleX;
|
||||
__REGISTER f32 xy;
|
||||
@@ -58,8 +58,8 @@ struct J3DTextureSRTInfo {
|
||||
psq_l xy, 0(src), 0, 0
|
||||
psq_st xy, 0(dst), 0, 0
|
||||
};
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}; // Size: 0x14
|
||||
|
||||
enum J3DTexMtxMode {
|
||||
|
||||
@@ -85,6 +85,12 @@ inline void J3DPSMtx33Copy(__REGISTER Mtx3P src, __REGISTER Mtx3P dst) {
|
||||
psq_st fr1, 0x18(dst), 0, 0
|
||||
stfs fr0, 0x20(dst)
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
dst[i][j] = src[i][j];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -110,6 +116,12 @@ inline void J3DPSMtx33CopyFrom34(__REGISTER MtxP src, __REGISTER Mtx3P dst) {
|
||||
psq_st x_y3, 24(dst), 0, 0
|
||||
stfs z3, 0x20(dst)
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
dst[i][j] = src[i][j];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -137,6 +149,12 @@ inline void J3DPSMulMtxVec(__REGISTER MtxP mtx, __REGISTER Vec* vec, __REGISTER
|
||||
ps_sum0 f6, f5, f6, f5
|
||||
psq_st f6, 8(dst), 1, 0
|
||||
}
|
||||
#else
|
||||
Vec tmp;
|
||||
tmp.x = mtx[0][0] * vec->x + mtx[0][1] * vec->y + mtx[0][2] * vec->z + mtx[0][3];
|
||||
tmp.y = mtx[1][0] * vec->x + mtx[1][1] * vec->y + mtx[1][2] * vec->z + mtx[1][3];
|
||||
tmp.z = mtx[2][0] * vec->x + mtx[2][1] * vec->y + mtx[2][2] * vec->z + mtx[2][3];
|
||||
*dst = tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -164,6 +182,12 @@ inline void J3DPSMulMtxVec(__REGISTER MtxP mtx, __REGISTER S16Vec* vec, __REGIST
|
||||
ps_sum0 f6, f5, f6, f5
|
||||
psq_st f6, 4(dst), 1, 7
|
||||
}
|
||||
#else
|
||||
S16Vec tmp;
|
||||
tmp.x = (s16)(mtx[0][0] * vec->x + mtx[0][1] * vec->y + mtx[0][2] * vec->z + mtx[0][3]);
|
||||
tmp.y = (s16)(mtx[1][0] * vec->x + mtx[1][1] * vec->y + mtx[1][2] * vec->z + mtx[1][3]);
|
||||
tmp.z = (s16)(mtx[2][0] * vec->x + mtx[2][1] * vec->y + mtx[2][2] * vec->z + mtx[2][3]);
|
||||
*dst = tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -195,6 +219,12 @@ inline void J3DPSMulMtxVec(__REGISTER Mtx3P mtx, __REGISTER Vec* vec, __REGISTER
|
||||
ps_sum0 f6, f5, f6, f5
|
||||
psq_st f6, 8(dst), 1, 0
|
||||
}
|
||||
#else
|
||||
Vec tmp;
|
||||
tmp.x = mtx[0][0] * vec->x + mtx[0][1] * vec->y + mtx[0][2] * vec->z;
|
||||
tmp.y = mtx[1][0] * vec->x + mtx[1][1] * vec->y + mtx[1][2] * vec->z;
|
||||
tmp.z = mtx[2][0] * vec->x + mtx[2][1] * vec->y + mtx[2][2] * vec->z;
|
||||
*dst = tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -226,6 +256,12 @@ inline void J3DPSMulMtxVec(__REGISTER Mtx3P mtx, __REGISTER S16Vec* vec, __REGIS
|
||||
ps_sum0 f6, f5, f6, f5
|
||||
psq_st f6, 4(dst), 1, 7
|
||||
}
|
||||
#else
|
||||
S16Vec tmp;
|
||||
tmp.x = (s16)(mtx[0][0] * vec->x + mtx[0][1] * vec->y + mtx[0][2] * vec->z);
|
||||
tmp.y = (s16)(mtx[1][0] * vec->x + mtx[1][1] * vec->y + mtx[1][2] * vec->z);
|
||||
tmp.z = (s16)(mtx[2][0] * vec->x + mtx[2][1] * vec->y + mtx[2][2] * vec->z);
|
||||
*dst = tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,10 @@ inline void setTVec3f(const __REGISTER f32* vec_a, __REGISTER f32* vec_b) {
|
||||
psq_st a_x, 0(vec_b), 0, 0
|
||||
stfs b_x, 8(vec_b)
|
||||
};
|
||||
#else
|
||||
vec_b[0] = vec_a[0];
|
||||
vec_b[1] = vec_a[1];
|
||||
vec_b[2] = vec_a[2];
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -163,6 +167,8 @@ inline float fsqrt_step(float mag) {
|
||||
#ifdef __MWERKS__
|
||||
f32 root = __frsqrte(mag);
|
||||
return 0.5f * root * (3.0f - mag * (root * root));
|
||||
#else
|
||||
return 1.0f / sqrtf(mag);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -182,6 +188,10 @@ inline void mulInternal(__REGISTER const f32* a, __REGISTER const f32* b, __REGI
|
||||
psq_st x_y, 0(dst), 0, 0
|
||||
};
|
||||
dst[2] = a[2] * b[2];
|
||||
#else
|
||||
dst[0] = a[0] * b[0];
|
||||
dst[1] = a[1] * b[1];
|
||||
dst[2] = a[2] * b[2];
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -359,6 +369,10 @@ struct TVec3<f32> : public Vec {
|
||||
fneg z, z
|
||||
stfs z, 8(rdst)
|
||||
};
|
||||
#else
|
||||
dst->x = -x;
|
||||
dst->y = -y;
|
||||
dst->z = -z;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -109,6 +109,12 @@ void J3DTexMtxInfo::setEffectMtx(Mtx param_0) {
|
||||
};
|
||||
mEffectMtx[3][2] = 0.0f;
|
||||
mEffectMtx[3][3] = 1.0f;
|
||||
#else
|
||||
JMath::gekko_ps_copy12(&mEffectMtx, param_0);
|
||||
mEffectMtx[3][0] = 0.0f;
|
||||
mEffectMtx[3][1] = 0.0f;
|
||||
mEffectMtx[3][2] = 0.0f;
|
||||
mEffectMtx[3][3] = 1.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -159,6 +159,14 @@ lbl_8005F118:
|
||||
li r3, 1
|
||||
psq_st f8, 32(r4), 1, 0
|
||||
blr
|
||||
#else
|
||||
Mtx invX;
|
||||
|
||||
if (C_MTXInvXpose(src, invX) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
J3DPSMtx33CopyFrom34(invX, dst);
|
||||
#endif // clang-format on
|
||||
}
|
||||
|
||||
@@ -327,6 +335,22 @@ ASM void J3DScaleNrmMtx(__REGISTER Mtx mtx, const __REGISTER Vec& scl) {
|
||||
fmuls f4, fp1, fp3
|
||||
stfs f4, 40(mtx)
|
||||
blr
|
||||
#else
|
||||
f32 sx = scl.x;
|
||||
f32 sy = scl.y;
|
||||
f32 sz = scl.z;
|
||||
|
||||
mtx[0][0] *= sx;
|
||||
mtx[0][1] *= sy;
|
||||
mtx[0][2] *= sz;
|
||||
|
||||
mtx[1][0] *= sx;
|
||||
mtx[1][1] *= sy;
|
||||
mtx[1][2] *= sz;
|
||||
|
||||
mtx[2][0] *= sx;
|
||||
mtx[2][1] *= sy;
|
||||
mtx[2][2] *= sz;
|
||||
#endif // clang-format on
|
||||
}
|
||||
|
||||
@@ -353,6 +377,22 @@ ASM void J3DScaleNrmMtx33(__REGISTER Mtx33 mtx, const __REGISTER Vec& scale) {
|
||||
psq_st f4, 24(mtx), 0, 0
|
||||
stfs f5, 0x20(mtx)
|
||||
blr
|
||||
#else
|
||||
f32 sx = scale.x;
|
||||
f32 sy = scale.y;
|
||||
f32 sz = scale.z;
|
||||
|
||||
mtx[0][0] *= sx;
|
||||
mtx[0][1] *= sy;
|
||||
mtx[0][2] *= sz;
|
||||
|
||||
mtx[1][0] *= sx;
|
||||
mtx[1][1] *= sy;
|
||||
mtx[1][2] *= sz;
|
||||
|
||||
mtx[2][0] *= sx;
|
||||
mtx[2][1] *= sy;
|
||||
mtx[2][2] *= sz;
|
||||
#endif // clang-format on
|
||||
}
|
||||
|
||||
@@ -431,6 +471,22 @@ ASM void J3DMtxProjConcat(__REGISTER Mtx mtx1, __REGISTER Mtx mtx2, __REGISTER M
|
||||
ps_madd f0, f9, f13, f0
|
||||
psq_st f0, 40(dst), 0, 0
|
||||
blr
|
||||
#else
|
||||
Mtx tmp;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
f32 a0 = mtx1[i][0];
|
||||
f32 a1 = mtx1[i][1];
|
||||
f32 a2 = mtx1[i][2];
|
||||
f32 a3 = mtx1[i][3];
|
||||
|
||||
tmp[i][0] = a0 * mtx2[0][0] + a1 * mtx2[1][0] + a2 * mtx2[2][0] + a3 * mtx2[3][0];
|
||||
tmp[i][1] = a0 * mtx2[0][1] + a1 * mtx2[1][1] + a2 * mtx2[2][1] + a3 * mtx2[3][1];
|
||||
tmp[i][2] = a0 * mtx2[0][2] + a1 * mtx2[1][2] + a2 * mtx2[2][2] + a3 * mtx2[3][2];
|
||||
tmp[i][3] = a0 * mtx2[0][3] + a1 * mtx2[1][3] + a2 * mtx2[2][3] + a3 * mtx2[3][3];
|
||||
}
|
||||
|
||||
JMath::gekko_ps_copy12(dst, tmp);
|
||||
#endif // clang-format on
|
||||
}
|
||||
|
||||
@@ -543,6 +599,15 @@ loop:
|
||||
#undef FP31
|
||||
#undef UNIT_R
|
||||
}
|
||||
#else
|
||||
void J3DPSMtxArrayConcat(Mtx mA, Mtx mB, Mtx mAB, u32 count) {
|
||||
Mtx* src = (Mtx*)mB;
|
||||
Mtx* dst = (Mtx*)mAB;
|
||||
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
C_MTXConcat(mA, src[i], dst[i]);
|
||||
}
|
||||
}
|
||||
#endif // clang-format on
|
||||
|
||||
f32 const PSMulUnit01[] = {
|
||||
|
||||
@@ -37,6 +37,8 @@ void JMAQuatLerp(__REGISTER const Quaternion* p, __REGISTER const Quaternion* q,
|
||||
|
||||
ps_sum0 dp, dp, dp, dp
|
||||
}
|
||||
#else
|
||||
dp = p->x * q->x + p->y * q->y + p->z * q->z + p->w * q->w;
|
||||
#endif // clang-format on
|
||||
f32 local_78 = dp;
|
||||
if (local_78 < 0.0) {
|
||||
@@ -68,6 +70,12 @@ void JMAFastVECNormalize(__REGISTER const Vec* src, __REGISTER Vec* dst) {
|
||||
fmuls vz, vz, length
|
||||
stfs vz, dst->z
|
||||
}
|
||||
#else
|
||||
f32 mag = src->x * src->x + src->y * src->y + src->z * src->z;
|
||||
length = 1.0f / sqrtf(mag);
|
||||
dst->x = src->x * length;
|
||||
dst->y = src->y * length;
|
||||
dst->z = src->z * length;
|
||||
#endif // clang-format on
|
||||
}
|
||||
|
||||
@@ -88,6 +96,10 @@ void JMAVECScaleAdd(__REGISTER const Vec* vec1, __REGISTER const Vec* vec2, __RE
|
||||
ps_madds0 rz, v1z, scale, v2z
|
||||
psq_st rz, 8(dst), 1, 0
|
||||
}
|
||||
#else
|
||||
dst->x = vec1->x * scale + vec2->x;
|
||||
dst->y = vec1->y * scale + vec2->y;
|
||||
dst->z = vec1->z * scale + vec2->z;
|
||||
#endif // clang-format on
|
||||
}
|
||||
|
||||
@@ -122,5 +134,18 @@ void JMAMTXApplyScale(__REGISTER const Mtx src, __REGISTER Mtx dst, __REGISTER f
|
||||
psq_st y, 24(dst), 0, 0
|
||||
psq_st z, 40(dst), 0, 0
|
||||
}
|
||||
#else
|
||||
dst[0][0] = src[0][0] * xScale;
|
||||
dst[0][1] = src[0][1] * yScale;
|
||||
dst[0][2] = src[0][2] * zScale;
|
||||
dst[0][3] = src[0][3];
|
||||
dst[1][0] = src[1][0] * xScale;
|
||||
dst[1][1] = src[1][1] * yScale;
|
||||
dst[1][2] = src[1][2] * zScale;
|
||||
dst[1][3] = src[1][3];
|
||||
dst[2][0] = src[2][0] * xScale;
|
||||
dst[2][1] = src[2][1] * yScale;
|
||||
dst[2][2] = src[2][2] * zScale;
|
||||
dst[2][3] = src[2][3];
|
||||
#endif // clang-format on
|
||||
}
|
||||
|
||||
@@ -228,6 +228,8 @@ int dThunder_c::create() {
|
||||
#ifdef __MWERKS__
|
||||
f32 tmp = __frsqrtes(var_f29_2);
|
||||
var_f29_2 = tmp * var_f29_2;
|
||||
#else
|
||||
var_f29_2 = sqrtf(var_f29_2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include <dolphin/mtx.h>
|
||||
#include "JSystem/J3DGraphBase/J3DTransform.h"
|
||||
|
||||
// translated to C, should be correct, but not tested.
|
||||
|
||||
void J3DPSMtxArrayConcat(Mtx mA, Mtx mB, Mtx mAB, u32 count) {
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
const float* b = (const float*)mB[i];
|
||||
float* res = (float*)mAB[i];
|
||||
|
||||
for (int row = 0; row < 3; row++) {
|
||||
float a0 = mA[row][0];
|
||||
float a1 = mA[row][1];
|
||||
float a2 = mA[row][2];
|
||||
float a3 = mA[row][3];
|
||||
|
||||
// Standard Matrix Multiply for 3x4 * 3x4 (with implicit 4th row [0,0,0,1])
|
||||
res[row * 4 + 0] = a0 * b[0] + a1 * b[4] + a2 * b[8];
|
||||
res[row * 4 + 1] = a0 * b[1] + a1 * b[5] + a2 * b[9];
|
||||
res[row * 4 + 2] = a0 * b[2] + a1 * b[6] + a2 * b[10];
|
||||
// The 4th column includes the translation
|
||||
res[row * 4 + 3] = a0 * b[3] + a1 * b[7] + a2 * b[11] + a3;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user