X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fstate.c;h=3969e188b0c388f4a501ac789071537d63e663a1;hb=045a4c528a71e5513acc2cfb8a77e31efcad5d87;hp=6b91d484d286dccf240efd5cb8b3b6b914831631;hpb=ed4402a7dfd12dbbf34c547b438a671ae8114197;p=picodrive.git diff --git a/pico/state.c b/pico/state.c index 6b91d48..3969e18 100644 --- a/pico/state.c +++ b/pico/state.c @@ -11,15 +11,11 @@ #include "../cpu/sh2/sh2.h" #include "sound/ym2612.h" +#include "state.h" // sn76496 extern int *sn76496_regs; -typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file); -typedef size_t (areaeof)(void *file); -typedef int (areaseek)(void *file, long offset, int whence); -typedef int (areaclose)(void *file); - static arearw *areaRead; static arearw *areaWrite; static areaeof *areaEof; @@ -174,6 +170,9 @@ typedef enum { CHUNK_SDRAM, CHUNK_DRAM, CHUNK_32XPAL, + CHUNK_32X_EVT, + CHUNK_32X_FIRST = CHUNK_MSH2, + CHUNK_32X_LAST = CHUNK_32X_EVT, // CHUNK_DEFAULT_COUNT, CHUNK_CARTHW_ = CHUNK_CARTHW, // defined in PicoInt @@ -222,6 +221,7 @@ static const char * const chunk_names[] = { "SDRAM", "DRAM", "PAL", + "events", }; static int write_chunk(chunk_name_e name, int len, void *data, void *file) @@ -334,7 +334,9 @@ static int state_save(void *file) CHECKED_WRITE_BUFF(CHUNK_DRAM, Pico32xMem->dram); CHECKED_WRITE_BUFF(CHUNK_32XPAL, Pico32xMem->pal); - sh2s[0].m68krcycles_done = sh2s[1].m68krcycles_done = SekCycleCnt; + memset(buff, 0, 0x40); + memcpy(buff, event_times, sizeof(event_times)); + CHECKED_WRITE(CHUNK_32X_EVT, 0x40, buff); } #endif @@ -384,6 +386,7 @@ static int state_load(void *file) unsigned char buff_m68k[0x60], buff_s68k[0x60]; unsigned char buff_z80[Z80_STATE_SIZE]; unsigned char buff_sh2[SH2_STATE_SIZE]; + unsigned char buff[0x40]; unsigned char chunk; void *ym2612_regs; char header[8]; @@ -406,8 +409,8 @@ static int state_load(void *file) if (len < 0 || len > 1024*512) R_ERROR_RETURN("bad length"); if (CHUNK_S68K <= chunk && chunk <= CHUNK_MISC_CD && !(PicoAHW & PAHW_MCD)) R_ERROR_RETURN("cd chunk in non CD state?"); - if (CHUNK_MSH2 <= chunk && chunk <= CHUNK_32XPAL && !(PicoAHW & PAHW_32X)) - R_ERROR_RETURN("32x chunk in non 32x state?"); + if (CHUNK_32X_FIRST <= chunk && chunk <= CHUNK_32X_LAST && !(PicoAHW & PAHW_32X)) + Pico32xStartup(); switch (chunk) { @@ -478,6 +481,11 @@ static int state_load(void *file) case CHUNK_SDRAM: CHECKED_READ_BUFF(Pico32xMem->sdram); break; case CHUNK_DRAM: CHECKED_READ_BUFF(Pico32xMem->dram); break; case CHUNK_32XPAL: CHECKED_READ_BUFF(Pico32xMem->pal); break; + + case CHUNK_32X_EVT: + CHECKED_READ_BUFF(buff); + memcpy(event_times, buff, sizeof(event_times)); + break; #endif default: if (carthw_chunks != NULL) @@ -507,18 +515,22 @@ readend: if (!(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1)) cdda_start_play(); - - SekUnpackCpu(buff_s68k, 1); } + if (PicoAHW & PAHW_32X) + Pico32xStateLoaded(1); + // must unpack 68k and z80 after banks are set up if (!(PicoAHW & PAHW_SMS)) SekUnpackCpu(buff_m68k, 0); + if (PicoAHW & PAHW_MCD) + SekUnpackCpu(buff_s68k, 1); z80_unpack(buff_z80); + // due to dep from 68k cycles.. if (PicoAHW & PAHW_32X) - Pico32xStateLoaded(); + Pico32xStateLoaded(0); return 0; } @@ -578,15 +590,10 @@ readend: return 0; } -int PicoState(const char *fname, int is_save) +static int pico_state_internal(void *afile, int is_save) { - void *afile = NULL; int ret; - afile = open_save_file(fname, is_save); - if (afile == NULL) - return -1; - if (is_save) ret = state_save(afile); else { @@ -601,10 +608,35 @@ int PicoState(const char *fname, int is_save) Pico.m.dirtyPal = 1; } + return ret; +} + +int PicoState(const char *fname, int is_save) +{ + void *afile = NULL; + int ret; + + afile = open_save_file(fname, is_save); + if (afile == NULL) + return -1; + + ret = pico_state_internal(afile, is_save); areaClose(afile); return ret; } +int PicoStateFP(void *afile, int is_save, + arearw *read, arearw *write, areaeof *eof, areaseek *seek) +{ + areaRead = read; + areaWrite = write; + areaEof = eof; + areaSeek = seek; + areaClose = NULL; + + return pico_state_internal(afile, is_save); +} + int PicoStateLoadGfx(const char *fname) { void *afile;