From 009d3fbcf7e1e3ea94656b5233e0bc96fa7b5a5b Mon Sep 17 00:00:00 2001 From: Made Date: Fri, 1 May 2020 18:59:48 +0200 Subject: decompile FX.s, FX_atan.s and partially decompile FX_ves.s --- arm9/lib/src/FX.c | 20 ++++++ arm9/lib/src/FX_atan.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++ arm9/lib/src/FX_vec_c.c | 34 ++++++++++ 3 files changed, 215 insertions(+) create mode 100644 arm9/lib/src/FX.c create mode 100644 arm9/lib/src/FX_atan.c create mode 100644 arm9/lib/src/FX_vec_c.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX.c b/arm9/lib/src/FX.c new file mode 100644 index 00000000..fa6fa6ba --- /dev/null +++ b/arm9/lib/src/FX.c @@ -0,0 +1,20 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +void FX_Init(){ + return; +} + +s32 FX_Modf(s32 x, s32 *iptr){ + if (x >= 0) + { + *iptr = x & 0x7FFFF000; + return x & 0xFFF; + } + else + { + *iptr = -(-x & 0x7FFFF000); + return -(-x & 0xFFF); + } +} diff --git a/arm9/lib/src/FX_atan.c b/arm9/lib/src/FX_atan.c new file mode 100644 index 00000000..684db81e --- /dev/null +++ b/arm9/lib/src/FX_atan.c @@ -0,0 +1,161 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +extern s16 FX_AtanTable_[]; + +u16 FX_Atan(s32 x){ + if (x >= 0) + { + if (x > 0x1000) + { + x = FX_Inv(x); + s16 y = FX_AtanTable_[x >> 5]; + return 0x4000 - y; + } + else if (x < 0x1000) + { + return FX_AtanTable_[x >> 5]; + } + else + { + return 0x2000; + } + } + else + { + if (x < -0x1000) + { + x = FX_Inv(-x); + s16 y = FX_AtanTable_[x >> 5]; + return y - 0x4000; + } + else if (x > -0x1000) + { + return -FX_AtanTable_[-x >> 5]; + } + else + { + return -0x2000; + } + } +} + +u16 FX_Atan2(s32 x, s32 y){ + s32 result; + u32 positive, bias, denominator, numerator; + if (x > 0) + { + if (y > 0) + { + if (y > x) + { + numerator = x; + denominator = y; + bias = 0; + positive = TRUE; + } + else if (y < x) + { + numerator = y; + denominator = x; + bias = 0x4000; + positive = FALSE; + } + else + { + return 0x2000; + } + } + else if (y < 0) + { + y = -y; + if (y < x) + { + numerator = y; + denominator = x; + bias = 0x4000; + positive = TRUE; + } + else if (y > x) + { + numerator = x; + denominator = y; + bias = 0x8000; + positive = FALSE; + } + else + { + return 0x6000; + } + } + else + { + return 0x4000; + } + } + else if (x < 0) + { + x = -x; + if (y < 0) + { + y = -y; + if (y > x) + { + numerator = x; + denominator = y; + bias = -0x8000; + positive = TRUE; + } + else if (y < x) + { + numerator = y; + denominator = x; + bias = -0x4000; + positive = FALSE; + } + else + { + return 0xA000; + } + } + else if (y > 0) + { + if (y < x) + { + numerator = y; + denominator = x; + bias = -0x4000; + positive = TRUE; + } + else if (y > x) + { + numerator = x; + denominator = y; + bias = 0x0; + positive = FALSE; + } + else + { + return 0xE000; + } + } + else + { + return 0xC000; + } + } + else + { + if (y >= 0) + return 0x0; + else + return 0x8000; + } + if (denominator == 0x0) + return 0x0; + if (positive) + return bias + FX_AtanTable_[FX_Div(numerator, denominator) >> 5]; + else + return bias - FX_AtanTable_[FX_Div(numerator, denominator) >> 5]; +} diff --git a/arm9/lib/src/FX_vec_c.c b/arm9/lib/src/FX_vec_c.c new file mode 100644 index 00000000..a2e0ffe4 --- /dev/null +++ b/arm9/lib/src/FX_vec_c.c @@ -0,0 +1,34 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +void VEC_Add(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *dst){ + dst->x = x->x + y->x; + dst->y = x->y + y->y; + dst->z = x->z + y->z; +} + +void VEC_Subtract(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *dst){ + dst->x = x->x - y->x; + dst->y = x->y - y->y; + dst->z = x->z - y->z; +} + +void VEC_Fx16Add(struct Vecx16 *x, struct Vecx16 *y, struct Vecx16 *dst){ + dst->x = x->x + y->x; + dst->y = x->y + y->y; + dst->z = x->z + y->z; +} + +s32 VEC_DotProduct(struct Vecx32 *x, struct Vecx32 *y){ + return ((s64)x->x * y->x + (s64)x->y * y->y + (s64)x->z * y->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; +} + +s32 VEC_Fx16DotProduct(struct Vecx16 *x, struct Vecx16 *y){ + s32 temp1, temp2; + temp1 = (x->x * y->x) + (x->y * y->y); + temp2 = (x->z * y->z) + (1 << (FX64_INT_SHIFT - 1)); + return (s32)(((s64)temp1 + temp2) >> FX64_INT_SHIFT); +} + +void VEC_CrossProduct(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *); -- cgit v1.2.3 From fefbe6b2dbc36e45fd521a75970fa58df5690615 Mon Sep 17 00:00:00 2001 From: Made Date: Fri, 1 May 2020 19:06:20 +0200 Subject: better vector names --- arm9/lib/src/FX_vec_c.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_vec_c.c b/arm9/lib/src/FX_vec_c.c index a2e0ffe4..bebf7ca0 100644 --- a/arm9/lib/src/FX_vec_c.c +++ b/arm9/lib/src/FX_vec_c.c @@ -2,33 +2,33 @@ #include "main.h" #include "fx.h" -void VEC_Add(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *dst){ - dst->x = x->x + y->x; - dst->y = x->y + y->y; - dst->z = x->z + y->z; +void VEC_Add(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ + dst->x = a->x + b->x; + dst->y = a->y + b->y; + dst->z = a->z + b->z; } -void VEC_Subtract(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *dst){ - dst->x = x->x - y->x; - dst->y = x->y - y->y; - dst->z = x->z - y->z; +void VEC_Subtract(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ + dst->x = a->x - b->x; + dst->y = a->y - b->y; + dst->z = a->z - b->z; } -void VEC_Fx16Add(struct Vecx16 *x, struct Vecx16 *y, struct Vecx16 *dst){ - dst->x = x->x + y->x; - dst->y = x->y + y->y; - dst->z = x->z + y->z; +void VEC_Fx16Add(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ + dst->x = a->x + b->x; + dst->y = a->y + b->y; + dst->z = a->z + b->z; } -s32 VEC_DotProduct(struct Vecx32 *x, struct Vecx32 *y){ - return ((s64)x->x * y->x + (s64)x->y * y->y + (s64)x->z * y->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; +s32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){ + return ((s64)a->x * b->x + (s64)a->y * b->y + (s64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; } -s32 VEC_Fx16DotProduct(struct Vecx16 *x, struct Vecx16 *y){ +s32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){ s32 temp1, temp2; - temp1 = (x->x * y->x) + (x->y * y->y); - temp2 = (x->z * y->z) + (1 << (FX64_INT_SHIFT - 1)); + temp1 = (a->x * b->x) + (a->y * b->y); + temp2 = (a->z * b->z) + (1 << (FX64_INT_SHIFT - 1)); return (s32)(((s64)temp1 + temp2) >> FX64_INT_SHIFT); } -void VEC_CrossProduct(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *); +void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst); -- cgit v1.2.3 From 3a51b862659071a4dab8296f1c9cfbe38d287887 Mon Sep 17 00:00:00 2001 From: Made Date: Fri, 1 May 2020 21:57:41 +0200 Subject: finish decompiling FX_vec.s --- arm9/lib/src/FX_vec.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++ arm9/lib/src/FX_vec_c.c | 34 ------------- 2 files changed, 125 insertions(+), 34 deletions(-) create mode 100644 arm9/lib/src/FX_vec.c delete mode 100644 arm9/lib/src/FX_vec_c.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_vec.c b/arm9/lib/src/FX_vec.c new file mode 100644 index 00000000..dc28bedf --- /dev/null +++ b/arm9/lib/src/FX_vec.c @@ -0,0 +1,125 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +void VEC_Add(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ + dst->x = a->x + b->x; + dst->y = a->y + b->y; + dst->z = a->z + b->z; +} + +void VEC_Subtract(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ + dst->x = a->x - b->x; + dst->y = a->y - b->y; + dst->z = a->z - b->z; +} + +void VEC_Fx16Add(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ + dst->x = a->x + b->x; + dst->y = a->y + b->y; + dst->z = a->z + b->z; +} + +s32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){ + return ((s64)a->x * b->x + (s64)a->y * b->y + (s64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; +} + +s32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){ + s32 temp1, temp2; + temp1 = (a->x * b->x) + (a->y * b->y); + temp2 = (a->z * b->z) + (1 << (FX64_INT_SHIFT - 1)); + return (s32)(((s64)temp1 + temp2) >> FX64_INT_SHIFT); +} + +void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ + s32 x, y, z; + x = (s32)(((s64)a->y * b->z - (s64)a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + y = (s32)(((s64)a->z * b->x - (s64)a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + z = (s32)(((s64)a->x * b->y - (s64)a->y * b->x + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + dst->x = x; + dst->y = y; + dst->z = z; +} + +void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ + s32 x, y, z; + x = ((a->y * b->z - a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + y = ((a->z * b->x - a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + z = ((a->x * b->y - a->y * b->x + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + dst->x = x; + dst->y = y; + dst->z = z; +} + +#define HW_REG_DIVCNT 0x04000280 +#define HW_REG_DIV_NUMER 0x04000290 +#define HW_REG_DIV_DENOM 0x04000298 +#define HW_REG_DIV_RESULT 0x040002A0 +#define HW_REG_DIVREM_RESULT 0x040002A8 + +#define HW_REG_SQRTCNT 0x040002B0 +#define HW_REG_SQRT_RESULT 0x040002B4 +#define HW_REG_SQRT_PARAM 0x040002B8 + +#define SETREG16(x, y) ((*(vu16 *)x) = y) +#define SETREG32(x, y) ((*(vu32 *)x) = y) +#define SETREG64(x, y) ((*(vu64 *)x) = y) +#define READREG16(x) (*(vu16 *)x) +#define READREG32(x) (*(vu32 *)x) +#define READREG64(x) (*(vu64 *)x) + +s32 VEC_Mag(struct Vecx32 *a){ + s64 l2 = (s64)a->x * a->x; + l2 += (s64)a->y * a->y; + l2 += (s64)a->z * a->z; + SETREG16(HW_REG_SQRTCNT, 0x1); + SETREG64(HW_REG_SQRT_PARAM, l2 * 4); + while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for coprocessor to finish + return ((s32)READREG32(HW_REG_SQRT_RESULT) + 1) >> 1; +} + +void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ + s64 l2 = (s64)a->x * a->x; + l2 += (s64)a->y * a->y; + l2 += (s64)a->z * a->z; + //1/sqrt(l) is computed by calculating sqrt(l)*(1/l) + SETREG16(HW_REG_DIVCNT, 0x2); + SETREG64(HW_REG_DIV_NUMER, 0x0100000000000000); + SETREG64(HW_REG_DIV_DENOM, l2); + SETREG16(HW_REG_SQRTCNT, 0x1); + SETREG64(HW_REG_SQRT_PARAM, l2 * 4); + while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for sqrt to finish + s32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); + while (READREG16(HW_REG_DIVCNT) & 0x8000); //wait for division to finish + l2 = READREG64(HW_REG_DIV_RESULT); + l2 = sqrtresult * l2; + dst->x = (l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D; + dst->y = (l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D; + dst->z = (l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D; +} + +void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ + s64 l2 = a->x * a->x; + l2 += a->y * a->y; + l2 += a->z * a->z; + //1/sqrt(l) is computed by calculating sqrt(l)*(1/l) + SETREG16(HW_REG_DIVCNT, 0x2); + SETREG64(HW_REG_DIV_NUMER, 0x0100000000000000); + SETREG64(HW_REG_DIV_DENOM, l2); + SETREG16(HW_REG_SQRTCNT, 0x1); + SETREG64(HW_REG_SQRT_PARAM, l2 * 4); + while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for sqrt to finish + s32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); + while (READREG16(HW_REG_DIVCNT) & 0x8000); //wait for division to finish + l2 = READREG64(HW_REG_DIV_RESULT); + l2 = sqrtresult * l2; + dst->x = (l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D; + dst->y = (l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D; + dst->z = (l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D; +} + +void VEC_MultAdd(s32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ + dst->x = (s32)(((s64)factor * a->x) >> FX32_INT_SHIFT) + b->x; + dst->y = (s32)(((s64)factor * a->y) >> FX32_INT_SHIFT) + b->y; + dst->z = (s32)(((s64)factor * a->z) >> FX32_INT_SHIFT) + b->z; +} diff --git a/arm9/lib/src/FX_vec_c.c b/arm9/lib/src/FX_vec_c.c deleted file mode 100644 index bebf7ca0..00000000 --- a/arm9/lib/src/FX_vec_c.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "global.h" -#include "main.h" -#include "fx.h" - -void VEC_Add(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ - dst->x = a->x + b->x; - dst->y = a->y + b->y; - dst->z = a->z + b->z; -} - -void VEC_Subtract(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ - dst->x = a->x - b->x; - dst->y = a->y - b->y; - dst->z = a->z - b->z; -} - -void VEC_Fx16Add(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ - dst->x = a->x + b->x; - dst->y = a->y + b->y; - dst->z = a->z + b->z; -} - -s32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){ - return ((s64)a->x * b->x + (s64)a->y * b->y + (s64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; -} - -s32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){ - s32 temp1, temp2; - temp1 = (a->x * b->x) + (a->y * b->y); - temp2 = (a->z * b->z) + (1 << (FX64_INT_SHIFT - 1)); - return (s32)(((s64)temp1 + temp2) >> FX64_INT_SHIFT); -} - -void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst); -- cgit v1.2.3 From dba3fd7f6eb8d0895bec720db75a6b37fc7259a0 Mon Sep 17 00:00:00 2001 From: Made Date: Sat, 2 May 2020 17:39:44 +0200 Subject: Decompile FX_cp.s --- arm9/lib/src/FX_cp.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ arm9/lib/src/FX_vec.c | 17 ------------ 2 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 arm9/lib/src/FX_cp.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_cp.c b/arm9/lib/src/FX_cp.c new file mode 100644 index 00000000..a8da0a8f --- /dev/null +++ b/arm9/lib/src/FX_cp.c @@ -0,0 +1,74 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +s32 FX_GetDivResult(); +s32 FX_GetSqrtResult(); +void FX_DivAsync(s32 numerator, s32 denominator); +void FX_InvAsync(s32 x); + +s32 FX_Div(s32 numerator, s32 denominator){ + FX_DivAsync(numerator, denominator); + return FX_GetDivResult(); +} + +s32 FX_Inv(s32 x){ + FX_InvAsync(x); + return FX_GetDivResult(); +} + +s32 FX_Sqrt(s32 x){ + if (x > 0) + { + SETREG16(HW_REG_SQRTCNT, 0x1); + SETREG64(HW_REG_SQRT_PARAM, (s64)x << 32); + return FX_GetSqrtResult(); + } + else + { + return 0; + } +} + +s64 FX_GetDivResultFx64c(){ + while (READREG16(HW_REG_DIVCNT) & 0x8000); + return READREG64(HW_REG_DIV_RESULT); +} + +s32 FX_GetDivResult(){ + while (READREG16(HW_REG_DIVCNT) & 0x8000); + return (READREG64(HW_REG_DIV_RESULT) + (1 << (0x14 - 1))) >> 0x14; +} + +void FX_InvAsync(s32 x){ + SETREG16(HW_REG_DIVCNT, 0x1); + SETREG64(HW_REG_DIV_NUMER, (s64)0x00001000 << 32); + SETREG64(HW_REG_DIV_DENOM, (u32)x); +} + +s32 FX_GetSqrtResult(){ + while (READREG16(HW_REG_SQRTCNT) & 0x8000); + return (READREG32(HW_REG_SQRT_RESULT) + (1 << (0xA - 1))) >> 0xA; +} + +void FX_DivAsync(s32 numerator, s32 denominator){ + SETREG16(HW_REG_DIVCNT, 0x1); + SETREG64(HW_REG_DIV_NUMER, (s64)numerator << 32); + SETREG64(HW_REG_DIV_DENOM, (u32)denominator); +} + + s32 FX_DivS32(s32 numerator, s32 denominator){ + SETREG16(HW_REG_DIVCNT, 0x0); + SETREG32(HW_REG_DIV_NUMER, (u32)numerator); //32bit write for some reason + SETREG64(HW_REG_DIV_DENOM, (u32)denominator); + while (READREG16(HW_REG_DIVCNT) & 0x8000); + return READREG32(HW_REG_DIV_RESULT); + } + + s32 FX_ModS32(s32 num, s32 mod){ + SETREG16(HW_REG_DIVCNT, 0x0); + SETREG32(HW_REG_DIV_NUMER, (u32)num); //32bit write for some reason + SETREG64(HW_REG_DIV_DENOM, (u32)mod); + while (READREG16(HW_REG_DIVCNT) & 0x8000); + return READREG32(HW_REG_DIVREM_RESULT); + } diff --git a/arm9/lib/src/FX_vec.c b/arm9/lib/src/FX_vec.c index dc28bedf..7b838829 100644 --- a/arm9/lib/src/FX_vec.c +++ b/arm9/lib/src/FX_vec.c @@ -51,23 +51,6 @@ void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst dst->z = z; } -#define HW_REG_DIVCNT 0x04000280 -#define HW_REG_DIV_NUMER 0x04000290 -#define HW_REG_DIV_DENOM 0x04000298 -#define HW_REG_DIV_RESULT 0x040002A0 -#define HW_REG_DIVREM_RESULT 0x040002A8 - -#define HW_REG_SQRTCNT 0x040002B0 -#define HW_REG_SQRT_RESULT 0x040002B4 -#define HW_REG_SQRT_PARAM 0x040002B8 - -#define SETREG16(x, y) ((*(vu16 *)x) = y) -#define SETREG32(x, y) ((*(vu32 *)x) = y) -#define SETREG64(x, y) ((*(vu64 *)x) = y) -#define READREG16(x) (*(vu16 *)x) -#define READREG32(x) (*(vu32 *)x) -#define READREG64(x) (*(vu64 *)x) - s32 VEC_Mag(struct Vecx32 *a){ s64 l2 = (s64)a->x * a->x; l2 += (s64)a->y * a->y; -- cgit v1.2.3 From 34dbccce4c71ba80c52cae8f1254c25d950f50c4 Mon Sep 17 00:00:00 2001 From: Made Date: Sun, 3 May 2020 14:49:24 +0200 Subject: decompile FX_mtx44 and update fx header --- arm9/lib/src/FX_cp.c | 34 +++++----- arm9/lib/src/FX_mtx44.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 19 deletions(-) create mode 100644 arm9/lib/src/FX_mtx44.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_cp.c b/arm9/lib/src/FX_cp.c index a8da0a8f..a2d8307b 100644 --- a/arm9/lib/src/FX_cp.c +++ b/arm9/lib/src/FX_cp.c @@ -1,11 +1,7 @@ #include "global.h" #include "main.h" #include "fx.h" - -s32 FX_GetDivResult(); -s32 FX_GetSqrtResult(); -void FX_DivAsync(s32 numerator, s32 denominator); -void FX_InvAsync(s32 x); + s32 FX_Div(s32 numerator, s32 denominator){ FX_DivAsync(numerator, denominator); @@ -57,18 +53,18 @@ void FX_DivAsync(s32 numerator, s32 denominator){ SETREG64(HW_REG_DIV_DENOM, (u32)denominator); } - s32 FX_DivS32(s32 numerator, s32 denominator){ - SETREG16(HW_REG_DIVCNT, 0x0); - SETREG32(HW_REG_DIV_NUMER, (u32)numerator); //32bit write for some reason - SETREG64(HW_REG_DIV_DENOM, (u32)denominator); - while (READREG16(HW_REG_DIVCNT) & 0x8000); - return READREG32(HW_REG_DIV_RESULT); - } +s32 FX_DivS32(s32 numerator, s32 denominator){ + SETREG16(HW_REG_DIVCNT, 0x0); + SETREG32(HW_REG_DIV_NUMER, (u32)numerator); //32bit write for some reason + SETREG64(HW_REG_DIV_DENOM, (u32)denominator); + while (READREG16(HW_REG_DIVCNT) & 0x8000); + return READREG32(HW_REG_DIV_RESULT); +} - s32 FX_ModS32(s32 num, s32 mod){ - SETREG16(HW_REG_DIVCNT, 0x0); - SETREG32(HW_REG_DIV_NUMER, (u32)num); //32bit write for some reason - SETREG64(HW_REG_DIV_DENOM, (u32)mod); - while (READREG16(HW_REG_DIVCNT) & 0x8000); - return READREG32(HW_REG_DIVREM_RESULT); - } +s32 FX_ModS32(s32 num, s32 mod){ + SETREG16(HW_REG_DIVCNT, 0x0); + SETREG32(HW_REG_DIV_NUMER, (u32)num); //32bit write for some reason + SETREG64(HW_REG_DIV_DENOM, (u32)mod); + while (READREG16(HW_REG_DIVCNT) & 0x8000); + return READREG32(HW_REG_DIVREM_RESULT); +} diff --git a/arm9/lib/src/FX_mtx44.c b/arm9/lib/src/FX_mtx44.c new file mode 100644 index 00000000..3c91b4df --- /dev/null +++ b/arm9/lib/src/FX_mtx44.c @@ -0,0 +1,172 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +void MI_Copy48B(void *src, void *dst); + + +void MTX_TransApply44(struct Mtx44 *mtx, struct Mtx44 *dst, s32 x, s32 y, s32 z){ + if(mtx != dst) + MI_Copy48B(mtx, dst); + dst->_[12] = mtx->_[12] + (s32)(((s64)x * mtx->_[0] + (s64)y * mtx->_[4] + (s64)z * mtx->_[8] ) >> FX32_INT_SHIFT); + dst->_[13] = mtx->_[13] + (s32)(((s64)x * mtx->_[1] + (s64)y * mtx->_[5] + (s64)z * mtx->_[9] ) >> FX32_INT_SHIFT); + dst->_[14] = mtx->_[14] + (s32)(((s64)x * mtx->_[2] + (s64)y * mtx->_[6] + (s64)z * mtx->_[10]) >> FX32_INT_SHIFT); + dst->_[15] = mtx->_[15] + (s32)(((s64)x * mtx->_[3] + (s64)y * mtx->_[7] + (s64)z * mtx->_[11]) >> FX32_INT_SHIFT); +} + +void MTX_Concat44(struct Mtx44 *a, struct Mtx44 *b, struct Mtx44 *c){ + struct Mtx44 temp; + struct Mtx44 *dst; + s32 a0, a1, a2, a3; + s32 b0, b1, b2, b3; + + if (c == b) + dst = &temp; + else + dst = c; + + a0 = a->_[0]; + a1 = a->_[1]; + a2 = a->_[2]; + a3 = a->_[3]; + dst->_[0] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[4] + (s64)a2 * b->_[8] + (s64)a3 * b->_[12]) >> FX32_INT_SHIFT); + dst->_[1] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[3] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + b0 = b->_[2]; + b1 = b->_[6]; + b2 = b->_[10]; + b3 = b->_[14]; + dst->_[2] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + a0 = a->_[4]; + a1 = a->_[5]; + a2 = a->_[6]; + a3 = a->_[7]; + dst->_[6] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[5] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[7] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + b0 = b->_[0]; + b1 = b->_[4]; + b2 = b->_[8]; + b3 = b->_[12]; + dst->_[4] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + a0 = a->_[8]; + a1 = a->_[9]; + a2 = a->_[10]; + a3 = a->_[11]; + dst->_[8] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[9] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[11] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + b0 = b->_[2]; + b1 = b->_[6]; + b2 = b->_[10]; + b3 = b->_[14]; + dst->_[10] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + a0 = a->_[12]; + a1 = a->_[13]; + a2 = a->_[14]; + a3 = a->_[15]; + dst->_[14] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[13] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[12] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[4] + (s64)a2 * b->_[8] + (s64)a3 * b->_[12]) >> FX32_INT_SHIFT); + dst->_[15] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + if (dst == &temp) + *c = temp; +} + +asm void MTX_Identity44_(struct Mtx44 *dst){ + mov r2, #0x1000 + mov r3, #0x0 + stmia r0!, {r2-r3} + mov r1, #0x0 + stmia r0!, {r1,r3} + stmia r0!, {r1-r3} + stmia r0!, {r1,r3} + stmia r0!, {r1-r3} + stmia r0!, {r1,r3} + stmia r0!, {r1-r2} + bx lr +} + +asm void MTX_Copy44To43_(struct Mtx44 *src, struct Mtx43 *dst){ + ldmia r0!, {r2-r3,r12} + add r0, r0, #0x4 + stmia r1!, {r2-r3,r12} + ldmia r0!, {r2-r3,r12} + add r0, r0, #0x4 + stmia r1!, {r2-r3,r12} + ldmia r0!, {r2-r3,r12} + add r0, r0, #0x4 + stmia r1!, {r2-r3,r12} + ldmia r0!, {r2-r3,r12} + add r0, r0, #0x4 + stmia r1!, {r2-r3,r12} + bx lr +} + +#pragma thumb on +asm void MTX_RotX44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ + str r2, [r0, #0x14] + str r2, [r0, #0x28] + str r1, [r0, #0x18] + neg r1, r1 + str r1, [r0, #0x24] + mov r1, #0x1 + mov r2, #0x0 + lsl r1, r1, #0xc + mov r3, #0x0 + stmia r0!, {r1-r3} + stmia r0!, {r2-r3} + add r0, #0x8 + stmia r0!, {r2-r3} + add r0, #0x8 + stmia r0!, {r2-r3} + stmia r0!, {r2-r3} + str r1, [r0, #0x0] + bx lr +} +#pragma thumb off + +#pragma thumb on +asm void MTX_RotY44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ + str r2, [r0, #0x0] + str r2, [r0, #0x28] + str r1, [r0, #0x20] + neg r1, r1 + str r1, [r0, #0x8] + mov r3, #0x1 + mov r1, #0x0 + lsl r3, r3, #0xc + mov r2, #0x0 + str r2, [r0, #0x4] + add r0, #0xc + stmia r0!, {r1-r3} + stmia r0!, {r1-r2} + str r2, [r0, #0x4] + add r0, #0xc + stmia r0!, {r1-r2} + stmia r0!, {r1-r3} + bx lr +} +#pragma thumb off + +#pragma thumb on +asm void MTX_RotZ44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ + str r2, [r0, #0x0] + str r2, [r0, #0x14] + str r1, [r0, #0x4] + neg r1, r1 + str r1, [r0, #0x10] + mov r3, #0x1 + mov r1, #0x0 + lsl r3, r3, #0xc + mov r2, #0x0 + add r0, #0x8 + stmia r0!, {r1-r2} + add r0, #0x8 + stmia r0!, {r1-r2} + stmia r0!, {r1-r3} + stmia r0!, {r1-r2} + stmia r0!, {r1-r3} + bx lr +} +#pragma thumb off -- cgit v1.2.3 From 8cd2ae6b66d4e2b2d5dbbf4e54f5a21cb21d7ebf Mon Sep 17 00:00:00 2001 From: Made Date: Mon, 4 May 2020 15:57:14 +0200 Subject: Decompile FX_mtx43.s --- arm9/lib/src/FX_mtx43.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 arm9/lib/src/FX_mtx43.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_mtx43.c b/arm9/lib/src/FX_mtx43.c new file mode 100644 index 00000000..c5d227b8 --- /dev/null +++ b/arm9/lib/src/FX_mtx43.c @@ -0,0 +1,207 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + + + + + +void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, s32 x, s32 y, s32 z){ + //this works because matrices are indexed columns first + MTX_ScaleApply33((struct Mtx33 *)mtx, (struct Mtx33 *)dst, x, y, z); + dst->_[9] = mtx->_[9]; + dst->_[10] = mtx->_[10]; + dst->_[11] = mtx->_[11]; +} + +s32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){ + struct Mtx43 tempmat; + struct Mtx43 *dst; + s32 det0, det1, det2, det; + s32 var0, var1, var2, var3; + if (mtx == inv) + dst = &tempmat; + else + dst = inv; + //subdeterminants + det0 = ((s64)mtx->_[4] * mtx->_[8] - (s64)mtx->_[5] * mtx->_[7] + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + det1 = ((s64)mtx->_[3] * mtx->_[8] - (s64)mtx->_[5] * mtx->_[6] + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + det2 = ((s64)mtx->_[3] * mtx->_[7] - (s64)mtx->_[4] * mtx->_[6] + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + //matrix determinant + det = ((s64)mtx->_[0] * det0 - (s64)mtx->_[1] * det1 + (s64)mtx->_[2] * det2 + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + + if (det == 0) + return -1; //not invertible + + FX_InvAsync(det); + + var0 = ((s64)mtx->_[1] * mtx->_[8] - (s64)mtx->_[7] * mtx->_[2]) >> FX32_INT_SHIFT; + var1 = ((s64)mtx->_[1] * mtx->_[5] - (s64)mtx->_[4] * mtx->_[2]) >> FX32_INT_SHIFT; + var2 = ((s64)mtx->_[0] * mtx->_[8] - (s64)mtx->_[6] * mtx->_[2]) >> FX32_INT_SHIFT; + var3 = ((s64)mtx->_[0] * mtx->_[5] - (s64)mtx->_[3] * mtx->_[2]) >> FX32_INT_SHIFT; + + s32 ret = FX_GetDivResult(); + dst->_[0] = (s32)(((s64)ret * det0) >> FX32_INT_SHIFT); + dst->_[1] = -(s32)(((s64)ret * var0) >> FX32_INT_SHIFT); + dst->_[2] = (s32)(((s64)ret * var1) >> FX32_INT_SHIFT); + dst->_[3] = -(s32)(((s64)ret * det1) >> FX32_INT_SHIFT); + dst->_[4] = (s32)(((s64)ret * var2) >> FX32_INT_SHIFT); + dst->_[5] = -(s32)(((s64)ret * var3) >> FX32_INT_SHIFT); + + dst->_[6] = (s32)(((s64)ret * det2) >> FX32_INT_SHIFT); + s32 temp = (s32)(((s64)mtx->_[0] * mtx->_[7] - (s64)mtx->_[6] * mtx->_[1]) >> FX32_INT_SHIFT); + dst->_[7] = -(s32)(((s64)ret * temp) >> FX32_INT_SHIFT); + s32 temp1 = (s32)(((s64)mtx->_[0] * mtx->_[4] - (s64)mtx->_[3] * mtx->_[1]) >> FX32_INT_SHIFT); + dst->_[8] = (s32)(((s64)ret * temp1) >> FX32_INT_SHIFT); + dst->_[9] = -(s32)(((s64)dst->_[0] * mtx->_[9] + (s64)dst->_[3] * mtx->_[10] + (s64)dst->_[6] * mtx->_[11]) >> FX32_INT_SHIFT); + dst->_[10] = -(s32)(((s64)dst->_[1] * mtx->_[9] + (s64)dst->_[4] * mtx->_[10] + (s64)dst->_[7] * mtx->_[11]) >> FX32_INT_SHIFT); + dst->_[11] = -(s32)(((s64)dst->_[2] * mtx->_[9] + (s64)dst->_[5] * mtx->_[10] + (s64)dst->_[8] * mtx->_[11]) >> FX32_INT_SHIFT); + + if (dst == &tempmat) + MI_Copy48B(&tempmat, inv); + return 0; +} + +void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c){ + struct Mtx43 temp; + struct Mtx43 *dst; + s32 a0, a1, a2; + s32 b0, b1, b2; + + if (c == b) + dst = &temp; + else + dst = c; + + a0 = a->_[0]; + a1 = a->_[1]; + a2 = a->_[2]; + dst->_[0] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[3] + (s64)a2 * b->_[6] ) >> FX32_INT_SHIFT); + dst->_[1] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + b0 = b->_[2]; + b1 = b->_[5]; + b2 = b->_[8]; + dst->_[2] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + a0 = a->_[3]; + a1 = a->_[4]; + a2 = a->_[5]; + dst->_[5] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[4] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + b0 = b->_[0]; + b1 = b->_[3]; + b2 = b->_[6]; + dst->_[3] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + a0 = a->_[6]; + a1 = a->_[7]; + a2 = a->_[8]; + dst->_[6] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[7] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + b0 = b->_[2]; + b1 = b->_[5]; + b2 = b->_[8]; + dst->_[8] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + a0 = a->_[9]; + a1 = a->_[10]; + a2 = a->_[11]; + dst->_[11] = ((((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT) + b->_[11]); + dst->_[10] = ((((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7]) >> FX32_INT_SHIFT) + b->_[10]); + dst->_[9] = ((((s64)a0 * b->_[0] + (s64)a1 * b->_[3] + (s64)a2 * b->_[6]) >> FX32_INT_SHIFT) + b->_[9]); + if (dst == &temp) + *c = temp; +} + +void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32 *dst){ + s32 x, y, z; + x = vec->x; + y = vec->y; + z = vec->z; + dst->x = ((s64)x * mtx->_[0] + (s64)y * mtx->_[3] + (s64)z * mtx->_[6]) >> FX32_INT_SHIFT; + dst->x += mtx->_[9]; + dst->y = ((s64)x * mtx->_[1] + (s64)y * mtx->_[4] + (s64)z * mtx->_[7]) >> FX32_INT_SHIFT; + dst->y += mtx->_[10]; + dst->z = ((s64)x * mtx->_[2] + (s64)y * mtx->_[5] + (s64)z * mtx->_[8]) >> FX32_INT_SHIFT; + dst->z += mtx->_[11]; +} + +asm void MTX_Identity43_(struct Mtx43 *mtx){ + mov r2, #0x1000 + mov r3, #0x0 + stmia r0!, {r2-r3} + mov r1, #0x0 + stmia r0!, {r1,r3} + stmia r0!, {r2-r3} + stmia r0!, {r1,r3} + stmia r0!, {r2-r3} + stmia r0!, {r1,r3} + bx lr +} + +asm void MTX_Copy43To44_(struct Mtx43 *src, struct Mtx44 *dst){ + stmdb sp!, {r4} + mov r12, #0x0 + ldmia r0!, {r2-r4} + stmia r1!, {r2-r4,r12} + ldmia r0!, {r2-r4} + stmia r1!, {r2-r4,r12} + ldmia r0!, {r2-r4} + stmia r1!, {r2-r4,r12} + mov r12, #0x1000 + ldmia r0!, {r2-r4} + stmia r1!, {r2-r4,r12} + ldmia sp!, {r4} + bx lr +} + +#pragma thumb on +asm void MTX_Scale43_(struct Mtx43 *dst, s32 x, s32 y, s32 z){ + stmia r0!, {r1} + mov r1, #0x0 + str r3, [r0, #0x1c] + mov r3, #0x0 + stmia r0!, {r1,r3} + stmia r0!, {r1-r3} + mov r2, #0x0 + stmia r0!, {r1,r3} + add r0, #0x4 + stmia r0!, {r1-r3} + bx lr +} +#pragma thumb off + +#pragma thumb on +asm void MTX_RotX43_(struct Mtx43 *mtx, s32 sinphi, s32 cosphi){ + str r1, [r0, #0x14] + neg r1, r1 + str r1, [r0, #0x1c] + mov r1, #0x1 + lsl r1, r1, #0xc + stmia r0!, {r1} + mov r3, #0x0 + mov r1, #0x0 + stmia r0!, {r1,r3} + stmia r0!, {r1-r2} + str r1, [r0, #0x4] + add r0, #0xc + stmia r0!, {r2-r3} + stmia r0!, {r1,r3} + bx lr +} +#pragma thumb off + +#pragma thumb on +asm void MTX_RotY43_(struct Mtx43 *mtx, s32 sinphi, s32 cosphi){ + str r1, [r0, #0x18] + mov r3, #0x0 + stmia r0!, {r2-r3} + neg r1, r1 + stmia r0!, {r1,r3} + mov r1, #0x1 + lsl r1, r1, #0xc + stmia r0!, {r1,r3} + add r0, #0x4 + mov r1, #0x0 + stmia r0!, {r1-r3} + stmia r0!, {r1,r3} + bx lr +} +#pragma thumb off -- cgit v1.2.3 From 8edaffd4aaddac79b3d15148783a74fa508c3edc Mon Sep 17 00:00:00 2001 From: Made Date: Mon, 4 May 2020 16:36:36 +0200 Subject: Decompile FX_mtx33.s --- arm9/lib/src/FX_mtx33.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ arm9/lib/src/FX_mtx43.c | 3 -- 2 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 arm9/lib/src/FX_mtx33.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_mtx33.c b/arm9/lib/src/FX_mtx33.c new file mode 100644 index 00000000..32b1ad2e --- /dev/null +++ b/arm9/lib/src/FX_mtx33.c @@ -0,0 +1,135 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, s32 x, s32 y, s32 z){ + dst->_[0] = ((s64)x * mtx->_[0]) >> FX32_INT_SHIFT; + dst->_[1] = ((s64)x * mtx->_[1]) >> FX32_INT_SHIFT; + dst->_[2] = ((s64)x * mtx->_[2]) >> FX32_INT_SHIFT; + dst->_[3] = ((s64)y * mtx->_[3]) >> FX32_INT_SHIFT; + dst->_[4] = ((s64)y * mtx->_[4]) >> FX32_INT_SHIFT; + dst->_[5] = ((s64)y * mtx->_[5]) >> FX32_INT_SHIFT; + dst->_[6] = ((s64)z * mtx->_[6]) >> FX32_INT_SHIFT; + dst->_[7] = ((s64)z * mtx->_[7]) >> FX32_INT_SHIFT; + dst->_[8] = ((s64)z * mtx->_[8]) >> FX32_INT_SHIFT; +} + +void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){ + struct Mtx33 temp; + struct Mtx33 *dst; + s32 a0, a1, a2; + s32 b0, b1, b2; + + if (c == b) + dst = &temp; + else + dst = c; + + a0 = a->_[0]; + a1 = a->_[1]; + a2 = a->_[2]; + dst->_[0] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[3] + (s64)a2 * b->_[6] ) >> FX32_INT_SHIFT); + dst->_[1] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + b0 = b->_[2]; + b1 = b->_[5]; + b2 = b->_[8]; + dst->_[2] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + a0 = a->_[3]; + a1 = a->_[4]; + a2 = a->_[5]; + dst->_[5] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[4] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + b0 = b->_[0]; + b1 = b->_[3]; + b2 = b->_[6]; + dst->_[3] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + a0 = a->_[6]; + a1 = a->_[7]; + a2 = a->_[8]; + dst->_[6] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[7] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + b0 = b->_[2]; + b1 = b->_[5]; + b2 = b->_[8]; + dst->_[8] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + + if (dst == &temp) + *c = temp; +} + +void MTX_MultVec33(struct Vecx32 *vec, struct Mtx33 *mtx, struct Vecx32 *dst){ + s32 x, y, z; + x = vec->x; + y = vec->y; + z = vec->z; + dst->x = ((s64)x * mtx->_[0] + (s64)y * mtx->_[3] + (s64)z * mtx->_[6]) >> FX32_INT_SHIFT; + dst->y = ((s64)x * mtx->_[1] + (s64)y * mtx->_[4] + (s64)z * mtx->_[7]) >> FX32_INT_SHIFT; + dst->z = ((s64)x * mtx->_[2] + (s64)y * mtx->_[5] + (s64)z * mtx->_[8]) >> FX32_INT_SHIFT; +} + +asm void MTX_Identity33_(struct Mtx33 *mtx){ + mov r2, #0x1000 + str r2, [r0, #0x20] + mov r3, #0x0 + stmia r0!, {r2-r3} + mov r1, #0x0 + stmia r0!, {r1,r3} + stmia r0!, {r2-r3} + stmia r0!, {r1,r3} + bx lr +} + +#pragma thumb on +asm void MTX_RotX33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ + mov r3, #0x1 + lsl r3, r3, #0xc + str r3, [r0, #0x0] + mov r3, #0x0 + str r3, [r0, #0x4] + str r3, [r0, #0x8] + str r3, [r0, #0xc] + str r2, [r0, #0x10] + str r1, [r0, #0x14] + str r3, [r0, #0x18] + neg r1, r1 + str r1, [r0, #0x1c] + str r2, [r0, #0x20] + bx lr +} +#pragma thumb off + +#pragma thumb on +asm void MTX_RotY33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ + str r2, [r0, #0x0] + str r2, [r0, #0x20] + mov r3, #0x0 + str r3, [r0, #0x4] + str r3, [r0, #0xc] + str r3, [r0, #0x14] + str r3, [r0, #0x1c] + neg r2, r1 + mov r3, #0x1 + lsl r3, r3, #0xc + str r1, [r0, #0x18] + str r2, [r0, #0x8] + str r3, [r0, #0x10] + bx lr +} +#pragma thumb off + +#pragma thumb on +asm void MTX_RotZ33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ + stmia r0!, {r2} + mov r3, #0x0 + stmia r0!, {r1,r3} + neg r1, r1 + stmia r0!, {r1-r2} + mov r1, #0x1 + lsl r1, r1, #0xc + str r3, [r0, #0x0] + str r3, [r0, #0x4] + str r3, [r0, #0x8] + str r1, [r0, #0xc] + bx lr +} +#pragma thumb off diff --git a/arm9/lib/src/FX_mtx43.c b/arm9/lib/src/FX_mtx43.c index c5d227b8..9cb8aa6e 100644 --- a/arm9/lib/src/FX_mtx43.c +++ b/arm9/lib/src/FX_mtx43.c @@ -3,9 +3,6 @@ #include "fx.h" - - - void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, s32 x, s32 y, s32 z){ //this works because matrices are indexed columns first MTX_ScaleApply33((struct Mtx33 *)mtx, (struct Mtx33 *)dst, x, y, z); -- cgit v1.2.3 From 246d8051ac7b7535c53d5d180eaf1d97451d31f2 Mon Sep 17 00:00:00 2001 From: Made Date: Mon, 4 May 2020 17:01:35 +0200 Subject: Decompile FX_mtx22.s --- arm9/lib/src/FX_mtx22.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 arm9/lib/src/FX_mtx22.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_mtx22.c b/arm9/lib/src/FX_mtx22.c new file mode 100644 index 00000000..fcd634b1 --- /dev/null +++ b/arm9/lib/src/FX_mtx22.c @@ -0,0 +1,30 @@ +#include "global.h" +#include "main.h" +#include "fx.h" + +void MTX_ScaleApply22(struct Mtx22 *mtx, struct Mtx22 *dst, s32 x, s32 y){ + dst->_[0] = ((s64)x * mtx->_[0]) >> FX32_INT_SHIFT; + dst->_[1] = ((s64)x * mtx->_[1]) >> FX32_INT_SHIFT; + dst->_[2] = ((s64)y * mtx->_[2]) >> FX32_INT_SHIFT; + dst->_[3] = ((s64)y * mtx->_[3]) >> FX32_INT_SHIFT; +} + +asm void MTX_Identity22_(struct Mtx22 *mtx){ + mov r1, #0x0 + mov r2, #0x1000 + mov r3, #0x0 + stmia r0!, {r2-r3} + stmia r0!, {r1-r2} + bx lr +} + +#pragma thumb on +asm void MTX_Rot22_(struct Mtx22 *mtx, s32 sinphi, s32 cosphi){ + str r2, [r0, #0x0] + str r1, [r0, #0x4] + neg r1, r1 + str r1, [r0, #0x8] + str r2, [r0, #0xc] + bx lr +} +#pragma thumb off -- cgit v1.2.3 From ab28b0b37f2fd9fba6010e48e15bd31170d678d7 Mon Sep 17 00:00:00 2001 From: Made Date: Mon, 4 May 2020 17:07:22 +0200 Subject: Add typedefs for fixed point types --- arm9/lib/src/FX.c | 2 +- arm9/lib/src/FX_atan.c | 12 +++--- arm9/lib/src/FX_cp.c | 28 +++++++------- arm9/lib/src/FX_mtx22.c | 12 +++--- arm9/lib/src/FX_mtx33.c | 56 +++++++++++++-------------- arm9/lib/src/FX_mtx43.c | 100 ++++++++++++++++++++++++------------------------ arm9/lib/src/FX_mtx44.c | 52 ++++++++++++------------- arm9/lib/src/FX_vec.c | 50 ++++++++++++------------ 8 files changed, 156 insertions(+), 156 deletions(-) (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX.c b/arm9/lib/src/FX.c index fa6fa6ba..f39b1995 100644 --- a/arm9/lib/src/FX.c +++ b/arm9/lib/src/FX.c @@ -6,7 +6,7 @@ void FX_Init(){ return; } -s32 FX_Modf(s32 x, s32 *iptr){ +fx32 FX_Modf(fx32 x, fx32 *iptr){ if (x >= 0) { *iptr = x & 0x7FFFF000; diff --git a/arm9/lib/src/FX_atan.c b/arm9/lib/src/FX_atan.c index 684db81e..085763f8 100644 --- a/arm9/lib/src/FX_atan.c +++ b/arm9/lib/src/FX_atan.c @@ -2,15 +2,15 @@ #include "main.h" #include "fx.h" -extern s16 FX_AtanTable_[]; +extern fx16 FX_AtanTable_[]; -u16 FX_Atan(s32 x){ +u16 FX_Atan(fx32 x){ if (x >= 0) { if (x > 0x1000) { x = FX_Inv(x); - s16 y = FX_AtanTable_[x >> 5]; + fx16 y = FX_AtanTable_[x >> 5]; return 0x4000 - y; } else if (x < 0x1000) @@ -27,7 +27,7 @@ u16 FX_Atan(s32 x){ if (x < -0x1000) { x = FX_Inv(-x); - s16 y = FX_AtanTable_[x >> 5]; + fx16 y = FX_AtanTable_[x >> 5]; return y - 0x4000; } else if (x > -0x1000) @@ -41,8 +41,8 @@ u16 FX_Atan(s32 x){ } } -u16 FX_Atan2(s32 x, s32 y){ - s32 result; +u16 FX_Atan2(fx32 x, fx32 y){ + fx32 result; u32 positive, bias, denominator, numerator; if (x > 0) { diff --git a/arm9/lib/src/FX_cp.c b/arm9/lib/src/FX_cp.c index a2d8307b..76dea4b4 100644 --- a/arm9/lib/src/FX_cp.c +++ b/arm9/lib/src/FX_cp.c @@ -1,23 +1,23 @@ #include "global.h" #include "main.h" #include "fx.h" - -s32 FX_Div(s32 numerator, s32 denominator){ + +fx32 FX_Div(fx32 numerator, fx32 denominator){ FX_DivAsync(numerator, denominator); return FX_GetDivResult(); } -s32 FX_Inv(s32 x){ +fx32 FX_Inv(fx32 x){ FX_InvAsync(x); return FX_GetDivResult(); } -s32 FX_Sqrt(s32 x){ +fx32 FX_Sqrt(fx32 x){ if (x > 0) { SETREG16(HW_REG_SQRTCNT, 0x1); - SETREG64(HW_REG_SQRT_PARAM, (s64)x << 32); + SETREG64(HW_REG_SQRT_PARAM, (fx64)x << 32); return FX_GetSqrtResult(); } else @@ -26,34 +26,34 @@ s32 FX_Sqrt(s32 x){ } } -s64 FX_GetDivResultFx64c(){ +fx64c FX_GetDivResultFx64c(){ while (READREG16(HW_REG_DIVCNT) & 0x8000); return READREG64(HW_REG_DIV_RESULT); } -s32 FX_GetDivResult(){ +fx32 FX_GetDivResult(){ while (READREG16(HW_REG_DIVCNT) & 0x8000); return (READREG64(HW_REG_DIV_RESULT) + (1 << (0x14 - 1))) >> 0x14; } -void FX_InvAsync(s32 x){ +void FX_InvAsync(fx32 x){ SETREG16(HW_REG_DIVCNT, 0x1); - SETREG64(HW_REG_DIV_NUMER, (s64)0x00001000 << 32); + SETREG64(HW_REG_DIV_NUMER, (fx64)0x00001000 << 32); SETREG64(HW_REG_DIV_DENOM, (u32)x); } -s32 FX_GetSqrtResult(){ +fx32 FX_GetSqrtResult(){ while (READREG16(HW_REG_SQRTCNT) & 0x8000); return (READREG32(HW_REG_SQRT_RESULT) + (1 << (0xA - 1))) >> 0xA; } -void FX_DivAsync(s32 numerator, s32 denominator){ +void FX_DivAsync(fx32 numerator, fx32 denominator){ SETREG16(HW_REG_DIVCNT, 0x1); - SETREG64(HW_REG_DIV_NUMER, (s64)numerator << 32); + SETREG64(HW_REG_DIV_NUMER, (fx64)numerator << 32); SETREG64(HW_REG_DIV_DENOM, (u32)denominator); } -s32 FX_DivS32(s32 numerator, s32 denominator){ +fx32 FX_Divfx32(fx32 numerator, fx32 denominator){ SETREG16(HW_REG_DIVCNT, 0x0); SETREG32(HW_REG_DIV_NUMER, (u32)numerator); //32bit write for some reason SETREG64(HW_REG_DIV_DENOM, (u32)denominator); @@ -61,7 +61,7 @@ s32 FX_DivS32(s32 numerator, s32 denominator){ return READREG32(HW_REG_DIV_RESULT); } -s32 FX_ModS32(s32 num, s32 mod){ +fx32 FX_Modfx32(fx32 num, fx32 mod){ SETREG16(HW_REG_DIVCNT, 0x0); SETREG32(HW_REG_DIV_NUMER, (u32)num); //32bit write for some reason SETREG64(HW_REG_DIV_DENOM, (u32)mod); diff --git a/arm9/lib/src/FX_mtx22.c b/arm9/lib/src/FX_mtx22.c index fcd634b1..19504574 100644 --- a/arm9/lib/src/FX_mtx22.c +++ b/arm9/lib/src/FX_mtx22.c @@ -2,11 +2,11 @@ #include "main.h" #include "fx.h" -void MTX_ScaleApply22(struct Mtx22 *mtx, struct Mtx22 *dst, s32 x, s32 y){ - dst->_[0] = ((s64)x * mtx->_[0]) >> FX32_INT_SHIFT; - dst->_[1] = ((s64)x * mtx->_[1]) >> FX32_INT_SHIFT; - dst->_[2] = ((s64)y * mtx->_[2]) >> FX32_INT_SHIFT; - dst->_[3] = ((s64)y * mtx->_[3]) >> FX32_INT_SHIFT; +void MTX_ScaleApply22(struct Mtx22 *mtx, struct Mtx22 *dst, fx32 x, fx32 y){ + dst->_[0] = ((fx64)x * mtx->_[0]) >> FX32_INT_SHIFT; + dst->_[1] = ((fx64)x * mtx->_[1]) >> FX32_INT_SHIFT; + dst->_[2] = ((fx64)y * mtx->_[2]) >> FX32_INT_SHIFT; + dst->_[3] = ((fx64)y * mtx->_[3]) >> FX32_INT_SHIFT; } asm void MTX_Identity22_(struct Mtx22 *mtx){ @@ -19,7 +19,7 @@ asm void MTX_Identity22_(struct Mtx22 *mtx){ } #pragma thumb on -asm void MTX_Rot22_(struct Mtx22 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_Rot22_(struct Mtx22 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r1, [r0, #0x4] neg r1, r1 diff --git a/arm9/lib/src/FX_mtx33.c b/arm9/lib/src/FX_mtx33.c index 32b1ad2e..391a6104 100644 --- a/arm9/lib/src/FX_mtx33.c +++ b/arm9/lib/src/FX_mtx33.c @@ -2,23 +2,23 @@ #include "main.h" #include "fx.h" -void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, s32 x, s32 y, s32 z){ - dst->_[0] = ((s64)x * mtx->_[0]) >> FX32_INT_SHIFT; - dst->_[1] = ((s64)x * mtx->_[1]) >> FX32_INT_SHIFT; - dst->_[2] = ((s64)x * mtx->_[2]) >> FX32_INT_SHIFT; - dst->_[3] = ((s64)y * mtx->_[3]) >> FX32_INT_SHIFT; - dst->_[4] = ((s64)y * mtx->_[4]) >> FX32_INT_SHIFT; - dst->_[5] = ((s64)y * mtx->_[5]) >> FX32_INT_SHIFT; - dst->_[6] = ((s64)z * mtx->_[6]) >> FX32_INT_SHIFT; - dst->_[7] = ((s64)z * mtx->_[7]) >> FX32_INT_SHIFT; - dst->_[8] = ((s64)z * mtx->_[8]) >> FX32_INT_SHIFT; +void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 z){ + dst->_[0] = ((fx64)x * mtx->_[0]) >> FX32_INT_SHIFT; + dst->_[1] = ((fx64)x * mtx->_[1]) >> FX32_INT_SHIFT; + dst->_[2] = ((fx64)x * mtx->_[2]) >> FX32_INT_SHIFT; + dst->_[3] = ((fx64)y * mtx->_[3]) >> FX32_INT_SHIFT; + dst->_[4] = ((fx64)y * mtx->_[4]) >> FX32_INT_SHIFT; + dst->_[5] = ((fx64)y * mtx->_[5]) >> FX32_INT_SHIFT; + dst->_[6] = ((fx64)z * mtx->_[6]) >> FX32_INT_SHIFT; + dst->_[7] = ((fx64)z * mtx->_[7]) >> FX32_INT_SHIFT; + dst->_[8] = ((fx64)z * mtx->_[8]) >> FX32_INT_SHIFT; } void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){ struct Mtx33 temp; struct Mtx33 *dst; - s32 a0, a1, a2; - s32 b0, b1, b2; + fx32 a0, a1, a2; + fx32 b0, b1, b2; if (c == b) dst = &temp; @@ -28,43 +28,43 @@ void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){ a0 = a->_[0]; a1 = a->_[1]; a2 = a->_[2]; - dst->_[0] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[3] + (s64)a2 * b->_[6] ) >> FX32_INT_SHIFT); - dst->_[1] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + dst->_[0] = (((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6] ) >> FX32_INT_SHIFT); + dst->_[1] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT); b0 = b->_[2]; b1 = b->_[5]; b2 = b->_[8]; - dst->_[2] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[2] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); a0 = a->_[3]; a1 = a->_[4]; a2 = a->_[5]; - dst->_[5] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); - dst->_[4] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + dst->_[5] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[4] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT); b0 = b->_[0]; b1 = b->_[3]; b2 = b->_[6]; - dst->_[3] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[3] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); a0 = a->_[6]; a1 = a->_[7]; a2 = a->_[8]; - dst->_[6] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); - dst->_[7] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + dst->_[6] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[7] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT); b0 = b->_[2]; b1 = b->_[5]; b2 = b->_[8]; - dst->_[8] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[8] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); if (dst == &temp) *c = temp; } void MTX_MultVec33(struct Vecx32 *vec, struct Mtx33 *mtx, struct Vecx32 *dst){ - s32 x, y, z; + fx32 x, y, z; x = vec->x; y = vec->y; z = vec->z; - dst->x = ((s64)x * mtx->_[0] + (s64)y * mtx->_[3] + (s64)z * mtx->_[6]) >> FX32_INT_SHIFT; - dst->y = ((s64)x * mtx->_[1] + (s64)y * mtx->_[4] + (s64)z * mtx->_[7]) >> FX32_INT_SHIFT; - dst->z = ((s64)x * mtx->_[2] + (s64)y * mtx->_[5] + (s64)z * mtx->_[8]) >> FX32_INT_SHIFT; + dst->x = ((fx64)x * mtx->_[0] + (fx64)y * mtx->_[3] + (fx64)z * mtx->_[6]) >> FX32_INT_SHIFT; + dst->y = ((fx64)x * mtx->_[1] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[7]) >> FX32_INT_SHIFT; + dst->z = ((fx64)x * mtx->_[2] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[8]) >> FX32_INT_SHIFT; } asm void MTX_Identity33_(struct Mtx33 *mtx){ @@ -80,7 +80,7 @@ asm void MTX_Identity33_(struct Mtx33 *mtx){ } #pragma thumb on -asm void MTX_RotX33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotX33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ mov r3, #0x1 lsl r3, r3, #0xc str r3, [r0, #0x0] @@ -99,7 +99,7 @@ asm void MTX_RotX33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ #pragma thumb off #pragma thumb on -asm void MTX_RotY33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotY33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r2, [r0, #0x20] mov r3, #0x0 @@ -118,7 +118,7 @@ asm void MTX_RotY33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ #pragma thumb off #pragma thumb on -asm void MTX_RotZ33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotZ33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ stmia r0!, {r2} mov r3, #0x0 stmia r0!, {r1,r3} diff --git a/arm9/lib/src/FX_mtx43.c b/arm9/lib/src/FX_mtx43.c index 9cb8aa6e..862bd6f2 100644 --- a/arm9/lib/src/FX_mtx43.c +++ b/arm9/lib/src/FX_mtx43.c @@ -3,7 +3,7 @@ #include "fx.h" -void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, s32 x, s32 y, s32 z){ +void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){ //this works because matrices are indexed columns first MTX_ScaleApply33((struct Mtx33 *)mtx, (struct Mtx33 *)dst, x, y, z); dst->_[9] = mtx->_[9]; @@ -11,48 +11,48 @@ void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, s32 x, s32 y, s32 z) dst->_[11] = mtx->_[11]; } -s32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){ +fx32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){ struct Mtx43 tempmat; struct Mtx43 *dst; - s32 det0, det1, det2, det; - s32 var0, var1, var2, var3; + fx32 det0, det1, det2, det; + fx32 var0, var1, var2, var3; if (mtx == inv) dst = &tempmat; else dst = inv; //subdeterminants - det0 = ((s64)mtx->_[4] * mtx->_[8] - (s64)mtx->_[5] * mtx->_[7] + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; - det1 = ((s64)mtx->_[3] * mtx->_[8] - (s64)mtx->_[5] * mtx->_[6] + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; - det2 = ((s64)mtx->_[3] * mtx->_[7] - (s64)mtx->_[4] * mtx->_[6] + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + det0 = ((fx64)mtx->_[4] * mtx->_[8] - (fx64)mtx->_[5] * mtx->_[7] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + det1 = ((fx64)mtx->_[3] * mtx->_[8] - (fx64)mtx->_[5] * mtx->_[6] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + det2 = ((fx64)mtx->_[3] * mtx->_[7] - (fx64)mtx->_[4] * mtx->_[6] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; //matrix determinant - det = ((s64)mtx->_[0] * det0 - (s64)mtx->_[1] * det1 + (s64)mtx->_[2] * det2 + (s64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; + det = ((fx64)mtx->_[0] * det0 - (fx64)mtx->_[1] * det1 + (fx64)mtx->_[2] * det2 + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT; if (det == 0) return -1; //not invertible FX_InvAsync(det); - var0 = ((s64)mtx->_[1] * mtx->_[8] - (s64)mtx->_[7] * mtx->_[2]) >> FX32_INT_SHIFT; - var1 = ((s64)mtx->_[1] * mtx->_[5] - (s64)mtx->_[4] * mtx->_[2]) >> FX32_INT_SHIFT; - var2 = ((s64)mtx->_[0] * mtx->_[8] - (s64)mtx->_[6] * mtx->_[2]) >> FX32_INT_SHIFT; - var3 = ((s64)mtx->_[0] * mtx->_[5] - (s64)mtx->_[3] * mtx->_[2]) >> FX32_INT_SHIFT; - - s32 ret = FX_GetDivResult(); - dst->_[0] = (s32)(((s64)ret * det0) >> FX32_INT_SHIFT); - dst->_[1] = -(s32)(((s64)ret * var0) >> FX32_INT_SHIFT); - dst->_[2] = (s32)(((s64)ret * var1) >> FX32_INT_SHIFT); - dst->_[3] = -(s32)(((s64)ret * det1) >> FX32_INT_SHIFT); - dst->_[4] = (s32)(((s64)ret * var2) >> FX32_INT_SHIFT); - dst->_[5] = -(s32)(((s64)ret * var3) >> FX32_INT_SHIFT); - - dst->_[6] = (s32)(((s64)ret * det2) >> FX32_INT_SHIFT); - s32 temp = (s32)(((s64)mtx->_[0] * mtx->_[7] - (s64)mtx->_[6] * mtx->_[1]) >> FX32_INT_SHIFT); - dst->_[7] = -(s32)(((s64)ret * temp) >> FX32_INT_SHIFT); - s32 temp1 = (s32)(((s64)mtx->_[0] * mtx->_[4] - (s64)mtx->_[3] * mtx->_[1]) >> FX32_INT_SHIFT); - dst->_[8] = (s32)(((s64)ret * temp1) >> FX32_INT_SHIFT); - dst->_[9] = -(s32)(((s64)dst->_[0] * mtx->_[9] + (s64)dst->_[3] * mtx->_[10] + (s64)dst->_[6] * mtx->_[11]) >> FX32_INT_SHIFT); - dst->_[10] = -(s32)(((s64)dst->_[1] * mtx->_[9] + (s64)dst->_[4] * mtx->_[10] + (s64)dst->_[7] * mtx->_[11]) >> FX32_INT_SHIFT); - dst->_[11] = -(s32)(((s64)dst->_[2] * mtx->_[9] + (s64)dst->_[5] * mtx->_[10] + (s64)dst->_[8] * mtx->_[11]) >> FX32_INT_SHIFT); + var0 = ((fx64)mtx->_[1] * mtx->_[8] - (fx64)mtx->_[7] * mtx->_[2]) >> FX32_INT_SHIFT; + var1 = ((fx64)mtx->_[1] * mtx->_[5] - (fx64)mtx->_[4] * mtx->_[2]) >> FX32_INT_SHIFT; + var2 = ((fx64)mtx->_[0] * mtx->_[8] - (fx64)mtx->_[6] * mtx->_[2]) >> FX32_INT_SHIFT; + var3 = ((fx64)mtx->_[0] * mtx->_[5] - (fx64)mtx->_[3] * mtx->_[2]) >> FX32_INT_SHIFT; + + fx32 ret = FX_GetDivResult(); + dst->_[0] = (fx32)(((fx64)ret * det0) >> FX32_INT_SHIFT); + dst->_[1] = -(fx32)(((fx64)ret * var0) >> FX32_INT_SHIFT); + dst->_[2] = (fx32)(((fx64)ret * var1) >> FX32_INT_SHIFT); + dst->_[3] = -(fx32)(((fx64)ret * det1) >> FX32_INT_SHIFT); + dst->_[4] = (fx32)(((fx64)ret * var2) >> FX32_INT_SHIFT); + dst->_[5] = -(fx32)(((fx64)ret * var3) >> FX32_INT_SHIFT); + + dst->_[6] = (fx32)(((fx64)ret * det2) >> FX32_INT_SHIFT); + fx32 temp = (fx32)(((fx64)mtx->_[0] * mtx->_[7] - (fx64)mtx->_[6] * mtx->_[1]) >> FX32_INT_SHIFT); + dst->_[7] = -(fx32)(((fx64)ret * temp) >> FX32_INT_SHIFT); + fx32 temp1 = (fx32)(((fx64)mtx->_[0] * mtx->_[4] - (fx64)mtx->_[3] * mtx->_[1]) >> FX32_INT_SHIFT); + dst->_[8] = (fx32)(((fx64)ret * temp1) >> FX32_INT_SHIFT); + dst->_[9] = -(fx32)(((fx64)dst->_[0] * mtx->_[9] + (fx64)dst->_[3] * mtx->_[10] + (fx64)dst->_[6] * mtx->_[11]) >> FX32_INT_SHIFT); + dst->_[10] = -(fx32)(((fx64)dst->_[1] * mtx->_[9] + (fx64)dst->_[4] * mtx->_[10] + (fx64)dst->_[7] * mtx->_[11]) >> FX32_INT_SHIFT); + dst->_[11] = -(fx32)(((fx64)dst->_[2] * mtx->_[9] + (fx64)dst->_[5] * mtx->_[10] + (fx64)dst->_[8] * mtx->_[11]) >> FX32_INT_SHIFT); if (dst == &tempmat) MI_Copy48B(&tempmat, inv); @@ -62,8 +62,8 @@ s32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){ void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c){ struct Mtx43 temp; struct Mtx43 *dst; - s32 a0, a1, a2; - s32 b0, b1, b2; + fx32 a0, a1, a2; + fx32 b0, b1, b2; if (c == b) dst = &temp; @@ -73,50 +73,50 @@ void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c){ a0 = a->_[0]; a1 = a->_[1]; a2 = a->_[2]; - dst->_[0] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[3] + (s64)a2 * b->_[6] ) >> FX32_INT_SHIFT); - dst->_[1] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + dst->_[0] = (((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6] ) >> FX32_INT_SHIFT); + dst->_[1] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT); b0 = b->_[2]; b1 = b->_[5]; b2 = b->_[8]; - dst->_[2] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[2] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); a0 = a->_[3]; a1 = a->_[4]; a2 = a->_[5]; - dst->_[5] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); - dst->_[4] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + dst->_[5] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[4] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT); b0 = b->_[0]; b1 = b->_[3]; b2 = b->_[6]; - dst->_[3] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[3] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); a0 = a->_[6]; a1 = a->_[7]; a2 = a->_[8]; - dst->_[6] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); - dst->_[7] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7] ) >> FX32_INT_SHIFT); + dst->_[6] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[7] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT); b0 = b->_[2]; b1 = b->_[5]; b2 = b->_[8]; - dst->_[8] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT); + dst->_[8] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT); a0 = a->_[9]; a1 = a->_[10]; a2 = a->_[11]; - dst->_[11] = ((((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2) >> FX32_INT_SHIFT) + b->_[11]); - dst->_[10] = ((((s64)a0 * b->_[1] + (s64)a1 * b->_[4] + (s64)a2 * b->_[7]) >> FX32_INT_SHIFT) + b->_[10]); - dst->_[9] = ((((s64)a0 * b->_[0] + (s64)a1 * b->_[3] + (s64)a2 * b->_[6]) >> FX32_INT_SHIFT) + b->_[9]); + dst->_[11] = ((((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT) + b->_[11]); + dst->_[10] = ((((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7]) >> FX32_INT_SHIFT) + b->_[10]); + dst->_[9] = ((((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6]) >> FX32_INT_SHIFT) + b->_[9]); if (dst == &temp) *c = temp; } void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32 *dst){ - s32 x, y, z; + fx32 x, y, z; x = vec->x; y = vec->y; z = vec->z; - dst->x = ((s64)x * mtx->_[0] + (s64)y * mtx->_[3] + (s64)z * mtx->_[6]) >> FX32_INT_SHIFT; + dst->x = ((fx64)x * mtx->_[0] + (fx64)y * mtx->_[3] + (fx64)z * mtx->_[6]) >> FX32_INT_SHIFT; dst->x += mtx->_[9]; - dst->y = ((s64)x * mtx->_[1] + (s64)y * mtx->_[4] + (s64)z * mtx->_[7]) >> FX32_INT_SHIFT; + dst->y = ((fx64)x * mtx->_[1] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[7]) >> FX32_INT_SHIFT; dst->y += mtx->_[10]; - dst->z = ((s64)x * mtx->_[2] + (s64)y * mtx->_[5] + (s64)z * mtx->_[8]) >> FX32_INT_SHIFT; + dst->z = ((fx64)x * mtx->_[2] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[8]) >> FX32_INT_SHIFT; dst->z += mtx->_[11]; } @@ -150,7 +150,7 @@ asm void MTX_Copy43To44_(struct Mtx43 *src, struct Mtx44 *dst){ } #pragma thumb on -asm void MTX_Scale43_(struct Mtx43 *dst, s32 x, s32 y, s32 z){ +asm void MTX_Scale43_(struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){ stmia r0!, {r1} mov r1, #0x0 str r3, [r0, #0x1c] @@ -166,7 +166,7 @@ asm void MTX_Scale43_(struct Mtx43 *dst, s32 x, s32 y, s32 z){ #pragma thumb off #pragma thumb on -asm void MTX_RotX43_(struct Mtx43 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotX43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ str r1, [r0, #0x14] neg r1, r1 str r1, [r0, #0x1c] @@ -186,7 +186,7 @@ asm void MTX_RotX43_(struct Mtx43 *mtx, s32 sinphi, s32 cosphi){ #pragma thumb off #pragma thumb on -asm void MTX_RotY43_(struct Mtx43 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotY43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ str r1, [r0, #0x18] mov r3, #0x0 stmia r0!, {r2-r3} diff --git a/arm9/lib/src/FX_mtx44.c b/arm9/lib/src/FX_mtx44.c index 3c91b4df..8d158602 100644 --- a/arm9/lib/src/FX_mtx44.c +++ b/arm9/lib/src/FX_mtx44.c @@ -5,20 +5,20 @@ void MI_Copy48B(void *src, void *dst); -void MTX_TransApply44(struct Mtx44 *mtx, struct Mtx44 *dst, s32 x, s32 y, s32 z){ +void MTX_TransApply44(struct Mtx44 *mtx, struct Mtx44 *dst, fx32 x, fx32 y, fx32 z){ if(mtx != dst) MI_Copy48B(mtx, dst); - dst->_[12] = mtx->_[12] + (s32)(((s64)x * mtx->_[0] + (s64)y * mtx->_[4] + (s64)z * mtx->_[8] ) >> FX32_INT_SHIFT); - dst->_[13] = mtx->_[13] + (s32)(((s64)x * mtx->_[1] + (s64)y * mtx->_[5] + (s64)z * mtx->_[9] ) >> FX32_INT_SHIFT); - dst->_[14] = mtx->_[14] + (s32)(((s64)x * mtx->_[2] + (s64)y * mtx->_[6] + (s64)z * mtx->_[10]) >> FX32_INT_SHIFT); - dst->_[15] = mtx->_[15] + (s32)(((s64)x * mtx->_[3] + (s64)y * mtx->_[7] + (s64)z * mtx->_[11]) >> FX32_INT_SHIFT); + dst->_[12] = mtx->_[12] + (fx32)(((fx64)x * mtx->_[0] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[8] ) >> FX32_INT_SHIFT); + dst->_[13] = mtx->_[13] + (fx32)(((fx64)x * mtx->_[1] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[9] ) >> FX32_INT_SHIFT); + dst->_[14] = mtx->_[14] + (fx32)(((fx64)x * mtx->_[2] + (fx64)y * mtx->_[6] + (fx64)z * mtx->_[10]) >> FX32_INT_SHIFT); + dst->_[15] = mtx->_[15] + (fx32)(((fx64)x * mtx->_[3] + (fx64)y * mtx->_[7] + (fx64)z * mtx->_[11]) >> FX32_INT_SHIFT); } void MTX_Concat44(struct Mtx44 *a, struct Mtx44 *b, struct Mtx44 *c){ struct Mtx44 temp; struct Mtx44 *dst; - s32 a0, a1, a2, a3; - s32 b0, b1, b2, b3; + fx32 a0, a1, a2, a3; + fx32 b0, b1, b2, b3; if (c == b) dst = &temp; @@ -29,46 +29,46 @@ void MTX_Concat44(struct Mtx44 *a, struct Mtx44 *b, struct Mtx44 *c){ a1 = a->_[1]; a2 = a->_[2]; a3 = a->_[3]; - dst->_[0] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[4] + (s64)a2 * b->_[8] + (s64)a3 * b->_[12]) >> FX32_INT_SHIFT); - dst->_[1] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); - dst->_[3] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + dst->_[0] = (((fx64)a0 * b->_[0] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[8] + (fx64)a3 * b->_[12]) >> FX32_INT_SHIFT); + dst->_[1] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[5] + (fx64)a2 * b->_[9] + (fx64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[3] = (((fx64)a0 * b->_[3] + (fx64)a1 * b->_[7] + (fx64)a2 * b->_[11] + (fx64)a3 * b->_[15]) >> FX32_INT_SHIFT); b0 = b->_[2]; b1 = b->_[6]; b2 = b->_[10]; b3 = b->_[14]; - dst->_[2] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[2] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2 + (fx64)a3 * b3) >> FX32_INT_SHIFT); a0 = a->_[4]; a1 = a->_[5]; a2 = a->_[6]; a3 = a->_[7]; - dst->_[6] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); - dst->_[5] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); - dst->_[7] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + dst->_[6] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2 + (fx64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[5] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[5] + (fx64)a2 * b->_[9] + (fx64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[7] = (((fx64)a0 * b->_[3] + (fx64)a1 * b->_[7] + (fx64)a2 * b->_[11] + (fx64)a3 * b->_[15]) >> FX32_INT_SHIFT); b0 = b->_[0]; b1 = b->_[4]; b2 = b->_[8]; b3 = b->_[12]; - dst->_[4] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[4] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2 + (fx64)a3 * b3) >> FX32_INT_SHIFT); a0 = a->_[8]; a1 = a->_[9]; a2 = a->_[10]; a3 = a->_[11]; - dst->_[8] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); - dst->_[9] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); - dst->_[11] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + dst->_[8] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2 + (fx64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[9] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[5] + (fx64)a2 * b->_[9] + (fx64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[11] = (((fx64)a0 * b->_[3] + (fx64)a1 * b->_[7] + (fx64)a2 * b->_[11] + (fx64)a3 * b->_[15]) >> FX32_INT_SHIFT); b0 = b->_[2]; b1 = b->_[6]; b2 = b->_[10]; b3 = b->_[14]; - dst->_[10] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[10] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2 + (fx64)a3 * b3) >> FX32_INT_SHIFT); a0 = a->_[12]; a1 = a->_[13]; a2 = a->_[14]; a3 = a->_[15]; - dst->_[14] = (((s64)a0 * b0 + (s64)a1 * b1 + (s64)a2 * b2 + (s64)a3 * b3) >> FX32_INT_SHIFT); - dst->_[13] = (((s64)a0 * b->_[1] + (s64)a1 * b->_[5] + (s64)a2 * b->_[9] + (s64)a3 * b->_[13]) >> FX32_INT_SHIFT); - dst->_[12] = (((s64)a0 * b->_[0] + (s64)a1 * b->_[4] + (s64)a2 * b->_[8] + (s64)a3 * b->_[12]) >> FX32_INT_SHIFT); - dst->_[15] = (((s64)a0 * b->_[3] + (s64)a1 * b->_[7] + (s64)a2 * b->_[11] + (s64)a3 * b->_[15]) >> FX32_INT_SHIFT); + dst->_[14] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2 + (fx64)a3 * b3) >> FX32_INT_SHIFT); + dst->_[13] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[5] + (fx64)a2 * b->_[9] + (fx64)a3 * b->_[13]) >> FX32_INT_SHIFT); + dst->_[12] = (((fx64)a0 * b->_[0] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[8] + (fx64)a3 * b->_[12]) >> FX32_INT_SHIFT); + dst->_[15] = (((fx64)a0 * b->_[3] + (fx64)a1 * b->_[7] + (fx64)a2 * b->_[11] + (fx64)a3 * b->_[15]) >> FX32_INT_SHIFT); if (dst == &temp) *c = temp; } @@ -104,7 +104,7 @@ asm void MTX_Copy44To43_(struct Mtx44 *src, struct Mtx43 *dst){ } #pragma thumb on -asm void MTX_RotX44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotX44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x14] str r2, [r0, #0x28] str r1, [r0, #0x18] @@ -127,7 +127,7 @@ asm void MTX_RotX44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ #pragma thumb off #pragma thumb on -asm void MTX_RotY44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotY44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r2, [r0, #0x28] str r1, [r0, #0x20] @@ -150,7 +150,7 @@ asm void MTX_RotY44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ #pragma thumb off #pragma thumb on -asm void MTX_RotZ44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi){ +asm void MTX_RotZ44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r2, [r0, #0x14] str r1, [r0, #0x4] diff --git a/arm9/lib/src/FX_vec.c b/arm9/lib/src/FX_vec.c index 7b838829..10a792be 100644 --- a/arm9/lib/src/FX_vec.c +++ b/arm9/lib/src/FX_vec.c @@ -20,29 +20,29 @@ void VEC_Fx16Add(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ dst->z = a->z + b->z; } -s32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){ - return ((s64)a->x * b->x + (s64)a->y * b->y + (s64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; +fx32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){ + return ((fx64)a->x * b->x + (fx64)a->y * b->y + (fx64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; } -s32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){ - s32 temp1, temp2; +fx32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){ + fx32 temp1, temp2; temp1 = (a->x * b->x) + (a->y * b->y); temp2 = (a->z * b->z) + (1 << (FX64_INT_SHIFT - 1)); - return (s32)(((s64)temp1 + temp2) >> FX64_INT_SHIFT); + return (fx32)(((fx64)temp1 + temp2) >> FX64_INT_SHIFT); } void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ - s32 x, y, z; - x = (s32)(((s64)a->y * b->z - (s64)a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); - y = (s32)(((s64)a->z * b->x - (s64)a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); - z = (s32)(((s64)a->x * b->y - (s64)a->y * b->x + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + fx32 x, y, z; + x = (fx32)(((fx64)a->y * b->z - (fx64)a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + y = (fx32)(((fx64)a->z * b->x - (fx64)a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); + z = (fx32)(((fx64)a->x * b->y - (fx64)a->y * b->x + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); dst->x = x; dst->y = y; dst->z = z; } void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ - s32 x, y, z; + fx32 x, y, z; x = ((a->y * b->z - a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); y = ((a->z * b->x - a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); z = ((a->x * b->y - a->y * b->x + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); @@ -51,20 +51,20 @@ void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst dst->z = z; } -s32 VEC_Mag(struct Vecx32 *a){ - s64 l2 = (s64)a->x * a->x; - l2 += (s64)a->y * a->y; - l2 += (s64)a->z * a->z; +fx32 VEC_Mag(struct Vecx32 *a){ + fx64 l2 = (fx64)a->x * a->x; + l2 += (fx64)a->y * a->y; + l2 += (fx64)a->z * a->z; SETREG16(HW_REG_SQRTCNT, 0x1); SETREG64(HW_REG_SQRT_PARAM, l2 * 4); while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for coprocessor to finish - return ((s32)READREG32(HW_REG_SQRT_RESULT) + 1) >> 1; + return ((fx32)READREG32(HW_REG_SQRT_RESULT) + 1) >> 1; } void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ - s64 l2 = (s64)a->x * a->x; - l2 += (s64)a->y * a->y; - l2 += (s64)a->z * a->z; + fx64 l2 = (fx64)a->x * a->x; + l2 += (fx64)a->y * a->y; + l2 += (fx64)a->z * a->z; //1/sqrt(l) is computed by calculating sqrt(l)*(1/l) SETREG16(HW_REG_DIVCNT, 0x2); SETREG64(HW_REG_DIV_NUMER, 0x0100000000000000); @@ -72,7 +72,7 @@ void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ SETREG16(HW_REG_SQRTCNT, 0x1); SETREG64(HW_REG_SQRT_PARAM, l2 * 4); while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for sqrt to finish - s32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); + fx32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); while (READREG16(HW_REG_DIVCNT) & 0x8000); //wait for division to finish l2 = READREG64(HW_REG_DIV_RESULT); l2 = sqrtresult * l2; @@ -82,7 +82,7 @@ void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ } void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ - s64 l2 = a->x * a->x; + fx64 l2 = a->x * a->x; l2 += a->y * a->y; l2 += a->z * a->z; //1/sqrt(l) is computed by calculating sqrt(l)*(1/l) @@ -92,7 +92,7 @@ void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ SETREG16(HW_REG_SQRTCNT, 0x1); SETREG64(HW_REG_SQRT_PARAM, l2 * 4); while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for sqrt to finish - s32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); + fx32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); while (READREG16(HW_REG_DIVCNT) & 0x8000); //wait for division to finish l2 = READREG64(HW_REG_DIV_RESULT); l2 = sqrtresult * l2; @@ -101,8 +101,8 @@ void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ dst->z = (l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D; } -void VEC_MultAdd(s32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ - dst->x = (s32)(((s64)factor * a->x) >> FX32_INT_SHIFT) + b->x; - dst->y = (s32)(((s64)factor * a->y) >> FX32_INT_SHIFT) + b->y; - dst->z = (s32)(((s64)factor * a->z) >> FX32_INT_SHIFT) + b->z; +void VEC_MultAdd(fx32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ + dst->x = (fx32)(((fx64)factor * a->x) >> FX32_INT_SHIFT) + b->x; + dst->y = (fx32)(((fx64)factor * a->y) >> FX32_INT_SHIFT) + b->y; + dst->z = (fx32)(((fx64)factor * a->z) >> FX32_INT_SHIFT) + b->z; } -- cgit v1.2.3 From 155f50c9890a93fbc191e078d304c161809e8fc6 Mon Sep 17 00:00:00 2001 From: Made Date: Mon, 4 May 2020 17:26:31 +0200 Subject: Move header and fix accidental name changes --- arm9/lib/src/FX_cp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_cp.c b/arm9/lib/src/FX_cp.c index 76dea4b4..a5a8d9cb 100644 --- a/arm9/lib/src/FX_cp.c +++ b/arm9/lib/src/FX_cp.c @@ -53,7 +53,7 @@ void FX_DivAsync(fx32 numerator, fx32 denominator){ SETREG64(HW_REG_DIV_DENOM, (u32)denominator); } -fx32 FX_Divfx32(fx32 numerator, fx32 denominator){ +fx32 FX_DivS32(fx32 numerator, fx32 denominator){ SETREG16(HW_REG_DIVCNT, 0x0); SETREG32(HW_REG_DIV_NUMER, (u32)numerator); //32bit write for some reason SETREG64(HW_REG_DIV_DENOM, (u32)denominator); @@ -61,7 +61,7 @@ fx32 FX_Divfx32(fx32 numerator, fx32 denominator){ return READREG32(HW_REG_DIV_RESULT); } -fx32 FX_Modfx32(fx32 num, fx32 mod){ +fx32 FX_ModS32(fx32 num, fx32 mod){ SETREG16(HW_REG_DIVCNT, 0x0); SETREG32(HW_REG_DIV_NUMER, (u32)num); //32bit write for some reason SETREG64(HW_REG_DIV_DENOM, (u32)mod); -- cgit v1.2.3 From f4c61411673207da9d6be013674f95eeb07408b5 Mon Sep 17 00:00:00 2001 From: Made Date: Mon, 4 May 2020 17:48:38 +0200 Subject: Add function attributes and remove thumb pragmas --- arm9/lib/src/FX.c | 4 ++-- arm9/lib/src/FX_atan.c | 4 ++-- arm9/lib/src/FX_cp.c | 20 ++++++++++---------- arm9/lib/src/FX_mtx22.c | 8 +++----- arm9/lib/src/FX_mtx33.c | 20 +++++++------------- arm9/lib/src/FX_mtx43.c | 24 +++++++++--------------- arm9/lib/src/FX_mtx44.c | 21 ++++++++------------- arm9/lib/src/FX_vec.c | 22 +++++++++++----------- 8 files changed, 52 insertions(+), 71 deletions(-) (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX.c b/arm9/lib/src/FX.c index f39b1995..4b9c213f 100644 --- a/arm9/lib/src/FX.c +++ b/arm9/lib/src/FX.c @@ -2,11 +2,11 @@ #include "main.h" #include "fx.h" -void FX_Init(){ +ARM_FUNC void FX_Init(){ return; } -fx32 FX_Modf(fx32 x, fx32 *iptr){ +ARM_FUNC fx32 FX_Modf(fx32 x, fx32 *iptr){ if (x >= 0) { *iptr = x & 0x7FFFF000; diff --git a/arm9/lib/src/FX_atan.c b/arm9/lib/src/FX_atan.c index 085763f8..979895a8 100644 --- a/arm9/lib/src/FX_atan.c +++ b/arm9/lib/src/FX_atan.c @@ -4,7 +4,7 @@ extern fx16 FX_AtanTable_[]; -u16 FX_Atan(fx32 x){ +ARM_FUNC u16 FX_Atan(fx32 x){ if (x >= 0) { if (x > 0x1000) @@ -41,7 +41,7 @@ u16 FX_Atan(fx32 x){ } } -u16 FX_Atan2(fx32 x, fx32 y){ +ARM_FUNC u16 FX_Atan2(fx32 x, fx32 y){ fx32 result; u32 positive, bias, denominator, numerator; if (x > 0) diff --git a/arm9/lib/src/FX_cp.c b/arm9/lib/src/FX_cp.c index a5a8d9cb..2ca9d720 100644 --- a/arm9/lib/src/FX_cp.c +++ b/arm9/lib/src/FX_cp.c @@ -3,17 +3,17 @@ #include "fx.h" -fx32 FX_Div(fx32 numerator, fx32 denominator){ +ARM_FUNC fx32 FX_Div(fx32 numerator, fx32 denominator){ FX_DivAsync(numerator, denominator); return FX_GetDivResult(); } -fx32 FX_Inv(fx32 x){ +ARM_FUNC fx32 FX_Inv(fx32 x){ FX_InvAsync(x); return FX_GetDivResult(); } -fx32 FX_Sqrt(fx32 x){ +ARM_FUNC fx32 FX_Sqrt(fx32 x){ if (x > 0) { SETREG16(HW_REG_SQRTCNT, 0x1); @@ -26,34 +26,34 @@ fx32 FX_Sqrt(fx32 x){ } } -fx64c FX_GetDivResultFx64c(){ +ARM_FUNC fx64c FX_GetDivResultFx64c(){ while (READREG16(HW_REG_DIVCNT) & 0x8000); return READREG64(HW_REG_DIV_RESULT); } -fx32 FX_GetDivResult(){ +ARM_FUNC fx32 FX_GetDivResult(){ while (READREG16(HW_REG_DIVCNT) & 0x8000); return (READREG64(HW_REG_DIV_RESULT) + (1 << (0x14 - 1))) >> 0x14; } -void FX_InvAsync(fx32 x){ +ARM_FUNC void FX_InvAsync(fx32 x){ SETREG16(HW_REG_DIVCNT, 0x1); SETREG64(HW_REG_DIV_NUMER, (fx64)0x00001000 << 32); SETREG64(HW_REG_DIV_DENOM, (u32)x); } -fx32 FX_GetSqrtResult(){ +ARM_FUNC fx32 FX_GetSqrtResult(){ while (READREG16(HW_REG_SQRTCNT) & 0x8000); return (READREG32(HW_REG_SQRT_RESULT) + (1 << (0xA - 1))) >> 0xA; } -void FX_DivAsync(fx32 numerator, fx32 denominator){ +ARM_FUNC void FX_DivAsync(fx32 numerator, fx32 denominator){ SETREG16(HW_REG_DIVCNT, 0x1); SETREG64(HW_REG_DIV_NUMER, (fx64)numerator << 32); SETREG64(HW_REG_DIV_DENOM, (u32)denominator); } -fx32 FX_DivS32(fx32 numerator, fx32 denominator){ +ARM_FUNC fx32 FX_DivS32(fx32 numerator, fx32 denominator){ SETREG16(HW_REG_DIVCNT, 0x0); SETREG32(HW_REG_DIV_NUMER, (u32)numerator); //32bit write for some reason SETREG64(HW_REG_DIV_DENOM, (u32)denominator); @@ -61,7 +61,7 @@ fx32 FX_DivS32(fx32 numerator, fx32 denominator){ return READREG32(HW_REG_DIV_RESULT); } -fx32 FX_ModS32(fx32 num, fx32 mod){ +ARM_FUNC fx32 FX_ModS32(fx32 num, fx32 mod){ SETREG16(HW_REG_DIVCNT, 0x0); SETREG32(HW_REG_DIV_NUMER, (u32)num); //32bit write for some reason SETREG64(HW_REG_DIV_DENOM, (u32)mod); diff --git a/arm9/lib/src/FX_mtx22.c b/arm9/lib/src/FX_mtx22.c index 19504574..38387c64 100644 --- a/arm9/lib/src/FX_mtx22.c +++ b/arm9/lib/src/FX_mtx22.c @@ -2,14 +2,14 @@ #include "main.h" #include "fx.h" -void MTX_ScaleApply22(struct Mtx22 *mtx, struct Mtx22 *dst, fx32 x, fx32 y){ +ARM_FUNC void MTX_ScaleApply22(struct Mtx22 *mtx, struct Mtx22 *dst, fx32 x, fx32 y){ dst->_[0] = ((fx64)x * mtx->_[0]) >> FX32_INT_SHIFT; dst->_[1] = ((fx64)x * mtx->_[1]) >> FX32_INT_SHIFT; dst->_[2] = ((fx64)y * mtx->_[2]) >> FX32_INT_SHIFT; dst->_[3] = ((fx64)y * mtx->_[3]) >> FX32_INT_SHIFT; } -asm void MTX_Identity22_(struct Mtx22 *mtx){ +ARM_FUNC asm void MTX_Identity22_(struct Mtx22 *mtx){ mov r1, #0x0 mov r2, #0x1000 mov r3, #0x0 @@ -18,8 +18,7 @@ asm void MTX_Identity22_(struct Mtx22 *mtx){ bx lr } -#pragma thumb on -asm void MTX_Rot22_(struct Mtx22 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_Rot22_(struct Mtx22 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r1, [r0, #0x4] neg r1, r1 @@ -27,4 +26,3 @@ asm void MTX_Rot22_(struct Mtx22 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0xc] bx lr } -#pragma thumb off diff --git a/arm9/lib/src/FX_mtx33.c b/arm9/lib/src/FX_mtx33.c index 391a6104..90beddba 100644 --- a/arm9/lib/src/FX_mtx33.c +++ b/arm9/lib/src/FX_mtx33.c @@ -2,7 +2,7 @@ #include "main.h" #include "fx.h" -void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 z){ +ARM_FUNC void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 z){ dst->_[0] = ((fx64)x * mtx->_[0]) >> FX32_INT_SHIFT; dst->_[1] = ((fx64)x * mtx->_[1]) >> FX32_INT_SHIFT; dst->_[2] = ((fx64)x * mtx->_[2]) >> FX32_INT_SHIFT; @@ -14,7 +14,7 @@ void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 dst->_[8] = ((fx64)z * mtx->_[8]) >> FX32_INT_SHIFT; } -void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){ +ARM_FUNC void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){ struct Mtx33 temp; struct Mtx33 *dst; fx32 a0, a1, a2; @@ -57,7 +57,7 @@ void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){ *c = temp; } -void MTX_MultVec33(struct Vecx32 *vec, struct Mtx33 *mtx, struct Vecx32 *dst){ +ARM_FUNC void MTX_MultVec33(struct Vecx32 *vec, struct Mtx33 *mtx, struct Vecx32 *dst){ fx32 x, y, z; x = vec->x; y = vec->y; @@ -67,7 +67,7 @@ void MTX_MultVec33(struct Vecx32 *vec, struct Mtx33 *mtx, struct Vecx32 *dst){ dst->z = ((fx64)x * mtx->_[2] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[8]) >> FX32_INT_SHIFT; } -asm void MTX_Identity33_(struct Mtx33 *mtx){ +ARM_FUNC asm void MTX_Identity33_(struct Mtx33 *mtx){ mov r2, #0x1000 str r2, [r0, #0x20] mov r3, #0x0 @@ -79,8 +79,7 @@ asm void MTX_Identity33_(struct Mtx33 *mtx){ bx lr } -#pragma thumb on -asm void MTX_RotX33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_RotX33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ mov r3, #0x1 lsl r3, r3, #0xc str r3, [r0, #0x0] @@ -96,10 +95,8 @@ asm void MTX_RotX33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x20] bx lr } -#pragma thumb off -#pragma thumb on -asm void MTX_RotY33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_RotY33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r2, [r0, #0x20] mov r3, #0x0 @@ -115,10 +112,8 @@ asm void MTX_RotY33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ str r3, [r0, #0x10] bx lr } -#pragma thumb off -#pragma thumb on -asm void MTX_RotZ33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_RotZ33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ stmia r0!, {r2} mov r3, #0x0 stmia r0!, {r1,r3} @@ -132,4 +127,3 @@ asm void MTX_RotZ33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi){ str r1, [r0, #0xc] bx lr } -#pragma thumb off diff --git a/arm9/lib/src/FX_mtx43.c b/arm9/lib/src/FX_mtx43.c index 862bd6f2..96ab4062 100644 --- a/arm9/lib/src/FX_mtx43.c +++ b/arm9/lib/src/FX_mtx43.c @@ -3,7 +3,7 @@ #include "fx.h" -void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){ +ARM_FUNC void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){ //this works because matrices are indexed columns first MTX_ScaleApply33((struct Mtx33 *)mtx, (struct Mtx33 *)dst, x, y, z); dst->_[9] = mtx->_[9]; @@ -11,7 +11,7 @@ void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, fx32 x, fx32 y, fx32 dst->_[11] = mtx->_[11]; } -fx32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){ +ARM_FUNC fx32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){ struct Mtx43 tempmat; struct Mtx43 *dst; fx32 det0, det1, det2, det; @@ -59,7 +59,7 @@ fx32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){ return 0; } -void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c){ +ARM_FUNC void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c){ struct Mtx43 temp; struct Mtx43 *dst; fx32 a0, a1, a2; @@ -107,7 +107,7 @@ void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c){ *c = temp; } -void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32 *dst){ +ARM_FUNC void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32 *dst){ fx32 x, y, z; x = vec->x; y = vec->y; @@ -120,7 +120,7 @@ void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32 *dst){ dst->z += mtx->_[11]; } -asm void MTX_Identity43_(struct Mtx43 *mtx){ +ARM_FUNC asm void MTX_Identity43_(struct Mtx43 *mtx){ mov r2, #0x1000 mov r3, #0x0 stmia r0!, {r2-r3} @@ -133,7 +133,7 @@ asm void MTX_Identity43_(struct Mtx43 *mtx){ bx lr } -asm void MTX_Copy43To44_(struct Mtx43 *src, struct Mtx44 *dst){ +ARM_FUNC asm void MTX_Copy43To44_(struct Mtx43 *src, struct Mtx44 *dst){ stmdb sp!, {r4} mov r12, #0x0 ldmia r0!, {r2-r4} @@ -149,8 +149,7 @@ asm void MTX_Copy43To44_(struct Mtx43 *src, struct Mtx44 *dst){ bx lr } -#pragma thumb on -asm void MTX_Scale43_(struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){ +THUMB_FUNC asm void MTX_Scale43_(struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){ stmia r0!, {r1} mov r1, #0x0 str r3, [r0, #0x1c] @@ -163,10 +162,8 @@ asm void MTX_Scale43_(struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){ stmia r0!, {r1-r3} bx lr } -#pragma thumb off -#pragma thumb on -asm void MTX_RotX43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_RotX43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ str r1, [r0, #0x14] neg r1, r1 str r1, [r0, #0x1c] @@ -183,10 +180,8 @@ asm void MTX_RotX43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ stmia r0!, {r1,r3} bx lr } -#pragma thumb off -#pragma thumb on -asm void MTX_RotY43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_RotY43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ str r1, [r0, #0x18] mov r3, #0x0 stmia r0!, {r2-r3} @@ -201,4 +196,3 @@ asm void MTX_RotY43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi){ stmia r0!, {r1,r3} bx lr } -#pragma thumb off diff --git a/arm9/lib/src/FX_mtx44.c b/arm9/lib/src/FX_mtx44.c index 8d158602..8152907d 100644 --- a/arm9/lib/src/FX_mtx44.c +++ b/arm9/lib/src/FX_mtx44.c @@ -5,7 +5,7 @@ void MI_Copy48B(void *src, void *dst); -void MTX_TransApply44(struct Mtx44 *mtx, struct Mtx44 *dst, fx32 x, fx32 y, fx32 z){ +ARM_FUNC void MTX_TransApply44(struct Mtx44 *mtx, struct Mtx44 *dst, fx32 x, fx32 y, fx32 z){ if(mtx != dst) MI_Copy48B(mtx, dst); dst->_[12] = mtx->_[12] + (fx32)(((fx64)x * mtx->_[0] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[8] ) >> FX32_INT_SHIFT); @@ -14,7 +14,7 @@ void MTX_TransApply44(struct Mtx44 *mtx, struct Mtx44 *dst, fx32 x, fx32 y, fx32 dst->_[15] = mtx->_[15] + (fx32)(((fx64)x * mtx->_[3] + (fx64)y * mtx->_[7] + (fx64)z * mtx->_[11]) >> FX32_INT_SHIFT); } -void MTX_Concat44(struct Mtx44 *a, struct Mtx44 *b, struct Mtx44 *c){ +ARM_FUNC void MTX_Concat44(struct Mtx44 *a, struct Mtx44 *b, struct Mtx44 *c){ struct Mtx44 temp; struct Mtx44 *dst; fx32 a0, a1, a2, a3; @@ -73,7 +73,7 @@ void MTX_Concat44(struct Mtx44 *a, struct Mtx44 *b, struct Mtx44 *c){ *c = temp; } -asm void MTX_Identity44_(struct Mtx44 *dst){ +ARM_FUNC asm void MTX_Identity44_(struct Mtx44 *dst){ mov r2, #0x1000 mov r3, #0x0 stmia r0!, {r2-r3} @@ -87,7 +87,7 @@ asm void MTX_Identity44_(struct Mtx44 *dst){ bx lr } -asm void MTX_Copy44To43_(struct Mtx44 *src, struct Mtx43 *dst){ +ARM_FUNC asm void MTX_Copy44To43_(struct Mtx44 *src, struct Mtx43 *dst){ ldmia r0!, {r2-r3,r12} add r0, r0, #0x4 stmia r1!, {r2-r3,r12} @@ -103,8 +103,8 @@ asm void MTX_Copy44To43_(struct Mtx44 *src, struct Mtx43 *dst){ bx lr } -#pragma thumb on -asm void MTX_RotX44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ + +THUMB_FUNC asm void MTX_RotX44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x14] str r2, [r0, #0x28] str r1, [r0, #0x18] @@ -124,10 +124,8 @@ asm void MTX_RotX44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ str r1, [r0, #0x0] bx lr } -#pragma thumb off -#pragma thumb on -asm void MTX_RotY44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_RotY44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r2, [r0, #0x28] str r1, [r0, #0x20] @@ -147,10 +145,8 @@ asm void MTX_RotY44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ stmia r0!, {r1-r3} bx lr } -#pragma thumb off -#pragma thumb on -asm void MTX_RotZ44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ +THUMB_FUNC asm void MTX_RotZ44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ str r2, [r0, #0x0] str r2, [r0, #0x14] str r1, [r0, #0x4] @@ -169,4 +165,3 @@ asm void MTX_RotZ44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi){ stmia r0!, {r1-r3} bx lr } -#pragma thumb off diff --git a/arm9/lib/src/FX_vec.c b/arm9/lib/src/FX_vec.c index 10a792be..af36fe89 100644 --- a/arm9/lib/src/FX_vec.c +++ b/arm9/lib/src/FX_vec.c @@ -2,36 +2,36 @@ #include "main.h" #include "fx.h" -void VEC_Add(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ +ARM_FUNC void VEC_Add(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ dst->x = a->x + b->x; dst->y = a->y + b->y; dst->z = a->z + b->z; } -void VEC_Subtract(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ +ARM_FUNC void VEC_Subtract(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ dst->x = a->x - b->x; dst->y = a->y - b->y; dst->z = a->z - b->z; } -void VEC_Fx16Add(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ +ARM_FUNC void VEC_Fx16Add(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ dst->x = a->x + b->x; dst->y = a->y + b->y; dst->z = a->z + b->z; } -fx32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){ +ARM_FUNC fx32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){ return ((fx64)a->x * b->x + (fx64)a->y * b->y + (fx64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT; } -fx32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){ +ARM_FUNC fx32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){ fx32 temp1, temp2; temp1 = (a->x * b->x) + (a->y * b->y); temp2 = (a->z * b->z) + (1 << (FX64_INT_SHIFT - 1)); return (fx32)(((fx64)temp1 + temp2) >> FX64_INT_SHIFT); } -void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ +ARM_FUNC void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ fx32 x, y, z; x = (fx32)(((fx64)a->y * b->z - (fx64)a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); y = (fx32)(((fx64)a->z * b->x - (fx64)a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); @@ -41,7 +41,7 @@ void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ dst->z = z; } -void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ +ARM_FUNC void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){ fx32 x, y, z; x = ((a->y * b->z - a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); y = ((a->z * b->x - a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT); @@ -51,7 +51,7 @@ void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst dst->z = z; } -fx32 VEC_Mag(struct Vecx32 *a){ +ARM_FUNC fx32 VEC_Mag(struct Vecx32 *a){ fx64 l2 = (fx64)a->x * a->x; l2 += (fx64)a->y * a->y; l2 += (fx64)a->z * a->z; @@ -61,7 +61,7 @@ fx32 VEC_Mag(struct Vecx32 *a){ return ((fx32)READREG32(HW_REG_SQRT_RESULT) + 1) >> 1; } -void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ +ARM_FUNC void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ fx64 l2 = (fx64)a->x * a->x; l2 += (fx64)a->y * a->y; l2 += (fx64)a->z * a->z; @@ -81,7 +81,7 @@ void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ dst->z = (l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D; } -void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ +ARM_FUNC void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ fx64 l2 = a->x * a->x; l2 += a->y * a->y; l2 += a->z * a->z; @@ -101,7 +101,7 @@ void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ dst->z = (l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D; } -void VEC_MultAdd(fx32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ +ARM_FUNC void VEC_MultAdd(fx32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){ dst->x = (fx32)(((fx64)factor * a->x) >> FX32_INT_SHIFT) + b->x; dst->y = (fx32)(((fx64)factor * a->y) >> FX32_INT_SHIFT) + b->y; dst->z = (fx32)(((fx64)factor * a->z) >> FX32_INT_SHIFT) + b->z; -- cgit v1.2.3