mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-15 12:24:39 +00:00
Gamealloc, Graph, and Graphalloc retail OK (#1675)
* Gamealloc OK * Graph + Graphalloc OK * PR review * gfxalloc * new lines * Remove imposter
This commit is contained in:
parent
a0d31dba68
commit
06379c3109
19 changed files with 202 additions and 158 deletions
257
src/code/graph.c
257
src/code/graph.c
|
@ -30,6 +30,7 @@ UCodeInfo D_8012D248[3] = {
|
|||
{ UCODE_S2DEX, gspS2DEX2d_fifoTextStart },
|
||||
};
|
||||
|
||||
#if OOT_DEBUG
|
||||
void Graph_FaultClient(void) {
|
||||
void* nextFb = osViGetNextFramebuffer();
|
||||
void* newFb = (SysCfb_GetFbPtr(0) != nextFb) ? SysCfb_GetFbPtr(0) : SysCfb_GetFbPtr(1);
|
||||
|
@ -93,6 +94,7 @@ void Graph_UCodeFaultClient(Gfx* workBuf) {
|
|||
UCodeDisas_Disassemble(&disassembler, workBuf);
|
||||
UCodeDisas_Destroy(&disassembler);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Graph_InitTHGA(GraphicsContext* gfxCtx) {
|
||||
GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIdx & 1];
|
||||
|
@ -139,13 +141,17 @@ void Graph_Init(GraphicsContext* gfxCtx) {
|
|||
gfxCtx->xScale = gViConfigXScale;
|
||||
gfxCtx->yScale = gViConfigYScale;
|
||||
osCreateMesgQueue(&gfxCtx->queue, gfxCtx->msgBuff, ARRAY_COUNT(gfxCtx->msgBuff));
|
||||
#if OOT_DEBUG
|
||||
func_800D31F0();
|
||||
Fault_AddClient(&sGraphFaultClient, Graph_FaultClient, NULL, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Graph_Destroy(GraphicsContext* gfxCtx) {
|
||||
#if OOT_DEBUG
|
||||
func_800D3210();
|
||||
Fault_RemoveClient(&sGraphFaultClient);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Graph_TaskSet00(GraphicsContext* gfxCtx) {
|
||||
|
@ -157,109 +163,122 @@ void Graph_TaskSet00(GraphicsContext* gfxCtx) {
|
|||
OSMesg msg;
|
||||
OSTask_t* task = &gfxCtx->task.list.t;
|
||||
OSScTask* scTask = &gfxCtx->task;
|
||||
CfbInfo* cfb;
|
||||
|
||||
gGfxTaskSentToNextReadyMinusAudioThreadUpdateTime =
|
||||
osGetTime() - sGraphPrevTaskTimeStart - gAudioThreadUpdateTimeAcc;
|
||||
|
||||
osSetTimer(&timer, OS_USEC_TO_CYCLES(3000000), 0, &gfxCtx->queue, (OSMesg)666);
|
||||
{
|
||||
CfbInfo* cfb;
|
||||
|
||||
osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_BLOCK);
|
||||
osStopTimer(&timer);
|
||||
osSetTimer(&timer, OS_USEC_TO_CYCLES(3000000), 0, &gfxCtx->queue, (OSMesg)666);
|
||||
|
||||
if (msg == (OSMesg)666) {
|
||||
PRINTF(VT_FGCOL(RED));
|
||||
PRINTF("RCPが帰ってきませんでした。"); // "RCP did not return."
|
||||
PRINTF(VT_RST);
|
||||
osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_BLOCK);
|
||||
osStopTimer(&timer);
|
||||
|
||||
LogUtils_LogHexDump((void*)PHYS_TO_K1(SP_BASE_REG), 0x20);
|
||||
LogUtils_LogHexDump((void*)PHYS_TO_K1(DPC_BASE_REG), 0x20);
|
||||
LogUtils_LogHexDump(gGfxSPTaskYieldBuffer, sizeof(gGfxSPTaskYieldBuffer));
|
||||
if (msg == (OSMesg)666) {
|
||||
#if OOT_DEBUG
|
||||
PRINTF(VT_FGCOL(RED));
|
||||
PRINTF("RCPが帰ってきませんでした。"); // "RCP did not return."
|
||||
PRINTF(VT_RST);
|
||||
|
||||
SREG(6) = -1;
|
||||
if (sPrevTaskWorkBuffer != NULL) {
|
||||
R_HREG_MODE = HREG_MODE_UCODE_DISAS;
|
||||
R_UCODE_DISAS_TOGGLE = 1;
|
||||
R_UCODE_DISAS_LOG_LEVEL = 2;
|
||||
Graph_DisassembleUCode(sPrevTaskWorkBuffer);
|
||||
LogUtils_LogHexDump((void*)PHYS_TO_K1(SP_BASE_REG), 0x20);
|
||||
LogUtils_LogHexDump((void*)PHYS_TO_K1(DPC_BASE_REG), 0x20);
|
||||
LogUtils_LogHexDump(gGfxSPTaskYieldBuffer, sizeof(gGfxSPTaskYieldBuffer));
|
||||
|
||||
SREG(6) = -1;
|
||||
if (sPrevTaskWorkBuffer != NULL) {
|
||||
R_HREG_MODE = HREG_MODE_UCODE_DISAS;
|
||||
R_UCODE_DISAS_TOGGLE = 1;
|
||||
R_UCODE_DISAS_LOG_LEVEL = 2;
|
||||
Graph_DisassembleUCode(sPrevTaskWorkBuffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
Fault_AddHungupAndCrashImpl("RCP is HUNG UP!!", "Oh! MY GOD!!");
|
||||
}
|
||||
|
||||
Fault_AddHungupAndCrashImpl("RCP is HUNG UP!!", "Oh! MY GOD!!");
|
||||
osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_NOBLOCK);
|
||||
|
||||
#if OOT_DEBUG
|
||||
sPrevTaskWorkBuffer = gfxCtx->workBuffer;
|
||||
#endif
|
||||
|
||||
if (gfxCtx->callback != NULL) {
|
||||
gfxCtx->callback(gfxCtx, gfxCtx->callbackParam);
|
||||
}
|
||||
|
||||
timeNow = osGetTime();
|
||||
if (gAudioThreadUpdateTimeStart != 0) {
|
||||
// The audio thread update is running
|
||||
// Add the time already spent to the accumulator and leave the rest for the next cycle
|
||||
|
||||
gAudioThreadUpdateTimeAcc += timeNow - gAudioThreadUpdateTimeStart;
|
||||
gAudioThreadUpdateTimeStart = timeNow;
|
||||
}
|
||||
gAudioThreadUpdateTimeTotalPerGfxTask = gAudioThreadUpdateTimeAcc;
|
||||
gAudioThreadUpdateTimeAcc = 0;
|
||||
|
||||
sGraphPrevTaskTimeStart = osGetTime();
|
||||
|
||||
task->type = M_GFXTASK;
|
||||
task->flags = OS_SC_DRAM_DLIST;
|
||||
task->ucode_boot = SysUcode_GetUCodeBoot();
|
||||
task->ucode_boot_size = SysUcode_GetUCodeBootSize();
|
||||
task->ucode = SysUcode_GetUCode();
|
||||
task->ucode_data = SysUcode_GetUCodeData();
|
||||
task->ucode_size = SP_UCODE_SIZE;
|
||||
task->ucode_data_size = SP_UCODE_DATA_SIZE;
|
||||
task->dram_stack = gGfxSPTaskStack;
|
||||
task->dram_stack_size = sizeof(gGfxSPTaskStack);
|
||||
task->output_buff = gGfxSPTaskOutputBuffer;
|
||||
task->output_buff_size = gGfxSPTaskOutputBuffer + ARRAY_COUNT(gGfxSPTaskOutputBuffer);
|
||||
task->data_ptr = (u64*)gfxCtx->workBuffer;
|
||||
|
||||
OPEN_DISPS(gfxCtx, "../graph.c", 828);
|
||||
task->data_size = (uintptr_t)WORK_DISP - (uintptr_t)gfxCtx->workBuffer;
|
||||
CLOSE_DISPS(gfxCtx, "../graph.c", 830);
|
||||
|
||||
task->yield_data_ptr = gGfxSPTaskYieldBuffer;
|
||||
|
||||
if (1) {}
|
||||
|
||||
task->yield_data_size = sizeof(gGfxSPTaskYieldBuffer);
|
||||
|
||||
scTask->next = NULL;
|
||||
scTask->flags = OS_SC_NEEDS_RSP | OS_SC_NEEDS_RDP | OS_SC_SWAPBUFFER | OS_SC_LAST_TASK;
|
||||
if (R_GRAPH_TASKSET00_FLAGS & 1) {
|
||||
R_GRAPH_TASKSET00_FLAGS &= ~1;
|
||||
scTask->flags &= ~OS_SC_SWAPBUFFER;
|
||||
gfxCtx->fbIdx--;
|
||||
}
|
||||
|
||||
scTask->msgQueue = &gfxCtx->queue;
|
||||
scTask->msg = NULL;
|
||||
|
||||
{ s16 pad; }
|
||||
|
||||
cfb = &sGraphCfbInfos[sGraphCfbInfoIdx];
|
||||
|
||||
sGraphCfbInfoIdx = (sGraphCfbInfoIdx + 1) % ARRAY_COUNT(sGraphCfbInfos);
|
||||
cfb->framebuffer = gfxCtx->curFrameBuffer;
|
||||
cfb->swapBuffer = gfxCtx->curFrameBuffer;
|
||||
|
||||
cfb->viMode = gfxCtx->viMode;
|
||||
cfb->viFeatures = gfxCtx->viFeatures;
|
||||
cfb->xScale = gfxCtx->xScale;
|
||||
cfb->yScale = gfxCtx->yScale;
|
||||
cfb->unk_10 = 0;
|
||||
cfb->updateRate = R_UPDATE_RATE;
|
||||
|
||||
scTask->framebuffer = cfb;
|
||||
|
||||
{ s16 pad2; }
|
||||
|
||||
gfxCtx->schedMsgQueue = &gScheduler.cmdQueue;
|
||||
|
||||
osSendMesg(&gScheduler.cmdQueue, (OSMesg)scTask, OS_MESG_BLOCK);
|
||||
Sched_Notify(&gScheduler);
|
||||
}
|
||||
|
||||
osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_NOBLOCK);
|
||||
|
||||
sPrevTaskWorkBuffer = gfxCtx->workBuffer;
|
||||
if (gfxCtx->callback != NULL) {
|
||||
gfxCtx->callback(gfxCtx, gfxCtx->callbackParam);
|
||||
}
|
||||
|
||||
timeNow = osGetTime();
|
||||
if (gAudioThreadUpdateTimeStart != 0) {
|
||||
// The audio thread update is running
|
||||
// Add the time already spent to the accumulator and leave the rest for the next cycle
|
||||
|
||||
gAudioThreadUpdateTimeAcc += timeNow - gAudioThreadUpdateTimeStart;
|
||||
gAudioThreadUpdateTimeStart = timeNow;
|
||||
}
|
||||
gAudioThreadUpdateTimeTotalPerGfxTask = gAudioThreadUpdateTimeAcc;
|
||||
gAudioThreadUpdateTimeAcc = 0;
|
||||
|
||||
sGraphPrevTaskTimeStart = osGetTime();
|
||||
|
||||
task->type = M_GFXTASK;
|
||||
task->flags = OS_SC_DRAM_DLIST;
|
||||
task->ucode_boot = SysUcode_GetUCodeBoot();
|
||||
task->ucode_boot_size = SysUcode_GetUCodeBootSize();
|
||||
task->ucode = SysUcode_GetUCode();
|
||||
task->ucode_data = SysUcode_GetUCodeData();
|
||||
task->ucode_size = SP_UCODE_SIZE;
|
||||
task->ucode_data_size = SP_UCODE_DATA_SIZE;
|
||||
task->dram_stack = gGfxSPTaskStack;
|
||||
task->dram_stack_size = sizeof(gGfxSPTaskStack);
|
||||
task->output_buff = gGfxSPTaskOutputBuffer;
|
||||
task->output_buff_size = gGfxSPTaskOutputBuffer + ARRAY_COUNT(gGfxSPTaskOutputBuffer);
|
||||
task->data_ptr = (u64*)gfxCtx->workBuffer;
|
||||
|
||||
OPEN_DISPS(gfxCtx, "../graph.c", 828);
|
||||
task->data_size = (uintptr_t)WORK_DISP - (uintptr_t)gfxCtx->workBuffer;
|
||||
CLOSE_DISPS(gfxCtx, "../graph.c", 830);
|
||||
|
||||
{ s32 pad2; } // Necessary to match stack usage
|
||||
|
||||
task->yield_data_ptr = gGfxSPTaskYieldBuffer;
|
||||
task->yield_data_size = sizeof(gGfxSPTaskYieldBuffer);
|
||||
|
||||
scTask->next = NULL;
|
||||
scTask->flags = OS_SC_NEEDS_RSP | OS_SC_NEEDS_RDP | OS_SC_SWAPBUFFER | OS_SC_LAST_TASK;
|
||||
if (R_GRAPH_TASKSET00_FLAGS & 1) {
|
||||
R_GRAPH_TASKSET00_FLAGS &= ~1;
|
||||
scTask->flags &= ~OS_SC_SWAPBUFFER;
|
||||
gfxCtx->fbIdx--;
|
||||
}
|
||||
|
||||
scTask->msgQueue = &gfxCtx->queue;
|
||||
scTask->msg = NULL;
|
||||
|
||||
cfb = &sGraphCfbInfos[sGraphCfbInfoIdx++];
|
||||
cfb->framebuffer = gfxCtx->curFrameBuffer;
|
||||
cfb->swapBuffer = gfxCtx->curFrameBuffer;
|
||||
cfb->viMode = gfxCtx->viMode;
|
||||
cfb->viFeatures = gfxCtx->viFeatures;
|
||||
cfb->xScale = gfxCtx->xScale;
|
||||
cfb->yScale = gfxCtx->yScale;
|
||||
cfb->unk_10 = 0;
|
||||
cfb->updateRate = R_UPDATE_RATE;
|
||||
|
||||
scTask->framebuffer = cfb;
|
||||
sGraphCfbInfoIdx %= ARRAY_COUNT(sGraphCfbInfos);
|
||||
|
||||
if (1) {}
|
||||
|
||||
gfxCtx->schedMsgQueue = &gScheduler.cmdQueue;
|
||||
|
||||
osSendMesg(&gScheduler.cmdQueue, (OSMesg)scTask, OS_MESG_BLOCK);
|
||||
Sched_Notify(&gScheduler);
|
||||
}
|
||||
|
||||
void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
||||
|
@ -268,6 +287,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
gameState->inPreNMIState = false;
|
||||
Graph_InitTHGA(gfxCtx);
|
||||
|
||||
#if OOT_DEBUG
|
||||
OPEN_DISPS(gfxCtx, "../graph.c", 966);
|
||||
|
||||
gDPNoOpString(WORK_DISP++, "WORK_DISP 開始", 0);
|
||||
|
@ -276,10 +296,12 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
gDPNoOpString(OVERLAY_DISP++, "OVERLAY_DISP 開始", 0);
|
||||
|
||||
CLOSE_DISPS(gfxCtx, "../graph.c", 975);
|
||||
#endif
|
||||
|
||||
GameState_ReqPadData(gameState);
|
||||
GameState_Update(gameState);
|
||||
|
||||
#if OOT_DEBUG
|
||||
OPEN_DISPS(gfxCtx, "../graph.c", 987);
|
||||
|
||||
gDPNoOpString(WORK_DISP++, "WORK_DISP 終了", 0);
|
||||
|
@ -288,6 +310,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
gDPNoOpString(OVERLAY_DISP++, "OVERLAY_DISP 終了", 0);
|
||||
|
||||
CLOSE_DISPS(gfxCtx, "../graph.c", 996);
|
||||
#endif
|
||||
|
||||
OPEN_DISPS(gfxCtx, "../graph.c", 999);
|
||||
|
||||
|
@ -300,6 +323,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
|
||||
CLOSE_DISPS(gfxCtx, "../graph.c", 1028);
|
||||
|
||||
#if OOT_DEBUG
|
||||
if (R_HREG_MODE == HREG_MODE_PLAY && R_PLAY_ENABLE_UCODE_DISAS == 2) {
|
||||
R_HREG_MODE = HREG_MODE_UCODE_DISAS;
|
||||
R_UCODE_DISAS_TOGGLE = -1;
|
||||
|
@ -326,6 +350,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
R_UCODE_DISAS_TOGGLE = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
problem = false;
|
||||
|
||||
|
@ -377,7 +402,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
|
||||
{
|
||||
OSTime timeNow = osGetTime();
|
||||
s32 pad[4];
|
||||
s32 pad;
|
||||
|
||||
gRSPGfxTimeTotal = gRSPGfxTimeAcc;
|
||||
gRSPAudioTimeTotal = gRSPAudioTimeAcc;
|
||||
|
@ -392,19 +417,29 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
sGraphPrevUpdateEndTime = timeNow;
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
if (gIsCtrlr2Valid && CHECK_BTN_ALL(gameState->input[0].press.button, BTN_Z) &&
|
||||
CHECK_BTN_ALL(gameState->input[0].cur.button, BTN_L | BTN_R)) {
|
||||
gSaveContext.gameMode = GAMEMODE_NORMAL;
|
||||
SET_NEXT_GAMESTATE(gameState, MapSelect_Init, MapSelectState);
|
||||
{
|
||||
GameState* state = gameState;
|
||||
|
||||
SET_NEXT_GAMESTATE(state, MapSelect_Init, MapSelectState);
|
||||
}
|
||||
gameState->running = false;
|
||||
}
|
||||
|
||||
if (gIsCtrlr2Valid && PreNmiBuff_IsResetting(gAppNmiBufferPtr) && !gameState->inPreNMIState) {
|
||||
// "To reset mode"
|
||||
PRINTF(VT_COL(YELLOW, BLACK) "PRE-NMIによりリセットモードに移行します\n" VT_RST);
|
||||
SET_NEXT_GAMESTATE(gameState, PreNMI_Init, PreNMIState);
|
||||
{
|
||||
GameState* state = gameState;
|
||||
|
||||
SET_NEXT_GAMESTATE(state, PreNMI_Init, PreNMIState);
|
||||
}
|
||||
gameState->running = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Graph_ThreadEntry(void* arg0) {
|
||||
|
@ -413,7 +448,6 @@ void Graph_ThreadEntry(void* arg0) {
|
|||
u32 size;
|
||||
GameStateOverlay* nextOvl = &gGameStateOverlayTable[GAMESTATE_SETUP];
|
||||
GameStateOverlay* ovl;
|
||||
char faultMsg[0x50];
|
||||
|
||||
PRINTF("グラフィックスレッド実行開始\n"); // "Start graphic thread execution"
|
||||
Graph_Init(&gfxCtx);
|
||||
|
@ -428,10 +462,15 @@ void Graph_ThreadEntry(void* arg0) {
|
|||
gameState = SYSTEM_ARENA_MALLOC(size, "../graph.c", 1196);
|
||||
|
||||
if (gameState == NULL) {
|
||||
#if OOT_DEBUG
|
||||
char faultMsg[0x50];
|
||||
PRINTF("確保失敗\n"); // "Failure to secure"
|
||||
|
||||
sprintf(faultMsg, "CLASS SIZE= %d bytes", size);
|
||||
Fault_AddHungupAndCrashImpl("GAME CLASS MALLOC FAILED", faultMsg);
|
||||
#else
|
||||
Fault_AddHungupAndCrash("../graph.c", 1200);
|
||||
#endif
|
||||
}
|
||||
|
||||
GameState_Init(gameState, ovl->init, &gfxCtx);
|
||||
|
@ -469,6 +508,7 @@ void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size) {
|
|||
return THGA_AllocTail(&gfxCtx->polyOpa, ALIGN16(size));
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) {
|
||||
if (R_HREG_MODE == HREG_MODE_UCODE_DISAS && R_UCODE_DISAS_LOG_MODE != 4) {
|
||||
dispRefs[0] = gfxCtx->polyOpa.p;
|
||||
|
@ -502,27 +542,4 @@ void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Gfx* Graph_GfxPlusOne(Gfx* gfx) {
|
||||
return gfx + 1;
|
||||
}
|
||||
|
||||
Gfx* Graph_BranchDlist(Gfx* gfx, Gfx* dst) {
|
||||
gSPBranchList(gfx, dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
void* Graph_DlistAlloc(Gfx** gfxP, u32 size) {
|
||||
u8* ptr;
|
||||
Gfx* dst;
|
||||
|
||||
size = ALIGN8(size);
|
||||
|
||||
ptr = (u8*)(*gfxP + 1);
|
||||
|
||||
dst = (Gfx*)(ptr + size);
|
||||
gSPBranchList(*gfxP, dst);
|
||||
|
||||
*gfxP = dst;
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue