rewrite file code, improved SMB

This commit is contained in:
dborth 2008-12-18 18:36:30 +00:00
parent 699d27a4ee
commit 1c12c46122
25 changed files with 707 additions and 900 deletions

View File

@ -12,7 +12,7 @@
#include "cheats.h" #include "cheats.h"
#include "snes9xGX.h" #include "snes9xGX.h"
#include "filesel.h" #include "fileop.h"
#include "menudraw.h" #include "menudraw.h"
extern SCheatData Cheat; extern SCheatData Cheat;

View File

@ -23,11 +23,10 @@ extern "C" {
} }
#endif #endif
#include "memmap.h"
#include "menudraw.h" #include "menudraw.h"
#include "snes9xGX.h"
#include "unzip.h" #include "unzip.h"
#include "filesel.h"
#include "snes9xGX.h"
u64 dvddir = 0; // offset of currently selected file or folder u64 dvddir = 0; // offset of currently selected file or folder
int dvddirlength = 0; // length of currently selected file or folder int dvddirlength = 0; // length of currently selected file or folder
@ -119,7 +118,7 @@ u64 dvdsf_last_length = 0;
int dvd_buffered_read(void *dst, u32 len, u64 offset) 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 // only read data if the data inside dvdsf_buffer cannot be used
if(offset != dvdsf_last_offset || len > dvdsf_last_length) if(offset != dvdsf_last_offset || len > dvdsf_last_length)
@ -148,12 +147,12 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
} }
else else
{ {
// no errors yet -> ret = 0 // no errors yet -> ret = 1
// the return value of dvd_read will be OR'd with ret // the return value of dvd_read will be AND'd with ret
// because dvd_read does return 1 on error and 0 on success and // because dvd_read does return 0 on error and 1 on success and
// because 0 | 1 = 1 ret will also contain 1 if at least one error // because 1 & 0 = 0 ret will also contain 0 if at least one error
// occured and 0 otherwise ;) // occured and 1 otherwise ;)
int ret = 0; // return value of dvd_read int ret = 1; // return value of dvd_read
// we might need to fix all 3 issues // 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 unsigned char *dst = (unsigned char *)dst_v; // gcc will not allow to use var[num] on void* types
@ -186,7 +185,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
} }
// read 32 bytes from the last 32 byte position // 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 // copy the bytes to the output buffer and update currentOffset, bufferOffset and bytesToRead
memcpy(&dst[bufferOffset], &buffer[j], k); memcpy(&dst[bufferOffset], &buffer[j], k);
@ -204,7 +203,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
// read data in 2048 byte sector // read data in 2048 byte sector
for(j = 0; j < i; j++) 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 memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer
// update currentOffset, bufferOffset and bytesToRead // update currentOffset, bufferOffset and bytesToRead
@ -217,7 +216,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
// fix third issue (length is not a multiply of 32) // fix third issue (length is not a multiply of 32)
if(bytesToRead) 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 memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer
} }
return ret; return ret;
@ -304,24 +303,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()) if (!getpvd())
{ {
ShowAction("Loading DVD...");
#ifdef HW_DOL #ifdef HW_DOL
DVD_Mount(); DVD_Mount(); // mount the DVD unit again
#elif WII_DVD #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(); DI_Mount();
while(DI_GetStatus() & DVD_INIT); while(DI_GetStatus() & DVD_INIT);
#endif #endif
if (!getpvd())
return false;
}
if (!getpvd())
{
if(!silent)
WaitPrompt ("Invalid DVD.");
return false;
}
}
return true; return true;
} }
@ -509,6 +522,7 @@ int DirectorySearch(char dir[512])
* SwitchDVDFolder * SwitchDVDFolder
* *
* Recursively searches for any directory path 'dir' specified * 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() * Also loads the directory contents via ParseDVDdirectory()
* It relies on dvddir, dvddirlength, and filelist being pre-populated * It relies on dvddir, dvddirlength, and filelist being pre-populated
***************************************************************************/ ***************************************************************************/
@ -585,6 +599,7 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
int offset; int offset;
int blocks; int blocks;
int i; int i;
int ret = 0;
u64 discoffset; u64 discoffset;
char readbuffer[2048]; char readbuffer[2048];
@ -592,15 +607,19 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
blocks = dvddirlength / 2048; blocks = dvddirlength / 2048;
offset = 0; offset = 0;
discoffset = dvddir; discoffset = dvddir;
ShowAction ((char*) "Loading..."); ShowAction ("Loading...");
if(length > 0 && length <= 2048) 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 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)) if (IsZipFile (readbuffer))
{ {
@ -610,18 +629,22 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
{ {
for (i = 0; i < blocks; i++) 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); memcpy (buffer + offset, readbuffer, 2048);
offset += 2048; offset += 2048;
discoffset += 2048; discoffset += 2048;
ShowProgress ((char *)"Loading...", offset, length); ShowProgress ("Loading...", offset, length);
} }
/*** And final cleanup ***/ /*** And final cleanup ***/
if (dvddirlength % 2048) if (dvddirlength % 2048)
{ {
i = 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); memcpy (buffer + offset, readbuffer, i);
} }
} }
@ -639,7 +662,7 @@ LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent)
else else
{ {
if(!silent) if(!silent)
WaitPrompt((char *)"Error loading file!"); WaitPrompt("Error loading file!");
return 0; return 0;
} }
} }

View File

@ -10,14 +10,14 @@
* DVD I/O functions * DVD I/O functions
***************************************************************************/ ***************************************************************************/
#ifndef _NGCDVD_H_ #ifndef _NGCDVD_
#define _NGCDVD_H_ #define _NGCDVD_
int getpvd (); int getpvd ();
bool MountDVD(bool silent);
int ParseDVDdirectory (); int ParseDVDdirectory ();
int LoadDVDFileOffset(unsigned char *buffer, int length); int LoadDVDFileOffset(unsigned char *buffer, int length);
int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent); int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent);
bool TestDVD();
int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_read (void *dst, unsigned int len, u64 offset);
int dvd_safe_read (void *dst, unsigned int len, u64 offset); int dvd_safe_read (void *dst, unsigned int len, u64 offset);
bool SwitchDVDFolder(char dir[]); bool SwitchDVDFolder(char dir[]);

View File

