diff options
-rw-r--r-- | arm9/asm/FX_mtx22.s | 50 | ||||
-rw-r--r-- | arm9/lib/src/FX_mtx22.c | 30 | ||||
-rw-r--r-- | include/fx.h | 97 |
3 files changed, 84 insertions, 93 deletions
diff --git a/arm9/asm/FX_mtx22.s b/arm9/asm/FX_mtx22.s deleted file mode 100644 index 571180d2..00000000 --- a/arm9/asm/FX_mtx22.s +++ /dev/null @@ -1,50 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .text - - arm_func_start MTX_Identity22_ -MTX_Identity22_: ; 0x020C3E8C - mov r1, #0x0 - mov r2, #0x1000 - mov r3, #0x0 - stmia r0!, {r2-r3} - stmia r0!, {r1-r2} - bx lr - - thumb_func_start MTX_Rot22_ -MTX_Rot22_: ; 0x020C3EA4 - str r2, [r0, #0x0] - str r1, [r0, #0x4] - neg r1, r1 - str r1, [r0, #0x8] - str r2, [r0, #0xc] - bx lr - - arm_func_start MTX_ScaleApply22 -MTX_ScaleApply22: ; 0x020C3EB0 - stmdb sp!, {lr} - sub sp, sp, #0x4 - ldr r12, [r0, #0x0] - smull lr, r12, r2, r12 - mov lr, lr, lsr #0xc - orr lr, lr, r12, lsl #0x14 - str lr, [r1, #0x0] - ldr r12, [r0, #0x4] - smull lr, r12, r2, r12 - mov r2, lr, lsr #0xc - orr r2, r2, r12, lsl #0x14 - str r2, [r1, #0x4] - ldr r2, [r0, #0x8] - smull r12, r2, r3, r2 - mov r12, r12, lsr #0xc - orr r12, r12, r2, lsl #0x14 - str r12, [r1, #0x8] - ldr r0, [r0, #0xc] - smull r2, r0, r3, r0 - mov r2, r2, lsr #0xc - orr r2, r2, r0, lsl #0x14 - str r2, [r1, #0xc] - add sp, sp, #0x4 - ldmia sp!, {lr} - bx lr 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 diff --git a/include/fx.h b/include/fx.h index 319c823d..bbbf621a 100644 --- a/include/fx.h +++ b/include/fx.h @@ -1,6 +1,11 @@ #ifndef GUARD_FX_H #define GUARD_FX_H +typedef s16 fx16; +typedef s32 fx32; +typedef s64 fx64; +typedef s64 fx64c; + #define FX16_INT_MASK 0xF000 #define FX16_INT_ABS_MASK 0x7000 #define FX16_FRAC_MASK 0x0FFF @@ -59,107 +64,113 @@ #define READREG32(x) (*(vu32 *)x) #define READREG64(x) (*(vu64 *)x) -//TODO: add muladd aund mulsub macros -//need the extra term on mulsub to round up? +#define FX32_MUL(a, b) ((fx32)(((fx64)a * b) >> FX32_INT_SHIFT)) +#define FX32_MUL_ADD_MUL(a, b, c, d) ((fx32)(((fx64)a * b + (fx64)c * d) >> FX32_INT_SHIFT)) +//the extra term here is for rounding +#define FX32_MUL_SUB_MUL(a, b, c, d) ((fx32)(((fx64)a * b - (fx64)c * d + (1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT)) struct Vecx32 { - s32 x; - s32 y; - s32 z; + fx32 x; + fx32 y; + fx32 z; }; struct Vecx16 { - s16 x; - s16 y; - s16 z; + fx16 x; + fx16 y; + fx16 z; }; //Matrices are indexed as [column][row] struct Mtx44 { - s32 _[16]; + fx32 _[16]; }; struct Mtx43 { - s32 _[12]; + fx32 _[12]; }; struct Mtx33 { - s32 _[9]; + fx32 _[9]; }; struct Mtx22 { - s32 _[4]; + fx32 _[4]; }; //FX void FX_Init(); -s32 FX_Modf(s32 x, s32 *iptr); +fx32 FX_Modf(fx32 x, fx32 *iptr); //Atan -u16 FX_Atan(s32 x); -u16 FX_Atan2(s32 x, s32 y); +u16 FX_Atan(fx32 x); +u16 FX_Atan2(fx32 x, fx32 y); //Vec void VEC_Add(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *dst); void VEC_Subtract(struct Vecx32 *x, struct Vecx32 *y, struct Vecx32 *dst); void VEC_Fx16Add(struct Vecx16 *x, struct Vecx16 *y, struct Vecx16 *dst); -s32 VEC_DotProduct(struct Vecx32 *x, struct Vecx32 *y); -s32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b); +fx32 VEC_DotProduct(struct Vecx32 *x, struct Vecx32 *y); +fx32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b); void VEC_CrossProduct(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst); void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst); -s32 VEC_Mag(struct Vecx32 *a); +fx32 VEC_Mag(struct Vecx32 *a); void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst); void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst); -void VEC_MultAdd(s32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst); +void VEC_MultAdd(fx32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst); //CP -s32 FX_Div(s32 numerator, s32 denominator); -s32 FX_Inv(s32 x); -s32 FX_Sqrt(s32 x); -s64 FX_GetDivResultFx64c(); -s32 FX_GetDivResult(); -void FX_InvAsync(s32 x); -s32 FX_GetSqrtResult(); -void FX_DivAsync(s32 numerator, s32 denominator); -s32 FX_DivS32(s32 numerator, s32 denominator); -s32 FX_ModS32(s32 num, s32 mod); +fx32 FX_Div(fx32 numerator, fx32 denominator); +fx32 FX_Inv(fx32 x); +fx32 FX_Sqrt(fx32 x); +fx64 FX_GetDivResultFx64c(); +fx32 FX_GetDivResult(); +void FX_InvAsync(fx32 x); +fx32 FX_GetSqrtResult(); +void FX_DivAsync(fx32 numerator, fx32 denominator); +fx32 FX_Divfx32(fx32 numerator, fx32 denominator); +fx32 FX_Modfx32(fx32 num, fx32 mod); //Mtx //The functions ending in underscores seem to be in assembly originally //Mtx44 -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); void MTX_Concat44(struct Mtx44 *a, struct Mtx44 *b, struct Mtx44 *c); void MTX_Identity44_(struct Mtx44 *dst); void MTX_Copy44To43_(struct Mtx44 *src, struct Mtx43 *dst); -void MTX_RotX44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi); -void MTX_RotY44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi); -void MTX_RotZ44_(struct Mtx44 *mtx, s32 sinphi, s32 cosphi); +void MTX_RotX44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi); +void MTX_RotY44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi); +void MTX_RotZ44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi); //Mtx43 -void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, s32 x, s32 y, s32 z); -s32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv); +void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 z); +fx32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv); void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c); void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32 *dst); void MTX_Identity43_(struct Mtx43 *mtx); void MTX_Copy43To44_(struct Mtx43 *src, struct Mtx44 *dst); -void MTX_Scale43_(struct Mtx43 *dst, s32 x, s32 y, s32 z); -void MTX_RotX43_(struct Mtx43 *mtx, s32 sinphi, s32 cosphi); -void MTX_RotY43_(struct Mtx43 *mtx, s32 sinphi, s32 cosphi); +void MTX_Scale43_(struct Mtx43 *dst, fx32 x, fx32 y, fx32 z); +void MTX_RotX43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi); +void MTX_RotY43_(struct Mtx43 *mtx, fx32 sinphi, fx32 cosphi); //Mtx33 -void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, s32 x, s32 y, s32 z); +void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 z); void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c); void MTX_MultVec33(struct Vecx32 *vec, struct Mtx33 *mtx, struct Vecx32 *dst); void MTX_Identity33_(struct Mtx33 *mtx); -void MTX_RotX33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi); -void MTX_RotY33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi); -void MTX_RotZ33_(struct Mtx33 *mtx, s32 sinphi, s32 cosphi); - +void MTX_RotX33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi); +void MTX_RotY33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi); +void MTX_RotZ33_(struct Mtx33 *mtx, fx32 sinphi, fx32 cosphi); + +//Mtx22 +void MTX_ScaleApply22(struct Mtx22 *mtx, struct Mtx22 *dst, fx32 x, fx32 y); +void MTX_Identity22_(struct Mtx22 *mtx); +void MTX_Rot22_(struct Mtx22 *mtx, fx32 sinphi, fx32 cosphi); #endif //GUARD_FX_H |