tidy up some functions

This commit is contained in:
dborth 2008-09-26 22:28:57 +00:00
parent dfc7ddd8e3
commit 7f9f088ef3
7 changed files with 24 additions and 26 deletions

View File

@ -22,6 +22,8 @@ extern "C" {
} }
#endif #endif
#include "memmap.h"
#include "menudraw.h" #include "menudraw.h"
#include "snes9xGX.h" #include "snes9xGX.h"
#include "unzip.h" #include "unzip.h"
@ -436,13 +438,14 @@ bool SwitchDVDFolder(char origdir[])
***************************************************************************/ ***************************************************************************/
int int
LoadDVDFile (unsigned char *buffer) LoadDVDFile ()
{ {
int offset; int offset;
int blocks; int blocks;
int i; int i;
u64 discoffset; u64 discoffset;
char readbuffer[2048]; char readbuffer[2048];
unsigned char *rbuffer = (unsigned char *) Memory.ROM;
// How many 2k blocks to read // How many 2k blocks to read
blocks = dvddirlength / 2048; blocks = dvddirlength / 2048;
@ -456,7 +459,7 @@ LoadDVDFile (unsigned char *buffer)
for (i = 0; i < blocks; i++) for (i = 0; i < blocks; i++)
{ {
dvd_read (readbuffer, 2048, discoffset); dvd_read (readbuffer, 2048, discoffset);
memcpy (buffer + offset, readbuffer, 2048); memcpy (rbuffer + offset, readbuffer, 2048);
offset += 2048; offset += 2048;
discoffset += 2048; discoffset += 2048;
} }
@ -466,12 +469,12 @@ LoadDVDFile (unsigned char *buffer)
{ {
i = dvddirlength % 2048; i = dvddirlength % 2048;
dvd_read (readbuffer, 2048, discoffset); dvd_read (readbuffer, 2048, discoffset);
memcpy (buffer + offset, readbuffer, i); memcpy (rbuffer + offset, readbuffer, i);
} }
} }
else else
{ {
return UnZipFile (buffer, discoffset); // unzip from dvd return UnZipFile (rbuffer, discoffset); // unzip from dvd
} }
return dvddirlength; return dvddirlength;
} }

View File

@ -15,7 +15,7 @@
int getpvd (); int getpvd ();
int ParseDVDdirectory (); int ParseDVDdirectory ();
int LoadDVDFile (unsigned char *buffer); int LoadDVDFile ();
bool TestDVD(); bool TestDVD();
int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_read (void *dst, unsigned int len, u64 offset);
bool SwitchDVDFolder(char dir[]); bool SwitchDVDFolder(char dir[]);

View File

