From 27b70f03c129523b35d2ea723c4eca868ef3032b Mon Sep 17 00:00:00 2001 From: louist103 <35883445+louist103@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:43:39 -0400 Subject: [PATCH] Track LUS changes for LUS refactor. (#163) * Track LUS changes. So far implemented: - Moving the big switch into unordered maps. - Dynamically switching between different ucodes. So far tested switching between f3dex2 and s2dex. * track LUS changes * LUS Bump --- libultraship | 2 +- mm/2s2h/framebuffer_effects.c | 4 +++- mm/include/functions.h | 3 ++- mm/src/code/PreRender.c | 5 ++-- mm/src/code/graph.c | 2 +- mm/src/code/stubs.c | 24 +++++++++---------- mm/src/code/sys_ucode.c | 13 +++++----- mm/src/code/z_parameter.c | 4 ++-- mm/src/code/z_room.c | 11 +++++---- mm/src/code/z_visfbuf.c | 17 +++++++++++-- .../fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c | 5 ++-- 11 files changed, 56 insertions(+), 34 deletions(-) diff --git a/libultraship b/libultraship index e40c19e99..75344bb10 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit e40c19e992073e1cde514ad1c4272c08b85b9708 +Subproject commit 75344bb10111fef29152cf75ea8cf278c26fe5a2 diff --git a/mm/2s2h/framebuffer_effects.c b/mm/2s2h/framebuffer_effects.c index 7bebb34e9..ec6043ae9 100644 --- a/mm/2s2h/framebuffer_effects.c +++ b/mm/2s2h/framebuffer_effects.c @@ -28,6 +28,7 @@ void FB_CreateFramebuffers(void) { * Setting oncePerFrame ensures that the copy will only happen once every game frame. This * is important for effects that could be affected by increased frame interpolation (like motion blur). * A pointer to a boolean is passed to the render for the render to set once the copy has been performed. + * This function uses opcodes from f3dex2 but may be called when s2dex is loaded, such as during shrink window. Make sure f3dex2 is loaded before this function is called. */ void FB_CopyToFramebuffer(Gfx** gfxp, s32 fb_src, s32 fb_dest, u8 oncePerFrame, u8* hasCopied) { Gfx* gfx = *gfxp; @@ -89,7 +90,8 @@ void FB_DrawFromFramebuffer(Gfx** gfxp, s32 fb, u8 alpha) { } /** - * Similar to FB_DrawFromFramebuffer, but scales the image relative to the center of the screen + * Similar to FB_DrawFromFramebuffer, but scales the image relative to the center of the screen. + * This function uses opcodes from f3dex2 but may be called when s2dex is loaded, such as during shrink window. Make sure f3dex2 is loaded before this function is called. */ void FB_DrawFromFramebufferScaled(Gfx** gfxp, s32 fb, u8 alpha, float scaleX, float scaleY) { Gfx* gfx = *gfxp; diff --git a/mm/include/functions.h b/mm/include/functions.h index 2ab5b51e7..5a319577a 100644 --- a/mm/include/functions.h +++ b/mm/include/functions.h @@ -1104,7 +1104,8 @@ void Check_RegionIsSupported(void); u64* SysUcode_GetUCodeBoot(void); size_t SysUcode_GetUCodeBootSize(void); -u64* SysUcode_GetUCode(void); +// BENTODO move this into its own header so we don't have so much header bloat with lus bridge +uint32_t SysUcode_GetUCode(void); u64* SysUcode_GetUCodeData(void); void func_80183070(void); diff --git a/mm/src/code/PreRender.c b/mm/src/code/PreRender.c index 79f717af4..14db7b268 100644 --- a/mm/src/code/PreRender.c +++ b/mm/src/code/PreRender.c @@ -18,6 +18,7 @@ #include "stackcheck.h" #include #include +#include "public/bridge/gfxbridge.h" /** * Assigns the "save" values in PreRender @@ -791,7 +792,7 @@ void Prerender_DrawBackground2DImpl(PreRenderBackground2DParams* bg2D, Gfx** gfx bg->b.imageFlip = 0; if (loadS2DEX2) { - gSPLoadUcodeL(gfx++, gspS2DEX2_fifo); + gSPLoadUcodeL(gfx++, ucode_s2dex); } if ((bg2D->fmt == G_IM_FMT_CI) && (bg2D->tlut != NULL)) { @@ -836,7 +837,7 @@ void Prerender_DrawBackground2DImpl(PreRenderBackground2DParams* bg2D, Gfx** gfx gDPPipeSync(gfx++); if (loadS2DEX2) { - gSPLoadUcode(gfx++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); + gSPLoadUcode(gfx++, SysUcode_GetUCode()); } *gfxp = gfx; diff --git a/mm/src/code/graph.c b/mm/src/code/graph.c index 23a382b5b..3f529f17d 100644 --- a/mm/src/code/graph.c +++ b/mm/src/code/graph.c @@ -180,7 +180,7 @@ retry: task->ucode_boot = SysUcode_GetUCodeBoot(); task->ucode_boot_size = SysUcode_GetUCodeBootSize(); task->ucode = SysUcode_GetUCode(); - task->ucode_data = SysUcode_GetUCodeData(); + //task->ucode_data = SysUcode_GetUCodeData(); task->ucode_size = SP_UCODE_SIZE; task->ucode_data_size = SP_UCODE_DATA_SIZE; task->dram_stack = (u64*)gGfxSPTaskStack; diff --git a/mm/src/code/stubs.c b/mm/src/code/stubs.c index 99236aa94..cf6952d40 100644 --- a/mm/src/code/stubs.c +++ b/mm/src/code/stubs.c @@ -70,18 +70,18 @@ GfxMasterList D_0E000000; Mtx D_01000000; u16 D_0F000000[SCREEN_WIDTH * SCREEN_HEIGHT]; -u64 gspS2DEX_fifoTextStart[1], gspS2DEX_fifoTextEnd[1]; -u64 gspS2DEX_fifoDataStart[1], gspS2DEX_fifoDataEnd[1]; -u64 gspS2DEX_fifo_dTextStart[1], gspS2DEX_fifo_dTextEnd[1]; -u64 gspS2DEX_fifo_dDataStart[1], gspS2DEX_fifo_dDataEnd[1]; -u64 gspS2DEX2_fifoTextStart[1], gspS2DEX2_fifoTextEnd[1]; -u64 gspS2DEX2_fifoDataStart[1], gspS2DEX2_fifoDataEnd[1]; -u64 gspS2DEX2_xbusTextStart[1], gspS2DEX2_xbusTextEnd[1]; -u64 gspS2DEX2_xbusDataStart[1], gspS2DEX2_xbusDataEnd[1]; -u64 gspF3DZEX2_NoN_PosLight_fifoTextStart[1]; -u64 gspF3DZEX2_NoN_PosLight_fifoTextEnd[1]; -u64 gspF3DZEX2_NoN_PosLight_fifoDataStart[1]; -u64 gspF3DZEX2_NoN_PosLight_fifoDataEnd[1]; +//u64 gspS2DEX_fifoTextStart[1], gspS2DEX_fifoTextEnd[1]; +//u64 gspS2DEX_fifoDataStart[1], gspS2DEX_fifoDataEnd[1]; +//u64 gspS2DEX_fifo_dTextStart[1], gspS2DEX_fifo_dTextEnd[1]; +//u64 gspS2DEX_fifo_dDataStart[1], gspS2DEX_fifo_dDataEnd[1]; +//u64 gspS2DEX2_fifoTextStart[1], gspS2DEX2_fifoTextEnd[1]; +//u64 gspS2DEX2_fifoDataStart[1], gspS2DEX2_fifoDataEnd[1]; +//u64 gspS2DEX2_xbusTextStart[1], gspS2DEX2_xbusTextEnd[1]; +//u64 gspS2DEX2_xbusDataStart[1], gspS2DEX2_xbusDataEnd[1]; +//u64 gspF3DZEX2_NoN_PosLight_fifoTextStart[1]; +//u64 gspF3DZEX2_NoN_PosLight_fifoTextEnd[1]; +//u64 gspF3DZEX2_NoN_PosLight_fifoDataStart[1]; +//u64 gspF3DZEX2_NoN_PosLight_fifoDataEnd[1]; Vec3f gZeroVec3f; Vec3s gZeroVec3s; diff --git a/mm/src/code/sys_ucode.c b/mm/src/code/sys_ucode.c index df59275e2..21c24f0bd 100644 --- a/mm/src/code/sys_ucode.c +++ b/mm/src/code/sys_ucode.c @@ -3,9 +3,10 @@ * Description: Functions for obtaining locations and sizes of microcode */ #include "global.h" +#include "public/bridge/gfxbridge.h" -u64* initialgspUcodeText = gspF3DZEX2_NoN_PosLight_fifoTextStart; -u64* initialgspUcodeData = gspF3DZEX2_NoN_PosLight_fifoDataStart; +UcodeHandlers initialgspUcodeText = ucode_f3dex2; +//u64* initialgspUcodeData = gspF3DZEX2_NoN_PosLight_fifoDataStart; u64* SysUcode_GetUCodeBoot(void) { return rspbootTextStart; @@ -15,10 +16,10 @@ size_t SysUcode_GetUCodeBootSize(void) { return (uintptr_t)rspbootTextEnd - (uintptr_t)rspbootTextStart; } -u64* SysUcode_GetUCode(void) { +UcodeHandlers SysUcode_GetUCode(void) { return initialgspUcodeText; } -u64* SysUcode_GetUCodeData(void) { - return initialgspUcodeData; -} +//u64* SysUcode_GetUCodeData(void) { +// return initialgspUcodeData; +//} diff --git a/mm/src/code/z_parameter.c b/mm/src/code/z_parameter.c index 0594153aa..a7c6ee516 100644 --- a/mm/src/code/z_parameter.c +++ b/mm/src/code/z_parameter.c @@ -6642,13 +6642,13 @@ void Interface_Draw(PlayState* play) { gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, pauseCtx->alpha); // Load in Grandma's Story - gSPLoadUcodeL(OVERLAY_DISP++, gspS2DEX2_fifo); + gSPLoadUcodeL(OVERLAY_DISP++, ucode_s2dex); gfx = OVERLAY_DISP; Prerender_DrawBackground2D(&gfx, sStoryTextures[interfaceCtx->storyType], sStoryTLUTs[interfaceCtx->storyType], SCREEN_WIDTH, SCREEN_HEIGHT, G_IM_FMT_CI, G_IM_SIZ_8b, 0x8000, 0x100, 0.0f, 0.0f, 1.0f, 1.0f, 0); OVERLAY_DISP = gfx; - gSPLoadUcode(OVERLAY_DISP++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); + gSPLoadUcode(OVERLAY_DISP++, SysUcode_GetUCode()); gDPPipeSync(OVERLAY_DISP++); diff --git a/mm/src/code/z_room.c b/mm/src/code/z_room.c index 00397fdac..8ad5f1f15 100644 --- a/mm/src/code/z_room.c +++ b/mm/src/code/z_room.c @@ -2,6 +2,9 @@ #include "PR/gs2dex.h" #include "debug.h" +#include "public/bridge/gfxbridge.h" + + void Room_Noop(PlayState* play, Room* room, Input* input, s32 arg3) { } @@ -325,7 +328,7 @@ void Room_DrawImageSingle(PlayState* play, Room* room, u32 flags) { } if (drawBackground) { - gSPLoadUcodeL(POLY_OPA_DISP++, gspS2DEX2_fifo); + gSPLoadUcodeL(POLY_OPA_DISP++, ucode_s2dex); gfx = POLY_OPA_DISP; @@ -343,7 +346,7 @@ void Room_DrawImageSingle(PlayState* play, Room* room, u32 flags) { POLY_OPA_DISP = gfx; - gSPLoadUcode(POLY_OPA_DISP++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); + gSPLoadUcode(POLY_OPA_DISP++, SysUcode_GetUCode()); } } @@ -424,7 +427,7 @@ void Room_DrawImageMulti(PlayState* play, Room* room, u32 flags) { } if (drawBackground) { - gSPLoadUcodeL(POLY_OPA_DISP++, gspS2DEX2_fifo); + gSPLoadUcodeL(POLY_OPA_DISP++, ucode_s2dex); gfx = POLY_OPA_DISP; @@ -442,7 +445,7 @@ void Room_DrawImageMulti(PlayState* play, Room* room, u32 flags) { POLY_OPA_DISP = gfx; - gSPLoadUcode(POLY_OPA_DISP++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); + gSPLoadUcode(POLY_OPA_DISP++, SysUcode_GetUCode()); } } diff --git a/mm/src/code/z_visfbuf.c b/mm/src/code/z_visfbuf.c index b1d3fa4e1..1ddd3a3c9 100644 --- a/mm/src/code/z_visfbuf.c +++ b/mm/src/code/z_visfbuf.c @@ -15,6 +15,7 @@ #include "sys_cfb.h" #include #include "2s2h/framebuffer_effects.h" +#include "public/bridge/gfxbridge.h" #define SCALE_MIN 0.032f #define SCALE_MAX 1.0f //!< also unchanged scale @@ -170,7 +171,11 @@ void VisFbuf_ApplyEffects(VisFbuf* this, Gfx** gfxP, void* source, void* img, s3 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); + + // The function FB_CopyToFramebuffer uses f3dex2 opcodes, clear and set geometry ode. We need to load f3dex2, call the function, and then reload s2dex. + gSPLoadUcode(gfx++, ucode_f3dex2); FB_CopyToFramebuffer(&gfx, 0, gReusableFrameBuffer, false, NULL); + gSPLoadUcode(gfx++, ucode_s2dex); gDPPipeSync(gfx++); // fill framebuffer with primColor @@ -186,7 +191,10 @@ void VisFbuf_ApplyEffects(VisFbuf* this, Gfx** gfxP, void* source, void* img, s3 //! @bug VisFbuf_SetBgSimple() sets the current color image back to the frame's default framebuffer at the end, //! so this will always fill in the default framebuffer, whatever are used as `source` and `img`. This does not //! arise in-game since this function is always used with `source = D_0F000000`. + + gSPLoadUcode(gfx++, ucode_f3dex2); gDPFillWideRectangle(gfx++, OTRGetRectDimensionFromLeftEdge(0), 0, OTRGetRectDimensionFromRightEdge(width - 1), height - 1); + gSPLoadUcode(gfx++, ucode_s2dex); gDPPipeSync(gfx++); // Set lod and primColor from struct, perform interpolation, draw image with scaling (this is the most general @@ -224,9 +232,14 @@ void VisFbuf_ApplyEffects(VisFbuf* this, Gfx** gfxP, void* source, void* img, s3 // 2S2H [Port][Widescreen] // Draw shrunk window using an adjusted horizontal scale accounting for different aspect ratios + // The function FB_DrawFromFramebufferScaled uses f3dex2 opcodes. We need to load f3dex2, call the function, and then + // reload s2dex. + + gSPLoadUcode(gfx++, ucode_f3dex2); FB_DrawFromFramebufferScaled(&gfx, gReusableFrameBuffer, 255, (1.0f - scale) * (OTRGetAspectRatio() / ((float)SCREEN_WIDTH / SCREEN_HEIGHT)), (1.0f - scale)); + gSPLoadUcode(gfx++, ucode_s2dex); } gDPPipeSync(gfx++); @@ -313,7 +326,7 @@ void VisFbuf_DrawInterpolate(VisFbuf* this, Gfx** gfxP, void* img, s32 width, s3 void VisFbuf_Draw(VisFbuf* this, Gfx** gfxP, void* img) { Gfx* gfx = *gfxP; - gSPLoadUcodeL(gfx++, gspS2DEX2_fifo); + gSPLoadUcodeL(gfx++, ucode_s2dex); switch (this->mode) { case VIS_FBUF_MODE_GENERAL: @@ -328,7 +341,7 @@ void VisFbuf_Draw(VisFbuf* this, Gfx** gfxP, void* img) { break; } - gSPLoadUcode(gfx++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); + gSPLoadUcode(gfx++, SysUcode_GetUCode()); *gfxP = gfx; } diff --git a/mm/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c b/mm/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c index 44c3b443a..46e677d13 100644 --- a/mm/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c +++ b/mm/src/overlays/fbdemos/ovl_fbdemo_wipe5/z_fbdemo_wipe5.c @@ -9,6 +9,7 @@ #include "sys_cfb.h" #include "z_fbdemo_wipe5.h" #include +#include "public/bridge/gfxbridge.h" #define THIS ((TransitionWipe5*)thisx) @@ -89,7 +90,7 @@ void TransitionWipe5_Draw(void* thisx, Gfx** gfxP) { s32 alpha = (1.0f - this->unk_0C) * 255.0f; gDPPipeSync(gfx++); - gSPLoadUcodeL(gfx++, gspS2DEX2_fifo); + gSPLoadUcodeL(gfx++, ucode_s2dex); if (this->unk_10 == 0) { gDPSetOtherMode(gfx++, G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE | @@ -114,7 +115,7 @@ void TransitionWipe5_Draw(void* thisx, Gfx** gfxP) { VisFbuf_SetBgSimple(&gfx, workBuffer, D_0F000000_TO_SEGMENTED, width, height, VIS_FBUF_BG_CYC_1CYC); } gDPPipeSync(gfx++); - gSPLoadUcode(gfx++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); + gSPLoadUcode(gfx++, SysUcode_GetUCode()); *gfxP = gfx; }