From 952b46f2c18859973e78bca102d864d02b69cbd5 Mon Sep 17 00:00:00 2001 From: alphanu1 <37101891+alphanu1@users.noreply.github.com> Date: Sat, 8 Sep 2018 22:09:30 +0100 Subject: [PATCH 1/2] Fix for crt interlaced bug --- gfx/video_driver.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 37efe7b01a..fad1e5b3a5 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -3232,14 +3232,26 @@ bool video_context_driver_get_metrics(gfx_ctx_metrics_t *metrics) bool video_context_driver_get_refresh_rate(float *refresh_rate) { + float refresh_holder = 0; + if (!current_video_context.get_refresh_rate || !refresh_rate) return false; if (!video_context_data) return false; - - if (refresh_rate) - *refresh_rate = - current_video_context.get_refresh_rate(video_context_data); + + if (!video_driver_crt_switching_active) + if (refresh_rate) + *refresh_rate = + current_video_context.get_refresh_rate(video_context_data); + + if (video_driver_crt_switching_active) + { + if (refresh_rate) + refresh_holder = + current_video_context.get_refresh_rate(video_context_data); + if (refresh_holder != video_driver_core_hz) /* Fix for incorrect interlace detsction -- HARD SET VSNC TO REQUIRED REFRESH FOR CRT*/ + *refresh_rate = video_driver_core_hz; + } return true; } From 5c6fc6db7e7fa61ce82ca0afc928b0b5a6914f69 Mon Sep 17 00:00:00 2001 From: alphanu1 <37101891+alphanu1@users.noreply.github.com> Date: Sat, 8 Sep 2018 22:11:31 +0100 Subject: [PATCH 2/2] New Porch Calc, Matched against an oscilloscope --- gfx/display_servers/dispserv_x11.c | 104 +++++++++++++++++++---------- 1 file changed, 67 insertions(+), 37 deletions(-) diff --git a/gfx/display_servers/dispserv_x11.c b/gfx/display_servers/dispserv_x11.c index dbc22ece98..9506dc8d07 100644 --- a/gfx/display_servers/dispserv_x11.c +++ b/gfx/display_servers/dispserv_x11.c @@ -23,8 +23,13 @@ #include "../video_driver.h" /* needed to set refresh rate in set resolution */ #include "../video_crt_switch.h" /* needed to set aspect for low res in linux */ +static unsigned orig_width = 0; +static unsigned orig_height = 0; static char old_mode[150]; static char new_mode[150]; +static char xrandr[250]; +static char fbset[150]; +static char output[250]; static bool crt_en = false; typedef struct @@ -45,10 +50,28 @@ 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) - system("xrandr -s 704x480"); + { + 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) free(dispserv); @@ -95,22 +118,41 @@ static bool x11_set_resolution(void *data, int vbp = 0; int hmax = 0; int vmax = 0; + int pdefault = 8; + int pwidth = 0; + float roundw = 0.0f; + float roundh = 0.0f; float pixel_clock = 0; - char xrandr[250]; - char fbset[150]; - char output[250]; crt_en = true; - - hsp = width*1.16; /* set core refresh from hz */ video_monitor_set_refresh_rate(hz); - /* following code is the mode line genorator */ + /* following code is the mode line genorator */ - hfp = width+8; - hbp = width*1.32; + hsp = width*1.145; + hfp = width*1.025; + + pwidth = width; + + if (height < 400 && width > 400 ) + pwidth = width/2; + + + roundw = roundf((float)pwidth/(float)height * 100)/100; + + if (height > width ) { + roundw = roundf((float)height/(float)width * 100)/100; + } + + if (roundw > 1.35) + roundw = 1.25; + + if (roundw < 1.20) + roundw = 1.34; + + hbp = width*roundw-8; hmax = hbp; if (height < 241) @@ -133,22 +175,18 @@ static bool x11_set_resolution(void *data, { vmax = 285; } - if (height > 240 && height < 260 && hz < 52) - { - vmax = 265; - } if (height > 250 && height < 260 && hz < 52) { vmax = 313; } if (height > 260 && height < 300) { - vmax = 313; + vmax = 318; } if (height > 400 && hz > 56) { - vmax = 523; + vmax = 533; } if (height > 520 && hz < 57) { @@ -157,35 +195,27 @@ static bool x11_set_resolution(void *data, if (height > 300 && hz < 56) { - vmax = 627; + vmax = 615; } - - if (hz < 53) - { - vfp = height+((vmax-height)*0.38); + if (height > 500 && hz < 56) + { + vmax = 624; } - if (hz > 56) - { - vfp = height+((vmax-height)*0.15); - } - if (hz > 53 && hz < 56) - { - vfp = height+((vmax-height)*0.35); + if (height > 300) + { + pdefault = pdefault*2; } - - if ( vfp < 1 ) - { - vfp = height+2; - - } + + vfp = height+((vmax-height)/2)-pdefault; if (height < 300) { vsp = vfp+3; /* needs to me 3 for progressive */ - } if (height > 300) + } + if (height > 300) { - vsp = vfp+6; /* needs to me 6 for interlaced */ + vsp = vfp+6; /* needs to me 6 for interlaced */ } vbp = vmax;