From 4a1d78d40df22668e4c17e08fb0034f2781b8576 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 18 Aug 2023 00:59:35 +0300 Subject: [PATCH] frontend: accept more bios --- frontend/libretro.c | 59 ++++++++++++++++++++++++++++++--------------- frontend/menu.c | 5 ++-- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index 6a3a97c9..a115fc67 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -2816,7 +2816,7 @@ void retro_run(void) set_vout_fb(); } -static bool try_use_bios(const char *path) +static bool try_use_bios(const char *path, bool preferred_only) { long size; const char *name; @@ -2828,12 +2828,20 @@ static bool try_use_bios(const char *path) size = ftell(fp); fclose(fp); - if (size != 512 * 1024) - return false; - name = strrchr(path, SLASH); if (name++ == NULL) name = path; + + if (preferred_only && size != 512 * 1024) + return false; + if (size != 512 * 1024 && size != 4 * 1024 * 1024) + return false; + if (strstr(name, "unirom")) + return false; + // jp bios have an addidional region check + if (preferred_only && (strcasestr(name, "00.") || strcasestr(name, "j.bin"))) + return false; + snprintf(Config.Bios, sizeof(Config.Bios), "%s", name); return true; } @@ -2844,7 +2852,8 @@ static bool try_use_bios(const char *path) static bool find_any_bios(const char *dirpath, char *path, size_t path_size) { - static const char *substrings[] = { "scph", "ps", "openbios" }; + static const char *substr_pref[] = { "scph", "ps" }; + static const char *substr_alt[] = { "scph", "ps", "openbios" }; DIR *dir; struct dirent *ent; bool ret = false; @@ -2854,27 +2863,39 @@ static bool find_any_bios(const char *dirpath, char *path, size_t path_size) if (dir == NULL) return false; - for (i = 0; i < (sizeof(substrings) / sizeof(substrings[0])); i++) + // try to find a "better" bios + while ((ent = readdir(dir))) { - const char *substr = substrings[i]; - size_t len = strlen(substr); - rewinddir(dir); - while ((ent = readdir(dir))) + for (i = 0; i < sizeof(substr_pref) / sizeof(substr_pref[0]); i++) { - if ((strncasecmp(ent->d_name, substr, len) != 0)) - continue; - if (strstr(ent->d_name, "unirom")) + const char *substr = substr_pref[i]; + if ((strncasecmp(ent->d_name, substr, strlen(substr)) != 0)) continue; + snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name); + ret = try_use_bios(path, true); + if (ret) + goto finish; + } + } + // another pass to look for anything fitting, even ps2 bios + rewinddir(dir); + while ((ent = readdir(dir))) + { + for (i = 0; i < sizeof(substr_alt) / sizeof(substr_alt[0]); i++) + { + const char *substr = substr_alt[i]; + if ((strncasecmp(ent->d_name, substr, strlen(substr)) != 0)) + continue; snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name); - ret = try_use_bios(path); + ret = try_use_bios(path, false); if (ret) - { - closedir(dir); - return ret; - } + goto finish; } } + + +finish: closedir(dir); return ret; } @@ -2971,7 +2992,7 @@ static void loadPSXBios(void) for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) { snprintf(path, sizeof(path), "%s%c%s.bin", dir, SLASH, bios[i]); - found_bios = try_use_bios(path); + found_bios = try_use_bios(path, true); if (found_bios) break; } diff --git a/frontend/menu.c b/frontend/menu.c index fb712247..901c72d5 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -111,7 +111,7 @@ int soft_filter; #define DEFAULT_PSX_CLOCK_S "50" #endif -static const char *bioses[24]; +static const char *bioses[32]; static const char *gpu_plugins[16]; static const char *spu_plugins[16]; static const char *memcards[32]; @@ -2450,7 +2450,8 @@ static void scan_bios_plugins(void) continue; snprintf(fname, sizeof(fname), "%s/%s", Config.BiosDir, ent->d_name); - if (stat(fname, &st) != 0 || st.st_size != 512*1024) { + if (stat(fname, &st) != 0 + || (st.st_size != 512*1024 && st.st_size != 4*1024*1024)) { printf("bad BIOS file: %s\n", ent->d_name); continue; } -- 2.39.5