diff --git a/Makefile b/Makefile index 20854d8f..1bf2aea2 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ SRCS = \ flashcart/flashcart.c \ flashcart/sc64/sc64_internal.c \ flashcart/sc64/sc64.c \ - menu/menu.c \ + menu/menu_main.c \ menu/settings.c \ utils/fs.c \ libs/toml/toml.c \ diff --git a/src/main.c b/src/main.c index 4bce174d..289d5af6 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ #include "boot/boot.h" #include "flashcart/flashcart.h" #include "menu/settings.h" -#include "menu/menu.h" +#include "menu/menu_main.h" static void init (void) { @@ -36,11 +36,11 @@ int main (void) { settings_load_default_state(&settings); settings_load_from_file(&settings); - if (boot_is_warm()) { - menu_restore(&settings); - } + // if (boot_is_warm()) { + // menu_restore(&settings); + // } - menu_run(&settings); + menu_main_init(&settings); deinit(); diff --git a/src/menu/menu.c b/src/menu/menu.c deleted file mode 100644 index 86d2c095..00000000 --- a/src/menu/menu.c +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#include "flashcart/flashcart.h" - -#include "settings.h" -#include "menu.h" - -void menu_restore (settings_t *settings) { - // TODO: restore last menu state from SD card -} - -FRESULT scan_files ( - char* path /* Start node to be scanned (***also used as work area***) */ -) -{ - FRESULT res; - DIR dir; - UINT i; - static FILINFO fno; - - - res = f_opendir(&dir, path); /* Open the directory */ - if (res == FR_OK) { - for (;;) { - res = f_readdir(&dir, &fno); /* Read a directory item */ - if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ - if (fno.fattrib & AM_DIR) { /* It is a directory */ - i = strlen(path); - sprintf(&path[i], "/%s", fno.fname); - res = scan_files(path); /* Enter the directory */ - if (res != FR_OK) break; - path[i] = 0; - } else { /* It is a file. */ - printf("%s/%s\n", path, fno.fname); - } - } - f_closedir(&dir); - } - - return res; -} - -void menu_run (settings_t *settings) { - // TODO: implement nice user interface here - - console_init(); - console_set_debug(true); - - if (settings->last_state.auto_load_last_rom) { // TODO: check if there is a button input to cancel. - - printf("Loading last ROM: %s\n", settings->last_rom.rom_path); - assertf(flashcart_load_rom(settings->last_rom.rom_path) == FLASHCART_OK, "ROM load error"); - - printf("Loading save: %s, type: %d, writeback: %d\n", settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback); - assertf(flashcart_load_save(settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback) == FLASHCART_OK, "Save load error"); - } - else { - printf("N64 Flashcart Menu\n\n"); - printf("File list:\n"); - char buff[256]; - strcpy(buff, "/"); - scan_files(buff); // TODO: use current_directory - - // TODO: wait for a key input - for (;;) { - wait_ms(1000); - } - } - // TODO: write menu state to SD card - -} diff --git a/src/menu/menu.h b/src/menu/menu.h deleted file mode 100644 index 804725d3..00000000 --- a/src/menu/menu.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef MENU_H__ -#define MENU_H__ - - -void menu_restore (settings_t *settings); -void menu_run (settings_t *settings); - -#endif diff --git a/src/menu/menu_main.c b/src/menu/menu_main.c new file mode 100644 index 00000000..a75e0122 --- /dev/null +++ b/src/menu/menu_main.c @@ -0,0 +1,92 @@ +#include +#include +// #include +// #include + +#include +#include + +#include "flashcart/flashcart.h" + +#include "settings.h" +#include "menu_main.h" + +// FIXME: use newlib rather than fatfs to do this! +FRESULT scan_file_path (char* path) { + + FRESULT res; + DIR dir; + char sfno[273]; + + res = f_opendir(&dir, path); + + if (res == FR_OK) { + for (;;) { + FILINFO fno; + + res = f_readdir(&dir, &fno); + + if ((res != FR_OK) || (fno.fname[0] == 0)) { + break; + } + + sprintf(sfno, "%c%c%c%c %10d %s/%s", + ((fno.fattrib & AM_DIR) ? 'D' : '-'), + ((fno.fattrib & AM_RDO) ? 'R' : '-'), + ((fno.fattrib & AM_SYS) ? 'S' : '-'), + ((fno.fattrib & AM_HID) ? 'H' : '-'), + (int)fno.fsize, path, fno.fname); + + printf("%s\n", sfno); + } + } + f_closedir(&dir); + return res; +} + +void menu_main_refresh (char *dir_path) { + console_clear(); + printf("N64 Flashcart Menu\n\n"); + printf("SD Card Directory list:\n\n"); + scan_file_path(dir_path); +} + +void menu_main_init (settings_t *settings) { + // TODO: implement nice user interface here + + console_init(); + console_set_debug(true); + + controller_init(); + + + // TODO: wait for a key input + + if (settings->last_state.auto_load_last_rom) { // TODO: check if there is a button input to cancel. + + printf("Loading last ROM: %s\n", settings->last_rom.rom_path); + assertf(flashcart_load_rom(settings->last_rom.rom_path) == FLASHCART_OK, "ROM load error"); + + printf("Loading save: %s, type: %d, writeback: %d\n", settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback); + assertf(flashcart_load_save(settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback) == FLASHCART_OK, "Save load error"); + } + else { + menu_main_refresh(settings->last_state.current_directory); + } + + for (;;) { + controller_scan(); + struct controller_data ckeys = get_keys_down(); + + if (ckeys.c[0].A) { + console_clear(); + printf("TODO: loading ROM...\n"); + wait_ms(1000); + printf("Failed... Returning to menu...\n"); + wait_ms(1000); + menu_main_refresh(settings->last_state.current_directory); + } + } + // TODO: write menu state to SD card + +} diff --git a/src/menu/menu_main.h b/src/menu/menu_main.h new file mode 100644 index 00000000..f8f8332c --- /dev/null +++ b/src/menu/menu_main.h @@ -0,0 +1,6 @@ +#ifndef MENU_MAIN_H__ +#define MENU_MAIN_H__ + +void menu_main_init (settings_t *settings); + +#endif diff --git a/src/menu/settings.c b/src/menu/settings.c index 89d9747b..aabc0306 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -155,7 +155,7 @@ void settings_load_default_state(settings_t *settings) { settings->last_rom.save_type = FLASHCART_SAVE_TYPE_NONE; settings->last_rom.save_writeback = false; - settings->last_state.current_directory = "sd://"; + settings->last_state.current_directory = "/"; // This must not include the trailing slash on dirs! settings->last_state.auto_load_last_rom = false; settings->boot_params.device_type = BOOT_DEVICE_TYPE_ROM;