improved savestate stability & compatibility

This commit is contained in:
ekeeke31 2011-02-23 19:14:55 +00:00
parent 4f7bfcb0c9
commit ef8efa2c10
6 changed files with 69 additions and 14 deletions

View File

@ -159,9 +159,7 @@ void sound_reset(void)
int sound_context_save(uint8 *state)
{
int bufferptr = 0;
save_param(YM2612GetContextPtr(),YM2612GetContextSize());
int bufferptr = YM2612SaveContext(state);
save_param(SN76489_GetContextPtr(),SN76489_GetContextSize());
save_param(&fm_cycles_count,sizeof(fm_cycles_count));
save_param(&psg_cycles_count,sizeof(psg_cycles_count));
@ -171,16 +169,14 @@ int sound_context_save(uint8 *state)
int sound_context_load(uint8 *state, char *version)
{
int bufferptr = 0;
YM2612Restore(&state[bufferptr]);
bufferptr += YM2612GetContextSize();
int bufferptr = YM2612LoadContext(state, version);
load_param(SN76489_GetContextPtr(),SN76489_GetContextSize());
if (version[15] > 0x30)
{
load_param(&fm_cycles_count,sizeof(fm_cycles_count));
load_param(&psg_cycles_count,sizeof(psg_cycles_count));
fm_cycles_count = psg_cycles_count;
}
return bufferptr;

View File

@ -2189,7 +2189,7 @@ void YM2612Restore(unsigned char *buffer)
/* restore internal state */
memcpy(&ym2612, buffer, sizeof(YM2612));
/* restore current timings */
/* keep current timings */
ym2612.OPN.ST.clock = clock;
ym2612.OPN.ST.rate = rate;
OPNSetPres(6*24);
@ -2202,6 +2202,57 @@ void YM2612Restore(unsigned char *buffer)
setup_connection(&ym2612.CH[4],4);
setup_connection(&ym2612.CH[5],5);
/* restore TL table (in case DAC precision has changed) */
/* restore TL table (DAC resolution might have been modified) */
init_tables();
}
int YM2612LoadContext(unsigned char *state, char *version)
{
int bufferptr = sizeof(YM2612);
/* restore YM2612 context */
YM2612Restore(state);
/* extended state */
if (version[15] > 0x31)
{
int c,s;
uint8 index;
/* restore DT table address pointer for each channel slots */
for( c = 0 ; c < 6 ; c++ )
{
for(s = 0 ; s < 4 ; s++ )
{
load_param(&index,sizeof(index));
bufferptr += sizeof(index);
ym2612.CH[c].SLOT[s].DT = ym2612.OPN.ST.dt_tab[index&7];
}
}
}
return bufferptr;
}
int YM2612SaveContext(unsigned char *state)
{
int c,s;
uint8 index;
int bufferptr = sizeof(YM2612);
/* save YM2612 context */
memcpy(state, &ym2612, sizeof(YM2612));
/* save DT table index for each channel slots */
for( c = 0 ; c < 6 ; c++ )
{
for(s = 0 ; s < 4 ; s++ )
{
index = (ym2612.CH[c].SLOT[s].DT - ym2612.OPN.ST.dt_tab[0]) >> 5;
save_param(&index,sizeof(index));
bufferptr += sizeof(index);
}
}
return bufferptr;
}

View File

@ -10,8 +10,8 @@
**
*/
#ifndef _H_FM_FM_
#define _H_FM_FM_
#ifndef _H_YM2612_
#define _H_YM2612_
/* compiler dependence */
#ifndef INLINE
@ -27,5 +27,8 @@ extern unsigned int YM2612Read(void);
extern unsigned char *YM2612GetContextPtr(void);
extern unsigned int YM2612GetContextSize(void);
extern void YM2612Restore(unsigned char *buffer);
extern int YM2612LoadContext(unsigned char *state, char *version);
extern int YM2612SaveContext(unsigned char *state);
#endif /* _H_FM_FM_ */
#endif /* _YM2612_ */

View File

@ -79,6 +79,7 @@ int state_load(unsigned char *buffer)
// IO
load_param(io_reg, sizeof(io_reg));
io_reg[0] = region_code | 0x20 | (config.tmss & 1);
// VDP
bufferptr += vdp_context_load(&state[bufferptr], version);
@ -111,6 +112,7 @@ int state_load(unsigned char *buffer)
// Z80
load_param(&Z80, sizeof(Z80_Regs));
Z80.irq_callback = z80_irq_callback;
// Cartridge HW
bufferptr += cart_hw_context_load(&state[bufferptr], version);

View File

@ -24,7 +24,7 @@
#define _STATE_H_
#define STATE_SIZE 0x48100
#define STATE_VERSION "GENPLUS-GX 1.4.1"
#define STATE_VERSION "GENPLUS-GX 1.4.2"
#define load_param(param, size) \
memcpy(param, &state[bufferptr], size); \

View File

@ -163,7 +163,6 @@ void vdp_reset(void)
vint_pending = 0;
irq_status = 0;
hvc_latch = 0;
v_counter = 0;
dmafill = 0;
fill_data = 0;
dma_length = 0;
@ -178,6 +177,7 @@ void vdp_reset(void)
cached_write = -1;
vc_max = 0xEA + 24*vdp_pal;
v_counter = lines_per_frame - 1;
status = vdp_pal | 0x200; /* FIFO empty flag */
@ -296,6 +296,9 @@ int vdp_context_load(uint8 *state, char *version)
vc_max += (28 - 20*vdp_pal);
}
/* keep current region mode */
status = (status & ~1) | vdp_pal;
/* restore FIFO timings */
fifo_latency = (reg[12] & 1) ? 190 : 214;
if ((code & 0x0F) == 0x01)