From d9153729685381acb0559d8a4fdca47cb839427a Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 31 Mar 2007 17:25:48 +0000 Subject: [PATCH] z80 timing change git-svn-id: file:///home/notaz/opt/svn/PicoDrive@84 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Memory.c | 5 +---- Pico/MemoryCmn.c | 13 +++++++++---- Pico/Pico.c | 15 +++++++++++---- Pico/PicoInt.h | 1 + Pico/cd/Pico.c | 11 +++++++++-- cpu/musashi/m68kcpu.c | 2 +- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Pico/Memory.c b/Pico/Memory.c index 3157a63..32b25ca 100644 --- a/Pico/Memory.c +++ b/Pico/Memory.c @@ -392,10 +392,7 @@ static void CPU_CALL PicoWrite8(u32 a,u8 d) //if ((a&0xe0ffff)==0xe0a9ba+0x69c) // dprintf("w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc); - - if ((a&0xe00000)==0xe00000) { - if((a&0xffff)==0xf62a) dprintf("(f62a) = %02x [%i|%i] @ %x", d, Pico.m.scanline, SekCyclesDone(), SekPc); - u8 *pm=(u8 *)(Pico.ram+((a^1)&0xffff)); pm[0]=d; return; } // Ram + if ((a&0xe00000)==0xe00000) { *(u8 *)(Pico.ram+((a^1)&0xffff))=d; return; } // Ram a&=0xffffff; OtherWrite8(a,d,8); diff --git a/Pico/MemoryCmn.c b/Pico/MemoryCmn.c index 02d45d8..48c564c 100644 --- a/Pico/MemoryCmn.c +++ b/Pico/MemoryCmn.c @@ -149,16 +149,21 @@ void OtherWrite8(u32 a,u32 d,int realsize) return; } if (a==0xa11100) { - extern int z80startCycle, z80stopCycle; //int lineCycles=(488-SekCyclesLeft)&0x1ff; d&=1; d^=1; if(!d) { // this is for a nasty situation where Z80 was enabled and disabled in the same 68k timeslice (Golden Axe III) if (Pico.m.z80Run) { - int lineCycles=(488-SekCyclesLeft)&0x1ff; + int lineCycles; z80stopCycle = SekCyclesDone(); - lineCycles=(lineCycles>>1)-(lineCycles>>5); - z80_run(lineCycles); + if (Pico.m.z80Run&2) + lineCycles=(488-SekCyclesLeft)&0x1ff; + else lineCycles=z80stopCycle-z80startCycle; // z80 was started at current line + if (lineCycles > 0 && lineCycles <= 488) { + dprintf("zrun: %i/%i cycles", lineCycles, (lineCycles>>1)-(lineCycles>>5)); + lineCycles=(lineCycles>>1)-(lineCycles>>5); + z80_run(lineCycles); + } } } else { z80startCycle = SekCyclesDone(); diff --git a/Pico/Pico.c b/Pico/Pico.c index d0845e1..04a0b97 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -430,11 +430,18 @@ static int PicoFrameHints(void) getSamples(y); // Run scanline: - if(Pico.m.dma_bytes) SekCycleCnt+=CheckDMA(); + if (Pico.m.dma_bytes) SekCycleCnt+=CheckDMA(); SekRun(cycles_68k); - if((PicoOpt&4) && Pico.m.z80Run) { - Pico.m.z80Run|=2; - z80CycleAim+=cycles_z80; + if ((PicoOpt&4) && Pico.m.z80Run) { + if (Pico.m.z80Run & 2) z80CycleAim+=cycles_z80; + else { + int cnt = SekCyclesDone() - z80startCycle; + cnt = (cnt>>1)-(cnt>>5); + //if (cnt > cycles_z80) printf("FIXME: z80 cycles: %i\n", cnt); + if (cnt > cycles_z80) cnt = cycles_z80; + Pico.m.z80Run |= 2; + z80CycleAim+=cnt; + } total_z80+=z80_run(z80CycleAim-total_z80); } } diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index e11f58b..2b802d7 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -299,6 +299,7 @@ void PicoWriteCD32(unsigned int a, unsigned int d); extern struct Pico Pico; extern struct PicoSRAM SRam; extern int emustatus; +extern int z80startCycle, z80stopCycle; // in 68k cycles int CheckDMA(void); // cd/Pico.c diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 00be7b6..0759acb 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -331,8 +331,15 @@ static int PicoFrameHintsMCD(void) } if ((PicoOpt&4) && Pico.m.z80Run) { - Pico.m.z80Run|=2; - z80CycleAim+=cycles_z80; + if (Pico.m.z80Run & 2) z80CycleAim+=cycles_z80; + else { + int cnt = SekCyclesDone() - z80startCycle; + cnt = (cnt>>1)-(cnt>>5); + //if (cnt > cycles_z80) printf("FIXME: z80 cycles: %i\n", cnt); + if (cnt > cycles_z80) cnt = cycles_z80; + Pico.m.z80Run |= 2; + z80CycleAim+=cnt; + } total_z80+=z80_run(z80CycleAim-total_z80); } diff --git a/cpu/musashi/m68kcpu.c b/cpu/musashi/m68kcpu.c index e4212a8..14a6cad 100644 --- a/cpu/musashi/m68kcpu.c +++ b/cpu/musashi/m68kcpu.c @@ -788,7 +788,7 @@ int m68k_execute(int num_cycles) m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */ /* Main loop. Keep going until we run out of clock cycles */ - while(GET_CYCLES() > 0) + while(GET_CYCLES() >= 0) { /* Set tracing accodring to T1. (T0 is done inside instruction) */ m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */ -- 2.39.2