From 85a3113ad0fd213af5d8f9102638bf109000f0c8 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 24 Jun 2024 04:43:53 -0400 Subject: [PATCH 1/9] split some graph.c related headers --- include/functions.h | 38 ----------- include/gamealloc.h | 33 ++++++++++ include/gfxbuffers.h | 12 ++++ include/graph.h | 70 +++++++++++++++++++++ include/macros.h | 43 ------------- include/speed_meter.h | 34 ++++++++++ include/speedmeter.h | 20 ------ include/sys_matrix.h | 18 ++++++ include/variables.h | 19 ------ include/z64.h | 18 +----- include/z64game.h | 42 ++++++------- include/z_game_dlftbls.h | 39 ++++++++++++ src/buffers/gfxbuffers.c | 4 +- src/code/audio_thread_manager.c | 1 + src/code/fault.c | 2 +- src/code/graph.c | 11 +++- src/code/sched.c | 1 + src/code/speed_meter.c | 1 + src/code/sys_math3d.c | 2 +- src/code/z_DLF.c | 1 + src/code/z_collision_check.c | 4 ++ src/code/z_game_dlftbls.c | 2 + src/code/z_room.c | 1 + src/overlays/actors/ovl_Fishing/z_fishing.c | 2 +- 24 files changed, 254 insertions(+), 164 deletions(-) create mode 100644 include/gamealloc.h create mode 100644 include/gfxbuffers.h create mode 100644 include/graph.h create mode 100644 include/speed_meter.h delete mode 100644 include/speedmeter.h create mode 100644 include/sys_matrix.h create mode 100644 include/z_game_dlftbls.h diff --git a/include/functions.h b/include/functions.h index d9c29270a63..096e0720ccf 100644 --- a/include/functions.h +++ b/include/functions.h @@ -292,8 +292,6 @@ void EffectSsDeadSound_SpawnStationary(PlayState* play, Vec3f* pos, u16 sfxId, s s16 repeatMode, s32 life); void EffectSsIceSmoke_Spawn(PlayState* play, Vec3f* pos, Vec3f* velocity, Vec3f* accel, s16 scale); void FlagSet_Update(PlayState* play); -void Overlay_LoadGameState(GameStateOverlay* overlayEntry); -void Overlay_FreeGameState(GameStateOverlay* overlayEntry); void ActorShape_Init(ActorShape* shape, f32 yOffset, ActorShadowFunc shadowDraw, f32 shadowScale); void ActorShadow_DrawCircle(Actor* actor, Lights* lights, PlayState* play); void ActorShadow_DrawWhiteCircle(Actor* actor, Lights* lights, PlayState* play); @@ -1218,41 +1216,6 @@ void func_800C213C(PreRender* this, Gfx** gfxP); void PreRender_RestoreFramebuffer(PreRender* this, Gfx** gfxP); void PreRender_CopyImageRegion(PreRender* this, Gfx** gfxP); void PreRender_ApplyFilters(PreRender* this); -void GameState_SetFBFilter(Gfx** gfxP); -void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx); -void GameState_SetFrameBuffer(GraphicsContext* gfxCtx); -void GameState_ReqPadData(GameState* gameState); -void GameState_Update(GameState* gameState); -void GameState_InitArena(GameState* gameState, size_t size); -void GameState_Realloc(GameState* gameState, size_t size); -void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* gfxCtx); -void GameState_Destroy(GameState* gameState); -GameStateFunc GameState_GetInit(GameState* gameState); -u32 GameState_IsRunning(GameState* gameState); -#if OOT_DEBUG -void* GameState_Alloc(GameState* gameState, size_t size, const char* file, int line); -void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, int line); -#endif -void* GameAlloc_Malloc(GameAlloc* this, u32 size); -void GameAlloc_Free(GameAlloc* this, void* data); -void GameAlloc_Cleanup(GameAlloc* this); -void GameAlloc_Init(GameAlloc* this); -void Graph_InitTHGA(GraphicsContext* gfxCtx); -GameStateOverlay* Graph_GetNextGameState(GameState* gameState); -void Graph_Init(GraphicsContext* gfxCtx); -void Graph_Destroy(GraphicsContext* gfxCtx); -void Graph_TaskSet00(GraphicsContext* gfxCtx); -void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState); -void Graph_ThreadEntry(void*); -void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size); -void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size); -#if OOT_DEBUG -void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); -void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); -#endif -Gfx* Gfx_Open(Gfx* gfx); -Gfx* Gfx_Close(Gfx* gfx, Gfx* dst); -void* Gfx_Alloc(Gfx** gfxP, u32 size); ListAlloc* ListAlloc_Init(ListAlloc* this); void* ListAlloc_Alloc(ListAlloc* this, u32 size); void ListAlloc_Free(ListAlloc* this, void* data); @@ -1261,7 +1224,6 @@ void Main(void* arg); void SysCfb_Init(s32 n64dd); void* SysCfb_GetFbPtr(s32 idx); void* SysCfb_GetFbEnd(void); - void Math3D_DrawSphere(PlayState* play, Sphere16* sph); void Math3D_DrawCylinder(PlayState* play, Cylinder16* cyl); void Matrix_Init(GameState* gameState); diff --git a/include/gamealloc.h b/include/gamealloc.h new file mode 100644 index 00000000000..837ed7132e1 --- /dev/null +++ b/include/gamealloc.h @@ -0,0 +1,33 @@ +#ifndef GAMEALLOC_H +#define GAMEALLOC_H + +#include "ultra64.h" + +typedef struct GameAllocEntry { + /* 0x00 */ struct GameAllocEntry* next; + /* 0x04 */ struct GameAllocEntry* prev; + /* 0x08 */ u32 size; + /* 0x0C */ u32 unk_0C; +} GameAllocEntry; // size = 0x10 + +typedef struct { + /* 0x00 */ GameAllocEntry base; + /* 0x10 */ GameAllocEntry* head; +} GameAlloc; // size = 0x14 + +#if OOT_DEBUG +void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, int line); +#endif + +void* GameAlloc_Malloc(GameAlloc* this, u32 size); +void GameAlloc_Free(GameAlloc* this, void* data); +void GameAlloc_Cleanup(GameAlloc* this); +void GameAlloc_Init(GameAlloc* this); + +#if OOT_DEBUG +#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_MallocDebug(alloc, size, file, line) +#else +#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_Malloc(alloc, size) +#endif + +#endif diff --git a/include/gfxbuffers.h b/include/gfxbuffers.h new file mode 100644 index 00000000000..48096b4fcf3 --- /dev/null +++ b/include/gfxbuffers.h @@ -0,0 +1,12 @@ +#ifndef GFXBUFFERS_H +#define GFXBUFFERS_H + +#include "ultra64.h" +#include "gfx.h" + +extern u64 gGfxSPTaskOutputBuffer[0x3000]; // 0x18000 bytes +extern u64 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE / sizeof(u64)]; // 0xC00 bytes +extern u64 gGfxSPTaskStack[SP_DRAM_STACK_SIZE64]; // 0x400 bytes +extern GfxPool gGfxPools[2]; // 0x24820 bytes + +#endif diff --git a/include/graph.h b/include/graph.h new file mode 100644 index 00000000000..8887621b404 --- /dev/null +++ b/include/graph.h @@ -0,0 +1,70 @@ +#ifndef GRAPH_H +#define GRAPH_H + +#include "ultra64.h" + +struct GameState; +struct GraphicsContext; + +void Graph_InitTHGA(GraphicsContext* gfxCtx); +struct GameStateOverlay* Graph_GetNextGameState(struct GameState* gameState); +void Graph_Init(GraphicsContext* gfxCtx); +void Graph_Destroy(GraphicsContext* gfxCtx); +void Graph_TaskSet00(GraphicsContext* gfxCtx); +void Graph_Update(GraphicsContext* gfxCtx, struct GameState* gameState); +void Graph_ThreadEntry(void*); +void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size); +void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size); +#if OOT_DEBUG +void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); +void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); +#endif +Gfx* Gfx_Open(Gfx* gfx); +Gfx* Gfx_Close(Gfx* gfx, Gfx* dst); +void* Gfx_Alloc(Gfx** gfxP, u32 size); + +#if OOT_DEBUG +#define GRAPH_ALLOC(gfxCtx, size) Graph_Alloc(gfxCtx, size) +#else +#define GRAPH_ALLOC(gfxCtx, size) ((void*)((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - ALIGN16(size)))) +#endif /* OOT_DEBUG */ + +extern struct GraphicsContext* __gfxCtx; + +#define WORK_DISP __gfxCtx->work.p +#define POLY_OPA_DISP __gfxCtx->polyOpa.p +#define POLY_XLU_DISP __gfxCtx->polyXlu.p +#define OVERLAY_DISP __gfxCtx->overlay.p + +#if OOT_DEBUG + +// __gfxCtx shouldn't be used directly. +// Use the DISP macros defined above when writing to display buffers. +#define OPEN_DISPS(gfxCtx, file, line) \ + { \ + GraphicsContext* __gfxCtx; \ + Gfx* dispRefs[4]; \ + __gfxCtx = gfxCtx; \ + (void)__gfxCtx; \ + Graph_OpenDisps(dispRefs, gfxCtx, file, line) + +#define CLOSE_DISPS(gfxCtx, file, line) \ + Graph_CloseDisps(dispRefs, gfxCtx, file, line); \ + } \ + (void)0 + +#else + +#define OPEN_DISPS(gfxCtx, file, line) \ + { \ + GraphicsContext* __gfxCtx = gfxCtx; \ + s32 __dispPad + +#define CLOSE_DISPS(gfxCtx, file, line) \ + (void)0; \ + } \ + (void)0 + +#endif /* OOT_DEBUG */ + +#endif diff --git a/include/macros.h b/include/macros.h index e135934060d..148065f4f06 100644 --- a/include/macros.h +++ b/include/macros.h @@ -158,37 +158,11 @@ struct GraphicsContext; -extern struct GraphicsContext* __gfxCtx; - -#define WORK_DISP __gfxCtx->work.p -#define POLY_OPA_DISP __gfxCtx->polyOpa.p -#define POLY_XLU_DISP __gfxCtx->polyXlu.p -#define OVERLAY_DISP __gfxCtx->overlay.p #if OOT_DEBUG -// __gfxCtx shouldn't be used directly. -// Use the DISP macros defined above when writing to display buffers. -#define OPEN_DISPS(gfxCtx, file, line) \ - { \ - GraphicsContext* __gfxCtx; \ - Gfx* dispRefs[4]; \ - __gfxCtx = gfxCtx; \ - (void)__gfxCtx; \ - Graph_OpenDisps(dispRefs, gfxCtx, file, line) - -#define CLOSE_DISPS(gfxCtx, file, line) \ - Graph_CloseDisps(dispRefs, gfxCtx, file, line); \ - } \ - (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) #define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_MallocDebug(size, file, line) #define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocRDebug(size, file, line) #define DEBUG_ARENA_FREE(size, file, line) DebugArena_FreeDebug(size, file, line) @@ -201,27 +175,11 @@ extern struct GraphicsContext* __gfxCtx; #define LOG_UTILS_CHECK_NULL_POINTER(exp, ptr, file, line) LogUtils_CheckNullPointer(exp, ptr, file, line) #define LOG_UTILS_CHECK_VALID_POINTER(exp, ptr, file, line) LogUtils_CheckValidPointer(exp, ptr, file, line) #define HUNGUP_AND_CRASH(file, line) Fault_AddHungupAndCrash(file, line) -#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_MallocDebug(alloc, size, file, line) #else -#define OPEN_DISPS(gfxCtx, file, line) \ - { \ - GraphicsContext* __gfxCtx = gfxCtx; \ - s32 __dispPad - -#define CLOSE_DISPS(gfxCtx, file, line) \ - (void)0; \ - } \ - (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) #define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_Malloc(size) #define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocR(size) #define DEBUG_ARENA_FREE(size, file, line) DebugArena_Free(size) @@ -234,7 +192,6 @@ extern struct GraphicsContext* __gfxCtx; #define LOG_UTILS_CHECK_NULL_POINTER(exp, ptr, file, line) (void)0 #define LOG_UTILS_CHECK_VALID_POINTER(exp, ptr, file, line) (void)0 #define HUNGUP_AND_CRASH(file, line) LogUtils_HungupThread(file, line) -#define GAME_ALLOC_MALLOC(alloc, size, file, line) GameAlloc_Malloc(alloc, size) #endif /* OOT_DEBUG */ diff --git a/include/speed_meter.h b/include/speed_meter.h new file mode 100644 index 00000000000..5bad3bb8ae7 --- /dev/null +++ b/include/speed_meter.h @@ -0,0 +1,34 @@ +#ifndef SPEEDMETER_H +#define SPEEDMETER_H + +#include "ultra64/ultratypes.h" + +struct GraphicsContext; +struct GameState; + +typedef struct { + /* 0x00 */ char unk_00[0x18]; + /* 0x18 */ s32 x; // Unused + /* 0x1C */ s32 y; +} SpeedMeter; // size = 0x20 + +void SpeedMeter_Init(SpeedMeter* this); +void SpeedMeter_Destroy(SpeedMeter* this); +void SpeedMeter_DrawTimeEntries(SpeedMeter* this, struct GraphicsContext* gfxCtx); +void SpeedMeter_DrawAllocEntries(SpeedMeter* meter, struct GraphicsContext* gfxCtx, struct GameState* state); + +extern volatile OSTime gAudioThreadUpdateTimeTotalPerGfxTask; +extern volatile OSTime gGfxTaskSentToNextReadyMinusAudioThreadUpdateTime; +extern volatile OSTime gRSPAudioTimeTotal; +extern volatile OSTime gRSPGfxTimeTotal; +extern volatile OSTime gRDPTimeTotal; +extern volatile OSTime gGraphUpdatePeriod; +extern volatile OSTime gAudioThreadUpdateTimeStart; +extern volatile OSTime gAudioThreadUpdateTimeAcc; +extern volatile OSTime gRSPAudioTimeAcc; +extern volatile OSTime gRSPGfxTimeAcc; +extern volatile OSTime gRSPOtherTimeAcc; +extern volatile OSTime D_8016A578; +extern volatile OSTime gRDPTimeAcc; + +#endif diff --git a/include/speedmeter.h b/include/speedmeter.h deleted file mode 100644 index ec4c3f799e7..00000000000 --- a/include/speedmeter.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SPEEDMETER_H -#define SPEEDMETER_H - -#include "ultra64/ultratypes.h" - -struct GraphicsContext; -struct GameState; - -typedef struct { - /* 0x00 */ char unk_00[0x18]; - /* 0x18 */ s32 x; // Unused - /* 0x1C */ s32 y; -} SpeedMeter; // size = 0x20 - -void SpeedMeter_Init(SpeedMeter* this); -void SpeedMeter_Destroy(SpeedMeter* this); -void SpeedMeter_DrawTimeEntries(SpeedMeter* this, struct GraphicsContext* gfxCtx); -void SpeedMeter_DrawAllocEntries(SpeedMeter* meter, struct GraphicsContext* gfxCtx, struct GameState* state); - -#endif diff --git a/include/sys_matrix.h b/include/sys_matrix.h new file mode 100644 index 00000000000..f012931cc9b --- /dev/null +++ b/include/sys_matrix.h @@ -0,0 +1,18 @@ +#ifndef SYS_MATRIX_H +#define SYS_MATRIX_H + +#if OOT_DEBUG + +#define MATRIX_CHECK_FLOATS(mtx, file, line) Matrix_CheckFloats(mtx, file, line) +#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx, file, line) +#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx, file, line) + +#else + +#define MATRIX_CHECK_FLOATS(mtx, file, line) (mtx) +#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx) +#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx) + +#endif /* OOT_DEBUG */ + +#endif diff --git a/include/variables.h b/include/variables.h index 10f67329ffc..a74f77ab687 100644 --- a/include/variables.h +++ b/include/variables.h @@ -56,7 +56,6 @@ extern Gfx D_80116280[]; extern ActorOverlay gActorOverlayTable[ACTOR_ID_MAX]; // original name: "actor_dlftbls" 801162A0 extern s32 gMaxActorId; // original name: "MaxProfile" extern s32 gDebugCamEnabled; -extern GameStateOverlay gGameStateOverlayTable[GAMESTATE_ID_MAX]; extern u8 gWeatherMode; extern u8 gLightConfigAfterUnderwater; extern u8 gInterruptSongOfStorms; @@ -202,20 +201,6 @@ extern PreNmiBuff* gAppNmiBufferPtr; extern uintptr_t gSegments[NUM_SEGMENTS]; extern Scheduler gScheduler; extern PadMgr gPadMgr; -extern volatile OSTime gAudioThreadUpdateTimeTotalPerGfxTask; -extern volatile OSTime gGfxTaskSentToNextReadyMinusAudioThreadUpdateTime; -extern volatile OSTime gRSPAudioTimeTotal; -extern volatile OSTime gRSPGfxTimeTotal; -extern volatile OSTime gRDPTimeTotal; -extern volatile OSTime gGraphUpdatePeriod; -extern volatile OSTime gAudioThreadUpdateTimeStart; -extern volatile OSTime gAudioThreadUpdateTimeAcc; -extern volatile OSTime gRSPAudioTimeAcc; -extern volatile OSTime gRSPGfxTimeAcc; -extern volatile OSTime gRSPOtherTimeAcc; -extern volatile OSTime D_8016A578; -extern volatile OSTime gRDPTimeAcc; - extern SfxBankEntry D_8016BAD0[9]; extern SfxBankEntry D_8016BC80[12]; extern SfxBankEntry D_8016BEC0[22]; @@ -240,10 +225,6 @@ extern u8 __osMaxControllers; extern __OSInode __osPfsInodeCache; extern OSPifRam __osPfsPifRam; extern u16 gZBuffer[SCREEN_HEIGHT][SCREEN_WIDTH]; // 0x25800 bytes -extern u64 gGfxSPTaskOutputBuffer[0x3000]; // 0x18000 bytes -extern u64 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE / sizeof(u64)]; // 0xC00 bytes -extern u64 gGfxSPTaskStack[SP_DRAM_STACK_SIZE64]; // 0x400 bytes -extern GfxPool gGfxPools[2]; // 0x24820 bytes extern u8 gAudioHeap[0x38000]; // 0x38000 bytes #endif diff --git a/include/z64.h b/include/z64.h index 03ef633b7f2..bd6564363a0 100644 --- a/include/z64.h +++ b/include/z64.h @@ -58,14 +58,16 @@ #include "mempak.h" #include "tha.h" #include "thga.h" -#include "speedmeter.h" +#include "speed_meter.h" #include "gfx.h" +#include "graph.h" #include "jpeg.h" #include "prerender.h" #include "rand.h" #include "sys_math.h" #include "sys_math3d.h" #include "fp_math.h" +#include "sys_matrix.h" #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 @@ -309,20 +311,6 @@ typedef struct { /* 0x02 */ u16 field; } EntranceInfo; // size = 0x4 -typedef struct { - /* 0x00 */ void* loadedRamAddr; - /* 0x04 */ RomFile file; // if applicable - /* 0x0C */ void* vramStart; // if applicable - /* 0x10 */ void* vramEnd; // if applicable - /* 0x14 */ void* unk_14; - /* 0x18 */ void* init; // initializes and executes the given context - /* 0x1C */ void* destroy; // deconstructs the context, and sets the next context to load - /* 0x20 */ void* unk_20; - /* 0x24 */ void* unk_24; - /* 0x28 */ UNK_TYPE4 unk_28; - /* 0x2C */ u32 instanceSize; -} GameStateOverlay; // size = 0x30 - typedef struct { /* 0x00 */ GameState state; /* 0xA4 */ u32 timer; diff --git a/include/z64game.h b/include/z64game.h index 8cd6478963e..05b63d1a27b 100644 --- a/include/z64game.h +++ b/include/z64game.h @@ -5,31 +5,9 @@ #include "ultra64/ultratypes.h" #include "padmgr.h" #include "tha.h" +#include "gamealloc.h" struct GraphicsContext; - -typedef struct GameAllocEntry { - /* 0x00 */ struct GameAllocEntry* next; - /* 0x04 */ struct GameAllocEntry* prev; - /* 0x08 */ u32 size; - /* 0x0C */ u32 unk_0C; -} GameAllocEntry; // size = 0x10 - -typedef struct { - /* 0x00 */ GameAllocEntry base; - /* 0x10 */ GameAllocEntry* head; -} GameAlloc; // size = 0x14 - -// Used in Graph_GetNextGameState in graph.c -#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) enumName, -#define DEFINE_GAMESTATE(typeName, enumName, name) DEFINE_GAMESTATE_INTERNAL(typeName, enumName) -typedef enum { -#include "tables/gamestate_table.h" - GAMESTATE_ID_MAX -} GameStateId; -#undef DEFINE_GAMESTATE -#undef DEFINE_GAMESTATE_INTERNAL - struct GameState; typedef void (*GameStateFunc)(struct GameState* gameState); @@ -48,4 +26,22 @@ typedef struct GameState { /* 0xA0 */ u32 inPreNMIState; } GameState; // size = 0xA4 +#if OOT_DEBUG +#define GAME_STATE_ALLOC(gameState, size, file, line) GameState_Alloc(gameState, size, file, line) +#else +#define GAME_STATE_ALLOC(gameState, size, file, line) THA_AllocTailAlign16(&(gameState)->tha, size) +#endif + +void GameState_ReqPadData(GameState* gameState); +void GameState_Update(GameState* gameState); +void GameState_Init(GameState* gameState, GameStateFunc init, struct GraphicsContext* gfxCtx); +void GameState_Destroy(GameState* gameState); +GameStateFunc GameState_GetInit(GameState* gameState); +u32 GameState_IsRunning(GameState* gameState); + +#if OOT_DEBUG +void* GameState_Alloc(GameState* gameState, size_t size, const char* file, int line); +#endif +void GameState_Realloc(GameState* gameState, size_t size); + #endif diff --git a/include/z_game_dlftbls.h b/include/z_game_dlftbls.h new file mode 100644 index 00000000000..ef379c4ea20 --- /dev/null +++ b/include/z_game_dlftbls.h @@ -0,0 +1,39 @@ +#ifndef Z_GAME_DLFTBLS_H +#define Z_GAME_DLFTBLS_H + +#include "ultra64.h" +#include "romfile.h" +#include "unk.h" + +typedef struct GameStateOverlay { + /* 0x00 */ void* loadedRamAddr; + /* 0x04 */ RomFile file; // if applicable + /* 0x0C */ void* vramStart; // if applicable + /* 0x10 */ void* vramEnd; // if applicable + /* 0x14 */ void* unk_14; + /* 0x18 */ void* init; // initializes and executes the given context + /* 0x1C */ void* destroy; // deconstructs the context, and sets the next context to load + /* 0x20 */ void* unk_20; + /* 0x24 */ void* unk_24; + /* 0x28 */ UNK_TYPE4 unk_28; + /* 0x2C */ u32 instanceSize; +} GameStateOverlay; // size = 0x30 + +/* START typedef enum GameStateId */ +// Used in Graph_GetNextGameState in graph.c +#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) enumName, +#define DEFINE_GAMESTATE(typeName, enumName, name) DEFINE_GAMESTATE_INTERNAL(typeName, enumName) +typedef enum { +#include "tables/gamestate_table.h" + GAMESTATE_ID_MAX +} GameStateId; +#undef DEFINE_GAMESTATE +#undef DEFINE_GAMESTATE_INTERNAL +/* END typedef enum GameStateId */ + +void Overlay_LoadGameState(GameStateOverlay* overlayEntry); +void Overlay_FreeGameState(GameStateOverlay* overlayEntry); + +extern GameStateOverlay gGameStateOverlayTable[GAMESTATE_ID_MAX]; + +#endif diff --git a/src/buffers/gfxbuffers.c b/src/buffers/gfxbuffers.c index fa466bc8290..de22850dc67 100644 --- a/src/buffers/gfxbuffers.c +++ b/src/buffers/gfxbuffers.c @@ -1,4 +1,6 @@ -#include "z64.h" +#pragma increment_block_number 1 +#include "gfxbuffers.h" +#include "alignment.h" ALIGNED(16) u64 gGfxSPTaskOutputBuffer[0x3000]; diff --git a/src/code/audio_thread_manager.c b/src/code/audio_thread_manager.c index 32c5826a5d9..87aaa7093ef 100644 --- a/src/code/audio_thread_manager.c +++ b/src/code/audio_thread_manager.c @@ -6,6 +6,7 @@ */ #include "global.h" +#include "speed_meter.h" void AudioMgr_NotifyTaskDone(AudioMgr* audioMgr) { AudioTask* task = audioMgr->rspTask; diff --git a/src/code/fault.c b/src/code/fault.c index 16f1a183f70..1c4b3093011 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -48,7 +48,7 @@ // just above (the exact upper bound depends on the block numbers assigned to // extern variables declared in headers). #if OOT_DEBUG -#pragma increment_block_number 0 +#pragma increment_block_number 1 #else #pragma increment_block_number 20 #endif diff --git a/src/code/graph.c b/src/code/graph.c index 92df90d8ff9..1d9b477454d 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -1,5 +1,12 @@ #include "global.h" +#include "gfx.h" +#include "gfxbuffers.h" +#include "graph.h" #include "terminal.h" +#include "z64game.h" +#include "z_game_dlftbls.h" +#include "regs.h" +#include "speed_meter.h" #define GFXPOOL_HEAD_MAGIC 0x1234 #define GFXPOOL_TAIL_MAGIC 0x5678 @@ -119,7 +126,7 @@ void Graph_InitTHGA(GraphicsContext* gfxCtx) { gfxCtx->unk_014 = 0; } -GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { +struct GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { void* gameStateInitFunc = GameState_GetInit(gameState); // Generates code to match gameStateInitFunc to a gamestate entry and returns it if found @@ -440,7 +447,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) { #endif } -void Graph_ThreadEntry(void* arg0) { +void Graph_ThreadEntry(void* arg) { GraphicsContext gfxCtx; GameState* gameState; u32 size; diff --git a/src/code/sched.c b/src/code/sched.c index fbfc42dc07f..841de6b9882 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -40,6 +40,7 @@ * @see irqmgr.c */ #include "global.h" +#include "speed_meter.h" #define RSP_DONE_MSG 667 #define RDP_DONE_MSG 668 diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c index dff46d91e30..9de934a0b4a 100644 --- a/src/code/speed_meter.c +++ b/src/code/speed_meter.c @@ -1,5 +1,6 @@ #include "global.h" #include "terminal.h" +#include "speed_meter.h" /** * How much time the audio update on the audio thread (`AudioThread_Update`) took in total, between scheduling the last diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index bb86036ad5b..2d9a00545c7 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -7,7 +7,7 @@ // For retail BSS ordering, the block number of cbf in Math3D_CylVsCylOverlapCenterDist // must be 0. -#pragma increment_block_number 108 +#pragma increment_block_number 112 s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); diff --git a/src/code/z_DLF.c b/src/code/z_DLF.c index 42fbc4b4768..eaa02d3cf61 100644 --- a/src/code/z_DLF.c +++ b/src/code/z_DLF.c @@ -1,5 +1,6 @@ #include "global.h" #include "terminal.h" +#include "z_game_dlftbls.h" void Overlay_LoadGameState(GameStateOverlay* overlayEntry) { if (overlayEntry->loadedRamAddr != NULL) { diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 9b0e03131fe..8ff8c8a363b 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -2363,6 +2363,10 @@ void CollisionCheck_ATTrisVsACTris(PlayState* play, CollisionCheckContext* colCh } } +#if OOT_DEBUG +//static s8 sBssDummy7; +#endif + void CollisionCheck_ATTrisVsACQuad(PlayState* play, CollisionCheckContext* colChkCtx, Collider* atCol, Collider* acCol) { static Vec3f hitPos; diff --git a/src/code/z_game_dlftbls.c b/src/code/z_game_dlftbls.c index 2cad84089de..28a53e0c276 100644 --- a/src/code/z_game_dlftbls.c +++ b/src/code/z_game_dlftbls.c @@ -1,4 +1,6 @@ #include "global.h" +#include "z_game_dlftbls.h" +#include "segment_symbols.h" // Linker symbol declarations (used in the table below) #define DEFINE_GAMESTATE(typeName, enumName, name) DECLARE_OVERLAY_SEGMENT(name) diff --git a/src/code/z_room.c b/src/code/z_room.c index 9c16a53b6d4..4f433cc9bc0 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -1,4 +1,5 @@ #include "global.h" +#include "gfxbuffers.h" #include "terminal.h" Vec3f D_801270A0 = { 0.0f, 0.0f, 0.0f }; diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index d1a18134cf4..79001ca47c7 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 208 +#pragma increment_block_number 198 #define FLAGS ACTOR_FLAG_4 From a6db75ae22398e7a28e3d6a424d71b777f296150 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 24 Jun 2024 04:57:32 -0400 Subject: [PATCH 2/9] formatting --- src/code/z_collision_check.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 8ff8c8a363b..9b0e03131fe 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -2363,10 +2363,6 @@ void CollisionCheck_ATTrisVsACTris(PlayState* play, CollisionCheckContext* colCh } } -#if OOT_DEBUG -//static s8 sBssDummy7; -#endif - void CollisionCheck_ATTrisVsACQuad(PlayState* play, CollisionCheckContext* colChkCtx, Collider* atCol, Collider* acCol) { static Vec3f hitPos; From 83bf26806ba254a8dde90adcccc32afca7e469cf Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 24 Jun 2024 22:03:29 -0400 Subject: [PATCH 3/9] implement suggestions, improve sys_matrix.c --- include/functions.h | 36 ------ include/gfxalloc.h | 10 ++ include/graph.h | 5 - include/sys_matrix.h | 74 +++++++++++ include/variables.h | 2 - include/z64.h | 6 - src/code/fault.c | 4 +- src/code/flg_set.c | 1 + src/code/game.c | 2 + src/code/gfxalloc.c | 3 +- src/code/graph.c | 2 +- src/code/sys_matrix.c | 122 +++++++++++------- src/code/z_actor.c | 6 +- src/code/z_collision_check.c | 2 +- src/code/z_debug.c | 1 + src/code/z_demo.c | 1 + src/code/z_eff_blure.c | 4 +- src/code/z_eff_spark.c | 2 +- src/code/z_kankyo.c | 3 +- src/code/z_map_exp.c | 2 +- src/code/z_message.c | 1 + src/code/z_parameter.c | 2 +- src/code/z_play.c | 1 + src/code/z_player_lib.c | 8 +- src/code/z_rcp.c | 1 + src/code/z_room.c | 16 +-- src/code/z_skin.c | 2 +- src/code/z_vismono.c | 1 + .../actors/ovl_Bg_Haka_Huta/z_bg_haka_huta.c | 2 +- .../z_bg_hidan_rsekizou.c | 2 +- .../ovl_Bg_Hidan_Sekizou/z_bg_hidan_sekizou.c | 2 +- .../ovl_Bg_Hidan_Sima/z_bg_hidan_sima.c | 2 +- .../z_bg_spot08_iceblock.c | 2 +- src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c | 2 +- .../actors/ovl_Boss_Goma/z_boss_goma.c | 2 +- src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c | 2 +- src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c | 10 +- src/overlays/actors/ovl_Boss_Va/z_boss_va.c | 2 +- .../actors/ovl_En_Bom_Chu/z_en_bom_chu.c | 2 +- .../actors/ovl_En_Goroiwa/z_en_goroiwa.c | 2 +- .../actors/ovl_En_Honotrap/z_en_honotrap.c | 2 +- .../ovl_En_Horse_Normal/z_en_horse_normal.c | 2 +- src/overlays/actors/ovl_En_Mag/z_en_mag.c | 1 + .../actors/ovl_En_Nutsball/z_en_nutsball.c | 2 +- src/overlays/actors/ovl_En_Okuta/z_en_okuta.c | 2 +- src/overlays/actors/ovl_En_Sda/z_en_sda.c | 2 +- src/overlays/actors/ovl_En_Sw/z_en_sw.c | 4 +- src/overlays/actors/ovl_En_Zl2/z_en_zl2.c | 14 +- src/overlays/actors/ovl_En_Zl3/z_en_zl3.c | 14 +- src/overlays/actors/ovl_Fishing/z_fishing.c | 4 +- .../ovl_Effect_Ss_Bomb/z_eff_ss_bomb.c | 2 +- .../ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c | 2 +- .../ovl_Effect_Ss_Dust/z_eff_ss_dust.c | 2 +- .../ovl_Effect_Ss_HitMark/z_eff_ss_hitmark.c | 2 +- .../z_eff_ss_kirakira.c | 2 +- .../z_eff_ss_lightning.c | 2 +- .../misc/ovl_kaleido_scope/z_kaleido_debug.c | 1 + .../misc/ovl_kaleido_scope/z_kaleido_scope.c | 1 + tools/namefixer.py | 6 +- 59 files changed, 249 insertions(+), 170 deletions(-) create mode 100644 include/gfxalloc.h diff --git a/include/functions.h b/include/functions.h index 096e0720ccf..79303fd4b17 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1226,42 +1226,6 @@ void* SysCfb_GetFbPtr(s32 idx); 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/gfxalloc.h b/include/gfxalloc.h new file mode 100644 index 00000000000..158a2a9f589 --- /dev/null +++ b/include/gfxalloc.h @@ -0,0 +1,10 @@ +#ifndef GFXALLOC_H +#define GFXALLOC_H + +#include "ultra64.h" + +Gfx* Gfx_Open(Gfx* gfx); +Gfx* Gfx_Close(Gfx* gfx, Gfx* dst); +void* Gfx_Alloc(Gfx** gfxP, u32 size); + +#endif diff --git a/include/graph.h b/include/graph.h index 8887621b404..479db9952e5 100644 --- a/include/graph.h +++ b/include/graph.h @@ -19,9 +19,6 @@ void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size); void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); #endif -Gfx* Gfx_Open(Gfx* gfx); -Gfx* Gfx_Close(Gfx* gfx, Gfx* dst); -void* Gfx_Alloc(Gfx** gfxP, u32 size); #if OOT_DEBUG #define GRAPH_ALLOC(gfxCtx, size) Graph_Alloc(gfxCtx, size) @@ -29,8 +26,6 @@ void* Gfx_Alloc(Gfx** gfxP, u32 size); #define GRAPH_ALLOC(gfxCtx, size) ((void*)((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - ALIGN16(size)))) #endif /* OOT_DEBUG */ -extern struct GraphicsContext* __gfxCtx; - #define WORK_DISP __gfxCtx->work.p #define POLY_OPA_DISP __gfxCtx->polyOpa.p #define POLY_XLU_DISP __gfxCtx->polyXlu.p diff --git a/include/sys_matrix.h b/include/sys_matrix.h index f012931cc9b..1b20901d573 100644 --- a/include/sys_matrix.h +++ b/include/sys_matrix.h @@ -1,6 +1,80 @@ #ifndef SYS_MATRIX_H #define SYS_MATRIX_H +#include "z64math.h" + + +struct GraphicsContext; +struct GameState; + +typedef enum { + /* 0 */ MTXMODE_NEW, // generates a new matrix + /* 1 */ MTXMODE_APPLY // applies transformation to the current matrix +} MatrixMode; + + +extern Mtx gIdentityMtx; +extern MtxF gIdentityMatrixF; + + +/* Stack operations */ +void Matrix_Init(GameState* gameState); +void Matrix_Push(void); +void Matrix_Pop(void); +void Matrix_Get(MtxF* dest); +void Matrix_Put(MtxF* src); +MtxF* Matrix_GetCurrent(void); +void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode); +void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode); + +/* Basic operations */ +void Matrix_Mult(MtxF* mf, u8 mode); + +void Matrix_RotateX(f32 x, u8 mode); +void Matrix_RotateY(f32 y, u8 mode); +void Matrix_RotateZ(f32 z, u8 mode); + +/* Compound operations */ + +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); + +/* Conversion and allocation operations */ + +#if OOT_DEBUG +MtxF* Matrix_CheckFloats(MtxF* mf, const char* file, int line); +#endif +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 + +/* Vector operations */ + +void Matrix_MultVec3f(Vec3f* src, Vec3f* dest); + +/* Copy and another conversion */ + +void Matrix_MtxFCopy(MtxF* dest, MtxF* src); +void Matrix_MtxToMtxF(Mtx* src, MtxF* dest); + +/* Miscellaneous */ + +void Matrix_MultVec3fExt(Vec3f* src, Vec3f* dest, MtxF* mf); +void Matrix_Transpose(MtxF* mf); +void Matrix_ReplaceRotation(MtxF* mf); +void Matrix_MtxFToYXZRot(MtxF* src, Vec3s* dest, s32 nonUniformScale); +void Matrix_MtxFToZYXRot(MtxF* src, Vec3s* dest, s32 nonUniformScale); +void Matrix_RotateAxis(f32 angle, Vec3f* axis, u8 mode); +void Matrix_SetTranslateScaleMtx2(Mtx* mtx, f32 scaleX, f32 scaleY, f32 scaleZ, f32 translateX, f32 translateY, + f32 translateZ); + + #if OOT_DEBUG #define MATRIX_CHECK_FLOATS(mtx, file, line) Matrix_CheckFloats(mtx, file, line) diff --git a/include/variables.h b/include/variables.h index a74f77ab687..33b75498889 100644 --- a/include/variables.h +++ b/include/variables.h @@ -100,8 +100,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 bd6564363a0..819e46c1c43 100644 --- a/include/z64.h +++ b/include/z64.h @@ -58,7 +58,6 @@ #include "mempak.h" #include "tha.h" #include "thga.h" -#include "speed_meter.h" #include "gfx.h" #include "graph.h" #include "jpeg.h" @@ -388,11 +387,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/fault.c b/src/code/fault.c index 1c4b3093011..6f70df31041 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -48,9 +48,9 @@ // just above (the exact upper bound depends on the block numbers assigned to // extern variables declared in headers). #if OOT_DEBUG -#pragma increment_block_number 1 +#pragma increment_block_number 18 #else -#pragma increment_block_number 20 +#pragma increment_block_number 23 #endif void FaultDrawer_Init(void); diff --git a/src/code/flg_set.c b/src/code/flg_set.c index 1904394868a..5d745fd4528 100644 --- a/src/code/flg_set.c +++ b/src/code/flg_set.c @@ -1,4 +1,5 @@ #include "global.h" +#include "gfxalloc.h" typedef struct { /* 0x00 */ u16* value; diff --git a/src/code/game.c b/src/code/game.c index 7d290e3329d..e3c6fb9c9e2 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -1,5 +1,7 @@ #include "global.h" #include "terminal.h" +#include "gfxalloc.h" +#include "speed_meter.h" SpeedMeter D_801664D0; VisCvg sVisCvg; diff --git a/src/code/gfxalloc.c b/src/code/gfxalloc.c index 79d8bb04e56..3b4d72f0574 100644 --- a/src/code/gfxalloc.c +++ b/src/code/gfxalloc.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "gfxalloc.h" +#include "alignment.h" Gfx* Gfx_Open(Gfx* gfx) { return gfx + 1; diff --git a/src/code/graph.c b/src/code/graph.c index 1d9b477454d..810aae6d7cb 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -126,7 +126,7 @@ void Graph_InitTHGA(GraphicsContext* gfxCtx) { gfxCtx->unk_014 = 0; } -struct GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { +GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { void* gameStateInitFunc = GameState_GetInit(gameState); // Generates code to match gameStateInitFunc to a gamestate entry and returns it if found diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index 2ca6e4cf47a..6a5fff02a09 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -1,14 +1,14 @@ #include "global.h" // clang-format off -Mtx gMtxClear = gdSPDefMtx( +Mtx gIdentityMtx = gdSPDefMtx( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); -MtxF gMtxFClear = { +MtxF gIdentityMatrixF = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, @@ -771,103 +771,131 @@ void Matrix_ReplaceRotation(MtxF* mf) { } /** - * Gets the rotation the specified matrix represents, using Tait-Bryan YXZ angles. - * The flag value doesn't matter for a rotation matrix. Not 0 does extra calculation. + * @brief Extract the YXZ Tait-Bryan rotation angles from the linear part \f$ A \f$ of a matrix. + * + * \f$ A \f$ should have orthogonal columns; the most general matrix of this form can be written as \f$ RS \f$ + * with \f$ S \f$ a scale matrix. + * + * If A has columns with the same norm (such as if it is just a rotation matrix), it is sufficient (and faster) to use + * `nonUniformScale` off: `nonUniformScale` being set enables extraction of the angles from a matrix with columns that + * are orthogonal but have different scales, at the cost of requiring extra calculation. + * + * @param[in] src Matrix to extract angles from. + * @param[out] dest vector to write angles to. + * @param[in] nonUniformScale boolean: true enables handling matrices with differently-scaled columns. + * + * @remark original name: "Matrix_to_rotate_new"? */ -void Matrix_MtxFToYXZRotS(MtxF* mf, Vec3s* rotDest, s32 flag) { +void Matrix_MtxFToYXZRot(MtxF* src, Vec3s* dest, s32 nonUniformScale) { f32 temp; f32 temp2; f32 temp3; f32 temp4; - temp = mf->xz; + temp = src->xz; temp *= temp; - temp += SQ(mf->zz); - rotDest->x = RAD_TO_BINANG(Math_FAtan2F(-mf->yz, sqrtf(temp))); + temp += SQ(src->zz); + dest->x = RAD_TO_BINANG(Math_FAtan2F(-src->yz, sqrtf(temp))); - if ((rotDest->x == 0x4000) || (rotDest->x == -0x4000)) { - rotDest->z = 0; + if ((dest->x == 0x4000) || (dest->x == -0x4000)) { + // cos(x) = 0 if either of these is true, and we get gimbal locking + // (https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles); fix z to make y + // well-defined. + dest->z = 0; - rotDest->y = RAD_TO_BINANG(Math_FAtan2F(-mf->zx, mf->xx)); + dest->y = RAD_TO_BINANG(Math_FAtan2F(-src->zx, src->xx)); } else { - rotDest->y = RAD_TO_BINANG(Math_FAtan2F(mf->xz, mf->zz)); + dest->y = RAD_TO_BINANG(Math_FAtan2F(src->xz, src->zz)); - if (!flag) { - rotDest->z = RAD_TO_BINANG(Math_FAtan2F(mf->yx, mf->yy)); + if (!nonUniformScale) { + // assume the columns have the same normalisation + dest->z = RAD_TO_BINANG(Math_FAtan2F(src->yx, src->yy)); } else { - temp = mf->xx; - temp2 = mf->zx; - temp3 = mf->zy; + temp = src->xx; + temp2 = src->zx; + temp3 = src->zy; temp *= temp; temp += SQ(temp2); - temp2 = mf->yx; + temp2 = src->yx; temp += SQ(temp2); - /* temp = xx^2+zx^2+yx^2 == 1 for a rotation matrix */ + // temp = xx^2+zx^2+yx^2 == 1 for a rotation matrix temp = sqrtf(temp); - temp = temp2 / temp; + temp = temp2 / temp; // yx in normalised column - temp2 = mf->xy; + temp2 = src->xy; temp2 *= temp2; temp2 += SQ(temp3); - temp3 = mf->yy; + temp3 = src->yy; temp2 += SQ(temp3); - /* temp2 = xy^2+zy^2+yy^2 == 1 for a rotation matrix */ + // temp2 = xy^2+zy^2+yy^2 == 1 for a rotation matrix temp2 = sqrtf(temp2); - temp2 = temp3 / temp2; + temp2 = temp3 / temp2; // yy in normalised column - /* for a rotation matrix, temp == yx and temp2 == yy - * which is the same as in the !flag branch */ - rotDest->z = RAD_TO_BINANG(Math_FAtan2F(temp, temp2)); + // for a rotation matrix, temp == yx and temp2 == yy which is the same as in the !nonUniformScale branch + dest->z = RAD_TO_BINANG(Math_FAtan2F(temp, temp2)); } } } /** - * Gets the rotation the specified matrix represents, using Tait-Bryan ZYX angles. - * The flag value doesn't matter for a rotation matrix. Not 0 does extra calculation. + * @brief Extract the ZYX Tait-Bryan rotation angles from the linear part \f$ A \f$ of a matrix. + * + * \f$ A \f$ should have orthogonal columns; the most general matrix of this form can be written as \f$ RS \f$ + * with \f$ S \f$ a scale matrix. + * + * If A has columns with the same norm (such as if it is just a rotation matrix), it is sufficient (and faster) to use + * `nonUniformScale` off: `nonUniformScale` being set enables extraction of the angles from a matrix with columns that + * are orthogonal but have different scales, at the cost of requiring extra calculation. + * + * @param[in] src Matrix to extract angles from. + * @param[out] dest vector to write angles to. + * @param[in] nonUniformScale boolean: true enables handling matrices with unnormalised columns. + * + * @remark original name: "Matrix_to_rotate2_new"? + * + * See Matrix_MtxFToYXZRot() for full inline documentation. */ -void Matrix_MtxFToZYXRotS(MtxF* mf, Vec3s* rotDest, s32 flag) { +void Matrix_MtxFToZYXRot(MtxF* src, Vec3s* dest, s32 nonUniformScale) { f32 temp; f32 temp2; f32 temp3; f32 temp4; - temp = mf->xx; + temp = src->xx; temp *= temp; - temp += SQ(mf->yx); - rotDest->y = RAD_TO_BINANG(Math_FAtan2F(-mf->zx, sqrtf(temp))); + temp += SQ(src->yx); + dest->y = RAD_TO_BINANG(Math_FAtan2F(-src->zx, sqrtf(temp))); - if ((rotDest->y == 0x4000) || (rotDest->y == -0x4000)) { - rotDest->x = 0; - rotDest->z = RAD_TO_BINANG(Math_FAtan2F(-mf->xy, mf->yy)); + if ((dest->y == 0x4000) || (dest->y == -0x4000)) { + dest->x = 0; + dest->z = RAD_TO_BINANG(Math_FAtan2F(-src->xy, src->yy)); } else { - rotDest->z = RAD_TO_BINANG(Math_FAtan2F(mf->yx, mf->xx)); + dest->z = RAD_TO_BINANG(Math_FAtan2F(src->yx, src->xx)); - if (!flag) { - rotDest->x = RAD_TO_BINANG(Math_FAtan2F(mf->zy, mf->zz)); + if (!nonUniformScale) { + dest->x = RAD_TO_BINANG(Math_FAtan2F(src->zy, src->zz)); } else { - // see Matrix_MtxFToYXZRotS - temp = mf->xy; - temp2 = mf->yy; - temp3 = mf->yz; + temp = src->xy; + temp2 = src->yy; + temp3 = src->yz; temp *= temp; temp += SQ(temp2); - temp2 = mf->zy; + temp2 = src->zy; temp += SQ(temp2); temp = sqrtf(temp); temp = temp2 / temp; - temp2 = mf->xz; + temp2 = src->xz; temp2 *= temp2; temp2 += SQ(temp3); - temp3 = mf->zz; + temp3 = src->zz; temp2 += SQ(temp3); temp2 = sqrtf(temp2); temp2 = temp3 / temp2; - rotDest->x = RAD_TO_BINANG(Math_FAtan2F(temp, temp2)); + dest->x = RAD_TO_BINANG(Math_FAtan2F(temp, temp2)); } } } diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 6afae4f1fd6..08f330f788f 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -2110,8 +2110,8 @@ void Actor_InitContext(PlayState* play, ActorContext* actorCtx, ActorEntry* play bzero(actorCtx, sizeof(ActorContext)); ActorOverlayTable_Init(); - Matrix_MtxFCopy(&play->billboardMtxF, &gMtxFClear); - Matrix_MtxFCopy(&play->viewProjectionMtxF, &gMtxFClear); + Matrix_MtxFCopy(&play->billboardMtxF, &gIdentityMatrixF); + Matrix_MtxFCopy(&play->viewProjectionMtxF, &gIdentityMatrixF); overlayEntry = &gActorOverlayTable[0]; for (i = 0; i < ARRAY_COUNT(gActorOverlayTable); i++) { @@ -3347,7 +3347,7 @@ s32 BodyBreak_SpawnParts(Actor* actor, BodyBreak* bodyBreak, PlayState* play, s1 mtx->zw, 0, 0, objectSlot, type); if (spawnedEnPart != NULL) { - Matrix_MtxFToYXZRotS(&bodyBreak->matrices[bodyBreak->count], &spawnedEnPart->actor.shape.rot, 0); + Matrix_MtxFToYXZRot(&bodyBreak->matrices[bodyBreak->count], &spawnedEnPart->actor.shape.rot, 0); spawnedEnPart->displayList = bodyBreak->dLists[bodyBreak->count]; spawnedEnPart->actor.scale = actor->scale; } diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 9b0e03131fe..af5d044b157 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -37,7 +37,7 @@ void Collider_DrawPoly(GraphicsContext* gfxCtx, Vec3f* vA, Vec3f* vB, Vec3f* vC, OPEN_DISPS(gfxCtx, "../z_collision_check.c", 713); - gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_OPA_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gDPSetPrimColor(POLY_OPA_DISP++, 0x00, 0xFF, r, g, b, 50); gDPPipeSync(POLY_OPA_DISP++); gDPSetRenderMode(POLY_OPA_DISP++, G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2); diff --git a/src/code/z_debug.c b/src/code/z_debug.c index 652b6f643a5..60b045f0203 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -1,4 +1,5 @@ #include "global.h" +#include "gfxalloc.h" typedef struct { /* 0x0 */ u8 x; diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 6961ed25be1..7ec2ef8a7df 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -1,4 +1,5 @@ #include "global.h" +#include "gfxalloc.h" #include "quake.h" #include "z64camera.h" diff --git a/src/code/z_eff_blure.c b/src/code/z_eff_blure.c index 47722faaf80..c18f4409778 100644 --- a/src/code/z_eff_blure.c +++ b/src/code/z_eff_blure.c @@ -809,7 +809,7 @@ void EffectBlure_DrawSimpleVertices(GraphicsContext* gfxCtx, EffectBlure* this, gSPMatrix(POLY_XLU_DISP++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPVertex(POLY_XLU_DISP++, &vtx[j], 4, 0); gSP2Triangles(POLY_XLU_DISP++, 0, 1, 3, 0, 0, 3, 2, 0); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); } } @@ -938,7 +938,7 @@ void EffectBlure_Draw(void* thisx, GraphicsContext* gfxCtx) { OPEN_DISPS(gfxCtx, "../z_eff_blure.c", 1596); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); if (this->numElements != 0) { if (this->flags == 0) { diff --git a/src/code/z_eff_spark.c b/src/code/z_eff_spark.c index f741c0a138c..61fac171705 100644 --- a/src/code/z_eff_spark.c +++ b/src/code/z_eff_spark.c @@ -154,7 +154,7 @@ void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) { OPEN_DISPS(gfxCtx, "../z_eff_spark.c", 293); if (this != NULL) { - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); POLY_XLU_DISP = Gfx_SetupDL(POLY_XLU_DISP, SETUPDL_38); gDPSetCycleType(POLY_XLU_DISP++, G_CYC_2CYCLE); diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 60f5c651f95..15cf67c8047 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -1,5 +1,6 @@ #include "global.h" #include "ultra64.h" +#include "gfxalloc.h" #include "terminal.h" #include "z64frame_advance.h" @@ -10,7 +11,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 80 +#pragma increment_block_number 84 typedef enum { /* 0x00 */ LIGHTNING_BOLT_START, diff --git a/src/code/z_map_exp.c b/src/code/z_map_exp.c index a4eb9d5207a..b3fdce5a178 100644 --- a/src/code/z_map_exp.c +++ b/src/code/z_map_exp.c @@ -319,7 +319,7 @@ void Minimap_DrawCompassIcons(PlayState* play) { if (play->interfaceCtx.minimapAlpha >= 0xAA) { Gfx_SetupDL_42Overlay(play->state.gfxCtx); - gSPMatrix(OVERLAY_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(OVERLAY_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); diff --git a/src/code/z_message.c b/src/code/z_message.c index e0a98beb547..a027d8dce08 100644 --- a/src/code/z_message.c +++ b/src/code/z_message.c @@ -1,4 +1,5 @@ #include "global.h" +#include "gfxalloc.h" #include "message_data_static.h" #include "terminal.h" #include "assets/textures/parameter_static/parameter_static.h" diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 8a32dd2a2bf..1d1e1b42822 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -3369,7 +3369,7 @@ void Interface_Draw(PlayState* play) { gSPSegment(OVERLAY_DISP++, 0x08, pauseCtx->iconItemSegment); Gfx_SetupDL_42Overlay(play->state.gfxCtx); gDPSetCombineMode(OVERLAY_DISP++, G_CC_MODULATERGBA_PRIM, G_CC_MODULATERGBA_PRIM); - gSPMatrix(OVERLAY_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(OVERLAY_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); pauseCtx->cursorVtx[16].v.ob[0] = pauseCtx->cursorVtx[18].v.ob[0] = pauseCtx->equipAnimX / 10; pauseCtx->cursorVtx[17].v.ob[0] = pauseCtx->cursorVtx[19].v.ob[0] = diff --git a/src/code/z_play.c b/src/code/z_play.c index 7abd6705c5d..cb3de6c72ba 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -1,4 +1,5 @@ #include "global.h" +#include "gfxalloc.h" #include "quake.h" #include "terminal.h" diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 80d4c210d1a..564ed7498ed 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -1542,13 +1542,13 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve Matrix_MultVec3f(&D_80126128, &hookedActor->world.pos); Matrix_RotateZYX(0x69E8, -0x5708, 0x458E, MTXMODE_APPLY); Matrix_Get(&sp14C); - Matrix_MtxFToYXZRotS(&sp14C, &hookedActor->world.rot, 0); + Matrix_MtxFToYXZRot(&sp14C, &hookedActor->world.rot, 0); hookedActor->shape.rot = hookedActor->world.rot; } else if (this->stateFlags1 & PLAYER_STATE1_11) { Vec3s spB8; Matrix_Get(&sp14C); - Matrix_MtxFToYXZRotS(&sp14C, &spB8, 0); + Matrix_MtxFToYXZRot(&sp14C, &spB8, 0); if (hookedActor->flags & ACTOR_FLAG_17) { hookedActor->world.rot.x = hookedActor->shape.rot.x = spB8.x - this->unk_3BC.x; @@ -1558,7 +1558,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve } } else { Matrix_Get(&this->mf_9E0); - Matrix_MtxFToYXZRotS(&this->mf_9E0, &this->unk_3BC, 0); + Matrix_MtxFToYXZRot(&this->mf_9E0, &this->unk_3BC, 0); } } } else if (limbIndex == PLAYER_LIMB_R_HAND) { @@ -1639,7 +1639,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve Matrix_MultVec3f(&D_80126190, &heldActor->world.pos); Matrix_RotateZYX(0, -0x4000, -0x4000, MTXMODE_APPLY); Matrix_Get(&sp44); - Matrix_MtxFToYXZRotS(&sp44, &heldActor->world.rot, 0); + Matrix_MtxFToYXZRot(&sp44, &heldActor->world.rot, 0); heldActor->shape.rot = heldActor->world.rot; if (func_8002DD78(this) != 0) { diff --git a/src/code/z_rcp.c b/src/code/z_rcp.c index a4100700b59..ced1563cd7c 100644 --- a/src/code/z_rcp.c +++ b/src/code/z_rcp.c @@ -1,4 +1,5 @@ #include "global.h" +#include "gfxalloc.h" Gfx sSetupDL[SETUPDL_MAX][6] = { { diff --git a/src/code/z_room.c b/src/code/z_room.c index 4f433cc9bc0..b2552580feb 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -43,14 +43,14 @@ void Room_DrawNormal(PlayState* play, Room* room, u32 flags) { func_800342EC(&D_801270A0, play); gSPSegment(POLY_OPA_DISP++, 0x03, room->segment); func_80093C80(play); - gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_OPA_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); } if (flags & ROOM_DRAW_XLU) { func_8003435C(&D_801270A0, play); gSPSegment(POLY_XLU_DISP++, 0x03, room->segment); Gfx_SetupDL_25Xlu(play->state.gfxCtx); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); } roomShape = &room->roomShape->normal; @@ -117,7 +117,7 @@ void Room_DrawCullable(PlayState* play, Room* room, u32 flags) { func_800342EC(&D_801270A0, play); gSPSegment(POLY_OPA_DISP++, 0x03, room->segment); func_80093C80(play); - gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_OPA_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); } if (1) {} @@ -126,7 +126,7 @@ void Room_DrawCullable(PlayState* play, Room* room, u32 flags) { func_8003435C(&D_801270A0, play); gSPSegment(POLY_XLU_DISP++, 0x03, room->segment); Gfx_SetupDL_25Xlu(play->state.gfxCtx); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); } roomShape = &room->roomShape->cullable; @@ -379,7 +379,7 @@ void Room_DrawImageSingle(PlayState* play, Room* room, u32 flags) { if (drawOpa) { Gfx_SetupDL_25Opa(play->state.gfxCtx); - gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_OPA_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(POLY_OPA_DISP++, entry->opa); } @@ -407,7 +407,7 @@ void Room_DrawImageSingle(PlayState* play, Room* room, u32 flags) { if (drawXlu) { gSPSegment(POLY_XLU_DISP++, 0x03, room->segment); Gfx_SetupDL_25Xlu(play->state.gfxCtx); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(POLY_XLU_DISP++, entry->xlu); } @@ -479,7 +479,7 @@ void Room_DrawImageMulti(PlayState* play, Room* room, u32 flags) { if (drawOpa) { Gfx_SetupDL_25Opa(play->state.gfxCtx); - gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_OPA_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(POLY_OPA_DISP++, dListsEntry->opa); } @@ -507,7 +507,7 @@ void Room_DrawImageMulti(PlayState* play, Room* room, u32 flags) { if (drawXlu) { gSPSegment(POLY_XLU_DISP++, 0x03, room->segment); Gfx_SetupDL_25Xlu(play->state.gfxCtx); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_MODELVIEW | G_MTX_LOAD); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(POLY_XLU_DISP++, dListsEntry->xlu); } diff --git a/src/code/z_skin.c b/src/code/z_skin.c index 69a14f06560..e3e546beea7 100644 --- a/src/code/z_skin.c +++ b/src/code/z_skin.c @@ -204,7 +204,7 @@ void Skin_DrawImpl(Actor* actor, PlayState* play, Skin* skin, SkinPostDraw postD skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment); if (!(drawFlags & SKIN_DRAW_FLAG_CUSTOM_MATRIX)) { - gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_OPA_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &skin->mtx); if (mtx == NULL) { diff --git a/src/code/z_vismono.c b/src/code/z_vismono.c index a35cdcd1052..68c81513723 100644 --- a/src/code/z_vismono.c +++ b/src/code/z_vismono.c @@ -9,6 +9,7 @@ */ #include "global.h" +#include "gfxalloc.h" // Height of the fragments the color frame buffer (CFB) is split into. // It is the maximum amount of lines such that all rgba16 SCREEN_WIDTH-long lines fit into diff --git a/src/overlays/actors/ovl_Bg_Haka_Huta/z_bg_haka_huta.c b/src/overlays/actors/ovl_Bg_Haka_Huta/z_bg_haka_huta.c index b1d38adc988..eebc2e17d5a 100644 --- a/src/overlays/actors/ovl_Bg_Haka_Huta/z_bg_haka_huta.c +++ b/src/overlays/actors/ovl_Bg_Haka_Huta/z_bg_haka_huta.c @@ -200,7 +200,7 @@ void func_8087D720(BgHakaHuta* this, PlayState* play) { this->dyna.actor.world.pos.y = this->dyna.actor.home.pos.y + vec.y; this->dyna.actor.world.pos.z = this->dyna.actor.home.pos.z + vec.z; Matrix_Get(&mtx); - Matrix_MtxFToYXZRotS(&mtx, &this->dyna.actor.shape.rot, 0); + Matrix_MtxFToYXZRot(&mtx, &this->dyna.actor.shape.rot, 0); } void BgHakaHuta_DoNothing(BgHakaHuta* this, PlayState* play) { diff --git a/src/overlays/actors/ovl_Bg_Hidan_Rsekizou/z_bg_hidan_rsekizou.c b/src/overlays/actors/ovl_Bg_Hidan_Rsekizou/z_bg_hidan_rsekizou.c index 5f8ec0ce03e..21626e31316 100644 --- a/src/overlays/actors/ovl_Bg_Hidan_Rsekizou/z_bg_hidan_rsekizou.c +++ b/src/overlays/actors/ovl_Bg_Hidan_Rsekizou/z_bg_hidan_rsekizou.c @@ -235,7 +235,7 @@ void BgHidanRsekizou_Draw(Actor* thisx, PlayState* play) { gSPMatrix(POLY_OPA_DISP++, MATRIX_NEW(play->state.gfxCtx, "../z_bg_hidan_rsekizou.c", 568), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_OPA_DISP++, gFireTempleSpinningFlamethrowerDL); - Matrix_MtxFCopy(&mf, &gMtxFClear); + Matrix_MtxFCopy(&mf, &gIdentityMatrixF); POLY_XLU_DISP = Gfx_SetupDL(POLY_XLU_DISP, SETUPDL_20); diff --git a/src/overlays/actors/ovl_Bg_Hidan_Sekizou/z_bg_hidan_sekizou.c b/src/overlays/actors/ovl_Bg_Hidan_Sekizou/z_bg_hidan_sekizou.c index d07db7eca0d..b23a85f63eb 100644 --- a/src/overlays/actors/ovl_Bg_Hidan_Sekizou/z_bg_hidan_sekizou.c +++ b/src/overlays/actors/ovl_Bg_Hidan_Sekizou/z_bg_hidan_sekizou.c @@ -348,7 +348,7 @@ Gfx* func_8088DC50(PlayState* play, BgHidanSekizou* this, s16 arg2, s16 arg3, Gf } temp_f20 = Math_SinS(arg2); temp_f22 = Math_CosS(arg2); - Matrix_MtxFCopy(&sp68, &gMtxFClear); + Matrix_MtxFCopy(&sp68, &gIdentityMatrixF); temp_v1 = Camera_GetCamDirYaw(GET_ACTIVE_CAM(play)) - arg2; if (ABS(temp_v1) < 0x4000) { diff --git a/src/overlays/actors/ovl_Bg_Hidan_Sima/z_bg_hidan_sima.c b/src/overlays/actors/ovl_Bg_Hidan_Sima/z_bg_hidan_sima.c index 8273e2696b3..1b3aed1dacd 100644 --- a/src/overlays/actors/ovl_Bg_Hidan_Sima/z_bg_hidan_sima.c +++ b/src/overlays/actors/ovl_Bg_Hidan_Sima/z_bg_hidan_sima.c @@ -233,7 +233,7 @@ Gfx* func_8088EB54(PlayState* play, BgHidanSima* this, Gfx* gfx) { f32 sin; s32 pad[2]; - Matrix_MtxFCopy(&mtxF, &gMtxFClear); + Matrix_MtxFCopy(&mtxF, &gIdentityMatrixF); cos = Math_CosS(this->dyna.actor.world.rot.y + 0x8000); sin = Math_SinS(this->dyna.actor.world.rot.y + 0x8000); diff --git a/src/overlays/actors/ovl_Bg_Spot08_Iceblock/z_bg_spot08_iceblock.c b/src/overlays/actors/ovl_Bg_Spot08_Iceblock/z_bg_spot08_iceblock.c index 3ad8321f17d..ed4b62933b4 100644 --- a/src/overlays/actors/ovl_Bg_Spot08_Iceblock/z_bg_spot08_iceblock.c +++ b/src/overlays/actors/ovl_Bg_Spot08_Iceblock/z_bg_spot08_iceblock.c @@ -251,7 +251,7 @@ void BgSpot08Iceblock_Roll(BgSpot08Iceblock* this, PlayState* play) { MTXMODE_NEW); Matrix_RotateY(BINANG_TO_RAD(this->dyna.actor.shape.rot.y), MTXMODE_APPLY); Matrix_Get(&mtx); - Matrix_MtxFToYXZRotS(&mtx, &this->dyna.actor.shape.rot, 0); + Matrix_MtxFToYXZRot(&mtx, &this->dyna.actor.shape.rot, 0); } void BgSpot08Iceblock_SpawnTwinFloe(BgSpot08Iceblock* this, PlayState* play) { diff --git a/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c b/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c index 6ba94dbed53..7694deafcbf 100644 --- a/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c +++ b/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c @@ -1920,7 +1920,7 @@ void BossFd_DrawBody(PlayState* play, BossFd* this) { this->bodyFallApart[i] = 2; Matrix_MultVec3f(&spF0, &spE4); Matrix_Get(&spFC); - Matrix_MtxFToYXZRotS(&spFC, &spDC, 0); + Matrix_MtxFToYXZRot(&spFC, &spDC, 0); bones = (EnVbBall*)Actor_SpawnAsChild(&play->actorCtx, &this->actor, play, ACTOR_EN_VB_BALL, spE4.x, spE4.y, spE4.z, spDC.x, spDC.y, spDC.z, i + 200); diff --git a/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c b/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c index bdbf0fcf035..3cd8dd7642e 100644 --- a/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c +++ b/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c @@ -2078,7 +2078,7 @@ void BossGoma_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* r this->deadLimbsState[limbIndex] = 2; Matrix_MultVec3f(&zero, &childPos); Matrix_Get(&mtx); - Matrix_MtxFToYXZRotS(&mtx, &childRot, 0); + Matrix_MtxFToYXZRot(&mtx, &childRot, 0); // These are the pieces of Gohma as it falls apart. It appears to use the same actor as the baby gohmas. babyGohma = (EnGoma*)Actor_SpawnAsChild(&play->actorCtx, &this->actor, play, ACTOR_EN_GOMA, childPos.x, childPos.y, childPos.z, childRot.x, childRot.y, childRot.z, diff --git a/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c b/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c index 94021d0ee1c..541063ed219 100644 --- a/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c +++ b/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c @@ -2556,7 +2556,7 @@ void BossMo_DrawTentacle(BossMo* this, PlayState* play) { Matrix_MultVec3f(&sp8C, &this->grabPosRot.pos); Matrix_RotateX(-35 * M_PI / 64, MTXMODE_APPLY); Matrix_Get(&sp98); - Matrix_MtxFToYXZRotS(&sp98, &sp84, 0); + Matrix_MtxFToYXZRot(&sp98, &sp84, 0); this->grabPosRot.rot.x = sp84.x; this->grabPosRot.rot.y = sp84.y; this->grabPosRot.rot.z = sp84.z; diff --git a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c index 43722451508..bf80a8fbd15 100644 --- a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c +++ b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c @@ -1110,7 +1110,7 @@ void BossTw_ShootBeam(BossTw* this, PlayState* play) { this->beamShootState = 1; Sfx_PlaySfxAtPos(&player->actor.projectedPos, NA_SE_IT_SHIELD_REFLECT_MG); - Matrix_MtxFToYXZRotS(&player->shieldMf, &sp128, 0); + Matrix_MtxFToYXZRot(&player->shieldMf, &sp128, 0); sp128.y += 0x8000; sp128.x = -sp128.x; this->magicDir.x = sp128.x; @@ -1216,7 +1216,7 @@ void BossTw_ShootBeam(BossTw* this, PlayState* play) { if (this->beamShootState == 1) { if (this->csState1 == 0) { - Matrix_MtxFToYXZRotS(&player->shieldMf, &sp128, 0); + Matrix_MtxFToYXZRot(&player->shieldMf, &sp128, 0); sp128.y += 0x8000; sp128.x = -sp128.x; Math_ApproachS(&this->magicDir.x, sp128.x, 5, 0x2000); @@ -3955,7 +3955,7 @@ void BossTw_BlastFire(BossTw* this, PlayState* play) { this->actor.world.pos = player2->bodyPartsPos[PLAYER_BODYPART_R_HAND]; this->actor.world.pos.y = -2000.0f; - Matrix_MtxFToYXZRotS(&player2->shieldMf, &blastDir, 0); + Matrix_MtxFToYXZRot(&player2->shieldMf, &blastDir, 0); blastDir.x = -blastDir.x; blastDir.y += 0x8000; Math_ApproachS(&this->magicDir.x, blastDir.x, 0xA, 0x800); @@ -4144,7 +4144,7 @@ void BossTw_BlastIce(BossTw* this, PlayState* play) { this->actor.world.pos = player2->bodyPartsPos[PLAYER_BODYPART_R_HAND]; this->actor.world.pos.y = -2000.0f; - Matrix_MtxFToYXZRotS(&player2->shieldMf, &reflDir, 0); + Matrix_MtxFToYXZRot(&player2->shieldMf, &reflDir, 0); reflDir.x = -reflDir.x; reflDir.y += 0x8000; Math_ApproachS(&this->magicDir.x, reflDir.x, 0xA, 0x800); @@ -4370,7 +4370,7 @@ s32 BossTw_BlastShieldCheck(BossTw* this, PlayState* play) { if ((sShieldIceCharge >= 3) || (sShieldFireCharge >= 3)) { this->timers[0] = 80; this->csState1 = 10; - Matrix_MtxFToYXZRotS(&player->shieldMf, &this->magicDir, 0); + Matrix_MtxFToYXZRot(&player->shieldMf, &this->magicDir, 0); this->magicDir.y += 0x8000; this->magicDir.x = -this->magicDir.x; D_8094C86F = 8; diff --git a/src/overlays/actors/ovl_Boss_Va/z_boss_va.c b/src/overlays/actors/ovl_Boss_Va/z_boss_va.c index 49a3b69f638..a255b4bdbdb 100644 --- a/src/overlays/actors/ovl_Boss_Va/z_boss_va.c +++ b/src/overlays/actors/ovl_Boss_Va/z_boss_va.c @@ -3018,7 +3018,7 @@ s32 BossVa_ZapperOverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, V case 7: Matrix_Translate(pos->x, pos->y, pos->z, MTXMODE_APPLY); Matrix_Get(&zapperMtx); - Matrix_MtxFToZYXRotS(&zapperMtx, &sZapperRot, false); + Matrix_MtxFToZYXRot(&zapperMtx, &sZapperRot, false); Matrix_RotateX(BINANG_TO_RAD(-sZapperRot.x), MTXMODE_APPLY); Matrix_RotateY(BINANG_TO_RAD(-sZapperRot.y), MTXMODE_APPLY); Matrix_RotateZ(BINANG_TO_RAD(-sZapperRot.z), MTXMODE_APPLY); diff --git a/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c b/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c index a0b95d22003..9d945c97302 100644 --- a/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c +++ b/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c @@ -187,7 +187,7 @@ void EnBomChu_UpdateFloorPoly(EnBomChu* this, CollisionPoly* floorPoly, PlayStat mf.yz = this->axisForwards.y; mf.zz = this->axisForwards.z; - Matrix_MtxFToYXZRotS(&mf, &this->actor.world.rot, 0); + Matrix_MtxFToYXZRot(&mf, &this->actor.world.rot, 0); // A hack for preventing bombchus from sticking to ledges. // The visual rotation reverts the sign inversion (shape.rot.x = -world.rot.x). diff --git a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c index 23df3261698..63fcc81dc93 100644 --- a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c +++ b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c @@ -481,7 +481,7 @@ void EnGoroiwa_UpdateRotation(EnGoroiwa* this, PlayState* play) { Matrix_RotateX(BINANG_TO_RAD(this->actor.shape.rot.x), MTXMODE_APPLY); Matrix_RotateZ(BINANG_TO_RAD(this->actor.shape.rot.z), MTXMODE_APPLY); Matrix_Get(&mtx); - Matrix_MtxFToYXZRotS(&mtx, &this->actor.shape.rot, 0); + Matrix_MtxFToYXZRot(&mtx, &this->actor.shape.rot, 0); } void EnGoroiwa_NextWaypoint(EnGoroiwa* this, PlayState* play) { diff --git a/src/overlays/actors/ovl_En_Honotrap/z_en_honotrap.c b/src/overlays/actors/ovl_En_Honotrap/z_en_honotrap.c index 8e3a20b2690..63f9bad041e 100644 --- a/src/overlays/actors/ovl_En_Honotrap/z_en_honotrap.c +++ b/src/overlays/actors/ovl_En_Honotrap/z_en_honotrap.c @@ -424,7 +424,7 @@ void EnHonotrap_FlameChase(EnHonotrap* this, PlayState* play) { Player* player = GET_PLAYER(play); Vec3s shieldRot; - Matrix_MtxFToYXZRotS(&player->shieldMf, &shieldRot, false); + Matrix_MtxFToYXZRot(&player->shieldMf, &shieldRot, false); this->actor.world.rot.y = ((shieldRot.y * 2) - this->actor.world.rot.y) + 0x8000; EnHonotrap_SetupFlameVanish(this); } else if (this->collider.cyl.base.atFlags & AT_HIT) { diff --git a/src/overlays/actors/ovl_En_Horse_Normal/z_en_horse_normal.c b/src/overlays/actors/ovl_En_Horse_Normal/z_en_horse_normal.c index 443dcf15c30..96b5d6e49a2 100644 --- a/src/overlays/actors/ovl_En_Horse_Normal/z_en_horse_normal.c +++ b/src/overlays/actors/ovl_En_Horse_Normal/z_en_horse_normal.c @@ -706,7 +706,7 @@ void EnHorseNormal_Draw(Actor* thisx, PlayState* play2) { if (mtx == NULL) { return; } - gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_OPA_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPMatrix(POLY_OPA_DISP++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); func_800A63CC(&this->actor, play, &this->skin, NULL, NULL, true, 0, SKIN_DRAW_FLAG_CUSTOM_TRANSFORMS | SKIN_DRAW_FLAG_CUSTOM_MATRIX); diff --git a/src/overlays/actors/ovl_En_Mag/z_en_mag.c b/src/overlays/actors/ovl_En_Mag/z_en_mag.c index e32b01b4e55..6280e1870fc 100644 --- a/src/overlays/actors/ovl_En_Mag/z_en_mag.c +++ b/src/overlays/actors/ovl_En_Mag/z_en_mag.c @@ -5,6 +5,7 @@ */ #include "z_en_mag.h" +#include "gfxalloc.h" #include "assets/objects/object_mag/object_mag.h" #define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_5) diff --git a/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c b/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c index 1d05b78c354..8370fe14657 100644 --- a/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c +++ b/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c @@ -121,7 +121,7 @@ void func_80ABBBA8(EnNutsball* this, PlayState* play) { this->collider.base.atFlags |= AT_TYPE_PLAYER; this->collider.elem.atDmgInfo.dmgFlags = DMG_DEKU_STICK; - Matrix_MtxFToYXZRotS(&player->shieldMf, &sp4C, 0); + Matrix_MtxFToYXZRot(&player->shieldMf, &sp4C, 0); this->actor.world.rot.y = sp4C.y + 0x8000; this->timer = 30; return; diff --git a/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c b/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c index 3b4bbb26fc6..425c172983b 100644 --- a/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c +++ b/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c @@ -491,7 +491,7 @@ void EnOkuta_ProjectileFly(EnOkuta* this, PlayState* play) { this->collider.base.atFlags &= ~(AT_HIT | AT_BOUNCED | AT_TYPE_ENEMY); this->collider.base.atFlags |= AT_TYPE_PLAYER; this->collider.elem.atDmgInfo.dmgFlags = DMG_DEKU_STICK; - Matrix_MtxFToYXZRotS(&player->shieldMf, &shieldRot, 0); + Matrix_MtxFToYXZRot(&player->shieldMf, &shieldRot, 0); this->actor.world.rot.y = shieldRot.y + 0x8000; this->timer = 30; } else { diff --git a/src/overlays/actors/ovl_En_Sda/z_en_sda.c b/src/overlays/actors/ovl_En_Sda/z_en_sda.c index 7a3b1c81fd8..7564db3c55a 100644 --- a/src/overlays/actors/ovl_En_Sda/z_en_sda.c +++ b/src/overlays/actors/ovl_En_Sda/z_en_sda.c @@ -281,7 +281,7 @@ void func_80AF95C4(EnSda* this, u8* shadowTexture, Player* player, PlayState* pl } PRINTF("SDA CONT 3\n"); if (this->actor.params != 1) { - Matrix_MtxFToYXZRotS(&player->shieldMf, &sp178, false); + Matrix_MtxFToYXZRot(&player->shieldMf, &sp178, false); sp178.y += (KREG(87) << 0xF) + 0x8000; sp178.x *= (KREG(88) - 1); Matrix_Mult(&player->shieldMf, MTXMODE_NEW); diff --git a/src/overlays/actors/ovl_En_Sw/z_en_sw.c b/src/overlays/actors/ovl_En_Sw/z_en_sw.c index 6ffffd208c9..b99e86690f9 100644 --- a/src/overlays/actors/ovl_En_Sw/z_en_sw.c +++ b/src/overlays/actors/ovl_En_Sw/z_en_sw.c @@ -110,7 +110,7 @@ s32 func_80B0BE20(EnSw* this, CollisionPoly* poly) { this->unk_3D8.yw = 0.0f; this->unk_3D8.zw = 0.0f; this->unk_3D8.ww = 1.0f; - Matrix_MtxFToYXZRotS(&this->unk_3D8, &this->actor.world.rot, 0); + Matrix_MtxFToYXZRot(&this->unk_3D8, &this->actor.world.rot, 0); //! @bug: Does not return. } @@ -429,7 +429,7 @@ s32 func_80B0CCF4(EnSw* this, f32* arg1) { sp2C.yw = 0.0f; sp2C.zw = 0.0f; sp2C.ww = 1.0f; - Matrix_MtxFToYXZRotS(&sp2C, &this->actor.world.rot, 0); + Matrix_MtxFToYXZRot(&sp2C, &this->actor.world.rot, 0); return true; } diff --git a/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c b/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c index e3b0c516bcb..9189e038050 100644 --- a/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c +++ b/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c @@ -463,7 +463,7 @@ s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Push(); Matrix_Translate(362.0f, -133.0f, 0.0f, MTXMODE_APPLY); Matrix_Get(&sp34); - Matrix_MtxFToYXZRotS(&sp34, &sp2C, 0); + Matrix_MtxFToYXZRot(&sp34, &sp2C, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B4EE38(this, sp2C.y, 0); func_80B4F230(this, sp2C.x, 1); @@ -473,7 +473,7 @@ s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-188.0f, -184.0f, 0.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp74[0], "../z_en_zl2.c", 1056); Matrix_Get(&sp34); - Matrix_MtxFToYXZRotS(&sp34, &sp2C, 0); + Matrix_MtxFToYXZRot(&sp34, &sp2C, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B4EE38(this, sp2C.y, 3); func_80B4F230(this, sp2C.x, 4); @@ -482,7 +482,7 @@ s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-410.0f, -184.0f, 0.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp74[1], "../z_en_zl2.c", 1100); Matrix_Get(&sp34); - Matrix_MtxFToYXZRotS(&sp34, &sp2C, 0); + Matrix_MtxFToYXZRot(&sp34, &sp2C, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B4EE38(this, sp2C.y, 6); func_80B4F230(this, sp2C.x, 7); @@ -494,7 +494,7 @@ s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Push(); Matrix_Translate(467.0f, 265.0f, 389.0f, MTXMODE_APPLY); Matrix_Get(&sp34); - Matrix_MtxFToYXZRotS(&sp34, &sp2C, 0); + Matrix_MtxFToYXZRot(&sp34, &sp2C, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B4EE38(this, sp2C.y, 9); func_80B4F230(this, sp2C.x, 10); @@ -504,7 +504,7 @@ s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-427.0f, -1.0f, -3.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp74[3], "../z_en_zl2.c", 1145); Matrix_Get(&sp34); - Matrix_MtxFToYXZRotS(&sp34, &sp2C, 0); + Matrix_MtxFToYXZRot(&sp34, &sp2C, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B4EE38(this, sp2C.y, 12); func_80B4F230(this, sp2C.x, 13); @@ -517,7 +517,7 @@ s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Push(); Matrix_Translate(467.0f, 265.0f, -389.0f, MTXMODE_APPLY); Matrix_Get(&sp34); - Matrix_MtxFToYXZRotS(&sp34, &sp2C, 0); + Matrix_MtxFToYXZRot(&sp34, &sp2C, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B4EE38(this, sp2C.y, 15); func_80B4F230(this, sp2C.x, 16); @@ -527,7 +527,7 @@ s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-427.0f, -1.0f, 3.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp74[5], "../z_en_zl2.c", 1189); Matrix_Get(&sp34); - Matrix_MtxFToYXZRotS(&sp34, &sp2C, 0); + Matrix_MtxFToYXZRot(&sp34, &sp2C, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B4EE38(this, sp2C.y, 18); func_80B4F230(this, sp2C.x, 19); diff --git a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c index cdc701bdd5b..20d26c49003 100644 --- a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c +++ b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c @@ -621,7 +621,7 @@ s32 func_80B5458C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Push(); Matrix_Translate(362.0f, -133.0f, 0.0f, MTXMODE_APPLY); Matrix_Get(&sp38); - Matrix_MtxFToYXZRotS(&sp38, &sp30, 0); + Matrix_MtxFToYXZRot(&sp38, &sp30, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B53980(this, sp30.y, 0); func_80B54360(this, sp30.x, 1); @@ -631,7 +631,7 @@ s32 func_80B5458C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-188.0f, -184.0f, 0.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp78[0], "../z_en_zl3.c", 1490); Matrix_Get(&sp38); - Matrix_MtxFToYXZRotS(&sp38, &sp30, 0); + Matrix_MtxFToYXZRot(&sp38, &sp30, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B53980(this, sp30.y, 3); } @@ -639,7 +639,7 @@ s32 func_80B5458C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-410.0f, -184.0f, 0.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp78[1], "../z_en_zl3.c", 1534); Matrix_Get(&sp38); - Matrix_MtxFToYXZRotS(&sp38, &sp30, 0); + Matrix_MtxFToYXZRot(&sp38, &sp30, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B54360(this, sp30.x, 7); } @@ -650,7 +650,7 @@ s32 func_80B5458C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Push(); Matrix_Translate(467.0f, 265.0f, 389.0f, MTXMODE_APPLY); Matrix_Get(&sp38); - Matrix_MtxFToYXZRotS(&sp38, &sp30, 0); + Matrix_MtxFToYXZRot(&sp38, &sp30, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B53980(this, sp30.y, 9); func_80B54360(this, sp30.x, 10); @@ -660,7 +660,7 @@ s32 func_80B5458C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-427.0f, -1.0f, -3.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp78[3], "../z_en_zl3.c", 1579); Matrix_Get(&sp38); - Matrix_MtxFToYXZRotS(&sp38, &sp30, 0); + Matrix_MtxFToYXZRot(&sp38, &sp30, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B53980(this, sp30.y, 12); func_80B54360(this, sp30.x, 13); @@ -673,7 +673,7 @@ s32 func_80B5458C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Push(); Matrix_Translate(467.0f, 265.0f, -389.0f, MTXMODE_APPLY); Matrix_Get(&sp38); - Matrix_MtxFToYXZRotS(&sp38, &sp30, 0); + Matrix_MtxFToYXZRot(&sp38, &sp30, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B53980(this, sp30.y, 15); func_80B54360(this, sp30.x, 16); @@ -683,7 +683,7 @@ s32 func_80B5458C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s Matrix_Translate(-427.0f, -1.0f, 3.0f, MTXMODE_APPLY); MATRIX_TO_MTX(&sp78[5], "../z_en_zl3.c", 1623); Matrix_Get(&sp38); - Matrix_MtxFToYXZRotS(&sp38, &sp30, 0); + Matrix_MtxFToYXZRot(&sp38, &sp30, 0); if (!FrameAdvance_IsEnabled(play)) { func_80B53980(this, sp30.y, 18); func_80B54360(this, sp30.x, 19); diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index 79001ca47c7..daa4c8a68c0 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 198 +#pragma increment_block_number 215 #define FLAGS ACTOR_FLAG_4 @@ -1683,7 +1683,7 @@ void Fishing_DrawLureHook(PlayState* play, Vec3f* pos, Vec3f* refPos, u8 hookInd Matrix_MultVec3f(&sZeroVec, &effect->pos); Matrix_Get(&mf); - Matrix_MtxFToYXZRotS(&mf, &sEffOwnersHatRot, 0); + Matrix_MtxFToYXZRot(&mf, &sEffOwnersHatRot, 0); sIsOwnersHatSunk = false; sIsOwnersHatHooked = false; diff --git a/src/overlays/effects/ovl_Effect_Ss_Bomb/z_eff_ss_bomb.c b/src/overlays/effects/ovl_Effect_Ss_Bomb/z_eff_ss_bomb.c index 5edefefc222..88b339d1b6a 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Bomb/z_eff_ss_bomb.c +++ b/src/overlays/effects/ovl_Effect_Ss_Bomb/z_eff_ss_bomb.c @@ -67,7 +67,7 @@ void EffectSsBomb_Draw(PlayState* play, u32 index, EffectSs* this) { SkinMatrix_MtxFMtxFMult(&mfTrans, &play->billboardMtxF, &mfTransBillboard); SkinMatrix_MtxFMtxFMult(&mfTransBillboard, &mfScale, &mfResult); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &mfResult); diff --git a/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c b/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c index 002cda25396..ed5bf0ac2c1 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c +++ b/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c @@ -87,7 +87,7 @@ void EffectSsDeadDs_Draw(PlayState* play, u32 index, EffectSs* this) { } } - Matrix_MtxFToZYXRotS(&mf, &rpy, 0); + Matrix_MtxFToZYXRot(&mf, &rpy, 0); this->rRoll = rpy.x; this->rPitch = rpy.y; this->rYaw = rpy.z; diff --git a/src/overlays/effects/ovl_Effect_Ss_Dust/z_eff_ss_dust.c b/src/overlays/effects/ovl_Effect_Ss_Dust/z_eff_ss_dust.c index 62dfc4472d4..1fe1027e6e6 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Dust/z_eff_ss_dust.c +++ b/src/overlays/effects/ovl_Effect_Ss_Dust/z_eff_ss_dust.c @@ -96,7 +96,7 @@ void EffectSsDust_Draw(PlayState* play, u32 index, EffectSs* this) { SkinMatrix_SetScale(&mfScale, scale, scale, 1.0f); SkinMatrix_MtxFMtxFMult(&mfTrans, &play->billboardMtxF, &mfTransBillboard); SkinMatrix_MtxFMtxFMult(&mfTransBillboard, &mfScale, &mfResult); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &mfResult); diff --git a/src/overlays/effects/ovl_Effect_Ss_HitMark/z_eff_ss_hitmark.c b/src/overlays/effects/ovl_Effect_Ss_HitMark/z_eff_ss_hitmark.c index 87e1ab51944..8a5c53c3ed2 100644 --- a/src/overlays/effects/ovl_Effect_Ss_HitMark/z_eff_ss_hitmark.c +++ b/src/overlays/effects/ovl_Effect_Ss_HitMark/z_eff_ss_hitmark.c @@ -86,7 +86,7 @@ void EffectSsHitMark_Draw(PlayState* play, u32 index, EffectSs* this) { SkinMatrix_SetScale(&mfScale, scale, scale, 1.0f); SkinMatrix_MtxFMtxFMult(&mfTrans, &play->billboardMtxF, &mfTransBillboard); SkinMatrix_MtxFMtxFMult(&mfTransBillboard, &mfScale, &mfResult); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &mfResult); diff --git a/src/overlays/effects/ovl_Effect_Ss_KiraKira/z_eff_ss_kirakira.c b/src/overlays/effects/ovl_Effect_Ss_KiraKira/z_eff_ss_kirakira.c index 09f9e791799..7acbb04b9fa 100644 --- a/src/overlays/effects/ovl_Effect_Ss_KiraKira/z_eff_ss_kirakira.c +++ b/src/overlays/effects/ovl_Effect_Ss_KiraKira/z_eff_ss_kirakira.c @@ -97,7 +97,7 @@ void EffectSsKiraKira_Draw(PlayState* play, u32 index, EffectSs* this) { SkinMatrix_MtxFMtxFMult(&mfTrans, &play->billboardMtxF, &mfTransBillboard); SkinMatrix_MtxFMtxFMult(&mfTransBillboard, &mfRotY, &mfTransBillboardRotY); SkinMatrix_MtxFMtxFMult(&mfTransBillboardRotY, &mfScale, &mfResult); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &mfResult); diff --git a/src/overlays/effects/ovl_Effect_Ss_Lightning/z_eff_ss_lightning.c b/src/overlays/effects/ovl_Effect_Ss_Lightning/z_eff_ss_lightning.c index 14c5389e42a..c9be8797acd 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Lightning/z_eff_ss_lightning.c +++ b/src/overlays/effects/ovl_Effect_Ss_Lightning/z_eff_ss_lightning.c @@ -100,7 +100,7 @@ void EffectSsLightning_Draw(PlayState* play, u32 index, EffectSs* this) { SkinMatrix_MtxFMtxFMult(&mfTransBillboard, &mfRotate, &mfTransBillboardRotate); SkinMatrix_MtxFMtxFMult(&mfTransBillboardRotate, &mfScale, &mfResult); - gSPMatrix(POLY_XLU_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, &gIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &mfResult); diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c index bdd17f01193..4eb85c14824 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c @@ -1,4 +1,5 @@ #include "z_kaleido_scope.h" +#include "gfxalloc.h" #include "assets/textures/parameter_static/parameter_static.h" // Positions of each input section in the editor diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c index 2e9f652f362..46fb78cb00e 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c @@ -1,4 +1,5 @@ #include "z_kaleido_scope.h" +#include "gfxalloc.h" #include "assets/textures/icon_item_static/icon_item_static.h" #include "assets/textures/icon_item_24_static/icon_item_24_static.h" #if OOT_NTSC diff --git a/tools/namefixer.py b/tools/namefixer.py index 150d094c44e..3b0bf270234 100755 --- a/tools/namefixer.py +++ b/tools/namefixer.py @@ -252,8 +252,10 @@ "actorCtx.unk_00": "actorCtx.freezeFlashTimer", "func_800339B8": "Actor_TestFloorInDirection", "Matrix_Reverse": "Matrix_Transpose", - "func_800D20CC": "Matrix_MtxFToYXZRotS", - "func_800D2264": "Matrix_MtxFToZYXRotS", + "func_800D20CC": "Matrix_MtxFToYXZRot", + "func_800D2264": "Matrix_MtxFToZYXRot", + "Matrix_MtxFToYXZRotS": "Matrix_MtxFToYXZRot", + "Matrix_MtxFToZYXRotS": "Matrix_MtxFToZYXRot", "func_800D23FC": "Matrix_RotateAxis", "PLAYER": ("GET_PLAYER(play)", {"ignore": (-1, '"PLAYER"')}), # ignore "PLAYER" in sSfxBankNames "ACTIVE_CAM": "GET_ACTIVE_CAM(play)", From 170d8174a791d1ff44dec3c9379f3d7faa3e1693 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 24 Jun 2024 22:04:31 -0400 Subject: [PATCH 4/9] format --- src/code/sys_matrix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index 6a5fff02a09..52a8e404d78 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -821,7 +821,7 @@ void Matrix_MtxFToYXZRot(MtxF* src, Vec3s* dest, s32 nonUniformScale) { temp += SQ(temp2); // temp = xx^2+zx^2+yx^2 == 1 for a rotation matrix temp = sqrtf(temp); - temp = temp2 / temp; // yx in normalised column + temp = temp2 / temp; // yx in normalised column temp2 = src->xy; temp2 *= temp2; @@ -830,7 +830,7 @@ void Matrix_MtxFToYXZRot(MtxF* src, Vec3s* dest, s32 nonUniformScale) { temp2 += SQ(temp3); // temp2 = xy^2+zy^2+yy^2 == 1 for a rotation matrix temp2 = sqrtf(temp2); - temp2 = temp3 / temp2; // yy in normalised column + temp2 = temp3 / temp2; // yy in normalised column // for a rotation matrix, temp == yx and temp2 == yy which is the same as in the !nonUniformScale branch dest->z = RAD_TO_BINANG(Math_FAtan2F(temp, temp2)); From 25c519ef9896bcd4656e0732d4f086b1d2691df3 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 24 Jun 2024 22:35:58 -0400 Subject: [PATCH 5/9] fix gMtxClear --- tools/ZAPDConfigs/gc-eu-mq-dbg/SymbolMap.txt | 2 +- tools/ZAPDConfigs/gc-eu-mq/SymbolMap.txt | 2 +- tools/ZAPDConfigs/gc-eu/SymbolMap.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/ZAPDConfigs/gc-eu-mq-dbg/SymbolMap.txt b/tools/ZAPDConfigs/gc-eu-mq-dbg/SymbolMap.txt index 99b4bad0a62..54d92b15e15 100644 --- a/tools/ZAPDConfigs/gc-eu-mq-dbg/SymbolMap.txt +++ b/tools/ZAPDConfigs/gc-eu-mq-dbg/SymbolMap.txt @@ -1,2 +1,2 @@ -8012DB20 gMtxClear +8012DB20 gIdentityMtx 80A8E610 sShadowTex diff --git a/tools/ZAPDConfigs/gc-eu-mq/SymbolMap.txt b/tools/ZAPDConfigs/gc-eu-mq/SymbolMap.txt index 70056f6b088..7e1132fc211 100644 --- a/tools/ZAPDConfigs/gc-eu-mq/SymbolMap.txt +++ b/tools/ZAPDConfigs/gc-eu-mq/SymbolMap.txt @@ -1,2 +1,2 @@ -800FBC00 gMtxClear +800FBC00 gIdentityMtx 80A72FA0 sShadowTex diff --git a/tools/ZAPDConfigs/gc-eu/SymbolMap.txt b/tools/ZAPDConfigs/gc-eu/SymbolMap.txt index b523f5646d3..99b8cf8c059 100644 --- a/tools/ZAPDConfigs/gc-eu/SymbolMap.txt +++ b/tools/ZAPDConfigs/gc-eu/SymbolMap.txt @@ -1,2 +1,2 @@ -800FBC20 gMtxClear +800FBC20 gIdentityMtx 80A73020 sShadowTex From 30f29754cbd4130b3e645b7587a27f02ace66dfa Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 24 Jun 2024 23:28:14 -0400 Subject: [PATCH 6/9] simplify graph.h --- include/graph.h | 11 ++--------- src/code/fault.c | 4 ++-- src/code/graph.c | 3 --- src/code/z_kankyo.c | 2 +- src/overlays/actors/ovl_Fishing/z_fishing.c | 2 +- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/graph.h b/include/graph.h index 479db9952e5..bbcae242afe 100644 --- a/include/graph.h +++ b/include/graph.h @@ -3,19 +3,12 @@ #include "ultra64.h" -struct GameState; struct GraphicsContext; -void Graph_InitTHGA(GraphicsContext* gfxCtx); -struct GameStateOverlay* Graph_GetNextGameState(struct GameState* gameState); -void Graph_Init(GraphicsContext* gfxCtx); -void Graph_Destroy(GraphicsContext* gfxCtx); -void Graph_TaskSet00(GraphicsContext* gfxCtx); -void Graph_Update(GraphicsContext* gfxCtx, struct GameState* gameState); void Graph_ThreadEntry(void*); -void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size); -void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size); + #if OOT_DEBUG +void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size); void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line); #endif diff --git a/src/code/fault.c b/src/code/fault.c index 6f70df31041..bddcd3b65ff 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -48,9 +48,9 @@ // just above (the exact upper bound depends on the block numbers assigned to // extern variables declared in headers). #if OOT_DEBUG -#pragma increment_block_number 18 +#pragma increment_block_number 19 #else -#pragma increment_block_number 23 +#pragma increment_block_number 24 #endif void FaultDrawer_Init(void); diff --git a/src/code/graph.c b/src/code/graph.c index 810aae6d7cb..97b75f945b0 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -51,9 +51,6 @@ void Graph_FaultClient(void) { osViSwapBuffer(nextFb); } -// TODO: merge Gfx and GfxMod to make this function's arguments consistent -void UCodeDisas_Disassemble(UCodeDisas*, Gfx*); - void Graph_DisassembleUCode(Gfx* workBuf) { UCodeDisas disassembler; diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 15cf67c8047..14b0c715139 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -11,7 +11,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 84 +#pragma increment_block_number 85 typedef enum { /* 0x00 */ LIGHTNING_BOLT_START, diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index daa4c8a68c0..adcd177f02a 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 215 +#pragma increment_block_number 216 #define FLAGS ACTOR_FLAG_4 From fb65b4b3b8f86415a511aa4ef7b1329ff6fa991c Mon Sep 17 00:00:00 2001 From: mzxrules Date: Sat, 6 Jul 2024 00:48:43 -0400 Subject: [PATCH 7/9] split structs out of gfx.h, document gfxalloc --- include/functions.h | 54 -------- include/gfx.h | 131 +++++++----------- include/gfxalloc.h | 4 +- include/gfxbuffers.h | 11 +- include/graph.h | 34 ++++- include/macros.h | 3 + include/ucode_disas.h | 47 +++++++ src/code/fault.c | 4 +- src/code/flg_set.c | 19 ++- src/code/game.c | 28 ++-- src/code/gfxalloc.c | 37 +++-- src/code/graph.c | 6 +- src/code/ucode_disas.c | 1 + src/code/z_camera.c | 2 +- src/code/z_collision_check.c | 2 +- src/code/z_debug.c | 19 ++- src/code/z_demo.c | 17 ++- src/code/z_kankyo.c | 20 +-- src/code/z_message.c | 28 ++-- src/code/z_play.c | 22 +-- .../actors/ovl_Door_Warp1/z_door_warp1.c | 3 + src/overlays/actors/ovl_En_Mag/z_en_mag.c | 17 ++- .../actors/ovl_En_Torch2/z_en_torch2.c | 2 + src/overlays/actors/ovl_Fishing/z_fishing.c | 2 +- .../actors/ovl_player_actor/z_player.c | 2 +- .../misc/ovl_kaleido_scope/z_kaleido_debug.c | 17 ++- .../misc/ovl_kaleido_scope/z_kaleido_scope.c | 19 ++- 27 files changed, 291 insertions(+), 260 deletions(-) create mode 100644 include/ucode_disas.h diff --git a/include/functions.h b/include/functions.h index 79303fd4b17..f7681e9121d 100644 --- a/include/functions.h +++ b/include/functions.h @@ -982,55 +982,6 @@ u32 Player_InitPauseDrawData(PlayState* play, u8* segment, SkelAnime* skelAnime) void Player_DrawPause(PlayState* play, u8* segment, SkelAnime* skelAnime, Vec3f* pos, Vec3s* rot, f32 scale, s32 sword, s32 tunic, s32 shield, s32 boots); void PreNMI_Init(GameState* thisx); -Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); -Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); -Gfx* Gfx_SetFog2(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); -Gfx* Gfx_SetupDL(Gfx* gfx, u32 i); -Gfx* Gfx_SetupDL_57(Gfx* gfx); -Gfx* Gfx_SetupDL_52NoCD(Gfx* gfx); -void Gfx_SetupDL_57Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_51Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_54Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_26Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_25Xlu2(GraphicsContext* gfxCtx); -void func_80093C80(PlayState* play); -void Gfx_SetupDL_25Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_25Xlu(GraphicsContext* gfxCtx); -Gfx* Gfx_SetupDL_64(Gfx* gfx); -Gfx* Gfx_SetupDL_34(Gfx* gfx); -void Gfx_SetupDL_44Xlu(GraphicsContext* gfxCtx); -void Gfx_SetupDL_36Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_28Opa(GraphicsContext* gfxCtx); -Gfx* Gfx_SetupDL_28(Gfx* gfx); -void Gfx_SetupDL_38Xlu(GraphicsContext* gfxCtx); -void Gfx_SetupDL_4Xlu(GraphicsContext* gfxCtx); -void Gfx_SetupDL_37Opa(GraphicsContext* gfxCtx); -Gfx* Gfx_SetupDL_39(Gfx* gfx); -void Gfx_SetupDL_39Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_39Overlay(GraphicsContext* gfxCtx); -void Gfx_SetupDL_39Ptr(Gfx** gfxP); -void Gfx_SetupDL_40Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_41Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_47Xlu(GraphicsContext* gfxCtx); -Gfx* Gfx_SetupDL_20NoCD(Gfx* gfx); -Gfx* Gfx_SetupDL_66(Gfx* gfx); -Gfx* func_800947AC(Gfx* gfx); -void Gfx_SetupDL_42Opa(GraphicsContext* gfxCtx); -void Gfx_SetupDL_42Overlay(GraphicsContext* gfxCtx); -void Gfx_SetupDL_27Xlu(GraphicsContext* gfxCtx); -void Gfx_SetupDL_60NoCDXlu(GraphicsContext* gfxCtx); -void Gfx_SetupDL_61Xlu(GraphicsContext* gfxCtx); -void Gfx_SetupDL_56Ptr(Gfx** gfxP); -Gfx* Gfx_BranchTexScroll(Gfx** gfxP, u32 x, u32 y, s32 width, s32 height); -Gfx* func_80094E78(GraphicsContext* gfxCtx, u32 x, u32 y); -Gfx* Gfx_TexScroll(GraphicsContext* gfxCtx, u32 x, u32 y, s32 width, s32 height); -Gfx* Gfx_TwoTexScroll(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, - u32 y2, s32 width2, s32 height2); -Gfx* Gfx_TwoTexScrollEnvColor(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, - u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a); -Gfx* Gfx_EnvColor(GraphicsContext* gfxCtx, s32 r, s32 g, s32 b, s32 a); -void Gfx_SetupFrame(GraphicsContext* gfxCtx, u8 r, u8 g, u8 b); -void func_80095974(GraphicsContext* gfxCtx); void func_80095AA0(PlayState* play, Room* room, Input* input, s32 arg3); void Room_DrawBackground2D(Gfx** gfxP, void* tex, void* tlut, u16 width, u16 height, u8 fmt, u8 siz, u16 tlutMode, u16 tlutCount, f32 offsetX, f32 offsetY); @@ -1251,11 +1202,6 @@ void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line void DebugArena_FreeDebug(void* ptr, const char* file, int line); void DebugArena_Display(void); #endif -void UCodeDisas_Init(UCodeDisas*); -void UCodeDisas_Destroy(UCodeDisas*); -void UCodeDisas_Disassemble(UCodeDisas*, Gfx*); -void UCodeDisas_RegisterUCode(UCodeDisas*, s32, UCodeInfo*); -void UCodeDisas_SetCurUCode(UCodeDisas*, void*); Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen); void AudioHeap_DiscardFont(s32 fontId); void AudioHeap_DiscardSequence(s32 seqId); diff --git a/include/gfx.h b/include/gfx.h index a50dd3a196e..070d4380087 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -2,54 +2,9 @@ #define GFX_H #include "ultra64.h" -#include "ultra64/gbi.h" -#include "sched.h" -#include "thga.h" +#include "graph.h" -// Texture memory size, 4 KiB -#define TMEM_SIZE 0x1000 - -typedef struct { - /* 0x00000 */ u16 headMagic; // GFXPOOL_HEAD_MAGIC - /* 0x00008 */ Gfx polyOpaBuffer[0x17E0]; - /* 0x0BF08 */ Gfx polyXluBuffer[0x800]; - /* 0x0FF08 */ Gfx overlayBuffer[0x400]; - /* 0x11F08 */ Gfx workBuffer[0x80]; - /* 0x11308 */ Gfx unusedBuffer[0x20]; - /* 0x12408 */ u16 tailMagic; // GFXPOOL_TAIL_MAGIC -} GfxPool; // size = 0x12410 - -typedef struct GraphicsContext { - /* 0x0000 */ Gfx* polyOpaBuffer; // Pointer to "Zelda 0" - /* 0x0004 */ Gfx* polyXluBuffer; // Pointer to "Zelda 1" - /* 0x0008 */ char unk_008[0x08]; // Unused, could this be pointers to "Zelda 2" / "Zelda 3" - /* 0x0010 */ Gfx* overlayBuffer; // Pointer to "Zelda 4" - /* 0x0014 */ u32 unk_014; - /* 0x0018 */ char unk_018[0x20]; - /* 0x0038 */ OSMesg msgBuff[0x08]; - /* 0x0058 */ OSMesgQueue* schedMsgQueue; - /* 0x005C */ OSMesgQueue queue; - /* 0x0078 */ OSScTask task; - /* 0x00E0 */ char unk_0E0[0xD0]; - /* 0x01B0 */ Gfx* workBuffer; - /* 0x01B4 */ TwoHeadGfxArena work; - /* 0x01C4 */ char unk_01C4[0xC0]; - /* 0x0284 */ OSViMode* viMode; - /* 0x0288 */ char unk_0288[0x20]; // Unused, could this be Zelda 2/3 ? - /* 0x02A8 */ TwoHeadGfxArena overlay; // "Zelda 4" - /* 0x02B8 */ TwoHeadGfxArena polyOpa; // "Zelda 0" - /* 0x02C8 */ TwoHeadGfxArena polyXlu; // "Zelda 1" - /* 0x02D8 */ u32 gfxPoolIdx; - /* 0x02DC */ u16* curFrameBuffer; - /* 0x02E0 */ char unk_2E0[0x04]; - /* 0x02E4 */ u32 viFeatures; - /* 0x02E8 */ s32 fbIdx; - /* 0x02EC */ void (*callback)(struct GraphicsContext*, void*); - /* 0x02F0 */ void* callbackParam; - /* 0x02F4 */ f32 xScale; - /* 0x02F8 */ f32 yScale; - /* 0x02FC */ char unk_2FC[0x04]; -} GraphicsContext; // size = 0x300 +struct PlayState; typedef enum { /* 0 */ SETUPDL_0, @@ -126,39 +81,55 @@ typedef enum { /* 71 */ SETUPDL_MAX } SetupDL; -#define UCODE_NULL 0 -#define UCODE_F3DZEX 1 -#define UCODE_UNK 2 -#define UCODE_S2DEX 3 - -typedef struct { - /* 0x00 */ u32 type; - /* 0x04 */ void* ptr; -} UCodeInfo; // size = 0x8 -typedef struct { - /* 0x00 */ uintptr_t segments[NUM_SEGMENTS]; - /* 0x40 */ Gfx* dlStack[18]; - /* 0x88 */ s32 dlDepth; - /* 0x8C */ u32 dlCnt; - /* 0x90 */ u32 vtxCnt; - /* 0x94 */ u32 spvtxCnt; - /* 0x98 */ u32 tri1Cnt; - /* 0x9C */ u32 tri2Cnt; - /* 0xA0 */ u32 quadCnt; - /* 0xA4 */ u32 lineCnt; - /* 0xA8 */ u32 loaducodeCnt; - /* 0xAC */ u32 pipeSyncRequired; - /* 0xB0 */ u32 tileSyncRequired; - /* 0xB4 */ u32 loadSyncRequired; - /* 0xB8 */ u32 syncErr; - /* 0xBC */ s32 enableLog; - /* 0xC0 */ s32 ucodeType; - /* 0xC4 */ s32 ucodeInfoCount; - /* 0xC8 */ UCodeInfo* ucodeInfo; - /* 0xCC */ u32 modeH; - /* 0xD0 */ u32 modeL; - /* 0xD4 */ u32 geometryMode; -} UCodeDisas; // size = 0xD8 +Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); +Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); +Gfx* Gfx_SetFog2(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far); +Gfx* Gfx_SetupDL(Gfx* gfx, u32 i); +Gfx* Gfx_SetupDL_57(Gfx* gfx); +Gfx* Gfx_SetupDL_52NoCD(Gfx* gfx); +void Gfx_SetupDL_57Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_51Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_54Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_26Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_25Xlu2(GraphicsContext* gfxCtx); +void func_80093C80(struct PlayState* play); +void Gfx_SetupDL_25Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_25Xlu(GraphicsContext* gfxCtx); +Gfx* Gfx_SetupDL_64(Gfx* gfx); +Gfx* Gfx_SetupDL_34(Gfx* gfx); +void Gfx_SetupDL_44Xlu(GraphicsContext* gfxCtx); +void Gfx_SetupDL_36Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_28Opa(GraphicsContext* gfxCtx); +Gfx* Gfx_SetupDL_28(Gfx* gfx); +void Gfx_SetupDL_38Xlu(GraphicsContext* gfxCtx); +void Gfx_SetupDL_4Xlu(GraphicsContext* gfxCtx); +void Gfx_SetupDL_37Opa(GraphicsContext* gfxCtx); +Gfx* Gfx_SetupDL_39(Gfx* gfx); +void Gfx_SetupDL_39Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_39Overlay(GraphicsContext* gfxCtx); +void Gfx_SetupDL_39Ptr(Gfx** gfxP); +void Gfx_SetupDL_40Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_41Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_47Xlu(GraphicsContext* gfxCtx); +Gfx* Gfx_SetupDL_20NoCD(Gfx* gfx); +Gfx* Gfx_SetupDL_66(Gfx* gfx); +Gfx* func_800947AC(Gfx* gfx); +void Gfx_SetupDL_42Opa(GraphicsContext* gfxCtx); +void Gfx_SetupDL_42Overlay(GraphicsContext* gfxCtx); +void Gfx_SetupDL_27Xlu(GraphicsContext* gfxCtx); +void Gfx_SetupDL_60NoCDXlu(GraphicsContext* gfxCtx); +void Gfx_SetupDL_61Xlu(GraphicsContext* gfxCtx); +void Gfx_SetupDL_56Ptr(Gfx** gfxP); +Gfx* Gfx_BranchTexScroll(Gfx** gfxP, u32 x, u32 y, s32 width, s32 height); +Gfx* func_80094E78(GraphicsContext* gfxCtx, u32 x, u32 y); +Gfx* Gfx_TexScroll(GraphicsContext* gfxCtx, u32 x, u32 y, s32 width, s32 height); +Gfx* Gfx_TwoTexScroll(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, + u32 y2, s32 width2, s32 height2); +Gfx* Gfx_TwoTexScrollEnvColor(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, + u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a); +Gfx* Gfx_EnvColor(GraphicsContext* gfxCtx, s32 r, s32 g, s32 b, s32 a); +void Gfx_SetupFrame(GraphicsContext* gfxCtx, u8 r, u8 g, u8 b); +void func_80095974(GraphicsContext* gfxCtx); #endif diff --git a/include/gfxalloc.h b/include/gfxalloc.h index 158a2a9f589..f269a4f32b5 100644 --- a/include/gfxalloc.h +++ b/include/gfxalloc.h @@ -3,8 +3,8 @@ #include "ultra64.h" -Gfx* Gfx_Open(Gfx* gfx); -Gfx* Gfx_Close(Gfx* gfx, Gfx* dst); +Gfx* Gfx_Open(Gfx* gfxDisp); +Gfx* Gfx_Close(Gfx* gfxDisp, Gfx* gfx); void* Gfx_Alloc(Gfx** gfxP, u32 size); #endif diff --git a/include/gfxbuffers.h b/include/gfxbuffers.h index 48096b4fcf3..38538b9ffcf 100644 --- a/include/gfxbuffers.h +++ b/include/gfxbuffers.h @@ -2,7 +2,16 @@ #define GFXBUFFERS_H #include "ultra64.h" -#include "gfx.h" + +typedef struct { + /* 0x00000 */ u16 headMagic; // GFXPOOL_HEAD_MAGIC + /* 0x00008 */ Gfx polyOpaBuffer[0x17E0]; + /* 0x0BF08 */ Gfx polyXluBuffer[0x800]; + /* 0x0FF08 */ Gfx overlayBuffer[0x400]; + /* 0x11F08 */ Gfx workBuffer[0x80]; + /* 0x11308 */ Gfx unusedBuffer[0x20]; + /* 0x12408 */ u16 tailMagic; // GFXPOOL_TAIL_MAGIC +} GfxPool; // size = 0x12410 extern u64 gGfxSPTaskOutputBuffer[0x3000]; // 0x18000 bytes extern u64 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE / sizeof(u64)]; // 0xC00 bytes diff --git a/include/graph.h b/include/graph.h index bbcae242afe..995408547bc 100644 --- a/include/graph.h +++ b/include/graph.h @@ -2,8 +2,40 @@ #define GRAPH_H #include "ultra64.h" +#include "sched.h" +#include "thga.h" -struct GraphicsContext; +typedef struct GraphicsContext { + /* 0x0000 */ Gfx* polyOpaBuffer; // Pointer to "Zelda 0" + /* 0x0004 */ Gfx* polyXluBuffer; // Pointer to "Zelda 1" + /* 0x0008 */ char unk_008[0x08]; // Unused, could this be pointers to "Zelda 2" / "Zelda 3" + /* 0x0010 */ Gfx* overlayBuffer; // Pointer to "Zelda 4" + /* 0x0014 */ u32 unk_014; + /* 0x0018 */ char unk_018[0x20]; + /* 0x0038 */ OSMesg msgBuff[0x08]; + /* 0x0058 */ OSMesgQueue* schedMsgQueue; + /* 0x005C */ OSMesgQueue queue; + /* 0x0078 */ OSScTask task; + /* 0x00E0 */ char unk_0E0[0xD0]; + /* 0x01B0 */ Gfx* workBuffer; + /* 0x01B4 */ TwoHeadGfxArena work; + /* 0x01C4 */ char unk_01C4[0xC0]; + /* 0x0284 */ OSViMode* viMode; + /* 0x0288 */ char unk_0288[0x20]; // Unused, could this be Zelda 2/3 ? + /* 0x02A8 */ TwoHeadGfxArena overlay; // "Zelda 4" + /* 0x02B8 */ TwoHeadGfxArena polyOpa; // "Zelda 0" + /* 0x02C8 */ TwoHeadGfxArena polyXlu; // "Zelda 1" + /* 0x02D8 */ u32 gfxPoolIdx; + /* 0x02DC */ u16* curFrameBuffer; + /* 0x02E0 */ char unk_2E0[0x04]; + /* 0x02E4 */ u32 viFeatures; + /* 0x02E8 */ s32 fbIdx; + /* 0x02EC */ void (*callback)(struct GraphicsContext*, void*); + /* 0x02F0 */ void* callbackParam; + /* 0x02F4 */ f32 xScale; + /* 0x02F8 */ f32 yScale; + /* 0x02FC */ char unk_2FC[0x04]; +} GraphicsContext; // size = 0x300 void Graph_ThreadEntry(void*); diff --git a/include/macros.h b/include/macros.h index 148065f4f06..2aaf77a92a6 100644 --- a/include/macros.h +++ b/include/macros.h @@ -7,6 +7,9 @@ #define BAD_RETURN(type) void #endif +// Texture memory size, 4 KiB +#define TMEM_SIZE 0x1000 + #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) diff --git a/include/ucode_disas.h b/include/ucode_disas.h new file mode 100644 index 00000000000..7a045a046fd --- /dev/null +++ b/include/ucode_disas.h @@ -0,0 +1,47 @@ +#ifndef UCODE_DISAS_H +#define UCODE_DISAS_H + +#include "ultra64.h" + +#define UCODE_NULL 0 +#define UCODE_F3DZEX 1 +#define UCODE_UNK 2 +#define UCODE_S2DEX 3 + +typedef struct { + /* 0x00 */ u32 type; + /* 0x04 */ void* ptr; +} UCodeInfo; // size = 0x8 + +typedef struct { + /* 0x00 */ uintptr_t segments[NUM_SEGMENTS]; + /* 0x40 */ Gfx* dlStack[18]; + /* 0x88 */ s32 dlDepth; + /* 0x8C */ u32 dlCnt; + /* 0x90 */ u32 vtxCnt; + /* 0x94 */ u32 spvtxCnt; + /* 0x98 */ u32 tri1Cnt; + /* 0x9C */ u32 tri2Cnt; + /* 0xA0 */ u32 quadCnt; + /* 0xA4 */ u32 lineCnt; + /* 0xA8 */ u32 loaducodeCnt; + /* 0xAC */ u32 pipeSyncRequired; + /* 0xB0 */ u32 tileSyncRequired; + /* 0xB4 */ u32 loadSyncRequired; + /* 0xB8 */ u32 syncErr; + /* 0xBC */ s32 enableLog; + /* 0xC0 */ s32 ucodeType; + /* 0xC4 */ s32 ucodeInfoCount; + /* 0xC8 */ UCodeInfo* ucodeInfo; + /* 0xCC */ u32 modeH; + /* 0xD0 */ u32 modeL; + /* 0xD4 */ u32 geometryMode; +} UCodeDisas; // size = 0xD8 + +void UCodeDisas_Init(UCodeDisas*); +void UCodeDisas_Destroy(UCodeDisas*); +void UCodeDisas_Disassemble(UCodeDisas*, Gfx*); +void UCodeDisas_RegisterUCode(UCodeDisas*, s32, UCodeInfo*); +void UCodeDisas_SetCurUCode(UCodeDisas*, void*); + +#endif diff --git a/src/code/fault.c b/src/code/fault.c index bddcd3b65ff..4440b9a5152 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -48,9 +48,9 @@ // just above (the exact upper bound depends on the block numbers assigned to // extern variables declared in headers). #if OOT_DEBUG -#pragma increment_block_number 19 +#pragma increment_block_number 28 #else -#pragma increment_block_number 24 +#pragma increment_block_number 33 #endif void FaultDrawer_Init(void); diff --git a/src/code/flg_set.c b/src/code/flg_set.c index 5d745fd4528..830a0751093 100644 --- a/src/code/flg_set.c +++ b/src/code/flg_set.c @@ -69,8 +69,8 @@ void FlagSet_Update(PlayState* play) { GraphicsContext* gfxCtx = play->state.gfxCtx; Input* input = &play->state.input[0]; - Gfx* gfx; - Gfx* polyOpa; + Gfx* newDisp; + Gfx* lockedGfxDisp; OPEN_DISPS(gfxCtx, "../flg_set.c", 131); @@ -78,12 +78,11 @@ void FlagSet_Update(PlayState* play) { GfxPrint printer; s32 pad; - polyOpa = POLY_OPA_DISP; - gfx = Gfx_Open(polyOpa); - gSPDisplayList(OVERLAY_DISP++, gfx); + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); GfxPrint_Init(&printer); - GfxPrint_Open(&printer, gfx); + GfxPrint_Open(&printer, newDisp); GfxPrint_SetColor(&printer, 250, 50, 50, 255); GfxPrint_SetPos(&printer, 4, 13); GfxPrint_Printf(&printer, entries[entryIdx].name); @@ -168,12 +167,12 @@ void FlagSet_Update(PlayState* play) { timer--; } - gfx = GfxPrint_Close(&printer); + newDisp = GfxPrint_Close(&printer); GfxPrint_Destroy(&printer); - gSPEndDisplayList(gfx++); - Gfx_Close(polyOpa, gfx); - POLY_OPA_DISP = gfx; + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; } if (CHECK_BTN_ALL(input->press.button, BTN_L)) { diff --git a/src/code/game.c b/src/code/game.c index e3c6fb9c9e2..9ad7c598498 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -154,22 +154,22 @@ void GameState_DrawInputDisplay(u16 input, Gfx** gfxP) { #endif void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) { - Gfx* newDList; - Gfx* polyOpaP; + Gfx* newDisp; + Gfx* lockedGfxDisp; OPEN_DISPS(gfxCtx, "../game.c", 746); - newDList = Gfx_Open(polyOpaP = POLY_OPA_DISP); - gSPDisplayList(OVERLAY_DISP++, newDList); + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); if (R_ENABLE_FB_FILTER == 1) { - GameState_SetFBFilter(&newDList); + GameState_SetFBFilter(&newDisp); } #if OOT_DEBUG sLastButtonPressed = gameState->input[0].press.button | gameState->input[0].cur.button; if (R_DISABLE_INPUT_DISPLAY == 0) { - GameState_DrawInputDisplay(sLastButtonPressed, &newDList); + GameState_DrawInputDisplay(sLastButtonPressed, &newDisp); } if (R_ENABLE_AUDIO_DBG & 1) { @@ -177,9 +177,9 @@ void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) { GfxPrint printer; GfxPrint_Init(&printer); - GfxPrint_Open(&printer, newDList); + GfxPrint_Open(&printer, newDisp); AudioDebug_Draw(&printer); - newDList = GfxPrint_Close(&printer); + newDisp = GfxPrint_Close(&printer); GfxPrint_Destroy(&printer); } #endif @@ -195,9 +195,9 @@ void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) { R_ENABLE_ARENA_DBG = 0; } - gSPEndDisplayList(newDList++); - Gfx_Close(polyOpaP, newDList); - POLY_OPA_DISP = newDList; + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; if (1) {} @@ -229,15 +229,15 @@ void GameState_SetFrameBuffer(GraphicsContext* gfxCtx) { void func_800C49F4(GraphicsContext* gfxCtx) { Gfx* newDlist; - Gfx* polyOpaP; + Gfx* lockedGfxDisp; OPEN_DISPS(gfxCtx, "../game.c", 846); - newDlist = Gfx_Open(polyOpaP = POLY_OPA_DISP); + newDlist = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); gSPDisplayList(OVERLAY_DISP++, newDlist); gSPEndDisplayList(newDlist++); - Gfx_Close(polyOpaP, newDlist); + Gfx_Close(lockedGfxDisp, newDlist); POLY_OPA_DISP = newDlist; if (1) {} diff --git a/src/code/gfxalloc.c b/src/code/gfxalloc.c index 3b4d72f0574..ce9ebd35dd8 100644 --- a/src/code/gfxalloc.c +++ b/src/code/gfxalloc.c @@ -1,26 +1,45 @@ +/** + * @file gfxalloc.c + */ #include "gfxalloc.h" #include "alignment.h" -Gfx* Gfx_Open(Gfx* gfx) { - return gfx + 1; +/// @brief Creates a new graphics display list pointer, using the memory reserved by gfxDisp +/// @param gfxDisp is the display list yielding memory. It cannot be written to until Gfx_Close is called. +/// @returns a new graphics display list pointer +/// @note This is used to give WORK_DISP more memory to write instructions without increasing the WORK_DISP buffer size. +Gfx* Gfx_Open(Gfx* gfxDisp) { + // reserve space for a gSPBranchList command when Gfx_Close is called + return gfxDisp + 1; } -Gfx* Gfx_Close(Gfx* gfx, Gfx* dst) { - gSPBranchList(gfx, dst); - return dst; +/// @brief Closes the graphics display list created by Gfx_Open +/// @param gfxDisp is the display list yielding memory. +/// @param gfx is the graphics display list pointer that was created with Gfx_Open +/// @returns gfxDisp's new position +Gfx* Gfx_Close(Gfx* gfxDisp, Gfx* gfx) { + // skips to the end of the display list being closed + gSPBranchList(gfxDisp, gfx); + return gfx; } +/// @brief Allocates a fixed size block of memory for graphics data on a graphics display list +/// @param gfxP is a pointer to a graphics display list +/// @param size number of bytes to reserve +/// @returns start pointer to allocated memory void* Gfx_Alloc(Gfx** gfxP, u32 size) { - u8* ptr; + u8* alloc; Gfx* dst; size = ALIGN8(size); - ptr = (u8*)(*gfxP + 1); + // reserve space for a gSPBranchList command + alloc = (u8*)(*gfxP + 1); - dst = (Gfx*)(ptr + size); + // create a gSPBranchList command that skips over the newly allocated memory + dst = (Gfx*)(alloc + size); gSPBranchList(*gfxP, dst); *gfxP = dst; - return ptr; + return alloc; } diff --git a/src/code/graph.c b/src/code/graph.c index 97b75f945b0..501a48bb55e 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -1,7 +1,8 @@ #include "global.h" -#include "gfx.h" #include "gfxbuffers.h" #include "graph.h" +#include "gfx.h" +#include "ucode_disas.h" #include "terminal.h" #include "z64game.h" #include "z_game_dlftbls.h" @@ -119,6 +120,9 @@ void Graph_InitTHGA(GraphicsContext* gfxCtx) { gfxCtx->overlayBuffer = pool->overlayBuffer; gfxCtx->workBuffer = pool->workBuffer; + //! @bug fbIdx is a signed integer that can overflow into the negatives. When compiled with IDO, the remainder + //! operator will yield -1 for odd negative values of fbIdx (i.e. the same as C99 onwards). This results in an out + //! of bounds array access in SysCfb_GetFbPtr due to the negative index value. gfxCtx->curFrameBuffer = SysCfb_GetFbPtr(gfxCtx->fbIdx % 2); gfxCtx->unk_014 = 0; } diff --git a/src/code/ucode_disas.c b/src/code/ucode_disas.c index de6f7eed4f9..67da8a64122 100644 --- a/src/code/ucode_disas.c +++ b/src/code/ucode_disas.c @@ -1,4 +1,5 @@ #include "global.h" +#include "ucode_disas.h" typedef struct { /* 0x00 */ u32 value; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 4caafe18c95..f253f9cc9bf 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 30 +#pragma increment_block_number 38 s16 Camera_RequestSettingImpl(Camera* camera, s16 requestedSetting, s16 flags); s32 Camera_RequestModeImpl(Camera* camera, s16 requestedMode, u8 forceModeChange); diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index af5d044b157..fdf70f7cffc 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -14,7 +14,7 @@ typedef s32 (*ColChkLineFunc)(PlayState*, CollisionCheckContext*, Collider*, Vec // For retail BSS ordering, the block number of sparkInit in CollisionCheck_BlueBlood // must be between 183 and 255 inclusive. -#pragma increment_block_number 50 +#pragma increment_block_number 55 #if OOT_DEBUG /** diff --git a/src/code/z_debug.c b/src/code/z_debug.c index 60b045f0203..c13c6a35c55 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -279,18 +279,17 @@ void Regs_DrawEditor(GfxPrint* printer) { * Draws the Reg Editor and Debug Camera text on screen */ void Debug_DrawText(GraphicsContext* gfxCtx) { - Gfx* gfx; - Gfx* opaStart; + Gfx* newDisp; + Gfx* lockedGfxDisp; GfxPrint printer; s32 pad; OPEN_DISPS(gfxCtx, "../z_debug.c", 628); GfxPrint_Init(&printer); - opaStart = POLY_OPA_DISP; - gfx = Gfx_Open(POLY_OPA_DISP); - gSPDisplayList(OVERLAY_DISP++, gfx); - GfxPrint_Open(&printer, gfx); + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); + GfxPrint_Open(&printer, newDisp); if ((OREG(0) == 1) || (OREG(0) == 8)) { DebugCamera_DrawScreenText(&printer); @@ -304,10 +303,10 @@ void Debug_DrawText(GraphicsContext* gfxCtx) { sDebugCamTextEntryCount = 0; - gfx = GfxPrint_Close(&printer); - gSPEndDisplayList(gfx++); - Gfx_Close(opaStart, gfx); - POLY_OPA_DISP = gfx; + newDisp = GfxPrint_Close(&printer); + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; if (1) {} diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 7ec2ef8a7df..9786ae11c7b 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -2212,18 +2212,17 @@ void CutsceneHandler_RunScript(PlayState* play, CutsceneContext* csCtx) { if (gSaveContext.save.cutsceneIndex >= 0xFFF0) { #if OOT_DEBUG if (BREG(0) != 0) { - Gfx* displayList; - Gfx* prevDisplayList; + Gfx* newDisp; + Gfx* lockedGfxDisp; OPEN_DISPS(play->state.gfxCtx, "../z_demo.c", 4101); - prevDisplayList = POLY_OPA_DISP; - displayList = Gfx_Open(POLY_OPA_DISP); - gSPDisplayList(OVERLAY_DISP++, displayList); - Cutscene_DrawDebugInfo(play, &displayList, csCtx); - gSPEndDisplayList(displayList++); - Gfx_Close(prevDisplayList, displayList); - POLY_OPA_DISP = displayList; + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); + Cutscene_DrawDebugInfo(play, &newDisp, csCtx); + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; if (1) {} CLOSE_DISPS(play->state.gfxCtx, "../z_demo.c", 4108); diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 14b0c715139..cc1e2036542 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -11,7 +11,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 85 +#pragma increment_block_number 94 typedef enum { /* 0x00 */ LIGHTNING_BOLT_START, @@ -979,18 +979,18 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex #if OOT_DEBUG if (R_ENABLE_ARENA_DBG != 0 || CREG(2) != 0) { - Gfx* displayList; - Gfx* prevDisplayList; + Gfx* newDisp; + Gfx* lockedGfxDisp; OPEN_DISPS(play->state.gfxCtx, "../z_kankyo.c", 1682); - prevDisplayList = POLY_OPA_DISP; - displayList = Gfx_Open(POLY_OPA_DISP); - gSPDisplayList(OVERLAY_DISP++, displayList); - Environment_PrintDebugInfo(play, &displayList); - gSPEndDisplayList(displayList++); - Gfx_Close(prevDisplayList, displayList); - POLY_OPA_DISP = displayList; + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); + Environment_PrintDebugInfo(play, &newDisp); + + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; if (1) {} CLOSE_DISPS(play->state.gfxCtx, "../z_kankyo.c", 1690); } diff --git a/src/code/z_message.c b/src/code/z_message.c index a027d8dce08..1a0121d20dd 100644 --- a/src/code/z_message.c +++ b/src/code/z_message.c @@ -3077,8 +3077,8 @@ void Message_DrawDebugText(PlayState* play, Gfx** p) { #endif void Message_Draw(PlayState* play) { - Gfx* plusOne; - Gfx* polyOpaP; + Gfx* newDisp; + Gfx* lockedGfxDisp; #if OOT_DEBUG s16 watchVar; @@ -3090,22 +3090,22 @@ void Message_Draw(PlayState* play) { watchVar = gSaveContext.save.info.scarecrowLongSongSet; Message_DrawDebugVariableChanged(&watchVar, play->state.gfxCtx); if (BREG(0) != 0 && play->msgCtx.textId != 0) { - plusOne = Gfx_Open(polyOpaP = POLY_OPA_DISP); - gSPDisplayList(OVERLAY_DISP++, plusOne); - Message_DrawDebugText(play, &plusOne); - gSPEndDisplayList(plusOne++); - Gfx_Close(polyOpaP, plusOne); - POLY_OPA_DISP = plusOne; + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); + Message_DrawDebugText(play, &newDisp); + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; } if (1) {} #endif - plusOne = Gfx_Open(polyOpaP = POLY_OPA_DISP); - gSPDisplayList(OVERLAY_DISP++, plusOne); - Message_DrawMain(play, &plusOne); - gSPEndDisplayList(plusOne++); - Gfx_Close(polyOpaP, plusOne); - POLY_OPA_DISP = plusOne; + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); + Message_DrawMain(play, &newDisp); + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; CLOSE_DISPS(play->state.gfxCtx, "../z_message_PAL.c", 3582); } diff --git a/src/code/z_play.c b/src/code/z_play.c index cb3de6c72ba..705372bffea 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -1116,11 +1116,11 @@ void Play_Draw(PlayState* this) { gSPSegment(POLY_OPA_DISP++, 0x01, this->billboardMtx); if (!OOT_DEBUG || (R_HREG_MODE != HREG_MODE_PLAY) || R_PLAY_DRAW_COVER_ELEMENTS) { - Gfx* gfxP; - Gfx* sp1CC = POLY_OPA_DISP; + Gfx* newDisp; + Gfx* lockedGfxDisp; - gfxP = Gfx_Open(sp1CC); - gSPDisplayList(OVERLAY_DISP++, gfxP); + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); if ((this->transitionMode == TRANS_MODE_INSTANCE_RUNNING) || (this->transitionMode == TRANS_MODE_INSTANCE_WAIT) || (this->transitionCtx.transitionType >= 56)) { @@ -1131,20 +1131,20 @@ void Play_Draw(PlayState* this) { SET_FULLSCREEN_VIEWPORT(&view); - View_ApplyTo(&view, VIEW_ALL, &gfxP); - this->transitionCtx.draw(&this->transitionCtx.instanceData, &gfxP); + View_ApplyTo(&view, VIEW_ALL, &newDisp); + this->transitionCtx.draw(&this->transitionCtx.instanceData, &newDisp); } - TransitionFade_Draw(&this->transitionFadeFlash, &gfxP); + TransitionFade_Draw(&this->transitionFadeFlash, &newDisp); if (gVisMonoColor.a > 0) { gPlayVisMono.vis.primColor.rgba = gVisMonoColor.rgba; - VisMono_Draw(&gPlayVisMono, &gfxP); + VisMono_Draw(&gPlayVisMono, &newDisp); } - gSPEndDisplayList(gfxP++); - Gfx_Close(sp1CC, gfxP); - POLY_OPA_DISP = gfxP; + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; } if (gTransitionTileState == TRANS_TILE_READY) { diff --git a/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c b/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c index dbddf179951..0e6e615351a 100644 --- a/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c +++ b/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c @@ -51,6 +51,9 @@ static InitChainEntry sInitChain[] = { ICHAIN_F32(uncullZoneDownward, 4000, ICHAIN_STOP), }; +// For retail BSS ordering, the block number of sWarpTimerTarget must be lower than sRutoWarpSubCamId. +#pragma increment_block_number 30 + static s16 sWarpTimerTarget; void DoorWarp1_SetupAction(DoorWarp1* this, DoorWarp1ActionFunc actionFunc) { diff --git a/src/overlays/actors/ovl_En_Mag/z_en_mag.c b/src/overlays/actors/ovl_En_Mag/z_en_mag.c index 6280e1870fc..1f162922a14 100644 --- a/src/overlays/actors/ovl_En_Mag/z_en_mag.c +++ b/src/overlays/actors/ovl_En_Mag/z_en_mag.c @@ -610,20 +610,19 @@ void EnMag_DrawInner(Actor* thisx, PlayState* play, Gfx** gfxP) { void EnMag_Draw(Actor* thisx, PlayState* play) { s32 pad; - Gfx* gfx; - Gfx* gfxRef; + Gfx* newDisp; + Gfx* lockedGfxDisp; OPEN_DISPS(play->state.gfxCtx, "../z_en_mag.c", 1151); - gfxRef = POLY_OPA_DISP; - gfx = Gfx_Open(gfxRef); - gSPDisplayList(OVERLAY_DISP++, gfx); + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); - EnMag_DrawInner(thisx, play, &gfx); + EnMag_DrawInner(thisx, play, &newDisp); - gSPEndDisplayList(gfx++); - Gfx_Close(gfxRef, gfx); - POLY_OPA_DISP = gfx; + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; CLOSE_DISPS(play->state.gfxCtx, "../z_en_mag.c", 1161); } diff --git a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c index 8c3c1c90a89..f7a5545751f 100644 --- a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c +++ b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c @@ -40,6 +40,8 @@ static s32 sHoldShieldTimer = 0; static u8 sZTargetFlag = false; static u8 sDeathFlag = false; +#pragma increment_block_number 30 + static Input sInput; static u8 sSwordJumpState; static Vec3f sSpawnPoint; diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index adcd177f02a..020b360ebe8 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 216 +#pragma increment_block_number 225 #define FLAGS ACTOR_FLAG_4 diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index c397d8ea5fb..56334f43832 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -359,7 +359,7 @@ void Player_Action_CsAction(Player* this, PlayState* play); // TODO: There's probably a way to do this with less padding by spreading the variables out and moving // data around. It would be easier if we had more options for controlling BSS ordering in debug. -#pragma increment_block_number 30 +#pragma increment_block_number 36 static s32 D_80858AA0; diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c index 4eb85c14824..b66ecb13c63 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_debug.c @@ -99,8 +99,8 @@ void KaleidoScope_DrawDebugEditor(PlayState* play) { static s32 heldDBtnTimer = 0; PauseContext* pauseCtx = &play->pauseCtx; Input* input = &play->state.input[0]; - Gfx* gfx; - Gfx* gfxRef; + Gfx* newDisp; + Gfx* lockedGfxDisp; s16 spD8[4]; s16 slot; s16 i; @@ -124,15 +124,14 @@ void KaleidoScope_DrawDebugEditor(PlayState* play) { gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0); - gfxRef = POLY_OPA_DISP; - gfx = Gfx_Open(gfxRef); - gSPDisplayList(OVERLAY_DISP++, gfx); + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, newDisp); - KaleidoScope_DrawDebugEditorText(&gfx); + KaleidoScope_DrawDebugEditorText(&newDisp); - gSPEndDisplayList(gfx++); - Gfx_Close(gfxRef, gfx); - POLY_OPA_DISP = gfx; + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; gDPPipeSync(POLY_OPA_DISP++); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 0, 0, 255); diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c index 46fb78cb00e..d336f45419b 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c @@ -438,25 +438,24 @@ static PreRender sPlayerPreRender; static void* sPreRenderCvg; void KaleidoScope_SetupPlayerPreRender(PlayState* play) { - Gfx* gfx; - Gfx* gfxRef; + Gfx* newDisp; + Gfx* lockedGfxDisp; void* fbuf; fbuf = play->state.gfxCtx->curFrameBuffer; OPEN_DISPS(play->state.gfxCtx, "../z_kaleido_scope_PAL.c", 496); - gfxRef = POLY_OPA_DISP; - gfx = Gfx_Open(gfxRef); - gSPDisplayList(WORK_DISP++, gfx); + newDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP); + gSPDisplayList(WORK_DISP++, newDisp); PreRender_SetValues(&sPlayerPreRender, PAUSE_EQUIP_PLAYER_WIDTH, PAUSE_EQUIP_PLAYER_HEIGHT, fbuf, NULL); - PreRender_SaveFramebuffer(&sPlayerPreRender, &gfx); - PreRender_DrawCoverage(&sPlayerPreRender, &gfx); + PreRender_SaveFramebuffer(&sPlayerPreRender, &newDisp); + PreRender_DrawCoverage(&sPlayerPreRender, &newDisp); - gSPEndDisplayList(gfx++); - Gfx_Close(gfxRef, gfx); - POLY_OPA_DISP = gfx; + gSPEndDisplayList(newDisp++); + Gfx_Close(lockedGfxDisp, newDisp); + POLY_OPA_DISP = newDisp; R_GRAPH_TASKSET00_FLAGS |= 1; From 40c74b46ad798aee6aae49f25bea539b3a1a1f1f Mon Sep 17 00:00:00 2001 From: mzxrules Date: Tue, 9 Jul 2024 20:43:22 -0400 Subject: [PATCH 8/9] merge main into graph_split --- src/boot/idle.c | 2 +- src/code/fault.c | 2 +- src/code/main.c | 2 +- src/code/z_bgcheck.c | 4 ++++ src/code/z_camera.c | 2 +- src/code/z_collision_check.c | 2 +- src/code/z_common_data.c | 2 +- src/code/z_demo.c | 2 +- src/code/z_kaleido_scope_call.c | 2 +- src/code/z_kankyo.c | 2 +- src/code/z_play.c | 4 ++++ src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c | 2 +- src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c | 4 ++++ src/overlays/actors/ovl_Fishing/z_fishing.c | 2 +- src/overlays/actors/ovl_player_actor/z_player.c | 2 +- 15 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/boot/idle.c b/src/boot/idle.c index 3d62994c477..b74ec895d2e 100644 --- a/src/boot/idle.c +++ b/src/boot/idle.c @@ -4,7 +4,7 @@ // For retail BSS ordering, the block number of sMainThread must be 0 or // just above (the exact upper bound depends on the block numbers assigned to // extern variables declared in headers). -#pragma increment_block_number 60 +#pragma increment_block_number 79 OSThread sMainThread; STACK(sMainStack, 0x900); diff --git a/src/code/fault.c b/src/code/fault.c index 4440b9a5152..236cd835ee1 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -50,7 +50,7 @@ #if OOT_DEBUG #pragma increment_block_number 28 #else -#pragma increment_block_number 33 +#pragma increment_block_number 52 #endif void FaultDrawer_Init(void); diff --git a/src/code/main.c b/src/code/main.c index ca72ab0e55e..71e3c87c6dc 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -9,7 +9,7 @@ u32 gSystemHeapSize = 0; // For retail BSS ordering, the block number of gIrqMgr must be greater than the // the block numbers assigned to extern variables above (declared in variables.h). -#pragma increment_block_number 220 +#pragma increment_block_number 250 PreNmiBuff* gAppNmiBufferPtr; Scheduler gScheduler; diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 4906fc556e6..19b3f74c259 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -1,6 +1,10 @@ #include "global.h" #include "terminal.h" +// For retail BSS ordering, the block number of polyVerts in CollisionPoly_CheckYIntersectApprox1 +// must be 0 or just above. +#pragma increment_block_number 30 + u16 DynaSSNodeList_GetNextNodeIdx(DynaSSNodeList* nodeList); void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* sector); s32 BgCheck_PosInStaticBoundingBox(CollisionContext* colCtx, Vec3f* pos); diff --git a/src/code/z_camera.c b/src/code/z_camera.c index f253f9cc9bf..c6e8c8d3dc0 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 38 +#pragma increment_block_number 60 s16 Camera_RequestSettingImpl(Camera* camera, s16 requestedSetting, s16 flags); s32 Camera_RequestModeImpl(Camera* camera, s16 requestedMode, u8 forceModeChange); diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index fdf70f7cffc..5cd00034d98 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -14,7 +14,7 @@ typedef s32 (*ColChkLineFunc)(PlayState*, CollisionCheckContext*, Collider*, Vec // For retail BSS ordering, the block number of sparkInit in CollisionCheck_BlueBlood // must be between 183 and 255 inclusive. -#pragma increment_block_number 55 +#pragma increment_block_number 80 #if OOT_DEBUG /** diff --git a/src/code/z_common_data.c b/src/code/z_common_data.c index 47aecd9e6aa..611c232c08b 100644 --- a/src/code/z_common_data.c +++ b/src/code/z_common_data.c @@ -3,7 +3,7 @@ // For retail BSS ordering, the block number of D_8015FA88 must be 0 or // just above (the exact upper bound depends on the block numbers assigned to // extern variables declared in headers). -#pragma increment_block_number 60 +#pragma increment_block_number 79 ALIGNED(16) SaveContext gSaveContext; u32 D_8015FA88; diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 9786ae11c7b..b9f3874a585 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -123,7 +123,7 @@ u16 gCamAtPointAppliedFrame; // For retail BSS ordering, the block number of sReturnToCamId must be greater // than that of gCamAtPointAppliedFrame (declared in variables.h). -#pragma increment_block_number 180 +#pragma increment_block_number 10 // Cam ID to return to when a scripted cutscene is finished s16 sReturnToCamId; diff --git a/src/code/z_kaleido_scope_call.c b/src/code/z_kaleido_scope_call.c index 7b53b8521aa..4cdd70fd64d 100644 --- a/src/code/z_kaleido_scope_call.c +++ b/src/code/z_kaleido_scope_call.c @@ -4,7 +4,7 @@ // For retail BSS ordering, the block number of sKaleidoScopeUpdateFunc must be 0 or // just above (the exact upper bound depends on the block numbers assigned to // extern variables declared in headers). -#pragma increment_block_number 60 +#pragma increment_block_number 90 void (*sKaleidoScopeUpdateFunc)(PlayState* play); void (*sKaleidoScopeDrawFunc)(PlayState* play); diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index cc1e2036542..f28b4599499 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -11,7 +11,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 94 +#pragma increment_block_number 124 typedef enum { /* 0x00 */ LIGHTNING_BOLT_START, diff --git a/src/code/z_play.c b/src/code/z_play.c index 705372bffea..629e17d3070 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -14,6 +14,10 @@ Color_RGBA8_u32 gVisMonoColor; FaultClient D_801614B8; #endif +// For retail BSS ordering, the block number of sTransitionFillTimer must be greater than the +// the block numbers assigned to extern variables above (declared in variables.h). +#pragma increment_block_number 30 + s16 sTransitionFillTimer; #if OOT_DEBUG diff --git a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c index 0d5b9736182..f03faf9b8aa 100644 --- a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c +++ b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c @@ -104,7 +104,7 @@ static Vec3f sZeroVec = { 0.0f, 0.0f, 0.0f }; // TODO: There's probably a way to do this with less padding by spreading the variables out and moving // data around. It would be easier if we had more options for controlling BSS ordering in debug. -#pragma increment_block_number 50 +#pragma increment_block_number 80 static EnGanonMant* sCape; diff --git a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c index bf80a8fbd15..08f134155ed 100644 --- a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c +++ b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c @@ -206,6 +206,10 @@ static InitChainEntry sInitChain[] = { ICHAIN_F32(targetArrowOffset, 0, ICHAIN_STOP), }; +// For retail BSS ordering, the block number of sEnvType must be between +// 0 and 187 inclusive. +#pragma increment_block_number 30 + static s8 sEnvType; static u8 sGroundBlastType; static BossTw* sKotakePtr; diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index 020b360ebe8..e5e0a9b9ab7 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 225 +#pragma increment_block_number 243 #define FLAGS ACTOR_FLAG_4 diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 56334f43832..ee59e73af9d 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -359,7 +359,7 @@ void Player_Action_CsAction(Player* this, PlayState* play); // TODO: There's probably a way to do this with less padding by spreading the variables out and moving // data around. It would be easier if we had more options for controlling BSS ordering in debug. -#pragma increment_block_number 36 +#pragma increment_block_number 66 static s32 D_80858AA0; From c1e57dcdda0bfddbb5daa84940be635de74d7e75 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Tue, 9 Jul 2024 21:55:10 -0400 Subject: [PATCH 9/9] fix bss --- src/code/sys_math3d.c | 2 +- src/code/z_collision_check.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 2d9a00545c7..197d2f178eb 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -7,7 +7,7 @@ // For retail BSS ordering, the block number of cbf in Math3D_CylVsCylOverlapCenterDist // must be 0. -#pragma increment_block_number 112 +#pragma increment_block_number 109 s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 5cd00034d98..c41c0ac3caf 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -2315,7 +2315,7 @@ void CollisionCheck_ATQuadVsACCyl(PlayState* play, CollisionCheckContext* colChk static s8 sBssDummy3; static s8 sBssDummy4; static s8 sBssDummy5; -static s8 sBssDummy6; +// static s8 sBssDummy6; #endif void CollisionCheck_ATTrisVsACTris(PlayState* play, CollisionCheckContext* colChkCtx, Collider* atCol,