fast mode timing changed (again...)
[picodrive.git] / Pico / Pico.c
index 96a6da0..c6bf03e 100644 (file)
@@ -423,24 +423,34 @@ static int PicoFrameHints(void)
 #include "PicoFrameHints.c"\r
 #endif\r
 \r
-// helper z80 runner\r
+// helper z80 runner. Runs only if z80 is enabled at this point\r
+// (z80WriteBusReq will handle the rest)\r
 static void PicoRunZ80Simple(int line_from, int line_to)\r
 {\r
-  int line_from_r=line_from, line_to_r=line_to, line = line_from;\r
+  int line_from_r=line_from, line_to_r=line_to, line=0;\r
   int line_sample = Pico.m.pal ? 68 : 93;\r
 \r
-  if(!(PicoOpt&4) || Pico.m.z80Run == 0) { line_from_r = line_to_r; line_to_r = 0; }\r
+  if (!(PicoOpt&4) || Pico.m.z80Run == 0) line_to_r = 0;\r
+  else {\r
+    extern const unsigned short vcounts[];\r
+    if (z80startCycle) {\r
+      line = vcounts[z80startCycle>>8];\r
+      if (line > line_from)\r
+        line_from_r = line;\r
+    }\r
+    z80startCycle = SekCyclesDone();\r
+  }\r
 \r
-  if(PicoOpt&1) {\r
+  if (PicoOpt&1) {\r
     // we have ym2612 enabled, so we have to run Z80 in lines, so we could update DAC and timers\r
-    for(; line < line_to; line++) {\r
+    for (line = line_from; line < line_to; line++) {\r
       sound_timers_and_dac(line);\r
-      if((line == 224 || line == line_sample) && PsndOut) getSamples(line);\r
-      if(line == 32 && PsndOut) emustatus &= ~1;\r
-      if(line >= line_from_r && line < line_to_r)\r
+      if ((line == 224 || line == line_sample) && PsndOut) getSamples(line);\r
+      if (line == 32 && PsndOut) emustatus &= ~1;\r
+      if (line >= line_from_r && line < line_to_r)\r
         z80_run(228);\r
     }\r
-  } else if(line_to_r-line_from_r > 0) {\r
+  } else if (line_to_r-line_from_r > 0) {\r
     z80_run(228*(line_to_r-line_from_r));\r
     // samples will be taken by caller\r
   }\r
@@ -482,6 +492,7 @@ static int PicoFrameSimple(void)
   Pico.video.status|=0x200;\r
 \r
   Pico.m.scanline=-1;\r
+  z80startCycle=0;\r
 \r
   SekCyclesReset();\r
 \r
@@ -507,11 +518,12 @@ static int PicoFrameSimple(void)
   if(sects) {\r
     int c = sects*cycles_68k_block;\r
 \r
-    lines += sects*lines_step;\r
-    PicoRunZ80Simple(line, lines);\r
-    // this is for approriate line counter, etc\r
+    // this "run" is for approriate line counter, etc\r
     SekCycleCnt += c;\r
     SekCycleAim += c;\r
+\r
+    lines += sects*lines_step;\r
+    PicoRunZ80Simple(line, lines);\r
   }\r
 \r
   // here we render sound if ym2612 is disabled\r