mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-01 00:15:10 +01:00
tidy up file code
This commit is contained in:
parent
4d6d662d02
commit
830db0e150
@ -29,6 +29,7 @@ extern "C" {
|
||||
u64 dvddir = 0; // offset of currently selected file or folder
|
||||
int dvddirlength = 0; // length of currently selected file or folder
|
||||
u64 dvdrootdir = 0; // offset of DVD root
|
||||
int dvdrootlength = 0; // length of DVD root
|
||||
bool isWii = false;
|
||||
|
||||
#ifdef HW_DOL
|
||||
@ -260,8 +261,9 @@ getpvd ()
|
||||
memcpy(&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4);
|
||||
dvddir = (u64)rootdir32;
|
||||
dvddir <<= 11;
|
||||
dvdrootdir = dvddir;
|
||||
memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4);
|
||||
dvdrootdir = dvddir;
|
||||
dvdrootlength = dvddirlength;
|
||||
IsJoliet = 1;
|
||||
break;
|
||||
}
|
||||
@ -306,7 +308,6 @@ getpvd ()
|
||||
***************************************************************************/
|
||||
bool TestDVD()
|
||||
{
|
||||
|
||||
if (!getpvd())
|
||||
{
|
||||
#ifdef HW_DOL
|
||||
@ -554,6 +555,11 @@ bool SwitchDVDFolder(char origdir[])
|
||||
if(dir[strlen(dir)-1] == '/')
|
||||
dir[strlen(dir)-1] = 0;
|
||||
|
||||
// start at root of DVD
|
||||
dvddir = dvdrootdir;
|
||||
dvddirlength = dvdrootlength;
|
||||
ParseDVDdirectory();
|
||||
|
||||
return SwitchDVDFolder(dirptr, 0);
|
||||
}
|
||||
|
||||
@ -567,7 +573,7 @@ bool SwitchDVDFolder(char origdir[])
|
||||
***************************************************************************/
|
||||
|
||||
int
|
||||
LoadDVDFile (unsigned char *buffer, int length)
|
||||
LoadDVDFileOffset (unsigned char *buffer, int length)
|
||||
{
|
||||
int offset;
|
||||
int blocks;
|
||||
@ -575,15 +581,13 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
u64 discoffset;
|
||||
char readbuffer[2048];
|
||||
|
||||
dvddir = filelist[selection].offset;
|
||||
dvddirlength = filelist[selection].length;
|
||||
|
||||
// How many 2k blocks to read
|
||||
blocks = dvddirlength / 2048;
|
||||
offset = 0;
|
||||
discoffset = dvddir;
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
if(length > 0 && length <= 2048)
|
||||
{
|
||||
dvd_read (buffer, length, discoffset);
|
||||
}
|
||||
@ -591,7 +595,11 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
{
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
|
||||
if (!IsZipFile (readbuffer))
|
||||
if (IsZipFile (readbuffer))
|
||||
{
|
||||
return UnZipBuffer (buffer, METHOD_DVD); // unzip from dvd
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < blocks; i++)
|
||||
{
|
||||
@ -610,14 +618,25 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
memcpy (buffer + offset, readbuffer, i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return UnZipBuffer (buffer, METHOD_DVD); // unzip from dvd
|
||||
}
|
||||
}
|
||||
return dvddirlength;
|
||||
}
|
||||
|
||||
int
|
||||
LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if(SwitchDVDFolder(filepath))
|
||||
{
|
||||
return LoadDVDFileOffset ((unsigned char *)buffer, datasize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char *)"Error loading file!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* uselessinquiry
|
||||
*
|
||||
@ -646,7 +665,7 @@ void uselessinquiry ()
|
||||
* dvd_motor_off( )
|
||||
* Turns off DVD drive motor so it doesn't make noise (Gamecube only)
|
||||
***************************************************************************/
|
||||
void dvd_motor_off( )
|
||||
void dvd_motor_off ()
|
||||
{
|
||||
dvd[0] = 0x2e;
|
||||
dvd[1] = 0;
|
||||
|
@ -13,7 +13,8 @@
|
||||
|
||||
int getpvd ();
|
||||
int ParseDVDdirectory ();
|
||||
int LoadDVDFile (unsigned char *buffer, int length);
|
||||
int LoadDVDFileOffset(unsigned char *buffer, int length);
|
||||
int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent);
|
||||
bool TestDVD();
|
||||
int dvd_read (void *dst, unsigned int len, u64 offset);
|
||||
int dvd_safe_read (void *dst, unsigned int len, u64 offset);
|
||||
|
@ -27,26 +27,6 @@
|
||||
// FAT file pointer - the only one we should ever use!
|
||||
FILE * fatfile;
|
||||
|
||||
/****************************************************************************
|
||||
* MountFAT
|
||||
* Attempts to mount the FAT device specified
|
||||
* Sets libfat to use the device by default
|
||||
* Enables read-ahead cache for SD/USB
|
||||
***************************************************************************/
|
||||
bool MountFAT(PARTITION_INTERFACE part)
|
||||
{
|
||||
bool mounted = fatMountNormalInterface(part, 8);
|
||||
|
||||
if(mounted)
|
||||
{
|
||||
fatSetDefaultInterface(part);
|
||||
#ifdef HW_RVL
|
||||
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
|
||||
fatEnableReadAhead (part, 6, 64);
|
||||
#endif
|
||||
}
|
||||
return mounted;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* UnmountFAT
|
||||
@ -72,6 +52,31 @@ void UnmountAllFAT()
|
||||
UnmountFAT(PI_SDGECKO_B);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* MountFAT
|
||||
* Checks if the device needs to be (re)mounted
|
||||
* If so, unmounts the device
|
||||
* Attempts to mount the device specified
|
||||
* Sets libfat to use the device by default
|
||||
* Enables read-ahead cache for SD/USB
|
||||
***************************************************************************/
|
||||
bool MountFAT(PARTITION_INTERFACE part)
|
||||
{
|
||||
UnmountFAT(part);
|
||||
|
||||
bool mounted = fatMountNormalInterface(part, 8);
|
||||
|
||||
if(mounted)
|
||||
{
|
||||
fatSetDefaultInterface(part);
|
||||
#ifdef HW_RVL
|
||||
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
|
||||
fatEnableReadAhead (part, 6, 64);
|
||||
#endif
|
||||
}
|
||||
return mounted;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* ChangeFATInterface
|
||||
* Unmounts all devices and attempts to mount/configure the device specified
|
||||
@ -84,9 +89,6 @@ bool ChangeFATInterface(int method, bool silent)
|
||||
|
||||
bool mounted = false;
|
||||
|
||||
// unmount all FAT devices
|
||||
UnmountAllFAT();
|
||||
|
||||
if(method == METHOD_SD)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
@ -104,6 +106,7 @@ bool ChangeFATInterface(int method, bool silent)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
mounted = MountFAT(PI_USBSTORAGE);
|
||||
|
||||
if(!mounted && !silent)
|
||||
WaitPrompt ((char *)"USB drive not found!");
|
||||
#endif
|
||||
@ -173,67 +176,6 @@ ParseFATdirectory(int method)
|
||||
return nbfiles;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATFile
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadFATFile (char * rbuffer, int length)
|
||||
{
|
||||
char zipbuffer[2048];
|
||||
char filepath[MAXPATHLEN];
|
||||
u32 size;
|
||||
|
||||
/* Check filename length */
|
||||
if (!MakeROMPath(filepath, METHOD_SD))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fatfile = fopen (filepath, "rb");
|
||||
if (fatfile > 0)
|
||||
{
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
fread (rbuffer, 1, length, fatfile);
|
||||
size = length;
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
fread (zipbuffer, 1, 2048, fatfile);
|
||||
|
||||
if (IsZipFile (zipbuffer))
|
||||
{
|
||||
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
fseek(fatfile, 0, SEEK_END);
|
||||
size = ftell(fatfile); // get filesize
|
||||
fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
|
||||
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
|
||||
|
||||
ShowProgress ((char *)"Loading...", 2048, size);
|
||||
|
||||
u32 offset = 2048;
|
||||
while(offset < size)
|
||||
{
|
||||
offset += fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks
|
||||
ShowProgress ((char *)"Loading...", offset, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (fatfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*) "Error opening file");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATSzFile
|
||||
* Loads the selected file # from the specified 7z into rbuffer
|
||||
@ -258,49 +200,71 @@ LoadFATSzFile(char * filepath, unsigned char * rbuffer)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Load savebuffer from FAT file
|
||||
* LoadFATFile
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadBufferFromFAT (char *filepath, bool silent)
|
||||
{
|
||||
return LoadBufferFromFAT((char *)savebuffer, filepath, silent);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Load buffer from FAT file
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadBufferFromFAT (char * buffer, char *filepath, bool silent)
|
||||
LoadFATFile (char * rbuffer, char *filepath, int length, bool silent)
|
||||
{
|
||||
char zipbuffer[2048];
|
||||
int size = 0;
|
||||
int readsize = 0;
|
||||
|
||||
fatfile = fopen (filepath, "rb");
|
||||
|
||||
if (fatfile <= 0)
|
||||
if (fatfile > 0)
|
||||
{
|
||||
if ( !silent )
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
char msg[100];
|
||||
sprintf(msg, "Couldn't open %s", filepath);
|
||||
WaitPrompt (msg);
|
||||
fread (rbuffer, 1, length, fatfile);
|
||||
size = length;
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
readsize = fread (zipbuffer, 1, 2048, fatfile);
|
||||
|
||||
if(readsize > 0)
|
||||
{
|
||||
if (IsZipFile (zipbuffer))
|
||||
{
|
||||
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
fseek(fatfile, 0, SEEK_END);
|
||||
size = ftell(fatfile); // get filesize
|
||||
fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
|
||||
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
|
||||
|
||||
ShowProgress ((char *)"Loading...", 2048, length);
|
||||
|
||||
int offset = 2048;
|
||||
while(offset < size && readsize != 0)
|
||||
{
|
||||
readsize = fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks
|
||||
offset += readsize;
|
||||
ShowProgress ((char *)"Loading...", offset, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (fatfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Error opening file!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fseek(fatfile, 0, SEEK_END); // go to end of file
|
||||
size = ftell(fatfile); // get filesize
|
||||
fseek(fatfile, 0, SEEK_SET); // go to start of file
|
||||
fread (savebuffer, 1, size, fatfile);
|
||||
fclose (fatfile);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Write savebuffer to FAT card file
|
||||
* SaveFATFile
|
||||
* Write buffer to FAT card file
|
||||
***************************************************************************/
|
||||
int
|
||||
SaveBufferToFAT (char *filepath, int datasize, bool silent)
|
||||
SaveFATFile (char * buffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if (datasize)
|
||||
{
|
||||
|
@ -23,11 +23,9 @@
|
||||
|
||||
bool ChangeFATInterface(int method, bool silent);
|
||||
int ParseFATdirectory(int method);
|
||||
int LoadFATFile (char * fbuffer, int length);
|
||||
int LoadFATSzFile(char * filepath, unsigned char * rbuffer);
|
||||
int SaveBufferToFAT (char *filepath, int datasize, bool silent);
|
||||
int LoadBufferFromFAT (char *filepath, bool silent);
|
||||
int LoadBufferFromFAT (char *buffer, char *filepath, bool silent);
|
||||
int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
|
||||
extern char currFATdir[MAXPATHLEN];
|
||||
extern FILE * fatfile;
|
||||
|
@ -140,15 +140,14 @@ int autoSaveMethod()
|
||||
int UpdateDirName(int method)
|
||||
{
|
||||
int size=0;
|
||||
char *test;
|
||||
char * test;
|
||||
char temp[1024];
|
||||
|
||||
// update DVD directory (does not utilize 'currentdir')
|
||||
// update DVD directory
|
||||
if(method == METHOD_DVD)
|
||||
{
|
||||
dvddir = filelist[selection].offset;
|
||||
dvddirlength = filelist[selection].length;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* current directory doesn't change */
|
||||
@ -186,32 +185,134 @@ int UpdateDirName(int method)
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*)"Directory name is too long !");
|
||||
WaitPrompt((char*)"Directory name is too long!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MakeROMPath(char filepath[], int method)
|
||||
|
||||
bool MakeFilePath(char filepath[], int type, int method)
|
||||
{
|
||||
char file[512];
|
||||
char folder[1024];
|
||||
char temppath[MAXPATHLEN];
|
||||
|
||||
// Check filename length
|
||||
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
|
||||
if(type == FILE_ROM)
|
||||
{
|
||||
sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename);
|
||||
|
||||
if(method == METHOD_SMB)
|
||||
strcpy(filepath, SMBPath(temppath));
|
||||
else
|
||||
strcpy(filepath, temppath);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
// Check path length
|
||||
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
|
||||
{
|
||||
WaitPrompt((char*)"Maximum filepath length reached!");
|
||||
filepath[0] = 0;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case FILE_SRAM:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s.sav", ROMFilename);
|
||||
break;
|
||||
case FILE_SNAPSHOT:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s.sgm", ROMFilename);
|
||||
break;
|
||||
case FILE_CHEAT:
|
||||
sprintf(folder, GCSettings.CheatFolder);
|
||||
sprintf(file, "%s.cht", ROMFilename);
|
||||
break;
|
||||
case FILE_PREF:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s", PREF_FILE_NAME);
|
||||
break;
|
||||
}
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
sprintf (temppath, "%s/%s/%s", ROOTFATDIR, folder, file);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
case METHOD_SMB:
|
||||
sprintf (temppath, "%s/%s", folder, file);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
case METHOD_MC_SLOTB:
|
||||
sprintf (temppath, "%s", file);
|
||||
temppath[31] = 0; // truncate filename
|
||||
break;
|
||||
}
|
||||
}
|
||||
strcpy(filepath, temppath);
|
||||
return true;
|
||||
}
|
||||
|
||||
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
offset = LoadFATFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
offset = LoadSMBFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
offset = LoadDVDFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
offset = LoadMCFile (buffer, CARD_SLOTA, filepath, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
offset = LoadMCFile (buffer, CARD_SLOTB, filepath, silent);
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
int LoadFile(char filepath[], int method, bool silent)
|
||||
{
|
||||
return LoadFile((char *)savebuffer, filepath, 0, method, silent);
|
||||
}
|
||||
|
||||
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
offset = SaveFATFile (buffer, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
offset = SaveSMBFile (buffer, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
offset = SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
offset = SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent);
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
int SaveFile(char filepath[], int datasize, int method, bool silent)
|
||||
{
|
||||
return SaveFile((char *)savebuffer, filepath, datasize, method, silent);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -393,11 +494,9 @@ int FileSelector (int method)
|
||||
if(IsSz())
|
||||
{
|
||||
// we'll store the 7z filepath for extraction later
|
||||
if(!MakeROMPath(szpath, method))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
if(!MakeFilePath(szpath, FILE_ROM, method))
|
||||
return 0;
|
||||
}
|
||||
|
||||
int szfiles = SzParse(szpath, method);
|
||||
if(szfiles)
|
||||
{
|
||||
@ -562,6 +661,7 @@ OpenDVD (int method)
|
||||
}
|
||||
}
|
||||
|
||||
currentdir[0] = 0;
|
||||
maxfiles = ParseDVDdirectory(); // load root folder
|
||||
|
||||
// switch to rom folder
|
||||
|
@ -39,7 +39,11 @@ extern char ROMFilename[512];
|
||||
|
||||
void AllocSaveBuffer();
|
||||
void FreeSaveBuffer();
|
||||
bool MakeROMPath(char filepath[], int method);
|
||||
bool MakeFilePath(char filepath[], int type, int method);
|
||||
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent);
|
||||
int LoadFile(char filepath[], int method, bool silent);
|
||||
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent);
|
||||
int SaveFile(char filepath[], int datasize, int method, bool silent);
|
||||
int OpenROM (int method);
|
||||
int autoLoadMethod();
|
||||
int autoSaveMethod();
|
||||
|
@ -226,23 +226,13 @@ GetFirstZipFilename (int method)
|
||||
{
|
||||
char * firstFilename = NULL;
|
||||
char tempbuffer[ZIPCHUNK];
|
||||
char filepath[1024];
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_ROM, method))
|
||||
return NULL;
|
||||
|
||||
// read start of ZIP
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD: // SD Card
|
||||
case METHOD_USB: // USB
|
||||
LoadFATFile (tempbuffer, ZIPCHUNK);
|
||||
break;
|
||||
|
||||
case METHOD_DVD: // DVD
|
||||
LoadDVDFile ((unsigned char *)tempbuffer, ZIPCHUNK);
|
||||
break;
|
||||
|
||||
case METHOD_SMB: // From SMB
|
||||
LoadSMBFile (tempbuffer, ZIPCHUNK);
|
||||
break;
|
||||
}
|
||||
LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT);
|
||||
|
||||
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
|
||||
int namelength = tempbuffer[26]; // filename length starts 26 bytes in
|
||||
|
@ -124,7 +124,7 @@ int MountCard(int cslot, bool silent)
|
||||
* Verify Memory Card file against buffer
|
||||
***************************************************************************/
|
||||
int
|
||||
VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
|
||||
VerifyMCFile (char *buf, int slot, char *filename, int datasize)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
@ -201,10 +201,11 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadMCFile
|
||||
* Load savebuffer from Memory Card file
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent)
|
||||
LoadMCFile (char *buf, int slot, char *filename, bool silent)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
@ -266,10 +267,11 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* SaveMCFile
|
||||
* Write savebuffer to Memory Card file
|
||||
***************************************************************************/
|
||||
int
|
||||
SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
|
@ -11,10 +11,9 @@
|
||||
#ifndef _NGCMCSAVE_
|
||||
#define _NGCMCSAVE_
|
||||
|
||||
int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize);
|
||||
|
||||
int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent);
|
||||
int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool silent);
|
||||
int VerifyMCFile (char *buf, int slot, char *filename, int datasize);
|
||||
int LoadMCFile (char *buf, int slot, char *filename, bool silent);
|
||||
int SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent);
|
||||
int MountCard(int cslot, bool silent);
|
||||
bool TestCard(int slot, bool silent);
|
||||
|
||||
|
@ -98,9 +98,9 @@ LoadManager ()
|
||||
if ( loadROM == 1 ) // if ROM was loaded, load the battery / state
|
||||
{
|
||||
if (GCSettings.AutoLoad == 1)
|
||||
LoadBatteryOrState(GCSettings.SaveMethod, 0, SILENT); // load battery
|
||||
LoadBatteryOrState(GCSettings.SaveMethod, FILE_SRAM, SILENT); // load battery
|
||||
else if (GCSettings.AutoLoad == 2)
|
||||
LoadBatteryOrState(GCSettings.SaveMethod, 1, SILENT); // load state
|
||||
LoadBatteryOrState(GCSettings.SaveMethod, FILE_SNAPSHOT, SILENT); // load state
|
||||
}
|
||||
|
||||
return loadROM;
|
||||
@ -354,20 +354,20 @@ GameMenu ()
|
||||
break;
|
||||
|
||||
case 2: // Load Battery
|
||||
quit = retval = LoadBatteryOrState(GCSettings.SaveMethod, 0, NOTSILENT);
|
||||
quit = retval = LoadBatteryOrState(GCSettings.SaveMethod, FILE_SRAM, NOTSILENT);
|
||||
emulator.emuReset();
|
||||
break;
|
||||
|
||||
case 3: // Save Battery
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, 0, NOTSILENT);
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, FILE_SRAM, NOTSILENT);
|
||||
break;
|
||||
|
||||
case 4: // Load State
|
||||
quit = retval = LoadBatteryOrState(GCSettings.SaveMethod, 1, NOTSILENT);
|
||||
quit = retval = LoadBatteryOrState(GCSettings.SaveMethod, FILE_SNAPSHOT, NOTSILENT);
|
||||
break;
|
||||
|
||||
case 5: // Save State
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, 1, NOTSILENT);
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, FILE_SNAPSHOT, NOTSILENT);
|
||||
break;
|
||||
|
||||
case 6: // Reset Zoom
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
extern int currconfig[4];
|
||||
|
||||
#define PREFS_FILE_NAME "VBAGX.xml"
|
||||
|
||||
char prefscomment[2][32];
|
||||
|
||||
/****************************************************************************
|
||||
@ -312,43 +310,25 @@ decodePrefsData (int method)
|
||||
bool
|
||||
SavePrefs (int method, bool silent)
|
||||
{
|
||||
char filepath[1024];
|
||||
int datasize;
|
||||
int offset = 0;
|
||||
|
||||
// there's no point in saving SMB settings TO SMB, because then we'll have no way to load them the next time!
|
||||
// so instead we'll save using whatever other method is available (eg: SD)
|
||||
if(method == METHOD_AUTO || method == METHOD_SMB)
|
||||
method = autoSaveMethod();
|
||||
|
||||
char filepath[1024];
|
||||
int datasize;
|
||||
int offset = 0;
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
datasize = preparePrefsData (method);
|
||||
if(!MakeFilePath(filepath, FILE_PREF, method))
|
||||
return false;
|
||||
|
||||
if (!silent)
|
||||
ShowAction ((char*) "Saving preferences...");
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = SaveBufferToFAT (filepath, datasize, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = SaveBufferToSMB (filepath, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA)
|
||||
{
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTB)
|
||||
{
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, datasize, silent);
|
||||
}
|
||||
AllocSaveBuffer ();
|
||||
datasize = preparePrefsData (method);
|
||||
|
||||
offset = SaveFile(filepath, datasize, method, silent);
|
||||
|
||||
FreeSaveBuffer ();
|
||||
|
||||
@ -371,29 +351,12 @@ LoadPrefsFromMethod (int method)
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_PREF, method))
|
||||
return false;
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = LoadBufferFromFAT (filepath, SILENT);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = LoadBufferFromSMB (filepath, SILENT);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA)
|
||||
{
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, SILENT);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTB)
|
||||
{
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, SILENT);
|
||||
}
|
||||
offset = LoadFile(filepath, method, SILENT);
|
||||
|
||||
if (offset > 0)
|
||||
retval = decodePrefsData (method);
|
||||
|
@ -222,25 +222,6 @@ SMBFILE OpenSMBFile(char * filepath)
|
||||
return SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Load SMB file
|
||||
* rom - pointer to memory where ROM will be stored
|
||||
* length - # bytes to read (0 for all)
|
||||
****************************************************************************/
|
||||
int
|
||||
LoadSMBFile (char * rom, int length)
|
||||
{
|
||||
char filepath[MAXPATHLEN];
|
||||
|
||||
/* Check filename length */
|
||||
if (!MakeROMPath(filepath, METHOD_SMB))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
return -1;
|
||||
}
|
||||
return LoadBufferFromSMB(rom, filepath, length, NOTSILENT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadSMBSzFile
|
||||
* Loads the selected file # from the specified 7z into rbuffer
|
||||
@ -268,17 +249,12 @@ LoadSMBSzFile(char * filepath, unsigned char * rbuffer)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Write savebuffer to SMB file
|
||||
* SaveSMBFile
|
||||
* Write buffer to SMB file
|
||||
****************************************************************************/
|
||||
// no buffer specified, use savebuffer
|
||||
int
|
||||
SaveBufferToSMB (char *filepath, int datasize, bool silent)
|
||||
{
|
||||
return SaveBufferToSMB((char *)savebuffer, filepath, datasize, silent);
|
||||
}
|
||||
|
||||
int
|
||||
SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
SaveSMBFile (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
@ -318,18 +294,12 @@ SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadSMBFile
|
||||
* Load up a buffer from SMB file
|
||||
****************************************************************************/
|
||||
|
||||
// no buffer is specified - so use savebuffer
|
||||
int
|
||||
LoadBufferFromSMB (char *filepath, bool silent)
|
||||
{
|
||||
return LoadBufferFromSMB((char *)savebuffer, filepath, 0, silent);
|
||||
}
|
||||
|
||||
int
|
||||
LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
|
||||
LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
|
@ -20,12 +20,9 @@ char * SMBPath(char * path);
|
||||
int UpdateSMBdirname();
|
||||
int ParseSMBdirectory ();
|
||||
SMBFILE OpenSMBFile(char * filepath);
|
||||
int LoadSMBFile (char * fbuffer, int length);
|
||||
int LoadSMBSzFile(char * filepath, unsigned char * rbuffer);
|
||||
int LoadBufferFromSMB (char *filepath, bool silent);
|
||||
int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int SaveBufferToSMB (char *filepath, int datasize, bool silent);
|
||||
int SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent);
|
||||
int LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int SaveSMBFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
|
||||
extern SMBFILE smbfile;
|
||||
|
||||
|
@ -143,16 +143,16 @@ int main()
|
||||
{
|
||||
if (GCSettings.AutoSave == 1)
|
||||
{
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, 0, SILENT); // save battery
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, FILE_SRAM, SILENT); // save battery
|
||||
}
|
||||
else if (GCSettings.AutoSave == 2)
|
||||
{
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, 1, SILENT); // save state
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, FILE_SNAPSHOT, SILENT); // save state
|
||||
}
|
||||
else if(GCSettings.AutoSave == 3)
|
||||
{
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, 0, SILENT); // save battery
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, 1, SILENT); // save state
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, FILE_SRAM, SILENT); // save battery
|
||||
SaveBatteryOrState(GCSettings.SaveMethod, FILE_SNAPSHOT, SILENT); // save state
|
||||
}
|
||||
ConfigRequested = 0;
|
||||
break;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define VERSIONNUM "1.0.4"
|
||||
#define VERSIONSTR "VBA GX 1.0.4"
|
||||
#define VERSIONSTRFULL "Visual Boy Advance GX 1.0.4"
|
||||
#define PREF_FILE_NAME "VBAGX.xml"
|
||||
|
||||
#define NOTSILENT 0
|
||||
#define SILENT 1
|
||||
@ -28,6 +29,14 @@ enum {
|
||||
METHOD_MC_SLOTB
|
||||
};
|
||||
|
||||
enum {
|
||||
FILE_ROM,
|
||||
FILE_SRAM,
|
||||
FILE_SNAPSHOT,
|
||||
FILE_CHEAT,
|
||||
FILE_PREF
|
||||
};
|
||||
|
||||
struct SGCSettings{
|
||||
int AutoLoad;
|
||||
int AutoSave;
|
||||
|
@ -250,8 +250,8 @@ int MemCPUWriteBatteryFile(char * membuffer)
|
||||
/****************************************************************************
|
||||
* LoadBatteryOrState
|
||||
* Load Battery/State file into memory
|
||||
* action = 0 - Load battery
|
||||
* action = 1 - Load state
|
||||
* action = FILE_SRAM - Load battery
|
||||
* action = FILE_SNAPSHOT - Load state
|
||||
****************************************************************************/
|
||||
|
||||
bool LoadBatteryOrState(int method, int action, bool silent)
|
||||
@ -259,44 +259,22 @@ bool LoadBatteryOrState(int method, int action, bool silent)
|
||||
char filepath[1024];
|
||||
bool result = false;
|
||||
int offset = 0;
|
||||
char ext[4];
|
||||
|
||||
if(action == 0)
|
||||
sprintf(ext, "sav");
|
||||
else
|
||||
sprintf(ext, "sgm");
|
||||
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod(); // we use 'Save' because we need R/W
|
||||
|
||||
if(!MakeFilePath(filepath, action, method))
|
||||
return false;
|
||||
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
AllocSaveBuffer();
|
||||
|
||||
// load the file into savebuffer
|
||||
offset = LoadFile(filepath, method, silent);
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.%s", ROOTFATDIR, GCSettings.SaveFolder, ROMFilename, ext);
|
||||
offset = LoadBufferFromFAT (filepath, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.%s", GCSettings.SaveFolder, ROMFilename, ext);
|
||||
offset = LoadBufferFromSMB (filepath, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%s.%s", ROMFilename, ext);
|
||||
|
||||
if(method == METHOD_MC_SLOTA)
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent);
|
||||
else
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent);
|
||||
|
||||
// skip save icon and comments for Memory Card saves
|
||||
int skip = sizeof (saveicon);
|
||||
skip += 64; // sizeof savecomment
|
||||
@ -307,7 +285,7 @@ bool LoadBatteryOrState(int method, int action, bool silent)
|
||||
// load savebuffer into VBA memory
|
||||
if (offset > 0)
|
||||
{
|
||||
if(action == 0)
|
||||
if(action == FILE_SRAM)
|
||||
{
|
||||
if(cartridgeType == 1)
|
||||
result = MemgbReadBatteryFile((char *)savebuffer, offset);
|
||||
@ -326,14 +304,14 @@ bool LoadBatteryOrState(int method, int action, bool silent)
|
||||
{
|
||||
if(offset == 0)
|
||||
{
|
||||
if(action == 0)
|
||||
if(action == FILE_SRAM)
|
||||
WaitPrompt ((char*) "Save file not found");
|
||||
else
|
||||
WaitPrompt ((char*) "State file not found");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(action == 0)
|
||||
if(action == FILE_SRAM)
|
||||
WaitPrompt ((char*) "Invalid save file");
|
||||
else
|
||||
WaitPrompt ((char*) "Invalid state file");
|
||||
@ -353,40 +331,37 @@ bool LoadBatteryOrState(int method, int action, bool silent)
|
||||
bool SaveBatteryOrState(int method, int action, bool silent)
|
||||
{
|
||||
char filepath[1024];
|
||||
char savecomment[2][32];
|
||||
bool result = false;
|
||||
int offset = 0;
|
||||
char ext[4];
|
||||
char savetype[10];
|
||||
int datasize = 0; // we need the actual size of the data written
|
||||
|
||||
if(action == 0)
|
||||
{
|
||||
sprintf(ext, "sav");
|
||||
sprintf(savetype, "SRAM");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(ext, "sgm");
|
||||
sprintf(savetype, "Freeze");
|
||||
}
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod();
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_SRAM, method))
|
||||
return false;
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod(); // we use 'Save' because we need R/W
|
||||
|
||||
AllocSaveBuffer();
|
||||
|
||||
// add save icon and comments for Memory Card saves
|
||||
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
char savecomment[2][32];
|
||||
char savetype[10];
|
||||
|
||||
offset = sizeof (saveicon);
|
||||
|
||||
// Copy in save icon
|
||||
memcpy (savebuffer, saveicon, offset);
|
||||
|
||||
// And the comments
|
||||
if(action == FILE_SRAM)
|
||||
sprintf(savetype, "SRAM");
|
||||
else
|
||||
sprintf(savetype, "Freeze");
|
||||
|
||||
sprintf (savecomment[0], "%s %s", VERSIONSTR, savetype);
|
||||
strncpy(savecomment[1], ROMFilename, 31); // truncate filename to 31 chars
|
||||
savecomment[1][31] = 0; // make sure last char is null byte
|
||||
@ -395,7 +370,7 @@ bool SaveBatteryOrState(int method, int action, bool silent)
|
||||
}
|
||||
|
||||
// put VBA memory into savebuffer, sets datasize to size of memory written
|
||||
if(action == 0)
|
||||
if(action == FILE_SRAM)
|
||||
{
|
||||
if(cartridgeType == 1)
|
||||
datasize = MemgbWriteBatteryFile((char *)savebuffer+offset);
|
||||
@ -445,28 +420,7 @@ bool SaveBatteryOrState(int method, int action, bool silent)
|
||||
// write savebuffer into file
|
||||
if(datasize > 0)
|
||||
{
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.%s", ROOTFATDIR, GCSettings.SaveFolder, ROMFilename, ext);
|
||||
offset = SaveBufferToFAT (filepath, datasize, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.%s", GCSettings.SaveFolder, ROMFilename, ext);
|
||||
offset = SaveBufferToSMB (filepath, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%s.%s", ROMFilename, ext);
|
||||
|
||||
if(method == METHOD_MC_SLOTA)
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize+offset, silent);
|
||||
else
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize+offset, silent);
|
||||
}
|
||||
offset = SaveFile(filepath, datasize, method, silent);
|
||||
|
||||
if(offset > 0)
|
||||
{
|
||||
@ -524,6 +478,110 @@ u32 systemReadJoypad(int which)
|
||||
return GetJoy(which);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Motion/Tilt sensor
|
||||
* Used for games like:
|
||||
* - Yoshi's Universal Gravitation
|
||||
* - Kirby's Tilt-N-Tumble
|
||||
* - Wario Ware Twisted!
|
||||
*
|
||||
****************************************************************************/
|
||||
int systemGetSensorX()
|
||||
{
|
||||
return sensorX;
|
||||
}
|
||||
|
||||
int systemGetSensorY()
|
||||
{
|
||||
return sensorY;
|
||||
}
|
||||
|
||||
void systemUpdateMotionSensor()
|
||||
{
|
||||
int chan = 0; // first wiimote
|
||||
/*
|
||||
WPADData *Data = WPAD_Data(chan);
|
||||
WPADData data = *Data;
|
||||
|
||||
WPAD_Orientation(chan, &data.orient);
|
||||
WPAD_GForce(chan, &data.gforce);
|
||||
WPAD_Accel(chan, &data.accel);
|
||||
|
||||
//rotz = (float)orient.roll;
|
||||
//roty = (float)orient.pitch;
|
||||
//rotx = (float)orient.yaw;
|
||||
|
||||
//rotz = (float)(2.0*3.14159*((int)orient.roll/360.0));//Removing extra stuff fails too
|
||||
//roty = (float)(2.0*3.14159*((int)orient.pitch/360.0));
|
||||
//rotx = (float)(2.0*3.14159*((int)orient.yaw/360.0));
|
||||
|
||||
//rotz = (float)accel.z;
|
||||
//roty = (float)accel.y;
|
||||
//rotx = (float)accel.x;
|
||||
|
||||
//rotz = 200-(gforce.z*50);//Even doing this without the extra stuff fails
|
||||
//roty = 200-(gforce.y*50);
|
||||
//rotx = 200-(gforce.x*50);
|
||||
|
||||
printf("ACCEL X %d \n", (int)Data->accel.x);
|
||||
printf("ACCEL Y %d \n", (int)Data->accel.y);
|
||||
printf("ACCEL Z %d \n", (int)Data->accel.z);
|
||||
|
||||
printf("HORIENT ROLL %1.3f ", (float)Data->orient.roll);
|
||||
printf("HORIENT PITCH %1.3f ", (float)Data->orient.pitch);
|
||||
printf("HORIENT YAW %1.3f ", (float)Data->orient.yaw);
|
||||
|
||||
printf("GFORCE X %1.3f \n", (float)data.gforce.x);
|
||||
printf("GFORCE Y %1.3f \n", (float)data.gforce.y);
|
||||
printf("GFORCE Z %1.3f \n", (float)data.gforce.z);
|
||||
*/
|
||||
/*
|
||||
if(sdlMotionButtons[KEY_LEFT]) {
|
||||
sensorX += 3;
|
||||
if(sensorX > 2197)
|
||||
sensorX = 2197;
|
||||
if(sensorX < 2047)
|
||||
sensorX = 2057;
|
||||
} else if(sdlMotionButtons[KEY_RIGHT]) {
|
||||
sensorX -= 3;
|
||||
if(sensorX < 1897)
|
||||
sensorX = 1897;
|
||||
if(sensorX > 2047)
|
||||
sensorX = 2037;
|
||||
} else if(sensorX > 2047) {
|
||||
sensorX -= 2;
|
||||
if(sensorX < 2047)
|
||||
sensorX = 2047;
|
||||
} else {
|
||||
sensorX += 2;
|
||||
if(sensorX > 2047)
|
||||
sensorX = 2047;
|
||||
}
|
||||
|
||||
if(sdlMotionButtons[KEY_UP]) {
|
||||
sensorY += 3;
|
||||
if(sensorY > 2197)
|
||||
sensorY = 2197;
|
||||
if(sensorY < 2047)
|
||||
sensorY = 2057;
|
||||
} else if(sdlMotionButtons[KEY_DOWN]) {
|
||||
sensorY -= 3;
|
||||
if(sensorY < 1897)
|
||||
sensorY = 1897;
|
||||
if(sensorY > 2047)
|
||||
sensorY = 2037;
|
||||
} else if(sensorY > 2047) {
|
||||
sensorY -= 2;
|
||||
if(sensorY < 2047)
|
||||
sensorY = 2047;
|
||||
} else {
|
||||
sensorY += 2;
|
||||
if(sensorY > 2047)
|
||||
sensorY = 2047;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* systemDrawScreen
|
||||
****************************************************************************/
|
||||
@ -571,7 +629,9 @@ static void ApplyPerImagePreferences()
|
||||
void LoadPatch(int method)
|
||||
{
|
||||
int patchsize = 0;
|
||||
int patchtype = -1;
|
||||
int patchtype;
|
||||
|
||||
ShowAction((char *)"Loading patch...");
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
@ -581,36 +641,13 @@ void LoadPatch(int method)
|
||||
sprintf(patchpath[1], "%s/%s.ups",currentdir,ROMFilename);
|
||||
sprintf(patchpath[2], "%s/%s.ppf",currentdir,ROMFilename);
|
||||
|
||||
ShowAction((char *)"Loading patch...");
|
||||
|
||||
switch (method)
|
||||
for(patchtype=0; patchtype<3; patchtype++)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
patchsize = LoadBufferFromFAT (patchpath[i], SILENT);
|
||||
patchsize = LoadFile(patchpath[patchtype], method, SILENT);
|
||||
|
||||
if(patchsize)
|
||||
{
|
||||
patchtype = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
patchsize = LoadBufferFromSMB (patchpath[i], SILENT);
|
||||
|
||||
if(patchsize)
|
||||
{
|
||||
patchtype = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(patchsize > 0)
|
||||
{
|
||||
@ -651,23 +688,33 @@ bool LoadGBROM(int method)
|
||||
|
||||
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
||||
|
||||
if(!inSz)
|
||||
{
|
||||
char filepath[1024];
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_ROM, method))
|
||||
return false;
|
||||
|
||||
gbRomSize = LoadFile ((char *)gbRom, filepath, filelist[selection].length, method, NOTSILENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
gbRomSize = LoadFATFile ((char *)gbRom, 0);
|
||||
gbRomSize = LoadFATSzFile(szpath, (unsigned char *)gbRom);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
gbRomSize = LoadDVDFile ((unsigned char *)gbRom, 0);
|
||||
gbRomSize = SzExtractFile(filelist[selection].offset, (unsigned char *)gbRom);
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
gbRomSize = LoadSMBFile ((char *)gbRom, 0);
|
||||
gbRomSize = LoadSMBSzFile(szpath, (unsigned char *)gbRom);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!gbRom)
|
||||
if(gbRomSize <= 0)
|
||||
return false;
|
||||
|
||||
return gbUpdateSizes();
|
||||
@ -823,21 +870,6 @@ bool LoadVBAROM(int method)
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* EEPROM
|
||||
****************************************************************************/
|
||||
int systemGetSensorX()
|
||||
{
|
||||
return sensorX;
|
||||
}
|
||||
|
||||
int systemGetSensorY()
|
||||
{
|
||||
return sensorY;
|
||||
}
|
||||
|
||||
void systemUpdateMotionSensor() {}
|
||||
|
||||
/****************************************************************************
|
||||
* Palette
|
||||
****************************************************************************/
|
||||
|
@ -173,30 +173,31 @@ bool VMCPULoadROM(int method)
|
||||
GBAROMSize = 0;
|
||||
rom = (u8 *)MEM2Storage;
|
||||
|
||||
if(!inSz)
|
||||
{
|
||||
char filepath[1024];
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_ROM, method))
|
||||
return false;
|
||||
|
||||
GBAROMSize = LoadFile ((char *)rom, filepath, filelist[selection].length, method, NOTSILENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(inSz)
|
||||
GBAROMSize = LoadFATSzFile(szpath, (unsigned char *)rom);
|
||||
else
|
||||
GBAROMSize = LoadFATFile((char *)rom, filelist[selection].length);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
if(inSz)
|
||||
GBAROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)rom);
|
||||
else
|
||||
GBAROMSize = LoadDVDFile((unsigned char *)rom, filelist[selection].length);
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
if(inSz)
|
||||
GBAROMSize = LoadSMBSzFile(szpath, (unsigned char *)rom);
|
||||
else
|
||||
GBAROMSize = LoadSMBFile((char *)rom, filelist[selection].length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(GBAROMSize)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user