From 3b0c4974b689305aca0aadd2272d816f57d0f0b1 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 8 Oct 2024 15:24:42 +0100 Subject: [PATCH] Work on rom info Improve layout handling --- src/menu/rom_info.c | 99 ++++++++++++++++++++++----------------- src/menu/rom_info.h | 21 ++++++--- src/menu/views/load_rom.c | 18 +++++-- 3 files changed, 85 insertions(+), 53 deletions(-) diff --git a/src/menu/rom_info.c b/src/menu/rom_info.c index e5b750ce..5ea165ea 100644 --- a/src/menu/rom_info.c +++ b/src/menu/rom_info.c @@ -792,47 +792,58 @@ static void extract_rom_info (match_t *match, rom_header_t *rom_header, rom_info } else { rom_info->features.expansion_pak = EXPANSION_PAK_NONE; } + + rom_info->metadata.description[0] = '\0'; + rom_info->settings.cheats_enabled = false; + rom_info->settings.patches_enabled = false; } -static void load_overrides (path_t *path, rom_info_t *rom_info) { - path_t *overrides_path = path_clone(path); +static void load_rom_info_from_file (path_t *path, rom_info_t *rom_info) { + path_t *rom_info_path = path_clone(path); - path_ext_replace(overrides_path, "ini"); + path_ext_replace(rom_info_path, "ini"); - mini_t *ini = mini_load(path_get(overrides_path)); + mini_t *ini = mini_load(path_get(rom_info_path)); - rom_info->override.cic = false; - rom_info->override.save = false; - rom_info->override.tv = false; + rom_info->boot_override.cic = false; + rom_info->boot_override.save = false; + rom_info->boot_override.tv = false; if (ini) { - rom_info->override.cic_type = mini_get_int(ini, NULL, "cic_type", ROM_CIC_TYPE_AUTOMATIC); - if (rom_info->override.cic_type != ROM_CIC_TYPE_AUTOMATIC) { - rom_info->override.cic = true; + + const char *rom_description = mini_get_string(ini, "metadata", "description", ""); + memcpy(rom_info->metadata.description , rom_description, sizeof(rom_info->metadata.description)); + + rom_info->boot_override.cic_type = mini_get_int(ini, "custom_boot", "cic_type", ROM_CIC_TYPE_AUTOMATIC); + if (rom_info->boot_override.cic_type != ROM_CIC_TYPE_AUTOMATIC) { + rom_info->boot_override.cic = true; } - rom_info->override.save_type = mini_get_int(ini, NULL, "save_type", SAVE_TYPE_AUTOMATIC); - if (rom_info->override.save_type != SAVE_TYPE_AUTOMATIC) { - rom_info->override.save = true; + rom_info->boot_override.save_type = mini_get_int(ini, "custom_boot", "save_type", SAVE_TYPE_AUTOMATIC); + if (rom_info->boot_override.save_type != SAVE_TYPE_AUTOMATIC) { + rom_info->boot_override.save = true; } - rom_info->override.tv_type = mini_get_int(ini, NULL, "tv_type", ROM_TV_TYPE_AUTOMATIC); - if (rom_info->override.tv_type != ROM_TV_TYPE_AUTOMATIC) { - rom_info->override.tv = true; + rom_info->boot_override.tv_type = mini_get_int(ini, "custom_boot", "tv_type", ROM_TV_TYPE_AUTOMATIC); + if (rom_info->boot_override.tv_type != ROM_TV_TYPE_AUTOMATIC) { + rom_info->boot_override.tv = true; } + rom_info->settings.cheats_enabled = mini_get_bool(ini, NULL, "cheats_enabled", false); + rom_info->settings.patches_enabled = mini_get_bool(ini, NULL, "patches_enabled", false); + mini_free(ini); } - path_free(overrides_path); + path_free(rom_info_path); } static rom_err_t save_override (path_t *path, const char *id, int value, int default_value) { - path_t *overrides_path = path_clone(path); + path_t *rom_info_path = path_clone(path); - path_ext_replace(overrides_path, "ini"); + path_ext_replace(rom_info_path, "ini"); - mini_t *ini = mini_try_load(path_get(overrides_path)); + mini_t *ini = mini_try_load(path_get(rom_info_path)); if (!ini) { return ROM_ERR_SAVE_IO; @@ -841,13 +852,13 @@ static rom_err_t save_override (path_t *path, const char *id, int value, int def int mini_err; if (value == default_value) { - mini_err = mini_delete_value(ini, NULL, id); + mini_err = mini_delete_value(ini, "custom_boot", id); } else { - mini_err = mini_set_int(ini, NULL, id, value); + mini_err = mini_set_int(ini, "custom_boot", id, value); } if ((mini_err != MINI_OK) && (mini_err != MINI_VALUE_NOT_FOUND)) { - path_free(overrides_path); + path_free(rom_info_path); mini_free(ini); return ROM_ERR_SAVE_IO; } @@ -856,7 +867,7 @@ static rom_err_t save_override (path_t *path, const char *id, int value, int def if (!empty) { if (mini_save(ini, MINI_FLAGS_NONE) != MINI_OK) { - path_free(overrides_path); + path_free(rom_info_path); mini_free(ini); return ROM_ERR_SAVE_IO; } @@ -865,21 +876,21 @@ static rom_err_t save_override (path_t *path, const char *id, int value, int def mini_free(ini); if (empty) { - if (remove(path_get(overrides_path)) && (errno != ENOENT)) { - path_free(overrides_path); + if (remove(path_get(rom_info_path)) && (errno != ENOENT)) { + path_free(rom_info_path); return ROM_ERR_SAVE_IO; } } - path_free(overrides_path); + path_free(rom_info_path); return ROM_OK; } rom_cic_type_t rom_info_get_cic_type (rom_info_t *rom_info) { - if (rom_info->override.cic) { - return rom_info->override.cic_type; + if (rom_info->boot_override.cic) { + return rom_info->boot_override.cic_type; } else { return rom_info->cic_type; } @@ -907,44 +918,44 @@ bool rom_info_get_cic_seed (rom_info_t *rom_info, uint8_t *seed) { *seed = cic_get_seed(cic_type); - return (!rom_info->override.cic); + return (!rom_info->boot_override.cic); } rom_err_t rom_info_override_cic_type (path_t *path, rom_info_t *rom_info, rom_cic_type_t cic_type) { - rom_info->override.cic = (cic_type != ROM_CIC_TYPE_AUTOMATIC); - rom_info->override.cic_type = cic_type; + rom_info->boot_override.cic = (cic_type != ROM_CIC_TYPE_AUTOMATIC); + rom_info->boot_override.cic_type = cic_type; - return save_override(path, "cic_type", rom_info->override.cic_type, ROM_CIC_TYPE_AUTOMATIC); + return save_override(path, "cic_type", rom_info->boot_override.cic_type, ROM_CIC_TYPE_AUTOMATIC); } rom_save_type_t rom_info_get_save_type (rom_info_t *rom_info) { - if (rom_info->override.save) { - return rom_info->override.save_type; + if (rom_info->boot_override.save) { + return rom_info->boot_override.save_type; } else { return rom_info->save_type; } } rom_err_t rom_info_override_save_type (path_t *path, rom_info_t *rom_info, rom_save_type_t save_type) { - rom_info->override.save = (save_type != SAVE_TYPE_AUTOMATIC); - rom_info->override.save_type = save_type; + rom_info->boot_override.save = (save_type != SAVE_TYPE_AUTOMATIC); + rom_info->boot_override.save_type = save_type; - return save_override(path, "save_type", rom_info->override.save_type, SAVE_TYPE_AUTOMATIC); + return save_override(path, "save_type", rom_info->boot_override.save_type, SAVE_TYPE_AUTOMATIC); } rom_tv_type_t rom_info_get_tv_type (rom_info_t *rom_info) { - if (rom_info->override.tv) { - return rom_info->override.tv_type; + if (rom_info->boot_override.tv) { + return rom_info->boot_override.tv_type; } else { return rom_info->tv_type; } } rom_err_t rom_info_override_tv_type (path_t *path, rom_info_t *rom_info, rom_tv_type_t tv_type) { - rom_info->override.tv = (tv_type != ROM_TV_TYPE_AUTOMATIC); - rom_info->override.tv_type = tv_type; + rom_info->boot_override.tv = (tv_type != ROM_TV_TYPE_AUTOMATIC); + rom_info->boot_override.tv_type = tv_type; - return save_override(path, "tv_type", rom_info->override.tv_type, ROM_TV_TYPE_AUTOMATIC); + return save_override(path, "tv_type", rom_info->boot_override.tv_type, ROM_TV_TYPE_AUTOMATIC); } rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info) { @@ -969,7 +980,7 @@ rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info) { extract_rom_info(&match, &rom_header, rom_info); - load_overrides(path, rom_info); + load_rom_info_from_file(path, rom_info); return ROM_OK; } diff --git a/src/menu/rom_info.h b/src/menu/rom_info.h index 731c6553..d95bc01c 100644 --- a/src/menu/rom_info.h +++ b/src/menu/rom_info.h @@ -199,7 +199,7 @@ typedef struct { /** @brief The TV type required by the ROM. */ rom_tv_type_t tv_type; - /** @brief Overrides of auto-detected CIC/save/TV types. */ + /** @brief Overrides the auto-detected CIC/save/TV types during rom boot. */ struct { bool cic; rom_cic_type_t cic_type; @@ -209,7 +209,7 @@ typedef struct { bool tv; rom_tv_type_t tv_type; - } override; + } boot_override; /** @brief The supported ROM accessories. */ struct { @@ -222,11 +222,23 @@ typedef struct { bool combo_rom_disk_game; rom_expansion_pak_t expansion_pak; } features; + + /** @brief The ROM settings. */ + struct { + bool cheats_enabled; + bool patches_enabled; + } settings; + + /** @brief The ROM metadata. */ + struct { + char description[256]; + } metadata; } rom_info_t; +bool rom_info_get_cic_seed (rom_info_t *rom_info, uint8_t *seed); +rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info); rom_cic_type_t rom_info_get_cic_type (rom_info_t *rom_info); -bool rom_info_get_cic_seed (rom_info_t *rom_info, uint8_t *seed); rom_err_t rom_info_override_cic_type (path_t *path, rom_info_t *rom_info, rom_cic_type_t cic_type); rom_save_type_t rom_info_get_save_type (rom_info_t *rom_info); @@ -235,7 +247,4 @@ rom_err_t rom_info_override_save_type (path_t *path, rom_info_t *rom_info, rom_s rom_tv_type_t rom_info_get_tv_type (rom_info_t *rom_info); rom_err_t rom_info_override_tv_type (path_t *path, rom_info_t *rom_info, rom_tv_type_t tv_type); -rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info); - - #endif diff --git a/src/menu/views/load_rom.c b/src/menu/views/load_rom.c index 36933b92..1a05540a 100644 --- a/src/menu/views/load_rom.c +++ b/src/menu/views/load_rom.c @@ -99,6 +99,10 @@ static const char *format_rom_expansion_pak_info (rom_expansion_pak_t expansion_ } } +static const char *format_rom_description(char *description) { + return description[0] == '\0' ? "None." : description; +} + static const char *format_cic_type (rom_cic_type_t cic_type) { switch (cic_type) { case ROM_CIC_TYPE_5101: return "5101"; @@ -118,6 +122,10 @@ static const char *format_cic_type (rom_cic_type_t cic_type) { } } +static const char *format_boolean_type (bool bool_value) { + return bool_value ? "On" : "Off"; +} + static void set_cic_type (menu_t *menu, void *arg) { rom_cic_type_t cic_type = (rom_cic_type_t) (arg); rom_err_t err = rom_info_override_cic_type(menu->load.rom_path, &menu->load.rom_info, cic_type); @@ -237,16 +245,20 @@ static void draw (menu_t *menu, surface_t *d) { "\n" "\n" "\n" - "Description:\n None.\n\n\n\n\n\n\n\n" + "Description:\n %s\n" + "\n\n\n\n\n\n\n" "Expansion PAK: %s\n" "TV type: %s\n" "CIC: %s\n" - "GS/AR Cheats: Off\n" - "Patches: Off\n" + "GS/AR Cheats: %s\n" + "Patches: %s\n" "Save type: %s\n", + format_rom_description(menu->load.rom_info.metadata.description), format_rom_expansion_pak_info(menu->load.rom_info.features.expansion_pak), format_rom_tv_type(rom_info_get_tv_type(&menu->load.rom_info)), format_cic_type(rom_info_get_cic_type(&menu->load.rom_info)), + format_boolean_type(menu->load.rom_info.settings.cheats_enabled), + format_boolean_type(menu->load.rom_info.settings.patches_enabled), format_rom_save_type(rom_info_get_save_type(&menu->load.rom_info), menu->load.rom_info.features.controller_pak) );