save event times to savestates

This commit is contained in:
notaz 2013-07-08 03:12:01 +03:00
parent 65514d85d5
commit 6a98f03eef
5 changed files with 26 additions and 11 deletions

View file

@ -1,6 +1,6 @@
/* /*
* PicoDrive * PicoDrive
* (C) notaz, 2009,2010 * (C) notaz, 2009,2010,2013
* *
* This work is licensed under the terms of MAME license. * This work is licensed under the terms of MAME license.
* See COPYING file in the top-level directory. * 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); 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 unsigned int event_time_next;
static event_cb *event_cbs[] = { static event_cb *event_cbs[] = {
[P32X_EVENT_PWM] = pwm_irq_event, [P32X_EVENT_PWM] = pwm_irq_event,

View file

@ -1619,9 +1619,11 @@ void PicoMemSetup32x(void)
void Pico32xStateLoaded(void) void Pico32xStateLoaded(void)
{ {
sh2s[0].m68krcycles_done = sh2s[1].m68krcycles_done = SekCycleCntT;
p32x_poll_event(3, 0);
bank_switch(Pico32x.regs[4 / 2]); bank_switch(Pico32x.regs[4 / 2]);
Pico32xSwapDRAM((Pico32x.vdp_regs[0x0a / 2] & P32XV_FS) ^ P32XV_FS); Pico32xSwapDRAM((Pico32x.vdp_regs[0x0a / 2] & P32XV_FS) ^ P32XV_FS);
p32x_poll_event(3, 0);
Pico32x.dirty_pal = 1; Pico32x.dirty_pal = 1;
memset(Pico32xMem->pwm, 0, sizeof(Pico32xMem->pwm)); memset(Pico32xMem->pwm, 0, sizeof(Pico32xMem->pwm));
p32x_timers_recalc(); p32x_timers_recalc();

View file

@ -722,6 +722,13 @@ void PicoFrameDrawOnlyMS(void);
// 32x/32x.c // 32x/32x.c
#ifndef NO_32X #ifndef NO_32X
extern struct Pico32x Pico32x; 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 Pico32xInit(void);
void PicoPower32x(void); void PicoPower32x(void);
void PicoReset32x(void); void PicoReset32x(void);
@ -731,12 +738,6 @@ void PicoFrame32x(void);
void p32x_sync_sh2s(unsigned int m68k_target); void p32x_sync_sh2s(unsigned int m68k_target);
void p32x_update_irls(int nested_call); void p32x_update_irls(int nested_call);
void p32x_reset_sh2s(void); 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); void p32x_event_schedule(enum p32x_event event, unsigned int now, int after);
// 32x/memory.c // 32x/memory.c

View file

@ -219,7 +219,8 @@ PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub)
cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0; cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0;
#endif #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) 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; context->execinfo &= ~FM68K_HALTED;
if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED; if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED;
#endif #endif
SekCycleCntT = *(unsigned int *)(cpu+0x50);
} }

View file

@ -174,6 +174,7 @@ typedef enum {
CHUNK_SDRAM, CHUNK_SDRAM,
CHUNK_DRAM, CHUNK_DRAM,
CHUNK_32XPAL, CHUNK_32XPAL,
CHUNK_32X_EVT,
// //
CHUNK_DEFAULT_COUNT, CHUNK_DEFAULT_COUNT,
CHUNK_CARTHW_ = CHUNK_CARTHW, // defined in PicoInt CHUNK_CARTHW_ = CHUNK_CARTHW, // defined in PicoInt
@ -222,6 +223,7 @@ static const char * const chunk_names[] = {
"SDRAM", "SDRAM",
"DRAM", "DRAM",
"PAL", "PAL",
"events",
}; };
static int write_chunk(chunk_name_e name, int len, void *data, void *file) 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_DRAM, Pico32xMem->dram);
CHECKED_WRITE_BUFF(CHUNK_32XPAL, Pico32xMem->pal); 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 #endif
@ -384,6 +388,7 @@ static int state_load(void *file)
unsigned char buff_m68k[0x60], buff_s68k[0x60]; unsigned char buff_m68k[0x60], buff_s68k[0x60];
unsigned char buff_z80[Z80_STATE_SIZE]; unsigned char buff_z80[Z80_STATE_SIZE];
unsigned char buff_sh2[SH2_STATE_SIZE]; unsigned char buff_sh2[SH2_STATE_SIZE];
unsigned char buff[0x40];
unsigned char chunk; unsigned char chunk;
void *ym2612_regs; void *ym2612_regs;
char header[8]; char header[8];
@ -478,6 +483,11 @@ static int state_load(void *file)
case CHUNK_SDRAM: CHECKED_READ_BUFF(Pico32xMem->sdram); break; case CHUNK_SDRAM: CHECKED_READ_BUFF(Pico32xMem->sdram); break;
case CHUNK_DRAM: CHECKED_READ_BUFF(Pico32xMem->dram); break; case CHUNK_DRAM: CHECKED_READ_BUFF(Pico32xMem->dram); break;
case CHUNK_32XPAL: CHECKED_READ_BUFF(Pico32xMem->pal); 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 #endif
default: default:
if (carthw_chunks != NULL) if (carthw_chunks != NULL)