memcard / DVD / other bug fixes

This commit is contained in:
dborth 2008-08-17 05:25:33 +00:00
parent d253f9f590
commit 62e6fab1ad
7 changed files with 50 additions and 127 deletions

View File

@ -362,22 +362,22 @@ ParseDVDdirectory ()
* DirectorySearch * DirectorySearch
* *
* Searches for the directory name specified within the current directory * Searches for the directory name specified within the current directory
* Returns the index of the directory, or 0 if not found * Returns the index of the directory, or -1 if not found
*/ */
int DirectorySearch(char dir[512]) int DirectorySearch(char dir[512])
{ {
for (int i = 0; i < maxfiles; i++ ) for (int i = 0; i < maxfiles; i++ )
if (strcmp(filelist[i].filename, dir) == 0) if (strcmp(filelist[i].filename, dir) == 0)
return i; return i;
return 0; return -1;
} }
/** /**
* SwitchDVDFolder * SwitchDVDFolder
* *
* Function to switch to the directory snes9x/roms, if it exists
* Also loads the folder contents
* Recursively searches for any directory path 'dir' specified * Recursively searches for any directory path 'dir' specified
* Also loads the directory contents via ParseDVDdirectory()
* It relies on dvddir, dvddirlength, and filelist being pre-populated
*/ */
bool SwitchDVDFolder(char * dir, int maxDepth) bool SwitchDVDFolder(char * dir, int maxDepth)
{ {
@ -385,7 +385,7 @@ bool SwitchDVDFolder(char * dir, int maxDepth)
return false; return false;
bool lastdir = false; bool lastdir = false;
char * nextdir = 0; char * nextdir = NULL;
unsigned int t = strcspn(dir, "/"); unsigned int t = strcspn(dir, "/");
if(t != strlen(dir)) if(t != strlen(dir))
@ -396,7 +396,8 @@ bool SwitchDVDFolder(char * dir, int maxDepth)
dir[t] = 0; dir[t] = 0;
int dirindex = DirectorySearch(dir); int dirindex = DirectorySearch(dir);
if(dirindex)
if(dirindex >= 0)
{ {
dvddir = filelist[dirindex].offset; dvddir = filelist[dirindex].offset;
dvddirlength = filelist[dirindex].length; dvddirlength = filelist[dirindex].length;
@ -410,16 +411,22 @@ bool SwitchDVDFolder(char * dir, int maxDepth)
return false; return false;
} }
bool SwitchDVDFolder(char * dir) bool SwitchDVDFolder(char origdir[])
{ {
// make a copy of origdir so we don't mess with original
char dir[200];
strcpy(dir, origdir);
char * dirptr = dir;
// strip off leading/trailing slashes on the directory path // strip off leading/trailing slashes on the directory path
// we don't want to screw up our recursion! // we don't want to screw up our recursion!
if(dir[0] == '/') if(dir[0] == '/')
dir = dir + 1; dirptr = dirptr + 1;
if(dir[strlen(dir)-1] == '/') if(dir[strlen(dir)-1] == '/')
dir[strlen(dir)-1] = 0; dir[strlen(dir)-1] = 0;
return SwitchDVDFolder(dir, 0); return SwitchDVDFolder(dirptr, 0);
} }
/**************************************************************************** /****************************************************************************

View File

@ -188,8 +188,8 @@ int FileSortCallback(const void *f1, const void *f2)
} }
/* If one is a file and one is a directory the directory is first. */ /* If one is a file and one is a directory the directory is first. */
if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1; if(((FILEENTRIES *)f1)->flags && !(((FILEENTRIES *)f2)->flags)) return -1;
if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1; if(!(((FILEENTRIES *)f1)->flags) && ((FILEENTRIES *)f2)->flags) return 1;
return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename);
} }

View File

