+static bool try_use_bios(const char *path)
+{
+ FILE *f;
+ long size;
+ const char *name;
+
+ f = fopen(path, "rb");
+ if (f == NULL)
+ return false;
+
+ fseek(f, 0, SEEK_END);
+ size = ftell(f);
+ fclose(f);
+
+ if (size != 512 * 1024)
+ return false;
+
+ name = strrchr(path, SLASH);
+ if (name++ == NULL)
+ name = path;
+ snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
+ return true;
+}
+
+#if 1
+#include <sys/types.h>
+#include <dirent.h>
+
+static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
+{
+ DIR *dir;
+ struct dirent *ent;
+ bool ret = false;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ return false;
+
+ while ((ent = readdir(dir))) {
+ if (strncasecmp(ent->d_name, "scph", 4) != 0)
+ continue;
+
+ snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
+ ret = try_use_bios(path);
+ if (ret)
+ break;
+ }
+ closedir(dir);
+ return ret;
+}
+#else
+#define find_any_bios(...) false
+#endif
+