[Core/CD] MAIN-CPU/SUB-CPU synchronization code cleanup

This commit is contained in:
ekeeke 2023-11-18 17:51:55 +01:00
parent 6f0ac9a668
commit 8169f02496
2 changed files with 49 additions and 64 deletions

View File

@ -411,11 +411,11 @@ static void s68k_poll_detect(unsigned int reg_mask)
if (s68k.poll.detected & 1) if (s68k.poll.detected & 1)
{ {
/* idle SUB-CPU until register is modified */ /* idle SUB-CPU until register is modified */
s68k.cycles = s68k.cycle_end;
s68k.stopped = reg_mask;
#ifdef LOG_SCD #ifdef LOG_SCD
error("s68k stopped from %d cycles\n", s68k.cycles); error("s68k stopped from %d cycles\n", s68k.cycles);
#endif #endif
s68k.cycles = s68k.cycle_end;
s68k.stopped = reg_mask;
} }
else else
{ {
@ -473,6 +473,24 @@ static void s68k_poll_sync(unsigned int reg_mask)
m68k.poll.detected &= ~reg_mask; m68k.poll.detected &= ~reg_mask;
} }
static void m68k_sync(void)
{
if (!m68k.stopped)
{
/* relative MAIN-CPU cycle counter */
unsigned int cycles = (s68k.cycles * MCYCLES_PER_LINE) / SCYCLES_PER_LINE;
/* save current MAIN-CPU end cycle count (recursive execution is possible) */
int end_cycle = m68k.cycle_end;
/* sync MAIN-CPU with SUB-CPU */
m68k_run(cycles);
/* restore MAIN-CPU end cycle count */
m68k.cycle_end = end_cycle;
}
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/* PCM chip & Gate-Array area */ /* PCM chip & Gate-Array area */
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@ -668,21 +686,8 @@ static unsigned int scd_read_word(unsigned int address)
/* MAIN-CPU communication words */ /* MAIN-CPU communication words */
if ((address & 0x1f0) == 0x10) if ((address & 0x1f0) == 0x10)
{ {
if (!m68k.stopped) /* sync MAIN-CPU with SUB-CPU (fixes Mighty Morphin Power Rangers) */
{ m68k_sync();
/* relative MAIN-CPU cycle counter */
unsigned int cycles = (s68k.cycles * MCYCLES_PER_LINE) / SCYCLES_PER_LINE;
/* save current MAIN-CPU end cycle count (recursive execution is possible) */
int end_cycle = m68k.cycle_end;
/* sync MAIN-CPU with SUB-CPU (Mighty Morphin Power Rangers) */
m68k_run(cycles);
/* restore MAIN-CPU end cycle count */
m68k.cycle_end = end_cycle;
}
s68k_poll_detect(3 << (address & 0x1e)); s68k_poll_detect(3 << (address & 0x1e));
} }
@ -1411,7 +1416,7 @@ void scd_init(void)
m68k.memory_map[i].write8 = m68k_unused_8_w; m68k.memory_map[i].write8 = m68k_unused_8_w;
m68k.memory_map[i].write16 = m68k_unused_16_w; m68k.memory_map[i].write16 = m68k_unused_16_w;
zbank_memory_map[i].read = NULL; zbank_memory_map[i].read = NULL;
zbank_memory_map[i].write = zbank_unused_w; zbank_memory_map[i].write = zbank_unused_w;
break; break;
} }

View File

@ -236,11 +236,11 @@ static void m68k_poll_detect(unsigned int reg_mask)
if (m68k.poll.detected & 1) if (m68k.poll.detected & 1)
{ {
/* idle MAIN-CPU until register is modified */ /* idle MAIN-CPU until register is modified */
m68k.cycles = m68k.cycle_end;
m68k.stopped = reg_mask;
#ifdef LOG_SCD #ifdef LOG_SCD
error("m68k stopped from %d cycles\n", m68k.cycles); error("m68k stopped from %d cycles\n", m68k.cycles);
#endif #endif
m68k.cycles = m68k.cycle_end;
m68k.stopped = reg_mask;
} }
else else
{ {
@ -298,6 +298,24 @@ static void m68k_poll_sync(unsigned int reg_mask)
m68k.poll.detected &= ~reg_mask; m68k.poll.detected &= ~reg_mask;
} }
static void s68k_sync(void)
{
if (!s68k.stopped)
{
/* relative SUB-CPU cycle counter */
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
/* save current SUB-CPU end cycle count (recursive execution is possible) */
int end_cycle = s68k.cycle_end;
/* sync SUB-CPU with MAIN-CPU */
s68k_run(cycles);
/* restore SUB-CPU end cycle count */
s68k.cycle_end = end_cycle;
}
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/* I/O Control */ /* I/O Control */
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@ -355,21 +373,8 @@ unsigned int ctrl_io_read_byte(unsigned int address)
/* SUB-CPU communication flags */ /* SUB-CPU communication flags */
if (index == 0x0f) if (index == 0x0f)
{ {
if (!s68k.stopped) /* sync SUB-CPU with MAIN-CPU (fixes Dracula Unleashed with Sega CD Model 2 Boot ROM) */
{ s68k_sync();
/* relative SUB-CPU cycle counter */
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
/* save current SUB-CPU end cycle count (recursive execution is possible) */
int end_cycle = s68k.cycle_end;
/* sync SUB-CPU with MAIN-CPU (Dracula Unleashed w/ Sega CD Model 2 Boot ROM) */
s68k_run(cycles);
/* restore SUB-CPU end cycle count */
s68k.cycle_end = end_cycle;
}
m68k_poll_detect(1<<0x0f); m68k_poll_detect(1<<0x0f);
return scd.regs[0x0f>>1].byte.l; return scd.regs[0x0f>>1].byte.l;
} }
@ -534,21 +539,8 @@ unsigned int ctrl_io_read_word(unsigned int address)
/* SUB-CPU communication words */ /* SUB-CPU communication words */
if (index >= 0x20) if (index >= 0x20)
{ {
if (!s68k.stopped) /* sync SUB-CPU with MAIN-CPU (fixes Soul Star) */
{ s68k_sync();
/* relative SUB-CPU cycle counter */
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
/* save current SUB-CPU end cycle count (recursive execution is possible) */
int end_cycle = s68k.cycle_end;
/* sync SUB-CPU with MAIN-CPU (Soul Star) */
s68k_run(cycles);
/* restore SUB-CPU end cycle count */
s68k.cycle_end = end_cycle;
}
m68k_poll_detect(3 << (index - 0x10)); m68k_poll_detect(3 << (index - 0x10));
} }
@ -659,20 +651,8 @@ void ctrl_io_write_byte(unsigned int address, unsigned int data)
/* level 2 interrupt enabled ? */ /* level 2 interrupt enabled ? */
if (scd.regs[0x32>>1].byte.l & 0x04) if (scd.regs[0x32>>1].byte.l & 0x04)
{ {
if (!s68k.stopped) /* sync SUB-CPU with MAIN-CPU (fixes Earnest Evans, Fhey Area) */
{ s68k_sync();
/* relative SUB-CPU cycle counter */
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
/* save current SUB-CPU end cycle count (recursive execution is possible) */
int end_cycle = s68k.cycle_end;
/* sync SUB-CPU with MAIN-CPU (Earnest Evans, Fhey Area) */
s68k_run(cycles);
/* restore SUB-CPU end cycle count */
s68k.cycle_end = end_cycle;
}
/* set IFL2 flag */ /* set IFL2 flag */
scd.regs[0x00].byte.h |= 0x01; scd.regs[0x00].byte.h |= 0x01;