2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "vt.h"
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
#define GFXPOOL_HEAD_MAGIC 0x1234
|
|
|
|
#define GFXPOOL_TAIL_MAGIC 0x5678
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-05 10:32:08 +00:00
|
|
|
OSTime sGraphUpdateTime;
|
2020-04-04 16:12:59 +00:00
|
|
|
OSTime sGraphSetTaskTime;
|
|
|
|
FaultClient sGraphFaultClient;
|
|
|
|
CfbInfo sGraphCfbInfos[3];
|
|
|
|
FaultClient sGraphUcodeFaultClient;
|
|
|
|
|
2020-04-13 23:03:10 +00:00
|
|
|
// clang-format off
|
2020-04-05 10:32:08 +00:00
|
|
|
UCodeInfo D_8012D230[3] = {
|
2020-06-05 17:18:39 +00:00
|
|
|
{ UCODE_F3DZEX, D_80155F50 },
|
|
|
|
{ UCODE_UNK, NULL },
|
|
|
|
{ UCODE_S2DEX, D_80113070 },
|
2020-04-04 16:12:59 +00:00
|
|
|
};
|
|
|
|
|
2020-04-05 10:32:08 +00:00
|
|
|
UCodeInfo D_8012D248[3] = {
|
2020-06-05 17:18:39 +00:00
|
|
|
{ UCODE_F3DZEX, D_80155F50 },
|
|
|
|
{ UCODE_UNK, NULL },
|
|
|
|
{ UCODE_S2DEX, D_80113070 },
|
2020-04-04 16:12:59 +00:00
|
|
|
};
|
2020-04-13 23:03:10 +00:00
|
|
|
// clang-format on
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
void Graph_FaultClient() {
|
2021-02-14 00:49:40 +00:00
|
|
|
void* nextFb = osViGetNextFramebuffer();
|
|
|
|
void* newFb = ((u32)SysCfb_GetFbPtr(0) != (u32)nextFb) ? SysCfb_GetFbPtr(0) : SysCfb_GetFbPtr(1);
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
osViSwapBuffer(newFb);
|
|
|
|
Fault_WaitForInput();
|
|
|
|
osViSwapBuffer(nextFb);
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void Graph_DisassembleUCode(Gfx* workBuf) {
|
2020-04-05 10:32:08 +00:00
|
|
|
UCodeDisas disassembler;
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
if (HREG(80) == 7 && HREG(81) != 0) {
|
2020-06-05 17:18:39 +00:00
|
|
|
UCodeDisas_Init(&disassembler);
|
2020-04-04 16:12:59 +00:00
|
|
|
disassembler.enableLog = HREG(83);
|
2020-06-05 17:18:39 +00:00
|
|
|
UCodeDisas_RegisterUCode(&disassembler, ARRAY_COUNT(D_8012D230), D_8012D230);
|
|
|
|
UCodeDisas_SetCurUCode(&disassembler, D_80155F50);
|
2021-02-14 00:49:40 +00:00
|
|
|
UCodeDisas_Disassemble(&disassembler, workBuf);
|
2020-04-05 10:32:08 +00:00
|
|
|
HREG(93) = disassembler.dlCnt;
|
|
|
|
HREG(84) = disassembler.tri2Cnt * 2 + disassembler.tri1Cnt + (disassembler.quadCnt * 2) + disassembler.lineCnt;
|
|
|
|
HREG(85) = disassembler.vtxCnt;
|
|
|
|
HREG(86) = disassembler.spvtxCnt;
|
|
|
|
HREG(87) = disassembler.tri1Cnt;
|
|
|
|
HREG(88) = disassembler.tri2Cnt;
|
|
|
|
HREG(89) = disassembler.quadCnt;
|
|
|
|
HREG(90) = disassembler.lineCnt;
|
|
|
|
HREG(91) = disassembler.syncErr;
|
|
|
|
HREG(92) = disassembler.loaducodeCnt;
|
2020-04-04 16:38:05 +00:00
|
|
|
if (HREG(82) == 1 || HREG(82) == 2) {
|
2020-04-05 10:32:08 +00:00
|
|
|
osSyncPrintf("vtx_cnt=%d\n", disassembler.vtxCnt);
|
|
|
|
osSyncPrintf("spvtx_cnt=%d\n", disassembler.spvtxCnt);
|
|
|
|
osSyncPrintf("tri1_cnt=%d\n", disassembler.tri1Cnt);
|
|
|
|
osSyncPrintf("tri2_cnt=%d\n", disassembler.tri2Cnt);
|
|
|
|
osSyncPrintf("quad_cnt=%d\n", disassembler.quadCnt);
|
|
|
|
osSyncPrintf("line_cnt=%d\n", disassembler.lineCnt);
|
|
|
|
osSyncPrintf("sync_err=%d\n", disassembler.syncErr);
|
|
|
|
osSyncPrintf("loaducode_cnt=%d\n", disassembler.loaducodeCnt);
|
|
|
|
osSyncPrintf("dl_depth=%d\n", disassembler.dlDepth);
|
|
|
|
osSyncPrintf("dl_cnt=%d\n", disassembler.dlCnt);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
2020-06-05 17:18:39 +00:00
|
|
|
UCodeDisas_Destroy(&disassembler);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void Graph_UCodeFaultClient(Gfx* workBuf) {
|
2020-04-05 10:32:08 +00:00
|
|
|
UCodeDisas disassembler;
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-06-05 17:18:39 +00:00
|
|
|
UCodeDisas_Init(&disassembler);
|
2020-04-04 16:12:59 +00:00
|
|
|
disassembler.enableLog = true;
|
2020-06-05 17:18:39 +00:00
|
|
|
UCodeDisas_RegisterUCode(&disassembler, ARRAY_COUNT(D_8012D248), D_8012D248);
|
|
|
|
UCodeDisas_SetCurUCode(&disassembler, D_80155F50);
|
2021-02-14 00:49:40 +00:00
|
|
|
UCodeDisas_Disassemble(&disassembler, workBuf);
|
2020-06-05 17:18:39 +00:00
|
|
|
UCodeDisas_Destroy(&disassembler);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-12 11:02:45 +00:00
|
|
|
void Graph_InitTHGA(GraphicsContext* gfxCtx) {
|
2021-02-14 00:49:40 +00:00
|
|
|
GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIdx & 1];
|
2020-04-04 16:12:59 +00:00
|
|
|
|
|
|
|
pool->headMagic = GFXPOOL_HEAD_MAGIC;
|
|
|
|
pool->tailMagic = GFXPOOL_TAIL_MAGIC;
|
|
|
|
THGA_Ct(&gfxCtx->polyOpa, pool->polyOpaBuffer, sizeof(pool->polyOpaBuffer));
|
|
|
|
THGA_Ct(&gfxCtx->polyXlu, pool->polyXluBuffer, sizeof(pool->polyXluBuffer));
|
|
|
|
THGA_Ct(&gfxCtx->overlay, pool->overlayBuffer, sizeof(pool->overlayBuffer));
|
|
|
|
THGA_Ct(&gfxCtx->work, pool->workBuffer, sizeof(pool->workBuffer));
|
|
|
|
|
|
|
|
gfxCtx->polyOpaBuffer = pool->polyOpaBuffer;
|
|
|
|
gfxCtx->polyXluBuffer = pool->polyXluBuffer;
|
|
|
|
gfxCtx->overlayBuffer = pool->overlayBuffer;
|
|
|
|
gfxCtx->workBuffer = pool->workBuffer;
|
|
|
|
|
|
|
|
gfxCtx->curFrameBuffer = (u16*)SysCfb_GetFbPtr(gfxCtx->fbIdx % 2);
|
|
|
|
gfxCtx->unk_014 = 0;
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
GameStateOverlay* Graph_GetNextGameState(GameState* gameState) {
|
2021-02-14 00:49:40 +00:00
|
|
|
void* gameStateInitFunc = GameState_GetInit(gameState);
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-05 10:32:08 +00:00
|
|
|
if (gameStateInitFunc == TitleSetup_Init) {
|
2020-04-04 16:12:59 +00:00
|
|
|
return &gGameStateOverlayTable[0];
|
|
|
|
}
|
2020-06-14 02:59:58 +00:00
|
|
|
if (gameStateInitFunc == Select_Init) {
|
2020-04-04 16:12:59 +00:00
|
|
|
return &gGameStateOverlayTable[1];
|
|
|
|
}
|
2020-04-05 10:32:08 +00:00
|
|
|
if (gameStateInitFunc == Title_Init) {
|
2020-04-04 16:12:59 +00:00
|
|
|
return &gGameStateOverlayTable[2];
|
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
if (gameStateInitFunc == Gameplay_Init) {
|
2020-04-04 16:12:59 +00:00
|
|
|
return &gGameStateOverlayTable[3];
|
|
|
|
}
|
2020-04-05 10:32:08 +00:00
|
|
|
if (gameStateInitFunc == Opening_Init) {
|
2020-04-04 16:12:59 +00:00
|
|
|
return &gGameStateOverlayTable[4];
|
|
|
|
}
|
2020-04-05 10:32:08 +00:00
|
|
|
if (gameStateInitFunc == func_80811A20) {
|
2020-04-04 16:12:59 +00:00
|
|
|
return &gGameStateOverlayTable[5];
|
|
|
|
}
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-04-05 10:32:08 +00:00
|
|
|
LOG_ADDRESS("game_init_func", gameStateInitFunc, "../graph.c", 696);
|
2020-04-04 16:12:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-05 10:32:08 +00:00
|
|
|
void Graph_Init(GraphicsContext* gfxCtx) {
|
2020-04-04 16:12:59 +00:00
|
|
|
bzero(gfxCtx, sizeof(GraphicsContext));
|
|
|
|
gfxCtx->gfxPoolIdx = 0;
|
|
|
|
gfxCtx->fbIdx = 0;
|
|
|
|
gfxCtx->viMode = NULL;
|
|
|
|
gfxCtx->viFeatures = gViConfigFeatures;
|
|
|
|
gfxCtx->xScale = gViConfigXScale;
|
|
|
|
gfxCtx->yScale = gViConfigYScale;
|
|
|
|
osCreateMesgQueue(&gfxCtx->queue, gfxCtx->msgBuff, ARRAY_COUNT(gfxCtx->msgBuff));
|
|
|
|
func_800D31F0();
|
|
|
|
Fault_AddClient(&sGraphFaultClient, Graph_FaultClient, 0, 0);
|
|
|
|
}
|
|
|
|
|
2020-04-05 10:32:08 +00:00
|
|
|
void Graph_Destroy(GraphicsContext* gfxCtx) {
|
2020-04-04 16:12:59 +00:00
|
|
|
func_800D3210();
|
|
|
|
Fault_RemoveClient(&sGraphFaultClient);
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
void Graph_TaskSet00(GraphicsContext* gfxCtx) {
|
2021-02-14 00:49:40 +00:00
|
|
|
static Gfx* D_8012D260 = NULL;
|
2020-04-04 16:12:59 +00:00
|
|
|
static s32 sGraphCfbInfoIdx = 0;
|
|
|
|
|
2020-08-16 21:59:55 +00:00
|
|
|
OSTime time;
|
2020-04-04 16:12:59 +00:00
|
|
|
OSTimer timer;
|
|
|
|
OSMesg msg;
|
2021-02-14 00:49:40 +00:00
|
|
|
OSTask_t* task = &gfxCtx->task.list.t;
|
|
|
|
OSScTask* scTask = &gfxCtx->task;
|
2020-04-04 16:12:59 +00:00
|
|
|
CfbInfo* cfb;
|
2020-08-16 21:59:55 +00:00
|
|
|
s32 pad1;
|
2020-04-04 16:12:59 +00:00
|
|
|
|
|
|
|
D_8016A528 = osGetTime() - sGraphSetTaskTime - D_8016A558;
|
|
|
|
|
2021-10-03 03:17:09 +00:00
|
|
|
osSetTimer(&timer, OS_USEC_TO_CYCLES(3000000), 0, &gfxCtx->queue, (OSMesg)666);
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-08-16 21:59:55 +00:00
|
|
|
osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_BLOCK);
|
2020-04-04 16:12:59 +00:00
|
|
|
osStopTimer(&timer);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
if (msg == (OSMesg)666) {
|
2020-04-04 16:12:59 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
|
|
|
osSyncPrintf("RCPが帰ってきませんでした。"); // "RCP did not return."
|
|
|
|
osSyncPrintf(VT_RST);
|
2021-02-14 00:49:40 +00:00
|
|
|
LogUtils_LogHexDump((void*)&HW_REG(SP_MEM_ADDR_REG, u32), 0x20);
|
|
|
|
LogUtils_LogHexDump((void*)&DPC_START_REG, 0x20);
|
2020-04-04 16:12:59 +00:00
|
|
|
LogUtils_LogHexDump(gGfxSPTaskYieldBuffer, sizeof(gGfxSPTaskYieldBuffer));
|
|
|
|
|
|
|
|
SREG(6) = -1;
|
2020-08-16 21:59:55 +00:00
|
|
|
if (D_8012D260 != 0) {
|
2020-04-04 16:12:59 +00:00
|
|
|
HREG(80) = 7;
|
|
|
|
HREG(81) = 1;
|
2020-08-16 21:59:55 +00:00
|
|
|
HREG(83) = 2;
|
|
|
|
D_8012D260 = D_8012D260;
|
|
|
|
Graph_DisassembleUCode(D_8012D260);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
Fault_AddHungupAndCrashImpl("RCP is HUNG UP!!", "Oh! MY GOD!!");
|
|
|
|
}
|
2020-08-16 21:59:55 +00:00
|
|
|
|
|
|
|
osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_NOBLOCK);
|
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
D_8012D260 = gfxCtx->workBuffer;
|
2020-08-16 21:59:55 +00:00
|
|
|
if (gfxCtx->callback != NULL) {
|
2020-04-04 16:12:59 +00:00
|
|
|
gfxCtx->callback(gfxCtx, gfxCtx->callbackParam);
|
2020-04-04 16:38:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
time = osGetTime();
|
2020-08-16 21:59:55 +00:00
|
|
|
if (D_8016A550 != 0) {
|
2020-04-04 16:12:59 +00:00
|
|
|
D_8016A558 = (D_8016A558 + time) - D_8016A550;
|
|
|
|
D_8016A550 = time;
|
|
|
|
}
|
|
|
|
D_8016A520 = D_8016A558;
|
|
|
|
D_8016A558 = 0;
|
|
|
|
sGraphSetTaskTime = osGetTime();
|
|
|
|
|
|
|
|
task->type = M_GFXTASK;
|
|
|
|
task->flags = OS_SC_DRAM_DLIST;
|
|
|
|
task->ucode_boot = SysUcode_GetUCodeBoot();
|
2020-04-13 23:03:10 +00:00
|
|
|
task->ucode_boot_size = SysUcode_GetUCodeBootSize();
|
|
|
|
task->ucode = SysUcode_GetUCode();
|
|
|
|
task->ucode_data = SysUcode_GetUCodeData();
|
2020-04-04 16:12:59 +00:00
|
|
|
task->ucode_size = 0x1000;
|
|
|
|
task->ucode_data_size = 0x800;
|
2020-08-16 21:59:55 +00:00
|
|
|
task->dram_stack = (u64*)gGfxSPTaskStack;
|
2020-04-04 16:12:59 +00:00
|
|
|
task->dram_stack_size = sizeof(gGfxSPTaskStack);
|
|
|
|
task->output_buff = gGfxSPTaskOutputBuffer;
|
2020-08-16 21:59:55 +00:00
|
|
|
task->output_buff_size = (u64*)((u8*)gGfxSPTaskOutputBuffer + sizeof(gGfxSPTaskOutputBuffer));
|
|
|
|
task->data_ptr = (u64*)gfxCtx->workBuffer;
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../graph.c", 828);
|
2020-10-29 21:31:09 +00:00
|
|
|
task->data_size = (u32)WORK_DISP - (u32)gfxCtx->workBuffer;
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../graph.c", 830);
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-08-16 21:59:55 +00:00
|
|
|
{ s32 pad2; } // Necessary to match stack usage
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-08-16 21:59:55 +00:00
|
|
|
task->yield_data_ptr = (u64*)gGfxSPTaskYieldBuffer;
|
2020-04-04 16:12:59 +00:00
|
|
|
task->yield_data_size = sizeof(gGfxSPTaskYieldBuffer);
|
|
|
|
|
|
|
|
scTask->next = NULL;
|
|
|
|
scTask->flags = OS_SC_RCP_MASK | OS_SC_SWAPBUFFER | OS_SC_LAST_TASK;
|
2020-04-04 16:38:05 +00:00
|
|
|
if (SREG(33) & 1) {
|
2020-04-04 16:12:59 +00:00
|
|
|
SREG(33) &= ~1;
|
|
|
|
scTask->flags &= ~OS_SC_SWAPBUFFER;
|
|
|
|
gfxCtx->fbIdx--;
|
|
|
|
}
|
|
|
|
|
2020-08-16 21:59:55 +00:00
|
|
|
scTask->msgQ = &gfxCtx->queue;
|
2020-04-04 16:12:59 +00:00
|
|
|
scTask->msg = NULL;
|
|
|
|
|
2020-08-16 21:59:55 +00:00
|
|
|
cfb = &sGraphCfbInfos[sGraphCfbInfoIdx++];
|
2020-04-04 16:12:59 +00:00
|
|
|
cfb->fb1 = gfxCtx->curFrameBuffer;
|
2020-05-26 15:39:27 +00:00
|
|
|
cfb->swapBuffer = gfxCtx->curFrameBuffer;
|
2020-04-04 16:12:59 +00:00
|
|
|
cfb->viMode = gfxCtx->viMode;
|
|
|
|
cfb->features = gfxCtx->viFeatures;
|
|
|
|
cfb->xScale = gfxCtx->xScale;
|
|
|
|
cfb->yScale = gfxCtx->yScale;
|
|
|
|
cfb->unk_10 = 0;
|
|
|
|
cfb->updateRate = R_UPDATE_RATE;
|
|
|
|
|
|
|
|
scTask->framebuffer = cfb;
|
|
|
|
sGraphCfbInfoIdx = sGraphCfbInfoIdx % ARRAY_COUNT(sGraphCfbInfos);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
|
|
|
if (1) {}
|
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
gfxCtx->schedMsgQ = &gSchedContext.cmdQ;
|
|
|
|
|
|
|
|
osSendMesg(&gSchedContext.cmdQ, scTask, OS_MESG_BLOCK);
|
2020-08-16 21:59:55 +00:00
|
|
|
Sched_SendEntryMsg(&gSchedContext);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
2020-08-16 21:59:55 +00:00
|
|
|
u32 problem;
|
2020-04-04 16:12:59 +00:00
|
|
|
|
|
|
|
gameState->unk_A0 = 0;
|
|
|
|
Graph_InitTHGA(gfxCtx);
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../graph.c", 966);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gDPNoOpString(WORK_DISP++, "WORK_DISP 開始", 0);
|
|
|
|
gDPNoOpString(POLY_OPA_DISP++, "POLY_OPA_DISP 開始", 0);
|
|
|
|
gDPNoOpString(POLY_XLU_DISP++, "POLY_XLU_DISP 開始", 0);
|
|
|
|
gDPNoOpString(OVERLAY_DISP++, "OVERLAY_DISP 開始", 0);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../graph.c", 975);
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
GameState_ReqPadData(gameState);
|
|
|
|
GameState_Update(gameState);
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../graph.c", 987);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gDPNoOpString(WORK_DISP++, "WORK_DISP 終了", 0);
|
|
|
|
gDPNoOpString(POLY_OPA_DISP++, "POLY_OPA_DISP 終了", 0);
|
|
|
|
gDPNoOpString(POLY_XLU_DISP++, "POLY_XLU_DISP 終了", 0);
|
|
|
|
gDPNoOpString(OVERLAY_DISP++, "OVERLAY_DISP 終了", 0);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../graph.c", 996);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../graph.c", 999);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPBranchList(WORK_DISP++, gfxCtx->polyOpaBuffer);
|
|
|
|
gSPBranchList(POLY_OPA_DISP++, gfxCtx->polyXluBuffer);
|
|
|
|
gSPBranchList(POLY_XLU_DISP++, gfxCtx->overlayBuffer);
|
|
|
|
gDPPipeSync(OVERLAY_DISP++);
|
|
|
|
gDPFullSync(OVERLAY_DISP++);
|
|
|
|
gSPEndDisplayList(OVERLAY_DISP++);
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../graph.c", 1028);
|
2020-04-04 16:12:59 +00:00
|
|
|
|
|
|
|
if (HREG(80) == 10 && HREG(93) == 2) {
|
|
|
|
HREG(80) = 7;
|
|
|
|
HREG(81) = -1;
|
|
|
|
HREG(83) = HREG(92);
|
|
|
|
}
|
2020-08-16 21:59:55 +00:00
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
if (HREG(80) == 7 && HREG(81) != 0) {
|
|
|
|
if (HREG(82) == 3) {
|
|
|
|
Fault_AddClient(&sGraphUcodeFaultClient, Graph_UCodeFaultClient, gfxCtx->workBuffer, "do_count_fault");
|
|
|
|
}
|
|
|
|
|
|
|
|
Graph_DisassembleUCode(gfxCtx->workBuffer);
|
|
|
|
|
|
|
|
if (HREG(82) == 3) {
|
|
|
|
Fault_RemoveClient(&sGraphUcodeFaultClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HREG(81) < 0) {
|
2021-02-14 00:49:40 +00:00
|
|
|
LogUtils_LogHexDump((void*)&HW_REG(SP_MEM_ADDR_REG, u32), 0x20);
|
|
|
|
LogUtils_LogHexDump((void*)&DPC_START_REG, 0x20);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (HREG(81) < 0) {
|
|
|
|
HREG(81) = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
problem = false;
|
2020-08-16 21:59:55 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIdx & 1];
|
|
|
|
|
|
|
|
if (pool->headMagic != GFXPOOL_HEAD_MAGIC) {
|
2021-10-03 03:17:09 +00:00
|
|
|
//! @bug (?) : "problem = true;" may be missing
|
2020-08-16 21:59:55 +00:00
|
|
|
osSyncPrintf("%c", 7);
|
2021-09-28 23:53:56 +00:00
|
|
|
// "Dynamic area head is destroyed"
|
2020-08-16 21:59:55 +00:00
|
|
|
osSyncPrintf(VT_COL(RED, WHITE) "ダイナミック領域先頭が破壊されています\n" VT_RST);
|
|
|
|
Fault_AddHungupAndCrash("../graph.c", 1070);
|
|
|
|
}
|
|
|
|
if (pool->tailMagic != GFXPOOL_TAIL_MAGIC) {
|
|
|
|
problem = true;
|
|
|
|
osSyncPrintf("%c", 7);
|
2021-09-28 23:53:56 +00:00
|
|
|
// "Dynamic region tail is destroyed"
|
2020-08-16 21:59:55 +00:00
|
|
|
osSyncPrintf(VT_COL(RED, WHITE) "ダイナミック領域末尾が破壊されています\n" VT_RST);
|
|
|
|
Fault_AddHungupAndCrash("../graph.c", 1076);
|
|
|
|
}
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
if (THGA_IsCrash(&gfxCtx->polyOpa)) {
|
|
|
|
problem = true;
|
|
|
|
osSyncPrintf("%c", 7);
|
2021-09-28 23:53:56 +00:00
|
|
|
// "Zelda 0 is dead"
|
2020-04-04 16:12:59 +00:00
|
|
|
osSyncPrintf(VT_COL(RED, WHITE) "ゼルダ0は死んでしまった(graph_alloc is empty)\n" VT_RST);
|
|
|
|
}
|
|
|
|
if (THGA_IsCrash(&gfxCtx->polyXlu)) {
|
|
|
|
problem = true;
|
|
|
|
osSyncPrintf("%c", 7);
|
2021-09-28 23:53:56 +00:00
|
|
|
// "Zelda 1 is dead"
|
2020-04-04 16:12:59 +00:00
|
|
|
osSyncPrintf(VT_COL(RED, WHITE) "ゼルダ1は死んでしまった(graph_alloc is empty)\n" VT_RST);
|
|
|
|
}
|
|
|
|
if (THGA_IsCrash(&gfxCtx->overlay)) {
|
|
|
|
problem = true;
|
|
|
|
osSyncPrintf("%c", 7);
|
2021-09-28 23:53:56 +00:00
|
|
|
// "Zelda 4 is dead"
|
2020-04-04 16:12:59 +00:00
|
|
|
osSyncPrintf(VT_COL(RED, WHITE) "ゼルダ4は死んでしまった(graph_alloc is empty)\n" VT_RST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!problem) {
|
|
|
|
Graph_TaskSet00(gfxCtx);
|
|
|
|
gfxCtx->gfxPoolIdx++;
|
|
|
|
gfxCtx->fbIdx++;
|
|
|
|
}
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2021-08-19 22:10:51 +00:00
|
|
|
func_800F3054();
|
2020-08-16 21:59:55 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
OSTime time = osGetTime();
|
|
|
|
s32 pad[4];
|
|
|
|
|
|
|
|
D_8016A538 = gRSPGFXTotalTime;
|
|
|
|
D_8016A530 = gRSPAudioTotalTime;
|
|
|
|
D_8016A540 = gRDPTotalTime;
|
|
|
|
gRSPGFXTotalTime = 0;
|
|
|
|
gRSPAudioTotalTime = 0;
|
|
|
|
gRDPTotalTime = 0;
|
|
|
|
|
|
|
|
if (sGraphUpdateTime != 0) {
|
|
|
|
D_8016A548 = time - sGraphUpdateTime;
|
|
|
|
}
|
|
|
|
sGraphUpdateTime = time;
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
if (D_8012DBC0 && CHECK_BTN_ALL(gameState->input[0].press.button, BTN_Z) &&
|
|
|
|
CHECK_BTN_ALL(gameState->input[0].cur.button, BTN_L | BTN_R)) {
|
2020-04-16 21:36:12 +00:00
|
|
|
gSaveContext.gameMode = 0;
|
2020-06-14 02:59:58 +00:00
|
|
|
SET_NEXT_GAMESTATE(gameState, Select_Init, SelectContext);
|
2020-04-04 16:12:59 +00:00
|
|
|
gameState->running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (D_8012DBC0 && PreNmiBuff_IsResetting(gAppNmiBufferPtr) && !gameState->unk_A0) {
|
2021-09-28 23:53:56 +00:00
|
|
|
// "To reset mode"
|
2020-04-04 16:12:59 +00:00
|
|
|
osSyncPrintf(VT_COL(YELLOW, BLACK) "PRE-NMIによりリセットモードに移行します\n" VT_RST);
|
|
|
|
SET_NEXT_GAMESTATE(gameState, PreNMI_Init, PreNMIContext);
|
|
|
|
gameState->running = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
void Graph_ThreadEntry(void* arg0) {
|
2020-04-04 16:12:59 +00:00
|
|
|
GraphicsContext gfxCtx;
|
|
|
|
GameState* gameState;
|
|
|
|
u32 size;
|
|
|
|
GameStateOverlay* nextOvl;
|
|
|
|
GameStateOverlay* ovl;
|
|
|
|
char faultMsg[0x50];
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
nextOvl = &gGameStateOverlayTable[0];
|
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("グラフィックスレッド実行開始\n"); // "Start graphic thread execution"
|
2020-04-05 10:32:08 +00:00
|
|
|
Graph_Init(&gfxCtx);
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
while (nextOvl) {
|
2020-04-04 16:12:59 +00:00
|
|
|
ovl = nextOvl;
|
|
|
|
Overlay_LoadGameState(ovl);
|
|
|
|
|
|
|
|
size = ovl->instanceSize;
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("クラスサイズ=%dバイト\n", size); // "Class size = %d bytes"
|
2020-04-04 16:12:59 +00:00
|
|
|
|
|
|
|
gameState = SystemArena_MallocDebug(size, "../graph.c", 1196);
|
2020-04-04 16:38:05 +00:00
|
|
|
|
|
|
|
if (!gameState) {
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("確保失敗\n"); // "Failure to secure"
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
sprintf(faultMsg, "CLASS SIZE= %d bytes", size);
|
|
|
|
Fault_AddHungupAndCrashImpl("GAME CLASS MALLOC FAILED", faultMsg);
|
|
|
|
}
|
2020-05-14 23:11:33 +00:00
|
|
|
GameState_Init(gameState, ovl->init, &gfxCtx);
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
while (GameState_IsRunning(gameState)) {
|
2020-04-04 16:12:59 +00:00
|
|
|
Graph_Update(&gfxCtx, gameState);
|
|
|
|
}
|
|
|
|
|
|
|
|
nextOvl = Graph_GetNextGameState(gameState);
|
2020-05-14 23:11:33 +00:00
|
|
|
GameState_Destroy(gameState);
|
2020-04-04 16:12:59 +00:00
|
|
|
SystemArena_FreeDebug(gameState, "../graph.c", 1227);
|
|
|
|
Overlay_FreeGameState(ovl);
|
|
|
|
}
|
2020-04-05 10:32:08 +00:00
|
|
|
Graph_Destroy(&gfxCtx);
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("グラフィックスレッド実行終了\n"); // "End of graphic thread execution"
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
void* Graph_Alloc(GraphicsContext* gfxCtx, size_t size) {
|
2020-04-04 16:12:59 +00:00
|
|
|
TwoHeadGfxArena* thga = &gfxCtx->polyOpa;
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
if (HREG(59) == 1) {
|
|
|
|
osSyncPrintf("graph_alloc siz=%d thga size=%08x bufp=%08x head=%08x tail=%08x\n", size, thga->size, thga->bufp,
|
|
|
|
thga->p, thga->d);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
return THGA_AllocEnd(&gfxCtx->polyOpa, ALIGN16(size));
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size) {
|
2020-04-04 16:12:59 +00:00
|
|
|
TwoHeadGfxArena* thga = &gfxCtx->polyOpa;
|
2020-04-04 16:38:05 +00:00
|
|
|
|
|
|
|
if (HREG(59) == 1) {
|
|
|
|
osSyncPrintf("graph_alloc siz=%d thga size=%08x bufp=%08x head=%08x tail=%08x\n", size, thga->size, thga->bufp,
|
|
|
|
thga->p, thga->d);
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
return THGA_AllocEnd(&gfxCtx->polyOpa, ALIGN16(size));
|
|
|
|
}
|
|
|
|
|
2020-04-05 17:29:30 +00:00
|
|
|
void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) {
|
2020-04-04 16:38:05 +00:00
|
|
|
if (HREG(80) == 7 && HREG(82) != 4) {
|
2020-04-05 17:29:30 +00:00
|
|
|
dispRefs[0] = gfxCtx->polyOpa.p;
|
|
|
|
dispRefs[1] = gfxCtx->polyXlu.p;
|
|
|
|
dispRefs[2] = gfxCtx->overlay.p;
|
2020-04-04 16:38:05 +00:00
|
|
|
|
2020-04-04 16:12:59 +00:00
|
|
|
gDPNoOpOpenDisp(gfxCtx->polyOpa.p++, file, line);
|
|
|
|
gDPNoOpOpenDisp(gfxCtx->polyXlu.p++, file, line);
|
|
|
|
gDPNoOpOpenDisp(gfxCtx->overlay.p++, file, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 17:29:30 +00:00
|
|
|
void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) {
|
2020-04-04 16:38:05 +00:00
|
|
|
if (HREG(80) == 7 && HREG(82) != 4) {
|
2020-04-05 17:29:30 +00:00
|
|
|
if (dispRefs[0] + 1 == gfxCtx->polyOpa.p) {
|
|
|
|
gfxCtx->polyOpa.p = dispRefs[0];
|
2020-04-04 16:38:05 +00:00
|
|
|
} else {
|
2020-04-04 16:12:59 +00:00
|
|
|
gDPNoOpCloseDisp(gfxCtx->polyOpa.p++, file, line);
|
2020-04-04 16:38:05 +00:00
|
|
|
}
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-05 17:29:30 +00:00
|
|
|
if (dispRefs[1] + 1 == gfxCtx->polyXlu.p) {
|
|
|
|
gfxCtx->polyXlu.p = dispRefs[1];
|
2020-04-04 16:38:05 +00:00
|
|
|
} else {
|
2020-04-04 16:12:59 +00:00
|
|
|
gDPNoOpCloseDisp(gfxCtx->polyXlu.p++, file, line);
|
2020-04-04 16:38:05 +00:00
|
|
|
}
|
2020-04-04 16:12:59 +00:00
|
|
|
|
2020-04-05 17:29:30 +00:00
|
|
|
if (dispRefs[2] + 1 == gfxCtx->overlay.p) {
|
|
|
|
gfxCtx->overlay.p = dispRefs[2];
|
2020-04-04 16:38:05 +00:00
|
|
|
} else {
|
2020-04-04 16:12:59 +00:00
|
|
|
gDPNoOpCloseDisp(gfxCtx->overlay.p++, file, line);
|
2020-04-04 16:38:05 +00:00
|
|
|
}
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
Gfx* Graph_GfxPlusOne(Gfx* gfx) {
|
|
|
|
return gfx + 1;
|
2020-04-04 16:12:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
Gfx* Graph_BranchDlist(Gfx* gfx, Gfx* dst) {
|
2020-04-04 16:12:59 +00:00
|
|
|
gSPBranchList(gfx, dst);
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:38:05 +00:00
|
|
|
void* Graph_DlistAlloc(Gfx** gfx, u32 size) {
|
2020-04-04 16:12:59 +00:00
|
|
|
u8* ptr;
|
|
|
|
Gfx* dst;
|
|
|
|
|
|
|
|
size = ((size + 7) & ~7),
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
ptr = (u8*)(*gfx + 1);
|
2020-04-04 16:12:59 +00:00
|
|
|
|
|
|
|
dst = (Gfx*)(ptr + size);
|
|
|
|
gSPBranchList(*gfx, dst);
|
|
|
|
|
|
|
|
*gfx = dst;
|
|
|
|
return ptr;
|
|
|
|
}
|