From 3e13e886c7f672786cbecf7d8cab06a2d7c92f6e Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sun, 17 Dec 2023 16:51:24 +0000 Subject: [PATCH] Add ability to force tv region based on detected ROM (#71) ## Description Add ability to force tv region based on detected ROM based on the ROM's destination code. Adds a setting so that this can be turned off (on by default). ## Motivation and Context #66 ## How Has This Been Tested? ## Screenshots ## Types of changes - [x] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [ ] Breaking change (breaking change) - [ ] Config and build (change in the configuration and build system, has no impact on code or features) ## Checklist: - [ ] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. Signed-off-by: GITHUB_USER --- src/menu/settings.c | 13 +++++++----- src/menu/settings.h | 3 +++ src/menu/views/load_rom.c | 42 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/menu/settings.c b/src/menu/settings.c index 882293c6..569f32d2 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -13,11 +13,12 @@ static settings_t init = { .hidden_files_enabled = false, .default_directory = "/", .use_saves_folder = true, + .autodetect_rom_region = true, - /* Beta feature flags */ + /* Beta feature flags (should always init to off) */ .bgm_enabled = false, .sound_enabled = false, - .rumble_enabled = true, + .rumble_enabled = false, }; @@ -32,6 +33,7 @@ void settings_load (settings_t *settings) { settings->hidden_files_enabled = mini_get_bool(ini, "menu", "show_hidden_files", init.hidden_files_enabled); settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory)); settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder); + settings->autodetect_rom_region = mini_get_bool(ini, "menu", "autodetect_rom_region", init.autodetect_rom_region); /* Beta feature flags, they might not be in the file */ settings->bgm_enabled = mini_get_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled); @@ -49,11 +51,12 @@ void settings_save (settings_t *settings) { mini_set_bool(ini, "menu", "show_hidden_files", settings->hidden_files_enabled); mini_set_string(ini, "menu", "default_directory", settings->default_directory); mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder); + mini_set_bool(ini, "menu", "autodetect_rom_region", settings->autodetect_rom_region); /* Beta feature flags, they should not save until production ready! */ - // mini_set_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled); - // mini_set_bool(ini, "menu_beta_flag", "sound_enabled", init.sound_enabled); - // mini_set_bool(ini, "menu_beta_flag", "rumble_enabled", init.rumble_enabled); + // mini_set_bool(ini, "menu_beta_flag", "bgm_enabled", settings->bgm_enabled); + // mini_set_bool(ini, "menu_beta_flag", "sound_enabled", settings->sound_enabled); + // mini_set_bool(ini, "menu_beta_flag", "rumble_enabled", settings->rumble_enabled); mini_save(ini, MINI_FLAGS_SKIP_EMPTY_GROUPS); diff --git a/src/menu/settings.h b/src/menu/settings.h index 20096d25..61ecf919 100644 --- a/src/menu/settings.h +++ b/src/menu/settings.h @@ -22,6 +22,9 @@ typedef struct { /** @brief Put saves into separate directory */ bool use_saves_folder; + /** @brief Enable forcing the (N64 system region) tv type to align with game region when booting the ROM. */ + bool autodetect_rom_region; + /** @brief Enable Background music */ bool bgm_enabled; diff --git a/src/menu/views/load_rom.c b/src/menu/views/load_rom.c index 9c5c4dca..1e072497 100644 --- a/src/menu/views/load_rom.c +++ b/src/menu/views/load_rom.c @@ -107,6 +107,40 @@ static const char *format_cic_type (cic_type_t cic_type) { } } +static boot_tv_type_t determine_tv_boot_type (destination_type_t rom_destination_code) { + // check the market type from the ROM destination_code and return best guess! + switch (rom_destination_code) { + case MARKET_NORTH_AMERICA: + case MARKET_JAPANESE: + case MARKET_JAPANESE_MULTI: + case MARKET_GATEWAY64_NTSC: + return BOOT_TV_TYPE_NTSC; + case MARKET_BRAZILIAN: + return BOOT_TV_TYPE_MPAL; + case MARKET_GERMAN: + case MARKET_FRENCH: + case MARKET_DUTCH: + case MARKET_ITALIAN: + case MARKET_SPANISH: + case MARKET_AUSTRALIAN: + case MARKET_SCANDINAVIAN: + case MARKET_GATEWAY64_PAL: + case MARKET_EUROPEAN_BASIC: + // FIXME: There might be some interesting errors with OTHER_X and OTHER_Y (e.g. TGR Asia). + // But they are mainly PAL regions. + case MARKET_OTHER_X: + case MARKET_OTHER_Y: + return BOOT_TV_TYPE_PAL; + // FIXME: We cannot be sure on these markets, so just return the default for the moment! + case MARKET_CHINESE: + case MARKET_CANADIAN: + case MARKET_KOREAN: + case MARKET_OTHER_Z: + default: + return BOOT_TV_TYPE_PASSTHROUGH; + } +} + static void process (menu_t *menu) { if (menu->actions.enter) { @@ -206,8 +240,14 @@ static void load (menu_t *menu) { menu->next_mode = MENU_MODE_BOOT; menu->boot_params->device_type = BOOT_DEVICE_TYPE_ROM; - menu->boot_params->tv_type = BOOT_TV_TYPE_PASSTHROUGH; menu->boot_params->detect_cic_seed = true; + + if (menu->settings.autodetect_rom_region) { + menu->boot_params->tv_type = determine_tv_boot_type(menu->load.rom_info.destination_code); + } + else { + menu->boot_params->tv_type = BOOT_TV_TYPE_PASSTHROUGH; + } } static void deinit (void) {