FAME + some random stuff added
[picodrive.git] / Pico / Pico.c
index decd634..b9fbfe6 100644 (file)
@@ -16,14 +16,13 @@ int PicoOpt=0; // disable everything by default
 int PicoSkipFrame=0; // skip rendering frame?\r
 int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
 int PicoAutoRgnOrder = 0;\r
-int emustatus = 0;\r
+int emustatus = 0; // rapid_ym2612, multi_ym_updates\r
 void (*PicoWriteSound)(int len) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware\r
 \r
 struct PicoSRAM SRam = {0,};\r
 int z80startCycle, z80stopCycle; // in 68k cycles\r
-//int z80ExtraCycles = 0;\r
 int PicoPad[2];  // Joypads, format is SACB RLDU\r
-int PicoMCD = 0; // mega CD status: scd_started, reset_pending\r
+int PicoMCD = 0; // mega CD status: scd_started\r
 \r
 // to be called once on emu init\r
 int PicoInit(void)\r
@@ -213,12 +212,10 @@ static __inline void SekRunM68k(int cyc)
   PicoCpu.cycles=cyc_do;\r
   CycloneRun(&PicoCpu);\r
   SekCycleCnt+=cyc_do-PicoCpu.cycles;\r
-#elif defined(EMU_A68K)\r
-  m68k_ICount=cyc_do;\r
-  M68000_RUN();\r
-  SekCycleCnt+=cyc_do-m68k_ICount;\r
 #elif defined(EMU_M68K)\r
   SekCycleCnt+=m68k_execute(cyc_do);\r
+#elif defined(EMU_F68K)\r
+  SekCycleCnt+=m68k_emulate(cyc_do);\r
 #endif\r
 }\r
 \r
@@ -233,12 +230,10 @@ static __inline void SekStep(void)
   PicoCpu.cycles=1;\r
   CycloneRun(&PicoCpu);\r
   SekCycleCnt+=1-PicoCpu.cycles;\r
-#elif defined(EMU_A68K)\r
-  m68k_ICount=1;\r
-  M68000_RUN();\r
-  SekCycleCnt+=1-m68k_ICount;\r
 #elif defined(EMU_M68K)\r
   SekCycleCnt+=m68k_execute(1);\r
+#elif defined(EMU_F68K)\r
+  SekCycleCnt+=m68k_emulate(1);\r
 #endif\r
   SekCycleAim=realaim;\r
 }\r
@@ -265,6 +260,8 @@ static int CheckIdle(void)
   return 0;\r
 }\r
 \r
+void lprintf_al(const char *fmt, ...);\r
+\r
 // to be called on 224 or line_sample scanlines only\r
 static __inline void getSamples(int y)\r
 {\r
@@ -422,24 +419,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
@@ -481,6 +488,7 @@ static int PicoFrameSimple(void)
   Pico.video.status|=0x200;\r
 \r
   Pico.m.scanline=-1;\r
+  z80startCycle=0;\r
 \r
   SekCyclesReset();\r
 \r
@@ -506,11 +514,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
@@ -625,7 +634,7 @@ void PicoFrameDrawOnly(void)
 // callback to output message from emu\r
 void (*PicoMessage)(const char *msg)=NULL;\r
 \r
-#if defined(__DEBUG_PRINT) || defined(__GP2X__)\r
+#if 1 // defined(__DEBUG_PRINT)\r
 // tmp debug: dump some stuff\r
 #define bit(r, x) ((r>>x)&1)\r
 void z80_debug(char *dstr);\r
@@ -654,7 +663,7 @@ char *debugString(void)
   sprintf(dstrp, "sram range: %06x-%06x, reg: %02x\n", SRam.start, SRam.end, Pico.m.sram_reg); dstrp+=strlen(dstrp);\r
   sprintf(dstrp, "pend int: v:%i, h:%i, vdp status: %04x\n", bit(pv->pending_ints,5), bit(pv->pending_ints,4), pv->status);\r
   dstrp+=strlen(dstrp);\r
-#ifdef EMU_C68K\r
+#if defined(EMU_C68K)\r
   sprintf(dstrp, "M68k: PC: %06x, st_flg: %x, cycles: %u\n", SekPc, PicoCpu.state_flags, SekCyclesDoneT());\r
   dstrp+=strlen(dstrp);\r
   sprintf(dstrp, "d0=%08x, a0=%08x, osp=%08x, irql=%i\n", PicoCpu.d[0], PicoCpu.a[0], PicoCpu.osp, PicoCpu.irq); dstrp+=strlen(dstrp);\r
@@ -662,6 +671,10 @@ char *debugString(void)
   for(r=2; r < 8; r++) {\r
     sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, PicoCpu.d[r], r, PicoCpu.a[r]); dstrp+=strlen(dstrp);\r
   }\r
+#elif defined(EMU_M68K)\r
+  sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoM68kCPU.int_level>>8); dstrp+=strlen(dstrp);\r
+#elif defined(EMU_F68K)\r
+  sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuM68k.interrupts[0]); dstrp+=strlen(dstrp);\r
 #endif\r
   sprintf(dstrp, "z80Run: %i, pal: %i, frame#: %i\n", Pico.m.z80Run, Pico.m.pal, Pico.m.frame_count); dstrp+=strlen(dstrp);\r
   z80_debug(dstrp); dstrp+=strlen(dstrp);\r