rewrite file code

reset preferences now resets control mappings
improved SMB
This commit is contained in:
dborth 2008-12-19 22:04:55 +00:00
parent d844b56dcb
commit 672f1ac0ba
24 changed files with 880 additions and 923 deletions

View File

@ -114,7 +114,7 @@ u64 dvdsf_last_length = 0;
int dvd_buffered_read(void *dst, u32 len, u64 offset)
{
int ret = 0;
int ret = 1;
// only read data if the data inside dvdsf_buffer cannot be used
if(offset != dvdsf_last_offset || len > dvdsf_last_length)
@ -143,12 +143,12 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
}
else
{
// no errors yet -> ret = 0
// the return value of dvd_read will be OR'd with ret
// because dvd_read does return 1 on error and 0 on success and
// because 0 | 1 = 1 ret will also contain 1 if at least one error
// occured and 0 otherwise ;)
int ret = 0; // return value of dvd_read
// no errors yet -> ret = 1
// the return value of dvd_read will be AND'd with ret
// because dvd_read does return 0 on error and 1 on success and
// because 1 & 0 = 0 ret will also contain 0 if at least one error
// occured and 1 otherwise ;)
int ret = 1; // return value of dvd_read
// we might need to fix all 3 issues
unsigned char *dst = (unsigned char *)dst_v; // gcc will not allow to use var[num] on void* types
@ -181,7 +181,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
}
// read 32 bytes from the last 32 byte position
ret |= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i);
ret &= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i);
// copy the bytes to the output buffer and update currentOffset, bufferOffset and bytesToRead
memcpy(&dst[bufferOffset], &buffer[j], k);
@ -199,7 +199,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
// read data in 2048 byte sector
for(j = 0; j < i; j++)
{
ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector
ret &= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector
memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer
// update currentOffset, bufferOffset and bytesToRead
@ -212,7 +212,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
// fix third issue (length is not a multiply of 32)
if(bytesToRead)
{
ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd
ret &= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd
memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer
}
return ret;
@ -299,25 +299,38 @@ getpvd ()
}
/****************************************************************************
* TestDVD()
* MountDVD()
*
* Tests if a ISO9660 DVD is inserted and available
* Tests if a ISO9660 DVD is inserted and available, and mounts it
***************************************************************************/
bool TestDVD()
{
bool MountDVD(bool silent)
{
if (!getpvd())
{
ShowAction("Loading DVD...");
#ifdef HW_DOL
DVD_Mount();
DVD_Mount(); // mount the DVD unit again
#elif WII_DVD
u32 val;
DI_GetCoverRegister(&val);
if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside.
{
if(!silent)
WaitPrompt("No disc inserted!");
return false;
}
DI_Mount();
while(DI_GetStatus() & DVD_INIT);
#endif
if (!getpvd())
return false;
}
if (!getpvd())
{
if(!silent)
WaitPrompt ("Invalid DVD.");
return false;
}
}
return true;
}
@ -506,6 +519,7 @@ int DirectorySearch(char dir[512])
* SwitchDVDFolder
*
* 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
***************************************************************************/
@ -559,7 +573,7 @@ bool SwitchDVDFolder(char origdir[])
if(dir[strlen(dir)-1] == '/')
dir[strlen(dir)-1] = 0;
// start at root of DVD
// start searching at root of DVD
dvddir = dvdrootdir;
dvddirlength = dvdrootlength;
ParseDVDdirectory();
@ -582,6 +596,7 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
int offset;
int blocks;
int i;
int ret = 0;
u64 discoffset;
char readbuffer[2048];
@ -589,15 +604,19 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
blocks = dvddirlength / 2048;
offset = 0;
discoffset = dvddir;
ShowAction ((char*) "Loading...");
ShowAction ("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);
ret = dvd_read (buffer, length, discoffset);
if(ret <= 0) // read failure
return 0;
}
else // load whole file
{
dvd_read (readbuffer, 2048, discoffset);
ret = dvd_read (readbuffer, 2048, discoffset);
if(ret <= 0) // read failure
return 0;
if (IsZipFile (readbuffer))
{
@ -607,17 +626,22 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
{
for (i = 0; i < blocks; i++)
{
dvd_read (readbuffer, 2048, discoffset);
ret = dvd_read (readbuffer, 2048, discoffset);
if(ret <= 0) // read failure
return 0;
memcpy (buffer + offset, readbuffer, 2048);
offset += 2048;
discoffset += 2048;
ShowProgress ("Loading...", offset, length);
}
/*** And final cleanup ***/
if (dvddirlength % 2048)
{
i = dvddirlength % 2048;
dvd_read (readbuffer, 2048, discoffset);
ret = dvd_read (readbuffer, 2048, discoffset);
if(ret <= 0) // read failure
return 0;
memcpy (buffer + offset, readbuffer, i);
}
}
@ -635,7 +659,7 @@ LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent)
else
{
if(!silent)
WaitPrompt((char *)"Error loading file!");
WaitPrompt("Error loading file!");
return 0;
}
}

View File

@ -13,13 +13,14 @@
#define _DVD_H_
int getpvd ();
bool MountDVD(bool silent);
int ParseDVDdirectory ();
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);
bool SwitchDVDFolder(char dir[]);
void SetDVDDriveType();
#ifdef HW_DOL
void dvd_motor_off ();
#endif

View File

@ -16,12 +16,15 @@
#include "common.h"
#include "fceugx.h"
#include "pad.h"
struct SGCSettings GCSettings;
void
DefaultSettings ()
{
ResetControls(); // controller button mappings
GCSettings.currpal = 0;
GCSettings.timing = 0; // 0 - NTSC, 1 - PAL
GCSettings.FourScore = 0;
@ -53,10 +56,4 @@ DefaultSettings ()
GCSettings.smbuser[19] = 0;
GCSettings.smbpwd[19] = 0;
GCSettings.smbshare[19] = 0;
GCSettings.gcip[0] = 0;
GCSettings.gwip[0] = 0;
GCSettings.mask[0] = 0;
GCSettings.smbsvid[0] = 0;
GCSettings.smbgcid[0] = 0;
}

View File

@ -30,6 +30,7 @@
#include "menu.h"
#include "preferences.h"
#include "fileop.h"
#include "smbop.h"
#include "gcaudio.h"
#include "gcvideo.h"
#include "pad.h"
@ -59,6 +60,16 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
* Shutdown / Reboot / Exit
***************************************************************************/
void ExitCleanup()
{
UnmountAllFAT();
CloseShare();
#ifdef HW_RVL
DI_Close();
#endif
}
#ifdef HW_DOL
#define PSOSDLOADID 0x7c6000a6
int *psoid = (int *) 0x80001800;
@ -67,9 +78,8 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
void Reboot()
{
UnmountAllFAT();
ExitCleanup();
#ifdef HW_RVL
DI_Close();
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
#else
#define SOFTRESET_ADR ((volatile u32*)0xCC003024)
@ -79,10 +89,9 @@ void Reboot()
void ExitToLoader()
{
UnmountAllFAT();
ExitCleanup();
// Exit to Loader
#ifdef HW_RVL
DI_Close();
exit(0);
#else // gamecube
if (psoid[0] == PSOSDLOADID)
@ -102,8 +111,7 @@ void ResetCB()
}
void ShutdownWii()
{
UnmountAllFAT();
DI_Close();
ExitCleanup();
SYS_ResetSystem(SYS_POWEROFF, 0, 0);
}
#endif
@ -202,7 +210,10 @@ int main(int argc, char *argv[])
}
InitialiseAudio();
fatInit (8, false);
// Initialize libFAT for SD and USB
MountAllFAT();
InitDeviceThread();
// Initialize DVD subsystem (GameCube only)
#ifdef HW_DOL
@ -215,7 +226,7 @@ int main(int argc, char *argv[])
/*** Minimal Emulation Loop ***/
if ( !FCEUI_Initialize() )
{
WaitPrompt((char *)"Unable to initialize FCE Ultra\n");
WaitPrompt("Unable to initialize FCE Ultra\n");
ExitToLoader();
}
@ -235,7 +246,7 @@ int main(int argc, char *argv[])
// Load preferences
if(!LoadPrefs())
{
WaitPrompt((char*) "Preferences reset - check settings!");
WaitPrompt("Preferences reset - check settings!");
selectedMenu = 1; // change to preferences menu
}
@ -249,9 +260,17 @@ int main(int argc, char *argv[])
ShutdownWii();
#endif
// go back to checking if devices were inserted/removed
// since we're entering the menu
LWP_ResumeThread (devicethread);
MainMenu(selectedMenu);
selectedMenu = 2; // return to game menu from now on
// stop checking if devices were removed/inserted
// since we're starting emulation again
LWP_SuspendThread (devicethread);
ResetVideo_Emu();
setFrameTimer(); // set frametimer method before emulation
@ -301,7 +320,7 @@ int main(int argc, char *argv[])
}
// save zoom level
SavePrefs(GCSettings.SaveMethod, SILENT);
SavePrefs(SILENT);
ConfigRequested = 0;
break; // leave emulation loop

View File

