diff --git a/file_io.c b/file_io.c index 80c3e59..075198a 100644 --- a/file_io.c +++ b/file_io.c @@ -17,6 +17,9 @@ #include "menu.h" #include "errno.h" #include "DiskImage.h" +#include "user_io.h" +#include "cfg.h" +#include "input.h" int nDirEntries = 0; struct dirent DirItem[1000]; @@ -321,12 +324,17 @@ int FileCanWrite(char *name) static int device = 0; static int usbnum = 0; +char *getStorageDir(int dev) +{ + static char path[32]; + if (!dev) return "/media/fat"; + sprintf(path, "/media/usb%d", usbnum); + return path; +} + char *getRootDir() { - static char dev[16]; - if(!device) return "/media/fat"; - sprintf(dev, "/media/usb%d", usbnum); - return dev; + return getStorageDir(device); } char *getFullPath(char *name) @@ -339,7 +347,7 @@ void setStorage(int dev) { device = 0; FileSave(CONFIG_DIR"/device.bin", &dev, sizeof(int)); - app_restart(); + fpga_load_rbf("menu.rbf"); } static int orig_device = 0; @@ -418,12 +426,19 @@ void FindStorage(void) if(device && !isUSBMounted()) { + int saveddev = device; + device = 0; + MiSTer_ini_parse(); + device = saveddev; + parse_video_mode(); + user_io_send_buttons(1); + printf("Waiting for USB...\n"); int btn = 0; int done = 0; for (int i = 30; i >= 0; i--) { - sprintf(str, "\n\n Waiting for USB...\n\n %d \n", i); + sprintf(str, "\n Waiting for USB...\n\n %d \n\n\n OSD/USER or ESC to cancel", i); InfoMessage(str); if (isUSBMounted()) { @@ -434,13 +449,13 @@ void FindStorage(void) for (int i = 0; i < 10; i++) { btn = fpga_get_buttons(); + if (!btn) btn = input_poll(1); if (btn) { printf("Button has been pressed %d\n", btn); InfoMessage("\n\n Canceled!\n"); usleep(500000); - device = 0; - done = 1; + setStorage(0); break; } usleep(100000); @@ -452,7 +467,7 @@ void FindStorage(void) { InfoMessage("\n\n No USB storage found\n Falling back to SD card\n"); usleep(2000000); - device = 0; + setStorage(0); } } diff --git a/file_io.h b/file_io.h index c025d99..f201999 100644 --- a/file_io.h +++ b/file_io.h @@ -75,6 +75,7 @@ int FileLoadConfig(char *name, void *pBuffer, int size); // supply pBuffer = 0 t void AdjustDirectory(char *path); int ScanDirectory(char* path, int mode, char *extension, int options); +char *getStorageDir(int dev); char *getRootDir(); char *getFullPath(char *name); diff --git a/fpga_io.c b/fpga_io.c index a77ce4c..b67b62e 100644 --- a/fpga_io.c +++ b/fpga_io.c @@ -452,7 +452,7 @@ int fpga_load_rbf(char *name) int ret = 0; printf("Loading RBF: %s\n", name); - sprintf(path, "%s/%s", getRootDir(), name); + sprintf(path, "%s/%s", !strcasecmp(name, "menu.rbf") ? getStorageDir(0) : getRootDir(), name); #ifdef REBOOT_ON_RBF_LOAD do_bridge(0); diff --git a/user_io.h b/user_io.h index 51e4b02..db4e592 100644 --- a/user_io.h +++ b/user_io.h @@ -207,4 +207,6 @@ void user_io_check_reset(unsigned short modifiers, char useKeys); void user_io_rtc_reset(); +void parse_video_mode(); + #endif // USER_IO_H