From d0aa36acc3179b5db6c38a8aa460d91bb17c7ad6 Mon Sep 17 00:00:00 2001 From: EkeEke Date: Sun, 7 Jan 2018 16:24:28 +0100 Subject: [PATCH] [Core/CPU] improved 68K/Z80 synchronization --- core/genesis.c | 10 +++++----- core/genesis.h | 2 +- core/system.c | 42 +----------------------------------------- core/system.h | 2 +- 4 files changed, 8 insertions(+), 48 deletions(-) diff --git a/core/genesis.c b/core/genesis.c index 1ef2db9..1d5d272 100644 --- a/core/genesis.c +++ b/core/genesis.c @@ -5,7 +5,7 @@ * Support for SG-1000, Mark-III, Master System, Game Gear, Mega Drive & Mega CD hardware * * Copyright (C) 1998-2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -474,8 +474,8 @@ void gen_zbusreq_w(unsigned int data, unsigned int cycles) /* check if Z80 is going to be restarted */ if (zstate == 3) { - /* resynchronize with 68k */ - Z80.cycles = cycles; + /* resynchronize with 68k (Z80 cycles should remain a multiple of 15 MClocks) */ + Z80.cycles = ((cycles + 14) / 15) * 15; /* disable 68k access to Z80 bus */ m68k.memory_map[0xa0].read8 = m68k_read_bus_8; @@ -496,8 +496,8 @@ void gen_zreset_w(unsigned int data, unsigned int cycles) /* check if Z80 is going to be restarted */ if (zstate == 0) { - /* resynchronize with 68k */ - Z80.cycles = cycles; + /* resynchronize with 68k (Z80 cycles should remain a multiple of 15 MClocks) */ + Z80.cycles = ((cycles + 14) / 15) * 15; /* reset Z80 & YM2612 */ z80_reset(); diff --git a/core/genesis.h b/core/genesis.h index 15fd52f..8a744db 100644 --- a/core/genesis.h +++ b/core/genesis.h @@ -5,7 +5,7 @@ * Support for SG-1000, Mark-III, Master System, Game Gear, Mega Drive & Mega CD hardware * * Copyright (C) 1998-2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/core/system.c b/core/system.c index ead4c5d..358262e 100644 --- a/core/system.c +++ b/core/system.c @@ -5,7 +5,7 @@ * Support for 16-bit & 8-bit hardware modes * * Copyright (C) 1998-2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2017 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -467,10 +467,6 @@ void system_frame_gen(int do_skip) { z80_run(788); } - else - { - Z80.cycles = 788; - } /* set VINT flag */ status |= 0x80; @@ -493,10 +489,6 @@ void system_frame_gen(int do_skip) { z80_run(MCYCLES_PER_LINE); } - else - { - Z80.cycles = MCYCLES_PER_LINE; - } /* Z80 interrupt is cleared at the end of the line */ Z80.irq_state = CLEAR_LINE; @@ -538,10 +530,6 @@ void system_frame_gen(int do_skip) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } - else - { - Z80.cycles = mcycles_vdp + MCYCLES_PER_LINE; - } /* run SVP chip */ if (svp) @@ -590,10 +578,6 @@ void system_frame_gen(int do_skip) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } - else - { - Z80.cycles = mcycles_vdp + MCYCLES_PER_LINE; - } /* run SVP chip */ if (svp) @@ -654,10 +638,6 @@ void system_frame_gen(int do_skip) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } - else - { - Z80.cycles = mcycles_vdp + MCYCLES_PER_LINE; - } /* run SVP chip */ if (svp) @@ -826,10 +806,6 @@ void system_frame_scd(int do_skip) { z80_run(788); } - else - { - Z80.cycles = 788; - } /* set VINT flag */ status |= 0x80; @@ -854,10 +830,6 @@ void system_frame_scd(int do_skip) { z80_run(MCYCLES_PER_LINE); } - else - { - Z80.cycles = MCYCLES_PER_LINE; - } /* Z80 interrupt is cleared at the end of the line */ Z80.irq_state = CLEAR_LINE; @@ -895,10 +867,6 @@ void system_frame_scd(int do_skip) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } - else - { - Z80.cycles = mcycles_vdp + MCYCLES_PER_LINE; - } /* update VDP cycle count */ mcycles_vdp += MCYCLES_PER_LINE; @@ -943,10 +911,6 @@ void system_frame_scd(int do_skip) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } - else - { - Z80.cycles = mcycles_vdp + MCYCLES_PER_LINE; - } /* update VDP cycle count */ mcycles_vdp += MCYCLES_PER_LINE; @@ -1003,10 +967,6 @@ void system_frame_scd(int do_skip) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } - else - { - Z80.cycles = mcycles_vdp + MCYCLES_PER_LINE; - } /* update VDP cycle count */ mcycles_vdp += MCYCLES_PER_LINE; diff --git a/core/system.h b/core/system.h index a61d19b..ac72727 100644 --- a/core/system.h +++ b/core/system.h @@ -5,7 +5,7 @@ * Support for 16-bit & 8-bit hardware modes * * Copyright (C) 1998-2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2017 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: