mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-22 02:29:19 +01:00
Add basic menu
This commit is contained in:
parent
3d77e24e58
commit
fc3e3c6c24
0
src/menu/extras.c
Normal file
0
src/menu/extras.c
Normal file
@ -1,7 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
// #include <sys/stat.h>
|
|
||||||
// #include <unistd.h>
|
|
||||||
|
|
||||||
#include <libdragon.h>
|
#include <libdragon.h>
|
||||||
#include <fatfs/ff.h>
|
#include <fatfs/ff.h>
|
||||||
@ -13,12 +11,23 @@
|
|||||||
#include "menu_info.h"
|
#include "menu_info.h"
|
||||||
#include "menu_fileinfo.h"
|
#include "menu_fileinfo.h"
|
||||||
|
|
||||||
|
static int scroll_menu_position = 0;
|
||||||
|
static int items_in_dir = 0;
|
||||||
|
static char current_filename[256];
|
||||||
|
|
||||||
|
// e.g. if (str_endswith(cur_rom, ".z64") || str_endswith(cur_rom, ".n64"))
|
||||||
|
static bool str_endswith(const char *str, const char *suffix) {
|
||||||
|
char *p = strstr(str, suffix);
|
||||||
|
return p && p[strlen(suffix)] == '\0';
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: use newlib rather than fatfs to do this!
|
// FIXME: use newlib rather than fatfs to do this!
|
||||||
FRESULT scan_file_path (char* path) {
|
FRESULT scan_file_path (char* path) {
|
||||||
|
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
DIR dir;
|
DIR dir;
|
||||||
char sfno[273];
|
char sfno[273];
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
res = f_opendir(&dir, path);
|
res = f_opendir(&dir, path);
|
||||||
|
|
||||||
@ -31,6 +40,8 @@ FRESULT scan_file_path (char* path) {
|
|||||||
if ((res != FR_OK) || (fno.fname[0] == 0)) {
|
if ((res != FR_OK) || (fno.fname[0] == 0)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
counter ++;
|
||||||
|
|
||||||
sprintf(sfno, "%c%c%c%c %10d %s/%s",
|
sprintf(sfno, "%c%c%c%c %10d %s/%s",
|
||||||
((fno.fattrib & AM_DIR) ? 'D' : '-'),
|
((fno.fattrib & AM_DIR) ? 'D' : '-'),
|
||||||
@ -38,10 +49,17 @@ FRESULT scan_file_path (char* path) {
|
|||||||
((fno.fattrib & AM_SYS) ? 'S' : '-'),
|
((fno.fattrib & AM_SYS) ? 'S' : '-'),
|
||||||
((fno.fattrib & AM_HID) ? 'H' : '-'),
|
((fno.fattrib & AM_HID) ? 'H' : '-'),
|
||||||
(int)fno.fsize, path, fno.fname);
|
(int)fno.fsize, path, fno.fname);
|
||||||
|
|
||||||
printf("%s\n", sfno);
|
if (scroll_menu_position == counter -1) {
|
||||||
|
printf("> %s\n", sfno);
|
||||||
|
sprintf(current_filename, "%s", fno.fname);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf(" %s\n", sfno);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
items_in_dir = counter -1;
|
||||||
f_closedir(&dir);
|
f_closedir(&dir);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -80,13 +98,41 @@ void menu_main_init (settings_t *settings) {
|
|||||||
controller_scan();
|
controller_scan();
|
||||||
joypad = get_keys_down();
|
joypad = get_keys_down();
|
||||||
|
|
||||||
|
if (joypad.c[0].up) {
|
||||||
|
console_clear();
|
||||||
|
if (scroll_menu_position > 0) {
|
||||||
|
scroll_menu_position --;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
scroll_menu_position = items_in_dir;
|
||||||
|
}
|
||||||
|
menu_main_refresh(settings->last_state.current_directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (joypad.c[0].down) {
|
||||||
|
console_clear();
|
||||||
|
if ((scroll_menu_position >= 0) && (scroll_menu_position < items_in_dir)) {
|
||||||
|
scroll_menu_position ++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
scroll_menu_position = 0;
|
||||||
|
}
|
||||||
|
menu_main_refresh(settings->last_state.current_directory);
|
||||||
|
}
|
||||||
|
|
||||||
if (joypad.c[0].A) {
|
if (joypad.c[0].A) {
|
||||||
console_clear();
|
console_clear();
|
||||||
printf("TODO: loading ROM...\n");
|
printf("Loading ROM...\n");
|
||||||
wait_ms(1000);
|
printf("%s\n", current_filename);
|
||||||
printf("Failed... Returning to menu...\n");
|
if (str_endswith(current_filename, ".z64") || str_endswith(current_filename, ".n64") || str_endswith(current_filename, ".v64")) {
|
||||||
wait_ms(1000);
|
assertf(flashcart_load_rom(current_filename) == FLASHCART_OK, "ROM load error");
|
||||||
menu_main_refresh(settings->last_state.current_directory);
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Failed... Returning to menu...\n");
|
||||||
|
wait_ms(1000);
|
||||||
|
menu_main_refresh(settings->last_state.current_directory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (joypad.c[0].start) { // FIXME: the START button on any controller!
|
if (joypad.c[0].start) { // FIXME: the START button on any controller!
|
||||||
console_clear();
|
console_clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user