From 2649e656f25bea88fb9193fdc6a72495e4aa7e42 Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:56:31 -0300 Subject: [PATCH 1/2] Simplify Config search --- .gitignore | 1 + include/common.h | 22 ++++++++++++++-- src/main.c | 68 +++++------------------------------------------- 3 files changed, 28 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 1dacedc..b04b34f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ asm/ *.7z *.XLF *.dat +bin/CONFIG.INI diff --git a/include/common.h b/include/common.h index 4a99cf6..290da72 100644 --- a/include/common.h +++ b/include/common.h @@ -14,12 +14,29 @@ enum #ifdef XFROM SOURCE_XFROM, #endif + SOURCE_XCONFIG, SOURCE_INVALID, SOURCE_COUNT, } CONFIG_SOURCES_ID; -static const char* SOURCES[SOURCE_COUNT] = -{ +char* CONFIG_PATHS[SOURCE_COUNT] = { + "mc0:/PS2BBL/CONFIG.INI", + "mc1:/PS2BBL/CONFIG.INI", + "mass:/PS2BBL/CONFIG.INI", +#ifdef MX4SIO + "massX:/PS2BBL/CONFIG.INI", +#endif +#ifdef HDD + "hdd0:__sysconf:pfs:/PS2BBL/CONFIG.INI", +#endif +#ifdef XFROM + "xfrom:/PS2BBL/CONFIG.INI", +#endif + "mc?:/PS2BBL/XCONFIG.INI", + "", +}; + +static const char* SOURCES[SOURCE_COUNT] = { "mc0", "mc1", "usb", @@ -32,6 +49,7 @@ static const char* SOURCES[SOURCE_COUNT] = #ifdef XFROM "xfrom", #endif + "XCONF", "NOT FOUND", }; diff --git a/src/main.c b/src/main.c index cae2335..ec16ff0 100644 --- a/src/main.c +++ b/src/main.c @@ -333,68 +333,15 @@ int main(int argc, char *argv[]) DPRINTF("load default settings\n"); SetDefaultSettings(); FILE *fp; - DPRINTF("Reading settings...\n"); - fp = fopen("mass:/PS2BBL/CONFIG.INI", "r"); - if (fp == NULL) { - DPRINTF("Cant load config from mass\n"); -#ifdef HDD - if (mnt("hdd0:__sysconf") == 0) - fp = fopen("pfs0:/PS2BBL/CONFIG.INI", "r" ); - if (fp == NULL) - { - DPRINTF("Cant open 'pfs0:/PS2BBL/CONFIG.INI'\n"); -#endif -#ifdef MX4SIO - char* MX4SIO_CONF = CheckPath("massX:/PS2BBL/CONFIG.INI"); - fp = fopen(MX4SIO_CONF, "r"); - if (fp == NULL) - { - DPRINTF("Cant open 'mx4sio:/PS2BBL/CONFIG.INI'\n"); -#endif -#ifdef PSX - char* PSX_CONF = CheckPath("mc?:/PS2BBL/XCONFIG.INI"); - fp = fopen(PSX_CONF, "r"); - if (fp == NULL) - { - DPRINTF("Cant open '%s'\n", PSX_CONF); -#endif - fp = fopen("mc0:/PS2BBL/CONFIG.INI", "r"); - if (fp == NULL) { - DPRINTF("Cant load config from mc0\n"); - fp = fopen("mc1:/PS2BBL/CONFIG.INI", "r"); - if (fp == NULL) { - DPRINTF("Cant load config from mc1\n"); - config_source = SOURCE_INVALID; - } else { - config_source = SOURCE_MC1; - } - } else { - config_source = SOURCE_MC0; - } -#ifdef PSX - } else { - config_source = PSX_CONF[2] - '0'; /* since the enumerators for SOURCE_MC0 and SOURCE_MC1 have values of 0 and 1 - we can substract '0' to the MC index and still get the proper value */ - - } - -#endif -#ifdef MX4SIO - } else { - config_source = SOURCE_MX4SIO; - - } -#endif -#ifdef HDD - } else { - config_source = SOURCE_HDD; - + for (x = SOURCE_CWD; x >= SOURCE_MC0; x--) { + char* T = CheckPath(CONFIG_PATHS[x]); + fp = fopen(T, "r"); + if (fp != NULL) { + config_source = x; + break; } -#endif - } else { - config_source = SOURCE_MASS; } - + if (config_source != SOURCE_INVALID) { DPRINTF("valid config on device '%s', reading now\n", SOURCES[config_source]); pad_button = 0x0001; // on valid config, change the value of `pad_button` so the pad detection loop iterates all the buttons instead of only those configured on default paths @@ -538,7 +485,6 @@ int main(int argc, char *argv[]) while (Timer() <= (tstart + GLOBCFG.DELAY)) { button = pad_button; // reset the value so we can iterate (bit-shift) again PAD = ReadCombinedPadStatus_raw(); - DPRINTF("PAD %x\n", PAD); for (x = 0; x < num_buttons; x++) { // check all pad buttons if (PAD & button) { DPRINTF("PAD detected\n"); From 20b28b38223f6071e32e7312ae0d70f681d918f3 Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:58:35 -0300 Subject: [PATCH 2/2] Allow reading config from program CWD Paste a `CONFIG.INI` file on the same folder than PS2BBL is currently stored, and it will use it instead of common config Useful to make per-region config on a system update setup Or to load config when booting from a device implicitly supported (eg: `host:/`, `cdrom0:/` --- include/common.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/common.h b/include/common.h index 290da72..d814f62 100644 --- a/include/common.h +++ b/include/common.h @@ -15,6 +15,7 @@ enum SOURCE_XFROM, #endif SOURCE_XCONFIG, + SOURCE_CWD, SOURCE_INVALID, SOURCE_COUNT, } CONFIG_SOURCES_ID; @@ -33,6 +34,7 @@ char* CONFIG_PATHS[SOURCE_COUNT] = { "xfrom:/PS2BBL/CONFIG.INI", #endif "mc?:/PS2BBL/XCONFIG.INI", + "CONFIG.INI", "", }; @@ -50,6 +52,7 @@ static const char* SOURCES[SOURCE_COUNT] = { "xfrom", #endif "XCONF", + "CWD", "NOT FOUND", };