2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2024-08-28 07:38:42 +00:00
|
|
|
#include "fault.h"
|
2024-09-03 19:30:14 +00:00
|
|
|
#include "stack.h"
|
2022-11-01 23:17:11 +00:00
|
|
|
#include "terminal.h"
|
2024-08-25 14:00:10 +00:00
|
|
|
#include "versions.h"
|
|
|
|
#if PLATFORM_N64
|
|
|
|
#include "cic6105.h"
|
|
|
|
#include "n64dd.h"
|
|
|
|
#endif
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-02-28 00:01:47 +00:00
|
|
|
extern u8 _buffersSegmentEnd[];
|
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 gScreenWidth = SCREEN_WIDTH;
|
|
|
|
s32 gScreenHeight = SCREEN_HEIGHT;
|
2020-03-17 04:31:30 +00:00
|
|
|
u32 gSystemHeapSize = 0;
|
|
|
|
|
2024-09-05 12:08:21 +00:00
|
|
|
#pragma increment_block_number "gc-eu:208 gc-eu-mq:208 gc-jp:208 gc-jp-ce:208 gc-jp-mq:208 gc-us:208 gc-us-mq:208"
|
2024-07-06 19:38:31 +00:00
|
|
|
|
2020-03-20 11:43:51 +00:00
|
|
|
PreNmiBuff* gAppNmiBufferPtr;
|
2022-06-03 19:43:30 +00:00
|
|
|
Scheduler gScheduler;
|
2020-03-17 04:31:30 +00:00
|
|
|
PadMgr gPadMgr;
|
|
|
|
IrqMgr gIrqMgr;
|
2022-10-02 15:38:09 +00:00
|
|
|
uintptr_t gSegments[NUM_SEGMENTS];
|
2020-03-17 04:31:30 +00:00
|
|
|
OSThread sGraphThread;
|
2022-02-06 18:00:01 +00:00
|
|
|
STACK(sGraphStack, 0x1800);
|
|
|
|
STACK(sSchedStack, 0x600);
|
|
|
|
STACK(sAudioStack, 0x800);
|
|
|
|
STACK(sPadMgrStack, 0x500);
|
|
|
|
STACK(sIrqMgrStack, 0x500);
|
2020-03-17 04:31:30 +00:00
|
|
|
StackEntry sGraphStackInfo;
|
|
|
|
StackEntry sSchedStackInfo;
|
|
|
|
StackEntry sAudioStackInfo;
|
|
|
|
StackEntry sPadMgrStackInfo;
|
|
|
|
StackEntry sIrqMgrStackInfo;
|
2020-05-11 00:04:41 +00:00
|
|
|
AudioMgr gAudioMgr;
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesgQueue sSerialEventQueue;
|
|
|
|
OSMesg sSerialMsgBuf[1];
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2021-02-14 00:49:40 +00:00
|
|
|
void Main_LogSystemHeap(void) {
|
2024-01-12 15:38:13 +00:00
|
|
|
PRINTF(VT_FGCOL(GREEN));
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(
|
|
|
|
T("システムヒープサイズ %08x(%dKB) 開始アドレス %08x\n", "System heap size %08x (%dKB) Start address %08x\n"),
|
|
|
|
gSystemHeapSize, gSystemHeapSize / 1024, _buffersSegmentEnd);
|
2024-01-12 15:38:13 +00:00
|
|
|
PRINTF(VT_RST);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2024-01-28 20:46:08 +00:00
|
|
|
#endif
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void Main(void* arg) {
|
2020-03-17 04:31:30 +00:00
|
|
|
IrqMgrClient irqClient;
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesgQueue irqMgrMsgQueue;
|
2020-03-17 04:31:30 +00:00
|
|
|
OSMesg irqMgrMsgBuf[60];
|
2022-10-02 15:38:09 +00:00
|
|
|
uintptr_t systemHeapStart;
|
|
|
|
uintptr_t fb;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("mainproc 実行開始\n", "mainproc Start running\n"));
|
2020-03-17 04:31:30 +00:00
|
|
|
gScreenWidth = SCREEN_WIDTH;
|
|
|
|
gScreenHeight = SCREEN_HEIGHT;
|
2022-04-30 23:03:22 +00:00
|
|
|
gAppNmiBufferPtr = (PreNmiBuff*)osAppNMIBuffer;
|
2020-03-20 11:43:51 +00:00
|
|
|
PreNmiBuff_Init(gAppNmiBufferPtr);
|
2020-10-03 15:22:44 +00:00
|
|
|
Fault_Init();
|
2024-08-25 14:00:10 +00:00
|
|
|
#if PLATFORM_N64
|
2024-09-04 18:56:24 +00:00
|
|
|
func_800AD410();
|
|
|
|
if (D_80121211 != 0) {
|
|
|
|
systemHeapStart = (uintptr_t)&_n64ddSegmentEnd;
|
2024-08-25 14:00:10 +00:00
|
|
|
SysCfb_Init(1);
|
|
|
|
} else {
|
2024-09-04 18:56:24 +00:00
|
|
|
func_800AD488();
|
2024-08-25 14:00:10 +00:00
|
|
|
systemHeapStart = (uintptr_t)_buffersSegmentEnd;
|
|
|
|
SysCfb_Init(0);
|
|
|
|
}
|
|
|
|
#else
|
2020-03-17 04:31:30 +00:00
|
|
|
SysCfb_Init(0);
|
2024-02-28 00:01:47 +00:00
|
|
|
systemHeapStart = (uintptr_t)_buffersSegmentEnd;
|
2024-08-25 14:00:10 +00:00
|
|
|
#endif
|
2022-10-02 15:38:09 +00:00
|
|
|
fb = (uintptr_t)SysCfb_GetFbPtr(0);
|
2022-03-13 23:22:14 +00:00
|
|
|
gSystemHeapSize = fb - systemHeapStart;
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("システムヒープ初期化 %08x-%08x %08x\n", "System heap initalization %08x-%08x %08x\n"), systemHeapStart,
|
|
|
|
fb, gSystemHeapSize);
|
2022-06-16 00:15:44 +00:00
|
|
|
SystemHeap_Init((void*)systemHeapStart, gSystemHeapSize); // initializes the system heap
|
2024-01-29 12:25:58 +00:00
|
|
|
|
2024-01-30 20:19:00 +00:00
|
|
|
#if OOT_DEBUG
|
|
|
|
{
|
2024-01-28 20:46:08 +00:00
|
|
|
void* debugHeapStart;
|
|
|
|
u32 debugHeapSize;
|
|
|
|
|
|
|
|
if (osMemSize >= 0x800000) {
|
|
|
|
debugHeapStart = SysCfb_GetFbEnd();
|
|
|
|
debugHeapSize = PHYS_TO_K0(0x600000) - (uintptr_t)debugHeapStart;
|
|
|
|
} else {
|
|
|
|
debugHeapSize = 0x400;
|
|
|
|
debugHeapStart = SYSTEM_ARENA_MALLOC(debugHeapSize, "../main.c", 565);
|
|
|
|
}
|
2024-01-29 12:25:58 +00:00
|
|
|
|
2024-01-28 20:46:08 +00:00
|
|
|
PRINTF("debug_InitArena(%08x, %08x)\n", debugHeapStart, debugHeapSize);
|
|
|
|
DebugArena_Init(debugHeapStart, debugHeapSize);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2024-01-30 20:19:00 +00:00
|
|
|
#endif
|
2024-01-28 20:46:08 +00:00
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
Regs_Init();
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
R_ENABLE_ARENA_DBG = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&sSerialEventQueue, sSerialMsgBuf, ARRAY_COUNT(sSerialMsgBuf));
|
|
|
|
osSetEventMesg(OS_EVENT_SI, &sSerialEventQueue, NULL);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2020-03-17 04:31:30 +00:00
|
|
|
Main_LogSystemHeap();
|
2024-01-28 20:46:08 +00:00
|
|
|
#endif
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&irqMgrMsgQueue, irqMgrMsgBuf, ARRAY_COUNT(irqMgrMsgBuf));
|
2022-02-06 18:00:01 +00:00
|
|
|
StackCheck_Init(&sIrqMgrStackInfo, sIrqMgrStack, STACK_TOP(sIrqMgrStack), 0, 0x100, "irqmgr");
|
2022-04-09 00:20:23 +00:00
|
|
|
IrqMgr_Init(&gIrqMgr, STACK_TOP(sIrqMgrStack), THREAD_PRI_IRQMGR, 1);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("タスクスケジューラの初期化\n", "Initialize the task scheduler\n"));
|
2022-02-06 18:00:01 +00:00
|
|
|
StackCheck_Init(&sSchedStackInfo, sSchedStack, STACK_TOP(sSchedStack), 0, 0x100, "sched");
|
2022-11-13 23:07:27 +00:00
|
|
|
Sched_Init(&gScheduler, STACK_TOP(sSchedStack), THREAD_PRI_SCHED, gViConfigModeType, 1, &gIrqMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-08-25 14:00:10 +00:00
|
|
|
#if PLATFORM_N64
|
|
|
|
CIC6105_AddFaultClient();
|
|
|
|
func_80001640();
|
|
|
|
#endif
|
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
IrqMgr_AddClient(&gIrqMgr, &irqClient, &irqMgrMsgQueue);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-02-06 18:00:01 +00:00
|
|
|
StackCheck_Init(&sAudioStackInfo, sAudioStack, STACK_TOP(sAudioStack), 0, 0x100, "audio");
|
2022-06-03 19:43:30 +00:00
|
|
|
AudioMgr_Init(&gAudioMgr, STACK_TOP(sAudioStack), THREAD_PRI_AUDIOMGR, THREAD_ID_AUDIOMGR, &gScheduler, &gIrqMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-02-06 18:00:01 +00:00
|
|
|
StackCheck_Init(&sPadMgrStackInfo, sPadMgrStack, STACK_TOP(sPadMgrStack), 0, 0x100, "padmgr");
|
2022-04-09 00:20:23 +00:00
|
|
|
PadMgr_Init(&gPadMgr, &sSerialEventQueue, &gIrqMgr, THREAD_ID_PADMGR, THREAD_PRI_PADMGR, STACK_TOP(sPadMgrStack));
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2023-11-30 21:22:30 +00:00
|
|
|
AudioMgr_WaitForInit(&gAudioMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-02-06 18:00:01 +00:00
|
|
|
StackCheck_Init(&sGraphStackInfo, sGraphStack, STACK_TOP(sGraphStack), 0, 0x100, "graph");
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateThread(&sGraphThread, THREAD_ID_GRAPH, Graph_ThreadEntry, arg, STACK_TOP(sGraphStack), THREAD_PRI_GRAPH);
|
2020-03-17 04:31:30 +00:00
|
|
|
osStartThread(&sGraphThread);
|
2022-04-09 00:20:23 +00:00
|
|
|
osSetThreadPri(NULL, THREAD_PRI_MAIN);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
while (true) {
|
2024-01-28 20:46:08 +00:00
|
|
|
s16* msg = NULL;
|
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&irqMgrMsgQueue, (OSMesg*)&msg, OS_MESG_BLOCK);
|
2020-03-22 21:19:43 +00:00
|
|
|
if (msg == NULL) {
|
2020-03-17 04:31:30 +00:00
|
|
|
break;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2024-08-25 14:00:10 +00:00
|
|
|
switch (*msg) {
|
|
|
|
case OS_SC_PRE_NMI_MSG:
|
|
|
|
PRINTF(T("main.c: リセットされたみたいだよ\n", "main.c: Looks like it's been reset\n"));
|
|
|
|
PreNmiBuff_SetReset(gAppNmiBufferPtr);
|
|
|
|
break;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("mainproc 後始末\n", "mainproc Cleanup\n"));
|
2020-03-17 04:31:30 +00:00
|
|
|
osDestroyThread(&sGraphThread);
|
2022-01-23 23:04:50 +00:00
|
|
|
RcpUtils_Reset();
|
2024-08-25 14:00:10 +00:00
|
|
|
#if PLATFORM_N64
|
|
|
|
CIC6105_RemoveFaultClient();
|
|
|
|
#endif
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("mainproc 実行終了\n", "mainproc End of execution\n"));
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|