MCPcopy Create free account
hub / github.com/TASEmulators/fceux / FCEUSS_SaveMS

Function FCEUSS_SaveMS

src/state.cpp:378–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376
377
378bool FCEUSS_SaveMS(EMUFILE* outstream, int compressionLevel)
379{
380 // reinit memory_savestate
381 // memory_savestate is global variable which already has its vector of bytes, so no need to allocate memory every time we use save/loadstate
382 memory_savestate.set_len(0); // this also seeks to the beginning
383 memory_savestate.unfail();
384
385 EMUFILE* os = &memory_savestate;
386
387 uint32 totalsize = 0;
388
389 FCEUPPU_SaveState();
390 FCEUSND_SaveState();
391 totalsize=WriteStateChunk(os,1,SFCPU);
392 totalsize+=WriteStateChunk(os,2,SFCPUC);
393 totalsize+=WriteStateChunk(os,3,FCEUPPU_STATEINFO);
394 totalsize+=WriteStateChunk(os,31,FCEU_NEWPPU_STATEINFO);
395 totalsize+=WriteStateChunk(os,4,FCEUCTRL_STATEINFO);
396 totalsize+=WriteStateChunk(os,5,FCEUSND_STATEINFO);
397 if(FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD|MOVIEMODE_FINISHED))
398 {
399 totalsize+=WriteStateChunk(os,6,FCEUMOV_STATEINFO);
400
401 //MBG TAS Editor HACK HACK HACK!
402 //do not save the movie state if we are in Taseditor! That would be a huge waste of time and space!
403 if(!FCEUMOV_Mode(MOVIEMODE_TASEDITOR))
404 {
405 os->fseek(5,SEEK_CUR);
406 int size = FCEUMOV_WriteState(os);
407 os->fseek(-(size+5),SEEK_CUR);
408 os->fputc(7);
409 write32le(size, os);
410 os->fseek(size,SEEK_CUR);
411
412 totalsize += 5 + size;
413 }
414 }
415 // save back buffer
416 {
417 extern uint8 *XBackBuf;
418 uint32 size = 256 * 256;
419 os->fputc(8);
420 write32le(size, os);
421 os->fwrite((char*)XBackBuf,size);
422 totalsize += 5 + size;
423 }
424
425 if(SPreSave) SPreSave();
426 totalsize+=WriteStateChunk(os,0x10,SFMDATA);
427 if(SPostSave) SPostSave();
428
429 //save the length of the file
430 size_t len = memory_savestate.size();
431
432 //sanity check: len and totalsize should be the same
433 if(len != totalsize)
434 {
435 FCEUD_PrintError("sanity violation: len != totalsize");

Callers 8

FCEUSS_SaveFunction · 0.85
FCEUSS_LoadFPFunction · 0.85
updateMethod · 0.85
dumpSavestateToMethod · 0.85
savestate_saveFunction · 0.85
collectCurrentStateMethod · 0.85
recalcMemoryUsageMethod · 0.85
collectCurrentStateMethod · 0.85

Calls 15

FCEUPPU_SaveStateFunction · 0.85
FCEUSND_SaveStateFunction · 0.85
WriteStateChunkFunction · 0.85
FCEUMOV_ModeFunction · 0.85
FCEUMOV_WriteStateFunction · 0.85
write32leFunction · 0.85
compress2Function · 0.85
FCEU_en32lsbFunction · 0.85
set_lenMethod · 0.80
unfailMethod · 0.80
bufMethod · 0.80
FCEUD_PrintErrorFunction · 0.50

Tested by

no test coverage detected