diff options
| author | MMDecomp <mmdecomp@anon.tld> | 2020-06-23 01:08:52 +0200 |
|---|---|---|
| committer | Kenix3 <kenixwhisperwind@gmail.com> | 2020-06-23 10:55:11 -0400 |
| commit | 7d61d4e6ff2e15dc3c7f166d407a203594a9c90b (patch) | |
| tree | 50afd8556a5521ba8a7b62320a5e8ae6d40ff824 /src/code | |
| parent | 2d191e301a4d6a4a49b62b31b17110c17df2afb5 (diff) | |
Decompile `game.c`
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/game.c | 262 | ||||
| -rw-r--r-- | src/code/title_setup.c | 66 | ||||
| -rw-r--r-- | src/code/z_prenmi.c | 4 | ||||
| -rw-r--r-- | src/code/z_rcp.c | 2 |
4 files changed, 331 insertions, 3 deletions
diff --git a/src/code/game.c b/src/code/game.c new file mode 100644 index 000000000..206cd69a4 --- /dev/null +++ b/src/code/game.c @@ -0,0 +1,262 @@ +#include <ultra64.h> +#include <global.h> + +s32 gFramerateDivisor = 1; +f32 gFramerateDivisorF = 1.0f; +f32 gFramerateDivisorHalf = 1.0f / 2.0f; +f32 gFramerateDivisorThird = 1.0f / 3.0f; + +u32 D_801D1510 = 0x0000000A; +u32 D_801D1514[3] = { 0 }; + +void Game_UpdateFramerateVariables(s32 divisor) { + gFramerateDivisor = divisor; + gFramerateDivisorF = (f32) divisor; + gFramerateDivisorHalf = (f32) (divisor * 0.5f); + gFramerateDivisorThird = (f32) (divisor / 3.0f); +} + +void Game_SetFramerateDivisor(GameState *gameState, s32 divisor) { + R_UPDATE_RATE = (s16) divisor; + gameState->framerateDivisor = divisor; + Game_UpdateFramerateVariables(divisor); +} + +void GameState_SetFBFilter(Gfx** gfx, u32 arg1) { + Gfx* _gfx = *gfx; + + if ((R_FB_FILTER_TYPE > 0) && (R_FB_FILTER_TYPE < 5)) { + D_801F8010.type = R_FB_FILTER_TYPE; + D_801F8010.color.red = R_FB_FILTER_PRIM_COLOR(0); + D_801F8010.color.green = R_FB_FILTER_PRIM_COLOR(1); + D_801F8010.color.blue = R_FB_FILTER_PRIM_COLOR(2); + D_801F8010.color.alpha = R_FB_FILTER_A; + func_80140D10(&D_801F8010, &_gfx, arg1); + } else { + if ((R_FB_FILTER_TYPE == 5) || (R_FB_FILTER_TYPE == 6)) { + D_801F8020.useRgba = (R_FB_FILTER_TYPE == 6); + D_801F8020.primColor.red = R_FB_FILTER_PRIM_COLOR(0); + D_801F8020.primColor.green = R_FB_FILTER_PRIM_COLOR(1); + D_801F8020.primColor.blue = R_FB_FILTER_PRIM_COLOR(2); + D_801F8020.primColor.alpha = R_FB_FILTER_A; + D_801F8020.envColor.red = R_FB_FILTER_ENV_COLOR(0); + D_801F8020.envColor.green = R_FB_FILTER_ENV_COLOR(1); + D_801F8020.envColor.blue = R_FB_FILTER_ENV_COLOR(2); + D_801F8020.envColor.alpha = R_FB_FILTER_A; + func_80142100(&D_801F8020, &_gfx, arg1); + } else { + if (R_FB_FILTER_TYPE == 7) { + sMonoColors.unk_00 = 0; + sMonoColors.primColor.red = R_FB_FILTER_PRIM_COLOR(0); + sMonoColors.primColor.green = R_FB_FILTER_PRIM_COLOR(1); + sMonoColors.primColor.blue = R_FB_FILTER_PRIM_COLOR(2); + sMonoColors.primColor.alpha = R_FB_FILTER_A; + sMonoColors.envColor.red = R_FB_FILTER_ENV_COLOR(0); + sMonoColors.envColor.green = R_FB_FILTER_ENV_COLOR(1); + sMonoColors.envColor.blue = R_FB_FILTER_ENV_COLOR(2); + sMonoColors.envColor.alpha = R_FB_FILTER_A; + VisMono_Draw(&sMonoColors, &_gfx, arg1); + } + } + } + + *gfx = _gfx; +} + +void Game_Nop80173534(GameState *ctxt) { + ; +} + +void GameState_Draw(GameState *ctxt, GraphicsContext *gCtxt) { + Gfx* nextDisplayList; + Gfx* _polyOpa; + // Unused vars impact regalloc + Gfx* temp_t2; + u32 temp_v1; + + _polyOpa = gCtxt->polyOpa.p; + nextDisplayList = Graph_GfxPlusOne(gCtxt->polyOpa.p); + gSPDisplayList(gCtxt->overlay.p++, nextDisplayList); + + if (R_FB_FILTER_TYPE && R_FB_FILTER_ENV_COLOR(3) == 0) { + GameState_SetFBFilter(&nextDisplayList, (u32) gCtxt->zbuffer); + } + + if (R_ENABLE_ARENA_DBG < 0) { + R_ENABLE_ARENA_DBG = 0; + } + + gSPEndDisplayList(nextDisplayList++); + Graph_BranchDlist(_polyOpa, nextDisplayList); + gCtxt->polyOpa.p = nextDisplayList; + +lblUnk:; // Label prevents reordering, if(1) around the above block don't seem to help unlike in OoT + func_800E9F78(gCtxt); + + if (R_ENABLE_ARENA_DBG != 0) { + SpeedMeter_DrawTimeEntries(&D_801F7FF0, gCtxt); + SpeedMeter_DrawAllocEntries(&D_801F7FF0, gCtxt, ctxt); + } +} + +void Game_ResetSegments(GraphicsContext *gCtxt) { + gSPSegment(gCtxt->polyOpa.p++, 0, 0); + gSPSegment(gCtxt->polyOpa.p++, 0xF, gCtxt->framebuffer); + gSPSegment(gCtxt->polyXlu.p++, 0, 0); + gSPSegment(gCtxt->polyXlu.p++, 0xF, gCtxt->framebuffer); + gSPSegment(gCtxt->overlay.p++, 0, 0); + gSPSegment(gCtxt->overlay.p++, 0xF, gCtxt->framebuffer); +} + +void func_801736DC(GraphicsContext *gCtxt) { + Gfx* nextDisplayList; + Gfx* _polyOpa; + + nextDisplayList = Graph_GfxPlusOne(_polyOpa = gCtxt->polyOpa.p); + gSPDisplayList(gCtxt->overlay.p++, nextDisplayList); + gSPEndDisplayList(nextDisplayList++); + Graph_BranchDlist(_polyOpa, nextDisplayList); + + gCtxt->polyOpa.p = nextDisplayList; +} + +void Game_UpdateInput(GameState *ctxt) { + Padmgr_GetInput(ctxt->input, 1); +} + +void Game_Update(GameState *ctxt) { + GraphicsContext* _gCtx; + _gCtx = ctxt->gfxCtx; + + Game_ResetSegments(ctxt->gfxCtx); + + ctxt->main(ctxt); + + if (R_PAUSE_MENU_MODE != 2) { + GameState_Draw(ctxt, _gCtx); + func_801736DC(_gCtx); + } +} + +void Game_IncrementFrameCount(GameState *ctxt) { + Game_Nop80173534(ctxt); + ctxt->frames++; +} + +void Game_InitHeap(GameState *ctxt, u32 size) { + GameState *_ctx; + void *buf; + + _ctx = ctxt; + buf = Gamealloc_Alloc(&_ctx->alloc, size); + + if (buf) { + GameStateHeap_Init(&ctxt->heap, buf, size); + return; + } + + GameStateHeap_Init(&ctxt->heap, NULL, 0); + assert_fail("../game.c", 0x40B); +} + +void Game_ResizeHeap(GameState *ctxt, u32 size) +{ + GameAlloc *alloc; + void *buf; + u32 systemMaxFree; + u32 bytesFree; + u32 bytesAllocated; + void *heapStart; + + heapStart = ctxt->heap.heapStart; + alloc = &ctxt->alloc; + GameStateHeap_Clear(&ctxt->heap); + Gamealloc_Free(alloc, heapStart); + StartHeap_AnalyzeArena(&systemMaxFree, &bytesFree, &bytesAllocated); + size = ((systemMaxFree - (sizeof(ArenaNode))) < size) ? (0) : (size); + if (!size) + { + size = systemMaxFree - (sizeof(ArenaNode)); + } + + if (buf = Gamealloc_Alloc(alloc, size)) + { + GameStateHeap_Init(&ctxt->heap, buf, size); + } + else + { + GameStateHeap_Init(&ctxt->heap, 0, 0); + assert_fail("../game.c", 0x432); + } +} + +void Game_StateInit(GameState *ctxt, GameStateFunc gameStateInit, GraphicsContext *gCtxt) { + ctxt->gfxCtx = gCtxt; + ctxt->frames = 0U; + ctxt->main = NULL; + ctxt->destroy = NULL; + ctxt->running = 1; + gCtxt->unk274 = D_801FBB88; + gCtxt->viConfigFeatures = gViConfigFeatures; + gCtxt->viConfigXScale = gViConfigXScale; + gCtxt->viConfigYScale = gViConfigYScale; + ctxt->nextGameStateInit = NULL; + ctxt->nextGameStateSize = 0U; + +lblUnk:; + Gamealloc_Init(&ctxt->alloc); + Game_InitHeap(ctxt, 0x100000); + Game_SetFramerateDivisor(ctxt, 3); + + gameStateInit(ctxt); + + func_80140CE0(&D_801F8010); + func_801420C0(&D_801F8020); + func_801418B0(&sMonoColors); + func_80140898(&D_801F8048); + func_801773A0(&D_801F7FF0); + func_8013ED9C(); + + osSendMesg(&ctxt->gfxCtx->unk5C, NULL, 1); +} + +void Game_StateFini(GameState *ctxt) { + func_80172BC0(); + func_8019E014(); + osRecvMesg(&ctxt->gfxCtx->unk5C, 0, 1); + + if (ctxt->destroy != 0) { + ctxt->destroy(ctxt); + } + + func_8013EDD0(); + func_801773C4(&D_801F7FF0); + func_80140D04(&D_801F8010); + func_801420F4(&D_801F8020); + func_80141900(&sMonoColors); + func_80140900(&D_801F8048); + GameStateHeap_Clear(&ctxt->heap); + Gamealloc_FreeAll(&ctxt->alloc); +} + +GameStateFunc Game_GetNextStateInit(GameState *ctxt) { + return ctxt->nextGameStateInit; +} + +u32 Game_GetNextStateSize(GameState *ctxt) { + return ctxt->nextGameStateSize; +} + +u32 Game_GetShouldContinue(GameState *ctxt) { + return ctxt->running; +} + +s32 Game_GetHeapFreeSize(GameState *ctxt) { + return GameStateHeap_GetFreeSize(&ctxt->heap); +} + +s32 func_80173B48(GameState *ctxt) { + s32 result; + result = OS_CYCLES_TO_NSEC(ctxt->framerateDivisor * sIrqMgrRetraceTime) - OS_CYCLES_TO_NSEC(D_801FBAF0); + return result; +} diff --git a/src/code/title_setup.c b/src/code/title_setup.c new file mode 100644 index 000000000..9fae78492 --- /dev/null +++ b/src/code/title_setup.c @@ -0,0 +1,66 @@ +#include <ultra64.h> +#include <global.h> + +void TitleSetup_GameStateResetContext(void) { + XREG(2) = 0; + XREG(10) = 0x1A; + XREG(11) = 0x14; + XREG(12) = 0xE; + XREG(13) = 0; + XREG(31) = 0; + XREG(41) = 0x50; + XREG(43) = 0xFFFFFC54; + + XREG(44) = 0xD7; + XREG(45) = 0xDA; + XREG(68) = 0x61; + XREG(69) = 0x93; + XREG(70) = 0x28; + XREG(73) = 0x1E; + XREG(74) = 0x42; + XREG(75) = 0x1E; + XREG(76) = 0x1C; + XREG(77) = 0x3C; + XREG(78) = 0x2F; + XREG(79) = 0x62; + XREG(87) = 0; + XREG(88) = 0x56; + XREG(89) = 0x258; + XREG(90) = 0x1C2; + XREG(91) = 0; + XREG(94) = 0; + XREG(95) = 0; + + YREG(32) = 0x50; + YREG(33) = 0x3C; + YREG(34) = 0xDC; + YREG(35) = 0x3C; + YREG(36) = 0x50; + YREG(37) = 0xA0; + YREG(38) = 0xDC; + YREG(39) = 0xA0; + YREG(40) = 0x8E; + YREG(41) = 0x6C; + YREG(42) = 0xCC; + YREG(43) = 0xB1; +} + +void TitleSetup_InitImpl(GameState *gameState) { + func_80185908(); + func_800E9360(); + TitleSetup_GameStateResetContext(); + + gameState->running = 0; + +setNextGamestate:; // This label is probably a leftover of a debug ifdef, it's essential to not have gameState->running reordered! + SET_NEXT_GAMESTATE(gameState, &Title_Init, TitleContext); +} + +void TitleSetup_Destroy(GameState *gameState) { + ; +} + +void TitleSetup_Init(GameState *gameState) { + gameState->destroy = &TitleSetup_Destroy; + TitleSetup_InitImpl(gameState); +} diff --git a/src/code/z_prenmi.c b/src/code/z_prenmi.c index e2e9721da..bf2dd00a1 100644 --- a/src/code/z_prenmi.c +++ b/src/code/z_prenmi.c @@ -43,8 +43,8 @@ void PreNMI_Main(PreNMIContext* prenmiCtx) { void PreNMI_Destroy(PreNMIContext* prenmiCtx) {} void PreNMI_Init(PreNMIContext* prenmiCtx) { - prenmiCtx->state.main = (func_ptr)PreNMI_Main; - prenmiCtx->state.destroy = (func_ptr)PreNMI_Destroy; + prenmiCtx->state.main = (GameStateFunc)PreNMI_Main; + prenmiCtx->state.destroy = (GameStateFunc)PreNMI_Destroy; prenmiCtx->timer = 30; prenmiCtx->unkA8 = 10; diff --git a/src/code/z_rcp.c b/src/code/z_rcp.c index f56a26eea..ba3e24b29 100644 --- a/src/code/z_rcp.c +++ b/src/code/z_rcp.c @@ -1307,7 +1307,7 @@ GLOBAL_ASM("asm/non_matchings/z_rcp/func_8012CF0C.asm") #endif void func_8012D374(GraphicsContext* gCtxt, u8 r, u8 g, u8 b) { - if ((gStaticContext->data[0xbe] < 2) && (D_801F6D10 < 2)) { + if ((R_PAUSE_MENU_MODE < 2) && (D_801F6D10 < 2)) { func_8012CF0C(gCtxt, 1, 1, r, g, b); } else { |