@ -50,7 +50,7 @@ extern unsigned char savebuffer[];
static int bufoffset; static int bufoffset;
static char membuffer[MEMBUFFER]; static char membuffer[MEMBUFFER];
char freezecomment[2][32] = { {"Snes9x GX 004 Freeze"}, {"Freeze"} }; char freezecomment[2][32] = { {"Snes9x GX 005 Freeze"}, {"Freeze"} };
/** /**
@ -166,7 +166,7 @@ NGCFreezeGame (int method, bool8 silent)
} }
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B
{ {
sprintf (filename, "%s.snz", Memory.ROMFilename); sprintf (filename, "%s.snz", Memory.ROMName);
ClearSaveBuffer (); ClearSaveBuffer ();
@ -175,7 +175,7 @@ NGCFreezeGame (int method, bool8 silent)
memcpy (savebuffer, saveicon, woffset); memcpy (savebuffer, saveicon, woffset);
/*** And the freezecomment ***/ /*** And the freezecomment ***/
sprintf (freezecomment[1], "%s", Memory.ROMFilename); sprintf (freezecomment[1], "%s", Memory.ROMName);
memcpy (savebuffer + woffset, freezecomment, 64); memcpy (savebuffer + woffset, freezecomment, 64);
woffset += 64; woffset += 64;
@ -266,7 +266,7 @@ NGCUnfreezeGame (int method, bool8 silent)
bufoffset = 0; bufoffset = 0;
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoLoadMethod(); method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W
if (method == METHOD_SD || method == METHOD_USB) // SD & USB if (method == METHOD_SD || method == METHOD_USB) // SD & USB
{ {
@ -283,7 +283,7 @@ NGCUnfreezeGame (int method, bool8 silent)
} }
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B
{ {
sprintf (filename, "%s.snz", Memory.ROMFilename); sprintf (filename, "%s.snz", Memory.ROMName);
int ret = 0; int ret = 0;

View File

@ -125,8 +125,6 @@ int MountCard(int cslot, bool silent)
int ret = -1; int ret = -1;
int tries = 0; int tries = 0;
*(unsigned long *) (0xcc006800) |= 1 << 13; // Disable Encryption
// Mount the card // Mount the card
while ( tries < 10 && ret != 0) while ( tries < 10 && ret != 0)
{ {
@ -229,7 +227,6 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
int CardError; int CardError;
unsigned int blocks; unsigned int blocks;
unsigned int SectorSize; unsigned int SectorSize;
char msg[80];
int bytesleft = 0; int bytesleft = 0;
int bytesread = 0; int bytesread = 0;
@ -247,6 +244,7 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
if (!CardFileExists (filename, slot)) if (!CardFileExists (filename, slot))
{ {
if (!silent)
WaitPrompt((char*) "Unable to open file"); WaitPrompt((char*) "Unable to open file");
return 0; return 0;
} }
@ -271,12 +269,6 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
CARD_Read (&CardFile, buf + bytesread, SectorSize, bytesread); CARD_Read (&CardFile, buf + bytesread, SectorSize, bytesread);
bytesleft -= SectorSize; bytesleft -= SectorSize;
bytesread += SectorSize; bytesread += SectorSize;
if ( !silent )
{
sprintf (msg, "Read %d of %d bytes", bytesread, blocks);
ShowProgress (msg, bytesread, blocks);
}
} }
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (slot); CARD_Unmount (slot);

View File

@ -25,8 +25,6 @@
#include "smbop.h" #include "smbop.h"
#include "filesel.h" #include "filesel.h"
#include "mxml.h"
extern unsigned char savebuffer[]; extern unsigned char savebuffer[];
extern int currconfig[4]; extern int currconfig[4];
@ -41,82 +39,6 @@ extern unsigned int ncpadmap[];
char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} }; char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} };
/****************************************************************************
* Prepare Preferences Data
*
* This sets up the save buffer for saving.
****************************************************************************/
void CreateXmlFile(char* filename)
{
mxml_node_t *xml;
mxml_node_t *data;
mxml_node_t *group;
xml = mxmlNewXML("1.0");
data = mxmlNewElement(xml, "screen");
//Create Some config value
mxmlElementSetAttr(data, "height","480");
mxmlElementSetAttr(data, "width","640");
//Lets do some sub items for funs
group = mxmlNewElement(data, "properties");
mxmlElementSetAttr(group, "username", "beardface");
mxmlElementSetAttr(group, "favorite_food", "dead babies");
/* now lets save the xml file to a file! */
FILE *fp;
fp = fopen(filename, "w");
mxmlSaveFile(xml, fp, MXML_NO_CALLBACK);
/*Time to clean up!*/
fclose(fp);
mxmlDelete(group);
mxmlDelete(data);
mxmlDelete(xml);
}
/****************************************************************************
* Prepare Preferences Data
*
* This sets up the save buffer for saving.
****************************************************************************/
void LoadXmlFile(char* filename)
{
FILE *fp;
mxml_node_t *tree;
mxml_node_t *data;
mxml_node_t *group;
/*Load our xml file! */
fp = fopen(filename, "r");
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
fclose(fp);
/*Load and printf our values! */
/* As a note, its a good idea to normally check if node* is NULL */
data = mxmlFindElement(tree, tree, "screen", NULL, NULL, MXML_DESCEND);
printf("Loaded following values from xml file:\n");
printf(" Height: %s\n",mxmlElementGetAttr(data,"height"));
printf(" Width: %s\n",mxmlElementGetAttr(data,"width"));
group = mxmlFindElement(tree, tree, "properties", NULL, NULL, MXML_DESCEND);
printf(" %s's favorite food is %s\n",mxmlElementGetAttr(group, "username"), mxmlElementGetAttr(group, "favorite_food"));
/* Yay Done! Now lets be considerate programmers, and put memory back how
we found it before we started playing with it...*/
mxmlDelete(group);
mxmlDelete(data);
mxmlDelete(tree);
}
/**************************************************************************** /****************************************************************************
* Prepare Preferences Data * Prepare Preferences Data
* *

View File

@ -595,6 +595,11 @@ NGCReportButtons ()
} }
mainmenu (3); // go to game menu mainmenu (3); // go to game menu
FrameTimer = 0;
ConfigRequested = 0;
setFrameTimerMethod(); // set frametimer method every time a ROM is loaded
S9xReportControllers(); // FIX
} }
else else
{ {
@ -790,15 +795,11 @@ extern void S9xInitSync();
void void
emulate () emulate ()
{ {
S9xSetSoundMute (TRUE); S9xSetSoundMute (TRUE);
AudioStart (); AudioStart ();
S9xInitSync(); S9xInitSync();
FrameTimer = 0;
ConfigRequested = 0;
setFrameTimerMethod(); // set frametimer method every time a ROM is loaded setFrameTimerMethod(); // set frametimer method every time a ROM is loaded
S9xReportControllers(); // FIX
while (1) while (1)
{ {
@ -928,6 +929,9 @@ main ()
if (!Memory.LoadROM ("VIRTUAL.ROM")) if (!Memory.LoadROM ("VIRTUAL.ROM"))
while (1); while (1);
CPU.Flags = save_flags; CPU.Flags = save_flags;
/*** Load SRAM ***/
Memory.LoadSRAM ("DVD");
} }
/*** Emulate ***/ /*** Emulate ***/

