new timing for main and cd
[picodrive.git] / pico / memory.c
index 664fd72..24e5f21 100644 (file)
@@ -309,6 +309,13 @@ NOINLINE void io_ports_write(u32 a, u32 d)
   Pico.ioports[a] = d;\r
 }\r
 \r
+// lame..\r
+static int z80_cycles_from_68k(void)\r
+{\r
+  return z80_cycle_aim\r
+    + cycles_68k_to_z80(SekCyclesDone() - last_z80_sync);\r
+}\r
+\r
 void NOINLINE ctl_write_z80busreq(u32 d)\r
 {\r
   d&=1; d^=1;\r
@@ -317,14 +324,13 @@ void NOINLINE ctl_write_z80busreq(u32 d)
   {\r
     if (d)\r
     {\r
-      z80_cycle_cnt = cycles_68k_to_z80(SekCyclesDone());\r
+      z80_cycle_cnt = z80_cycles_from_68k();\r
     }\r
     else\r
     {\r
-      z80stopCycle = SekCyclesDone();\r
       if ((PicoOpt&POPT_EN_Z80) && !Pico.m.z80_reset) {\r
         pprof_start(m68k);\r
-        PicoSyncZ80(z80stopCycle);\r
+        PicoSyncZ80(SekCyclesDone());\r
         pprof_end_sub(m68k);\r
       }\r
     }\r
@@ -350,7 +356,7 @@ void NOINLINE ctl_write_z80reset(u32 d)
     }\r
     else\r
     {\r
-      z80_cycle_cnt = cycles_68k_to_z80(SekCyclesDone());\r
+      z80_cycle_cnt = z80_cycles_from_68k();\r
       z80_reset();\r
     }\r
     Pico.m.z80_reset = d;\r
@@ -486,7 +492,7 @@ static void PicoWrite8_z80(u32 a, u32 d)
   }\r
 \r
   if ((a & 0x4000) == 0x0000) { // z80 RAM\r
-    SekCyclesBurn(2); // hack\r
+    SekCyclesBurnRun(2); // FIXME hack\r
     Pico.zram[a & 0x1fff] = (u8)d;\r
     return;\r
   }\r
@@ -940,7 +946,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew);\r
             if (ym2612.OPN.ST.mode & 1) {\r
               // this is not right, should really be done on overflow only\r
-              int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
+              int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k();\r
               timer_a_next_oflow = (cycles << 8) + timer_a_step;\r
             }\r
             elprintf(EL_YMTIMER, "timer a set to %i, %i", 1024 - TAnew, timer_a_next_oflow>>8);\r
@@ -955,7 +961,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             //ym2612.OPN.ST.TBT  = 0;\r
             timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800\r
             if (ym2612.OPN.ST.mode & 2) {\r
-              int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
+              int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k();\r
               timer_b_next_oflow = (cycles << 8) + timer_b_step;\r
             }\r
             elprintf(EL_YMTIMER, "timer b set to %i, %i", 256 - d, timer_b_next_oflow>>8);\r
@@ -963,7 +969,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
           return 0;\r
         case 0x27: { /* mode, timer control */\r
           int old_mode = ym2612.OPN.ST.mode;\r
-          int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
+          int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k();\r
           ym2612.OPN.ST.mode = d;\r
 \r
           elprintf(EL_YMTIMER, "st mode %02x", d);\r
@@ -1041,7 +1047,7 @@ static u32 ym2612_read_local_z80(void)
 \r
 static u32 ym2612_read_local_68k(void)\r
 {\r
-  int xcycles = cycles_68k_to_z80(SekCyclesDone()) << 8;\r
+  int xcycles = z80_cycles_from_68k() << 8;\r
 \r
   ym2612_read_local();\r
 \r