@ -26,7 +26,9 @@ enum {
METHOD_DVD,
METHOD_SMB,
METHOD_MC_SLOTA,
METHOD_MC_SLOTB
METHOD_MC_SLOTB,
METHOD_SD_SLOTA,
METHOD_SD_SLOTB
};
enum {
@ -46,15 +48,12 @@ struct SGCSettings{
char LoadFolder[200]; // Path to game files
char SaveFolder[200]; // Path to save files
char CheatFolder[200]; // Path to cheat files
char gcip[16];
char gwip[16];
char mask[16];
char smbip[16];
char smbuser[20];
char smbpwd[20];
char smbgcid[20];
char smbsvid[20];
char smbshare[20];
int Zoom; // 0 - off, 1 - on
float ZoomLevel; // zoom amount
int VerifySaves;

View File

@ -79,7 +79,7 @@ bool SaveRAM (int method, bool silent)
if(nesGameType == 4)
{
if(!silent)
WaitPrompt((char *)"Saving is not available for FDS games!");
WaitPrompt("Saving is not available for FDS games!");
return false;
}
@ -89,7 +89,9 @@ bool SaveRAM (int method, bool silent)
if (!MakeFilePath(filepath, FILE_RAM, method))
return false;
ShowAction ((char*) "Saving...");
ShowAction ("Saving...");
AllocSaveBuffer ();
// save game save to savebuffer
if(nesGameType == 1)
@ -104,15 +106,16 @@ bool SaveRAM (int method, bool silent)
if (offset > 0)
{
if ( !silent )
WaitPrompt((char *)"Save successful");
WaitPrompt("Save successful");
retval = true;
}
}
else
{
if ( !silent )
WaitPrompt((char *)"No data to save!");
WaitPrompt("No data to save!");
}
FreeSaveBuffer ();
return retval;
}
@ -120,11 +123,12 @@ bool LoadRAM (int method, bool silent)
{
char filepath[1024];
int offset = 0;
bool retval = false;
if(nesGameType == 4)
{
if(!silent)
WaitPrompt((char *)"Saving is not available for FDS games!");
WaitPrompt("Saving is not available for FDS games!");
return false;
}
@ -134,7 +138,9 @@ bool LoadRAM (int method, bool silent)
if (!MakeFilePath(filepath, FILE_RAM, method))
return false;
ShowAction ((char*) "Loading...");
ShowAction ("Loading...");
AllocSaveBuffer ();
offset = LoadFile(filepath, method, silent);
@ -146,12 +152,14 @@ bool LoadRAM (int method, bool silent)
NGCFCEU_GameSave(&UNIFCart, 1);
ResetNES();
return true;
retval = true;
}
// if we reached here, nothing was done!
if(!silent)
WaitPrompt ((char*) "Save file not found");
return false;
else
{
// if we reached here, nothing was done!
if(!silent)
WaitPrompt ("Save file not found");
}
FreeSaveBuffer ();
return retval;
}

View File

@ -292,7 +292,9 @@ bool SaveState (int method, bool silent)
if (!MakeFilePath(filepath, FILE_STATE, method))
return false;
ShowAction ((char*) "Saving...");
ShowAction ("Saving...");
AllocSaveBuffer ();
datasize = GCFCEUSS_Save();
@ -303,10 +305,11 @@ bool SaveState (int method, bool silent)
if (offset > 0)
{
if ( !silent )
WaitPrompt((char *)"Save successful");
WaitPrompt("Save successful");
retval = true;
}
}
FreeSaveBuffer ();
return retval;
}
@ -314,6 +317,7 @@ bool LoadState (int method, bool silent)
{
char filepath[1024];
int offset = 0;
bool retval = false;
if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' because we need R/W
@ -321,19 +325,23 @@ bool LoadState (int method, bool silent)
if (!MakeFilePath(filepath, FILE_STATE, method))
return false;
ShowAction ((char*) "Loading...");
ShowAction ("Loading...");
AllocSaveBuffer ();
offset = LoadFile(filepath, method, silent);
if (offset > 0)
{
GCFCEUSS_Load();
return 1;
retval = true;
}
// if we reached here, nothing was done!
if(!silent)
WaitPrompt ((char*) "State file not found");
return 0;
else
{
// if we reached here, nothing was done!
if(!silent)
WaitPrompt ("State file not found");
}
FreeSaveBuffer ();
return retval;
}

View File

