sync to FCEUX svn, other minor fixes

This commit is contained in:
dborth 2010-10-06 03:57:22 +00:00
parent 1e98f458ad
commit ec93d4f2b3
18 changed files with 149 additions and 108 deletions

View File

@ -30,12 +30,8 @@
#include "fceu.h"
#include "file.h"
#include "cart.h"
#ifdef GEKKO
#include <string.h>
#else
#include "memory.h"
#endif
#include "driver.h"
#include "utils/memory.h"
using namespace std;
@ -166,7 +162,7 @@ static void CheatMemErr(void)
int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type)
{
struct CHEATF *temp;
if(!(temp=(struct CHEATF *)malloc(sizeof(struct CHEATF))))
if(!(temp=(struct CHEATF *)FCEU_dmalloc(sizeof(struct CHEATF))))
{
CheatMemErr();
return(0);
@ -251,7 +247,8 @@ void FCEU_LoadGameCheats(FILE *override)
char *neo=&tbuf[4+2+2+1+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x%*[:]%02x",&addr,&val,&compare)!=3)
continue;
namebuf=(char *)malloc(strlen(neo)+1);
if (!(namebuf=(char *)FCEU_dmalloc(strlen(neo)+1)))
return;
strcpy(namebuf,neo);
}
else
@ -259,7 +256,8 @@ void FCEU_LoadGameCheats(FILE *override)
char *neo=&tbuf[4+2+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x",&addr,&val)!=2)
continue;
namebuf=(char *)malloc(strlen(neo)+1);
if (!(namebuf=(char *)FCEU_dmalloc(strlen(neo)+1)))
return;
strcpy(namebuf,neo);
}
@ -367,7 +365,7 @@ int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int ty
{
char *t;
if(!(t=(char *)malloc(strlen(name)+1)))
if(!(t=(char *)FCEU_dmalloc(strlen(name)+1)))
{
CheatMemErr();
return(0);
@ -663,7 +661,7 @@ static int InitCheatComp(void)
{
uint32 x;
CheatComp=(uint16*)malloc(65536*sizeof(uint16));
CheatComp=(uint16*)FCEU_dmalloc(65536*sizeof(uint16));
if(!CheatComp)
{
CheatMemErr();

View File

@ -46,6 +46,8 @@
#include <ctype.h>
#include "conddebug.h"
#include "types.h"
#include "utils/memory.h"
// Next non-whitespace character in string
char next;
@ -93,7 +95,9 @@ Condition* InfixOperator(const char** str, Condition(*nextPart(const char**)), i
return 0;
}
mid = (Condition*)malloc(sizeof(Condition));
mid = (Condition*)FCEU_dmalloc(sizeof(Condition));
if (!mid)
return NULL;
memset(mid, 0, sizeof(Condition));
mid->lhs = t;
@ -317,10 +321,14 @@ Condition* Primitive(const char** str, Condition* c)
/* Handle * and / operators */
Condition* Term(const char** str)
{
Condition* t = (Condition*)malloc(sizeof(Condition));
Condition* t1;
Condition* t;
Condition* t1;
Condition* mid;
t = (Condition*)FCEU_dmalloc(sizeof(Condition));
if (!t)
return NULL;
memset(t, 0, sizeof(Condition));
if (!Primitive(str, t))
@ -335,7 +343,9 @@ Condition* Term(const char** str)
scan(str);
t1 = (Condition*)malloc(sizeof(Condition));
if (!(t1 = (Condition*)FCEU_dmalloc(sizeof(Condition))))
return NULL;
memset(t1, 0, sizeof(Condition));
if (!Primitive(str, t1))
@ -345,7 +355,9 @@ Condition* Term(const char** str)
return 0;
}
mid = (Condition*)malloc(sizeof(Condition));
if (!(mid = (Condition*)FCEU_dmalloc(sizeof(Condition))))
return NULL;
memset(mid, 0, sizeof(Condition));
mid->lhs = t;

View File

@ -9,6 +9,7 @@
#include "version.h"
#include "fceu.h"
#include "driver.h"
#include "utils/memory.h"
static char *aboutString = 0;
@ -43,7 +44,9 @@ FCEU TAS+ - Luke Gustafson\n\
const char *compilerString = FCEUD_GetCompilerString();
//allocate the string and concatenate the template with the compiler string
aboutString = (char*)malloc(strlen(aboutTemplate) + strlen(compilerString) + 1);
sprintf(aboutString,"%s%s",aboutTemplate,compilerString);
if (!(aboutString = (char*)FCEU_dmalloc(strlen(aboutTemplate) + strlen(compilerString) + 1)))
return NULL;
sprintf(aboutString,"%s%s",aboutTemplate,compilerString);
return aboutString;
}

View File

@ -135,6 +135,8 @@ int checkCondition(const char* condition, int num)
{
watchpoint[num].cond = c;
watchpoint[num].condText = (char*)malloc(strlen(condition) + 1);
if (!watchpoint[num].condText)
return 0;
strcpy(watchpoint[num].condText, condition);
}
else

View File

@ -115,7 +115,7 @@ public:
vec->resize(preallocate);
len = preallocate;
}
EMUFILE_MEMORY() : vec(new std::vector<u8>()), ownvec(true), pos(0), len(0) { vec->reserve(1024); }
EMUFILE_MEMORY() : vec(new std::vector<u8>()), ownvec(true), pos(0), len(0) { vec->reserve(8192); }
EMUFILE_MEMORY(void* buf, s32 size) : vec(new std::vector<u8>()), ownvec(true), pos(0), len(size) {
vec->resize(size);
if(size != 0)
@ -139,10 +139,15 @@ public:
//we dont generate straight into the buffer because it will null terminate (one more byte than we want)
int amt = vsnprintf(0,0,format,argptr);
char* tempbuf = new char[amt+1];
vsprintf(tempbuf,format,argptr);
fwrite(tempbuf,amt);
delete[] tempbuf;
va_end(argptr);
va_start(argptr, format);
vsprintf(tempbuf,format,argptr);
fwrite(tempbuf,amt);
delete[] tempbuf;
va_end(argptr);
return amt;
};

View File

@ -446,7 +446,7 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode)
ResetGameLoaded();
if (!AutosaveStatus)
AutosaveStatus = (int*)malloc(sizeof(int)*AutosaveQty);
AutosaveStatus = (int*)FCEU_dmalloc(sizeof(int)*AutosaveQty);
for (AutosaveIndex=0; AutosaveIndex<AutosaveQty; ++AutosaveIndex)
AutosaveStatus[AutosaveIndex] = 0;

View File

@ -65,7 +65,7 @@ void ApplyIPS(FILE *ips, FCEUFILE* fp)
if(!ips) return;
char* buf = (char*)malloc(fp->size);
char* buf = (char*)FCEU_dmalloc(fp->size);
memcpy(buf,fp->EnsureMemorystream()->buf(),fp->size);
@ -284,7 +284,7 @@ FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext
{
//if the archive contained no files, try to open it the old fashioned way
EMUFILE_FILE* fp = FCEUD_UTF8_fstream(fileToOpen,mode);
if(!fp)
if(!fp || (fp->get_fp() == NULL))
{
return 0;
}
@ -471,7 +471,7 @@ void FCEUI_SetDirOverride(int which, char *n)
int ret;
va_start(ap,fmt);
if(!(*strp=(char*)malloc(2048))) //mbg merge 7/17/06 cast to char*
if(!(*strp=(char*)FCEU_dmalloc(2048))) //mbg merge 7/17/06 cast to char*
return(0);
ret=vsnprintf(*strp,2048,fmt,ap);
va_end(ap);

View File

@ -1508,7 +1508,7 @@ static int NewiNES_Init(int num)
{
CloseHandle(mapVROM);
mapVROM = NULL;
if((VROM = (uint8 *)malloc(CHRRAMSize)) == NULL) return 0;
if((VROM = (uint8 *)FCEU_dmalloc(CHRRAMSize)) == NULL) return 0;
}
else
{
@ -1516,11 +1516,11 @@ static int NewiNES_Init(int num)
{
CloseHandle(mapVROM);
mapVROM = NULL;
if((VROM = (uint8 *)malloc(CHRRAMSize)) == NULL) return 0;
if((VROM = (uint8 *)FCEU_dmalloc(CHRRAMSize)) == NULL) return 0;
}
}
#else
if((VROM = (uint8 *)malloc(CHRRAMSize)) == NULL) return 0;
if((VROM = (uint8 *)FCEU_dmalloc(CHRRAMSize)) == NULL) return 0;
#endif
UNIFchrrama=VROM;
SetupCartCHRMapping(0,VROM,CHRRAMSize,1);

View File

@ -22,7 +22,7 @@
#include "share.h"
static int seq,ptr,bit,cnt,have;
static uint8 bdata[20];
static uint8 bdata[32];
static uint8 Read(int w, uint8 ret)
@ -60,8 +60,8 @@ static void Update(void *data, int arg)
*(uint8 *)data=0;
seq=ptr=0;
have=1;
strcpy((char*)bdata,(char *)data+1); //mbg merge 7/17/06 added casts
strcpy((char*)&bdata[13],"SUNSOFT"); //mbg merge 7/17/06 added cast
strcpy((char*) bdata, (char*) data + 1); // mbg merge 7/17/06
strcpy((char*) bdata + 13, "SUNSOFT"); // mbg merge 0/17/06
}
}

View File

@ -37,6 +37,7 @@
#include "cheat.h"
#include "input.h"
#include "driver.h"
#include "utils/memory.h"
int FCEUnetplay=0;
@ -120,11 +121,11 @@ int FCEUNET_SendFile(uint8 cmd, char *fn)
fstat(fileno(fp),&sb);
len = sb.st_size;
buf = (char*)malloc(len); //mbg merge 7/17/06 added cast
buf = (char*)FCEU_dmalloc(len); //mbg merge 7/17/06 added cast
fread(buf, 1, len, fp);
fclose(fp);
cbuf = (char*)malloc(4 + len + len / 1000 + 12); //mbg merge 7/17/06 added cast
cbuf = (char*)FCEU_dmalloc(4 + len + len / 1000 + 12); //mbg merge 7/17/06 added cast
FCEU_en32lsb((uint8*)cbuf, len); //mbg merge 7/17/06 added cast
compress2((uint8*)cbuf + 4, &clen, (uint8*)buf, len, 7); //mbg merge 7/17/06 added casts
free(buf);
@ -164,9 +165,9 @@ static FILE *FetchFile(uint32 remlen)
}
//printf("Receiving file: %d...\n",clen);
if(fp = tmpfile())
if((fp = tmpfile()))
{
cbuf = (char *)malloc(clen); //mbg merge 7/17/06 added cast
cbuf = (char *)FCEU_dmalloc(clen); //mbg merge 7/17/06 added cast
if(!FCEUD_RecvData(cbuf, clen))
{
NetError();
@ -183,7 +184,7 @@ static FILE *FetchFile(uint32 remlen)
free(cbuf);
return(0);
}
buf = (char *)malloc(len); //mbg merge 7/17/06 added cast
buf = (char *)FCEU_dmalloc(len); //mbg merge 7/17/06 added cast
uncompress((uint8*)buf, &len, (uint8*)cbuf + 4, clen - 4); //mbg merge 7/17/06 added casts
fwrite(buf, 1, len, fp);

View File

@ -775,16 +775,17 @@ static void RDoTriangle(void)
if(!lengthcount[2] || !TriCount)
{ /* Counter is halted, but we still need to output. */
int32 *start = &WaveHi[ChannelBC[2]];
/*int32 *start = &WaveHi[ChannelBC[2]];
int32 count = SOUNDTS - ChannelBC[2];
while(count--)
{
//Modify volume based on channel volume modifiers
*start += (tcout/256*FSettings.TriangleVolume)&(~0xFFFF); // TODO OPTIMIZE ME NOW DAMMIT!
start++;
}
//for(V=ChannelBC[2];V<SOUNDTS;V++)
// WaveHi[V]+=tcout;
}*/
int32 cout = (tcout/256*FSettings.TriangleVolume)&(~0xFFFF);
for(V=ChannelBC[2];V<SOUNDTS;V++)
WaveHi[V]+=cout;
}
else
for(V=ChannelBC[2];V<SOUNDTS;V++)

View File

@ -474,7 +474,7 @@ void FCEUSS_Save(const char *fname)
st = FCEUD_UTF8_fstream(fn,"wb");
}
if(st == NULL)
if(st == NULL || st->get_fp() == NULL)
{
FCEU_DispMessage("State %d save error.",0,CurrentState);
return;
@ -557,7 +557,7 @@ int FCEUSS_LoadFP_old(EMUFILE* is, ENUM_SSLOADPARAMS params)
{
FCEUMOV_PreLoad();
}
is->fread((char*)&header,16);
is->fread((char*)&header,16);
if(memcmp(header,"FCS",3))
{
return(0);
@ -720,12 +720,12 @@ bool FCEUSS_Load(const char *fname)
{
strcpy(fn, FCEU_MakeFName(FCEUMKF_STATE,CurrentState,fname).c_str());
st=FCEUD_UTF8_fstream(fn,"rb");
strcpy(lastLoadstateMade,fn);
strcpy(lastLoadstateMade,fn);
}
if(st == NULL)
if(st == NULL || (st->get_fp() == NULL))
{
FCEU_DispMessage("State %d load error.",0,CurrentState);
FCEU_DispMessage("State %d load error. Filename: %s",0,CurrentState, fn);
SaveStateStatus[CurrentState]=0;
return false;
}
@ -739,11 +739,11 @@ bool FCEUSS_Load(const char *fname)
{
char szFilename[260]={0};
splitpath(fname, 0, 0, szFilename, 0);
FCEU_DispMessage("State %s loaded.",0,szFilename);
FCEU_DispMessage("State %s loaded. Filename: %s",0,szFilename, fn);
}
else
{
FCEU_DispMessage("State %d loaded.",0,CurrentState);
FCEU_DispMessage("State %d loaded. Filename: %s",0,CurrentState, fn);
SaveStateStatus[CurrentState]=1;
}
delete st;
@ -786,7 +786,7 @@ bool FCEUSS_Load(const char *fname)
{
SaveStateStatus[CurrentState]=1;
}
FCEU_DispMessage("Error(s) reading state %d!",0,CurrentState);
FCEU_DispMessage("Error(s) reading state %d! Filename: %s",0,CurrentState, fn);
delete st;
return 0;
}

View File

@ -76,3 +76,13 @@ void FCEU_free(void *ptr) // Might do something with this and FCEU_malloc lat
{
free(ptr);
}
void *FCEU_dmalloc(uint32 size)
{
return malloc(size);
}
void FCEU_dfree(void *ptr)
{
free(ptr);
}

View File

@ -29,3 +29,8 @@ void *FCEU_gmalloc(uint32 size);
void FCEU_gfree(void *ptr);
void FCEU_free(void *ptr);
void FCEU_memmove(void *d, void *s, uint32 l);
// wrapper for debugging when its needed, otherwise act like
// normal malloc/free
void *FCEU_dmalloc(uint32 size);
void FCEU_dfree(void *ptr);

View File

@ -628,7 +628,7 @@ int SaveSnapshot(void)
uint8 *tmp=XBuf+FSettings.FirstSLine*256;
uint8 *dest,*mal,*mork;
if(!(mal=mork=dest=(uint8 *)malloc((totallines<<8)+totallines)))
if(!(mal=mork=dest=(uint8 *)FCEU_dmalloc((totallines<<8)+totallines)))
goto PNGerr;
// mork=dest=XBuf;
@ -723,7 +723,7 @@ int SaveSnapshot(char fileName[512])
uint8 *tmp=XBuf+FSettings.FirstSLine*256;
uint8 *dest,*mal,*mork;
if(!(mal=mork=dest=(uint8 *)malloc((totallines<<8)+totallines)))
if(!(mal=mork=dest=(uint8 *)FCEU_dmalloc((totallines<<8)+totallines)))
goto PNGerr;
// mork=dest=XBuf;

View File

@ -875,7 +875,7 @@ class GuiKeyboard : public GuiWindow
typedef struct _optionlist {
int length;
char name[MAX_OPTIONS][50];
char name[MAX_OPTIONS][100];
char value[MAX_OPTIONS][50];
} OptionList;

View File

@ -79,10 +79,12 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l)
optionTxt[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionTxt[i]->SetPosition(8,0);
optionTxt[i]->SetMaxWidth(230);
optionVal[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionVal[i]->SetPosition(250,0);
optionVal[i]->SetMaxWidth(230);
optionBg[i] = new GuiImage(bgOptionsEntry);

View File

@ -2006,8 +2006,10 @@ static int MenuGameCheats()
for(i=0; i < numcheats; i++)
{
FCEUI_GetCheat(i,&name,NULL,NULL,NULL,&status,NULL);
sprintf (options.name[i], "%s", name);
if(!FCEUI_GetCheat(i,&name,NULL,NULL,NULL,&status,NULL))
break;
snprintf (options.name[i], 100, "%s", name);
sprintf (options.value[i], status ? "On" : "Off");
}