View File

@ -48,7 +48,7 @@ prepareMCsavedata ()
memcpy (savebuffer, saveicon, offset); memcpy (savebuffer, saveicon, offset);
/*** And the sramcomments ***/ /*** And the sramcomments ***/
sprintf (sramcomment[1], "%s", Memory.ROMFilename); sprintf (sramcomment[1], "%s", Memory.ROMName);
memcpy (savebuffer + offset, sramcomment, 64); memcpy (savebuffer + offset, sramcomment, 64);
offset += 64; offset += 64;
@ -81,7 +81,7 @@ prepareMCsavedata ()
* Prepare Exportable SRAM Save Data * Prepare Exportable SRAM Save Data
* *
* This sets up the save buffer for saving in a format compatible with * This sets up the save buffer for saving in a format compatible with
* snes9x on other platforms. This is used when saving to SD or SMB. * snes9x on other platforms. This is used when saving to SD / USB / SMB.
****************************************************************************/ ****************************************************************************/
int int
prepareEXPORTsavedata () prepareEXPORTsavedata ()
@ -243,7 +243,7 @@ LoadSRAM (int method, bool silent)
ShowAction ((char*) "Loading..."); ShowAction ((char*) "Loading...");
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoLoadMethod(); method = autoSaveMethod(); // we use 'Save' because SRAM needs R/W
char filepath[1024]; char filepath[1024];
int offset = 0; int offset = 0;
@ -259,14 +259,13 @@ LoadSRAM (int method, bool silent)
sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename); sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename);
offset = LoadBufferFromSMB (filepath, silent); offset = LoadBufferFromSMB (filepath, silent);
} }
else if(method == METHOD_MC_SLOTA) else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{ {
sprintf (filepath, "%s.srm", Memory.ROMFilename); sprintf (filepath, "%s.srm", Memory.ROMName);
if(method == METHOD_MC_SLOTA)
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent); offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent);
} else
else if(method == METHOD_MC_SLOTB)
{
sprintf (filepath, "%s.srm", Memory.ROMFilename);
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent); offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent);
} }
@ -320,14 +319,13 @@ SaveSRAM (int method, bool silent)
sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename); sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename);
offset = SaveBufferToSMB (filepath, datasize, silent); offset = SaveBufferToSMB (filepath, datasize, silent);
} }
else if(method == METHOD_MC_SLOTA) else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{ {
sprintf (filepath, "%s.srm", Memory.ROMFilename); sprintf (filepath, "%s.srm", Memory.ROMName);
if(method == METHOD_MC_SLOTA)
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent); offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent);
} else
else if(method == METHOD_MC_SLOTB)
{
sprintf (filepath, "%s.srm", Memory.ROMFilename);
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent); offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent);
} }