@ -14,26 +14,106 @@
#include <stdlib.h>
#include <string.h>
#include <ogcsys.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <zlib.h>
#include <sdcard/wiisd_io.h>
#include <sdcard/gcsd.h>
#include <ogc/usbstorage.h>
#include "dvd.h"
#include "common.h"
#include "fceugx.h"
#include "fileop.h"
#include "memcardop.h"
#include "smbop.h"
#include "gcunzip.h"
#include "menudraw.h"
#include "filesel.h"
// FAT file pointer - the only one we should ever use!
FILE * fatfile;
// file pointer - the only one we should ever use!
FILE * file;
bool unmountRequired[9] = { false, false, false, false, false, false, false, false, false };
bool isMounted[9] = { false, false, false, false, false, false, false, false, false };
#ifdef HW_RVL
const DISC_INTERFACE* sd = &__io_wiisd;
const DISC_INTERFACE* usb = &__io_usbstorage;
#else
const DISC_INTERFACE* carda = &__io_gcsda;
const DISC_INTERFACE* cardb = &__io_gcsdb;
#endif
/****************************************************************************
* UnmountFAT
* Unmounts the FAT device specified
* deviceThreading
***************************************************************************/
void UnmountFAT(PARTITION_INTERFACE part)
lwp_t devicethread;
/****************************************************************************
* devicecallback
*
* This checks our devices for changes (SD/USB removed) and
* initializes the network in the background
***************************************************************************/
static void *
devicecallback (void *arg)
{
if(!fatUnmount(part))
fatUnsafeUnmount(part);
while (1)
{
#ifdef HW_RVL
if(isMounted[METHOD_SD])
{
if(!sd->isInserted()) // check if the device was removed
{
unmountRequired[METHOD_SD] = true;
isMounted[METHOD_SD] = false;
}
}
if(isMounted[METHOD_USB])
{
if(!usb->isInserted()) // check if the device was removed - doesn't work on USB!
{
unmountRequired[METHOD_USB] = true;
isMounted[METHOD_USB] = false;
}
}
InitializeNetwork(SILENT);
#else
if(isMounted[METHOD_SD_SLOTA])
{
if(!carda->isInserted()) // check if the device was removed
{
unmountRequired[METHOD_SD_SLOTA] = true;
isMounted[METHOD_SD_SLOTA] = false;
}
}
if(isMounted[METHOD_SD_SLOTB])
{
if(!cardb->isInserted()) // check if the device was removed
{
unmountRequired[METHOD_SD_SLOTB] = true;
isMounted[METHOD_SD_SLOTB] = false;
}
}
#endif
usleep(500000); // suspend thread for 1/2 sec
}
return NULL;
}
/****************************************************************************
* InitDeviceThread
*
* libOGC provides a nice wrapper for LWP access.
* This function sets up a new local queue and attaches the thread to it.
***************************************************************************/
void
InitDeviceThread()
{
LWP_CreateThread (&devicethread, devicecallback, NULL, NULL, 0, 80);
}
/****************************************************************************
@ -43,11 +123,12 @@ void UnmountFAT(PARTITION_INTERFACE part)
void UnmountAllFAT()
{
#ifdef HW_RVL
UnmountFAT(PI_INTERNAL_SD);
UnmountFAT(PI_USBSTORAGE);
fatUnmount("sd");
fatUnmount("usb");
#else
fatUnmount("carda");
fatUnmount("cardb");
#endif
UnmountFAT(PI_SDGECKO_A);
UnmountFAT(PI_SDGECKO_B);
}
/****************************************************************************
@ -56,67 +137,125 @@ void UnmountAllFAT()
* 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)
bool MountFAT(int method)
{
UnmountFAT(part);
bool mounted = true; // assume our disc is already mounted
char name[10];
const DISC_INTERFACE* disc = NULL;
bool mounted = fatMountNormalInterface(part, 8);
if(mounted)
switch(method)
{
fatSetDefaultInterface(part);
#ifdef HW_RVL
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
fatEnableReadAhead (part, 6, 64);
#endif
#ifdef HW_RVL
case METHOD_SD:
sprintf(name, "sd");
disc = sd;
break;
case METHOD_USB:
sprintf(name, "usb");
disc = usb;
break;
#else
case METHOD_SD_SLOTA:
sprintf(name, "carda");
disc = carda;
break;
case METHOD_SD_SLOTB:
sprintf(name, "cardb");
disc = cardb;
break;
#endif
default:
return false; // unknown device
}
sprintf(rootdir, "%s:/", name);
if(unmountRequired[method])
{
unmountRequired[method] = false;
fatUnmount(name);
disc->shutdown();
}
if(!isMounted[method])
{
if(!disc->startup())
mounted = false;
else if(!fatMountSimple(name, disc))
mounted = false;
else
fatEnableReadAhead(name, 6, 64);
}
isMounted[method] = mounted;
return mounted;
}
void MountAllFAT()
{
#ifdef HW_RVL
MountFAT(METHOD_SD);
MountFAT(METHOD_USB);
#else
MountFAT(METHOD_SD_SLOTA);
MountFAT(METHOD_SD_SLOTB);
#endif
}
/****************************************************************************
* ChangeFATInterface
* Unmounts all devices and attempts to mount/configure the device specified
* ChangeInterface
* Attempts to mount/configure the device specified
***************************************************************************/
bool ChangeFATInterface(int method, bool silent)
bool ChangeInterface(int method, bool silent)
{
bool mounted = false;
if(method == METHOD_SD)
{
#ifdef HW_RVL
mounted = MountFAT(PI_INTERNAL_SD); // try Wii internal SD
#endif
if(!mounted) // internal SD not found
mounted = MountFAT(PI_SDGECKO_A); // try SD Gecko on slot A
mounted = MountFAT(METHOD_SD); // try Wii internal SD
#else
mounted = MountFAT(METHOD_SD_SLOTA); // try SD Gecko on slot A
if(!mounted) // internal SD and SD Gecko (on slot A) not found
mounted = MountFAT(PI_SDGECKO_B); // try SD Gecko on slot B
mounted = MountFAT(METHOD_SD_SLOTB); // try SD Gecko on slot B
#endif
if(!mounted && !silent) // no SD device found
WaitPrompt ((char *)"SD card not found!");
WaitPrompt ("SD card not found!");
}
else if(method == METHOD_USB)
{
#ifdef HW_RVL
mounted = MountFAT(PI_USBSTORAGE);
mounted = MountFAT(method);
if(!mounted && !silent)
WaitPrompt ((char *)"USB drive not found!");
WaitPrompt ("USB drive not found!");
#endif
}
else if(method == METHOD_SMB)
{
sprintf(rootdir, "smb:/");
mounted = ConnectShare(NOTSILENT);
}
else if(method == METHOD_DVD)
{
sprintf(rootdir, "/");
mounted = MountDVD(NOTSILENT);
}
return mounted;
}
/***************************************************************************
* Browse FAT subdirectories
* Browse subdirectories
**************************************************************************/
int
ParseFATdirectory(int method)
ParseDirectory()
{
int nbfiles = 0;
DIR_ITER *fatdir;
DIR_ITER *dir;
char fulldir[MAXPATHLEN];
char filename[MAXPATHLEN];
char tmpname[MAXPATHLEN];
struct stat filestat;
@ -128,28 +267,32 @@ ParseFATdirectory(int method)
// Clear any existing values
memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);
// add device to path
sprintf(fulldir, "%s%s", rootdir, currentdir);
// open the directory
fatdir = diropen(currentdir);
if (fatdir == NULL)
dir = diropen(fulldir);
if (dir == NULL)
{
sprintf(msg, "Couldn't open %s", currentdir);
sprintf(msg, "Error opening %s", fulldir);
WaitPrompt(msg);
// if we can't open the dir, open root dir
sprintf(currentdir,"%s",ROOTFATDIR);
sprintf(fulldir,"%s",rootdir);
fatdir = diropen(currentdir);
dir = diropen(currentdir);
if (fatdir == NULL)
if (dir == NULL)
{
sprintf(msg, "Error opening %s", currentdir);
sprintf(msg, "Error opening %s", fulldir);
WaitPrompt(msg);
return 0;
}
}
// index files/folders
while(dirnext(fatdir,filename,&filestat) == 0)
while(dirnext(dir,filename,&filestat) == 0)
{
if(strcmp(filename,".") != 0)
{
@ -164,7 +307,7 @@ ParseFATdirectory(int method)
}
// close directory
dirclose(fatdir);
dirclose(dir);
// Sort the file list
qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);
@ -173,99 +316,190 @@ ParseFATdirectory(int method)
}
/****************************************************************************
* LoadFATSzFile
* LoadSzFile
* Loads the selected file # from the specified 7z into rbuffer
* Returns file size
***************************************************************************/
int
LoadFATSzFile(char * filepath, unsigned char * rbuffer)
u32
LoadSzFile(char * filepath, unsigned char * rbuffer)
{
u32 size;
fatfile = fopen (filepath, "rb");
if (fatfile > 0)
u32 size = 0;
// stop checking if devices were removed/inserted
// since we're loading a file
LWP_SuspendThread (devicethread);
file = fopen (filepath, "rb");
if (file > 0)
{
size = SzExtractFile(filelist[selection].offset, rbuffer);
fclose (fatfile);
return size;
fclose (file);
}
else
{
WaitPrompt((char*) "Error opening file");
return 0;
WaitPrompt("Error opening file");
}
// go back to checking if devices were inserted/removed
LWP_ResumeThread (devicethread);
return size;
}
/****************************************************************************
* LoadFATFile
* LoadFile
***************************************************************************/
int
LoadFATFile (char * rbuffer, char *filepath, int length, bool silent)
u32
LoadFileBuf (char * rbuffer, char *filepath, u32 length, int method, bool silent)
{
char zipbuffer[2048];
int size = 0;
int readsize = 0;
u32 size = 0;
u32 readsize = 0;
fatfile = fopen (filepath, "rb");
if(!ChangeInterface(method, NOTSILENT))
return 0;
if (fatfile > 0)
switch(method)
{
case METHOD_DVD:
return LoadDVDFile (rbuffer, filepath, length, silent);
break;
case METHOD_MC_SLOTA:
return LoadMCFile (rbuffer, CARD_SLOTA, filepath, silent);
break;
case METHOD_MC_SLOTB:
return LoadMCFile (rbuffer, CARD_SLOTB, filepath, silent);
break;
}
// stop checking if devices were removed/inserted
// since we're loading a file
LWP_SuspendThread (devicethread);
// add device to filepath
char fullpath[1024];
sprintf(fullpath, "%s%s", rootdir, filepath);
file = fopen (fullpath, "rb");
if (file > 0)
{
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
{
fread (rbuffer, 1, length, fatfile);
size = length;
size = fread (rbuffer, 1, length, file);
}
else // load whole file
{
readsize = fread (zipbuffer, 1, 2048, fatfile);
readsize = fread (zipbuffer, 1, 2048, file);
if(readsize > 0)
{
if (IsZipFile (zipbuffer))
{
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
size = UnZipBuffer ((unsigned char *)rbuffer, method); // unzip
}
else
{
// Just load the file up
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 (rbuffer, 1, size, fatfile);
struct stat fileinfo;
fstat(file->_file, &fileinfo);
size = fileinfo.st_size;
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
ShowProgress ("Loading...", 2048, length);
u32 offset = 2048;
while(offset < size)
{
readsize = fread (rbuffer + offset, 1, (1024*512), file); // read in 512K chunks
if(readsize <= 0 || readsize > (1024*512))
break; // read failure
if(readsize > 0)
offset += readsize;
ShowProgress ("Loading...", offset, length);
}
if(offset != size) // # bytes read doesn't match # expected
size = 0;
}
}
}
fclose (fatfile);
return size;
fclose (file);
}
else
if(!size && !silent)
{
if(!silent)
WaitPrompt((char*) "Error opening file!");
return 0;
unmountRequired[method] = true;
WaitPrompt("Error loading file!");
}
// go back to checking if devices were inserted/removed
LWP_ResumeThread (devicethread);
return size;
}
u32 LoadFile(char filepath[], int method, bool silent)
{
return LoadFileBuf((char *)savebuffer, filepath, 0, method, silent);
}
/****************************************************************************
* SaveFATFile
* Write buffer to FAT card file
* SaveFile
* Write buffer to file
***************************************************************************/
int
SaveFATFile (char * buffer, char *filepath, int datasize, bool silent)
u32
SaveFileBuf (char * buffer, char *filepath, u32 datasize, int method, bool silent)
{
u32 written = 0;
if(!ChangeInterface(method, NOTSILENT))
return 0;
switch(method)
{
case METHOD_MC_SLOTA:
return SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent);
break;
case METHOD_MC_SLOTB:
return SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent);
break;
}
if (datasize)
{
fatfile = fopen (filepath, "wb");
// stop checking if devices were removed/inserted
// since we're saving a file
LWP_SuspendThread (devicethread);
if (fatfile <= 0)
{
char msg[100];
sprintf(msg, "Couldn't save %s", filepath);
WaitPrompt (msg);
return 0;
}
// add device to filepath
char fullpath[1024];
sprintf(fullpath, "%s%s", rootdir, filepath);
fwrite (savebuffer, 1, datasize, fatfile);
fclose (fatfile);
// open file for writing
file = fopen (filepath, "wb");
if (file > 0)
{
written = fwrite (savebuffer, 1, datasize, file);
fclose (file);
}
if(!written && !silent)
{
unmountRequired[method] = true;
WaitPrompt ("Error saving file!");
}
// go back to checking if devices were inserted/removed
LWP_ResumeThread (devicethread);
}
return datasize;
return written;
}
u32 SaveFile(char filepath[], u32 datasize, int method, bool silent)
{
return SaveFileBuf((char *)savebuffer, filepath, datasize, method, silent);
}

View File

@ -16,20 +16,22 @@
#include <string.h>
#include <ogcsys.h>
#include <fat.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <unistd.h>
#define ROOTFATDIR "fat:/"
void InitDeviceThread();
void MountAllFAT();
void UnmountAllFAT();
bool ChangeFATInterface(int method, bool silent);
int ParseFATdirectory(int method);
int LoadFATSzFile(char * filepath, unsigned char * rbuffer);
int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent);
int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent);
bool ChangeInterface(int method, bool silent);
int ParseDirectory();
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 FILE * fatfile;
extern FILE * file;
extern bool unmountRequired[];
extern lwp_t devicethread;
#endif

View File

