From 46a9888647af3f153dd920cea64f1f6ebb25c446 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 2 Aug 2023 20:32:21 +0200 Subject: [PATCH] port: hackfix modeswitching --- port/fast3d/gfx_api.h | 1 + port/fast3d/gfx_pc.cpp | 1 + port/fast3d/gfx_pc.h | 4 ++-- port/include/video.h | 2 ++ port/src/pdmain.c | 2 ++ port/src/pdsched.c | 16 +++------------- port/src/video.c | 8 ++++++++ 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/port/fast3d/gfx_api.h b/port/fast3d/gfx_api.h index 9de67e7ab..fdb5035ce 100644 --- a/port/fast3d/gfx_api.h +++ b/port/fast3d/gfx_api.h @@ -23,6 +23,7 @@ extern struct GfxDimensions extern struct XYWidthHeight gfx_current_game_window_viewport; // The area of the window the game is drawn to, (0, 0) is top-left corner extern uint32_t gfx_msaa_level; +extern struct XYWidthHeight gfx_current_native_viewport; // The internal/native video mode of the game void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen, uint32_t width, uint32_t height, diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index a67333a88..478b7215e 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -201,6 +201,7 @@ int32_t gfx_current_window_position_y; struct GfxDimensions gfx_current_dimensions; static struct GfxDimensions gfx_prev_dimensions; struct XYWidthHeight gfx_current_game_window_viewport; +struct XYWidthHeight gfx_current_native_viewport; static bool game_renders_to_framebuffer; static int game_framebuffer; diff --git a/port/fast3d/gfx_pc.h b/port/fast3d/gfx_pc.h index 520ffe443..a0f858f81 100644 --- a/port/fast3d/gfx_pc.h +++ b/port/fast3d/gfx_pc.h @@ -10,8 +10,8 @@ #include -#define SCREEN_WIDTH 640 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH (gfx_current_native_viewport.width) +#define SCREEN_HEIGHT (gfx_current_native_viewport.height) extern uintptr_t gfxFramebuffer; diff --git a/port/include/video.h b/port/include/video.h index ed2dc5931..b463a267a 100644 --- a/port/include/video.h +++ b/port/include/video.h @@ -12,4 +12,6 @@ void videoEndFrame(void); void *videoGetWindowHandle(void); +void videoUpdateNativeResolution(const int w, const int h); + #endif diff --git a/port/src/pdmain.c b/port/src/pdmain.c index c4fc6b9bb..85960adc2 100644 --- a/port/src/pdmain.c +++ b/port/src/pdmain.c @@ -237,8 +237,10 @@ void mainInit(void) g_VmShowStats = 0; // no copyright screen + viSetMode(VIMODE_HI); viConfigureForLegal(); viBlack(true); + viUpdateMode(); filesInit(); diff --git a/port/src/pdsched.c b/port/src/pdsched.c index 3e786affe..7fc696cb4 100644 --- a/port/src/pdsched.c +++ b/port/src/pdsched.c @@ -197,19 +197,9 @@ void __scUpdateViMode(void) var8005ce74 = (var8005ce74 + 1) % 2; if (g_SchedViModesPending[1 - var8005ce74]) { - if (var8008dd60[1 - var8005ce74]->comRegs.width != var8008dcc0[1 - var8005ce74].comRegs.width - || var8008dd60[1 - var8005ce74]->comRegs.xScale != var8008dcc0[1 - var8005ce74].comRegs.xScale - || var8008dd60[1 - var8005ce74]->fldRegs[0].yScale != var8008dcc0[1 - var8005ce74].fldRegs[0].yScale - || var8008dd60[1 - var8005ce74]->fldRegs[1].yScale != var8008dcc0[1 - var8005ce74].fldRegs[1].yScale - || var8008dd60[1 - var8005ce74]->fldRegs[0].origin != var8008dcc0[1 - var8005ce74].fldRegs[0].origin - || var8008dd60[1 - var8005ce74]->fldRegs[1].origin != var8008dcc0[1 - var8005ce74].fldRegs[1].origin) { - osViSetMode(var8008dd60[1 - var8005ce74]); - osViBlack(g_ViUnblackTimer); - osViSetXScale(g_ViXScalesBySlot[1 - var8005ce74]); - osViSetYScale(g_ViYScalesBySlot[1 - var8005ce74]); - osViSetSpecialFeatures(OS_VI_GAMMA_OFF | OS_VI_DITHER_FILTER_ON); - } - + // TODO: make this a little less awkward + extern struct rend_vidat *g_ViBackData; + videoUpdateNativeResolution(g_ViBackData->bufx, g_ViBackData->bufy); g_SchedViModesPending[1 - var8005ce74] = false; } diff --git a/port/src/video.c b/port/src/video.c index f214eaae9..c74a0eb15 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -23,6 +23,8 @@ s32 videoInit(void) { wmAPI = &gfx_sdl; renderingAPI = &gfx_opengl_api; + gfx_current_native_viewport.width = 320; + gfx_current_native_viewport.height = 240; gfx_current_game_window_viewport.width = 640; gfx_current_game_window_viewport.height = 480; gfx_init(wmAPI, renderingAPI, "PD", false, 640, 480, 100, 100); @@ -82,3 +84,9 @@ void *videoGetWindowHandle(void) } return NULL; } + +void videoUpdateNativeResolution(const int w, const int h) +{ + gfx_current_native_viewport.width = w; + gfx_current_native_viewport.height = h; +}