From: notaz Date: Mon, 8 Jul 2013 00:12:01 +0000 (+0300) Subject: save event times to savestates X-Git-Tag: v1.85~60 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=picodrive.git;a=commitdiff_plain;h=6a98f03eefe99c0e316199fa2e8da4eae7653a1f save event times to savestates --- diff --git a/pico/32x/32x.c b/pico/32x/32x.c index 1b74c2d..dbd3fa8 100644 --- a/pico/32x/32x.c +++ b/pico/32x/32x.c @@ -1,6 +1,6 @@ /* * PicoDrive - * (C) notaz, 2009,2010 + * (C) notaz, 2009,2010,2013 * * This work is licensed under the terms of MAME license. * See COPYING file in the top-level directory. @@ -225,7 +225,7 @@ static void fillend_event(unsigned int now) typedef void (event_cb)(unsigned int now); -static unsigned int event_times[P32X_EVENT_COUNT]; +unsigned int event_times[P32X_EVENT_COUNT]; static unsigned int event_time_next; static event_cb *event_cbs[] = { [P32X_EVENT_PWM] = pwm_irq_event, diff --git a/pico/32x/memory.c b/pico/32x/memory.c index 109aaf4..e694066 100644 --- a/pico/32x/memory.c +++ b/pico/32x/memory.c @@ -1619,9 +1619,11 @@ void PicoMemSetup32x(void) void Pico32xStateLoaded(void) { + sh2s[0].m68krcycles_done = sh2s[1].m68krcycles_done = SekCycleCntT; + p32x_poll_event(3, 0); + bank_switch(Pico32x.regs[4 / 2]); Pico32xSwapDRAM((Pico32x.vdp_regs[0x0a / 2] & P32XV_FS) ^ P32XV_FS); - p32x_poll_event(3, 0); Pico32x.dirty_pal = 1; memset(Pico32xMem->pwm, 0, sizeof(Pico32xMem->pwm)); p32x_timers_recalc(); diff --git a/pico/pico_int.h b/pico/pico_int.h index 8d1a337..bcb971e 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -722,6 +722,13 @@ void PicoFrameDrawOnlyMS(void); // 32x/32x.c #ifndef NO_32X extern struct Pico32x Pico32x; +enum p32x_event { + P32X_EVENT_PWM, + P32X_EVENT_FILLEND, + P32X_EVENT_COUNT, +}; +extern unsigned int event_times[P32X_EVENT_COUNT]; + void Pico32xInit(void); void PicoPower32x(void); void PicoReset32x(void); @@ -731,12 +738,6 @@ void PicoFrame32x(void); void p32x_sync_sh2s(unsigned int m68k_target); void p32x_update_irls(int nested_call); void p32x_reset_sh2s(void); - -enum p32x_event { - P32X_EVENT_PWM, - P32X_EVENT_FILLEND, - P32X_EVENT_COUNT, -}; void p32x_event_schedule(enum p32x_event event, unsigned int now, int after); // 32x/memory.c diff --git a/pico/sek.c b/pico/sek.c index 39168a9..85bfd28 100644 --- a/pico/sek.c +++ b/pico/sek.c @@ -219,7 +219,8 @@ PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub) cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0; #endif - *(unsigned int *)(cpu+0x40)=pc; + *(unsigned int *)(cpu+0x40) = pc; + *(unsigned int *)(cpu+0x50) = SekCycleCntT; } PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) @@ -256,6 +257,7 @@ PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) context->execinfo &= ~FM68K_HALTED; if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED; #endif + SekCycleCntT = *(unsigned int *)(cpu+0x50); } diff --git a/pico/state.c b/pico/state.c index 6b91d48..761b64c 100644 --- a/pico/state.c +++ b/pico/state.c @@ -174,6 +174,7 @@ typedef enum { CHUNK_SDRAM, CHUNK_DRAM, CHUNK_32XPAL, + CHUNK_32X_EVT, // CHUNK_DEFAULT_COUNT, CHUNK_CARTHW_ = CHUNK_CARTHW, // defined in PicoInt @@ -222,6 +223,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 +336,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 +388,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]; @@ -478,6 +483,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)