From 70abd5df179a52b5557303824493a92422dcb814 Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 31 Jan 2017 17:56:52 +1100 Subject: [PATCH] [Glide64] Make scrx and scry private members of settings --- Source/Glide64/Config.cpp | 4 +- Source/Glide64/FBtoScreen.cpp | 10 +- Source/Glide64/Main.cpp | 291 +++++++++------------------------- Source/Glide64/Settings.cpp | 115 +++++++++++--- Source/Glide64/Settings.h | 16 +- Source/Glide64/TexBuffer.cpp | 10 +- Source/Glide64/Util.cpp | 12 +- Source/Glide64/rdp.cpp | 10 +- Source/Glide64/ucode06.h | 13 +- 9 files changed, 207 insertions(+), 274 deletions(-) diff --git a/Source/Glide64/Config.cpp b/Source/Glide64/Config.cpp index 55c9bd4bd..48d5cb305 100644 --- a/Source/Glide64/Config.cpp +++ b/Source/Glide64/Config.cpp @@ -321,7 +321,7 @@ public: m_WindowRes.SetItemData(m_WindowRes.AddString("1920x1440"), 21); m_WindowRes.SetItemData(m_WindowRes.AddString("2048x1536"), 22); m_WindowRes.SetItemData(m_WindowRes.AddString("2048x2048"), 23); - SetComboBoxIndex(m_WindowRes, g_settings->res_data); + SetComboBoxIndex(m_WindowRes, g_settings->ScreenRes()); TTSetTxt(IDC_CMB_WINDOW_RES, "Resolution:\n\nThis option selects the windowed resolution.\n\n[Recommended: 640x480, 800x600, 1024x768]"); m_cbxVSync.Attach(GetDlgItem(IDC_CHK_VERTICAL_SYNC)); @@ -368,7 +368,7 @@ public: char spinVRAM[100]; m_spinVRAM.GetWindowText(spinVRAM, sizeof(spinVRAM)); CSettings oldsettings = *g_settings; - g_settings->res_data = m_WindowRes.GetCurSel(); + g_settings->SetScreenRes(m_WindowRes.GetCurSel()); g_settings->vsync = m_cbxVSync.GetCheck() == BST_CHECKED; g_settings->texenh_options = m_cbxTextureSettings.GetCheck() == BST_CHECKED; g_settings->wrpResolution = m_cmbFSResolution.GetCurSel(); diff --git a/Source/Glide64/FBtoScreen.cpp b/Source/Glide64/FBtoScreen.cpp index d67176132..fdea2311b 100644 --- a/Source/Glide64/FBtoScreen.cpp +++ b/Source/Glide64/FBtoScreen.cpp @@ -130,11 +130,11 @@ static int SetupFBtoScreenCombiner(uint32_t texture_size, uint32_t opaque) static void DrawRE2Video(FB_TO_SCREEN_INFO & fb_info, float scale) { float scale_y = (float)fb_info.width / rdp.vi_height; - float height = g_settings->scr_res_x / scale_y; + float height = g_settings->scr_res_x() / scale_y; float ul_x = 0.5f; - float ul_y = (g_settings->scr_res_y - height) / 2.0f; - float lr_y = g_settings->scr_res_y - ul_y - 1.0f; - float lr_x = g_settings->scr_res_x - 1.0f; + float ul_y = (g_settings->scr_res_y() - height) / 2.0f; + float lr_y = g_settings->scr_res_y() - ul_y - 1.0f; + float lr_x = g_settings->scr_res_x() - 1.0f; float lr_u = (fb_info.width - 1)*scale; float lr_v = (fb_info.height - 1)*scale; VERTEX v[4] = { @@ -506,7 +506,7 @@ static void DrawHiresDepthBufferToScreen(FB_TO_SCREEN_INFO & fb_info) GrTexInfo t_info; float scale = 0.25f; GrLOD_t LOD = GR_LOD_LOG2_1024; - if (g_settings->scr_res_x > 1024) + if (g_settings->scr_res_x() > 1024) { scale = 0.125f; LOD = GR_LOD_LOG2_2048; diff --git a/Source/Glide64/Main.cpp b/Source/Glide64/Main.cpp index 5032abef9..991b81b68 100644 --- a/Source/Glide64/Main.cpp +++ b/Source/Glide64/Main.cpp @@ -122,11 +122,11 @@ bool g_fullscreen; void _ChangeSize() { - rdp.scale_1024 = g_settings->scr_res_x / 1024.0f; - rdp.scale_768 = g_settings->scr_res_y / 768.0f; + rdp.scale_1024 = g_settings->scr_res_x() / 1024.0f; + rdp.scale_768 = g_settings->scr_res_y() / 768.0f; // float res_scl_x = (float)g_settings->res_x / 320.0f; - float res_scl_y = (float)g_settings->res_y / 240.0f; + float res_scl_y = (float)g_settings->res_y() / 240.0f; uint32_t scale_x = *gfx.VI_X_SCALE_REG & 0xFFF; if (!scale_x) return; @@ -155,7 +155,7 @@ void _ChangeSize() WriteTrace(TraceResolution, TraceDebug, "hstart: %d, hend: %d, vstart: %d, vend: %d", hstart, hend, vstart, vend); WriteTrace(TraceResolution, TraceDebug, "size: %d x %d", (int)rdp.vi_width, (int)rdp.vi_height); - rdp.scale_x = (float)g_settings->res_x / rdp.vi_width; + rdp.scale_x = (float)g_settings->res_x() / rdp.vi_width; if (region > 0 && g_settings->pal230) { // odd... but pal games seem to want 230 as height... @@ -163,13 +163,13 @@ void _ChangeSize() } else { - rdp.scale_y = (float)g_settings->res_y / rdp.vi_height * aspect; + rdp.scale_y = (float)g_settings->res_y() / rdp.vi_height * aspect; } // rdp.offset_x = g_settings->offset_x * res_scl_x; // rdp.offset_y = g_settings->offset_y * res_scl_y; //rdp.offset_x = 0; // rdp.offset_y = 0; - rdp.offset_y = ((float)g_settings->res_y - rdp.vi_height * rdp.scale_y) * 0.5f; + rdp.offset_y = ((float)g_settings->res_y() - rdp.vi_height * rdp.scale_y) * 0.5f; if (((uint32_t)rdp.vi_width <= (*gfx.VI_WIDTH_REG) / 2) && (rdp.vi_width > rdp.vi_height)) rdp.scale_y *= 0.5f; @@ -183,18 +183,16 @@ void _ChangeSize() void ChangeSize() { - g_settings->UpdateAspectRatio(); + g_settings->UpdateScreenSize(ev_fullscreen); _ChangeSize(); - rdp.offset_x = (g_settings->scr_res_x - g_settings->res_x) / 2.0f; - float offset_y = (g_settings->scr_res_y - g_settings->res_y) / 2.0f; - g_settings->res_x += (uint32_t)rdp.offset_x; - g_settings->res_y += (uint32_t)offset_y; + rdp.offset_x = (g_settings->scr_res_x() - g_settings->res_x()) / 2.0f; + float offset_y = (g_settings->scr_res_y() - g_settings->res_y()) / 2.0f; rdp.offset_y += offset_y; if (g_settings->aspectmode() == CSettings::Aspect_Original) { rdp.scale_x = rdp.scale_y = 1.0f; - rdp.offset_x = (g_settings->scr_res_x - rdp.vi_width) / 2.0f; - rdp.offset_y = (g_settings->scr_res_y - rdp.vi_height) / 2.0f; + rdp.offset_x = (g_settings->scr_res_x() - rdp.vi_width) / 2.0f; + rdp.offset_y = (g_settings->scr_res_y() - rdp.vi_height) / 2.0f; } } @@ -240,7 +238,7 @@ void guLoadTextures() tbuf_size = 8 * grTexCalcMemRequired(GR_LOD_LOG2_256, GR_LOD_LOG2_256, GR_ASPECT_LOG2_1x1, GR_TEXFMT_RGB_565); } - else if (g_settings->scr_res_x <= 1024) + else if (g_settings->scr_res_x() <= 1024) { grTextureBufferExt(GR_TMU0, voodoo.tex_min_addr[GR_TMU0], GR_LOD_LOG2_1024, GR_LOD_LOG2_1024, GR_ASPECT_LOG2_1x1, GR_TEXFMT_RGB_565, GR_MIPMAPLEVELMASK_BOTH); @@ -381,187 +379,9 @@ void SetWindowDisplaySize(HWND hWnd) { if ((HWND)hWnd == NULL) hWnd = GetActiveWindow(); g_hwnd_win = (HWND)hWnd; - - // Resolutions, MUST be in the correct order (SST1VID.H) - uint32_t resolutions[0x18][2] = { - { 320, 200 }, - { 320, 240 }, - { 400, 256 }, - { 512, 384 }, - { 640, 200 }, - { 640, 350 }, - { 640, 400 }, - { 640, 480 }, - { 800, 600 }, - { 960, 720 }, - { 856, 480 }, - { 512, 256 }, - { 1024, 768 }, - { 1280, 1024 }, - { 1600, 1200 }, - { 400, 300 }, - - // 0x10 - { 1152, 864 }, - { 1280, 960 }, - { 1600, 1024 }, - { 1792, 1344 }, - { 1856, 1392 }, - { 1920, 1440 }, - { 2048, 1536 }, - { 2048, 2048 } - }; - -#ifndef ANDROID - uint32_t screen_resolution = g_settings->res_data; + if (ev_fullscreen) { - uint32_t _width, _height = 0; - screen_resolution = grWrapperFullScreenResolutionExt(&_width, &_height); - g_settings->scr_res_x = g_settings->res_x = _width; - g_settings->scr_res_y = g_settings->res_y = _height; - } - else if (evoodoo) - { - g_settings->scr_res_x = g_settings->res_x = resolutions[g_settings->res_data][0]; - g_settings->scr_res_y = g_settings->res_y = resolutions[g_settings->res_data][1]; - screen_resolution |= 0x80000000; - } -#endif - - if ((HWND)hWnd == NULL) hWnd = GetActiveWindow(); - g_width = g_height = 0; - if (screen_resolution & 0x80000000) - { - switch (screen_resolution & ~0x80000000) - { - case GR_RESOLUTION_320x200: - g_width = 320; - g_height = 200; - break; - case GR_RESOLUTION_320x240: - g_width = 320; - g_height = 240; - break; - case GR_RESOLUTION_400x256: - g_width = 400; - g_height = 256; - break; - case GR_RESOLUTION_512x384: - g_width = 512; - g_height = 384; - break; - case GR_RESOLUTION_640x200: - g_width = 640; - g_height = 200; - break; - case GR_RESOLUTION_640x350: - g_width = 640; - g_height = 350; - break; - case GR_RESOLUTION_640x400: - g_width = 640; - g_height = 400; - break; - case GR_RESOLUTION_640x480: - g_width = 640; - g_height = 480; - break; - case GR_RESOLUTION_800x600: - g_width = 800; - g_height = 600; - break; - case GR_RESOLUTION_960x720: - g_width = 960; - g_height = 720; - break; - case GR_RESOLUTION_856x480: - g_width = 856; - g_height = 480; - break; - case GR_RESOLUTION_512x256: - g_width = 512; - g_height = 256; - break; - case GR_RESOLUTION_1024x768: - g_width = 1024; - g_height = 768; - break; - case GR_RESOLUTION_1280x1024: - g_width = 1280; - g_height = 1024; - break; - case GR_RESOLUTION_1600x1200: - g_width = 1600; - g_height = 1200; - break; - case GR_RESOLUTION_400x300: - g_width = 400; - g_height = 300; - break; - case GR_RESOLUTION_1152x864: - g_width = 1152; - g_height = 864; - break; - case GR_RESOLUTION_1280x960: - g_width = 1280; - g_height = 960; - break; - case GR_RESOLUTION_1600x1024: - g_width = 1600; - g_height = 1024; - break; - case GR_RESOLUTION_1792x1344: - g_width = 1792; - g_height = 1344; - break; - case GR_RESOLUTION_1856x1392: - g_width = 1856; - g_height = 1392; - break; - case GR_RESOLUTION_1920x1440: - g_width = 1920; - g_height = 1440; - break; - case GR_RESOLUTION_2048x1536: - g_width = 2048; - g_height = 1536; - break; - case GR_RESOLUTION_2048x2048: - g_width = 2048; - g_height = 2048; - break; - default: - WriteTrace(TraceGlitch, TraceWarning, "unknown SstWinOpen resolution : %x", screen_resolution); - } - } - - if (screen_resolution & 0x80000000) - { - RECT clientRect, toolbarRect, statusbarRect; - ZeroMemory(&g_windowedRect, sizeof(RECT)); - ZeroMemory(&clientRect, sizeof(RECT)); - ZeroMemory(&toolbarRect, sizeof(RECT)); - ZeroMemory(&statusbarRect, sizeof(RECT)); - HWND hToolBar = FindWindowEx(hWnd, NULL, REBARCLASSNAME, NULL); - HWND hStatusBar = FindWindowEx(hWnd, NULL, STATUSCLASSNAME, NULL); - if (hStatusBar == NULL) hStatusBar = FindWindowEx(hWnd, NULL, "msctls_statusbar32", NULL); // 1964 - if (hToolBar != NULL) GetWindowRect(hToolBar, &toolbarRect); - if (hStatusBar != NULL) GetWindowRect(hStatusBar, &statusbarRect); - viewport_offset = statusbarRect.bottom - statusbarRect.top; - GetWindowRect(hWnd, &g_windowedRect); - GetClientRect(hWnd, &clientRect); - g_windowedRect.right += (g_width - (clientRect.right - clientRect.left)); - g_windowedRect.bottom += (g_height + (toolbarRect.bottom - toolbarRect.top) + (statusbarRect.bottom - statusbarRect.top) - (clientRect.bottom - clientRect.top)); - SetWindowPos(hWnd, NULL, 0, 0, g_windowedRect.right - g_windowedRect.left, - g_windowedRect.bottom - g_windowedRect.top, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); - - g_fullscreen = false; - } - else - { - g_width = GetFullScreenResWidth(screen_resolution); - g_height = GetFullScreenResHeight(screen_resolution); ZeroMemory(&g_windowedRect, sizeof(RECT)); GetWindowRect(hWnd, &g_windowedRect); @@ -569,7 +389,7 @@ void SetWindowDisplaySize(HWND hWnd) g_windowedStyle = GetWindowLong(hWnd, GWL_STYLE); // primary monitor only - if (!EnterFullScreen(screen_resolution)) + if (!EnterFullScreen(g_settings->wrpResolution)) { WriteTrace(TraceGlitch, TraceWarning, "can't change to fullscreen mode"); } @@ -587,6 +407,33 @@ void SetWindowDisplaySize(HWND hWnd) viewport_offset = 0; g_fullscreen = true; } + else + { + RECT clientRect = { 0 }, toolbarRect = { 0 }, statusbarRect = { 0 }, windowedRect = { 0 }; + ZeroMemory(&g_windowedRect, sizeof(RECT)); + HWND hToolBar = FindWindowEx(hWnd, NULL, REBARCLASSNAME, NULL); + HWND hStatusBar = FindWindowEx(hWnd, NULL, STATUSCLASSNAME, NULL); + if (hStatusBar == NULL) + { + hStatusBar = FindWindowEx(hWnd, NULL, "msctls_statusbar32", NULL); + } + if (hToolBar != NULL) + { + GetWindowRect(hToolBar, &toolbarRect); + } + if (hStatusBar != NULL) + { + GetWindowRect(hStatusBar, &statusbarRect); + } + viewport_offset = statusbarRect.bottom - statusbarRect.top; + GetWindowRect(hWnd, &g_windowedRect); + GetClientRect(hWnd, &clientRect); + g_windowedRect.right += (g_width - (clientRect.right - clientRect.left)); + g_windowedRect.bottom += (g_height + (toolbarRect.bottom - toolbarRect.top) + (statusbarRect.bottom - statusbarRect.top) - (clientRect.bottom - clientRect.top)); + SetWindowPos(hWnd, NULL, 0, 0, g_windowedRect.right - g_windowedRect.left, g_windowedRect.bottom - g_windowedRect.top, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); + + g_fullscreen = false; + } } void ExitFullScreen(void) @@ -666,6 +513,7 @@ int InitGfx() //*/ #ifndef ANDROID + g_settings->UpdateScreenSize(ev_fullscreen); SetWindowDisplaySize(gfx.hWnd); gfx_context = grSstWinOpen(GR_COLORFORMAT_RGBA, GR_ORIGIN_UPPER_LEFT, 2, 1); if (!gfx_context) @@ -781,8 +629,6 @@ int InitGfx() grDepthBufferFunction(GR_CMP_LESS); grDepthMask(FXTRUE); - g_settings->res_x = g_settings->scr_res_x; - g_settings->res_y = g_settings->scr_res_y; ChangeSize(); guLoadTextures(); @@ -802,7 +648,7 @@ int InitGfx() grTexFilterMode(1, GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR); grTexClampMode(0, GR_TEXTURECLAMP_CLAMP, GR_TEXTURECLAMP_CLAMP); grTexClampMode(1, GR_TEXTURECLAMP_CLAMP, GR_TEXTURECLAMP_CLAMP); - grClipWindow(0, 0, g_settings->scr_res_x, g_settings->scr_res_y); + grClipWindow(0, 0, g_settings->scr_res_x(), g_settings->scr_res_y()); rdp.update |= UPDATE_SCISSOR | UPDATE_COMBINE | UPDATE_ZBUF_ENABLED | UPDATE_CULL_MODE; if (!g_settings->ghq_use) @@ -813,27 +659,45 @@ int InitGfx() /* Plugin path */ int options = g_settings->ghq_fltr() | g_settings->ghq_enht() | texcmpr[g_settings->ghq_cmpr] | texhirs[g_settings->ghq_hirs]; if (g_settings->ghq_enht_cmpr) + { options |= COMPRESS_TEX; + } if (g_settings->ghq_hirs_cmpr) + { options |= COMPRESS_HIRESTEX; - // if (g_settings->ghq_enht_tile) - // options |= TILE_TEX; + } if (g_settings->ghq_hirs_tile) + { options |= TILE_HIRESTEX; + } if (g_settings->ghq_enht_f16bpp) + { options |= FORCE16BPP_TEX; + } if (g_settings->ghq_hirs_f16bpp) + { options |= FORCE16BPP_HIRESTEX; + } if (g_settings->ghq_enht_gz) + { options |= GZ_TEXCACHE; + } if (g_settings->ghq_hirs_gz) + { options |= GZ_HIRESTEXCACHE; + } if (g_settings->ghq_cache_save) + { options |= (DUMP_TEXCACHE | DUMP_HIRESTEXCACHE); + } if (g_settings->ghq_hirs_let_texartists_fly) + { options |= LET_TEXARTISTS_FLY; + } if (g_settings->ghq_hirs_dump) + { options |= DUMP_TEX; + } g_settings->ghq_use = (int)ext_ghq_init(voodoo.max_tex_size, // max texture width supported by hardware voodoo.max_tex_size, // max texture height supported by hardware @@ -846,8 +710,9 @@ int InitGfx() } } if (g_settings->ghq_use && strstr(extensions, "TEXMIRROR")) + { voodoo.sup_mirroring = 1; - + } return TRUE; } @@ -903,9 +768,9 @@ extern "C" int WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID /*lpReser void CALL ReadScreen(void **dest, int *width, int *height) { - *width = g_settings->res_x; - *height = g_settings->res_y; - uint8_t * buff = (uint8_t*)malloc(g_settings->res_x * g_settings->res_y * 3); + *width = g_settings->res_x(); + *height = g_settings->res_y(); + uint8_t * buff = (uint8_t*)malloc(g_settings->res_x() * g_settings->res_y() * 3); uint8_t * line = buff; *dest = (void*)buff; @@ -918,17 +783,17 @@ void CALL ReadScreen(void **dest, int *width, int *height) FXFALSE, &info)) { - uint32_t offset_src = info.strideInBytes*(g_settings->scr_res_y - 1); + uint32_t offset_src = info.strideInBytes*(g_settings->scr_res_y() - 1); // Copy the screen uint8_t r, g, b; if (info.writeMode == GR_LFBWRITEMODE_8888) { uint32_t col; - for (uint32_t y = 0; y < g_settings->res_y; y++) + for (uint32_t y = 0; y < g_settings->res_y(); y++) { uint32_t *ptr = (uint32_t*)((uint8_t*)info.lfbPtr + offset_src); - for (uint32_t x = 0; x < g_settings->res_x; x++) + for (uint32_t x = 0; x < g_settings->res_x(); x++) { col = *(ptr++); r = (uint8_t)((col >> 16) & 0xFF); @@ -938,17 +803,17 @@ void CALL ReadScreen(void **dest, int *width, int *height) line[x * 3 + 1] = g; line[x * 3 + 2] = r; } - line += g_settings->res_x * 3; + line += g_settings->res_x() * 3; offset_src -= info.strideInBytes; } } else { uint16_t col; - for (uint32_t y = 0; y < g_settings->res_y; y++) + for (uint32_t y = 0; y < g_settings->res_y(); y++) { uint16_t *ptr = (uint16_t*)((uint8_t*)info.lfbPtr + offset_src); - for (uint32_t x = 0; x < g_settings->res_x; x++) + for (uint32_t x = 0; x < g_settings->res_x(); x++) { col = *(ptr++); r = (uint8_t)((float)(col >> 11) / 31.0f * 255.0f); @@ -958,7 +823,7 @@ void CALL ReadScreen(void **dest, int *width, int *height) line[x * 3 + 1] = g; line[x * 3 + 2] = r; } - line += g_settings->res_x * 3; + line += g_settings->res_x() * 3; offset_src -= info.strideInBytes; } } @@ -1582,7 +1447,7 @@ void newSwapBuffers() WriteTrace(TraceRDP, TraceDebug, "swapped"); rdp.update |= UPDATE_SCISSOR | UPDATE_COMBINE | UPDATE_ZBUF_ENABLED | UPDATE_CULL_MODE; - grClipWindow(0, 0, g_settings->scr_res_x, g_settings->scr_res_y); + grClipWindow(0, 0, g_settings->scr_res_x(), g_settings->scr_res_y()); grDepthBufferFunction(GR_CMP_ALWAYS); grDepthMask(FXFALSE); grCullMode(GR_CULL_DISABLE); @@ -1610,8 +1475,8 @@ void newSwapBuffers() const uint32_t offset_x = (uint32_t)rdp.offset_x; const uint32_t offset_y = (uint32_t)rdp.offset_y; - const uint32_t image_width = g_settings->scr_res_x - offset_x * 2; - const uint32_t image_height = g_settings->scr_res_y - offset_y * 2; + const uint32_t image_width = g_settings->scr_res_x() - offset_x * 2; + const uint32_t image_height = g_settings->scr_res_y() - offset_y * 2; GrLfbInfo_t info; info.size = sizeof(GrLfbInfo_t); diff --git a/Source/Glide64/Settings.cpp b/Source/Glide64/Settings.cpp index fbb231b8d..b443f2912 100644 --- a/Source/Glide64/Settings.cpp +++ b/Source/Glide64/Settings.cpp @@ -1,5 +1,6 @@ #include #include "Gfx_1.3.h" +#include "ScreenResolution.h" #include "SettingsID.h" #ifdef _WIN32 @@ -11,13 +12,11 @@ extern int g_width, g_height; CSettings::CSettings() : m_dirty(false), -res_x(640), -scr_res_x(640), -res_y(480), -scr_res_y(480), -#ifndef ANDROID -res_data(GR_RESOLUTION_640x480), -#endif + m_res_x(640), + m_scr_res_x(640), + m_res_y(480), + m_scr_res_y(480), + m_ScreenRes(7), advanced_options(0), texenh_options(0), vsync(0), @@ -109,8 +108,8 @@ void CSettings::RegisterSettings(void) Set_log_dir = FindSystemSettingId("Dir:Log"); SetModuleName("Glide64"); -#ifdef _WIN32 general_setting(Set_Resolution, "resolution", 7); +#ifdef _WIN32 general_setting(Set_FullScreenRes, "FullScreenRes", GetCurrentResIndex()); #endif general_setting(Set_vsync, "vsync", 1); @@ -206,6 +205,69 @@ void CSettings::RegisterSettings(void) game_setting_default(Set_fb_render, "fb_render", Set_fb_render_default); } +void CSettings::SetScreenRes(uint32_t value) +{ + if (value >= 0x18) + { + value = 7; + } + + if (value != m_ScreenRes) + { + m_ScreenRes = value; + m_dirty = true; + } +} + +void CSettings::UpdateScreenSize(bool fullscreen) +{ + // Resolutions, MUST be in the correct order (SST1VID.H) + uint32_t resolutions[0x18][2] = { + { 320, 200 }, + { 320, 240 }, + { 400, 256 }, + { 512, 384 }, + { 640, 200 }, + { 640, 350 }, + { 640, 400 }, + { 640, 480 }, + { 800, 600 }, + { 960, 720 }, + { 856, 480 }, + { 512, 256 }, + { 1024, 768 }, + { 1280, 1024 }, + { 1600, 1200 }, + { 400, 300 }, + + // 0x10 + { 1152, 864 }, + { 1280, 960 }, + { 1600, 1024 }, + { 1792, 1344 }, + { 1856, 1392 }, + { 1920, 1440 }, + { 2048, 1536 }, + { 2048, 2048 } + }; + +#ifndef ANDROID + if (fullscreen) + { + g_width = GetFullScreenResWidth(wrpResolution); + g_height = GetFullScreenResHeight(wrpResolution); + } + else + { + g_width = resolutions[m_ScreenRes][0]; + g_height = resolutions[m_ScreenRes][1]; + } + m_scr_res_x = m_res_x = g_width; + m_scr_res_y = m_res_y = g_height; +#endif + UpdateAspectRatio(); +} + void CSettings::SetAspectmode(AspectMode_t value) { if (value != m_aspectmode) @@ -297,32 +359,36 @@ void CSettings::UpdateAspectRatio(void) switch (m_aspectmode) { case Aspect_4x3: - if (scr_res_x >= scr_res_y * 4.0f / 3.0f) { - res_y = scr_res_y; - res_x = (uint32_t)(res_y * 4.0f / 3.0f); + if (m_scr_res_x >= m_scr_res_y * 4.0f / 3.0f) { + m_res_y = m_scr_res_y; + m_res_x = (uint32_t)(m_res_y * 4.0f / 3.0f); } else { - res_x = scr_res_x; - res_y = (uint32_t)(res_x / 4.0f * 3.0f); + m_res_x = m_scr_res_x; + m_res_y = (uint32_t)(m_res_x / 4.0f * 3.0f); } break; case Aspect_16x9: - if (scr_res_x >= scr_res_y * 16.0f / 9.0f) + if (m_scr_res_x >= m_scr_res_y * 16.0f / 9.0f) { - res_y = scr_res_y; - res_x = (uint32_t)(res_y * 16.0f / 9.0f); + m_res_y = m_scr_res_y; + m_res_x = (uint32_t)(m_res_y * 16.0f / 9.0f); } else { - res_x = scr_res_x; - res_y = (uint32_t)(res_x / 16.0f * 9.0f); + m_res_x = m_scr_res_x; + m_res_y = (uint32_t)(m_res_x / 16.0f * 9.0f); } break; default: //stretch or original - res_x = scr_res_x; - res_y = scr_res_y; + m_res_x = m_scr_res_x; + m_res_y = m_scr_res_y; } + + m_res_x += (uint32_t)(m_scr_res_x - m_res_x) / 2.0f; + m_res_y += (uint32_t)(m_scr_res_y - m_res_y) / 2.0f; + } void CSettings::ReadSettings() @@ -331,8 +397,7 @@ void CSettings::ReadSettings() this->scr_res_x = this->res_x = g_width; this->scr_res_y = this->res_y = g_height; #else - this->res_data = (uint32_t)GetSetting(Set_Resolution); - if (this->res_data >= 24) this->res_data = 12; + SetScreenRes(GetSetting(Set_Resolution)); this->wrpResolution = GetSetting(Set_FullScreenRes); #endif this->vsync = GetSetting(Set_vsync); @@ -548,8 +613,8 @@ void CSettings::ReadGameSettings(const char * name) g_settings->fog = GetSetting(g_romopen ? Set_fog : Set_fog_default); g_settings->buff_clear = GetSetting(g_romopen ? Set_buff_clear : Set_buff_clear_default); #ifdef _WIN32 - g_settings->res_data = GetSetting(Set_Resolution); - if (g_settings->res_data < 0 || g_settings->res_data >= 0x18) g_settings->res_data = 12; + g_settings->m_ScreenRes = GetSetting(Set_Resolution); + if (g_settings->m_ScreenRes < 0 || g_settings->m_ScreenRes >= 0x18) g_settings->m_ScreenRes = 12; #endif //frame buffer @@ -615,7 +680,7 @@ void CSettings::ReadGameSettings(const char * name) void CSettings::WriteSettings(void) { #ifdef _WIN32 - SetSetting(Set_Resolution, (int)g_settings->res_data); + SetSetting(Set_Resolution, g_settings->m_ScreenRes); SetSetting(Set_FullScreenRes, g_settings->wrpResolution); #endif SetSetting(Set_vsync, g_settings->vsync); diff --git a/Source/Glide64/Settings.h b/Source/Glide64/Settings.h index 0a508f3e4..5d7cb0725 100644 --- a/Source/Glide64/Settings.h +++ b/Source/Glide64/Settings.h @@ -144,11 +144,6 @@ public: ucode_Turbo3d = 21, }; - uint32_t res_x, scr_res_x; - uint32_t res_y, scr_res_y; -#ifndef ANDROID - uint32_t res_data; -#endif int advanced_options; int texenh_options; @@ -183,6 +178,11 @@ public: inline bool fb_optimize_texrect_enabled(void) const { return ((m_frame_buffer&fb_optimize_texrect) != 0); } inline const char * log_dir(void) const { return m_log_dir; } + inline uint32_t res_x(void) const { return m_res_x; } + inline uint32_t res_y(void) const { return m_res_y; } + inline uint32_t scr_res_x(void) const { return m_scr_res_x; } + inline uint32_t scr_res_y(void) const { return m_scr_res_y; } + inline uint32_t ScreenRes(void) const { return m_ScreenRes; } inline bool FlushLogs(void) const { return m_FlushLogs; } inline ScreenRotate_t rotate(void) const { return m_rotate; } inline Filtering_t filtering(void) const { return m_filtering; } @@ -256,6 +256,7 @@ public: int wrpVRAM; int wrpFBO; int wrpAnisotropic; + void SetScreenRes(uint32_t value); void SetAspectmode(AspectMode_t value); void SetLODmode(PixelLevelOfDetail_t value); void SetFiltering(Filtering_t value); @@ -269,6 +270,8 @@ public: void ReadGameSettings(const char * name); void WriteSettings(void); void UpdateAspectRatio(void); + void UpdateScreenSize(bool fullscreen); + private: void ReadSettings(); @@ -277,6 +280,9 @@ private: bool m_dirty; bool m_FlushLogs; char m_log_dir[260]; + uint32_t m_ScreenRes; + uint32_t m_res_x, m_scr_res_x; + uint32_t m_res_y, m_scr_res_y; AspectMode_t m_aspectmode; uint32_t m_frame_buffer; FBCRCMODE_t m_fb_crc_mode; diff --git a/Source/Glide64/TexBuffer.cpp b/Source/Glide64/TexBuffer.cpp index 22405b51c..26c1003d4 100644 --- a/Source/Glide64/TexBuffer.cpp +++ b/Source/Glide64/TexBuffer.cpp @@ -57,7 +57,7 @@ static TBUFF_COLOR_IMAGE * AllocateTextureBuffer(COLOR_IMAGE & cimage) texbuf.height = cimage.height; texbuf.format = cimage.format; texbuf.size = cimage.size; - texbuf.scr_width = minval(cimage.width * rdp.scale_x, g_settings->scr_res_x); + texbuf.scr_width = minval(cimage.width * rdp.scale_x, g_settings->scr_res_x()); float height = minval(rdp.vi_height, cimage.height); if (cimage.status == ci_copy_self || (cimage.status == ci_copy && cimage.width == rdp.frame_buffers[rdp.main_ci_index].width)) height = rdp.vi_height; @@ -369,7 +369,7 @@ static GrTextureFormat_t TexBufSetupCombiner(int force_rgb = FALSE) GR_BLEND_ZERO, GR_BLEND_ONE, GR_BLEND_ZERO); - grClipWindow(0, 0, g_settings->scr_res_x, g_settings->scr_res_y); + grClipWindow(0, 0, g_settings->scr_res_x(), g_settings->scr_res_y()); grDepthBufferFunction(GR_CMP_ALWAYS); grDepthMask(FXFALSE); grCullMode(GR_CULL_DISABLE); @@ -457,7 +457,7 @@ int CloseTextureBuffer(int draw) }; grTexSource(rdp.tbuff_tex->tmu, rdp.tbuff_tex->tex_addr, GR_MIPMAPLEVELMASK_BOTH, &(rdp.tbuff_tex->info)); - grClipWindow(0, 0, g_settings->res_x, g_settings->res_y); + grClipWindow(0, 0, g_settings->res_x(), g_settings->res_y()); grDrawTriangle(&v[0], &v[2], &v[1]); grDrawTriangle(&v[2], &v[3], &v[1]); rdp.update |= UPDATE_ZBUF_ENABLED | UPDATE_COMBINE | UPDATE_TEXTURE | UPDATE_ALPHA_COMPARE; @@ -519,7 +519,7 @@ int CopyTextureBuffer(COLOR_IMAGE & fb_from, COLOR_IMAGE & fb_to) rdp.offset_y = rdp.offset_y_bak; rdp.offset_x_bak = rdp.offset_y_bak = 0; AddOffset(v, 4); - grClipWindow(0, 0, g_settings->res_x, g_settings->res_y); + grClipWindow(0, 0, g_settings->res_x(), g_settings->res_y()); grDrawTriangle(&v[0], &v[2], &v[1]); grDrawTriangle(&v[2], &v[3], &v[1]); rdp.tbuff_tex->info.format = buf_format; @@ -539,7 +539,7 @@ int CopyDepthBuffer() WriteTrace(TraceRDP, TraceDebug, "CopyDepthBuffer. "); float bound = 1024.0f; GrLOD_t LOD = GR_LOD_LOG2_1024; - if (g_settings->scr_res_x > 1024) + if (g_settings->scr_res_x() > 1024) { bound = 2048.0f; LOD = GR_LOD_LOG2_2048; diff --git a/Source/Glide64/Util.cpp b/Source/Glide64/Util.cpp index 0183aacf2..37b682317 100644 --- a/Source/Glide64/Util.cpp +++ b/Source/Glide64/Util.cpp @@ -1656,10 +1656,10 @@ void update_scissor() rdp.update ^= UPDATE_SCISSOR; // KILL the floating point error with 0.01f - rdp.scissor.ul_x = (uint32_t)maxval(minval((rdp.scissor_o.ul_x * rdp.scale_x + rdp.offset_x + 0.01f), g_settings->res_x), 0); - rdp.scissor.lr_x = (uint32_t)maxval(minval((rdp.scissor_o.lr_x * rdp.scale_x + rdp.offset_x + 0.01f), g_settings->res_x), 0); - rdp.scissor.ul_y = (uint32_t)maxval(minval((rdp.scissor_o.ul_y * rdp.scale_y + rdp.offset_y + 0.01f), g_settings->res_y), 0); - rdp.scissor.lr_y = (uint32_t)maxval(minval((rdp.scissor_o.lr_y * rdp.scale_y + rdp.offset_y + 0.01f), g_settings->res_y), 0); + rdp.scissor.ul_x = (uint32_t)maxval(minval((rdp.scissor_o.ul_x * rdp.scale_x + rdp.offset_x + 0.01f), g_settings->res_x()), 0); + rdp.scissor.lr_x = (uint32_t)maxval(minval((rdp.scissor_o.lr_x * rdp.scale_x + rdp.offset_x + 0.01f), g_settings->res_x()), 0); + rdp.scissor.ul_y = (uint32_t)maxval(minval((rdp.scissor_o.ul_y * rdp.scale_y + rdp.offset_y + 0.01f), g_settings->res_y()), 0); + rdp.scissor.lr_y = (uint32_t)maxval(minval((rdp.scissor_o.lr_y * rdp.scale_y + rdp.offset_y + 0.01f), g_settings->res_y()), 0); //grClipWindow specifies the hardware clipping window. Any pixels outside the clipping window are rejected. //Values are inclusive for minimum x and y values and exclusive for maximum x and y values. // grClipWindow (rdp.scissor.ul_x?rdp.scissor.ul_x+1:0, rdp.scissor.ul_y?rdp.scissor.ul_y+1:0, rdp.scissor.lr_x, rdp.scissor.lr_y); @@ -1971,8 +1971,8 @@ void update() rdp.clip_min_x = maxval((rdp.view_trans[0] - scale_x + rdp.offset_x) / rdp.clip_ratio, 0.0f); rdp.clip_min_y = maxval((rdp.view_trans[1] - scale_y + rdp.offset_y) / rdp.clip_ratio, 0.0f); - rdp.clip_max_x = minval((rdp.view_trans[0] + scale_x + rdp.offset_x) * rdp.clip_ratio, g_settings->res_x); - rdp.clip_max_y = minval((rdp.view_trans[1] + scale_y + rdp.offset_y) * rdp.clip_ratio, g_settings->res_y); + rdp.clip_max_x = minval((rdp.view_trans[0] + scale_x + rdp.offset_x) * rdp.clip_ratio, g_settings->res_x()); + rdp.clip_max_y = minval((rdp.view_trans[1] + scale_y + rdp.offset_y) * rdp.clip_ratio, g_settings->res_y()); WriteTrace(TraceRDP, TraceDebug, " |- viewport - (%d, %d, %d, %d)", (uint32_t)rdp.clip_min_x, (uint32_t)rdp.clip_min_y, (uint32_t)rdp.clip_max_x, (uint32_t)rdp.clip_max_y); if (!rdp.scissor_set) diff --git a/Source/Glide64/rdp.cpp b/Source/Glide64/rdp.cpp index 6ff0b2fde..44cc4e152 100644 --- a/Source/Glide64/rdp.cpp +++ b/Source/Glide64/rdp.cpp @@ -476,8 +476,8 @@ static void CopyFrameBuffer(GrBuffer_t buffer = GR_BUFFER_BACKBUFFER) } else { - float scale_x = (g_settings->scr_res_x - rdp.offset_x*2.0f) / maxval(width, rdp.vi_width); - float scale_y = (g_settings->scr_res_y - rdp.offset_y*2.0f) / maxval(height, rdp.vi_height); + float scale_x = (g_settings->scr_res_x() - rdp.offset_x*2.0f) / maxval(width, rdp.vi_width); + float scale_y = (g_settings->scr_res_y() - rdp.offset_y*2.0f) / maxval(height, rdp.vi_height); WriteTrace(TraceRDP, TraceDebug, "width: %d, height: %d, ul_y: %d, lr_y: %d, scale_x: %f, scale_y: %f, ci_width: %d, ci_height: %d", width, height, rdp.ci_upper_bound, rdp.ci_lower_bound, scale_x, scale_y, rdp.ci_width, rdp.ci_height); GrLfbInfo_t info; @@ -2299,8 +2299,8 @@ static void rdp_fillrect() if (s_lr_x < 0) s_lr_x = 0; if (s_lr_y < 0) s_lr_y = 0; - if ((uint32_t)s_ul_x > g_settings->res_x) s_ul_x = g_settings->res_x; - if ((uint32_t)s_ul_y > g_settings->res_y) s_ul_y = g_settings->res_y; + if ((uint32_t)s_ul_x > g_settings->res_x()) { s_ul_x = g_settings->res_x(); } + if ((uint32_t)s_ul_y > g_settings->res_y()) { s_ul_y = g_settings->res_y(); } WriteTrace(TraceRDP, TraceDebug, " - %d, %d, %d, %d", s_ul_x, s_ul_y, s_lr_x, s_lr_y); @@ -2741,7 +2741,7 @@ static void rdp_setcolorimage() { if (g_settings->fb_hwfbe_enabled() && !rdp.copy_ci_index && (rdp.copy_zi_index || g_settings->hacks(CSettings::hack_BAR))) { - GrLOD_t LOD = g_settings->scr_res_x > 1024 ? GR_LOD_LOG2_1024 : GR_LOD_LOG2_2048; + GrLOD_t LOD = g_settings->scr_res_x() > 1024 ? GR_LOD_LOG2_1024 : GR_LOD_LOG2_2048; grTextureAuxBufferExt(rdp.texbufs[0].tmu, rdp.texbufs[0].begin, LOD, LOD, GR_ASPECT_LOG2_1x1, GR_TEXFMT_RGB_565, GR_MIPMAPLEVELMASK_BOTH); grAuxBufferExt(GR_BUFFER_TEXTUREAUXBUFFER_EXT); diff --git a/Source/Glide64/ucode06.h b/Source/Glide64/ucode06.h index ea5991784..f446cd543 100644 --- a/Source/Glide64/ucode06.h +++ b/Source/Glide64/ucode06.h @@ -209,9 +209,7 @@ void DrawHiresDepthImage(const DRAWIMAGE & d) grDepthBufferFunction(GR_CMP_ALWAYS); grDepthMask(FXFALSE); - GrLOD_t LOD = GR_LOD_LOG2_1024; - if (g_settings->scr_res_x > 1024) - LOD = GR_LOD_LOG2_2048; + GrLOD_t LOD = g_settings->scr_res_x() > 1024 ? GR_LOD_LOG2_2048 : GR_LOD_LOG2_1024; float lr_x = (float)d.imageW * rdp.scale_x; float lr_y = (float)d.imageH * rdp.scale_y; @@ -262,8 +260,8 @@ void DrawDepthImage(const DRAWIMAGE & d) float scale_y_src = 1.0f / rdp.scale_y; int src_width = d.imageW; int src_height = d.imageH; - int dst_width = minval(int(src_width*scale_x_dst), (int)g_settings->scr_res_x); - int dst_height = minval(int(src_height*scale_y_dst), (int)g_settings->scr_res_y); + int dst_width = minval(int(src_width*scale_x_dst), (int)g_settings->scr_res_x()); + int dst_height = minval(int(src_height*scale_y_dst), (int)g_settings->scr_res_y()); uint16_t * src = (uint16_t*)(gfx.RDRAM + d.imagePtr); uint16_t * dst = new uint16_t[dst_width*dst_height]; for (int y = 0; y < dst_height; y++) @@ -447,7 +445,7 @@ void DrawImage(DRAWIMAGE & d) rdp.allow_combine = 0; if (rdp.ci_width == 512 && !no_dlist) - grClipWindow(0, 0, g_settings->scr_res_x, g_settings->scr_res_y); + grClipWindow(0, 0, g_settings->scr_res_x(), g_settings->scr_res_y()); else if (d.scaleX == 1.0f && d.scaleY == 1.0f) grClipWindow(rdp.scissor.ul_x, rdp.scissor.ul_y, rdp.scissor.lr_x, rdp.scissor.lr_y); else @@ -550,7 +548,6 @@ void DrawImage(DRAWIMAGE & d) ConvertCoordsConvert(v, 4); grDrawVertexArrayContiguous(GR_TRIANGLE_STRIP, 4, v, sizeof(VERTEX)); - rdp.tri_n += 2; } else @@ -600,7 +597,7 @@ void DrawHiresImage(DRAWIMAGE & d, int screensize = FALSE) setTBufTex(rdp.tbuff_tex->t_mem, rdp.tbuff_tex->width << rdp.tbuff_tex->size >> 1); const float Z = set_sprite_combine_mode(); - grClipWindow(0, 0, g_settings->res_x, g_settings->res_y); + grClipWindow(0, 0, g_settings->res_x(), g_settings->res_y()); if (d.imageW % 2 == 1) d.imageW -= 1; if (d.imageH % 2 == 1) d.imageH -= 1;