BOOL UploadGAR (void) { FILE *GAR; char filename[MAX_PATH]; int i; if (!PromptFile(topHWnd,"Game Action Replay RAM file (gar.bin)\0gar.bin\0\0",filename,NULL,Path_PLUG,"Please select a valid Game Action Replay data file...","gar.bin",FALSE)) return FALSE; if ((GAR = fopen(filename,"rb")) == NULL) { MessageBox(topHWnd,"Unable to open GAR data file!",MSGBOX_TITLE,MB_OK | MB_ICONERROR); return FALSE; } OpenStatus(topHWnd); InitPort(); StatusText("Resetting CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading initialization plugin..."); if (!LoadPlugin("garset.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running initialization plugin..."); RunCode(); Sleep(SLEEP_LONG); StatusText("Loading upload plugin..."); if (!LoadPlugin("garup.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running upload plugin..."); RunCode(); StatusText("Uploading from data file..."); BYTE a[256]; for (i = 0; i < 8; i++) { fread(&a,256,1,GAR); if (!WriteBlock(a, 256)) { fclose(GAR); CloseStatus(); return FALSE; } StatusPercent((i*100)/8); } StatusPercent(100); StatusText("...done!"); fclose(GAR); StatusText("Upload complete!"); StatusOK(); ResetNES(RESET_COPYMODE); return TRUE; }
BOOL DownloadGAR (void) { FILE *GAR; char filename[MAX_PATH]; int i; if (!PromptFile(topHWnd,"Game Action Replay RAM file (gar_d.bin)\0gar_d.bin\0\0",filename,NULL,Path_PLUG,"Please specify where to save Game Action Replay RAM data...","gar_d.bin",TRUE)) return FALSE; if ((GAR = fopen(filename,"wb")) == NULL) { MessageBox(topHWnd,"Unable to open file for output!",MSGBOX_TITLE,MB_OK | MB_ICONERROR); return FALSE; } OpenStatus(topHWnd); InitPort(); StatusText("Resetting CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading initialization plugin..."); if (!LoadPlugin("garset.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running initialization plugin..."); RunCode(); Sleep(SLEEP_LONG); StatusText("Loading download plugin..."); if (!LoadPlugin("gardn.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running download plugin..."); RunCode(); StatusText("Saving to file..."); for (i = 0; i < 0x800; i++) { BYTE n; if (!ReadByte(n)) { fclose(GAR); CloseStatus(); return FALSE; } fwrite(&n,1,1,GAR); if (!(i & 0x7)) StatusPercent((i*100)/2048); } fclose(GAR); StatusText("Download complete!"); StatusOK(); ResetNES(RESET_COPYMODE); return TRUE; }
bool LoadRAM (int method, bool silent) { ShowAction ((char*) "Loading..."); if(method == METHOD_AUTO) method = autoSaveMethod(); // we use 'Save' because we need R/W char filepath[1024]; int offset = 0; if(method == METHOD_SD || method == METHOD_USB) { if(ChangeFATInterface(method, NOTSILENT)) { sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename); offset = LoadSaveBufferFromFAT (filepath, silent); } } else if(method == METHOD_SMB) { sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename); offset = LoadSaveBufferFromSMB (filepath, silent); } else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { sprintf (filepath, "%08x.sav", iNESGameCRC32); if(method == METHOD_MC_SLOTA) offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent); else offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent); } if (offset > 0) { if(nesGameType == 1) NGCFCEU_GameSave(&iNESCart, 1); else if(nesGameType == 2) NGCFCEU_GameSave(&UNIFCart, 1); ResetNES(); return 1; } // if we reached here, nothing was done! if(!silent) WaitPrompt ((char*) "Save file not found"); return 0; }
BOOL CMD_DUMPCART (void) { int dtype = 2; int rbyte = 0, rcount = 0; PPlugin plugin; char *path, *ext; char filename[MAX_PATH]; char fnamebuf[MAX_PATH]; int cmode, battery, bytes, numk; int mapper,submapper=0; int nes2=0, wram=0, vram=0; BYTE ctype; WORD nblks; char Status[256]; FILE *CRC, *DATA; // select board name plugin = PromptPlugin(PLUG_STD); if (plugin == NULL) return FALSE; mapper = plugin->num; PromptTitle = "Choose a ROM filename (omit extension)"; if (!Prompt(topHWnd)) return FALSE; strcpy(filename,PromptResult); OpenStatus(topHWnd); StatusText("Resetting USB CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Unloading any existing plugin..."); if (!LoadPlugin("clear.bin")) { CloseStatus(); return FALSE; } RunCode(); Sleep(SLEEP_SHORT); StatusText("Resetting USB CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading plugin..."); if (!LoadPlugin(plugin->file)) { CloseStatus(); return FALSE; } StatusText("Running plugin..."); RunCode(); Sleep(SLEEP_LONG); if (SaveCRC) CRC = fopen(strjoin3(fnamebuf,Path_CRC,filename,".txt"),"wb"); cmode = 0; if (!ReadByte((BYTE *)&cmode)) // mirroring { CloseStatus(); return FALSE; } battery = 0; while (1) { // for the first 'header' byte, wait longer than usual // since the plugin might be busy doing size detection, which can take a while int s; if (!ReadByteEx((BYTE *)&nblks,10,TRUE) || !ReadByte((BYTE *)&nblks+1)) { CloseStatus(); return FALSE; } bytes = nblks << 8; numk = bytes / 1024; if (!ReadByte(&ctype)) { CloseStatus(); return FALSE; } if (ctype == 0) break; switch (ctype) { case 1: ext = ".prg"; if(numk >= 4096) nes2 = 1; path = Path_PRG; sprintf(Status,"Dumping %iK PRG ROM...",numk); break; case 2: ext = ".chr"; if(numk >= 2048) nes2 = 1; path = Path_CHR; sprintf(Status,"Dumping %iK CHR ROM...",numk); break; case 3: ext = ".sav"; path = Path_WRAM; sprintf(Status,"Dumping %iK WRAM/VRAM...",numk); battery = 1; break; case 4: rbyte = nblks / 4; continue; case 5: nes2 = 1; wram = nblks & 0xFF; vram = nblks >> 8; if(wram & 0xF0) battery = 1; if(vram & 0xF0) battery = 1; sprintf(Status,"Non battery WRAM size: %i Bytes...", ((wram & 0x0f)?64 << (wram & 0x0F):0)); StatusText(Status); sprintf(Status,"battery WRAM size: %i Bytes...", ((wram >> 4)?64 << (wram & 0x0F):0)); StatusText(Status); sprintf(Status,"Non battery VRAM size: %i Bytes...", ((vram & 0x0f)?64 << (vram & 0x0F):0)); StatusText(Status); sprintf(Status,"battery VRAM size: %i Bytes...", ((vram >> 4)?64 << (vram & 0x0F):0)); StatusText(Status); continue; case 6: //Mapper number override by plugin. mapper = nblks & 0xFFF; submapper = (nblks & 0xF000) >> 12; sprintf(Status,"Mapper number: %i, submapper: %i...",mapper,submapper); StatusText(Status); if((mapper > 255) || (submapper > 0)) nes2 = 1; continue; case 255: sprintf(Status,"."); continue; //Prevent timeout. default:StatusText("Unknown block type %i! Aborting...",ctype); StatusOK(); return FALSE; break; } StatusText(Status); DATA = fopen(strjoin3(fnamebuf,path,filename,ext),"w+b"); if (DATA == NULL) { StatusText("Unable to open output file!"); StatusOK(); return FALSE; } for (s = 0; s < numk; s++) { int a; BYTE n; for (a = 0; a < 1024; a++) { if (!ReadByte(&n)) { CloseStatus(); return FALSE; } fwrite(&n,1,1,DATA); } if (rbyte) { rcount++; if (rbyte <= rcount) { rcount = 0; StatusText("Resetting USB CopyNES as requested by plugin..."); ResetNES(RESET_COPYMODE); StatusText("Reloading plugin..."); LoadPlugin(plugin->file); StatusText("Rerunning plugin..."); RunCode(); rbyte = 0; if (!ReadByte((BYTE *)&rbyte) || !ReadByte((BYTE *)&rbyte+1)) { CloseStatus(); return FALSE; } rbyte /= 4; } } StatusPercent((s*100)/numk); DoEvents(); } StatusPercent(100); StatusText("...done!"); if (SaveCRC) fprintf(CRC,"%s%s %08X\n",filename,ext,GetCRC(DATA)); fclose(DATA); } if (SaveCRC) fclose(CRC); StatusText("Dump complete!"); StatusOK(); ResetNES(RESET_COPYMODE); { int scrn4 = (cmode & 0x2) >> 1; int mirror = (~cmode & 0x1); int mcon = (cmode & 0x4) >> 2; if (plugin->num == 9999) return TRUE; WriteNES(filename,mapper,battery,mirror,scrn4,nes2,wram,vram,submapper,0); if (MakeUnif == 1) WriteUNIF(filename,plugin->name,battery,mirror,scrn4,mcon); if (SaveFiles == 0) { unlink(strjoin3(fnamebuf,Path_CHR,filename,".chr")); unlink(strjoin3(fnamebuf,Path_PRG,filename,".prg")); } } return TRUE; }
void FCEUI_SaveMovie(char *fname, uint8 flags, const char* metadata) { FILE *fp; char *fn; int poweron=0; uint8 padding[4] = {0,0,0,0}; int n_padding; FCEUI_StopMovie(); char origname[512]; if(fname) { fp = FCEUD_UTF8fopen(fname, "wb"); strcpy(origname,fname); } else { fp=FCEUD_UTF8fopen(fn=FCEU_MakeFName(FCEUMKF_MOVIE,CurrentMovie,0),"wb"); strcpy(origname,fn); free(fn); } if(!fp) return; // don't need the movieSyncHackOn sync hack for newly recorded movies flags |= MOVIE_FLAG_NOSYNCHACK; resetDMCacc=movieSyncHackOn=0; // add PAL flag if(FCEUI_GetCurrentVidSystem(0,0)) flags |= MOVIE_FLAG_PAL; if(flags & MOVIE_FLAG_FROM_POWERON) { poweron=1; flags &= ~MOVIE_FLAG_FROM_POWERON; flags |= MOVIE_FLAG_FROM_RESET; } // write header write32le(MOVIE_MAGIC, fp); write32le(MOVIE_VERSION, fp); fputc(flags, fp); fputc(0, fp); // reserved fputc(0, fp); // reserved fputc(0, fp); // reserved write32le(0, fp); // leave room for length frames write32le(0, fp); // leave room for rerecord count write32le(0, fp); // leave room for movie data size write32le(0, fp); // leave room for savestate_offset write32le(0, fp); // leave room for offset_to_controller_data fwrite(FCEUGameInfo->MD5, 1, 16, fp); // write ROM checksum write32le(FCEU_VERSION_NUMERIC, fp); // write emu version used fputs(FileBase, fp); // write ROM name used fputc(0, fp); if(metadata) { if(strlen(metadata) < MOVIE_MAX_METADATA) fputs(metadata, fp); else fwrite(metadata, 1, MOVIE_MAX_METADATA-1, fp); } fputc(0, fp); // add padding n_padding = (4 - (ftell(fp) & 0x3)) & 0x3; fwrite(padding, 1, n_padding, fp); if(flags & MOVIE_FLAG_FROM_RESET) { if(poweron) { // make a for-movie-recording power-on clear the game's save data, too // (note: FCEU makes a save state immediately after this and that loads that on movie playback) extern char lastLoadedGameName [2048]; extern int disableBatteryLoading, suppressAddPowerCommand; suppressAddPowerCommand=1; disableBatteryLoading=1; suppressMovieStop=1; { // NOTE: this will NOT write an FCEUNPCMD_POWER into the movie file FCEUGI * gi = FCEUI_LoadGame(lastLoadedGameName); if(!gi) PowerNES(); // and neither will this, if it can even happen } suppressMovieStop=0; disableBatteryLoading=0; suppressAddPowerCommand=0; } } savestate_offset = ftell(fp); FCEUSS_SaveFP(fp); fseek(fp, 0, SEEK_END); ResetInputTypes(); // add padding n_padding = (4 - (ftell(fp) & 0x3)) & 0x3; fwrite(padding, 1, n_padding, fp); firstframeoffset = ftell(fp); // finish header fseek(fp, 24, SEEK_SET); // offset_to_savestate offset write32le(savestate_offset, fp); write32le(firstframeoffset, fp); fseek(fp, firstframeoffset, SEEK_SET); // set recording flag current=CurrentMovie; movie_readonly = 0; frameptr = 0; framecount = 0; rerecord_count = 0; slots[current] = fp; memset(joop,0,sizeof(joop)); current++; framets=0; nextd = -1; // trigger a reset if(flags & MOVIE_FLAG_FROM_RESET) { if(poweron) { PowerNES(); // NOTE: this will write an FCEUNPCMD_POWER into the movie file } else ResetNES(); // NOTE: this will write an FCEUNPCMD_RESET into the movie file } if(!fname) FCEUI_SelectMovie(CurrentMovie,1); /* Quick hack to display status. */ else FCEU_DispMessage("Movie recording started."); strcpy(curMovieFilename, origname); }
bool LoadRAM (char * filepath, bool silent) { int offset = 0; bool retval = false; int device; if(!FindDevice(filepath, &device)) return 0; if(GameInfo->type == GIT_FDS) // RAM saves don't exist for FDS games return false; AllocSaveBuffer (); offset = LoadFile(filepath, silent); // Check to see if this is a PocketNES save file if (goomba_is_sram(savebuffer)) { void* cleaned = goomba_cleanup(savebuffer); if (!cleaned) { ErrorPrompt(goomba_last_error()); } else if (cleaned != savebuffer) { memcpy(savebuffer, cleaned, GOOMBA_COLOR_SRAM_SIZE); free(cleaned); } // Look for just one save file. If there aren't any, or there is more than one, don't read any data. const stateheader* sh1 = NULL; const stateheader* sh2 = NULL; const stateheader* sh = stateheader_first(savebuffer); while (sh && stateheader_plausible(sh)) { if (little_endian_conv_16(sh->type) != GOOMBA_SRAMSAVE) { } else if (sh1 == NULL) { sh1 = sh; } else { sh2 = sh; break; } sh = stateheader_advance(sh); } if (sh1 == NULL) { ErrorPrompt("PocketNES save file has no SRAM."); offset = 0; } else if (sh2 != NULL) { ErrorPrompt("PocketNES save file has more than one SRAM."); offset = 0; } else { goomba_size_t len; void* extracted = goomba_extract(savebuffer, sh1, &len); if (!extracted) ErrorPrompt(goomba_last_error()); else { memcpy(savebuffer, extracted, len); offset = len; free(extracted); } } } if (offset > 0) { if(GameInfo->type == GIT_CART) WiiFCEU_GameSave(&iNESCart, 1); else if(GameInfo->type == GIT_VSUNI) WiiFCEU_GameSave(&UNIFCart, 1); ResetNES(); retval = true; } else { // if we reached here, nothing was done! if(!silent) InfoPrompt ("Save file not found"); } FreeSaveBuffer (); return retval; }