From 37f6352eec5033fa6c6d1eb7f9ac99d9e0282b4b Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 12 Apr 2023 00:10:24 +0000 Subject: [PATCH] Further work --- src/menu/menu_main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/menu/menu_main.c b/src/menu/menu_main.c index e46f0ba8..73f78db8 100644 --- a/src/menu/menu_main.c +++ b/src/menu/menu_main.c @@ -13,8 +13,8 @@ #include "menu_fileinfo.h" #include "rom_database.h" -static int scroll_menu_position = 0; -static int items_in_dir = 0; +static int scroll_menu_position = 1; +static int items_in_dir = 1; static FILINFO current_fileinfo; @@ -31,7 +31,7 @@ FRESULT scan_file_path (char* path) { DIR dir; char sfno[280]; int counter = 0; //FIXME: we dont account for an empty dir or only one valid file! - + res = f_opendir(&dir, path); if (res == FR_OK) { @@ -57,7 +57,7 @@ FRESULT scan_file_path (char* path) { ((file_info.fattrib & AM_HID) ? 'H' : '-'), (int)file_info.fsize, file_info.fname); - if (scroll_menu_position == counter -1) { + if (scroll_menu_position == counter) { printf("-> %s\n", sfno); current_fileinfo = file_info; } @@ -66,7 +66,7 @@ FRESULT scan_file_path (char* path) { } } } - items_in_dir = counter -1; + items_in_dir = counter; f_closedir(&dir); return res; } @@ -74,7 +74,8 @@ FRESULT scan_file_path (char* path) { void menu_main_refresh (char *dir_path) { console_clear(); printf("SC64 Flashcart Menu Rev: 0.0.2\n\n"); - printf("SD Card Directory list:\n\n"); + printf("SD Card Directory list: %s\n\n", dir_path); + printf("SD Card Directory files: %d of %d\n\n", scroll_menu_position, items_in_dir); printf(" | DRH | FILE SIZE | FILE NAME\n"); printf(" |-----|------------|----------\n"); scan_file_path(dir_path); @@ -112,7 +113,7 @@ void menu_main_init (settings_t *settings) { if (joypad.c[0].up) { //console_clear(); - if (scroll_menu_position > 0) { + if (scroll_menu_position > 1 && scroll_menu_position <= items_in_dir) { scroll_menu_position --; } else { @@ -123,11 +124,11 @@ void menu_main_init (settings_t *settings) { if (joypad.c[0].down) { //console_clear(); - if ((scroll_menu_position >= 0) && (scroll_menu_position < items_in_dir)) { + if (scroll_menu_position < items_in_dir) { scroll_menu_position ++; } else { - scroll_menu_position = 0; + scroll_menu_position = 1; } menu_main_refresh(current_dir); } @@ -150,10 +151,10 @@ void menu_main_init (settings_t *settings) { else { if (current_fileinfo.fattrib & AM_DIR) { // if this is a directory we need to transverse to it! + items_in_dir = 1; + scroll_menu_position = 1; last_dir = current_dir; current_dir = current_fileinfo.fname; - scroll_menu_position = 0; - items_in_dir = 0; menu_main_refresh(current_dir); } else {