diff --git a/core/cd_hw/scd.c b/core/cd_hw/scd.c index 89e22f2..2d30e64 100644 --- a/core/cd_hw/scd.c +++ b/core/cd_hw/scd.c @@ -411,11 +411,11 @@ static void s68k_poll_detect(unsigned int reg_mask) if (s68k.poll.detected & 1) { /* idle SUB-CPU until register is modified */ - s68k.cycles = s68k.cycle_end; - s68k.stopped = reg_mask; #ifdef LOG_SCD error("s68k stopped from %d cycles\n", s68k.cycles); #endif + s68k.cycles = s68k.cycle_end; + s68k.stopped = reg_mask; } else { @@ -473,6 +473,24 @@ static void s68k_poll_sync(unsigned int 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 */ /*--------------------------------------------------------------------------*/ @@ -668,21 +686,8 @@ static unsigned int scd_read_word(unsigned int address) /* MAIN-CPU communication words */ if ((address & 0x1f0) == 0x10) { - 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 (Mighty Morphin Power Rangers) */ - m68k_run(cycles); - - /* restore MAIN-CPU end cycle count */ - m68k.cycle_end = end_cycle; - } - + /* sync MAIN-CPU with SUB-CPU (fixes Mighty Morphin Power Rangers) */ + m68k_sync(); 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].write16 = m68k_unused_16_w; zbank_memory_map[i].read = NULL; - zbank_memory_map[i].write = zbank_unused_w; + zbank_memory_map[i].write = zbank_unused_w; break; } diff --git a/core/mem68k.c b/core/mem68k.c index 966a576..cecc298 100644 --- a/core/mem68k.c +++ b/core/mem68k.c @@ -236,11 +236,11 @@ static void m68k_poll_detect(unsigned int reg_mask) if (m68k.poll.detected & 1) { /* idle MAIN-CPU until register is modified */ - m68k.cycles = m68k.cycle_end; - m68k.stopped = reg_mask; #ifdef LOG_SCD error("m68k stopped from %d cycles\n", m68k.cycles); #endif + m68k.cycles = m68k.cycle_end; + m68k.stopped = reg_mask; } else { @@ -298,6 +298,24 @@ static void m68k_poll_sync(unsigned int 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 */ /*--------------------------------------------------------------------------*/ @@ -355,21 +373,8 @@ unsigned int ctrl_io_read_byte(unsigned int address) /* SUB-CPU communication flags */ if (index == 0x0f) { - 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 (Dracula Unleashed w/ Sega CD Model 2 Boot ROM) */ - s68k_run(cycles); - - /* restore SUB-CPU end cycle count */ - s68k.cycle_end = end_cycle; - } - + /* sync SUB-CPU with MAIN-CPU (fixes Dracula Unleashed with Sega CD Model 2 Boot ROM) */ + s68k_sync(); m68k_poll_detect(1<<0x0f); return scd.regs[0x0f>>1].byte.l; } @@ -534,21 +539,8 @@ unsigned int ctrl_io_read_word(unsigned int address) /* SUB-CPU communication words */ if (index >= 0x20) { - 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 (Soul Star) */ - s68k_run(cycles); - - /* restore SUB-CPU end cycle count */ - s68k.cycle_end = end_cycle; - } - + /* sync SUB-CPU with MAIN-CPU (fixes Soul Star) */ + s68k_sync(); 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 ? */ if (scd.regs[0x32>>1].byte.l & 0x04) { - 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 (Earnest Evans, Fhey Area) */ - s68k_run(cycles); - - /* restore SUB-CPU end cycle count */ - s68k.cycle_end = end_cycle; - } + /* sync SUB-CPU with MAIN-CPU (fixes Earnest Evans, Fhey Area) */ + s68k_sync(); /* set IFL2 flag */ scd.regs[0x00].byte.h |= 0x01;