void AddExState(void *v, uint32 s, int type, char *desc) { if(desc) { SFMDATA[SFEXINDEX].desc=(char *)FCEU_malloc(5); strcpy(SFMDATA[SFEXINDEX].desc,desc); } else SFMDATA[SFEXINDEX].desc=0; SFMDATA[SFEXINDEX].v=v; SFMDATA[SFEXINDEX].s=s; if(type) SFMDATA[SFEXINDEX].s|=RLSB; if(SFEXINDEX<SFMDATA_SIZE-1) SFEXINDEX++; else { static int once=1; if(once) { once=0; FCEU_PrintError("Error in AddExState: SFEXINDEX overflow.\nSomebody made SFMDATA_SIZE too small."); } } SFMDATA[SFEXINDEX].v=0; // End marker. }
static int InitializeBoard(void) { int x=0; if(!sboardname) return(0); while(bmap[x].name) { if(!strcmp(sboardname,(char *)bmap[x].name)) { if(!malloced[16]) { if(bmap[x].flags & BMCFLAG_16KCHRR) CHRRAMSize = 16384; else CHRRAMSize = 8192; if((UNIFchrrama=(uint8 *)FCEU_malloc(CHRRAMSize))) { SetupCartCHRMapping(0,UNIFchrrama,CHRRAMSize,1); AddExState(UNIFchrrama, CHRRAMSize, 0,"CHRR"); } else return(-1); } if(bmap[x].flags&BMCFLAG_FORCE4) mirrortodo=4; MooMirroring(); bmap[x].init(&UNIFCart); return(1); } x++; } FCEU_PrintError("Board type not supported."); return(0); }
///allocates the specified number of bytes. returns null if this fails void *FCEU_malloc(uint32 size) { void *ret; ret=malloc(size); if(!ret) { FCEU_PrintError("Error allocating memory!"); return(0); } //mbg 6/17/08 - sometimes this memory is used as RAM or somesuch without clearing first. //this yields different behavior in debug and release modes. //specifically, saveram wasnt getting cleared so the games thought their savefiles were initialized //so we are going to clear it here. memset(ret,0,size); return ret; }
FCEUGI *FCEUI_CopyFamiStart(void) { ResetGameLoaded(); FCEUGameInfo = malloc(sizeof(FCEUGI)); memset(FCEUGameInfo, 0, sizeof(FCEUGI)); FCEUGameInfo->soundchan = 0; FCEUGameInfo->soundrate = 0; FCEUGameInfo->name = "copyfami"; FCEUGameInfo->type = GIT_CART; FCEUGameInfo->vidsys = GIV_USER; FCEUGameInfo->input[0] = FCEUGameInfo->input[1] = -1; FCEUGameInfo->inputfc = -1; FCEUGameInfo->cspecial = 0; FCEU_printf("Starting CopyFamicom...\n\n"); if (!CopyFamiLoad()) { FCEU_PrintError("An error occurred while starting CopyFamicom."); return 0; } FCEU_ResetVidSys(); if (FCEUGameInfo->type != GIT_NSF) if (FSettings.GameGenie) FCEU_OpenGenie(); PowerNES(); FCEUSS_CheckStates(); FCEUMOV_CheckMovies(); if (FCEUGameInfo->type != GIT_NSF) { FCEU_LoadGamePalette(); FCEU_LoadGameCheats(0); } FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. return(FCEUGameInfo); }
FCEUGI *FCEUI_LoadGame(const char *name) { FCEUFILE *fp; char *ipsfn; ResetGameLoaded(); FCEUGameInfo = malloc(sizeof(FCEUGI)); memset(FCEUGameInfo, 0, sizeof(FCEUGI)); FCEUGameInfo->soundchan = 0; FCEUGameInfo->soundrate = 0; FCEUGameInfo->name=0; FCEUGameInfo->type=GIT_CART; FCEUGameInfo->vidsys=GIV_USER; FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=-1; FCEUGameInfo->inputfc=-1; FCEUGameInfo->cspecial=0; FCEU_printf("Loading %s...\n\n",name); GetFileBase(name); ipsfn=FCEU_MakeFName(FCEUMKF_IPS,0,0); fp=FCEU_fopen(name,ipsfn,"rb",0); free(ipsfn); if(!fp) { FCEU_PrintError("Error opening \"%s\"!",name); return 0; } if(iNESLoad(name,fp)) goto endlseq; if(NSFLoad(fp)) goto endlseq; if(UNIFLoad(name,fp)) goto endlseq; if(FDSLoad(name,fp)) goto endlseq; FCEU_PrintError("An error occurred while loading the file."); FCEU_fclose(fp); return 0; endlseq: FCEU_fclose(fp); FCEU_ResetVidSys(); if(FCEUGameInfo->type!=GIT_NSF) if(FSettings.GameGenie) OpenGenie(); PowerNES(); FCEUSS_CheckStates(); FCEUMOV_CheckMovies(); if(FCEUGameInfo->type!=GIT_NSF) { FCEU_LoadGamePalette(); FCEU_LoadGameCheats(0); } FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. return(FCEUGameInfo); }
static const char* convertToFCM(const char *fname, char *buffer) { #ifdef WIN32 justAutoConverted=0; // convert to fcm if not already const char* dot = strrchr(fname, '.'); if(dot) { int fmv = !stricmp(dot, ".fmv"); int nmv = !stricmp(dot, ".nmv"); int vmv = !stricmp(dot, ".vmv"); if(fmv || nmv || vmv) { strcpy(buffer, fname); buffer[dot-fname]='\0'; strcat(buffer,"-autoconverted.fcm"); int fceuver=0; if(fmv) fceuver=1; else if(nmv) fceuver=2; else if(vmv) fceuver=3; extern char lastLoadedGameName [2048]; char cmd [1024], offset[64], romInfo[1024]; if(movieConvertOK) sprintf(romInfo, "-smd5=\"%s\" -sromname=\"%s (MAYBE)\" -s", lastLoadedGameName, FileBase); else sprintf(romInfo, "-sromname=\"(unknown)\" -s"); if(movieConvertOffset2) sprintf(offset, "-o %d:%d", movieConvertOffset2,movieConvertOffset1); else sprintf(offset, "-o %d", movieConvertOffset1); sprintf(cmd, ".\\util\\nesmock\\nesmock.exe %s %s -spal=%c -sfceuver=%d \"%s\" \"%s\" ", offset, romInfo, FCEUI_GetCurrentVidSystem(0,0)?'1':'0', fceuver, fname, buffer); // FCEU_PrintError(cmd); executeCommand(cmd); FILE* file = FCEUD_UTF8fopen(buffer,"rb"); if(file) { fseek(file, 12, SEEK_SET); int frames=0; read32le(&frames, file); if(frames) { fname = buffer; justAutoConverted=1; } else { static int errAlready=0; if(!errAlready) { errAlready=1; FCEU_PrintError("For some reason, nesmock was unable to create a valid FCM from the given file.\nThe command given was:\n%s\nPerhaps the file specified is not a movie file or contains no input data,\nor perhaps it is a movie file of a version unsupported by nesmock.\n\n(This error message will self-destruct until you restart FCEU.)", cmd); } } fclose(file); } else { char str [512]; str[0] = '\0'; GetCurrentDirectory(512,str); strcat(str, "\\util\\nesmock\\nesmock.exe"); file = FCEUD_UTF8fopen(str, "rb"); if(file) { static int errAlready=0; if(!errAlready) { errAlready=1; FCEU_PrintError("For some reason, nesmock was unable to convert the movie to FCM format.\nThe command given was:\n%s\n\n(This error message will self-destruct until you restart FCEU.)", cmd); fclose(file); } } else { static int errAlready=0; if(!errAlready) { errAlready=1; FCEU_PrintError("Nesmock not found, so the movie could not be converted to FCM format.\nYou must place nesmock.exe at this location so FCEU can find it:\n%s\n\n(This error message will self-destruct until you restart FCEU.)", str); } } } } } #endif return fname; }
// // LoadFile - Can be used in a threaded scenario so while loading graphics can update // - Probably not needed on PS3. Loading always seems instant. // size_t LoadFile (char * rbuffer, const char *filepath, size_t length, bool silent) { FCEU_PrintError("LoadFile(%p, %c, %d, %b)", rbuffer, filepath, length, silent); char zipbuffer[2048]; size_t size = 0, offset = 0, readsize = 0; int retry = 1; int device; // open the file while(retry) { file = fopen (filepath, "rb"); if(!file) { FCEU_PrintError("1: LoadFile %s failed", filepath); return 0; } /*if(length > 0 && length <= 2048) // do a partial read (eg: to check file header) { size = fread (rbuffer, 1, length, file); } else // load whole file*/ { readsize = fread (zipbuffer, 1, 32, file); if(!readsize) { fclose (file); FCEU_PrintError("2: LoadFile %s failed", filepath); return 0; } if (IsZipFile (zipbuffer)) { size = UnZipBuffer ((unsigned char *)rbuffer); // unzip } else { fseek(file,0,SEEK_END); size = ftell(file); fseek(file,0,SEEK_SET); //fseeko(file,0,SEEK_END); //size = ftello(file); //fseeko(file,0,SEEK_SET); while(!feof(file)) { FCEU_printf("Loading...%d/%d", offset, size); readsize = fread (rbuffer + offset, 1, 4096, file); // read in next chunk if(readsize <= 0) break; // reading finished (or failed) offset += readsize; } size = offset; } } retry = 0; fclose (file); } // go back to checking if devices were inserted/removed return size; }