core, improve mcd+32x cpu synchronization

This commit is contained in:
kub 2022-10-12 21:44:32 +00:00
parent db8af214be
commit fdaf9d10bd
2 changed files with 47 additions and 50 deletions

View file

@ -215,7 +215,7 @@ void PicoReset32x(void)
}
}
static void p32x_start_blank(void)
static void p32x_render_frame(void)
{
if (Pico32xDrawMode != PDM32X_OFF && !PicoIn.skipFrame) {
int offs, lines;
@ -228,7 +228,6 @@ static void p32x_start_blank(void)
lines = 240;
}
// XXX: no proper handling of 32col mode..
if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0 && // 32x not blanking
(!(Pico.video.debug_p & PVD_KILL_32X)))
{
@ -242,7 +241,10 @@ static void p32x_start_blank(void)
pprof_end(draw);
}
}
static void p32x_start_blank(void)
{
// enter vblank
Pico32x.vdp_regs[0x0a/2] |= P32XV_VBLK|P32XV_PEN;
@ -258,17 +260,23 @@ static void p32x_start_blank(void)
p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, SekCyclesDone());
}
static void p32x_end_blank(void)
{
// end vblank
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank
if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0) // no forced blanking
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_PEN; // no palette access
if (!(Pico32x.sh2_regs[0] & 0x80))
p32x_schedule_hint(NULL, SekCyclesDone());
}
void p32x_schedule_hint(SH2 *sh2, unsigned int m68k_cycles)
{
// rather rough, 32x hint is useless in practice
int after;
if (!((Pico32x.sh2irq_mask[0] | Pico32x.sh2irq_mask[1]) & 4))
return; // nobody cares
// note: when Pico.m.scanline is 224, SH2s might
// still be at scanline 93 (or so)
if (!(Pico32x.sh2_regs[0] & 0x80) &&
Pico.m.scanline > (Pico.video.reg[1] & 0x08 ? 240 : 224))
if (!(Pico32x.sh2_regs[0] & 0x80) && (Pico.video.status & PVS_VB2))
return;
after = (Pico32x.sh2_regs[4 / 2] + 1) * 488;
@ -572,14 +580,6 @@ void PicoFrame32x(void)
sh2_execute_prepare(&msh2, PicoIn.opt & POPT_EN_DRC);
sh2_execute_prepare(&ssh2, PicoIn.opt & POPT_EN_DRC);
Pico.m.scanline = 0;
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank
if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0) // no forced blanking
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_PEN; // no palette access
if (!(Pico32x.sh2_regs[0] & 0x80))
p32x_schedule_hint(NULL, SekCyclesDone());
p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, SekCyclesDone());
p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, SekCyclesDone());

View file

@ -62,6 +62,21 @@ static __inline void SekRunM68k(int cyc)
SekSyncM68k();
}
static void SyncCPUs(unsigned int cycles)
{
// sync cpus
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80))
PicoSyncZ80(cycles);
#ifdef PICO_CD
if (PicoIn.AHW & PAHW_MCD)
pcd_sync_s68k(cycles, 0);
#endif
#ifdef PICO_32X
p32x_sync_sh2s(cycles);
#endif
}
static void do_hint(struct PicoVideo *pv)
{
pv->pending_ints |= 0x10;
@ -87,21 +102,11 @@ static int PicoFrameHints(void)
struct PicoVideo *pv = &Pico.video;
int lines, y, lines_vis, skip;
int vcnt_wrap, vcnt_adj;
unsigned int cycles;
int hint; // Hint counter
pevt_log_m68k_o(EVT_FRAME_START);
if ((PicoIn.opt&POPT_ALT_RENDERER) && !PicoIn.skipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
// draw a frame just after vblank in alternative render mode
// yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
PicoFrameFull();
#ifdef DRAW_FINISH_FUNC
DRAW_FINISH_FUNC();
#endif
skip = 1;
}
else skip=PicoIn.skipFrame;
skip = PicoIn.skipFrame;
Pico.t.m68c_frame_start = Pico.t.m68c_aim;
pv->v_counter = Pico.m.scanline = 0;
@ -109,9 +114,12 @@ static int PicoFrameHints(void)
PsndStartFrame();
hint = pv->hint_cnt;
// === active display ===
pv->status |= PVS_ACTIVE;
for (y = 0; ; y++)
lines_vis = (pv->reg[1] & 8) ? 240 : 224;
for (y = 0; y < lines_vis; y++)
{
pv->v_counter = Pico.m.scanline = y;
if ((pv->reg[12]&6) == 6) { // interlace mode 2
@ -120,9 +128,6 @@ static int PicoFrameHints(void)
pv->v_counter &= 0xff;
}
if ((y == 224 && !(pv->reg[1] & 8)) || y == 240)
break;
PAD_DELAY();
// H-Interrupts:
@ -155,9 +160,10 @@ static int PicoFrameHints(void)
pevt_log_m68k_o(EVT_NEXT_LINE);
}
lines_vis = (pv->reg[1] & 8) ? 240 : 224;
if (y == lines_vis)
pv->status &= ~PVS_ACTIVE;
SyncCPUs(Pico.t.m68c_aim);
// === VBLANK, 1st line ===
pv->status &= ~PVS_ACTIVE;
if (!skip)
{
@ -167,6 +173,9 @@ static int PicoFrameHints(void)
DRAW_FINISH_FUNC();
#endif
}
#ifdef PICO_32X
p32x_render_frame();
#endif
memcpy(PicoIn.padInt, PicoIn.pad, sizeof(PicoIn.padInt));
PAD_DELAY();
@ -198,19 +207,13 @@ static int PicoFrameHints(void)
SekInterrupt(6);
}
cycles = Pico.t.m68c_aim;
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80)) {
PicoSyncZ80(cycles);
PicoSyncZ80(Pico.t.m68c_aim);
elprintf(EL_INTS, "zint");
z80_int();
}
#ifdef PICO_CD
if (PicoIn.AHW & PAHW_MCD)
pcd_sync_s68k(cycles, 0);
#endif
#ifdef PICO_32X
p32x_sync_sh2s(cycles);
p32x_start_blank();
#endif
@ -221,6 +224,7 @@ static int PicoFrameHints(void)
if (PicoLineHook) PicoLineHook();
pevt_log_m68k_o(EVT_NEXT_LINE);
// === VBLANK ===
if (Pico.m.pal) {
lines = 313;
vcnt_wrap = 0x103;
@ -269,6 +273,7 @@ static int PicoFrameHints(void)
}
}
// === VBLANK last line ===
pv->status &= ~(SR_VB | PVS_VB2);
pv->status |= ((pv->reg[1] >> 3) ^ SR_VB) & SR_VB; // forced blanking
@ -297,17 +302,9 @@ static int PicoFrameHints(void)
if (PicoLineHook) PicoLineHook();
pevt_log_m68k_o(EVT_NEXT_LINE);
// sync cpus
cycles = Pico.t.m68c_aim;
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80))
PicoSyncZ80(cycles);
#ifdef PICO_CD
if (PicoIn.AHW & PAHW_MCD)
pcd_sync_s68k(cycles, 0);
#endif
SyncCPUs(Pico.t.m68c_aim);
#ifdef PICO_32X
p32x_sync_sh2s(cycles);
p32x_end_blank();
#endif
// get samples from sound chips