fix for file loading errors

This commit is contained in:
dborth 2009-12-14 06:56:29 +00:00
parent 0e901eca08
commit a2ca3ac04a
8 changed files with 21 additions and 34 deletions

View File

@ -99,7 +99,7 @@ FCEUGI::~FCEUGI()
if(archiveFilename) delete archiveFilename; if(archiveFilename) delete archiveFilename;
} }
static void CloseGame(void) static void FCEU_CloseGame(void)
{ {
if(GameInfo) if(GameInfo)
{ {
@ -360,7 +360,7 @@ static DECLFR(ARAMH)
void ResetGameLoaded(void) void ResetGameLoaded(void)
{ {
if(GameInfo) CloseGame(); if(GameInfo) FCEU_CloseGame();
EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it
GameStateRestore=0; GameStateRestore=0;
PPU_hook=0; PPU_hook=0;
@ -421,7 +421,7 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode)
for (AutosaveIndex=0; AutosaveIndex<AutosaveQty; ++AutosaveIndex) for (AutosaveIndex=0; AutosaveIndex<AutosaveQty; ++AutosaveIndex)
AutosaveStatus[AutosaveIndex] = 0; AutosaveStatus[AutosaveIndex] = 0;
CloseGame(); FCEU_CloseGame();
GameInfo = new FCEUGI(); GameInfo = new FCEUGI();
memset(GameInfo, 0, sizeof(FCEUGI)); memset(GameInfo, 0, sizeof(FCEUGI));
@ -714,7 +714,7 @@ void FCEUI_CloseGame(void)
if(!FCEU_IsValidUI(FCEUI_CLOSEGAME)) if(!FCEU_IsValidUI(FCEUI_CLOSEGAME))
return; return;
CloseGame(); FCEU_CloseGame();
} }
void ResetNES(void) void ResetNES(void)

View File

@ -776,9 +776,9 @@ int FDSLoad(const char *name, FCEUFILE *fp)
FILE *zp; FILE *zp;
int x; int x;
char *fn; char *fn;
#ifndef GEKKO
FCEU_fseek(fp,0,SEEK_SET); FCEU_fseek(fp,0,SEEK_SET);
#endif
if(!SubLoad(fp)) if(!SubLoad(fp))
return(0); return(0);

View File

@ -424,8 +424,10 @@ int FCEU_fseek(FCEUFILE *fp, long offset, int whence)
//else //else
// return fseek((FILE *)fp->fp,offset,whence); // return fseek((FILE *)fp->fp,offset,whence);
fp->stream->seekg(offset,(std::ios_base::seekdir)whence); if(fp->mode == FCEUFILE::READ || fp->mode == FCEUFILE::READWRITE)
fp->stream->seekp(offset,(std::ios_base::seekdir)whence); fp->stream->seekg(offset,(std::ios_base::seekdir)whence);
if(fp->mode == FCEUFILE::WRITE || fp->mode == FCEUFILE::READWRITE)
fp->stream->seekp(offset,(std::ios_base::seekdir)whence);
return FCEU_ftell(fp); return FCEU_ftell(fp);
} }

View File

@ -167,9 +167,8 @@ static INLINE void BANKSET(uint32 A, uint32 bank)
int NSFLoad(const char *name, FCEUFILE *fp) int NSFLoad(const char *name, FCEUFILE *fp)
{ {
int x; int x;
#ifndef GEKKO
FCEU_fseek(fp,0,SEEK_SET); FCEU_fseek(fp,0,SEEK_SET);
#endif
FCEU_fread(&NSFHeader,1,0x80,fp); FCEU_fread(&NSFHeader,1,0x80,fp);
if(memcmp(NSFHeader.ID,"NESM\x1a",5)) if(memcmp(NSFHeader.ID,"NESM\x1a",5))
return 0; return 0;

View File

@ -117,6 +117,10 @@ typedef uint32_t uint32;
#define PSS ":" #define PSS ":"
#define PS ':' #define PS ':'
#else
#error PSS_STYLE undefined or invalid; see "types.h" for possible values, and add as compile-time option.
#endif #endif

View File

@ -556,9 +556,7 @@ static void UNIFGI(GI h)
int UNIFLoad(const char *name, FCEUFILE *fp) int UNIFLoad(const char *name, FCEUFILE *fp)
{ {
#ifndef GEKKO
FCEU_fseek(fp,0,SEEK_SET); FCEU_fseek(fp,0,SEEK_SET);
#endif
FCEU_fread(&unhead,1,4,fp); FCEU_fread(&unhead,1,4,fp);
if(memcmp(&unhead,"UNIF",4)) if(memcmp(&unhead,"UNIF",4))
return 0; return 0;

View File

@ -184,11 +184,7 @@ private:
if(!myBuf && !usevec) if(!myBuf && !usevec)
throw new std::runtime_error("memory_streambuf is not expandable"); throw new std::runtime_error("memory_streambuf is not expandable");
size_t newcapacity; size_t newcapacity = std::max(upto,capacity);
if(upto == 0)
newcapacity = capacity + capacity/2 + 2;
else
newcapacity = std::max(upto,capacity);
if(newcapacity == capacity) return; if(newcapacity == capacity) return;

View File

@ -17,6 +17,8 @@
#include <string.h> #include <string.h>
#include <malloc.h> #include <malloc.h>
#include "file.h"
#include "fceugx.h" #include "fceugx.h"
#include "gcaudio.h" #include "gcaudio.h"
#include "fceusupport.h" #include "fceusupport.h"
@ -61,28 +63,19 @@ int GCMemROM(int size)
FCEUFILE * fceufp = new FCEUFILE(); FCEUFILE * fceufp = new FCEUFILE();
fceufp->size = size; fceufp->size = size;
fceufp->filename = romFilename; fceufp->filename = romFilename;
memorystream * fceumem; fceufp->mode = FCEUFILE::READ; // read only
memorystream * fceumem = new memorystream((char *) nesrom, size);
romLoaded = false;
// for some reason FCEU_fseek(fp,0,SEEK_SET); fails, so we will do this
fceumem = new memorystream((char *) nesrom, size);
fceufp->stream = fceumem; fceufp->stream = fceumem;
romLoaded = iNESLoad(romFilename, fceufp, 1); romLoaded = iNESLoad(romFilename, fceufp, 1);
if(!romLoaded) if(!romLoaded)
{ {
delete fceumem;
fceumem = new memorystream((char *) nesrom, size);
fceufp->stream = fceumem;
romLoaded = UNIFLoad(romFilename, fceufp); romLoaded = UNIFLoad(romFilename, fceufp);
} }
if(!romLoaded) if(!romLoaded)
{ {
delete fceumem;
fceumem = new memorystream((char *) nesrom, size);
fceufp->stream = fceumem;
romLoaded = NSFLoad(romFilename, fceufp); romLoaded = NSFLoad(romFilename, fceufp);
} }
@ -118,11 +111,6 @@ int GCMemROM(int size)
} }
if (FDSBIOS[1] != 0) if (FDSBIOS[1] != 0)
{ {
// load game
delete fceumem;
fceumem = new memorystream((char *) nesrom, size);
fceufp->stream = fceumem;
romLoaded = FDSLoad(romFilename, fceufp); romLoaded = FDSLoad(romFilename, fceufp);
} }
} }