1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-02 15:55:59 +00:00
oot/src/code/main.c

118 lines
4.2 KiB
C
Raw Normal View History

#include "global.h"
#include "vt.h"
2020-03-17 04:31:30 +00:00
s32 gScreenWidth = SCREEN_WIDTH;
s32 gScreenHeight = SCREEN_HEIGHT;
2020-03-17 04:31:30 +00:00
u32 gSystemHeapSize = 0;
PreNmiBuff* gAppNmiBufferPtr;
2020-03-17 04:31:30 +00:00
SchedContext gSchedContext;
PadMgr gPadMgr;
IrqMgr gIrqMgr;
u32 gSegments[NUM_SEGMENTS];
OSThread sGraphThread;
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;
AudioMgr gAudioMgr;
OSMesgQueue sSerialEventQueue;
OSMesg sSerialMsgBuf[1];
2020-03-17 04:31:30 +00:00
void Main_LogSystemHeap(void) {
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_FGCOL(GREEN));
// "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);
}
void Main(void* arg) {
2020-03-17 04:31:30 +00:00
IrqMgrClient irqClient;
OSMesgQueue irqMgrMsgQueue;
2020-03-17 04:31:30 +00:00
OSMesg irqMgrMsgBuf[60];
u32 systemHeapStart;
2020-03-17 04:31:30 +00:00
u32 fb;
s32 debugHeapStart;
2020-03-17 04:31:30 +00:00
s32 debugHeapSize;
2020-03-22 21:19:43 +00:00
s16* msg;
2020-03-17 04:31:30 +00:00
osSyncPrintf("mainproc 実行開始\n"); // "Start running"
2020-03-17 04:31:30 +00:00
gScreenWidth = SCREEN_WIDTH;
gScreenHeight = SCREEN_HEIGHT;
gAppNmiBufferPtr = (PreNmiBuff*)osAppNMIBuffer;
PreNmiBuff_Init(gAppNmiBufferPtr);
Fault_Init();
2020-03-17 04:31:30 +00:00
SysCfb_Init(0);
systemHeapStart = (u32)gSystemHeap;
2020-03-17 04:31:30 +00:00
fb = SysCfb_GetFbPtr(0);
gSystemHeapSize = fb - systemHeapStart;
// "System heap initalization"
osSyncPrintf("システムヒープ初期化 %08x-%08x %08x\n", systemHeapStart, fb, gSystemHeapSize);
SystemHeap_Init(systemHeapStart, gSystemHeapSize); // initializes the system heap
Fix/cleanup/rephrase miscellaneous stuff (#983) * Add parens around params usage in VEC_SET macro * Remove unnecessary space character in a xml * Use defines instead of magic values in head/tail magic comments * Use `OS_USEC_TO_CYCLES` to make a time look better in `Graph_TaskSet00` * `0x25800` -> `sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])` * `0x803DA800` -> `0x80400000 - frame buffer size` * Use `OS_VI_` defines instead of hex * Add empty line after some variable declarations * Remove unused `extern CutsceneData` in `z_bg_dy_yoseizo.c` * `Matrix_MtxFToYXZRotS` does not use `MTXMODE_` * Use `MTXMODE_` more * Remove `ASCII_TO_U32`, use `'IS64'` * Add explicit `!= NULL` in some ternaries * Use `INV_CONTENT`, `AMMO` macros more * Use `PLAYER_AP_` enum more to compare to `Player#heldItemActionParam` * Get rid of lowercase hex (outside libultra) * `gWindMill*` -> `gWindmill*` * Format and small fix enums in `z_boss_mo.h` * Use `CHECK_BTN_ANY` more * Fix xz/xy mistake in comment in tektite * Rephrase comments mentioning "the devs" in a more neutral way * Clean-up some objectively useless parens * Fix some negative values written as u16 instead of s16 in ichains * `SKJ_ACTON_` -> `SKJ_ACTION_` * Run formatter * Fix unk_ offset of `TransformUpdateIndex#unk_10` -> `unk_0E` * Remove comments using in-game text * Remove `U` suffix from integer literals * Revert "Remove `ASCII_TO_U32`, use `'IS64'`" This reverts commit c801337dde9fe5e8b7a7ecf85ad3629bf5b87aaf. * Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)` * Add empty line after decl x2 * Revert "Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)`" This reverts commit d80bdb32da449edc74e02b8ab3f5a2c532e74bdb. * Make `CUR_UPG_VALUE(UPG_STRENGTH)` compare to integers (eventually needs its own enum) * Only use `PLAYER_SHIELD_` enum with `Player#currentShield` * Only use `PLAYER_TUNIC_` enum with `Player#currentTunic`
2021-10-03 03:17:09 +00:00
if (osMemSize >= 0x800000) {
debugHeapStart = SysCfb_GetFbEnd();
debugHeapSize = PHYS_TO_K0(0x600000) - debugHeapStart;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
debugHeapSize = 0x400;
debugHeapStart = SystemArena_MallocDebug(debugHeapSize, "../main.c", 565);
2020-03-17 04:31:30 +00:00
}
osSyncPrintf("debug_InitArena(%08x, %08x)\n", debugHeapStart, debugHeapSize);
DebugArena_Init(debugHeapStart, debugHeapSize);
2020-03-17 04:31:30 +00:00
func_800636C0();
R_ENABLE_ARENA_DBG = 0;
2020-03-17 04:31:30 +00:00
osCreateMesgQueue(&sSerialEventQueue, sSerialMsgBuf, ARRAY_COUNT(sSerialMsgBuf));
osSetEventMesg(OS_EVENT_SI, &sSerialEventQueue, NULL);
2020-03-17 04:31:30 +00:00
Main_LogSystemHeap();
osCreateMesgQueue(&irqMgrMsgQueue, irqMgrMsgBuf, ARRAY_COUNT(irqMgrMsgBuf));
StackCheck_Init(&sIrqMgrStackInfo, sIrqMgrStack, STACK_TOP(sIrqMgrStack), 0, 0x100, "irqmgr");
IrqMgr_Init(&gIrqMgr, STACK_TOP(sIrqMgrStack), THREAD_PRI_IRQMGR, 1);
2020-03-17 04:31:30 +00:00
osSyncPrintf("タスクスケジューラの初期化\n"); // "Initialize the task scheduler"
StackCheck_Init(&sSchedStackInfo, sSchedStack, STACK_TOP(sSchedStack), 0, 0x100, "sched");
Sched_Init(&gSchedContext, STACK_TOP(sSchedStack), THREAD_PRI_SCHED, D_80013960, 1, &gIrqMgr);
2020-03-17 04:31:30 +00:00
IrqMgr_AddClient(&gIrqMgr, &irqClient, &irqMgrMsgQueue);
2020-03-17 04:31:30 +00:00
StackCheck_Init(&sAudioStackInfo, sAudioStack, STACK_TOP(sAudioStack), 0, 0x100, "audio");
AudioMgr_Init(&gAudioMgr, STACK_TOP(sAudioStack), THREAD_PRI_AUDIOMGR, THREAD_ID_AUDIOMGR, &gSchedContext,
&gIrqMgr);
2020-03-17 04:31:30 +00:00
StackCheck_Init(&sPadMgrStackInfo, sPadMgrStack, STACK_TOP(sPadMgrStack), 0, 0x100, "padmgr");
PadMgr_Init(&gPadMgr, &sSerialEventQueue, &gIrqMgr, THREAD_ID_PADMGR, THREAD_PRI_PADMGR, STACK_TOP(sPadMgrStack));
2020-03-17 04:31:30 +00:00
AudioMgr_Unlock(&gAudioMgr);
2020-03-17 04:31:30 +00:00
StackCheck_Init(&sGraphStackInfo, sGraphStack, STACK_TOP(sGraphStack), 0, 0x100, "graph");
osCreateThread(&sGraphThread, THREAD_ID_GRAPH, Graph_ThreadEntry, arg, STACK_TOP(sGraphStack), THREAD_PRI_GRAPH);
2020-03-17 04:31:30 +00:00
osStartThread(&sGraphThread);
osSetThreadPri(NULL, THREAD_PRI_MAIN);
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;
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
}
if (*msg == OS_SC_PRE_NMI_MSG) {
osSyncPrintf("main.c: リセットされたみたいだよ\n"); // "Looks like it's been reset"
PreNmiBuff_SetReset(gAppNmiBufferPtr);
2020-03-17 04:31:30 +00:00
}
}
osSyncPrintf("mainproc 後始末\n"); // "Cleanup"
2020-03-17 04:31:30 +00:00
osDestroyThread(&sGraphThread);
RcpUtils_Reset();
osSyncPrintf("mainproc 実行終了\n"); // "End of execution"
2020-03-17 04:31:30 +00:00
}