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 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 arm9/lib/src/FX_cp.c (limited to 'arm9/lib/src/FX_cp.c') 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); + } -- 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 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'arm9/lib/src/FX_cp.c') 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); +} -- 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_cp.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'arm9/lib/src/FX_cp.c') 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); -- 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/FX_cp.c') 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_cp.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'arm9/lib/src/FX_cp.c') 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); -- cgit v1.2.3