Skip to content

Commit

Permalink
loader: replace overwrite functions with initialize function. Key cha…
Browse files Browse the repository at this point in the history
…nge: set value only if it is not set.
  • Loading branch information
AKuHAK committed Oct 18, 2024
1 parent 9ed63a8 commit c6c8051
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions ee/loader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ struct SSystemSettings {
uint8_t disk_id[5];
uint64_t disk_id_int; // 8 bytes, but that's ok for compare reasons
};
} sys;
} sys = {
.bDebugColors = -1,
.bLogo = -1,
.eecore_mod_base = -1,
.fs_sectors = -1,
};

struct SDriver {
// All modules
Expand Down Expand Up @@ -652,25 +657,29 @@ int fakelist_add_array(struct SFakeList *fl, toml_table_t *tbl_root)
return 0;
}

void toml_string_in_overwrite(toml_table_t *t, const char *name, char **dest)
void toml_string_in_initialize(toml_table_t *t, const char *name, char **dest)
{
if (*dest != NULL)
return;
toml_datum_t v = toml_string_in(t, name);
if (v.ok) {
if (*dest != NULL)
free (*dest);
*dest = v.u.s;
}
}

void toml_bool_in_overwrite(toml_table_t *t, const char *name, int *dest)
void toml_bool_in_initialize(toml_table_t *t, const char *name, int *dest)
{
if (*dest != -1)
return;
toml_datum_t v = toml_bool_in(t, name);
if (v.ok)
*dest = v.u.b;
}

void toml_int_in_overwrite(toml_table_t *t, const char *name, int *dest)
void toml_int_in_initialize(toml_table_t *t, const char *name, int *dest)
{
if (*dest != -1)
return;
toml_datum_t v = toml_int_in(t, name);
if (v.ok)
*dest = v.u.i;
Expand Down Expand Up @@ -722,26 +731,26 @@ int load_driver(const char * type, const char * subtype)
free(v.u.s);
}

toml_string_in_overwrite(tbl_root, "default_bsd", &sys.sBSD);
toml_string_in_overwrite(tbl_root, "default_bsdfs", &sys.sBSDFS);
toml_string_in_overwrite(tbl_root, "default_dvd", &sys.sDVDMode);
toml_string_in_overwrite(tbl_root, "default_ata0", &sys.sATA0File);
toml_string_in_overwrite(tbl_root, "default_ata0id", &sys.sATA0IDFile);
toml_string_in_overwrite(tbl_root, "default_ata1", &sys.sATA1File);
toml_string_in_overwrite(tbl_root, "default_mc0", &sys.sMC0File);
toml_string_in_overwrite(tbl_root, "default_mc1", &sys.sMC1File);
toml_string_in_overwrite(tbl_root, "default_elf", &sys.sELFFile);
toml_string_in_overwrite(tbl_root, "default_mt", &sys.sMT);
toml_string_in_overwrite(tbl_root, "default_gc", &sys.sGC);
toml_string_in_overwrite(tbl_root, "default_cwd", &sys.sCWDpath);
toml_string_in_overwrite(tbl_root, "default_cfg", &sys.sCFGFile);
toml_bool_in_overwrite (tbl_root, "default_dbc", &sys.bDebugColors);
toml_bool_in_overwrite (tbl_root, "default_logo", &sys.bLogo);

toml_string_in_overwrite(tbl_root, "eecore_elf", &sys.eecore_elf);
toml_int_in_overwrite (tbl_root, "eecore_mod_base", &sys.eecore_mod_base);

toml_int_in_overwrite (tbl_root, "cdvdman_fs_sectors", &sys.fs_sectors);
toml_string_in_initialize(tbl_root, "default_bsd", &sys.sBSD);
toml_string_in_initialize(tbl_root, "default_bsdfs", &sys.sBSDFS);
toml_string_in_initialize(tbl_root, "default_dvd", &sys.sDVDMode);
toml_string_in_initialize(tbl_root, "default_ata0", &sys.sATA0File);
toml_string_in_initialize(tbl_root, "default_ata0id", &sys.sATA0IDFile);
toml_string_in_initialize(tbl_root, "default_ata1", &sys.sATA1File);
toml_string_in_initialize(tbl_root, "default_mc0", &sys.sMC0File);
toml_string_in_initialize(tbl_root, "default_mc1", &sys.sMC1File);
toml_string_in_initialize(tbl_root, "default_elf", &sys.sELFFile);
toml_string_in_initialize(tbl_root, "default_mt", &sys.sMT);
toml_string_in_initialize(tbl_root, "default_gc", &sys.sGC);
toml_string_in_initialize(tbl_root, "default_cwd", &sys.sCWDpath);
toml_string_in_initialize(tbl_root, "default_cfg", &sys.sCFGFile);
toml_bool_in_initialize (tbl_root, "default_dbc", &sys.bDebugColors);
toml_bool_in_initialize (tbl_root, "default_logo", &sys.bLogo);

toml_string_in_initialize(tbl_root, "eecore_elf", &sys.eecore_elf);
toml_int_in_initialize (tbl_root, "eecore_mod_base", &sys.eecore_mod_base);

toml_int_in_initialize (tbl_root, "cdvdman_fs_sectors", &sys.fs_sectors);

arr = toml_array_in(tbl_root, "ilink_id");
if (arr != NULL) {
Expand Down

0 comments on commit c6c8051

Please sign in to comment.