@ -13,32 +13,117 @@
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <zlib.h> #include <zlib.h>
#include "memmap.h" #include <sdcard/wiisd_io.h>
#include <sdcard/gcsd.h>
#include <ogc/usbstorage.h>
#include "snes9xGX.h"
#include "fileop.h" #include "fileop.h"
#include "smbop.h"
#include "dvd.h"
#include "memcardop.h"
#include "unzip.h" #include "unzip.h"
#include "video.h" #include "video.h"
#include "menudraw.h" #include "menudraw.h"
#include "filesel.h" #include "filesel.h"
#include "sram.h"
#include "preferences.h" #include "preferences.h"
#include "snes9xGX.h"
// FAT file pointer - the only one we should ever use! // file pointer - the only one we should ever use!
FILE * fatfile; 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 * deviceThreading
* Unmounts the FAT device specified
***************************************************************************/ ***************************************************************************/
void UnmountFAT(PARTITION_INTERFACE part) #define TSTACK 16384
lwpq_t devicequeue;
lwp_t devicethread;
static unsigned char devicestack[TSTACK];
/****************************************************************************
* 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)) while (1)
fatUnsafeUnmount(part); {
#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()
{
/*** Initialise a new queue ***/
LWP_InitQueue (&devicequeue);
/*** Create the thread on this queue ***/
LWP_CreateThread (&devicethread, devicecallback, NULL, devicestack, TSTACK, 80);
} }
/**************************************************************************** /****************************************************************************
@ -48,11 +133,12 @@ void UnmountFAT(PARTITION_INTERFACE part)
void UnmountAllFAT() void UnmountAllFAT()
{ {
#ifdef HW_RVL #ifdef HW_RVL
UnmountFAT(PI_INTERNAL_SD); fatUnmount("sd");
UnmountFAT(PI_USBSTORAGE); fatUnmount("usb");
#else
fatUnmount("carda");
fatUnmount("cardb");
#endif #endif
UnmountFAT(PI_SDGECKO_A);
UnmountFAT(PI_SDGECKO_B);
} }
/**************************************************************************** /****************************************************************************
@ -61,67 +147,128 @@ void UnmountAllFAT()
* If so, unmounts the device * If so, unmounts the device
* Attempts to mount the device specified * Attempts to mount the device specified
* Sets libfat to use the device by default * 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); switch(method)
if(mounted)
{ {
fatSetDefaultInterface(part); #ifdef HW_RVL
#ifdef HW_RVL case METHOD_SD:
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE) sprintf(name, "sd");
fatEnableReadAhead (part, 6, 64); disc = sd;
#endif 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);
// isInserted doesn't work properly for USB - so we will force a shutdown
//unmountRequired[METHOD_USB] = true;
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; return mounted;
} }
void MountAllFAT()
{
#ifdef HW_RVL
MountFAT(METHOD_SD);
MountFAT(METHOD_USB);
#else
MountFAT(METHOD_SD_SLOTA);
MountFAT(METHOD_SD_SLOTB);
#endif
}
/**************************************************************************** /****************************************************************************
* ChangeFATInterface * ChangeInterface
* Unmounts all devices and attempts to mount/configure the device specified * Attempts to mount/configure the device specified
***************************************************************************/ ***************************************************************************/
bool ChangeFATInterface(int method, bool silent) bool ChangeInterface(int method, bool silent)
{ {
bool mounted = false; bool mounted = false;
if(method == METHOD_SD) if(method == METHOD_SD)
{ {
#ifdef HW_RVL #ifdef HW_RVL
mounted = MountFAT(PI_INTERNAL_SD); // try Wii internal SD mounted = MountFAT(METHOD_SD); // try Wii internal SD
#endif #else
mounted = MountFAT(METHOD_SD_SLOTA); // try SD Gecko on slot A
if(!mounted) // internal SD not found
mounted = MountFAT(PI_SDGECKO_A); // try SD Gecko on slot A
if(!mounted) // internal SD and SD Gecko (on slot A) not found 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 if(!mounted && !silent) // no SD device found
WaitPrompt ((char *)"SD card not found!"); WaitPrompt ("SD card not found!");
} }
else if(method == METHOD_USB) else if(method == METHOD_USB)
{ {
#ifdef HW_RVL #ifdef HW_RVL
mounted = MountFAT(PI_USBSTORAGE); mounted = MountFAT(method);
if(!mounted && !silent) if(!mounted && !silent)
WaitPrompt ((char *)"USB drive not found!"); WaitPrompt ("USB drive not found!");
#endif #endif
} }
else if(method == METHOD_SMB)
{
sprintf(rootdir, "smb:/");
mounted = ConnectShare(NOTSILENT);
}
else if(method == METHOD_DVD)
{
sprintf(rootdir, "/");
mounted = MountDVD(NOTSILENT);
}
return mounted; return mounted;
} }
/*************************************************************************** /***************************************************************************
* Browse FAT subdirectories * Browse subdirectories
**************************************************************************/ **************************************************************************/
int int
ParseFATdirectory(int method) ParseDirectory()
{ {
int nbfiles = 0; int nbfiles = 0;
DIR_ITER *fatdir; DIR_ITER *dir;
char fulldir[MAXPATHLEN];
char filename[MAXPATHLEN]; char filename[MAXPATHLEN];
char tmpname[MAXPATHLEN]; char tmpname[MAXPATHLEN];
struct stat filestat; struct stat filestat;
@ -133,28 +280,32 @@ ParseFATdirectory(int method)
// Clear any existing values // Clear any existing values
memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);
// add device to path
sprintf(fulldir, "%s%s", rootdir, currentdir);
// open the directory // open the directory
fatdir = diropen(currentdir); dir = diropen(fulldir);
if (fatdir == NULL)
if (dir == NULL)
{ {
sprintf(msg, "Couldn't open %s", currentdir); sprintf(msg, "Error opening %s", fulldir);
WaitPrompt(msg); WaitPrompt(msg);
// if we can't open the dir, open root dir // 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); WaitPrompt(msg);
return 0; return 0;
} }
} }
// index files/folders // index files/folders
while(dirnext(fatdir,filename,&filestat) == 0) while(dirnext(dir,filename,&filestat) == 0)
{ {
if(strcmp(filename,".") != 0) if(strcmp(filename,".") != 0)
{ {
@ -169,7 +320,7 @@ ParseFATdirectory(int method)
} }
// close directory // close directory
dirclose(fatdir); dirclose(dir);
// Sort the file list // Sort the file list
qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);
@ -178,109 +329,168 @@ ParseFATdirectory(int method)
} }
/**************************************************************************** /****************************************************************************
* LoadFATSzFile * LoadSzFile
* Loads the selected file # from the specified 7z into rbuffer * Loads the selected file # from the specified 7z into rbuffer
* Returns file size * Returns file size
***************************************************************************/ ***************************************************************************/
int u32
LoadFATSzFile(char * filepath, unsigned char * rbuffer) LoadSzFile(char * filepath, unsigned char * rbuffer)
{ {
u32 size; u32 size;
fatfile = fopen (filepath, "rb"); file = fopen (filepath, "rb");
if (fatfile > 0) if (file > 0)
{ {
size = SzExtractFile(filelist[selection].offset, rbuffer); size = SzExtractFile(filelist[selection].offset, rbuffer);
fclose (fatfile); fclose (file);
return size; return size;
} }
else else
{ {
WaitPrompt((char*) "Error opening file"); WaitPrompt("Error opening file");
return 0; return 0;
} }
} }
/**************************************************************************** /****************************************************************************
* LoadFATFile * LoadFile
***************************************************************************/ ***************************************************************************/
int u32
LoadFATFile (char * rbuffer, char *filepath, int length, bool silent) LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent)
{ {
char zipbuffer[2048]; char zipbuffer[2048];
int size = 0; u32 size = 0;
int readsize = 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;
}
// 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) if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
{ {
fread (rbuffer, 1, length, fatfile); size = fread (rbuffer, 1, length, file);
size = length;
} }
else // load whole file else // load whole file
{ {
readsize = fread (zipbuffer, 1, 2048, fatfile); readsize = fread (zipbuffer, 1, 2048, file);
if(readsize > 0) if(readsize > 0)
{ {
if (IsZipFile (zipbuffer)) if (IsZipFile (zipbuffer))
{ {
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT size = UnZipBuffer ((unsigned char *)rbuffer, method); // unzip
} }
else else
{ {
// Just load the file up struct stat fileinfo;
fseek(fatfile, 0, SEEK_END); fstat(file->_file, &fileinfo);
size = ftell(fatfile); // get filesize size = fileinfo.st_size;
fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
ShowProgress ((char *)"Loading...", 2048, length); memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
int offset = 2048; ShowProgress ("Loading...", 2048, length);
while(offset < size && readsize != 0)
u32 offset = 2048;
while(offset < size)
{ {
readsize = fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks readsize = fread (rbuffer + offset, 1, (1024*512), file); // read in 512K chunks
offset += readsize;
ShowProgress ((char *)"Loading...", offset, length); 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); fclose (file);
return size;
} }
else if(!size && !silent)
{ {
if(!silent) unmountRequired[method] = true;
WaitPrompt((char*) "Error opening file!"); WaitPrompt("Error loading file!");
return 0;
} }
return size;
}
u32 LoadFile(char filepath[], int method, bool silent)
{
return LoadFile((char *)savebuffer, filepath, 0, method, silent);
} }
/**************************************************************************** /****************************************************************************
* SaveFATFile * SaveFile
* Write buffer to FAT card file * Write buffer to file
***************************************************************************/ ***************************************************************************/
int u32
SaveFATFile (char * buffer, char *filepath, int datasize, bool silent) SaveFile (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) if (datasize)
{ {
fatfile = fopen (filepath, "wb"); // add device to filepath
char fullpath[1024];
sprintf(fullpath, "%s%s", rootdir, filepath);
if (fatfile <= 0) // open file for writing
{ file = fopen (filepath, "wb");
char msg[100];
sprintf(msg, "Couldn't save %s", filepath);
WaitPrompt (msg);
return 0;
}
fwrite (savebuffer, 1, datasize, fatfile); if (file > 0)
fclose (fatfile); {
written = fwrite (savebuffer, 1, datasize, file);
fclose (file);
}
if(!written && !silent)
{
unmountRequired[method] = true;
WaitPrompt ("Error saving file!");
}
} }
return datasize; return written;
} }
u32 SaveFile(char filepath[], u32 datasize, int method, bool silent)
{
return SaveFile((char *)savebuffer, filepath, datasize, method, silent);
}

View File

@ -8,30 +8,32 @@
* *
* fileop.h * fileop.h
* *
* FAT File operations * File operations
****************************************************************************/ ****************************************************************************/
#ifndef _FATFILESC_ #ifndef _FILEOP_H_
#define _FATFILESC_ #define _FILEOP_H_
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <fat.h> #include <fat.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#define ROOTFATDIR "fat:/" void InitDeviceThread();
void MountAllFAT();
void UnmountAllFAT(); void UnmountAllFAT();
bool ChangeFATInterface(int method, bool silent); bool ChangeInterface(int method, bool silent);
int ParseFATdirectory(int method); int ParseDirectory();
int LoadFATSzFile(char * filepath, unsigned char * rbuffer); u32 LoadFile(char * rbuffer, char *filepath, u32 length, int method, bool silent);
int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent); u32 LoadFile(char filepath[], int method, bool silent);
int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent); u32 LoadSzFile(char * filepath, unsigned char * rbuffer);
u32 SaveFile(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 char currFATdir[MAXPATHLEN];
extern FILE * fatfile; extern FILE * file;
extern bool unmountRequired[];
#endif #endif

View File

@ -42,6 +42,7 @@ extern "C" {
int offset; int offset;
int selection; int selection;
char rootdir[10];
char currentdir[MAXPATHLEN]; char currentdir[MAXPATHLEN];
char szpath[MAXPATHLEN]; char szpath[MAXPATHLEN];
int maxfiles; int maxfiles;
@ -92,19 +93,19 @@ FreeSaveBuffer ()
****************************************************************************/ ****************************************************************************/
int autoLoadMethod() 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; return METHOD_SD;
else if(ChangeFATInterface(METHOD_USB, SILENT)) else if(ChangeInterface(METHOD_USB, SILENT))
return METHOD_USB; return METHOD_USB;
else if(TestDVD()) else if(ChangeInterface(METHOD_DVD, SILENT))
return METHOD_DVD; return METHOD_DVD;
else if(ConnectShare (SILENT)) else if(ChangeInterface(METHOD_SMB, SILENT))
return METHOD_SMB; return METHOD_SMB;
else else
{ {
WaitPrompt((char*) "Unable to auto-determine load method!"); WaitPrompt("Unable to auto-determine load method!");
return 0; // no method found return 0; // no method found
} }
} }
@ -116,21 +117,21 @@ int autoLoadMethod()
****************************************************************************/ ****************************************************************************/
int autoSaveMethod() 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; return METHOD_SD;
else if(ChangeFATInterface(METHOD_USB, SILENT)) else if(ChangeInterface(METHOD_USB, SILENT))
return METHOD_USB; return METHOD_USB;
else if(TestCard(CARD_SLOTA, SILENT)) else if(TestCard(CARD_SLOTA, SILENT))
return METHOD_MC_SLOTA; return METHOD_MC_SLOTA;
else if(TestCard(CARD_SLOTB, SILENT)) else if(TestCard(CARD_SLOTB, SILENT))
return METHOD_MC_SLOTB; return METHOD_MC_SLOTB;
else if(ConnectShare (SILENT)) else if(ChangeInterface(METHOD_SMB, SILENT))
return METHOD_SMB; return METHOD_SMB;
else else
{ {
WaitPrompt((char*) "Unable to auto-determine save method!"); WaitPrompt("Unable to auto-determine save method!");
return 0; // no method found return 0; // no method found
} }
} }
@ -187,7 +188,7 @@ int UpdateDirName(int method)
} }
else else
{ {
WaitPrompt((char*)"Directory name is too long!"); WaitPrompt("Directory name is too long!");
return -1; return -1;
} }
} }
@ -204,7 +205,7 @@ bool MakeFilePath(char filepath[], int type, int method)
// Check path length // Check path length
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN) if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
{ {
WaitPrompt((char*)"Maximum filepath length reached!"); WaitPrompt("Maximum filepath length reached!");
filepath[0] = 0; filepath[0] = 0;
return false; return false;
} }
@ -236,86 +237,20 @@ bool MakeFilePath(char filepath[], int type, int method)
} }
switch(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_SLOTA:
case METHOD_MC_SLOTB: case METHOD_MC_SLOTB:
sprintf (temppath, "%s", file); sprintf (temppath, "%s", file);
temppath[31] = 0; // truncate filename temppath[31] = 0; // truncate filename
break; break;
default:
sprintf (temppath, "%s/%s", folder, file);
break;
} }
} }
strcpy(filepath, temppath); strcpy(filepath, temppath);
return true; return true;
} }
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent)
{
int offset = 0;
switch(method)
{
case METHOD_SD:
case METHOD_USB:
if(ChangeFATInterface(method, NOTSILENT))
offset = LoadFATFile (buffer, filepath, length, silent);
break;
case METHOD_SMB:
offset = LoadSMBFile (buffer, filepath, length, silent);
break;
case METHOD_DVD:
offset = LoadDVDFile (buffer, filepath, length, silent);
break;
case METHOD_MC_SLOTA:
offset = LoadMCFile (buffer, CARD_SLOTA, filepath, silent);
break;
case METHOD_MC_SLOTB:
offset = LoadMCFile (buffer, CARD_SLOTB, filepath, silent);
break;
}
return offset;
}
int LoadFile(char filepath[], int method, bool silent)
{
return LoadFile((char *)savebuffer, filepath, 0, method, silent);
}
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent)
{
int offset = 0;
switch(method)
{
case METHOD_SD:
case METHOD_USB:
if(ChangeFATInterface(method, NOTSILENT))
offset = SaveFATFile (buffer, filepath, datasize, silent);
break;
case METHOD_SMB:
offset = SaveSMBFile (buffer, filepath, datasize, silent);
break;
case METHOD_MC_SLOTA:
offset = SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent);
break;
case METHOD_MC_SLOTB:
offset = SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent);
break;
}
return offset;
}
int SaveFile(char filepath[], int datasize, int method, bool silent)
{
return SaveFile((char *)savebuffer, filepath, datasize, method, silent);
}
/**************************************************************************** /****************************************************************************
* FileSortCallback * FileSortCallback
* *
@ -358,7 +293,7 @@ bool IsValidROM(int method)
if(filelist[selection].length < (1024*96) || if(filelist[selection].length < (1024*96) ||
filelist[selection].length > (1024*1024*8)) filelist[selection].length > (1024*1024*8))
{ {
WaitPrompt((char *)"Invalid file size!"); WaitPrompt("Invalid file size!");
return false; return false;
} }
@ -393,7 +328,7 @@ bool IsValidROM(int method)
} }
} }
} }
WaitPrompt((char *)"Unknown file type!"); WaitPrompt("Unknown file type!");
return false; return false;
} }
@ -513,23 +448,18 @@ int FileSelector (int method)
{ {
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
maxfiles = ParseFATdirectory(method);
break;
case METHOD_DVD: case METHOD_DVD:
maxfiles = ParseDVDdirectory(); maxfiles = ParseDVDdirectory();
break; break;
case METHOD_SMB: default:
maxfiles = ParseSMBdirectory(NOTSILENT); maxfiles = ParseDirectory();
break; break;
} }
if (!maxfiles) if (!maxfiles)
{ {
WaitPrompt ((char*) "Error reading directory!"); WaitPrompt ("Error reading directory!");
haverom = 1; // quit menu haverom = 1; // quit menu
} }
} }
@ -540,11 +470,6 @@ int FileSelector (int method)
} }
else // this is a file 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 // 7z file - let's open it up to select a file inside
if(IsSz()) if(IsSz())
{ {
@ -552,6 +477,11 @@ int FileSelector (int method)
if(!MakeFilePath(szpath, FILE_ROM, method)) if(!MakeFilePath(szpath, FILE_ROM, method))
return 0; return 0;
// add device to filepath
char fullpath[1024];
sprintf(fullpath, "%s%s", rootdir, szpath);
strcpy(szpath, fullpath);
int szfiles = SzParse(szpath, method); int szfiles = SzParse(szpath, method);
if(szfiles) if(szfiles)
{ {
@ -559,7 +489,7 @@ int FileSelector (int method)
inSz = true; inSz = true;
} }
else else
WaitPrompt((char*) "Error opening archive!"); WaitPrompt("Error opening archive!");
} }
else else
{ {
@ -570,7 +500,7 @@ int FileSelector (int method)
// store the filename (w/o ext) - used for sram/freeze naming // store the filename (w/o ext) - used for sram/freeze naming
StripExt(Memory.ROMFilename, filelist[selection].filename); StripExt(Memory.ROMFilename, filelist[selection].filename);
ShowAction ((char *)"Loading..."); ShowAction ("Loading...");
SNESROMSize = 0; SNESROMSize = 0;
@ -587,15 +517,11 @@ int FileSelector (int method)
{ {
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
SNESROMSize = LoadFATSzFile(szpath, (unsigned char *)Memory.ROM);
break;
case METHOD_DVD: case METHOD_DVD:
SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM); SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM);
break; break;
case METHOD_SMB: default:
SNESROMSize = LoadSMBSzFile(szpath, (unsigned char *)Memory.ROM); SNESROMSize = LoadSzFile(szpath, (unsigned char *)Memory.ROM);
break; break;
} }
} }
@ -604,7 +530,7 @@ int FileSelector (int method)
if (SNESROMSize > 0) if (SNESROMSize > 0)
return 1; return 1;
else else
WaitPrompt((char*) "Error loading ROM!"); WaitPrompt("Error loading ROM!");
} }
} }
redraw = 1; redraw = 1;
@ -713,99 +639,32 @@ int FileSelector (int method)
} }
/**************************************************************************** /****************************************************************************
* OpenDVD * OpenROM
* * Opens device specified by method, displays a list of ROMS
* Function to load a DVD directory and display to user.
***************************************************************************/ ***************************************************************************/
int int
OpenDVD (int method) OpenROM (int method)
{ {
if (!getpvd()) if(method == METHOD_AUTO)
method = autoLoadMethod();
if(ChangeInterface(method, NOTSILENT))
{ {
ShowAction((char*) "Loading DVD..."); // change current dir to roms directory
#ifdef HW_DOL switch(method)
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.
{ {
WaitPrompt((char *)"No disc inserted!"); case METHOD_DVD:
return 0; 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 load 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) if (maxfiles > 0)
{ {
// Select an entry // Select an entry
@ -814,41 +673,9 @@ OpenFAT (int method)
else else
{ {
// no entries found // no entries found
WaitPrompt ((char *)"No Files Found!"); WaitPrompt ("No Files Found!");
return 0; return 0;
} }
} }
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

@ -34,6 +34,7 @@ extern FILEENTRIES filelist[MAXFILES];
extern unsigned char *savebuffer; extern unsigned char *savebuffer;
extern int offset; extern int offset;
extern int selection; extern int selection;
extern char rootdir[10];
extern char currentdir[MAXPATHLEN]; extern char currentdir[MAXPATHLEN];
extern int maxfiles; extern int maxfiles;
extern unsigned long SNESROMSize; extern unsigned long SNESROMSize;
@ -41,10 +42,6 @@ extern unsigned long SNESROMSize;
void AllocSaveBuffer(); void AllocSaveBuffer();
void FreeSaveBuffer(); void FreeSaveBuffer();
bool MakeFilePath(char filepath[], int type, int method); bool MakeFilePath(char filepath[], int type, int method);
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent);
int LoadFile(char filepath[], int method, bool silent);
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent);
int SaveFile(char filepath[], int datasize, int method, bool silent);
int OpenROM (int method); int OpenROM (int method);
int autoLoadMethod(); int autoLoadMethod();
int autoSaveMethod(); int autoSaveMethod();

View File

@ -20,7 +20,6 @@
#include <string.h> #include <string.h>
#include <fat.h> #include <fat.h>
#include <zlib.h> #include <zlib.h>
#include <smb.h>
#include "snes9x.h" #include "snes9x.h"
#include "memmap.h" #include "memmap.h"
@ -31,7 +30,7 @@
#include "snes9xGX.h" #include "snes9xGX.h"
#include "images/saveicon.h" #include "images/saveicon.h"
#include "freeze.h" #include "freeze.h"
#include "filesel.h" #include "fileop.h"
#include "menudraw.h" #include "menudraw.h"
extern void S9xSRTCPreSaveState (); extern void S9xSRTCPreSaveState ();
@ -128,7 +127,7 @@ NGCFreezeGame (int method, bool8 silent)
int woffset = 0; // bytes written (expected) int woffset = 0; // bytes written (expected)
char msg[100]; char msg[100];
ShowAction ((char*) "Saving..."); ShowAction ("Saving...");
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoSaveMethod(); method = autoSaveMethod();
@ -187,7 +186,7 @@ NGCFreezeGame (int method, bool8 silent)
if(offset > 0) // save successful! if(offset > 0) // save successful!
{ {
if(!silent) if(!silent)
WaitPrompt((char*) "Save successful"); WaitPrompt("Save successful");
return 1; return 1;
} }
return 0; return 0;
@ -244,7 +243,7 @@ NGCUnfreezeGame (int method, bool8 silent)
bufoffset = 0; bufoffset = 0;
ShowAction ((char*) "Loading..."); ShowAction ("Loading...");
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W
@ -284,7 +283,7 @@ NGCUnfreezeGame (int method, bool8 silent)
} }
else if ( DestBuffSize != decompressedsize ) else if ( DestBuffSize != decompressedsize )
{ {
WaitPrompt((char*) "Unzipped size doesn't match expected size!"); WaitPrompt("Unzipped size doesn't match expected size!");
} }
else else
{ {
@ -300,12 +299,12 @@ NGCUnfreezeGame (int method, bool8 silent)
if (S9xUnfreezeGame ("AGAME") == SUCCESS) if (S9xUnfreezeGame ("AGAME") == SUCCESS)
result = 1; result = 1;
else else
WaitPrompt((char*) "Error thawing"); WaitPrompt("Error thawing");
} }
else else
{ {
if(!silent) if(!silent)
WaitPrompt((char*) "Freeze file not found"); WaitPrompt("Freeze file not found");
} }
FreeSaveBuffer (); FreeSaveBuffer ();
return result; return result;

View File

@ -94,7 +94,7 @@ gui_alloc ()
texdata_bg = memalign (32, 640 * 480 * 4); texdata_bg = memalign (32, 640 * 480 * 4);
texdata_menu = memalign (32, 640 * 480 * 4); texdata_menu = memalign (32, 640 * 480 * 4);
Gui.texmem = memalign (32, 640 * 480 * 4); Gui.texmem = memalign (32, 640 * 480 * 4);
mem_alloced = 1; mem_alloced = 1;
} }
} }
@ -107,7 +107,7 @@ gui_free ()
free (texdata_bg); free (texdata_bg);
free (texdata_menu); free (texdata_menu);
free (Gui.texmem); free (Gui.texmem);
mem_alloced = 0; mem_alloced = 0;
} }
} }
@ -116,16 +116,16 @@ gui_free ()
* make BG * make BG
* *
* Blend the last rendered emulator screen and the menu backdrop. * Blend the last rendered emulator screen and the menu backdrop.
* Save this as a texture to be loaded later * Save this as a texture to be loaded later
****************************************************************************/ ****************************************************************************/
void void
gui_makebg () gui_makebg ()
{ {
IMGCTX ctx; IMGCTX ctx;
PNGUPROP imgProp; PNGUPROP imgProp;
/** Load menu backdrop (either from file or buffer) **/ /** Load menu backdrop (either from file or buffer) **/
ctx = PNGU_SelectImageFromDevice ("bg.png"); ctx = PNGU_SelectImageFromDevice ("bg.png");
PNGU_GetImageProperties (ctx, &imgProp); PNGU_GetImageProperties (ctx, &imgProp);
// can check image dimensions here // can check image dimensions here
@ -136,7 +136,7 @@ gui_makebg ()
Make_Texture_RGBA8 (&texdata_bg, Gui.texmem, 640, 480); Make_Texture_RGBA8 (&texdata_bg, Gui.texmem, 640, 480);
PNGU_ReleaseImageContext (ctx); PNGU_ReleaseImageContext (ctx);
DCFlushRange (&texdata_bg, imgProp.imgWidth * imgProp.imgHeight * 4); DCFlushRange (&texdata_bg, imgProp.imgWidth * imgProp.imgHeight * 4);
/* /*
texdata_bg = memalign (32, 640 * 480 * 4); texdata_bg = memalign (32, 640 * 480 * 4);
#ifdef HW_RVL #ifdef HW_RVL
@ -149,7 +149,7 @@ gui_makebg ()
*/ */
/** blend last rendered snes frame and menu backdrop **/ /** blend last rendered snes frame and menu backdrop **/
// draw 640x480 quads // draw 640x480 quads
int xscale, yscale, xshift, yshift; int xscale, yscale, xshift, yshift;
xshift = yshift = 0; xshift = yshift = 0;
@ -159,17 +159,17 @@ gui_makebg ()
square[0] = square[9] = -xscale + xshift; square[0] = square[9] = -xscale + xshift;
square[4] = square[1] = yscale + yshift; square[4] = square[1] = yscale + yshift;
square[7] = square[10] = -yscale + yshift; square[7] = square[10] = -yscale + yshift;
// draw 2 quads // draw 2 quads
GX_InvalidateTexAll (); GX_InvalidateTexAll ();
// behind (last snes frame) // behind (last snes frame)
square[2] = square[5] = square[8] = square[11] = 0; // z value square[2] = square[5] = square[8] = square[11] = 0; // z value
GX_InvVtxCache (); GX_InvVtxCache ();
GX_LoadTexObj (&texobj, GX_TEXMAP0); // load last rendered snes frame GX_LoadTexObj (&texobj, GX_TEXMAP0); // load last rendered snes frame
draw_square (view); draw_square (view);
// in front (menu backdrop) // in front (menu backdrop)
square[2] = square[5] = square[8] = square[11] = 1; // z value square[2] = square[5] = square[8] = square[11] = 1; // z value
GX_InvVtxCache (); GX_InvVtxCache ();
@ -177,7 +177,7 @@ gui_makebg ()
draw_square (view); draw_square (view);
GX_DrawDone (); GX_DrawDone ();
/* DEBUG ----------- /* DEBUG -----------
// show the output // show the output
VIDEO_SetNextFramebuffer (xfb[whichfb]); VIDEO_SetNextFramebuffer (xfb[whichfb]);
@ -189,7 +189,7 @@ gui_makebg ()
#endif #endif
WaitButtonAB(); WaitButtonAB();
*/ */
// load blended image from efb to a texture // load blended image from efb to a texture
GX_InitTexObj (&texobj_BG, &texdata_bg, 640, 480, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_InitTexObj (&texobj_BG, &texdata_bg, 640, 480, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
GX_SetTexCopySrc ( 0,0,640,480 ); GX_SetTexCopySrc ( 0,0,640,480 );
@ -197,8 +197,8 @@ gui_makebg ()
GX_CopyTex (&texdata_bg, 0); // assuming that the efb is 640x480, which it should be GX_CopyTex (&texdata_bg, 0); // assuming that the efb is 640x480, which it should be
GX_PixModeSync (); // wait until copy has completed GX_PixModeSync (); // wait until copy has completed
DCFlushRange (&texdata_bg, 640 * 480 * 4); DCFlushRange (&texdata_bg, 640 * 480 * 4);
square[2] = square[5] = square[8] = square[11] = 0; // reset z value square[2] = square[5] = square[8] = square[11] = 0; // reset z value
GX_InvVtxCache (); GX_InvVtxCache ();
} }
@ -220,13 +220,13 @@ gui_draw ()
gui_setfontcolour (0,255,0,255); gui_setfontcolour (0,255,0,255);
// top bar text // top bar text
setfontsize (32); // 32/24 depending on whether selected or not setfontsize (32); // 32/24 depending on whether selected or not
gui_DrawText (-1, 35, (char *)"Menu"); gui_DrawText (-1, 35, "Menu");
// main text // main text
setfontsize (24); setfontsize (24);
gui_DrawText (75, 113, (char *)"Hello World"); gui_DrawText (75, 113, "Hello World");
// bottom bar text // bottom bar text
setfontsize (24); setfontsize (24);
gui_DrawText (75, 400, (char *)"Description"); gui_DrawText (75, 400, "Description");
} }
void void
@ -236,7 +236,7 @@ gui_savescreen ()
handle = fopen ("out.txt", "wb"); handle = fopen ("out.txt", "wb");
fwrite (Gui.texmem, 1, sizeof(Gui.texmem), handle); fwrite (Gui.texmem, 1, sizeof(Gui.texmem), handle);
fclose (handle); fclose (handle);
printf("\nsaved screen."); printf("\nsaved screen.");
} }
@ -245,15 +245,15 @@ gui_showscreen ()
{ {
/** Screen to Texture **/ /** Screen to Texture **/
GX_InitTexObj (&texobj_MENU, texdata_menu, 640, 480, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_InitTexObj (&texobj_MENU, texdata_menu, 640, 480, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
Make_Texture_RGBA8 (texdata_menu, Gui.texmem, 640, 480); Make_Texture_RGBA8 (texdata_menu, Gui.texmem, 640, 480);
DCFlushRange (&texdata_menu, 640 * 480 * 4); DCFlushRange (&texdata_menu, 640 * 480 * 4);
GX_InvalidateTexAll (); GX_InvalidateTexAll ();
/** thats nice, but will it blend? **/ /** thats nice, but will it blend? **/
// draw 640x480 quads // draw 640x480 quads
int xscale, yscale, xshift, yshift; int xscale, yscale, xshift, yshift;
xshift = yshift = 0; xshift = yshift = 0;
@ -263,25 +263,25 @@ gui_showscreen ()
square[0] = square[9] = -xscale + xshift; square[0] = square[9] = -xscale + xshift;
square[4] = square[1] = yscale + yshift; square[4] = square[1] = yscale + yshift;
square[7] = square[10] = -yscale + yshift; square[7] = square[10] = -yscale + yshift;
// draw 2 quads // draw 2 quads
// backdrop // backdrop
square[2] = square[5] = square[8] = square[11] = 0; // z value square[2] = square[5] = square[8] = square[11] = 0; // z value
GX_InvVtxCache (); GX_InvVtxCache ();
GX_LoadTexObj (&texobj_BG, GX_TEXMAP0); GX_LoadTexObj (&texobj_BG, GX_TEXMAP0);
draw_square (view); draw_square (view);
// menu overlay // menu overlay
square[2] = square[5] = square[8] = square[11] = 1; // z value square[2] = square[5] = square[8] = square[11] = 1; // z value
GX_InvVtxCache (); GX_InvVtxCache ();
GX_LoadTexObj (&texobj_MENU, GX_TEXMAP0); GX_LoadTexObj (&texobj_MENU, GX_TEXMAP0);
draw_square (view); draw_square (view);
GX_DrawDone (); GX_DrawDone ();
/** Display **/ /** Display **/
// show the output // show the output
VIDEO_SetNextFramebuffer (xfb[whichfb]); VIDEO_SetNextFramebuffer (xfb[whichfb]);
VIDEO_Flush (); VIDEO_Flush ();
@ -298,20 +298,20 @@ gui_showscreen ()
/**************************************************************************** /****************************************************************************
* Make Texture RGBA8 * Make Texture RGBA8
* *
* input: pointer to RGBA data * input: pointer to RGBA data
* output: formatted texture data (GX_TF_RGBA8) * output: formatted texture data (GX_TF_RGBA8)
* code modified from quake wii (thanks :) * code modified from quake wii (thanks :)
* todo: fix last few lines (?) * todo: fix last few lines (?)
****************************************************************************/ ****************************************************************************/
void void
Make_Texture_RGBA8 (void * dst_tex, void * src_data, int width, int height) Make_Texture_RGBA8 (void * dst_tex, void * src_data, int width, int height)
{ {
if ( (width % 4) || (height % 4) ) { if ( (width % 4) || (height % 4) ) {
printf ("Error: make_texture_rgba8 width/height not multiple of 4"); printf ("Error: make_texture_rgba8 width/height not multiple of 4");
return; return;
} }
int i, x, y; int i, x, y;
u8 *pos; u8 *pos;
@ -371,9 +371,9 @@ void
gui_drawbox (int x1, int y1, int width, int height, int r, int g, int b, int a) gui_drawbox (int x1, int y1, int width, int height, int r, int g, int b, int a)
{ {
u32 colour = ((u8)r << 24) | ((u8)g << 16) | ((u8)b << 8) | (u8)a; u32 colour = ((u8)r << 24) | ((u8)g << 16) | ((u8)b << 8) | (u8)a;
int i, j; int i, j;
u32* memory = (u32*) Gui.texmem; u32* memory = (u32*) Gui.texmem;
for (j = y1; j<height; j++) { for (j = y1; j<height; j++) {
for (i = x1; i<width; i++) { for (i = x1; i<width; i++) {
@ -417,7 +417,7 @@ gui_DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
* Place the font bitmap on the screen * Place the font bitmap on the screen
****************************************************************************/ ****************************************************************************/
void void
gui_DrawText (int x, int y, char *text) gui_DrawText (int x, int y, const char *text)
{ {
int px, n; int px, n;
int i; int i;
@ -488,7 +488,7 @@ gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a)
u32 colour; u32 colour;
int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py; int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py;
int sp; int sp;
u32* memory = (u32*)Gui.texmem; u32* memory = (u32*)Gui.texmem;
colour = ((u8)r << 24) | ((u8)g << 16) | ((u8)b << 8) | (u8)a; colour = ((u8)r << 24) | ((u8)g << 16) | ((u8)b << 8) | (u8)a;
@ -506,7 +506,7 @@ gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a)
py = y1; py = y1;
sp = (py * 640) + px; sp = (py * 640) + px;
/*** Plot this pixel ***/ /*** Plot this pixel ***/
memory[sp] = colour; memory[sp] = colour;
@ -546,21 +546,21 @@ gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a)
/* */ /* */
/** draw menu, etc **/ /** draw menu, etc **/
// - draw topbar, bottombar // - draw topbar, bottombar
// - draw icons // - draw icons
// - draw bar text // - draw bar text
// draw main text // draw main text
/** make textures **/ /** make textures **/
// - load background texture // - load background texture
// - draw onto quad // - draw onto quad
// - make foreground texture // - make foreground texture
// - draw onto quad // - draw onto quad
/** render image **/ /** render image **/
/** update framebuffer **/ /** update framebuffer **/
/* */ /* */

View File

@ -26,7 +26,7 @@ void gui_alphasetup ();
void gui_makebg (); void gui_makebg ();
void Make_Texture_RGBA8 (void * dst_tex, void * src_data, int width, int height); void Make_Texture_RGBA8 (void * dst_tex, void * src_data, int width, int height);
void gui_drawbox (int x1, int y1, int width, int height, int r, int g, int b, int a); void gui_drawbox (int x1, int y1, int width, int height, int r, int g, int b, int a);
void gui_DrawText (int x, int y, char *text); void gui_DrawText (int x, int y, const char *text);
void gui_setfontcolour (int r, int g, int b, int a); void gui_setfontcolour (int r, int g, int b, int a);
void gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a); void gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a);
void gui_clearscreen (); void gui_clearscreen ();

View File

@ -82,9 +82,9 @@ bool TestCard(int slot, bool silent)
if(!silent) if(!silent)
{ {
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Mounted Slot A Memory Card!"); WaitPrompt("Mounted Slot A Memory Card!");
else else
WaitPrompt((char*) "Mounted Slot B Memory Card!"); WaitPrompt("Mounted Slot B Memory Card!");
} }
CARD_Unmount (slot); CARD_Unmount (slot);
return true; return true;
@ -94,9 +94,9 @@ bool TestCard(int slot, bool silent)
if(!silent) if(!silent)
{ {
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
} }
return false; return false;
@ -154,7 +154,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
if (!CardFileExists (filename, slot)) if (!CardFileExists (filename, slot))
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to open file for verify!"); WaitPrompt("Unable to open file for verify!");
return 0; return 0;
} }
@ -182,7 +182,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
{ {
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "File did not verify!"); WaitPrompt("File did not verify!");
return 0; return 0;
} }
@ -199,9 +199,9 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
} }
else else
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
return 0; return 0;
} }
@ -234,7 +234,7 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
if (!CardFileExists (filename, slot)) if (!CardFileExists (filename, slot))
{ {
if (!silent) if (!silent)
WaitPrompt((char*) "Unable to open file"); WaitPrompt("Unable to open file");
return 0; return 0;
} }
@ -264,9 +264,9 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
} }
else else
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
return bytesread; return bytesread;
} }
@ -311,7 +311,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to open card file!"); WaitPrompt("Unable to open card file!");
return 0; return 0;
} }
@ -324,7 +324,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Not enough space to update file!"); WaitPrompt("Not enough space to update file!");
return 0; return 0;
} }
@ -334,7 +334,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to delete temporary file!"); WaitPrompt("Unable to delete temporary file!");
return 0; return 0;
} }
@ -343,7 +343,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to delete existing file!"); WaitPrompt("Unable to delete existing file!");
return 0; return 0;
} }
@ -352,7 +352,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to create updated card file!"); WaitPrompt("Unable to create updated card file!");
return 0; return 0;
} }
} }
@ -365,9 +365,9 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
if ( CardError == CARD_ERROR_INSSPACE ) if ( CardError == CARD_ERROR_INSSPACE )
WaitPrompt((char*) "Not enough space to create file!"); WaitPrompt("Not enough space to create file!");
else else
WaitPrompt((char*) "Unable to create card file!"); WaitPrompt("Unable to create card file!");
return 0; return 0;
} }
} }
@ -411,13 +411,13 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
} }
else else
if ( !silent ) if ( !silent )
WaitPrompt((char*) "This game does not appear to use SRAM"); WaitPrompt("This game does not appear to use SRAM");
} }
else else
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
return 0; return 0;

