mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-30 15:43:19 -04:00
Add C versions of all ASM blocks (except THP)
This commit is contained in:
@@ -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