From b3eae0e5b7bcc2c5d3c8a1d562f0737d80c7e35c Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Sat, 8 Jul 2023 14:41:25 -0400 Subject: Port OoT's docs for `fault.c` and `fault_drawer.c` (#1199) * fault.h * some docs stealing * fix building * fault_internal.h * pass * finish stealing docs * finish cleanup * format * warning * Update src/boot_O2_g3/fault.c Co-authored-by: Derek Hensley * Update src/boot_O2_g3/fault.c Co-authored-by: Derek Hensley * Update src/boot_O2_g3/fault.c Co-authored-by: Derek Hensley * review Co-authored-by: Derek Hensley * arggggg * arggggg part 2 * STACK * PHYS_TO_K0(0x400000) * format * fix * Instance * format * Neutral reset * variables.h cleanup * bss * frameBuffer * format * Update src/boot_O2_g3/fault.c Co-authored-by: Derek Hensley * review Co-authored-by: Derek Hensley * Update src/boot_O2_g3/fault.c Co-authored-by: Derek Hensley * bss * bss * bss * callback cleanup * fix function declarations * fix again * bss * bss * Update src/overlays/actors/ovl_En_Fishing/z_en_fishing.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update src/boot_O2_g3/fault.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * bss * bss * Update src/boot_O2_g3/fault.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * review * import bss * format * minor cleanup * bss * review * fix * bss * bss * bss * bss * bss * format * a * Z_PRIORITY_FAULT * bss * fix * idle.c bss doesn't want to get fixed :c * review * bss --------- Co-authored-by: Derek Hensley Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> --- src/code/graph.c | 30 ++++++++++++++++++------------ src/code/main.c | 7 ++++--- src/code/padmgr.c | 4 +++- src/code/sched.c | 24 ++++++++++++++---------- src/code/sys_flashrom.c | 1 + src/code/sys_initial_check.c | 3 ++- src/code/sys_matrix.c | 1 + src/code/z_actor.c | 1 + src/code/z_actor_dlftbls.c | 6 ++++-- src/code/z_bgcheck.c | 14 +++++++------- src/code/z_collision_check.c | 1 + src/code/z_demo.c | 1 + src/code/z_kaleido_manager.c | 5 +++-- src/code/z_play.c | 1 + src/code/z_player_lib.c | 1 - 15 files changed, 61 insertions(+), 39 deletions(-) (limited to 'src/code') diff --git a/src/code/graph.c b/src/code/graph.c index 6d4665b39..ce929e6c0 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -1,5 +1,17 @@ -#include "prevent_bss_reordering.h" -#include "global.h" +#include "z64.h" +#include "regs.h" +#include "functions.h" +#include "fault.h" + +// Variables are put before most headers as a hacky way to bypass bss reordering +FaultAddrConvClient sGraphFaultAddrConvClient; +FaultClient sGraphFaultClient; +GfxMasterList* gGfxMasterDL; +CfbInfo sGraphCfbInfos[3]; +OSTime sGraphTaskStartTime; + +#include "variables.h" +#include "macros.h" #include "buffers.h" #include "idle.h" #include "system_malloc.h" @@ -10,12 +22,6 @@ #include "overlays/gamestates/ovl_title/z_title.h" #include "z_title_setup.h" -FaultAddrConvClient sGraphFaultAddrConvClient; -FaultClient sGraphFaultClient; -GfxMasterList* gGfxMasterDL; -CfbInfo sGraphCfbInfos[3]; -OSTime sGraphTaskStartTime; - void Graph_FaultClient(void) { FaultDrawer_DrawText(30, 100, "ShowFrameBuffer PAGE 0/1"); osViSwapBuffer(SysCfb_GetFramebuffer(0)); @@ -93,7 +99,7 @@ GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { return NULL; } -void* Graph_FaultAddrConv(void* address, void* param) { +uintptr_t Graph_FaultAddrConv(uintptr_t address, void* param) { uintptr_t addr = address; GameStateOverlay* gameStateOvl = &gGameStateOverlayTable[0]; size_t ramConv; @@ -112,7 +118,7 @@ void* Graph_FaultAddrConv(void* address, void* param) { } } } - return NULL; + return 0; } void Graph_Init(GraphicsContext* gfxCtx) { @@ -124,7 +130,7 @@ void Graph_Init(GraphicsContext* gfxCtx) { gfxCtx->xScale = gViConfigXScale; gfxCtx->yScale = gViConfigYScale; osCreateMesgQueue(&gfxCtx->queue, gfxCtx->msgBuff, ARRAY_COUNT(gfxCtx->msgBuff)); - Fault_AddClient(&sGraphFaultClient, Graph_FaultClient, NULL, NULL); + Fault_AddClient(&sGraphFaultClient, (void*)Graph_FaultClient, NULL, NULL); Fault_AddAddrConvClient(&sGraphFaultAddrConvClient, Graph_FaultAddrConv, NULL); } @@ -354,7 +360,7 @@ void Graph_ThreadEntry(void* arg) { gGfxSPTaskOutputBufferEndHiRes = (u8*)gGfxSPTaskOutputBufferHiRes + sizeof(*gGfxSPTaskOutputBufferHiRes); SysCfb_Init(); - Fault_SetFB(gWorkBuffer, SCREEN_WIDTH, SCREEN_HEIGHT); + Fault_SetFrameBuffer(gWorkBuffer, SCREEN_WIDTH, SCREEN_HEIGHT); Graph_Init(&gfxCtx); while (nextOvl) { diff --git a/src/code/main.c b/src/code/main.c index f969df70d..7fbb7ccb8 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -1,12 +1,11 @@ #include "audiomgr.h" +#include "fault.h" #include "idle.h" #include "irqmgr.h" #include "padmgr.h" #include "scheduler.h" #include "stack.h" #include "stackcheck.h" -#include "system_heap.h" -#include "z64thread.h" // Variables are put before most headers as a hacky way to bypass bss reordering OSMesgQueue sSerialEventQueue; @@ -32,6 +31,8 @@ PadMgr gPadMgr; #include "main.h" #include "buffers.h" #include "global.h" +#include "system_heap.h" +#include "z64thread.h" s32 gScreenWidth = SCREEN_WIDTH; s32 gScreenHeight = SCREEN_HEIGHT; @@ -47,7 +48,7 @@ void Main(void* arg) { gScreenHeight = SCREEN_HEIGHT; Nmi_Init(); - Fault_Start(); + Fault_Init(); Check_RegionIsSupported(); Check_ExpansionPak(); diff --git a/src/code/padmgr.c b/src/code/padmgr.c index a04a14f57..eb6a811b7 100644 --- a/src/code/padmgr.c +++ b/src/code/padmgr.c @@ -30,9 +30,11 @@ * `osContStartReadData` to receiving the data. By running this on a separate thread to the game state, work can be * done while waiting for this operation to complete. */ + #include "global.h" #include "io/controller.h" #include "ultra64/motor.h" +#include "fault.h" #define PADMGR_RETRACE_MSG (1 << 0) #define PADMGR_PRE_NMI_MSG (1 << 1) @@ -641,7 +643,7 @@ void PadMgr_HandleRetrace(void) { } // Rumble Pak - if (gFaultStruct.msgId != 0) { + if (gFaultMgr.msgId != 0) { // If fault is active, no rumble PadMgr_RumbleStop(); } else if (sPadMgrInstance->rumbleOffTimer > 0) { diff --git a/src/code/sched.c b/src/code/sched.c index fb7a0073c..19e6a6bc9 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -1,15 +1,8 @@ -#include "prevent_bss_reordering.h" -#include "global.h" +#include "fault.h" #include "idle.h" -#include "stackcheck.h" -#include "z64thread.h" - -#define RSP_DONE_MSG 667 -#define RDP_DONE_MSG 668 -#define ENTRY_MSG 670 -#define RDP_AUDIO_CANCEL_MSG 671 -#define RSP_GFX_CANCEL_MSG 672 +#include "z64.h" +// Variables are put before most headers as a hacky way to bypass bss reordering FaultClient sSchedFaultClient; OSTime sRSPGFXStartTime; @@ -20,6 +13,17 @@ OSTime sRDPStartTime; u64* gAudioSPDataPtr; u32 gAudioSPDataSize; +#include "functions.h" +#include "variables.h" +#include "stackcheck.h" +#include "z64thread.h" + +#define RSP_DONE_MSG 667 +#define RDP_DONE_MSG 668 +#define ENTRY_MSG 670 +#define RDP_AUDIO_CANCEL_MSG 671 +#define RSP_GFX_CANCEL_MSG 672 + void Sched_SwapFramebuffer(CfbInfo* cfbInfo) { if (cfbInfo->swapBuffer != NULL) { osViSwapBuffer(cfbInfo->swapBuffer); diff --git a/src/code/sys_flashrom.c b/src/code/sys_flashrom.c index f2424b850..0f4e9f748 100644 --- a/src/code/sys_flashrom.c +++ b/src/code/sys_flashrom.c @@ -1,5 +1,6 @@ #include "prevent_bss_reordering.h" #include "global.h" +#include "fault.h" #include "stack.h" #include "stackcheck.h" #include "system_malloc.h" diff --git a/src/code/sys_initial_check.c b/src/code/sys_initial_check.c index ec61d07b5..3f46a5818 100644 --- a/src/code/sys_initial_check.c +++ b/src/code/sys_initial_check.c @@ -7,6 +7,7 @@ * are DMA'd directly to fixed RAM addresses. */ #include "global.h" +#include "fault.h" #include "misc/locerrmsg/locerrmsg.h" #include "misc/memerrmsg/memerrmsg.h" @@ -23,7 +24,7 @@ // Address with enough room after to load either of the error message image files before the fault screen buffer at the // end of RDRAM -#define CHECK_ERRMSG_STATIC_SEGMENT (u8*)(FAULT_FB_ADDRESS - MAX(SIZEOF_LOCERRMSG, SIZEOF_MEMERRMSG)) +#define CHECK_ERRMSG_STATIC_SEGMENT (u8*)((uintptr_t)FAULT_FB_ADDRESS - MAX(SIZEOF_LOCERRMSG, SIZEOF_MEMERRMSG)) void Check_WriteRGBA16Pixel(u16* buffer, u32 x, u32 y, u32 value) { if (value & RGBA16_PIXEL_OPAQUE) { diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index de8da3def..6269add5f 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -39,6 +39,7 @@ * (APPLY), or to just overwrite it (NEW). */ +#include "prevent_bss_reordering.h" #include "global.h" /* data */ diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 094b36787..35dbc8361 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -4,6 +4,7 @@ */ #include "global.h" +#include "fault.h" #include "loadfragment.h" #include "z64horse.h" #include "z64quake.h" diff --git a/src/code/z_actor_dlftbls.c b/src/code/z_actor_dlftbls.c index 2e2f80a50..012c118fb 100644 --- a/src/code/z_actor_dlftbls.c +++ b/src/code/z_actor_dlftbls.c @@ -1,4 +1,5 @@ #include "global.h" +#include "fault.h" // Init Vars declarations (also used in the table below) #define DEFINE_ACTOR(name, _enumValue, _allocType, _debugName) extern ActorInit name##_InitVars; @@ -60,7 +61,7 @@ void ActorOverlayTable_FaultClient(void* arg0, void* arg1) { } } -void* ActorOverlayTable_FaultAddrConv(void* address, void* param) { +uintptr_t ActorOverlayTable_FaultAddrConv(uintptr_t address, void* param) { uintptr_t addr = address; ActorOverlay* actorOvl = &gActorOverlayTable[0]; size_t ramConv; @@ -79,7 +80,8 @@ void* ActorOverlayTable_FaultAddrConv(void* address, void* param) { } } } - return NULL; + + return 0; } void ActorOverlayTable_Init(void) { diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index f63ff6b01..ab2eca48a 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -1,4 +1,5 @@ #include "global.h" +#include "fault.h" #include "fixed_point.h" #include "vt.h" #include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" @@ -80,9 +81,15 @@ BgSpecialSceneMaxObjects sCustomDynapolyMem[] = { // TODO: All these bss variables are localized to one function and can // likely be made into in-function static bss variables in the future +char D_801ED950[80]; +char D_801ED9A0[80]; + Vec3f D_801ED9F0[3]; // polyVerts Vec3f D_801EDA18[3]; // polyVerts +MtxF sModelToWorldMtxF; Vec3f D_801EDA80[3]; // polyVerts +char D_801EDAA8[80]; +char D_801EDAF8[80]; Vec3f D_801EDB48[3]; // polyVerts #ifndef NON_MATCHING @@ -92,13 +99,6 @@ Sphere16 D_801EDBA8; // sphere; TriNorm D_801EDBB0; // tri; #endif -char D_801ED950[80]; -char D_801ED9A0[80]; - -char D_801EDAA8[80]; -char D_801EDAF8[80]; -MtxF sModelToWorldMtxF; - void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* sector); f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast); s32 BgCheck_SphVsDynaWall(CollisionContext* colCtx, u16 xpFlags, f32* outX, f32* outZ, Vec3f* pos, f32 radius, diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 39b57cbd0..af1f4ad6c 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -1,3 +1,4 @@ +#include "prevent_bss_reordering.h" #include "global.h" #include "z64collision_check.h" diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 262bc0ebc..771e76722 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -1,3 +1,4 @@ +#include "prevent_bss_reordering.h" #include "global.h" #include "z64quake.h" #include "z64rumble.h" diff --git a/src/code/z_kaleido_manager.c b/src/code/z_kaleido_manager.c index a84e74776..e09492d4e 100644 --- a/src/code/z_kaleido_manager.c +++ b/src/code/z_kaleido_manager.c @@ -1,4 +1,5 @@ #include "global.h" +#include "fault.h" #include "loadfragment.h" #define KALEIDO_OVERLAY(name) \ @@ -16,7 +17,7 @@ void* sKaleidoAreaPtr = NULL; KaleidoMgrOverlay* gKaleidoMgrCurOvl = NULL; FaultAddrConvClient sKaleidoMgrFaultAddrConvClient; -void* KaleidoManager_FaultAddrConv(void* address, void* param) { +uintptr_t KaleidoManager_FaultAddrConv(uintptr_t address, void* param) { uintptr_t addr = address; KaleidoMgrOverlay* kaleidoMgrOvl = gKaleidoMgrCurOvl; size_t ramConv; @@ -34,7 +35,7 @@ void* KaleidoManager_FaultAddrConv(void* address, void* param) { } } } - return NULL; + return 0; } void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl) { diff --git a/src/code/z_play.c b/src/code/z_play.c index a97cf9f8e..2965e0e2e 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -1,3 +1,4 @@ +#include "prevent_bss_reordering.h" #include "global.h" #include "buffers.h" #include "idle.h" diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index d87905117..bd8a5b94e 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -3,7 +3,6 @@ * Description: Set of library functions to interact with the Player system */ -#include "prevent_bss_reordering.h" #include "global.h" #include "objects/gameplay_keep/gameplay_keep.h" -- cgit v1.2.3