View File

@ -259,7 +259,7 @@ void CheatMenu()
} }
else else
{ {
WaitPrompt((char*)"No cheats found!"); WaitPrompt("No cheats found!");
} }
menu = oldmenu; menu = oldmenu;
} }
@ -311,7 +311,7 @@ GameMenu ()
if(Cheat.num_cheats == 0) if(Cheat.num_cheats == 0)
gamemenu[3][0] = '\0'; gamemenu[3][0] = '\0';
ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu"); ret = RunMenu (gamemenu, gamemenuCount, "Game Menu");
switch (ret) switch (ret)
{ {
@ -463,7 +463,7 @@ FileOptions ()
else if (GCSettings.AutoSave == 2) sprintf (filemenu[5],"Auto Save SNAPSHOT"); else if (GCSettings.AutoSave == 2) sprintf (filemenu[5],"Auto Save SNAPSHOT");
else if (GCSettings.AutoSave == 3) sprintf (filemenu[5],"Auto Save BOTH"); else if (GCSettings.AutoSave == 3) sprintf (filemenu[5],"Auto Save BOTH");
ret = RunMenu (filemenu, filemenuCount, (char*)"Save/Load Options"); ret = RunMenu (filemenu, filemenuCount, "Save/Load Options");
switch (ret) switch (ret)
{ {
@ -555,7 +555,7 @@ VideoOptions ()
sprintf (videomenu[7], "Video Shift: %d, %d", GCSettings.xshift, GCSettings.yshift); sprintf (videomenu[7], "Video Shift: %d, %d", GCSettings.xshift, GCSettings.yshift);
ret = RunMenu (videomenu, videomenuCount, (char*)"Video Options"); ret = RunMenu (videomenu, videomenuCount, "Video Options");
switch (ret) switch (ret)
{ {
@ -598,7 +598,7 @@ VideoOptions ()
case 8: case 8:
// reset video shifts // reset video shifts
GCSettings.xshift = GCSettings.yshift = 0; GCSettings.xshift = GCSettings.yshift = 0;
WaitPrompt((char *)"Video Shift Reset"); WaitPrompt("Video Shift Reset");
break; break;
case -1: // Button B case -1: // Button B
@ -687,21 +687,21 @@ GetButtonMap(u16 ctrlr_type, char* btn_name)
switch (ctrlr_type) { switch (ctrlr_type) {
case CTRLR_NUNCHUK: case CTRLR_NUNCHUK:
strncpy (cfg_text[3], (char*)"NUNCHUK", 7); strncpy (cfg_text[3], "NUNCHUK", 7);
break; break;
case CTRLR_CLASSIC: case CTRLR_CLASSIC:
strncpy (cfg_text[3], (char*)"CLASSIC", 7); strncpy (cfg_text[3], "CLASSIC", 7);
break; break;
case CTRLR_GCPAD: case CTRLR_GCPAD:
strncpy (cfg_text[3], (char*)"GC PAD", 7); strncpy (cfg_text[3], "GC PAD", 7);
break; break;
case CTRLR_WIIMOTE: case CTRLR_WIIMOTE:
strncpy (cfg_text[3], (char*)"WIIMOTE", 7); strncpy (cfg_text[3], "WIIMOTE", 7);
break; break;
}; };
/*** note which button we are remapping ***/ /*** 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 for (k=0; k<9-strlen(btn_name); k++) strcat(temp, " "); // add whitespace padding to align text
strncat (temp, btn_name, 9); // snes button we are remapping strncat (temp, btn_name, 9); // snes button we are remapping
strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display
@ -757,19 +757,19 @@ ConfigureButtons (u16 ctrlr_type)
/*** Update Menu Title (based on controller we're configuring) ***/ /*** Update Menu Title (based on controller we're configuring) ***/
switch (ctrlr_type) { switch (ctrlr_type) {
case CTRLR_NUNCHUK: case CTRLR_NUNCHUK:
menu_title = (char*)"SNES - NUNCHUK"; sprintf(menu_title, "SNES - NUNCHUK");
currentpadmap = ncpadmap; currentpadmap = ncpadmap;
break; break;
case CTRLR_CLASSIC: case CTRLR_CLASSIC:
menu_title = (char*)"SNES - CLASSIC"; sprintf(menu_title, "SNES - CLASSIC");
currentpadmap = ccpadmap; currentpadmap = ccpadmap;
break; break;
case CTRLR_GCPAD: case CTRLR_GCPAD:
menu_title = (char*)"SNES - GC PAD"; sprintf(menu_title, "SNES - GC PAD");
currentpadmap = gcpadmap; currentpadmap = gcpadmap;
break; break;
case CTRLR_WIIMOTE: case CTRLR_WIIMOTE:
menu_title = (char*)"SNES - WIIMOTE"; sprintf(menu_title, "SNES - WIIMOTE");
currentpadmap = wmpadmap; currentpadmap = wmpadmap;
break; break;
}; };
@ -793,7 +793,7 @@ ConfigureButtons (u16 ctrlr_type)
strncat (temp, ctrlr_def[ctrlr_type].map[j].name, 6); // update button map display strncat (temp, ctrlr_def[ctrlr_type].map[j].name, 6); // update button map display
} }
else 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 strncpy (cfg_btns_menu[i], temp, 19); // move back updated information
} }
@ -878,7 +878,7 @@ ConfigureControllers ()
else sprintf (ctlrmenu[3], "Justifiers: OFF"); else sprintf (ctlrmenu[3], "Justifiers: OFF");
/*** Controller Config Menu ***/ /*** Controller Config Menu ***/
ret = RunMenu (ctlrmenu, ctlrmenucount, (char*)"Configure Controllers"); ret = RunMenu (ctlrmenu, ctlrmenucount, "Configure Controllers");
switch (ret) switch (ret)
{ {
@ -953,7 +953,7 @@ PreferencesMenu ()
menu = 0; menu = 0;
while (quit == 0) while (quit == 0)
{ {
ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences"); ret = RunMenu (prefmenu, prefmenuCount, "Preferences");
switch (ret) switch (ret)
{ {
@ -971,7 +971,7 @@ PreferencesMenu ()
case 3: case 3:
DefaultSettings (); DefaultSettings ();
WaitPrompt((char *)"Preferences Reset"); WaitPrompt("Preferences Reset");
break; break;
case -1: /*** Button B ***/ case -1: /*** Button B ***/
@ -1030,7 +1030,7 @@ MainMenu (int selectedMenu)
} }
else else
{ {
ret = RunMenu (menuitems, menucount, (char*)"Main Menu"); ret = RunMenu (menuitems, menucount, "Main Menu");
} }
switch (ret) switch (ret)

View File

@ -144,7 +144,7 @@ DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
* Place the font bitmap on the screen * Place the font bitmap on the screen
***************************************************************************/ ***************************************************************************/
void void
DrawText (int x, int y, char *text) DrawText (int x, int y, const char *text)
{ {
int px, n; int px, n;
int i; int i;
@ -222,7 +222,7 @@ Credits ()
setfontcolour (0x00, 0x00, 0x00); setfontcolour (0x00, 0x00, 0x00);
setfontsize (28); setfontsize (28);
DrawText (-1, 60, (char*)"Credits"); DrawText (-1, 60, "Credits");
int ypos = 25; int ypos = 25;
@ -232,33 +232,33 @@ Credits ()
ypos += 32; ypos += 32;
setfontsize (20); setfontsize (20);
DrawText (-1, ypos += 30, (char*)"Technical"); DrawText (-1, ypos += 30, "Technical");
setfontsize (16); setfontsize (16);
DrawText (75, ypos += 30, (char*)"Snes9x GX 00x"); DrawText (75, ypos += 30, "Snes9x GX 00x");
DrawText (350, ypos, (char*)"michniewski & Tantric"); DrawText (350, ypos, "michniewski & Tantric");
DrawText (75, ypos += 20, (char*)"Snes9X GX 2.0.1 GameCube"); DrawText (75, ypos += 20, "Snes9X GX 2.0.1 GameCube");
DrawText (350, ypos, (char*)"crunchy2, eke-eke, others"); DrawText (350, ypos, "crunchy2, eke-eke, others");
DrawText (75, ypos += 20, (char*)"Snes9x GX GameCube Port"); DrawText (75, ypos += 20, "Snes9x GX GameCube Port");
DrawText (350, ypos, (char*)"SoftDev"); DrawText (350, ypos, "SoftDev");
DrawText (75, ypos += 20, (char*)"Snes9x 1.5.1"); DrawText (75, ypos += 20, "Snes9x 1.5.1");
DrawText (350, ypos, (char*)"Snes9x Team"); DrawText (350, ypos, "Snes9x Team");
DrawText (75, ypos += 20, (char*)"GX"); DrawText (75, ypos += 20, "GX");
DrawText (350, ypos, (char*)"http://www.gc-linux.org"); DrawText (350, ypos, "http://www.gc-linux.org");
DrawText (75, ypos += 20, (char*)"libogc"); DrawText (75, ypos += 20, "libogc");
DrawText (350, ypos, (char*)"Shagkur & wintermute"); DrawText (350, ypos, "Shagkur & wintermute");
setfontsize (20); setfontsize (20);
DrawText (-1, ypos += 40, (char*)"Testing"); DrawText (-1, ypos += 40, "Testing");
setfontsize (16); setfontsize (16);
DrawText (-1, ypos += 30, (char*)"TehSkeen users"); DrawText (-1, ypos += 30, "TehSkeen users");
setfontsize (12); setfontsize (12);
DrawText (-1, ypos += 75, (char*)"Snes9x - Copyright (c) Snes9x Team 1996 - 2006"); DrawText (-1, ypos += 75, "Snes9x - Copyright (c) Snes9x Team 1996 - 2006");
DrawText (-1, ypos += 15, (char*)"This software is open source and may be copied, distributed, or modified"); DrawText (-1, ypos += 15, "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 += 15, "under the terms of the GNU General Public License (GPL) Version 2.");
showscreen (); showscreen ();
} }
@ -402,7 +402,7 @@ WaitButtonAB ()
* Show a prompt * Show a prompt
***************************************************************************/ ***************************************************************************/
void void
WaitPrompt (char *msg) WaitPrompt (const char *msg)
{ {
int ypos = (screenheight - 64) >> 1; int ypos = (screenheight - 64) >> 1;
@ -414,7 +414,7 @@ WaitPrompt (char *msg)
clearscreen (); clearscreen ();
DrawText (-1, ypos, msg); DrawText (-1, ypos, msg);
ypos += 30; ypos += 30;
DrawText (-1, ypos, (char*)"Press A to continue"); DrawText (-1, ypos, "Press A to continue");
showscreen (); showscreen ();
WaitButtonA (); WaitButtonA ();
} }
@ -424,7 +424,7 @@ WaitPrompt (char *msg)
and 0 if B button was pressed. and 0 if B button was pressed.
***************************************************************************/ ***************************************************************************/
int int
WaitPromptChoice (char *msg, char *bmsg, char *amsg) WaitPromptChoice (const char *msg, const char *bmsg, const char *amsg)
{ {
int ypos = (screenheight - 64) >> 1; int ypos = (screenheight - 64) >> 1;
@ -447,7 +447,7 @@ WaitPromptChoice (char *msg, char *bmsg, char *amsg)
* Show an action in progress * Show an action in progress
***************************************************************************/ ***************************************************************************/
void void
ShowAction (char *msg) ShowAction (const char *msg)
{ {
int ypos = (screenheight - 30) >> 1; int ypos = (screenheight - 30) >> 1;
@ -465,7 +465,7 @@ ShowAction (char *msg)
* Generic Menu Routines * Generic Menu Routines
***************************************************************************/ ***************************************************************************/
void 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 i, w = 0;
int ypos = 0; int ypos = 0;
@ -556,7 +556,7 @@ int FindMenuItem(char items[][50], int maxitems, int currentItem, int direction)
int menu = 0; int menu = 0;
int 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 redraw = 1;
int quit = 0; int quit = 0;
@ -649,7 +649,7 @@ ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection)
clearscreen (); clearscreen ();
setfontsize (28); setfontsize (28);
DrawText (-1, 60, (char*)"Choose Game"); DrawText (-1, 60, "Choose Game");
setfontsize(18); setfontsize(18);
@ -709,7 +709,7 @@ ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, i
clearscreen (); clearscreen ();
setfontsize (28); setfontsize (28);
DrawText (-1, 60, (char*)"Cheats"); DrawText (-1, 60, "Cheats");
setfontsize(18); setfontsize(18);
@ -758,7 +758,7 @@ void RomInfo()
ypos += 32; ypos += 32;
setfontsize (28); setfontsize (28);
DrawText (-1, 60, (char*)"Rom Information"); DrawText (-1, 60, "Rom Information");
setfontsize (16); setfontsize (16);
setfontcolour (0x00, 0x00, 0x00); setfontcolour (0x00, 0x00, 0x00);
@ -777,49 +777,49 @@ void RomInfo()
char fmtString[1024]; char fmtString[1024];
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_ROM); DrawText (150, ypos, MENU_INFO_ROM);
DrawText (300, ypos, Memory.ROMName); DrawText (300, ypos, Memory.ROMName);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_ROMID); DrawText (150, ypos, MENU_INFO_ROMID);
DrawText (300, ypos, Memory.ROMId); DrawText (300, ypos, Memory.ROMId);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_COMPANY); DrawText (150, ypos, MENU_INFO_COMPANY);
DrawText (300, ypos, Memory.CompanyId); DrawText (300, ypos, Memory.CompanyId);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_SIZE); DrawText (150, ypos, MENU_INFO_SIZE);
sprintf(fmtString, "%d", Memory.ROMSize); sprintf(fmtString, "%d", Memory.ROMSize);
DrawText (300, ypos, fmtString); DrawText (300, ypos, fmtString);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_SRAM); DrawText (150, ypos, MENU_INFO_SRAM);
sprintf(fmtString, "%d", Memory.SRAMSize); sprintf(fmtString, "%d", Memory.SRAMSize);
DrawText (300, ypos, fmtString); DrawText (300, ypos, fmtString);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_TYPE); DrawText (150, ypos, MENU_INFO_TYPE);
sprintf(fmtString, "%d", Memory.ROMType); sprintf(fmtString, "%d", Memory.ROMType);
DrawText (300, ypos, fmtString); DrawText (300, ypos, fmtString);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_CHECKSUM); DrawText (150, ypos, MENU_INFO_CHECKSUM);
sprintf(fmtString, "%04x / %04x", Memory.ROMChecksum, Memory.ROMComplementChecksum); sprintf(fmtString, "%04x / %04x", Memory.ROMChecksum, Memory.ROMComplementChecksum);
DrawText (300, ypos, fmtString); DrawText (300, ypos, fmtString);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_TVTYPE); DrawText (150, ypos, MENU_INFO_TVTYPE);
sprintf(fmtString, "%s", Settings.PAL ? "PAL" : "NTSC"); sprintf(fmtString, "%s", Settings.PAL ? "PAL" : "NTSC");
DrawText (300, ypos, fmtString); DrawText (300, ypos, fmtString);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_FRAMES); DrawText (150, ypos, MENU_INFO_FRAMES);
sprintf(fmtString, "%d", Memory.ROMFramesPerSecond); sprintf(fmtString, "%d", Memory.ROMFramesPerSecond);
DrawText (300, ypos, fmtString); DrawText (300, ypos, fmtString);
ypos += 20; ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_CRC32); DrawText (150, ypos, MENU_INFO_CRC32);
sprintf(fmtString, "%08X", Memory.ROMCRC32); sprintf(fmtString, "%08X", Memory.ROMCRC32);
DrawText (300, ypos, fmtString); DrawText (300, ypos, fmtString);
@ -918,7 +918,7 @@ DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b)
* Show the user what's happening * Show the user what's happening
***************************************************************************/ ***************************************************************************/
void void
ShowProgress (char *msg, int done, int total) ShowProgress (const char *msg, int done, int total)
{ {
if(total <= 0) // division by 0 is bad! if(total <= 0) // division by 0 is bad!
return; return;

View File

@ -27,20 +27,20 @@
int FT_Init (); int FT_Init ();
void setfontsize (int pixelsize); void setfontsize (int pixelsize);
void setfontcolour (u8 r, u8 g, u8 b); 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 unpackbackdrop (); void unpackbackdrop ();
void Credits (); void Credits ();
void RomInfo (); void RomInfo ();
void WaitButtonA (); void WaitButtonA ();
int RunMenu (char items[][50], int maxitems, char *title, int fontsize = 20, int x = -1); int RunMenu (char items[][50], int maxitems, const char *title, int fontsize = 20, int x = -1);
void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize = 20, int x = -1); void DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize = 20, int x = -1);
void ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, int selection); 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 (FILEENTRIES filelist[], int maxfiles, int offset, int selection);
void WaitPrompt (char *msg); void WaitPrompt (const char *msg);
int WaitPromptChoice (char *msg, char* bmsg, char* amsg); int WaitPromptChoice (const char *msg, const char* bmsg, const char* amsg);
void ShowAction (char *msg); void ShowAction (const char *msg);
void ShowProgress (char *msg, int done, int total); void ShowProgress (const char *msg, int done, int total);
void DrawPolygon (int vertices, int *varray, u8 r, u8 g, u8 b); 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 );

View File

@ -15,7 +15,7 @@
#include "snes9xGX.h" #include "snes9xGX.h"
#include "menudraw.h" #include "menudraw.h"
#include "memfile.h" #include "memfile.h"
#include "filesel.h" #include "fileop.h"
static int readInt2(MFILE *f) { static int readInt2(MFILE *f) {
int res = 0; int res = 0;
@ -411,7 +411,7 @@ void LoadPatch(int method)
int patchtype; int patchtype;
char patchpath[3][512]; char patchpath[3][512];
ShowAction((char *)"Loading patch..."); ShowAction("Loading patch...");
AllocSaveBuffer (); AllocSaveBuffer ();

View File

@ -327,7 +327,7 @@ SavePrefs (int method, bool silent)
return false; return false;
if (!silent) if (!silent)
ShowAction ((char*) "Saving preferences..."); ShowAction ("Saving preferences...");
AllocSaveBuffer (); AllocSaveBuffer ();
datasize = preparePrefsData (method); datasize = preparePrefsData (method);
@ -339,7 +339,7 @@ SavePrefs (int method, bool silent)
if (offset > 0) if (offset > 0)
{ {
if (!silent) if (!silent)
WaitPrompt ((char *)"Preferences saved"); WaitPrompt ("Preferences saved");
return true; return true;
} }
return false; return false;
@ -376,17 +376,17 @@ LoadPrefsFromMethod (int method)
***************************************************************************/ ***************************************************************************/
bool LoadPrefs() bool LoadPrefs()
{ {
ShowAction ((char*) "Loading preferences..."); ShowAction ("Loading preferences...");
bool prefFound = false; bool prefFound = false;
if(ChangeFATInterface(METHOD_SD, SILENT)) if(ChangeInterface(METHOD_SD, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_SD); prefFound = LoadPrefsFromMethod(METHOD_SD);
if(!prefFound && ChangeFATInterface(METHOD_USB, SILENT)) if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_USB); prefFound = LoadPrefsFromMethod(METHOD_USB);
if(!prefFound && TestCard(CARD_SLOTA, SILENT)) if(!prefFound && TestCard(CARD_SLOTA, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA); prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA);
if(!prefFound && TestCard(CARD_SLOTB, SILENT)) if(!prefFound && TestCard(CARD_SLOTB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB); prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB);
if(!prefFound && ConnectShare (SILENT)) if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_SMB); prefFound = LoadPrefsFromMethod(METHOD_SMB);
return prefFound; return prefFound;

View File

@ -45,12 +45,6 @@ DefaultSettings ()
GCSettings.smbpwd[19] = 0; GCSettings.smbpwd[19] = 0;
GCSettings.smbshare[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;
GCSettings.Superscope = 0; GCSettings.Superscope = 0;
GCSettings.Mouse = 0; GCSettings.Mouse = 0;
GCSettings.Justifier = 0; GCSettings.Justifier = 0;

View File

@ -12,40 +12,38 @@
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <network.h> #include <network.h>
#include <smb.h> #include <smb.h>
#include <zlib.h> #include <zlib.h>
#include <errno.h> #include <errno.h>
#include "memmap.h"
#include "smbop.h" #include "snes9xGX.h"
#include "fileop.h"
#include "unzip.h" #include "unzip.h"
#include "video.h" #include "video.h"
#include "menudraw.h" #include "menudraw.h"
#include "filesel.h" #include "filesel.h"
#include "snes9xGX.h"
bool networkInit = false; bool networkInit = false;
bool networkShareInit = false; bool networkShareInit = false;
unsigned int SMBTimer = 0; bool networkInitHalt = false;
#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
/**************************************************************************** /****************************************************************************
* InitializeNetwork * InitializeNetwork
* Initializes the Wii/GameCube network interface * 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; s32 result;
while ((result = net_init()) == -EAGAIN); while ((result = net_init()) == -EAGAIN);
@ -56,19 +54,28 @@ bool InitializeNetwork(bool silent)
if (if_config(myIP, NULL, NULL, true) < 0) if (if_config(myIP, NULL, NULL, true) < 0)
{ {
networkInitHalt = true; // do not attempt a reconnection again
if(!silent) if(!silent)
WaitPrompt((char*) "Error reading IP address."); WaitPrompt("Error reading IP address.");
return false;
} }
else else
{ {
return true; networkInit = true;
} }
} }
else
{
if(!silent)
WaitPrompt("Unable to initialize network.");
}
}
if(!silent) void CloseShare()
WaitPrompt((char*) "Unable to initialize network."); {
return false; if(networkShareInit)
smbClose();
networkShareInit = false;
} }
/**************************************************************************** /****************************************************************************
@ -90,266 +97,33 @@ ConnectShare (bool silent)
strlen(GCSettings.smbip) == 0) strlen(GCSettings.smbip) == 0)
{ {
if(!silent) if(!silent)
WaitPrompt((char*) "Invalid network settings. Check settings.xml."); WaitPrompt("Invalid network settings. Check settings.xml.");
return false; return false;
} }
if(!networkInit) if(!networkInit)
networkInit = InitializeNetwork(silent); InitializeNetwork(silent);
if(networkInit) if(networkInit)
{ {
// connection may have expired if(unmountRequired[METHOD_SMB])
if (networkShareInit && SMBTimer > SMBTIMEOUT) CloseShare();
{
networkShareInit = false;
SMBTimer = 0;
SMB_Close(smbconn);
}
if(!networkShareInit) if(!networkShareInit)
{ {
if(!silent) if(!silent)
ShowAction ((char*) "Connecting to network share..."); ShowAction ("Connecting to network share...");
if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd, if(smbInit(GCSettings.smbuser, GCSettings.smbpwd,
GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS) GCSettings.smbshare, GCSettings.smbip))
{
networkShareInit = true; networkShareInit = true;
}
} }
if(!networkShareInit && !silent) if(!networkShareInit && !silent)
WaitPrompt ((char*) "Failed to connect to network share."); WaitPrompt ("Failed to connect to network share.");
} }
return networkShareInit; return networkShareInit;
} }
/****************************************************************************
* SMBPath
*
* Returns a SMB-style path
*****************************************************************************/
char * SMBPath(char * path)
{
// fix path - replace all '/' with '\'
for(uint 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, 1024, 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;
ShowProgress ((char *)"Loading...", boffset, length);
}
}
}
SMB_CloseFile (smbfile);
return boffset;
}

View File

@ -11,21 +11,10 @@
****************************************************************************/ ****************************************************************************/
#ifndef _NGCSMB_ #ifndef _NGCSMB_
#define _NGCSMB_ #define _NGCSMB_
#include <smb.h> void InitializeNetwork(bool silent);
bool InitializeNetwork(bool silent);
bool ConnectShare (bool silent); bool ConnectShare (bool silent);
char * SMBPath(char * path); void CloseShare();
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;
#endif #endif

View File

@ -19,9 +19,6 @@
#include <ogcsys.h> #include <ogcsys.h>
#include <unistd.h> #include <unistd.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include <sdcard/card_cmn.h>
#include <sdcard/wiisd_io.h>
#include <sdcard/card_io.h>
#include <fat.h> #include <fat.h>
#ifdef WII_DVD #ifdef WII_DVD
@ -76,6 +73,16 @@ extern unsigned int timediffallowed;
* Shutdown / Reboot / Exit * Shutdown / Reboot / Exit
***************************************************************************/ ***************************************************************************/
void ExitCleanup()
{
UnmountAllFAT();
CloseShare();
#ifdef HW_RVL
DI_Close();
#endif
}
#ifdef HW_DOL #ifdef HW_DOL
#define PSOSDLOADID 0x7c6000a6 #define PSOSDLOADID 0x7c6000a6
int *psoid = (int *) 0x80001800; int *psoid = (int *) 0x80001800;
@ -84,9 +91,8 @@ extern unsigned int timediffallowed;
void Reboot() void Reboot()
{ {
UnmountAllFAT(); ExitCleanup();
#ifdef HW_RVL #ifdef HW_RVL
DI_Close();
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
#else #else
#define SOFTRESET_ADR ((volatile u32*)0xCC003024) #define SOFTRESET_ADR ((volatile u32*)0xCC003024)
@ -96,10 +102,9 @@ void Reboot()
void ExitToLoader() void ExitToLoader()
{ {
UnmountAllFAT(); ExitCleanup();
// Exit to Loader // Exit to Loader
#ifdef HW_RVL #ifdef HW_RVL
DI_Close();
exit(0); exit(0);
#else // gamecube #else // gamecube
if (psoid[0] == PSOSDLOADID) if (psoid[0] == PSOSDLOADID)
@ -119,8 +124,7 @@ void ResetCB()
} }
void ShutdownWii() void ShutdownWii()
{ {
UnmountAllFAT(); ExitCleanup();
DI_Close();
SYS_ResetSystem(SYS_POWEROFF, 0, 0); SYS_ResetSystem(SYS_POWEROFF, 0, 0);
} }
#endif #endif
@ -218,12 +222,12 @@ emulate ()
} }
else if ( GCSettings.AutoSave == 2 ) else if ( GCSettings.AutoSave == 2 )
{ {
if ( WaitPromptChoice ((char*)"Save Freeze State?", (char*)"Don't Save", (char*)"Save") ) if ( WaitPromptChoice ("Save Freeze State?", "Don't Save", "Save") )
NGCFreezeGame ( GCSettings.SaveMethod, SILENT ); NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
} }
else if ( GCSettings.AutoSave == 3 ) else if ( GCSettings.AutoSave == 3 )
{ {
if ( WaitPromptChoice ((char*)"Save SRAM and Freeze State?", (char*)"Don't Save", (char*)"Save") ) if ( WaitPromptChoice ("Save SRAM and Freeze State?", "Don't Save", "Save") )
{ {
SaveSRAM(GCSettings.SaveMethod, SILENT ); SaveSRAM(GCSettings.SaveMethod, SILENT );
NGCFreezeGame ( GCSettings.SaveMethod, SILENT ); NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
@ -414,12 +418,8 @@ main(int argc, char *argv[])
while (1); while (1);
// Initialize libFAT for SD and USB // Initialize libFAT for SD and USB
fatInit (8, false); MountAllFAT();
InitDeviceThread();
#ifdef _DEBUG_VIDEO
// log stuff
debughandle = fopen ("log.txt", "wb");
#endif
// Initialize DVD subsystem (GameCube only) // Initialize DVD subsystem (GameCube only)
#ifdef HW_DOL #ifdef HW_DOL
@ -432,7 +432,7 @@ main(int argc, char *argv[])
// Load preferences // Load preferences
if(!LoadPrefs()) if(!LoadPrefs())
{ {
WaitPrompt((char*) "Preferences reset - check settings!"); WaitPrompt("Preferences reset - check settings!");
selectedMenu = 1; // change to preferences menu selectedMenu = 1; // change to preferences menu
} }

View File

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

View File

@ -22,7 +22,7 @@
#include "snes9xGX.h" #include "snes9xGX.h"
#include "images/saveicon.h" #include "images/saveicon.h"
#include "menudraw.h" #include "menudraw.h"
#include "filesel.h" #include "fileop.h"
extern int padcal; extern int padcal;
extern unsigned short gcpadmap[]; extern unsigned short gcpadmap[];
@ -131,7 +131,7 @@ decodesavedata (int method, int readsize)
} }
else else
{ {
WaitPrompt((char*)"Incompatible SRAM save!"); WaitPrompt("Incompatible SRAM save!");
} }
} }
@ -150,7 +150,7 @@ LoadSRAM (int method, bool silent)
if(!MakeFilePath(filepath, FILE_SRAM, method)) if(!MakeFilePath(filepath, FILE_SRAM, method))
return 0; return 0;
ShowAction ((char*) "Loading..."); ShowAction ("Loading...");
AllocSaveBuffer(); AllocSaveBuffer();
@ -169,7 +169,7 @@ LoadSRAM (int method, bool silent)
// if we reached here, nothing was done! // if we reached here, nothing was done!
if(!silent) if(!silent)
WaitPrompt ((char*) "SRAM file not found"); WaitPrompt ("SRAM file not found");
return 0; return 0;
} }
@ -192,7 +192,7 @@ SaveSRAM (int method, bool silent)
if(!MakeFilePath(filepath, FILE_SRAM, method)) if(!MakeFilePath(filepath, FILE_SRAM, method))
return false; return false;
ShowAction ((char*) "Saving..."); ShowAction ("Saving...");
AllocSaveBuffer (); AllocSaveBuffer ();
@ -205,14 +205,14 @@ SaveSRAM (int method, bool silent)
if (offset > 0) if (offset > 0)
{ {
if ( !silent ) if ( !silent )
WaitPrompt((char *)"Save successful"); WaitPrompt("Save successful");
retval = true; retval = true;
} }
} }
else else
{ {
if(!silent) if(!silent)
WaitPrompt((char *)"No SRAM data to save!"); WaitPrompt("No SRAM data to save!");
} }
FreeSaveBuffer (); FreeSaveBuffer ();

