Improvements in the USB init management code

This commit is contained in:
fabio.olimpieri 2011-06-10 21:44:13 +00:00
parent 07b3a3c166
commit 41d0826a4a
4 changed files with 30 additions and 32 deletions

View File

@ -24,7 +24,7 @@ FileBrowser::~FileBrowser()
void FileBrowser::pushDirectory(const char *in_path) void FileBrowser::pushDirectory(const char *in_path)
{ {
const char *cur = this->cur_path_prefix ? xstrdup(this->cur_path_prefix) : NULL; const char *cur = this->cur_path_prefix ? xstrdup(this->cur_path_prefix) : NULL;
size_t cur_len = this->cur_path_prefix ? strlen(this->cur_path_prefix) : NULL; size_t cur_len = this->cur_path_prefix ? strlen(this->cur_path_prefix) : 0;
char *path_cpy = xstrdup(in_path); char *path_cpy = xstrdup(in_path);
char *path = path_cpy; char *path = path_cpy;

View File

@ -1,7 +1,7 @@
#include "menu.hh" #include "menu.hh"
#include "dialogue_box.hh" #include "dialogue_box.hh"
extern int usbismount; extern bool usbismount;
class KeyboardTypingListener : public KeyboardListener, TimeoutHandler class KeyboardTypingListener : public KeyboardListener, TimeoutHandler
{ {
@ -70,7 +70,7 @@ public:
switch (which) switch (which)
{ {
case 0: /* Insert disc */ case 0: /* Insert disc */
if (Gui::gui->np->Usbport & usbismount) Gui::gui->dv->setDirectory(Gui::gui->game_base_path_usb); if (Gui::gui->np->Usbport && usbismount) Gui::gui->dv->setDirectory(Gui::gui->game_base_path_usb);
else Gui::gui->dv->setDirectory(Gui::gui->game_base_path); else Gui::gui->dv->setDirectory(Gui::gui->game_base_path);
Gui::gui->pushView(Gui::gui->dv); Gui::gui->pushView(Gui::gui->dv);

View File

@ -81,7 +81,7 @@ public:
void updateSubmenus() void updateSubmenus()
{ {
int submenu_defs[4]; int submenu_defs[5];
submenu_defs[0] = Gui::gui->np->JoystickSwap == true ? 0 : 1; submenu_defs[0] = Gui::gui->np->JoystickSwap == true ? 0 : 1;
submenu_defs[1] = !Gui::gui->np->Emul1541Proc; submenu_defs[1] = !Gui::gui->np->Emul1541Proc;

View File

@ -45,7 +45,7 @@ extern int init_graphics(void);
// Global variables // Global variables
C64 *TheC64 = NULL; // Global C64 object C64 *TheC64 = NULL; // Global C64 object
char AppDirPath[1024]; // Path of application directory char AppDirPath[1024]; // Path of application directory
int usbismount = 0; bool usbismount = false;
// ROM file names // ROM file names
#ifndef DATADIR #ifndef DATADIR
@ -83,31 +83,27 @@ int usbismount = 0;
#if defined(GEKKO) #if defined(GEKKO)
//init and deinit USB device functions //init and deinit USB device functions
//code taken from Arikado
int InitUSB() bool InitUSB()
{ {
printf("Initializing USB FAT subsytem ...\n\n"); printf("Initializing USB FAT subsytem ...\n\n");
fatUnmount("usb:"); fatUnmount("usb:");
// This should wake up the drive
bool isMounted = fatMountSimple("usb", &__io_usbstorage); bool isMounted = fatMountSimple("usb", &__io_usbstorage);
if(!isMounted) bool isInserted = __io_usbstorage.isInserted();
{ if (!isInserted) return false;
fatUnmount("usb:");
fatMountSimple("usb", &__io_usbstorage);
bool isInserted = __io_usbstorage.isInserted();
if(isInserted) // USB Drive may be "sleeeeping"
{ int retry = 10; // We need to try Mounting a few times to wake it up
while(retry) int retry = 10;
{ while (retry && !isMounted)
isMounted = fatMountSimple("usb", &__io_usbstorage); {
if (isMounted) break; sleep(1);
sleep(1); isMounted = fatMountSimple("usb", &__io_usbstorage);
retry--; retry--;
}
}
} }
return isMounted; return isMounted;
} }
@ -180,21 +176,23 @@ extern "C" int main(int argc, char **argv)
//initialize libfat library //initialize libfat library
if (!fatInitDefault()) if (!fatInitDefault())
{ {
printf("Couldn't initialize SD fat subsytem\n\n"); printf("Couldn't initialize SD fat subsytem\n\n");
sleep(3); sleep(3);
exit(0); exit(0);
} }
else
printf("SD FAT subsytem initialized\n\n");
usbismount = InitUSB(); usbismount = InitUSB();
if (usbismount) if (usbismount)
printf("USB FAT subsytem initialized\n"); printf("USB FAT subsytem initialized\n\n");
else else
printf("Impossible to initialize USB FAT subsytem\n"); printf("Impossible to initialize USB FAT subsytem\n\n");
sleep(2); sleep(3);
//create tmp directory if it does not exist //create tmp directory if it does not exist
dir_tmp = diropen("/frodo/tmp"); dir_tmp = diropen("/frodo/tmp");
if (!dir_tmp) {mkdir("/frodo/tmp",0777);printf("Making tmp directory\n");sleep(3);} else dirclose(dir_tmp); if (!dir_tmp) {mkdir("/frodo/tmp",0777);printf("Making tmp directory\n");sleep(2);} else dirclose(dir_tmp);
#endif #endif