2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "vt.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-03-20 11:43:51 +00:00
|
|
|
PreNmiBuff* gAppNmiBufferPtr;
|
2020-03-17 04:31:30 +00:00
|
|
|
SchedContext gSchedContext;
|
|
|
|
PadMgr gPadMgr;
|
|
|
|
IrqMgr gIrqMgr;
|
|
|
|
u32 gSegments[NUM_SEGMENTS];
|
|
|
|
OSThread sGraphThread;
|
|
|
|
u8 sGraphStack[0x1800];
|
|
|
|
u8 sSchedStack[0x600];
|
|
|
|
u8 sAudioStack[0x800];
|
|
|
|
u8 sPadMgrStack[0x500];
|
|
|
|
u8 sIrqMgrStack[0x500];
|
|
|
|
StackEntry sGraphStackInfo;
|
|
|
|
StackEntry sSchedStackInfo;
|
|
|
|
StackEntry sAudioStackInfo;
|
|
|
|
StackEntry sPadMgrStackInfo;
|
|
|
|
StackEntry sIrqMgrStackInfo;
|
2020-05-11 00:04:41 +00:00
|
|
|
AudioMgr gAudioMgr;
|
2020-03-17 04:31:30 +00:00
|
|
|
OSMesgQueue sSiIntMsgQ;
|
|
|
|
OSMesg sSiIntMsgBuf[1];
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void Main_LogSystemHeap(void) {
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(GREEN));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "System heap size% 08x (% dKB) Start address% 08x"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("システムヒープサイズ %08x(%dKB) 開始アドレス %08x\n", gSystemHeapSize, gSystemHeapSize / 1024,
|
|
|
|
gSystemHeap);
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void Main(void* arg) {
|
2020-03-17 04:31:30 +00:00
|
|
|
IrqMgrClient irqClient;
|
|
|
|
OSMesgQueue irqMgrMsgQ;
|
|
|
|
OSMesg irqMgrMsgBuf[60];
|
|
|
|
u32 sysHeap;
|
|
|
|
u32 fb;
|
|
|
|
s32 debugHeap;
|
|
|
|
s32 debugHeapSize;
|
2020-03-22 21:19:43 +00:00
|
|
|
s16* msg;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("mainproc 実行開始\n"); // "Start running"
|
2020-03-17 04:31:30 +00:00
|
|
|
gScreenWidth = SCREEN_WIDTH;
|
|
|
|
gScreenHeight = SCREEN_HEIGHT;
|
2020-03-20 11:43:51 +00:00
|
|
|
gAppNmiBufferPtr = (PreNmiBuff*)osAppNmiBuffer;
|
|
|
|
PreNmiBuff_Init(gAppNmiBufferPtr);
|
2020-10-03 15:22:44 +00:00
|
|
|
Fault_Init();
|
2020-03-17 04:31:30 +00:00
|
|
|
SysCfb_Init(0);
|
|
|
|
sysHeap = (u32)gSystemHeap;
|
|
|
|
fb = SysCfb_GetFbPtr(0);
|
|
|
|
gSystemHeapSize = (fb - sysHeap);
|
2021-09-04 13:33:19 +00:00
|
|
|
// "System heap initalization"
|
|
|
|
osSyncPrintf("システムヒープ初期化 %08x-%08x %08x\n", sysHeap, fb, gSystemHeapSize);
|
|
|
|
SystemHeap_Init(sysHeap, gSystemHeapSize); // initializes the system heap
|
2021-10-03 03:17:09 +00:00
|
|
|
if (osMemSize >= 0x800000) {
|
2020-03-17 04:31:30 +00:00
|
|
|
debugHeap = SysCfb_GetFbEnd();
|
2020-03-22 21:19:43 +00:00
|
|
|
debugHeapSize = (s32)(0x80600000 - debugHeap);
|
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
debugHeapSize = 0x400;
|
|
|
|
debugHeap = SystemArena_MallocDebug(debugHeapSize, "../main.c", 0x235);
|
|
|
|
}
|
|
|
|
osSyncPrintf("debug_InitArena(%08x, %08x)\n", debugHeap, debugHeapSize);
|
|
|
|
DebugArena_Init(debugHeap, debugHeapSize);
|
|
|
|
func_800636C0();
|
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
R_ENABLE_ARENA_DBG = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
osCreateMesgQueue(&sSiIntMsgQ, sSiIntMsgBuf, 1);
|
|
|
|
osSetEventMesg(5, &sSiIntMsgQ, 0);
|
|
|
|
|
|
|
|
Main_LogSystemHeap();
|
|
|
|
|
2021-10-03 03:17:09 +00:00
|
|
|
osCreateMesgQueue(&irqMgrMsgQ, irqMgrMsgBuf, 0x3C);
|
2020-03-22 21:19:43 +00:00
|
|
|
StackCheck_Init(&sIrqMgrStackInfo, sIrqMgrStack, sIrqMgrStack + sizeof(sIrqMgrStack), 0, 0x100, "irqmgr");
|
2020-10-03 15:22:44 +00:00
|
|
|
IrqMgr_Init(&gIrqMgr, &sGraphStackInfo, Z_PRIORITY_IRQMGR, 1);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("タスクスケジューラの初期化\n"); // "Initialize the task scheduler"
|
2020-03-22 21:19:43 +00:00
|
|
|
StackCheck_Init(&sSchedStackInfo, sSchedStack, sSchedStack + sizeof(sSchedStack), 0, 0x100, "sched");
|
2020-10-03 15:22:44 +00:00
|
|
|
Sched_Init(&gSchedContext, &sAudioStack, Z_PRIORITY_SCHED, D_80013960, 1, &gIrqMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
IrqMgr_AddClient(&gIrqMgr, &irqClient, &irqMgrMsgQ);
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
StackCheck_Init(&sAudioStackInfo, sAudioStack, sAudioStack + sizeof(sAudioStack), 0, 0x100, "audio");
|
2021-10-03 03:17:09 +00:00
|
|
|
AudioMgr_Init(&gAudioMgr, sAudioStack + sizeof(sAudioStack), Z_PRIORITY_AUDIOMGR, 0xA, &gSchedContext, &gIrqMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
StackCheck_Init(&sPadMgrStackInfo, sPadMgrStack, sPadMgrStack + sizeof(sPadMgrStack), 0, 0x100, "padmgr");
|
2020-10-03 15:22:44 +00:00
|
|
|
PadMgr_Init(&gPadMgr, &sSiIntMsgQ, &gIrqMgr, 7, Z_PRIORITY_PADMGR, &sIrqMgrStack);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-11 00:04:41 +00:00
|
|
|
AudioMgr_Unlock(&gAudioMgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
StackCheck_Init(&sGraphStackInfo, sGraphStack, sGraphStack + sizeof(sGraphStack), 0, 0x100, "graph");
|
2021-02-14 00:49:40 +00:00
|
|
|
osCreateThread(&sGraphThread, 4, Graph_ThreadEntry, arg, sGraphStack + sizeof(sGraphStack), Z_PRIORITY_GRAPH);
|
2020-03-17 04:31:30 +00:00
|
|
|
osStartThread(&sGraphThread);
|
2020-10-03 15:22:44 +00:00
|
|
|
osSetThreadPri(0, Z_PRIORITY_SCHED);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
while (true) {
|
2020-03-17 04:31:30 +00:00
|
|
|
msg = NULL;
|
2021-02-14 00:49:40 +00:00
|
|
|
osRecvMesg(&irqMgrMsgQ, (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
|
|
|
}
|
|
|
|
if (*msg == OS_SC_PRE_NMI_MSG) {
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("main.c: リセットされたみたいだよ\n"); // "Looks like it's been reset"
|
2020-03-20 11:43:51 +00:00
|
|
|
PreNmiBuff_SetReset(gAppNmiBufferPtr);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("mainproc 後始末\n"); // "Cleanup"
|
2020-03-17 04:31:30 +00:00
|
|
|
osDestroyThread(&sGraphThread);
|
|
|
|
func_800FBFD8();
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("mainproc 実行終了\n"); // "End of execution"
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|