From 09cb10dfb678aebcb0550d876857c03038112896 Mon Sep 17 00:00:00 2001 From: dborth Date: Fri, 8 Aug 2008 07:57:01 +0000 Subject: [PATCH] -add functions to auto-determine load/save device -libfat cleanup, add sd gecko support -tweak to mouse code --- source/ngc/cheatmgr.cpp | 9 +++-- source/ngc/fileop.cpp | 56 +++++++++++++++++++++---- source/ngc/fileop.h | 5 ++- source/ngc/filesel.cpp | 83 +++++++++++++------------------------- source/ngc/mcsave.cpp | 59 ++++++++++++++++++++++----- source/ngc/mcsave.h | 3 +- source/ngc/memfile.cpp | 23 ++++------- source/ngc/menu.cpp | 9 ++--- source/ngc/preferences.cpp | 63 +++++++++++++---------------- source/ngc/snes9xGX.cpp | 14 ++++--- source/ngc/sram.cpp | 13 ++---- 11 files changed, 188 insertions(+), 149 deletions(-) diff --git a/source/ngc/cheatmgr.cpp b/source/ngc/cheatmgr.cpp index 1e5594f..96380e9 100644 --- a/source/ngc/cheatmgr.cpp +++ b/source/ngc/cheatmgr.cpp @@ -30,10 +30,11 @@ SetupCheats() char cheatFile[150] = { '\0' }; - if(GCSettings.SaveMethod == METHOD_SD) - sprintf (cheatFile, "%s/snes9x/cheats/%s.cht", ROOTSDDIR, Memory.ROMFilename); - else if(GCSettings.SaveMethod == METHOD_USB) - sprintf (cheatFile, "%s/snes9x/cheats/%s.cht", ROOTUSBDIR, Memory.ROMFilename); + if(GCSettings.SaveMethod == METHOD_SD || GCSettings.SaveMethod == METHOD_USB) + { + changeFATInterface(GCSettings.SaveMethod); + sprintf (cheatFile, "%s/snes9x/cheats/%s.cht", ROOTFATDIR, Memory.ROMFilename); + } // load cheat file if present if(strlen(cheatFile) > 0) diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 248be48..37e36cc 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -51,6 +51,52 @@ bool fat_is_mounted(PARTITION_INTERFACE partition) { return false; } +/**************************************************************************** + * changeFATInterface + * Checks if the device (method) specified is available, and + * sets libfat to use the device +****************************************************************************/ +bool changeFATInterface(int method) +{ + bool devFound = false; + + if(method == METHOD_SD) + { + // check which SD device is loaded + + #ifdef HW_RVL + if (fat_is_mounted(PI_INTERNAL_SD)) + { + devFound = true; + fatSetDefaultInterface(PI_INTERNAL_SD); + } + #endif + + if (!devFound && fat_is_mounted(PI_SDGECKO_A)) + { + devFound = true; + fatSetDefaultInterface(PI_SDGECKO_A); + } + if(!devFound && fat_is_mounted(PI_SDGECKO_B)) + { + devFound = true; + fatSetDefaultInterface(PI_SDGECKO_B); + } + } + else if(method == METHOD_USB) + { + #ifdef HW_RVL + if(fat_is_mounted(PI_USBSTORAGE)) + { + devFound = true; + fatSetDefaultInterface(PI_USBSTORAGE); + } + #endif + } + + return devFound; +} + /**************************************************************************** * fat_enable_readahead_all ****************************************************************************/ @@ -160,10 +206,7 @@ int updateFATdirname(int method) sprintf(temp, "/%s/..", GCSettings.LoadFolder); if (strcmp(currFATdir, temp) == 0) { - if(method == METHOD_SD) - sprintf(currFATdir,"%s",ROOTSDDIR); - else - sprintf(currFATdir,"%s",ROOTUSBDIR); + sprintf(currFATdir,"%s",ROOTFATDIR); } /* update current directory name */ @@ -200,10 +243,7 @@ int parseFATdirectory(int method) WaitPrompt(msg); // if we can't open the previous dir, open root dir - if(method == METHOD_SD) - sprintf(currFATdir,"%s",ROOTSDDIR); - else - sprintf(currFATdir,"%s",ROOTUSBDIR); + sprintf(currFATdir,"%s",ROOTFATDIR); fatdir = diropen(currFATdir); diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index 0c4bc6f..46f7aeb 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -21,10 +21,11 @@ #include #include -#define ROOTSDDIR "fat3:/" -#define ROOTUSBDIR "fat4:/" +#define ROOTFATDIR "fat:/" bool fat_remount(PARTITION_INTERFACE partition); +bool fat_is_mounted(PARTITION_INTERFACE partition); +bool changeFATInterface(int method); static int FileSortCallback(const void *f1, const void *f2); int updateFATdirname(int method); int parseFATdirectory(int method); diff --git a/source/ngc/filesel.cpp b/source/ngc/filesel.cpp index 3158657..a3b17ef 100644 --- a/source/ngc/filesel.cpp +++ b/source/ngc/filesel.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include "snes9x.h" #include "memmap.h" @@ -51,67 +50,43 @@ extern int screenheight; extern FILEENTRIES filelist[MAXFILES]; /**************************************************************************** -* Auto-determines the load method -* THIS CODE STILL NEEDS WORK +* autoLoadMethod() +* Auto-determines and sets the load method +* Returns method set ****************************************************************************/ int autoLoadMethod() { - return METHOD_SD; + if(changeFATInterface(METHOD_SD)) + return METHOD_SD; + else if(changeFATInterface(METHOD_USB)) + return METHOD_USB; + else + { + WaitPrompt((char*) "Unable to auto-determine load method!"); + return 0; // no method found + } } /**************************************************************************** -* Auto-determines the save method -* THIS CODE STILL NEEDS WORK +* autoSaveMethod() +* Auto-determines and sets the save method +* Returns method set ****************************************************************************/ int autoSaveMethod() { - return METHOD_SD; - int method = -1; - - while(method < 0) + if(changeFATInterface(METHOD_SD)) + return METHOD_SD; + else if(changeFATInterface(METHOD_USB)) + return METHOD_USB; + else if(TestCard(CARD_SLOTA, NOTSILENT)) + return METHOD_MC_SLOTA; + else if(TestCard(CARD_SLOTB, NOTSILENT)) + return METHOD_MC_SLOTB; + else { - WaitPrompt((char*) "Checking SD"); - - if(diropen(ROOTSDDIR)) - { - WaitPrompt((char*) "Found SD!"); - method = METHOD_SD; - break; - } - - WaitPrompt((char*) "Checking USB"); - - if(diropen(ROOTUSBDIR)) - { - WaitPrompt((char*) "Found USB!"); - method = METHOD_USB; - break; - } - - WaitPrompt((char*) "Checking Slot A"); - - // check Memory Card Slot A - if(MountCard(CARD_SLOTA, SILENT) == 0) - { - WaitPrompt((char*) "Found Memory Card A!"); - method = METHOD_MC_SLOTA; - break; - } - WaitPrompt((char*) "Checking Slot B"); - - // check Memory Card Slot B - if(MountCard(CARD_SLOTB, SILENT) == 0) - { - WaitPrompt((char*) "Found Memory Card B!"); - method = METHOD_MC_SLOTB; - break; - } - - // no method found - WaitPrompt((char*) "Error: Could not determine save method."); - method = 0; + WaitPrompt((char*) "Unable to auto-determine save method!"); + return 0; // no method found } - return method; } /**************************************************************************** @@ -534,10 +509,8 @@ OpenFAT (int method) havedir = 0; // gamecube only /* change current dir to snes roms directory */ - if(method == METHOD_SD) - sprintf ( currFATdir, "%s/%s", ROOTSDDIR, GCSettings.LoadFolder ); - else - sprintf ( currFATdir, "%s/%s", ROOTUSBDIR, GCSettings.LoadFolder ); + changeFATInterface(GCSettings.LoadMethod); + sprintf ( currFATdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder ); /* Parse initial root directory and get entries list */ if ((maxfiles = parseFATdirectory (method))) diff --git a/source/ngc/mcsave.cpp b/source/ngc/mcsave.cpp index e312bde..62f45fe 100644 --- a/source/ngc/mcsave.cpp +++ b/source/ngc/mcsave.cpp @@ -66,18 +66,57 @@ ClearSaveBuffer () int CardFileExists (char *filename, int slot) { - int CardError; + int CardError; - CardError = CARD_FindFirst (slot, &CardDir, TRUE); - while (CardError != CARD_ERROR_NOFILE) - { - CardError = CARD_FindNext (&CardDir); + CardError = CARD_FindFirst (slot, &CardDir, TRUE); + while (CardError != CARD_ERROR_NOFILE) + { + CardError = CARD_FindNext (&CardDir); - if (strcmp ((char *) CardDir.filename, filename) == 0) - return 1; - } + if (strcmp ((char *) CardDir.filename, filename) == 0) + return 1; + } - return 0; + return 0; +} + +/**************************************************************************** + * TestCard + * + * Checks to see if a card is in the card slot specified + ****************************************************************************/ +bool TestCard(int slot, bool silent) +{ + /*** Initialize Card System ***/ + memset (SysArea, 0, CARD_WORKAREA); + CARD_Init ("SNES", "00"); + + /*** Try to mount the card ***/ + if (MountCard(slot, silent) == 0) + { + // Mount successful! + if(!silent) + { + if (slot == CARD_SLOTA) + WaitPrompt((char*) "Mounted Slot A Memory Card!"); + else + WaitPrompt((char*) "Mounted Slot B Memory Card!"); + } + CARD_Unmount (slot); + return true; + } + else + { + if(!silent) + { + if (slot == CARD_SLOTA) + WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); + else + WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); + } + + return false; + } } /**************************************************************************** @@ -87,7 +126,7 @@ CardFileExists (char *filename, int slot) * workarounds implemented for when the mount fails. * Returns the result of the last attempted CARD_Mount command. ****************************************************************************/ -int MountCard(int cslot, bool8 silent) +int MountCard(int cslot, bool silent) { int ret; int tries; diff --git a/source/ngc/mcsave.h b/source/ngc/mcsave.h index 6c12abe..8128a56 100644 --- a/source/ngc/mcsave.h +++ b/source/ngc/mcsave.h @@ -21,6 +21,7 @@ int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize); int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent); int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool8 silent); -int MountCard(int cslot, bool8 silent); +int MountCard(int cslot, bool silent); +bool TestCard(int slot, bool silent); #endif diff --git a/source/ngc/memfile.cpp b/source/ngc/memfile.cpp index a2437a6..b0d63a7 100644 --- a/source/ngc/memfile.cpp +++ b/source/ngc/memfile.cpp @@ -145,13 +145,10 @@ NGCFreezeGame (int method, bool8 silent) int offset = 0; char msg[100]; - if (method == METHOD_SD) // SD + if (method == METHOD_SD || method == METHOD_USB) // SD { - sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename); - } - if (method == METHOD_USB) // USB - { - sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename); + changeFATInterface(GCSettings.SaveMethod); + sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); } else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B { @@ -192,14 +189,12 @@ NGCFreezeGame (int method, bool8 silent) } else { - if(method == METHOD_SD) - sprintf(msg, "Couldn't save to %s/%s/", ROOTSDDIR, GCSettings.SaveFolder); - else - sprintf(msg, "Couldn't save to %s/%s/", ROOTUSBDIR, GCSettings.SaveFolder); + changeFATInterface(GCSettings.SaveMethod); + sprintf(msg, "Couldn't save to %s/%s/", ROOTFATDIR, GCSettings.SaveFolder); WaitPrompt (msg); } } - else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTA) // MC Slot A or B + else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B { if (!silent) ShowAction ((char*) "Saving freeze game..."); @@ -353,10 +348,8 @@ NGCUnfreezeGame (int method, bool8 silent) if (method == METHOD_SD || method == METHOD_USB) // SD & USB { - if(method == METHOD_SD) - sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename); - else - sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename); + changeFATInterface(GCSettings.SaveMethod); + sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); handle = fopen (filename, "rb"); diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 01c18ba..7e77678 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -617,7 +617,7 @@ ConfigureButtons (u16 ctrlr_type) menu = oldmenu; } // end configurebuttons() -int ctlrmenucount = 9; +int ctlrmenucount = 10; char ctlrmenu[][50] = { // toggle: "MultiTap", @@ -657,7 +657,7 @@ ConfigureControllers () if (GCSettings.Mouse > 0) sprintf (ctlrmenu[2], "Mice: %d", GCSettings.Mouse); else sprintf (ctlrmenu[2], "Mice: OFF"); - + if (GCSettings.Justifier > 0) sprintf (ctlrmenu[3], "Justifiers: %d", GCSettings.Justifier); else sprintf (ctlrmenu[3], "Justifiers: OFF"); @@ -684,7 +684,7 @@ ConfigureControllers () if (GCSettings.Justifier > 2) GCSettings.Justifier = 0; break; - + case 4: /*** Configure Nunchuk ***/ ConfigureButtons (CTRLR_NUNCHUK); @@ -694,7 +694,7 @@ ConfigureControllers () /*** Configure Classic ***/ ConfigureButtons (CTRLR_CLASSIC); break; - + case 6: /*** Configure Wiimote ***/ ConfigureButtons (CTRLR_WIIMOTE); @@ -807,7 +807,6 @@ mainmenu (int selectedMenu) quit = 1; break; } - } /*** Remove any still held buttons ***/ diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 4a27e79..25afc30 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -45,40 +45,40 @@ char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} }; int preparePrefsData () { - int offset = sizeof (saveicon); - int size; + int offset = sizeof (saveicon); + int size; - memset (savebuffer, 0, SAVEBUFFERSIZE); + memset (savebuffer, 0, SAVEBUFFERSIZE); /*** Copy in save icon ***/ - memcpy (savebuffer, saveicon, offset); + memcpy (savebuffer, saveicon, offset); /*** And the prefscomments ***/ - memcpy (savebuffer + offset, prefscomment, 64); - offset += 64; + memcpy (savebuffer + offset, prefscomment, 64); + offset += 64; - /*** Save all settings ***/ - size = sizeof (Settings); - memcpy (savebuffer + offset, &Settings, size); - offset += size; + /*** Save all settings ***/ + size = sizeof (Settings); + memcpy (savebuffer + offset, &Settings, size); + offset += size; - /*** Save GC specific settings ***/ - size = sizeof (GCSettings); - memcpy (savebuffer + offset, &GCSettings, size); - offset += size; + /*** Save GC specific settings ***/ + size = sizeof (GCSettings); + memcpy (savebuffer + offset, &GCSettings, size); + offset += size; - /*** Save buttonmaps ***/ - size = sizeof (unsigned int) *12; // this size applies to all padmaps - memcpy (savebuffer + offset, &gcpadmap, size); - offset += size; - memcpy (savebuffer + offset, &wmpadmap, size); - offset += size; - memcpy (savebuffer + offset, &ccpadmap, size); - offset += size; - memcpy (savebuffer + offset, &ncpadmap, size); - offset += size; + /*** Save buttonmaps ***/ + size = sizeof (unsigned int) *12; // this size applies to all padmaps + memcpy (savebuffer + offset, &gcpadmap, size); + offset += size; + memcpy (savebuffer + offset, &wmpadmap, size); + offset += size; + memcpy (savebuffer + offset, &ccpadmap, size); + offset += size; + memcpy (savebuffer + offset, &ncpadmap, size); + offset += size; - return offset; + return offset; } @@ -118,7 +118,6 @@ decodePrefsData () return false; } - /**************************************************************************** * Save Preferences ****************************************************************************/ @@ -140,10 +139,8 @@ SavePrefs (int method, bool silent) if(method == METHOD_SD || method == METHOD_USB) { - if(method == METHOD_SD) - sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); - else - sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); + changeFATInterface(GCSettings.SaveMethod); + sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); offset = SaveBufferToFAT (filepath, datasize, silent); } else if(method == METHOD_SMB) @@ -190,10 +187,8 @@ LoadPrefs (int method, bool silent) if(method == METHOD_SD || method == METHOD_USB) { - if(method == METHOD_SD) - sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); - else - sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); + changeFATInterface(GCSettings.SaveMethod); + sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); offset = LoadBufferFromFAT (filepath, silent); } else if(method == METHOD_SMB) diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index d6e3bb4..573c1ec 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -201,7 +201,7 @@ extern unsigned int timediffallowed; // hold superscope/mouse/justifier cursor positions int cursor_x[5] = {0,0,0,0,0}; -int cursor_y[5] = {0,0,0,0,0}; +int cursor_y[5] = {0,0,0,0,0}; extern void fat_enable_readahead_all(); @@ -646,7 +646,6 @@ void SetControllers () { if (Settings.MultiPlayer5Master == true) { - S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0); S9xSetController (1, CTL_MP5, 1, 2, 3, -1); } @@ -657,8 +656,9 @@ void SetControllers () } else if (Settings.MouseMaster == true) { - S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0); - S9xSetController (1, CTL_MOUSE, (GCSettings.Mouse == 2), 0, 0, 0); + // some games (eg: Mario Paint) don't allow the mouse in port 2 + S9xSetController (0, CTL_MOUSE, (GCSettings.Mouse == 2), 0, 0, 0); + S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0); } else if (Settings.JustifierMaster == true) { @@ -749,14 +749,14 @@ SetDefaultButtonMap () ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Cursor"); ASSIGN_BUTTON_FALSE (maxcode++, "Superscope ToggleTurbo"); ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Pause"); - + maxcode = 0x60; /*** Mouse ***/ ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 L"); ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 R"); ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 L"); ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 R"); - + maxcode = 0x70; /*** Justifier ***/ ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 AimOffscreen"); @@ -835,7 +835,9 @@ main () /*** Initialize libFAT for SD and USB ***/ fatInitDefault(); //fatInit(8192, false); +#ifdef HW_RVL //fat_enable_readahead_all(); +#endif /*** Initialize DVD subsystem ***/ DVD_Init (); diff --git a/source/ngc/sram.cpp b/source/ngc/sram.cpp index a724ce5..cef0483 100644 --- a/source/ngc/sram.cpp +++ b/source/ngc/sram.cpp @@ -250,11 +250,8 @@ LoadSRAM (int method, bool silent) if(method == METHOD_SD || method == METHOD_USB) { - if(method == METHOD_SD) - sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename); - else - sprintf (filepath, "%s/%s/%s.srm", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename); - + changeFATInterface(GCSettings.SaveMethod); + sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); offset = LoadBufferFromFAT (filepath, silent); } else if(method == METHOD_SMB) @@ -313,10 +310,8 @@ SaveSRAM (int method, bool silent) { if(method == METHOD_SD || method == METHOD_USB) { - if(method == METHOD_SD) - sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename); - else - sprintf (filepath, "%s/%s/%s.srm", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename); + changeFATInterface(GCSettings.SaveMethod); + sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); offset = SaveBufferToFAT (filepath, datasize, silent); } else if(method == METHOD_SMB)