diff --git a/gfx/display_servers/dispserv_win32.c b/gfx/display_servers/dispserv_win32.c
index 35d0ed367e..54c3a79d02 100644
--- a/gfx/display_servers/dispserv_win32.c
+++ b/gfx/display_servers/dispserv_win32.c
@@ -59,12 +59,12 @@ typedef struct
} dispserv_win32_t;
/*
-NOTE: When an application displays a window, its taskbar button is created
-by the system. When the button is in place, the taskbar sends a
-TaskbarButtonCreated message to the window. Its value is computed by
-calling RegisterWindowMessage(L("TaskbarButtonCreated")). That message must
-be received by your application before it calls any ITaskbarList3 method.
-*/
+ NOTE: When an application displays a window, its taskbar button is created
+ by the system. When the button is in place, the taskbar sends a
+ TaskbarButtonCreated message to the window. Its value is computed by
+ calling RegisterWindowMessage(L("TaskbarButtonCreated")). That message must
+ be received by your application before it calls any ITaskbarList3 method.
+ */
static unsigned win32_orig_width = 0;
static unsigned win32_orig_height = 0;
@@ -105,10 +105,10 @@ static void* win32_display_server_init(void)
static void win32_display_server_destroy(void *data)
{
dispserv_win32_t *dispserv = (dispserv_win32_t*)data;
-
- if (win32_orig_width > 0 && win32_orig_height > 0 )
+
+ if (win32_orig_width > 0 && win32_orig_height > 0)
video_display_server_switch_resolution(win32_orig_width, win32_orig_height,
- win32_orig_refresh , (float)win32_orig_refresh, crt_center );
+ win32_orig_refresh, (float)win32_orig_refresh, crt_center );
#ifdef HAS_TASKBAR_EXT
if (g_taskbarList && win32_taskbar_is_created())
@@ -124,7 +124,7 @@ static void win32_display_server_destroy(void *data)
static bool win32_display_server_set_window_opacity(void *data, unsigned opacity)
{
- HWND hwnd = win32_get_window();
+ HWND hwnd = win32_get_window();
dispserv_win32_t *serv = (dispserv_win32_t*)data;
if (serv)
@@ -132,11 +132,11 @@ static bool win32_display_server_set_window_opacity(void *data, unsigned opacity
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* Set window transparency on Windows 2000 and above */
- if(opacity < 100)
+ if (opacity < 100)
{
SetWindowLongPtr(hwnd,
- GWL_EXSTYLE,
- GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
+ GWL_EXSTYLE,
+ GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
return SetLayeredWindowAttributes(hwnd, 0, (255 * opacity) / 100, LWA_ALPHA);
}
@@ -151,7 +151,7 @@ static bool win32_display_server_set_window_opacity(void *data, unsigned opacity
static bool win32_display_server_set_window_progress(void *data, int progress, bool finished)
{
- HWND hwnd = win32_get_window();
+ HWND hwnd = win32_get_window();
dispserv_win32_t *serv = (dispserv_win32_t*)data;
if (serv)
@@ -164,23 +164,23 @@ static bool win32_display_server_set_window_progress(void *data, int progress, b
if (progress == -1)
{
if (ITaskbarList3_SetProgressState(
- g_taskbarList, hwnd, TBPF_INDETERMINATE) != S_OK)
+ g_taskbarList, hwnd, TBPF_INDETERMINATE) != S_OK)
return false;
}
else if (finished)
{
if (ITaskbarList3_SetProgressState(
- g_taskbarList, hwnd, TBPF_NOPROGRESS) != S_OK)
+ g_taskbarList, hwnd, TBPF_NOPROGRESS) != S_OK)
return false;
}
else if (progress >= 0)
{
if (ITaskbarList3_SetProgressState(
- g_taskbarList, hwnd, TBPF_NORMAL) != S_OK)
+ g_taskbarList, hwnd, TBPF_NORMAL) != S_OK)
return false;
if (ITaskbarList3_SetProgressValue(
- g_taskbarList, hwnd, progress, 100) != S_OK)
+ g_taskbarList, hwnd, progress, 100) != S_OK)
return false;
}
#endif
@@ -195,7 +195,7 @@ static bool win32_display_server_set_window_decorations(void *data, bool on)
if (serv)
serv->decorations = on;
- /* menu_setting performs a reinit instead to properly
+ /* menu_setting performs a reinit instead to properly
* apply decoration changes */
return true;
@@ -216,74 +216,73 @@ static bool win32_display_server_set_resolution(void *data,
if (!serv)
return false;
-
+
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &curDevmode);
-
+
if (win32_orig_width == 0)
- win32_orig_width = GetSystemMetrics(SM_CXSCREEN);
- win32_orig_refresh = curDevmode.dmDisplayFrequency;
+ win32_orig_width = GetSystemMetrics(SM_CXSCREEN);
+ win32_orig_refresh = curDevmode.dmDisplayFrequency;
if (win32_orig_height == 0)
- win32_orig_height = GetSystemMetrics(SM_CYSCREEN);
+ win32_orig_height = GetSystemMetrics(SM_CYSCREEN);
/* Used to stop super resolution bug */
if (width == curDevmode.dmPelsWidth)
- width = 0;
- if (width == 0)
+ width = 0;
+ if (width == 0)
width = curDevmode.dmPelsWidth;
- if (height == 0)
+ if (height == 0)
height = curDevmode.dmPelsHeight;
- if (depth == 0)
+ if (depth == 0)
depth = curDevmode.dmBitsPerPel;
- if (freq == 0)
+ if (freq == 0)
freq = curDevmode.dmDisplayFrequency;
- for (iModeNum = 0; ; iModeNum++)
+ for (iModeNum = 0;; iModeNum++)
{
- if (!EnumDisplaySettings(NULL, iModeNum, &devmode))
+ if (!EnumDisplaySettings(NULL, iModeNum, &devmode))
break;
- if (devmode.dmPelsWidth != width)
+ if (devmode.dmPelsWidth != width)
continue;
- if (devmode.dmPelsHeight != height)
+ if (devmode.dmPelsHeight != height)
continue;
- if (devmode.dmBitsPerPel != depth)
+ if (devmode.dmBitsPerPel != depth)
continue;
- if (devmode.dmDisplayFrequency != freq)
+ if (devmode.dmDisplayFrequency != freq)
continue;
- devmode.dmFields |=
- DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
- res =
- win32_change_display_settings(NULL, &devmode, CDS_TEST);
+ devmode.dmFields |=
+ DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
+ res =
+ win32_change_display_settings(NULL, &devmode, CDS_TEST);
- switch (res)
+ switch (res)
{
+ case DISP_CHANGE_SUCCESSFUL:
+ res = win32_change_display_settings(NULL, &devmode, flags);
+ switch (res)
+ {
case DISP_CHANGE_SUCCESSFUL:
- res = win32_change_display_settings(NULL, &devmode, flags);
- switch (res)
- {
- case DISP_CHANGE_SUCCESSFUL:
- return true;
- case DISP_CHANGE_NOTUPDATED:
- return true;
- default:
- break;
- }
- break;
- case DISP_CHANGE_RESTART:
- break;
+ return true;
+ case DISP_CHANGE_NOTUPDATED:
+ return true;
default:
break;
+ }
+ break;
+ case DISP_CHANGE_RESTART:
+ break;
+ default:
+ break;
}
}
return true;
}
-
const video_display_server_t dispserv_win32 = {
win32_display_server_init,
win32_display_server_destroy,
@@ -294,4 +293,3 @@ const video_display_server_t dispserv_win32 = {
NULL, /* get_output_options */
"win32"
};
-
diff --git a/gfx/display_servers/dispserv_x11.c b/gfx/display_servers/dispserv_x11.c
index 3a93980bea..f4f6f16f7a 100644
--- a/gfx/display_servers/dispserv_x11.c
+++ b/gfx/display_servers/dispserv_x11.c
@@ -50,28 +50,29 @@ static void* x11_display_server_init(void)
static void x11_display_server_destroy(void *data)
{
- dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
+ dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
int i = 0;
- if (crt_en == true)
- {
- sprintf(output,"xrandr -s %dx%d", orig_width, orig_height);
- system(output);
-
- for (i =0; i < 3; i++)
- {
- sprintf(output,"xrandr --delmode %s%d %s", "VGA",i ,old_mode);
- system(output);
- sprintf(output,"xrandr --delmode %s-%d %s", "VGA",i ,old_mode);
- system(output);
- sprintf(output,"xrandr --delmode %s%d %s", "DVI",i ,old_mode);
- system(output);
- sprintf(output,"xrandr --delmode %s-%d %s", "DVI",i ,old_mode);
- system(output);
- }
-
- sprintf(output,"xrandr --rmmode %s", old_mode);
- system(output);
+ if (crt_en)
+ {
+ sprintf(output, "xrandr -s %dx%d", orig_width, orig_height);
+ system(output);
+
+ for (i = 0; i < 3; i++)
+ {
+ sprintf(output, "xrandr --delmode %s%d %s", "VGA", i, old_mode);
+ system(output);
+ sprintf(output, "xrandr --delmode %s-%d %s", "VGA", i, old_mode);
+ system(output);
+
+ sprintf(output, "xrandr --delmode %s%d %s", "DVI", i, old_mode);
+ system(output);
+ sprintf(output, "xrandr --delmode %s-%d %s", "DVI", i, old_mode);
+ system(output);
+ }
+
+ sprintf(output, "xrandr --rmmode %s", old_mode);
+ system(output);
}
if (dispserv)
@@ -90,7 +91,7 @@ static bool x11_display_server_set_window_opacity(void *data, unsigned opacity)
if (opacity == (unsigned)-1)
XDeleteProperty(g_x11_dpy, g_x11_win, net_wm_opacity);
- else
+ else
XChangeProperty(g_x11_dpy, g_x11_win, net_wm_opacity, cardinal, 32, PropModeReplace, (const unsigned char*)&opacity, 1);
return true;
@@ -126,62 +127,62 @@ static bool x11_display_server_set_resolution(void *data,
float pixel_clock = 0;
crt_en = true;
-
- /* set core refresh from hz */
- video_monitor_set_refresh_rate(hz);
-
- /* following code is the mode line genorator */
- hsp = width*1.140;
- hfp = width*1.055;
+ /* set core refresh from hz */
+ video_monitor_set_refresh_rate(hz);
+
+ /* following code is the mode line genorator */
+
+ hsp = width * 1.140;
+ hfp = width * 1.055;
pwidth = width;
- if (height < 400 && width > 400 )
- pwidth = width/2;
-
+ if (height < 400 && width > 400)
+ pwidth = width / 2;
- roundw = roundf((float)pwidth/(float)height * 100)/100;
+ roundw = roundf((float)pwidth / (float)height * 100) / 100;
- if (height > width ) {
- roundw = roundf((float)height/(float)width * 100)/100;
+ if (height > width)
+ {
+ roundw = roundf((float)height / (float)width * 100) / 100;
}
if (roundw > 1.35)
roundw = 1.25;
- if (roundw < 1.20)
+ if (roundw < 1.20)
roundw = 1.34;
- hbp = width*roundw-8;
+ hbp = width * roundw - 8;
hmax = hbp;
-
+
if (height < 241)
- {
+ {
vmax = 261;
}
if (height < 241 && hz > 56 && hz < 58)
- {
+ {
vmax = 280;
}
- if (height < 241 && hz < 55)
- {
+ if (height < 241 && hz < 55)
+ {
vmax = 313;
}
if (height > 250 && height < 260 && hz > 54)
- {
+ {
vmax = 296;
}
if (height > 250 && height < 260 && hz > 52 && hz < 54)
- {
+ {
vmax = 285;
}
if (height > 250 && height < 260 && hz < 52)
- {
+ {
vmax = 313;
}
if (height > 260 && height < 300)
- {
+ {
vmax = 318;
}
@@ -202,33 +203,32 @@ static bool x11_display_server_set_resolution(void *data,
{
vmax = 624;
}
- if (height > 300)
+ if (height > 300)
{
- pdefault = pdefault*2;
+ pdefault = pdefault * 2;
}
-
- vfp = height+((vmax-height)/2)-pdefault;
+ vfp = height + ((vmax - height) / 2) - pdefault;
if (height < 300)
{
- vsp = vfp+3; /* needs to me 3 for progressive */
- }
+ vsp = vfp + 3; /* needs to me 3 for progressive */
+ }
if (height > 300)
{
- vsp = vfp+6; /* needs to me 6 for interlaced */
+ vsp = vfp + 6; /* needs to me 6 for interlaced */
}
-
+
vbp = vmax;
if (height < 300)
{
- pixel_clock = (hmax*vmax*hz)/1000000;
+ pixel_clock = (hmax * vmax * hz) / 1000000;
}
-
+
if (height > 300)
{
- pixel_clock = ((hmax*vmax*hz)/1000000)/2;
+ pixel_clock = ((hmax * vmax * hz) / 1000000) / 2;
}
/* above code is the modeline genorator */
@@ -237,60 +237,63 @@ static bool x11_display_server_set_resolution(void *data,
{
snprintf(xrandr, sizeof(xrandr), "xrandr --newmode \"%dx%d_%0.2f\" %lf %d %d %d %d %d %d %d %d -hsync -vsync", width, height, hz, pixel_clock, width, hfp, hsp, hbp, height, vfp, vsp, vbp);
system(xrandr);
-
}
/* create interlaced newmode from modline variables */
if (height > 300)
- {
+ {
snprintf(xrandr, sizeof(xrandr), "xrandr --newmode \"%dx%d_%0.2f\" %lf %d %d %d %d %d %d %d %d interlace -hsync -vsync", width, height, hz, pixel_clock, width, hfp, hsp, hbp, height, vfp, vsp, vbp);
system(xrandr);
-
}
- /* variable for new mode */
- snprintf(new_mode, sizeof(new_mode), "%dx%d_%0.2f", width, height, hz);
- /* need to run loops for DVI0 - DVI-2 and VGA0 - VGA-2 outputs to add and delete modes */
- for (i =0; i < 3; i++)
- {
- snprintf(output, sizeof(output), "xrandr --addmode %s%d %s", "DVI",i ,new_mode);
- system(output);
- snprintf(output, sizeof(output), "xrandr --delmode %s%d %s", "DVI",i ,old_mode);
- system(output);
- }
- for (i =0; i < 3; i++)
- {
- snprintf(output, sizeof(output), "xrandr --addmode %s-%d %s", "DVI",i ,new_mode);
- system(output);
- snprintf(output, sizeof(output), "xrandr --delmode %s-%d %s", "DVI",i ,old_mode);
- system(output);
- }
- for (i =0; i < 3; i++)
- {
- snprintf(output, sizeof(output), "xrandr --addmode %s%d %s", "VGA",i ,new_mode);
- system(output);
- snprintf(output, sizeof(output), "xrandr --delmode %s%d %s", "VGA",i ,old_mode);
- system(output);
- }
- for (i =0; i < 3; i++)
- {
- snprintf(output, sizeof(output), "xrandr --addmode %s-%d %s", "VGA",i ,new_mode);
- system(output);
- snprintf(output, sizeof(output), "xrandr --delmode %s-%d %s", "VGA",i ,old_mode);
- system(output);
- }
-
- snprintf(output, sizeof(output), "xrandr -s %s", new_mode);
+ /* variable for new mode */
+ snprintf(new_mode, sizeof(new_mode), "%dx%d_%0.2f", width, height, hz);
+
+ /* need to run loops for DVI0 - DVI-2 and VGA0 - VGA-2 outputs to add and delete modes */
+ for (i = 0; i < 3; i++)
+ {
+ snprintf(output, sizeof(output), "xrandr --addmode %s%d %s", "DVI", i, new_mode);
system(output);
- /* remove old mode */
- snprintf(output, sizeof(output), "xrandr --rmmode %s", old_mode);
- system(output);
- system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recaputure window. */
- /* variable for old mode */
- snprintf(old_mode, sizeof(old_mode), "%s", new_mode);
- system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recaputure window. */
- /* Second run needed as some times it runs to fast to capture first time */
+ snprintf(output, sizeof(output), "xrandr --delmode %s%d %s", "DVI", i, old_mode);
+ system(output);
+ }
+ for (i = 0; i < 3; i++)
+ {
+ snprintf(output, sizeof(output), "xrandr --addmode %s-%d %s", "DVI", i, new_mode);
+ system(output);
+ snprintf(output, sizeof(output), "xrandr --delmode %s-%d %s", "DVI", i, old_mode);
+ system(output);
+ }
+ for (i = 0; i < 3; i++)
+ {
+ snprintf(output, sizeof(output), "xrandr --addmode %s%d %s", "VGA", i, new_mode);
+ system(output);
+ snprintf(output, sizeof(output), "xrandr --delmode %s%d %s", "VGA", i, old_mode);
+ system(output);
+ }
+ for (i = 0; i < 3; i++)
+ {
+ snprintf(output, sizeof(output), "xrandr --addmode %s-%d %s", "VGA", i, new_mode);
+ system(output);
+ snprintf(output, sizeof(output), "xrandr --delmode %s-%d %s", "VGA", i, old_mode);
+ system(output);
+ }
- return true;
+ snprintf(output, sizeof(output), "xrandr -s %s", new_mode);
+ system(output);
+
+ /* remove old mode */
+ snprintf(output, sizeof(output), "xrandr --rmmode %s", old_mode);
+ system(output);
+
+ system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recapture window. */
+
+ /* variable for old mode */
+ snprintf(old_mode, sizeof(old_mode), "%s", new_mode);
+
+ system("xdotool windowactivate $(xdotool search --class RetroArch)"); /* needs xdotool installed. needed to recapture window. */
+ /* Second run needed as some times it runs to fast to capture first time */
+
+ return true;
}
const char *x11_display_server_get_output_options(void)
@@ -309,4 +312,3 @@ const video_display_server_t dispserv_x11 = {
x11_display_server_get_output_options,
"x11"
};
-
diff --git a/gfx/video_crt_switch.c b/gfx/video_crt_switch.c
index a96218544b..282d2aea39 100644
--- a/gfx/video_crt_switch.c
+++ b/gfx/video_crt_switch.c
@@ -1,210 +1,206 @@
-/* CRT SwitchRes Core
- * Copyright (C) 2018 Alphanu / Ben Templeman.
- *
- * RetroArch - A frontend for libretro.
- * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- * Copyright (C) 2011-2017 - Daniel De Matteis
- *
- * RetroArch is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with RetroArch.
- * If not, see .
-*/
-#include
-#include
-#include
-
-#include "video_driver.h"
-#include "video_crt_switch.h"
-#include "video_display_server.h"
-
-static unsigned ra_core_width = 0;
-static unsigned ra_core_height = 0;
-static unsigned ra_tmp_width = 0;
-static unsigned ra_tmp_height = 0;
-static unsigned ra_set_core_hz = 0;
-static unsigned orig_width = 0;
-static unsigned orig_height = 0;
-static int crt_center_adjust = 0;
-
-static bool first_run = true;
-
-static float ra_tmp_core_hz = 0.0f;
-static float fly_aspect = 0.0f;
-static float ra_core_hz = 0.0f;
-
-static void crt_check_first_run(void)
-{
- if (!first_run)
- return;
-
-
-
- first_run = false;
-}
-
-static void switch_crt_hz(void)
-{
- if (ra_core_hz == ra_tmp_core_hz)
- return;
- /* set hz float to an int for windows switching */
- if (ra_core_hz < 100)
- {
- if (ra_core_hz < 53)
- ra_set_core_hz = 50;
- if (ra_core_hz >= 53 && ra_core_hz < 57)
- ra_set_core_hz = 55;
- if (ra_core_hz >= 57)
- ra_set_core_hz = 60;
- }
-
- if (ra_core_hz > 100)
- {
- if (ra_core_hz < 106)
- ra_set_core_hz = 120;
- if (ra_core_hz >= 106 && ra_core_hz < 114)
- ra_set_core_hz = 110;
- if (ra_core_hz >= 114)
- ra_set_core_hz = 120;
- }
-
- video_monitor_set_refresh_rate(ra_set_core_hz);
-
- ra_tmp_core_hz = ra_core_hz;
-}
-
-
-void crt_aspect_ratio_switch(unsigned width, unsigned height)
-{
- /* send aspect float to videeo_driver */
- fly_aspect = (float)width / height;
- video_driver_set_aspect_ratio_value((float)fly_aspect);
-}
-
-static void switch_res_crt(unsigned width, unsigned height)
-{
- if (height > 100)
- {
- video_display_server_switch_resolution(width, height,
- ra_set_core_hz, ra_core_hz, crt_center_adjust);
- video_driver_apply_state_changes();
- }
-}
-
-/* Create correct aspect to fit video if resolution does not exist */
-static void crt_screen_setup_aspect(unsigned width, unsigned height)
-{
-
- switch_crt_hz();
- /* get original resolution of core */
- if (height == 4)
- {
- /* detect menu only */
- if (width < 1920)
- width = 320;
-
- height = 240;
-
- crt_aspect_ratio_switch(width, height);
- }
-
- if (height < 200 && height != 144)
- {
- crt_aspect_ratio_switch(width, height);
- height = 200;
- }
-
- if (height > 200)
- crt_aspect_ratio_switch(width, height);
-
- if (height == 144 && ra_set_core_hz == 50)
- {
- height = 288;
- crt_aspect_ratio_switch(width, height);
- }
-
- if (height > 200 && height < 224)
- {
- crt_aspect_ratio_switch(width, height);
- height = 224;
- }
-
- if (height > 224 && height < 240)
- {
- crt_aspect_ratio_switch(width, height);
- height = 240;
- }
-
- if (height > 240 && height < 255)
- {
- crt_aspect_ratio_switch(width, height);
- height = 254;
- }
-
- if (height == 528 && ra_set_core_hz == 60)
- {
- crt_aspect_ratio_switch(width, height);
- height = 480;
- }
-
- if (height >= 240 && height < 255 && ra_set_core_hz == 55)
- {
- crt_aspect_ratio_switch(width, height);
- height = 254;
- }
-
- switch_res_crt(width, height);
-}
-
-
-void crt_switch_res_core(unsigned width, unsigned height, float hz, unsigned crt_mode, int crt_switch_center_adjust)
-{
- /* ra_core_hz float passed from within
- * void video_driver_monitor_adjust_system_rates(void) */
- ra_core_width = width;
- ra_core_height = height;
- ra_core_hz = hz;
- crt_center_adjust = crt_switch_center_adjust;
-
- if (crt_mode == 2)
- {
- if (hz > 53)
- ra_core_hz = hz*2;
-
- if (hz <= 53)
- ra_core_hz = 120.0f;
- }
-
- crt_check_first_run();
-
- /* Detect resolution change and switch */
- if (
- (ra_tmp_height != ra_core_height) ||
- (ra_core_width != ra_tmp_width)
- )
- crt_screen_setup_aspect(width, height);
-
- ra_tmp_height = ra_core_height;
- ra_tmp_width = ra_core_width;
-
- /* Check if aspect is correct, if notchange */
- if (video_driver_get_aspect_ratio() != fly_aspect)
- {
- video_driver_set_aspect_ratio_value((float)fly_aspect);
- video_driver_apply_state_changes();
- }
-}
-
-void crt_video_restore(void)
-{
- if (first_run)
- return;
-
- first_run = true;
-}
+/* CRT SwitchRes Core
+ * Copyright (C) 2018 Alphanu / Ben Templeman.
+ *
+ * RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2017 - Daniel De Matteis
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+#include
+#include
+#include
+
+#include "video_driver.h"
+#include "video_crt_switch.h"
+#include "video_display_server.h"
+
+static unsigned ra_core_width = 0;
+static unsigned ra_core_height = 0;
+static unsigned ra_tmp_width = 0;
+static unsigned ra_tmp_height = 0;
+static unsigned ra_set_core_hz = 0;
+static unsigned orig_width = 0;
+static unsigned orig_height = 0;
+static int crt_center_adjust = 0;
+
+static bool first_run = true;
+
+static float ra_tmp_core_hz = 0.0f;
+static float fly_aspect = 0.0f;
+static float ra_core_hz = 0.0f;
+
+static void crt_check_first_run(void)
+{
+ if (!first_run)
+ return;
+
+ first_run = false;
+}
+
+static void switch_crt_hz(void)
+{
+ if (ra_core_hz == ra_tmp_core_hz)
+ return;
+ /* set hz float to an int for windows switching */
+ if (ra_core_hz < 100)
+ {
+ if (ra_core_hz < 53)
+ ra_set_core_hz = 50;
+ if (ra_core_hz >= 53 && ra_core_hz < 57)
+ ra_set_core_hz = 55;
+ if (ra_core_hz >= 57)
+ ra_set_core_hz = 60;
+ }
+
+ if (ra_core_hz > 100)
+ {
+ if (ra_core_hz < 106)
+ ra_set_core_hz = 120;
+ if (ra_core_hz >= 106 && ra_core_hz < 114)
+ ra_set_core_hz = 110;
+ if (ra_core_hz >= 114)
+ ra_set_core_hz = 120;
+ }
+
+ video_monitor_set_refresh_rate(ra_set_core_hz);
+
+ ra_tmp_core_hz = ra_core_hz;
+}
+
+void crt_aspect_ratio_switch(unsigned width, unsigned height)
+{
+ /* send aspect float to videeo_driver */
+ fly_aspect = (float)width / height;
+ video_driver_set_aspect_ratio_value((float)fly_aspect);
+}
+
+static void switch_res_crt(unsigned width, unsigned height)
+{
+ if (height > 100)
+ {
+ video_display_server_switch_resolution(width, height,
+ ra_set_core_hz, ra_core_hz, crt_center_adjust);
+ video_driver_apply_state_changes();
+ }
+}
+
+/* Create correct aspect to fit video if resolution does not exist */
+static void crt_screen_setup_aspect(unsigned width, unsigned height)
+{
+
+ switch_crt_hz();
+ /* get original resolution of core */
+ if (height == 4)
+ {
+ /* detect menu only */
+ if (width < 1920)
+ width = 320;
+
+ height = 240;
+
+ crt_aspect_ratio_switch(width, height);
+ }
+
+ if (height < 200 && height != 144)
+ {
+ crt_aspect_ratio_switch(width, height);
+ height = 200;
+ }
+
+ if (height > 200)
+ crt_aspect_ratio_switch(width, height);
+
+ if (height == 144 && ra_set_core_hz == 50)
+ {
+ height = 288;
+ crt_aspect_ratio_switch(width, height);
+ }
+
+ if (height > 200 && height < 224)
+ {
+ crt_aspect_ratio_switch(width, height);
+ height = 224;
+ }
+
+ if (height > 224 && height < 240)
+ {
+ crt_aspect_ratio_switch(width, height);
+ height = 240;
+ }
+
+ if (height > 240 && height < 255)
+ {
+ crt_aspect_ratio_switch(width, height);
+ height = 254;
+ }
+
+ if (height == 528 && ra_set_core_hz == 60)
+ {
+ crt_aspect_ratio_switch(width, height);
+ height = 480;
+ }
+
+ if (height >= 240 && height < 255 && ra_set_core_hz == 55)
+ {
+ crt_aspect_ratio_switch(width, height);
+ height = 254;
+ }
+
+ switch_res_crt(width, height);
+}
+
+void crt_switch_res_core(unsigned width, unsigned height, float hz, unsigned crt_mode, int crt_switch_center_adjust)
+{
+ /* ra_core_hz float passed from within
+ * void video_driver_monitor_adjust_system_rates(void) */
+ ra_core_width = width;
+ ra_core_height = height;
+ ra_core_hz = hz;
+ crt_center_adjust = crt_switch_center_adjust;
+
+ if (crt_mode == 2)
+ {
+ if (hz > 53)
+ ra_core_hz = hz * 2;
+
+ if (hz <= 53)
+ ra_core_hz = 120.0f;
+ }
+
+ crt_check_first_run();
+
+ /* Detect resolution change and switch */
+ if (
+ (ra_tmp_height != ra_core_height) ||
+ (ra_core_width != ra_tmp_width)
+ )
+ crt_screen_setup_aspect(width, height);
+
+ ra_tmp_height = ra_core_height;
+ ra_tmp_width = ra_core_width;
+
+ /* Check if aspect is correct, if notchange */
+ if (video_driver_get_aspect_ratio() != fly_aspect)
+ {
+ video_driver_set_aspect_ratio_value((float)fly_aspect);
+ video_driver_apply_state_changes();
+ }
+}
+
+void crt_video_restore(void)
+{
+ if (first_run)
+ return;
+
+ first_run = true;
+}
diff --git a/gfx/video_crt_switch.h b/gfx/video_crt_switch.h
index d23c4c3059..98cfd4150b 100644
--- a/gfx/video_crt_switch.h
+++ b/gfx/video_crt_switch.h
@@ -1,38 +1,38 @@
-/* CRT SwitchRes Core
- * Copyright (C) 2018 Alphanu / Ben Templeman.
- *
- * RetroArch - A frontend for libretro.
- * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- * Copyright (C) 2011-2017 - Daniel De Matteis
- *
- * RetroArch is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with RetroArch.
- * If not, see .
-*/
-
-#ifndef __VIDEO_CRT_SWITCH_H__
-#define __VIDEO_CRT_SWITCH_H__
-
-#include
-
-#include
-#include
-
-RETRO_BEGIN_DECLS
-
-void crt_switch_res_core(unsigned width, unsigned height, float hz, unsigned crt_mode, int crt_switch_center_adjust);
-
-void crt_aspect_ratio_switch(unsigned width, unsigned height);
-
-void crt_video_restore(void);
-
-RETRO_END_DECLS
-
-#endif
+/* CRT SwitchRes Core
+ * Copyright (C) 2018 Alphanu / Ben Templeman.
+ *
+ * RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2017 - Daniel De Matteis
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#ifndef __VIDEO_CRT_SWITCH_H__
+#define __VIDEO_CRT_SWITCH_H__
+
+#include
+
+#include
+#include
+
+RETRO_BEGIN_DECLS
+
+void crt_switch_res_core(unsigned width, unsigned height, float hz, unsigned crt_mode, int crt_switch_center_adjust);
+
+void crt_aspect_ratio_switch(unsigned width, unsigned height);
+
+void crt_video_restore(void);
+
+RETRO_END_DECLS
+
+#endif