diff --git a/src/menu/settings.c b/src/menu/settings.c index 703871aab..998b60c4f 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -15,8 +15,11 @@ static settings_t init = { .use_saves_folder = true, .soundfx_enabled = false, .rom_autoload_enabled = false, + .disk_autoload_enabled = false, .rom_autoload_path = "", + .disk_autoload_path = "", .rom_autoload_filename = "", + .disk_autoload_filename = "", /* Beta feature flags (should always init to off) */ .bgm_enabled = false, @@ -45,8 +48,11 @@ void settings_load (settings_t *settings) { settings->soundfx_enabled = mini_get_bool(ini, "menu", "soundfx_enabled", init.soundfx_enabled); settings->rom_autoload_enabled = mini_get_bool(ini, "menu", "autoload_rom_enabled", init.rom_autoload_enabled); + settings->disk_autoload_enabled = mini_get_bool(ini, "menu", "autoload_rom_enabled", init.rom_autoload_enabled); settings->rom_autoload_path = strdup(mini_get_string(ini, "autoload", "rom_path", init.rom_autoload_path)); + settings->disk_autoload_path = strdup(mini_get_string(ini, "autoload", "disk_path", init.disk_autoload_path)); settings->rom_autoload_filename = strdup(mini_get_string(ini, "autoload", "rom_filename", init.rom_autoload_filename)); + settings->disk_autoload_filename = strdup(mini_get_string(ini, "autoload", "disk_filename", init.disk_autoload_filename)); /* 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); @@ -64,8 +70,11 @@ void settings_save (settings_t *settings) { mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder); mini_set_bool(ini, "menu", "soundfx_enabled", settings->soundfx_enabled); mini_set_bool(ini, "menu", "autoload_rom_enabled", settings->rom_autoload_enabled); + mini_set_bool(ini, "menu", "autoload_disk_enabled", settings->disk_autoload_enabled); mini_set_string(ini, "autoload", "rom_path", settings->rom_autoload_path); + mini_set_string(ini, "autoload", "disk_path", settings->disk_autoload_path); mini_set_string(ini, "autoload", "rom_filename", settings->rom_autoload_filename); + mini_set_string(ini, "autoload", "disk_filename", settings->disk_autoload_filename); /* Beta feature flags, they should not save until production ready! */ // mini_set_bool(ini, "menu_beta_flag", "bgm_enabled", settings->bgm_enabled); diff --git a/src/menu/settings.h b/src/menu/settings.h index 26454412b..afba61270 100644 --- a/src/menu/settings.h +++ b/src/menu/settings.h @@ -34,12 +34,21 @@ typedef struct { /** @brief Enable the ability to bypass the menu and instantly load a ROM */ bool rom_autoload_enabled; + /** @brief Enable the ability to bypass the menu and instantly load a Disk (with ROM if also enabled) */ + bool disk_autoload_enabled; + /** @brief A path to the autoloaded ROM */ char *rom_autoload_path; + /** @brief A path to the autoloaded DD image */ + char *disk_autoload_path; + /** @brief A filename of the autoloaded ROM */ char *rom_autoload_filename; + /** @brief A filename of the autoloaded DD image */ + char *disk_autoload_filename; + } settings_t; diff --git a/src/menu/views/load_disk.c b/src/menu/views/load_disk.c index 359812f7d..a1268f28a 100644 --- a/src/menu/views/load_disk.c +++ b/src/menu/views/load_disk.c @@ -3,6 +3,10 @@ #include "boot/boot.h" #include "../sound.h" #include "views.h" +#include +#include "utils/fs.h" +#include + static component_boxart_t *boxart; @@ -25,14 +29,45 @@ static char *format_disk_region (disk_region_t region) { } } +static void set_autoload_type (menu_t *menu, void *arg) { + bool combined_disk_rom = (bool)(uintptr_t)(arg); + free(menu->settings.disk_autoload_path); + menu->settings.disk_autoload_path = strdup(strip_fs_prefix(path_get(menu->browser.directory))); + free(menu->settings.disk_autoload_filename); + menu->settings.disk_autoload_filename = strdup(menu->browser.entry->name); + if (combined_disk_rom) { // FIXME: we need to get this from menu->load.rom_path + // free(menu->settings.rom_autoload_path); + // menu->settings.rom_autoload_path = strdup(strip_fs_prefix(path_get(menu->browser.directory))); // path_last_get(menu->load.rom_path) + // free(menu->settings.rom_autoload_filename); + // menu->settings.rom_autoload_filename = strdup(menu->browser.entry->name); + } + // FIXME: add a confirmation box here! (press start on reboot) + menu->settings.disk_autoload_enabled = true; + settings_save(&menu->settings); + menu->browser.reload = true; +} + +static void set_load_combined_disk_rom_type(menu_t *menu, void *arg) { + menu->boot_pending.disk_file = true; + menu->load.combined_disk_rom = true; +} + +static component_context_menu_t options_context_menu = { .list = { + { .text = "Load with ROM", .action = set_load_combined_disk_rom_type }, // TODO: this is for backwards compatibility, is it really needed?! + { .text = "Set disk to autoload", .action = set_autoload_type, .arg = (void *)(uintptr_t)(false) }, + //{ .text = "Set disk & ROM to autoload", .action = set_autoload_type, .arg = (void *)(uintptr_t)(true) }, // FIXME: handle ROM expansions! + COMPONENT_CONTEXT_MENU_LIST_END, +}}; static void process (menu_t *menu) { if (menu->actions.enter) { menu->boot_pending.disk_file = true; menu->load.combined_disk_rom = false; + } else if (menu->actions.options) { + ui_components_context_menu_show(&options_context_menu); + sound_play_effect(SFX_SETTING); } else if (menu->actions.lz_context && menu->load.rom_path) { - menu->boot_pending.disk_file = true; - menu->load.combined_disk_rom = true; + set_load_combined_disk_rom_type(menu, NULL); sound_play_effect(SFX_SETTING); } else if (menu->actions.back) { sound_play_effect(SFX_EXIT); @@ -74,8 +109,8 @@ static void draw (menu_t *menu, surface_t *d) { menu->load.disk_info.id, menu->load.disk_info.version, menu->load.disk_info.disk_type, - menu->load.rom_path ? "ROM: " : "", - menu->load.rom_path ? path_last_get(menu->load.rom_path) : "" + menu->load.rom_path ? "Expansion ROM: " : "", + menu->load.rom_path ? path_last_get(menu->load.rom_path) : "" // We should check this against the ROM DB to see if it is FEAT_64DD_ENHANCED from extract_rom_info?! ); ui_components_actions_bar_text_draw( @@ -88,7 +123,7 @@ static void draw (menu_t *menu, surface_t *d) { ui_components_actions_bar_text_draw( ALIGN_RIGHT, VALIGN_TOP, "L|Z: Load with ROM\n" - "\n" + "R: Options\n" ); } @@ -117,7 +152,15 @@ static void draw_progress (float progress) { static void load (menu_t *menu) { cart_load_err_t err; + err = cart_load_64dd_ipl_and_disk(menu, draw_progress); + if (err != CART_LOAD_OK) { + menu_show_error(menu, cart_load_convert_error_message(err)); + return; + } + if (menu->load.rom_path && menu->load.combined_disk_rom) { + // FIXME: if the ROM is not a DD expansion ROM, it will just load the ROM. We need to check and warn! + // something involving: menu->load.rom_info.game_code[0] != 'C' or 'E' or homebrew ... (FEAT_64DD_ENHANCED) from extract_rom_info err = cart_load_n64_rom_and_save(menu, draw_progress); if (err != CART_LOAD_OK) { menu_show_error(menu, cart_load_convert_error_message(err)); @@ -125,12 +168,6 @@ static void load (menu_t *menu) { } } - err = cart_load_64dd_ipl_and_disk(menu, draw_progress); - if (err != CART_LOAD_OK) { - menu_show_error(menu, cart_load_convert_error_message(err)); - return; - } - menu->next_mode = MENU_MODE_BOOT; if (menu->load.combined_disk_rom) { diff --git a/src/menu/views/startup.c b/src/menu/views/startup.c index c12a90450..83280a531 100644 --- a/src/menu/views/startup.c +++ b/src/menu/views/startup.c @@ -14,14 +14,30 @@ void view_startup_init (menu_t *menu) { joypad_poll(); joypad_buttons_t b_held = joypad_get_buttons_held(port); - if (menu->settings.rom_autoload_enabled && b_held.start) { + if ((menu->settings.rom_autoload_enabled || menu->settings.disk_autoload_enabled) && b_held.start) { menu->settings.rom_autoload_enabled = false; + menu->settings.disk_autoload_enabled = false; menu->settings.rom_autoload_path = ""; + menu->settings.disk_autoload_path = ""; menu->settings.rom_autoload_filename = ""; + menu->settings.disk_autoload_filename = ""; settings_save(&menu->settings); } } - if (menu->settings.rom_autoload_enabled) { + if (menu->settings.disk_autoload_enabled) { // Disk takes priority over ROM, especially when both are enabled. + menu->browser.directory = path_init(menu->storage_prefix, menu->settings.disk_autoload_path); + menu->load.disk_path = path_clone_push(menu->browser.directory, menu->settings.disk_autoload_filename); + menu->boot_pending.disk_file = true; + if (menu->settings.rom_autoload_enabled) { + menu->browser.directory = path_init(menu->storage_prefix, menu->settings.rom_autoload_path); + menu->load.rom_path = path_clone_push(menu->browser.directory, menu->settings.rom_autoload_filename); + menu->load.combined_disk_rom = true; + } + menu->next_mode = MENU_MODE_LOAD_DISK; + + return; + } + else if (menu->settings.rom_autoload_enabled) { menu->browser.directory = path_init(menu->storage_prefix, menu->settings.rom_autoload_path); menu->load.rom_path = path_clone_push(menu->browser.directory, menu->settings.rom_autoload_filename); menu->boot_pending.rom_file = true;