Unverified Commit 1b5afcaa authored by jdgleaver's avatar jdgleaver Committed by GitHub
Browse files

Improve save state efficiency (#102)

parent 8133b0a0
Pipeline #102006 passed with stages
in 1 minute and 20 seconds
......@@ -753,12 +753,14 @@ size_t retro_serialize_size(void)
bool retro_serialize(void *data, size_t size)
{
LSS_FILE fp;
if(!lynx)
return false;
fp.memptr = (UBYTE *) data;
fp.memptr = (UBYTE *)data;
fp.index = 0;
fp.index_limit = size;
fp.nul_stream = 0;
return lynx->ContextSave(&fp);
}
......@@ -766,12 +768,14 @@ bool retro_serialize(void *data, size_t size)
bool retro_unserialize(const void *data, size_t size)
{
LSS_FILE fp;
if(!lynx)
return false;
fp.memptr = (UBYTE *) data;
fp.memptr = (UBYTE *)data;
fp.index = 0;
fp.index_limit = size;
fp.nul_stream = 0;
return lynx->ContextLoad(&fp);
}
......
......@@ -66,9 +66,11 @@ extern void lynx_decrypt(unsigned char * result, const unsigned char * encrypted
int lss_read(void* dest, int varsize, int varcount, LSS_FILE *fp)
{
ULONG copysize=varsize*varcount;
if((fp->index + copysize) > fp->index_limit)
copysize=fp->index_limit - fp->index;
memcpy(dest,fp->memptr+fp->index,copysize);
if (!fp->nul_stream) {
if((fp->index + copysize) > fp->index_limit)
copysize=fp->index_limit - fp->index;
memcpy(dest,fp->memptr+fp->index,copysize);
}
fp->index+=copysize;
return copysize;
}
......@@ -76,7 +78,11 @@ int lss_read(void* dest, int varsize, int varcount, LSS_FILE *fp)
int lss_write(void* src, int varsize, int varcount, LSS_FILE *fp)
{
ULONG copysize=varsize*varcount;
memcpy(fp->memptr+fp->index,src,copysize);
if (!fp->nul_stream) {
if((fp->index + copysize) > fp->index_limit)
copysize=fp->index_limit - fp->index;
memcpy(fp->memptr+fp->index,src,copysize);
}
fp->index+=copysize;
return copysize;
}
......@@ -84,7 +90,11 @@ int lss_write(void* src, int varsize, int varcount, LSS_FILE *fp)
int lss_printf(LSS_FILE *fp, const char *str)
{
ULONG copysize=strlen(str);
memcpy(fp->memptr+fp->index,str,copysize);
if (!fp->nul_stream) {
if((fp->index + copysize) > fp->index_limit)
copysize=fp->index_limit - fp->index;
memcpy(fp->memptr+fp->index,str,copysize);
}
fp->index+=copysize;
return copysize;
}
......@@ -422,15 +432,14 @@ void CSystem::Reset(void)
size_t CSystem::ContextSize()
{
LSS_FILE fp;
const int max_size = 0x40000 + HANDY_AUDIO_BUFFER_SIZE;
fp.memptr = (UBYTE *) malloc(max_size);
fp.index = 0;
fp.index_limit = max_size;
fp.memptr = NULL;
fp.index = 0;
fp.index_limit = 0;
fp.nul_stream = 1;
ContextSave(&fp);
free(fp.memptr);
return fp.index;
}
......
......@@ -139,6 +139,7 @@ typedef struct lssfile
UBYTE *memptr;
ULONG index;
ULONG index_limit;
UBYTE nul_stream;
} LSS_FILE;
int lss_read(void* dest, int varsize, int varcount, LSS_FILE *fp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment