From 49aef3f016ea52549ff84f85aa77711a0b96e870 Mon Sep 17 00:00:00 2001 From: Jamiras Date: Mon, 9 Dec 2024 16:17:47 -0700 Subject: [PATCH] allow auto speed for pcsx_rearmed --- src/rc_libretro.c | 87 ++++++++++++++++++++++++++++------------- test/test_rc_libretro.c | 23 +++++------ 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/src/rc_libretro.c b/src/rc_libretro.c index d343ce78..978ff0b7 100644 --- a/src/rc_libretro.c +++ b/src/rc_libretro.c @@ -124,7 +124,7 @@ static const rc_disallowed_setting_t _rc_disallowed_neocd_settings[] = { }; static const rc_disallowed_setting_t _rc_disallowed_pcsx_rearmed_settings[] = { - { "pcsx_rearmed_psxclock", "<55" }, + { "pcsx_rearmed_psxclock", ",!auto,<55" }, { "pcsx_rearmed_region", "pal" }, { NULL, NULL } }; @@ -202,14 +202,14 @@ static const rc_disallowed_core_settings_t rc_disallowed_core_settings[] = { { NULL, NULL } }; -static int rc_libretro_string_equal_nocase_wildcard(const char* test, const char* value) { +static int rc_libretro_string_equal_nocase_wildcard(const char* test, const char* match) { char c1, c2; while ((c1 = *test++)) { - if (tolower(c1) != tolower(c2 = *value++) && c2 != '?') + if (tolower(c1) != tolower(c2 = *match++) && c2 != '?') return (c2 == '*'); } - return (*value == '\0'); + return (*match == '\0'); } static int rc_libretro_numeric_less_than(const char* test, const char* value) { @@ -218,7 +218,50 @@ static int rc_libretro_numeric_less_than(const char* test, const char* value) { return (test_num < value_num); } +static int rc_libretro_match_token(const char* val, const char* token, size_t size, int* result) { + if (*token == '!') { + /* !X => if X is a match, it's explicitly allowed. match with result = false */ + if (rc_libretro_match_token(val, token + 1, size - 1, result)) { + *result = 0; + return 1; + } + } + + if (*token == '<') { + /* if val < token, match with result = true */ + char buffer[128]; + memcpy(buffer, token + 1, size - 1); + buffer[size - 1] = '\0'; + if (rc_libretro_numeric_less_than(val, buffer)) { + *result = 1; + return 1; + } + } + + if (memcmp(token, val, size) == 0 && val[size] == 0) { + /* exact match, match with result = true */ + *result = 1; + return 1; + } + else { + /* check for case insensitive match */ + char buffer[128]; + memcpy(buffer, token, size); + buffer[size] = '\0'; + if (rc_libretro_string_equal_nocase_wildcard(val, buffer)) { + /* case insensitive match, match with result = true */ + *result = 1; + return 1; + } + } + + /* no match */ + return 0; +} + static int rc_libretro_match_value(const char* val, const char* match) { + int result = 0; + /* if value starts with a comma, it's a CSV list of potential matches */ if (*match == ',') { do { @@ -229,33 +272,23 @@ static int rc_libretro_match_value(const char* val, const char* match) { ++match; size = match - ptr; - if (val[size] == '\0') { - if (memcmp(ptr, val, size) == 0) { - return 1; - } - else { - char buffer[128]; - memcpy(buffer, ptr, size); - buffer[size] = '\0'; - if (rc_libretro_string_equal_nocase_wildcard(buffer, val)) - return 1; - } - } - } while (*match == ','); + if (rc_libretro_match_token(val, ptr, size, &result)) + return result; - return 0; + } while (*match == ','); } + else { + /* a leading exclamation point means the provided value(s) are not forbidden (are allowed) */ + if (*match == '!') + return !rc_libretro_match_value(val, &match[1]); - /* a leading exclamation point means the provided value(s) are not forbidden (are allowed) */ - if (*match == '!') - return !rc_libretro_match_value(val, &match[1]); - - /* a leading less tahn means the provided value is the minimum allowed */ - if (*match == '<') - return rc_libretro_numeric_less_than(val, &match[1]); + /* just a single value, attempt to match it */ + if (rc_libretro_match_token(val, match, strlen(match), &result)) + return result; + } - /* just a single value, attempt to match it */ - return rc_libretro_string_equal_nocase_wildcard(val, match); + /* value did not match filters, assume it's allowed */ + return 0; } int rc_libretro_is_setting_allowed(const rc_disallowed_setting_t* disallowed_settings, const char* setting, const char* value) { diff --git a/test/test_rc_libretro.c b/test/test_rc_libretro.c index 08f04669..4de5c19d 100644 --- a/test/test_rc_libretro.c +++ b/test/test_rc_libretro.c @@ -698,13 +698,13 @@ void test_rc_libretro(void) { TEST_SUITE_BEGIN(); /* rc_libretro_disallowed_settings */ - TEST_PARAMS3(test_allowed_setting, "Beetle PSX", "beetle_psx_cpu_freq_scale", "750%"); - TEST_PARAMS3(test_allowed_setting, "Beetle PSX", "beetle_psx_cpu_freq_scale", "100%(native)"); + TEST_PARAMS3(test_allowed_setting, "Beetle PSX", "beetle_psx_cpu_freq_scale", "750%"); + TEST_PARAMS3(test_allowed_setting, "Beetle PSX", "beetle_psx_cpu_freq_scale", "100%(native)"); TEST_PARAMS3(test_disallowed_setting, "Beetle PSX", "beetle_psx_cpu_freq_scale", "99%"); TEST_PARAMS3(test_disallowed_setting, "Beetle PSX", "beetle_psx_cpu_freq_scale", "50%"); - TEST_PARAMS3(test_allowed_setting, "Beetle PSX HW", "beetle_psx_hw_cpu_freq_scale", "750%"); - TEST_PARAMS3(test_allowed_setting, "Beetle PSX HW", "beetle_psx_hw_cpu_freq_scale", "100%(native)"); + TEST_PARAMS3(test_allowed_setting, "Beetle PSX HW", "beetle_psx_hw_cpu_freq_scale", "750%"); + TEST_PARAMS3(test_allowed_setting, "Beetle PSX HW", "beetle_psx_hw_cpu_freq_scale", "100%(native)"); TEST_PARAMS3(test_disallowed_setting, "Beetle PSX HW", "beetle_psx_hw_cpu_freq_scale", "99%"); TEST_PARAMS3(test_disallowed_setting, "Beetle PSX HW", "beetle_psx_hw_cpu_freq_scale", "50%"); @@ -734,8 +734,8 @@ void test_rc_libretro(void) { TEST_PARAMS3(test_disallowed_setting, "FCEUmm", "fceumm_region", "Dendy"); TEST_PARAMS3(test_allowed_setting, "FCEUmm", "fceumm_palette", "default"); /* setting we don't care about */ - TEST_PARAMS3(test_allowed_setting, "Flycast", "reicast_sh4clock", "500"); - TEST_PARAMS3(test_allowed_setting, "Flycast", "reicast_sh4clock", "200"); + TEST_PARAMS3(test_allowed_setting, "Flycast", "reicast_sh4clock", "500"); + TEST_PARAMS3(test_allowed_setting, "Flycast", "reicast_sh4clock", "200"); TEST_PARAMS3(test_disallowed_setting, "Flycast", "reicast_sh4clock", "190"); TEST_PARAMS3(test_disallowed_setting, "Flycast", "reicast_sh4clock", "50"); @@ -796,9 +796,10 @@ void test_rc_libretro(void) { TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_region", "Auto"); TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_region", "NTSC"); TEST_PARAMS3(test_disallowed_setting, "PCSX-ReARMed", "pcsx_rearmed_region", "PAL"); - TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "100"); - TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "57"); - TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "55"); + TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "auto"); + TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "100"); + TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "57"); + TEST_PARAMS3(test_allowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "55"); TEST_PARAMS3(test_disallowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "54"); TEST_PARAMS3(test_disallowed_setting, "PCSX-ReARMed", "pcsx_rearmed_psxclock", "30"); @@ -831,8 +832,8 @@ void test_rc_libretro(void) { TEST_PARAMS3(test_allowed_setting, "Snes9x", "snes9x_layer_5", "enabled"); TEST_PARAMS3(test_disallowed_setting, "Snes9x", "snes9x_layer_5", "disabled"); - TEST_PARAMS3(test_allowed_setting, "SwanStation", "swanstation_CPU_Overclock", "1000"); - TEST_PARAMS3(test_allowed_setting, "SwanStation", "swanstation_CPU_Overclock", "100"); + TEST_PARAMS3(test_allowed_setting, "SwanStation", "swanstation_CPU_Overclock", "1000"); + TEST_PARAMS3(test_allowed_setting, "SwanStation", "swanstation_CPU_Overclock", "100"); TEST_PARAMS3(test_disallowed_setting, "SwanStation", "swanstation_CPU_Overclock", "99"); TEST_PARAMS3(test_disallowed_setting, "SwanStation", "swanstation_CPU_Overclock", "50");