diff options
| author | mzxrules <mzxrules@gmail.com> | 2023-05-29 17:40:10 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-29 17:40:10 -0400 |
| commit | 65d72a54cf712292f0bb97af8eeaa10c2eeb2e8c (patch) | |
| tree | 25b5e09d8aea798a67649b388aef95e13c8e68e8 /src | |
| parent | aa0a968791eb62ab02f2ce0b9e073362ebdd7243 (diff) | |
z_syscfb.c, z_vimode.c, code_80140CE0 split and OK (#1159)
* z_vimode
* Fixups
* WIP
* matching
* sys_cfb OK
* some documentation
* vimode docs, name all syscfb vars
* quick fixes
* suggested changes, more things I missed
* merge suggestions
* code_80140CE0 -> z_viscvg
* format
* update symbols
* more suggestions
* fix include order
* sNotebookViMode comment, bss fix
---------
Co-authored-by: Kelebek1 <eeeedddccc@hotmail.co.uk>
Co-authored-by: louist103 <louist103@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/code/code_80140CE0.c | 7 | ||||
| -rw-r--r-- | src/code/game.c | 12 | ||||
| -rw-r--r-- | src/code/graph.c | 29 | ||||
| -rw-r--r-- | src/code/sys_cfb.c | 125 | ||||
| -rw-r--r-- | src/code/z_actor.c | 2 | ||||
| -rw-r--r-- | src/code/z_demo.c | 1 | ||||
| -rw-r--r-- | src/code/z_fbdemo_circle.c | 4 | ||||
| -rw-r--r-- | src/code/z_kankyo.c | 2 | ||||
| -rw-r--r-- | src/code/z_lights.c | 11 | ||||
| -rw-r--r-- | src/code/z_parameter.c | 10 | ||||
| -rw-r--r-- | src/code/z_play.c | 30 | ||||
| -rw-r--r-- | src/code/z_rcp.c | 14 | ||||
| -rw-r--r-- | src/code/z_view.c | 4 | ||||
| -rw-r--r-- | src/code/z_vimode.c | 376 | ||||
| -rw-r--r-- | src/code/z_viscvg.c | 90 | ||||
| -rw-r--r-- | src/code/z_viszbuf.c | 8 | ||||
| -rw-r--r-- | src/libultra/io/osViModeMpalLan1.c | 39 | ||||
| -rw-r--r-- | src/libultra/io/osViModeNtscHpf1.c | 39 | ||||
| -rw-r--r-- | src/libultra/io/osViModeNtscLan1.c | 39 | ||||
| -rw-r--r-- | src/libultra/io/osViModePalLan1.c | 39 | ||||
| -rw-r--r-- | src/overlays/actors/ovl_En_Test3/z_en_test3.c | 1 | ||||
| -rw-r--r-- | src/overlays/actors/ovl_player_actor/z_player.c | 1 | ||||
| -rw-r--r-- | src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c | 6 |
23 files changed, 721 insertions, 168 deletions
diff --git a/src/code/code_80140CE0.c b/src/code/code_80140CE0.c deleted file mode 100644 index f3d487fab..000000000 --- a/src/code/code_80140CE0.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "global.h" - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80140CE0/func_80140CE0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80140CE0/func_80140D04.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80140CE0/func_80140D10.s") diff --git a/src/code/game.c b/src/code/game.c index bc8b9e39f..c98241177 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -31,7 +31,7 @@ void GameState_SetFBFilter(Gfx** gfx, void* zbuffer) { D_801F8010.color.g = R_FB_FILTER_PRIM_COLOR(1); D_801F8010.color.b = R_FB_FILTER_PRIM_COLOR(2); D_801F8010.color.a = R_FB_FILTER_A; - func_80140D10(&D_801F8010, &dlist, zbuffer); + VisCvg_Draw(&D_801F8010, &dlist); } else if ((R_FB_FILTER_TYPE == 5) || (R_FB_FILTER_TYPE == 6)) { sVisZbuf.useRgba = (R_FB_FILTER_TYPE == 6); sVisZbuf.primColor.r = R_FB_FILTER_PRIM_COLOR(0); @@ -194,7 +194,7 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g gameState->main = NULL; gameState->destroy = NULL; gameState->running = 1; - gfxCtx->viMode = D_801FBB88; + gfxCtx->viMode = gActiveViMode; gfxCtx->viConfigFeatures = gViConfigFeatures; gfxCtx->xScale = gViConfigXScale; gfxCtx->yScale = gViConfigYScale; @@ -210,10 +210,10 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g init(gameState); - func_80140CE0(&D_801F8010); + VisCvg_Init(&D_801F8010); VisZbuf_Init(&sVisZbuf); VisMono_Init(&sMonoColors); - func_80140898(&D_801F8048); + ViMode_Init(&D_801F8048); func_801773A0(&D_801F7FF0); Rumble_Init(); @@ -232,10 +232,10 @@ void GameState_Destroy(GameState* gameState) { Rumble_Destroy(); func_801773C4(&D_801F7FF0); - func_80140D04(&D_801F8010); + VisCvg_Destroy(&D_801F8010); VisZbuf_Destroy(&sVisZbuf); VisMono_Destroy(&sMonoColors); - func_80140900(&D_801F8048); + ViMode_Destroy(&D_801F8048); THA_Destroy(&gameState->heap); GameAlloc_Cleanup(&gameState->alloc); } diff --git a/src/code/graph.c b/src/code/graph.c index 558f7d563..bf9067b69 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -16,12 +16,12 @@ OSTime sGraphTaskStartTime; void Graph_FaultClient(void) { FaultDrawer_DrawText(30, 100, "ShowFrameBuffer PAGE 0/1"); - osViSwapBuffer(SysCfb_GetFbPtr(0)); - osViSetMode(D_801FBB88); + osViSwapBuffer(SysCfb_GetFramebuffer(0)); + osViSetMode(gActiveViMode); osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF); Fault_WaitForInput(); - osViSwapBuffer(SysCfb_GetFbPtr(1)); - osViSetMode(D_801FBB88); + osViSwapBuffer(SysCfb_GetFramebuffer(1)); + osViSetMode(gActiveViMode); osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF); } @@ -50,7 +50,7 @@ void Graph_SetNextGfxPool(GraphicsContext* gfxCtx) { gfxCtx->workBuffer = pool->workBuffer; gfxCtx->debugBuffer = pool->debugBuffer; - gfxCtx->curFrameBuffer = SysCfb_GetFbPtr(gfxCtx->framebufferIndex % 2); + gfxCtx->curFrameBuffer = SysCfb_GetFramebuffer(gfxCtx->framebufferIndex % 2); gSegments[0x0F] = gfxCtx->curFrameBuffer; gfxCtx->zbuffer = SysCfb_GetZBuffer(); @@ -179,7 +179,7 @@ retry: task->dramStack = (u64*)gGfxSPTaskStack; task->dramStackSize = sizeof(gGfxSPTaskStack); task->outputBuff = gGfxSPTaskOutputBufferPtr; - task->outputBuffSize = gGfxSPTaskOutputBufferSize; + task->outputBuffSize = gGfxSPTaskOutputBufferEnd; task->dataPtr = (u64*)gGfxMasterDL; task->dataSize = 0; task->yieldDataPtr = (u64*)gGfxSPTaskYieldBuffer; @@ -340,18 +340,19 @@ void Graph_ThreadEntry(void* arg) { u32 size; s32 pad[2]; - gZBuffer = SystemArena_Malloc(sizeof(*gZBuffer) + sizeof(*gWorkBuffer) + 64 - 1); - gZBuffer = (void*)ALIGN64((u32)gZBuffer); + gZBufferLoRes = SystemArena_Malloc(sizeof(*gZBufferLoRes) + sizeof(*gWorkBufferLoRes) + 64 - 1); + gZBufferLoRes = (void*)ALIGN64((u32)gZBufferLoRes); - gWorkBuffer = (void*)((u8*)gZBuffer + sizeof(*gZBuffer)); + gWorkBufferLoRes = (void*)((u8*)gZBufferLoRes + sizeof(*gZBufferLoRes)); - gGfxSPTaskOutputBuffer2 = gGfxSPTaskOutputBuffer = SystemArena_Malloc(sizeof(*gGfxSPTaskOutputBuffer)); + gGfxSPTaskOutputBufferHiRes = gGfxSPTaskOutputBufferLoRes = + SystemArena_Malloc(sizeof(*gGfxSPTaskOutputBufferLoRes)); - gGfxSPTaskOutputBufferEnd = (u8*)gGfxSPTaskOutputBuffer + sizeof(*gGfxSPTaskOutputBuffer); - gGfxSPTaskOutputBufferEnd2 = (u8*)gGfxSPTaskOutputBuffer2 + sizeof(*gGfxSPTaskOutputBuffer2); + gGfxSPTaskOutputBufferEndLoRes = (u8*)gGfxSPTaskOutputBufferLoRes + sizeof(*gGfxSPTaskOutputBufferLoRes); + gGfxSPTaskOutputBufferEndHiRes = (u8*)gGfxSPTaskOutputBufferHiRes + sizeof(*gGfxSPTaskOutputBufferHiRes); - func_80178978(); - Fault_SetFB(D_801FBB90, SCREEN_WIDTH, SCREEN_HEIGHT); + SysCfb_Init(); + Fault_SetFB(gWorkBuffer, SCREEN_WIDTH, SCREEN_HEIGHT); Graph_Init(&gfxCtx); while (nextOvl) { diff --git a/src/code/sys_cfb.c b/src/code/sys_cfb.c index 25d92227c..16c39855c 100644 --- a/src/code/sys_cfb.c +++ b/src/code/sys_cfb.c @@ -2,20 +2,127 @@ #include "buffers.h" #include "system_malloc.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/func_80178750.s") +extern u16 gFramebufferHiRes0[HIRES_BUFFER_WIDTH][HIRES_BUFFER_HEIGHT]; +extern u16 gFramebufferHiRes1[HIRES_BUFFER_WIDTH][HIRES_BUFFER_HEIGHT]; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/func_80178818.s") +OSViMode sNotebookViMode; // placeholder name +void* gFramebuffers[2]; +OSViMode* gActiveViMode; +u16* gZBufferPtr; +void* gWorkBuffer; +u64* gGfxSPTaskOutputBufferPtr; +void* gGfxSPTaskOutputBufferEnd; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/func_80178978.s") +void* sCfbLoRes1; +void* sCfbLoRes0; +u16 (*gZBufferLoRes)[SCREEN_WIDTH * SCREEN_HEIGHT]; +u16 (*gWorkBufferLoRes)[SCREEN_WIDTH * SCREEN_HEIGHT]; +u64 (*gGfxSPTaskOutputBufferLoRes)[0x3000]; +void* gGfxSPTaskOutputBufferEndLoRes; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/func_801789D4.s") +void* sCfbHiRes1; +void* sCfbHiRes0; +u16 (*gZBufferHiRes)[HIRES_BUFFER_WIDTH * HIRES_BUFFER_HEIGHT]; +u16 (*gWorkBufferHiRes)[HIRES_BUFFER_WIDTH * HIRES_BUFFER_HEIGHT]; +u64 (*gGfxSPTaskOutputBufferHiRes)[0x3000]; +void* gGfxSPTaskOutputBufferEndHiRes; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/SysCfb_GetFbPtr.s") +s16 gCfbWidth; +s16 gCfbHeight; +s16 gCfbLeftAdjust; +s16 gCfbUpperAdjust; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/SysCfb_GetZBuffer.s") +u8 gSysCfbHiResEnabled; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/func_80178A24.s") +void SysCfb_SetLoResMode(void) { + gFramebuffers[1] = sCfbLoRes1; + gFramebuffers[0] = sCfbLoRes0; + gZBufferPtr = *gZBufferLoRes; + gWorkBuffer = gWorkBufferLoRes; + gGfxSPTaskOutputBufferPtr = *gGfxSPTaskOutputBufferLoRes; + gGfxSPTaskOutputBufferEnd = gGfxSPTaskOutputBufferEndLoRes; + gCfbWidth = SCREEN_WIDTH; + gCfbHeight = SCREEN_HEIGHT; + gCfbLeftAdjust = 0; + gCfbUpperAdjust = 0; + gSysCfbHiResEnabled = false; + gScreenWidth = gCfbWidth; + gScreenHeight = gCfbHeight; + gActiveViMode = &osViModeNtscLan1; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/func_80178A34.s") +void SysCfb_SetHiResMode(void) { + gFramebuffers[1] = sCfbHiRes1; + gFramebuffers[0] = sCfbHiRes0; + gZBufferPtr = *gZBufferHiRes; + gWorkBuffer = gWorkBufferHiRes; + gGfxSPTaskOutputBufferPtr = *gGfxSPTaskOutputBufferHiRes; + gGfxSPTaskOutputBufferEnd = gGfxSPTaskOutputBufferEndHiRes; + if (1) {} + gCfbWidth = HIRES_BUFFER_WIDTH; + gCfbHeight = HIRES_BUFFER_HEIGHT; + gCfbLeftAdjust = 30; + gCfbUpperAdjust = 10; + gScreenWidth = gCfbWidth; + gScreenHeight = gCfbHeight; + if ((gCfbWidth == SCREEN_WIDTH_HIRES) && (gCfbHeight == SCREEN_HEIGHT_HIRES)) { + gActiveViMode = &osViModeNtscHpf1; + } else { + s32 rightAdjust; + s32 lowerAdjust; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_cfb/func_80178A94.s") + //! FAKE: + l1: + rightAdjust = gCfbWidth - 610; + lowerAdjust = gCfbHeight - 470; + ViMode_Configure(&sNotebookViMode, -1, osTvType, 0, 1, 0, 1, gCfbWidth, gCfbHeight, 30, rightAdjust, 10, + lowerAdjust); + gActiveViMode = &sNotebookViMode; + } + gSysCfbHiResEnabled = true; +} + +void SysCfb_Init(void) { + sCfbLoRes1 = gFramebuffer1; + sCfbLoRes0 = gFramebuffer0; + sCfbHiRes1 = gFramebufferHiRes1; + sCfbHiRes0 = gFramebufferHiRes0; + SysCfb_SetLoResMode(); +} + +// Unused +void SysCfb_Reset(void) { + gFramebuffers[0] = NULL; + gFramebuffers[1] = NULL; +} + +void* SysCfb_GetFramebuffer(s32 index) { + if (index < 2) { + return gFramebuffers[index]; + } + return NULL; +} + +void* SysCfb_GetZBuffer(void) { + return gZBufferPtr; +} + +void* SysCfb_GetWorkBuffer(void) { + return gWorkBuffer; +} + +u16 SysCfb_GetZBufferPixel(s32 x, s32 y) { + u16* zBuff = SysCfb_GetZBuffer(); + u16 val; + + if (zBuff != NULL) { + val = (&zBuff[x])[y * gCfbWidth]; + } else { + val = 0; + } + return val; +} + +s32 SysCfb_GetZBufferInt(s32 x, s32 y) { + return Environment_ZBufValToFixedPoint(SysCfb_GetZBufferPixel(x, y) << 2) >> 3; +} diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 3d98c8f46..c46b6ec3b 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -2705,7 +2705,7 @@ void Actor_DrawLensActors(PlayState* play, s32 numLensActors, Actor** lensActors spA4 = play->unk_18E68; if (dbgVar2) { - PreRender_SetValues(&play->pauseBgPreRender, D_801FBBCC, D_801FBBCE, gfxCtx->curFrameBuffer, zbuffer); + PreRender_SetValues(&play->pauseBgPreRender, gCfbWidth, gCfbHeight, gfxCtx->curFrameBuffer, zbuffer); gfxTemp = gfx; func_80170200(&play->pauseBgPreRender, &gfxTemp, zbuffer, spA4); diff --git a/src/code/z_demo.c b/src/code/z_demo.c index da965969f..733ec4bc1 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -1,4 +1,3 @@ -#include "prevent_bss_reordering.h" #include "global.h" #include "z64quake.h" #include "z64rumble.h" diff --git a/src/code/z_fbdemo_circle.c b/src/code/z_fbdemo_circle.c index bc07df883..addfe6b67 100644 --- a/src/code/z_fbdemo_circle.c +++ b/src/code/z_fbdemo_circle.c @@ -82,8 +82,8 @@ void TransitionCircle_SetType(void* thisx, s32 type) { void TransitionCircle_LoadAndSetTexture(Gfx** gfxp, TexturePtr texture, s32 fmt, s32 arg3, s32 masks, s32 maskt, f32 arg6) { Gfx* gfx = *gfxp; - s32 xh = D_801FBBCC; - s32 yh = D_801FBBCE; + s32 xh = gCfbWidth; + s32 yh = gCfbHeight; s32 width = 1 << masks; s32 height = 1 << maskt; f32 s; diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index d6d38f9d6..2191498a3 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -2,7 +2,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800F5090.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800F50D4.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Environment_ZBufValToFixedPoint.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Environment_Init.s") diff --git a/src/code/z_lights.c b/src/code/z_lights.c index 860d04ae9..534ec6dfc 100644 --- a/src/code/z_lights.c +++ b/src/code/z_lights.c @@ -360,12 +360,9 @@ Lights* Lights_New(GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambient lights = GRAPH_ALLOC(gfxCtx, sizeof(Lights)); - lights->l.a.l.col[0] = ambientR; - lights->l.a.l.colc[0] = ambientR; - lights->l.a.l.col[1] = ambientG; - lights->l.a.l.colc[1] = ambientG; - lights->l.a.l.col[2] = ambientB; - lights->l.a.l.colc[2] = ambientB; + lights->l.a.l.col[0] = lights->l.a.l.colc[0] = ambientR; + lights->l.a.l.col[1] = lights->l.a.l.colc[1] = ambientG; + lights->l.a.l.col[2] = lights->l.a.l.colc[2] = ambientB; lights->enablePosLights = 0; lights->numLights = 0; @@ -394,7 +391,7 @@ void Lights_GlowCheck(PlayState* play) { s32 screenPosX = PROJECTED_TO_SCREEN_X(projectedPos, invW); s32 screenPosY = PROJECTED_TO_SCREEN_Y(projectedPos, invW); s32 wZ = (s32)((projectedPos.z * invW) * 16352.0f) + 16352; - s32 zBuf = func_80178A94(screenPosX, screenPosY); + s32 zBuf = SysCfb_GetZBufferInt(screenPosX, screenPosY); if (wZ < zBuf) { params->drawGlow = 1; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 1c03f5cb1..d0558d7f8 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2421,7 +2421,7 @@ void Interface_UpdateButtonsPart1(PlayState* play) { // Related to pictograph if (sPictoState == PICTO_BOX_STATE_LENS) { if (!(play->actorCtx.flags & ACTORCTX_FLAG_PICTO_BOX_ON)) { - Play_CompressI8ToI5((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : D_801FBB90, + Play_CompressI8ToI5((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : gWorkBuffer, (u8*)((void)0, gSaveContext.pictoPhotoI5), PICTO_PHOTO_WIDTH * PICTO_PHOTO_HEIGHT); interfaceCtx->unk_222 = interfaceCtx->unk_224 = 0; @@ -2460,7 +2460,7 @@ void Interface_UpdateButtonsPart1(PlayState* play) { Interface_SetHudVisibility(HUD_VISIBILITY_ALL); sPictoState = PICTO_BOX_STATE_OFF; if (sPictoPhotoBeingTaken) { - Play_CompressI8ToI5((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : D_801FBB90, + Play_CompressI8ToI5((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : gWorkBuffer, (u8*)((void)0, gSaveContext.pictoPhotoI5), PICTO_PHOTO_WIDTH * PICTO_PHOTO_HEIGHT); Snap_RecordPictographedActors(play); @@ -2493,7 +2493,7 @@ void Interface_UpdateButtonsPart1(PlayState* play) { sPictoState = PICTO_BOX_STATE_LENS; } else { Play_DecompressI5ToI8((u8*)((void)0, gSaveContext.pictoPhotoI5), - (play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : D_801FBB90, + (play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : gWorkBuffer, PICTO_PHOTO_WIDTH * PICTO_PHOTO_HEIGHT); play->haltAllActors = true; sPictoState = PICTO_BOX_STATE_SETUP_PHOTO; @@ -6631,7 +6631,7 @@ void Interface_Draw(PlayState* play) { // Draw pictograph photo if (sPictoState >= PICTO_BOX_STATE_SETUP_PHOTO) { if (!(play->actorCtx.flags & ACTORCTX_FLAG_PICTO_BOX_ON)) { - Play_CompressI8ToI5((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : D_801FBB90, + Play_CompressI8ToI5((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : gWorkBuffer, (u8*)gSaveContext.pictoPhotoI5, PICTO_PHOTO_WIDTH * PICTO_PHOTO_HEIGHT); interfaceCtx->unk_222 = interfaceCtx->unk_224 = 0; @@ -6667,7 +6667,7 @@ void Interface_Draw(PlayState* play) { for (sp2CC = 0; sp2CC < (PICTO_PHOTO_HEIGHT / 8); sp2CC++, pictoRectTop += 8) { pictoRectLeft = PICTO_PHOTO_TOPLEFT_X; gDPLoadTextureBlock(OVERLAY_DISP++, - (u8*)((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : D_801FBB90) + + (u8*)((play->pictoPhotoI8 != NULL) ? play->pictoPhotoI8 : gWorkBuffer) + (0x500 * sp2CC), G_IM_FMT_I, G_IM_SIZ_8b, PICTO_PHOTO_WIDTH, 8, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); diff --git a/src/code/z_play.c b/src/code/z_play.c index e25b50b4b..dd06a461e 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -358,10 +358,10 @@ void Play_Destroy(GameState* thisx) { if (sBombersNotebookOpen) { MsgEvent_SendNullTask(); - func_80178750(); - gfxCtx->curFrameBuffer = SysCfb_GetFbPtr(gfxCtx->framebufferIndex % 2); + SysCfb_SetLoResMode(); + gfxCtx->curFrameBuffer = SysCfb_GetFramebuffer(gfxCtx->framebufferIndex % 2); gfxCtx->zbuffer = SysCfb_GetZBuffer(); - gfxCtx->viMode = D_801FBB88; + gfxCtx->viMode = gActiveViMode; gfxCtx->viConfigFeatures = gViConfigFeatures; gfxCtx->xScale = gViConfigXScale; gfxCtx->yScale = gViConfigYScale; @@ -1242,7 +1242,7 @@ void Play_DrawMain(PlayState* this) { goto PostWorldDraw; } - PreRender_SetValues(&this->pauseBgPreRender, D_801FBBCC, D_801FBBCE, gfxCtx->curFrameBuffer, gfxCtx->zbuffer); + PreRender_SetValues(&this->pauseBgPreRender, gCfbWidth, gCfbHeight, gfxCtx->curFrameBuffer, gfxCtx->zbuffer); if (R_PAUSE_BG_PRERENDER_STATE == PAUSE_BG_PRERENDER_PROCESS) { MsgEvent_SendNullTask(); @@ -1442,24 +1442,24 @@ void Play_Draw(PlayState* this) { GraphicsContext* gfxCtx2 = this->state.gfxCtx; if (sBombersNotebookOpen) { - if (D_801FBBD4 != 1) { + if (gSysCfbHiResEnabled != 1) { MsgEvent_SendNullTask(); - func_80178818(); - gfxCtx2->curFrameBuffer = SysCfb_GetFbPtr(gfxCtx2->framebufferIndex % 2); + SysCfb_SetHiResMode(); + gfxCtx2->curFrameBuffer = SysCfb_GetFramebuffer(gfxCtx2->framebufferIndex % 2); gfxCtx2->zbuffer = SysCfb_GetZBuffer(); - gfxCtx2->viMode = D_801FBB88; + gfxCtx2->viMode = gActiveViMode; gfxCtx2->viConfigFeatures = gViConfigFeatures; gfxCtx2->xScale = gViConfigXScale; gfxCtx2->yScale = gViConfigYScale; gfxCtx2->updateViMode = true; } } else { - if (D_801FBBD4 != 0) { + if (gSysCfbHiResEnabled != 0) { MsgEvent_SendNullTask(); - func_80178750(); - gfxCtx2->curFrameBuffer = SysCfb_GetFbPtr(gfxCtx2->framebufferIndex % 2); + SysCfb_SetLoResMode(); + gfxCtx2->curFrameBuffer = SysCfb_GetFramebuffer(gfxCtx2->framebufferIndex % 2); gfxCtx2->zbuffer = SysCfb_GetZBuffer(); - gfxCtx2->viMode = D_801FBB88; + gfxCtx2->viMode = gActiveViMode; gfxCtx2->viConfigFeatures = gViConfigFeatures; gfxCtx2->xScale = gViConfigXScale; gfxCtx2->yScale = gViConfigYScale; @@ -2252,10 +2252,10 @@ void Play_Init(GameState* thisx) { R_PICTO_PHOTO_STATE = PICTO_PHOTO_STATE_OFF; PreRender_Init(&this->pauseBgPreRender); - PreRender_SetValuesSave(&this->pauseBgPreRender, D_801FBBCC, D_801FBBCE, NULL, NULL, NULL); - PreRender_SetValues(&this->pauseBgPreRender, D_801FBBCC, D_801FBBCE, NULL, NULL); + PreRender_SetValuesSave(&this->pauseBgPreRender, gCfbWidth, gCfbHeight, NULL, NULL, NULL); + PreRender_SetValues(&this->pauseBgPreRender, gCfbWidth, gCfbHeight, NULL, NULL); - this->unk_18E64 = D_801FBB90; + this->unk_18E64 = gWorkBuffer; this->pictoPhotoI8 = gPictoPhotoI8; this->unk_18E68 = D_80784600; this->unk_18E58 = D_80784600; diff --git a/src/code/z_rcp.c b/src/code/z_rcp.c index 299639e98..4b5787129 100644 --- a/src/code/z_rcp.c +++ b/src/code/z_rcp.c @@ -1459,7 +1459,7 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g gSPDisplayList(&masterGfx[0], D_0E000000.syncSegments); gSPDisplayList(&masterGfx[1], sFillSetupDL); - gDPSetColorImage(&masterGfx[2], G_IM_FMT_RGBA, G_IM_SIZ_16b, D_801FBBCC, D_0F000000); + gDPSetColorImage(&masterGfx[2], G_IM_FMT_RGBA, G_IM_SIZ_16b, gCfbWidth, D_0F000000); if (zbuffer != NULL) { gDPSetDepthImage(&masterGfx[3], zbuffer); } else { @@ -1471,7 +1471,7 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g masterGfx = gGfxMasterDL->setScissor; - gDPSetScissor(&masterGfx[0], G_SC_NON_INTERLACE, 0, 0, D_801FBBCC, D_801FBBCE); + gDPSetScissor(&masterGfx[0], G_SC_NON_INTERLACE, 0, 0, gCfbWidth, gCfbHeight); gSPEndDisplayList(&masterGfx[1]); // Clear Z-Buffer @@ -1481,13 +1481,13 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g if (zbuffer == NULL) { gSPEndDisplayList(&masterGfx[0]); } else { - gDPSetColorImage(&masterGfx[0], G_IM_FMT_RGBA, G_IM_SIZ_16b, D_801FBBCC, zbuffer); + gDPSetColorImage(&masterGfx[0], G_IM_FMT_RGBA, G_IM_SIZ_16b, gCfbWidth, zbuffer); gDPPipeSync(&masterGfx[1]); gDPSetCycleType(&masterGfx[2], G_CYC_FILL); gDPSetRenderMode(&masterGfx[3], G_RM_NOOP, G_RM_NOOP2); gDPSetFillColor(&masterGfx[4], (GPACK_RGBA5551(255, 255, 240, 0) << 16) | GPACK_RGBA5551(255, 255, 240, 0)); gSPDisplayList(&masterGfx[5], D_0E000000.clearFillRect); - gDPSetColorImage(&masterGfx[6], G_IM_FMT_RGBA, G_IM_SIZ_16b, D_801FBBCC, D_0F000000); + gDPSetColorImage(&masterGfx[6], G_IM_FMT_RGBA, G_IM_SIZ_16b, gCfbWidth, D_0F000000); gSPEndDisplayList(&masterGfx[7]); } @@ -1495,7 +1495,7 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g masterGfx = gGfxMasterDL->clearFrameBuffer; - gDPSetColorImage(&masterGfx[0], G_IM_FMT_RGBA, G_IM_SIZ_16b, D_801FBBCC, D_0F000000); + gDPSetColorImage(&masterGfx[0], G_IM_FMT_RGBA, G_IM_SIZ_16b, gCfbWidth, D_0F000000); gDPSetCycleType(&masterGfx[1], G_CYC_FILL); gDPSetRenderMode(&masterGfx[2], G_RM_NOOP, G_RM_NOOP2); gDPSetFillColor(&masterGfx[3], (GPACK_RGBA5551(r, g, b, 1) << 16) | GPACK_RGBA5551(r, g, b, 1)); @@ -1505,7 +1505,7 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g masterGfx = gGfxMasterDL->clearFillRect; - gDPFillRectangle(&masterGfx[0], 0, 0, D_801FBBCC - 1, D_801FBBCE - 1); + gDPFillRectangle(&masterGfx[0], 0, 0, gCfbWidth - 1, gCfbHeight - 1); gDPPipeSync(&masterGfx[1]); gSPEndDisplayList(&masterGfx[2]); @@ -1513,7 +1513,7 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g masterGfx = gGfxMasterDL->fillRect; - gDPFillRectangle(&masterGfx[0], 0, 0, D_801FBBCC, D_801FBBCE); + gDPFillRectangle(&masterGfx[0], 0, 0, gCfbWidth, gCfbHeight); gDPPipeSync(&masterGfx[1]); gSPEndDisplayList(&masterGfx[2]); diff --git a/src/code/z_view.c b/src/code/z_view.c index 105e6643a..4adc00b8d 100644 --- a/src/code/z_view.c +++ b/src/code/z_view.c @@ -18,8 +18,8 @@ void View_ViewportToVp(Vp* dest, Viewport* src) { dest->vp.vtrans[2] = 0x01FF; dest->vp.vtrans[3] = 0; - if ((src->leftX == 0) && (src->rightX == SCREEN_WIDTH_HIGH_RES) && (src->topY == 0) && - (src->bottomY == SCREEN_HEIGHT_HIGH_RES)) {} + if ((src->leftX == 0) && (src->rightX == HIRES_BUFFER_WIDTH) && (src->topY == 0) && + (src->bottomY == HIRES_BUFFER_HEIGHT)) {} } void View_Init(View* view, GraphicsContext* gfxCtx) { diff --git a/src/code/z_vimode.c b/src/code/z_vimode.c index b7d2dea64..2ddd27775 100644 --- a/src/code/z_vimode.c +++ b/src/code/z_vimode.c @@ -1,17 +1,377 @@ #include "global.h" +#include "ultra64/viint.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_80140260.s") +typedef struct { + /* 0x00 */ u32 burst; + /* 0x04 */ u32 vSync; + /* 0x08 */ u32 hSync; + /* 0x0C */ u32 leap; + /* 0x10 */ u32 hStart; + /* 0x14 */ u32 vStart; + /* 0x18 */ u32 vBurst; +} ViModeStruct; // size = 0x1C -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_8014026C.s") +void ViMode_LogPrint(OSViMode* osViMode) { +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_80140730.s") +/** + * Configures the custom OSViMode for this ViMode + * + * @param viMode ViMode to configure the custom OSViMode for + * @param type Identifying type for the OSViMode + * @param tvType TV Type: NTSC, PAL, MPAL or FPAL + * @param loRes Boolean: true = low resolution, false = high resolution. + * Corresponds to "L" or "H" in libultra VI mode names + * @param antialiasOff Boolean: true = point-sampling, false = anti-aliasing. + * Corresponds to "P" or "A" in libultra VI mode names + * @param modeN Boolean: controls interlacing mode, different based on resolution. + * Corresponds to "N" or "F" in libultra VI mode names + * @param fb16Bit Bolean: true = 16-bit framebuffer, false = 32-bit framebuffer. + * Corresponds to "1" or "2" in libultra VI mode names + * @param width Screen width + * @param height Screen height + * @param leftAdjust Left edge adjustment + * @param rightAdjust Right edge adjustment + * @param upperAdjust Upper edge adjustment + * @param lowerAdjust Lower edge adjustment + */ +void ViMode_Configure(OSViMode* viMode, s32 type, s32 tvType, s32 loRes, s32 antialiasOff, s32 modeN, s32 fb16Bit, + s32 width, s32 height, s32 leftAdjust, s32 rightAdjust, s32 upperAdjust, s32 lowerAdjust) { + s32 hiRes; + s32 antialiasOn; + s32 modeF; + s32 fb32Bit; + s32 hiResDeflicker; // deflickered interlacing + s32 hiResInterlaced; + s32 loResDeinterlaced; + s32 loResInterlaced; + s32 modeLAN1; // L=(lo res) A=(antialias) N=(deinterlace) 1=(16-bit) + s32 modeLPN2; // L=(lo res) P=(point-sampled) N=(deinterlace) 2=(32-bit) + s32 modeHPN2; // H=(hi res) P=(point-sampled) N=(normal interlacing) 2=(32-bit) + s32 yScaleLo; + s32 yScaleHiEvenField; + s32 yScaleHiOddField; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_80140810.s") + hiRes = !loRes; + antialiasOn = !antialiasOff; + modeF = !modeN; + fb32Bit = !fb16Bit; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_80140898.s") + hiResDeflicker = hiRes && modeF; + hiResInterlaced = hiRes && modeN; + loResDeinterlaced = loRes && modeN; + loResInterlaced = loRes && modeF; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_80140900.s") + modeLAN1 = loRes && antialiasOn && modeN && fb16Bit; + modeLPN2 = loRes && antialiasOff && modeN && fb32Bit; + modeHPN2 = hiRes && antialiasOff && modeN && fb32Bit; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_8014090C.s") + upperAdjust &= ~1; + lowerAdjust &= ~1; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_vimode/func_80140970.s") + yScaleLo = (hiResDeflicker ? 2 : 1) * (((SCREEN_HEIGHT << 11) / SCREEN_HEIGHT) / (loRes ? 1 : 2)); + + yScaleHiEvenField = modeF ? (loResInterlaced ? 0x1000000 : 0x2000000) : 0; + yScaleHiOddField = modeF ? (loResInterlaced ? 0x3000000 : 0x2000000) : 0; + + viMode->type = type; + viMode->comRegs.ctrl = OS_VI_UNK2000 | OS_VI_UNK1000 | OS_VI_GAMMA | OS_VI_GAMMA_DITHER | + (!loResDeinterlaced ? OS_VI_UNK40 : 0) | (antialiasOn ? OS_VI_DIVOT : 0) | + (fb32Bit ? OS_VI_UNK2 | OS_VI_UNK1 : OS_VI_UNK2); + + if (modeLAN1) { + // Anti-aliased, fetch extra lines as-needed + viMode->comRegs.ctrl |= 0x100; + } else if (modeLPN2 | modeHPN2) { + // Point-sampled, resampling disabled + viMode->comRegs.ctrl |= 0x300; + } else { + if (antialiasOff) { + // Point-sampled, resampling enabled + viMode->comRegs.ctrl |= 0x200; + } else { + // Anti-aliased, always fetch extra lines + viMode->comRegs.ctrl |= 0; + } + } + + viMode->comRegs.width = width * (hiResInterlaced ? 2 : 1); + + if (tvType < 3) { + static const ViModeStruct D_801DF0C0[] = { + { + // OS_TV_PAL + BURST(58, 35, 4, 64), + VSYNC(624), + HSYNC(3177, 21), + LEAP(3183, 3182), + HSTART(128, 768), + START(95, 569), + BURST(107, 2, 9, 0), + }, + { + // OS_TV_NTSC + BURST(57, 34, 5, 62), + VSYNC(524), + HSYNC(3093, 0), + LEAP(3093, 3093), + HSTART(108, 748), + START(37, 511), + BURST(4, 2, 14, 0), + }, + { + // OS_TV_MPAL + BURST(57, 30, 5, 70), + VSYNC(524), + HSYNC(3088, 0), + LEAP(3100, 3100), + HSTART(108, 748), + START(37, 511), + BURST(4, 2, 14, 0), + }, + }; + const ViModeStruct* ptr = &D_801DF0C0[tvType]; + + viMode->comRegs.burst = ptr->burst; + viMode->comRegs.vSync = ptr->vSync; + viMode->comRegs.hSync = ptr->hSync; + viMode->comRegs.leap = ptr->leap; + viMode->comRegs.hStart = ptr->hStart; + viMode->fldRegs[0].vStart = ptr->vStart; + viMode->fldRegs[1].vStart = ptr->vStart; + viMode->fldRegs[0].vBurst = ptr->vBurst; + viMode->fldRegs[1].vBurst = ptr->vBurst; + } else { + __assert("../z_vimode.c", 216); + } + + viMode->comRegs.hStart += (leftAdjust << 16) + (s16)rightAdjust; + viMode->fldRegs[0].vStart += (upperAdjust << 16) + (s16)lowerAdjust; + viMode->fldRegs[1].vStart += (upperAdjust << 16) + (s16)lowerAdjust; + + if (loResDeinterlaced) { + viMode->comRegs.vSync++; + if (tvType == OS_TV_MPAL) { + viMode->comRegs.hSync += HSYNC(1, 4); + viMode->comRegs.leap += LEAP((u16)-4, (u16)-2); + } + } else { + viMode->fldRegs[0].vStart += START((u16)-3, (u16)-2); + if (tvType == OS_TV_MPAL) { + viMode->fldRegs[0].vBurst += BURST((u8)-2, (u8)-1, 12, -1); + } else if (tvType == OS_TV_PAL) { + viMode->fldRegs[1].vBurst += BURST((u8)-2, (u8)-1, 2, 0); + } + } + + viMode->comRegs.xScale = (SCREEN_WIDTH << 10) / SCREEN_WIDTH; + viMode->comRegs.vCurrent = 0; + + viMode->fldRegs[0].origin = ORIGIN(width * 2 * (fb16Bit ? 1 : 2)); + viMode->fldRegs[1].origin = ORIGIN(width * 2 * (fb16Bit ? 1 : 2) * (loRes ? 1 : 2)); + + viMode->fldRegs[0].yScale = yScaleLo | yScaleHiEvenField; + viMode->fldRegs[1].yScale = yScaleLo | yScaleHiOddField; + + viMode->fldRegs[0].vIntr = 2; + viMode->fldRegs[1].vIntr = 2; +} + +void ViMode_Save(ViMode* viMode) { + R_VI_MODE_EDIT_STATE = viMode->editState; + R_VI_MODE_EDIT_WIDTH = viMode->viWidth; + R_VI_MODE_EDIT_HEIGHT = viMode->viHeight; + R_VI_MODE_EDIT_ULY_ADJ = viMode->upperAdjust; + R_VI_MODE_EDIT_LRY_ADJ = viMode->lowerAdjust; + R_VI_MODE_EDIT_ULX_ADJ = viMode->leftAdjust; + R_VI_MODE_EDIT_LRX_ADJ = viMode->rightAdjust; + + if (SREG(58) == 1) { + SREG(58) = 0; + switch (SREG(59)) { + case 1: + ViMode_LogPrint(&osViModePalLan1); + break; + + case 2: + ViMode_LogPrint(&osViModeFpalLan1); + break; + + default: + ViMode_LogPrint(&viMode->customViMode); + break; + } + } +} + +void ViMode_Load(ViMode* viMode) { + //! @bug This condition always fails as the lowest bit is masked out to 0 + if ((R_VI_MODE_EDIT_WIDTH & ~3) == 1) { + R_VI_MODE_EDIT_WIDTH += 4; + } + + viMode->editState = R_VI_MODE_EDIT_STATE; + viMode->viWidth = R_VI_MODE_EDIT_WIDTH & ~3; + viMode->viHeight = R_VI_MODE_EDIT_HEIGHT; + viMode->upperAdjust = R_VI_MODE_EDIT_ULY_ADJ; + viMode->lowerAdjust = R_VI_MODE_EDIT_LRY_ADJ; + viMode->leftAdjust = R_VI_MODE_EDIT_ULX_ADJ; + viMode->rightAdjust = R_VI_MODE_EDIT_LRX_ADJ; +} + +void ViMode_Init(ViMode* viMode) { + viMode->editState = VI_MODE_EDIT_STATE_INACTIVE; + viMode->viWidth = SCREEN_WIDTH; + viMode->viHeight = SCREEN_HEIGHT; + viMode->leftAdjust = 0; + viMode->rightAdjust = 0; + viMode->upperAdjust = 0; + viMode->lowerAdjust = 0; + viMode->viFeatures = OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF; + viMode->tvType = osTvType; + viMode->fb16Bit = true; + viMode->modeN = true; + viMode->antialiasOff = false; + viMode->loRes = true; + + ViMode_Save(viMode); +} + +void ViMode_Destroy(ViMode* viMode) { +} + +void ViMode_ConfigureFeatures(ViMode* viMode, s32 viFeatures) { + u32 ctrl = viMode->customViMode.comRegs.ctrl; + + if (viFeatures & OS_VI_GAMMA_ON) { + ctrl |= OS_VI_GAMMA; + } + if (viFeatures & OS_VI_GAMMA_OFF) { + ctrl &= ~OS_VI_GAMMA; + } + if (viFeatures & OS_VI_GAMMA_DITHER_ON) { + ctrl |= OS_VI_GAMMA_DITHER; + } + if (viFeatures & OS_VI_GAMMA_DITHER_OFF) { + ctrl &= ~OS_VI_GAMMA_DITHER; + } + if (viFeatures & OS_VI_DIVOT_ON) { + ctrl |= OS_VI_DIVOT; + } + if (viFeatures & OS_VI_DIVOT_OFF) { + ctrl &= ~OS_VI_DIVOT; + } + viMode->customViMode.comRegs.ctrl = ctrl; +} + +/** + * Updates the custom VI mode with controller input and any edits made with the REG editor + * (through R_VI_MODE_EDIT_* entries) + */ +void ViMode_Update(ViMode* viMode, Input* input) { + ViMode_Load(viMode); + + if ((viMode->editState == VI_MODE_EDIT_STATE_ACTIVE) || (viMode->editState == VI_MODE_EDIT_STATE_2) || + (viMode->editState == VI_MODE_EDIT_STATE_3)) { + gScreenWidth = viMode->viWidth; + gScreenHeight = viMode->viHeight; + + // Controls to reset the ViMode to defaults + if (CHECK_BTN_ALL(input->cur.button, BTN_START | BTN_CUP | BTN_CRIGHT)) { + ViMode_Init(viMode); + } + + // Controls to adjust the screen dimensions (upper-left) + if (CHECK_BTN_ALL(input->cur.button, BTN_CUP)) { + if (CHECK_BTN_ALL(input->cur.button, BTN_DUP)) { + viMode->upperAdjust--; + } + if (CHECK_BTN_ALL(input->cur.button, BTN_DDOWN)) { + viMode->upperAdjust++; + } + if (CHECK_BTN_ALL(input->cur.button, BTN_DLEFT)) { + viMode->leftAdjust--; + } + if (CHECK_BTN_ALL(input->cur.button, BTN_DRIGHT)) { + viMode->leftAdjust++; + } + } + + // Controls to adjust the screen dimensions (lower-right) + if (CHECK_BTN_ALL(input->cur.button, BTN_CRIGHT)) { + if (CHECK_BTN_ALL(input->cur.button, BTN_DUP)) { + viMode->lowerAdjust--; + } + if (CHECK_BTN_ALL(input->cur.button, BTN_DDOWN)) { + viMode->lowerAdjust++; + } + if (CHECK_BTN_ALL(input->cur.button, BTN_DLEFT)) { + viMode->rightAdjust--; + } + if (CHECK_BTN_ALL(input->cur.button, BTN_DRIGHT)) { + viMode->rightAdjust++; + } + } + + // Controls to adjust key features + if (CHECK_BTN_ALL(input->cur.button, BTN_CDOWN)) { + if (CHECK_BTN_ALL(input->press.button, BTN_DUP)) { + viMode->loRes = !viMode->loRes; + } + if (CHECK_BTN_ALL(input->press.button, BTN_DDOWN)) { + viMode->antialiasOff = !viMode->antialiasOff; + } + if (CHECK_BTN_ALL(input->press.button, BTN_DLEFT)) { + viMode->modeN = !viMode->modeN; + } + if (CHECK_BTN_ALL(input->press.button, BTN_DRIGHT)) { + viMode->fb16Bit = !viMode->fb16Bit; + } + } + + // Clamp adjustments + if (viMode->editState >= VI_MODE_EDIT_STATE_2) { + // Allow parts of the framebuffer to possibly be offscreen by a small margin + if (viMode->leftAdjust < -16) { + viMode->leftAdjust = -16; + } + if (viMode->upperAdjust < -50) { + viMode->upperAdjust = -50; + } + if (viMode->rightAdjust > 16) { + viMode->rightAdjust = 16; + } + if (viMode->lowerAdjust > 50) { + viMode->lowerAdjust = 50; + } + } else { + // Do not allow parts of the framebuffer to end up offscreen + if (viMode->leftAdjust < 0) { + viMode->leftAdjust = 0; + } + if (viMode->upperAdjust < 0) { + viMode->upperAdjust = 0; + } + if (viMode->rightAdjust > 0) { + viMode->rightAdjust = 0; + } + if (viMode->lowerAdjust > 0) { + viMode->lowerAdjust = 0; + } + } + + ViMode_Configure(&viMode->customViMode, OS_VI_UNK28, osTvType, viMode->loRes, viMode->antialiasOff, + viMode->modeN, viMode->fb16Bit, viMode->viWidth, viMode->viHeight, viMode->leftAdjust, + viMode->rightAdjust, viMode->upperAdjust, viMode->lowerAdjust); + ViMode_ConfigureFeatures(viMode, viMode->viFeatures); + + if (viMode->editState == VI_MODE_EDIT_STATE_3) { + // Log comparison between the NTSC LAN1 mode and the custom mode + ViMode_LogPrint(&osViModeNtscLan1); + ViMode_LogPrint(&viMode->customViMode); + viMode->editState = VI_MODE_EDIT_STATE_2; + } + } + + ViMode_Save(viMode); +} diff --git a/src/code/z_viscvg.c b/src/code/z_viscvg.c new file mode 100644 index 000000000..888fa19b3 --- /dev/null +++ b/src/code/z_viscvg.c @@ -0,0 +1,90 @@ +#include "global.h" + +Gfx D_801C5DD0[] = { + gsDPSetOtherMode(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_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PRIM | G_RM_VISCVG | G_RM_VISCVG2), + gsSPBranchList(D_0E000000.fillRect), +}; + +Gfx D_801C5DE0[] = { + gsDPSetOtherMode(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_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PRIM | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | + GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_A_MEM) | + GBL_c2(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_A_MEM)), + gsSPBranchList(D_0E000000.fillRect), +}; + +Gfx D_801C5DF0[] = { + gsDPSetOtherMode(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_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PRIM | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM) | + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM)), + gsSPBranchList(D_0E000000.fillRect), +}; + +Gfx D_801C5E00[] = { + gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_DISABLE | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PRIM | G_RM_CLD_SURF | G_RM_CLD_SURF2), + gsSPDisplayList(D_0E000000.fillRect), + gsDPSetOtherMode(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_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PRIM | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM) | + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM)), + gsSPBranchList(D_0E000000.fillRect), +}; + +void VisCvg_Init(struct_801F8010* this) { + this->type = 0; + this->setScissor = false; + this->color.r = 255; + this->color.g = 255; + this->color.b = 255; + this->color.a = 255; +} + +void VisCvg_Destroy(struct_801F8010* this) { +} + +void VisCvg_Draw(struct_801F8010* this, Gfx** gfxp) { + Gfx* gfx = *gfxp; + + gDPPipeSync(gfx++); + gDPSetPrimDepth(gfx++, -1, -1); + + if (this->setScissor == true) { + gSPDisplayList(gfx++, D_0E000000.setScissor); + } + + switch (this->type) { + case 1: + gSPDisplayList(gfx++, D_801C5DF0); + break; + + case 2: + gDPSetColor(gfx++, G_SETPRIMCOLOR, this->color.rgba); + gSPDisplayList(gfx++, D_801C5E00); + break; + + case 3: + gDPSetColor(gfx++, G_SETBLENDCOLOR, this->color.rgba); + gSPDisplayList(gfx++, D_801C5DD0); + break; + + case 4: + gDPSetColor(gfx++, G_SETFOGCOLOR, this->color.rgba); + gSPDisplayList(gfx++, D_801C5DE0); + break; + + default: + break; + } + + gDPPipeSync(gfx++); + *gfxp = gfx; +} diff --git a/src/code/z_viszbuf.c b/src/code/z_viszbuf.c index 9970a1e1b..cf603f324 100644 --- a/src/code/z_viszbuf.c +++ b/src/code/z_viszbuf.c @@ -1,6 +1,6 @@ #include "global.h" -#define VISZBUF_ZBUFFRAG_HEIGHT (TMEM_SIZE / (D_801FBBCC * G_IM_SIZ_16b_BYTES)) +#define VISZBUF_ZBUFFRAG_HEIGHT (TMEM_SIZE / (gCfbWidth * G_IM_SIZ_16b_BYTES)) void VisZbuf_Init(VisZbuf* this) { this->useRgba = false; @@ -42,12 +42,12 @@ void VisZbuf_Draw(VisZbuf* this, Gfx** gfxP, void* zbuffer) { gDPSetColor(gfx++, G_SETPRIMCOLOR, this->primColor.rgba); gDPSetColor(gfx++, G_SETENVCOLOR, this->envColor.rgba); - for (y = 0; y < (D_801FBBCE - height) + 1; y += height) { - gDPLoadTextureTile(gfx++, zbuffer, fmt, G_IM_SIZ_16b, D_801FBBCC, 0, 0, y, D_801FBBCC - 1, (y + height) - 1, 0, + for (y = 0; y < (gCfbHeight - height) + 1; y += height) { + gDPLoadTextureTile(gfx++, zbuffer, fmt, G_IM_SIZ_16b, gCfbWidth, 0, 0, y, gCfbWidth - 1, (y + height) - 1, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(gfx++, 0, y << 2, D_801FBBCC << 2, (y + height) << 2, G_TX_RENDERTILE, 0, y << 5, 1 << 10, + gSPTextureRectangle(gfx++, 0, y << 2, gCfbWidth << 2, (y + height) << 2, G_TX_RENDERTILE, 0, y << 5, 1 << 10, 1 << 10); } diff --git a/src/libultra/io/osViModeMpalLan1.c b/src/libultra/io/osViModeMpalLan1.c index c7c09f659..ccccf68ae 100644 --- a/src/libultra/io/osViModeMpalLan1.c +++ b/src/libultra/io/osViModeMpalLan1.c @@ -1,34 +1,35 @@ #include "global.h" +#include "ultra64/viint.h" OSViMode osViModeMpalLan1 = { OS_VI_MPAL_LAN1, // type { // comRegs - 0x311E, // ctrl - SCREEN_WIDTH, // width - 0x4651E39, // burst - 0x20D, // vSync - 0x40C11, // hSync - 0xC190C1A, // leap - 0x6C02EC, // hStart - 0x200, // xScale - 0, // vCurrent + 0x311E, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { // [0] - 0x280, // origin - 0x400, // yScale - 0x2501FF, // vStart - 0xE0204, // vBurst - 2, // vIntr + ORIGIN(640), // origin + SCALE(1, 0), // yScale + START(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr }, { // [1] - 0x280, // origin - 0x400, // yScale - 0x2501FF, // vStart - 0xE0204, // vBurst - 2, // vIntr + ORIGIN(640), // origin + SCALE(1, 0), // yScale + START(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr } }, }; diff --git a/src/libultra/io/osViModeNtscHpf1.c b/src/libultra/io/osViModeNtscHpf1.c index ac0a1fa2b..5f88f4e94 100644 --- a/src/libultra/io/osViModeNtscHpf1.c +++ b/src/libultra/io/osViModeNtscHpf1.c @@ -1,34 +1,35 @@ #include "global.h" +#include "ultra64/viint.h" OSViMode osViModeNtscHpf1 = { OS_VI_NTSC_HPF1, // type { // comRegs - 0x324E, // ctrl - 640, // width - 0x3E52239, // burst - 0x20C, // vSync - 0xC15, // hSync - 0xC150C15, // leap - 0x6C02EC, // hStart - 0x400, // xScale - 0, // vCurrent + 0x324E, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // 0x3E52239, // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // 0x6C02EC, // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { // [0] - 0x500, // origin - 0x2000800, // yScale - 0x2301FD, // vStart - 0xE0204, // vBurst - 2, // vIntr + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // 0x2000800, // yScale + START(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr }, { // [1] - 0xA00, // origin - 0x2000800, // yScale - 0x2501FF, // vStart - 0xE0204, // vBurst - 2 // vIntr + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // 0x2000800, // yScale + START(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2) // vIntr } }, }; diff --git a/src/libultra/io/osViModeNtscLan1.c b/src/libultra/io/osViModeNtscLan1.c index 632d763f4..86eb473b7 100644 --- a/src/libultra/io/osViModeNtscLan1.c +++ b/src/libultra/io/osViModeNtscLan1.c @@ -1,34 +1,35 @@ #include "global.h" +#include "ultra64/viint.h" OSViMode osViModeNtscLan1 = { OS_VI_NTSC_LAN1, // type { // comRegs - 0x311E, // ctrl - SCREEN_WIDTH, // width - 0x3E52239, // burst - 0x20D, // vSync - 0xC15, // hSync - 0xC150C15, // leap - 0x6C02EC, // hStart - 0x200, // xScale - 0, // vCurrent + 0x311E, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { // [0] - 0x280, // origin - 0x400, // yScale - 0x2501FF, // vStart - 0xE0204, // vBurst - 2, // vIntr + ORIGIN(640), // origin + SCALE(1, 0), // yScale + START(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr }, { // [1] - 0x280, // origin - 0x400, // yScale - 0x2501FF, // vStart - 0xE0204, // vBurst - 2, // vIntr + ORIGIN(640), // origin + SCALE(1, 0), // yScale + START(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr } }, }; diff --git a/src/libultra/io/osViModePalLan1.c b/src/libultra/io/osViModePalLan1.c index 174cbf142..f875bb731 100644 --- a/src/libultra/io/osViModePalLan1.c +++ b/src/libultra/io/osViModePalLan1.c @@ -1,34 +1,35 @@ #include "global.h" +#include "ultra64/viint.h" OSViMode osViModePalLan1 = { OS_VI_PAL_LAN1, // type { // comRegs - 0x311E, // ctrl - SCREEN_WIDTH, // width - 0x4541E3A, // burst - 0x271, // vSync - 0x170C69, // hSync - 0xC6F0C6D, // leap - 0x800300, // hStart - 0x200, // xScale - 0, // vCurrent + 0x311E, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { // [0] - 0x280, // origin - 0x400, // yScale - 0x5F0239, // vStart - 0x9026B, // vBurst - 2, // vIntr + ORIGIN(640), // origin + SCALE(1, 0), // yScale + START(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr }, { // [1] - 0x280, // origin - 0x400, // yScale - 0x5F0239, // vStart - 0x9026B, // vBurst - 2 // vIntr + ORIGIN(640), // origin + SCALE(1, 0), // yScale + START(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr } }, }; diff --git a/src/overlays/actors/ovl_En_Test3/z_en_test3.c b/src/overlays/actors/ovl_En_Test3/z_en_test3.c index 444142715..7de134218 100644 --- a/src/overlays/actors/ovl_En_Test3/z_en_test3.c +++ b/src/overlays/actors/ovl_En_Test3/z_en_test3.c @@ -4,6 +4,7 @@ * Description: Kafei */ +#include "prevent_bss_reordering.h" #include "z_en_test3.h" #include "objects/object_test3/object_test3.h" #include "overlays/actors/ovl_En_Door/z_en_door.h" diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 9f5257b32..7f33b45c1 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -4,6 +4,7 @@ * Description: Player */ +#include "prevent_bss_reordering.h" #include "global.h" #include "z64quake.h" #include "z64rumble.h" diff --git a/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c b/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c index 48c8bdf58..9e11df190 100644 --- a/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c +++ b/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c @@ -81,7 +81,7 @@ void TransitionWipe5_Draw(void* thisx, Gfx** gfxP) { Gfx* gfx = *gfxP; s32 width = gScreenWidth; s32 height = gScreenHeight; - void* sp50 = D_801FBB90; + void* workBuffer = gWorkBuffer; TransitionWipe5* this = THIS; s32 alpha = (1.0f - this->unk_0C) * 255.0f; @@ -92,7 +92,7 @@ void TransitionWipe5_Draw(void* thisx, Gfx** 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_COPY | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2); - func_8014116C(&gfx, D_0F000000, sp50, width, height, 1); + func_8014116C(&gfx, D_0F000000, workBuffer, width, height, 1); } else { if (alpha == 255) { gDPSetOtherMode(gfx++, @@ -108,7 +108,7 @@ void TransitionWipe5_Draw(void* thisx, Gfx** gfxP) { gDPSetEnvColor(gfx++, 255, 255, 255, alpha); gDPSetCombineLERP(gfx++, TEXEL0, 0, ENVIRONMENT, 0, 0, 0, 0, ENVIRONMENT, TEXEL0, 0, ENVIRONMENT, 0, 0, 0, 0, ENVIRONMENT); - func_8014116C(&gfx, sp50, D_0F000000, width, height, 0); + func_8014116C(&gfx, workBuffer, D_0F000000, width, height, 0); } gDPPipeSync(gfx++); gSPLoadUcode(gfx++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); |