@ -33,6 +33,7 @@
int offset;
int selection;
char rootdir[10];
char currentdir[MAXPATHLEN];
char szpath[MAXPATHLEN];
char romFilename[200];
@ -44,15 +45,33 @@ extern int screenheight;
FILEENTRIES filelist[MAXFILES];
bool inSz = false;
unsigned char savebuffer[SAVEBUFFERSIZE];
unsigned char *savebuffer = NULL;
/****************************************************************************
* Clear the savebuffer
****************************************************************************/
* AllocSaveBuffer ()
* Allocate and clear the savebuffer
***************************************************************************/
void
ClearSaveBuffer ()
AllocSaveBuffer ()
{
memset (savebuffer, 0, SAVEBUFFERSIZE);
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;
}
/****************************************************************************
@ -62,19 +81,19 @@ ClearSaveBuffer ()
****************************************************************************/
int autoLoadMethod()
{
ShowAction ((char*) "Attempting to determine load method...");
ShowAction ("Attempting to determine load method...");
if(ChangeFATInterface(METHOD_SD, SILENT))
if(ChangeInterface(METHOD_SD, SILENT))
return METHOD_SD;
else if(ChangeFATInterface(METHOD_USB, SILENT))
else if(ChangeInterface(METHOD_USB, SILENT))
return METHOD_USB;
else if(TestDVD())
else if(ChangeInterface(METHOD_DVD, SILENT))
return METHOD_DVD;
else if(ConnectShare (SILENT))
else if(ChangeInterface(METHOD_SMB, SILENT))
return METHOD_SMB;
else
{
WaitPrompt((char*) "Unable to auto-determine load method!");
WaitPrompt("Unable to auto-determine load method!");
return 0; // no method found
}
}
@ -86,27 +105,28 @@ int autoLoadMethod()
****************************************************************************/
int autoSaveMethod()
{
ShowAction ((char*) "Attempting to determine save method...");
ShowAction ("Attempting to determine save method...");
if(ChangeFATInterface(METHOD_SD, SILENT))
if(ChangeInterface(METHOD_SD, SILENT))
return METHOD_SD;
else if(ChangeFATInterface(METHOD_USB, SILENT))
else if(ChangeInterface(METHOD_USB, SILENT))
return METHOD_USB;
else if(TestCard(CARD_SLOTA, SILENT))
return METHOD_MC_SLOTA;
else if(TestCard(CARD_SLOTB, SILENT))
return METHOD_MC_SLOTB;
else if(ConnectShare (SILENT))
else if(ChangeInterface(METHOD_SMB, SILENT))
return METHOD_SMB;
else
{
WaitPrompt((char*) "Unable to auto-determine save method!");
WaitPrompt("Unable to auto-determine save method!");
return 0; // no method found
}
}
/***************************************************************************
* Update curent directory name
/****************************************************************************
* UpdateDirName()
* Update curent directory name for file browser
***************************************************************************/
int UpdateDirName(int method)
{
@ -156,7 +176,7 @@ int UpdateDirName(int method)
}
else
{
WaitPrompt((char*)"Directory name is too long!");
WaitPrompt("Directory name is too long!");
return -1;
}
}
@ -173,7 +193,7 @@ bool MakeFilePath(char filepath[], int type, int method)
// Check path length
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
{
WaitPrompt((char*)"Maximum filepath length reached!");
WaitPrompt("Maximum filepath length reached!");
filepath[0] = 0;
return false;
}
@ -205,86 +225,20 @@ bool MakeFilePath(char filepath[], int type, int method)
}
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;
default:
sprintf (temppath, "%s/%s", folder, file);
break;
}
}
strcpy(filepath, temppath);
return true;
}
int LoadFileBuf(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 LoadFileBuf((char *)savebuffer, filepath, 0, method, silent);
}
int SaveFileBuf(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 SaveFileBuf((char *)savebuffer, filepath, datasize, method, silent);
}
/***************************************************************************
* FileSortCallback
*
@ -327,7 +281,7 @@ bool IsValidROM(int method)
if(filelist[selection].length < (1024*10) ||
filelist[selection].length > (1024*1024*3))
{
WaitPrompt((char *)"Invalid file size!");
WaitPrompt("Invalid file size!");
return false;
}
@ -366,7 +320,7 @@ bool IsValidROM(int method)
}
}
}
WaitPrompt((char *)"Unknown file type!");
WaitPrompt("Unknown file type!");
return false;
}
@ -488,23 +442,18 @@ int FileSelector (int method)
{
switch (method)
{
case METHOD_SD:
case METHOD_USB:
maxfiles = ParseFATdirectory(method);
break;
case METHOD_DVD:
maxfiles = ParseDVDdirectory();
break;
maxfiles = ParseDVDdirectory();
break;
case METHOD_SMB:
maxfiles = ParseSMBdirectory(NOTSILENT);
break;
default:
maxfiles = ParseDirectory();
break;
}
if (!maxfiles)
{
WaitPrompt ((char*) "Error reading directory!");
WaitPrompt ("Error reading directory!");
haverom = 1; // quit menu
}
}
@ -515,11 +464,6 @@ int FileSelector (int method)
}
else // this is a file
{
// better do another unmount/remount, just in case
if(method == METHOD_SD || method == METHOD_USB)
if(!ChangeFATInterface(method, NOTSILENT))
return 0;
// 7z file - let's open it up to select a file inside
if(IsSz())
{
@ -527,6 +471,11 @@ int FileSelector (int method)
if(!MakeFilePath(szpath, FILE_ROM, method))
return 0;
// add device to filepath
char fullpath[1024];
sprintf(fullpath, "%s%s", rootdir, szpath);
strcpy(szpath, fullpath);
int szfiles = SzParse(szpath, method);
if(szfiles)
{
@ -534,7 +483,7 @@ int FileSelector (int method)
inSz = true;
}
else
WaitPrompt((char*) "Error opening archive!");
WaitPrompt("Error opening archive!");
}
else
{
@ -545,7 +494,7 @@ int FileSelector (int method)
// store the filename (w/o ext) - used for state saving
StripExt(romFilename, filelist[selection].filename);
ShowAction ((char *)"Loading...");
ShowAction ("Loading...");
int size = 0;
@ -562,15 +511,11 @@ int FileSelector (int method)
{
switch (method)
{
case METHOD_SD:
case METHOD_USB:
size = LoadFATSzFile(szpath, nesrom);
break;
case METHOD_DVD:
size = SzExtractFile(filelist[selection].offset, nesrom);
break;
case METHOD_SMB:
size = LoadSMBSzFile(szpath, nesrom);
default:
size = LoadSzFile(szpath, nesrom);
break;
}
}
@ -586,7 +531,7 @@ int FileSelector (int method)
}
else
{
WaitPrompt((char*) "Error loading ROM!");
WaitPrompt("Error loading ROM!");
return 0;
}
}
@ -696,99 +641,32 @@ int FileSelector (int method)
}
/****************************************************************************
* OpenDVD
*
* Function to load a DVD directory and display to user.
****************************************************************************/
* OpenROM
* Opens device specified by method, displays a list of ROMS
***************************************************************************/
int
OpenDVD (int method)
OpenROM (int method)
{
if (!getpvd())
if(method == METHOD_AUTO)
method = autoLoadMethod();
if(ChangeInterface(method, NOTSILENT))
{
ShowAction((char*) "Loading DVD...");
#ifdef HW_DOL
DVD_Mount(); // mount the DVD unit again
#elif WII_DVD
u32 val;
DI_GetCoverRegister(&val);
if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside.
// change current dir to roms directory
switch(method)
{
WaitPrompt((char *)"No disc inserted!");
return 0;
case METHOD_DVD:
currentdir[0] = 0;
maxfiles = ParseDVDdirectory (); // Parse root directory
SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder
break;
default:
sprintf(currentdir, "/%s", GCSettings.LoadFolder);
maxfiles = ParseDirectory(); // Parse root directory
break;
}
DI_Mount();
while(DI_GetStatus() & DVD_INIT);
#endif
if (!getpvd())
{
WaitPrompt ((char *)"Invalid DVD.");
return 0; // not a ISO9660 DVD
}
}
currentdir[0] = 0;
maxfiles = ParseDVDdirectory(); // load root folder
// switch to rom folder
SwitchDVDFolder(GCSettings.LoadFolder);
if (maxfiles > 0)
{
return FileSelector (method);
}
else
{
// no entries found
WaitPrompt ((char *)"No Files Found!");
return 0;
}
}
/****************************************************************************
* OpenSMB
*
* Function to load from an SMB share
****************************************************************************/
int
OpenSMB (int method)
{
// Connect to network share
if(ConnectShare (NOTSILENT))
{
// change current dir to root dir
sprintf(currentdir, "/%s", GCSettings.LoadFolder);
maxfiles = ParseSMBdirectory (SILENT);
if (maxfiles > 0)
{
return FileSelector (method);
}
else
{
// no entries found
WaitPrompt ((char *)"No Files Found!");
return 0;
}
}
return 0;
}
/****************************************************************************
* OpenFAT
*
* Function to load from FAT
****************************************************************************/
int
OpenFAT (int method)
{
if(ChangeFATInterface(method, NOTSILENT))
{
// change current dir to snes roms directory
sprintf ( currentdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder );
// Parse initial root directory and get entries list
maxfiles = ParseFATdirectory (method);
if (maxfiles > 0)
{
// Select an entry
@ -797,41 +675,9 @@ OpenFAT (int method)
else
{
// no entries found
WaitPrompt ((char *)"No Files Found!");
WaitPrompt ("No Files Found!");
return 0;
}
}
return 0;
}
/****************************************************************************
* OpenROM
* Opens device specified by method, displays a list of ROMS
****************************************************************************/
int
OpenROM (int method)
{
int loadROM = 0;
if(method == METHOD_AUTO)
method = autoLoadMethod();
switch (method)
{
case METHOD_SD:
case METHOD_USB:
loadROM = OpenFAT (method);
break;
case METHOD_DVD:
// Load from DVD
loadROM = OpenDVD (method);
break;
case METHOD_SMB:
// Load from Network (SMB)
loadROM = OpenSMB (method);
break;
}
return loadROM;
}

View File

@ -32,18 +32,16 @@ extern FILEENTRIES filelist[MAXFILES];
extern bool isWii;
extern int offset;
extern int selection;
extern char rootdir[10];
extern char currentdir[MAXPATHLEN];
extern int maxfiles;
extern unsigned char savebuffer[];
extern unsigned char *savebuffer;
extern char romFilename[];
extern int nesGameType;
void ClearSaveBuffer ();
void AllocSaveBuffer();
void FreeSaveBuffer();
bool MakeFilePath(char filepath[], int type, int method);
int LoadFileBuf(char * buffer, char filepath[], int length, int method, bool silent);
int LoadFile(char filepath[], int method, bool silent);
int SaveFileBuf(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();

View File

@ -29,6 +29,7 @@
/*
* PKWare Zip Header - adopted into zip standard
*/
#define PKZIPID 0x504b0304
#define MAXROM 0x500000
#define ZIPCHUNK 2048
@ -63,25 +64,26 @@ FLIP16 (u16 b)
/****************************************************************************
* IsZipFile
*
* Returns 1 when Zip signature is found
****************************************************************************/
* Returns TRUE when PKZIPID is first four characters of buffer
***************************************************************************/
int
IsZipFile (char *buffer)
{
unsigned int *check;
check = (unsigned int *) buffer;
if (check[0] == 0x504b0304) // ZIP file
if (check[0] == PKZIPID)
return 1;
return 0;
}
/*****************************************************************************
* UnZipBuffer
*
* It should be noted that there is a limit of 5MB total size for any ROM
******************************************************************************/
/*****************************************************************************
* UnZipBuffer
*
* It should be noted that there is a limit of 5MB total size for any ROM
******************************************************************************/
int
UnZipBuffer (unsigned char *outbuffer, int method)
@ -97,31 +99,31 @@ UnZipBuffer (unsigned char *outbuffer, int method)
int have = 0;
char readbuffer[ZIPCHUNK];
u64 discoffset = 0;
int sizeread = 0;
// Read Zip Header
switch (method)
{
case METHOD_SD:
case METHOD_USB:
fseek(fatfile, 0, SEEK_SET);
fread (readbuffer, 1, ZIPCHUNK, fatfile);
break;
case METHOD_DVD:
discoffset = dvddir;
dvd_read (readbuffer, ZIPCHUNK, discoffset);
sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset);
break;
case METHOD_SMB:
SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile);
default:
fseek(file, 0, SEEK_SET);
sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
break;
}
if(sizeread <= 0)
return 0;
/*** Copy PKZip header to local, used as info ***/
memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER));
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
ShowProgress ("Loading...", 0, pkzip.uncompressedSize);
/*** Prepare the zip stream ***/
memset (&zs, 0, sizeof (z_stream));
zs.zalloc = Z_NULL;
@ -176,21 +178,18 @@ UnZipBuffer (unsigned char *outbuffer, int method)
switch (method)
{
case METHOD_SD:
case METHOD_USB:
fread (readbuffer, 1, ZIPCHUNK, fatfile);
break;
case METHOD_DVD:
readoffset += ZIPCHUNK;
dvd_read (readbuffer, ZIPCHUNK, discoffset+readoffset);
sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset+readoffset);
break;
case METHOD_SMB:
readoffset += ZIPCHUNK;
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
default:
sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
break;
}
if(sizeread <= 0)
break; // read failure
ShowProgress ("Loading...", bufferoffset, pkzip.uncompressedSize);
}
while (res != Z_STREAM_END);
@ -225,13 +224,21 @@ GetFirstZipFilename (int method)
return NULL;
// read start of ZIP
LoadFileBuf (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT);
if(LoadFileBuf (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
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
int namelength = tempbuffer[26]; // filename length starts 26 bytes in
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
firstFilename[namelength] = 0; // truncate at filename length
if(namelength > 0 && namelength < 200) // the filename is a reasonable length
{
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
firstFilename[namelength] = 0; // truncate at filename length
}
else
{
WaitPrompt("Error - Invalid ZIP file!");
}
}
return firstFilename;
}
@ -255,6 +262,7 @@ char szerrormsg[][30] = {
"7z: CRC Error",
"7z: Not implemented",
"7z: Fail",
"7z: Data read failure",
"7z: Archive error",
"7z: Dictionary too large",
};
@ -303,9 +311,11 @@ void SzDisplayError(SZ_RESULT res)
}
// 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)
{
u32 seekok = 0;
u32 sizeread = 0;
// the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *) object;
@ -318,23 +328,31 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
// read data
switch (szMethod)
{
case METHOD_SD:
case METHOD_USB:
fseek(fatfile, offset, SEEK_SET);
fread(sz_buffer, 1, maxRequiredSize, fatfile);
break;
case METHOD_DVD:
dvd_safe_read(sz_buffer, maxRequiredSize, offset);
sizeread = dvd_safe_read(sz_buffer, maxRequiredSize, offset);
break;
case METHOD_SMB:
SMB_ReadFile(sz_buffer, maxRequiredSize, offset, smbfile);
default:
seekok = fseek(file, offset, SEEK_SET);
sizeread = fread(sz_buffer, 1, maxRequiredSize, file);
break;
}
if(seekok != 0 || sizeread <= 0)
{
char msg[150];
sprintf(msg, "sizeread: %u", sizeread);
WaitPrompt(msg);
return SZE_FAILREAD;
}
*buffer = sz_buffer;
*processedSize = maxRequiredSize;
s->pos += *processedSize;
if(maxRequiredSize > 1024) // only show progress for large reads
// this isn't quite right, but oh well
ShowProgress ("Loading...", s->pos, filelist[selection].length);
return SZ_OK;
}
@ -346,10 +364,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
// check if the 7z SDK wants to move the pointer to somewhere after the EOF
if (pos >= s->len)
{
WaitPrompt((char *) "7z: Error - attempt to read after EOF!");
return SZE_FAIL;
}
// save new position and return
s->pos = pos;
@ -378,13 +393,9 @@ int SzParse(char * filepath, int method)
{
case METHOD_SD:
case METHOD_USB:
fatfile = fopen (filepath, "rb");
if(!fatfile)
return 0;
break;
case METHOD_SMB:
smbfile = OpenSMBFile(filepath);
if(!smbfile)
file = fopen (filepath, "rb");
if(!file)
return 0;
break;
}
@ -392,7 +403,7 @@ int SzParse(char * filepath, int method)
// set szMethod to current chosen load method
szMethod = method;
// set handler functions for reading data from FAT/SMB/DVD
// set handler functions for reading data from SD/USB/SMB/DVD
SzArchiveStream.InStream.Read = SzFileReadImp;
SzArchiveStream.InStream.Seek = SzFileSeekImp;
@ -471,10 +482,8 @@ int SzParse(char * filepath, int method)
{
case METHOD_SD:
case METHOD_USB:
fclose(fatfile);
break;
case METHOD_SMB:
SMB_CloseFile (smbfile);
fclose(file);
break;
}
return nbfiles;
@ -508,16 +517,16 @@ int SzExtractFile(int i, unsigned char *buffer)
// Unzip the file
SzRes = SzExtract2(
&SzArchiveStream.InStream,
&SzDb,
i, // index of file
&SzBlockIndex, // index of solid block
&buffer,
&SzBufferSize,
&SzOffset, // offset of stream for required file in *outBuffer
&SzOutSizeProcessed, // size of file in *outBuffer
&SzAllocImp,
&SzAllocTempImp);
&SzArchiveStream.InStream,
&SzDb,
i, // index of file
&SzBlockIndex, // index of solid block
&buffer,
&SzBufferSize,
&SzOffset, // offset of stream for required file in *outBuffer
&SzOutSizeProcessed, // size of file in *outBuffer
&SzAllocImp,
&SzAllocTempImp);
// close 7Zip archive and free memory
SzClose();
@ -534,3 +543,4 @@ int SzExtractFile(int i, unsigned char *buffer)
return SzOutSizeProcessed;
}
}

