summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-11-22 23:55:05 -0300
committerGitHub <noreply@github.com>2023-11-23 13:55:05 +1100
commit506e2155474b1914fe93f070c55debdeaf6df0a6 (patch)
tree5ffab32ee39bb1cafc8803caafd1030ff72f93ef
parent5ef277df2db5dd54c02c098ec88777f63680f6c3 (diff)
Yet another header cleanup (#1508)
* lights.c * z64skin_matrix.h * Move out some stuff from macros.h * gamealloc.h * move most transition functions to z64transition.h * z64lib.h * `include` cleanup on transition files * z_overlay cleanup * z64malloc.h * format * forgot to remove those * forgot this * fix borken includes
-rw-r--r--include/functions.h117
-rw-r--r--include/gamealloc.h24
-rw-r--r--include/gfx.h21
-rw-r--r--include/ichain.h2
-rw-r--r--include/macros.h20
-rw-r--r--include/main.h2
-rw-r--r--include/variables.h4
-rw-r--r--include/z64.h4
-rw-r--r--include/z64curve.h3
-rw-r--r--include/z64game.h16
-rw-r--r--include/z64lib.h29
-rw-r--r--include/z64light.h32
-rw-r--r--include/z64malloc.h17
-rw-r--r--include/z64math.h1
-rw-r--r--include/z64save.h4
-rw-r--r--include/z64skin.h11
-rw-r--r--include/z64skin_matrix.h34
-rw-r--r--include/z64speed_meter.h2
-rw-r--r--include/z64transition.h76
-rw-r--r--src/code/gamealloc.c6
-rw-r--r--src/code/speed_meter.c13
-rw-r--r--src/code/z_actor.c2
-rw-r--r--src/code/z_camera.c1
-rw-r--r--src/code/z_collision_check.c4
-rw-r--r--src/code/z_effect_soft_sprite.c1
-rw-r--r--src/code/z_fbdemo.c3
-rw-r--r--src/code/z_fbdemo_circle.c24
-rw-r--r--src/code/z_fbdemo_dlftbls.c5
-rw-r--r--src/code/z_fbdemo_fade.c12
-rw-r--r--src/code/z_fcurve_data_skelanime.c10
-rw-r--r--src/code/z_lib.c12
-rw-r--r--src/code/z_lights.c28
-rw-r--r--src/code/z_malloc.c3
-rw-r--r--src/code/z_overlay.c60
-rw-r--r--src/code/z_parameter.c2
-rw-r--r--src/code/z_play.c1
-rw-r--r--src/code/z_play_hireso.c2
-rw-r--r--src/code/z_skelanime.c1
-rw-r--r--src/code/z_skin_awb.c4
-rw-r--r--src/code/z_skin_matrix.c6
-rw-r--r--src/libultra/gu/cosf.c1
-rw-r--r--src/libultra/gu/sinf.c1
-rw-r--r--src/libultra/io/controller.c1
-rw-r--r--src/overlays/actors/ovl_En_Test3/z_en_test3.c3
-rw-r--r--src/overlays/actors/ovl_En_Test6/z_en_test6.c5
-rw-r--r--src/overlays/actors/ovl_player_actor/z_player.c1
-rw-r--r--undefined_syms.txt5
47 files changed, 386 insertions, 250 deletions
diff --git a/include/functions.h b/include/functions.h
index 50e7687c3..8a63226ed 100644
--- a/include/functions.h
+++ b/include/functions.h
@@ -489,7 +489,6 @@ s32 Actor_TrackNone(Vec3s* headRot, Vec3s* torsoRot);
s32 Actor_TrackPoint(Actor* actor, Vec3f* target, Vec3s* headRot, Vec3s* torsoRot);
s32 Actor_TrackPlayerSetFocusHeight(PlayState* play, Actor* actor, Vec3s* headRot, Vec3s* torsoRot, f32 focusHeight);
s32 Actor_TrackPlayer(PlayState* play, Actor* actor, Vec3s* headRot, Vec3s* torsoRot, Vec3f focusPos);
-void SaveContext_Init(void);
void GetItem_Draw(PlayState* play, s16 drawId);
@@ -505,21 +504,6 @@ void Font_LoadCharNES(PlayState* play, u8 codePointIndex, s32 offset);
void Font_LoadMessageBoxEndIcon(Font* font, u16 icon);
void Font_LoadOrderedFont(Font* font);
-void* Lib_MemCpy(void* dest, void* src, size_t size);
-void* Lib_MemSet(void* buffer, s32 value, size_t size);
-void Lib_GetControlStickData(f32* outMagnitude, s16* outAngle, Input* input);
-void Actor_ProcessInitChain(Actor* actor, InitChainEntry* ichain);
-void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src);
-void Lib_PlaySfx(u16 sfxId);
-void Lib_PlaySfx_2(u16 sfxId);
-void Lib_PlaySfx_AtPos(Vec3f* pos, u16 sfxId);
-void Lib_Vec3f_TranslateAndRotateY(Vec3f* translation, s16 rotAngle, Vec3f* src, Vec3f* dst);
-void Color_RGB8_Lerp(Color_RGB8* from, Color_RGB8* to, f32 lerp, Color_RGB8* dst);
-void Lib_Nop801004FC(void);
-void* Lib_SegmentedToVirtual(void* ptr);
-void* Lib_SegmentedToVirtualNull(void* ptr);
-uintptr_t Lib_VirtualToPhysical(void* ptr);
-void* Lib_PhysicalToVirtual(uintptr_t ptr);
void LifeMeter_Init(PlayState* play);
void LifeMeter_UpdateColors(PlayState* play);
s32 LifeMeter_SaveInterfaceHealth(PlayState* play);
@@ -528,43 +512,7 @@ s32 LifeMeter_DecreaseInterfaceHealth(PlayState* play);
void LifeMeter_Draw(PlayState* play);
void LifeMeter_UpdateSizeAndBeep(PlayState* play);
u32 LifeMeter_IsCritical(void);
-void Lights_PointSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius, s32 type);
-void Lights_PointNoGlowSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius);
-void Lights_PointGlowSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius);
-void Lights_PointSetColorAndRadius(LightInfo* info, u8 r, u8 g, u8 b, s16 radius);
-void Lights_PointSetPosition(LightInfo* info, s16 x, s16 y, s16 z);
-void Lights_DirectionalSetInfo(LightInfo* info, s8 x, s8 y, s8 z, u8 r, u8 g, u8 b);
-void Lights_Reset(Lights* lights, u8 r, u8 g, u8 b);
-void Lights_Draw(Lights* lights, GraphicsContext* gfxCtx);
-Light* Lights_FindSlot(Lights* lights);
-void Lights_BindPointWithReference(Lights* lights, LightParams* params, Vec3f* pos);
-void Lights_BindPoint(Lights* lights, LightParams* params, PlayState* play);
-void Lights_BindDirectional(Lights* lights, LightParams* params, void* unused);
-void Lights_BindAll(Lights* lights, LightNode* listHead, Vec3f* refPos, PlayState* play);
-LightNode* Lights_FindBufSlot(void);
-void Lights_FreeNode(LightNode* light);
-void LightContext_Init(PlayState* play, LightContext* lightCtx);
-void LightContext_SetAmbientColor(LightContext* lightCtx, u8 r, u8 g, u8 b);
-void LightContext_SetFog(LightContext* lightCtx, u8 r, u8 g, u8 b, s16 near, s16 far);
-Lights* LightContext_NewLights(LightContext* lightCtx, GraphicsContext* gfxCtx);
-void LightContext_InitList(PlayState* play, LightContext* lightCtx);
-void LightContext_DestroyList(PlayState* play, LightContext* lightCtx);
-LightNode* LightContext_InsertLight(PlayState* play, LightContext* lightCtx, LightInfo* info);
-void LightContext_RemoveLight(PlayState* play, LightContext* lightCtx, LightNode* light);
-Lights* Lights_NewAndDraw(GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambientB, u8 numLights, u8 r, u8 g, u8 b, s8 x, s8 y, s8 z);
-Lights* Lights_New(GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambientB);
-void Lights_GlowCheck(PlayState* play);
-void Lights_DrawGlow(PlayState* play);
-void* ZeldaArena_Malloc(size_t size);
-void* ZeldaArena_MallocR(size_t size);
-void* ZeldaArena_Realloc(void* ptr, size_t newSize);
-void ZeldaArena_Free(void* ptr);
-void* ZeldaArena_Calloc(size_t num, size_t size);
-void ZeldaArena_GetSizes(size_t* outMaxFree, size_t* outFree, size_t* outAlloc);
-s32 ZeldaArena_Check(void);
-void ZeldaArena_Init(void* start, size_t size);
-void ZeldaArena_Cleanup(void);
-u8 ZeldaArena_IsInitialized(void);
+
// void func_80102E40(void);
// void func_80102E90(void);
// void func_80102EA4(void);
@@ -773,31 +721,6 @@ void Inventory_SaveLotteryCodeGuess(PlayState* play);
s32 Schedule_RunScript(PlayState* play, u8* script, ScheduleOutput* output);
-void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDest);
-void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest);
-void SkinMatrix_MtxFMtxFMult(MtxF* mfB, MtxF* mfA, MtxF* dest);
-void SkinMatrix_GetClear(MtxF** mfp);
-void SkinMatrix_GetClear(MtxF** mfp);
-void SkinMatrix_MtxFCopy(MtxF* src, MtxF* dest);
-s32 SkinMatrix_Invert(MtxF* src, MtxF* dest);
-void SkinMatrix_SetScale(MtxF* mf, f32 x, f32 y, f32 z);
-void SkinMatrix_SetRotateRPY(MtxF* mf, s16 roll, s16 pitch, s16 yaw);
-void SkinMatrix_SetRotateYRP(MtxF* mf, s16 yaw, s16 roll, s16 pitch);
-void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z);
-void SkinMatrix_SetScaleRotateRPYTranslate(MtxF* mf, f32 scaleX, f32 scaleY, f32 scaleZ, s16 roll, s16 pitch, s16 yaw, f32 dx, f32 dy, f32 dz);
-void SkinMatrix_SetScaleRotateYRPTranslate(MtxF* mf, f32 scaleX, f32 scaleY, f32 scaleZ, s16 yaw, s16 roll, s16 pitch, f32 dx, f32 dy, f32 dz);
-void SkinMatrix_SetRotateRPYTranslate(MtxF* mf, s16 roll, s16 pitch, s16 yaw, f32 dx, f32 dy, f32 dz);
-void SkinMatrix_Vec3fToVec3s(Vec3f* src, Vec3s* dest);
-void SkinMatrix_Vec3sToVec3f(Vec3s* src, Vec3f* dest);
-void SkinMatrix_MtxFToMtx(MtxF* src, Mtx* dest);
-Mtx* SkinMatrix_MtxFToNewMtx(GraphicsContext* gfxCtx, MtxF* src);
-void SkinMatrix_SetRotateAroundVec(MtxF* mf, s16 a, f32 x, f32 y, f32 z);
-void SkinMatrix_SetXRotation(MtxF* mf, s16 a);
-void SkinMatrix_MulXRotation(MtxF* mf, s16 a);
-void SkinMatrix_SetYRotation(MtxF* mf, s16 a);
-void SkinMatrix_MulYRotation(MtxF* mf, s16 a);
-void SkinMatrix_SetZRotation(MtxF* mf, s16 a);
-
uintptr_t KaleidoManager_FaultAddrConv(uintptr_t address, void* param);
void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl);
void KaleidoManager_ClearOvl(KaleidoMgrOverlay* ovl);
@@ -809,39 +732,6 @@ void KaleidoScopeCall_Init(PlayState* play);
void KaleidoScopeCall_Destroy(PlayState* play);
void KaleidoScopeCall_Update(PlayState* play);
void KaleidoScopeCall_Draw(PlayState* play);
-void Transition_Init(TransitionContext* transitionCtx);
-void Transition_Destroy(TransitionContext* transitionCtx);
-
-void TransitionTile_Destroy(TransitionTile* this);
-TransitionTile* TransitionTile_Init(TransitionTile* this, s32 cols, s32 rows);
-void TransitionTile_Draw(TransitionTile* this, Gfx** gfxP);
-void TransitionTile_Update(TransitionTile* this);
-
-void TransitionFade_Start(void* thisx);
-void* TransitionFade_Init(void* thisx);
-void TransitionFade_Destroy(void* thisx);
-void TransitionFade_Update(void* thisx, s32 updateRate);
-void TransitionFade_Draw(void* thisx, Gfx** gfxP);
-s32 TransitionFade_IsDone(void* thisx);
-void TransitionFade_SetColor(void* thisx, u32 color);
-void TransitionFade_SetType(void* thisx, s32 type);
-void TransitionOverlay_ClearLoadInfo(TransitionOverlay *overlayEntry);
-void TransitionOverlay_SetSegment(TransitionOverlay *overlayEntry, void* vramStart, void* vramEnd, uintptr_t vromStart, uintptr_t vromEnd);
-void TransitionCircle_Start(void* thisx);
-void* TransitionCircle_Init(void* thisx);
-void TransitionCircle_Destroy(void* thisx);
-void TransitionCircle_Update(void* thisx);
-void TransitionCircle_SetColor(void* thisx, u32 color);
-void TransitionCircle_SetType(void* thisx, s32 type);
-void TransitionCircle_LoadAndSetTexture(Gfx** gfxp, TexturePtr texture, s32 fmt, s32 arg3, s32 masks, s32 maskt, f32 arg6);
-void TransitionCircle_Draw(void* thisx, Gfx** gfxp);
-s32 TransitionCircle_IsDone(void* thisx);
-void* TransitionOverlay_VramToRam(TransitionOverlay *overlayEntry, void* vramAddr);
-void TransitionOverlay_VramToRamArray(TransitionOverlay *overlayEntry, void** vramAddrs, s32 count);
-s32 TransitionOverlay_Load(TransitionOverlay *overlayEntry);
-s32 TransitionOverlay_Free(TransitionOverlay *overlayEntry);
-void func_80165438(UNK_PTR param_1);
-// void func_80165444(s32 param_1, UNK_TYPE4 param_2, UNK_TYPE4 param_3, UNK_TYPE4 param_4, UNK_TYPE4 param_5);
void Play_SetMotionBlurAlpha(u32 alpha);
void Play_EnableMotionBlur(u32 alpha);
@@ -894,11 +784,6 @@ void Play_AssignPlayerCsIdsFromScene(GameState* thisx, s32 spawnCsId);
void Play_FillScreen(GameState* thisx, s16 fillScreenOn, u8 red, u8 green, u8 blue, u8 alpha);
void Play_Init(GameState* thisx);
-void GameAlloc_Log(GameAlloc* this);
-void* GameAlloc_Malloc(GameAlloc* this, size_t size);
-void GameAlloc_Free(GameAlloc* this, void* data);
-void GameAlloc_Cleanup(GameAlloc* this);
-void GameAlloc_Init(GameAlloc* this);
void Graph_FaultClient(void);
void Graph_InitTHGA(TwoHeadGfxArena* arena, Gfx* buffer, s32 size);
void Graph_SetNextGfxPool(GraphicsContext* gfxCtx);
diff --git a/include/gamealloc.h b/include/gamealloc.h
new file mode 100644
index 000000000..ad97415ea
--- /dev/null
+++ b/include/gamealloc.h
@@ -0,0 +1,24 @@
+#ifndef GAMEALLOC_H
+#define GAMEALLOC_H
+
+#include "ultra64.h"
+
+typedef struct GameAllocEntry {
+ /* 0x0 */ struct GameAllocEntry* next;
+ /* 0x4 */ struct GameAllocEntry* prev;
+ /* 0x8 */ size_t size;
+ /* 0xC */ u32 unk_0C;
+} GameAllocEntry; // size = 0x10
+
+typedef struct GameAlloc {
+ /* 0x00 */ GameAllocEntry base;
+ /* 0x10 */ GameAllocEntry* head;
+} GameAlloc; // size = 0x14
+
+void GameAlloc_Log(GameAlloc* this);
+void* GameAlloc_Malloc(GameAlloc* this, size_t size);
+void GameAlloc_Free(GameAlloc* this, void* data);
+void GameAlloc_Cleanup(GameAlloc* this);
+void GameAlloc_Init(GameAlloc* this);
+
+#endif
diff --git a/include/gfx.h b/include/gfx.h
index 87f949d8b..a26c759ad 100644
--- a/include/gfx.h
+++ b/include/gfx.h
@@ -239,6 +239,10 @@ void func_8012D40C(f32* param_1, f32* param_2, s16* param_3);
extern Gfx gSetupDLs[SETUPDL_MAX][6];
extern Gfx gEmptyDL[];
+
+extern GfxMasterList D_0E000000;
+
+
#define WORK_DISP __gfxCtx->work.p
#define POLY_OPA_DISP __gfxCtx->polyOpa.p
#define POLY_XLU_DISP __gfxCtx->polyXlu.p
@@ -283,4 +287,21 @@ extern Gfx gEmptyDL[];
_g->words.w1 = (unsigned int)(d); \
})
+/**
+ * `x` vertex x
+ * `y` vertex y
+ * `z` vertex z
+ * `s` texture s coordinate
+ * `t` texture t coordinate
+ * `crnx` red component of color vertex, or x component of normal vertex
+ * `cgny` green component of color vertex, or y component of normal vertex
+ * `cbnz` blue component of color vertex, or z component of normal vertex
+ * `a` alpha
+ */
+#define VTX(x, y, z, s, t, crnx, cgny, cbnz, a) \
+ { { { x, y, z }, 0, { s, t }, { crnx, cgny, cbnz, a } }, }
+
+#define VTX_T(x, y, z, s, t, cr, cg, cb, a) \
+ { { x, y, z }, 0, { s, t }, { cr, cg, cb, a }, }
+
#endif
diff --git a/include/ichain.h b/include/ichain.h
index 07bd07313..591bd8f57 100644
--- a/include/ichain.h
+++ b/include/ichain.h
@@ -3,7 +3,7 @@
#include "libc/stddef.h"
-typedef struct {
+typedef struct InitChainEntry {
u32 cont: 1;
u32 type: 4;
u32 offset: 11;
diff --git a/include/macros.h b/include/macros.h
index 223a12e8e..6d7433037 100644
--- a/include/macros.h
+++ b/include/macros.h
@@ -3,7 +3,6 @@
#include "libc/stdint.h"
#include "PR/os_convert.h"
-#include "main.h"
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
@@ -21,8 +20,6 @@
#define ARRAY_COUNT_2D(arr) (ARRAY_COUNT(arr) * ARRAY_COUNT(arr[0]))
-#define SEGMENTED_TO_K0(addr) (void*)((gSegments[SEGMENT_NUMBER(addr)] + K0BASE) + SEGMENT_OFFSET(addr))
-
#define GET_ACTIVE_CAM(play) ((play)->cameraPtrs[(play)->activeCamId])
#define GET_PLAYER(play) ((Player*)(play)->actorCtx.actorLists[ACTORCAT_PLAYER].first)
@@ -67,23 +64,6 @@
(flag & 0x1) ? 0 : \
0)
-/**
- * `x` vertex x
- * `y` vertex y
- * `z` vertex z
- * `s` texture s coordinate
- * `t` texture t coordinate
- * `crnx` red component of color vertex, or x component of normal vertex
- * `cgny` green component of color vertex, or y component of normal vertex
- * `cbnz` blue component of color vertex, or z component of normal vertex
- * `a` alpha
- */
-#define VTX(x, y, z, s, t, crnx, cgny, cbnz, a) \
- { { { x, y, z }, 0, { s, t }, { crnx, cgny, cbnz, a } }, }
-
-#define VTX_T(x, y, z, s, t, cr, cg, cb, a) \
- { { x, y, z }, 0, { s, t }, { cr, cg, cb, a }, }
-
#define SQ(x) ((x) * (x))
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define ABS_ALT(x) ((x) < 0 ? -(x) : (x))
diff --git a/include/main.h b/include/main.h
index 2b25dbb07..796faece0 100644
--- a/include/main.h
+++ b/include/main.h
@@ -16,4 +16,6 @@ extern PadMgr gPadMgr;
void Main(void* arg);
+#define SEGMENTED_TO_K0(addr) (void*)((gSegments[SEGMENT_NUMBER(addr)] + K0BASE) + SEGMENT_OFFSET(addr))
+
#endif
diff --git a/include/variables.h b/include/variables.h
index 6cec93922..474251159 100644
--- a/include/variables.h
+++ b/include/variables.h
@@ -1519,7 +1519,6 @@ extern TriNorm D_801EF590;
extern TriNorm D_801EF5C8;
extern TriNorm D_801EF600;
extern TriNorm D_801EF638;
-extern SaveContext gSaveContext;
// extern UNK_TYPE1 D_801F4E20;
// extern UNK_TYPE1 sBeatingHeartsDDPrim;
@@ -1532,7 +1531,7 @@ extern SaveContext gSaveContext;
// extern UNK_TYPE1 D_801F4F66;
// extern UNK_TYPE1 D_801F4F68;
// extern UNK_TYPE1 D_801F4F6A;
-// extern LightsBuffer sLightsBuffer;
+
// extern UNK_TYPE1 D_801F5130;
// extern UNK_TYPE1 D_801F5270;
// extern UNK_TYPE1 D_801F528E;
@@ -1652,7 +1651,6 @@ extern AudioCustomReverbFunction gAudioCustomReverbFunction;
extern AudioCustomSynthFunction gAudioCustomSynthFunction;
// other segments
-extern GfxMasterList D_0E000000;
extern Mtx D_01000000;
extern u16 D_0F000000[];
diff --git a/include/z64.h b/include/z64.h
index d8aa31074..5ef67b9e8 100644
--- a/include/z64.h
+++ b/include/z64.h
@@ -21,6 +21,8 @@
#include "sfx.h"
#include "message_data_static.h"
+#include "main.h"
+
#include "gfx.h"
#include "gfxprint.h"
#include "padutils.h"
@@ -47,6 +49,7 @@
#include "z64game.h"
#include "z64interface.h"
#include "z64item.h"
+#include "z64lib.h"
#include "z64light.h"
#include "z64map.h"
#include "z64math.h"
@@ -58,6 +61,7 @@
#include "z64save.h"
#include "z64scene.h"
#include "z64schedule.h"
+#include "z64skin_matrix.h"
#include "z64skin.h"
#include "z64skybox.h"
#include "z64sound_source.h"
diff --git a/include/z64curve.h b/include/z64curve.h
index 77174be5e..ae3c3442b 100644
--- a/include/z64curve.h
+++ b/include/z64curve.h
@@ -4,6 +4,7 @@
#include "PR/ultratypes.h"
#include "z64math.h"
+struct Actor;
struct PlayState;
typedef struct {
@@ -56,7 +57,7 @@ s32 SkelCurve_Init(struct PlayState* play, SkelCurve* skelCurve, CurveSkeletonHe
void SkelCurve_Destroy(struct PlayState* play, SkelCurve* skelCurve);
void SkelCurve_SetAnim(SkelCurve* skelCurve, CurveAnimationHeader* animation, f32 arg2, f32 endFrame, f32 curFrame, f32 playSpeed);
s32 SkelCurve_Update(struct PlayState* play, SkelCurve* skelCurve);
-void SkelCurve_Draw(Actor* actor, struct PlayState* play, SkelCurve* skelCurve, OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, Actor* thisx);
+void SkelCurve_Draw(struct Actor* actor, struct PlayState* play, SkelCurve* skelCurve, OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, struct Actor* thisx);
// ZAPD compatibility typedefs
diff --git a/include/z64game.h b/include/z64game.h
index 50dd68473..352c5e189 100644
--- a/include/z64game.h
+++ b/include/z64game.h
@@ -2,11 +2,13 @@
#define Z64GAME_H
#include "ultra64.h"
+
#include "libc/stdbool.h"
#include "libc/stdint.h"
+#include "gamealloc.h"
+#include "padmgr.h"
#include "padutils.h"
#include "tha.h"
-#include "padmgr.h"
#include "unk.h"
struct GraphicsContext;
@@ -42,18 +44,6 @@ typedef struct {
/* 0x2C */ size_t instanceSize;
} GameStateOverlay; // size = 0x30
-typedef struct GameAllocEntry {
- /* 0x0 */ struct GameAllocEntry* next;
- /* 0x4 */ struct GameAllocEntry* prev;
- /* 0x8 */ size_t size;
- /* 0xC */ u32 unk_0C;
-} GameAllocEntry; // size = 0x10
-
-typedef struct GameAlloc {
- /* 0x00 */ GameAllocEntry base;
- /* 0x10 */ GameAllocEntry* head;
-} GameAlloc; // size = 0x14
-
typedef struct GameState {
/* 0x00 */ struct GraphicsContext* gfxCtx;
/* 0x04 */ GameStateFunc main;
diff --git a/include/z64lib.h b/include/z64lib.h
new file mode 100644
index 000000000..0a4009ba3
--- /dev/null
+++ b/include/z64lib.h
@@ -0,0 +1,29 @@
+#ifndef Z64LIB_H
+#define Z64LIB_H
+
+#include "ultra64.h"
+
+#include "color.h"
+#include "z64math.h"
+
+struct Actor;
+struct InitChainEntry;
+struct Input;
+
+void* Lib_MemCpy(void* dest, void* src, size_t size);
+void* Lib_MemSet(void* buffer, s32 value, size_t size);
+void Lib_GetControlStickData(f32* outMagnitude, s16* outAngle, struct Input* input);
+void Actor_ProcessInitChain(struct Actor* actor, struct InitChainEntry* ichain);
+void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src);
+void Lib_PlaySfx(u16 sfxId);
+void Lib_PlaySfx_2(u16 sfxId);
+void Lib_PlaySfx_AtPos(Vec3f* pos, u16 sfxId);
+void Lib_Vec3f_TranslateAndRotateY(Vec3f* translation, s16 rotAngle, Vec3f* src, Vec3f* dst);
+void Color_RGB8_Lerp(Color_RGB8* from, Color_RGB8* to, f32 lerp, Color_RGB8* dst);
+void Lib_Nop801004FC(void);
+void* Lib_SegmentedToVirtual(void* ptr);
+void* Lib_SegmentedToVirtualNull(void* ptr);
+uintptr_t Lib_VirtualToPhysical(void* ptr);
+void* Lib_PhysicalToVirtual(uintptr_t ptr);
+
+#endif
diff --git a/include/z64light.h b/include/z64light.h
index 21b1920c3..7b9fa12a1 100644
--- a/include/z64light.h
+++ b/include/z64light.h
@@ -2,13 +2,13 @@
#define Z64LIGHT_H
#include "ultra64.h"
-#include "PR/gbi.h"
#include "color.h"
#include "z64math.h"
+struct GraphicsContext;
struct PlayState;
-typedef struct {
+typedef struct AdjLightSettings {
/* 0x00 */ s16 ambientColor[3];
/* 0x06 */ s16 light1Color[3];
/* 0x0C */ s16 light2Color[3];
@@ -17,7 +17,7 @@ typedef struct {
/* 0x1A */ s16 zFar;
} AdjLightSettings; // size = 0x1C
-typedef struct {
+typedef struct LightPoint {
/* 0x0 */ s16 x;
/* 0x2 */ s16 y;
/* 0x4 */ s16 z;
@@ -26,7 +26,7 @@ typedef struct {
/* 0xA */ s16 radius;
} LightPoint; // size = 0xC
-typedef struct {
+typedef struct LightDirectional {
/* 0x0 */ s8 x;
/* 0x1 */ s8 y;
/* 0x2 */ s8 z;
@@ -39,7 +39,7 @@ typedef union LightParams {
} LightParams; // size = 0xC
typedef struct LightInfo {
- /* 0x0 */ u8 type;
+ /* 0x0 */ u8 type; // LightType enum
/* 0x2 */ LightParams params;
} LightInfo; // size = 0xE
@@ -77,7 +77,25 @@ typedef enum LightType {
/* 2 */ LIGHT_POINT_GLOW
} LightType;
-typedef void (*LightsBindFunc)(Lights* lights, LightParams* params, Vec3f* vec);
-typedef void (*LightsPosBindFunc)(Lights* lights, LightParams* params, struct PlayState* play);
+void Lights_PointNoGlowSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius);
+void Lights_PointGlowSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius);
+void Lights_PointSetColorAndRadius(LightInfo* info, u8 r, u8 g, u8 b, s16 radius);
+void Lights_PointSetPosition(LightInfo* info, s16 x, s16 y, s16 z);
+void Lights_DirectionalSetInfo(LightInfo* info, s8 x, s8 y, s8 z, u8 r, u8 g, u8 b);
+void Lights_Reset(Lights* lights, u8 r, u8 g, u8 b);
+void Lights_Draw(Lights* lights, struct GraphicsContext* gfxCtx);
+void Lights_BindAll(Lights* lights, LightNode* listHead, Vec3f* refPos, struct PlayState* play);
+void LightContext_Init(struct PlayState* play, LightContext* lightCtx);
+void LightContext_SetAmbientColor(LightContext* lightCtx, u8 r, u8 g, u8 b);
+void LightContext_SetFog(LightContext* lightCtx, u8 r, u8 g, u8 b, s16 near, s16 far);
+Lights* LightContext_NewLights(LightContext* lightCtx, struct GraphicsContext* gfxCtx);
+void LightContext_InitList(struct PlayState* play, LightContext* lightCtx);
+void LightContext_DestroyList(struct PlayState* play, LightContext* lightCtx);
+LightNode* LightContext_InsertLight(struct PlayState* play, LightContext* lightCtx, LightInfo* info);
+void LightContext_RemoveLight(struct PlayState* play, LightContext* lightCtx, LightNode* light);
+Lights* Lights_NewAndDraw(struct GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambientB, u8 numLights, u8 r, u8 g, u8 b, s8 x, s8 y, s8 z);
+Lights* Lights_New(struct GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambientB);
+void Lights_GlowCheck(struct PlayState* play);
+void Lights_DrawGlow(struct PlayState* play);
#endif
diff --git a/include/z64malloc.h b/include/z64malloc.h
new file mode 100644
index 000000000..b679d3984
--- /dev/null
+++ b/include/z64malloc.h
@@ -0,0 +1,17 @@
+#ifndef Z64MALLOC_H
+#define Z64MALLOC_H
+
+#include "ultra64.h"
+
+void* ZeldaArena_Malloc(size_t size);
+void* ZeldaArena_MallocR(size_t size);
+void* ZeldaArena_Realloc(void* ptr, size_t newSize);
+void ZeldaArena_Free(void* ptr);
+void* ZeldaArena_Calloc(size_t num, size_t size);
+void ZeldaArena_GetSizes(size_t* outMaxFree, size_t* outFree, size_t* outAlloc);
+s32 ZeldaArena_Check(void);
+void ZeldaArena_Init(void* start, size_t size);
+void ZeldaArena_Cleanup(void);
+u8 ZeldaArena_IsInitialized(void);
+
+#endif
diff --git a/include/z64math.h b/include/z64math.h
index fa9b0a4ff..27ab62dca 100644
--- a/include/z64math.h
+++ b/include/z64math.h
@@ -2,6 +2,7 @@
#define Z64MATH_H
#include "ultra64.h"
+#include "libc/math.h"
#define VEC_SET(V,X,Y,Z) V.x=X;V.y=Y;V.z=Z
diff --git a/include/z64save.h b/include/z64save.h
index cdebffc25..67449a178 100644
--- a/include/z64save.h
+++ b/include/z64save.h
@@ -1678,6 +1678,8 @@ void Sram_SetFlashPagesOwlSave(SramContext* sramCtx, s32 curPage, s32 numPages);
void Sram_StartWriteToFlashOwlSave(SramContext* sramCtx);
void Sram_UpdateWriteToFlashOwlSave(SramContext* sramCtx);
+void SaveContext_Init(void);
+
extern u32 gSramSlotOffsets[];
extern u8 gAmmoItems[];
extern s32 gFlashSaveStartPages[];
@@ -1686,4 +1688,6 @@ extern s32 gFlashSpecialSaveNumPages[];
extern s32 gFlashOwlSaveStartPages[];
extern s32 gFlashOwlSaveNumPages[];
+extern SaveContext gSaveContext;
+
#endif
diff --git a/include/z64skin.h b/include/z64skin.h
index a9e2ebc01..b334e939c 100644
--- a/include/z64skin.h
+++ b/include/z64skin.h
@@ -3,6 +3,7 @@
#include "z64animation.h"
+struct Actor;
struct GraphicsContext;
struct GameState;
struct PlayState;
@@ -89,10 +90,10 @@ void Skin_UpdateVertices(MtxF* mtx, SkinVertex* skinVertices, SkinLimbModif* mod
void Skin_ApplyLimbModifications(struct GraphicsContext* gfxCtx, Skin* skin, s32 limbIndex, s32 arg3);
void Skin_DrawAnimatedLimb(struct GraphicsContext* gfxCtx, Skin* skin, s32 limbIndex, s32 arg3, s32 drawFlags);
void Skin_DrawLimb(struct GraphicsContext* gfxCtx, Skin* skin, s32 limbIndex, Gfx* dListOverride, s32 drawFlags);
-void func_80138228(Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, s32 setTranslation);
-void func_80138258(Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation);
-void func_8013828C(Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation, s32 arg6);
-void func_801382C4(Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation, s32 arg6, s32 drawFlags);
+void func_80138228(struct Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, s32 setTranslation);
+void func_80138258(struct Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation);
+void func_8013828C(struct Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation, s32 arg6);
+void func_801382C4(struct Actor* actor, struct PlayState* play, Skin* skin, SkinPostDraw postDraw, SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation, s32 arg6, s32 drawFlags);
void Skin_GetLimbPos(Skin* skin, s32 limbIndex, Vec3f* offset, Vec3f* dst);
void Skin_GetVertexPos(Skin* skin, s32 limbIndex, s32 vtxIndex, Vec3f* dst);
@@ -101,6 +102,6 @@ void Skin_InitAnimatedLimb(struct GameState* gameState, Skin* skin, s32 limbInde
void Skin_Init(struct GameState* gameState, Skin* skin, SkeletonHeader* skeletonHeader, AnimationHeader* animationHeader);
void Skin_Free(struct GameState* gameState, Skin* skin);
s32 func_801387D4(Skin* skin, SkinLimb** skeleton, MtxF* limbMatrices, u8 parentIndex, u8 limbIndex);
-s32 Skin_ApplyAnimTransformations(Skin* skin, MtxF* limbMatrices, Actor* actor, s32 setTranslation);
+s32 Skin_ApplyAnimTransformations(Skin* skin, MtxF* limbMatrices, struct Actor* actor, s32 setTranslation);
#endif
diff --git a/include/z64skin_matrix.h b/include/z64skin_matrix.h
new file mode 100644
index 000000000..01f7c885a
--- /dev/null
+++ b/include/z64skin_matrix.h
@@ -0,0 +1,34 @@
+#ifndef Z64SKIN_MATRIX_H
+#define Z64SKIN_MATRIX_H
+
+#include "ultra64.h"
+#include "z64math.h"
+
+struct GraphicsContext;
+
+void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDest);
+void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest);
+void SkinMatrix_MtxFMtxFMult(MtxF* mfB, MtxF* mfA, MtxF* dest);
+void SkinMatrix_GetClear(MtxF** mfp);
+void SkinMatrix_GetClear(MtxF** mfp);
+void SkinMatrix_MtxFCopy(MtxF* src, MtxF* dest);
+s32 SkinMatrix_Invert(MtxF* src, MtxF* dest);
+void SkinMatrix_SetScale(MtxF* mf, f32 x, f32 y, f32 z);
+void SkinMatrix_SetRotateRPY(MtxF* mf, s16 roll, s16 pitch, s16 yaw);
+void SkinMatrix_SetRotateYRP(MtxF* mf, s16 yaw, s16 roll, s16 pitch);
+void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z);
+void SkinMatrix_SetScaleRotateRPYTranslate(MtxF* mf, f32 scaleX, f32 scaleY, f32 scaleZ, s16 roll, s16 pitch, s16 yaw, f32 dx, f32 dy, f32 dz);
+void SkinMatrix_SetScaleRotateYRPTranslate(MtxF* mf, f32 scaleX, f32 scaleY, f32 scaleZ, s16 yaw, s16 roll, s16 pitch, f32 dx, f32 dy, f32 dz);
+void SkinMatrix_SetRotateRPYTranslate(MtxF* mf, s16 roll, s16 pitch, s16 yaw, f32 dx, f32 dy, f32 dz);
+void SkinMatrix_Vec3fToVec3s(Vec3f* src, Vec3s* dest);
+void SkinMatrix_Vec3sToVec3f(Vec3s* src, Vec3f* dest);
+void SkinMatrix_MtxFToMtx(MtxF* src, Mtx* dest);
+Mtx* SkinMatrix_MtxFToNewMtx(struct GraphicsContext* gfxCtx, MtxF* src);
+void SkinMatrix_SetRotateAroundVec(MtxF* mf, s16 a, f32 x, f32 y, f32 z);
+void SkinMatrix_SetXRotation(MtxF* mf, s16 a);
+void SkinMatrix_MulXRotation(MtxF* mf, s16 a);
+void SkinMatrix_SetYRotation(MtxF* mf, s16 a);
+void SkinMatrix_MulYRotation(MtxF* mf, s16 a);
+void SkinMatrix_SetZRotation(MtxF* mf, s16 a);
+
+#endif
diff --git a/include/z64speed_meter.h b/include/z64speed_meter.h
index 44b47ed1e..2c2bd9053 100644
--- a/include/z64speed_meter.h
+++ b/include/z64speed_meter.h
@@ -1,7 +1,7 @@
#ifndef Z64SPEED_METER_H
#define Z64SPEED_METER_H
-#include "PR/ultratypes.h"
+#include "ultra64.h"
struct GameState;
struct GraphicsContext;
diff --git a/include/z64transition.h b/include/z64transition.h
index 267098997..fa46ac40c 100644
--- a/include/z64transition.h
+++ b/include/z64transition.h
@@ -2,26 +2,37 @@
#define Z64TRANSITION_H
#include "ultra64.h"
+
#include "libc/stdint.h"
+#include "unk.h"
+
#include "overlays/fbdemos/ovl_fbdemo_triforce/z_fbdemo_triforce.h"
#include "overlays/fbdemos/ovl_fbdemo_wipe1/z_fbdemo_wipe1.h"
#include "overlays/fbdemos/ovl_fbdemo_wipe3/z_fbdemo_wipe3.h"
#include "overlays/fbdemos/ovl_fbdemo_wipe4/z_fbdemo_wipe4.h"
#include "overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.h"
-typedef enum {
+typedef enum TransitionOverlayStatus {
+ /* -1 */ TRANSITION_OVERLAY_STATUS_FAILED = -1, // failed allocation or null reference
+ /* 0 */ TRANSITION_OVERLAY_STATUS_LOAD_FREE, // successfully loaded/freed overlay
+ /* 1 */ TRANSITION_OVERLAY_STATUS_ADD_REMOVAL, // successfully added/removed instance
+ /* 2 */ TRANSITION_OVERLAY_STATUS_LOADED_NO_INSTANCES, // overlay is loaded but has no instances (?) TODO: Figure out why this exists
+ /* 3 */ TRANSITION_OVERLAY_STATUS_INTERNAL // internal overlay, so always loaded
+} TransitionOverlayStatus;
+
+typedef enum TransitionTileState {
/* 0 */ TRANS_TILE_OFF, // Inactive, do nothing
/* 1 */ TRANS_TILE_SETUP, // Save the necessary buffers
/* 2 */ TRANS_TILE_PROCESS, // Initialize the transition
/* 3 */ TRANS_TILE_READY // The transition is ready, so will update and draw each frame
} TransitionTileState;
-typedef struct {
+typedef struct TransitionTileVtxData {
/* 0x0 */ f32 x;
/* 0x4 */ f32 y;
} TransitionTileVtxData; // size = 0x8
-typedef struct {
+typedef struct TransitionTile {
/* 0x00 */ s32 cols;
/* 0x04 */ s32 rows;
/* 0x08 */ s32 frame;
@@ -38,7 +49,7 @@ typedef struct {
#define TC_SET_PARAMS (1 << 7)
-typedef struct {
+typedef struct TransitionInit {
/* 0x00 */ void* (*init)(void* transition);
/* 0x04 */ void (*destroy)(void* transition);
/* 0x08 */ void (*update)(void* transition, s32 updateRate);
@@ -50,7 +61,7 @@ typedef struct {
/* 0x20 */ s32 (*isDone)(void* transition);
} TransitionInit; // size = 0x24
-typedef struct {
+typedef struct TransitionOverlay {
union {
struct {
/* 0x00 */ u32 count : 8;
@@ -73,8 +84,8 @@ typedef enum {
#define TRANS_INSTANCE_TYPE_FADE_FLASH 3
-typedef struct {
- /* 0x0 */ u8 type;
+typedef struct TransitionFade {
+ /* 0x0 */ u8 type; // TransitionFadeType enum
/* 0x1 */ u8 isDone;
/* 0x2 */ u8 direction;
/* 0x4 */ Color_RGBA8_u32 color;
@@ -83,7 +94,7 @@ typedef struct {
#define FBDEMO_CIRCLE_GET_MASK_TYPE(type) ((type) & 1)
-typedef struct {
+typedef struct TransitionCircle {
/* 0x00 */ Color_RGBA8_u32 color;
/* 0x04 */ f32 referenceRadius; // Reference for where to transition to
/* 0x08 */ f32 stepValue; // How fast the Transition is
@@ -103,7 +114,7 @@ typedef struct {
#define TRANS_TRIGGER_START 20 // start transition (exiting an area)
#define TRANS_TRIGGER_END -20 // transition is ending (arriving in a new area)
-typedef enum {
+typedef enum TransitionMode {
/* 0 */ TRANS_MODE_OFF,
/* 1 */ TRANS_MODE_SETUP,
/* 2 */ TRANS_MODE_INSTANCE_INIT,
@@ -128,7 +139,7 @@ typedef enum {
#define TRANS_TYPE_WIPE3 (1 << 6)
#define TRANS_TYPE_SET_PARAMS (1 << 7)
-typedef enum {
+typedef enum TransitionType {
/* 0 */ TRANS_TYPE_WIPE,
/* 1 */ TRANS_TYPE_TRIFORCE,
/* 2 */ TRANS_TYPE_FADE_BLACK,
@@ -188,12 +199,12 @@ typedef union TransitionInstance {
#undef DEFINE_TRANSITION
#undef DEFINE_TRANSITION_INTERNAL
-typedef struct {
+typedef struct TransitionContext {
/* 0x000 */ s16 transitionType;
/* 0x002 */ s8 fbdemoType;
- /* 0x003 */ char unk_003[0x5];
+ /* 0x003 */ UNK_TYPE1 unk_003[0x5];
/* 0x008 */ TransitionInstance instanceData;
- /* 0x220 */ char unk_220[0x10];
+ /* 0x220 */ UNK_TYPE1 unk_220[0x10];
/* 0x230 */ void* (*init)(void* transition);
/* 0x234 */ void (*destroy)(void* transition);
/* 0x238 */ void (*update)(void* transition, s32 updateRate);
@@ -203,7 +214,44 @@ typedef struct {
/* 0x248 */ void (*setColor)(void* transition, u32 color);
/* 0x24C */ void (*setEnvColor)(void* transition, u32 color);
/* 0x250 */ s32 (*isDone)(void* transition);
- /* 0x254 */ char unk_254[0x4];
+ /* 0x254 */ UNK_TYPE1 unk_254[0x4];
} TransitionContext; // size = 0x258
+
+// z_dbdemo_dlftbls.c
+
+void Transition_Init(TransitionContext* transitionCtx);
+void Transition_Destroy(TransitionContext* transitionCtx);
+
+// z_fbdemo.c
+
+void TransitionTile_Destroy(TransitionTile* this);
+TransitionTile* TransitionTile_Init(TransitionTile* this, s32 cols, s32 rows);
+void TransitionTile_Draw(TransitionTile* this, Gfx** gfxP);
+void TransitionTile_Update(TransitionTile* this);
+
+// z_fbdemo_fade.c
+
+void TransitionFade_Start(void* thisx);
+void* TransitionFade_Init(void* thisx);
+void TransitionFade_Destroy(void* thisx);
+void TransitionFade_Update(void* thisx, s32 updateRate);
+void TransitionFade_Draw(void* thisx, Gfx** gfxP);
+s32 TransitionFade_IsDone(void* thisx);
+void TransitionFade_SetColor(void* thisx, u32 color);
+void TransitionFade_SetType(void* thisx, s32 type);
+
+// z_fbdemo_circle.c
+
+void TransitionCircle_LoadAndSetTexture(Gfx** gfxp, TexturePtr texture, s32 fmt, s32 arg3, s32 masks, s32 maskt, f32 arg6);
+
+// z_overlay.c
+
+void* TransitionOverlay_VramToRam(TransitionOverlay* overlayEntry, void* vramAddr);
+void TransitionOverlay_VramToRamArray(TransitionOverlay *overlayEntry, void** vramAddrs, s32 count);
+TransitionOverlayStatus TransitionOverlay_Load(TransitionOverlay *overlayEntry);
+TransitionOverlayStatus TransitionOverlay_Free(TransitionOverlay *overlayEntry);
+void TransitionOverlay_ClearLoadInfo(TransitionOverlay *overlayEntry);
+void TransitionOverlay_SetSegment(TransitionOverlay *overlayEntry, void* vramStart, void* vramEnd, uintptr_t vromStart, uintptr_t vromEnd);
+
#endif
diff --git a/src/code/gamealloc.c b/src/code/gamealloc.c
index 6067ad91c..a0d6f741f 100644
--- a/src/code/gamealloc.c
+++ b/src/code/gamealloc.c
@@ -1,10 +1,10 @@
-#include "global.h"
+#include "gamealloc.h"
+
#include "system_malloc.h"
void GameAlloc_Log(GameAlloc* this) {
- GameAllocEntry* iter;
+ GameAllocEntry* iter = this->base.next;
- iter = this->base.next;
while (iter != &this->base) {
iter = iter->next;
}
diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c
index 0835cbd1b..894127f2c 100644
--- a/src/code/speed_meter.c
+++ b/src/code/speed_meter.c
@@ -1,8 +1,15 @@
-#include "global.h"
-#include "sys_cfb.h"
+#include "prevent_bss_reordering.h"
#include "z64speed_meter.h"
-#include "z64view.h"
+
+#include "gfx.h"
+#include "regs.h"
+#include "sys_cfb.h"
#include "system_malloc.h"
+#include "z64game.h"
+#include "z64malloc.h"
+#include "z64view.h"
+
+#include "variables.h"
/**
* How much time the RSP ran audio tasks for over the course of `gGraphUpdatePeriod`.
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index 7d2df00da..0a5d51e22 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -4,11 +4,13 @@
*/
#include "z64actor.h"
+
#include "prevent_bss_reordering.h"
#include "fault.h"
#include "sys_cfb.h"
#include "loadfragment.h"
#include "z64horse.h"
+#include "z64malloc.h"
#include "z64quake.h"
#include "z64rumble.h"
diff --git a/src/code/z_camera.c b/src/code/z_camera.c
index 00d2978dd..b9123a718 100644
--- a/src/code/z_camera.c
+++ b/src/code/z_camera.c
@@ -45,6 +45,7 @@
#include "global.h"
#include "libc/string.h"
+#include "z64malloc.h"
#include "z64quake.h"
#include "z64shrink_window.h"
#include "z64view.h"
diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c
index af1f4ad6c..e190084af 100644
--- a/src/code/z_collision_check.c
+++ b/src/code/z_collision_check.c
@@ -1,7 +1,9 @@
#include "prevent_bss_reordering.h"
-#include "global.h"
#include "z64collision_check.h"
+#include "global.h"
+#include "z64malloc.h"
+
typedef s32 (*ColChkResetFunc)(struct PlayState*, Collider*);
typedef void (*ColChkBloodFunc)(struct PlayState*, Collider*, Vec3f*);
typedef void (*ColChkApplyFunc)(struct PlayState*, CollisionCheckContext*, Collider*);
diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c
index 08aa845ab..4b47f2b34 100644
--- a/src/code/z_effect_soft_sprite.c
+++ b/src/code/z_effect_soft_sprite.c
@@ -1,5 +1,6 @@
#include "global.h"
#include "loadfragment.h"
+#include "z64malloc.h"
EffectSsInfo sEffectSsInfo = { NULL, 0, 0 };
diff --git a/src/code/z_fbdemo.c b/src/code/z_fbdemo.c
index 441af901e..6ad5f7a6c 100644
--- a/src/code/z_fbdemo.c
+++ b/src/code/z_fbdemo.c
@@ -9,6 +9,9 @@
* @note The only coded effect has a visual effect to blend the tiles to a single point, which looks like the screen
* gets sucked into.
*/
+
+#include "z64transition.h"
+
#include "global.h"
#include "system_malloc.h"
diff --git a/src/code/z_fbdemo_circle.c b/src/code/z_fbdemo_circle.c
index efd492d5c..81322284f 100644
--- a/src/code/z_fbdemo_circle.c
+++ b/src/code/z_fbdemo_circle.c
@@ -1,7 +1,10 @@
-#include "global.h"
+#include "z64transition.h"
+
#include "sys_cfb.h"
+#include "z64math.h"
+#include "variables.h"
-typedef enum {
+typedef enum TransitionCircleDirection {
/* 0 */ TRANS_CIRCLE_DIR_IN,
/* 1 */ TRANS_CIRCLE_DIR_OUT
} TransitionCircleDirection;
@@ -18,10 +21,18 @@ Gfx sTransCircleSetupDL[] = {
gsSPEndDisplayList(),
};
-//! @bug: TransitionCircle_Update should take an additional argument `s32 updateRate`
+void TransitionCircle_Start(void* thisx);
+void* TransitionCircle_Init(void* thisx);
+void TransitionCircle_Destroy(void* thisx);
+void TransitionCircle_Update(void* thisx, s32 updateRate);
+void TransitionCircle_SetColor(void* thisx, u32 color);
+void TransitionCircle_SetType(void* thisx, s32 type);
+void TransitionCircle_Draw(void* thisx, Gfx** gfxp);
+s32 TransitionCircle_IsDone(void* thisx);
+
TransitionInit TransitionCircle_InitVars = {
- TransitionCircle_Init, TransitionCircle_Destroy, (void*)TransitionCircle_Update, TransitionCircle_Draw,
- TransitionCircle_Start, TransitionCircle_SetType, TransitionCircle_SetColor, NULL,
+ TransitionCircle_Init, TransitionCircle_Destroy, TransitionCircle_Update, TransitionCircle_Draw,
+ TransitionCircle_Start, TransitionCircle_SetType, TransitionCircle_SetColor, NULL,
TransitionCircle_IsDone,
};
@@ -56,8 +67,9 @@ void* TransitionCircle_Init(void* thisx) {
void TransitionCircle_Destroy(void* thisx) {
}
-void TransitionCircle_Update(void* thisx) {
+void TransitionCircle_Update(void* thisx, s32 updateRate) {
TransitionCircle* this = (TransitionCircle*)thisx;
+ s32 unused = updateRate ? 0 : 0;
this->isDone = Math_StepToF(&this->referenceRadius, this->targetRadius, this->stepValue);
}
diff --git a/src/code/z_fbdemo_dlftbls.c b/src/code/z_fbdemo_dlftbls.c
index 48d424813..df73ed1b3 100644
--- a/src/code/z_fbdemo_dlftbls.c
+++ b/src/code/z_fbdemo_dlftbls.c
@@ -1,4 +1,7 @@
-#include "global.h"
+#include "z64transition.h"
+
+#include "segment_symbols.h"
+#include "z64lib.h"
// InitVars and Linker symbol declarations (used in the table below)
#define DEFINE_TRANSITION(_enumValue, structName, _instanceName, name) \
diff --git a/src/code/z_fbdemo_fade.c b/src/code/z_fbdemo_fade.c
index a9ab37d48..f1e535594 100644
--- a/src/code/z_fbdemo_fade.c
+++ b/src/code/z_fbdemo_fade.c
@@ -1,13 +1,19 @@
-#include "global.h"
+#include "z64transition.h"
+
+#include "libc/stdbool.h"
+#include "gfx.h"
+#include "regs.h"
+#include "z64math.h"
+#include "z64save.h"
#define THIS ((TransitionFade*)thisx)
-typedef enum {
+typedef enum TransitionFadeDirection {
/* 0 */ TRANS_FADE_DIR_IN,
/* 1 */ TRANS_FADE_DIR_OUT
} TransitionFadeDirection;
-typedef enum {
+typedef enum TransitionFadeType {
/* 0 */ TRANS_FADE_TYPE_NONE,
/* 1 */ TRANS_FADE_TYPE_ONE_WAY,
/* 2 */ TRANS_FADE_TYPE_FLASH
diff --git a/src/code/z_fcurve_data_skelanime.c b/src/code/z_fcurve_data_skelanime.c
index 669e01348..6569d95d7 100644
--- a/src/code/z_fcurve_data_skelanime.c
+++ b/src/code/z_fcurve_data_skelanime.c
@@ -25,9 +25,15 @@
* - higher detail draws both.
*/
-#include "global.h"
#include "z64curve.h"
+#include "libc/stdbool.h"
+#include "z64actor.h"
+#include "z64animation.h"
+#include "z64curve.h"
+#include "z64malloc.h"
+#include "z64.h"
+
void SkelCurve_Clear(SkelCurve* skelCurve) {
skelCurve->limbCount = 0;
skelCurve->skeleton = NULL;
@@ -76,7 +82,7 @@ void SkelCurve_SetAnim(SkelCurve* skelCurve, CurveAnimationHeader* animation, f3
skelCurve->animation = animation;
}
-typedef enum {
+typedef enum SkelCurveVecType {
/* 0 */ SKELCURVE_VEC_TYPE_SCALE,
/* 1 */ SKELCURVE_VEC_TYPE_ROTATION,
/* 2 */ SKELCURVE_VEC_TYPE_POSIITON,
diff --git a/src/code/z_lib.c b/src/code/z_lib.c
index afbcba0ed..12bf959fc 100644
--- a/src/code/z_lib.c
+++ b/src/code/z_lib.c
@@ -1,4 +1,12 @@
-#include "global.h"
+#include "z64lib.h"
+
+#include "main.h"
+#include "ichain.h"
+#include "sfx.h"
+#include "z64actor.h"
+#include "z64game.h"
+#include "functions.h"
+#include "macros.h"
void* Lib_MemCpy(void* dest, void* src, size_t size) {
bcopy(src, dest, size);
@@ -11,7 +19,7 @@ void* Lib_MemSet(void* buffer, s32 value, size_t size) {
s32 i;
if (value == 0) {
- bzero(buffer, (u32)size);
+ bzero(buffer, size);
return buffer;
}
diff --git a/src/code/z_lights.c b/src/code/z_lights.c
index e5b34f387..e15043b9e 100644
--- a/src/code/z_lights.c
+++ b/src/code/z_lights.c
@@ -1,10 +1,15 @@
-#include "global.h"
+#include "z64light.h"
+
#include "sys_cfb.h"
+#include "z64skin_matrix.h"
+#include "z64.h"
+#include "functions.h"
+
#include "objects/gameplay_keep/gameplay_keep.h"
LightsBuffer sLightsBuffer;
-void Lights_PointSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius, s32 type) {
+void Lights_PointSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius, LightType type) {
info->type = type;
info->params.point.x = x;
info->params.point.y = y;
@@ -79,7 +84,7 @@ void Lights_Draw(Lights* lights, GraphicsContext* gfxCtx) {
}
Light* Lights_FindSlot(Lights* lights) {
- if (lights->numLights >= 7) {
+ if (lights->numLights >= ARRAY_COUNT(lights->l.l)) {
return NULL;
}
return &lights->l.l[lights->numLights++];
@@ -182,6 +187,9 @@ void Lights_BindDirectional(Lights* lights, LightParams* params, void* unused) {
}
}
+typedef void (*LightsBindFunc)(Lights* lights, LightParams* params, Vec3f* vec);
+typedef void (*LightsPosBindFunc)(Lights* lights, LightParams* params, struct PlayState* play);
+
/**
* For every light in a provided list, try to find a free slot in the provided Lights group and bind
* a light to it. Then apply color and positional/directional info for each light
@@ -240,13 +248,15 @@ LightNode* Lights_FindBufSlot(void) {
}
void Lights_FreeNode(LightNode* light) {
- if (light != NULL) {
- sLightsBuffer.numOccupied--;
- light->info = NULL;
- sLightsBuffer.searchIndex =
- (light - sLightsBuffer.lights) /
- (s32)sizeof(LightNode); //! @bug Due to pointer arithmetic, the division is unnecessary
+ if (light == NULL) {
+ return;
}
+
+ sLightsBuffer.numOccupied--;
+ light->info = NULL;
+
+ //! @bug Due to pointer arithmetic, the division is unnecessary
+ sLightsBuffer.searchIndex = (light - sLightsBuffer.lights) / (s32)sizeof(LightNode);
}
void LightContext_Init(PlayState* play, LightContext* lightCtx) {
diff --git a/src/code/z_malloc.c b/src/code/z_malloc.c
index c23da3927..80d7fc7af 100644
--- a/src/code/z_malloc.c
+++ b/src/code/z_malloc.c
@@ -1,4 +1,5 @@
-#include "global.h"
+#include "z64malloc.h"
+
#include "os_malloc.h"
Arena sZeldaArena;
diff --git a/src/code/z_overlay.c b/src/code/z_overlay.c
index fe0857820..c994ba9ec 100644
--- a/src/code/z_overlay.c
+++ b/src/code/z_overlay.c
@@ -2,18 +2,13 @@
* @file z_overlay.c
*
* Functions for handling transition overlays in memory
- *
- * Status codes returned from TransitionOverlay_Load and TransitionOverlay_Free:
- *
- * -1 : failed allocation or null reference
- * 0 : successfully loaded/freed overlay
- * 1 : successfully added/removed instance
- * 2 : overlay is loaded but has no instances (?) TODO: Figure out why this exists
- * 3 : internal overlay, so always loaded
*/
-#include "global.h"
+#include "z64transition.h"
+
#include "loadfragment.h"
+#include "z64lib.h"
+#include "z64malloc.h"
void* TransitionOverlay_VramToRam(TransitionOverlay* overlayEntry, void* vramAddr) {
void* loadedRamAddr = Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr);
@@ -32,46 +27,51 @@ void TransitionOverlay_VramToRamArray(TransitionOverlay* overlayEntry, void** vr
}
}
-s32 TransitionOverlay_Load(TransitionOverlay* overlayEntry) {
+TransitionOverlayStatus TransitionOverlay_Load(TransitionOverlay* overlayEntry) {
s32 count;
void* loadedRamAddr;
if (overlayEntry->vromStart == 0) {
- return 3;
+ return TRANSITION_OVERLAY_STATUS_INTERNAL;
}
+
if (Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr) == NULL) {
loadedRamAddr = ZeldaArena_Malloc((uintptr_t)overlayEntry->vramEnd - (uintptr_t)overlayEntry->vramStart);
if (loadedRamAddr == NULL) {
- return -1;
+ return TRANSITION_OVERLAY_STATUS_FAILED;
}
+
Overlay_Load(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd,
loadedRamAddr);
overlayEntry->loadInfo.addr = Lib_VirtualToPhysical(loadedRamAddr);
overlayEntry->loadInfo.count = 1;
- return 0;
- } else {
- count = overlayEntry->loadInfo.count;
- if (count != 0) {
- count++;
- overlayEntry->loadInfo.count = count;
- if (count == 0) {
- return 2;
- } else {
- return 1;
- }
+ return TRANSITION_OVERLAY_STATUS_LOAD_FREE;
+ }
+
+ count = overlayEntry->loadInfo.count;
+ if (count != 0) {
+ count++;
+ overlayEntry->loadInfo.count = count;
+
+ if (count == 0) {
+ return TRANSITION_OVERLAY_STATUS_LOADED_NO_INSTANCES;
+ } else {
+ return TRANSITION_OVERLAY_STATUS_ADD_REMOVAL;
}
- return 2;
}
+
+ return TRANSITION_OVERLAY_STATUS_LOADED_NO_INSTANCES;
}
-s32 TransitionOverlay_Free(TransitionOverlay* overlayEntry) {
+TransitionOverlayStatus TransitionOverlay_Free(TransitionOverlay* overlayEntry) {
s32 count;
void* loadedRamAddr;
if (overlayEntry->vromStart == 0) {
- return 3;
+ return TRANSITION_OVERLAY_STATUS_INTERNAL;
}
+
loadedRamAddr = Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr);
if (loadedRamAddr != NULL) {
count = overlayEntry->loadInfo.count;
@@ -81,13 +81,13 @@ s32 TransitionOverlay_Free(TransitionOverlay* overlayEntry) {
if (count == 0) {
ZeldaArena_Free(loadedRamAddr);
overlayEntry->loadInfo.addr = Lib_VirtualToPhysical(NULL);
- return 0;
+ return TRANSITION_OVERLAY_STATUS_LOAD_FREE;
}
- return 1;
+ return TRANSITION_OVERLAY_STATUS_ADD_REMOVAL;
}
- return 2;
+ return TRANSITION_OVERLAY_STATUS_LOADED_NO_INSTANCES;
}
- return -1;
+ return TRANSITION_OVERLAY_STATUS_FAILED;
}
void TransitionOverlay_ClearLoadInfo(TransitionOverlay* overlayEntry) {
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index f3077da95..db101efb5 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -1,9 +1,11 @@
#include "global.h"
#include "PR/gs2dex.h"
#include "sys_cfb.h"
+#include "z64malloc.h"
#include "z64snap.h"
#include "z64view.h"
#include "z64voice.h"
+
#include "archives/icon_item_static/icon_item_static_yar.h"
#include "interface/parameter_static/parameter_static.h"
#include "interface/do_action_static/do_action_static.h"
diff --git a/src/code/z_play.c b/src/code/z_play.c
index ee519270a..226980b4d 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -2,6 +2,7 @@
#include "z64.h"
#include "regs.h"
#include "functions.h"
+#include "z64malloc.h"
#include "z64vismono.h"
#include "z64visfbuf.h"
diff --git a/src/code/z_play_hireso.c b/src/code/z_play_hireso.c
index 1b2572ea8..e9610039f 100644
--- a/src/code/z_play_hireso.c
+++ b/src/code/z_play_hireso.c
@@ -1,6 +1,8 @@
#include "global.h"
#include "sys_cfb.h"
#include "z64bombers_notebook.h"
+#include "z64malloc.h"
+
#include "interface/schedule_static/schedule_static.h"
#include "archives/schedule_dma_static/schedule_dma_static_yar.h"
diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c
index 7b33d9cf5..58542b786 100644
--- a/src/code/z_skelanime.c
+++ b/src/code/z_skelanime.c
@@ -1,4 +1,5 @@
#include "global.h"
+#include "z64malloc.h"
#define ANIM_INTERP 1
diff --git a/src/code/z_skin_awb.c b/src/code/z_skin_awb.c
index edbcef05f..8425d961a 100644
--- a/src/code/z_skin_awb.c
+++ b/src/code/z_skin_awb.c
@@ -1,6 +1,8 @@
-#include "global.h"
#include "z64skin.h"
+#include "global.h"
+#include "z64malloc.h"
+
void Skin_Setup(Skin* skin) {
skin->skeletonHeader = NULL;
skin->limbCount = 0;
diff --git a/src/code/z_skin_matrix.c b/src/code/z_skin_matrix.c
index 9b30a3c0b..8f9635508 100644
--- a/src/code/z_skin_matrix.c
+++ b/src/code/z_skin_matrix.c
@@ -1,4 +1,8 @@
-#include "global.h"
+#include "z64skin_matrix.h"
+
+#include "gfx.h"
+#include "macros.h"
+#include "z64math.h"
MtxF sMtxFClear = { {
{ 1.0f, 0.0f, 0.0f, 0.0f },
diff --git a/src/libultra/gu/cosf.c b/src/libultra/gu/cosf.c
index 65330e9a6..8f9eafe65 100644
--- a/src/libultra/gu/cosf.c
+++ b/src/libultra/gu/cosf.c
@@ -1,3 +1,4 @@
+#include "ultra64.h"
#include "libc/math.h"
#include "macros.h"
diff --git a/src/libultra/gu/sinf.c b/src/libultra/gu/sinf.c
index 963bc2022..d067d5ea7 100644
--- a/src/libultra/gu/sinf.c
+++ b/src/libultra/gu/sinf.c
@@ -1,3 +1,4 @@
+#include "ultra64.h"
#include "libc/math.h"
#include "macros.h"
diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c
index 762dcbb09..ca57673cd 100644
--- a/src/libultra/io/controller.c
+++ b/src/libultra/io/controller.c
@@ -1,5 +1,6 @@
#include "ultra64.h"
#include "PR/controller.h"
+#include "libc/stdbool.h"
#include "alignment.h"
#include "macros.h"
diff --git a/src/overlays/actors/ovl_En_Test3/z_en_test3.c b/src/overlays/actors/ovl_En_Test3/z_en_test3.c
index 4d3f7e444..c10acf5c9 100644
--- a/src/overlays/actors/ovl_En_Test3/z_en_test3.c
+++ b/src/overlays/actors/ovl_En_Test3/z_en_test3.c
@@ -5,6 +5,9 @@
*/
#include "z_en_test3.h"
+
+#include "z64malloc.h"
+
#include "objects/object_test3/object_test3.h"
#include "overlays/actors/ovl_En_Door/z_en_door.h"
#include "objects/gameplay_keep/gameplay_keep.h"
diff --git a/src/overlays/actors/ovl_En_Test6/z_en_test6.c b/src/overlays/actors/ovl_En_Test6/z_en_test6.c
index bfa096a38..3601bb9e0 100644
--- a/src/overlays/actors/ovl_En_Test6/z_en_test6.c
+++ b/src/overlays/actors/ovl_En_Test6/z_en_test6.c
@@ -5,9 +5,12 @@
*/
#include "z_en_test6.h"
+
+#include "z64cutscene_commands.h"
+#include "z64malloc.h"
#include "z64quake.h"
+
#include "objects/gameplay_keep/gameplay_keep.h"
-#include "z64cutscene_commands.h"
#define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_20 | ACTOR_FLAG_200000 | ACTOR_FLAG_2000000)
diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c
index 317d8e9ca..412d5ae1f 100644
--- a/src/overlays/actors/ovl_player_actor/z_player.c
+++ b/src/overlays/actors/ovl_player_actor/z_player.c
@@ -7,6 +7,7 @@
#include "prevent_bss_reordering.h"
#include "global.h"
#include "z64horse.h"
+#include "z64malloc.h"
#include "z64quake.h"
#include "z64rumble.h"
#include "z64shrink_window.h"
diff --git a/undefined_syms.txt b/undefined_syms.txt
index cb3fea946..4dc64eb0d 100644
--- a/undefined_syms.txt
+++ b/undefined_syms.txt
@@ -537,11 +537,6 @@ D_0C000000 = 0x0C000000;
D_0E000000 = 0x0E000000;
-// TODO the following are fake and are offsets into the structure at D_0E000000
-D_0E000140 = 0x0E000140;
-D_0E0001C8 = 0x0E0001C8;
-D_0E0002C8 = 0x0E0002C8;
-
// segment 0x0F
D_0F000000 = 0x0F000000;