diff --git a/include/functions.h b/include/functions.h index d9c29270a63..af94175c532 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1072,21 +1072,7 @@ void Skin_Init(PlayState* play, Skin* skin, SkeletonHeader* skeletonHeader, Anim void Skin_Free(PlayState* play, Skin* skin); s32 Skin_ApplyAnimTransformations(Skin* skin, MtxF* limbMatrices, Actor* actor, s32 setTranslation); -void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDest); -void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest); -void SkinMatrix_MtxFMtxFMult(MtxF* mfA, MtxF* mfB, MtxF* dest); -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_SetRotateZYX(MtxF* mf, s16 x, s16 y, s16 z); -void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z); -void SkinMatrix_SetTranslateRotateYXZScale(MtxF* dest, f32 scaleX, f32 scaleY, f32 scaleZ, s16 rotX, s16 rotY, s16 rotZ, - f32 translateX, f32 translateY, f32 translateZ); -void SkinMatrix_SetTranslateRotateZYX(MtxF* dest, s16 rotX, s16 rotY, s16 rotZ, f32 translateX, f32 translateY, - f32 translateZ); -Mtx* SkinMatrix_MtxFToNewMtx(GraphicsContext* gfxCtx, MtxF* src); -void SkinMatrix_SetRotateAxis(MtxF* mf, s16 angle, f32 axisX, f32 axisY, f32 axisZ); + void Sram_InitNewSave(void); void Sram_InitDebugSave(void); void Sram_OpenSave(SramContext* sramCtx); @@ -1264,42 +1250,7 @@ void* SysCfb_GetFbEnd(void); void Math3D_DrawSphere(PlayState* play, Sphere16* sph); void Math3D_DrawCylinder(PlayState* play, Cylinder16* cyl); -void Matrix_Init(GameState* gameState); -void Matrix_Push(void); -void Matrix_Pop(void); -void Matrix_Get(MtxF* dest); -void Matrix_Put(MtxF* src); -void Matrix_Mult(MtxF* mf, u8 mode); -void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode); -void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode); -void Matrix_RotateX(f32 x, u8 mode); -void Matrix_RotateY(f32 y, u8 mode); -void Matrix_RotateZ(f32 z, u8 mode); -void Matrix_RotateZYX(s16 x, s16 y, s16 z, u8 mode); -void Matrix_TranslateRotateZYX(Vec3f* translation, Vec3s* rotation); -void Matrix_SetTranslateRotateYXZ(f32 translateX, f32 translateY, f32 translateZ, Vec3s* rot); -Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest); -#if OOT_DEBUG -Mtx* Matrix_ToMtx(Mtx* dest, const char* file, int line); -Mtx* Matrix_NewMtx(GraphicsContext* gfxCtx, const char* file, int line); -#else -Mtx* Matrix_ToMtx(Mtx* dest); -Mtx* Matrix_NewMtx(GraphicsContext* gfxCtx); -#endif -void Matrix_MultVec3f(Vec3f* src, Vec3f* dest); -void Matrix_MtxFCopy(MtxF* dest, MtxF* src); -void Matrix_MtxToMtxF(Mtx* src, MtxF* dest); -void Matrix_MultVec3fExt(Vec3f* src, Vec3f* dest, MtxF* mf); -void Matrix_Transpose(MtxF* mf); -void Matrix_ReplaceRotation(MtxF* mf); -void Matrix_MtxFToYXZRotS(MtxF* mf, Vec3s* rotDest, s32 flag); -void Matrix_MtxFToZYXRotS(MtxF* mf, Vec3s* rotDest, s32 flag); -void Matrix_RotateAxis(f32 angle, Vec3f* axis, u8 mode); -#if OOT_DEBUG -MtxF* Matrix_CheckFloats(MtxF* mf, const char* file, int line); -#endif -void Matrix_SetTranslateScaleMtx2(Mtx* mtx, f32 scaleX, f32 scaleY, f32 scaleZ, f32 translateX, f32 translateY, - f32 translateZ); + u64* SysUcode_GetUCodeBoot(void); size_t SysUcode_GetUCodeBootSize(void); u64* SysUcode_GetUCode(void); diff --git a/include/macros.h b/include/macros.h index a42693b39af..f32fd20a62a 100644 --- a/include/macros.h +++ b/include/macros.h @@ -183,9 +183,6 @@ extern struct GraphicsContext* __gfxCtx; (void)0 #define GRAPH_ALLOC(gfxCtx, size) Graph_Alloc(gfxCtx, size) -#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx, file, line) -#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx, file, line) -#define MATRIX_CHECK_FLOATS(mtx, file, line) Matrix_CheckFloats(mtx, file, line) #define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSyncDebug(ram, vrom, size, file, line) #define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsyncDebug(req, ram, vrom, size, unk5, queue, msg, file, line) #define GAME_STATE_ALLOC(gameState, size, file, line) GameState_Alloc(gameState, size, file, line) @@ -216,9 +213,6 @@ extern struct GraphicsContext* __gfxCtx; (void)0 #define GRAPH_ALLOC(gfxCtx, size) ((void*)((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - ALIGN16(size)))) -#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx) -#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx) -#define MATRIX_CHECK_FLOATS(mtx, file, line) (mtx) #define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSync(ram, vrom, size) #define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsync(req, ram, vrom, size, unk5, queue, msg) #define GAME_STATE_ALLOC(gameState, size, file, line) THA_AllocTailAlign16(&(gameState)->tha, size) diff --git a/include/skin_matrix.h b/include/skin_matrix.h new file mode 100644 index 00000000000..36fb76b144b --- /dev/null +++ b/include/skin_matrix.h @@ -0,0 +1,25 @@ +#ifndef MATRIX_H +#define 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* mfA, MtxF* mfB, MtxF* dest); +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_SetRotateZYX(MtxF* mf, s16 x, s16 y, s16 z); +void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z); +void SkinMatrix_SetTranslateRotateYXZScale(MtxF* dest, f32 scaleX, f32 scaleY, f32 scaleZ, s16 rotX, s16 rotY, s16 rotZ, + f32 translateX, f32 translateY, f32 translateZ); +void SkinMatrix_SetTranslateRotateZYX(MtxF* dest, s16 rotX, s16 rotY, s16 rotZ, f32 translateX, f32 translateY, + f32 translateZ); +Mtx* SkinMatrix_MtxFToNewMtx(struct GraphicsContext* gfxCtx, MtxF* src); +void SkinMatrix_SetRotateAxis(MtxF* mf, s16 angle, f32 axisX, f32 axisY, f32 axisZ); + +#endif diff --git a/include/sys_matrix.h b/include/sys_matrix.h new file mode 100644 index 00000000000..2589cbed569 --- /dev/null +++ b/include/sys_matrix.h @@ -0,0 +1,79 @@ +#ifndef MATRIX_STACK_H +#define MATRIX_STACK_H + +#include "ultra64.h" +#include "z64math.h" + +struct GameState; +struct GraphicsContext; + +// Matrix stack operations + +typedef enum { + /* 0 */ MTXMODE_NEW, // generates a new matrix + /* 1 */ MTXMODE_APPLY // applies transformation to the current matrix +} MatrixMode; + +void Matrix_Init(struct GameState* gameState); +void Matrix_Push(void); +void Matrix_Pop(void); +void Matrix_Get(MtxF* dest); +void Matrix_Put(MtxF* src); +void Matrix_Mult(MtxF* mf, u8 mode); +void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode); +void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode); +void Matrix_RotateX(f32 x, u8 mode); +void Matrix_RotateY(f32 y, u8 mode); +void Matrix_RotateZ(f32 z, u8 mode); +void Matrix_RotateZYX(s16 x, s16 y, s16 z, u8 mode); +void Matrix_TranslateRotateZYX(Vec3f* translation, Vec3s* rotation); +void Matrix_SetTranslateRotateYXZ(f32 translateX, f32 translateY, f32 translateZ, Vec3s* rot); +void Matrix_MultVec3f(Vec3f* src, Vec3f* dest); +void Matrix_ReplaceRotation(MtxF* mf); +void Matrix_RotateAxis(f32 angle, Vec3f* axis, u8 mode); + +#if OOT_DEBUG + +Mtx* Matrix_ToMtx(Mtx* dest, const char* file, int line); +#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx, file, line) + +Mtx* Matrix_NewMtx(struct GraphicsContext* gfxCtx, const char* file, int line); +#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx, file, line) + +#else + +Mtx* Matrix_ToMtx(Mtx* dest); +#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx) + +Mtx* Matrix_NewMtx(struct GraphicsContext* gfxCtx); +#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx) + +#endif + +// Operations not involving the matrix stack + +extern Mtx gMtxClear; +extern MtxF gMtxFClear; + +Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest); +void Matrix_MtxFCopy(MtxF* dest, MtxF* src); +void Matrix_MtxToMtxF(Mtx* src, MtxF* dest); +void Matrix_MultVec3fExt(Vec3f* src, Vec3f* dest, MtxF* mf); +void Matrix_Transpose(MtxF* mf); +void Matrix_MtxFToYXZRotS(MtxF* mf, Vec3s* rotDest, s32 flag); +void Matrix_MtxFToZYXRotS(MtxF* mf, Vec3s* rotDest, s32 flag); +void Matrix_SetTranslateScaleMtx2(Mtx* mtx, f32 scaleX, f32 scaleY, f32 scaleZ, f32 translateX, f32 translateY, + f32 translateZ); + +#if OOT_DEBUG + +MtxF* Matrix_CheckFloats(MtxF* mf, const char* file, int line); +#define MATRIX_CHECK_FLOATS(mtx, file, line) Matrix_CheckFloats(mtx, file, line) + +#else + +#define MATRIX_CHECK_FLOATS(mtx, file, line) (mtx) + +#endif + +#endif diff --git a/include/variables.h b/include/variables.h index 10f67329ffc..099b7c7cf44 100644 --- a/include/variables.h +++ b/include/variables.h @@ -101,8 +101,6 @@ extern u8 gBossMarkState; extern s32 gScreenWidth; extern s32 gScreenHeight; -extern Mtx gMtxClear; -extern MtxF gMtxFClear; #if OOT_DEBUG extern u32 gIsCtrlr2Valid; #endif diff --git a/include/z64.h b/include/z64.h index 03ef633b7f2..02185d77177 100644 --- a/include/z64.h +++ b/include/z64.h @@ -66,6 +66,8 @@ #include "sys_math.h" #include "sys_math3d.h" #include "fp_math.h" +#include "sys_matrix.h" +#include "skin_matrix.h" #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 @@ -400,11 +402,6 @@ typedef struct DebugDispObject { /* 0x28 */ struct DebugDispObject* next; } DebugDispObject; // size = 0x2C -typedef enum { - /* 0 */ MTXMODE_NEW, // generates a new matrix - /* 1 */ MTXMODE_APPLY // applies transformation to the current matrix -} MatrixMode; - typedef struct StackEntry { /* 0x00 */ struct StackEntry* next; /* 0x04 */ struct StackEntry* prev; diff --git a/src/code/main.c b/src/code/main.c index 13a96e26338..c70cd6bb455 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -1,3 +1,6 @@ +// 1) The block number for gAppNmiBufferPtr must be <= 193 +#pragma increment_block_number 130 + #include "global.h" #include "terminal.h" @@ -7,6 +10,9 @@ s32 gScreenWidth = SCREEN_WIDTH; s32 gScreenHeight = SCREEN_HEIGHT; u32 gSystemHeapSize = 0; +// 2) The block number for gIrqMgr must be <= 241 and > gPadMgr's +#pragma increment_block_number 40 + PreNmiBuff* gAppNmiBufferPtr; Scheduler gScheduler; PadMgr gPadMgr; diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index 2ca6e4cf47a..76574332fa3 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -1,4 +1,5 @@ #include "global.h" +#include "sys_matrix.h" // clang-format off Mtx gMtxClear = gdSPDefMtx( diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 681fa2d5190..7d8b8d89857 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -6,7 +6,7 @@ // For retail BSS ordering, the block number of D_8015BD7C // must be between 88 and 123 inclusive. -#pragma increment_block_number 26 +#pragma increment_block_number 7 s16 Camera_RequestSettingImpl(Camera* camera, s16 requestedSetting, s16 flags); s32 Camera_RequestModeImpl(Camera* camera, s16 requestedMode, u8 forceModeChange); diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 4e516005c36..1f5153bc56f 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -115,7 +115,9 @@ void* sUnusedEntranceCsList[] = { gDekuTreeIntroCs, gJabuJabuIntroCs, gDcOpeningCs, gMinuetCs, gIceCavernSerenadeCs, gTowerBarrierCs, }; -#pragma increment_block_number 248 +// Because the other bss variables are already declared (in header files), this directive only affects the block number +// of sReturnToCamId and sQuakeIndex. For matching, their block numbers should come after gCamAtPointAppliedFrame's. +#pragma increment_block_number 210 // Stores the frame the relevant cam data was last applied on u16 gCamAtSplinePointsAppliedFrame; diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index ee1af2c1e23..91f3c43165a 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -1,3 +1,5 @@ +#include "ultra64/ultratypes.h" + #include "global.h" #include "ultra64.h" #include "terminal.h" @@ -10,7 +12,7 @@ // For retail BSS ordering, the block number of sLensFlareUnused must be lower // than the extern variables declared in the header (e.g. gLightningStrike) // while the block number of sNGameOverLightNode must be higher. -#pragma increment_block_number 70 +#pragma increment_block_number 160 typedef enum { /* 0x00 */ LIGHTNING_BOLT_START, @@ -218,7 +220,7 @@ s16 sSunDepthTestY; // These variables could be moved farther down in the file to reduce the amount // of block number padding here, but currently this causes BSS ordering issues // for debug. -#pragma increment_block_number 227 +#pragma increment_block_number 100 LightNode* sNGameOverLightNode; LightInfo sNGameOverLightInfo; diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 80d4c210d1a..d98ea9434d4 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -437,6 +437,9 @@ Gfx gCullFrontDList[] = { gsSPEndDisplayList(), }; +// The block number for sCurBodyPartPos must be <= 251 +#pragma increment_block_number 100 + Vec3f* sCurBodyPartPos; s32 sDListsLodOffset; Vec3f sGetItemRefPos; diff --git a/src/code/z_skin_matrix.c b/src/code/z_skin_matrix.c index 46d2fbe4c15..d658ed56e54 100644 --- a/src/code/z_skin_matrix.c +++ b/src/code/z_skin_matrix.c @@ -1,5 +1,6 @@ #include "global.h" #include "terminal.h" +#include "skin_matrix.h" // clang-format off MtxF sMtxFClear = { diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index 199fba0fea3..cc2f4f084ca 100644 --- a/src/overlays/actors/ovl_Fishing/z_fishing.c +++ b/src/overlays/actors/ovl_Fishing/z_fishing.c @@ -12,7 +12,7 @@ #include "terminal.h" // For retail BSS ordering, the block number of sStreamSfxProjectedPos must be 0. -#pragma increment_block_number 182 +#pragma increment_block_number 180 #define FLAGS ACTOR_FLAG_4