This commit is contained in:
twinaphex 2021-09-18 16:55:50 +02:00
parent af56c54d18
commit 3818257257
2 changed files with 6 additions and 55 deletions

View File

@ -27,7 +27,7 @@
#define RLSB MDFNSTATE_RLSB //0x80000000 #define RLSB MDFNSTATE_RLSB //0x80000000
int32_t smem_read(StateMem *st, void *buffer, uint32_t len) static int32_t smem_read(StateMem *st, void *buffer, uint32_t len)
{ {
if ((len + st->loc) > st->len) if ((len + st->loc) > st->len)
return 0; return 0;
@ -38,7 +38,7 @@ int32_t smem_read(StateMem *st, void *buffer, uint32_t len)
return(len); return(len);
} }
int32_t smem_write(StateMem *st, void *buffer, uint32_t len) static int32_t smem_write(StateMem *st, void *buffer, uint32_t len)
{ {
if ((len + st->loc) > st->malloced) if ((len + st->loc) > st->malloced)
{ {
@ -58,15 +58,7 @@ int32_t smem_write(StateMem *st, void *buffer, uint32_t len)
return(len); return(len);
} }
int32_t smem_putc(StateMem *st, int value) static int32_t smem_seek(StateMem *st, uint32_t offset, int whence)
{
uint8_t tmpval = value;
if(smem_write(st, &tmpval, 1) != 1)
return(-1);
return(1);
}
int32_t smem_seek(StateMem *st, uint32_t offset, int whence)
{ {
switch(whence) switch(whence)
{ {
@ -84,7 +76,7 @@ int32_t smem_seek(StateMem *st, uint32_t offset, int whence)
return(0); return(0);
} }
int smem_write32le(StateMem *st, uint32_t b) static int smem_write32le(StateMem *st, uint32_t b)
{ {
uint8_t s[4]; uint8_t s[4];
s[0]=b; s[0]=b;
@ -94,7 +86,7 @@ int smem_write32le(StateMem *st, uint32_t b)
return((smem_write(st, s, 4)<4)?0:4); return((smem_write(st, s, 4)<4)?0:4);
} }
int smem_read32le(StateMem *st, uint32_t *b) static int smem_read32le(StateMem *st, uint32_t *b)
{ {
uint8_t s[4]; uint8_t s[4];
@ -246,38 +238,6 @@ static SFORMAT *FindSF(const char *name, SFORMAT *sf)
return NULL; return NULL;
} }
// Fast raw chunk reader
static void DOReadChunk(StateMem *st, SFORMAT *sf)
{
while(sf->size || sf->name) // Size can sometimes be zero, so also check for the text name.
// These two should both be zero only at the end of a struct.
{
if(!sf->size || !sf->v)
{
sf++;
continue;
}
if(sf->size == (uint32_t) ~0) // Link to another SFORMAT struct
{
DOReadChunk(st, (SFORMAT *)sf->v);
sf++;
continue;
}
int32_t bytesize = sf->size;
// Loading raw data, bool types are stored as they appear in memory, not as single bytes in the full state format.
// In the SFORMAT structure, the size member for bool entries is the number of bool elements, not the total in-memory size,
// so we adjust it here.
if(sf->flags & MDFNSTATE_BOOL)
bytesize *= sizeof(bool);
smem_read(st, (uint8_t *)sf->v, bytesize);
sf++;
}
}
static int ReadStateChunk(StateMem *st, SFORMAT *sf, int size) static int ReadStateChunk(StateMem *st, SFORMAT *sf, int size)
{ {
int temp = st->loc; int temp = st->loc;

View File

@ -9,18 +9,9 @@ typedef struct
uint32_t loc; uint32_t loc;
uint32_t len; uint32_t len;
uint32_t malloced; uint32_t malloced;
uint32_t initial_malloc; // A setting! uint32_t initial_malloc; /* A setting! */
} StateMem; } StateMem;
// Eh, we abuse the smem_* in-memory stream code
// in a few other places. :)
int32_t smem_read(StateMem *st, void *buffer, uint32_t len);
int32_t smem_write(StateMem *st, void *buffer, uint32_t len);
int32_t smem_putc(StateMem *st, int value);
int32_t smem_seek(StateMem *st, uint32_t offset, int whence);
int smem_write32le(StateMem *st, uint32_t b);
int smem_read32le(StateMem *st, uint32_t *b);
int MDFNSS_SaveSM(void *st, int, int, const void*, const void*, const void*); int MDFNSS_SaveSM(void *st, int, int, const void*, const void*, const void*);
int MDFNSS_LoadSM(void *st, int, int); int MDFNSS_LoadSM(void *st, int, int);