@ -166,16 +166,14 @@ ParseFATdirectory(int method)
* LoadFATFile * LoadFATFile
***************************************************************************/ ***************************************************************************/
int int
LoadFATFile (char *filename, int length) LoadFATFile ()
{ {
char zipbuffer[2048]; char zipbuffer[2048];
char filepath[MAXPATHLEN]; char filepath[MAXPATHLEN];
FILE *handle; FILE *handle;
unsigned char *rbuffer; unsigned char *rbuffer = (unsigned char *) Memory.ROM;
u32 size; u32 size;
rbuffer = (unsigned char *) Memory.ROM;
/* Check filename length */ /* Check filename length */
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
sprintf(filepath, "%s/%s",currentdir,filelist[selection].filename); sprintf(filepath, "%s/%s",currentdir,filelist[selection].filename);
@ -198,11 +196,10 @@ LoadFATFile (char *filename, int length)
{ {
// Just load the file up // Just load the file up
fseek(handle, 0, SEEK_END); fseek(handle, 0, SEEK_END);
length = ftell(handle); // get filesize size = ftell(handle); // get filesize
fseek(handle, 2048, SEEK_SET); // seek back to point where we left off fseek(handle, 2048, SEEK_SET); // seek back to point where we left off
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
fread (rbuffer + 2048, 1, length - 2048, handle); fread (rbuffer + 2048, 1, size - 2048, handle);
size = length;
} }
fclose (handle); fclose (handle);
return size; return size;

View File

@ -26,7 +26,7 @@
bool ChangeFATInterface(int method, bool silent); bool ChangeFATInterface(int method, bool silent);
int ParseFATdirectory(int method); int ParseFATdirectory(int method);
int LoadFATFile (char *filename, int length); int LoadFATFile ();
int SaveBufferToFAT (char *filepath, int datasize, bool silent); int SaveBufferToFAT (char *filepath, int datasize, bool silent);
int LoadBufferFromFAT (char *filepath, bool silent); int LoadBufferFromFAT (char *filepath, bool silent);

View File

@ -322,20 +322,18 @@ int FileSelector (int method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
ARAM_ROMSIZE = LoadFATFile (filelist[selection].filename, ARAM_ROMSIZE = LoadFATFile ();
filelist[selection].length);
break; break;
case METHOD_DVD: case METHOD_DVD:
dvddir = filelist[selection].offset; dvddir = filelist[selection].offset;
dvddirlength = filelist[selection].length; dvddirlength = filelist[selection].length;
ARAM_ROMSIZE = LoadDVDFile (Memory.ROM); ARAM_ROMSIZE = LoadDVDFile ();
break; break;
case METHOD_SMB: case METHOD_SMB:
ARAM_ROMSIZE = ARAM_ROMSIZE =
LoadSMBFile (filelist[selection].filename, LoadSMBFile ();
filelist[selection].length);
break; break;
} }

View File

@ -216,7 +216,7 @@ ParseSMBdirectory ()
* Load SMB file * Load SMB file
****************************************************************************/ ****************************************************************************/
int int
LoadSMBFile (char *filename, int length) LoadSMBFile ()
{ {
char filepath[MAXPATHLEN]; char filepath[MAXPATHLEN];
@ -236,7 +236,7 @@ LoadSMBFile (char *filename, int length)
* Write savebuffer to SMB file * Write savebuffer to SMB file
****************************************************************************/ ****************************************************************************/
int int
SaveBufferToSMB (char *filepath, int datasize, bool8 silent) SaveBufferToSMB (char *filepath, int datasize, bool silent)
{ {
if(!ConnectShare (NOTSILENT)) if(!ConnectShare (NOTSILENT))
return 0; return 0;
@ -282,14 +282,14 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent)
// no buffer is specified - so use savebuffer // no buffer is specified - so use savebuffer
int int
LoadBufferFromSMB (char *filepath, bool8 silent) LoadBufferFromSMB (char *filepath, bool silent)
{ {
ClearSaveBuffer (); ClearSaveBuffer ();
return LoadBufferFromSMB((char *)savebuffer, filepath, silent); return LoadBufferFromSMB((char *)savebuffer, filepath, silent);
} }
int int
LoadBufferFromSMB (char * sbuffer, char *filepath, bool8 silent) LoadBufferFromSMB (char * sbuffer, char *filepath, bool silent)
{ {
if(!ConnectShare (NOTSILENT)) if(!ConnectShare (NOTSILENT))
return 0; return 0;

View File

@ -19,9 +19,9 @@ bool ConnectShare (bool silent);
char * SMBPath(char * path); char * SMBPath(char * path);
int UpdateSMBdirname(); int UpdateSMBdirname();
int ParseSMBdirectory (); int ParseSMBdirectory ();
int LoadSMBFile (char *filename, int length); int LoadSMBFile ();
int LoadBufferFromSMB (char *filepath, bool8 silent); int LoadBufferFromSMB (char *filepath, bool silent);
int LoadBufferFromSMB (char * sbuffer, char *filepath, bool8 silent); int LoadBufferFromSMB (char * sbuffer, char *filepath, bool silent);
int SaveBufferToSMB (char *filepath, int datasize, bool8 silent); int SaveBufferToSMB (char *filepath, int datasize, bool silent);
#endif #endif