Skip to content

Commit

Permalink
core, some save state fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Jun 20, 2024
1 parent e948a12 commit b6c6af5
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
13 changes: 8 additions & 5 deletions pico/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,9 +1284,11 @@ static u32 ym2612_read_local_68k(void)
void ym2612_pack_state(void)
{
// timers are saved as tick counts, in 16.16 int format
int tac, tat = 0, tbc, tbt = 0;
int tac, tat = 0, tbc, tbt = 0, busy = 0;
tac = 1024 - ym2612.OPN.ST.TA;
tbc = 256 - ym2612.OPN.ST.TB;
if (Pico.t.ym2612_busy > 0)
busy = (Pico.t.ym2612_busy * 32/90) >> 8;
if (Pico.t.timer_a_next_oflow != TIMER_NO_OFLOW)
tat = (int)((double)(Pico.t.timer_a_step - Pico.t.timer_a_next_oflow)
/ (double)Pico.t.timer_a_step * tac * 65536);
Expand All @@ -1301,12 +1303,12 @@ void ym2612_pack_state(void)
YM2612PicoStateSave2_940(tat, tbt);
else
#endif
YM2612PicoStateSave2(tat, tbt);
YM2612PicoStateSave2(tat, tbt, busy);
}

void ym2612_unpack_state(void)
{
int i, ret, tac, tat, tbc, tbt;
int i, ret, tac, tat, tbc, tbt, busy = 0;
YM2612PicoStateLoad();

// feed all the registers and update internal state
Expand Down Expand Up @@ -1336,12 +1338,13 @@ void ym2612_unpack_state(void)
ret = YM2612PicoStateLoad2_940(&tat, &tbt);
else
#endif
ret = YM2612PicoStateLoad2(&tat, &tbt);
ret = YM2612PicoStateLoad2(&tat, &tbt, &busy);
if (ret != 0) {
elprintf(EL_STATUS, "old ym2612 state");
return; // no saved timers
}

Pico.t.ym2612_busy = (busy << 8) * 90/32;
tac = (1024 - ym2612.OPN.ST.TA) << 16;
tbc = (256 - ym2612.OPN.ST.TB) << 16;
if (ym2612.OPN.ST.mode & 1)
Expand Down Expand Up @@ -1383,7 +1386,7 @@ static void access_68k_bus(int delay) // bus delay as Q8
Pico.t.z80_busdelay &= 0xff; // leftover cycle fraction
// don't use SekCyclesBurn() here since the Z80 doesn't run in cycle lock to
// the 68K. Count the stolen cycles to be accounted later in the 68k CPU runs
Pico.t.z80_buscycles += 8;
Pico.t.z80_buscycles += 8; // TODO <=8.4 for Rick 2, but >=8.9 for misc_test
}

static unsigned char z80_md_vdp_read(unsigned short a)
Expand Down
1 change: 1 addition & 0 deletions pico/pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void PicoLoopPrepare(void)
Pico.t.vcnt_wrap = 0xEB;
Pico.t.vcnt_adj = 6;
}
PicoVideoFIFOMode(Pico.video.reg[1]&0x40, Pico.video.reg[12]&1);

Pico.m.dirtyPal = 1;
rendstatus_old = -1;
Expand Down
5 changes: 4 additions & 1 deletion pico/sek.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub)
*(u32 *)(cpu+0x50) = SekCycleCntS68k;
*(s16 *)(cpu+0x4e) = SekCycleCntS68k - SekCycleAimS68k;
} else {
*(u32 *)(cpu+0x50) = Pico.t.m68c_cnt;
*(u32 *)(cpu+0x50) = Pico.t.m68c_cnt + Pico.t.z80_buscycles +
((Pico.t.refresh_delay + (1<<14)/2) >> 14);
*(s16 *)(cpu+0x4e) = Pico.t.m68c_cnt - Pico.t.m68c_aim;
}
}
Expand Down Expand Up @@ -266,6 +267,8 @@ PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub)
} else {
Pico.t.m68c_cnt = *(u32 *)(cpu+0x50);
Pico.t.m68c_aim = Pico.t.m68c_cnt - *(s16 *)(cpu+0x4e);
Pico.t.z80_buscycles = 0;
Pico.t.refresh_delay = 0;
}
}

Expand Down
8 changes: 5 additions & 3 deletions pico/sound/ym2612.c
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,7 @@ typedef struct
UINT32 eg_timer;
UINT32 lfo_cnt;
UINT16 lfo_ampm;
UINT16 unused2;
INT16 busy_timer;
UINT32 keyon_field; // 20
UINT32 kcode_fc_sl3_3;
UINT32 reserved[2];
Expand All @@ -2063,7 +2063,7 @@ typedef struct
} ym_save_addon2;


