summaryrefslogtreecommitdiff
path: root/arm9/lib/src
diff options
context:
space:
mode:
authorMade <made111@gmx.de>2020-05-01 18:59:48 +0200
committerMade <made111@gmx.de>2020-05-01 18:59:48 +0200
commit009d3fbcf7e1e3ea94656b5233e0bc96fa7b5a5b (patch)
tree1b7bc878715cc3d2f95c74fd3768c8596bcfff97 /arm9/lib/src
parent10b569f131fc58959d7c50dd4b07f01a52b5e162 (diff)
decompile FX.s, FX_atan.s and partially decompile FX_ves.s
Diffstat (limited to 'arm9/lib/src')
-rw-r--r--arm9/lib/src/FX.c20
-rw-r--r--arm9/lib/src/FX_atan.c161
-rw-r--r--arm9/lib/src/FX_vec_c.c34
3 files changed, 215 insertions, 0 deletions
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 *);