diff --git a/include/functions.h b/include/functions.h index 65514ca8e0..4cfd6cfe28 100644 --- a/include/functions.h +++ b/include/functions.h @@ -2927,8 +2927,8 @@ s32 ShrinkWindow_GetPillarboxTarget(void); void ShrinkWindow_SetPillarboxMagnitude(s32 magnitude); s32 ShrinkWindow_GetPillarboxMagnitude(void); void ShrinkWindow_Init(void); -void ShrinkWindow_Fini(void); -void ShrinkWindow_Step(s32 framerateDivisor); +void ShrinkWindow_Destroy(void); +void ShrinkWindow_Update(s32 framerateDivisor); void ShrinkWindow_Draw(GraphicsContext* gfxCtx); // void func_80161180(void); // void func_8016119C(void); diff --git a/spec b/spec index 0faeb12290..a569dba5fa 100644 --- a/spec +++ b/spec @@ -581,7 +581,6 @@ beginseg include "build/src/code/z_player_call.o" include "build/data/code/z_player_call.bss.o" include "build/src/code/z_shrink_window.o" - include "build/data/code/z_shrink_window.bss.o" include "build/src/code/db_camera.o" include "build/data/code/db_camera.bss.o" include "build/data/code/code_801D0B50.data.o" diff --git a/src/code/z_shrink_window.c b/src/code/z_shrink_window.c index 3b2d861144..194ee50839 100644 --- a/src/code/z_shrink_window.c +++ b/src/code/z_shrink_window.c @@ -1,25 +1,121 @@ +/** + * File: z_shrink_window.c + * Description: Draws black top/bottom/side borders on the viewing window (e.g. Z-targeting, talking to NPC) + */ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_SetLetterboxTarget.s") +ShrinkWindowContext gShrinkWindowContext; +ShrinkWindowContext* gShrinkWindowContextPtr; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_GetLetterboxTarget.s") +void ShrinkWindow_SetLetterboxTarget(s32 target) { + gShrinkWindowContextPtr->letterboxTarget = target; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_SetLetterboxMagnitude.s") +s32 ShrinkWindow_GetLetterboxTarget(void) { + return gShrinkWindowContextPtr->letterboxTarget; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_GetLetterboxMagnitude.s") +void ShrinkWindow_SetLetterboxMagnitude(s32 magnitude) { + gShrinkWindowContextPtr->letterboxMagnitude = magnitude; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_SetPillarboxTarget.s") +s32 ShrinkWindow_GetLetterboxMagnitude(void) { + return gShrinkWindowContextPtr->letterboxMagnitude; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_GetPillarboxTarget.s") +void ShrinkWindow_SetPillarboxTarget(s32 target) { + gShrinkWindowContextPtr->pillarboxTarget = target; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_SetPillarboxMagnitude.s") +s32 ShrinkWindow_GetPillarboxTarget(void) { + return gShrinkWindowContextPtr->pillarboxTarget; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_GetPillarboxMagnitude.s") +void ShrinkWindow_SetPillarboxMagnitude(s32 magnitude) { + gShrinkWindowContextPtr->pillarboxMagnitude = magnitude; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_Init.s") +s32 ShrinkWindow_GetPillarboxMagnitude(void) { + return gShrinkWindowContextPtr->pillarboxMagnitude; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_Fini.s") +void ShrinkWindow_Init(void) { + gShrinkWindowContextPtr = &gShrinkWindowContext; + bzero(gShrinkWindowContextPtr, sizeof(gShrinkWindowContext)); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_Step.s") +void ShrinkWindow_Destroy(void) { + gShrinkWindowContextPtr = NULL; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_shrink_window/ShrinkWindow_Draw.s") +void ShrinkWindow_Update(s32 framerateDivisor) { + s32 step = ((framerateDivisor == 3) ? 10 : 30 / framerateDivisor); + s32 nextMagnitude; + + nextMagnitude = gShrinkWindowContextPtr->letterboxMagnitude; + Math_StepToIGet(&nextMagnitude, gShrinkWindowContextPtr->letterboxTarget, step); + gShrinkWindowContextPtr->letterboxMagnitude = nextMagnitude; + + nextMagnitude = gShrinkWindowContextPtr->pillarboxMagnitude; + Math_StepToIGet(&nextMagnitude, gShrinkWindowContextPtr->pillarboxTarget, step); + gShrinkWindowContextPtr->pillarboxMagnitude = nextMagnitude; +} + +void ShrinkWindow_Draw(GraphicsContext* gfxCtx) { + Gfx* gfx; + s8 letterboxMagnitude = gShrinkWindowContextPtr->letterboxMagnitude; + s8 pillarboxMagnitude = gShrinkWindowContextPtr->pillarboxMagnitude; + + if (letterboxMagnitude > 0) { + OPEN_DISPS(gfxCtx); + + gfx = OVERLAY_DISP; + + gDPPipeSync(gfx++); + gDPSetCycleType(gfx++, G_CYC_FILL); + gDPSetRenderMode(gfx++, G_RM_NOOP, G_RM_NOOP2); + gDPSetFillColor(gfx++, (GPACK_RGBA5551(0, 0, 0, 1) << 16) | GPACK_RGBA5551(0, 0, 0, 1)); + gDPFillRectangle(gfx++, 0, 0, gScreenWidth - 1, letterboxMagnitude - 1); + gDPFillRectangle(gfx++, 0, gScreenHeight - letterboxMagnitude, gScreenWidth - 1, gScreenHeight - 1); + + gDPPipeSync(gfx++); + gDPSetCycleType(gfx++, G_CYC_1CYCLE); + gDPSetRenderMode(gfx++, G_RM_XLU_SURF, G_RM_XLU_SURF2); + gDPSetPrimColor(gfx++, 0, 0, 0, 0, 0, 0); + gDPFillRectangle(gfx++, 0, letterboxMagnitude, gScreenWidth, letterboxMagnitude + 1); + gDPFillRectangle(gfx++, 0, gScreenHeight - letterboxMagnitude - 1, gScreenWidth, + gScreenHeight - letterboxMagnitude); + + gDPPipeSync(gfx++); + OVERLAY_DISP = gfx++; + + CLOSE_DISPS(gfxCtx); + } + if (pillarboxMagnitude > 0) { + OPEN_DISPS(gfxCtx); + + gfx = OVERLAY_DISP; + + gDPPipeSync(gfx++); + gDPSetCycleType(gfx++, G_CYC_FILL); + gDPSetRenderMode(gfx++, G_RM_NOOP, G_RM_NOOP2); + gDPSetFillColor(gfx++, (GPACK_RGBA5551(0, 0, 0, 1) << 16) | GPACK_RGBA5551(0, 0, 0, 1)); + + gDPFillRectangle(gfx++, 0, 0, pillarboxMagnitude - 1, gScreenHeight - 1); + gDPFillRectangle(gfx++, gScreenWidth - pillarboxMagnitude, 0, gScreenWidth - 1, gScreenHeight - 1); + + gDPPipeSync(gfx++); + gDPSetCycleType(gfx++, G_CYC_1CYCLE); + gDPSetRenderMode(gfx++, G_RM_XLU_SURF, G_RM_XLU_SURF2); + gDPSetPrimColor(gfx++, 0, 0, 0, 0, 0, 0); + + gDPFillRectangle(gfx++, pillarboxMagnitude, 0, pillarboxMagnitude + 2, gScreenHeight); + gDPFillRectangle(gfx++, gScreenWidth - pillarboxMagnitude - 2, 0, gScreenWidth - pillarboxMagnitude, + gScreenHeight); + + gDPPipeSync(gfx++); + OVERLAY_DISP = gfx++; + + CLOSE_DISPS(gfxCtx); + } +} diff --git a/src/overlays/gamestates/ovl_daytelop/z_daytelop.c b/src/overlays/gamestates/ovl_daytelop/z_daytelop.c index ba34c24482..d4c729d564 100644 --- a/src/overlays/gamestates/ovl_daytelop/z_daytelop.c +++ b/src/overlays/gamestates/ovl_daytelop/z_daytelop.c @@ -205,7 +205,7 @@ void Daytelop_Main(GameState* thisx) { } void Daytelop_Destroy(GameState* thisx) { - ShrinkWindow_Fini(); + ShrinkWindow_Destroy(); } void Daytelop_nop80815770(DaytelopContext* this) { @@ -227,7 +227,7 @@ void Daytelop_Init(GameState* thisx) { Game_SetFramerateDivisor(thisx, 1); SysMatrix_StateAlloc(thisx); - ShrinkWindow_Fini(); + ShrinkWindow_Destroy(); View_Init(&this->view, thisx->gfxCtx); thisx->main = Daytelop_Main; thisx->destroy = Daytelop_Destroy; diff --git a/src/overlays/gamestates/ovl_opening/z_opening.c b/src/overlays/gamestates/ovl_opening/z_opening.c index b19955071a..f3279db4ed 100644 --- a/src/overlays/gamestates/ovl_opening/z_opening.c +++ b/src/overlays/gamestates/ovl_opening/z_opening.c @@ -43,7 +43,7 @@ void Opening_Main(GameState* thisx) { } void Opening_Destroy(GameState* thisx) { - ShrinkWindow_Fini(); + ShrinkWindow_Destroy(); } void Opening_Init(GameState* thisx) { diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index da6808725b..d58f7ac856 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -887,7 +887,7 @@ void Select_Main(GameState* thisx) { } void Select_Destroy(GameState* thisx) { - ShrinkWindow_Fini(); + ShrinkWindow_Destroy(); } void Select_Init(GameState* thisx) { diff --git a/src/overlays/gamestates/ovl_title/z_title.c b/src/overlays/gamestates/ovl_title/z_title.c index 83e3f487ad..c8027fcbe4 100644 --- a/src/overlays/gamestates/ovl_title/z_title.c +++ b/src/overlays/gamestates/ovl_title/z_title.c @@ -145,7 +145,7 @@ void Title_Destroy(GameState* thisx) { TitleContext* this = (TitleContext*)thisx; func_80146E40(&this->gameState, &this->sramCtx); - ShrinkWindow_Fini(); + ShrinkWindow_Destroy(); CIC6105_Nop80081828(); } diff --git a/tools/actorfixer.py b/tools/actorfixer.py index 16100c9261..238c7f9c04 100755 --- a/tools/actorfixer.py +++ b/tools/actorfixer.py @@ -20,6 +20,8 @@ animdict ={ "func_800F0568": "Audio_PlaySoundAtPosition", "func_8016970C": "Play_CameraSetAtEye", "func_800BBA88": "Enemy_StartFinishingBlow", + "ShrinkWindow_Step": "ShrinkWindow_Update", + "ShrinkWindow_Fini": "ShrinkWindow_Destroy", "func_801A89A8": "Audio_QueueSeqCmd", } diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 558565b7dc..b64e05c56b 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -2901,8 +2901,8 @@ 0x80160C78:("ShrinkWindow_SetPillarboxMagnitude",), 0x80160C8C:("ShrinkWindow_GetPillarboxMagnitude",), 0x80160CA0:("ShrinkWindow_Init",), - 0x80160CD4:("ShrinkWindow_Fini",), - 0x80160CE4:("ShrinkWindow_Step",), + 0x80160CD4:("ShrinkWindow_Destroy",), + 0x80160CE4:("ShrinkWindow_Update",), 0x80160D98:("ShrinkWindow_Draw",), 0x80161180:("func_80161180",), 0x8016119C:("func_8016119C",),