mirror of
https://github.com/pret/pmd-sky.git
synced 2026-10-02 07:08:09 -05:00
start moving nitro fx files to src and wire up fx_const generation
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -37,3 +37,6 @@ toolchain_tmp/
|
||||
|
||||
# Windows when copying files
|
||||
*.Identifier
|
||||
|
||||
# Generated files
|
||||
lib/include/nitro/fx/fx_const.h
|
||||
|
||||
15
common.mk
15
common.mk
@@ -70,6 +70,17 @@ NATIVE_TOOLS := \
|
||||
|
||||
TOOLDIRS := $(foreach tool,$(NATIVE_TOOLS),$(dir $(tool)))
|
||||
|
||||
# TODO: move to NitroSDK makefile
|
||||
FX_CONST_H := $(WORK_DIR)/lib/include/nitro/fx/fx_const.h
|
||||
PROJECT_CLEAN_TARGETS += $(FX_CONST_H)
|
||||
$(FX_CONST_H): $(MKFXCONST) $(TOOLSDIR)/gen_fx_consts/fx_const.csv
|
||||
$(MKFXCONST) $@
|
||||
|
||||
# $(ALL_LIB_OBJS): $(FX_CONST_H)
|
||||
# sdk9: $(ALL_LIB_OBJS)
|
||||
# $(WORK_DIR)/include/global.h: $(FX_CONST_H) ;
|
||||
|
||||
|
||||
PRECOMPILE_SRC := include/global.pch
|
||||
PRECOMPILE_OBJ := $(BUILD_DIR)/precompile/global.mch
|
||||
PRECOMPILE_OBJ_BASENAME := global.mch
|
||||
@@ -77,7 +88,7 @@ PRECOMPILE_OBJ_DIR := $(dir $(PRECOMPILE_OBJ))
|
||||
PRECOMPILE_DEPFILE := $(BUILD_DIR)/precompile/global.d
|
||||
|
||||
# Directories
|
||||
NITROSDK_SRC_SUBDIRS := os mi snd fs gx
|
||||
NITROSDK_SRC_SUBDIRS := os mi snd fs gx fx
|
||||
|
||||
LIB_SUBDIRS := DSE NitroSDK MSL_C
|
||||
SRC_SUBDIR := src
|
||||
@@ -196,7 +207,7 @@ ifeq ($(NODEP),)
|
||||
$(PRECOMPILE_DEPFILE):
|
||||
$(DEPFILES):
|
||||
|
||||
$(PRECOMPILE_OBJ): $(PRECOMPILE_SRC)
|
||||
$(PRECOMPILE_OBJ): $(PRECOMPILE_SRC) $(FX_CONST_H)
|
||||
$(MW_COMPILE_SRC_PRECOMPILE) $(PRECOMPILE_SRC) -precompile $(PRECOMPILE_OBJ)
|
||||
@$(call fixdep_precompile,$(PRECOMPILE_DEPFILE))
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "include/fx_vec.inc"
|
||||
|
||||
.text
|
||||
|
||||
arm_func_start FX_Atan2Idx
|
||||
FX_Atan2Idx: ; 0x02075EC8
|
||||
stmdb sp!, {r4, lr}
|
||||
cmp r0, #0
|
||||
ble _02075F5C
|
||||
cmp r1, #0
|
||||
ble _02075F14
|
||||
cmp r1, r0
|
||||
ble _02075EF4
|
||||
mov r2, r0
|
||||
mov r4, #0
|
||||
mov r0, #1
|
||||
b _0207600C
|
||||
_02075EF4:
|
||||
bge _02075F0C
|
||||
mov r2, r1
|
||||
mov r1, r0
|
||||
mov r4, #0x4000
|
||||
mov r0, #0
|
||||
b _0207600C
|
||||
_02075F0C:
|
||||
mov r0, #0x2000
|
||||
ldmia sp!, {r4, pc}
|
||||
_02075F14:
|
||||
bge _02075F54
|
||||
rsb r1, r1, #0
|
||||
cmp r1, r0
|
||||
bge _02075F38
|
||||
mov r2, r1
|
||||
mov r1, r0
|
||||
mov r4, #0x4000
|
||||
mov r0, #1
|
||||
b _0207600C
|
||||
_02075F38:
|
||||
ble _02075F4C
|
||||
mov r2, r0
|
||||
mov r4, #0x8000
|
||||
mov r0, #0
|
||||
b _0207600C
|
||||
_02075F4C:
|
||||
mov r0, #0x6000
|
||||
ldmia sp!, {r4, pc}
|
||||
_02075F54:
|
||||
mov r0, #0x4000
|
||||
ldmia sp!, {r4, pc}
|
||||
_02075F5C:
|
||||
bge _02075FFC
|
||||
cmp r1, #0
|
||||
rsb r0, r0, #0
|
||||
bge _02075FB0
|
||||
rsb r1, r1, #0
|
||||
cmp r1, r0
|
||||
ble _02075F8C
|
||||
mov r4, #0x8000
|
||||
mov r2, r0
|
||||
rsb r4, r4, #0
|
||||
mov r0, #1
|
||||
b _0207600C
|
||||
_02075F8C:
|
||||
bge _02075FA8
|
||||
mov r4, #0x4000
|
||||
mov r2, r1
|
||||
mov r1, r0
|
||||
rsb r4, r4, #0
|
||||
mov r0, #0
|
||||
b _0207600C
|
||||
_02075FA8:
|
||||
mov r0, #0xa000
|
||||
ldmia sp!, {r4, pc}
|
||||
_02075FB0:
|
||||
cmp r1, #0
|
||||
ble _02075FF4
|
||||
cmp r1, r0
|
||||
bge _02075FD8
|
||||
mov r4, #0x4000
|
||||
mov r2, r1
|
||||
mov r1, r0
|
||||
rsb r4, r4, #0
|
||||
mov r0, #1
|
||||
b _0207600C
|
||||
_02075FD8:
|
||||
ble _02075FEC
|
||||
mov r4, #0
|
||||
mov r2, r0
|
||||
mov r0, r4
|
||||
b _0207600C
|
||||
_02075FEC:
|
||||
mov r0, #0xe000
|
||||
ldmia sp!, {r4, pc}
|
||||
_02075FF4:
|
||||
mov r0, #0xc000
|
||||
ldmia sp!, {r4, pc}
|
||||
_02075FFC:
|
||||
cmp r1, #0
|
||||
movge r0, #0
|
||||
movlt r0, #0x8000
|
||||
ldmia sp!, {r4, pc}
|
||||
_0207600C:
|
||||
cmp r1, #0
|
||||
moveq r0, #0
|
||||
ldmeqia sp!, {r4, pc}
|
||||
cmp r0, #0
|
||||
mov r0, r2
|
||||
beq _02076048
|
||||
bl FX_Div
|
||||
mov r1, r0, asr #5
|
||||
ldr r0, _0207606C ; =FX_AtanIdxTable_
|
||||
mov r1, r1, lsl #1
|
||||
ldrsh r0, [r0, r1]
|
||||
add r0, r4, r0
|
||||
mov r0, r0, lsl #0x10
|
||||
mov r0, r0, lsr #0x10
|
||||
ldmia sp!, {r4, pc}
|
||||
_02076048:
|
||||
bl FX_Div
|
||||
mov r1, r0, asr #5
|
||||
ldr r0, _0207606C ; =FX_AtanIdxTable_
|
||||
mov r1, r1, lsl #1
|
||||
ldrsh r0, [r0, r1]
|
||||
sub r0, r4, r0
|
||||
mov r0, r0, lsl #0x10
|
||||
mov r0, r0, lsr #0x10
|
||||
ldmia sp!, {r4, pc}
|
||||
.align 2, 0
|
||||
_0207606C: .word FX_AtanIdxTable_
|
||||
arm_func_end FX_Atan2Idx
|
||||
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "include/fx_cp.inc"
|
||||
|
||||
.text
|
||||
|
||||
arm_func_start FX_Div
|
||||
FX_Div: ; 0x02075B38
|
||||
stmdb sp!, {r3, lr}
|
||||
bl FX_DivAsync
|
||||
bl FX_GetDivResult
|
||||
ldmia sp!, {r3, pc}
|
||||
arm_func_end FX_Div
|
||||
|
||||
arm_func_start FX_GetDivResultFx64c
|
||||
FX_GetDivResultFx64c: ; 0x02075B48
|
||||
ldr r1, _02075B64 ; =0x04000280
|
||||
_02075B4C:
|
||||
ldrh r0, [r1]
|
||||
tst r0, #0x8000
|
||||
bne _02075B4C
|
||||
ldr r1, _02075B68 ; =0x040002A0
|
||||
ldmia r1, {r0, r1}
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_02075B64: .word 0x04000280
|
||||
_02075B68: .word 0x040002A0
|
||||
arm_func_end FX_GetDivResultFx64c
|
||||
|
||||
arm_func_start FX_GetDivResult
|
||||
FX_GetDivResult: ; 0x02075B6C
|
||||
ldr r1, _02075B9C ; =0x04000280
|
||||
_02075B70:
|
||||
ldrh r0, [r1]
|
||||
tst r0, #0x8000
|
||||
bne _02075B70
|
||||
ldr r0, _02075BA0 ; =0x040002A0
|
||||
ldr r1, [r0]
|
||||
ldr r0, [r0, #4]
|
||||
adds r2, r1, #0x80000
|
||||
adc r1, r0, #0
|
||||
mov r0, r2, lsr #0x14
|
||||
orr r0, r0, r1, lsl #12
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_02075B9C: .word 0x04000280
|
||||
_02075BA0: .word 0x040002A0
|
||||
arm_func_end FX_GetDivResult
|
||||
|
||||
arm_func_start FX_InvAsync
|
||||
FX_InvAsync: ; 0x02075BA4
|
||||
ldr r2, _02075BD0 ; =0x04000280
|
||||
mov r1, #1
|
||||
strh r1, [r2]
|
||||
mov r1, #0
|
||||
str r1, [r2, #0x10]
|
||||
mov r1, #0x1000
|
||||
str r1, [r2, #0x14]
|
||||
str r0, [r2, #0x18]
|
||||
mov r0, #0
|
||||
str r0, [r2, #0x1c]
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_02075BD0: .word 0x04000280
|
||||
arm_func_end FX_InvAsync
|
||||
|
||||
arm_func_start FX_DivAsync
|
||||
FX_DivAsync: ; 0x02075BD4
|
||||
ldr r3, _02075BF8 ; =0x04000280
|
||||
mov r2, #1
|
||||
strh r2, [r3]
|
||||
mov r2, #0
|
||||
str r2, [r3, #0x10]
|
||||
str r0, [r3, #0x14]
|
||||
str r1, [r3, #0x18]
|
||||
str r2, [r3, #0x1c]
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_02075BF8: .word 0x04000280
|
||||
arm_func_end FX_DivAsync
|
||||
|
||||
arm_func_start FX_DivS32
|
||||
FX_DivS32: ; 0x02075BFC
|
||||
ldr r2, _02075C30 ; =0x04000280
|
||||
mov r3, #0
|
||||
strh r3, [r2]
|
||||
str r0, [r2, #0x10]
|
||||
str r1, [r2, #0x18]
|
||||
mov r0, r3
|
||||
str r0, [r2, #0x1c]
|
||||
_02075C18:
|
||||
ldrh r0, [r2]
|
||||
tst r0, #0x8000
|
||||
bne _02075C18
|
||||
ldr r0, _02075C34 ; =0x040002A0
|
||||
ldr r0, [r0]
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_02075C30: .word 0x04000280
|
||||
_02075C34: .word 0x040002A0
|
||||
arm_func_end FX_DivS32
|
||||
|
||||
arm_func_start FX_ModS32
|
||||
FX_ModS32: ; 0x02075C38
|
||||
ldr r2, _02075C6C ; =0x04000280
|
||||
mov r3, #0
|
||||
strh r3, [r2]
|
||||
str r0, [r2, #0x10]
|
||||
str r1, [r2, #0x18]
|
||||
mov r0, r3
|
||||
str r0, [r2, #0x1c]
|
||||
_02075C54:
|
||||
ldrh r0, [r2]
|
||||
tst r0, #0x8000
|
||||
bne _02075C54
|
||||
ldr r0, _02075C70 ; =0x040002A8
|
||||
ldr r0, [r0]
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_02075C6C: .word 0x04000280
|
||||
_02075C70: .word 0x040002A8
|
||||
arm_func_end FX_ModS32
|
||||
251
lib/NitroSDK/src/fx/fx_atanidx.c
Normal file
251
lib/NitroSDK/src/fx/fx_atanidx.c
Normal file
@@ -0,0 +1,251 @@
|
||||
#include <nitro.h>
|
||||
#include <nitro/fx/fx_trig.h>
|
||||
// #include <nitro/fx/fx_cp.h>
|
||||
// #include <nitro/fx/fx_const.h>
|
||||
|
||||
|
||||
extern fx16 FX_AtanIdxTable_[128 + 1];
|
||||
|
||||
extern fx32 FX_Div (fx32 numer, fx32 denom);
|
||||
|
||||
// const fx16 FX_AtanIdxTable_[128 + 1] = {
|
||||
// (u16)0,
|
||||
// (u16)81,
|
||||
// (u16)163,
|
||||
// (u16)244,
|
||||
// (u16)326,
|
||||
// (u16)407,
|
||||
// (u16)489,
|
||||
// (u16)570,
|
||||
// (u16)651,
|
||||
// (u16)732,
|
||||
// (u16)813,
|
||||
// (u16)894,
|
||||
// (u16)975,
|
||||
// (u16)1056,
|
||||
// (u16)1136,
|
||||
// (u16)1217,
|
||||
// (u16)1297,
|
||||
// (u16)1377,
|
||||
// (u16)1457,
|
||||
// (u16)1537,
|
||||
// (u16)1617,
|
||||
// (u16)1696,
|
||||
// (u16)1775,
|
||||
// (u16)1854,
|
||||
// (u16)1933,
|
||||
// (u16)2012,
|
||||
// (u16)2090,
|
||||
// (u16)2168,
|
||||
// (u16)2246,
|
||||
// (u16)2324,
|
||||
// (u16)2401,
|
||||
// (u16)2478,
|
||||
// (u16)2555,
|
||||
// (u16)2632,
|
||||
// (u16)2708,
|
||||
// (u16)2784,
|
||||
// (u16)2860,
|
||||
// (u16)2935,
|
||||
// (u16)3010,
|
||||
// (u16)3085,
|
||||
// (u16)3159,
|
||||
// (u16)3233,
|
||||
// (u16)3307,
|
||||
// (u16)3380,
|
||||
// (u16)3453,
|
||||
// (u16)3526,
|
||||
// (u16)3599,
|
||||
// (u16)3670,
|
||||
// (u16)3742,
|
||||
// (u16)3813,
|
||||
// (u16)3884,
|
||||
// (u16)3955,
|
||||
// (u16)4025,
|
||||
// (u16)4095,
|
||||
// (u16)4164,
|
||||
// (u16)4233,
|
||||
// (u16)4302,
|
||||
// (u16)4370,
|
||||
// (u16)4438,
|
||||
// (u16)4505,
|
||||
// (u16)4572,
|
||||
// (u16)4639,
|
||||
// (u16)4705,
|
||||
// (u16)4771,
|
||||
// (u16)4836,
|
||||
// (u16)4901,
|
||||
// (u16)4966,
|
||||
// (u16)5030,
|
||||
// (u16)5094,
|
||||
// (u16)5157,
|
||||
// (u16)5220,
|
||||
// (u16)5282,
|
||||
// (u16)5344,
|
||||
// (u16)5406,
|
||||
// (u16)5467,
|
||||
// (u16)5528,
|
||||
// (u16)5589,
|
||||
// (u16)5649,
|
||||
// (u16)5708,
|
||||
// (u16)5768,
|
||||
// (u16)5826,
|
||||
// (u16)5885,
|
||||
// (u16)5943,
|
||||
// (u16)6000,
|
||||
// (u16)6058,
|
||||
// (u16)6114,
|
||||
// (u16)6171,
|
||||
// (u16)6227,
|
||||
// (u16)6282,
|
||||
// (u16)6337,
|
||||
// (u16)6392,
|
||||
// (u16)6446,
|
||||
// (u16)6500,
|
||||
// (u16)6554,
|
||||
// (u16)6607,
|
||||
// (u16)6660,
|
||||
// (u16)6712,
|
||||
// (u16)6764,
|
||||
// (u16)6815,
|
||||
// (u16)6867,
|
||||
// (u16)6917,
|
||||
// (u16)6968,
|
||||
// (u16)7018,
|
||||
// (u16)7068,
|
||||
// (u16)7117,
|
||||
// (u16)7166,
|
||||
// (u16)7214,
|
||||
// (u16)7262,
|
||||
// (u16)7310,
|
||||
// (u16)7358,
|
||||
// (u16)7405,
|
||||
// (u16)7451,
|
||||
// (u16)7498,
|
||||
// (u16)7544,
|
||||
// (u16)7589,
|
||||
// (u16)7635,
|
||||
// (u16)7679,
|
||||
// (u16)7724,
|
||||
// (u16)7768,
|
||||
// (u16)7812,
|
||||
// (u16)7856,
|
||||
// (u16)7899,
|
||||
// (u16)7942,
|
||||
// (u16)7984,
|
||||
// (u16)8026,
|
||||
// (u16)8068,
|
||||
// (u16)8110,
|
||||
// (u16)8151,
|
||||
// (u16)8192
|
||||
// };
|
||||
|
||||
// u16 FX_AtanIdx (fx32 x)
|
||||
// {
|
||||
// if (x >= 0) {
|
||||
// if (x > FX32_ONE) {
|
||||
// return (u16)(16384 - FX_AtanIdxTable_[FX_Inv(x) >> 5]);
|
||||
// } else if (x < FX32_ONE) {
|
||||
// return (u16)FX_AtanIdxTable_[x >> 5];
|
||||
// } else {
|
||||
// return (u16)8192;
|
||||
// }
|
||||
// } else {
|
||||
// if (x < -FX32_ONE) {
|
||||
// return (u16)(-16384 + FX_AtanIdxTable_[FX_Inv(-x) >> 5]);
|
||||
// } else if (x > -FX32_ONE) {
|
||||
// return (u16) - FX_AtanIdxTable_[-x >> 5];
|
||||
// } else {
|
||||
// return (u16) - 8192;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
u16 FX_Atan2Idx (fx32 y, fx32 x)
|
||||
{
|
||||
fx32 a, b;
|
||||
int c;
|
||||
int sgn;
|
||||
|
||||
if (y > 0) {
|
||||
if (x > 0) {
|
||||
if (x > y) {
|
||||
a = y;
|
||||
b = x;
|
||||
c = 0;
|
||||
sgn = 1;
|
||||
} else if (x < y) {
|
||||
a = x;
|
||||
b = y;
|
||||
c = 16384;
|
||||
sgn = 0;
|
||||
} else {
|
||||
return (u16)8192;
|
||||
}
|
||||
} else if (x < 0) {
|
||||
x = -x;
|
||||
if (x < y) {
|
||||
a = x;
|
||||
b = y;
|
||||
c = 16384;
|
||||
sgn = 1;
|
||||
} else if (x > y) {
|
||||
a = y;
|
||||
b = x;
|
||||
c = 32768;
|
||||
sgn = 0;
|
||||
} else {
|
||||
return (u16)24576;
|
||||
}
|
||||
} else {
|
||||
return (u16)16384;
|
||||
}
|
||||
} else if (y < 0) {
|
||||
y = -y;
|
||||
if (x < 0) {
|
||||
x = -x;
|
||||
if (x > y) {
|
||||
a = y;
|
||||
b = x;
|
||||
c = -32768;
|
||||
sgn = 1;
|
||||
} else if (x < y) {
|
||||
a = x;
|
||||
b = y;
|
||||
c = -16384;
|
||||
sgn = 0;
|
||||
} else {
|
||||
return (u16) - 24576;
|
||||
}
|
||||
} else if (x > 0) {
|
||||
if (x < y) {
|
||||
a = x;
|
||||
b = y;
|
||||
c = -16384;
|
||||
sgn = 1;
|
||||
} else if (x > y) {
|
||||
a = y;
|
||||
b = x;
|
||||
c = 0;
|
||||
sgn = 0;
|
||||
} else {
|
||||
return (u16) - 8192;
|
||||
}
|
||||
} else {
|
||||
return (u16) - 16384;
|
||||
}
|
||||
} else {
|
||||
if (x >= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return (u16)32768;
|
||||
}
|
||||
}
|
||||
|
||||
if (b == 0)
|
||||
return 0;
|
||||
if (sgn)
|
||||
return (u16)(c + FX_AtanIdxTable_[FX_Div(a, b) >> 5]);
|
||||
else
|
||||
return (u16)(c - FX_AtanIdxTable_[FX_Div(a, b) >> 5]);
|
||||
}
|
||||
135
lib/NitroSDK/src/fx/fx_cp.c
Normal file
135
lib/NitroSDK/src/fx/fx_cp.c
Normal file
@@ -0,0 +1,135 @@
|
||||
#include <nitro.h>
|
||||
#include <nitro/fx/fx_cp.h>
|
||||
|
||||
#define FX_DIV_SHIFT (32 - FX32_SHIFT)
|
||||
#define FX_DIV_1_2 (1 << (FX_DIV_SHIFT - 1))
|
||||
|
||||
#define FX_SQRT_SHIFT ((32 + FX32_SHIFT) / 2 - FX32_SHIFT)
|
||||
#define FX_SQRT_1_2 (1 << (FX_SQRT_SHIFT - 1))
|
||||
|
||||
#define FX_INVSQRT_SHIFT (FX64C_SHIFT + ((32 + FX32_SHIFT) / 2 - FX32_SHIFT))
|
||||
#define FX_INVSQRT_1_2 (1LL << (FX_INVSQRT_SHIFT - 1))
|
||||
|
||||
fx32 FX_Div (fx32 numer, fx32 denom)
|
||||
{
|
||||
FX_DivAsync(numer, denom);
|
||||
return FX_GetDivResult();
|
||||
}
|
||||
|
||||
// fx64c FX_DivFx64c (fx32 numer, fx32 denom)
|
||||
// {
|
||||
// FX_DivAsync(numer, denom);
|
||||
// return (fx64c)CP_GetDivResult64();
|
||||
// }
|
||||
//
|
||||
// fx32 FX_Inv (fx32 denom)
|
||||
// {
|
||||
// FX_InvAsync(denom);
|
||||
// return FX_GetDivResult();
|
||||
// }
|
||||
//
|
||||
// fx64c FX_InvFx64c (fx32 denom)
|
||||
// {
|
||||
// FX_InvAsync(denom);
|
||||
// return (fx64c)CP_GetDivResult64();
|
||||
// }
|
||||
//
|
||||
// fx32 FX_Sqrt (fx32 x)
|
||||
// {
|
||||
// SDK_ASSERT(!CP_IsSqrtBusy());
|
||||
//
|
||||
// if (x > 0) {
|
||||
// CP_SetSqrt64((u64)x << 32);
|
||||
// return FX_GetSqrtResult();
|
||||
// } else {
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fx32 FX_InvSqrt (fx32 x)
|
||||
// {
|
||||
// if (x > 0) {
|
||||
// fx64c inv_x;
|
||||
// s64 sqrt_x;
|
||||
// s64 tmp;
|
||||
//
|
||||
// FX_InvAsync(x);
|
||||
// FX_SqrtAsync(x);
|
||||
//
|
||||
// inv_x = FX_GetInvResultFx64c();
|
||||
// sqrt_x = CP_GetSqrtResult32();
|
||||
// tmp = inv_x * sqrt_x;
|
||||
// return (fx32)((tmp + FX_INVSQRT_1_2) >> FX_INVSQRT_SHIFT);
|
||||
// } else {
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
fx64c FX_GetDivResultFx64c (void)
|
||||
{
|
||||
return (fx64c)CP_GetDivResult64();
|
||||
}
|
||||
|
||||
fx32 FX_GetDivResult (void)
|
||||
{
|
||||
return (fx32)((CP_GetDivResult64() + FX_DIV_1_2) >> FX_DIV_SHIFT);
|
||||
}
|
||||
|
||||
void FX_InvAsync (fx32 denom)
|
||||
{
|
||||
SDK_ASSERT(!CP_IsDivBusy());
|
||||
FX_DIVISION_BY_ZERO(FX32_ONE, denom);
|
||||
|
||||
CP_SetDiv64_32((u64)FX32_ONE << 32, (u32)denom);
|
||||
}
|
||||
|
||||
// void FX_SqrtAsync (fx32 x)
|
||||
// {
|
||||
// SDK_ASSERT(!CP_IsSqrtBusy());
|
||||
// if (x > 0) {
|
||||
// CP_SetSqrt64((u64)x << 32);
|
||||
// } else {
|
||||
// CP_SetSqrt64(0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void FX_SqrtAsyncImm (fx32 x)
|
||||
// {
|
||||
// SDK_ASSERT(!CP_IsSqrtBusy());
|
||||
// if (x > 0) {
|
||||
// CP_SetSqrtImm64((u64)x << 32);
|
||||
// } else {
|
||||
// CP_SetSqrtImm64(0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fx32 FX_GetSqrtResult (void)
|
||||
// {
|
||||
// return (fx32)((CP_GetSqrtResult32() + FX_SQRT_1_2) >> FX_SQRT_SHIFT);
|
||||
// }
|
||||
|
||||
void FX_DivAsync (fx32 numer, fx32 denom)
|
||||
{
|
||||
SDK_ASSERT(!CP_IsDivBusy());
|
||||
FX_DIVISION_BY_ZERO(numer, denom);
|
||||
|
||||
CP_SetDiv64_32((u64)numer << 32, (u32)denom);
|
||||
}
|
||||
|
||||
s32 FX_DivS32 (s32 a, s32 b)
|
||||
{
|
||||
SDK_ASSERT(!CP_IsDivBusy());
|
||||
FX_DIVISION_BY_ZERO(a, b);
|
||||
|
||||
CP_SetDiv32_32((u32)a, (u32)b);
|
||||
return CP_GetDivResult32();
|
||||
}
|
||||
|
||||
s32 FX_ModS32 (s32 a, s32 b)
|
||||
{
|
||||
SDK_ASSERT(!CP_IsDivBusy());
|
||||
FX_DIVISION_BY_ZERO(a, b);
|
||||
|
||||
CP_SetDiv32_32((u32)a, (u32)b);
|
||||
return CP_GetDivRemainder32();
|
||||
}
|
||||
@@ -2,5 +2,7 @@
|
||||
#define NITRO_CP_H_
|
||||
|
||||
#include <nitro/cp/context.h>
|
||||
#include <nitro/cp/divider.h>
|
||||
#include <nitro/cp/sqrt.h>
|
||||
|
||||
#endif //NITRO_CP_H_
|
||||
|
||||
173
lib/include/nitro/cp/divider.h
Normal file
173
lib/include/nitro/cp/divider.h
Normal file
@@ -0,0 +1,173 @@
|
||||
#ifndef NITRO_CP_DIVIDER_H_
|
||||
#define NITRO_CP_DIVIDER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <nitro/hw/io_reg.h>
|
||||
|
||||
#define CP_DIV_32_32BIT_MODE (0UL << REG_CP_DIVCNT_MODE_SHIFT)
|
||||
#define CP_DIV_64_32BIT_MODE (1UL << REG_CP_DIVCNT_MODE_SHIFT)
|
||||
#define CP_DIV_64_64BIT_MODE (2UL << REG_CP_DIVCNT_MODE_SHIFT)
|
||||
|
||||
static inline void CP_SetDivControl (u16 parameter)
|
||||
{
|
||||
reg_CP_DIVCNT = parameter;
|
||||
}
|
||||
|
||||
static inline void CP_SetDivImm32_32_NS_ (u32 numer, u32 denom)
|
||||
{
|
||||
*(REGType32 *)REG_DIV_NUMER_ADDR = numer;
|
||||
*(REGType64 *)REG_DIV_DENOM_ADDR = denom;
|
||||
}
|
||||
|
||||
static inline void CP_SetDivImm64_32_NS_ (u64 numer, u32 denom)
|
||||
{
|
||||
*(REGType64 *)REG_DIV_NUMER_ADDR = numer;
|
||||
*(REGType64 *)REG_DIV_DENOM_ADDR = denom;
|
||||
}
|
||||
|
||||
static inline void CP_SetDivImm64_64_NS_ (u64 numer, u64 denom)
|
||||
{
|
||||
*(REGType64 *)REG_DIV_NUMER_ADDR = numer;
|
||||
*(REGType64 *)REG_DIV_DENOM_ADDR = denom;
|
||||
}
|
||||
|
||||
static inline void CP_SetDivImm32_32 (u32 numer, u32 denom)
|
||||
{
|
||||
CP_SetDivImm32_32_NS_(numer, denom);
|
||||
}
|
||||
|
||||
static inline void CP_SetDivImm64_32 (u64 numer, u32 denom)
|
||||
{
|
||||
CP_SetDivImm64_32_NS_(numer, denom);
|
||||
}
|
||||
|
||||
static inline void CP_SetDivImm64_64 (u64 numer, u64 denom)
|
||||
{
|
||||
CP_SetDivImm64_64_NS_(numer, denom);
|
||||
}
|
||||
|
||||
static inline void CP_SetDiv32_32 (u32 numer, u32 denom)
|
||||
{
|
||||
reg_CP_DIVCNT = CP_DIV_32_32BIT_MODE;
|
||||
CP_SetDivImm32_32_NS_(numer, denom);
|
||||
}
|
||||
|
||||
static inline void CP_SetDiv64_32 (u64 numer, u32 denom)
|
||||
{
|
||||
reg_CP_DIVCNT = CP_DIV_64_32BIT_MODE;
|
||||
CP_SetDivImm64_32_NS_(numer, denom);
|
||||
}
|
||||
|
||||
static inline void CP_SetDiv64_64 (u64 numer, u64 denom)
|
||||
{
|
||||
reg_CP_DIVCNT = CP_DIV_64_64BIT_MODE;
|
||||
CP_SetDivImm64_64_NS_(numer, denom);
|
||||
}
|
||||
|
||||
static inline s32 CP_IsDivBusy (void)
|
||||
{
|
||||
return (reg_CP_DIVCNT & REG_CP_DIVCNT_BUSY_MASK);
|
||||
}
|
||||
|
||||
static inline void CP_WaitDiv (void)
|
||||
{
|
||||
while (CP_IsDivBusy()) {
|
||||
}
|
||||
}
|
||||
|
||||
static inline s64 CP_GetDivResultImm64 (void)
|
||||
{
|
||||
return (s64)(*(REGType64 *)REG_DIV_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s32 CP_GetDivResultImm32 (void)
|
||||
{
|
||||
return (s32)(*(REGType32 *)REG_DIV_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s16 CP_GetDivResultImm16 (void)
|
||||
{
|
||||
return (s16)(*(REGType16 *)REG_DIV_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s8 CP_GetDivResultImm8 (void)
|
||||
{
|
||||
return (s8)(*(REGType8 *)REG_DIV_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s64 CP_GetDivResult64 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivResultImm64();
|
||||
}
|
||||
|
||||
static inline s32 CP_GetDivResult32 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivResultImm32();
|
||||
}
|
||||
|
||||
static inline s16 CP_GetDivResult16 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivResultImm16();
|
||||
}
|
||||
|
||||
static inline s8 CP_GetDivResult8 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivResultImm8();
|
||||
}
|
||||
|
||||
static inline s64 CP_GetDivRemainderImm64 (void)
|
||||
{
|
||||
return (s64)(*(REGType64 *)REG_DIVREM_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s32 CP_GetDivRemainderImm32 (void)
|
||||
{
|
||||
return (s32)(*(REGType32 *)REG_DIVREM_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s16 CP_GetDivRemainderImm16 (void)
|
||||
{
|
||||
return (s16)(*(REGType16 *)REG_DIVREM_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s8 CP_GetDivRemainderImm8 (void)
|
||||
{
|
||||
return (s8)(*(REGType8 *)REG_DIVREM_RESULT_ADDR);
|
||||
}
|
||||
|
||||
static inline s64 CP_GetDivRemainder64 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivRemainderImm64();
|
||||
}
|
||||
|
||||
static inline s32 CP_GetDivRemainder32 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivRemainderImm32();
|
||||
}
|
||||
|
||||
static inline s16 CP_GetDivRemainder16 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivRemainderImm16();
|
||||
}
|
||||
|
||||
static inline s8 CP_GetDivRemainder8 (void)
|
||||
{
|
||||
CP_WaitDiv();
|
||||
return CP_GetDivRemainderImm8();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
98
lib/include/nitro/cp/sqrt.h
Normal file
98
lib/include/nitro/cp/sqrt.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#ifndef NITRO_CP_SQRT_H_
|
||||
#define NITRO_CP_SQRT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <nitro/cp/context.h>
|
||||
|
||||
#define CP_SQRT_32BIT_MODE (0UL << REG_CP_SQRTCNT_MODE_SHIFT)
|
||||
#define CP_SQRT_64BIT_MODE (1UL << REG_CP_SQRTCNT_MODE_SHIFT)
|
||||
|
||||
static inline void CP_SetSqrtControl (u16 param)
|
||||
{
|
||||
reg_CP_SQRTCNT = param;
|
||||
}
|
||||
|
||||
static inline void CP_SetSqrtImm64_NS_ (u64 param)
|
||||
{
|
||||
*((REGType64 *)REG_SQRT_PARAM_ADDR) = param;
|
||||
}
|
||||
|
||||
static inline void CP_SetSqrtImm32_NS_ (u32 param)
|
||||
{
|
||||
*((REGType32 *)REG_SQRT_PARAM_ADDR) = param;
|
||||
}
|
||||
|
||||
static inline void CP_SetSqrtImm64 (u64 param)
|
||||
{
|
||||
*((REGType64 *)REG_SQRT_PARAM_ADDR) = param;
|
||||
}
|
||||
|
||||
static inline void CP_SetSqrtImm32 (u32 param)
|
||||
{
|
||||
*((REGType32 *)REG_SQRT_PARAM_ADDR) = param;
|
||||
}
|
||||
|
||||
static inline void CP_SetSqrt64 (u64 param)
|
||||
{
|
||||
reg_CP_SQRTCNT = CP_SQRT_64BIT_MODE;
|
||||
CP_SetSqrtImm64_NS_(param);
|
||||
}
|
||||
|
||||
static inline void CP_SetSqrt32 (u32 param)
|
||||
{
|
||||
reg_CP_SQRTCNT = CP_SQRT_32BIT_MODE;
|
||||
CP_SetSqrtImm32_NS_(param);
|
||||
}
|
||||
|
||||
static inline s32 CP_IsSqrtBusy (void)
|
||||
{
|
||||
return (reg_CP_SQRTCNT & REG_CP_SQRTCNT_BUSY_MASK);
|
||||
}
|
||||
|
||||
static inline void CP_WaitSqrt (void)
|
||||
{
|
||||
while (CP_IsSqrtBusy()) {
|
||||
}
|
||||
}
|
||||
|
||||
static inline u32 CP_GetSqrtResultImm32 (void)
|
||||
{
|
||||
return (u32)(*((REGType32 *)REG_SQRT_RESULT_ADDR));
|
||||
}
|
||||
|
||||
static inline u16 CP_GetSqrtResultImm16 (void)
|
||||
{
|
||||
return (u16)(*((REGType16 *)REG_SQRT_RESULT_ADDR));
|
||||
}
|
||||
|
||||
static inline u8 CP_GetSqrtResultImm8 (void)
|
||||
{
|
||||
return (u8)(*((REGType8 *)REG_SQRT_RESULT_ADDR));
|
||||
}
|
||||
|
||||
static inline u32 CP_GetSqrtResult32 (void)
|
||||
{
|
||||
CP_WaitSqrt();
|
||||
return CP_GetSqrtResultImm32();
|
||||
}
|
||||
|
||||
static inline u16 CP_GetSqrtResult16 (void)
|
||||
{
|
||||
CP_WaitSqrt();
|
||||
return CP_GetSqrtResultImm16();
|
||||
}
|
||||
|
||||
static inline u8 CP_GetSqrtResult8 (void)
|
||||
{
|
||||
CP_WaitSqrt();
|
||||
return CP_GetSqrtResultImm8();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
78
lib/include/nitro/fx/fx_cp.h
Normal file
78
lib/include/nitro/fx/fx_cp.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef NITRO_FX_CP_H_
|
||||
#define NITRO_FX_CP_H_
|
||||
|
||||
#include <nitro/fx/fx.h>
|
||||
#include <nitro/fx/fx_const.h>
|
||||
#include <nitro/cp/divider.h>
|
||||
#include <nitro/cp/sqrt.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
fx32 FX_Div(fx32 numer, fx32 denom);
|
||||
fx64c FX_DivFx64c(fx32 numer, fx32 denom);
|
||||
SDK_DECL_INLINE fx32 FX_Mod(fx32 numer, fx32 denom);
|
||||
fx32 FX_Sqrt(fx32 x);
|
||||
fx32 FX_Inv(fx32 denom);
|
||||
fx64c FX_InvFx64c(fx32 denom);
|
||||
fx32 FX_InvSqrt(fx32 x);
|
||||
|
||||
void FX_DivAsync(fx32 numer, fx32 denom);
|
||||
SDK_DECL_INLINE void FX_DivAsyncImm(fx32 numer, fx32 denom);
|
||||
fx64c FX_GetDivResultFx64c(void);
|
||||
fx32 FX_GetDivResult(void);
|
||||
fx64c FX_GetDivRemainderFx64c(void);
|
||||
fx32 FX_GetDivRemainder(void);
|
||||
|
||||
void FX_InvAsync(fx32 denom);
|
||||
SDK_DECL_INLINE void FX_InvAsyncImm(fx32 denom);
|
||||
SDK_DECL_INLINE fx64c FX_GetInvResultFx64c(void);
|
||||
SDK_DECL_INLINE fx32 FX_GetInvResult(void);
|
||||
|
||||
void FX_SqrtAsync(fx32 x);
|
||||
void FX_SqrtAsyncImm(fx32 x);
|
||||
fx32 FX_GetSqrtResult(void);
|
||||
|
||||
s32 FX_DivS32(s32 a, s32 b);
|
||||
s32 FX_ModS32(s32 a, s32 b);
|
||||
|
||||
#define FX_DIVISION_BY_ZERO(a, b) \
|
||||
SDK_WARNING(b != 0, "Division by zero(%d / %d)", a, b)
|
||||
|
||||
// SDK_INLINE void FX_InvAsyncImm (fx32 denom)
|
||||
// {
|
||||
// SDK_ASSERT(!CP_IsDivBusy());
|
||||
// FX_DIVISION_BY_ZERO(FX32_ONE, denom);
|
||||
//
|
||||
// CP_SetDivImm64_32((u64)FX32_ONE << 32, (u32)denom);
|
||||
// }
|
||||
|
||||
SDK_INLINE fx64c FX_GetInvResultFx64c (void)
|
||||
{
|
||||
return FX_GetDivResultFx64c();
|
||||
}
|
||||
|
||||
SDK_INLINE fx32 FX_GetInvResult (void)
|
||||
{
|
||||
return FX_GetDivResult();
|
||||
}
|
||||
|
||||
// SDK_INLINE void FX_DivAsyncImm (fx32 numer, fx32 denom)
|
||||
// {
|
||||
// SDK_ASSERT(!CP_IsDivBusy());
|
||||
// FX_DIVISION_BY_ZERO(numer, denom);
|
||||
//
|
||||
// CP_SetDivImm64_32((u64)numer << 32, (u32)denom);
|
||||
// }
|
||||
|
||||
SDK_INLINE fx32 FX_Mod (fx32 numer, fx32 denom)
|
||||
{
|
||||
return (fx32)FX_ModS32(numer, denom);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
56
lib/include/nitro/fx/fx_trig.h
Normal file
56
lib/include/nitro/fx/fx_trig.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef NITRO_FXTRIG_H_
|
||||
#define NITRO_FXTRIG_H_
|
||||
|
||||
#include <nitro/fx/fx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SDK_FX_DYNAMIC_TABLE
|
||||
extern fx16 FX_SinCosTable_[];
|
||||
#else
|
||||
extern const fx16 FX_SinCosTable_[];
|
||||
#endif
|
||||
|
||||
#define FX_DEG_TO_RAD(deg) ((fx32)((FX64C_TWOPI_360 * (deg) + 0x80000000LL) >> 32))
|
||||
#define FX_DEG_TO_IDX(deg) ((u16) ((FX64C_65536_360 * (deg) + 0x80000000000LL) >> 44))
|
||||
|
||||
#define FX_RAD_TO_DEG(rad) ((fx32)((FX64C_360_TWOPI * (rad) + 0x80000000LL) >> 32))
|
||||
#define FX_RAD_TO_IDX(rad) ((u16)((FX64C_65536_TWOPI * (rad) + 0x80000000000LL) >> 44))
|
||||
|
||||
#define FX_IDX_TO_RAD(idx) ((fx32)((FX64C_TWOPI_65536 * (idx) + 0x80000LL) >> 20))
|
||||
#define FX_IDX_TO_DEG(idx) ((fx32)((FX64C_360_65536 * (idx) + 0x80000LL) >> 20))
|
||||
|
||||
SDK_DECL_INLINE fx16 FX_SinIdx(int idx);
|
||||
SDK_DECL_INLINE fx16 FX_CosIdx(int idx);
|
||||
|
||||
u16 FX_AtanIdx(fx32 x);
|
||||
u16 FX_Atan2Idx(fx32 y, fx32 x);
|
||||
|
||||
fx16 FX_Atan(fx32 x);
|
||||
fx16 FX_Atan2(fx32 y, fx32 x);
|
||||
|
||||
u16 FX_AsinIdx(fx32 x);
|
||||
u16 FX_AcosIdx(fx32 x);
|
||||
|
||||
fx64c FX_SinFx64c(fx32 rad);
|
||||
fx64c FX_CosFx64c(fx32 rad);
|
||||
|
||||
SDK_INLINE fx16 FX_SinIdx (int idx)
|
||||
{
|
||||
SDK_MINMAX_ASSERT(idx, 0, 65535);
|
||||
return FX_SinCosTable_[((idx >> 4) << 1)];
|
||||
}
|
||||
|
||||
SDK_INLINE fx16 FX_CosIdx (int idx)
|
||||
{
|
||||
SDK_MINMAX_ASSERT(idx, 0, 65535);
|
||||
return FX_SinCosTable_[((idx >> 4) << 1) + 1];
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -52,5 +52,9 @@ typedef int BOOL;
|
||||
#endif
|
||||
|
||||
#define SDK_FORCE_EXPORT __declspec(force_export)
|
||||
|
||||
#define SDK_INLINE static inline
|
||||
#define SDK_DECL_INLINE static
|
||||
|
||||
#endif //SDK_ASM
|
||||
#endif //NITRO_TYPES_H_
|
||||
|
||||
4
main.lsf
4
main.lsf
@@ -225,9 +225,9 @@ Static main
|
||||
|
||||
### NitroSDK ###
|
||||
Object lib/NitroSDK/asm/mtx.o
|
||||
Object lib/NitroSDK/asm/fx_cp.o
|
||||
Object lib/NitroSDK/src/fx/fx_cp.o
|
||||
Object lib/NitroSDK/asm/fx_vec.o
|
||||
Object lib/NitroSDK/asm/fx_atanidx.o
|
||||
Object lib/NitroSDK/src/fx/fx_atanidx.o
|
||||
Object lib/NitroSDK/asm/fx_fx.o
|
||||
Object lib/NitroSDK/asm/gx.o
|
||||
Object lib/NitroSDK/asm/gxstate.o
|
||||
|
||||
Reference in New Issue
Block a user