mirror of
https://github.com/libretro/beetle-pce-fast-libretro.git
synced 2024-11-22 23:39:50 +00:00
Cleanup savestate code
This commit is contained in:
parent
d204418002
commit
e83f16af87
@ -409,7 +409,7 @@ int StateAction(StateMem *sm, int load, int data_only)
|
||||
// if(BaseRAM[i] != 0xFF)
|
||||
// printf("%d %02x\n", i, BaseRAM[i]);
|
||||
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "MAIN");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "MAIN", false);
|
||||
|
||||
ret &= HuC6280_StateAction(sm, load, data_only);
|
||||
ret &= VDC_StateAction(sm, load, data_only);
|
||||
@ -759,7 +759,7 @@ int HuC_StateAction(StateMem *sm, int load, int data_only)
|
||||
SFVAR(HuCSF2Latch),
|
||||
SFEND
|
||||
};
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "HuC");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "HuC", false);
|
||||
|
||||
if(load)
|
||||
HuCSF2Latch &= 0x3;
|
||||
|
@ -302,7 +302,7 @@ int ArcadeCard::StateAction(StateMem *sm, int load, int data_only)
|
||||
SFEND
|
||||
};
|
||||
|
||||
if(!MDFNSS_StateAction(sm, load, data_only, ACUsedRegs, "ArcadeCardUsed"))
|
||||
if(!MDFNSS_StateAction(sm, load, data_only, ACUsedRegs, "ArcadeCardUsed", false))
|
||||
return(0);
|
||||
|
||||
SFORMAT ACStateRegs[] =
|
||||
@ -325,7 +325,7 @@ int ArcadeCard::StateAction(StateMem *sm, int load, int data_only)
|
||||
SFARRAY(ACRAM, ACRAMUsed ? 0x200000 : 0x0),
|
||||
SFEND
|
||||
};
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, ACStateRegs, "ArcadeCard");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, ACStateRegs, "ArcadeCard", false);
|
||||
|
||||
|
||||
return(ret);
|
||||
|
@ -763,7 +763,7 @@ int HuC6280_StateAction(StateMem *sm, int load, int data_only)
|
||||
SFEND
|
||||
};
|
||||
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, SFCPU, "CPU");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, SFCPU, "CPU", false);
|
||||
|
||||
if(load)
|
||||
{
|
||||
|
@ -229,7 +229,7 @@ int INPUT_StateAction(StateMem *sm, int load, int data_only)
|
||||
SFVAR(read_index),
|
||||
SFEND
|
||||
};
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "JOY");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "JOY", false);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
@ -899,7 +899,7 @@ static int ADPCM_StateAction(StateMem *sm, int load, int data_only)
|
||||
SFEND
|
||||
};
|
||||
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "APCM");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "APCM", false);
|
||||
if(load)
|
||||
{
|
||||
MSM5205.SetSample(ad_sample);
|
||||
@ -932,7 +932,7 @@ int PCECD_StateAction(StateMem *sm, int load, int data_only)
|
||||
SFEND
|
||||
};
|
||||
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "PECD");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "PECD", false);
|
||||
ret &= PCECD_Drive_StateAction(sm, load, data_only, "CDRM");
|
||||
ret &= ADPCM_StateAction(sm, load, data_only);
|
||||
|
||||
|
@ -1299,7 +1299,7 @@ int PCECD_Drive_StateAction(StateMem * sm, int load, int data_only, const char *
|
||||
SFEND
|
||||
};
|
||||
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, sname);
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, sname, false);
|
||||
|
||||
if(load)
|
||||
{
|
||||
|
@ -608,7 +608,7 @@ int PCEFast_PSG::StateAction(StateMem *sm, int load, int data_only)
|
||||
SFEND
|
||||
};
|
||||
tmpstr[3] = '0' + ch;
|
||||
ret &= MDFNSS_StateAction(sm, load, data_only, CH_StateRegs, tmpstr);
|
||||
ret &= MDFNSS_StateAction(sm, load, data_only, CH_StateRegs, tmpstr, false);
|
||||
}
|
||||
|
||||
SFORMAT PSG_StateRegs[] =
|
||||
@ -624,7 +624,7 @@ int PCEFast_PSG::StateAction(StateMem *sm, int load, int data_only)
|
||||
SFEND
|
||||
};
|
||||
|
||||
ret &= MDFNSS_StateAction(sm, load, data_only, PSG_StateRegs, "PSG");
|
||||
ret &= MDFNSS_StateAction(sm, load, data_only, PSG_StateRegs, "PSG", false);
|
||||
|
||||
if(load)
|
||||
{
|
||||
|
@ -1093,7 +1093,7 @@ int VDC_StateAction(StateMem *sm, int load, int data_only)
|
||||
};
|
||||
|
||||
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, VCE_StateRegs, "VCE");
|
||||
int ret = MDFNSS_StateAction(sm, load, data_only, VCE_StateRegs, "VCE", false);
|
||||
|
||||
int chip = 0;
|
||||
{
|
||||
@ -1155,7 +1155,7 @@ int VDC_StateAction(StateMem *sm, int load, int data_only)
|
||||
SFEND
|
||||
};
|
||||
|
||||
ret &= MDFNSS_StateAction(sm, load, data_only, VDC_StateRegs, "VDC0");
|
||||
ret &= MDFNSS_StateAction(sm, load, data_only, VDC_StateRegs, "VDC0", false);
|
||||
|
||||
if(load)
|
||||
{
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
#include <boolean.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "mednafen.h"
|
||||
#include "driver.h"
|
||||
#include "general.h"
|
||||
@ -375,69 +373,60 @@ static int ReadStateChunk(StateMem *st, SFORMAT *sf, int size)
|
||||
}
|
||||
|
||||
/* 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, std::vector <SSDescriptor> §ions)
|
||||
static int MDFNSS_StateAction_internal(void *st_p, int load, int data_only, SSDescriptor *section)
|
||||
{
|
||||
StateMem *st = (StateMem*)st_p;
|
||||
std::vector<SSDescriptor>::iterator section;
|
||||
|
||||
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)
|
||||
{
|
||||
char sname[32];
|
||||
if(smem_read32le(st, &tmp_size) != 4)
|
||||
return(0);
|
||||
|
||||
for(section = sections.begin(); section != sections.end(); section++)
|
||||
total += tmp_size + 32 + 4;
|
||||
|
||||
// Yay, we found the section
|
||||
if(!strncmp(sname, section->name, 32))
|
||||
{
|
||||
int found = 0;
|
||||
uint32_t tmp_size;
|
||||
uint32_t total = 0;
|
||||
|
||||
while(smem_read(st, (uint8_t *)sname, 32) == 32)
|
||||
if(!ReadStateChunk(st, section->sf, tmp_size))
|
||||
{
|
||||
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");
|
||||
printf("Error reading chunk: %s\n", section->name);
|
||||
return(0);
|
||||
}
|
||||
if(!found && !section->optional) // Not found. We are sad!
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(smem_seek(st, tmp_size, SEEK_CUR) < 0)
|
||||
{
|
||||
printf("Section missing: %.32s\n", section->name);
|
||||
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);
|
||||
}
|
||||
if(!WriteStateChunk(st, section->name, section->sf))
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(1);
|
||||
@ -445,11 +434,14 @@ static int MDFNSS_StateAction_internal(void *st_p, int load, int data_only, std:
|
||||
|
||||
int MDFNSS_StateAction(void *st_p, int load, int data_only, SFORMAT *sf, const char *name, bool optional)
|
||||
{
|
||||
SSDescriptor love;
|
||||
StateMem *st = (StateMem*)st_p;
|
||||
std::vector <SSDescriptor> love;
|
||||
|
||||
love.push_back(SSDescriptor(sf, name, optional));
|
||||
return(MDFNSS_StateAction_internal(st, load, 0, love));
|
||||
love.sf = sf;
|
||||
love.name = name;
|
||||
love.optional = optional;
|
||||
|
||||
return(MDFNSS_StateAction_internal(st, load, 0, &love));
|
||||
}
|
||||
|
||||
int MDFNSS_SaveSM(void *st_p, int, int, const void*, const void*, const void*)
|
||||
|
@ -90,25 +90,13 @@ INLINE uint32_t SF_FORCE_D(double *) { return(0); }
|
||||
#define SFEND { 0, 0, 0, 0 }
|
||||
|
||||
// State-Section Descriptor
|
||||
class SSDescriptor
|
||||
struct SSDescriptor
|
||||
{
|
||||
public:
|
||||
SSDescriptor(SFORMAT *n_sf, const char *n_name, bool n_optional = 0)
|
||||
{
|
||||
sf = n_sf;
|
||||
name = n_name;
|
||||
optional = n_optional;
|
||||
}
|
||||
~SSDescriptor(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SFORMAT *sf;
|
||||
const char *name;
|
||||
bool optional;
|
||||
SFORMAT *sf;
|
||||
const char *name;
|
||||
bool optional;
|
||||
};
|
||||
|
||||
int MDFNSS_StateAction(void *st, int load, int data_only, SFORMAT *sf, const char *name, bool optional = 0);
|
||||
int MDFNSS_StateAction(void *st, int load, int data_only, SFORMAT *sf, const char *name, bool optional);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user