diff options
author | Made <made111@gmx.de> | 2020-05-01 18:59:48 +0200 |
---|---|---|
committer | Made <made111@gmx.de> | 2020-05-01 18:59:48 +0200 |
commit | 009d3fbcf7e1e3ea94656b5233e0bc96fa7b5a5b (patch) | |
tree | 1b7bc878715cc3d2f95c74fd3768c8596bcfff97 /arm9/lib/src/FX_atan.c | |
parent | 10b569f131fc58959d7c50dd4b07f01a52b5e162 (diff) |
decompile FX.s, FX_atan.s and partially decompile FX_ves.s
Diffstat (limited to 'arm9/lib/src/FX_atan.c')
-rw-r--r-- | arm9/lib/src/FX_atan.c | 161 |
1 files changed, 161 insertions, 0 deletions
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]; +} |