From be297089d0eef9747c6917f1dae70dfc7046a8e8 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 11 Jul 2008 20:48:05 +0000 Subject: [PATCH] z80/ym2612 reset handling improved git-svn-id: file:///home/notaz/opt/svn/PicoDrive@540 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/MemoryCmn.c | 73 ++++++++++++++++++++++--------------------- Pico/PicoFrameHints.c | 6 ++-- Pico/sound/ym2612.c | 3 +- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Pico/MemoryCmn.c b/Pico/MemoryCmn.c index 6493207..fbe5041 100644 --- a/Pico/MemoryCmn.c +++ b/Pico/MemoryCmn.c @@ -60,27 +60,46 @@ u32 z80ReadBusReq(void) return d|0x80; } -#ifndef _ASM_MEMORY_C -static -#endif -void z80WriteBusReq(u32 d) +static void z80WriteBusReq(u32 d) +{ + d&=1; d^=1; + elprintf(EL_BUSREQ, "set_zrun: %i->%i [%i] @%06x", Pico.m.z80Run, d, SekCyclesDone(), SekPc); + if (d ^ Pico.m.z80Run) + { + if (d) + { + z80_cycle_cnt = cycles_68k_to_z80(SekCyclesDone()); + } + else + { + z80stopCycle = SekCyclesDone(); + if ((PicoOpt&POPT_EN_Z80) && !Pico.m.z80_reset) + PicoSyncZ80(z80stopCycle); + } + Pico.m.z80Run=d; + } +} + +static void z80WriteReset(u32 d) { d&=1; d^=1; + elprintf(EL_BUSREQ, "set_zreset: %i->%i [%i] @%06x", Pico.m.z80_reset, d, SekCyclesDone(), SekPc); + if (d ^ Pico.m.z80_reset) { - if (!d) + if (d) { if ((PicoOpt&POPT_EN_Z80) && Pico.m.z80Run) - { - z80stopCycle = SekCyclesDone(); - PicoSyncZ80(z80stopCycle); - } - } else { - if (!Pico.m.z80Run) - z80_cycle_cnt = cycles_68k_to_z80(SekCyclesDone()); + PicoSyncZ80(SekCyclesDone()); + } + else + { + z80_cycle_cnt = cycles_68k_to_z80(SekCyclesDone()); + z80_reset(); } + YM2612ResetChip(); + timers_reset(); + Pico.m.z80_reset=d; } - elprintf(EL_BUSREQ, "set_zrun: %i->%i [%i] @%06x", Pico.m.z80Run, d, SekCyclesDone(), SekPc); - Pico.m.z80Run=(u8)d; } #ifndef _ASM_MEMORY_C @@ -161,17 +180,8 @@ void OtherWrite8(u32 a,u32 d) if ((a&0xffffe0)==0xa10000) { IoWrite8(a, d); return; } // I/O ports #endif if (a==0xa11100) { z80WriteBusReq(d); return; } - if (a==0xa11200) { - elprintf(EL_BUSREQ, "write z80Reset: %02x", d); - if (!(d&0x1)) { Pico.m.z80_reset = 1; Pico.m.z80Run = 0; YM2612ResetChip(); } - else if (Pico.m.z80_reset) { - Pico.m.z80_reset = 0; - YM2612ResetChip(); - z80_reset(); - timers_reset(); - } - return; - } + if (a==0xa11200) { z80WriteReset(d); return; } + #if !defined(_ASM_MEMORY_C) || defined(_ASM_MEMORY_C_AMIPS) if ((a&0xff7f00)==0xa06000) // Z80 BANK register { @@ -206,17 +216,8 @@ void OtherWrite16(u32 a,u32 d) else elprintf(EL_ANOMALY, "68k z80 write with no bus or reset! [%06x] %04x @ %06x", a, d&0xffff, SekPc); return; } - if (a==0xa11200) { - elprintf(EL_BUSREQ, "write z80reset: %04x", d); - if (!(d&0x100)) { Pico.m.z80_reset = 1; Pico.m.z80Run = 0; YM2612ResetChip(); } - else if (Pico.m.z80_reset) { - Pico.m.z80_reset = 0; - YM2612ResetChip(); - z80_reset(); - timers_reset(); - } - return; - } + if (a==0xa11200) { z80WriteReset(d>>8); return; } + if ((a&0xff7f00)==0xa06000) // Z80 BANK register { Pico.m.z80_bank68k>>=1; diff --git a/Pico/PicoFrameHints.c b/Pico/PicoFrameHints.c index 7a372bf..84db382 100644 --- a/Pico/PicoFrameHints.c +++ b/Pico/PicoFrameHints.c @@ -124,7 +124,7 @@ static int PicoFrameHints(void) emustatus &= ~1; else if ((y == 224 || y == line_sample) && PsndOut) { - if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80)) + if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) PicoSyncZ80(SekCycleCnt); if (ym2612.dacen && PsndDacLine <= y) PsndDoDAC(y); @@ -188,7 +188,7 @@ static int PicoFrameHints(void) elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt); SekInterrupt(6); } - if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80)) { + if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) { PicoSyncZ80(SekCycleCnt); elprintf(EL_INTS, "zint"); z80_int(); @@ -246,7 +246,7 @@ static int PicoFrameHints(void) } // sync z80 - if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80)) + if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1) PsndDoDAC(lines-1); diff --git a/Pico/sound/ym2612.c b/Pico/sound/ym2612.c index 56c363a..0c26739 100644 --- a/Pico/sound/ym2612.c +++ b/Pico/sound/ym2612.c @@ -1668,6 +1668,8 @@ void YM2612Init_(int clock, int rate) ym2612.OPN.ST.clock = clock; ym2612.OPN.ST.rate = rate; + OPNSetPres( 6*24 ); + /* Extend handler */ YM2612ResetChip_(); } @@ -1680,7 +1682,6 @@ void YM2612ResetChip_(void) memset(ym2612.REGS, 0, sizeof(ym2612.REGS)); - OPNSetPres( 6*24 ); set_timers( 0x30 ); /* mode 0 , timer reset */ ym2612.REGS[0x27] = 0x30; -- 2.39.2