(video_crt_switch.c) C89 build fixes

This commit is contained in:
libretroadmin 2023-07-16 20:50:35 +02:00
parent eb01ce0c09
commit 07f22270f7
1 changed files with 45 additions and 67 deletions

View File

@ -57,12 +57,12 @@ static void crt_rpi_switch(videocrt_switch_t *p_switch,int width, int height, fl
static bool crt_check_for_changes(videocrt_switch_t *p_switch) static bool crt_check_for_changes(videocrt_switch_t *p_switch)
{ {
if ((p_switch->ra_core_height != p_switch->ra_tmp_height) || if ( (p_switch->ra_core_height != p_switch->ra_tmp_height)
(p_switch->ra_core_width != p_switch->ra_tmp_width) || || (p_switch->ra_core_width != p_switch->ra_tmp_width)
(p_switch->center_adjust != p_switch->tmp_center_adjust|| || (p_switch->center_adjust != p_switch->tmp_center_adjust
p_switch->porch_adjust != p_switch->tmp_porch_adjust ) || || p_switch->porch_adjust != p_switch->tmp_porch_adjust)
(p_switch->ra_core_hz != p_switch->ra_tmp_core_hz) || || (p_switch->ra_core_hz != p_switch->ra_tmp_core_hz)
(p_switch->rotated != p_switch->tmp_rotated)) || (p_switch->rotated != p_switch->tmp_rotated))
return true; return true;
return false; return false;
} }
@ -77,23 +77,18 @@ static void crt_store_temp_changes(videocrt_switch_t *p_switch)
p_switch->tmp_rotated = p_switch->rotated; p_switch->tmp_rotated = p_switch->rotated;
} }
static bool is_aspect_ratio_core_provided(void)
{
settings_t *settings = config_get_ptr();
return settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CORE;
}
static void crt_aspect_ratio_switch( static void crt_aspect_ratio_switch(
videocrt_switch_t *p_switch, videocrt_switch_t *p_switch,
unsigned width, unsigned height, unsigned width, unsigned height,
float srm_width, float srm_height) float srm_width, float srm_height)
{ {
settings_t *settings = config_get_ptr();
float fly_aspect = (float)width / (float)height; float fly_aspect = (float)width / (float)height;
p_switch->fly_aspect = fly_aspect; p_switch->fly_aspect = fly_aspect;
video_driver_state_t *video_st = video_state_get_ptr(); video_driver_state_t *video_st = video_state_get_ptr();
/* We only force aspect ratio for the core provided setting */ /* We only force aspect ratio for the core provided setting */
if (!is_aspect_ratio_core_provided()) if (settings->uints.video_aspect_ratio_idx != ASPECT_RATIO_CORE)
{ {
RARCH_LOG("[CRT]: Aspect ratio forced by user: %f\n", video_st->aspect_ratio); RARCH_LOG("[CRT]: Aspect ratio forced by user: %f\n", video_st->aspect_ratio);
return; return;
@ -120,6 +115,7 @@ static void crt_switch_set_aspect(
float srm_xscale, float srm_yscale, float srm_xscale, float srm_yscale,
bool srm_isstretched ) bool srm_isstretched )
{ {
sr_state state;
unsigned int patched_width = 0; unsigned int patched_width = 0;
unsigned int patched_height = 0; unsigned int patched_height = 0;
int scaled_width = 0; int scaled_width = 0;
@ -139,7 +135,6 @@ static void crt_switch_set_aspect(
patched_height = height; patched_height = height;
} }
sr_state state;
sr_get_state(&state); sr_get_state(&state);
if ((int)srm_width >= state.super_width && !srm_isstretched) if ((int)srm_width >= state.super_width && !srm_isstretched)
@ -153,29 +148,14 @@ static void crt_switch_set_aspect(
crt_aspect_ratio_switch(p_switch, scaled_width, scaled_height, srm_width, srm_height); crt_aspect_ratio_switch(p_switch, scaled_width, scaled_height, srm_width, srm_height);
} }
static bool is_kms_driver_context(void)
{
gfx_ctx_ident_t gfxctx;
video_context_driver_get_ident(&gfxctx);
RARCH_LOG("[CRT] Video context is: %s\n", gfxctx.ident);
return (gfxctx.ident && strncmp(gfxctx.ident, "kms",3) == 0);
}
static bool is_khr_driver_context()
{
gfx_ctx_ident_t gfxctx;
video_context_driver_get_ident(&gfxctx);
RARCH_LOG("[CRT] Video context is: %s\n", gfxctx.ident);
return (gfxctx.ident && strncmp(gfxctx.ident, "khr_display",11) == 0);
}
#if !defined(HAVE_VIDEOCORE) #if !defined(HAVE_VIDEOCORE)
static bool crt_sr2_init(videocrt_switch_t *p_switch, static bool crt_sr2_init(videocrt_switch_t *p_switch,
int monitor_index, unsigned int crt_mode, unsigned int super_width) int monitor_index, unsigned int crt_mode, unsigned int super_width)
{ {
const char* err_msg; char *mode;
char* mode; const char *err_msg;
char index[10]; char index[10];
gfx_ctx_ident_t gfxctx;
char ra_config_path[PATH_MAX_LENGTH]; char ra_config_path[PATH_MAX_LENGTH];
char sr_ini_file[PATH_MAX_LENGTH]; char sr_ini_file[PATH_MAX_LENGTH];
@ -184,8 +164,12 @@ static bool crt_sr2_init(videocrt_switch_t *p_switch,
else else
strlcpy(index, "0", sizeof(index)); strlcpy(index, "0", sizeof(index));
p_switch->kms_ctx = is_kms_driver_context(); video_context_driver_get_ident(&gfxctx);
p_switch->khr_ctx = is_khr_driver_context();
p_switch->kms_ctx = (gfxctx.ident && strncmp(gfxctx.ident, "kms", 3) == 0);
p_switch->khr_ctx = (gfxctx.ident && strncmp(gfxctx.ident, "khr_display", 11) == 0);
RARCH_LOG("[CRT] Video context is: %s\n", gfxctx.ident);
if (!p_switch->sr2_active) if (!p_switch->sr2_active)
{ {
@ -200,18 +184,18 @@ static bool crt_sr2_init(videocrt_switch_t *p_switch,
{ {
case 1: case 1:
sr_set_monitor("arcade_15"); sr_set_monitor("arcade_15");
RARCH_LOG("[CRT]: CRT Mode: %d - arcade_15 \n", crt_mode) ; RARCH_LOG("[CRT]: CRT Mode: %d - arcade_15 \n", crt_mode);
break; break;
case 2: case 2:
sr_set_monitor("arcade_31"); sr_set_monitor("arcade_31");
RARCH_LOG("[CRT]: CRT Mode: %d - arcade_31 \n", crt_mode) ; RARCH_LOG("[CRT]: CRT Mode: %d - arcade_31 \n", crt_mode);
break; break;
case 3: case 3:
sr_set_monitor("pc_31_120"); sr_set_monitor("pc_31_120");
RARCH_LOG("[CRT]: CRT Mode: %d - pc_31_120 \n", crt_mode) ; RARCH_LOG("[CRT]: CRT Mode: %d - pc_31_120 \n", crt_mode);
break; break;
case 4: case 4:
RARCH_LOG("[CRT]: CRT Mode: %d - Selected from ini \n", crt_mode) ; RARCH_LOG("[CRT]: CRT Mode: %d - Selected from ini \n", crt_mode);
break; break;
default: default:
break; break;
@ -219,15 +203,15 @@ static bool crt_sr2_init(videocrt_switch_t *p_switch,
if (super_width > 2) if (super_width > 2)
{ {
sr_set_user_mode(super_width, 0, 0);
char sw[16]; char sw[16];
sprintf(sw, "%d", super_width); sr_set_user_mode(super_width, 0, 0);
snprintf(sw, sizeof(sw), "%d", super_width);
sr_set_option(SR_OPT_SUPER_WIDTH, sw); sr_set_option(SR_OPT_SUPER_WIDTH, sw);
} }
if (p_switch->kms_ctx) if (p_switch->kms_ctx)
p_switch->rtn = sr_init_disp("dummy", NULL); p_switch->rtn = sr_init_disp("dummy", NULL);
else if (monitor_index+1 > 0) else if (monitor_index + 1 > 0)
{ {
RARCH_LOG("[CRT]: Monitor Index Manual: %s\n", &index[0]); RARCH_LOG("[CRT]: Monitor Index Manual: %s\n", &index[0]);
p_switch->rtn = sr_init_disp(index, NULL); p_switch->rtn = sr_init_disp(index, NULL);
@ -301,7 +285,6 @@ static void get_modeline_for_kms(videocrt_switch_t *p_switch, sr_mode* srm)
p_switch->vsync = srm->vsync; p_switch->vsync = srm->vsync;
} }
static void switch_res_crt( static void switch_res_crt(
videocrt_switch_t *p_switch, videocrt_switch_t *p_switch,
unsigned width, unsigned height, unsigned width, unsigned height,
@ -371,17 +354,21 @@ static void switch_res_crt(
p_switch->sr_core_hz = (float)srm.vfreq; p_switch->sr_core_hz = (float)srm.vfreq;
crt_switch_set_aspect(p_switch, crt_switch_set_aspect(p_switch,
p_switch->rotated? h : w, p_switch->rotated ? h : w,
p_switch->rotated? w : h, p_switch->rotated ? w : h,
srm.width, srm.height, srm.width, srm.height,
(float)srm.x_scale, (float)srm.y_scale, srm.is_stretched); (float)srm.x_scale,
(float)srm.y_scale,
srm.is_stretched);
} }
else else
{ {
crt_switch_set_aspect(p_switch, crt_switch_set_aspect(p_switch,
width, height, width, height,
width, height, width, height,
(float)1, (float)1, false); 1.0f,
1.0f,
false);
video_driver_set_size(width , height); video_driver_set_size(width , height);
video_driver_apply_state_changes(); video_driver_apply_state_changes();
} }
@ -406,6 +393,7 @@ void crt_switch_res_core(
int monitor_index, bool dynamic, int monitor_index, bool dynamic,
int super_width, bool hires_menu) int super_width, bool hires_menu)
{ {
settings_t *settings = config_get_ptr();
if (height <= 4) if (height <= 4)
{ {
hz = 60; hz = 60;
@ -463,8 +451,8 @@ void crt_switch_res_core(
crt_store_temp_changes(p_switch); crt_store_temp_changes(p_switch);
} }
if (is_aspect_ratio_core_provided() && if ( (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CORE)
video_driver_get_aspect_ratio() != p_switch->fly_aspect) && video_driver_get_aspect_ratio() != p_switch->fly_aspect)
{ {
video_driver_state_t *video_st = video_state_get_ptr(); video_driver_state_t *video_st = video_state_get_ptr();
float fly_aspect = (float)p_switch->fly_aspect; float fly_aspect = (float)p_switch->fly_aspect;
@ -560,7 +548,7 @@ static void crt_rpi_switch(videocrt_switch_t *p_switch,
int yscale = 1; int yscale = 1;
if (height > 300) if (height > 300)
height = height/2; height /= 2;
/* set core refresh from hz */ /* set core refresh from hz */
video_monitor_set_refresh_rate(hz); video_monitor_set_refresh_rate(hz);
@ -574,17 +562,17 @@ static void crt_rpi_switch(videocrt_switch_t *p_switch,
w = w+width; w = w+width;
if (w > 2000) if (w > 2000)
w =w- width; w = w - width;
width = w; width = w;
crt_aspect_ratio_switch(p_switch, width,height,width,height); crt_aspect_ratio_switch(p_switch, width,height,width,height);
/* following code is the mode line generator */ /* following code is the mode line generator */
hfp = ((width * 0.044) + (width / 112)); hfp = ((width * 0.044f) + (width / 112));
hbp = ((width * 0.172) + (width /64)); hbp = ((width * 0.172f) + (width /64));
hsp = (width * 0.117); hsp = (width * 0.117f);
if (height < 241) if (height < 241)
vmax = 261; vmax = 261;
@ -621,18 +609,15 @@ static void crt_rpi_switch(videocrt_switch_t *p_switch,
vsp = vfp + 6; /* needs to be 6 for interlaced */ vsp = vfp + 6; /* needs to be 6 for interlaced */
vsp = 3; vsp = 3;
vbp = (vmax-height)-vsp-vfp; vbp = (vmax - height) - vsp - vfp;
hmax = width+hfp+hsp+hbp; hmax = width + hfp + hsp + hbp;
if (height < 300) if (height < 300)
{ pixel_clock = (hmax * vmax * hz);
pixel_clock = (hmax * vmax * hz) ;
ip_flag = 0;
}
if (height > 300) if (height > 300)
{ {
pixel_clock = (hmax * vmax * (hz/2)) /2 ; pixel_clock = (hmax * vmax * (hz/2)) / 2;
ip_flag = 1; ip_flag = 1;
} }
@ -643,19 +628,12 @@ static void crt_rpi_switch(videocrt_switch_t *p_switch,
hz, ip_flag, pixel_clock); hz, ip_flag, pixel_clock);
vcos_init(); vcos_init();
vchi_initialise(&vchi_instance); vchi_initialise(&vchi_instance);
vchi_connect(NULL, 0, vchi_instance); vchi_connect(NULL, 0, vchi_instance);
vc_vchi_gencmd_init(vchi_instance, &vchi_connection, 1); vc_vchi_gencmd_init(vchi_instance, &vchi_connection, 1);
vc_gencmd(buffer, sizeof(buffer), set_hdmi_timing); vc_gencmd(buffer, sizeof(buffer), set_hdmi_timing);
vc_gencmd_stop(); vc_gencmd_stop();
vchi_disconnect(vchi_instance); vchi_disconnect(vchi_instance);
snprintf(output1, sizeof(output1), snprintf(output1, sizeof(output1),
"tvservice -e \"DMT 87\" > /dev/null"); "tvservice -e \"DMT 87\" > /dev/null");
system(output1); system(output1);