From 48bf31f86feb952028f3d5082892c2dfbb8246a7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 2 Jul 2025 19:30:49 +1000 Subject: [PATCH] Wii/GC: Clear framebuffer initially to grey --- src/gcwii/Graphics_GCWii.c | 13 ++++++++----- src/gcwii/Window_GCWii.c | 37 +++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/gcwii/Graphics_GCWii.c b/src/gcwii/Graphics_GCWii.c index cd4fdfd96..822c035f2 100644 --- a/src/gcwii/Graphics_GCWii.c +++ b/src/gcwii/Graphics_GCWii.c @@ -9,8 +9,11 @@ static void* fifo_buffer; #define FIFO_SIZE (256 * 1024) + +extern GXRModeObj* cur_mode; extern void* Window_XFB; static void* xfbs[2]; + static int curFB; static GfxResourceID white_square; static GXTexRegionCallback regionCB; @@ -22,7 +25,7 @@ static GXTexRegionCallback regionCB; *---------------------------------------------------------General---------------------------------------------------------* *#########################################################################################################################*/ static void InitGX(void) { - GXRModeObj* mode = VIDEO_GetPreferredMode(NULL); + GXRModeObj* mode = cur_mode; fifo_buffer = MEM_K0_TO_K1(memalign(32, FIFO_SIZE)); memset(fifo_buffer, 0, FIFO_SIZE); @@ -242,7 +245,8 @@ static BitmapCol* GCWii_GetRow(struct Bitmap* bmp, int y, void* ctx) { int blockXStride = (4 * 4) * 4; // 16 pixels per tile // Do the inverse of converting from 4x4 tiled to linear - for (u32 x = 0; x < bmp->width; x++){ + for (u32 x = 0; x < bmp->width; x++) + { int tileY = y >> 2, tileX = x >> 2; int locY = y & 0x3, locX = x & 0x3; int idx = (tileY * blockYStride) + (tileX * blockXStride) + ((locY << 2) + locX) * 2; @@ -260,9 +264,8 @@ static BitmapCol* GCWii_GetRow(struct Bitmap* bmp, int y, void* ctx) { cc_result Gfx_TakeScreenshot(struct Stream* output) { BitmapCol tmp[1024]; - GXRModeObj* vmode = VIDEO_GetPreferredMode(NULL); - int width = vmode->fbWidth; - int height = vmode->efbHeight; + int width = cur_mode->fbWidth; + int height = cur_mode->efbHeight; u8* buffer = memalign(32, width * height * 4); if (!buffer) return ERR_OUT_OF_MEMORY; diff --git a/src/gcwii/Window_GCWii.c b/src/gcwii/Window_GCWii.c index ee414eb71..2fe333169 100644 --- a/src/gcwii/Window_GCWii.c +++ b/src/gcwii/Window_GCWii.c @@ -23,7 +23,8 @@ static cc_bool launcherMode; static int mouseSupported; #include "../VirtualCursor.h" static void* xfb; -static GXRModeObj* rmode; + +GXRModeObj* cur_mode; void* Window_XFB; struct _DisplayData DisplayInfo; struct cc_window WindowInfo; @@ -34,28 +35,24 @@ static void OnPowerOff(void) { Window_RequestClose(); } static void InitVideo(void) { - // Initialise the video system VIDEO_Init(); // Obtain the preferred video mode from the system // This will correspond to the settings in the Wii menu - rmode = VIDEO_GetPreferredMode(NULL); - // Allocate memory for the display in the uncached region - xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); - - Window_XFB = xfb; - //console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); + cur_mode = VIDEO_GetPreferredMode(NULL); - // Set up the video registers with the chosen mode - VIDEO_Configure(rmode); - // Tell the video hardware where our display memory is + // Allocate memory for the display in the uncached region + xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(cur_mode)); + Window_XFB = xfb; + + VIDEO_Configure(cur_mode); VIDEO_SetNextFramebuffer(xfb); - // Make the display visible VIDEO_SetBlack(FALSE); - // Flush the video register changes to the hardware VIDEO_Flush(); - // Wait for Video setup to complete + VIDEO_WaitVSync(); + + VIDEO_ClearFrameBuffer(cur_mode, xfb, COLOR_GRAY); VIDEO_WaitVSync(); } @@ -68,13 +65,13 @@ void Window_PreInit(void) { } void Window_Init(void) { - DisplayInfo.Width = rmode->fbWidth; - DisplayInfo.Height = rmode->xfbHeight; + DisplayInfo.Width = cur_mode->fbWidth; + DisplayInfo.Height = cur_mode->xfbHeight; DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - Window_Main.Width = rmode->fbWidth; - Window_Main.Height = rmode->xfbHeight; + Window_Main.Width = cur_mode->fbWidth; + Window_Main.Height = cur_mode->xfbHeight; Window_Main.Focused = true; Window_Main.Exists = true; @@ -544,8 +541,8 @@ void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) { // TODO XFB is raw yuv, but is absolutely a pain to work with.. for (int y = r.y; y < r.y + r.height; y++) { - cc_uint32* src = Bitmap_GetRow(bmp, y) + r.x; - u16* dst = (u16*)xfb + y * rmode->fbWidth + r.x; + cc_uint32* src = Bitmap_GetRow(bmp, y) + r.x; + u16* dst = (u16*)xfb + y * cur_mode->fbWidth + r.x; for (int x = 0; x < r.width / 2; x++) { cc_uint32 rgb0 = src[(x<<1) + 0];