From 3e0ffaa64d20e0700de0d3e0e2603e4e54eb52a8 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Mon, 29 Jun 2026 14:40:52 -0700 Subject: [PATCH] move mtx to c --- lib/NitroSDK/asm/fx_vec.s | 175 -------------------------- lib/NitroSDK/asm/mtx.s | 213 -------------------------------- lib/NitroSDK/src/fx/fx_mtx43.c | 36 ++++++ lib/NitroSDK/src/fx/fx_mtx44.c | 61 +++++++++ lib/NitroSDK/src/gx/g3_util.c | 35 ++++++ lib/include/nitro/fx/fx.h | 112 ++++++++--------- lib/include/nitro/fx/fx_cp.h | 14 +-- lib/include/nitro/fx/fx_mtx43.h | 99 +++++++++++++++ lib/include/nitro/fx/fx_mtx44.h | 119 ++++++++++++++++++ lib/include/nitro/gx/g3_util.h | 72 +++++++++++ main.lsf | 5 +- 11 files changed, 488 insertions(+), 453 deletions(-) delete mode 100644 lib/NitroSDK/asm/fx_vec.s delete mode 100644 lib/NitroSDK/asm/mtx.s create mode 100644 lib/NitroSDK/src/fx/fx_mtx43.c create mode 100644 lib/NitroSDK/src/fx/fx_mtx44.c create mode 100644 lib/NitroSDK/src/gx/g3_util.c create mode 100644 lib/include/nitro/fx/fx_mtx43.h create mode 100644 lib/include/nitro/fx/fx_mtx44.h create mode 100644 lib/include/nitro/gx/g3_util.h diff --git a/lib/NitroSDK/asm/fx_vec.s b/lib/NitroSDK/asm/fx_vec.s deleted file mode 100644 index 1ed88384..00000000 --- a/lib/NitroSDK/asm/fx_vec.s +++ /dev/null @@ -1,175 +0,0 @@ - .include "asm/macros.inc" - .include "include/fx_vec.inc" - - .text - - arm_func_start VEC_DotProduct -VEC_DotProduct: ; 0x02075C74 - stmdb sp!, {r4, lr} - ldr r3, [r0, #4] - ldr r2, [r1, #4] - ldr ip, [r0] - smull r4, lr, r3, r2 - ldr r2, [r1] - ldr r3, [r0, #8] - smlal r4, lr, ip, r2 - ldr r0, [r1, #8] - smlal r4, lr, r3, r0 - adds r0, r4, #0x800 - adc r1, lr, #0 - mov r0, r0, lsr #0xc - orr r0, r0, r1, lsl #20 - ldmia sp!, {r4, pc} - arm_func_end VEC_DotProduct - - arm_func_start VEC_CrossProduct -VEC_CrossProduct: ; 0x02075CB0 - stmdb sp!, {r4, r5, r6, r7, r8, lr} - ldmia r0, {r5, lr} - ldr r6, [r1, #8] - ldr r0, [r0, #8] - ldmia r1, {r4, ip} - smull r8, r7, lr, r6 - smull r3, r1, r0, ip - subs r3, r8, r3 - sbc r1, r7, r1 - adds r3, r3, #0x800 - smull r8, r7, r0, r4 - smull r6, r0, r5, r6 - adc r1, r1, #0 - subs r6, r8, r6 - mov r3, r3, lsr #0xc - orr r3, r3, r1, lsl #20 - sbc r7, r7, r0 - adds r0, r6, #0x800 - smull ip, r6, r5, ip - adc r5, r7, #0 - smull r4, r1, lr, r4 - mov r7, r0, lsr #0xc - subs r4, ip, r4 - sbc r0, r6, r1 - adds r1, r4, #0x800 - str r3, [r2] - orr r7, r7, r5, lsl #20 - adc r0, r0, #0 - mov r1, r1, lsr #0xc - str r7, [r2, #4] - orr r1, r1, r0, lsl #20 - str r1, [r2, #8] - ldmia sp!, {r4, r5, r6, r7, r8, pc} - arm_func_end VEC_CrossProduct - - arm_func_start VEC_Normalize -VEC_Normalize: ; 0x02075D34 - stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, lr} - ldr r2, [r0, #4] - ldr r3, [r0] - smull r6, r5, r2, r2 - smlal r6, r5, r3, r3 - ldr r2, [r0, #8] - ldr r4, _02075E40 ; =0x04000280 - smlal r6, r5, r2, r2 - mov r3, #2 - strh r3, [r4] - mov r3, #0 - str r3, [r4, #0x10] - mov r3, #0x1000000 - str r3, [r4, #0x14] - str r6, [r4, #0x18] - mov r2, r5, lsl #2 - str r5, [r4, #0x1c] - mov r3, #1 - strh r3, [r4, #0x30] - mov r3, r6, lsl #2 - str r3, [r4, #0x38] - orr r2, r2, r6, lsr #30 - str r2, [r4, #0x3c] -_02075D90: - ldrh r2, [r4, #0x30] - tst r2, #0x8000 - bne _02075D90 - ldr r2, _02075E44 ; =0x040002B4 - ldr ip, [r2] - sub r3, r2, #0x34 -_02075DA8: - ldrh r2, [r3] - tst r2, #0x8000 - bne _02075DA8 - ldr sb, _02075E48 ; =0x040002A0 - ldr r5, [r0] - ldr r8, [sb] - mov r7, ip, asr #0x1f - umull r3, r2, r8, ip - umull r6, lr, r3, r5 - mov r4, r5, asr #0x1f - mla r2, r8, r7, r2 - ldr r7, [sb, #4] - mla lr, r3, r4, lr - mla r2, r7, ip, r2 - mla lr, r2, r5, lr - adds r4, r6, #0 - adc r4, lr, #0x1000 - mov r4, r4, asr #0xd - str r4, [r1] - ldr ip, [r0, #4] - umull r5, lr, r3, ip - mov r4, ip, asr #0x1f - mla lr, r3, r4, lr - mla lr, r2, ip, lr - adds r4, r5, #0 - adc r4, lr, #0x1000 - mov r4, r4, asr #0xd - str r4, [r1, #4] - ldr ip, [r0, #8] - umull r4, lr, r3, ip - mov r0, ip, asr #0x1f - mla lr, r3, r0, lr - mla lr, r2, ip, lr - adds r0, r4, #0 - adc r0, lr, #0x1000 - mov r0, r0, asr #0xd - str r0, [r1, #8] - ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, pc} - .align 2, 0 -_02075E40: .word 0x04000280 -_02075E44: .word 0x040002B4 -_02075E48: .word 0x040002A0 - arm_func_end VEC_Normalize - - arm_func_start VEC_Distance -VEC_Distance: ; 0x02075E4C - stmdb sp!, {r4, lr} - ldr r3, [r0, #4] - ldr r2, [r1, #4] - ldr r4, [r0] - sub r2, r3, r2 - smull ip, r3, r2, r2 - ldr lr, [r1] - ldr r2, [r0, #8] - sub r4, r4, lr - ldr r0, [r1, #8] - smlal ip, r3, r4, r4 - sub r0, r2, r0 - smlal ip, r3, r0, r0 - mov r0, r3, lsl #2 - ldr r2, _02075EC0 ; =0x040002B0 - mov r1, #1 - strh r1, [r2] - mov r1, ip, lsl #2 - str r1, [r2, #8] - orr r0, r0, ip, lsr #30 - str r0, [r2, #0xc] -_02075EA0: - ldrh r0, [r2] - tst r0, #0x8000 - bne _02075EA0 - ldr r0, _02075EC4 ; =0x040002B4 - ldr r0, [r0] - add r0, r0, #1 - mov r0, r0, asr #1 - ldmia sp!, {r4, pc} - .align 2, 0 -_02075EC0: .word 0x040002B0 -_02075EC4: .word 0x040002B4 - arm_func_end VEC_Distance - diff --git a/lib/NitroSDK/asm/mtx.s b/lib/NitroSDK/asm/mtx.s deleted file mode 100644 index 1246aa96..00000000 --- a/lib/NitroSDK/asm/mtx.s +++ /dev/null @@ -1,213 +0,0 @@ - .include "asm/macros.inc" - .include "include/mtx.inc" - - .text - - arm_func_start MTX_LookAt -MTX_LookAt: ; 0x02075828 - stmdb sp!, {r3, r4, r5, r6, lr} - sub sp, sp, #0x24 - mov r6, r0 - ldr r5, [r6] - ldr r4, [r2] - add r0, sp, #0x18 - sub r4, r5, r4 - str r4, [sp, #0x18] - ldr ip, [r6, #4] - ldr r4, [r2, #4] - mov r5, r1 - sub r1, ip, r4 - str r1, [sp, #0x1c] - ldr r4, [r6, #8] - ldr r2, [r2, #8] - mov r1, r0 - sub r2, r4, r2 - mov r4, r3 - str r2, [sp, #0x20] - bl VEC_Normalize - add r1, sp, #0x18 - add r2, sp, #0xc - mov r0, r5 - bl VEC_CrossProduct - add r0, sp, #0xc - mov r1, r0 - bl VEC_Normalize - add r0, sp, #0x18 - add r1, sp, #0xc - add r2, sp, #0 - bl VEC_CrossProduct - ldr r1, [sp, #0xc] - mov r0, r6 - str r1, [r4] - ldr r2, [sp] - add r1, sp, #0xc - str r2, [r4, #4] - ldr r2, [sp, #0x18] - str r2, [r4, #8] - ldr r2, [sp, #0x10] - str r2, [r4, #0xc] - ldr r2, [sp, #4] - str r2, [r4, #0x10] - ldr r2, [sp, #0x1c] - str r2, [r4, #0x14] - ldr r2, [sp, #0x14] - str r2, [r4, #0x18] - ldr r2, [sp, #8] - str r2, [r4, #0x1c] - ldr r2, [sp, #0x20] - str r2, [r4, #0x20] - bl VEC_DotProduct - rsb r0, r0, #0 - str r0, [r4, #0x24] - mov r0, r6 - add r1, sp, #0 - bl VEC_DotProduct - rsb r0, r0, #0 - str r0, [r4, #0x28] - mov r0, r6 - add r1, sp, #0x18 - bl VEC_DotProduct - rsb r0, r0, #0 - str r0, [r4, #0x2c] - add sp, sp, #0x24 - ldmia sp!, {r3, r4, r5, r6, pc} - arm_func_end MTX_LookAt - - arm_func_start MTX_OrthoW -MTX_OrthoW: ; 0x02075930 - stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, sl, fp, lr} - sub sp, sp, #8 - str r2, [sp] - mov sl, r0 - ldr r0, [sp] - mov r2, r3 - sub r0, r2, r0 - ldr r8, [sp, #0x3c] - str r3, [sp, #4] - mov fp, r1 - ldr sb, [sp, #0x38] - bl FX_InvAsync - mov r0, #0 - str r0, [r8, #4] - str r0, [r8, #8] - str r0, [r8, #0xc] - str r0, [r8, #0x10] - str r0, [r8, #0x18] - str r0, [r8, #0x1c] - str r0, [r8, #0x20] - str r0, [r8, #0x24] - str r0, [r8, #0x2c] - str sb, [r8, #0x3c] - bl FX_GetDivResultFx64c - mov r6, r1 - mov r4, r0 - ldr r1, _02075B34 ; =0x04000290 - mov r3, #0 - mov r2, #0x1000 - str r3, [r1] - sub r0, sl, fp - str r2, [r1, #4] - str r0, [r1, #8] - mov r0, r3 - cmp sb, #0x1000 - str r0, [r1, #0xc] - beq _020759E0 - mov r5, sb, asr #0x1f - umull r0, r1, r4, sb - mla r1, r4, r5, r1 - mla r1, r6, sb, r1 - bl _ll_sdiv - mov r4, r0 - mov r6, r1 -_020759E0: - mov r1, r6, lsl #0xd - mov r0, #0x80000000 - orr r1, r1, r4, lsr #19 - adds r0, r0, r4, lsl #13 - adc r0, r1, #0 - str r0, [r8] - bl FX_GetDivResultFx64c - mov r5, r0 - mov r7, r1 - mov r3, #0 - ldr ip, _02075B34 ; =0x04000290 - ldr r1, [sp, #0x30] - ldr r0, [sp, #0x34] - str r3, [ip] - mov r2, #0x1000 - str r2, [ip, #4] - sub r0, r1, r0 - mov lr, r3 - str r0, [ip, #8] - cmp sb, #0x1000 - str lr, [ip, #0xc] - beq _02075A54 - mov ip, sb, asr #0x1f - umull r0, r1, r5, sb - mla r1, r5, ip, r1 - mla r1, r7, sb, r1 - bl _ll_sdiv - mov r5, r0 - mov r7, r1 -_02075A54: - mov r1, r7, lsl #0xd - mov r0, #0x80000000 - orr r1, r1, r5, lsr #19 - adds r0, r0, r5, lsl #13 - adc r0, r1, #0 - str r0, [r8, #0x14] - bl FX_GetDivResultFx64c - cmp sb, #0x1000 - beq _02075A9C - mov r2, sb, asr #0x1f - umull ip, r3, r0, sb - mla r3, r0, r2, r3 - mla r3, r1, sb, r3 - mov r0, ip - mov r1, r3 - mov r2, #0x1000 - mov r3, #0 - bl _ll_sdiv -_02075A9C: - ldr r3, [sp, #4] - ldr r2, [sp] - add r2, r3, r2 - rsb ip, r2, #0 - add r2, sl, fp - rsb r3, r2, #0 - ldr sl, [sp, #0x34] - ldr r2, [sp, #0x30] - mov sb, ip, asr #0x1f - add r2, sl, r2 - umull fp, sl, r4, ip - mla sl, r4, sb, sl - mov r4, #0x80000000 - mla sl, r6, ip, sl - adds r4, r4, r0, lsl #13 - mov sb, r1, lsl #0xd - mov r6, r3, asr #0x1f - umull ip, r4, r5, r3 - mla r4, r5, r6, r4 - orr sb, sb, r0, lsr #19 - mla r4, r7, r3, r4 - adc r3, sb, #0 - str r3, [r8, #0x28] - adds r3, fp, #0x80000000 - adc r7, sl, #0 - adds r3, ip, #0x80000000 - mov r3, r2, asr #0x1f - umull r6, r5, r0, r2 - mla r5, r0, r3, r5 - adc r3, r4, #0 - str r7, [r8, #0x30] - mla r5, r1, r2, r5 - adds r0, r6, #0x80000000 - str r3, [r8, #0x34] - adc r0, r5, #0 - str r0, [r8, #0x38] - add sp, sp, #8 - ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, sl, fp, pc} - .align 2, 0 -_02075B34: .word 0x04000290 - arm_func_end MTX_OrthoW - diff --git a/lib/NitroSDK/src/fx/fx_mtx43.c b/lib/NitroSDK/src/fx/fx_mtx43.c new file mode 100644 index 00000000..879ee1fb --- /dev/null +++ b/lib/NitroSDK/src/fx/fx_mtx43.c @@ -0,0 +1,36 @@ +#include +#include +#include + +void MTX_LookAt (const VecFx32 *camPos, const VecFx32 *camUp, const VecFx32 *target, MtxFx43 *mtx) +{ + VecFx32 vLook, vRight, vUp; + + SDK_NULL_ASSERT(camPos); + SDK_NULL_ASSERT(camUp); + SDK_NULL_ASSERT(target); + SDK_NULL_ASSERT(mtx); + + vLook.x = camPos->x - target->x; + vLook.y = camPos->y - target->y; + vLook.z = camPos->z - target->z; + + VEC_Normalize(&vLook, &vLook); + VEC_CrossProduct(camUp, &vLook, &vRight); + VEC_Normalize(&vRight, &vRight); + VEC_CrossProduct(&vLook, &vRight, &vUp); + + mtx->_00 = vRight.x; + mtx->_01 = vUp.x; + mtx->_02 = vLook.x; + mtx->_10 = vRight.y; + mtx->_11 = vUp.y; + mtx->_12 = vLook.y; + mtx->_20 = vRight.z; + mtx->_21 = vUp.z; + mtx->_22 = vLook.z; + mtx->_30 = -VEC_DotProduct(camPos, &vRight); + mtx->_31 = -VEC_DotProduct(camPos, &vUp); + mtx->_32 = -VEC_DotProduct(camPos, &vLook); +} + diff --git a/lib/NitroSDK/src/fx/fx_mtx44.c b/lib/NitroSDK/src/fx/fx_mtx44.c new file mode 100644 index 00000000..96758690 --- /dev/null +++ b/lib/NitroSDK/src/fx/fx_mtx44.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include + +#include + +void MTX_OrthoW (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 *mtx) +{ + fx64c inv1, inv2, inv3; + + SDK_NULL_ASSERT(mtx); + SDK_ASSERTMSG(t != b, "G3_Ortho: 't' and 'b' clipping planes are equal."); + SDK_ASSERTMSG(l != r, "G3_Ortho: 'l' and 'r' clipping planes are equal."); + SDK_ASSERTMSG(n != f, "G3_Ortho: 'n' and 'f' clipping planes are equal."); + + SDK_MINMAX_ASSERT(f, -0x10000 * FX32_ONE, 0x10000 * FX32_ONE - 1); + SDK_MINMAX_ASSERT(n, -0x10000 * FX32_ONE, 0x10000 * FX32_ONE - 1); + + { + FX_InvAsync(r - l); + mtx->_01 = 0; + mtx->_02 = 0; + mtx->_03 = 0; + mtx->_10 = 0; + mtx->_12 = 0; + mtx->_13 = 0; + mtx->_20 = 0; + mtx->_21 = 0; + mtx->_23 = 0; + mtx->_33 = scaleW; + inv1 = FX_GetInvResultFx64c(); + } + { + FX_InvAsyncImm(t - b); + if (scaleW != FX32_ONE) { + inv1 = (inv1 * scaleW) / FX32_ONE; + } + mtx->_00 = FX_Mul32x64c(FX32_ONE * 2, inv1); + inv2 = FX_GetInvResultFx64c(); + } + { + FX_InvAsyncImm(n - f); + if (scaleW != FX32_ONE) { + inv2 = (inv2 * scaleW) / FX32_ONE; + } + mtx->_11 = FX_Mul32x64c(FX32_ONE * 2, inv2); + inv3 = FX_GetInvResultFx64c(); + } + + if (scaleW != FX32_ONE) { + inv3 = (inv3 * scaleW) / FX32_ONE; + } + mtx->_22 = FX_Mul32x64c(FX32_ONE * 2, inv3); + mtx->_30 = FX_Mul32x64c(-r - l, inv1); + mtx->_31 = FX_Mul32x64c(-t - b, inv2); + mtx->_32 = FX_Mul32x64c(f + n, inv3); +} + +#include + diff --git a/lib/NitroSDK/src/gx/g3_util.c b/lib/NitroSDK/src/gx/g3_util.c new file mode 100644 index 00000000..dcc69c89 --- /dev/null +++ b/lib/NitroSDK/src/gx/g3_util.c @@ -0,0 +1,35 @@ +#include +#include + + +void G3i_OrthoW_ (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, BOOL draw, MtxFx44 *mtx) +{ + MtxFx44 tmp[1]; + + if (mtx == NULL) { + mtx = tmp; + } + + MTX_OrthoW(t, b, l, r, n, f, scaleW, mtx); + + if (draw) { + G3_MtxMode(GX_MTXMODE_PROJECTION); + G3_LoadMtx44(mtx); + } +} + +void G3i_LookAt_ (const VecFx32 *camPos, const VecFx32 *camUp, const VecFx32 *target, BOOL draw, MtxFx43 *mtx) +{ + MtxFx43 tmp[1]; + + if (mtx == NULL) { + mtx = tmp; + } + + MTX_LookAt(camPos, camUp, target, mtx); + + if (draw) { + G3_MtxMode(GX_MTXMODE_POSITION_VECTOR); + G3_LoadMtx43(mtx); + } +} diff --git a/lib/include/nitro/fx/fx.h b/lib/include/nitro/fx/fx.h index 5fe543f2..032cc3cc 100644 --- a/lib/include/nitro/fx/fx.h +++ b/lib/include/nitro/fx/fx.h @@ -185,62 +185,62 @@ typedef struct { void FX_Init(void); -// #if !(defined(SDK_WIN32) || defined(SDK_FROM_TOOL)) -// -// SDK_DECL_INLINE s32 FX_Whole(fx32 v); -// SDK_DECL_INLINE fx32 FX_Floor(fx32 v); -// -// fx32 FX_Modf(fx32 x, fx32 * iPtr); -// -// SDK_INLINE s32 FX_Whole (fx32 v) -// { -// return (s32)(v >> FX32_SHIFT); -// } -// -// SDK_INLINE fx32 FX_Floor (fx32 v) -// { -// return (fx32)(v & (FX32_INT_MASK | FX32_SIGN_MASK)); -// } -// -// SDK_INLINE fx32 FX32_CAST (s64 res) -// { -// SDK_WARNING(res >= FX32_MIN && res <= FX32_MAX, "FX_Mul: Overflow/Underflow"); -// return (fx32)res; -// } -// -// fx32 FX_MulFunc(fx32 v1, fx32 v2); -// SDK_DECL_INLINE fx32 FX_MulInline(fx32 v1, fx32 v2); -// -// SDK_INLINE fx32 FX_MulInline (fx32 v1, fx32 v2) -// { -// return FX32_CAST(((s64)(v1) * v2 + 0x800LL) >> FX32_SHIFT); -// } -// -// #ifndef FX_Mul -// #ifdef SDK_CODE_ARM -// #define FX_Mul(v1, v2) FX_MulInline(v1, v2) -// #else -// #define FX_Mul(v1, v2) FX_MulFunc(v1, v2) -// #endif -// #endif -// -// #ifndef FX_Mul32x64c -// #ifdef SDK_CODE_ARM -// #define FX_Mul32x64c(v32, v64c) FX_Mul32x64cInline(v32, v64c) -// #else -// #define FX_Mul32x64c(v32, v64c) FX_Mul32x64cFunc(v32, v64c) -// #endif -// #endif -// -// fx32 FX_Mul32x64cFunc(fx32 v32, fx64c v64c); -// SDK_DECL_INLINE fx32 FX_Mul32x64cInline(fx32 v32, fx64c v64c); -// -// SDK_INLINE fx32 FX_Mul32x64cInline (fx32 v32, fx64c v64c) -// { -// fx64c tmp = v64c * v32 + 0x80000000LL; -// return FX32_CAST(tmp >> FX64C_SHIFT); -// } -// #endif +#if !(defined(SDK_WIN32) || defined(SDK_FROM_TOOL)) + + SDK_DECL_INLINE s32 FX_Whole(fx32 v); + SDK_DECL_INLINE fx32 FX_Floor(fx32 v); + + fx32 FX_Modf(fx32 x, fx32 * iPtr); + + SDK_INLINE s32 FX_Whole (fx32 v) + { + return (s32)(v >> FX32_SHIFT); + } + + SDK_INLINE fx32 FX_Floor (fx32 v) + { + return (fx32)(v & (FX32_INT_MASK | FX32_SIGN_MASK)); + } + + SDK_INLINE fx32 FX32_CAST (s64 res) + { + SDK_WARNING(res >= FX32_MIN && res <= FX32_MAX, "FX_Mul: Overflow/Underflow"); + return (fx32)res; + } + + fx32 FX_MulFunc(fx32 v1, fx32 v2); + SDK_DECL_INLINE fx32 FX_MulInline(fx32 v1, fx32 v2); + + SDK_INLINE fx32 FX_MulInline (fx32 v1, fx32 v2) + { + return FX32_CAST(((s64)(v1) * v2 + 0x800LL) >> FX32_SHIFT); + } + + #ifndef FX_Mul + #ifdef SDK_CODE_ARM + #define FX_Mul(v1, v2) FX_MulInline(v1, v2) + #else + #define FX_Mul(v1, v2) FX_MulFunc(v1, v2) + #endif + #endif + + #ifndef FX_Mul32x64c + #ifdef SDK_CODE_ARM + #define FX_Mul32x64c(v32, v64c) FX_Mul32x64cInline(v32, v64c) + #else + #define FX_Mul32x64c(v32, v64c) FX_Mul32x64cFunc(v32, v64c) + #endif + #endif + + fx32 FX_Mul32x64cFunc(fx32 v32, fx64c v64c); + SDK_DECL_INLINE fx32 FX_Mul32x64cInline(fx32 v32, fx64c v64c); + + SDK_INLINE fx32 FX_Mul32x64cInline (fx32 v32, fx64c v64c) + { + fx64c tmp = v64c * v32 + 0x80000000LL; + return FX32_CAST(tmp >> FX64C_SHIFT); + } +#endif #ifdef __cplusplus } diff --git a/lib/include/nitro/fx/fx_cp.h b/lib/include/nitro/fx/fx_cp.h index a4515cd7..0ed5029f 100644 --- a/lib/include/nitro/fx/fx_cp.h +++ b/lib/include/nitro/fx/fx_cp.h @@ -40,13 +40,13 @@ s32 FX_ModS32(s32 a, s32 b); #define FX_DIVISION_BY_ZERO(a, b) \ SDK_WARNING(b != 0, "Division by zero(%d / %d)", a, b) -// SDK_INLINE void FX_InvAsyncImm (fx32 denom) -// { -// SDK_ASSERT(!CP_IsDivBusy()); -// FX_DIVISION_BY_ZERO(FX32_ONE, denom); -// -// CP_SetDivImm64_32((u64)FX32_ONE << 32, (u32)denom); -// } +SDK_INLINE void FX_InvAsyncImm (fx32 denom) +{ + SDK_ASSERT(!CP_IsDivBusy()); + FX_DIVISION_BY_ZERO(FX32_ONE, denom); + + CP_SetDivImm64_32((u64)FX32_ONE << 32, (u32)denom); +} SDK_INLINE fx64c FX_GetInvResultFx64c (void) { diff --git a/lib/include/nitro/fx/fx_mtx43.h b/lib/include/nitro/fx/fx_mtx43.h new file mode 100644 index 00000000..df012a4e --- /dev/null +++ b/lib/include/nitro/fx/fx_mtx43.h @@ -0,0 +1,99 @@ +#ifndef NITRO_FX_MTX43_H_ +#define NITRO_FX_MTX43_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +SDK_DECL_INLINE void MTX_Identity43(MtxFx43 * pDst); +SDK_DECL_INLINE void MTX_Copy43(const MtxFx43 * pSrc, MtxFx43 * pDst); +SDK_DECL_INLINE void MTX_Copy43To33(const MtxFx43 * pSrc, MtxFx33 * pDst); +SDK_DECL_INLINE void MTX_Copy43To44(const MtxFx43 * pSrc, MtxFx44 * pDst); +SDK_DECL_INLINE void MTX_Transpose43(const MtxFx43 * pSrc, MtxFx43 * pDst); +void MTX_TransApply43(const MtxFx43 * pSrc, MtxFx43 * pDst, fx32 x, fx32 y, fx32 z); +SDK_DECL_INLINE void MTX_Scale43(MtxFx43 * pDst, fx32 x, fx32 y, fx32 z); +void MTX_ScaleApply43(const MtxFx43 * pSrc, MtxFx43 * pDst, fx32 x, fx32 y, fx32 z); +SDK_DECL_INLINE void MTX_RotX43(MtxFx43 * pDst, fx32 sinVal, fx32 cosVal); +SDK_DECL_INLINE void MTX_RotY43(MtxFx43 * pDst, fx32 sinVal, fx32 cosVal); +SDK_DECL_INLINE void MTX_RotZ43(MtxFx43 * pDst, fx32 sinVal, fx32 cosVal); +void MTX_RotAxis43(MtxFx43 * pDst, const VecFx32 * vec, fx32 sinVal, fx32 cosVal); +int MTX_Inverse43(const MtxFx43 * pSrc, MtxFx43 * pDst); +void MTX_Concat43(const MtxFx43 * a, const MtxFx43 * b, MtxFx43 * ab); +void MTX_MultVec43(const VecFx32 * vec, const MtxFx43 * m, VecFx32 * dst); +void MTX_LookAt(const VecFx32 * camPos, const VecFx32 * camUp, const VecFx32 * target, MtxFx43 * mtx); + +void MTX_Identity43_(register MtxFx43 * pDst); +void MTX_Copy43To44_(register const MtxFx43 * pSrc, register MtxFx44 * pDst); +void MTX_Transpose43_(register const MtxFx43 * pSrc, register MtxFx43 * pDst); +void MTX_Scale43_(register MtxFx43 * pDst, register fx32 x, register fx32 y, register fx32 z); +void MTX_RotX43_(register MtxFx43 * pDst, register fx32 sinVal, register fx32 cosVal); +void MTX_RotY43_(register MtxFx43 * pDst, register fx32 sinVal, register fx32 cosVal); +void MTX_RotZ43_(register MtxFx43 * pDst, register fx32 sinVal, register fx32 cosVal); + +SDK_INLINE void MTX_Identity43 (MtxFx43 * pDst) +{ + SDK_NULL_ASSERT(pDst); + MTX_Identity43_(pDst); +} + +SDK_INLINE void MTX_Copy43 (const MtxFx43 * pSrc, MtxFx43 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + MI_Copy48B(pSrc, pDst); +} + +SDK_INLINE void MTX_Copy43To33 (const MtxFx43 * pSrc, MtxFx33 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + MI_Copy36B(pSrc, pDst); +} + +SDK_INLINE void MTX_Copy43To44 (const MtxFx43 * pSrc, MtxFx44 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + MTX_Copy43To44_(pSrc, pDst); +} + +SDK_INLINE void MTX_Transpose43 (const MtxFx43 * pSrc, MtxFx43 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + + MTX_Transpose43_(pSrc, pDst); +} + +SDK_INLINE void MTX_Scale43 (MtxFx43 * pDst, fx32 x, fx32 y, fx32 z) +{ + SDK_NULL_ASSERT(pDst); + MTX_Scale43_(pDst, x, y, z); +} + +SDK_INLINE void MTX_RotX43 (MtxFx43 * pDst, fx32 sinVal, fx32 cosVal) +{ + SDK_NULL_ASSERT(pDst); + MTX_RotX43_(pDst, sinVal, cosVal); +} + +SDK_INLINE void MTX_RotY43 (MtxFx43 * pDst, fx32 sinVal, fx32 cosVal) +{ + SDK_NULL_ASSERT(pDst); + MTX_RotY43_(pDst, sinVal, cosVal); +} + +SDK_INLINE void MTX_RotZ43 (MtxFx43 * pDst, fx32 sinVal, fx32 cosVal) +{ + SDK_NULL_ASSERT(pDst); + MTX_RotZ43_(pDst, sinVal, cosVal); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/nitro/fx/fx_mtx44.h b/lib/include/nitro/fx/fx_mtx44.h new file mode 100644 index 00000000..eb003b88 --- /dev/null +++ b/lib/include/nitro/fx/fx_mtx44.h @@ -0,0 +1,119 @@ +#ifndef NITRO_FX_MTX44_H_ +#define NITRO_FX_MTX44_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +SDK_DECL_INLINE void MTX_Identity44(MtxFx44 * pDst); +SDK_DECL_INLINE void MTX_Copy44To33(const MtxFx44 * pSrc, MtxFx33 * pDst); +SDK_DECL_INLINE void MTX_Copy44To43(const MtxFx44 * pSrc, MtxFx43 * pDst); +SDK_DECL_INLINE void MTX_Transpose44(const MtxFx44 * pSrc, MtxFx44 * pDst); +void MTX_TransApply44(const MtxFx44 * pSrc, MtxFx44 * pDst, fx32 x, fx32 y, fx32 z); +SDK_DECL_INLINE void MTX_Scale44(MtxFx44 * pDst, fx32 x, fx32 y, fx32 z); +void MTX_ScaleApply44(const MtxFx44 * pSrc, MtxFx44 * pDst, fx32 x, fx32 y, fx32 z); +SDK_DECL_INLINE void MTX_RotX44(MtxFx44 * pDst, fx32 sinVal, fx32 cosVal); +SDK_DECL_INLINE void MTX_RotY44(MtxFx44 * pDst, fx32 sinVal, fx32 cosVal); +SDK_DECL_INLINE void MTX_RotZ44(MtxFx44 * pDst, fx32 sinVal, fx32 cosVal); +void MTX_RotAxis44(MtxFx44 * pDst, const VecFx32 * vec, fx32 sinVal, fx32 cosVal); +void MTX_Concat44(const MtxFx44 * a, const MtxFx44 * b, MtxFx44 * ab); +void MTX_FrustumW(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx); +void MTX_PerspectiveW(fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx); +void MTX_OrthoW(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx); + +void MTX_Identity44_(register MtxFx44 * pDst); +void MTX_Copy44To33_(register const MtxFx44 * pSrc, register MtxFx33 * pDst); +void MTX_Copy44To43_(register const MtxFx44 * pSrc, register MtxFx43 * pDst); +void MTX_Transpose44_(register const MtxFx44 * pSrc, register MtxFx44 * pDst); +void MTX_Scale44_(register MtxFx44 * pDst, register fx32 x, register fx32 y, register fx32 z); +void MTX_RotX44_(register MtxFx44 * pDst, register fx32 sinVal, register fx32 cosVal); +void MTX_RotY44_(register MtxFx44 * pDst, register fx32 sinVal, register fx32 cosVal); +void MTX_RotZ44_(register MtxFx44 * pDst, register fx32 sinVal, register fx32 cosVal); + +SDK_INLINE void MTX_Identity44 (MtxFx44 * pDst) +{ + SDK_NULL_ASSERT(pDst); + MTX_Identity44_(pDst); +} + +SDK_INLINE void MTX_Copy44 (const MtxFx44 * pSrc, MtxFx44 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + + MI_Copy64B(pSrc, pDst); +} + +SDK_INLINE void MTX_Copy44To33 (const MtxFx44 * pSrc, MtxFx33 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + + MTX_Copy44To33_(pSrc, pDst); +} + +SDK_INLINE void MTX_Copy44To43 (const MtxFx44 * pSrc, MtxFx43 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + + MTX_Copy44To43_(pSrc, pDst); +} + +SDK_INLINE void MTX_Transpose44 (const MtxFx44 * pSrc, MtxFx44 * pDst) +{ + SDK_NULL_ASSERT(pSrc); + SDK_NULL_ASSERT(pDst); + + MTX_Transpose44_(pSrc, pDst); +} + +SDK_INLINE void MTX_Scale44 (MtxFx44 * pDst, fx32 x, fx32 y, fx32 z) +{ + SDK_NULL_ASSERT(pDst); + MTX_Scale44_(pDst, x, y, z); +} + +SDK_INLINE void MTX_RotX44 (MtxFx44 * pDst, fx32 sinVal, fx32 cosVal) +{ + SDK_NULL_ASSERT(pDst); + MTX_RotX44_(pDst, sinVal, cosVal); +} + +SDK_INLINE void MTX_RotY44 (MtxFx44 * pDst, fx32 sinVal, fx32 cosVal) +{ + SDK_NULL_ASSERT(pDst); + MTX_RotY44_(pDst, sinVal, cosVal); +} + +SDK_INLINE void MTX_RotZ44 (MtxFx44 * pDst, fx32 sinVal, fx32 cosVal) +{ + SDK_NULL_ASSERT(pDst); + MTX_RotZ44_(pDst, sinVal, cosVal); +} + +SDK_INLINE void MTX_Frustum (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx) +{ + MTX_FrustumW(t, b, l, r, n, f, FX32_ONE, mtx); +} + +SDK_INLINE +void MTX_Perspective (fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, MtxFx44 * mtx) +{ + MTX_PerspectiveW(fovySin, fovyCos, aspect, n, f, FX32_ONE, mtx); +} + +SDK_INLINE void MTX_Ortho (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx) +{ + MTX_OrthoW(t, b, l, r, n, f, FX32_ONE, mtx); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/nitro/gx/g3_util.h b/lib/include/nitro/gx/g3_util.h new file mode 100644 index 00000000..d6dc7c7d --- /dev/null +++ b/lib/include/nitro/gx/g3_util.h @@ -0,0 +1,72 @@ +#ifndef NITRO_G3_UTIL_H_ +#define NITRO_G3_UTIL_H_ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void G3i_FrustumW_(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, BOOL draw, MtxFx44 * mtx); +void G3i_PerspectiveW_(fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, fx32 scaleW, BOOL draw, MtxFx44 * mtx); +void G3i_OrthoW_(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, BOOL draw, MtxFx44 * mtx); +void G3i_LookAt_(const VecFx32 * camPos, const VecFx32 * camUp, const VecFx32 * target, BOOL draw, MtxFx43 * mtx); +void G3_RotX(fx32 s, fx32 c); +void G3_RotY(fx32 s, fx32 c); +void G3_RotZ(fx32 s, fx32 c); +void G3_LoadTexMtxTexCoord(const MtxFx44 * mtx); +void G3_LoadTexMtxEnv(const MtxFx44 * mtx); + +void G3BS_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx); +void G3CS_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx); +void G3B_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx); +void G3C_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx); +void G3BS_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx); +void G3B_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx); +void G3CS_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx); +void G3C_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx); + +static inline void G3_Frustum (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx) +{ + G3i_FrustumW_(t, b, l, r, n, f, FX32_ONE, TRUE, mtx); +} + +static inline void G3_Perspective (fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, MtxFx44 * mtx) +{ + G3i_PerspectiveW_(fovySin, fovyCos, aspect, n, f, FX32_ONE, TRUE, mtx); +} + +static inline void G3_Ortho (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx) +{ + G3i_OrthoW_(t, b, l, r, n, f, FX32_ONE, TRUE, mtx); +} + +static inline void G3_FrustumW (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx) +{ + G3i_FrustumW_(t, b, l, r, n, f, scaleW, TRUE, mtx); +} + +static inline void G3_PerspectiveW (fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx) +{ + G3i_PerspectiveW_(fovySin, fovyCos, aspect, n, f, scaleW, TRUE, mtx); +} + +static inline void G3_OrthoW (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx) +{ + G3i_OrthoW_(t, b, l, r, n, f, scaleW, TRUE, mtx); +} + +static inline void G3_LookAt (const VecFx32 * camPos, const VecFx32 * camUp, const VecFx32 * target, MtxFx43 * mtx) +{ + G3i_LookAt_(camPos, camUp, target, TRUE, mtx); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/main.lsf b/main.lsf index 83177414..ff4607a5 100644 --- a/main.lsf +++ b/main.lsf @@ -224,7 +224,8 @@ Static main Object asm/main_02075600.o ### NitroSDK ### - Object lib/NitroSDK/asm/mtx.o + Object lib/NitroSDK/src/fx/fx_mtx43.o + Object lib/NitroSDK/src/fx/fx_mtx44.o Object lib/NitroSDK/src/fx/fx_cp.o Object lib/NitroSDK/src/fx/fx_vec.o Object lib/NitroSDK/src/fx/fx_atanidx.o @@ -236,7 +237,7 @@ Static main Object lib/NitroSDK/src/gx/g2.o Object lib/NitroSDK/src/gx/g3imm.o Object lib/NitroSDK/asm/g3x.o - Object lib/NitroSDK/asm/g3_util.o + Object lib/NitroSDK/src/gx/g3_util.o Object lib/NitroSDK/asm/gx_load2d.o Object lib/NitroSDK/asm/gx_load3d.o Object lib/NitroSDK/src/gxasm.o