From d6c9698353f1ef0ec0d873f35d850cb5d8ce778a Mon Sep 17 00:00:00 2001 From: alphanu Date: Sun, 8 Jun 2025 08:33:24 -0700 Subject: [PATCH] Added Horizontal and vertical geometry adjustments --- configuration.c | 2 +- gfx/video_crt_switch.c | 33 ++++++++++++++++++++++++++++----- gfx/video_crt_switch.h | 5 ++++- gfx/video_driver.c | 5 +++-- gfx/video_driver.h | 1 + intl/msg_hash_us.h | 2 +- menu/menu_setting.c | 6 +++--- 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/configuration.c b/configuration.c index 492188ce99..1536ed979e 100644 --- a/configuration.c +++ b/configuration.c @@ -2687,7 +2687,7 @@ static struct config_int_setting *populate_settings_int( SETTING_INT("crt_switch_center_adjust", &settings->ints.crt_switch_center_adjust, false, DEFAULT_CRT_SWITCH_CENTER_ADJUST, false); SETTING_INT("crt_switch_porch_adjust", &settings->ints.crt_switch_porch_adjust, false, DEFAULT_CRT_SWITCH_PORCH_ADJUST, false); - SETTING_INT("crt_switch_porch_adjust", &settings->ints.crt_switch_porch_adjust, false, DEFAULT_CRT_SWITCH_VERTICAL_ADJUST, false); + SETTING_INT("crt_switch_vertical_adjust", &settings->ints.crt_switch_vertical_adjust, false, DEFAULT_CRT_SWITCH_VERTICAL_ADJUST, false); #ifdef HAVE_WINDOW_OFFSET SETTING_INT("video_window_offset_x", &settings->ints.video_window_offset_x, true, DEFAULT_WINDOW_OFFSET_X, false); SETTING_INT("video_window_offset_y", &settings->ints.video_window_offset_y, true, DEFAULT_WINDOW_OFFSET_Y, false); diff --git a/gfx/video_crt_switch.c b/gfx/video_crt_switch.c index c1f72f70b6..98ab5d84d7 100644 --- a/gfx/video_crt_switch.c +++ b/gfx/video_crt_switch.c @@ -46,6 +46,9 @@ static void crt_adjust_sr_ini(videocrt_switch_t *p_switch); static bool ini_overrides_loaded = false; static char core_name[NAME_MAX_LENGTH]; /* Same size as library_name on retroarch_data.h */ static char content_dir[DIR_MAX_LENGTH]; +static char _hSize[12]; +static char _hShift[12]; +static char _vShift[12]; #if defined(HAVE_VIDEOCORE) /* Need to add video core to SR2 */ #include "include/userland/interface/vmcs_host/vc_vchi_gencmd.h" @@ -56,8 +59,9 @@ static bool crt_check_for_changes(videocrt_switch_t *p_switch) { if ( (p_switch->ra_core_height != p_switch->ra_tmp_height) || (p_switch->ra_core_width != p_switch->ra_tmp_width) - || (p_switch->center_adjust != p_switch->tmp_center_adjust - || p_switch->porch_adjust != p_switch->tmp_porch_adjust) + || (p_switch->center_adjust != p_switch->tmp_center_adjust) + || (p_switch->porch_adjust != p_switch->tmp_porch_adjust) + || (p_switch->vert_adjust != p_switch->tmp_vert_adjust) || (p_switch->ra_core_hz != p_switch->ra_tmp_core_hz) || (p_switch->rotated != p_switch->tmp_rotated)) return true; @@ -72,6 +76,7 @@ static void crt_store_temp_changes(videocrt_switch_t *p_switch) p_switch->tmp_porch_adjust = p_switch->porch_adjust; p_switch->ra_tmp_core_hz = p_switch->ra_core_hz; p_switch->tmp_rotated = p_switch->rotated; + p_switch->tmp_vert_adjust = p_switch->vert_adjust; } static void crt_aspect_ratio_switch( @@ -304,6 +309,14 @@ static void switch_res_crt( char current_content_dir[DIR_MAX_LENGTH]; double rr = p_switch->ra_core_hz; const char *_core_name = (const char*)runloop_state_get_ptr()->system.info.library_name; + + const char* hSize = (const char*)_hSize; + const char* hShift = (const char*)_hShift; + const char* vShift = (const char*)_vShift; + + sr_set_option(SR_OPT_H_SIZE, hSize); + sr_set_option(SR_OPT_H_SHIFT, hShift); + sr_set_option(SR_OPT_V_SHIFT, vShift); /* Check for core and content changes in case we need to make any adjustments */ if (string_is_empty(_core_name)) @@ -386,8 +399,11 @@ void crt_switch_res_core( int crt_switch_porch_adjust, int monitor_index, bool dynamic, int super_width, bool hires_menu, - unsigned video_aspect_ratio_idx) + unsigned video_aspect_ratio_idx, + int crt_switch_vert_adjust) { + + if (height <= 4) { hz = 60; @@ -400,7 +416,7 @@ void crt_switch_res_core( { native_width = 320; height = 240; - } + } width = native_width; } @@ -408,6 +424,7 @@ void crt_switch_res_core( { p_switch->menu_active = false; p_switch->porch_adjust = crt_switch_porch_adjust; + p_switch->vert_adjust = crt_switch_vert_adjust; p_switch->ra_core_height = height; p_switch->ra_core_hz = hz; @@ -425,7 +442,13 @@ void crt_switch_res_core( #if defined(HAVE_VIDEOCORE) crt_rpi_switch(p_switch, width, height, hz, 0, native_width); #else - + + sprintf(_hSize, "%lf", 1+ + ((float)crt_switch_porch_adjust/100.0)); + sprintf(_hShift, "%d", + crt_switch_center_adjust); + sprintf(_vShift, "%d", + crt_switch_vert_adjust); if (p_switch->hh_core) { int corrected_width = 320; diff --git a/gfx/video_crt_switch.h b/gfx/video_crt_switch.h index 1b354d80f8..0be6a1dac1 100644 --- a/gfx/video_crt_switch.h +++ b/gfx/video_crt_switch.h @@ -48,8 +48,10 @@ typedef struct videocrt_switch int center_adjust; int porch_adjust; + int vert_adjust; int tmp_porch_adjust; int tmp_center_adjust; + int tmp_vert_adjust; int rtn; int interlace; int doublescan; @@ -85,7 +87,8 @@ void crt_switch_res_core( bool dynamic, int super_width, bool hires_menu, - unsigned video_aspect_ratio_idx); + unsigned video_aspect_ratio_idx, + int crt_switch_vert_adjust); void crt_destroy_modes(videocrt_switch_t *p_switch); diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 5a0b657ac1..c1351fcebb 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -2890,6 +2890,7 @@ void video_driver_build_info(video_frame_info_t *video_info) video_info->crt_switch_resolution_super = settings->uints.crt_switch_resolution_super; video_info->crt_switch_center_adjust = settings->ints.crt_switch_center_adjust; video_info->crt_switch_porch_adjust = settings->ints.crt_switch_porch_adjust; + video_info->crt_switch_vert_adjust = settings->ints.crt_switch_vertical_adjust; video_info->crt_switch_hires_menu = settings->bools.crt_switch_hires_menu; video_info->black_frame_insertion = settings->uints.video_black_frame_insertion; video_info->bfi_dark_frames = settings->uints.video_bfi_dark_frames; @@ -4363,8 +4364,8 @@ void video_driver_frame(const void *data, unsigned width, dynamic_super_width, video_info.crt_switch_resolution_super, video_info.crt_switch_hires_menu, - config_get_ptr()->uints.video_aspect_ratio_idx - ); + config_get_ptr()->uints.video_aspect_ratio_idx, + video_info.crt_switch_vert_adjust); } else if (!video_info.crt_switch_resolution) #endif diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 7492155403..5be4a05352 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -395,6 +395,7 @@ typedef struct video_frame_info int custom_vp_y; int crt_switch_center_adjust; int crt_switch_porch_adjust; + int crt_switch_vert_adjust; unsigned hard_sync_frames; unsigned runahead_frames; diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 60f86d2830..96c21f103a 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -2187,7 +2187,7 @@ MSG_HASH( ) MSG_HASH( MENU_ENUM_LABEL_VALUE_CRT_SWITCH_VERTICAL_ADJUST, - "Vertical Size" + "Vertical Centring" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_CRT_SWITCH_HIRES_MENU, diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 738a22bbde..fe69be88ee 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -14094,7 +14094,7 @@ static bool setting_append_list( (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; (*list)[list_info->index - 1].offset_by = -3; SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ADVANCED); - menu_settings_list_current_add_range(list, list_info, -20, 20, 2.0, true, true); + menu_settings_list_current_add_range(list, list_info, -50, 50, 1.0, true, true); CONFIG_INT( list, list_info, @@ -14111,7 +14111,7 @@ static bool setting_append_list( (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; (*list)[list_info->index - 1].offset_by = 0; SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ADVANCED); - menu_settings_list_current_add_range(list, list_info, -50, 50, 2.0, true, true); + menu_settings_list_current_add_range(list, list_info, -50, 100, 1.0, true, true); CONFIG_INT( list, list_info, @@ -14128,7 +14128,7 @@ static bool setting_append_list( (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; (*list)[list_info->index - 1].offset_by = 0; SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ADVANCED); - menu_settings_list_current_add_range(list, list_info, -10, 10, 2.0, true, true); + menu_settings_list_current_add_range(list, list_info, -20, 20, 1.0, true, true); CONFIG_BOOL( list, list_info,