mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-21 18:19:19 +01:00
improve handling
rename files
This commit is contained in:
parent
05173ca0f0
commit
4c6a030d29
2
Makefile
2
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 \
|
||||
|
10
src/main.c
10
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();
|
||||
|
||||
|
@ -1,77 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libdragon.h>
|
||||
#include <fatfs/ff.h>
|
||||
|
||||
#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
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#ifndef MENU_H__
|
||||
#define MENU_H__
|
||||
|
||||
|
||||
void menu_restore (settings_t *settings);
|
||||
void menu_run (settings_t *settings);
|
||||
|
||||
#endif
|
92
src/menu/menu_main.c
Normal file
92
src/menu/menu_main.c
Normal file
@ -0,0 +1,92 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
// #include <sys/stat.h>
|
||||
// #include <unistd.h>
|
||||
|
||||
#include <libdragon.h>
|
||||
#include <fatfs/ff.h>
|
||||
|
||||
#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
|
||||
|
||||
}
|
6
src/menu/menu_main.h
Normal file
6
src/menu/menu_main.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef MENU_MAIN_H__
|
||||
#define MENU_MAIN_H__
|
||||
|
||||
void menu_main_init (settings_t *settings);
|
||||
|
||||
#endif
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user