int MDFNSS_StateAction(void* st_p, int load, SFORMAT* sf, const char* name)
{
   StateMem* st = (StateMem*)st_p;
   if (load)
   {
      char sname[32];

      int found = 0;
      uint32 tmp_size;
      uint32 total = 0;

      while (smem_read(st, (uint8*)sname, 32) == 32)
      {
         if (smem_read32le(st, &tmp_size) != 4)
            return (0);

         total += tmp_size + 32 + 4;

         // Yay, we found the section
         if (!strncmp(sname, name, 32))
         {
            if (!ReadStateChunk(st, sf, tmp_size))
            {
               printf("Error reading chunk: %s\n", name);
               return (0);
            }
            found = 1;
            break;
         }
         else
         {
            if (smem_seek(st, tmp_size, SEEK_CUR) < 0)
            {
               puts("Chunk seek failure");
               return (0);
            }
         }
      }
      if (smem_seek(st, -total, SEEK_CUR) < 0)
      {
         puts("Reverse seek error");
         return (0);
      }
      if (!found) // Not found.  We are sad!
      {
         printf("Section missing:  %.32s\n", name);
         return (0);
      }


   }
   else
   {
      if (!WriteStateChunk(st, name, sf))
         return (0);
   }

   return (1);
}
/* This function is called by the game driver(NES, GB, GBA) to save a state. */
static int MDFNSS_StateAction_internal(void *st_p, int load, int data_only, SSDescriptor *section)
{
   StateMem *st = (StateMem*)st_p;

   if(load)
   {
      char sname[32];

      int found = 0;
      uint32_t tmp_size;
      uint32_t total = 0;

      while(smem_read(st, (uint8_t *)sname, 32) == 32)
      {
         if(smem_read32le(st, &tmp_size) != 4)
            return(0);

         total += tmp_size + 32 + 4;

         // Yay, we found the section
         if(!strncmp(sname, section->name, 32))
         {
            if(!ReadStateChunk(st, section->sf, tmp_size))
            {
               printf("Error reading chunk: %s\n", section->name);
               return(0);
            }
            found = 1;
            break;
         } 
         else
         {
            if(smem_seek(st, tmp_size, SEEK_CUR) < 0)
            {
               puts("Chunk seek failure");
               return(0);
            }
         }
      }
      if(smem_seek(st, -total, SEEK_CUR) < 0)
      {
         puts("Reverse seek error");
         return(0);
      }
      if(!found && !section->optional) // Not found.  We are sad!
      {
         printf("Section missing:  %.32s\n", section->name);
         return(0);
      }
   }
   else
   {
      if(!WriteStateChunk(st, section->name, section->sf))
         return(0);
   }

   return(1);
}
Exemple #3
0
int FCEUSS_SaveFP(MEM_TYPE *st) {
	static uint32 totalsize;
	uint8 header[16] = { 0 };

	header[0] = 'F';
	header[1] = 'C';
	header[2] = 'S';
	header[3] = 0xFF;

	header[3] = 0xFF;
	FCEU_en32lsb(header + 8, FCEU_VERSION_NUMERIC);
	fwrite(header, 1, 16, st);
	FCEUPPU_SaveState();
	FCEUSND_SaveState();
	totalsize = WriteStateChunk(st, 1, SFCPU);
	totalsize += WriteStateChunk(st, 2, SFCPUC);
	totalsize += WriteStateChunk(st, 3, FCEUPPU_STATEINFO);
	totalsize += WriteStateChunk(st, 4, FCEUCTRL_STATEINFO);
	totalsize += WriteStateChunk(st, 5, FCEUSND_STATEINFO);
	if (SPreSave) SPreSave();
	totalsize += WriteStateChunk(st, 0x10, SFMDATA);
	if (SPreSave) SPostSave();

	fseek(st, 4, SEEK_SET);
	write32le(totalsize, st);
	return(1);
}
Exemple #4
0
void SaveState(void)
{
	FILE *st=NULL;
	char *fname;

	TempAddrT=TempAddr;
	RefreshAddrT=RefreshAddr;

	if(geniestage==1)
	{
	 FCEU_DispMessage("Cannot save FCS in GG screen.");
	 return;
        }

	 fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
	 st=fopen(fname,"wb");
	 free(fname);

	 if(st!=NULL)
	 {
	  static uint32 totalsize;
	  static uint8 header[16]="FCS";
	  memset(header+4,0,13);
	  header[3]=VERSION_NUMERIC;
	  fwrite(header,1,16,st);

#ifdef ASM_6502
          asmcpu_pack();
#endif
	  totalsize=WriteStateChunk(st,1,SFCPU);
	  totalsize+=WriteStateChunk(st,2,SFCPUC);
	  totalsize+=WriteStateChunk(st,3,FCEUPPU_STATEINFO);
	  totalsize+=WriteStateChunk(st,4,FCEUCTRL_STATEINFO);
	  totalsize+=WriteStateChunk(st,5,SFSND);


	  if(SPreSave) SPreSave();
	  totalsize+=WriteStateChunk(st,0x10,SFMDATA);
	  if(SPostSave) SPostSave();

	  fseek(st,4,SEEK_SET);
	  write32(totalsize,st);
	  SaveStateStatus[CurrentState]=1;
	  fclose(st);
#ifdef GP2X
	  sync();
#endif
	  FCEU_DispMessage("State %d saved.",CurrentState);
	 }
	 else
	  FCEU_DispMessage("State %d save error.",CurrentState);
}
Exemple #5
0
void SaveState(const char *fname)
{
	MEMFILE *st=NULL;

	TempAddrT=TempAddr;
	RefreshAddrT=RefreshAddr;

	if(geniestage==1)
	{
	 FCEU_DispMessage("Cannot save FCS in GG screen.");
	 return;
        }

	st=mem_fopen_write(fname);

	 if(st!=NULL)
	 {
	  static uint32 totalsize;
	  static uint8 header[16]="FCS";
	  memset(header+4,0,13);
	  header[3]=VERSION_NUMERIC;
	  mem_fwrite(header,1,16,st);

#ifdef ASM_6502
          asmcpu_pack();
#endif
	  totalsize=WriteStateChunk(st,1,SFCPU);
	  totalsize+=WriteStateChunk(st,2,SFCPUC);
	  totalsize+=WriteStateChunk(st,3,FCEUPPU_STATEINFO);
	  totalsize+=WriteStateChunk(st,4,FCEUCTRL_STATEINFO);
	  totalsize+=WriteStateChunk(st,5,SFSND);


	  if(SPreSave) SPreSave();
	  totalsize+=WriteStateChunk(st,0x10,SFMDATA);
	  if(SPostSave) SPostSave();

	  mem_fseek(st,4,SEEK_SET);
	  mem_write32(totalsize,st);
	  SaveStateStatus[CurrentState]=1;
	  mem_fclose(st);
	 }
}
Exemple #6
0
int FCEUSS_SaveFP(FILE *st)
{
  static uint32 totalsize;
  static uint8 header[16]="FCS";

  memset(header+4,0,13);
  header[3]=0xFF;
  FCEU_en32lsb(header + 8, FCEU_VERSION_NUMERIC);
  fwrite(header,1,16,st);
  FCEUPPU_SaveState();
  FCEUSND_SaveState();
  totalsize=WriteStateChunk(st,1,SFCPU);
  totalsize+=WriteStateChunk(st,2,SFCPUC);
  totalsize+=WriteStateChunk(st,3,FCEUPPU_STATEINFO);
  totalsize+=WriteStateChunk(st,4,FCEUCTRL_STATEINFO);
  totalsize+=WriteStateChunk(st,5,FCEUSND_STATEINFO);
  if(SPreSave) SPreSave();
  totalsize+=WriteStateChunk(st,0x10,SFMDATA);
  if(SPreSave) SPostSave();

  fseek(st,4,SEEK_SET);
  write32le(totalsize,st);
  return(1);
}
Exemple #7
0
/* This function is called by the game driver(NES, GB, GBA) to save a state. */
int MDFNSS_StateAction(StateMem *st, int load, int data_only, std::vector <SSDescriptor> &sections)
{
	std::vector<SSDescriptor>::iterator section;

	if(load)
	{
		char sname[4];

		for(section = sections.begin(); section != sections.end(); section++)
		{
			if(data_only)
			{
				ReadStateChunk(st, section->sf, ~0, 1);
			}
			else
			{
				int found = 0;
				uint32 tmp_size;
				uint32 total = 0;
				while(smem_read(st, (uint8 *)sname, 4) == 4)
				{
					if(!smem_read32le(st, &tmp_size)) return(0);
					total += tmp_size + 8;
					// Yay, we found the section
					if(!memcmp(sname, section->name, 4))
					{
						if(!ReadStateChunk(st, section->sf, tmp_size, 0))
						{
							printf("Error reading chunk: %.4s\n", section->name);
							return(0);
						}
						found = 1;
						break;
					}
					else
					{
						//puts("SEEK");
						if(smem_seek(st, tmp_size, SEEK_CUR) < 0)
						{
							puts("Chunk seek failure");
							return(0);
						}
					}
				}
				if(smem_seek(st, -(int)total, SEEK_CUR) < 0)
				{
					puts("Reverse seek error");
					return(0);
				}
				if(!found && !section->optional) // Not found. We are sad!
				{
					printf("Chunk missing: %.4s\n", section->name);
					return(0);
				}
			}
		}
	}
	else
		for(section = sections.begin(); section != sections.end(); section++)
		{
			if(!WriteStateChunk(st, section->name, section->sf, data_only))
				return(0);
		}
		return(1);
}
/* This function is called by the game driver(NES, GB, GBA) to save a state. */
int MDFNSS_StateAction(void *st_p, int load, int data_only, std::vector <SSDescriptor> &sections)
{
    StateMem *st = (StateMem*)st_p;
    std::vector<SSDescriptor>::iterator section;

    if(load)
    {
        {
            char sname[32];

            for(section = sections.begin(); section != sections.end(); section++)
            {
                int found = 0;
                uint32 tmp_size;
                uint32 total = 0;

                while(smem_read(st, (uint8 *)sname, 32) == 32)
                {
                    if(smem_read32le(st, &tmp_size) != 4)
                        return(0);

                    total += tmp_size + 32 + 4;

                    // Yay, we found the section
                    if(!strncmp(sname, section->name, 32))
                    {
                        if(!ReadStateChunk(st, section->sf, tmp_size))
                        {
                            printf("Error reading chunk: %s\n", section->name);
                            return(0);
                        }
                        found = 1;
                        break;
                    }
                    else
                    {
                        if(smem_seek(st, tmp_size, SEEK_CUR) < 0)
                        {
                            puts("Chunk seek failure");
                            return(0);
                        }
                    }
                }
                if(smem_seek(st, -total, SEEK_CUR) < 0)
                {
                    puts("Reverse seek error");
                    return(0);
                }
                if(!found && !section->optional) // Not found.  We are sad!
                {
                    printf("Section missing:  %.32s\n", section->name);
                    return(0);
                }
            }
        }
    }
    else
    {
        for(section = sections.begin(); section != sections.end(); section++)
        {
            if(!WriteStateChunk(st, section->name, section->sf))
                return(0);
        }
    }

    return(1);
}