From 9da4d08661d4b1834d74e1df9295f74461e36a7f Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 4 Dec 2024 19:18:56 +0000 Subject: [PATCH] Add ability to autoload disks BREAKING CHANGES: context button has changed for loading expansion ROM's TODO: does not yet autoload disk with ROM --- src/menu/settings.c | 9 +++++++++ src/menu/settings.h | 9 +++++++++ src/menu/views/load_disk.c | 28 +++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/menu/settings.c b/src/menu/settings.c index 5361f0a6..f600ad42 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -16,7 +16,10 @@ static settings_t init = { .sound_enabled = true, .rom_autoload_enabled = false, .rom_autoload_path = "", + .disk_autoload_path = "", .rom_autoload_filename = "", + .disk_autoload_filename = "", + .autoload_disk_uses_rom = false, /* Beta feature flags (should always init to off) */ .bgm_enabled = false, @@ -46,7 +49,10 @@ void settings_load (settings_t *settings) { settings->rom_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)); + settings->autoload_disk_uses_rom = mini_get_bool(ini, "autoload", "disk_uses_rom", init.autoload_disk_uses_rom); /* 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); @@ -65,7 +71,10 @@ void settings_save (settings_t *settings) { mini_set_bool(ini, "menu", "sound_enabled", settings->sound_enabled); mini_set_bool(ini, "menu", "autoload_rom_enabled", settings->rom_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); + mini_set_bool(ini, "autoload", "disk_uses_rom", settings->autoload_disk_uses_rom); /* 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 471879eb..6ce34af4 100644 --- a/src/menu/settings.h +++ b/src/menu/settings.h @@ -37,9 +37,18 @@ typedef struct { /** @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; + + /** @brief Load a DD image with a ROM compatible with expansion */ + bool autoload_disk_uses_rom; + } settings_t; diff --git a/src/menu/views/load_disk.c b/src/menu/views/load_disk.c index c1e24a79..026cbc79 100644 --- a/src/menu/views/load_disk.c +++ b/src/menu/views/load_disk.c @@ -3,6 +3,8 @@ #include "boot/boot.h" #include "../sound.h" #include "views.h" +#include +#include "utils/fs.h" static bool load_disk_with_rom; @@ -27,12 +29,31 @@ static char *format_disk_region (disk_region_t region) { } } +static void set_autoload_type (menu_t *menu, void *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); + // FIXME: add a confirmation box here! (press start on reboot) + menu->settings.rom_autoload_enabled = true; + settings_save(&menu->settings); + menu->browser.reload = true; +} + +static component_context_menu_t options_context_menu = { .list = { + { .text = "Set disk to autoload", .action = set_autoload_type }, + //{ .text = "Set DD Exp to autoload", .action = set_autoload_type }, // 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; load_disk_with_rom = false; - } else if (menu->actions.options && menu->load.rom_path) { + } 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; load_disk_with_rom = true; sound_play_effect(SFX_SETTING); @@ -76,7 +97,7 @@ 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 ? "Associated ROM: " : "", menu->load.rom_path ? path_last_get(menu->load.rom_path) : "" ); @@ -89,7 +110,8 @@ static void draw (menu_t *menu, surface_t *d) { if (menu->load.rom_path) { ui_components_actions_bar_text_draw( ALIGN_RIGHT, VALIGN_TOP, - "R: Load with ROM" + "L|Z: Load with ROM" + "R: Options" ); }