View File

@ -25,7 +25,6 @@
extern void FCEU_ResetPalette(void);
extern unsigned int SMBTimer;
int FDSTimer = 0;
u32 FrameTimer = 0;
int FDSSwitchRequested;
@ -275,7 +274,6 @@ copy_to_xfb (u32 arg)
copynow = GX_FALSE;
}
SMBTimer++;
FrameTimer++;
// FDS switch disk requested - need to eject, select, and insert

View File

@ -77,9 +77,9 @@ bool TestCard(int slot, bool silent)
if(!silent)
{
if (slot == CARD_SLOTA)
WaitPrompt((char*) "Mounted Slot A Memory Card!");
WaitPrompt("Mounted Slot A Memory Card!");
else
WaitPrompt((char*) "Mounted Slot B Memory Card!");
WaitPrompt("Mounted Slot B Memory Card!");
}
CARD_Unmount (slot);
return true;
@ -89,9 +89,9 @@ bool TestCard(int slot, bool silent)
if(!silent)
{
if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
WaitPrompt("Unable to Mount Slot A Memory Card!");
else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
WaitPrompt("Unable to Mount Slot B Memory Card!");
}
return false;
@ -149,7 +149,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
if (!CardFileExists (filename, slot))
{
CARD_Unmount (slot);
WaitPrompt((char*) "Unable to open file for verify!");
WaitPrompt("Unable to open file for verify!");
return 0;
}
@ -177,7 +177,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
{
CARD_Close (&CardFile);
CARD_Unmount (slot);
WaitPrompt((char*) "File did not verify!");
WaitPrompt("File did not verify!");
return 0;
}
@ -194,9 +194,9 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
}
else
if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
WaitPrompt("Unable to Mount Slot A Memory Card!");
else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
WaitPrompt("Unable to Mount Slot B Memory Card!");
return 0;
}
@ -229,7 +229,7 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
if (!CardFileExists (filename, slot))
{
if (!silent)
WaitPrompt((char*) "Unable to open file");
WaitPrompt("Unable to open file");
return 0;
}
@ -259,9 +259,9 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
}
else
if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
WaitPrompt("Unable to Mount Slot A Memory Card!");
else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
WaitPrompt("Unable to Mount Slot B Memory Card!");
return bytesread;
}
@ -306,7 +306,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError)
{
CARD_Unmount (slot);
WaitPrompt((char*) "Unable to open card file!");
WaitPrompt("Unable to open card file!");
return 0;
}
@ -319,7 +319,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError)
{
CARD_Unmount (slot);
WaitPrompt((char*) "Not enough space to update file!");
WaitPrompt("Not enough space to update file!");
return 0;
}
@ -329,7 +329,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError)
{
CARD_Unmount (slot);
WaitPrompt((char*) "Unable to delete temporary file!");
WaitPrompt("Unable to delete temporary file!");
return 0;
}
@ -338,7 +338,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError)
{
CARD_Unmount (slot);
WaitPrompt((char*) "Unable to delete existing file!");
WaitPrompt("Unable to delete existing file!");
return 0;
}
@ -347,7 +347,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError)
{
CARD_Unmount (slot);
WaitPrompt((char*) "Unable to create updated card file!");
WaitPrompt("Unable to create updated card file!");
return 0;
}
}
@ -360,9 +360,9 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
{
CARD_Unmount (slot);
if ( CardError == CARD_ERROR_INSSPACE )
WaitPrompt((char*) "Not enough space to create file!");
WaitPrompt("Not enough space to create file!");
else
WaitPrompt((char*) "Unable to create card file!");
WaitPrompt("Unable to create card file!");
return 0;
}
}
@ -406,13 +406,13 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
}
else
if ( !silent )
WaitPrompt((char*) "This game does not appear to use RAM");
WaitPrompt("This game does not appear to use RAM");
}
else
if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
WaitPrompt("Unable to Mount Slot A Memory Card!");
else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
WaitPrompt("Unable to Mount Slot B Memory Card!");
return 0;

View File

