Commit 7d7d759d authored by bbbradsmith's avatar bbbradsmith
Browse files

hatari-mapper needs to serialize its internal state for savestates, not just the contained emulator

parent 52a8d773
......@@ -34,9 +34,6 @@ extern int Reset_Cold(void);
#include <time.h>
#endif
long frame=0;
static unsigned long Ktime=0, LastFPSTime=0;
//VIDEO
extern SDL_Surface *sdlscrn;
unsigned short int bmp[1024*1024];
......@@ -52,9 +49,10 @@ char RPATH[512];
//EMU FLAGS
int NPAGE=-1, KCOL=1, BKGCOLOR=0, MAXPAS=6;
int SHIFTON=-1,MOUSEMODE=-1,SHOWKEY=-1,PAS=4,STATUTON=-1;
int SND; //SOUND ON/OFF
int SND=1; //SOUND ON/OFF
static int firstps=0;
int pauseg=0; //enter_gui
int slowdown=0;
//JOY
int al[2];//left analog1
......@@ -80,6 +78,66 @@ extern int LEDA,LEDB,LEDC;
int BOXDEC= 32+2;
int STAT_BASEY;
// savestate serialization
static bool serialize_forward;
static char* serialize_data;
#define SERIALIZE_STEP \
if (serialize_forward) memcpy(serialize_data, x, sizeof(*x)); \
else memcpy(x, serialize_data, sizeof(*x)); \
serialize_data += sizeof(*x);
void serialize_char(char *x) { SERIALIZE_STEP }
void serialize_int(int *x) { SERIALIZE_STEP }
int hatari_mapper_serialize_size()
{
return 1023;
}
static bool hatari_mapper_serialize_bidi(char* data, char version)
{
// ignoring version, there is only one version so far
serialize_data = data;
serialize_int(&NPAGE);
serialize_int(&KCOL);
serialize_int(&BKGCOLOR);
serialize_int(&MAXPAS);
serialize_int(&SHIFTON);
serialize_int(&MOUSEMODE);
serialize_int(&SHOWKEY);
serialize_int(&PAS);
serialize_int(&STATUTON);
serialize_int(&SND);
serialize_int(&pauseg);
serialize_int(&slowdown);
serialize_int(&fmousex);
serialize_int(&fmousey);
serialize_int(&gmx);
serialize_int(&gmy);
if ((int)(data - serialize_data) > hatari_mapper_serialize_size())
{
fprintf(stderr, "hatari_mapper_serialize_size()=%d insufficient! (Needs: %d)\n", hatari_mapper_serialize_size(), (int)(data - serialize_data));
return false;
}
return true;
}
bool hatari_mapper_serialize(char* data, char version)
{
serialize_forward = true;
return hatari_mapper_serialize_bidi(data, version);
}
bool hatari_mapper_unserialize(const char* data, char version)
{
serialize_forward = false;
return hatari_mapper_serialize_bidi((char*)data, version);
}
// input state
static retro_input_state_t input_state_cb;
static retro_input_poll_t input_poll_cb;
......@@ -124,14 +182,10 @@ long GetTicks(void)
}
int slowdown=0;
//NO SURE FIND BETTER WAY TO COME BACK IN MAIN THREAD IN HATARI GUI
void gui_poll_events(void)
{
slowdown=0;
frame++;
LastFPSTime = Ktime;
co_switch(mainThread);
}
......
......@@ -763,10 +763,14 @@ const char RETRO_SAVE_VERSION = 1;
char* retro_save_buffer = NULL;
int retro_save_pos = 0;
int retro_save_size = 0;
int retro_save_head = 16; // bytes reserved for libretro header/state
int retro_save_head = 1; // bytes reserved for libretro header/state
int retro_save_max = 0;
int retro_save_error = 0;
extern int hatari_mapper_serialize_size();
extern bool hatari_mapper_serialize(char* data, char version);
extern bool hatari_mapper_unserialize(const char* data, char version);
size_t retro_serialize_size(void)
{
return 10 * 1024 * 1024; // Hatari uncompressed savestates seem to be about 6MB
......@@ -775,11 +779,13 @@ size_t retro_serialize_size(void)
bool retro_serialize(void *data_, size_t size)
{
retro_save_max = size;
retro_save_head = hatari_mapper_serialize_size() + 1;
if (size < retro_save_head) return false;
retro_save_buffer = data_;
memset(retro_save_buffer, 0, size);
retro_save_buffer[0] = RETRO_SAVE_VERSION;
retro_save_error = 0;
retro_save_error = hatari_mapper_serialize(data_+1, retro_save_buffer[0]) ? 0 : 1;
retro_save_size = retro_save_head;
MemorySnapShot_Capture("", false);
return retro_save_error == 0;
}
......@@ -787,10 +793,11 @@ bool retro_serialize(void *data_, size_t size)
bool retro_unserialize(const void *data_, size_t size)
{
retro_save_max = size;
retro_save_head = hatari_mapper_serialize_size() + 1;
if (size < retro_save_head) return false;
retro_save_buffer = (void*)data_; // discarding const
if (retro_save_buffer[0] != RETRO_SAVE_VERSION) return false; // unknown version
retro_save_error = 0;
retro_save_error = hatari_mapper_unserialize(data_+1, retro_save_buffer[0]) ? 0 : 1;
retro_save_size = size;
MemorySnapShot_Restore("", false);
return retro_save_error == 0;
......
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