void YM2612PicoStateSave2(int tat, int tbt)
void YM2612PicoStateSave2(int tat, int tbt, int busy)
{
ym_save_addon_slot ss;
ym_save_addon2 sa2;
Expand Down Expand Up @@ -2121,10 +2121,11 @@ void YM2612PicoStateSave2(int tat, int tbt)
sa.eg_timer = ym2612.OPN.eg_timer;
sa.lfo_cnt = ym2612.OPN.lfo_cnt;
sa.lfo_ampm = g_lfo_ampm;
sa.busy_timer = busy;
memcpy(ptr, &sa, sizeof(sa)); // 0x30 max
}

int YM2612PicoStateLoad2(int *tat, int *tbt)
int YM2612PicoStateLoad2(int *tat, int *tbt, int *busy)
{
ym_save_addon_slot ss;
ym_save_addon2 sa2;
Expand All @@ -2150,6 +2151,7 @@ int YM2612PicoStateLoad2(int *tat, int *tbt)
g_lfo_ampm = sa.lfo_ampm;
if (tat != NULL) *tat = sa.TAT;
if (tbt != NULL) *tbt = sa.TBT;
if (busy != NULL) *busy = sa.busy_timer;

// chans 1,2,3
ptr = &ym2612.REGS[0x0b8];
Expand Down
4 changes: 2 additions & 2 deletions pico/sound/ym2612.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ int YM2612PicoTick_(int n);
void YM2612PicoStateLoad_(void);

void *YM2612GetRegs(void);
void YM2612PicoStateSave2(int tat, int tbt);
int YM2612PicoStateLoad2(int *tat, int *tbt);
void YM2612PicoStateSave2(int tat, int tbt, int busy);
int YM2612PicoStateLoad2(int *tat, int *tbt, int *busy);

/* NB must be macros for compiling GP2X 940 code */
#ifndef __GP2X__
Expand Down
2 changes: 1 addition & 1 deletion pico/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ struct PicoTmp
unsigned short vram[0x8000];
unsigned short cram[0x40];
unsigned short vsram[0x40];
unsigned int satcache[0x80];
unsigned int satcache[2*0x80];

//struct PicoMisc m;
struct PicoVideo video;
Expand Down
7 changes: 3 additions & 4 deletions pico/videoport.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ void PicoVideoFIFOMode(int active, int h40)

if (vf->fifo_maxslot)
PicoVideoFIFOSync(lc);
else
lc = 0;

vf->fifo_cyc2sl = vdpcyc2sl[active][h40];
vf->fifo_sl2cyc = vdpsl2cyc[active][h40];
Expand Down Expand Up @@ -1243,20 +1245,17 @@ void PicoVideoLoad(void)
vf->fifo_ql = vf->fifo_qx = vf->fifo_total = 0;
if (pv->fifo_cnt) {
int wc = pv->fifo_cnt;
pv->status |= PVS_CPUWR;
vf->fifo_total = (wc+b) >> b;
vf->fifo_queue[vf->fifo_qx + vf->fifo_ql] = (wc << 3) | b | FQ_FGDMA;
vf->fifo_ql ++;
}
if (pv->fifo_bgcnt) {
int wc = pv->fifo_bgcnt;
if (!vf->fifo_ql)
pv->status |= PVS_DMABG;
vf->fifo_queue[vf->fifo_qx + vf->fifo_ql] = (wc << 3) | FQ_BGDMA;
vf->fifo_ql ++;
}
if (vf->fifo_ql)
pv->status |= SR_DMA;
PicoVideoCacheSAT(1);
vf->fifo_maxslot = 0;
}
// vim:shiftwidth=2:ts=2:expandtab
3 changes: 2 additions & 1 deletion pico/z80if.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void z80_pack(void *data)
struct z80_state *s = data;
memset(data, 0, Z80_STATE_SIZE);
memcpy(s->magic, "Z80a", 4);
s->cyc = Pico.t.z80c_cnt;
s->cyc = Pico.t.z80c_cnt + ((Pico.t.z80_busdelay + (1<<8)/2) >> 8);
#if defined(_USE_DRZ80)
#define DRR8(n) (drZ80.Z80##n >> 24)
#define DRR16(n) (drZ80.Z80##n >> 16)
Expand Down Expand Up @@ -224,6 +224,7 @@ int z80_unpack(const void *data)
return 0;
}
Pico.t.z80c_cnt = s->cyc;
Pico.t.z80_busdelay = 0;

#if defined(_USE_DRZ80)
#define DRW8(n, v) drZ80.Z80##n = (u32)(v) << 24
Expand Down
4 changes: 2 additions & 2 deletions platform/gp2x/code940/940.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void Main940(void)
break;

case JOB940_PICOSTATESAVE2:
YM2612PicoStateSave2(0, 0);
YM2612PicoStateSave2(0, 0, 0);
memcpy(shared_ctl->writebuff0, ym2612_940->REGS, 0x200);
break;

Expand All @@ -197,7 +197,7 @@ void Main940(void)

case JOB940_PICOSTATELOAD2:
memcpy(ym2612_940->REGS, shared_ctl->writebuff0, 0x200);
YM2612PicoStateLoad2(0, 0);
YM2612PicoStateLoad2(0, 0, 0);
break;

case JOB940_YM2612UPDATEONE:
Expand Down

0 comments on commit b6c6af5

Please sign in to comment.