Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop] WiP: Autoload disks #170

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
9 changes: 9 additions & 0 deletions src/menu/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/menu/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
59 changes: 48 additions & 11 deletions src/menu/views/load_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "boot/boot.h"
#include "../sound.h"
#include "views.h"
#include <string.h>
#include "utils/fs.h"
#include <stdbool.h>


static component_boxart_t *boxart;

Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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"
);
}

Expand Down Expand Up @@ -117,20 +152,22 @@ 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));
return;
}
}

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) {
Expand Down
20 changes: 18 additions & 2 deletions src/menu/views/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading