2006-07-29 05:46:15 +00:00
|
|
|
/* FCE Ultra - NES/Famicom Emulator
|
|
|
|
*
|
|
|
|
* Copyright notice for this file:
|
|
|
|
* Copyright (C) 2002 Xodnizel
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-05-26 07:34:40 +00:00
|
|
|
#include <limits.h>
|
2006-07-29 05:46:15 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-08-01 05:50:19 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2006-07-29 05:46:15 +00:00
|
|
|
|
2008-07-09 05:47:13 +00:00
|
|
|
#ifndef WIN32
|
2006-07-29 05:46:15 +00:00
|
|
|
#include <zlib.h>
|
2008-07-09 05:47:13 +00:00
|
|
|
#endif
|
2006-07-29 05:46:15 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "file.h"
|
2006-08-01 05:50:19 +00:00
|
|
|
#include "utils/endian.h"
|
|
|
|
#include "utils/memory.h"
|
|
|
|
#include "utils/md5.h"
|
|
|
|
#include "utils/unzip.h"
|
|
|
|
#include "driver.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "fceu.h"
|
|
|
|
#include "state.h"
|
|
|
|
#include "movie.h"
|
2006-07-29 05:46:15 +00:00
|
|
|
#include "driver.h"
|
2008-05-26 07:34:40 +00:00
|
|
|
#include "utils/xstring.h"
|
2006-07-29 05:46:15 +00:00
|
|
|
|
2008-06-22 02:38:00 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2006-07-29 05:46:15 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8 *data;
|
|
|
|
uint32 size;
|
|
|
|
uint32 location;
|
|
|
|
} MEMWRAP;
|
|
|
|
|
|
|
|
void ApplyIPS(FILE *ips, MEMWRAP *dest)
|
|
|
|
{
|
2008-06-22 02:38:00 +00:00
|
|
|
uint8 header[5];
|
|
|
|
uint32 count=0;
|
|
|
|
|
|
|
|
FCEU_printf(" Applying IPS...\n");
|
|
|
|
if(fread(header,1,5,ips)!=5)
|
|
|
|
{
|
|
|
|
fclose(ips);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(memcmp(header,"PATCH",5))
|
|
|
|
{
|
|
|
|
fclose(ips);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(fread(header,1,3,ips)==3)
|
|
|
|
{
|
|
|
|
uint32 offset=(header[0]<<16)|(header[1]<<8)|header[2];
|
|
|
|
uint16 size;
|
|
|
|
|
|
|
|
if(!memcmp(header,"EOF",3))
|
|
|
|
{
|
|
|
|
FCEU_printf(" IPS EOF: Did %d patches\n\n",count);
|
|
|
|
fclose(ips);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size=fgetc(ips)<<8;
|
|
|
|
size|=fgetc(ips);
|
|
|
|
if(!size) /* RLE */
|
|
|
|
{
|
|
|
|
uint8 *start;
|
|
|
|
uint8 b;
|
|
|
|
size=fgetc(ips)<<8;
|
|
|
|
size|=fgetc(ips);
|
|
|
|
|
|
|
|
//FCEU_printf(" Offset: %8d Size: %5d RLE\n",offset,size);
|
|
|
|
|
|
|
|
if((offset+size)>dest->size)
|
|
|
|
{
|
|
|
|
uint8 *tmp;
|
|
|
|
|
|
|
|
// Probably a little slow.
|
|
|
|
tmp=(uint8 *)realloc(dest->data,offset+size);
|
|
|
|
if(!tmp)
|
|
|
|
{
|
|
|
|
FCEU_printf(" Oops. IPS patch %d(type RLE) goes beyond end of file. Could not allocate memory.\n",count);
|
|
|
|
fclose(ips);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dest->size=offset+size;
|
|
|
|
dest->data=tmp;
|
|
|
|
memset(dest->data+dest->size,0,offset+size-dest->size);
|
|
|
|
}
|
|
|
|
b=fgetc(ips);
|
|
|
|
start=dest->data+offset;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*start=b;
|
|
|
|
start++;
|
|
|
|
} while(--size);
|
|
|
|
}
|
|
|
|
else /* Normal patch */
|
|
|
|
{
|
|
|
|
//FCEU_printf(" Offset: %8d Size: %5d\n",offset,size);
|
|
|
|
if((offset+size)>dest->size)
|
|
|
|
{
|
|
|
|
uint8 *tmp;
|
|
|
|
|
|
|
|
// Probably a little slow.
|
|
|
|
tmp=(uint8 *)realloc(dest->data,offset+size);
|
|
|
|
if(!tmp)
|
|
|
|
{
|
|
|
|
FCEU_printf(" Oops. IPS patch %d(type normal) goes beyond end of file. Could not allocate memory.\n",count);
|
|
|
|
fclose(ips);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dest->data=tmp;
|
|
|
|
memset(dest->data+dest->size,0,offset+size-dest->size);
|
|
|
|
}
|
|
|
|
fread(dest->data+offset,1,size,ips);
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
fclose(ips);
|
|
|
|
FCEU_printf(" Hard IPS end!\n");
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static MEMWRAP *MakeMemWrap(void *tz, int type)
|
|
|
|
{
|
2008-06-22 02:38:00 +00:00
|
|
|
MEMWRAP *tmp;
|
|
|
|
|
|
|
|
if(!(tmp=(MEMWRAP *)FCEU_malloc(sizeof(MEMWRAP))))
|
|
|
|
goto doret;
|
|
|
|
tmp->location=0;
|
|
|
|
|
|
|
|
if(type==0)
|
|
|
|
{
|
|
|
|
fseek((FILE *)tz,0,SEEK_END);
|
|
|
|
tmp->size=ftell((FILE *)tz);
|
|
|
|
fseek((FILE *)tz,0,SEEK_SET);
|
|
|
|
if(!(tmp->data=(uint8*)FCEU_malloc(tmp->size)))
|
|
|
|
{
|
|
|
|
free(tmp);
|
|
|
|
tmp=0;
|
|
|
|
goto doret;
|
|
|
|
}
|
|
|
|
fread(tmp->data,1,tmp->size,(FILE *)tz);
|
|
|
|
}
|
|
|
|
else if(type==1)
|
|
|
|
{
|
|
|
|
/* Bleck. The gzip file format has the size of the uncompressed data,
|
|
|
|
but I can't get to the info with the zlib interface(?). */
|
|
|
|
for(tmp->size=0; gzgetc(tz) != EOF; tmp->size++);
|
|
|
|
gzseek(tz,0,SEEK_SET);
|
|
|
|
if(!(tmp->data=(uint8 *)FCEU_malloc(tmp->size)))
|
|
|
|
{
|
|
|
|
free(tmp);
|
|
|
|
tmp=0;
|
|
|
|
goto doret;
|
|
|
|
}
|
|
|
|
gzread(tz,tmp->data,tmp->size);
|
|
|
|
}
|
|
|
|
else if(type==2)
|
|
|
|
{
|
|
|
|
unz_file_info ufo;
|
|
|
|
unzGetCurrentFileInfo(tz,&ufo,0,0,0,0,0,0);
|
|
|
|
|
|
|
|
tmp->size=ufo.uncompressed_size;
|
|
|
|
if(!(tmp->data=(uint8 *)FCEU_malloc(ufo.uncompressed_size)))
|
|
|
|
{
|
|
|
|
free(tmp);
|
|
|
|
tmp=0;
|
|
|
|
goto doret;
|
|
|
|
}
|
|
|
|
unzReadCurrentFile(tz,tmp->data,ufo.uncompressed_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
doret:
|
|
|
|
if(type==0)
|
|
|
|
{
|
|
|
|
fclose((FILE *)tz);
|
|
|
|
}
|
|
|
|
else if(type==1)
|
|
|
|
{
|
|
|
|
gzclose(tz);
|
|
|
|
}
|
|
|
|
else if(type==2)
|
|
|
|
{
|
|
|
|
unzCloseCurrentFile(tz);
|
|
|
|
unzClose(tz);
|
|
|
|
}
|
|
|
|
return tmp;
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef __GNUC__
|
2008-06-22 02:38:00 +00:00
|
|
|
#define strcasecmp strcmp
|
2006-07-29 05:46:15 +00:00
|
|
|
#endif
|
|
|
|
|
2008-07-09 05:47:13 +00:00
|
|
|
void FCEU_SplitArchiveFilename(std::string src, std::string& archive, std::string& file, std::string& fileToOpen)
|
|
|
|
{
|
|
|
|
size_t pipe = src.find_first_of('|');
|
|
|
|
if(pipe == std::string::npos)
|
|
|
|
{
|
|
|
|
archive = "";
|
|
|
|
file = src;
|
|
|
|
fileToOpen = src;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
archive = src.substr(0,pipe);
|
|
|
|
file = src.substr(pipe+1);
|
|
|
|
fileToOpen = archive;
|
|
|
|
}
|
|
|
|
}
|
2006-07-29 05:46:15 +00:00
|
|
|
|
|
|
|
FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext)
|
|
|
|
{
|
2008-06-22 02:38:00 +00:00
|
|
|
FILE *ipsfile=0;
|
2008-07-09 05:47:13 +00:00
|
|
|
FCEUFILE *fceufp=0;
|
2008-06-22 02:38:00 +00:00
|
|
|
|
2008-07-09 05:47:13 +00:00
|
|
|
bool read = (std::string)mode == "rb";
|
|
|
|
bool write = (std::string)mode == "wb";
|
|
|
|
if(read&&write || (!read&&!write))
|
2008-06-22 02:38:00 +00:00
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
FCEU_PrintError("invalid file open mode specified (only wb and rb are supported)");
|
|
|
|
return 0;
|
2008-06-22 02:38:00 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 05:47:13 +00:00
|
|
|
std::string archive,fname,fileToOpen;
|
|
|
|
FCEU_SplitArchiveFilename(path,archive,fname,fileToOpen);
|
|
|
|
|
2008-06-22 02:38:00 +00:00
|
|
|
|
2008-07-09 05:47:13 +00:00
|
|
|
//try to setup the ips file
|
|
|
|
if(ipsfn && read)
|
|
|
|
ipsfile=FCEUD_UTF8fopen(ipsfn,"rb");
|
2008-06-22 02:38:00 +00:00
|
|
|
|
2008-07-09 05:47:13 +00:00
|
|
|
if(read)
|
|
|
|
{
|
|
|
|
ArchiveScanRecord asr = FCEUD_ScanArchive(fileToOpen);
|
|
|
|
if(asr.numFiles == 0)
|
2008-06-22 02:38:00 +00:00
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
//if the archive contained no files, try to open it the old fashioned way
|
|
|
|
std::fstream* fp = FCEUD_UTF8_fstream(fileToOpen,mode);
|
|
|
|
if(!fp)
|
2008-06-22 02:38:00 +00:00
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
return 0;
|
2008-06-22 02:38:00 +00:00
|
|
|
}
|
2008-07-09 05:47:13 +00:00
|
|
|
fceufp = new FCEUFILE();
|
|
|
|
fceufp->filename = fileToOpen;
|
|
|
|
fceufp->archiveIndex = -1;
|
|
|
|
fceufp->stream = (std::iostream*)fp;
|
|
|
|
FCEU_fseek(fceufp,0,SEEK_END);
|
|
|
|
fceufp->size = FCEU_ftell(fceufp);
|
|
|
|
FCEU_fseek(fceufp,0,SEEK_SET);
|
|
|
|
return fceufp;
|
2008-06-22 02:38:00 +00:00
|
|
|
}
|
2008-07-09 05:47:13 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
//open an archive file
|
|
|
|
if(archive == "")
|
|
|
|
fceufp = FCEUD_OpenArchive(asr, fileToOpen, 0);
|
|
|
|
else
|
|
|
|
fceufp = FCEUD_OpenArchive(asr, archive, &fname);
|
|
|
|
return fceufp;
|
2008-06-22 02:38:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FCEU_fclose(FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
delete fp;
|
2008-06-22 02:38:00 +00:00
|
|
|
return 1;
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64 FCEU_fread(void *ptr, size_t size, size_t nmemb, FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
fp->stream->read((char*)ptr,size*nmemb);
|
|
|
|
uint32 read = fp->stream->gcount();
|
|
|
|
return read/size;
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64 FCEU_fwrite(void *ptr, size_t size, size_t nmemb, FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
fp->stream->write((char*)ptr,size*nmemb);
|
|
|
|
//todo - how do we tell how many bytes we wrote?
|
|
|
|
return nmemb;
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FCEU_fseek(FCEUFILE *fp, long offset, int whence)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
//if(fp->type==1)
|
|
|
|
//{
|
|
|
|
// return( (gzseek(fp->fp,offset,whence)>0)?0:-1);
|
|
|
|
//}
|
|
|
|
//else if(fp->type>=2)
|
|
|
|
//{
|
|
|
|
// MEMWRAP *wz;
|
|
|
|
// wz=(MEMWRAP*)fp->fp;
|
|
|
|
|
|
|
|
// switch(whence)
|
|
|
|
// {
|
|
|
|
// case SEEK_SET:if(offset>=(long)wz->size) //mbg merge 7/17/06 - added cast to long
|
|
|
|
// return(-1);
|
|
|
|
// wz->location=offset;break;
|
|
|
|
// case SEEK_CUR:if(offset+wz->location>wz->size)
|
|
|
|
// return (-1);
|
|
|
|
// wz->location+=offset;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// return 0;
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
// return fseek((FILE *)fp->fp,offset,whence);
|
|
|
|
|
|
|
|
fp->stream->seekg(offset,(std::ios_base::seekdir)whence);
|
|
|
|
fp->stream->seekp(offset,(std::ios_base::seekdir)whence);
|
|
|
|
|
|
|
|
return FCEU_ftell(fp);
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64 FCEU_ftell(FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
if(fp->mode == FCEUFILE::READ)
|
|
|
|
return fp->stream->tellg();
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-07-09 05:47:13 +00:00
|
|
|
return fp->stream->tellp();
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FCEU_read16le(uint16 *val, FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
return read16le(val,fp->stream);
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FCEU_read32le(uint32 *Bufo, FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
return read32le(Bufo, fp->stream);
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FCEU_fgetc(FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
return fp->stream->get();
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64 FCEU_fgetsize(FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
return fp->size;
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FCEU_fisarchive(FCEUFILE *fp)
|
|
|
|
{
|
2008-07-09 05:47:13 +00:00
|
|
|
if(fp->archiveIndex==0) return 0;
|
|
|
|
else return 1;
|
2006-07-29 05:46:15 +00:00
|
|
|
}
|
2006-08-01 05:50:19 +00:00
|
|
|
|
2008-06-25 03:36:38 +00:00
|
|
|
std::string GetMfn() //Retrieves the movie filename from curMovieFilename (for adding to savestate and auto-save files)
|
|
|
|
{
|
|
|
|
std::string movieFilenamePart;
|
|
|
|
extern char curMovieFilename[512];
|
|
|
|
if(*curMovieFilename)
|
|
|
|
{
|
|
|
|
char drv[PATH_MAX], dir[PATH_MAX], name[PATH_MAX], ext[PATH_MAX];
|
|
|
|
splitpath(curMovieFilename,drv,dir,name,ext);
|
|
|
|
movieFilenamePart = std::string(".") + name;
|
|
|
|
}
|
|
|
|
return movieFilenamePart;
|
|
|
|
}
|
2006-08-01 05:50:19 +00:00
|
|
|
|
2008-06-22 02:38:00 +00:00
|
|
|
static std::string BaseDirectory;
|
2006-08-01 05:50:19 +00:00
|
|
|
char FileBase[2048];
|
2008-06-22 02:38:00 +00:00
|
|
|
static char FileExt[2048]; //Includes the . character, as in ".nes"
|
2006-08-01 05:50:19 +00:00
|
|
|
|
|
|
|
static char FileBaseDirectory[2048];
|
|
|
|
|
2008-06-22 02:38:00 +00:00
|
|
|
/// Updates the base directory
|
|
|
|
void FCEUI_SetBaseDirectory(std::string const & dir)
|
2006-08-01 05:50:19 +00:00
|
|
|
{
|
2008-06-22 02:38:00 +00:00
|
|
|
BaseDirectory = dir;
|
2006-08-01 05:50:19 +00:00
|
|
|
}
|
|
|
|
|
2008-05-24 16:25:15 +00:00
|
|
|
static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0,0,0,0,0,0,0,0}; // odirs, odors. ^_^
|
2006-08-01 05:50:19 +00:00
|
|
|
|
|
|
|
void FCEUI_SetDirOverride(int which, char *n)
|
|
|
|
{
|
2007-02-05 20:41:23 +00:00
|
|
|
// FCEU_PrintError("odirs[%d]=%s->%s", which, odirs[which], n);
|
|
|
|
if (which < FCEUIOD__COUNT)
|
|
|
|
{
|
|
|
|
odirs[which] = n;
|
|
|
|
}
|
|
|
|
|
2008-07-09 05:47:13 +00:00
|
|
|
if(GameInfo) //Rebuild cache of present states/movies.
|
2007-02-05 20:41:23 +00:00
|
|
|
{
|
2008-05-24 16:25:15 +00:00
|
|
|
if(which==FCEUIOD_STATES)
|
2007-02-05 20:41:23 +00:00
|
|
|
{
|
|
|
|
FCEUSS_CheckStates();
|
|
|
|
}
|
|
|
|
}
|
2006-08-01 05:50:19 +00:00
|
|
|
}
|
|
|
|
|
2008-05-24 16:25:15 +00:00
|
|
|
#ifndef HAVE_ASPRINTF
|
|
|
|
static int asprintf(char **strp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(ap,fmt);
|
|
|
|
if(!(*strp=(char*)malloc(2048))) //mbg merge 7/17/06 cast to char*
|
|
|
|
return(0);
|
|
|
|
ret=vsnprintf(*strp,2048,fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
#endif
|
2006-08-01 05:50:19 +00:00
|
|
|
|
2008-06-17 06:55:07 +00:00
|
|
|
std::string FCEU_GetPath(int type)
|
2006-08-01 05:50:19 +00:00
|
|
|
{
|
2008-06-17 06:55:07 +00:00
|
|
|
char ret[FILENAME_MAX];
|
2008-05-24 16:25:15 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FCEUMKF_STATE:
|
|
|
|
if(odirs[FCEUIOD_STATES])
|
2008-06-17 06:55:07 +00:00
|
|
|
return (odirs[FCEUIOD_STATES]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "fcs";
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_MOVIE:
|
|
|
|
if(odirs[FCEUIOD_MOVIES])
|
2008-06-17 06:55:07 +00:00
|
|
|
return (odirs[FCEUIOD_MOVIES]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "movies";
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_MEMW:
|
|
|
|
if(odirs[FCEUIOD_MEMW])
|
2008-06-17 06:55:07 +00:00
|
|
|
return (odirs[FCEUIOD_MEMW]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "tools";
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_BBOT:
|
|
|
|
if(odirs[FCEUIOD_BBOT])
|
2008-06-17 06:55:07 +00:00
|
|
|
return (odirs[FCEUIOD_BBOT]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "tools";
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_ROMS:
|
|
|
|
if(odirs[FCEUIOD_ROMS])
|
2008-06-17 06:55:07 +00:00
|
|
|
return (odirs[FCEUIOD_ROMS]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory;
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_INPUT:
|
|
|
|
if(odirs[FCEUIOD_INPUT])
|
2008-06-17 06:55:07 +00:00
|
|
|
return (odirs[FCEUIOD_INPUT]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "tools";
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_LUA:
|
|
|
|
if(odirs[FCEUIOD_LUA])
|
2008-06-17 06:55:07 +00:00
|
|
|
return (odirs[FCEUIOD_LUA]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "tools";
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-17 06:55:07 +00:00
|
|
|
|
|
|
|
return ret;
|
2006-08-01 05:50:19 +00:00
|
|
|
}
|
|
|
|
|
2008-06-17 06:55:07 +00:00
|
|
|
std::string FCEU_MakePath(int type, const char* filebase)
|
2006-08-01 05:50:19 +00:00
|
|
|
{
|
2008-06-17 06:55:07 +00:00
|
|
|
char ret[FILENAME_MAX];
|
2006-08-01 05:50:19 +00:00
|
|
|
|
2008-05-24 16:25:15 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FCEUMKF_MOVIE:
|
|
|
|
if(odirs[FCEUIOD_MOVIES])
|
2008-06-22 02:38:00 +00:00
|
|
|
return (string)odirs[FCEUIOD_MOVIES] + PSS + filebase;
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "movies" + PSS + filebase;
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_STATE:
|
|
|
|
if(odirs[FCEUIOD_STATES])
|
2008-06-22 02:38:00 +00:00
|
|
|
return (string)odirs[FCEUIOD_STATES] + PSS + filebase;
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
return BaseDirectory + PSS + "fcs" + PSS + filebase;
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-17 06:55:07 +00:00
|
|
|
return ret;
|
2006-08-01 05:50:19 +00:00
|
|
|
}
|
|
|
|
|
2008-06-17 06:55:07 +00:00
|
|
|
std::string FCEU_MakeFName(int type, int id1, char *cd1)
|
2006-08-01 05:50:19 +00:00
|
|
|
{
|
2008-06-17 06:55:07 +00:00
|
|
|
char ret[FILENAME_MAX];
|
2008-05-24 16:25:15 +00:00
|
|
|
struct stat tmpstat;
|
2008-06-25 04:01:06 +00:00
|
|
|
std::string mfnString;
|
|
|
|
const char* mfn;
|
2006-08-01 05:50:19 +00:00
|
|
|
|
2008-05-24 16:25:15 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FCEUMKF_MOVIE:
|
2008-05-26 07:34:40 +00:00
|
|
|
if(odirs[FCEUIOD_MOVIES])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s.fm2",odirs[FCEUIOD_MOVIES],FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"movies"PSS"%s.fm2",BaseDirectory.c_str(),FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_STATE:
|
2006-08-01 05:50:19 +00:00
|
|
|
{
|
2008-06-25 04:01:06 +00:00
|
|
|
mfnString = GetMfn();
|
|
|
|
mfn = mfnString.c_str();
|
2008-05-24 16:25:15 +00:00
|
|
|
if(odirs[FCEUIOD_STATES])
|
|
|
|
{
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s%s.fc%d",odirs[FCEUIOD_STATES],FileBase,mfn,id1);
|
2008-05-24 16:25:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"fcs"PSS"%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1);
|
2008-05-26 07:34:40 +00:00
|
|
|
}
|
|
|
|
if(stat(ret,&tmpstat)==-1)
|
|
|
|
{
|
|
|
|
if(odirs[FCEUIOD_STATES])
|
|
|
|
{
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s%s.fc%d",odirs[FCEUIOD_STATES],FileBase,mfn,id1);
|
2008-05-26 07:34:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"fcs"PSS"%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1);
|
2008-05-26 07:34:40 +00:00
|
|
|
}
|
2008-05-24 16:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FCEUMKF_SNAP:
|
|
|
|
if(FSettings.SnapName)
|
|
|
|
{
|
|
|
|
if(odirs[FCEUIOD_SNAPS])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory.c_str(),FileBase,id1,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(odirs[FCEUIOD_SNAPS])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%d.%s",odirs[FCEUIOD_SNAPS],id1,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"snaps"PSS"%d.%s",BaseDirectory.c_str(),id1,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FCEUMKF_FDS:
|
|
|
|
if(odirs[FCEUIOD_NV])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s.fds",odirs[FCEUIOD_NV],FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"sav"PSS"%s.fds",BaseDirectory.c_str(),FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
case FCEUMKF_SAV:
|
|
|
|
if(odirs[FCEUIOD_NV])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory.c_str(),FileBase,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
if(stat(ret,&tmpstat)==-1)
|
|
|
|
{
|
|
|
|
if(odirs[FCEUIOD_NV])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory.c_str(),FileBase,cd1);
|
2008-05-24 16:25:15 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-06-25 00:43:02 +00:00
|
|
|
case FCEUMKF_AUTOSTATE:
|
2008-06-25 03:36:38 +00:00
|
|
|
extern char curMovieFilename[512];
|
2008-06-25 04:16:43 +00:00
|
|
|
mfnString = GetMfn();
|
|
|
|
mfn = mfnString.c_str();
|
2008-05-24 16:25:15 +00:00
|
|
|
if(odirs[FCEUIOD_STATES])
|
|
|
|
{
|
2008-06-25 03:36:38 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s%s-autosave%d.fcs",odirs[FCEUIOD_STATES],FileBase,mfn,id1);
|
2006-08-01 05:50:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-25 03:36:38 +00:00
|
|
|
sprintf(ret,"%s"PSS"fcs"PSS"%s%s-autosave%d.fcs",BaseDirectory.c_str(),FileBase,mfn,id1);
|
2006-08-01 05:50:19 +00:00
|
|
|
}
|
2008-05-24 16:25:15 +00:00
|
|
|
if(stat(ret,&tmpstat)==-1)
|
|
|
|
{
|
|
|
|
if(odirs[FCEUIOD_STATES])
|
|
|
|
{
|
2008-06-25 03:36:38 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s%s-autosave%d.fcs",odirs[FCEUIOD_STATES],FileBase,mfn,id1);
|
2008-05-24 16:25:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-25 03:36:38 +00:00
|
|
|
sprintf(ret,"%s"PSS"fcs"PSS"%s%s-autosave%d.fcs",BaseDirectory.c_str(),FileBase,mfn,id1);
|
2008-05-24 16:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FCEUMKF_CHEAT:
|
|
|
|
if(odirs[FCEUIOD_CHEATS])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"cheats"PSS"%s.cht",BaseDirectory.c_str(),FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
2008-06-17 06:55:07 +00:00
|
|
|
case FCEUMKF_IPS:sprintf(ret,"%s"PSS"%s%s.ips",FileBaseDirectory,FileBase,FileExt);break;
|
2008-06-22 02:38:00 +00:00
|
|
|
case FCEUMKF_GGROM:sprintf(ret,"%s"PSS"gg.rom",BaseDirectory.c_str());break;
|
2008-05-24 16:25:15 +00:00
|
|
|
case FCEUMKF_FDSROM:
|
|
|
|
if(odirs[FCEUIOD_FDSROM])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"disksys.rom",odirs[FCEUIOD_FDSROM]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"disksys.rom",BaseDirectory.c_str());
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
2008-06-22 02:38:00 +00:00
|
|
|
case FCEUMKF_PALETTE:sprintf(ret,"%s"PSS"%s.pal",BaseDirectory.c_str(),FileBase);break;
|
2008-05-24 16:25:15 +00:00
|
|
|
case FCEUMKF_MOVIEGLOB:
|
2008-05-26 07:34:40 +00:00
|
|
|
//these globs use ??? because we can load multiple formats
|
2008-05-24 16:25:15 +00:00
|
|
|
if(odirs[FCEUIOD_MOVIES])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"*.???",odirs[FCEUIOD_MOVIES]);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"movies"PSS"*.???",BaseDirectory.c_str());
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
2008-06-22 02:38:00 +00:00
|
|
|
case FCEUMKF_MOVIEGLOB2:sprintf(ret,"%s"PSS"*.???",BaseDirectory.c_str());break;
|
2008-05-24 16:25:15 +00:00
|
|
|
case FCEUMKF_STATEGLOB:
|
|
|
|
if(odirs[FCEUIOD_STATES])
|
2008-06-17 06:55:07 +00:00
|
|
|
sprintf(ret,"%s"PSS"%s*.fc?",odirs[FCEUIOD_STATES],FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
else
|
2008-06-22 02:38:00 +00:00
|
|
|
sprintf(ret,"%s"PSS"fcs"PSS"%s*.fc?",BaseDirectory.c_str(),FileBase);
|
2008-05-24 16:25:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-17 06:55:07 +00:00
|
|
|
|
|
|
|
return ret;
|
2006-08-01 05:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetFileBase(const char *f)
|
|
|
|
{
|
2008-05-24 16:25:15 +00:00
|
|
|
const char *tp1,*tp3;
|
|
|
|
|
|
|
|
#if PSS_STYLE==4
|
|
|
|
tp1=((char *)strrchr(f,':'));
|
|
|
|
#elif PSS_STYLE==1
|
|
|
|
tp1=((char *)strrchr(f,'/'));
|
|
|
|
#else
|
|
|
|
tp1=((char *)strrchr(f,'\\'));
|
|
|
|
#if PSS_STYLE!=3
|
|
|
|
tp3=((char *)strrchr(f,'/'));
|
|
|
|
if(tp1<tp3) tp1=tp3;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if(!tp1)
|
|
|
|
{
|
|
|
|
tp1=f;
|
|
|
|
strcpy(FileBaseDirectory,".");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(FileBaseDirectory,f,tp1-f);
|
|
|
|
FileBaseDirectory[tp1-f]=0;
|
|
|
|
tp1++;
|
|
|
|
}
|
2006-08-01 05:50:19 +00:00
|
|
|
|
2008-05-24 16:25:15 +00:00
|
|
|
if(((tp3=strrchr(f,'.'))!=NULL) && (tp3>tp1))
|
|
|
|
{
|
|
|
|
memcpy(FileBase,tp1,tp3-tp1);
|
|
|
|
FileBase[tp3-tp1]=0;
|
|
|
|
strcpy(FileExt,tp3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(FileBase,tp1);
|
|
|
|
FileExt[0]=0;
|
|
|
|
}
|
2006-08-20 19:40:15 +00:00
|
|
|
}
|