@ -125,7 +125,7 @@ VideoOptions ()
sprintf (videomenu[6], "8 Sprite Limit - %s",
GCSettings.slimit == true ? " ON" : "OFF");
ret = RunMenu (videomenu, videomenuCount, (char*)"Video Options", 20, -1);
ret = RunMenu (videomenu, videomenuCount, "Video Options", 20, -1);
switch (ret)
{
@ -275,7 +275,7 @@ FileOptions()
else if (GCSettings.AutoSave == 2) sprintf (filemenu[5],"Auto Save STATE");
else if (GCSettings.AutoSave == 3) sprintf (filemenu[5],"Auto Save BOTH");
ret = RunMenu (filemenu, filemenuCount, (char*)"Save/Load Options", 20, -1);
ret = RunMenu (filemenu, filemenuCount, "Save/Load Options", 20, -1);
switch (ret)
{
@ -374,7 +374,7 @@ GameMenu ()
if(!GCSettings.Zoom)
gamemenu[7][0] = '\0';
ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu", 20, -1);
ret = RunMenu (gamemenu, gamemenuCount, "Game Menu", 20, -1);
switch (ret)
{
@ -502,21 +502,21 @@ GetButtonMap(u16 ctrlr_type, char* btn_name)
switch (ctrlr_type) {
case CTRLR_NUNCHUK:
strncpy (cfg_text[3], (char*)"NUNCHUK", 7);
strncpy (cfg_text[3], "NUNCHUK", 7);
break;
case CTRLR_CLASSIC:
strncpy (cfg_text[3], (char*)"CLASSIC", 7);
strncpy (cfg_text[3], "CLASSIC", 7);
break;
case CTRLR_GCPAD:
strncpy (cfg_text[3], (char*)"GC PAD", 7);
strncpy (cfg_text[3], "GC PAD", 7);
break;
case CTRLR_WIIMOTE:
strncpy (cfg_text[3], (char*)"WIIMOTE", 7);
strncpy (cfg_text[3], "WIIMOTE", 7);
break;
};
/*** note which button we are remapping ***/
sprintf (temp, (char*)"Remapping ");
sprintf (temp, "Remapping ");
for (k=0; k<9-strlen(btn_name); k++) strcat(temp, " "); // add whitespace padding to align text
strncat (temp, btn_name, 9); // nes button we are remapping
strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display
@ -560,7 +560,7 @@ ConfigureButtons (u16 ctrlr_type)
int ret = 0;
int oldmenu = menu;
menu = 0;
char* menu_title = NULL;
char menu_title[50];
u32 pressed;
unsigned int* currentpadmap = 0;
@ -571,19 +571,19 @@ ConfigureButtons (u16 ctrlr_type)
/*** Update Menu Title (based on controller we're configuring) ***/
switch (ctrlr_type) {
case CTRLR_NUNCHUK:
menu_title = (char*)"NES - NUNCHUK";
sprintf(menu_title, "NES - NUNCHUK");
currentpadmap = ncpadmap;
break;
case CTRLR_CLASSIC:
menu_title = (char*)"NES - CLASSIC";
sprintf(menu_title, "NES - CLASSIC");
currentpadmap = ccpadmap;
break;
case CTRLR_GCPAD:
menu_title = (char*)"NES - GC PAD";
sprintf(menu_title, "NES - GC PAD");
currentpadmap = gcpadmap;
break;
case CTRLR_WIIMOTE:
menu_title = (char*)"NES - WIIMOTE";
sprintf(menu_title, "NES - WIIMOTE");
currentpadmap = wmpadmap;
break;
};
@ -607,7 +607,7 @@ ConfigureButtons (u16 ctrlr_type)
strncat (temp, ctrlr_def[ctrlr_type].map[j].name, 6); // update button map display
}
else
strcat (temp, (char*)"---"); // otherwise, button is 'unmapped'
strcat (temp, "---"); // otherwise, button is 'unmapped'
strncpy (cfg_btns_menu[i], temp, 19); // move back updated information
}
@ -687,7 +687,7 @@ ConfigureControllers ()
GCSettings.crosshair == true ? " ON" : "OFF");
/*** Controller Config Menu ***/
ret = RunMenu (ctlrmenu, ctlrmenucount, (char*)"Configure Controllers", 20, -1);
ret = RunMenu (ctlrmenu, ctlrmenucount, "Configure Controllers", 20, -1);
switch (ret)
{
@ -759,7 +759,7 @@ PreferencesMenu ()
menu = 0;
while (quit == 0)
{
ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences", 20, -1);
ret = RunMenu (prefmenu, prefmenuCount, "Preferences", 20, -1);
switch (ret)
{
@ -777,12 +777,12 @@ PreferencesMenu ()
case 3:
DefaultSettings ();
WaitPrompt((char *)"Preferences Reset");
WaitPrompt("Preferences Reset");
break;
case -1: /*** Button B ***/
case 4:
SavePrefs(GCSettings.SaveMethod, SILENT);
SavePrefs(SILENT);
quit = 1;
break;
@ -836,7 +836,7 @@ MainMenu (int selectedMenu)
}
else
{
ret = RunMenu (menuitems, menucount, (char*)"Main Menu", 20, -1);
ret = RunMenu (menuitems, menucount, "Main Menu", 20, -1);
}
switch (ret)

View File

@ -134,7 +134,7 @@ DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
* Place the font bitmap on the screen
****************************************************************************/
void
DrawText (int x, int y, char *text)
DrawText (int x, int y, const char *text)
{
int px, n;
int i;
@ -212,7 +212,7 @@ Credits ()
setfontcolour (0xFF, 0xFF, 0xFF);
setfontsize (28);
DrawText (-1, 145, (char*)"Credits");
DrawText (-1, 145, "Credits");
int ypos = 140;
@ -220,26 +220,26 @@ Credits ()
ypos += 20;
setfontsize (14);
DrawText (125, ypos += 22, (char*)"GameCube/Wii Port v2.x");
DrawText (350, ypos, (char*)"Tantric");
DrawText (125, ypos += 18, (char*)"GameCube/Wii Port v1.0.9");
DrawText (350, ypos, (char*)"askot & dsbomb");
DrawText (125, ypos += 18, (char*)"GameCube Port v1.0.8");
DrawText (350, ypos, (char*)"SoftDev");
DrawText (125, ypos += 18, (char*)"FCE Ultra");
DrawText (350, ypos, (char*)"Xodnizel");
DrawText (125, ypos += 18, (char*)"Original FCE");
DrawText (350, ypos, (char*)"BERO");
DrawText (125, ypos += 18, (char*)"libogc");
DrawText (350, ypos, (char*)"Shagkur & wintermute");
DrawText (125, ypos += 18, (char*)"Testing");
DrawText (350, ypos, (char*)"tehskeen users");
DrawText (125, ypos += 22, "GameCube/Wii Port v2.x");
DrawText (350, ypos, "Tantric");
DrawText (125, ypos += 18, "GameCube/Wii Port v1.0.9");
DrawText (350, ypos, "askot & dsbomb");
DrawText (125, ypos += 18, "GameCube Port v1.0.8");
DrawText (350, ypos, "SoftDev");
DrawText (125, ypos += 18, "FCE Ultra");
DrawText (350, ypos, "Xodnizel");
DrawText (125, ypos += 18, "Original FCE");
DrawText (350, ypos, "BERO");
DrawText (125, ypos += 18, "libogc");
DrawText (350, ypos, "Shagkur & wintermute");
DrawText (125, ypos += 18, "Testing");
DrawText (350, ypos, "tehskeen users");
DrawText (-1, ypos += 36, (char*)"And many others who have contributed over the years!");
DrawText (-1, ypos += 36, "And many others who have contributed over the years!");
setfontsize (12);
DrawText (-1, ypos += 50, (char*)"This software is open source and may be copied, distributed, or modified");
DrawText (-1, ypos += 15, (char*)"under the terms of the GNU General Public License (GPL) Version 2.");
DrawText (-1, ypos += 50, "This software is open source and may be copied, distributed, or modified");
DrawText (-1, ypos += 15, "under the terms of the GNU General Public License (GPL) Version 2.");
showscreen ();
}
@ -336,7 +336,7 @@ WaitButtonAB ()
* Show a prompt
****************************************************************************/
void
WaitPrompt (char *msg)
WaitPrompt (const char *msg)
{
int ypos = (screenheight - 64) >> 1;
@ -348,7 +348,7 @@ WaitPrompt (char *msg)
clearscreen ();
DrawText (-1, ypos, msg);
ypos += 30;
DrawText (-1, ypos, (char*)"Press A to continue");
DrawText (-1, ypos, "Press A to continue");
showscreen ();
WaitButtonA ();
}
@ -358,7 +358,7 @@ WaitPrompt (char *msg)
and 0 if B button was pressed.
****************************************************************************/
int
WaitPromptChoice (char *msg, char *bmsg, char *amsg)
WaitPromptChoice (const char *msg, const char *bmsg, const char *amsg)
{
int ypos = (screenheight - 64) >> 1;
@ -381,7 +381,7 @@ WaitPromptChoice (char *msg, char *bmsg, char *amsg)
* Show an action in progress
****************************************************************************/
void
ShowAction (char *msg)
ShowAction (const char *msg)
{
int ypos = (screenheight - 30) >> 1;
@ -399,7 +399,7 @@ ShowAction (char *msg)
* Generic Menu Routines
****************************************************************************/
void
DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize, int x)
DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize, int x)
{
int i, w = 0;
int ypos = 0;
@ -488,7 +488,7 @@ int FindMenuItem(char items[][50], int maxitems, int currentItem, int direction)
int menu = 0;
int
RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x)
RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x)
{
int redraw = 1;
int quit = 0;
@ -581,7 +581,7 @@ ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection)
clearscreen ();
setfontsize (28);
DrawText (-1, 145, (char*)"Choose Game");
DrawText (-1, 145, "Choose Game");
setfontsize(18);
@ -654,7 +654,7 @@ void RomInfo()
ypos += 20;
setfontsize (28);
DrawText (-1, 145, (char*)"Rom Information");
DrawText (-1, 145, "Rom Information");
setfontsize (16);
setfontcolour (0xFF, 0xFF, 0xFF);
@ -786,34 +786,46 @@ DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b)
* Progress Bar
*
* Show the user what's happening
****************************************************************************/
***************************************************************************/
void
ShowProgress (char *msg, int done, int total)
ShowProgress (const char *msg, int done, int total)
{
int ypos = (screenheight - 30) >> 1;
if(total <= 0) // division by 0 is bad!
return;
else if(done > total) // this shouldn't happen
done = total;
if (screenheight == 480)
ypos += 52;
else
ypos += 32;
int xpos, ypos;
int i;
int xpos;
int i;
if(done < 5000) // we just started!
{
ypos = (screenheight - 30) >> 1;
clearscreen ();
DrawText (-1, ypos, msg);
if (screenheight == 480)
ypos += 52;
else
ypos += 32;
/*** Draw a white outline box ***/
for (i = 380; i < 401; i++)
DrawLine (100, i, 540, i, 0xff, 0xff, 0xff);
clearscreen ();
setfontsize(20);
DrawText (-1, ypos, msg);
/*** Draw a white outline box ***/
for (i = 380; i < 401; i++)
DrawLine (100, i, 540, i, 0xff, 0xff, 0xff);
}
/*** Show progess ***/
xpos = (int) (((float) done / (float) total) * 438);
xpos = (int) (((float) done / (float) total) * 438);
for (i = 381; i < 400; i++)
DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80);
for (i = 381; i < 400; i++)
DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80);
showscreen ();
if(done < 5000) // we just started!
{
showscreen ();
}
}
/****************************************************************************

View File

@ -19,20 +19,20 @@
int FT_Init ();
void setfontsize (int pixelsize);
void setfontcolour (u8 r, u8 g, u8 b);
void DrawText (int x, int y, char *text);
void DrawText (int x, int y, const char *text);
void Credits ();
void RomInfo ();
void WaitButtonA ();
int RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x);
void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize, int x);
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 WaitPrompt (char *msg);
int WaitPromptChoice (char *msg, char* bmsg, char* amsg);
void ShowAction (char *msg);
void ShowProgress (char *msg, int done, int total);
void WaitPrompt (const char *msg);
int WaitPromptChoice (const char *msg, const char* bmsg, const char* amsg);
void ShowAction (const char *msg);
void ShowProgress (const char *msg, int done, int total);
void DrawPolygon (int vertices, int *varray, u8 r, u8 g, u8 b);
void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b );
void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b);
#endif

View File

@ -25,54 +25,6 @@
extern bool romLoaded;
// Original NES controller buttons
// All other pads are mapped to this
unsigned int nespadmap[] = {
JOY_B, JOY_A,
RAPID_B, RAPID_A, // rapid press A/B buttons
JOY_SELECT, JOY_START,
JOY_UP, JOY_DOWN,
JOY_LEFT, JOY_RIGHT,
0 // insert coin for VS games, insert/eject/select disk for FDS
};
/*** Gamecube controller Padmap ***/
unsigned int gcpadmap[] = {
PAD_BUTTON_B, PAD_BUTTON_A,
PAD_BUTTON_Y, PAD_BUTTON_X,
PAD_TRIGGER_Z, PAD_BUTTON_START,
PAD_BUTTON_UP, PAD_BUTTON_DOWN,
PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT,
PAD_TRIGGER_L
};
/*** Wiimote Padmap ***/
unsigned int wmpadmap[] = {
WPAD_BUTTON_1, WPAD_BUTTON_2,
0, 0,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN,
WPAD_BUTTON_A
};
/*** Classic Controller Padmap ***/
unsigned int ccpadmap[] = {
WPAD_CLASSIC_BUTTON_Y, WPAD_CLASSIC_BUTTON_B,
WPAD_CLASSIC_BUTTON_X, WPAD_CLASSIC_BUTTON_A,
WPAD_CLASSIC_BUTTON_MINUS, WPAD_CLASSIC_BUTTON_PLUS,
WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN,
WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT,
WPAD_CLASSIC_BUTTON_FULL_L
};
/*** Nunchuk + wiimote Padmap ***/
unsigned int ncpadmap[] = {
WPAD_NUNCHUK_BUTTON_C, WPAD_NUNCHUK_BUTTON_Z,
0, 0,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN,
WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT,
WPAD_BUTTON_A
};
static uint32 JSReturn = 0;
void *InputDPR;
@ -81,6 +33,88 @@ unsigned int myzappers[2][3];
extern INPUTC *FCEU_InitZapper(int w);
unsigned int nespadmap[11]; // Original NES controller buttons
unsigned int gcpadmap[11]; // Gamecube controller Padmap
unsigned int wmpadmap[11]; // Wiimote Padmap
unsigned int ccpadmap[11]; // Classic Controller Padmap
unsigned int ncpadmap[11]; // Nunchuk + wiimote Padmap
void ResetControls()
{
int i = 0;
// Original NES controller buttons
// All other pads are mapped to this
i=0;
nespadmap[i++] = JOY_B;
nespadmap[i++] = JOY_A;
nespadmap[i++] = RAPID_B;
nespadmap[i++] = RAPID_A; // rapid press A/B buttons
nespadmap[i++] = JOY_SELECT;
nespadmap[i++] = JOY_START;
nespadmap[i++] = JOY_UP;
nespadmap[i++] = JOY_DOWN;
nespadmap[i++] = JOY_LEFT;
nespadmap[i++] = JOY_RIGHT;
nespadmap[i++] = 0; // insert coin for VS games, insert/eject/select disk for FDS
/*** Gamecube controller Padmap ***/
i=0;
gcpadmap[i++] = PAD_BUTTON_B;
gcpadmap[i++] = PAD_BUTTON_A;
gcpadmap[i++] = PAD_BUTTON_Y;
gcpadmap[i++] = PAD_BUTTON_X;
gcpadmap[i++] = PAD_TRIGGER_Z;
gcpadmap[i++] = PAD_BUTTON_START;
gcpadmap[i++] = PAD_BUTTON_UP;
gcpadmap[i++] = PAD_BUTTON_DOWN;
gcpadmap[i++] = PAD_BUTTON_LEFT;
gcpadmap[i++] = PAD_BUTTON_RIGHT;
gcpadmap[i++] = PAD_TRIGGER_L;
/*** Wiimote Padmap ***/
i=0;
wmpadmap[i++] = WPAD_BUTTON_1;
wmpadmap[i++] = WPAD_BUTTON_2;
wmpadmap[i++] = 0;
wmpadmap[i++] = 0;
wmpadmap[i++] = WPAD_BUTTON_MINUS;
wmpadmap[i++] = WPAD_BUTTON_PLUS;
wmpadmap[i++] = WPAD_BUTTON_RIGHT;
wmpadmap[i++] = WPAD_BUTTON_LEFT;
wmpadmap[i++] = WPAD_BUTTON_UP;
wmpadmap[i++] = WPAD_BUTTON_DOWN;
wmpadmap[i++] = WPAD_BUTTON_A;
/*** Classic Controller Padmap ***/
i=0;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_Y;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_B;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_X;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_A;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_MINUS;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_PLUS;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_UP;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_DOWN;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_LEFT;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_RIGHT;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_FULL_L;
/*** Nunchuk + wiimote Padmap ***/
i=0;
ncpadmap[i++] = WPAD_NUNCHUK_BUTTON_C;
ncpadmap[i++] = WPAD_NUNCHUK_BUTTON_Z;
ncpadmap[i++] = 0;
ncpadmap[i++] = 0;
ncpadmap[i++] = WPAD_BUTTON_MINUS;
ncpadmap[i++] = WPAD_BUTTON_PLUS;
ncpadmap[i++] = WPAD_BUTTON_UP;
ncpadmap[i++] = WPAD_BUTTON_DOWN;
ncpadmap[i++] = WPAD_BUTTON_LEFT;
ncpadmap[i++] = WPAD_BUTTON_RIGHT;
ncpadmap[i++] = WPAD_BUTTON_A;
}
/****************************************************************************
* Initialise Pads
****************************************************************************/

