diff --git a/include/variables.h b/include/variables.h index 2cf99e391b..b3aa0a6021 100644 --- a/include/variables.h +++ b/include/variables.h @@ -3353,7 +3353,7 @@ extern Arena mainHeap; // extern UNK_TYPE1 D_801F5730; // extern UNK_TYPE1 D_801F57B4; // extern UNK_TYPE1 D_801F5834; -extern s32* gNMIBuffer; +// extern NmiBuff* gNMIBuffer; // extern UNK_TYPE1 D_801F5850; // extern UNK_TYPE1 D_801F58B0; // extern UNK_TYPE1 D_801F59AC; @@ -3440,7 +3440,7 @@ extern u64 lastRenderFrameTimestamp; extern OSMesgQueue siEventCallbackQueue; extern OSMesg siEventCallbackBuffer[1]; extern u32 gSegments[NUM_SEGMENTS]; -extern SchedContext schedContext; +extern SchedContext gSchedContext; extern IrqMgrClient mainIrqmgrCallbackNode; extern OSMesgQueue mainIrqmgrCallbackQueue; extern OSMesg mainIrqCallbackBuffer[60]; diff --git a/include/z64.h b/include/z64.h index d3923d6c88..3d61fe5ea4 100644 --- a/include/z64.h +++ b/include/z64.h @@ -348,6 +348,13 @@ typedef struct { /* 0x14 */ u32 relocations[1]; } OverlayRelocationSection; // size >= 0x18 +typedef struct { + /* 0x00 */ u32 resetting; + /* 0x04 */ u32 resetCount; + /* 0x08 */ OSTime duration; + /* 0x10 */ OSTime resetTime; +} NmiBuff; // size >= 0x18 + typedef struct { /* 0x00 */ s16 intPart[16]; /* 0x20 */ u16 fracPart[16]; diff --git a/spec b/spec index a569dba5fa..18ce776d04 100644 --- a/spec +++ b/spec @@ -523,7 +523,7 @@ beginseg include "build/src/code/z_msgevent.o" include "build/data/code/z_msgevent.data.o" include "build/src/code/z_nmi_buff.o" - include "build/data/code/z_nmi_buff.bss.o" + include "build/src/code/code_8010C1B0.o" include "build/src/code/z_olib.o" pad_text include "build/src/code/z_parameter.o" diff --git a/src/code/code_8010C1B0.c b/src/code/code_8010C1B0.c new file mode 100644 index 0000000000..7141901e2f --- /dev/null +++ b/src/code/code_8010C1B0.c @@ -0,0 +1,20 @@ +#include "global.h" + +// Blocks the current thread until all currently queued scheduler tasks have been completed +void func_8010C1B0(void) { + OSScTask task; + OSMesgQueue queue; + OSMesg msg; + + task.next = NULL; + task.flags = OS_SC_RCP_MASK; + task.msgQ = &queue; + task.msg = NULL; + task.framebuffer = NULL; + task.list.t.type = M_NULTASK; + + osCreateMesgQueue(task.msgQ, &msg, 1); + osSendMesg(&gSchedContext.cmdQ, &task, OS_MESG_BLOCK); + Sched_SendEntryMsg(&gSchedContext); + osRecvMesg(&queue, NULL, OS_MESG_BLOCK); +} \ No newline at end of file diff --git a/src/code/main.c b/src/code/main.c index 75101c8ab5..648536aef1 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -1,3 +1,8 @@ +/** + * This file has unmigrated bss. It is not practical to migrate it until we have a better way of dealing with bss + * reordering than just prevent_bss_reordering.h: there is too much of it to control, and it cannot be split into + * separate files since most of it is at addresses ending in 8. + */ #include "global.h" void Main(void* arg) { @@ -29,18 +34,18 @@ void Main(void* arg) { osCreateMesgQueue(&mainIrqmgrCallbackQueue, mainIrqCallbackBuffer, ARRAY_COUNT(mainIrqCallbackBuffer)); StackCheck_Init(&schedStackEntry, schedStack, schedStack + sizeof(schedStack), 0, 0x100, "sched"); - Sched_Init(&schedContext, schedStack + sizeof(schedStack), Z_PRIORITY_SCHED, D_8009B290, 1, &gIrqMgr); + Sched_Init(&gSchedContext, schedStack + sizeof(schedStack), Z_PRIORITY_SCHED, D_8009B290, 1, &gIrqMgr); CIC6105_AddRomInfoFaultPage(); IrqMgr_AddClient(&gIrqMgr, &mainIrqmgrCallbackNode, &mainIrqmgrCallbackQueue); StackCheck_Init(&audioStackEntry, audioStack, audioStack + sizeof(audioStack), 0, 0x100, "audio"); - AudioMgr_Init(&audioContext, audioStack + sizeof(audioStack), Z_PRIORITY_AUDIOMGR, 0xA, &schedContext, &gIrqMgr); + AudioMgr_Init(&audioContext, audioStack + sizeof(audioStack), Z_PRIORITY_AUDIOMGR, 0xA, &gSchedContext, &gIrqMgr); StackCheck_Init(&padmgrStackEntry, padmgrStack, padmgrStack + sizeof(padmgrStack), 0, 0x100, "padmgr"); Padmgr_Start(&siEventCallbackQueue, &gIrqMgr, 7, Z_PRIORITY_PADMGR, padmgrStack + sizeof(padmgrStack)); - + AudioMgr_Unlock(&audioContext); StackCheck_Init(&graphStackEntry, graphStack, graphStack + sizeof(graphStack), 0, 0x100, "graph"); diff --git a/src/code/z_nmi_buff.c b/src/code/z_nmi_buff.c index a12fa65913..205bd8d0f3 100644 --- a/src/code/z_nmi_buff.c +++ b/src/code/z_nmi_buff.c @@ -1,9 +1,30 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/z_nmi_buff/Nmi_Init.s") +#define COLD_RESET 0 +#define NMI 1 -#pragma GLOBAL_ASM("asm/non_matchings/code/z_nmi_buff/Nmi_SetPrenmiStart.s") +NmiBuff* gNMIBuffer; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_nmi_buff/Nmi_GetPrenmiHasStarted.s") +void Nmi_Init(void) { + gNMIBuffer = (NmiBuff*)osAppNmiBuffer; + gNMIBuffer->resetting = false; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_nmi_buff/func_8010C1B0.s") + if (osResetType == COLD_RESET) { + gNMIBuffer->resetCount = 0; + gNMIBuffer->duration = 0; + } else { + gNMIBuffer->resetCount++; + gNMIBuffer->duration += gNMIBuffer->resetTime; + } + + gNMIBuffer->resetTime = 0; +} + +void Nmi_SetPrenmiStart(void) { + gNMIBuffer->resetting = true; + gNMIBuffer->resetTime = osGetTime(); +} + +u32 Nmi_GetPrenmiHasStarted(void) { + return gNMIBuffer->resetting; +} diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index ed536b3188..a71ca3f090 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -398,6 +398,7 @@ 0x8010A000 : "z_map_exp", 0x8010A760 : "z_msgevent", 0x8010C0C0 : "z_nmi_buff", + 0x8010C1B0 : "code_8010C1B0", 0x8010C230 : "z_olib", 0x8010CB70 : "[PADDING]", 0x8010CB80 : "z_parameter", diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index a7bc541645..4f5da48f71 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -4189,7 +4189,7 @@ 0x801F8160:("siEventCallbackQueue","OSMesgQueue","",0x18), 0x801F8178:("siEventCallbackBuffer","OSMesg","[1]",0x4), 0x801F8180:("gSegments","u32","[16]",0x40), - 0x801F81C0:("schedContext","SchedContext","",0x338), + 0x801F81C0:("gSchedContext","SchedContext","",0x338), 0x801F84F8:("mainIrqmgrCallbackNode","IrqMgrClient","",0x8), 0x801F8500:("mainIrqmgrCallbackQueue","OSMesgQueue","",0x18), 0x801F8518:("mainIrqCallbackBuffer","OSMesg","[60]",0xf0),