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
This commit is contained in:
Rozelette
2021-04-07 16:16:16 -05:00
committed by GitHub
parent b22e26dbd8
commit d2c181a0a9
34 changed files with 626 additions and 492 deletions
+2 -2
View File
@@ -18,7 +18,7 @@
/* Functions */
extern u32 osVirtualToPhysical(void*);
extern void* osPhysicalToVirtual(u32);
extern uintptr_t osVirtualToPhysical(void*);
extern void* osPhysicalToVirtual(uintptr_t);
#endif
+50 -50
View File
@@ -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);
-28
View File
@@ -1,28 +0,0 @@
#ifndef _GUINT_H_
#define _GUINT_H_
// TODO should be in libultra/gu
#include <PR/gbi.h>
#include <PR/abi.h>
#include <PR/ultratypes.h>
#include <sptask.h> // TODO the load path for this is actually PR/sptask.h, why?
#include <PR/gu.h>
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
+5 -4
View File
@@ -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
+29
View File
@@ -0,0 +1,29 @@
#ifndef _MATH_H_
#define _MATH_H_
#include <PR/ultratypes.h>
#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
+7
View File
@@ -0,0 +1,7 @@
#ifndef _STDBOOL_H_
#define _STDBOOL_H_
#define false 0
#define true !false
#endif /* _STDBOOL_H_ */
+29
View File
@@ -0,0 +1,29 @@
#ifndef _STDINT_H_
#define _STDINT_H_
#include <ultra64.h>
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_ */
+1 -1
View File
@@ -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;
+5 -3
View File
@@ -1,13 +1,17 @@
#ifndef _Z64_H_
#define _Z64_H_
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <PR/ultratypes.h>
#include <PR/gbi.h>
#include <PR/sched.h>
#include <io/controller.h>
#include <osint.h>
#include <viint.h>
#include <guint.h>
#include <math.h>
#include <os.h>
#include <stdlib.h>
#include <xstdio.h>
@@ -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);