diff --git a/include/audiomgr.h b/include/audiomgr.h index 23a6ef7bfc..c9780d3779 100644 --- a/include/audiomgr.h +++ b/include/audiomgr.h @@ -7,7 +7,7 @@ #include "scheduler.h" #include "z64audio.h" -typedef struct { +typedef struct AudioMgr { /* 0x000 */ IrqMgr* irqMgr; /* 0x004 */ Scheduler* sched; /* 0x008 */ OSScTask audioTask; diff --git a/include/idle.h b/include/idle.h index 86efabe90c..f00c0a4c0d 100644 --- a/include/idle.h +++ b/include/idle.h @@ -2,9 +2,7 @@ #define IDLE_H #include "ultra64.h" -#include "irqmgr.h" -extern IrqMgr gIrqMgr; extern OSMesgQueue gPiMgrCmdQueue; extern OSViMode gViConfigMode; extern u8 gViConfigModeType; diff --git a/include/irqmgr.h b/include/irqmgr.h index 576f390bf5..d6c4643272 100644 --- a/include/irqmgr.h +++ b/include/irqmgr.h @@ -15,7 +15,7 @@ typedef struct IrqMgrClient { /* 0x4 */ OSMesgQueue* queue; } IrqMgrClient; // size = 0x8 -typedef struct { +typedef struct IrqMgr { /* 0x000 */ OSScMsg retraceMsg; /* 0x020 */ OSScMsg prenmiMsg; /* 0x040 */ OSScMsg nmiMsg; @@ -29,6 +29,8 @@ typedef struct { /* 0x278 */ OSTime retraceTime; } IrqMgr; // size = 0x280 +extern IrqMgr gIrqMgr; + extern vs32 gIrqMgrResetStatus; extern volatile OSTime sIrqMgrResetTime; extern volatile OSTime gIrqMgrRetraceTime; diff --git a/include/main.h b/include/main.h index e6f8f9f552..b52f34c8f0 100644 --- a/include/main.h +++ b/include/main.h @@ -3,22 +3,12 @@ #include "ultra64.h" -#include "stdint.h" - -#include "scheduler.h" -#include "padmgr.h" - extern s32 gScreenWidth; extern s32 gScreenHeight; extern size_t gSystemHeapSize; -extern uintptr_t gSegments[NUM_SEGMENTS]; -extern Scheduler gScheduler; extern OSThread gGraphThread; -extern PadMgr gPadMgr; void Main(void* arg); -#define SEGMENTED_TO_K0(addr) (void*)((gSegments[SEGMENT_NUMBER(addr)] + K0BASE) + SEGMENT_OFFSET(addr)) - #endif diff --git a/include/padmgr.h b/include/padmgr.h index 4bd78d9012..a012f1450e 100644 --- a/include/padmgr.h +++ b/include/padmgr.h @@ -23,7 +23,7 @@ typedef enum { /* 2 */ CONT_PAK_OTHER } ControllerPakType; -typedef struct { +typedef struct PadMgr { /* 0x000 */ u8 validCtrlrsMask; /* 0x004 */ void (*rumbleRetraceCallback)(void*); /* 0x008 */ void* rumbleRetraceArg; @@ -88,4 +88,6 @@ void PadMgr_RumbleSetSingle(s32 port, s32 enable); void PadMgr_RumbleSet(u8 enable[MAXCONTROLLERS]); s32 PadMgr_ControllerHasRumblePak(s32 port); +extern PadMgr gPadMgr; + #endif diff --git a/include/scheduler.h b/include/scheduler.h index 096f2e9b61..ebdf69dc3e 100644 --- a/include/scheduler.h +++ b/include/scheduler.h @@ -28,7 +28,7 @@ typedef struct { /* 0x18 */ f32 yScale; } CfbInfo; // size = 0x1C -typedef struct { +typedef struct Scheduler { /* 0x000 */ OSMesgQueue interruptQueue; /* 0x018 */ OSMesg interruptMsgBuf[64]; /* 0x118 */ OSMesgQueue cmdQueue; @@ -58,4 +58,6 @@ void Sched_SendGfxCancelMsg(Scheduler* sched); void Sched_Init(Scheduler* sched, void* stack, OSPri pri, u8 viModeType, UNK_TYPE arg4, IrqMgr* irqMgr); +extern Scheduler gScheduler; + #endif diff --git a/include/segmented_address.h b/include/segmented_address.h new file mode 100644 index 0000000000..faa6f26496 --- /dev/null +++ b/include/segmented_address.h @@ -0,0 +1,12 @@ +#ifndef SEGMENTED_ADDRESS_H +#define SEGMENTED_ADDRESS_H + +#include "ultra64.h" + +#include "stdint.h" + +extern uintptr_t gSegments[NUM_SEGMENTS]; + +#define SEGMENTED_TO_K0(addr) (void*)((gSegments[SEGMENT_NUMBER(addr)] + K0BASE) + SEGMENT_OFFSET(addr)) + +#endif diff --git a/include/z64.h b/include/z64.h index 3efb583387..f801fecdc9 100644 --- a/include/z64.h +++ b/include/z64.h @@ -23,6 +23,7 @@ #include "padutils.h" #include "regs.h" #include "scheduler.h" +#include "segmented_address.h" #include "sequence.h" #include "seqcmd.h" #include "sfx.h" diff --git a/include/z64player.h b/include/z64player.h index 67eda81f29..56e173d2e7 100644 --- a/include/z64player.h +++ b/include/z64player.h @@ -1,6 +1,8 @@ #ifndef Z64PLAYER_H #define Z64PLAYER_H +#include "stdbool.h" + #include "alignment.h" #include "PR/os.h" #include "z64actor.h" diff --git a/src/boot/idle.c b/src/boot/idle.c index 7e96241c2c..3c21386727 100644 --- a/src/boot/idle.c +++ b/src/boot/idle.c @@ -1,6 +1,8 @@ #include "prevent_bss_reordering.h" + +#include "stdbool.h" + #include "buffers.h" -#include "irqmgr.h" #include "main.h" #include "segment_symbols.h" #include "stack.h" @@ -10,7 +12,7 @@ #include "z64thread.h" // Variables are put before most headers as a hacky way to bypass bss reordering -IrqMgr gIrqMgr; +struct IrqMgr gIrqMgr; STACK(sIrqMgrStack, 0x500); StackEntry sIrqMgrStackInfo; OSThread sMainThread; @@ -22,6 +24,7 @@ OSViMode gViConfigMode; u8 gViConfigModeType; #include "idle.h" +#include "irqmgr.h" u8 D_80096B20 = 1; vu8 gViConfigUseBlack = true; diff --git a/src/code/main.c b/src/code/main.c index f45a1dfb20..e2822a9a87 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -1,19 +1,13 @@ -#include "audiomgr.h" -#include "fault.h" -#include "idle.h" -#include "irqmgr.h" -#include "padmgr.h" -#include "scheduler.h" -#include "CIC6105.h" +#include "prevent_bss_reordering.h" +#include "ultra64.h" #include "stack.h" -#include "stackcheck.h" // Variables are put before most headers as a hacky way to bypass bss reordering OSMesgQueue sSerialEventQueue; OSMesg sSerialMsgBuf[1]; u32 gSegments[NUM_SEGMENTS]; -Scheduler gScheduler; -IrqMgrClient sIrqClient; +struct Scheduler gScheduler; +struct IrqMgrClient sIrqClient; OSMesgQueue sIrqMgrMsgQueue; OSMesg sIrqMgrMsgBuf[60]; OSThread gGraphThread; @@ -21,17 +15,28 @@ STACK(sGraphStack, 0x1800); STACK(sSchedStack, 0x600); STACK(sAudioStack, 0x800); STACK(sPadMgrStack, 0x500); -StackEntry sGraphStackInfo; -StackEntry sSchedStackInfo; -StackEntry sAudioStackInfo; -StackEntry sPadMgrStackInfo; -AudioMgr sAudioMgr; +struct StackEntry sGraphStackInfo; +struct StackEntry sSchedStackInfo; +struct StackEntry sAudioStackInfo; +struct StackEntry sPadMgrStackInfo; +struct AudioMgr sAudioMgr; static s32 sBssPad; -PadMgr gPadMgr; +struct PadMgr gPadMgr; #include "main.h" + +#include "audiomgr.h" #include "buffers.h" -#include "global.h" +#include "CIC6105.h" +#include "fault.h" +#include "idle.h" +#include "irqmgr.h" +#include "padmgr.h" +#include "regs.h" +#include "segment_symbols.h" +#include "stack.h" +#include "stackcheck.h" +#include "scheduler.h" #include "sys_initial_check.h" #include "system_heap.h" #include "z64nmi_buff.h" diff --git a/src/code/padmgr.c b/src/code/padmgr.c index f8da69762a..69570d8c47 100644 --- a/src/code/padmgr.c +++ b/src/code/padmgr.c @@ -38,7 +38,7 @@ #include "fault.h" #include "macros.h" -#include "main.h" +#include "scheduler.h" #include "z64math.h" #include "z64voice.h" diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c index d027e913d9..df477db775 100644 --- a/src/code/speed_meter.c +++ b/src/code/speed_meter.c @@ -3,7 +3,6 @@ #include "libc64/malloc.h" #include "gfx.h" -#include "main.h" #include "regs.h" #include "sys_cfb.h" #include "z64game.h" diff --git a/src/code/z_jpeg.c b/src/code/z_jpeg.c index 00cbe135a1..1b66fb8d9f 100644 --- a/src/code/z_jpeg.c +++ b/src/code/z_jpeg.c @@ -1,7 +1,7 @@ #include "z64jpeg.h" #include "stdbool.h" -#include "main.h" +#include "scheduler.h" #include "sys_ucode.h" #include "macros.h" diff --git a/src/code/z_lib.c b/src/code/z_lib.c index 8a494cf76a..e8d95584a7 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -3,7 +3,7 @@ #include "libc64/qrand.h" -#include "main.h" +#include "segmented_address.h" #include "sfx.h" #include "z64game.h" diff --git a/src/code/z_nulltask.c b/src/code/z_nulltask.c index b060e06393..fc65107d5d 100644 --- a/src/code/z_nulltask.c +++ b/src/code/z_nulltask.c @@ -1,7 +1,6 @@ #include "scheduler.h" #include "macros.h" -#include "main.h" /** * Blocks the current thread until all queued scheduler tasks have completed.