2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-05-14 23:11:33 +00:00
|
|
|
#include "vt.h"
|
|
|
|
|
|
|
|
SpeedMeter D_801664D0;
|
|
|
|
struct_801664F0 D_801664F0;
|
2020-05-15 09:02:39 +00:00
|
|
|
struct_80166500 D_80166500;
|
|
|
|
VisMono sMonoColors;
|
2021-05-04 01:49:09 +00:00
|
|
|
ViMode sViMode;
|
2020-05-14 23:11:33 +00:00
|
|
|
FaultClient sGameFaultClient;
|
|
|
|
u16 sLastButtonPressed;
|
|
|
|
|
|
|
|
void GameState_FaultPrint(void) {
|
2020-07-18 09:55:35 +00:00
|
|
|
static char sBtnChars[] = "ABZSuldr*+LRudlr";
|
2020-05-14 23:11:33 +00:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
osSyncPrintf("last_button=%04x\n", sLastButtonPressed);
|
|
|
|
FaultDrawer_DrawText(120, 180, "%08x", sLastButtonPressed);
|
|
|
|
for (i = 0; i < ARRAY_COUNT(sBtnChars); i++) {
|
|
|
|
if (sLastButtonPressed & (1 << i)) {
|
2022-02-02 21:43:34 +00:00
|
|
|
FaultDrawer_DrawText((i * 8) + 120, 190, "%c", sBtnChars[i]);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_SetFBFilter(Gfx** gfx) {
|
2022-06-24 23:45:05 +00:00
|
|
|
Gfx* gfxP = *gfx;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
if ((R_FB_FILTER_TYPE > 0) && (R_FB_FILTER_TYPE < 5)) {
|
|
|
|
D_801664F0.type = R_FB_FILTER_TYPE;
|
|
|
|
D_801664F0.color.r = R_FB_FILTER_PRIM_COLOR(0);
|
|
|
|
D_801664F0.color.g = R_FB_FILTER_PRIM_COLOR(1);
|
|
|
|
D_801664F0.color.b = R_FB_FILTER_PRIM_COLOR(2);
|
|
|
|
D_801664F0.color.a = R_FB_FILTER_A;
|
|
|
|
func_800ACE98(&D_801664F0, &gfxP);
|
|
|
|
} else if ((R_FB_FILTER_TYPE == 5) || (R_FB_FILTER_TYPE == 6)) {
|
2020-05-15 09:02:39 +00:00
|
|
|
D_80166500.useRgba = (R_FB_FILTER_TYPE == 6);
|
|
|
|
D_80166500.primColor.r = R_FB_FILTER_PRIM_COLOR(0);
|
|
|
|
D_80166500.primColor.g = R_FB_FILTER_PRIM_COLOR(1);
|
|
|
|
D_80166500.primColor.b = R_FB_FILTER_PRIM_COLOR(2);
|
|
|
|
D_80166500.primColor.a = R_FB_FILTER_A;
|
2020-05-14 23:11:33 +00:00
|
|
|
D_80166500.envColor.r = R_FB_FILTER_ENV_COLOR(0);
|
|
|
|
D_80166500.envColor.g = R_FB_FILTER_ENV_COLOR(1);
|
|
|
|
D_80166500.envColor.b = R_FB_FILTER_ENV_COLOR(2);
|
|
|
|
D_80166500.envColor.a = R_FB_FILTER_A;
|
|
|
|
func_800AD958(&D_80166500, &gfxP);
|
|
|
|
} else if (R_FB_FILTER_TYPE == 7) {
|
2020-05-15 09:02:39 +00:00
|
|
|
sMonoColors.unk_00 = 0;
|
2020-05-14 23:11:33 +00:00
|
|
|
sMonoColors.primColor.r = R_FB_FILTER_PRIM_COLOR(0);
|
|
|
|
sMonoColors.primColor.g = R_FB_FILTER_PRIM_COLOR(1);
|
|
|
|
sMonoColors.primColor.b = R_FB_FILTER_PRIM_COLOR(2);
|
|
|
|
sMonoColors.primColor.a = R_FB_FILTER_A;
|
|
|
|
sMonoColors.envColor.r = R_FB_FILTER_ENV_COLOR(0);
|
|
|
|
sMonoColors.envColor.g = R_FB_FILTER_ENV_COLOR(1);
|
|
|
|
sMonoColors.envColor.b = R_FB_FILTER_ENV_COLOR(2);
|
|
|
|
sMonoColors.envColor.a = R_FB_FILTER_A;
|
2020-05-15 09:02:39 +00:00
|
|
|
VisMono_Draw(&sMonoColors, &gfxP);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
*gfx = gfxP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void func_800C4344(GameState* gameState) {
|
|
|
|
Input* selectedInput;
|
|
|
|
s32 hexDumpSize;
|
|
|
|
u16 hReg82;
|
|
|
|
|
|
|
|
if (HREG(80) == 0x14) {
|
|
|
|
__osMalloc_FreeBlockTest_Enable = HREG(82);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HREG(80) == 0xC) {
|
2021-02-14 00:49:40 +00:00
|
|
|
selectedInput = &gameState->input[(u32)HREG(81) < 4U ? HREG(81) : 0];
|
2020-05-14 23:11:33 +00:00
|
|
|
hReg82 = HREG(82);
|
2020-10-03 15:22:44 +00:00
|
|
|
HREG(83) = selectedInput->cur.button;
|
|
|
|
HREG(84) = selectedInput->press.button;
|
|
|
|
HREG(85) = selectedInput->rel.stick_x;
|
|
|
|
HREG(86) = selectedInput->rel.stick_y;
|
|
|
|
HREG(87) = selectedInput->rel.stick_x;
|
|
|
|
HREG(88) = selectedInput->rel.stick_y;
|
|
|
|
HREG(89) = selectedInput->cur.stick_x;
|
|
|
|
HREG(90) = selectedInput->cur.stick_y;
|
|
|
|
HREG(93) = (selectedInput->cur.button == hReg82);
|
|
|
|
HREG(94) = CHECK_BTN_ALL(selectedInput->cur.button, hReg82);
|
|
|
|
HREG(95) = CHECK_BTN_ALL(selectedInput->press.button, hReg82);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 14:17:48 +00:00
|
|
|
if (gIsCtrlr2Valid) {
|
2020-05-14 23:11:33 +00:00
|
|
|
func_8006390C(&gameState->input[1]);
|
|
|
|
}
|
|
|
|
|
2022-03-10 20:21:46 +00:00
|
|
|
gDmaMgrVerbose = HREG(60);
|
2020-05-14 23:11:33 +00:00
|
|
|
gDmaMgrDmaBuffSize = SREG(21) != 0 ? ALIGN16(SREG(21)) : 0x2000;
|
|
|
|
gSystemArenaLogSeverity = HREG(61);
|
|
|
|
gZeldaArenaLogSeverity = HREG(62);
|
|
|
|
if (HREG(80) == 8) {
|
|
|
|
if (HREG(94) != 8) {
|
|
|
|
HREG(94) = 8;
|
|
|
|
HREG(81) = 0;
|
|
|
|
HREG(82) = 0;
|
|
|
|
HREG(83) = 0;
|
|
|
|
}
|
|
|
|
if (HREG(81) < 0) {
|
|
|
|
HREG(81) = 0;
|
|
|
|
// & 0xFFFFFFFF necessary for matching.
|
|
|
|
hexDumpSize = (HREG(83) == 0 ? 0x100 : HREG(83) * 0x10) & 0xFFFFFFFF;
|
|
|
|
LogUtils_LogHexDump(PHYSICAL_TO_VIRTUAL(HREG(82) << 8), hexDumpSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_DrawInputDisplay(u16 input, Gfx** gfx) {
|
|
|
|
static const u16 sInpDispBtnColors[] = {
|
2020-07-17 01:37:53 +00:00
|
|
|
GPACK_RGBA5551(255, 255, 0, 1), GPACK_RGBA5551(255, 255, 0, 1), GPACK_RGBA5551(255, 255, 0, 1),
|
|
|
|
GPACK_RGBA5551(255, 255, 0, 1), GPACK_RGBA5551(120, 120, 120, 1), GPACK_RGBA5551(120, 120, 120, 1),
|
|
|
|
GPACK_RGBA5551(0, 255, 255, 1), GPACK_RGBA5551(255, 0, 255, 1), GPACK_RGBA5551(120, 120, 120, 1),
|
|
|
|
GPACK_RGBA5551(120, 120, 120, 1), GPACK_RGBA5551(120, 120, 120, 1), GPACK_RGBA5551(120, 120, 120, 1),
|
|
|
|
GPACK_RGBA5551(255, 0, 0, 1), GPACK_RGBA5551(120, 120, 120, 1), GPACK_RGBA5551(0, 255, 0, 1),
|
|
|
|
GPACK_RGBA5551(0, 0, 255, 1),
|
2020-05-14 23:11:33 +00:00
|
|
|
};
|
2020-06-14 03:29:59 +00:00
|
|
|
s32 i, j, k;
|
2020-05-14 23:11:33 +00:00
|
|
|
Gfx* gfxP = *gfx;
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
gDPPipeSync(gfxP++);
|
|
|
|
gDPSetOtherMode(gfxP++,
|
|
|
|
G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
|
|
|
|
G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE,
|
|
|
|
G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
j = i;
|
2020-05-14 23:11:33 +00:00
|
|
|
if (input & (1 << i)) {
|
|
|
|
gDPSetFillColor(gfxP++, (sInpDispBtnColors[i] << 0x10) | sInpDispBtnColors[i]);
|
2020-07-18 09:55:35 +00:00
|
|
|
k = i + 1;
|
2020-06-14 03:29:59 +00:00
|
|
|
gDPFillRectangle(gfxP++, (j * 4) + 226, 220, (k * 4) + 225, 223);
|
2020-05-14 23:11:33 +00:00
|
|
|
gDPPipeSync(gfxP++);
|
|
|
|
}
|
2020-07-18 09:55:35 +00:00
|
|
|
}
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
*gfx = gfxP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) {
|
|
|
|
Gfx* newDList;
|
|
|
|
Gfx* polyOpaP;
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../game.c", 746);
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
newDList = Graph_GfxPlusOne(polyOpaP = POLY_OPA_DISP);
|
|
|
|
gSPDisplayList(OVERLAY_DISP++, newDList);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
if (R_ENABLE_FB_FILTER == 1) {
|
|
|
|
GameState_SetFBFilter(&newDList);
|
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
sLastButtonPressed = gameState->input[0].press.button | gameState->input[0].cur.button;
|
2020-05-14 23:11:33 +00:00
|
|
|
if (R_DISABLE_INPUT_DISPLAY == 0) {
|
|
|
|
GameState_DrawInputDisplay(sLastButtonPressed, &newDList);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (R_ENABLE_AUDIO_DBG & 1) {
|
2020-08-29 23:00:17 +00:00
|
|
|
s32 pad;
|
|
|
|
GfxPrint printer;
|
|
|
|
|
|
|
|
GfxPrint_Init(&printer);
|
|
|
|
GfxPrint_Open(&printer, newDList);
|
2021-08-30 00:08:41 +00:00
|
|
|
AudioDebug_Draw(&printer);
|
2020-08-29 23:00:17 +00:00
|
|
|
newDList = GfxPrint_Close(&printer);
|
|
|
|
GfxPrint_Destroy(&printer);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (R_ENABLE_ARENA_DBG < 0) {
|
2020-08-29 23:00:17 +00:00
|
|
|
s32 pad;
|
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
DebugArena_Display();
|
|
|
|
SystemArena_Display();
|
2021-09-04 13:33:19 +00:00
|
|
|
// "%08x bytes left until the death of Hyrule (game_alloc)"
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf("ハイラル滅亡まであと %08x バイト(game_alloc)\n", THA_GetSize(&gameState->tha));
|
|
|
|
R_ENABLE_ARENA_DBG = 0;
|
|
|
|
}
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
gSPEndDisplayList(newDList++);
|
|
|
|
Graph_BranchDlist(polyOpaP, newDList);
|
2020-10-29 21:31:09 +00:00
|
|
|
POLY_OPA_DISP = newDList;
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
if (1) {}
|
|
|
|
|
|
|
|
CLOSE_DISPS(gfxCtx, "../game.c", 800);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
func_80063D7C(gfxCtx);
|
|
|
|
|
|
|
|
if (R_ENABLE_ARENA_DBG != 0) {
|
|
|
|
SpeedMeter_DrawTimeEntries(&D_801664D0, gfxCtx);
|
|
|
|
SpeedMeter_DrawAllocEntries(&D_801664D0, gfxCtx, gameState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_SetFrameBuffer(GraphicsContext* gfxCtx) {
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../game.c", 814);
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPSegment(POLY_OPA_DISP++, 0, 0);
|
|
|
|
gSPSegment(POLY_OPA_DISP++, 0xF, gfxCtx->curFrameBuffer);
|
|
|
|
gSPSegment(POLY_OPA_DISP++, 0xE, gZBuffer);
|
|
|
|
gSPSegment(POLY_XLU_DISP++, 0, 0);
|
|
|
|
gSPSegment(POLY_XLU_DISP++, 0xF, gfxCtx->curFrameBuffer);
|
|
|
|
gSPSegment(POLY_XLU_DISP++, 0xE, gZBuffer);
|
|
|
|
gSPSegment(OVERLAY_DISP++, 0, 0);
|
|
|
|
gSPSegment(OVERLAY_DISP++, 0xF, gfxCtx->curFrameBuffer);
|
|
|
|
gSPSegment(OVERLAY_DISP++, 0xE, gZBuffer);
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
CLOSE_DISPS(gfxCtx, "../game.c", 838);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void func_800C49F4(GraphicsContext* gfxCtx) {
|
|
|
|
Gfx* newDlist;
|
|
|
|
Gfx* polyOpaP;
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../game.c", 846);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
newDlist = Graph_GfxPlusOne(polyOpaP = POLY_OPA_DISP);
|
|
|
|
gSPDisplayList(OVERLAY_DISP++, newDlist);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
gSPEndDisplayList(newDlist++);
|
|
|
|
Graph_BranchDlist(polyOpaP, newDlist);
|
2020-10-29 21:31:09 +00:00
|
|
|
POLY_OPA_DISP = newDlist;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
if (1) {}
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../game.c", 865);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void PadMgr_RequestPadData(PadMgr*, Input*, s32);
|
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
void GameState_ReqPadData(GameState* gameState) {
|
2021-02-14 00:49:40 +00:00
|
|
|
PadMgr_RequestPadData(&gPadMgr, &gameState->input[0], 1);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_Update(GameState* gameState) {
|
|
|
|
GraphicsContext* gfxCtx = gameState->gfxCtx;
|
2020-05-19 19:55:49 +00:00
|
|
|
|
|
|
|
GameState_SetFrameBuffer(gfxCtx);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
gameState->main(gameState);
|
|
|
|
|
|
|
|
func_800C4344(gameState);
|
|
|
|
|
2020-07-18 09:55:35 +00:00
|
|
|
if (SREG(63) == 1u) {
|
2020-05-14 23:11:33 +00:00
|
|
|
if (SREG(48) < 0) {
|
|
|
|
SREG(48) = 0;
|
|
|
|
gfxCtx->viMode = &gViConfigMode;
|
|
|
|
gfxCtx->viFeatures = gViConfigFeatures;
|
|
|
|
gfxCtx->xScale = gViConfigXScale;
|
|
|
|
gfxCtx->yScale = gViConfigYScale;
|
|
|
|
} else if (SREG(48) > 0) {
|
2021-05-04 01:49:09 +00:00
|
|
|
ViMode_Update(&sViMode, gameState->input);
|
|
|
|
gfxCtx->viMode = &sViMode.customViMode;
|
|
|
|
gfxCtx->viFeatures = sViMode.viFeatures;
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->xScale = 1.0f;
|
|
|
|
gfxCtx->yScale = 1.0f;
|
|
|
|
}
|
|
|
|
} else if (SREG(63) >= 2) {
|
|
|
|
gfxCtx->viMode = &gViConfigMode;
|
|
|
|
gfxCtx->viFeatures = gViConfigFeatures;
|
|
|
|
gfxCtx->xScale = gViConfigXScale;
|
|
|
|
gfxCtx->yScale = gViConfigYScale;
|
2021-07-27 23:44:58 +00:00
|
|
|
if (SREG(63) == 6 || (SREG(63) == 2u && osTvType == OS_TV_NTSC)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModeNtscLan1;
|
|
|
|
gfxCtx->yScale = 1.0f;
|
|
|
|
}
|
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
if (SREG(63) == 5 || (SREG(63) == 2u && osTvType == OS_TV_MPAL)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModeMpalLan1;
|
|
|
|
gfxCtx->yScale = 1.0f;
|
|
|
|
}
|
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
if (SREG(63) == 4 || (SREG(63) == 2u && osTvType == OS_TV_PAL)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModePalLan1;
|
|
|
|
gfxCtx->yScale = 1.0f;
|
|
|
|
}
|
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
if (SREG(63) == 3 || (SREG(63) == 2u && osTvType == OS_TV_PAL)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModeFpalLan1;
|
|
|
|
gfxCtx->yScale = 0.833f;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gfxCtx->viMode = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HREG(80) == 0x15) {
|
|
|
|
if (HREG(95) != 0x15) {
|
|
|
|
HREG(95) = 0x15;
|
|
|
|
HREG(81) = 0;
|
|
|
|
HREG(82) = gViConfigAdditionalScanLines;
|
|
|
|
HREG(83) = 0;
|
|
|
|
HREG(84) = 0;
|
|
|
|
}
|
|
|
|
|
2020-05-19 19:55:49 +00:00
|
|
|
if (HREG(82) < 0) {
|
|
|
|
HREG(82) = 0;
|
|
|
|
}
|
|
|
|
if (HREG(82) > 0x30) {
|
|
|
|
HREG(82) = 0x30;
|
|
|
|
}
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
if ((HREG(83) != HREG(82)) || HREG(84) != HREG(81)) {
|
|
|
|
HREG(83) = HREG(82);
|
|
|
|
HREG(84) = HREG(81);
|
|
|
|
gViConfigAdditionalScanLines = HREG(82);
|
2020-05-19 19:55:49 +00:00
|
|
|
gViConfigYScale = HREG(81) == 0 ? 240.0f / (gViConfigAdditionalScanLines + 240.0f) : 1.0f;
|
2020-05-14 23:11:33 +00:00
|
|
|
D_80009430 = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-18 09:55:35 +00:00
|
|
|
if (R_PAUSE_MENU_MODE != 2u) {
|
2020-05-19 19:55:49 +00:00
|
|
|
GameState_Draw(gameState, gfxCtx);
|
|
|
|
func_800C49F4(gfxCtx);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gameState->frames++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_InitArena(GameState* gameState, size_t size) {
|
|
|
|
void* arena;
|
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラル確保 サイズ=%u バイト\n"); // "Hyrule reserved size = %u bytes"
|
2020-05-14 23:11:33 +00:00
|
|
|
arena = GameAlloc_MallocDebug(&gameState->alloc, size, "../game.c", 992);
|
|
|
|
if (arena != NULL) {
|
|
|
|
THA_Ct(&gameState->tha, arena, size);
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラル確保成功\n"); // "Successful Hyral"
|
2020-05-14 23:11:33 +00:00
|
|
|
} else {
|
|
|
|
THA_Ct(&gameState->tha, NULL, 0);
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラル確保失敗\n"); // "Failure to secure Hyrule"
|
2020-05-14 23:11:33 +00:00
|
|
|
Fault_AddHungupAndCrash("../game.c", 999);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_Realloc(GameState* gameState, size_t size) {
|
2020-07-18 09:55:35 +00:00
|
|
|
GameAlloc* alloc = &gameState->alloc;
|
2020-05-14 23:11:33 +00:00
|
|
|
void* gameArena;
|
|
|
|
u32 systemMaxFree;
|
|
|
|
u32 systemFree;
|
|
|
|
u32 systemAlloc;
|
2021-02-14 00:49:40 +00:00
|
|
|
void* thaBufp = gameState->tha.bufp;
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
THA_Dt(&gameState->tha);
|
2020-07-18 09:55:35 +00:00
|
|
|
GameAlloc_Free(alloc, thaBufp);
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラル一時解放!!\n"); // "Hyrule temporarily released!!"
|
2020-05-14 23:11:33 +00:00
|
|
|
SystemArena_GetSizes(&systemMaxFree, &systemFree, &systemAlloc);
|
|
|
|
if ((systemMaxFree - 0x10) < size) {
|
2022-03-13 23:22:14 +00:00
|
|
|
osSyncPrintf("%c", BEL);
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Not enough memory. Change the hyral size to the largest possible value"
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf("メモリが足りません。ハイラルサイズを可能な最大値に変更します\n");
|
|
|
|
osSyncPrintf("(hyral=%08x max=%08x free=%08x alloc=%08x)\n", size, systemMaxFree, systemFree, systemAlloc);
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
size = systemMaxFree - 0x10;
|
|
|
|
}
|
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラル再確保 サイズ=%u バイト\n", size); // "Hyral reallocate size = %u bytes"
|
2020-07-18 09:55:35 +00:00
|
|
|
gameArena = GameAlloc_MallocDebug(alloc, size, "../game.c", 1033);
|
2020-05-14 23:11:33 +00:00
|
|
|
if (gameArena != NULL) {
|
|
|
|
THA_Ct(&gameState->tha, gameArena, size);
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラル再確保成功\n"); // "Successful reacquisition of Hyrule"
|
2020-05-14 23:11:33 +00:00
|
|
|
} else {
|
|
|
|
THA_Ct(&gameState->tha, NULL, 0);
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラル再確保失敗\n"); // "Failure to secure Hyral"
|
2020-05-14 23:11:33 +00:00
|
|
|
SystemArena_Display();
|
|
|
|
Fault_AddHungupAndCrash("../game.c", 1044);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* gfxCtx) {
|
2021-08-15 23:15:58 +00:00
|
|
|
OSTime startTime;
|
|
|
|
OSTime endTime;
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("game コンストラクタ開始\n"); // "game constructor start"
|
2020-05-14 23:11:33 +00:00
|
|
|
gameState->gfxCtx = gfxCtx;
|
|
|
|
gameState->frames = 0;
|
|
|
|
gameState->main = NULL;
|
|
|
|
gameState->destroy = NULL;
|
|
|
|
gameState->running = 1;
|
|
|
|
startTime = osGetTime();
|
|
|
|
gameState->size = 0;
|
|
|
|
gameState->init = NULL;
|
|
|
|
endTime = osGetTime();
|
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
// "game_set_next_game_null processing time %d us"
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf("game_set_next_game_null 処理時間 %d us\n", OS_CYCLES_TO_USEC(endTime - startTime));
|
|
|
|
startTime = endTime;
|
|
|
|
GameAlloc_Init(&gameState->alloc);
|
|
|
|
|
|
|
|
endTime = osGetTime();
|
2021-09-04 13:33:19 +00:00
|
|
|
// "gamealloc_init processing time %d us"
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf("gamealloc_init 処理時間 %d us\n", OS_CYCLES_TO_USEC(endTime - startTime));
|
|
|
|
|
|
|
|
startTime = endTime;
|
|
|
|
GameState_InitArena(gameState, 0x100000);
|
2020-06-17 19:23:42 +00:00
|
|
|
R_UPDATE_RATE = 3;
|
2020-05-14 23:11:33 +00:00
|
|
|
init(gameState);
|
|
|
|
|
|
|
|
endTime = osGetTime();
|
2021-09-04 13:33:19 +00:00
|
|
|
// "init processing time %d us"
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf("init 処理時間 %d us\n", OS_CYCLES_TO_USEC(endTime - startTime));
|
|
|
|
|
|
|
|
startTime = endTime;
|
|
|
|
LogUtils_CheckNullPointer("this->cleanup", gameState->destroy, "../game.c", 1088);
|
|
|
|
func_800ACE70(&D_801664F0);
|
|
|
|
func_800AD920(&D_80166500);
|
2020-05-15 09:02:39 +00:00
|
|
|
VisMono_Init(&sMonoColors);
|
2020-05-14 23:11:33 +00:00
|
|
|
if (SREG(48) == 0) {
|
2021-05-04 01:49:09 +00:00
|
|
|
ViMode_Init(&sViMode);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
SpeedMeter_Init(&D_801664D0);
|
|
|
|
func_800AA0B4();
|
|
|
|
osSendMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK);
|
|
|
|
|
|
|
|
endTime = osGetTime();
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Other initialization processing time %d us"
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf("その他初期化 処理時間 %d us\n", OS_CYCLES_TO_USEC(endTime - startTime));
|
|
|
|
|
2021-11-28 10:47:55 +00:00
|
|
|
Fault_AddClient(&sGameFaultClient, GameState_FaultPrint, NULL, NULL);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("game コンストラクタ終了\n"); // "game constructor end"
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_Destroy(GameState* gameState) {
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("game デストラクタ開始\n"); // "game destructor start"
|
2022-07-04 15:51:38 +00:00
|
|
|
AudioMgr_StopAllSfx();
|
2021-08-19 22:10:51 +00:00
|
|
|
func_800F3054();
|
2020-05-14 23:11:33 +00:00
|
|
|
osRecvMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK);
|
|
|
|
LogUtils_CheckNullPointer("this->cleanup", gameState->destroy, "../game.c", 1139);
|
|
|
|
if (gameState->destroy != NULL) {
|
|
|
|
gameState->destroy(gameState);
|
|
|
|
}
|
|
|
|
func_800AA0F0();
|
|
|
|
SpeedMeter_Destroy(&D_801664D0);
|
|
|
|
func_800ACE90(&D_801664F0);
|
|
|
|
func_800AD950(&D_80166500);
|
2020-05-15 09:02:39 +00:00
|
|
|
VisMono_Destroy(&sMonoColors);
|
2020-05-14 23:11:33 +00:00
|
|
|
if (SREG(48) == 0) {
|
2021-05-04 01:49:09 +00:00
|
|
|
ViMode_Destroy(&sViMode);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
THA_Dt(&gameState->tha);
|
|
|
|
GameAlloc_Cleanup(&gameState->alloc);
|
|
|
|
SystemArena_Display();
|
|
|
|
Fault_RemoveClient(&sGameFaultClient);
|
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("game デストラクタ終了\n"); // "game destructor end"
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GameStateFunc GameState_GetInit(GameState* gameState) {
|
|
|
|
return gameState->init;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GameState_GetSize(GameState* gameState) {
|
|
|
|
return gameState->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GameState_IsRunning(GameState* gameState) {
|
|
|
|
return gameState->running;
|
|
|
|
}
|
|
|
|
|
2020-05-26 15:39:27 +00:00
|
|
|
void* GameState_Alloc(GameState* gameState, size_t size, char* file, s32 line) {
|
2020-05-14 23:11:33 +00:00
|
|
|
void* ret;
|
|
|
|
|
|
|
|
if (THA_IsCrash(&gameState->tha)) {
|
|
|
|
osSyncPrintf("ハイラルは滅亡している\n");
|
|
|
|
ret = NULL;
|
2021-02-14 00:49:40 +00:00
|
|
|
} else if ((u32)THA_GetSize(&gameState->tha) < size) {
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Hyral on the verge of extinction does not have %d bytes left (%d bytes until extinction)"
|
2020-05-14 23:11:33 +00:00
|
|
|
osSyncPrintf("滅亡寸前のハイラルには %d バイトの余力もない(滅亡まであと %d バイト)\n", size,
|
|
|
|
THA_GetSize(&gameState->tha));
|
|
|
|
ret = NULL;
|
|
|
|
} else {
|
|
|
|
ret = THA_AllocEndAlign16(&gameState->tha, size);
|
|
|
|
if (THA_IsCrash(&gameState->tha)) {
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("ハイラルは滅亡してしまった\n"); // "Hyrule has been destroyed"
|
2020-05-14 23:11:33 +00:00
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret != NULL) {
|
|
|
|
osSyncPrintf(VT_FGCOL(GREEN));
|
|
|
|
osSyncPrintf("game_alloc(%08x) %08x-%08x [%s:%d]\n", size, ret, (u32)ret + size, file, line);
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* GameState_AllocEndAlign16(GameState* gameState, size_t size) {
|
|
|
|
return THA_AllocEndAlign16(&gameState->tha, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 GameState_GetArenaSize(GameState* gameState) {
|
|
|
|
return THA_GetSize(&gameState->tha);
|
|
|
|
}
|