Commit d74ecc05 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Cleanups

parent 53b8c542
......@@ -108,25 +108,6 @@ struct race_state_0x10 /* Older state format */
typedef struct race_state_0x11 race_state_t;
static int state_store(race_state_t *rs);
static int state_restore(race_state_t *rs);
static int state_restore_0x10(FILE *stream);
int state_store_mem(void *state)
{
return state_store((race_state_t*)state);
}
int state_restore_mem(void *state)
{
return state_restore((race_state_t*)state);
}
int state_get_size(void)
{
return sizeof(race_state_t);
}
static int state_store(race_state_t *rs)
{
int i = 0;
......@@ -279,83 +260,6 @@ static int state_restore(race_state_t *rs)
return 1;
}
int state_restore(FILE *stream)
{
/* Note current position (in case of compatibility rewinds */
long read_pos = ftell(stream);
/* Read header */
struct race_state_header rsh;
if (fread(&rsh, sizeof(rsh), 1, stream) < 1)
return 0;
/* Verify state version */
if (rsh.state_version == 0x10)
{
fseek(stream, read_pos, SEEK_SET); /* Rewind and load old format */
return state_restore_0x10(stream);
}
else if (rsh.state_version != CURRENT_SAVE_STATE_VERSION)
return 0; /* Unsupported version */
/* Verify ROM signature */
if (memcmp(mainrom, rsh.rom_signature, sizeof(rsh.rom_signature)) != 0)
return 0;
/* Read state data */
race_state_t rs;
if (fread(&rs, sizeof(rs), 1, stream) < 1)
return 0;
/* Restore state */
return state_restore(&rs);
}
int state_store(FILE *stream)
{
/* Set version & ROM signature information */
struct race_state_header rsh;
rsh.state_version = CURRENT_SAVE_STATE_VERSION;
memcpy(rsh.rom_signature, mainrom, sizeof(rsh.rom_signature));
/* Initialize state data */
race_state_t rs;
if (!state_store(&rs))
return 0;
/* Write to file */
if (fwrite(&rsh, sizeof(rsh), 1, stream) < 1)
return 0;
if (fwrite(&rs, sizeof(rs), 1, stream) < 1)
return 0;
return 1;
}
int state_store(char* filename)
{
FILE *stream;
if (!(stream = fopen(filename, "w")))
return 0;
int status = state_store(stream);
fclose(stream);
return status;
}
int state_restore(char* filename)
{
FILE *stream;
if (!(stream = fopen(filename, "r")))
return 0;
int status = state_restore(stream);
fclose(stream);
return status;
}
static int state_restore_0x10(FILE *stream)
{
struct race_state_0x10 rs;
......@@ -443,3 +347,95 @@ static int state_restore_0x10(FILE *stream)
return 1;
}
int state_store_mem(void *state)
{
return state_store((race_state_t*)state);
}
int state_restore_mem(void *state)
{
return state_restore((race_state_t*)state);
}
int state_get_size(void)
{
return sizeof(race_state_t);
}
int state_restore(FILE *stream)
{
/* Note current position (in case of compatibility rewinds */
long read_pos = ftell(stream);
/* Read header */
struct race_state_header rsh;
if (fread(&rsh, sizeof(rsh), 1, stream) < 1)
return 0;
/* Verify state version */
if (rsh.state_version == 0x10)
{
fseek(stream, read_pos, SEEK_SET); /* Rewind and load old format */
return state_restore_0x10(stream);
}
else if (rsh.state_version != CURRENT_SAVE_STATE_VERSION)
return 0; /* Unsupported version */
/* Verify ROM signature */
if (memcmp(mainrom, rsh.rom_signature, sizeof(rsh.rom_signature)) != 0)
return 0;
/* Read state data */
race_state_t rs;
if (fread(&rs, sizeof(rs), 1, stream) < 1)
return 0;
/* Restore state */
return state_restore(&rs);
}
int state_store(FILE *stream)
{
/* Set version & ROM signature information */
struct race_state_header rsh;
rsh.state_version = CURRENT_SAVE_STATE_VERSION;
memcpy(rsh.rom_signature, mainrom, sizeof(rsh.rom_signature));
/* Initialize state data */
race_state_t rs;
if (!state_store(&rs))
return 0;
/* Write to file */
if (fwrite(&rsh, sizeof(rsh), 1, stream) < 1)
return 0;
if (fwrite(&rs, sizeof(rs), 1, stream) < 1)
return 0;
return 1;
}
int state_store(char* filename)
{
FILE *stream;
if (!(stream = fopen(filename, "w")))
return 0;
int status = state_store(stream);
fclose(stream);
return status;
}
int state_restore(char* filename)
{
FILE *stream;
if (!(stream = fopen(filename, "r")))
return 0;
int status = state_restore(stream);
fclose(stream);
return status;
}
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