2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2024-08-28 07:38:42 +00:00
|
|
|
#include "fault.h"
|
2024-09-04 09:10:14 +00:00
|
|
|
#include "osMalloc.h"
|
2022-11-01 23:17:11 +00:00
|
|
|
#include "terminal.h"
|
2024-09-04 05:46:41 +00:00
|
|
|
#if PLATFORM_N64
|
|
|
|
#include "n64dd.h"
|
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2024-08-25 14:00:10 +00:00
|
|
|
#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128"
|
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
SpeedMeter D_801664D0;
|
2023-09-16 21:16:58 +00:00
|
|
|
VisCvg sVisCvg;
|
|
|
|
VisZBuf sVisZBuf;
|
|
|
|
VisMono sVisMono;
|
2021-05-04 01:49:09 +00:00
|
|
|
ViMode sViMode;
|
2024-02-27 07:23:19 +00:00
|
|
|
|
|
|
|
#if OOT_DEBUG
|
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;
|
|
|
|
|
2024-01-12 15:38:13 +00:00
|
|
|
PRINTF("last_button=%04x\n", sLastButtonPressed);
|
2024-09-04 03:43:06 +00:00
|
|
|
Fault_DrawText(120, 180, "%08x", sLastButtonPressed);
|
2020-05-14 23:11:33 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sBtnChars); i++) {
|
|
|
|
if (sLastButtonPressed & (1 << i)) {
|
2024-09-04 03:43:06 +00:00
|
|
|
Fault_DrawText((i * 8) + 120, 190, "%c", sBtnChars[i]);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2023-09-16 21:16:58 +00:00
|
|
|
void GameState_SetFBFilter(Gfx** gfxP) {
|
|
|
|
Gfx* gfx = *gfxP;
|
|
|
|
|
|
|
|
if ((R_FB_FILTER_TYPE >= FB_FILTER_CVG_RGB) && (R_FB_FILTER_TYPE <= FB_FILTER_CVG_RGB_FOG)) {
|
|
|
|
// Visualize coverage
|
|
|
|
sVisCvg.vis.type = FB_FILTER_TO_CVG_TYPE(R_FB_FILTER_TYPE);
|
|
|
|
sVisCvg.vis.primColor.r = R_FB_FILTER_PRIM_COLOR(0);
|
|
|
|
sVisCvg.vis.primColor.g = R_FB_FILTER_PRIM_COLOR(1);
|
|
|
|
sVisCvg.vis.primColor.b = R_FB_FILTER_PRIM_COLOR(2);
|
|
|
|
sVisCvg.vis.primColor.a = R_FB_FILTER_A;
|
|
|
|
VisCvg_Draw(&sVisCvg, &gfx);
|
|
|
|
} else if ((R_FB_FILTER_TYPE == FB_FILTER_ZBUF_IA) || (R_FB_FILTER_TYPE == FB_FILTER_ZBUF_RGBA)) {
|
|
|
|
// Visualize z-buffer
|
|
|
|
sVisZBuf.vis.type = (R_FB_FILTER_TYPE == FB_FILTER_ZBUF_RGBA);
|
|
|
|
sVisZBuf.vis.primColor.r = R_FB_FILTER_PRIM_COLOR(0);
|
|
|
|
sVisZBuf.vis.primColor.g = R_FB_FILTER_PRIM_COLOR(1);
|
|
|
|
sVisZBuf.vis.primColor.b = R_FB_FILTER_PRIM_COLOR(2);
|
|
|
|
sVisZBuf.vis.primColor.a = R_FB_FILTER_A;
|
|
|
|
sVisZBuf.vis.envColor.r = R_FB_FILTER_ENV_COLOR(0);
|
|
|
|
sVisZBuf.vis.envColor.g = R_FB_FILTER_ENV_COLOR(1);
|
|
|
|
sVisZBuf.vis.envColor.b = R_FB_FILTER_ENV_COLOR(2);
|
|
|
|
sVisZBuf.vis.envColor.a = R_FB_FILTER_A;
|
|
|
|
VisZBuf_Draw(&sVisZBuf, &gfx);
|
|
|
|
} else if (R_FB_FILTER_TYPE == FB_FILTER_MONO) {
|
|
|
|
// Monochrome filter
|
|
|
|
sVisMono.vis.type = 0;
|
|
|
|
sVisMono.vis.primColor.r = R_FB_FILTER_PRIM_COLOR(0);
|
|
|
|
sVisMono.vis.primColor.g = R_FB_FILTER_PRIM_COLOR(1);
|
|
|
|
sVisMono.vis.primColor.b = R_FB_FILTER_PRIM_COLOR(2);
|
|
|
|
sVisMono.vis.primColor.a = R_FB_FILTER_A;
|
|
|
|
sVisMono.vis.envColor.r = R_FB_FILTER_ENV_COLOR(0);
|
|
|
|
sVisMono.vis.envColor.g = R_FB_FILTER_ENV_COLOR(1);
|
|
|
|
sVisMono.vis.envColor.b = R_FB_FILTER_ENV_COLOR(2);
|
|
|
|
sVisMono.vis.envColor.a = R_FB_FILTER_A;
|
|
|
|
VisMono_Draw(&sVisMono, &gfx);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
2023-09-16 21:16:58 +00:00
|
|
|
*gfxP = gfx;
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void func_800C4344(GameState* gameState) {
|
2024-09-04 05:46:41 +00:00
|
|
|
#if PLATFORM_N64
|
2024-09-04 18:56:24 +00:00
|
|
|
if (D_80121212 != 0) {
|
|
|
|
func_801C7E78();
|
2024-09-04 05:46:41 +00:00
|
|
|
}
|
|
|
|
#elif OOT_DEBUG
|
2020-05-14 23:11:33 +00:00
|
|
|
Input* selectedInput;
|
|
|
|
s32 hexDumpSize;
|
2022-11-26 20:22:01 +00:00
|
|
|
u16 inputCompareValue;
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_HEAP_FREE_BLOCK_TEST) {
|
|
|
|
__osMalloc_FreeBlockTest_Enable = R_HEAP_FREE_BLOCK_TEST_TOGGLE;
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_INPUT_TEST) {
|
|
|
|
selectedInput =
|
|
|
|
&gameState->input[(u32)R_INPUT_TEST_CONTROLLER_PORT < MAXCONTROLLERS ? R_INPUT_TEST_CONTROLLER_PORT : 0];
|
|
|
|
|
|
|
|
inputCompareValue = R_INPUT_TEST_COMPARE_VALUE;
|
|
|
|
R_INPUT_TEST_BUTTON_CUR = selectedInput->cur.button;
|
|
|
|
R_INPUT_TEST_BUTTON_PRESS = selectedInput->press.button;
|
|
|
|
R_INPUT_TEST_REL_STICK_X = selectedInput->rel.stick_x;
|
|
|
|
R_INPUT_TEST_REL_STICK_Y = selectedInput->rel.stick_y;
|
|
|
|
R_INPUT_TEST_REL_STICK_X_2 = selectedInput->rel.stick_x;
|
|
|
|
R_INPUT_TEST_REL_STICK_Y_2 = selectedInput->rel.stick_y;
|
|
|
|
R_INPUT_TEST_CUR_STICK_X = selectedInput->cur.stick_x;
|
|
|
|
R_INPUT_TEST_CUR_STICK_Y = selectedInput->cur.stick_y;
|
|
|
|
R_INPUT_TEST_COMPARE_BUTTON_CUR = (selectedInput->cur.button == inputCompareValue);
|
|
|
|
R_INPUT_TEST_COMPARE_COMBO_CUR = CHECK_BTN_ALL(selectedInput->cur.button, inputCompareValue);
|
|
|
|
R_INPUT_TEST_COMPARE_COMBO_PRESS = CHECK_BTN_ALL(selectedInput->press.button, inputCompareValue);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 14:17:48 +00:00
|
|
|
if (gIsCtrlr2Valid) {
|
2022-10-15 05:40:00 +00:00
|
|
|
Regs_UpdateEditor(&gameState->input[1]);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2022-03-10 20:21:46 +00:00
|
|
|
gDmaMgrVerbose = HREG(60);
|
2022-11-17 02:57:02 +00:00
|
|
|
gDmaMgrDmaBuffSize = SREG(21) != 0 ? ALIGN16(SREG(21)) : DMAMGR_DEFAULT_BUFSIZE;
|
2020-05-14 23:11:33 +00:00
|
|
|
gSystemArenaLogSeverity = HREG(61);
|
|
|
|
gZeldaArenaLogSeverity = HREG(62);
|
2022-11-26 20:22:01 +00:00
|
|
|
|
|
|
|
if (R_HREG_MODE == HREG_MODE_PRINT_MEMORY) {
|
|
|
|
if (R_PRINT_MEMORY_INIT != HREG_MODE_PRINT_MEMORY) {
|
|
|
|
R_PRINT_MEMORY_INIT = HREG_MODE_PRINT_MEMORY;
|
|
|
|
R_PRINT_MEMORY_TRIGGER = 0;
|
|
|
|
R_PRINT_MEMORY_ADDR = 0;
|
|
|
|
R_PRINT_MEMORY_SIZE = 0;
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
2022-11-26 20:22:01 +00:00
|
|
|
|
|
|
|
if (R_PRINT_MEMORY_TRIGGER < 0) {
|
|
|
|
R_PRINT_MEMORY_TRIGGER = 0;
|
|
|
|
hexDumpSize = (u32)(R_PRINT_MEMORY_SIZE == 0 ? 0x100 : R_PRINT_MEMORY_SIZE * 0x10);
|
|
|
|
LogUtils_LogHexDump((void*)(0x80000000 + (R_PRINT_MEMORY_ADDR << 8)), hexDumpSize);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2023-09-16 21:16:58 +00:00
|
|
|
void GameState_DrawInputDisplay(u16 input, Gfx** gfxP) {
|
2020-05-14 23:11:33 +00:00
|
|
|
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;
|
2023-09-16 21:16:58 +00:00
|
|
|
Gfx* gfx = *gfxP;
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2023-09-16 21:16:58 +00:00
|
|
|
gDPPipeSync(gfx++);
|
|
|
|
gDPSetOtherMode(gfx++,
|
2020-05-14 23:11:33 +00:00
|
|
|
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)) {
|
2023-09-16 21:16:58 +00:00
|
|
|
gDPSetFillColor(gfx++, (sInpDispBtnColors[i] << 0x10) | sInpDispBtnColors[i]);
|
2020-07-18 09:55:35 +00:00
|
|
|
k = i + 1;
|
2023-09-16 21:16:58 +00:00
|
|
|
gDPFillRectangle(gfx++, (j * 4) + 226, 220, (k * 4) + 225, 223);
|
|
|
|
gDPPipeSync(gfx++);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
2020-07-18 09:55:35 +00:00
|
|
|
}
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2023-09-16 21:16:58 +00:00
|
|
|
*gfxP = gfx;
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-02-01 00:07:12 +00:00
|
|
|
newDList = Gfx_Open(polyOpaP = POLY_OPA_DISP);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(OVERLAY_DISP++, newDList);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
if (R_ENABLE_FB_FILTER == 1) {
|
|
|
|
GameState_SetFBFilter(&newDList);
|
|
|
|
}
|
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
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
|
|
|
}
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
if (R_ENABLE_ARENA_DBG < 0) {
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2020-08-29 23:00:17 +00:00
|
|
|
s32 pad;
|
2020-05-14 23:11:33 +00:00
|
|
|
DebugArena_Display();
|
|
|
|
SystemArena_Display();
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル滅亡まであと %08x バイト(game_alloc)\n",
|
|
|
|
"%08x bytes left until Hyrule is destroyed (game_alloc)\n"),
|
|
|
|
THA_GetRemaining(&gameState->tha));
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
R_ENABLE_ARENA_DBG = 0;
|
|
|
|
}
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
gSPEndDisplayList(newDList++);
|
2024-02-01 00:07:12 +00:00
|
|
|
Gfx_Close(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
|
|
|
CLOSE_DISPS(gfxCtx, "../game.c", 800);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2022-12-30 01:23:09 +00:00
|
|
|
Debug_DrawText(gfxCtx);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-02-01 00:07:12 +00:00
|
|
|
newDlist = Gfx_Open(polyOpaP = POLY_OPA_DISP);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(OVERLAY_DISP++, newDlist);
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2024-09-04 05:46:41 +00:00
|
|
|
#if PLATFORM_N64
|
2024-09-04 18:56:24 +00:00
|
|
|
if (D_80121212 != 0) {
|
|
|
|
func_801C6EA0(&newDlist);
|
2024-09-04 05:46:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
gSPEndDisplayList(newDlist++);
|
2024-02-01 00:07:12 +00:00
|
|
|
Gfx_Close(polyOpaP, newDlist);
|
2020-10-29 21:31:09 +00:00
|
|
|
POLY_OPA_DISP = newDlist;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
CLOSE_DISPS(gfxCtx, "../game.c", 865);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-03 00:52:13 +00:00
|
|
|
void PadMgr_RequestPadData(PadMgr* padMgr, Input* inputs, s32 gameRequest);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
void GameState_ReqPadData(GameState* gameState) {
|
2022-09-03 00:52:13 +00:00
|
|
|
PadMgr_RequestPadData(&gPadMgr, gameState->input, true);
|
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);
|
|
|
|
|
2024-09-04 05:46:41 +00:00
|
|
|
#if PLATFORM_N64
|
2024-09-04 18:56:24 +00:00
|
|
|
if (D_80121212 != 0) {
|
|
|
|
func_801C7E78();
|
2024-09-04 05:46:41 +00:00
|
|
|
}
|
2024-09-04 18:56:24 +00:00
|
|
|
if ((B_80121220 != NULL) && (B_80121220->unk_74 != NULL)) {
|
|
|
|
B_80121220->unk_74(gameState);
|
2024-09-04 05:46:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
func_800C4344(gameState);
|
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2020-07-18 09:55:35 +00:00
|
|
|
if (SREG(63) == 1u) {
|
2022-11-13 23:07:27 +00:00
|
|
|
if (R_VI_MODE_EDIT_STATE < VI_MODE_EDIT_STATE_INACTIVE) {
|
|
|
|
R_VI_MODE_EDIT_STATE = VI_MODE_EDIT_STATE_INACTIVE;
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &gViConfigMode;
|
|
|
|
gfxCtx->viFeatures = gViConfigFeatures;
|
|
|
|
gfxCtx->xScale = gViConfigXScale;
|
|
|
|
gfxCtx->yScale = gViConfigYScale;
|
2022-11-13 23:07:27 +00:00
|
|
|
} else if (R_VI_MODE_EDIT_STATE > VI_MODE_EDIT_STATE_INACTIVE) {
|
|
|
|
ViMode_Update(&sViMode, &gameState->input[0]);
|
2021-05-04 01:49:09 +00:00
|
|
|
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;
|
2022-11-13 23:07:27 +00:00
|
|
|
|
2024-09-06 12:46:44 +00:00
|
|
|
if (SREG(63) == 6 || (SREG(63) == 2u && (u32)osTvType == OS_TV_NTSC)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModeNtscLan1;
|
|
|
|
gfxCtx->yScale = 1.0f;
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:46:44 +00:00
|
|
|
if (SREG(63) == 5 || (SREG(63) == 2u && (u32)osTvType == OS_TV_MPAL)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModeMpalLan1;
|
|
|
|
gfxCtx->yScale = 1.0f;
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:46:44 +00:00
|
|
|
if (SREG(63) == 4 || (SREG(63) == 2u && (u32)osTvType == OS_TV_PAL)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModePalLan1;
|
|
|
|
gfxCtx->yScale = 1.0f;
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:46:44 +00:00
|
|
|
if (SREG(63) == 3 || (SREG(63) == 2u && (u32)osTvType == OS_TV_PAL)) {
|
2020-05-14 23:11:33 +00:00
|
|
|
gfxCtx->viMode = &osViModeFpalLan1;
|
|
|
|
gfxCtx->yScale = 0.833f;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gfxCtx->viMode = NULL;
|
|
|
|
}
|
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_VI) {
|
|
|
|
if (R_VI_INIT != HREG_MODE_VI) {
|
|
|
|
R_VI_INIT = HREG_MODE_VI;
|
|
|
|
R_VI_NEXT_Y_SCALE_MODE = 0;
|
|
|
|
R_VI_NEXT_ADDI_SCAN_LINES = gViConfigAdditionalScanLines;
|
|
|
|
R_VI_CUR_ADDI_SCAN_LINES = 0;
|
|
|
|
R_VI_CUR_Y_SCALE_MODE = 0;
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_VI_NEXT_ADDI_SCAN_LINES < 0) {
|
|
|
|
R_VI_NEXT_ADDI_SCAN_LINES = 0;
|
2020-05-19 19:55:49 +00:00
|
|
|
}
|
2022-11-26 20:22:01 +00:00
|
|
|
|
|
|
|
if (R_VI_NEXT_ADDI_SCAN_LINES > 0x30) {
|
|
|
|
R_VI_NEXT_ADDI_SCAN_LINES = 0x30;
|
2020-05-19 19:55:49 +00:00
|
|
|
}
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
if ((R_VI_CUR_ADDI_SCAN_LINES != R_VI_NEXT_ADDI_SCAN_LINES) ||
|
|
|
|
R_VI_CUR_Y_SCALE_MODE != R_VI_NEXT_Y_SCALE_MODE) {
|
|
|
|
|
|
|
|
R_VI_CUR_ADDI_SCAN_LINES = R_VI_NEXT_ADDI_SCAN_LINES;
|
|
|
|
R_VI_CUR_Y_SCALE_MODE = R_VI_NEXT_Y_SCALE_MODE;
|
|
|
|
|
|
|
|
gViConfigAdditionalScanLines = R_VI_NEXT_ADDI_SCAN_LINES;
|
|
|
|
gViConfigYScale = R_VI_NEXT_Y_SCALE_MODE == 0
|
|
|
|
? ((f32)SCREEN_HEIGHT) / (gViConfigAdditionalScanLines + (f32)SCREEN_HEIGHT)
|
|
|
|
: 1.0f;
|
2020-05-14 23:11:33 +00:00
|
|
|
D_80009430 = 1;
|
|
|
|
}
|
|
|
|
}
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2022-12-20 00:19:57 +00:00
|
|
|
if (R_PAUSE_BG_PRERENDER_STATE != (u32)PAUSE_BG_PRERENDER_PROCESS) {
|
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;
|
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル確保 サイズ=%u バイト\n", "Hyrule reserved size = %u bytes\n"), size);
|
2024-01-29 20:27:29 +00:00
|
|
|
arena = GAME_ALLOC_MALLOC(&gameState->alloc, size, "../game.c", 992);
|
|
|
|
|
2020-05-14 23:11:33 +00:00
|
|
|
if (arena != NULL) {
|
2022-11-13 23:29:50 +00:00
|
|
|
THA_Init(&gameState->tha, arena, size);
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル確保成功\n", "Hyrule successfully secured\n"));
|
2020-05-14 23:11:33 +00:00
|
|
|
} else {
|
2022-11-13 23:29:50 +00:00
|
|
|
THA_Init(&gameState->tha, NULL, 0);
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル確保失敗\n", "Failure to secure Hyrule\n"));
|
2024-09-04 05:46:41 +00:00
|
|
|
#if PLATFORM_N64
|
|
|
|
HUNGUP_AND_CRASH("../game.c", 985);
|
|
|
|
#else
|
2024-01-29 20:27:29 +00:00
|
|
|
HUNGUP_AND_CRASH("../game.c", 999);
|
2024-09-04 05:46:41 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2022-11-13 23:29:50 +00:00
|
|
|
void* thaStart = gameState->tha.start;
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2022-11-13 23:29:50 +00:00
|
|
|
THA_Destroy(&gameState->tha);
|
|
|
|
GameAlloc_Free(alloc, thaStart);
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル一時解放!!\n", "Hyrule temporarily released!!\n"));
|
2020-05-14 23:11:33 +00:00
|
|
|
SystemArena_GetSizes(&systemMaxFree, &systemFree, &systemAlloc);
|
|
|
|
if ((systemMaxFree - 0x10) < size) {
|
2024-01-12 15:38:13 +00:00
|
|
|
PRINTF("%c", BEL);
|
|
|
|
PRINTF(VT_FGCOL(RED));
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("メモリが足りません。ハイラルサイズを可能な最大値に変更します\n",
|
|
|
|
"Not enough memory. Change Hyrule size to maximum possible value\n"));
|
2024-01-12 15:38:13 +00:00
|
|
|
PRINTF("(hyral=%08x max=%08x free=%08x alloc=%08x)\n", size, systemMaxFree, systemFree, systemAlloc);
|
|
|
|
PRINTF(VT_RST);
|
2020-05-14 23:11:33 +00:00
|
|
|
size = systemMaxFree - 0x10;
|
|
|
|
}
|
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル再確保 サイズ=%u バイト\n", "Hyrule reallocate size = %u bytes\n"), size);
|
2024-01-29 20:27:29 +00:00
|
|
|
|
|
|
|
gameArena = GAME_ALLOC_MALLOC(alloc, size, "../game.c", 1033);
|
2020-05-14 23:11:33 +00:00
|
|
|
if (gameArena != NULL) {
|
2022-11-13 23:29:50 +00:00
|
|
|
THA_Init(&gameState->tha, gameArena, size);
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル再確保成功\n", "Successful reacquisition of Hyrule\n"));
|
2020-05-14 23:11:33 +00:00
|
|
|
} else {
|
2022-11-13 23:29:50 +00:00
|
|
|
THA_Init(&gameState->tha, NULL, 0);
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラル再確保失敗\n", "Failure to secure Hyrule\n"));
|
2024-01-29 20:27:29 +00:00
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2020-05-14 23:11:33 +00:00
|
|
|
SystemArena_Display();
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2024-09-04 05:46:41 +00:00
|
|
|
|
|
|
|
#if PLATFORM_N64
|
|
|
|
HUNGUP_AND_CRASH("../game.c", 1030);
|
|
|
|
#else
|
2024-01-29 20:27:29 +00:00
|
|
|
HUNGUP_AND_CRASH("../game.c", 1044);
|
2024-09-04 05:46:41 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("game コンストラクタ開始\n", "game constructor start\n"));
|
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();
|
2024-02-27 07:37:33 +00:00
|
|
|
|
|
|
|
// Thse assignments must be written this way for matching and to avoid a warning due to casting a pointer to an
|
|
|
|
// integer without a cast. This assigns init = NULL and size = 0.
|
|
|
|
gameState->size = (u32)(gameState->init = NULL);
|
2024-01-29 20:27:29 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
s32 requiredScopeTemp;
|
|
|
|
endTime = osGetTime();
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("game_set_next_game_null 処理時間 %d us\n", "game_set_next_game_null processing time %d us\n"),
|
|
|
|
OS_CYCLES_TO_USEC(endTime - startTime));
|
2024-01-29 20:27:29 +00:00
|
|
|
startTime = endTime;
|
|
|
|
GameAlloc_Init(&gameState->alloc);
|
|
|
|
}
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
endTime = osGetTime();
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("gamealloc_init 処理時間 %d us\n", "gamealloc_init processing time %d us\n"),
|
|
|
|
OS_CYCLES_TO_USEC(endTime - startTime));
|
2020-05-14 23:11:33 +00:00
|
|
|
startTime = endTime;
|
|
|
|
GameState_InitArena(gameState, 0x100000);
|
2024-01-29 20:27:29 +00:00
|
|
|
|
2020-06-17 19:23:42 +00:00
|
|
|
R_UPDATE_RATE = 3;
|
2020-05-14 23:11:33 +00:00
|
|
|
init(gameState);
|
|
|
|
endTime = osGetTime();
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("init 処理時間 %d us\n", "init processing time %d us\n"), OS_CYCLES_TO_USEC(endTime - startTime));
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
startTime = endTime;
|
2024-01-16 14:59:02 +00:00
|
|
|
LOG_UTILS_CHECK_NULL_POINTER("this->cleanup", gameState->destroy, "../game.c", 1088);
|
2023-09-16 21:16:58 +00:00
|
|
|
VisCvg_Init(&sVisCvg);
|
|
|
|
VisZBuf_Init(&sVisZBuf);
|
|
|
|
VisMono_Init(&sVisMono);
|
2024-01-30 18:54:38 +00:00
|
|
|
if ((R_VI_MODE_EDIT_STATE == VI_MODE_EDIT_STATE_INACTIVE) || !OOT_DEBUG) {
|
2021-05-04 01:49:09 +00:00
|
|
|
ViMode_Init(&sViMode);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
SpeedMeter_Init(&D_801664D0);
|
2022-09-27 16:40:26 +00:00
|
|
|
Rumble_Init();
|
2020-05-14 23:11:33 +00:00
|
|
|
osSendMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK);
|
|
|
|
endTime = osGetTime();
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("その他初期化 処理時間 %d us\n", "Other initialization processing time %d us\n"),
|
|
|
|
OS_CYCLES_TO_USEC(endTime - startTime));
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2021-11-28 10:47:55 +00:00
|
|
|
Fault_AddClient(&sGameFaultClient, GameState_FaultPrint, NULL, NULL);
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("game コンストラクタ終了\n", "game constructor end\n"));
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameState_Destroy(GameState* gameState) {
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("game デストラクタ開始\n", "game destructor start\n"));
|
2022-07-04 15:51:38 +00:00
|
|
|
AudioMgr_StopAllSfx();
|
2024-01-31 23:25:23 +00:00
|
|
|
Audio_Update();
|
2020-05-14 23:11:33 +00:00
|
|
|
osRecvMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK);
|
2024-01-16 14:59:02 +00:00
|
|
|
LOG_UTILS_CHECK_NULL_POINTER("this->cleanup", gameState->destroy, "../game.c", 1139);
|
2020-05-14 23:11:33 +00:00
|
|
|
if (gameState->destroy != NULL) {
|
|
|
|
gameState->destroy(gameState);
|
|
|
|
}
|
2022-09-27 16:40:26 +00:00
|
|
|
Rumble_Destroy();
|
2020-05-14 23:11:33 +00:00
|
|
|
SpeedMeter_Destroy(&D_801664D0);
|
2023-09-16 21:16:58 +00:00
|
|
|
VisCvg_Destroy(&sVisCvg);
|
|
|
|
VisZBuf_Destroy(&sVisZBuf);
|
|
|
|
VisMono_Destroy(&sVisMono);
|
2024-01-30 18:54:38 +00:00
|
|
|
if ((R_VI_MODE_EDIT_STATE == VI_MODE_EDIT_STATE_INACTIVE) || !OOT_DEBUG) {
|
2021-05-04 01:49:09 +00:00
|
|
|
ViMode_Destroy(&sViMode);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
2022-11-13 23:29:50 +00:00
|
|
|
THA_Destroy(&gameState->tha);
|
2020-05-14 23:11:33 +00:00
|
|
|
GameAlloc_Cleanup(&gameState->alloc);
|
2024-01-29 20:27:29 +00:00
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2020-05-14 23:11:33 +00:00
|
|
|
SystemArena_Display();
|
|
|
|
Fault_RemoveClient(&sGameFaultClient);
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("game デストラクタ終了\n", "game destructor end\n"));
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-30 18:54:38 +00:00
|
|
|
#if OOT_DEBUG
|
2024-02-27 07:37:33 +00:00
|
|
|
void* GameState_Alloc(GameState* gameState, size_t size, const char* file, int line) {
|
2020-05-14 23:11:33 +00:00
|
|
|
void* ret;
|
|
|
|
|
|
|
|
if (THA_IsCrash(&gameState->tha)) {
|
2024-01-12 15:38:13 +00:00
|
|
|
PRINTF("ハイラルは滅亡している\n");
|
2020-05-14 23:11:33 +00:00
|
|
|
ret = NULL;
|
2022-11-13 23:29:50 +00:00
|
|
|
} else if ((u32)THA_GetRemaining(&gameState->tha) < size) {
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("滅亡寸前のハイラルには %d バイトの余力もない(滅亡まであと %d バイト)\n",
|
|
|
|
"Hyrule on the verge of extinction does not have %d bytes left (%d bytes until extinction)\n"),
|
|
|
|
size, THA_GetRemaining(&gameState->tha));
|
2020-05-14 23:11:33 +00:00
|
|
|
ret = NULL;
|
|
|
|
} else {
|
2022-11-13 23:29:50 +00:00
|
|
|
ret = THA_AllocTailAlign16(&gameState->tha, size);
|
2020-05-14 23:11:33 +00:00
|
|
|
if (THA_IsCrash(&gameState->tha)) {
|
2024-08-22 20:33:50 +00:00
|
|
|
PRINTF(T("ハイラルは滅亡してしまった\n", "Hyrule has been destroyed\n"));
|
2020-05-14 23:11:33 +00:00
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret != NULL) {
|
2024-01-12 15:38:13 +00:00
|
|
|
PRINTF(VT_FGCOL(GREEN));
|
|
|
|
PRINTF("game_alloc(%08x) %08x-%08x [%s:%d]\n", size, ret, (uintptr_t)ret + size, file, line);
|
|
|
|
PRINTF(VT_RST);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* GameState_AllocEndAlign16(GameState* gameState, size_t size) {
|
2022-11-13 23:29:50 +00:00
|
|
|
return THA_AllocTailAlign16(&gameState->tha, size);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|
2024-01-29 20:27:29 +00:00
|
|
|
#endif
|
2020-05-14 23:11:33 +00:00
|
|
|
|
|
|
|
s32 GameState_GetArenaSize(GameState* gameState) {
|
2022-11-13 23:29:50 +00:00
|
|
|
return THA_GetRemaining(&gameState->tha);
|
2020-05-14 23:11:33 +00:00
|
|
|
}
|