View File

@ -103,32 +103,30 @@ UnZipBuffer (unsigned char *outbuffer, int method)
int have = 0; int have = 0;
char readbuffer[ZIPCHUNK]; char readbuffer[ZIPCHUNK];
u64 discoffset = 0; u64 discoffset = 0;
int sizeread = 0;
// Read Zip Header // Read Zip Header
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
fseek(fatfile, 0, SEEK_SET);
fread (readbuffer, 1, ZIPCHUNK, fatfile);
break;
case METHOD_DVD: case METHOD_DVD:
discoffset = dvddir; discoffset = dvddir;
dvd_read (readbuffer, ZIPCHUNK, discoffset); sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset);
break; break;
default:
case METHOD_SMB: fseek(file, 0, SEEK_SET);
SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile); sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
break; break;
} }
if(sizeread <= 0)
return 0;
/*** Copy PKZip header to local, used as info ***/ /*** Copy PKZip header to local, used as info ***/
memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER)); memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER));
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize); pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
ShowProgress ((char *)"Loading...", 0, pkzip.uncompressedSize); ShowProgress ("Loading...", 0, pkzip.uncompressedSize);
/*** Prepare the zip stream ***/ /*** Prepare the zip stream ***/
memset (&zs, 0, sizeof (z_stream)); memset (&zs, 0, sizeof (z_stream));
@ -184,22 +182,18 @@ UnZipBuffer (unsigned char *outbuffer, int method)
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
fread (readbuffer, 1, ZIPCHUNK, fatfile);
break;
case METHOD_DVD: case METHOD_DVD:
readoffset += ZIPCHUNK; readoffset += ZIPCHUNK;
dvd_read (readbuffer, ZIPCHUNK, discoffset+readoffset); sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset+readoffset);
break; break;
default:
case METHOD_SMB: sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
readoffset += ZIPCHUNK;
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
break; break;
} }
ShowProgress ((char *)"Loading...", bufferoffset, pkzip.uncompressedSize); if(sizeread <= 0)
break; // read failure
ShowProgress ("Loading...", bufferoffset, pkzip.uncompressedSize);
} }
while (res != Z_STREAM_END); while (res != Z_STREAM_END);
@ -234,13 +228,21 @@ GetFirstZipFilename (int method)
return NULL; return NULL;
// read start of ZIP // read start of ZIP
LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT); if(LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT))
{
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
int namelength = tempbuffer[26]; // filename length starts 26 bytes in
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) if(namelength > 0 && namelength < 200) // the filename is a reasonable length
int namelength = tempbuffer[26]; // filename length starts 26 bytes in {
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in firstFilename[namelength] = 0; // truncate at filename length
firstFilename[namelength] = 0; // truncate at filename length }
else
{
WaitPrompt("Error - Invalid ZIP file!");
}
}
return firstFilename; return firstFilename;
} }
@ -264,6 +266,7 @@ char szerrormsg[][30] = {
"7z: CRC Error", "7z: CRC Error",
"7z: Not implemented", "7z: Not implemented",
"7z: Fail", "7z: Fail",
"7z: Data read failure",
"7z: Archive error", "7z: Archive error",
"7z: Dictionary too large", "7z: Dictionary too large",
}; };
@ -312,9 +315,11 @@ void SzDisplayError(SZ_RESULT res)
} }
// function used by the 7zip SDK to read data from SD/USB/DVD/SMB // 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) SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
{ {
int seekok = 0;
int sizeread = 0;
// the void* object is a SzFileInStream // the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *) object; SzFileInStream *s = (SzFileInStream *) object;
@ -327,26 +332,25 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
// read data // read data
switch (szMethod) switch (szMethod)
{ {
case METHOD_SD:
case METHOD_USB:
fseek(fatfile, offset, SEEK_SET);
fread(sz_buffer, 1, maxRequiredSize, fatfile);
break;
case METHOD_DVD: case METHOD_DVD:
dvd_safe_read(sz_buffer, maxRequiredSize, offset); sizeread = dvd_safe_read(sz_buffer, maxRequiredSize, offset);
break; break;
case METHOD_SMB: default:
SMB_ReadFile(sz_buffer, maxRequiredSize, offset, smbfile); seekok = fseek(file, offset, SEEK_SET);
sizeread = fread(sz_buffer, 1, maxRequiredSize, file);
break; break;
} }
if(seekok != 0 || sizeread <= 0)
return SZE_FAILREAD;
*buffer = sz_buffer; *buffer = sz_buffer;
*processedSize = maxRequiredSize; *processedSize = maxRequiredSize;
s->pos += *processedSize; s->pos += *processedSize;
if(maxRequiredSize > 1024) // only show progress for large reads if(maxRequiredSize > 1024) // only show progress for large reads
// this isn't quite right, but oh well // this isn't quite right, but oh well
ShowProgress ((char *)"Loading...", s->pos, filelist[selection].length); ShowProgress ("Loading...", s->pos, filelist[selection].length);
return SZ_OK; return SZ_OK;
} }
@ -359,10 +363,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
// check if the 7z SDK wants to move the pointer to somewhere after the EOF // check if the 7z SDK wants to move the pointer to somewhere after the EOF
if (pos >= s->len) if (pos >= s->len)
{
WaitPrompt((char *) "7z: Error - attempt to read after EOF!");
return SZE_FAIL; return SZE_FAIL;
}
// save new position and return // save new position and return
s->pos = pos; s->pos = pos;
@ -391,13 +392,9 @@ int SzParse(char * filepath, int method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fatfile = fopen (filepath, "rb");
if(!fatfile)
return 0;
break;
case METHOD_SMB: case METHOD_SMB:
smbfile = OpenSMBFile(filepath); file = fopen (filepath, "rb");
if(!smbfile) if(!file)
return 0; return 0;
break; break;
} }
@ -405,7 +402,7 @@ int SzParse(char * filepath, int method)
// set szMethod to current chosen load method // set szMethod to current chosen load method
szMethod = 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.Read = SzFileReadImp;
SzArchiveStream.InStream.Seek = SzFileSeekImp; SzArchiveStream.InStream.Seek = SzFileSeekImp;
@ -484,10 +481,8 @@ int SzParse(char * filepath, int method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fclose(fatfile);
break;
case METHOD_SMB: case METHOD_SMB:
SMB_CloseFile (smbfile); fclose(file);
break; break;
} }
return nbfiles; return nbfiles;
@ -521,16 +516,16 @@ int SzExtractFile(int i, unsigned char *buffer)
// Unzip the file // Unzip the file
SzRes = SzExtract2( SzRes = SzExtract2(
&SzArchiveStream.InStream, &SzArchiveStream.InStream,
&SzDb, &SzDb,
i, // index of file i, // index of file
&SzBlockIndex, // index of solid block &SzBlockIndex, // index of solid block
&buffer, &buffer,
&SzBufferSize, &SzBufferSize,
&SzOffset, // offset of stream for required file in *outBuffer &SzOffset, // offset of stream for required file in *outBuffer
&SzOutSizeProcessed, // size of file in *outBuffer &SzOutSizeProcessed, // size of file in *outBuffer
&SzAllocImp, &SzAllocImp,
&SzAllocTempImp); &SzAllocTempImp);
// close 7Zip archive and free memory // close 7Zip archive and free memory
SzClose(); SzClose();

View File

@ -28,8 +28,6 @@
/*** Snes9x GFX Buffer ***/ /*** Snes9x GFX Buffer ***/
static unsigned char snes9xgfx[1024 * 512 * 2]; static unsigned char snes9xgfx[1024 * 512 * 2];
extern unsigned int SMBTimer;
/*** 2D Video ***/ /*** 2D Video ***/
unsigned int *xfb[2] = { NULL, NULL }; // Double buffered unsigned int *xfb[2] = { NULL, NULL }; // Double buffered
int whichfb = 0; // Switch int whichfb = 0; // Switch
@ -309,7 +307,6 @@ copy_to_xfb (u32 arg)
} }
FrameTimer++; FrameTimer++;
SMBTimer++;
} }
/**************************************************************************** /****************************************************************************

View File

@ -61,10 +61,11 @@ typedef UInt32 CFileSize;
#define SZE_NOTIMPL (4) #define SZE_NOTIMPL (4)
#define SZE_FAIL (5) #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_; } #define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }