diff --git a/config/rel_slices.yml b/config/rel_slices.yml index b99f1837..b4b5d6f0 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -362,9 +362,9 @@ sys_math3d.c: .rodata: [0x806437D0, 0x80643810] .data: [0x8065F150, 0x8065F168] .bss: [0x812F54A0, 0x812F5668] -#sys_math.c: -# .text: [0x80408940, 0x80408A44] -# .rodata: [0x806437C0, 0x806437D0] +sys_math.c: + .text: [0x80408940, 0x80408A44] + .rodata: [0x806437C0, 0x806437D0] sys_math_atan.c: .text: [0x8040C06C, 0x8040C284] .rodata: [0x80643810, 0x80643828] diff --git a/include/m_lib.h b/include/m_lib.h index c7ed5f3a..5180ca21 100644 --- a/include/m_lib.h +++ b/include/m_lib.h @@ -12,18 +12,6 @@ extern "C" { #endif -#define SHT_MIN_S -32768 /* 0x8000 */ -#define SHT_MAX_S 32767 /* 0x7FFF */ - -#define SHT_MIN ((f32)SHT_MIN_S) -#define SHT_MAX ((f32)SHT_MAX_S) - -#define USHT_MIN_S 0 -#define USHT_MAX_S 65535 - -#define USHT_MIN ((f32)USHT_MIN_S) -#define USHT_MAX ((f32)USHT_MAX_S) - #define SHT_MINV (1.0f / SHT_MAX) #define ABS(x) (((x) >= 0) ? (x) : -(x)) #define SQ(x) ((x) * (x)) diff --git a/include/sys_math.h b/include/sys_math.h index 9e111ed5..b0dc5cd8 100644 --- a/include/sys_math.h +++ b/include/sys_math.h @@ -4,11 +4,26 @@ #include "types.h" #include "MSL_C/math.h" #include "libc64/qrand.h" +#include "m_lib.h" #ifdef __cplusplus extern "C" { #endif +#define SHT_MIN_S -32768 /* 0x8000 */ +#define SHT_MAX_S 32767 /* 0x7FFF */ + +#define SHT_MIN ((f32)SHT_MIN_S) +#define SHT_MAX ((f32)SHT_MAX_S) + +#define SHT_MINV (1.0f / SHT_MAX) + +#define USHT_MIN_S 0 +#define USHT_MAX_S 65535 + +#define USHT_MIN ((f32)USHT_MIN_S) +#define USHT_MAX ((f32)USHT_MAX_S) + /* Macro to generate a random float in the range of [0, n) */ #define RANDOM_F(n) (fqrand() * (f32)(n)) diff --git a/src/sys_math.c b/src/sys_math.c index 6cbfe8f3..5c9d8944 100644 --- a/src/sys_math.c +++ b/src/sys_math.c @@ -3,19 +3,26 @@ #include "libc64/qrand.h" #include "libc/math.h" - -void init_rnd(){ +extern void init_rnd() { sqrand(osGetCount()); } -f32 sinf_table(f32 x){ - f32 max = 3.05185094476e-05f; - s16 sinf = sins((s16)(10430.0595703f * x)); - return sinf * max; +#ifdef MUST_MATCH +FORCESTRIP static f32 _rodata_order(int in) { + return (f32)in; +} +#endif + +extern f32 sinf_table(f32 x) { + s16 v = (SHT_MAX / M_PI) * x; + s16 sin = sins(v); + + return sin * SHT_MINV; } -f32 cosf_table(f32 x){ - f32 max = 3.05185094476e-05f; - s16 cosf = coss((s16)(10430.0595703f * x)); - return cosf * max; +extern f32 cosf_table(f32 x) { + s16 v = (SHT_MAX / M_PI) * x; + s16 cos = coss(v); + + return cos * SHT_MINV; }