2023-02-14 22:26:40 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2023-02-22 19:28:09 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2023-02-14 22:26:40 +01:00
|
|
|
|
|
|
|
#include <libdragon.h>
|
2023-02-23 03:59:54 +01:00
|
|
|
#include <fatfs/ff.h>
|
2023-02-14 22:26:40 +01:00
|
|
|
|
|
|
|
#include "flashcart/flashcart.h"
|
|
|
|
|
2023-02-24 15:24:59 +01:00
|
|
|
#include "settings.h"
|
2023-02-14 22:26:40 +01:00
|
|
|
#include "menu.h"
|
|
|
|
|
2023-02-24 15:24:59 +01:00
|
|
|
void menu_restore (settings_t *settings) {
|
2023-02-14 22:26:40 +01:00
|
|
|
// TODO: restore last menu state from SD card
|
|
|
|
}
|
|
|
|
|
2023-02-23 03:59:54 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-24 15:24:59 +01:00
|
|
|
void menu_run (settings_t *settings) {
|
2023-02-14 22:26:40 +01:00
|
|
|
// TODO: implement nice user interface here
|
|
|
|
|
|
|
|
console_init();
|
|
|
|
console_set_debug(true);
|
|
|
|
|
2023-02-24 15:24:59 +01:00
|
|
|
if (settings->last_state.auto_load_last_rom) { // TODO: check if there is a button input to cancel.
|
2023-02-14 22:26:40 +01:00
|
|
|
|
2023-02-24 15:24:59 +01:00
|
|
|
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");
|
2023-02-14 22:26:40 +01:00
|
|
|
|
2023-02-24 15:24:59 +01:00
|
|
|
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");
|
2023-02-22 19:28:09 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("N64 Flashcart Menu\n\n");
|
2023-02-23 03:40:07 +01:00
|
|
|
printf("File list:\n");
|
2023-02-23 03:59:54 +01:00
|
|
|
char buff[256];
|
|
|
|
strcpy(buff, "/");
|
2023-02-24 15:24:59 +01:00
|
|
|
scan_files(buff); // TODO: use current_directory
|
2023-02-23 03:59:54 +01:00
|
|
|
|
2023-02-22 19:28:09 +01:00
|
|
|
// TODO: wait for a key input
|
2023-02-24 15:24:59 +01:00
|
|
|
for (;;) {
|
|
|
|
wait_ms(1000);
|
|
|
|
}
|
2023-02-22 19:28:09 +01:00
|
|
|
}
|
2023-02-14 22:26:40 +01:00
|
|
|
// TODO: write menu state to SD card
|
|
|
|
|
|
|
|
}
|