View File

@ -25,6 +25,7 @@ extern unsigned int wmpadmap[];
extern unsigned int ccpadmap[];
extern unsigned int ncpadmap[];
void ResetControls();
s8 WPAD_StickX(u8 chan,u8 right);
s8 WPAD_StickY(u8 chan, u8 right);
void InitialisePads();

View File

@ -18,13 +18,10 @@
#include "menudraw.h"
#include "memcardop.h"
#include "fileop.h"
#include "smbop.h"
#include "filesel.h"
#include "fceugx.h"
#include "pad.h"
extern const unsigned short saveicon[1024];
extern unsigned char savebuffer[];
extern int currconfig[4];
// button map configurations
@ -319,33 +316,35 @@ decodePrefsData (int method)
/****************************************************************************
* Save Preferences
****************************************************************************/
***************************************************************************/
bool
SavePrefs (int method, bool silent)
SavePrefs (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();
// We'll save using the first available method (probably SD) since this
// is the method preferences will be loaded from by default
int method = autoSaveMethod();
if(!MakeFilePath(filepath, FILE_PREF, method))
return false;
if (!silent)
ShowAction ((char*) "Saving preferences...");
ShowAction ("Saving preferences...");
AllocSaveBuffer ();
datasize = preparePrefsData (method);
offset = SaveFile(filepath, datasize, method, silent);
FreeSaveBuffer ();
if (offset > 0)
{
if (!silent)
WaitPrompt ((char *)"Preferences saved");
WaitPrompt ("Preferences saved");
return true;
}
return false;
@ -353,8 +352,7 @@ SavePrefs (int method, bool silent)
/****************************************************************************
* Load Preferences from specified method
****************************************************************************/
***************************************************************************/
bool
LoadPrefsFromMethod (int method)
{
@ -365,32 +363,35 @@ LoadPrefsFromMethod (int method)
if(!MakeFilePath(filepath, FILE_PREF, method))
return false;
AllocSaveBuffer ();
offset = LoadFile(filepath, method, SILENT);
if (offset > 0)
{
retval = decodePrefsData (method);
}
FreeSaveBuffer ();
return retval;
}
/****************************************************************************
* Load Preferences
* Checks sources consecutively until we find a preference file
****************************************************************************/
***************************************************************************/
bool LoadPrefs()
{
ShowAction ("Loading preferences...");
bool prefFound = false;
if(ChangeFATInterface(METHOD_SD, SILENT))
if(ChangeInterface(METHOD_SD, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_SD);
if(!prefFound && ChangeFATInterface(METHOD_USB, SILENT))
if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_USB);
if(!prefFound && TestCard(CARD_SLOTA, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA);
if(!prefFound && TestCard(CARD_SLOTB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB);
if(!prefFound && ConnectShare (SILENT))
if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_SMB);
return prefFound;

View File

@ -9,5 +9,5 @@
* Preferences save/load preferences utilities
****************************************************************************/
bool SavePrefs (int method, bool silent);
bool SavePrefs (bool silent);
bool LoadPrefs ();

View File

@ -21,30 +21,28 @@
#include "common.h"
#include "fceugx.h"
#include "smbop.h"
#include "fileop.h"
#include "gcunzip.h"
#include "menudraw.h"
#include "filesel.h"
bool networkInit = false;
bool networkShareInit = false;
unsigned int SMBTimer = 0;
#define SMBTIMEOUT ( 3600 ) // Some implementations timeout in 10 minutes
// SMB connection/file handles - the only ones we should ever use!
SMBCONN smbconn;
SMBFILE smbfile;
#define ZIPCHUNK 16384
bool networkInitHalt = false;
/****************************************************************************
* InitializeNetwork
* Initializes the Wii/GameCube network interface
****************************************************************************/
bool InitializeNetwork(bool silent)
void InitializeNetwork(bool silent)
{
ShowAction ((char*) "Initializing network...");
if(networkInit || networkInitHalt)
return;
if(!silent)
ShowAction ("Initializing network...");
s32 result;
while ((result = net_init()) == -EAGAIN);
@ -55,19 +53,28 @@ bool InitializeNetwork(bool silent)
if (if_config(myIP, NULL, NULL, true) < 0)
{
networkInitHalt = true; // do not attempt a reconnection again
if(!silent)
WaitPrompt((char*) "Error reading IP address.");
return false;
WaitPrompt("Error reading IP address.");
}
else
{
return true;
networkInit = true;
}
}
else
{
if(!silent)
WaitPrompt("Unable to initialize network.");
}
}
if(!silent)
WaitPrompt((char*) "Unable to initialize network.");
return false;
void CloseShare()
{
if(networkShareInit)
smbClose();
networkShareInit = false;
}
/****************************************************************************
@ -89,266 +96,33 @@ ConnectShare (bool silent)
strlen(GCSettings.smbip) == 0)
{
if(!silent)
WaitPrompt((char*) "Invalid network settings. Check settings.xml.");
WaitPrompt("Invalid network settings. Check settings.xml.");
return false;
}
if(!networkInit)
networkInit = InitializeNetwork(silent);
InitializeNetwork(silent);
if(networkInit)
{
// connection may have expired
if (networkShareInit && SMBTimer > SMBTIMEOUT)
{
networkShareInit = false;
SMBTimer = 0;
SMB_Close(smbconn);
}
if(unmountRequired[METHOD_SMB])
CloseShare();
if(!networkShareInit)
{
if(!silent)
ShowAction ((char*) "Connecting to network share...");
ShowAction ("Connecting to network share...");
if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd,
GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS)
if(smbInit(GCSettings.smbuser, GCSettings.smbpwd,
GCSettings.smbshare, GCSettings.smbip))
{
networkShareInit = true;
}
}
if(!networkShareInit && !silent)
WaitPrompt ((char*) "Failed to connect to network share.");
WaitPrompt ("Failed to connect to network share.");
}
return networkShareInit;
}
/****************************************************************************
* SMBPath
*
* Returns a SMB-style path
*****************************************************************************/
char * SMBPath(char * path)
{
// fix path - replace all '/' with '\'
int i;
for(i=0; i < strlen(path); i++)
if(path[i] == '/')
path[i] = '\\';
return path;
}
/****************************************************************************
* parseSMBDirectory
*
* Load the directory and put in the filelist array
*****************************************************************************/
int
ParseSMBdirectory (bool silent)
{
if(!ConnectShare (NOTSILENT))
return 0;
int filecount = 0;
char searchpath[1024];
char tmpname[MAXJOLIET];
SMBDIRENTRY smbdir;
// initialize selection
selection = offset = 0;
// Clear any existing values
memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);
if(strlen(currentdir) <= 1) // root
sprintf(searchpath, "*");
else
sprintf(searchpath, "%s/*", currentdir);
if (SMB_FindFirst
(SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
{
if(!silent)
{
char msg[200];
sprintf(msg, "Could not open %s", currentdir);
WaitPrompt (msg);
}
// if we can't open the dir, open root dir
sprintf(searchpath, "/");
sprintf(searchpath,"*");
sprintf(currentdir,"/");
if (SMB_FindFirst
(SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
return 0;
}
// index files/folders
do
{
if(strcmp(smbdir.name,".") != 0 &&
!(strlen(currentdir) <= 1 && strcmp(smbdir.name,"..") == 0))
{
memset (&filelist[filecount], 0, sizeof (FILEENTRIES));
filelist[filecount].length = smbdir.size_low;
smbdir.name[MAXJOLIET] = 0;
if(smbdir.attributes == SMB_SRCH_DIRECTORY)
filelist[filecount].flags = 1; // flag this as a dir
else
filelist[filecount].flags = 0;
StripExt(tmpname, smbdir.name); // hide file extension
memcpy (&filelist[filecount].displayname, tmpname, MAXDISPLAY);
filelist[filecount].displayname[MAXDISPLAY] = 0;
strcpy (filelist[filecount].filename, smbdir.name);
filecount++;
}
} while (SMB_FindNext (&smbdir, smbconn) == SMB_SUCCESS);
// close directory
SMB_FindClose (smbconn);
// Sort the file list
qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback);
return filecount;
}
/****************************************************************************
* Open SMB file
***************************************************************************/
SMBFILE OpenSMBFile(char * filepath)
{
return SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
}
/****************************************************************************
* LoadSMBSzFile
* Loads the selected file # from the specified 7z into rbuffer
* Returns file size
***************************************************************************/
int
LoadSMBSzFile(char * filepath, unsigned char * rbuffer)
{
if(!ConnectShare (NOTSILENT))
return 0;
smbfile = OpenSMBFile(filepath);
if (smbfile)
{
u32 size = SzExtractFile(filelist[selection].offset, rbuffer);
SMB_CloseFile (smbfile);
return size;
}
else
{
WaitPrompt((char*) "Error opening file");
return 0;
}
}
/****************************************************************************
* SaveSMBFile
* Write buffer to SMB file
****************************************************************************/
int
SaveSMBFile (char * sbuffer, char *filepath, int datasize, bool silent)
{
if(!ConnectShare (NOTSILENT))
return 0;
int dsize = datasize;
int wrote = 0;
int boffset = 0;
smbfile =
SMB_OpenFile (SMBPath(filepath), SMB_OPEN_WRITING | SMB_DENY_NONE,
SMB_OF_CREATE | SMB_OF_TRUNCATE, smbconn);
if (smbfile)
{
while (dsize > 0)
{
if (dsize > 1024)
wrote =
SMB_WriteFile ((char *) sbuffer + boffset, 1024, boffset, smbfile);
else
wrote =
SMB_WriteFile ((char *) sbuffer + boffset, dsize, boffset, smbfile);
boffset += wrote;
dsize -= wrote;
}
SMB_CloseFile (smbfile);
}
else
{
char msg[100];
sprintf(msg, "Couldn't save SMB: %s", SMBPath(filepath));
WaitPrompt (msg);
}
return boffset;
}
/****************************************************************************
* LoadSMBFile
* Load up a buffer from SMB file
****************************************************************************/
int
LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent)
{
if(!ConnectShare (NOTSILENT))
return 0;
int ret;
int boffset = 0;
smbfile = OpenSMBFile(filepath);
if (!smbfile)
{
if(!silent)
{
char msg[100];
sprintf(msg, "Couldn't open SMB: %s", SMBPath(filepath));
WaitPrompt (msg);
}
return 0;
}
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
{
boffset = SMB_ReadFile (sbuffer, length, 0, smbfile);
}
else // load whole file
{
ret = SMB_ReadFile (sbuffer, 2048, boffset, smbfile);
if (IsZipFile (sbuffer))
{
boffset = UnZipBuffer ((unsigned char *)sbuffer, METHOD_SMB); // unzip from SMB
}
else
{
// Just load the file up
while ((ret = SMB_ReadFile (sbuffer + boffset, 2048, boffset, smbfile)) > 0)
{
boffset += ret;
}
}
}
SMB_CloseFile (smbfile);
return boffset;
}

View File

@ -9,21 +9,11 @@
* SMB support routines
****************************************************************************/
#ifndef _SMBOP_H_
#define _SMBOP_H_
#ifndef _NGCSMB_
#define _NGCSMB_
#include <smb.h>
bool InitializeNetwork(bool silent);
void InitializeNetwork(bool silent);
bool ConnectShare (bool silent);
char * SMBPath(char * path);
int UpdateSMBdirname();
int ParseSMBdirectory (bool silent);
SMBFILE OpenSMBFile(char * filepath);
int LoadSMBSzFile(char * filepath, unsigned char * rbuffer);
int LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent);
int SaveSMBFile (char * sbuffer, char *filepath, int length, bool silent);
extern SMBFILE smbfile;
void CloseShare();
#endif

View File

@ -61,10 +61,11 @@ typedef UInt32 CFileSize;
#define SZE_NOTIMPL (4)
#define SZE_FAIL (5)
#define SZE_FAILREAD (6)
#define SZE_ARCHIVE_ERROR (6)
#define SZE_ARCHIVE_ERROR (7)
#define SZE_OUTOFMEMORYDIC (7)
#define SZE_OUTOFMEMORYDIC (8)
#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }