From d2c181a0a99430cd9893b022bd179cffc11dbbba Mon Sep 17 00:00:00 2001 From: Rozelette Date: Wed, 7 Apr 2021 16:16:16 -0500 Subject: [PATCH] z_lib fully matched (#85) * z_lib OK * Documentation * Added stdbool and stdint * Fixup for new names * Fixup bad merge * Feedback * Use u/s32 for intptr_t --- include/convert.h | 4 +- include/functions.h | 100 +-- include/guint.h | 28 - include/macros.h | 9 +- include/math.h | 29 + include/stdbool.h | 7 + include/stdint.h | 29 + include/variables.h | 2 +- include/z64.h | 8 +- linker_scripts/code_script.txt | 4 +- src/code/code_0x800E8EA0.c | 14 +- src/code/z_actor.c | 8 +- src/code/z_effect_soft_sprite_old_init.c | 2 +- src/code/z_en_item00.c | 14 +- src/code/z_lib.c | 620 ++++++++++-------- src/code/z_room.c | 2 +- src/code/z_scene.c | 46 +- src/code/z_scene_proc.c | 18 +- src/code/z_skelanime.c | 62 +- src/libultra/gu/sinf.c | 2 +- src/libultra/gu/sins.c | 2 +- src/libultra/os/virtualtophysical.c | 12 +- .../ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c | 4 +- .../actors/ovl_Bg_Ikana_Ray/z_bg_ikana_ray.c | 2 +- .../ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c | 8 +- src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c | 2 +- .../actors/ovl_En_Dy_Extra/z_en_dy_extra.c | 6 +- .../ovl_En_Ending_Hero/z_en_ending_hero.c | 4 +- .../actors/ovl_En_Po_Fusen/z_en_po_fusen.c | 4 +- src/overlays/actors/ovl_En_Rsn/z_en_rsn.c | 2 +- .../actors/ovl_En_Scopecoin/z_en_scopecoin.c | 2 +- .../actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c | 4 +- tables/functions.txt | 56 +- tables/variables.txt | 2 +- 34 files changed, 626 insertions(+), 492 deletions(-) delete mode 100644 include/guint.h create mode 100644 include/math.h create mode 100644 include/stdbool.h create mode 100644 include/stdint.h diff --git a/include/convert.h b/include/convert.h index 20ee30130a..31bdb034f7 100644 --- a/include/convert.h +++ b/include/convert.h @@ -18,7 +18,7 @@ /* Functions */ -extern u32 osVirtualToPhysical(void*); -extern void* osPhysicalToVirtual(u32); +extern uintptr_t osVirtualToPhysical(void*); +extern void* osPhysicalToVirtual(uintptr_t); #endif diff --git a/include/functions.h b/include/functions.h index 22304d5429..17b8f5ef5f 100644 --- a/include/functions.h +++ b/include/functions.h @@ -312,7 +312,7 @@ s32 osContStartReadData(OSMesgQueue* mq); void osContGetReadData(OSContPad* data); void __osPackReadData(void); // void func_8008A170(void); -u32 osVirtualToPhysical(void* vaddr); +uintptr_t osVirtualToPhysical(void* vaddr); u32 __osGetSR(void); void __osSetSR(u32 value); void osWritebackDCache(void* vaddr, s32 nbytes); @@ -1806,25 +1806,25 @@ u32 func_800FE4B8(GlobalContext* ctxt); void func_800FEAB0(void); // void func_800FEAC0(void); // void func_800FEAF4(void); -void* Lib_bcopy(void* dst, void* src, size_t n); -s32* Lib_MemSet(s32* buffer, s32 value, u32 size); +void* Lib_MemCpy(void* dest, void* src, size_t size); +void* Lib_MemSet(void* buffer, s32 value, size_t size); f32 Math_CosS(s16 angle); f32 Math_SinS(s16 angle); -s32 Lib_StepTowardsGet_i(s32 start, s32 value, s32 step); -void Lib_StepTowards_i(s32* start, s32 value, s32 step); -s32 Lib_StepTowardsCheck_i(s32* start, s32 value, s32 step); -s32 Lib_StepTowardsCheckFramerateScaled_s(s16* start, s16 target, s16 step); -s32 Lib_StepTowardsCheck_s(s16* start, s16 target, s16 step); -s32 Lib_StepTowardsCheck_c(s8* start, s8 target, s8 step); -s32 Lib_StepTowardsCheck_f(f32* start, f32 target, f32 step); -// void func_800FF0D0(void); -// void func_800FF138(void); -// void func_800FF1FC(void); -// void func_800FF2A8(void); -// void func_800FF2F8(void); -// void func_800FF3A0(void); +s32 Math_StepToIImpl(s32 start, s32 target, s32 step); +void Math_StepToIGet(s32* pValue, s32 target, s32 step); +s32 Math_StepToI(s32* pValue, s32 target, s32 step); +s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step); +s32 Math_StepToS(s16* pValue, s16 target, s16 step); +s32 Math_StepToC(s8* pValue, s8 target, s8 step); +s32 Math_StepToF(f32* pValue, f32 target, f32 step); +s32 Math_StepUntilAngleS(s16* pValue, s16 target, s16 step); +s32 Math_StepToAngleS(s16* pValue, s16 target, s16 step); +s32 Math_AsymStepToS(s16* pValue, s16 target, s16 incrStep, s16 decrStep); +s32 Math_StepUntilF(f32* pValue, f32 limit, f32 step); +s32 Math_AsymStepToF(f32* pValue, f32 target, f32 incrStep, f32 decrStep); +void func_800FF3A0(f32* distOut, s16* angleOut, Input* input); s16 Rand_S16Offset(s16 base, s16 range); -s16 Math_Rand_S16OffsetStride(s16 base, s16 stride, s16 range); +s16 Rand_S16OffsetStride(s16 base, s16 stride, s16 range); void Math_Vec3f_Copy(Vec3f* dest, Vec3f* src); void Math_Vec3s_Copy(Vec3s* dest, Vec3s* src); void Math_Vec3s_ToVec3f(Vec3f* dest, Vec3s* src); @@ -1836,45 +1836,45 @@ void Math_Vec3f_Scale(Vec3f* vec, f32 scale); void Math_Vec3f_ScaleAndStore(Vec3f* vec, f32 scale, Vec3f* dest); void Math_Vec3f_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dest); void Math_Vec3f_SumScaled(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest); -void Math_Vec3f_ModifyRand(Vec3f* orig, f32 scale, Vec3f* dest); -void Math_Vec3f_DistXYZAndStoreNormalizedDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest); +void Math_Vec3f_AddRand(Vec3f* orig, f32 scale, Vec3f* dest); +void Math_Vec3f_DistXYZAndStoreNormDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest); f32 Math_Vec3f_DistXYZ(Vec3f* a, Vec3f* b); -f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* difference); +f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* dest); f32 Math_Vec3f_DistXZ(Vec3f* a, Vec3f* b); -f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* xDiff, f32* zDiff); -f32 Math_Vec3f_PushAwayXZ(Vec3f* start, Vec3f* pusher, f32 distanceToApproach); +f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* dx, f32* dz); +f32 Math_Vec3f_StepToXZ(Vec3f* start, Vec3f* target, f32 speed); f32 Math_Vec3f_DiffY(Vec3f* a, Vec3f* b); -s16 Math_Vec3f_Yaw(Vec3f* from, Vec3f* to); -s16 Math_Vec3f_Pitch(Vec3f* from, Vec3f* to); -void Actor_ProcessInitChain(Actor* actor, InitChainEntry* init); -void IChain_Apply_u8(u8* actor, InitChainEntry* init); -void IChain_Apply_s8(u8* actor, InitChainEntry* init); -void IChain_Apply_u16(u8* actor, InitChainEntry* init); -void IChain_Apply_s16(u8* actor, InitChainEntry* init); -void IChain_Apply_u32(u8* actor, InitChainEntry* init); -void IChain_Apply_s32(u8* actor, InitChainEntry* init); -void IChain_Apply_f32(u8* actor, InitChainEntry* init); -void IChain_Apply_f32div1000(u8* actor, InitChainEntry* init); -void IChain_Apply_Vec3f(u8* actor, InitChainEntry* init); -void IChain_Apply_Vec3fdiv1000(u8* actor, InitChainEntry* init); -void IChain_Apply_Vec3s(u8* actor, InitChainEntry* init); -f32 Math_SmoothScaleMaxMinF(f32* a0, f32 a1, f32 a2, f32 a3, f32 a4); -void Math_SmoothScaleMaxF(f32* start, f32 target, f32 scale, f32 maxStep); -void Math_SmoothDownscaleMaxF(f32* start, f32 scale, f32 maxStep); -s32 Math_SmoothScaleMaxMinS(s16* start, s16 target, s16 scale, s16 maxStep, s16 minStep); -void Math_SmoothScaleMaxS(s16* start, s16 target, s16 scale, s16 maxStep); +s16 Math_Vec3f_Yaw(Vec3f* a, Vec3f* b); +s16 Math_Vec3f_Pitch(Vec3f* a, Vec3f* b); +void Actor_ProcessInitChain(Actor* actor, InitChainEntry* ichain); +// void IChain_Apply_u8(u8* actor, InitChainEntry* init); +// void IChain_Apply_s8(u8* actor, InitChainEntry* init); +// void IChain_Apply_u16(u8* actor, InitChainEntry* init); +// void IChain_Apply_s16(u8* actor, InitChainEntry* init); +// void IChain_Apply_u32(u8* actor, InitChainEntry* init); +// void IChain_Apply_s32(u8* actor, InitChainEntry* init); +// void IChain_Apply_f32(u8* actor, InitChainEntry* init); +// void IChain_Apply_f32div1000(u8* actor, InitChainEntry* init); +// void IChain_Apply_Vec3f(u8* actor, InitChainEntry* init); +// void IChain_Apply_Vec3fdiv1000(u8* actor, InitChainEntry* init); +// void IChain_Apply_Vec3s(u8* actor, InitChainEntry* init); +f32 Math_SmoothStepToF(f32* pValue, f32 target, f32 fraction, f32 step, f32 minStep); +void Math_ApproachF(f32* pValue, f32 target, f32 scale, f32 maxStep); +void Math_ApproachZeroF(f32* pValue, f32 scale, f32 maxStep); +s32 Math_SmoothStepToS(s16* pValue, s16 target, s16 scale, s16 step, s16 minStep); +void Math_ApproachS(s16* pValue, s16 target, s16 scale, s16 maxStep); void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src); -void func_801000A4(u16 param_1); -void func_801000CC(u16 param_1); -void func_801000F4(UNK_TYPE4 param_1, u16 param_2); -void Lib_TranslateAndRotateYVec3f(Vec3f* translation, s16 rotation, Vec3f* src, Vec3f* dst); +void func_801000A4(u16 sfxId); +void func_801000CC(u16 sfxId); +void func_801000F4(s32 a0, u16 a1); +void Lib_Vec3f_TranslateAndRotateY(Vec3f* translation, s16 a, Vec3f* src, Vec3f* dst); void Lib_LerpRGB(Color_RGB8* a, Color_RGB8* b, f32 t, Color_RGB8* dst); -f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach); +f32 Math_Vec3f_StepTo(Vec3f* start, Vec3f* target, f32 speed); void Lib_Nop801004FC(void); -void* Lib_PtrSegToVirt(void* ptr); -void* Lib_PtrSegToVirtNull(void* ptr); -void* Lib_PtrSegToK0(void* ptr); -void* Lib_PtrSegToK0Null(void* ptr); +void* Lib_SegmentedToVirtual(void* ptr); +void* Lib_SegmentedToVirtualNull(void* ptr); +void* Lib_PhysicalToVirtual(void* ptr); +void* Lib_PhysicalToVirtualNull(void* ptr); void LifeMeter_Init(GlobalContext* ctxt); void LifeMeter_UpdateColors(GlobalContext* ctxt); // UNK_TYPE4 func_80100A80(GlobalContext* ctxt); diff --git a/include/guint.h b/include/guint.h deleted file mode 100644 index 90639d28a7..0000000000 --- a/include/guint.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _GUINT_H_ -#define _GUINT_H_ - -// TODO should be in libultra/gu - -#include -#include -#include -#include // TODO the load path for this is actually PR/sptask.h, why? -#include - -typedef union { - /* 0x0 */ struct { - /* 0x0 */ unsigned int hi; - /* 0x4 */ unsigned int lo; - } word; - /* 0x0 */ double d; -} du; - - -typedef union { - /* 0x0 */ unsigned int i; - /* 0x0 */ float f; -} fu; - -typedef float Matrix[4][4]; - -#endif diff --git a/include/macros.h b/include/macros.h index 1d1d0fc03d..9bd1088f53 100644 --- a/include/macros.h +++ b/include/macros.h @@ -2,19 +2,20 @@ #define _MACROS_H_ #include "convert.h" +#include "stdint.h" #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) #define HW_REG(reg, type) *(volatile type*)((reg) | 0xa0000000) -// UB: u32 casts here should be uintptr_t casts. // TODO: After uintptr_t cast change should have an AVOID_UB target that just toggles the KSEG0 bit in the address rather than add/sub 0x80000000 -#define PHYSICAL_TO_VIRTUAL(addr) ((u32)(addr) + 0x80000000) -#define PHYSICAL_TO_VIRTUAL2(addr) ((u32)(addr) - 0x80000000) -#define VIRTUAL_TO_PHYSICAL(addr) (u32)((u8*)(addr) - 0x80000000) +#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) + 0x80000000) +#define PHYSICAL_TO_VIRTUAL2(addr) ((uintptr_t)(addr) - 0x80000000) +#define VIRTUAL_TO_PHYSICAL(addr) (uintptr_t)((u8*)(addr) - 0x80000000) #define SEGMENTED_TO_VIRTUAL(addr) (void*)(PHYSICAL_TO_VIRTUAL(gSegments[SEGMENT_NUMBER(addr)]) + SEGMENT_OFFSET(addr)) + #define ALIGN16(val) (((val) + 0xF) & ~0xF) // Currently most often called ctxt in MM, TODO: Refactor names when its used diff --git a/include/math.h b/include/math.h new file mode 100644 index 0000000000..08ea6a2390 --- /dev/null +++ b/include/math.h @@ -0,0 +1,29 @@ +#ifndef _MATH_H_ +#define _MATH_H_ + +#include + +#define M_PI 3.14159265358979323846f +#define M_SQRT2 1.41421356237309504880f +#define FLT_MAX 340282346638528859811704183484516925440.0f +#define SHT_MAX 32767.0f +#define SHT_MINV (1.0f / SHT_MAX) +#define DEGTORAD(x) (x * M_PI / 180.0f) + +typedef union { + struct { + u32 hi; + u32 lo; + } word; + + f64 d; +} du; + +typedef union { + u32 i; + f32 f; +} fu; + +extern f32 __libm_qnan_f; + +#endif diff --git a/include/stdbool.h b/include/stdbool.h new file mode 100644 index 0000000000..3c714cbb41 --- /dev/null +++ b/include/stdbool.h @@ -0,0 +1,7 @@ +#ifndef _STDBOOL_H_ +#define _STDBOOL_H_ + +#define false 0 +#define true !false + +#endif /* _STDBOOL_H_ */ diff --git a/include/stdint.h b/include/stdint.h new file mode 100644 index 0000000000..03b2c99e17 --- /dev/null +++ b/include/stdint.h @@ -0,0 +1,29 @@ +#ifndef _STDINT_H_ +#define _STDINT_H_ + +#include + +typedef s32 intptr_t; +typedef u32 uintptr_t; + +#define INT8_MIN (-0x80) +#define INT16_MIN (-0x8000) +#define INT32_MIN (-0x80000000) +#define INT64_MIN (-0x8000000000000000) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff +#define INT64_MAX 0x7fffffffffffffff + +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffff +#define UINT64_MAX 0xffffffffffffffff + +#define INTPTR_MIN (-0x80000000) +#define INTPTR_MAX 0x7fffffff +#define UINTPTR_MAX 0xffffffff + + +#endif /* _STDINT_H_ */ diff --git a/include/variables.h b/include/variables.h index 985ef0d55d..359e77ee55 100644 --- a/include/variables.h +++ b/include/variables.h @@ -1010,7 +1010,7 @@ extern u8 kanfontOrdering[92]; // extern UNK_TYPE1 D_801BE90C; // extern UNK_TYPE1 D_801BE92C; // extern UNK_TYPE1 D_801BE944; -extern actor_init_var_func actorInitVarFuncs[11]; +// extern actor_init_var_func sInitChainHandlers[11]; // extern UNK_TYPE2 D_801BE990; // extern UNK_TYPE2 D_801BE992; // extern UNK_TYPE2 D_801BE994; diff --git a/include/z64.h b/include/z64.h index 19f7903e32..8ff93be369 100644 --- a/include/z64.h +++ b/include/z64.h @@ -1,13 +1,17 @@ #ifndef _Z64_H_ #define _Z64_H_ +#include +#include +#include + #include #include #include #include #include #include -#include +#include #include #include #include @@ -444,8 +448,6 @@ typedef unsigned long(*func)(void); typedef void(*func_ptr)(void); -typedef void(*actor_init_var_func)(u8*, InitChainEntry*); - typedef void(*osCreateThread_func)(void*); typedef void*(*printf_func)(void*, char*, size_t); diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index fa6bccee00..3c70e2e230 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -487,7 +487,7 @@ SECTIONS build/asm/code/code_data_z_jpeg.o(.data) build/asm/code/code_data_z_kanfont.o(.data) build/asm/code/code_data_z_kankyo.o(.data) - build/asm/code/code_data_z_lib.o(.data) + build/src/code/z_lib.o(.data) build/asm/code/code_data_z_lifemeter.o(.data) build/src/code/z_lights.o(.data) build/asm/code/code_data_z_map_disp.o(.data) @@ -563,7 +563,7 @@ SECTIONS build/asm/code/code_rodata_z_horse.o(.rodata) build/asm/code/code_rodata_z_jpeg.o(.rodata) build/asm/code/code_rodata_z_kankyo.o(.rodata) - build/asm/code/code_rodata_z_lib.o(.rodata) + build/src/code/z_lib.o(.rodata) build/asm/code/code_rodata_z_lifemeter.o(.rodata) build/src/code/z_lights.o(.rodata) build/asm/code/code_rodata_z_map_disp.o(.rodata) diff --git a/src/code/code_0x800E8EA0.c b/src/code/code_0x800E8EA0.c index cfb9a5b18a..403bdb2265 100644 --- a/src/code/code_0x800E8EA0.c +++ b/src/code/code_0x800E8EA0.c @@ -19,10 +19,10 @@ s32 nop_800E8EEC(UNK_TYPE4 param_1) { void nop_800E8EFC(UNK_TYPE4 param_1) {} s32 func_800E8F08(Vec3s* param_1, Vec3s* param_2) { - Math_SmoothScaleMaxMinS(¶m_1->y, 0, 6, 6200, 100); - Math_SmoothScaleMaxMinS(¶m_1->x, 0, 6, 6200, 100); - Math_SmoothScaleMaxMinS(¶m_2->y, 0, 6, 6200, 100); - Math_SmoothScaleMaxMinS(¶m_2->x, 0, 6, 6200, 100); + Math_SmoothStepToS(¶m_1->y, 0, 6, 6200, 100); + Math_SmoothStepToS(¶m_1->x, 0, 6, 6200, 100); + Math_SmoothStepToS(¶m_2->y, 0, 6, 6200, 100); + Math_SmoothStepToS(¶m_2->x, 0, 6, 6200, 100); return 1; } @@ -34,10 +34,10 @@ s32 func_800E8FA4(Actor* actor, Vec3f* param_2, Vec3s* param_3, Vec3s* param_4) targetPitch = Math_Vec3f_Pitch(&actor->focus.pos,param_2); targetYaw = Math_Vec3f_Yaw(&actor->focus.pos,param_2) - actor->world.rot.y; - Math_SmoothScaleMaxMinS(¶m_3->x, targetPitch, 6, 2000, 1); + Math_SmoothStepToS(¶m_3->x, targetPitch, 6, 2000, 1); param_3->x = (param_3->x < -6000)? -6000 : ((6000 < param_3->x)? 6000 : param_3->x); - yawDiffFromTarget = Math_SmoothScaleMaxMinS(¶m_3->y, targetYaw, 6, 2000, 1); + yawDiffFromTarget = Math_SmoothStepToS(¶m_3->y, targetYaw, 6, 2000, 1); param_3->y = (param_3->y < -8000)? -8000 : ((8000 < param_3->y)? 8000 : param_3->y); if (yawDiffFromTarget != 0) { @@ -46,7 +46,7 @@ s32 func_800E8FA4(Actor* actor, Vec3f* param_2, Vec3s* param_3, Vec3s* param_4) } } - Math_SmoothScaleMaxMinS(¶m_4->y, targetYaw - param_3->y, 4, 2000, 1); + Math_SmoothStepToS(¶m_4->y, targetYaw - param_3->y, 4, 2000, 1); param_4->y = (param_4->y < -12000)? -12000 : ((12000 < param_4->y)? 12000 : param_4->y); return 1; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 2a4699860f..e941198f63 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -265,11 +265,11 @@ void Actor_TitleCardCreate(GlobalContext* ctxt, TitleCardContext* titleCtxt, u32 void Actor_TitleCardUpdate(GlobalContext* ctxt, TitleCardContext* titleCtxt) { if (DECR(titleCtxt->fadeInDelay) == 0) { if (DECR(titleCtxt->fadeOutDelay) == 0) { - Lib_StepTowardsCheck_s(&titleCtxt->alpha, 0, 30); - Lib_StepTowardsCheck_s(&titleCtxt->color, 0, 70); + Math_StepToS(&titleCtxt->alpha, 0, 30); + Math_StepToS(&titleCtxt->color, 0, 70); } else { - Lib_StepTowardsCheck_s(&titleCtxt->alpha, 255, 10); - Lib_StepTowardsCheck_s(&titleCtxt->color, 255, 20); + Math_StepToS(&titleCtxt->alpha, 255, 10); + Math_StepToS(&titleCtxt->color, 255, 20); } } } diff --git a/src/code/z_effect_soft_sprite_old_init.c b/src/code/z_effect_soft_sprite_old_init.c index bc2ac56c93..b0bbccfab0 100644 --- a/src/code/z_effect_soft_sprite_old_init.c +++ b/src/code/z_effect_soft_sprite_old_init.c @@ -26,7 +26,7 @@ void EffectSs_DrawGEffect(GlobalContext* globalCtx, EffectSs* this, void* textur if (mtx != NULL) { gSPMatrix(POLY_XLU_DISP++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPSegment(POLY_XLU_DISP++, 0x08, Lib_PtrSegToVirt(texture)); + gSPSegment(POLY_XLU_DISP++, 0x08, Lib_SegmentedToVirtual(texture)); func_8012C9BC(gfxCtx); gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, this->rgPrimColorR, this->rgPrimColorG, this->rgPrimColorB, this->rgPrimColorA); diff --git a/src/code/z_en_item00.c b/src/code/z_en_item00.c index 1bdfc3a398..b4917b6371 100644 --- a/src/code/z_en_item00.c +++ b/src/code/z_en_item00.c @@ -275,14 +275,14 @@ void func_800A640C(EnItem00* this, GlobalContext* ctxt) { this->actor.shape.rot.y = this->actor.shape.rot.y + 960; } else if ((this->actor.params >= ITEM00_SHIELD_HERO) && (this->actor.params != ITEM00_NUTS_10) && (this->actor.params < ITEM00_BOMBS_0)) { if (this->unk152 == -1) { - if (!Math_SmoothScaleMaxMinS(&this->actor.shape.rot.x, this->actor.world.rot.x - 0x4000, 2, 3000, 1500)) { + if (!Math_SmoothStepToS(&this->actor.shape.rot.x, this->actor.world.rot.x - 0x4000, 2, 3000, 1500)) { this->unk152 = -2; } - } else if (!Math_SmoothScaleMaxMinS(&this->actor.shape.rot.x, -0x4000 - this->actor.world.rot.x, 2, 3000, 1500)) { + } else if (!Math_SmoothStepToS(&this->actor.shape.rot.x, -0x4000 - this->actor.world.rot.x, 2, 3000, 1500)) { this->unk152 = -1; } - Math_SmoothScaleMaxMinS(&this->actor.world.rot.x, 0, 2, 2500, 500); + Math_SmoothStepToS(&this->actor.world.rot.x, 0, 2, 2500, 500); } else if ((this->actor.params == ITEM00_MAP) || (this->actor.params == ITEM00_COMPASS)) { this->unk152 = -1; this->actor.shape.rot.y = this->actor.shape.rot.y + 960; @@ -292,7 +292,7 @@ void func_800A640C(EnItem00* this, GlobalContext* ctxt) { this->actor.shape.yOffset = (Math_SinS(this->actor.shape.rot.y) * 150.0f) + 850.0f; } - Math_SmoothScaleMaxMinF(&this->actor.speedXZ, 0.0f, 1.0f, 0.5f, 0.0f); + Math_SmoothStepToF(&this->actor.speedXZ, 0.0f, 1.0f, 0.5f, 0.0f); if (this->unk14C == 0) { if ((this->actor.params != ITEM00_SMALL_KEY) && (this->actor.params != ITEM00_HEART_PIECE) && (this->actor.params != ITEM00_HEART_CONTAINER)) { @@ -443,7 +443,7 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) { this->actionFunc(this, globalCtx); - Math_SmoothScaleMaxMinF(&this->actor.scale.x, this->unk154, 0.1f, this->unk154 * 0.1f, 0.0f); + Math_SmoothStepToF(&this->actor.scale.x, this->unk154, 0.1f, this->unk154 * 0.1f, 0.0f); this->actor.scale.z = this->actor.scale.x; this->actor.scale.y = this->actor.scale.x; @@ -709,7 +709,7 @@ void EnItem00_DrawRupee(EnItem00* this, GlobalContext* globalCtx) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD); - gSPSegment(POLY_OPA_DISP++, 0x08, Lib_PtrSegToVirt(D_801ADF30[iconNb])); + gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_801ADF30[iconNb])); gSPDisplayList(POLY_OPA_DISP++, &D_040622C0); // TODO symbol @@ -751,7 +751,7 @@ void EnItem00_DrawSprite(EnItem00* this, GlobalContext* globalCtx) { POLY_OPA_DISP = func_8012C724(POLY_OPA_DISP); - gSPSegment(POLY_OPA_DISP++, 0x08, Lib_PtrSegToVirt(D_801ADF44[iconNb])); + gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_801ADF44[iconNb])); gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD); diff --git a/src/code/z_lib.c b/src/code/z_lib.c index de911c257f..1d67449e65 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -1,222 +1,268 @@ #include #include -void* Lib_bcopy(void* dest, void* src, size_t n) { - bcopy(src, dest, n); +void* Lib_MemCpy(void* dest, void* src, size_t size) { + bcopy(src, dest, size); return dest; } -#ifdef NON_MATCHING -void* Lib_MemSet(u8* a0, u32 a1, u32 a2) { +void* Lib_MemSet(void* buffer, s32 value, size_t size) { u8* v0; + s32 i; - // XXX: realloc is messed up - if (a1 == 0) { - _blkclr((void*)a0, (u32)a2); + if (value == 0) { + bzero(buffer, (u32)size); - return a0; + return buffer; } - for (v0 = a0; a2 != 0; a2--) { - *v0++ = a1; + for (v0 = (u8*)buffer, i = size; i > 0; i--) { + *v0++ = value; } - return a0; + return buffer; } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Lib_MemSet.asm") -#endif f32 Math_CosS(s16 angle) { - return coss(angle) * D_801DDA80; + return coss(angle) * SHT_MINV; } f32 Math_SinS(s16 angle) { - return sins(angle) * D_801DDA84; + return sins(angle) * SHT_MINV; } -s32 Lib_StepTowardsGet_i(s32 start, s32 value, s32 step) { - s32 v1; +s32 Math_StepToIImpl(s32 start, s32 target, s32 step) { + s32 ret; - if (value >= start) { - v1 = start + step; - if (value >= v1) { - return v1; + if (target >= start) { + ret = start + step; + if (target >= ret) { + return ret; } } else { - v1 = start - step; - if (v1 >= value) { - return v1; + ret = start - step; + if (ret >= target) { + return ret; } } - return value; + return target; } -void Lib_StepTowards_i(s32* start, s32 value, s32 step) { - *start = Lib_StepTowardsGet_i(*start, value, step); +void Math_StepToIGet(s32* pValue, s32 target, s32 step) { + *pValue = Math_StepToIImpl(*pValue, target, step); } -s32 Lib_StepTowardsCheck_i(s32* start, s32 value, s32 step) { - Lib_StepTowards_i(start, value, step); +s32 Math_StepToI(s32* pValue, s32 target, s32 step) { + Math_StepToIGet(pValue, target, step); - return value == *start; + return target == *pValue; } -s32 Lib_StepTowardsCheckFramerateScaled_s(s16* start, s16 target, s16 step) { +s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step) { f32 f0; if (step != 0) { f0 = gFramerateDivisorHalf; - if ((s16)(*start - target) > 0) { + if ((s16)(*pValue - target) > 0) { step = -step; } - *start += (s16)(step * f0); + *pValue += (s16)(step * f0); - if (((s16)(*start - target) * step) >= 0) { - *start = target; + if (((s16)(*pValue - target) * step) >= 0) { + *pValue = target; - return 1; + return true; } - } else if (target == *start) { - return 1; + } else if (target == *pValue) { + return true; } - return 0; + return false; } -s32 Lib_StepTowardsCheck_s(s16* start, s16 target, s16 step) { +s32 Math_StepToS(s16* pValue, s16 target, s16 step) { if (step != 0) { - if (target < *start) { + if (target < *pValue) { step = -step; } - *start += step; + *pValue += step; - if (((*start - target) * step) >= 0) { - *start = target; + if (((*pValue - target) * step) >= 0) { + *pValue = target; - return 1; + return true; } - } else if (target == *start) { - return 1; + } else if (target == *pValue) { + return true; } - return 0; + return false; } -s32 Lib_StepTowardsCheck_c(s8* start, s8 target, s8 step) { +s32 Math_StepToC(s8* pValue, s8 target, s8 step) { if (step != 0) { - if (target < *start) { + if (target < *pValue) { step = -step; } - *start += step; + *pValue += step; - if (((*start - target) * step) >= 0) { - *start = target; + if (((*pValue - target) * step) >= 0) { + *pValue = target; - return 1; + return true; } - } else if (target == *start) { - return 1; + } else if (target == *pValue) { + return true; } - return 0; + return false; } -#ifdef NON_MATCHING -s32 Lib_StepTowardsCheck_f(f32* start, f32 target, f32 step) { +s32 Math_StepToF(f32* pValue, f32 target, f32 step) { + if (step != 0.0f) { + if (target < *pValue) { + step = -step; + } + + *pValue += step; + + if (((*pValue - target) * step) >= 0) { + *pValue = target; + + return true; + } + } else if (target == *pValue) { + return true; + } + + return false; +} + +s32 Math_StepUntilAngleS(s16* pValue, s16 target, s16 step) { + s16 orig = *pValue; + + *pValue += step; + + if (((s16)(*pValue - target) * (s16)(orig - target)) <= 0) { + *pValue = target; + + return true; + } + + return false; +} + +s32 Math_StepToAngleS(s16* pValue, s16 target, s16 step) { + s32 diff = target - *pValue; + + if (diff < 0) { + step = -step; + } + + if (diff > INT16_MAX) { + step = -step; + diff = -UINT16_MAX - -diff; + } else if (diff <= INT16_MIN) { + diff += UINT16_MAX; + step = -step; + } + if (step != 0) { - // XXX: regalloc is messed up - if (target < *start) { + *pValue += step; + + if ((diff * step) <= 0) { + *pValue = target; + return true; + } + } else if (target == *pValue) { + return true; + } + + return false; +} + +s32 Math_AsymStepToS(s16* pValue, s16 target, s16 incrStep, s16 decrStep) { + s16 step = ((target - *pValue) >= 0) ? incrStep : decrStep; + + if (step != 0) { + if (target < *pValue) { step = -step; } - *start += step; + *pValue += step; - if (((*start - target) * step) >= 0) { - *start = target; - - return 1; + if (((*pValue - target) * step) >= 0) { + *pValue = target; + return true; } - } else if (target != *start) { - return 1; + } else if (target == *pValue) { + return true; } - return 0; + return false; } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Lib_StepTowardsCheck_f.asm") -#endif -#ifdef NON_MATCHING -s32 func_800FF0D0(s16* a0, s16 a1, s16 a2) { - s32 v0 = *a0; +s32 Math_StepUntilF(f32* pValue, f32 limit, f32 step) { + f32 orig = *pValue; - // XXX: regalloc is messed up - *a0 += a2; + *pValue += step; - if (((*a0 - a1) * (v0 - a1)) <= 0) { - *a0 = a1; - - return 1; + if (((*pValue - limit) * (orig - limit)) <= 0) { + *pValue = limit; + return true; } - return 0; -} -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF0D0.asm") -#endif - -#ifdef NON_MATCHING -void func_800FF138() { - -} -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF138.asm") -#endif - -#ifdef NON_MATCHING -void func_800FF1FC(void) { - -} -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF1FC.asm") -#endif - -#ifdef NON_MATCHING -void func_800FF2A8(void) { - -} -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF2A8.asm") -#endif - -#ifdef NON_MATCHING -void func_800FF2F8(void) { - + return false; } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF2F8.asm") -#endif +s32 Math_AsymStepToF(f32* pValue, f32 target, f32 incrStep, f32 decrStep) { + f32 step = (target >= *pValue) ? incrStep : decrStep; -#ifdef NON_MATCHING -void func_800FF3A0(void) { + if (step != 0) { + if (target < *pValue) { + step = -step; + } + *pValue += step; + + if (((*pValue - target) * step) >= 0) { + *pValue = target; + return true; + } + } else if (target == *pValue) { + return true; + } + + return false; +} + +void func_800FF3A0(f32* distOut, s16* angleOut, Input* input) { + f32 x = input->rel.stick_x; + f32 y = input->rel.stick_y; + f32 dist; + + dist = sqrtf(SQ(x) + SQ(y)); + *distOut = (60.0f < dist) ? 60.0f : dist; + + if (dist > 0.0f) { + x = input->cur.stick_x; + y = input->cur.stick_y; + *angleOut = Math_FAtan2F(y, -x); + } else { + *angleOut = 0; + } } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/func_800FF3A0.asm") -#endif s16 Rand_S16Offset(s16 base, s16 range) { return (s16)(Rand_ZeroOne() * range) + base; } -s16 Math_Rand_S16OffsetStride(s16 base, s16 stride, s16 range) { +s16 Rand_S16OffsetStride(s16 base, s16 stride, s16 range) { return (s16)(Rand_ZeroOne() * range) * stride + base; } @@ -302,194 +348,214 @@ void Math_Vec3f_SumScaled(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest) { dest->z = b->z * scale + a->z; } -void Math_Vec3f_ModifyRand(Vec3f* orig, f32 scale, Vec3f* dest) { +void Math_Vec3f_AddRand(Vec3f* orig, f32 scale, Vec3f* dest) { dest->x = randPlusMinusPoint5Scaled(scale) + orig->x; dest->y = randPlusMinusPoint5Scaled(scale) + orig->y; dest->z = randPlusMinusPoint5Scaled(scale) + orig->z; } -void Math_Vec3f_DistXYZAndStoreNormalizedDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest) { - f32 f0 = Math_Vec3f_DistXYZAndStoreDiff(a, b, dest); - f32 f2; +void Math_Vec3f_DistXYZAndStoreNormDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest) { + f32 diff = Math_Vec3f_DistXYZAndStoreDiff(a, b, dest); + f32 normScale; - if (f0 == 0) { + if (diff == 0) { return; } - f2 = scale / f0; + normScale = scale / diff; - dest->x *= f2; - dest->y *= f2; - dest->z *= f2; + dest->x *= normScale; + dest->y *= normScale; + dest->z *= normScale; } f32 Math_Vec3f_DistXYZ(Vec3f* a, Vec3f* b) { - Vec3f sp1C; - Math_Vec3f_Diff(b, a, &sp1C); - return sqrtf((sp1C.x * sp1C.x) + (sp1C.y * sp1C.y) + (sp1C.z * sp1C.z)); + Vec3f diff; + Math_Vec3f_Diff(b, a, &diff); + return sqrtf(SQ(diff.x) + SQ(diff.y) + SQ(diff.z)); } -f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* difference) { - Math_Vec3f_Diff(b, a, difference); - return sqrtf((difference->x * difference->x) + (difference->y * difference->y) + (difference->z * difference->z)); +f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* dest) { + Math_Vec3f_Diff(b, a, dest); + return sqrtf(SQ(dest->x) + SQ(dest->y) + SQ(dest->z)); } f32 Math_Vec3f_DistXZ(Vec3f* a, Vec3f* b) { f32 dx = b->x - a->x; f32 dz = b->z - a->z; - return sqrtf((dx * dx) + (dz * dz)); + return sqrtf(SQ(dx) + SQ(dz)); } -f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* xDiff, f32* zDiff) { - *xDiff = b->x - a->x; - *zDiff = b->z - a->z; - return sqrtf((*xDiff * *xDiff) + (*zDiff * *zDiff)); +f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* dx, f32* dz) { + *dx = b->x - a->x; + *dz = b->z - a->z; + return sqrtf(SQ(*dx) + SQ(*dz)); } -#ifdef NON_MATCHING -void Math_Vec3f_PushAwayXZ(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) { +f32 Math_Vec3f_StepToXZ(Vec3f* start, Vec3f* target, f32 speed) { f32 sp24; f32 sp20; - f32 f0 = Math_Vec3f_DistXZAndStore(pusher, start, &sp24, &sp20); - f32 f2 = f0 - distanceToApproach; + f32 f0 = Math_Vec3f_DistXZAndStore(target, start, &sp24, &sp20); + f32 f2 = f0 - speed; - if ((f0 >= distanceToApproach) && (f2 != 0)) { - f2 /= f0; - } else { - f2 = 0; + if (speed > f0) { + f2 = 0.0f; } - start->x = pusher->x + sp24 * f2; - start->z = pusher->z + sp20 * f2; + if (f2 == 0.0f) { + f0 = 0.0f; + } else { + f0 = f2 / f0; + } + + start->x = target->x + sp24 * f0; + start->z = target->z + sp20 * f0; + + return f2; } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Math_Vec3f_PushAwayXZ.asm") -#endif f32 Math_Vec3f_DiffY(Vec3f* a, Vec3f* b) { return b->y - a->y; } -s16 Math_Vec3f_Yaw(Vec3f* from, Vec3f* to) { - f32 f14 = to->x - from->x; - f32 f12 = to->z - from->z; +s16 Math_Vec3f_Yaw(Vec3f* a, Vec3f* b) { + f32 f14 = b->x - a->x; + f32 f12 = b->z - a->z; return Math_FAtan2F(f12, f14); } -s16 Math_Vec3f_Pitch(Vec3f* from, Vec3f* to) { - return Math_FAtan2F(Math_Vec3f_DistXZ(from, to), from->y - to->y); +s16 Math_Vec3f_Pitch(Vec3f* a, Vec3f* b) { + return Math_FAtan2F(Math_Vec3f_DistXZ(a, b), a->y - b->y); } -void Actor_ProcessInitChain(Actor* actor, InitChainEntry* init) { +void IChain_Apply_u8(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_s8(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_u16(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_s16(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_u32(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_s32(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_f32(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_f32div1000(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_Vec3f(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_Vec3fdiv1000(u8* ptr, InitChainEntry* ichain); +void IChain_Apply_Vec3s(u8* ptr, InitChainEntry* ichain); + +void (*sInitChainHandlers[])(u8* ptr, InitChainEntry* ichain) = { + IChain_Apply_u8, IChain_Apply_s8, IChain_Apply_u16, IChain_Apply_s16, + IChain_Apply_u32, IChain_Apply_s32, IChain_Apply_f32, IChain_Apply_f32div1000, + IChain_Apply_Vec3f, IChain_Apply_Vec3fdiv1000, IChain_Apply_Vec3s, +}; + +void Actor_ProcessInitChain(Actor* actor, InitChainEntry* ichain) { do { - actorInitVarFuncs[init->type]((u8*)actor, init); - } while ((init++)->cont); + sInitChainHandlers[ichain->type]((u8*)actor, ichain); + } while ((ichain++)->cont); } -void IChain_Apply_u8(u8* actor, InitChainEntry* init) { - *(u8*)(actor + init->offset) = (u8)(init->value); +void IChain_Apply_u8(u8* ptr, InitChainEntry* ichain) { + *(u8*)(ptr + ichain->offset) = (u8)(ichain->value); } -void IChain_Apply_s8(u8* actor, InitChainEntry* init) { - *(u8*)(actor + init->offset) = (u8)(init->value); +void IChain_Apply_s8(u8* ptr, InitChainEntry* ichain) { + *(u8*)(ptr + ichain->offset) = (u8)(ichain->value); } -void IChain_Apply_u16(u8* actor, InitChainEntry* init) { - *(u16*)(actor + init->offset) = (u16)(init->value); +void IChain_Apply_u16(u8* ptr, InitChainEntry* ichain) { + *(u16*)(ptr + ichain->offset) = (u16)(ichain->value); } -void IChain_Apply_s16(u8* actor, InitChainEntry* init) { - *(u16*)(actor + init->offset) = (u16)(init->value); +void IChain_Apply_s16(u8* ptr, InitChainEntry* ichain) { + *(u16*)(ptr + ichain->offset) = (u16)(ichain->value); } -void IChain_Apply_u32(u8* actor, InitChainEntry* init) { - *(u32*)(actor + init->offset) = (u32)(init->value); +void IChain_Apply_u32(u8* ptr, InitChainEntry* ichain) { + *(u32*)(ptr + ichain->offset) = (u32)(ichain->value); } -void IChain_Apply_s32(u8* actor, InitChainEntry* init) { - *(u32*)(actor + init->offset) = (u32)(init->value); +void IChain_Apply_s32(u8* ptr, InitChainEntry* ichain) { + *(u32*)(ptr + ichain->offset) = (u32)(ichain->value); } -void IChain_Apply_f32(u8* actor, InitChainEntry* init) { - *(f32*)(actor + init->offset) = (f32)(init->value); +void IChain_Apply_f32(u8* ptr, InitChainEntry* ichain) { + *(f32*)(ptr + ichain->offset) = (f32)(ichain->value); } -void IChain_Apply_f32div1000(u8* actor, InitChainEntry* init) { - *(f32*)(actor + init->offset) = (f32)(init->value) / 1000; +void IChain_Apply_f32div1000(u8* ptr, InitChainEntry* ichain) { + *(f32*)(ptr + ichain->offset) = (f32)(ichain->value) / 1000; } -void IChain_Apply_Vec3f(u8* actor, InitChainEntry* init) { - Vec3f* v0 = (Vec3f*)(actor + init->offset); - f32 f0 = (f32)(init->value); +void IChain_Apply_Vec3f(u8* ptr, InitChainEntry* ichain) { + Vec3f* v0 = (Vec3f*)(ptr + ichain->offset); + f32 f0 = (f32)(ichain->value); v0->z = f0; v0->y = f0; v0->x = f0; } -void IChain_Apply_Vec3fdiv1000(u8* actor, InitChainEntry* init) { - Vec3f* v0 = (Vec3f*)(actor + init->offset); - f32 f0 = (f32)(init->value) / 1000; +void IChain_Apply_Vec3fdiv1000(u8* ptr, InitChainEntry* ichain) { + Vec3f* v0 = (Vec3f*)(ptr + ichain->offset); + f32 f0 = (f32)(ichain->value) / 1000; v0->z = f0; v0->y = f0; v0->x = f0; } -void IChain_Apply_Vec3s(u8* actor, InitChainEntry* init) { - Vec3s* v0 = (Vec3s*)(actor + init->offset); - s16 v1 = (s16)(init->value); +void IChain_Apply_Vec3s(u8* ptr, InitChainEntry* ichain) { + Vec3s* v0 = (Vec3s*)(ptr + ichain->offset); + s16 v1 = (s16)(ichain->value); v0->z = v1; v0->y = v1; v0->x = v1; } -f32 Math_SmoothScaleMaxMinF(f32* a0, f32 a1, f32 a2, f32 a3, f32 a4) { - f32 f0; +f32 Math_SmoothStepToF(f32* pValue, f32 target, f32 fraction, f32 step, f32 minStep) { + f32 stepSize; - if (*a0 != a1) { - f0 = (a1 - *a0) * a2; + if (*pValue != target) { + stepSize = (target - *pValue) * fraction; - if ((f0 >= a4) || (f0 <= -a4)) { - if (f0 > a3) { - f0 = a3; + if ((stepSize >= minStep) || (stepSize <= -minStep)) { + if (stepSize > step) { + stepSize = step; } - if (f0 < -a3) { - f0 = -a3; + if (stepSize < -step) { + stepSize = -step; } - *a0 += f0; + *pValue += stepSize; } else { - if (f0 > 0) { - if (f0 < a4) { - *a0 += a4; + if (stepSize > 0) { + if (stepSize < minStep) { + *pValue += minStep; - if (a1 < *a0) { - *a0 = a1; + if (target < *pValue) { + *pValue = target; } } } else { - if (-a4 < f0) { - *a0 += -a4; + if (-minStep < stepSize) { + *pValue += -minStep; - if (*a0 < a1) { - *a0 = a1; + if (*pValue < target) { + *pValue = target; } } } } } - return fabsf(a1 - *a0); + return fabsf(target - *pValue); } -void Math_SmoothScaleMaxF(f32* start, f32 target, f32 scale, f32 maxStep) { +void Math_ApproachF(f32* pValue, f32 target, f32 scale, f32 maxStep) { f32 f2; - if (*start != target) { - f2 = (target - *start) * scale; + if (*pValue != target) { + f2 = (target - *pValue) * scale; if (f2 > maxStep) { f2 = maxStep; @@ -497,12 +563,12 @@ void Math_SmoothScaleMaxF(f32* start, f32 target, f32 scale, f32 maxStep) { f2 = -maxStep; } - *start += f2; + *pValue += f2; } } -void Math_SmoothDownscaleMaxF(f32* start, f32 scale, f32 maxStep) { - f32 f0 = *start * scale; +void Math_ApproachZeroF(f32* pValue, f32 scale, f32 maxStep) { + f32 f0 = *pValue * scale; if (maxStep < f0) { f0 = maxStep; @@ -510,32 +576,61 @@ void Math_SmoothDownscaleMaxF(f32* start, f32 scale, f32 maxStep) { f0 = -maxStep; } - *start = *start - f0; + *pValue = *pValue - f0; } -#ifdef NON_MATCHING -s32 Math_SmoothScaleMaxMinS(s16* start, s16 target, s16 scale, s16 maxStep, s16 minStep) { +s32 Math_SmoothStepToS(s16* pValue, s16 target, s16 scale, s16 step, s16 minStep) { + s16 stepSize = 0; + s16 diff = target - *pValue; + if (*pValue != target) { + stepSize = diff / scale; + + if ((stepSize > minStep) || (stepSize < -minStep)) { + if (stepSize > step) { + stepSize = step; + } + + if (stepSize < -step) { + stepSize = -step; + } + + *pValue += stepSize; + } else { + if (diff >= 0) { + *pValue += minStep; + + if ((s16)(target - *pValue) <= 0) { + *pValue = target; + } + } else { + *pValue -= minStep; + + if ((s16)(target - *pValue) >= 0) { + *pValue = target; + } + } + } + } + + return diff; } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Math_SmoothScaleMaxMinS.asm") -#endif -void Math_SmoothScaleMaxS(s16* start, s16 target, s16 scale, s16 maxStep) { - s16 v0 = target - *start; - v0 /= scale; +void Math_ApproachS(s16* pValue, s16 target, s16 scale, s16 maxStep) { + s16 diff = target - *pValue; + diff /= scale; - if (v0 > maxStep) { - *start += maxStep; + if (diff > maxStep) { + *pValue += maxStep; return; } - if (v0 < -maxStep) { - *start -= maxStep; + if (diff < -maxStep) { + *pValue -= maxStep; return; } - *start += v0; + *pValue += diff; } void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src) { @@ -545,55 +640,55 @@ void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src) { dst->a = src->a; } -void func_801000A4(u16 a0) { - play_sound(a0); +void func_801000A4(u16 sfxId) { + play_sound(sfxId); } -void func_801000CC(u16 a0) { - func_8019F128(a0); +void func_801000CC(u16 sfxId) { + func_8019F128(sfxId); } void func_801000F4(s32 a0, u16 a1) { func_8019F1C0(a0, a1); } -void Lib_TranslateAndRotateYVec3f(Vec3f* translation, s16 rotation, Vec3f* src, Vec3f* dst) { +void Lib_Vec3f_TranslateAndRotateY(Vec3f* translation, s16 a, Vec3f* src, Vec3f* dst) { f32 sp1C; f32 f0; - sp1C = Math_CosS(rotation); - f0 = Math_SinS(rotation); + sp1C = Math_CosS(a); + f0 = Math_SinS(a); dst->x = translation->x + (src->x * sp1C + src->z * f0); dst->y = translation->y + src->y; dst->z = translation->z + (src->z * sp1C - src->x * f0); } -#ifdef NON_MATCHING void Lib_LerpRGB(Color_RGB8* a, Color_RGB8* b, f32 t, Color_RGB8* dst) { - // XXX regalloc is slightly off - dst->r = (f32)a->r + ((f32)b->r - (f32)a->r) * t; - dst->g = (f32)a->g + ((f32)b->g - (f32)a->g) * t; - dst->b = (f32)a->b + ((f32)b->b - (f32)a->b) * t; -} -#else -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_lib/Lib_LerpRGB.asm") -#endif + f32 aF; -f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) { - Vec3f sp24; + aF = a->r; + dst->r = aF + (b->r - aF) * t; + aF = a->g; + dst->g = aF + (b->g - aF) * t; + aF = a->b; + dst->b = aF + (b->b - aF) * t; +} + +f32 Math_Vec3f_StepTo(Vec3f* start, Vec3f* target, f32 speed) { + Vec3f diff; f32 f2; f32 f0; - Math_Vec3f_Diff(pusher, start, &sp24); - f0 = Math3D_Vec3fMagnitude(&sp24); - if (distanceToApproach < f0) { - f2 = distanceToApproach / f0; - f0 = f0 - distanceToApproach; - start->x = start->x + f2 * sp24.x; - start->y = start->y + f2 * sp24.y; - start->z = start->z + f2 * sp24.z; + Math_Vec3f_Diff(target, start, &diff); + f0 = Math3D_Vec3fMagnitude(&diff); + if (speed < f0) { + f2 = speed / f0; + f0 = f0 - speed; + start->x = start->x + f2 * diff.x; + start->y = start->y + f2 * diff.y; + start->z = start->z + f2 * diff.z; } else { - Math_Vec3f_Copy(start, pusher); + Math_Vec3f_Copy(start, target); f0 = 0; } @@ -602,20 +697,19 @@ f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) { void Lib_Nop801004FC(void) {} -void* Lib_PtrSegToVirt(void* ptr) { +void* Lib_SegmentedToVirtual(void* ptr) { return SEGMENTED_TO_VIRTUAL(ptr); } -void* Lib_PtrSegToVirtNull(void* ptr) { - // UB: to cast the pointer to u32 in order to bitshift. - if (((u32)ptr >> 28) == 0) { +void* Lib_SegmentedToVirtualNull(void* ptr) { + if (((uintptr_t)ptr >> 28) == 0) { return ptr; } return SEGMENTED_TO_VIRTUAL(ptr); } -void* Lib_PtrSegToK0(void* ptr) { +void* Lib_PhysicalToVirtual(void* ptr) { if (ptr == NULL) { return NULL; } else { @@ -623,7 +717,7 @@ void* Lib_PtrSegToK0(void* ptr) { } } -void* Lib_PtrSegToK0Null(void* ptr) { +void* Lib_PhysicalToVirtualNull(void* ptr) { if (ptr == NULL) { return NULL; } else { diff --git a/src/code/z_room.c b/src/code/z_room.c index 04842eeb6e..0e6b1afe31 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -28,7 +28,7 @@ void Room_DrawType0Mesh(GlobalContext* ctxt, Room* room, u32 flags) { } mesh = &room->mesh->type0; - meshParams = (RoomMeshType0Params*)Lib_PtrSegToVirt(mesh->paramsStart); + meshParams = (RoomMeshType0Params*)Lib_SegmentedToVirtual(mesh->paramsStart); for (i = 0; i < mesh->count; i++) { if ((flags & 1) && (meshParams->opaqueDl != NULL)) { gSPDisplayList(gfxCtx->polyOpa.p++, meshParams->opaqueDl); diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 671f60447f..496c8ca7ae 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -157,7 +157,7 @@ void Scene_HeaderCommand00(GlobalContext* ctxt, SceneCmd* entry) { s16 temp16; u8 unk20; - ctxt->linkActorEntry = (ActorEntry*)Lib_PtrSegToVirt(entry->spawnList.segment) + + ctxt->linkActorEntry = (ActorEntry*)Lib_SegmentedToVirtual(entry->spawnList.segment) + ctxt->setupEntranceList[ctxt->curSpawn].spawn; if ( (ctxt->linkActorEntry->params & 0x0F00) >> 8 == 0x0C || (gSaveContext.extra.unk10 == 0x02 && gSaveContext.extra.unk42 == 0x0CFF) @@ -181,13 +181,13 @@ void Scene_HeaderCommand00(GlobalContext* ctxt, SceneCmd* entry) { // Scene Command 0x01: Actor List void Scene_HeaderCommand01(GlobalContext* ctxt, SceneCmd* entry) { ctxt->sceneNumActorsToLoad = (u16)entry->actorList.num; - ctxt->setupActorList = (ActorEntry*)Lib_PtrSegToVirt(entry->actorList.segment); + ctxt->setupActorList = (ActorEntry*)Lib_SegmentedToVirtual(entry->actorList.segment); ctxt->actorCtx.unkC = (u16)0; } // Scene Command 0x02: Cutscene Camera List void Scene_HeaderCommand02(GlobalContext* ctxt, SceneCmd* entry) { - ctxt->unk18858 = (UNK_PTR)Lib_PtrSegToVirt(entry->csCameraList.segment); + ctxt->unk18858 = (UNK_PTR)Lib_SegmentedToVirtual(entry->csCameraList.segment); } // Scene Command 0x03: Collision Header @@ -195,18 +195,18 @@ void Scene_HeaderCommand03(GlobalContext* ctxt, SceneCmd* entry) { BgMeshHeader* temp_ret; BgMeshHeader* temp_s0; - temp_ret = (BgMeshHeader*)Lib_PtrSegToVirt(entry->colHeader.segment); + temp_ret = (BgMeshHeader*)Lib_SegmentedToVirtual(entry->colHeader.segment); temp_s0 = temp_ret; - temp_s0->vertices = (BgVertex*)Lib_PtrSegToVirt(temp_ret->vertices); - temp_s0->polygons = (CollisionPoly*)Lib_PtrSegToVirt(temp_s0->polygons); + temp_s0->vertices = (BgVertex*)Lib_SegmentedToVirtual(temp_ret->vertices); + temp_s0->polygons = (CollisionPoly*)Lib_SegmentedToVirtual(temp_s0->polygons); if (temp_s0->attributes != 0) { - temp_s0->attributes = (BgPolygonAttributes*)Lib_PtrSegToVirt(temp_s0->attributes); + temp_s0->attributes = (BgPolygonAttributes*)Lib_SegmentedToVirtual(temp_s0->attributes); } if (temp_s0->cameraData != 0) { - temp_s0->cameraData = (void*)Lib_PtrSegToVirt(temp_s0->cameraData); + temp_s0->cameraData = (void*)Lib_SegmentedToVirtual(temp_s0->cameraData); } if (temp_s0->waterboxes != 0) { - temp_s0->waterboxes = (BgWaterBox*)Lib_PtrSegToVirt(temp_s0->waterboxes); + temp_s0->waterboxes = (BgWaterBox*)Lib_SegmentedToVirtual(temp_s0->waterboxes); } BgCheck_Init(&ctxt->colCtx, ctxt, temp_s0); @@ -215,12 +215,12 @@ void Scene_HeaderCommand03(GlobalContext* ctxt, SceneCmd* entry) { // Scene Command 0x04: Room List void Scene_HeaderCommand04(GlobalContext* ctxt, SceneCmd* entry) { ctxt->numRooms = entry->roomList.num; - ctxt->roomList = (RoomFileLocation*)Lib_PtrSegToVirt(entry->roomList.segment); + ctxt->roomList = (RoomFileLocation*)Lib_SegmentedToVirtual(entry->roomList.segment); } // Scene Command 0x06: Entrance List void Scene_HeaderCommand06(GlobalContext* ctxt, SceneCmd* entry) { - ctxt->setupEntranceList = (EntranceEntry*)Lib_PtrSegToVirt(entry->entranceList.segment); + ctxt->setupEntranceList = (EntranceEntry*)Lib_SegmentedToVirtual(entry->entranceList.segment); } // Scene Command 0x07: Special Files @@ -250,7 +250,7 @@ void Scene_HeaderCommand08(GlobalContext* ctxt, SceneCmd* entry) { // Scene Command 0x0A: Mesh Header void Scene_HeaderCommand0A(GlobalContext* ctxt, SceneCmd* entry) { - ctxt->roomContext.currRoom.mesh = (RoomMesh*)Lib_PtrSegToVirt(entry->mesh.segment); + ctxt->roomContext.currRoom.mesh = (RoomMesh*)Lib_SegmentedToVirtual(entry->mesh.segment); } // Scene Command 0x0B: Object List @@ -262,7 +262,7 @@ void Scene_HeaderCommand0B(GlobalContext *ctxt, SceneCmd *entry) { s16* objectEntry; void* nextPtr; - objectEntry = (s16*)Lib_PtrSegToVirt(entry->objectList.segment); + objectEntry = (s16*)Lib_SegmentedToVirtual(entry->objectList.segment); k = 0; i = ctxt->sceneContext.spawnedObjectCount; status = &ctxt->sceneContext.objects[i]; @@ -307,7 +307,7 @@ void Scene_HeaderCommand0C(GlobalContext* ctxt, SceneCmd* entry) { s32 i; LightInfo* lightInfo; - lightInfo = (LightInfo*)Lib_PtrSegToVirt(entry->lightList.segment); + lightInfo = (LightInfo*)Lib_SegmentedToVirtual(entry->lightList.segment); for (i = 0; i < entry->lightList.num; i++) { LightContext_InsertLight(ctxt, &ctxt->lightCtx, lightInfo); @@ -317,13 +317,13 @@ void Scene_HeaderCommand0C(GlobalContext* ctxt, SceneCmd* entry) { // Scene Command 0x0D: Path List void Scene_HeaderCommand0D(GlobalContext* ctxt, SceneCmd* entry) { - ctxt->setupPathList = (void*)Lib_PtrSegToVirt(entry->pathList.segment); + ctxt->setupPathList = (void*)Lib_SegmentedToVirtual(entry->pathList.segment); } // Scene Command 0x0E: Transition Actor List void Scene_HeaderCommand0E(GlobalContext* ctxt, SceneCmd* entry) { ctxt->transitionActorCount = entry->transiActorList.num; - ctxt->transitionActorList = (TransitionActorEntry*)Lib_PtrSegToVirt((void*)entry->transiActorList.segment); + ctxt->transitionActorList = (TransitionActorEntry*)Lib_SegmentedToVirtual((void*)entry->transiActorList.segment); func_80105818(ctxt, ctxt->transitionActorCount, ctxt->transitionActorList); } @@ -334,7 +334,7 @@ void func_8012FEBC(GlobalContext* ctxt, u8* nbTransitionActors) { // Scene Command 0x0F: Light Setting List void Scene_HeaderCommand0F(GlobalContext* ctxt, SceneCmd* entry) { ctxt->kankyoContext.environmentSettingsCount = entry->lightSettingList.num; - ctxt->kankyoContext.environmentSettingsList = (void*)Lib_PtrSegToVirt(entry->lightSettingList.segment); + ctxt->kankyoContext.environmentSettingsList = (void*)Lib_SegmentedToVirtual(entry->lightSettingList.segment); } s32 func_8012FF10(GlobalContext* ctxt, s32 fileIndex) { @@ -423,7 +423,7 @@ void Scene_HeaderCommand05(GlobalContext* ctxt, SceneCmd* entry) { } void Scene_HeaderCommand13(GlobalContext* ctxt, SceneCmd* entry) { - ctxt->setupExitList = (void*)Lib_PtrSegToVirt(entry->exitList.segment); + ctxt->setupExitList = (void*)Lib_SegmentedToVirtual(entry->exitList.segment); } // Scene Command 0x09: Undefined @@ -450,10 +450,10 @@ void Scene_HeaderCommand18(GlobalContext* ctxt, SceneCmd* entry) { SceneCmd** altHeaderList; SceneCmd* altHeader; if (gSaveContext.extra.sceneSetupIndex) { - altHeaderList = (SceneCmd**)Lib_PtrSegToVirt(entry->altHeaders.segment); + altHeaderList = (SceneCmd**)Lib_SegmentedToVirtual(entry->altHeaders.segment); altHeader = altHeaderList[gSaveContext.extra.sceneSetupIndex - 1]; if (altHeader != NULL) { - Scene_ProcessHeader(ctxt, (SceneCmd*)Lib_PtrSegToVirt(altHeader)); + Scene_ProcessHeader(ctxt, (SceneCmd*)Lib_SegmentedToVirtual(altHeader)); (entry + 1)->base.code = 0x14; } } @@ -462,12 +462,12 @@ void Scene_HeaderCommand18(GlobalContext* ctxt, SceneCmd* entry) { // Scene Command 0x17: Cutscene Data void Scene_HeaderCommand17(GlobalContext* ctxt, SceneCmd* entry) { ctxt->csCtx.cutsceneCount = (u8)entry->base.data1; - ctxt->cutsceneList = (CutsceneEntry*)Lib_PtrSegToVirt((void*)entry->base.data2); + ctxt->cutsceneList = (CutsceneEntry*)Lib_SegmentedToVirtual((void*)entry->base.data2); } // Scene Command 0x1B: Cutscene Actor List void Scene_HeaderCommand1B(GlobalContext* ctxt, SceneCmd* entry) { - ActorCutscene_Init(ctxt, (ActorCutscene*)Lib_PtrSegToVirt(entry->cutsceneActorList.segment), + ActorCutscene_Init(ctxt, (ActorCutscene*)Lib_SegmentedToVirtual(entry->cutsceneActorList.segment), entry->cutsceneActorList.num); } @@ -521,7 +521,7 @@ void Scene_HeaderCommand19(GlobalContext *ctxt, SceneCmd *entry) { // Scene Command 0x1A: Texture Animations void Scene_HeaderCommand1A(GlobalContext* ctxt, SceneCmd* entry) { - ctxt->sceneTextureAnimations = (AnimatedTexture*)Lib_PtrSegToVirt(entry->textureAnimations.segment); + ctxt->sceneTextureAnimations = (AnimatedTexture*)Lib_SegmentedToVirtual(entry->textureAnimations.segment); } void func_801306A4(GlobalContext *ctxt) { diff --git a/src/code/z_scene_proc.c b/src/code/z_scene_proc.c index 9dea984ea5..6d235616c3 100644 --- a/src/code/z_scene_proc.c +++ b/src/code/z_scene_proc.c @@ -109,14 +109,14 @@ void SceneProc_DrawFlashingTexture(GlobalContext* ctxt, u32 segment, FlashingTex void SceneProc_DrawType2Texture(GlobalContext* ctxt, u32 segment, FlashingTextureParams* params) { Color_RGBA8* envColor; - FlashingTexturePrimColor* primColor = (FlashingTexturePrimColor *)Lib_PtrSegToVirt(params->primColors); + FlashingTexturePrimColor* primColor = (FlashingTexturePrimColor *)Lib_SegmentedToVirtual(params->primColors); u32 pad; u32 index = gSceneProcStep % params->cycleLength; primColor += index; if (params->envColors) { - envColor = (Color_RGBA8*)Lib_PtrSegToVirt(params->envColors) + index; + envColor = (Color_RGBA8*)Lib_SegmentedToVirtual(params->envColors) + index; } else { envColor = NULL; } @@ -133,8 +133,8 @@ s32 SceneProc_Lerp(s32 a, s32 b, f32 t) { void SceneProc_DrawType3Texture(GlobalContext* ctxt, u32 segment, FlashingTextureParams* params) { FlashingTextureParams* params2 = params; Color_RGBA8* envColorTo; - FlashingTexturePrimColor* primColorTo = (FlashingTexturePrimColor *)Lib_PtrSegToVirt(params2->primColors); - u16* keyFrames = (u16*)Lib_PtrSegToVirt(params2->keyFrames); + FlashingTexturePrimColor* primColorTo = (FlashingTexturePrimColor *)Lib_SegmentedToVirtual(params2->primColors); + u16* keyFrames = (u16*)Lib_SegmentedToVirtual(params2->keyFrames); s32 index = gSceneProcStep % params2->cycleLength; s32 pad1; s32 keyFrameIndex; @@ -169,7 +169,7 @@ void SceneProc_DrawType3Texture(GlobalContext* ctxt, u32 segment, FlashingTextur primColorIn.lodFrac = SceneProc_Lerp(primColorFrom->lodFrac, primColorTo->lodFrac, t); if (params2->envColors) { - envColorTo = (Color_RGBA8*)Lib_PtrSegToVirt(params2->envColors) + keyFrameIndex; + envColorTo = (Color_RGBA8*)Lib_SegmentedToVirtual(params2->envColors) + keyFrameIndex; envColorFrom = envColorTo - 1; envColorIn.red = SceneProc_Lerp(envColorFrom->red, envColorTo->red, t); envColorIn.green = SceneProc_Lerp(envColorFrom->green, envColorTo->green, t); @@ -210,10 +210,10 @@ void SceneProc_DrawType5Texture(GlobalContext* ctxt, u32 segment, CyclingTexture GraphicsContext* gfxCtx; s32 step; - dls = (Gfx**)Lib_PtrSegToVirt(params->textureDls); - offsets = (u8*)Lib_PtrSegToVirt(params->textureDlOffsets); + dls = (Gfx**)Lib_SegmentedToVirtual(params->textureDls); + offsets = (u8*)Lib_SegmentedToVirtual(params->textureDlOffsets); step = gSceneProcStep % params->cycleLength; - dl = (Gfx*)Lib_PtrSegToVirt(dls[offsets[step]]); + dl = (Gfx*)Lib_SegmentedToVirtual(dls[offsets[step]]); gfxCtx = ctxt->state.gfxCtx; if (gSceneProcFlags & 1) { @@ -239,7 +239,7 @@ void SceneProc_DrawAnimatedTextures(GlobalContext* ctxt, AnimatedTexture* textur segment = textures->segment; segmentAbs = ((segment < 0)? -segment : segment) + 7; - gSceneProcDrawFuncs[textures->type](ctxt, segmentAbs, (void*)Lib_PtrSegToVirt(textures->params)); + gSceneProcDrawFuncs[textures->type](ctxt, segmentAbs, (void*)Lib_SegmentedToVirtual(textures->params)); textures++; } while (segment > -1); diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c index 09ac2403c7..85e8f3f67b 100644 --- a/src/code/z_skelanime.c +++ b/src/code/z_skelanime.c @@ -39,7 +39,7 @@ void SkelAnime_LodDrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* sk s32 pad; Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; @@ -98,7 +98,7 @@ void SkelAnime_LodDraw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; pos.z = limbDrawTable[0].z; @@ -147,7 +147,7 @@ void SkelAnime_LodDrawLimbSV(GlobalContext* globalCtx, s32 limbIndex, Skeleton* Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; @@ -217,7 +217,7 @@ void SkelAnime_LodDrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* li gSPSegment(gfxCtx->polyOpa.p++, 0xD, mtx); Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; pos.z = limbDrawTable[0].z; @@ -268,7 +268,7 @@ void SkelAnime_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skele Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; pos.x = limbEntry->translation.x; @@ -321,7 +321,7 @@ void SkelAnime_Draw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDra gfxCtx = globalCtx->state.gfxCtx; Matrix_Push(); - rootLimb = Lib_PtrSegToVirt(skeleton->limbs[0]); + rootLimb = Lib_SegmentedToVirtual(skeleton->limbs[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -365,7 +365,7 @@ void SkelAnime_DrawLimbSV(GlobalContext* globalCtx, s32 limbIndex, Skeleton* ske Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; @@ -429,7 +429,7 @@ void SkelAnime_DrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbD Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -480,7 +480,7 @@ void func_80134148(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton, Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; @@ -551,7 +551,7 @@ void func_801343C0(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDraw Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -598,9 +598,9 @@ void func_801343C0(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDraw * rotation value list, otherwise it is copied from the initial rotation value list */ void SkelAnime_AnimateFrame(AnimationHeader* animationSeg, s32 currentFrame, s32 limbCount, Vec3s* dst) { - AnimationHeader* animationHeader = Lib_PtrSegToVirt(animationSeg); - AnimationRotationIndex* index = Lib_PtrSegToVirt(animationHeader->rotationIndexSeg); - AnimationRotationValue* rotationValueTable = Lib_PtrSegToVirt(animationHeader->rotationValueSeg); + AnimationHeader* animationHeader = Lib_SegmentedToVirtual(animationSeg); + AnimationRotationIndex* index = Lib_SegmentedToVirtual(animationHeader->rotationIndexSeg); + AnimationRotationValue* rotationValueTable = Lib_SegmentedToVirtual(animationHeader->rotationValueSeg); AnimationRotationValue* frameRotationValueTable = &rotationValueTable[currentFrame]; s32 i; u16 limit = animationHeader->limit; @@ -618,12 +618,12 @@ void SkelAnime_AnimateFrame(AnimationHeader* animationSeg, s32 currentFrame, s32 } s16 SkelAnime_GetTotalFrames(GenericAnimationHeader* animationSeg) { - GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg); + GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg); return animation->frameCount; } s16 SkelAnime_GetFrameCount(GenericAnimationHeader* animationSeg) { - GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg); + GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg); return (u16)animation->frameCount - 1; } @@ -641,7 +641,7 @@ Gfx* SkelAnime_Draw2Limb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skel Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; @@ -697,7 +697,7 @@ Gfx* SkelAnime_Draw2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDr Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -744,7 +744,7 @@ Gfx* SkelAnime_DrawLimbSV2(GlobalContext* globalCtx, s32 limbIndex, Skeleton* sk Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[limbIndex]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; @@ -808,7 +808,7 @@ Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb Matrix_Push(); - limbEntry = Lib_PtrSegToVirt(skeleton->limbs[0]); + limbEntry = Lib_SegmentedToVirtual(skeleton->limbs[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -851,7 +851,7 @@ Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb #pragma GLOBAL_ASM("./asm/non_matchings/code/z_skelanime/func_80134FFC.asm") s16 func_801353D4(GenericAnimationHeader* animationSeg) { - GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg); + GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg); return animation->unk02; } @@ -861,7 +861,7 @@ s16 func_801353D4(GenericAnimationHeader* animationSeg) { * SkelAnime_GetTotalFrames */ s16 SkelAnime_GetTotalFrames2(GenericAnimationHeader* animationSeg) { - GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg); + GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg); return animation->frameCount; } @@ -871,7 +871,7 @@ s16 SkelAnime_GetTotalFrames2(GenericAnimationHeader* animationSeg) { * SkelAnime_GetFrameCount */ s16 SkelAnime_GetFrameCount2(GenericAnimationHeader* animationSeg) { - GenericAnimationHeader* animation = Lib_PtrSegToVirt(animationSeg); + GenericAnimationHeader* animation = Lib_SegmentedToVirtual(animationSeg); return animation->frameCount - 1; } @@ -941,7 +941,7 @@ void SkelAnime_LoadLinkAnimetion(GlobalContext* globalCtx, LinkAnimetionEntry* l entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_LINKANIMETION); if (entry != NULL) { - linkAnimetionEntry = Lib_PtrSegToVirt(linkAnimetionSeg); + linkAnimetionEntry = Lib_SegmentedToVirtual(linkAnimetionSeg); osCreateMesgQueue(&entry->types.type0.msgQueue, &entry->types.type0.msg, 1); DmaMgr_SendRequestImpl( &entry->types.type0.req, ram, @@ -1096,7 +1096,7 @@ void SkelAnime_InitLinkAnimetion(GlobalContext* globalCtx, SkelAnime* skelAnime, s32 limbCount; u32 allocSize; - skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg); + skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); headerCount = skeletonHeader->limbCount; skelAnime->initFlags = flags; limbCount = (flags & 2) ? headerCount : 1; @@ -1111,7 +1111,7 @@ void SkelAnime_InitLinkAnimetion(GlobalContext* globalCtx, SkelAnime* skelAnime, skelAnime->limbCount = limbCount; skelAnime->dListCount = skeletonHeader->dListCount; - skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg); + skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg); allocSize = sizeof(Vec3s) * limbCount; if (flags & 8) { @@ -1363,9 +1363,9 @@ void SkelAnime_Init(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHead AnimationHeader* animationSeg, Vec3s* limbDrawTbl, Vec3s* transitionDrawTable, s32 limbCount) { SkeletonHeader* skeletonHeader; - skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg); + skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); skelAnime->limbCount = skeletonHeader->limbCount + 1; - skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg); + skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg); if (limbDrawTbl == NULL) { skelAnime->limbDrawTbl = zelda_malloc(sizeof(*skelAnime->limbDrawTbl) * skelAnime->limbCount); skelAnime->transitionDrawTbl = zelda_malloc(sizeof(*skelAnime->transitionDrawTbl) * skelAnime->limbCount); @@ -1383,10 +1383,10 @@ void SkelAnime_InitSV(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHe AnimationHeader* animationSeg, Vec3s* limbDrawTbl, Vec3s* transitionDrawTable, s32 limbCount) { SkeletonHeader* skeletonHeader; - skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg); + skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); skelAnime->limbCount = skeletonHeader->limbCount + 1; skelAnime->dListCount = skeletonHeader->dListCount; - skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg); + skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg); if (limbDrawTbl == NULL) { skelAnime->limbDrawTbl = zelda_malloc(sizeof(*skelAnime->limbDrawTbl) * skelAnime->limbCount); @@ -1406,9 +1406,9 @@ void SkelAnime_InitSkin(GlobalContext* globalCtx, SkelAnime* skelAnime, Skeleton AnimationHeader* animationSeg) { SkeletonHeader* skeletonHeader; - skeletonHeader = Lib_PtrSegToVirt(skeletonHeaderSeg); + skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); skelAnime->limbCount = skeletonHeader->limbCount + 1; - skelAnime->skeleton = Lib_PtrSegToVirt(skeletonHeader->skeletonSeg); + skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->skeletonSeg); skelAnime->limbDrawTbl = zelda_malloc(sizeof(*skelAnime->limbDrawTbl) * skelAnime->limbCount); skelAnime->transitionDrawTbl = zelda_malloc(sizeof(*skelAnime->transitionDrawTbl) * skelAnime->limbCount); diff --git a/src/libultra/gu/sinf.c b/src/libultra/gu/sinf.c index 4757cd3378..250664373b 100644 --- a/src/libultra/gu/sinf.c +++ b/src/libultra/gu/sinf.c @@ -1,4 +1,4 @@ -#include +#include static const du P[] = { {0x3FF00000, 0x00000000}, diff --git a/src/libultra/gu/sins.c b/src/libultra/gu/sins.c index 9608cee8c5..ba48dbc70a 100644 --- a/src/libultra/gu/sins.c +++ b/src/libultra/gu/sins.c @@ -1,4 +1,4 @@ -#include +#include #include "sintable.h" diff --git a/src/libultra/os/virtualtophysical.c b/src/libultra/os/virtualtophysical.c index 8150a1a23b..1999bdd7e6 100644 --- a/src/libultra/os/virtualtophysical.c +++ b/src/libultra/os/virtualtophysical.c @@ -1,12 +1,12 @@ #include #include +#include -u32 osVirtualToPhysical(void* virtualAddress) { - // UB: u32 casts here should be uintptr_t casts. - if (((u32)virtualAddress >= 0x80000000) && ((u32)virtualAddress < 0xA0000000)) { - return (u32)virtualAddress & 0x1FFFFFFF; - } else if (((u32)virtualAddress >= 0xA0000000) && ((u32)virtualAddress < 0xC0000000)) { - return (u32)virtualAddress & 0x1FFFFFFF; +uintptr_t osVirtualToPhysical(void* virtualAddress) { + if (((uintptr_t)virtualAddress >= 0x80000000) && ((uintptr_t)virtualAddress < 0xA0000000)) { + return (uintptr_t)virtualAddress & 0x1FFFFFFF; + } else if (((uintptr_t)virtualAddress >= 0xA0000000) && ((uintptr_t)virtualAddress < 0xC0000000)) { + return (uintptr_t)virtualAddress & 0x1FFFFFFF; } else { return __osProbeTLB(virtualAddress); } diff --git a/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c b/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c index 678c4ca715..209d54023a 100644 --- a/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c +++ b/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c @@ -97,9 +97,9 @@ void func_80B6DD80(BgHakaCurtain* this) { void func_80B6DD9C(BgHakaCurtain* this, GlobalContext* globalCtx) { if (this->dyna.actor.world.pos.y < this->dyna.actor.home.pos.y + 150.0f - 30.0f) { - Lib_StepTowardsCheck_f(&this->dyna.actor.velocity.y, 1.6f, 0.12f); + Math_StepToF(&this->dyna.actor.velocity.y, 1.6f, 0.12f); } else { - Lib_StepTowardsCheck_f(&this->dyna.actor.velocity.y, 0.8f, 0.05f); + Math_StepToF(&this->dyna.actor.velocity.y, 0.8f, 0.05f); } this->dyna.actor.world.pos.y += this->dyna.actor.velocity.y; if (this->dyna.actor.home.pos.y + 150.0f < this->dyna.actor.world.pos.y) { diff --git a/src/overlays/actors/ovl_Bg_Ikana_Ray/z_bg_ikana_ray.c b/src/overlays/actors/ovl_Bg_Ikana_Ray/z_bg_ikana_ray.c index 03c1541cb3..0522ddb558 100644 --- a/src/overlays/actors/ovl_Bg_Ikana_Ray/z_bg_ikana_ray.c +++ b/src/overlays/actors/ovl_Bg_Ikana_Ray/z_bg_ikana_ray.c @@ -49,7 +49,7 @@ void BgIkanaRay_Init(Actor* thisx, GlobalContext* globalCtx) { Collider_SetCylinder(globalCtx, collision, thisx, &bgIkanaRayCylinderInit); Collider_UpdateCylinder(thisx, &THIS->collision); - THIS->animatedTextures = (AnimatedTexture*)Lib_PtrSegToVirt(object_ikana_obj_001228); + THIS->animatedTextures = (AnimatedTexture*)Lib_SegmentedToVirtual(object_ikana_obj_001228); if (Actor_GetSwitchFlag(globalCtx, THIS->base.params & 0x7F) != 0) { BgIkanaRay_SetActivated(THIS); diff --git a/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c b/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c index b73cfe2c8c..ace471874d 100644 --- a/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c +++ b/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c @@ -115,8 +115,8 @@ void func_80BD58F0(BgIkanaShutter* this) { } void func_80BD5910(BgIkanaShutter* this, GlobalContext* globalCtx) { - Lib_StepTowardsCheck_f(&this->dyna.actor.velocity.y, 4.0f, 0.5f); - if (Math_SmoothScaleMaxMinF(&this->dyna.actor.world.pos.y, this->dyna.actor.home.pos.y + 220.0f, 0.5f, + Math_StepToF(&this->dyna.actor.velocity.y, 4.0f, 0.5f); + if (Math_SmoothStepToF(&this->dyna.actor.world.pos.y, this->dyna.actor.home.pos.y + 220.0f, 0.5f, this->dyna.actor.velocity.y, 1.0f) < 0.5f) { func_80BD599C(this); } @@ -185,8 +185,8 @@ void func_80BD5BC4(BgIkanaShutter* this) { } void func_80BD5BD8(BgIkanaShutter* this, GlobalContext* globalCtx) { - Lib_StepTowardsCheck_f(&this->dyna.actor.velocity.y, 4.0f, 0.5f); - if (Math_SmoothScaleMaxMinF(&this->dyna.actor.world.pos.y, this->dyna.actor.home.pos.y + -220.0f, 0.5f, + Math_StepToF(&this->dyna.actor.velocity.y, 4.0f, 0.5f); + if (Math_SmoothStepToF(&this->dyna.actor.world.pos.y, this->dyna.actor.home.pos.y + -220.0f, 0.5f, this->dyna.actor.velocity.y, 1.0f) < 0.5f) { BgIkanaShutter_SetupDoNothing(this); } diff --git a/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c b/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c index d0432db3f9..87ace87bf2 100644 --- a/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c +++ b/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c @@ -135,7 +135,7 @@ void BgLotus_Sink(BgLotus* this, GlobalContext* globalCtx) { this->timer--; BgLotus_SetScaleXZ(this); } else { - if (Lib_StepTowardsCheck_f(&this->dyna.actor.scale.x, 0, 0.0050000003539f)) { + if (Math_StepToF(&this->dyna.actor.scale.x, 0, 0.0050000003539f)) { this->dyna.actor.draw = NULL; this->timer = 100; func_800C62BC(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); diff --git a/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c b/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c index 603a3e18b2..2006a701e7 100644 --- a/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c +++ b/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c @@ -45,7 +45,7 @@ void EnDyExtra_Init(Actor* thisx, GlobalContext* globalCtx) { } void func_80A61334(EnDyExtra* this, GlobalContext* globalCtx) { - Math_SmoothScaleMaxF(&this->actor.gravity, 0.0f, 0.1f, 0.005f); + Math_ApproachF(&this->actor.gravity, 0.0f, 0.1f, 0.005f); if (this->actor.world.pos.y < -85.0f) { this->actor.velocity.y = 0.0f; @@ -58,7 +58,7 @@ void func_80A61334(EnDyExtra* this, GlobalContext* globalCtx) { } void func_80A613C8(EnDyExtra* this, GlobalContext* globalCtx) { - Math_SmoothScaleMaxF(&this->actor.gravity, 0.0f, 0.1f, 0.005f); + Math_ApproachF(&this->actor.gravity, 0.0f, 0.1f, 0.005f); if (this->unk14C == 0 || this->unk150 < 0.02f) { Actor_MarkForDeath(&this->actor); @@ -95,7 +95,7 @@ void EnDyExtra_Draw(Actor* thisx, GlobalContext* globalCtx) { EnDyExtra* this = THIS; s32 pad; GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; - Vtx* vertices = Lib_PtrSegToVirt(D_0600DD40); + Vtx* vertices = Lib_SegmentedToVirtual(D_0600DD40); s32 i; u8 unk[3]; diff --git a/src/overlays/actors/ovl_En_Ending_Hero/z_en_ending_hero.c b/src/overlays/actors/ovl_En_Ending_Hero/z_en_ending_hero.c index 1d4c7a8167..52f6b760c4 100644 --- a/src/overlays/actors/ovl_En_Ending_Hero/z_en_ending_hero.c +++ b/src/overlays/actors/ovl_En_Ending_Hero/z_en_ending_hero.c @@ -86,13 +86,13 @@ void EnEndingHero_Draw(Actor* thisx, GlobalContext* globalCtx) { func_8012C28C(globalCtx->state.gfxCtx); func_8012C2DC(globalCtx->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, Lib_PtrSegToVirt(D_80C1E970[this->unk242])); + gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_80C1E970[this->unk242])); if (this->unk242 < 3) { index = this->unk242; } - gSPSegment(POLY_OPA_DISP++, 0x09, Lib_PtrSegToVirt(D_80C1E984[index])); + gSPSegment(POLY_OPA_DISP++, 0x09, Lib_SegmentedToVirtual(D_80C1E984[index])); SkelAnime_DrawSV(globalCtx, this->skelAnime.skeleton, this->skelAnime.limbDrawTbl, this->skelAnime.dListCount, 0, 0, &this->actor); diff --git a/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c b/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c index d06b07d285..d5a265053f 100644 --- a/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c +++ b/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c @@ -157,9 +157,9 @@ void EnPoFusen_Idle(EnPoFusen *this, GlobalContext *gCtx) { this->actor.shape.rot.z = (Math_SinS(this->randBaseRotChange) * 910.0f); if ((this->randScaleChange < 0x4000) && (this->randScaleChange >= -0x3FFF)) { - Math_SmoothScaleMaxMinS( &this->limb9Rot, 0x38E, 0x14, 0xBB8, 0x64); + Math_SmoothStepToS( &this->limb9Rot, 0x38E, 0x14, 0xBB8, 0x64); } else { - Math_SmoothScaleMaxMinS( &this->limb9Rot, 0x71C, 0x8, 0xBB8, 0x64); + Math_SmoothStepToS( &this->limb9Rot, 0x71C, 0x8, 0xBB8, 0x64); } this->avgBaseRotation = this->limb9Rot * 3; diff --git a/src/overlays/actors/ovl_En_Rsn/z_en_rsn.c b/src/overlays/actors/ovl_En_Rsn/z_en_rsn.c index bdbdbb6900..3c1c82589e 100644 --- a/src/overlays/actors/ovl_En_Rsn/z_en_rsn.c +++ b/src/overlays/actors/ovl_En_Rsn/z_en_rsn.c @@ -95,7 +95,7 @@ void EnRsn_Draw(Actor* thisx, GlobalContext* globalCtx) { EnRsn* this = THIS; OPEN_DISPS(globalCtx->state.gfxCtx); func_8012C5B0(globalCtx->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, Lib_PtrSegToVirt(D_06005458)); + gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_06005458)); SkelAnime_DrawSV(globalCtx, this->skelAnime.skeleton, this->skelAnime.limbDrawTbl, this->skelAnime.dListCount, EnRsn_OverrideLimbDraw, EnRsn_PostLimbDraw, &this->actor); CLOSE_DISPS(globalCtx->state.gfxCtx); diff --git a/src/overlays/actors/ovl_En_Scopecoin/z_en_scopecoin.c b/src/overlays/actors/ovl_En_Scopecoin/z_en_scopecoin.c index 35833f2ce0..67a049bc70 100644 --- a/src/overlays/actors/ovl_En_Scopecoin/z_en_scopecoin.c +++ b/src/overlays/actors/ovl_En_Scopecoin/z_en_scopecoin.c @@ -88,7 +88,7 @@ void EnScopecoin_Draw(Actor *thisx, GlobalContext *globalCtx) { OPEN_DISPS(gfxCtx); gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPSegment(POLY_OPA_DISP++, 0x08, Lib_PtrSegToVirt(D_80BFD280[this->unk148])); + gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_80BFD280[this->unk148])); gSPDisplayList(POLY_OPA_DISP++, D_040622C0); CLOSE_DISPS(gfxCtx); diff --git a/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c b/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c index 850d03597f..14a2f384e4 100644 --- a/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c +++ b/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c @@ -283,7 +283,7 @@ void func_80931004(EnTuboTrap *this, GlobalContext *globalCtx) { // levitate void func_80931138(EnTuboTrap *this, GlobalContext *globalCtx) { this->actor.shape.rot.y += 5000; - Math_SmoothScaleMaxF(&this->actor.world.pos.y, this->targetHeight, 0.8f, 3.0f); + Math_ApproachF(&this->actor.world.pos.y, this->targetHeight, 0.8f, 3.0f); if (fabsf(this->actor.world.pos.y - this->targetHeight) < 10.0f) { this->actor.speedXZ = 10.0f; @@ -301,7 +301,7 @@ void func_809311C4(EnTuboTrap *this, GlobalContext *globalCtx) { Audio_PlayActorSound2(&this->actor, 0x3037); if ((SQ(dX) + SQ(dY) + SQ(dZ) > 57600.0f)) { //240.0f ^ 2 - Math_SmoothScaleMaxF(&this->actor.gravity, -3.0f, 0.2f, 0.5f); + Math_ApproachF(&this->actor.gravity, -3.0f, 0.2f, 0.5f); } this->actor.shape.rot.y += 5000; diff --git a/tables/functions.txt b/tables/functions.txt index 672094f4a1..67c2c31b9f 100644 --- a/tables/functions.txt +++ b/tables/functions.txt @@ -1796,25 +1796,25 @@ 0x800FEAB0:("func_800FEAB0",), 0x800FEAC0:("func_800FEAC0",), 0x800FEAF4:("func_800FEAF4",), - 0x800FEC90:("Lib_bcopy",), + 0x800FEC90:("Lib_MemCpy",), 0x800FECC0:("Lib_MemSet",), 0x800FED44:("Math_CosS",), 0x800FED84:("Math_SinS",), - 0x800FEDC4:("Lib_StepTowardsGet_i",), - 0x800FEE08:("Lib_StepTowards_i",), - 0x800FEE34:("Lib_StepTowardsCheck_i",), - 0x800FEE70:("Lib_StepTowardsCheckFramerateScaled_s",), - 0x800FEF2C:("Lib_StepTowardsCheck_s",), - 0x800FEFB4:("Lib_StepTowardsCheck_c",), - 0x800FF03C:("Lib_StepTowardsCheck_f",), - 0x800FF0D0:("func_800FF0D0",), - 0x800FF138:("func_800FF138",), - 0x800FF1FC:("func_800FF1FC",), - 0x800FF2A8:("func_800FF2A8",), - 0x800FF2F8:("func_800FF2F8",), + 0x800FEDC4:("Math_StepToIImpl",), + 0x800FEE08:("Math_StepToIGet",), + 0x800FEE34:("Math_StepToI",), + 0x800FEE70:("Math_ScaledStepToS",), + 0x800FEF2C:("Math_StepToS",), + 0x800FEFB4:("Math_StepToC",), + 0x800FF03C:("Math_StepToF",), + 0x800FF0D0:("Math_StepUntilAngleS",), + 0x800FF138:("Math_StepToAngleS",), + 0x800FF1FC:("Math_AsymStepToS",), + 0x800FF2A8:("Math_StepUntilF",), + 0x800FF2F8:("Math_AsymStepToF",), 0x800FF3A0:("func_800FF3A0",), 0x800FF450:("Rand_S16Offset",), - 0x800FF4A4:("Math_Rand_S16OffsetStride",), + 0x800FF4A4:("Rand_S16OffsetStride",), 0x800FF50C:("Math_Vec3f_Copy",), 0x800FF52C:("Math_Vec3s_Copy",), 0x800FF54C:("Math_Vec3s_ToVec3f",), @@ -1826,13 +1826,13 @@ 0x800FF6C4:("Math_Vec3f_ScaleAndStore",), 0x800FF6F8:("Math_Vec3f_Lerp",), 0x800FF750:("Math_Vec3f_SumScaled",), - 0x800FF79C:("Math_Vec3f_ModifyRand",), - 0x800FF810:("Math_Vec3f_DistXYZAndStoreNormalizedDiff",), + 0x800FF79C:("Math_Vec3f_AddRand",), + 0x800FF810:("Math_Vec3f_DistXYZAndStoreNormDiff",), 0x800FF884:("Math_Vec3f_DistXYZ",), 0x800FF8D4:("Math_Vec3f_DistXYZAndStoreDiff",), 0x800FF92C:("Math_Vec3f_DistXZ",), 0x800FF960:("Math_Vec3f_DistXZAndStore",), - 0x800FF9A4:("Math_Vec3f_PushAwayXZ",), + 0x800FF9A4:("Math_Vec3f_StepToXZ",), 0x800FFA4C:("Math_Vec3f_DiffY",), 0x800FFA60:("Math_Vec3f_Yaw",), 0x800FFA94:("Math_Vec3f_Pitch",), @@ -1848,23 +1848,23 @@ 0x800FFC50:("IChain_Apply_Vec3f",), 0x800FFC7C:("IChain_Apply_Vec3fdiv1000",), 0x800FFCB4:("IChain_Apply_Vec3s",), - 0x800FFCD8:("Math_SmoothScaleMaxMinF",), - 0x800FFDF8:("Math_SmoothScaleMaxF",), - 0x800FFE68:("Math_SmoothDownscaleMaxF",), - 0x800FFEBC:("Math_SmoothScaleMaxMinS",), - 0x800FFFD8:("Math_SmoothScaleMaxS",), + 0x800FFCD8:("Math_SmoothStepToF",), + 0x800FFDF8:("Math_ApproachF",), + 0x800FFE68:("Math_ApproachZeroF",), + 0x800FFEBC:("Math_SmoothStepToS",), + 0x800FFFD8:("Math_ApproachS",), 0x8010007C:("Color_RGBA8_Copy",), 0x801000A4:("func_801000A4",), 0x801000CC:("func_801000CC",), 0x801000F4:("func_801000F4",), - 0x8010011C:("Lib_TranslateAndRotateYVec3f",), + 0x8010011C:("Lib_Vec3f_TranslateAndRotateY",), 0x801001B8:("Lib_LerpRGB",), - 0x80100448:("Lib_PushAwayVec3f",), + 0x80100448:("Math_Vec3f_StepTo",), 0x801004FC:("Lib_Nop801004FC",), - 0x80100504:("Lib_PtrSegToVirt",), - 0x8010053C:("Lib_PtrSegToVirtNull",), - 0x80100584:("Lib_PtrSegToK0",), - 0x801005A0:("Lib_PtrSegToK0Null",), + 0x80100504:("Lib_SegmentedToVirtual",), + 0x8010053C:("Lib_SegmentedToVirtualNull",), + 0x80100584:("Lib_PhysicalToVirtual",), + 0x801005A0:("Lib_PhysicalToVirtualNull",), 0x801005C0:("LifeMeter_Init",), 0x8010069C:("LifeMeter_UpdateColors",), 0x80100A80:("func_80100A80",), diff --git a/tables/variables.txt b/tables/variables.txt index cc61fee78d..f6b846a036 100644 --- a/tables/variables.txt +++ b/tables/variables.txt @@ -1004,7 +1004,7 @@ 0x801BE90C:("D_801BE90C","UNK_TYPE1","",0x1), 0x801BE92C:("D_801BE92C","UNK_TYPE1","",0x1), 0x801BE944:("D_801BE944","UNK_TYPE1","",0x1), - 0x801BE960:("actorInitVarFuncs","actor_init_var_func","[11]",0x2c), + 0x801BE960:("sInitChainHandlers","actor_init_var_func","[11]",0x2c), 0x801BE990:("D_801BE990","UNK_TYPE2","",0x2), 0x801BE992:("D_801BE992","UNK_TYPE2","",0x2), 0x801BE994:("D_801BE994","UNK_TYPE2","",0x2),