From ce8c18789f31dd3465cd531027c72629b8746137 Mon Sep 17 00:00:00 2001 From: aquanull Date: Thu, 9 Jun 2011 12:17:47 +0000 Subject: [PATCH] Some minimal fixes and clean-ups. --- src/drivers/win/cdlogger.cpp | 78 +++++++++++++++++++----------------- src/drivers/win/replay.cpp | 6 +-- src/drivers/win/texthook.cpp | 2 +- src/fceu.cpp | 8 +--- src/fds.cpp | 6 +-- src/filter.cpp | 62 ++++++++++++++-------------- src/ines.cpp | 12 +++++- src/video.cpp | 10 ++--- 8 files changed, 93 insertions(+), 91 deletions(-) diff --git a/src/drivers/win/cdlogger.cpp b/src/drivers/win/cdlogger.cpp index b8cf66d3..3708e0da 100644 --- a/src/drivers/win/cdlogger.cpp +++ b/src/drivers/win/cdlogger.cpp @@ -357,47 +357,51 @@ void SaveStrippedRom(){ //this is based off of iNesSave() fp = fopen(sromfilename,"wb"); -if(GameInfo->type==GIT_NSF) -{ - //Not used because if bankswitching, the addresses involved - //could still end up being used through writes - //static uint16 LoadAddr; - //LoadAddr=NSFHeader.LoadAddressLow; - //LoadAddr|=(NSFHeader.LoadAddressHigh&0x7F)<<8; - - //Simple store/restore for writing a working NSF header - NSFLoadLow = NSFHeader.LoadAddressLow; - NSFLoadHigh = NSFHeader.LoadAddressHigh; - NSFHeader.LoadAddressLow=0; - NSFHeader.LoadAddressHigh&=0xF0; - fwrite(&NSFHeader,1,0x8,fp); - NSFHeader.LoadAddressLow = NSFLoadLow; - NSFHeader.LoadAddressHigh = NSFLoadHigh; - - fseek(fp,0x8,SEEK_SET); - for(i = 0;i < ((NSFMaxBank+1)*4096);i++){ - if(cdloggerdata[i] & 3)fputc(NSFDATA[i],fp); - else fputc(0,fp); - } - -} -else -{ - if(fwrite(&head,1,16,fp)!=16)return; - - if(head.ROM_type&4) /* Trainer */ + if(GameInfo->type==GIT_NSF) { - fwrite(trainerpoo,512,1,fp); - } + //Not used because if bankswitching, the addresses involved + //could still end up being used through writes + //static uint16 LoadAddr; + //LoadAddr=NSFHeader.LoadAddressLow; + //LoadAddr|=(NSFHeader.LoadAddressHigh&0x7F)<<8; + + //Simple store/restore for writing a working NSF header + NSFLoadLow = NSFHeader.LoadAddressLow; + NSFLoadHigh = NSFHeader.LoadAddressHigh; + NSFHeader.LoadAddressLow=0; + NSFHeader.LoadAddressHigh&=0xF0; + fwrite(&NSFHeader,1,0x8,fp); + NSFHeader.LoadAddressLow = NSFLoadLow; + NSFHeader.LoadAddressHigh = NSFLoadHigh; + + fseek(fp,0x8,SEEK_SET); + for(i = 0;i < ((NSFMaxBank+1)*4096);i++){ + if(cdloggerdata[i] & 3)fputc(NSFDATA[i],fp); + else fputc(0,fp); + } - for(i = 0;i < head.ROM_size*0x4000;i++){ - if(cdloggerdata[i] & 3)fputc(ROM[i],fp); - else fputc(0,fp); } - //fwrite(ROM,0x4000,head.ROM_size,fp); + else + { + if(fwrite(&head,1,16,fp)!=16) + { + fclose(fp); + return; + } - if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp); -} + if(head.ROM_type&4) /* Trainer */ + { + fwrite(trainerpoo,512,1,fp); + } + + for(i = 0;i < head.ROM_size*0x4000;i++){ + if(cdloggerdata[i] & 3)fputc(ROM[i],fp); + else fputc(0,fp); + } + //fwrite(ROM,0x4000,head.ROM_size,fp); + + if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp); + } fclose(fp); } diff --git a/src/drivers/win/replay.cpp b/src/drivers/win/replay.cpp index ed226987..aa491c99 100644 --- a/src/drivers/win/replay.cpp +++ b/src/drivers/win/replay.cpp @@ -585,8 +585,8 @@ BOOL CALLBACK ReplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP ArchiveScanRecord asr = FCEUD_ScanArchive(filename); if(!asr.isArchive()) { FCEUFILE* fp = FCEU_fopen(filename,0,"rb",0); - fp->stream = fp->stream->memwrap(); if(fp) { + fp->stream = fp->stream->memwrap(); HandleScan(hwndDlg,fp ,items); delete fp; } @@ -787,11 +787,11 @@ static void UpdateRecordDialog(HWND hwndDlg) static void UpdateRecordDialogPath(HWND hwndDlg, const std::string &fname) { - char* baseMovieDir = strdup(FCEU_GetPath(FCEUMKF_MOVIE).c_str()); + const std::string &baseMovieDir = FCEU_GetPath(FCEUMKF_MOVIE); char* fn=0; // display a shortened filename if the file exists in the base movie directory - if(!strncmp(fname.c_str(), baseMovieDir, strlen(baseMovieDir))) + if(!strncmp(fname.c_str(), baseMovieDir.c_str(), baseMovieDir.size())) { char szDrive[MAX_PATH]={0}; char szDirectory[MAX_PATH]={0}; diff --git a/src/drivers/win/texthook.cpp b/src/drivers/win/texthook.cpp index 1347d8ed..84891cc9 100644 --- a/src/drivers/win/texthook.cpp +++ b/src/drivers/win/texthook.cpp @@ -705,7 +705,7 @@ int TextHookerSaveTableFile(){ FP = fopen(nameo,"wb"); line = 0; //init the line counter - char hex[] = { 0 ,0 }; + char hex[3] = { 0, 0, 0 }; //write the table file to the file for ( i = 0; i < 256; i++ ) { //go through each possible hex value diff --git a/src/fceu.cpp b/src/fceu.cpp index fe443c61..a3c99c7e 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -409,17 +409,13 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode) const char* romextensions[] = {"nes","fds",0}; fp=FCEU_fopen(name,0,"rb",0,-1,romextensions); - if(!fp) - { - return 0; - } - - GetFileBase(fp->filename.c_str()); if(!fp) { FCEU_PrintError("Error opening \"%s\"!",name); return 0; } + + GetFileBase(fp->filename.c_str()); //--------- //file opened ok. start loading. diff --git a/src/fds.cpp b/src/fds.cpp index 9f3f861e..84404560 100644 --- a/src/fds.cpp +++ b/src/fds.cpp @@ -890,16 +890,14 @@ void FDSClose(void) FILE *fp; int x; isFDS = false; - char *fn=strdup(FCEU_MakeFName(FCEUMKF_FDS,0,0).c_str()); if(!DiskWritten) return; - if(!(fp=FCEUD_UTF8fopen(fn,"wb"))) + const std::string &fn = FCEU_MakeFName(FCEUMKF_FDS,0,0); + if(!(fp=FCEUD_UTF8fopen(fn.c_str(),"wb"))) { - free(fn); return; } - free(fn); for(x=0;x>16)-SQ2NCOEFFS],D=sq2coeffs;c;c--,D++) - { - acc+=(S[c]**D)>>6; - acc2+=(S[1+c]**D)>>6; - } + for(c=SQ2NCOEFFS,S=&in[(x>>16)-SQ2NCOEFFS],D=sq2coeffs;c;c--,D++) + { + acc+=(S[c]**D)>>6; + acc2+=(S[1+c]**D)>>6; + } - acc=((int64)acc*(65536-(x&65535))+(int64)acc2*(x&65535))>>(16+11); - *out=acc; - out++; - count++; - } + acc=((int64)acc*(65536-(x&65535))+(int64)acc2*(x&65535))>>(16+11); + *out=acc; + out++; + count++; + } else - for(x=mrindex;x>16)-NCOEFFS],D=coeffs;c;c--,D++) - { - acc+=(S[c]**D)>>6; - acc2+=(S[1+c]**D)>>6; - } + for(c=NCOEFFS,S=&in[(x>>16)-NCOEFFS],D=coeffs;c;c--,D++) + { + acc+=(S[c]**D)>>6; + acc2+=(S[1+c]**D)>>6; + } - acc=((int64)acc*(65536-(x&65535))+(int64)acc2*(x&65535))>>(16+11); - *out=acc; - out++; - count++; - } + acc=((int64)acc*(65536-(x&65535))+(int64)acc2*(x&65535))>>(16+11); + *out=acc; + out++; + count++; + } - mrindex=x-max; + mrindex=x-max; if(FSettings.soundq==2) { diff --git a/src/ines.cpp b/src/ines.cpp index 74ed0a38..deffee0d 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -845,7 +845,11 @@ int iNesSave(){ fp = fopen(name,"wb"); - if(fwrite(&head,1,16,fp)!=16)return 0; + if(fwrite(&head,1,16,fp)!=16) + { + fclose(fp); + return 0; + } if(head.ROM_type&4) /* Trainer */ { @@ -872,7 +876,11 @@ int iNesSaveAs(char* name) int x = 0; if (!fp) int x = 1; - if(fwrite(&head,1,16,fp)!=16)return 0; + if(fwrite(&head,1,16,fp)!=16) + { + fclose(fp); + return 0; + } if(head.ROM_type&4) /* Trainer */ { diff --git a/src/video.cpp b/src/video.cpp index 0e1874e1..c461556b 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -531,7 +531,6 @@ int SaveSnapshot(void) { unsigned int lastu=0; - char *fn=0; int totallines=FSettings.LastSLine-FSettings.FirstSLine+1; int x,u,y; FILE *pp=NULL; @@ -543,20 +542,19 @@ int SaveSnapshot(void) for(u=lastu;u<99999;u++) { - pp=FCEUD_UTF8fopen((fn=strdup(FCEU_MakeFName(FCEUMKF_SNAP,u,"png").c_str())),"rb"); + pp=FCEUD_UTF8fopen(FCEU_MakeFName(FCEUMKF_SNAP,u,"png").c_str(),"rb"); if(pp==NULL) break; fclose(pp); } lastu=u; - if(!(pp=FCEUD_UTF8fopen(fn,"wb"))) + if(!(pp=FCEUD_UTF8fopen(FCEU_MakeFName(FCEUMKF_SNAP,u,"png").c_str(),"wb"))) { - free(fn); free(compmem); return 0; } - free(fn); + { static uint8 header[8]={137,80,78,71,13,10,26,10}; if(fwrite(header,8,1,pp)!=1) @@ -644,8 +642,6 @@ int SaveSnapshot(char fileName[512]) if(!(compmem=(uint8 *)FCEU_malloc(compmemsize))) return 0; - pp = fopen(fileName, "w"); - if(!(pp=FCEUD_UTF8fopen(fileName,"wb"))) { free(compmem);