diff --git a/source/ngc/dvd.c b/source/ngc/dvd.c index 4b17e16..1a2dfc1 100644 --- a/source/ngc/dvd.c +++ b/source/ngc/dvd.c @@ -16,7 +16,7 @@ #include #include -#ifdef WII_DVD +#ifdef HW_RVL #include #endif @@ -24,11 +24,14 @@ #include "gcunzip.h" #include "fceugx.h" -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; +#define MAXDVDFILES 2000 + +static int diroffset = 0; +static u64 dvddir = 0; // offset of currently selected file or folder +static int dvddirlength = 0; // length of currently selected file or folder +static u64 dvdrootdir = 0; // offset of DVD root +static int dvdrootlength = 0; // length of DVD root +static bool isWii = false; #ifdef HW_DOL /** DVD I/O Address base **/ @@ -44,7 +47,7 @@ volatile unsigned long *dvd = (volatile unsigned long *) 0xCC006000; #define ALIGN_FORWARD(x,align) ((typeof(x))((((uint32_t)(x)) + (align) - 1) & (~(align-1)))) #define ALIGN_BACKWARD(x,align) ((typeof(x))(((uint32_t)(x)) & (~(align-1)))) -int +static int dvd_read (void *dst, unsigned int len, u64 offset) { if (len > 2048) @@ -108,30 +111,40 @@ dvd_read (void *dst, unsigned int len, u64 offset) #define DVD_MAX_READ_LENGTH 2048 #define DVD_SECTOR_SIZE 2048 -unsigned char dvdsf_buffer[DVD_SECTOR_SIZE]; -u64 dvdsf_last_offset = 0; -u64 dvdsf_last_length = 0; +static unsigned char dvdsf_buffer[DVD_SECTOR_SIZE]; +static u64 dvdsf_last_offset = 0; +static u64 dvdsf_last_length = 0; -int dvd_buffered_read(void *dst, u32 len, u64 offset) +static int dvd_buffered_read(void *dst, u32 len, u64 offset) { - int ret = 1; + int ret = 1; - // only read data if the data inside dvdsf_buffer cannot be used - if(offset != dvdsf_last_offset || len > dvdsf_last_length) - { - memset(&dvdsf_buffer, '\0', DVD_SECTOR_SIZE); - ret = dvd_read(&dvdsf_buffer, len, offset); - dvdsf_last_offset = offset; + // only read data if the data inside dvdsf_buffer cannot be used + if(offset != dvdsf_last_offset || len > dvdsf_last_length) + { + memset(&dvdsf_buffer, '\0', DVD_SECTOR_SIZE); + ret = dvd_read(&dvdsf_buffer, len, offset); + dvdsf_last_offset = offset; dvdsf_last_length = len; - } + } - memcpy(dst, &dvdsf_buffer, len); - return ret; + memcpy(dst, &dvdsf_buffer, len); + return ret; } -int dvd_safe_read(void *dst_v, u32 len, u64 offset) +/**************************************************************************** + * dvd_safe_read + * + * A 'safer' DVD read function + * This function relies on dvddir (file offset) being prepopulated! + * returns: 1 - ok ; 0 - error + ***************************************************************************/ + +int dvd_safe_read(void *dst_v, u32 len, u64 fileoffset) { - unsigned char buffer[DVD_SECTOR_SIZE]; // buffer for one dvd sector + u64 offset = dvddir + fileoffset; + + unsigned char buffer[DVD_SECTOR_SIZE]; // buffer for one dvd sector // if read size and length are a multiply of DVD_(OFFSET,LENGTH)_MULTIPLY and length < DVD_MAX_READ_LENGTH // we don't need to fix anything @@ -237,7 +250,7 @@ static int IsJoliet = 0; * The PVD should reside between sector 16 and 31. * This is for single session DVD only. ***************************************************************************/ -int +static int getpvd () { int sector = 16; @@ -311,7 +324,7 @@ bool MountDVD(bool silent) ShowAction("Loading DVD..."); #ifdef HW_DOL DVD_Mount(); // mount the DVD unit again - #elif WII_DVD + #elif HW_RVL u32 val; DI_GetCoverRegister(&val); if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside. @@ -340,7 +353,7 @@ bool MountDVD(bool silent) * Support function to return the next file entry, if any * Declared static to avoid accidental external entry. ***************************************************************************/ -static int diroffset = 0; + static int getentry (int entrycount, unsigned char dvdbuffer[]) { @@ -354,7 +367,7 @@ getentry (int entrycount, unsigned char dvdbuffer[]) u32 offset32; /* Basic checks */ - if (entrycount >= MAXFILES) + if (entrycount >= MAXDVDFILES) return 0; if (diroffset >= 2048) @@ -424,19 +437,26 @@ getentry (int entrycount, unsigned char dvdbuffer[]) if (rr != NULL) *rr = 0; - strcpy (filelist[entrycount].filename, fname); + browserList = (BROWSERENTRY *)realloc(browserList, (entrycount+1) * sizeof(BROWSERENTRY)); + if(!browserList) // failed to allocate required memory + { + WaitPrompt("Out of memory: too many files!"); + return 0; + } + memset(&(browserList[entrycount]), 0, sizeof(BROWSERENTRY)); // clear the new entry + + strcpy (browserList[entrycount].filename, fname); StripExt(tmpname, fname); // hide file extension - tmpname[MAXDISPLAY - 1] = 0; - strcpy (filelist[entrycount].displayname, tmpname); + strcpy (browserList[entrycount].displayname, tmpname); memcpy (&offset32, &dvdbuffer[diroffset + EXTENT], 4); - filelist[entrycount].offset = (u64)offset32; - memcpy (&filelist[entrycount].length, &dvdbuffer[diroffset + FILE_LENGTH], 4); - memcpy (&filelist[entrycount].flags, &dvdbuffer[diroffset + FILE_FLAGS], 1); + browserList[entrycount].offset = (u64)offset32; + memcpy (&(browserList[entrycount].length), &dvdbuffer[diroffset + FILE_LENGTH], 4); + memcpy (&(browserList[entrycount].isdir), &dvdbuffer[diroffset + FILE_FLAGS], 1); - filelist[entrycount].offset <<= 11; - filelist[entrycount].flags = filelist[entrycount].flags & 2; + browserList[entrycount].offset <<= 11; + browserList[entrycount].isdir = browserList[entrycount].isdir & 2; /*** Prepare for next entry ***/ @@ -448,7 +468,7 @@ getentry (int entrycount, unsigned char dvdbuffer[]) } /**************************************************************************** - * parseDVDdirectory + * ParseDVDdirectory * * This function will parse the directory tree. * It relies on dvddir and dvddirlength being pre-populated by a call to @@ -466,16 +486,13 @@ ParseDVDdirectory () int filecount = 0; unsigned char dvdbuffer[2048]; - // initialize selection - selection = offset = 0; + // reset browser + ResetBrowser(); pdoffset = rdoffset = dvddir; pdlength = dvddirlength; filecount = 0; - // Clear any existing values - memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); - /*** Get as many files as possible ***/ while (len < pdlength) { @@ -486,7 +503,7 @@ ParseDVDdirectory () while (getentry (filecount, dvdbuffer)) { - if(strlen(filelist[filecount].filename) > 0 && filecount < MAXFILES) + if(strlen(browserList[filecount].filename) > 0 && filecount < MAXDVDFILES) filecount++; } @@ -495,35 +512,46 @@ ParseDVDdirectory () } // Sort the file list - qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback); + qsort(browserList, filecount, sizeof(BROWSERENTRY), FileSortCallback); return filecount; } +/**************************************************************************** + * SetDVDdirectory + * Set the current DVD file offset + ***************************************************************************/ + +void SetDVDdirectory(u64 dir, int length) +{ + dvddir = dir; + dvddirlength = length; +} + /**************************************************************************** * DirectorySearch * * Searches for the directory name specified within the current directory * Returns the index of the directory, or -1 if not found ***************************************************************************/ -int DirectorySearch(char dir[512]) +static int DirectorySearch(char dir[512]) { int i; - for (i = 0; i < maxfiles; i++ ) - if (strcmp(filelist[i].filename, dir) == 0) + for (i = 0; i < browser.numEntries; i++ ) + if (strcmp(browserList[i].filename, dir) == 0) return i; return -1; } /**************************************************************************** - * SwitchDVDFolder + * SwitchDVDFolderR * * Recursively searches for any directory path 'dir' specified * Also can be used to find and set the offset for a file * Also loads the directory contents via ParseDVDdirectory() * It relies on dvddir, dvddirlength, and filelist being pre-populated ***************************************************************************/ -bool SwitchDVDFolderR(char * dir, int maxDepth) +static bool SwitchDVDFolderR(char * dir, int maxDepth) { if(maxDepth > 8) // only search to a max depth of 8 levels return false; @@ -543,12 +571,12 @@ bool SwitchDVDFolderR(char * dir, int maxDepth) if(dirindex >= 0) { - dvddir = filelist[dirindex].offset; - dvddirlength = filelist[dirindex].length; - selection = dirindex; + dvddir = browserList[dirindex].offset; + dvddirlength = browserList[dirindex].length; + browser.selIndex = dirindex; - if(filelist[dirindex].flags) // only parse directories - maxfiles = ParseDVDdirectory(); + if(browserList[dirindex].isdir) // only parse directories + browser.numEntries = ParseDVDdirectory(); if(lastdir) return true; @@ -582,12 +610,9 @@ bool SwitchDVDFolder(char origdir[]) } /**************************************************************************** - * LoadDVDFile + * LoadDVDFileOffset * This function will load a file from DVD - * The values for offset and length are inherited from dvddir and - * dvddirlength. - * - * The buffer parameter should re-use the initial ROM buffer + * It assumes dvddir and dvddirlength are prepopulated ***************************************************************************/ int @@ -649,6 +674,13 @@ LoadDVDFileOffset (unsigned char *buffer, int length) return dvddirlength; } +/**************************************************************************** + * LoadDVDFile + * This function will load a file from DVD, given a filepath + * It will attempt to find the offset of the file, and if successful it + * will populate dvddir and dvddirlength, and load the file + ***************************************************************************/ + int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent) { diff --git a/source/ngc/dvd.h b/source/ngc/dvd.h index 67dccce..6175947 100644 --- a/source/ngc/dvd.h +++ b/source/ngc/dvd.h @@ -12,20 +12,18 @@ #ifndef _DVD_H_ #define _DVD_H_ -int getpvd (); bool MountDVD(bool silent); -int ParseDVDdirectory (); +int ParseDVDdirectory(); +void SetDVDdirectory(u64 dir, int length); +bool SwitchDVDFolder(char dir[]); + int LoadDVDFileOffset(unsigned char *buffer, int length); int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent); -int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_safe_read (void *dst, unsigned int len, u64 offset); -bool SwitchDVDFolder(char dir[]); + void SetDVDDriveType(); #ifdef HW_DOL void dvd_motor_off (); #endif -extern u64 dvddir; -extern int dvddirlength; - #endif diff --git a/source/ngc/fceugx.c b/source/ngc/fceugx.c index 1f2b911..f80d7d4 100644 --- a/source/ngc/fceugx.c +++ b/source/ngc/fceugx.c @@ -44,7 +44,6 @@ int ConfigRequested = 0; int ShutdownRequested = 0; int ResetRequested = 0; char appPath[1024]; -bool isWii; uint8 *xbsave=NULL; int frameskip = 0; @@ -60,7 +59,7 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); * Shutdown / Reboot / Exit ***************************************************************************/ -void ExitCleanup() +static void ExitCleanup() { LWP_SuspendThread (devicethread); UnmountAllFAT(); @@ -123,7 +122,7 @@ void ShutdownWii() * lowlevel Qoob Modchip disable ***************************************************************************/ -void ipl_set_config(unsigned char c) +static void ipl_set_config(unsigned char c) { volatile unsigned long* exi = (volatile unsigned long*)0xCC006800; unsigned long val,addr; @@ -143,7 +142,7 @@ void ipl_set_config(unsigned char c) } #endif -void CreateAppPath(char origpath[]) +static void CreateAppPath(char origpath[]) { #ifdef HW_DOL sprintf(appPath, GCSettings.SaveFolder); @@ -178,7 +177,7 @@ int main(int argc, char *argv[]) ipl_set_config(6); // disable Qoob modchip #endif - #ifdef WII_DVD + #ifdef HW_RVL DI_Init(); // first #endif diff --git a/source/ngc/fceuload.c b/source/ngc/fceuload.c index feceab5..9d1e340 100644 --- a/source/ngc/fceuload.c +++ b/source/ngc/fceuload.c @@ -43,7 +43,7 @@ FCEUFILE *fceufp = NULL; MEMWRAP *fceumem = NULL; unsigned char * fceuFileData = NULL; -void MakeFCEUFile(char * membuffer, int length) +static void MakeFCEUFile(char * membuffer, int length) { if(fceufp != NULL) { diff --git a/source/ngc/fceuram.c b/source/ngc/fceuram.c index ea24450..4b5e095 100644 --- a/source/ngc/fceuram.c +++ b/source/ngc/fceuram.c @@ -43,9 +43,9 @@ extern u32 iNESGameCRC32; extern CartInfo iNESCart; extern CartInfo UNIFCart; -int NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation, int method) +static u32 NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation, int method) { - int offset = 0; + u32 offset = 0; char comment[2][32]; memset(comment, 0, 64); diff --git a/source/ngc/fceustate.c b/source/ngc/fceustate.c index e9c43ab..30c8afb 100644 --- a/source/ngc/fceustate.c +++ b/source/ngc/fceustate.c @@ -48,26 +48,21 @@ extern u32 iNESGameCRC32; #define RLSB 0x80000000 -int sboffset; /*** Used as a basic fileptr ***/ -int mcversion = 0x981211; +static int sboffset; /*** Used as a basic fileptr ***/ +static int mcversion = 0x981211; /**************************************************************************** * Memory based file functions ****************************************************************************/ /*** Open a file ***/ -void memopen() +static void memopen() { sboffset = 0; } -/*** Close a file ***/ -void memclose() { - sboffset = 0; -} - /*** Write to the file ***/ -void memfwrite( void *buffer, int len ) { +static void memfwrite( void *buffer, int len ) { if ( (sboffset + len ) > SAVEBUFFERSIZE) WaitPrompt("Buffer Exceeded"); @@ -78,7 +73,7 @@ void memfwrite( void *buffer, int len ) { } /*** Read from a file ***/ -void memfread( void *buffer, int len ) { +static void memfread( void *buffer, int len ) { if ( ( sboffset + len ) > SAVEBUFFERSIZE) WaitPrompt("Buffer exceeded"); @@ -94,7 +89,7 @@ void memfread( void *buffer, int len ) { * * Read the array of SFORMAT structures to memory ****************************************************************************/ -int GCReadChunk(int chunkid, SFORMAT *sf) +static int GCReadChunk(int chunkid, SFORMAT *sf) { int csize; static char chunk[6]; @@ -154,7 +149,7 @@ int GCReadChunk(int chunkid, SFORMAT *sf) * * Reads the SFORMAT arrays ****************************************************************************/ -int GCFCEUSS_Load(int method) +static int GCFCEUSS_Load(int method) { memopen(); // reset file pointer @@ -202,7 +197,7 @@ int GCFCEUSS_Load(int method) * * Write the array of SFORMAT structures to the file ****************************************************************************/ -int GCSaveChunk(int chunkid, SFORMAT *sf) +static int GCSaveChunk(int chunkid, SFORMAT *sf) { int chnkstart; int csize = 0; @@ -257,7 +252,7 @@ int GCSaveChunk(int chunkid, SFORMAT *sf) extern void (*SPreSave)(void); extern void (*SPostSave)(void); -int GCFCEUSS_Save(int method) +static int GCFCEUSS_Save(int method) { int totalsize = 0; static unsigned char header[16] = "FCS\xff"; diff --git a/source/ngc/fileop.c b/source/ngc/fileop.c index 34bc2cc..eeaf681 100644 --- a/source/ngc/fileop.c +++ b/source/ngc/fileop.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -31,8 +32,8 @@ #include "menudraw.h" #include "filesel.h" -// file pointer - the only one we should ever use! -FILE * file; +unsigned char * savebuffer = NULL; +FILE * file; // file pointer - the only one we should ever use! bool unmountRequired[9] = { false, false, false, false, false, false, false, false, false }; bool isMounted[9] = { false, false, false, false, false, false, false, false, false }; @@ -101,7 +102,6 @@ devicecallback (void *arg) #endif usleep(500000); // suspend thread for 1/2 sec } - return NULL; } @@ -254,7 +254,6 @@ bool ChangeInterface(int method, bool silent) int ParseDirectory() { - int nbfiles = 0; DIR_ITER *dir; char fulldir[MAXPATHLEN]; char filename[MAXPATHLEN]; @@ -262,14 +261,11 @@ ParseDirectory() struct stat filestat; char msg[128]; - // initialize selection - selection = offset = 0; - - // Clear any existing values - memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); + // reset browser + ResetBrowser(); // add device to path - sprintf(fulldir, "%s%s", rootdir, currentdir); + sprintf(fulldir, "%s%s", rootdir, browser.dir); // open the directory dir = diropen(fulldir); @@ -282,7 +278,7 @@ ParseDirectory() // if we can't open the dir, open root dir sprintf(fulldir,"%s",rootdir); - dir = diropen(currentdir); + dir = diropen(browser.dir); if (dir == NULL) { @@ -293,17 +289,29 @@ ParseDirectory() } // index files/folders + int entryNum = 0; + while(dirnext(dir,filename,&filestat) == 0) { if(strcmp(filename,".") != 0) { - memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES)); - strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN); + browserList = (BROWSERENTRY *)realloc(browserList, (entryNum+1) * sizeof(BROWSERENTRY)); + + if(!browserList) // failed to allocate required memory + { + WaitPrompt("Out of memory: too many files!"); + entryNum = 0; + break; + } + memset(&(browserList[entryNum]), 0, sizeof(BROWSERENTRY)); // clear the new entry + + strncpy(browserList[entryNum].filename, filename, MAXJOLIET); StripExt(tmpname, filename); // hide file extension - strncpy(filelist[nbfiles].displayname, tmpname, MAXDISPLAY+1); // crop name for display - filelist[nbfiles].length = filestat.st_size; - filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir - nbfiles++; + strncpy(browserList[entryNum].displayname, tmpname, MAXDISPLAY); // crop name for display + browserList[entryNum].length = filestat.st_size; + browserList[entryNum].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir + + entryNum++; } } @@ -311,9 +319,36 @@ ParseDirectory() dirclose(dir); // Sort the file list - qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); + qsort(browserList, entryNum, sizeof(BROWSERENTRY), FileSortCallback); - return nbfiles; + return entryNum; +} + +/**************************************************************************** + * AllocSaveBuffer () + * Clear and allocate the savebuffer + ***************************************************************************/ +void +AllocSaveBuffer () +{ + if (savebuffer != NULL) + free(savebuffer); + + savebuffer = (unsigned char *) memalign(32, SAVEBUFFERSIZE); + memset (savebuffer, 0, SAVEBUFFERSIZE); +} + +/**************************************************************************** + * FreeSaveBuffer () + * Free the savebuffer memory + ***************************************************************************/ +void +FreeSaveBuffer () +{ + if (savebuffer != NULL) + free(savebuffer); + + savebuffer = NULL; } /**************************************************************************** @@ -333,7 +368,7 @@ LoadSzFile(char * filepath, unsigned char * rbuffer) file = fopen (filepath, "rb"); if (file > 0) { - size = SzExtractFile(filelist[selection].offset, rbuffer); + size = SzExtractFile(browserList[browser.selIndex].offset, rbuffer); fclose (file); } else @@ -503,4 +538,3 @@ u32 SaveFile(char filepath[], u32 datasize, int method, bool silent) { return SaveFileBuf((char *)savebuffer, filepath, datasize, method, silent); } - diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index f6be116..5b7cf1b 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -6,11 +6,11 @@ * * fatop.h * - * FAT File operations + * File operations ****************************************************************************/ -#ifndef _FATOP_H_ -#define _FATOP_H_ +#ifndef _FILEOP_H_ +#define _FILEOP_H_ #include #include #include @@ -18,18 +18,22 @@ #include #include +#define SAVEBUFFERSIZE (1024 * 512) + void InitDeviceThread(); void MountAllFAT(); void UnmountAllFAT(); bool ChangeInterface(int method, bool silent); int ParseDirectory(); +void AllocSaveBuffer(); +void FreeSaveBuffer(); u32 LoadFileBuf(char * rbuffer, char *filepath, u32 length, int method, bool silent); u32 LoadFile(char filepath[], int method, bool silent); u32 LoadSzFile(char * filepath, unsigned char * rbuffer); u32 SaveFileBuf(char * buffer, char *filepath, u32 datasize, int method, bool silent); u32 SaveFile(char filepath[], u32 datasize, int method, bool silent); -extern char currFATdir[MAXPATHLEN]; +extern unsigned char * savebuffer; extern FILE * file; extern bool unmountRequired[]; extern bool isMounted[]; diff --git a/source/ngc/filesel.c b/source/ngc/filesel.c index 3b02341..3aec8e6 100644 --- a/source/ngc/filesel.c +++ b/source/ngc/filesel.c @@ -15,7 +15,7 @@ #include #include -#ifdef WII_DVD +#ifdef HW_RVL #include #endif @@ -31,48 +31,15 @@ #include "fceuload.h" #include "gcunzip.h" -int offset; -int selection; +BROWSERINFO browser; +BROWSERENTRY * browserList = NULL; // list of files/folders in browser + char rootdir[10]; -char currentdir[MAXPATHLEN]; -char szpath[MAXPATHLEN]; +static char szpath[MAXPATHLEN]; +static bool inSz = false; + char romFilename[200]; int nesGameType; -int maxfiles; -extern int screenheight; - -// Global file entry table -FILEENTRIES filelist[MAXFILES]; -bool inSz = false; - -unsigned char *savebuffer = NULL; - -/**************************************************************************** - * AllocSaveBuffer () - * Allocate and clear the savebuffer - ***************************************************************************/ -void -AllocSaveBuffer () -{ - if (savebuffer != NULL) - free(savebuffer); - - savebuffer = (unsigned char *) malloc(SAVEBUFFERSIZE); - memset (savebuffer, 0, SAVEBUFFERSIZE); -} - -/**************************************************************************** - * FreeSaveBuffer () - * Free the savebuffer memory - ***************************************************************************/ -void -FreeSaveBuffer () -{ - if (savebuffer != NULL) - free(savebuffer); - - savebuffer = NULL; -} /**************************************************************************** * autoLoadMethod() @@ -131,6 +98,25 @@ int autoSaveMethod(bool silent) return method; } +/**************************************************************************** + * ResetBrowser() + * Clears the file browser memory, and allocates one initial entry + ***************************************************************************/ +void ResetBrowser() +{ + browser.selIndex = browser.pageIndex = 0; + + // Clear any existing values + if(browserList != NULL) + { + free(browserList); + browserList = NULL; + } + // set aside space for 1 entry + browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY)); + memset(browserList, 0, sizeof(BROWSERENTRY)); +} + /**************************************************************************** * UpdateDirName() * Update curent directory name for file browser @@ -143,21 +129,18 @@ int UpdateDirName(int method) // update DVD directory if(method == METHOD_DVD) - { - dvddir = filelist[selection].offset; - dvddirlength = filelist[selection].length; - } + SetDVDdirectory(browserList[browser.selIndex].offset, browserList[browser.selIndex].length); /* current directory doesn't change */ - if (strcmp(filelist[selection].filename,".") == 0) + if (strcmp(browserList[browser.selIndex].filename,".") == 0) { return 0; } /* go up to parent directory */ - else if (strcmp(filelist[selection].filename,"..") == 0) + else if (strcmp(browserList[browser.selIndex].filename,"..") == 0) { /* determine last subdirectory namelength */ - sprintf(temp,"%s",currentdir); + sprintf(temp,"%s",browser.dir); test = strtok(temp,"/"); while (test != NULL) { @@ -166,8 +149,8 @@ int UpdateDirName(int method) } /* remove last subdirectory name */ - size = strlen(currentdir) - size - 1; - currentdir[size] = 0; + size = strlen(browser.dir) - size - 1; + browser.dir[size] = 0; return 1; } @@ -175,10 +158,10 @@ int UpdateDirName(int method) else { /* test new directory namelength */ - if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) + if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) < MAXPATHLEN) { /* update current directory name */ - sprintf(currentdir, "%s/%s",currentdir, filelist[selection].filename); + sprintf(browser.dir, "%s/%s",browser.dir, browserList[browser.selIndex].filename); return 1; } else @@ -198,7 +181,7 @@ bool MakeFilePath(char filepath[], int type, int method) if(type == FILE_ROM) { // Check path length - if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN) + if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN) { WaitPrompt("Maximum filepath length reached!"); filepath[0] = 0; @@ -206,7 +189,7 @@ bool MakeFilePath(char filepath[], int type, int method) } else { - sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename); + sprintf(temppath, "%s/%s",browser.dir,browserList[browser.selIndex].filename); } } else @@ -258,19 +241,19 @@ bool MakeFilePath(char filepath[], int type, int method) int FileSortCallback(const void *f1, const void *f2) { /* Special case for implicit directories */ - if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.') + if(((BROWSERENTRY *)f1)->filename[0] == '.' || ((BROWSERENTRY *)f2)->filename[0] == '.') { - if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; } - if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; } - if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; } - if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; } + if(strcmp(((BROWSERENTRY *)f1)->filename, ".") == 0) { return -1; } + if(strcmp(((BROWSERENTRY *)f2)->filename, ".") == 0) { return 1; } + if(strcmp(((BROWSERENTRY *)f1)->filename, "..") == 0) { return -1; } + if(strcmp(((BROWSERENTRY *)f2)->filename, "..") == 0) { return 1; } } /* If one is a file and one is a directory the directory is first. */ - if(((FILEENTRIES *)f1)->flags && !(((FILEENTRIES *)f2)->flags)) return -1; - if(!(((FILEENTRIES *)f1)->flags) && ((FILEENTRIES *)f2)->flags) return 1; + if(((BROWSERENTRY *)f1)->isdir && !(((BROWSERENTRY *)f2)->isdir)) return -1; + if(!(((BROWSERENTRY *)f1)->isdir) && ((BROWSERENTRY *)f2)->isdir) return 1; - return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); + return stricmp(((BROWSERENTRY *)f1)->filename, ((BROWSERENTRY *)f2)->filename); } /**************************************************************************** @@ -285,16 +268,16 @@ int FileSortCallback(const void *f1, const void *f2) bool IsValidROM(int method) { // file size should be between 10K and 3MB - if(filelist[selection].length < (1024*10) || - filelist[selection].length > (1024*1024*3)) + if(browserList[browser.selIndex].length < (1024*10) || + browserList[browser.selIndex].length > (1024*1024*3)) { WaitPrompt("Invalid file size!"); return false; } - if (strlen(filelist[selection].filename) > 4) + if (strlen(browserList[browser.selIndex].filename) > 4) { - char * p = strrchr(filelist[selection].filename, '.'); + char * p = strrchr(browserList[browser.selIndex].filename, '.'); if (p != NULL) { @@ -339,9 +322,9 @@ bool IsValidROM(int method) bool IsSz() { - if (strlen(filelist[selection].filename) > 4) + if (strlen(browserList[browser.selIndex].filename) > 4) { - char * p = strrchr(filelist[selection].filename, '.'); + char * p = strrchr(browserList[browser.selIndex].filename, '.'); if (p != NULL) if(stricmp(p, ".7z") == 0) @@ -394,7 +377,7 @@ int FileSelector (int method) while (haverom == 0) { if (redraw) - ShowFiles (filelist, maxfiles, offset, selection); + ShowFiles (browserList, browser.numEntries, browser.pageIndex, browser.selIndex); redraw = 0; VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads @@ -422,20 +405,16 @@ int FileSelector (int method) if ( selectit ) selectit = 0; - if (filelist[selection].flags) // This is directory + if (browserList[browser.selIndex].isdir) // This is directory { /* update current directory and set new entry list if directory has changed */ int status; - if(inSz && selection == 0) // inside a 7z, requesting to leave + if(inSz && browser.selIndex == 0) // inside a 7z, requesting to leave { if(method == METHOD_DVD) - { - // go to directory the 7z was in - dvddir = filelist[0].offset; - dvddirlength = filelist[0].length; - } + SetDVDdirectory(browserList[0].offset, browserList[0].length); inSz = false; status = 1; SzClose(); @@ -450,15 +429,15 @@ int FileSelector (int method) switch (method) { case METHOD_DVD: - maxfiles = ParseDVDdirectory(); + browser.numEntries = ParseDVDdirectory(); break; default: - maxfiles = ParseDirectory(); + browser.numEntries = ParseDirectory(); break; } - if (!maxfiles) + if (!browser.numEntries) { WaitPrompt ("Error reading directory!"); haverom = 1; // quit menu @@ -466,7 +445,7 @@ int FileSelector (int method) } else if (status == -1) // directory name too long { - haverom = 1; // quit menu + return 0; // quit menu } } else // this is a file @@ -486,7 +465,7 @@ int FileSelector (int method) int szfiles = SzParse(szpath, method); if(szfiles) { - maxfiles = szfiles; + browser.numEntries = szfiles; inSz = true; } else @@ -499,7 +478,7 @@ int FileSelector (int method) return 0; // store the filename (w/o ext) - used for state saving - StripExt(romFilename, filelist[selection].filename); + StripExt(romFilename, browserList[browser.selIndex].filename); ShowAction ("Loading..."); @@ -512,14 +491,14 @@ int FileSelector (int method) if(!MakeFilePath(filepath, FILE_ROM, method)) return 0; - size = LoadFileBuf((char *)nesrom, filepath, filelist[selection].length, method, NOTSILENT); + size = LoadFileBuf((char *)nesrom, filepath, browserList[browser.selIndex].length, method, NOTSILENT); } else { switch (method) { case METHOD_DVD: - size = SzExtractFile(filelist[selection].offset, nesrom); + size = SzExtractFile(browserList[browser.selIndex].offset, nesrom); break; default: size = LoadSzFile(szpath, nesrom); @@ -545,106 +524,125 @@ int FileSelector (int method) } redraw = 1; } // End of A - if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) - { - while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) + if ((p & PAD_BUTTON_B) + || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))) + { + while ((PAD_ButtonsDown(0) & PAD_BUTTON_B) #ifdef HW_RVL - || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) + || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) #endif - ) - VIDEO_WaitVSync(); - if ( strcmp(filelist[0].filename,"..") == 0 ) + ) + VIDEO_WaitVSync(); + if (strcmp(browserList[0].filename, "..") == 0) { - selection = 0; + browser.selIndex = 0; selectit = 1; } - else if ( strcmp(filelist[1].filename,"..") == 0 ) + else if (strcmp(browserList[1].filename, "..") == 0) { - selection = selectit = 1; - } else + browser.selIndex = selectit = 1; + } + else { - return 0; + return 0; } - } // End of B - if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) ) - { - if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/ - scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. - move_selection = 1; //continue (move selection) + } // End of B + if (((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN + | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay + < -PADCAL)) + { + if ((p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN + | WPAD_CLASSIC_BUTTON_DOWN))) + { /*** Button just pressed ***/ + scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. + move_selection = 1; //continue (move selection) } - else if (scroll_delay == 0) { /*** Button is held ***/ + else if (scroll_delay == 0) + { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; - move_selection = 1; //continue (move selection) - } else { - scroll_delay--; // wait + move_selection = 1; //continue (move selection) + } + else + { + scroll_delay--; // wait } if (move_selection) { - selection++; - if (selection == maxfiles) - selection = offset = 0; - if ((selection - offset) >= PAGESIZE) - offset += PAGESIZE; - redraw = 1; + browser.selIndex++; + if (browser.selIndex == browser.numEntries) + browser.selIndex = browser.pageIndex = 0; + if ((browser.selIndex - browser.pageIndex) >= PAGESIZE) + browser.pageIndex += PAGESIZE; + redraw = 1; move_selection = 0; } - } // End of down - if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) ) - { - if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/ - scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. - move_selection = 1; //continue (move selection) + } // End of down + if (((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP + | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay + > PADCAL)) + { + if ((p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP + | WPAD_CLASSIC_BUTTON_UP))) + { /*** Button just pressed***/ + scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. + move_selection = 1; //continue (move selection) } - else if (scroll_delay == 0) { /*** Button is held ***/ + else if (scroll_delay == 0) + { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; - move_selection = 1; //continue (move selection) - } else { - scroll_delay--; // wait + move_selection = 1; //continue (move selection) + } + else + { + scroll_delay--; // wait } if (move_selection) { - selection--; - if (selection < 0) { - selection = maxfiles - 1; - offset = selection - PAGESIZE + 1; - } - if (selection < offset) - offset -= PAGESIZE; - if (offset < 0) - offset = 0; - redraw = 1; + browser.selIndex--; + if (browser.selIndex < 0) + { + browser.selIndex = browser.numEntries - 1; + browser.pageIndex = browser.selIndex - PAGESIZE + 1; + } + if (browser.selIndex < browser.pageIndex) + browser.pageIndex -= PAGESIZE; + if (browser.pageIndex < 0) + browser.pageIndex = 0; + redraw = 1; move_selection = 0; } - } // End of Up - if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) ) - { - /*** Go back a page ***/ - selection -= PAGESIZE; - if (selection < 0) - { - selection = maxfiles - 1; - offset = selection - PAGESIZE + 1; - } - if (selection < offset) - offset -= PAGESIZE; - if (offset < 0) - offset = 0; - redraw = 1; - } - if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) ) - { - /*** Go forward a page ***/ - selection += PAGESIZE; - if (selection > maxfiles - 1) - selection = offset = 0; - if ((selection - offset) >= PAGESIZE) - offset += PAGESIZE; - redraw = 1; - } - } - return 0; + } // End of Up + if ((p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT + | WPAD_CLASSIC_BUTTON_LEFT))) + { + /*** Go back a page ***/ + browser.selIndex -= PAGESIZE; + if (browser.selIndex < 0) + { + browser.selIndex = browser.numEntries - 1; + browser.pageIndex = browser.selIndex - PAGESIZE + 1; + } + if (browser.selIndex < browser.pageIndex) + browser.pageIndex -= PAGESIZE; + if (browser.pageIndex < 0) + browser.pageIndex = 0; + redraw = 1; + } + if ((p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT + | WPAD_CLASSIC_BUTTON_RIGHT))) + { + /*** Go forward a page ***/ + browser.selIndex += PAGESIZE; + if (browser.selIndex > browser.numEntries - 1) + browser.selIndex = browser.pageIndex = 0; + if ((browser.selIndex - browser.pageIndex) >= PAGESIZE) + browser.pageIndex += PAGESIZE; + redraw = 1; + } + } + return 0; } /**************************************************************************** @@ -664,17 +662,17 @@ OpenROM (int method) switch(method) { case METHOD_DVD: - currentdir[0] = 0; - maxfiles = ParseDVDdirectory (); // Parse root directory + browser.dir[0] = 0; + browser.numEntries = ParseDVDdirectory(); // Parse root directory SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder break; default: - sprintf(currentdir, "/%s", GCSettings.LoadFolder); - maxfiles = ParseDirectory(); // Parse root directory + sprintf(browser.dir, "/%s", GCSettings.LoadFolder); + browser.numEntries = ParseDirectory(); // Parse root directory break; } - if (maxfiles > 0) + if (browser.numEntries > 0) { // Select an entry return FileSelector (method); diff --git a/source/ngc/filesel.h b/source/ngc/filesel.h index 1744286..790b7f7 100644 --- a/source/ngc/filesel.h +++ b/source/ngc/filesel.h @@ -14,38 +14,39 @@ #include -#define SAVEBUFFERSIZE (512 * 1024) #define MAXJOLIET 255 #define MAXDISPLAY 50 typedef struct { - u64 offset; - unsigned int length; - char flags; - char filename[MAXJOLIET + 1]; - char displayname[MAXDISPLAY + 1]; -} FILEENTRIES; + char dir[MAXPATHLEN]; // directory path of browserList + int numEntries; // # of entries in browserList + int selIndex; // currently selected index of browserList + int pageIndex; // starting index of browserList page display +} BROWSERINFO; -#define MAXFILES 2000 // Restrict to 2000 files per dir -extern FILEENTRIES filelist[MAXFILES]; -extern bool isWii; -extern int offset; -extern int selection; +typedef struct +{ + u64 offset; // DVD offset + unsigned int length; // file length + char isdir; // 0 - file, 1 - directory + char filename[MAXJOLIET + 1]; // full filename + char displayname[MAXDISPLAY + 1]; // name for browser display +} BROWSERENTRY; + +extern BROWSERINFO browser; +extern BROWSERENTRY * browserList; extern char rootdir[10]; -extern char currentdir[MAXPATHLEN]; -extern int maxfiles; -extern unsigned char *savebuffer; + extern char romFilename[]; extern int nesGameType; -void AllocSaveBuffer(); -void FreeSaveBuffer(); bool MakeFilePath(char filepath[], int type, int method); int OpenROM (int method); int autoLoadMethod(); int autoSaveMethod(bool silent); int FileSortCallback(const void *f1, const void *f2); void StripExt(char* returnstring, char * inputstring); +void ResetBrowser(); #endif diff --git a/source/ngc/gcaudio.c b/source/ngc/gcaudio.c index 03c0676..20daa33 100644 --- a/source/ngc/gcaudio.c +++ b/source/ngc/gcaudio.c @@ -21,7 +21,7 @@ static u8 mixbuffer[16000]; static int mixhead = 0; static int mixtail = 0; static int whichab = 0; -int IsPlaying = 0; +static int IsPlaying = 0; /**************************************************************************** * MixerCollect @@ -61,7 +61,7 @@ static int MixerCollect( u8 *outbuffer, int len ) * * Manages which buffer is played next ***************************************************************************/ -void AudioSwitchBuffers() +static void AudioSwitchBuffers() { if ( !ConfigRequested ) { diff --git a/source/ngc/gcunzip.c b/source/ngc/gcunzip.c index 3213e94..a1476e7 100644 --- a/source/ngc/gcunzip.c +++ b/source/ngc/gcunzip.c @@ -25,18 +25,32 @@ #include "menudraw.h" #include "gcunzip.h" -/* - * PKWare Zip Header - adopted into zip standard - */ -#define PKZIPID 0x504b0304 -#define MAXROM 0x500000 #define ZIPCHUNK 2048 +/* + * Zip file header definition + */ +typedef struct +{ + unsigned int zipid __attribute__ ((__packed__)); // 0x04034b50 + unsigned short zipversion __attribute__ ((__packed__)); + unsigned short zipflags __attribute__ ((__packed__)); + unsigned short compressionMethod __attribute__ ((__packed__)); + unsigned short lastmodtime __attribute__ ((__packed__)); + unsigned short lastmoddate __attribute__ ((__packed__)); + unsigned int crc32 __attribute__ ((__packed__)); + unsigned int compressedSize __attribute__ ((__packed__)); + unsigned int uncompressedSize __attribute__ ((__packed__)); + unsigned short filenameLength __attribute__ ((__packed__)); + unsigned short extraDataLength __attribute__ ((__packed__)); +} +PKZIPHEADER; + /* * Zip files are stored little endian * Support functions for short and int types */ -u32 +static u32 FLIP32 (u32 b) { unsigned int c; @@ -49,7 +63,7 @@ FLIP32 (u32 b) return c; } -u16 +static u16 FLIP16 (u16 b) { u16 c; @@ -63,7 +77,7 @@ FLIP16 (u16 b) /**************************************************************************** * IsZipFile * - * Returns TRUE when PKZIPID is first four characters of buffer + * Returns TRUE when 0x504b0304 is first four characters of buffer ***************************************************************************/ int IsZipFile (char *buffer) @@ -72,7 +86,7 @@ IsZipFile (char *buffer) check = (unsigned int *) buffer; - if (check[0] == PKZIPID) + if (check[0] == 0x504b0304) return 1; return 0; @@ -80,8 +94,6 @@ IsZipFile (char *buffer) /***************************************************************************** * UnZipBuffer -* -* It should be noted that there is a limit of 5MB total size for any ROM ******************************************************************************/ int @@ -97,15 +109,13 @@ UnZipBuffer (unsigned char *outbuffer, int method) int readoffset = 0; int have = 0; char readbuffer[ZIPCHUNK]; - u64 discoffset = 0; int sizeread = 0; // Read Zip Header switch (method) { case METHOD_DVD: - discoffset = dvddir; - sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset); + sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, 0); break; default: fseek(file, 0, SEEK_SET); @@ -179,7 +189,7 @@ UnZipBuffer (unsigned char *outbuffer, int method) { case METHOD_DVD: readoffset += ZIPCHUNK; - sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset+readoffset); + sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, readoffset); break; default: sizeread = fread (readbuffer, 1, ZIPCHUNK, file); @@ -255,7 +265,7 @@ typedef struct _SzFileInStream } SzFileInStream; // 7zip error list -char szerrormsg[][30] = { +static char szerrormsg[][30] = { "7z: Data error", "7z: Out of memory", "7z: CRC Error", @@ -266,20 +276,19 @@ char szerrormsg[][30] = { "7z: Dictionary too large", }; -SZ_RESULT SzRes; +static SZ_RESULT SzRes; +static SzFileInStream SzArchiveStream; +static CArchiveDatabaseEx SzDb; +static ISzAlloc SzAllocImp; +static ISzAlloc SzAllocTempImp; +static UInt32 SzBlockIndex = 0xFFFFFFFF; +static size_t SzBufferSize; +static size_t SzOffset; +static size_t SzOutSizeProcessed; +static CFileItem *SzF; -SzFileInStream SzArchiveStream; -CArchiveDatabaseEx SzDb; -ISzAlloc SzAllocImp; -ISzAlloc SzAllocTempImp; -UInt32 SzBlockIndex = 0xFFFFFFFF; -size_t SzBufferSize; -size_t SzOffset; -size_t SzOutSizeProcessed; -CFileItem *SzF; - -char sz_buffer[2048]; -int szMethod = 0; +static char sz_buffer[2048]; +static int szMethod = 0; /**************************************************************************** * Is7ZipFile @@ -304,13 +313,13 @@ Is7ZipFile (char *buffer) } // display an error message -void SzDisplayError(SZ_RESULT res) +static void SzDisplayError(SZ_RESULT res) { WaitPrompt(szerrormsg[(res - 1)]); } // function used by the 7zip SDK to read data from SD/USB/DVD/SMB -SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize) +static SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize) { u32 seekok = 0; u32 sizeread = 0; @@ -337,12 +346,7 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz } if(seekok != 0 || sizeread <= 0) - { - char msg[150]; - sprintf(msg, "sizeread: %u", sizeread); - WaitPrompt(msg); return SZE_FAILREAD; - } *buffer = sz_buffer; *processedSize = maxRequiredSize; @@ -350,13 +354,13 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz if(maxRequiredSize > 1024) // only show progress for large reads // this isn't quite right, but oh well - ShowProgress ("Loading...", s->pos, filelist[selection].length); + ShowProgress ("Loading...", s->pos, browserList[browser.selIndex].length); return SZ_OK; } // function used by the 7zip SDK to change the filepointer -SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) +static SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) { // the void* object is a SzFileInStream SzFileInStream *s = (SzFileInStream *) object; @@ -374,17 +378,23 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) * SzParse * * Opens a 7z file, and parses it -* Right now doesn't parse 7z, since we'll always use the first file -* But it could parse the entire 7z for full browsing capability +* It parses the entire 7z for full browsing capability ***************************************************************************/ int SzParse(char * filepath, int method) { + if(!filepath) + return 0; + int nbfiles = 0; - // save the offset and the length of this file inside the archive stream structure - SzArchiveStream.offset = filelist[selection].offset; - SzArchiveStream.len = filelist[selection].length; + // save the length/offset of this file + unsigned int filelen = browserList[browser.selIndex].length; + u64 fileoff = browserList[browser.selIndex].offset; + + // setup archive stream + SzArchiveStream.offset = 0; + SzArchiveStream.len = filelen; SzArchiveStream.pos = 0; // open file @@ -397,6 +407,9 @@ int SzParse(char * filepath, int method) if(!file) return 0; break; + case METHOD_DVD: + SwitchDVDFolder(filepath); + break; } // set szMethod to current chosen load method @@ -432,14 +445,14 @@ int SzParse(char * filepath, int method) { // Parses the 7z into a full file listing - // erase all previous entries - memset(&filelist, 0, sizeof(FILEENTRIES) * MAXFILES); + // reset browser + ResetBrowser(); // add '..' folder in case the user wants exit the 7z - strncpy(filelist[0].displayname, "..", 2); - filelist[0].flags = 1; - filelist[0].offset = dvddir; - filelist[0].length = dvddirlength; + strncpy(browserList[0].displayname, "..", 2); + browserList[0].isdir = 1; + browserList[0].offset = fileoff; + browserList[0].length = filelen; // get contents and parse them into file list structure unsigned int SzI, SzJ; @@ -452,22 +465,25 @@ int SzParse(char * filepath, int method) if (SzF->IsDirectory) continue; - // do not exceed MAXFILES to avoid possible buffer overflows - if (SzJ == (MAXFILES - 1)) + browserList = (BROWSERENTRY *)realloc(browserList, (SzJ+1) * sizeof(BROWSERENTRY)); + + if(!browserList) // failed to allocate required memory + { + WaitPrompt("Out of memory: too many files!"); + nbfiles = 0; break; + } + memset(&(browserList[SzJ]), 0, sizeof(BROWSERENTRY)); // clear the new entry // parse information about this file to the dvd file list structure - strncpy(filelist[SzJ].filename, SzF->Name, MAXJOLIET); // copy joliet name (useless...) - filelist[SzJ].filename[MAXJOLIET] = 0; // terminate string - strncpy(filelist[SzJ].displayname, SzF->Name, MAXDISPLAY+1); // crop name for display - filelist[SzJ].length = SzF->Size; // filesize - filelist[SzJ].offset = SzI; // the extraction function identifies the file with this number - filelist[SzJ].flags = 0; // only files will be displayed (-> no flags) + strncpy(browserList[SzJ].filename, SzF->Name, MAXJOLIET); // copy joliet name (useless...) + strncpy(browserList[SzJ].displayname, SzF->Name, MAXDISPLAY); // crop name for display + browserList[SzJ].length = SzF->Size; // filesize + browserList[SzJ].offset = SzI; // the extraction function identifies the file with this number + browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags) SzJ++; } - // update maxfiles and select the first entry - offset = selection = 0; nbfiles = SzJ; } else @@ -542,4 +558,3 @@ int SzExtractFile(int i, unsigned char *buffer) return SzOutSizeProcessed; } } - diff --git a/source/ngc/gcunzip.h b/source/ngc/gcunzip.h index 89b8f5f..bcea992 100644 --- a/source/ngc/gcunzip.h +++ b/source/ngc/gcunzip.h @@ -12,35 +12,11 @@ #ifndef _GCUNZIP_H_ #define _GCUNZIP_H_ -#include - -extern int IsZipFile (char *buffer); +int IsZipFile (char *buffer); char * GetFirstZipFilename(int method); int UnZipBuffer (unsigned char *outbuffer, int method); int SzParse(char * filepath, int method); int SzExtractFile(int i, unsigned char *buffer); void SzClose(); -/* - * Zip file header definition - */ -typedef struct -{ - unsigned int zipid __attribute__ ((__packed__)); // 0x04034b50 - unsigned short zipversion __attribute__ ((__packed__)); - unsigned short zipflags __attribute__ ((__packed__)); - unsigned short compressionMethod __attribute__ ((__packed__)); - unsigned short lastmodtime __attribute__ ((__packed__)); - unsigned short lastmoddate __attribute__ ((__packed__)); - unsigned int crc32 __attribute__ ((__packed__)); - unsigned int compressedSize __attribute__ ((__packed__)); - unsigned int uncompressedSize __attribute__ ((__packed__)); - unsigned short filenameLength __attribute__ ((__packed__)); - unsigned short extraDataLength __attribute__ ((__packed__)); -} -PKZIPHEADER; - -u32 FLIP32 (u32 b); -u16 FLIP16 (u16 b); - #endif diff --git a/source/ngc/gcvideo.c b/source/ngc/gcvideo.c index 0b5a593..fbc04f5 100644 --- a/source/ngc/gcvideo.c +++ b/source/ngc/gcvideo.c @@ -31,7 +31,7 @@ int FDSSwitchRequested; /*** External 2D Video ***/ /*** 2D Video Globals ***/ -GXRModeObj *vmode; // Graphics Mode Object +static GXRModeObj *vmode; // Graphics Mode Object unsigned int *xfb[2]; // Framebuffers int whichfb = 0; // Frame buffer toggle int screenheight; @@ -62,11 +62,11 @@ struct pcpal { unsigned char b; } pcpalette[256]; -unsigned int gcpalette[256]; // Much simpler GC palette -unsigned short rgb565[256]; // Texture map palette +static unsigned int gcpalette[256]; // Much simpler GC palette +static unsigned short rgb565[256]; // Texture map palette -long long prev; -long long now; +static long long prev; +static long long now; long long gettime(); u32 diff_usec(long long start,long long end); @@ -84,7 +84,7 @@ camera; This structure controls the size of the image on the screen. Think of the output as a -80 x 80 by -60 x 60 graph. ***/ -s16 square[] ATTRIBUTE_ALIGN (32) = +static s16 square[] ATTRIBUTE_ALIGN (32) = { /* * X, Y, Z @@ -109,7 +109,7 @@ static camera cam = { {0.0F, 0.0F, 0.0F}, /** Original NES PAL Resolutions: **/ /* 240 lines progressive (PAL 50Hz) */ -GXRModeObj PAL_240p = +static GXRModeObj PAL_240p = { VI_TVMODE_PAL_DS, // viDisplayMode 640, // fbWidth @@ -146,7 +146,7 @@ GXRModeObj PAL_240p = /** Original NES NTSC Resolutions: **/ /* 240 lines progressive (NTSC or PAL 60Hz) */ -GXRModeObj NTSC_240p = +static GXRModeObj NTSC_240p = { VI_TVMODE_EURGB60_DS, // viDisplayMode 640, // fbWidth @@ -181,7 +181,7 @@ GXRModeObj NTSC_240p = }; /* TV Modes table */ -GXRModeObj *tvmodes[2] = { +static GXRModeObj *tvmodes[2] = { &NTSC_240p, &PAL_240p }; @@ -190,7 +190,7 @@ GXRModeObj *tvmodes[2] = { * change frame timings depending on whether ROM is NTSC or PAL ***************************************************************************/ -int normaldiff; +static int normaldiff; void setFrameTimer() { @@ -202,7 +202,7 @@ void setFrameTimer() prev = gettime(); } -void SyncSpeed() +static void SyncSpeed() { now = gettime(); while (diff_usec(prev, now) < normaldiff) now = gettime(); @@ -213,8 +213,8 @@ void SyncSpeed() * VideoThreading ***************************************************************************/ #define TSTACK 16384 -lwpq_t videoblankqueue; -lwp_t vbthread; +static lwpq_t videoblankqueue; +static lwp_t vbthread; static unsigned char vbstack[TSTACK]; /**************************************************************************** @@ -448,7 +448,7 @@ UpdateScaling() * * called by postRetraceCallback in InitGCVideo - scans gcpad and wpad ***************************************************************************/ -void +static void UpdatePadsCB () { #ifdef HW_RVL @@ -814,7 +814,7 @@ showscreen () * Support routine for gcpalette ****************************************************************************/ -unsigned int rgbcolor(unsigned char r1, unsigned char g1, unsigned char b1, +static unsigned int rgbcolor(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2) { int y1,cb1,cr1,y2,cb2,cr2,cb,cr; diff --git a/source/ngc/memcardop.c b/source/ngc/memcardop.c index ad806e3..8994cb1 100644 --- a/source/ngc/memcardop.c +++ b/source/ngc/memcardop.c @@ -24,22 +24,16 @@ #include "fileop.h" #include "filesel.h" -#define VERIFBUFFERSIZE 65536 -static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); -unsigned char verifbuffer[VERIFBUFFERSIZE] ATTRIBUTE_ALIGN (32); -card_dir CardDir; -card_file CardFile; -card_stat CardStatus; - /**************************************************************************** * CardFileExists * * Wrapper to search through the files on the card. * Returns TRUE if found. ***************************************************************************/ -int +static int CardFileExists (char *filename, int slot) { + card_dir CardDir; int CardError; CardError = CARD_FindFirst (slot, &CardDir, TRUE); @@ -54,6 +48,28 @@ CardFileExists (char *filename, int slot) return 0; } +/**************************************************************************** + * MountCard + * + * Mounts the memory card in the given slot. + * Returns the result of the last attempted CARD_Mount command. + ***************************************************************************/ +static int MountCard(int cslot, bool silent, u8 * SysArea) +{ + int ret = -1; + int tries = 0; + + // Mount the card + while ( tries < 10 && ret != 0) + { + EXI_ProbeReset (); + ret = CARD_Mount (cslot, &SysArea, NULL); + VIDEO_WaitVSync (); + tries++; + } + return ret; +} + /**************************************************************************** * TestCard * @@ -67,11 +83,12 @@ bool TestCard(int slot, bool silent) #endif /*** Initialize Card System ***/ + u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("FCEU", "00"); /*** Try to mount the card ***/ - if (MountCard(slot, silent) == 0) + if (MountCard(slot, silent, (u8 *)SysArea) == 0) { // Mount successful! if(!silent) @@ -98,35 +115,14 @@ bool TestCard(int slot, bool silent) } } -/**************************************************************************** - * MountCard - * - * Mounts the memory card in the given slot. - * Returns the result of the last attempted CARD_Mount command. - ***************************************************************************/ -int MountCard(int cslot, bool silent) -{ - int ret = -1; - int tries = 0; - - // Mount the card - while ( tries < 10 && ret != 0) - { - EXI_ProbeReset (); - ret = CARD_Mount (cslot, SysArea, NULL); - VIDEO_WaitVSync (); - tries++; - } - return ret; -} - - /**************************************************************************** * Verify Memory Card file against buffer ***************************************************************************/ -int +static int VerifyMCFile (char *buf, int slot, char *filename, int datasize) { + card_file CardFile; + unsigned char verifbuffer[65536] ATTRIBUTE_ALIGN (32); int CardError; unsigned int blocks; unsigned int SectorSize; @@ -135,11 +131,12 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize) int bytesread = 0; /*** Initialize Card System ***/ + u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("FCEU", "00"); /*** Try to mount the card ***/ - CardError = MountCard(slot, NOTSILENT); + CardError = MountCard(slot, NOTSILENT, (u8 *)SysArea); if (CardError == 0) { @@ -167,7 +164,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize) if (blocks > (unsigned int)datasize) blocks = datasize; - memset (verifbuffer, 0, VERIFBUFFERSIZE); + memset (verifbuffer, 0, 65536); bytesleft = blocks; bytesread = 0; while (bytesleft > 0) @@ -208,6 +205,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize) int LoadMCFile (char *buf, int slot, char *filename, bool silent) { + card_file CardFile; int CardError; unsigned int blocks; unsigned int SectorSize; @@ -215,11 +213,12 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent) int bytesread = 0; /*** Initialize Card System ***/ + u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("FCEU", "00"); /*** Try to mount the card ***/ - CardError = MountCard(slot, NOTSILENT); + CardError = MountCard(slot, NOTSILENT, (u8 *)SysArea); if (CardError == 0) { @@ -273,6 +272,8 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent) int SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) { + card_file CardFile; + card_stat CardStatus; int CardError; unsigned int blocks; unsigned int SectorSize; @@ -282,11 +283,12 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) return 0; /*** Initialize Card System ***/ + u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("FCEU", "00"); /*** Try to mount the card ***/ - CardError = MountCard(slot, NOTSILENT); + CardError = MountCard(slot, NOTSILENT, (u8 *)SysArea); if (CardError == 0) { diff --git a/source/ngc/memcardop.h b/source/ngc/memcardop.h index 405a0b9..78a3a46 100644 --- a/source/ngc/memcardop.h +++ b/source/ngc/memcardop.h @@ -12,10 +12,8 @@ #ifndef _MEMCARDOP_H_ #define _MEMCARDOP_H_ -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); #endif diff --git a/source/ngc/menu.c b/source/ngc/menu.c index cbd71c0..e690a42 100644 --- a/source/ngc/menu.c +++ b/source/ngc/menu.c @@ -16,7 +16,7 @@ #include #include -#ifdef WII_DVD +#ifdef HW_RVL #include #endif @@ -69,23 +69,24 @@ LoadManager () /**************************************************************************** * Video Options Menu ****************************************************************************/ -static int videomenuCount = 8; -static char videomenu[][50] = { - "Video Rendering", - "Video Scaling", - "Video Cropping", - "Palette", - "Enable Zooming", - "Timing", - "8 Sprite Limit", - "Back to Preferences Menu" - -}; - -void +static void VideoOptions () { + int videomenuCount = 8; + char videomenu[][50] = { + + "Video Rendering", + "Video Scaling", + "Video Cropping", + "Palette", + "Enable Zooming", + "Timing", + "8 Sprite Limit", + "Back to Preferences Menu" + + }; + int ret = 0; int quit = 0; int oldmenu = menu; @@ -176,28 +177,28 @@ VideoOptions () menu = oldmenu; } - /**************************************************************************** * File Options Menu ****************************************************************************/ -static int filemenuCount = 8; -static char filemenu[][50] = { - "Load Method", - "Load Folder", - "Save Method", - "Save Folder", - - "Auto Load", - "Auto Save", - "Verify MC Saves", - - "Back to Preferences Menu" -}; - -void +static void FileOptions() { + int filemenuCount = 8; + char filemenu[][50] = { + + "Load Method", + "Load Folder", + "Save Method", + "Save Folder", + + "Auto Load", + "Auto Save", + "Verify MC Saves", + + "Back to Preferences Menu" + }; + int ret = 0; int quit = 0; int oldmenu = menu; @@ -323,7 +324,7 @@ FileOptions() * Game Options Menu ****************************************************************************/ -int +static int GameMenu () { int gamemenuCount = 9; @@ -433,7 +434,7 @@ GameMenu () * Here, I simply move the designated value to the gcpadmaps array, which saves * on updating the cmd sequences. ****************************************************************************/ -u32 +static u32 GetInput (u16 ctrlr_type) { //u32 exp_type; @@ -481,20 +482,20 @@ GetInput (u16 ctrlr_type) return pressed; } // end GetInput() -int cfg_text_count = 7; -char cfg_text[][50] = { -"Remapping ", -"Press Any Button", -"on the", -" ", // identify controller -" ", -"Press C-Left or", -"Home to exit" -}; - -u32 +static u32 GetButtonMap(u16 ctrlr_type, char* btn_name) { + int cfg_text_count = 7; + char cfg_text[][50] = { + "Remapping ", + "Press Any Button", + "on the", + " ", // identify controller + " ", + "Press C-Left or", + "Home to exit" + }; + u32 pressed, previous; char temp[50] = ""; uint k; @@ -532,30 +533,25 @@ GetButtonMap(u16 ctrlr_type, char* btn_name) return pressed; } // end getButtonMap() -int cfg_btns_count = 12; -char cfg_btns_menu[][50] = { - "B - ", - "A - ", - "RAPID B - ", - "RAPID A - ", - "SELECT - ", - "START - ", - "UP - ", - "DOWN - ", - "LEFT - ", - "RIGHT - ", - "SPECIAL - ", - "Return to previous" -}; - -extern unsigned int gcpadmap[]; -extern unsigned int wmpadmap[]; -extern unsigned int ccpadmap[]; -extern unsigned int ncpadmap[]; - -void +static void ConfigureButtons (u16 ctrlr_type) { + int cfg_btns_count = 12; + char cfg_btns_menu[][50] = { + "B - ", + "A - ", + "RAPID B - ", + "RAPID A - ", + "SELECT - ", + "START - ", + "UP - ", + "DOWN - ", + "LEFT - ", + "RIGHT - ", + "SPECIAL - ", + "Return to previous" + }; + int quit = 0; int ret = 0; int oldmenu = menu; @@ -647,21 +643,21 @@ ConfigureButtons (u16 ctrlr_type) menu = oldmenu; } // end configurebuttons() -int ctlrmenucount = 8; -char ctlrmenu[][50] = { - "Four Score", - "Zapper", - "Zapper Crosshair", - "Nunchuk", - "Classic Controller", - "Wiimote", - "Gamecube Pad", - "Back to Preferences Menu" -}; - -void +static void ConfigureControllers () { + int ctlrmenucount = 8; + char ctlrmenu[][50] = { + "Four Score", + "Zapper", + "Zapper Crosshair", + "Nunchuk", + "Classic Controller", + "Wiimote", + "Gamecube Pad", + "Back to Preferences Menu" + }; + int quit = 0; int ret = 0; int oldmenu = menu; @@ -741,18 +737,19 @@ ConfigureControllers () /**************************************************************************** * Preferences Menu ***************************************************************************/ -static int prefmenuCount = 5; -static char prefmenu[][50] = { - "Controllers", - "Video", - "Saving / Loading", - "Reset Preferences", - "Back to Main Menu" -}; void PreferencesMenu () { + int prefmenuCount = 5; + char prefmenu[][50] = { + "Controllers", + "Video", + "Saving / Loading", + "Reset Preferences", + "Back to Main Menu" + }; + int ret = 0; int quit = 0; int oldmenu = menu; @@ -794,20 +791,21 @@ PreferencesMenu () /**************************************************************************** * Main Menu ****************************************************************************/ -int menucount = 7; -char menuitems[][50] = { - "Choose Game", - "Preferences", - "Game Menu", - "Credits", - "DVD Motor Off", - "Reset System", - "Return to Loader" -}; void MainMenu (int selectedMenu) { + int menucount = 7; + char menuitems[][50] = { + "Choose Game", + "Preferences", + "Game Menu", + "Credits", + "DVD Motor Off", + "Reset System", + "Return to Loader" + }; + int quit = 0; int ret; diff --git a/source/ngc/menudraw.c b/source/ngc/menudraw.c index b2a02a4..4de173f 100644 --- a/source/ngc/menudraw.c +++ b/source/ngc/menudraw.c @@ -29,10 +29,9 @@ #include "networkop.h" /*** Globals ***/ -FT_Library ftlibrary; -FT_Face face; -FT_GlyphSlot slot; -FT_UInt glyph_index; +static FT_Library ftlibrary; +static FT_Face face; +static FT_GlyphSlot slot; static unsigned int fonthi, fontlo; extern char fontface[]; /*** From fontface.s ***/ @@ -585,7 +584,7 @@ RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x) ****************************************************************************/ void -ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection) +ShowFiles (BROWSERENTRY * browserList, int maxfiles, int offset, int selection) { int i, j; char text[MAXPATHLEN]; @@ -609,15 +608,15 @@ ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection) j = 0; for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++) { - if (filelist[i].flags) // if a dir + if (browserList[i].isdir) // if a dir { strcpy (text, "["); - strcat (text, filelist[i].displayname); + strcat (text, browserList[i].displayname); strcat (text, "]"); } else { - sprintf(text, filelist[i].displayname); + sprintf(text, browserList[i].displayname); } if (j == (selection - offset)) { diff --git a/source/ngc/menudraw.h b/source/ngc/menudraw.h index 81aaa16..c665c3b 100644 --- a/source/ngc/menudraw.h +++ b/source/ngc/menudraw.h @@ -26,7 +26,7 @@ void WaitButtonA (); int RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x); void DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize, int x); void ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, int selection); -void ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection); +void ShowFiles (BROWSERENTRY * browserList, int maxfiles, int offset, int selection); void WaitPrompt (const char *msg); int WaitPromptChoice (const char *msg, const char* bmsg, const char* amsg); diff --git a/source/ngc/networkop.c b/source/ngc/networkop.c index b2b73cb..d2e5cba 100644 --- a/source/ngc/networkop.c +++ b/source/ngc/networkop.c @@ -21,10 +21,10 @@ #include "fileop.h" #include "http.h" -bool networkInit = false; -bool autoNetworkInit = true; -bool networkShareInit = false; -bool updateChecked = false; // true if checked for app update +static bool networkInit = false; +static bool autoNetworkInit = true; +static bool networkShareInit = false; +static bool updateChecked = false; // true if checked for app update static char updateURL[128]; // URL of app update bool updateFound = false; // true if an app update was found @@ -90,7 +90,7 @@ void UpdateCheck() } } -bool unzipArchive(char * zipfilepath, char * unzipfolderpath) +static bool unzipArchive(char * zipfilepath, char * unzipfolderpath) { unzFile uf = unzOpen(zipfilepath); if (uf==NULL) diff --git a/source/ngc/pad.c b/source/ngc/pad.c index b0c9da1..0c03f87 100644 --- a/source/ngc/pad.c +++ b/source/ngc/pad.c @@ -28,8 +28,8 @@ extern bool romLoaded; static uint32 JSReturn = 0; void *InputDPR; -INPUTC *zapperdata[2]; -unsigned int myzappers[2][3]; +static INPUTC *zapperdata[2]; +static unsigned int myzappers[2][3]; extern INPUTC *FCEU_InitZapper(int w); @@ -243,10 +243,10 @@ s8 WPAD_StickY(u8 chan, u8 right) } // hold zapper cursor positions -int pos_x = 0; -int pos_y = 0; +static int pos_x = 0; +static int pos_y = 0; -void UpdateCursorPosition (int pad) +static void UpdateCursorPosition (int pad) { #define ZAPPERPADCAL 20 @@ -309,11 +309,11 @@ void UpdateCursorPosition (int pad) /**************************************************************************** * Convert GC Joystick Readings to JOY ****************************************************************************/ -int RAPID_SKIP = 2; // frames to skip between rapid button presses -int RAPID_PRESS = 2; // number of rapid button presses to execute -int rapidbutton[4][2] = {{0}}; +static int RAPID_SKIP = 2; // frames to skip between rapid button presses +static int RAPID_PRESS = 2; // number of rapid button presses to execute +static int rapidbutton[4][2] = {{0}}; -unsigned char DecodeJoy( unsigned short pad ) +static unsigned char DecodeJoy( unsigned short pad ) { signed char pad_x = PAD_StickX (pad); signed char pad_y = PAD_StickY (pad); diff --git a/source/ngc/preferences.c b/source/ngc/preferences.c index 6370399..2026f0e 100644 --- a/source/ngc/preferences.c +++ b/source/ngc/preferences.c @@ -22,49 +22,42 @@ #include "pad.h" extern const unsigned short saveicon[1024]; -extern int currconfig[4]; -// button map configurations -extern unsigned int gcpadmap[]; -extern unsigned int wmpadmap[]; -extern unsigned int ccpadmap[]; -extern unsigned int ncpadmap[]; - -char prefscomment[2][32]; +static char prefscomment[2][32]; /**************************************************************************** * Prepare Preferences Data * * This sets up the save buffer for saving. ****************************************************************************/ -mxml_node_t *xml; -mxml_node_t *data; -mxml_node_t *section; -mxml_node_t *item; -mxml_node_t *elem; +static mxml_node_t *xml; +static mxml_node_t *data; +static mxml_node_t *section; +static mxml_node_t *item; +static mxml_node_t *elem; -char temp[200]; +static char temp[200]; -const char * toStr(int i) +static const char * toStr(int i) { sprintf(temp, "%d", i); return temp; } -const char * FtoStr(float i) +static const char * FtoStr(float i) { sprintf(temp, "%.2f", i); return temp; } -void createXMLSection(const char * name, const char * description) +static void createXMLSection(const char * name, const char * description) { section = mxmlNewElement(data, "section"); mxmlElementSetAttr(section, "name", name); mxmlElementSetAttr(section, "description", description); } -void createXMLSetting(const char * name, const char * description, const char * value) +static void createXMLSetting(const char * name, const char * description, const char * value) { item = mxmlNewElement(section, "setting"); mxmlElementSetAttr(item, "name", name); @@ -72,7 +65,7 @@ void createXMLSetting(const char * name, const char * description, const char * mxmlElementSetAttr(item, "description", description); } -void createXMLController(unsigned int controller[], const char * name, const char * description) +static void createXMLController(unsigned int controller[], const char * name, const char * description) { item = mxmlNewElement(section, "controller"); mxmlElementSetAttr(item, "name", name); @@ -88,7 +81,7 @@ void createXMLController(unsigned int controller[], const char * name, const cha } } -const char * XMLSaveCallback(mxml_node_t *node, int where) +static const char * XMLSaveCallback(mxml_node_t *node, int where) { const char *name; @@ -115,8 +108,7 @@ const char * XMLSaveCallback(mxml_node_t *node, int where) return (NULL); } - -int +static int preparePrefsData (int method) { int offset = 0; @@ -190,36 +182,29 @@ preparePrefsData (int method) return datasize; } - /**************************************************************************** * Decode Preferences Data ****************************************************************************/ -void loadXMLSettingStr(char * var, const char * name, int maxsize) +static void loadXMLSettingStr(char * var, const char * name, int maxsize) { item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); if(item) snprintf(var, maxsize, "%s", mxmlElementGetAttr(item, "value")); } -void loadXMLSettingInt(int * var, const char * name) +static void loadXMLSettingInt(int * var, const char * name) { item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); if(item) *var = atoi(mxmlElementGetAttr(item, "value")); } -void loadXMLSettingFloat(float * var, const char * name) +static void loadXMLSettingFloat(float * var, const char * name) { item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); if(item) *var = atof(mxmlElementGetAttr(item, "value")); } -void loadXMLSettingBool(bool * var, const char * name) -{ - item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); - if(item) - *var = atoi(mxmlElementGetAttr(item, "value")); -} -void loadXMLController(unsigned int controller[], const char * name) +static void loadXMLController(unsigned int controller[], const char * name) { item = mxmlFindElement(xml, xml, "controller", "name", name, MXML_DESCEND); @@ -237,7 +222,7 @@ void loadXMLController(unsigned int controller[], const char * name) } } -bool +static bool decodePrefsData (int method) { int offset = 0; diff --git a/source/unzip/unzip.c b/source/unzip/unzip.c index d3b2f96..eda77d5 100644 --- a/source/unzip/unzip.c +++ b/source/unzip/unzip.c @@ -84,12 +84,6 @@ woven in by Terry Thorsen 1/2003. #define SIZECENTRALDIRITEM (0x2e) #define SIZEZIPLOCALHEADER (0x1e) - - - -const char unz_copyright[] = - " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - /* unz_file_info_interntal contain internal info about a file in zipfile*/ typedef struct unz_file_info_internal_s { @@ -412,9 +406,6 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) int err=UNZ_OK; - if (unz_copyright[0]!=' ') - return NULL; - if (pzlib_filefunc_def==NULL) fill_fopen_filefunc(&us.z_filefunc); else