sram bugfix + savestate refactoring

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@744 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-08-10 14:22:50 +00:00
parent 0f4090a90a
commit 85bd209c99
3 changed files with 11 additions and 84 deletions

View file

@ -1,4 +1,4 @@
// (c) Copyright 2006-2007 notaz, All rights reserved. // (c) Copyright 2006-2009 notaz, All rights reserved.
// Free for non-commercial use. // Free for non-commercial use.
// For commercial use, separate licencing terms must be obtained. // For commercial use, separate licencing terms must be obtained.
@ -22,7 +22,6 @@
#include <pico/pico_int.h> #include <pico/pico_int.h>
#include <pico/patch.h> #include <pico/patch.h>
#include <pico/cd/cue.h> #include <pico/cd/cue.h>
#include <zlib/zlib.h>
#define STATUS_MSG_TIMEOUT 2000 #define STATUS_MSG_TIMEOUT 2000
@ -516,13 +515,14 @@ int emu_reload_rom(char *rom_fname)
emu_status_msg(Pico.m.pal ? "PAL SYSTEM / 50 FPS" : "NTSC SYSTEM / 60 FPS"); emu_status_msg(Pico.m.pal ? "PAL SYSTEM / 50 FPS" : "NTSC SYSTEM / 60 FPS");
} }
strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);
rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0;
rom_loaded = 1;
// load SRAM for this ROM // load SRAM for this ROM
if (currentConfig.EmuOpt & EOPT_EN_SRAM) if (currentConfig.EmuOpt & EOPT_EN_SRAM)
emu_save_load_game(1, 1); emu_save_load_game(1, 1);
strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);
rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0;
rom_loaded = 1;
return 1; return 1;
fail2: fail2:
@ -766,18 +766,6 @@ void update_movie(void)
} }
} }
static size_t gzRead2(void *p, size_t _size, size_t _n, void *file)
{
return gzread(file, p, _n);
}
static size_t gzWrite2(void *p, size_t _size, size_t _n, void *file)
{
return gzwrite(file, p, _n);
}
static int try_ropen_file(const char *fname) static int try_ropen_file(const char *fname)
{ {
FILE *f; FILE *f;
@ -842,23 +830,6 @@ int emu_check_save_file(int slot)
return emu_get_save_fname(1, 0, slot) ? 1 : 0; return emu_get_save_fname(1, 0, slot) ? 1 : 0;
} }
void emu_setSaveStateCbs(int gz)
{
if (gz) {
areaRead = gzRead2;
areaWrite = gzWrite2;
areaEof = (areaeof *) gzeof;
areaSeek = (areaseek *) gzseek;
areaClose = (areaclose *) gzclose;
} else {
areaRead = (arearw *) fread;
areaWrite = (arearw *) fwrite;
areaEof = (areaeof *) feof;
areaSeek = (areaseek *) fseek;
areaClose = (areaclose *) fclose;
}
}
int emu_save_load_game(int load, int sram) int emu_save_load_game(int load, int sram)
{ {
int ret = 0; int ret = 0;
@ -929,34 +900,13 @@ int emu_save_load_game(int load, int sram)
} }
else else
{ {
void *PmovFile = NULL; ret = PicoState(saveFname, !load);
if (strcmp(saveFname + strlen(saveFname) - 3, ".gz") == 0) if (!ret) {
{
if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {
emu_setSaveStateCbs(1);
if (!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);
}
}
else
{
if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {
emu_setSaveStateCbs(0);
}
}
if(PmovFile) {
ret = PmovState(load ? 6 : 5, PmovFile);
areaClose(PmovFile);
PmovFile = 0;
if (load) Pico.m.dirtyPal=1;
#ifndef NO_SYNC #ifndef NO_SYNC
else sync(); if (!load) sync();
#endif #endif
}
else ret = -1;
if (!ret)
emu_status_msg(load ? "STATE LOADED" : "STATE SAVED"); emu_status_msg(load ? "STATE LOADED" : "STATE SAVED");
else } else {
{
emu_status_msg(load ? "LOAD FAILED" : "SAVE FAILED"); emu_status_msg(load ? "LOAD FAILED" : "SAVE FAILED");
ret = -1; ret = -1;
} }

View file

@ -113,7 +113,6 @@ int emu_write_config(int game);
char *emu_get_save_fname(int load, int is_sram, int slot); char *emu_get_save_fname(int load, int is_sram, int slot);
int emu_check_save_file(int slot); int emu_check_save_file(int slot);
void emu_setSaveStateCbs(int gz);
void emu_text_out8 (int x, int y, const char *text); void emu_text_out8 (int x, int y, const char *text);
void emu_text_out16(int x, int y, const char *text); void emu_text_out16(int x, int y, const char *text);

View file

@ -20,7 +20,6 @@
#include <pico/pico_int.h> #include <pico/pico_int.h>
#include <pico/patch.h> #include <pico/patch.h>
#include <zlib/zlib.h>
#define array_size(x) (sizeof(x) / sizeof(x[0])) #define array_size(x) (sizeof(x) / sizeof(x[0]))
@ -971,7 +970,7 @@ static void draw_savestate_bg(int slot)
struct PicoVideo tmp_pv; struct PicoVideo tmp_pv;
unsigned short tmp_cram[0x40]; unsigned short tmp_cram[0x40];
unsigned short tmp_vsram[0x40]; unsigned short tmp_vsram[0x40];
void *tmp_vram, *file; void *tmp_vram;
char *fname; char *fname;
fname = emu_get_save_fname(1, 0, slot); fname = emu_get_save_fname(1, 0, slot);
@ -985,28 +984,7 @@ static void draw_savestate_bg(int slot)
memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram)); memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video)); memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) { PicoStateLoadVDP(fname);
file = gzopen(fname, "rb");
emu_setSaveStateCbs(1);
} else {
file = fopen(fname, "rb");
emu_setSaveStateCbs(0);
}
if (file) {
if (PicoAHW & PAHW_MCD) {
PicoCdLoadStateGfx(file);
} else {
areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
areaSeek(file, 0x2000, SEEK_CUR);
areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
areaSeek(file, 0x221a0, SEEK_SET);
areaRead(&Pico.video, 1, sizeof(Pico.video), file);
}
areaClose(file);
}
/* do a frame and fetch menu bg */ /* do a frame and fetch menu bg */
pemu_forced_frame(POPT_EN_SOFTSCALE); pemu_forced_frame(POPT_EN_SOFTSCALE);