idle loops adjusted
[picodrive.git] / Pico / Pico.c
index aae914b..b5e4e28 100644 (file)
@@ -16,6 +16,7 @@ int PicoOpt = 0;
 int PicoSkipFrame = 0; // skip rendering frame?\r
 int emustatus = 0;     // rapid_ym2612, multi_ym_updates\r
 int PicoPad[2];        // Joypads, format is SACB RLDU\r
+int PicoPadInt[2];     // internal copy\r
 int PicoAHW = 0;       // active addon hardware: scd_active, 32x_active, svp_active, pico_active\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
@@ -23,7 +24,7 @@ struct PicoSRAM SRam = {0,};
 \r
 void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware\r
 void (*PicoResetHook)(void) = NULL;\r
-void (*PicoLineHook)(int count) = NULL;\r
+void (*PicoLineHook)(void) = NULL;\r
 \r
 // to be called once on emu init\r
 void PicoInit(void)\r
@@ -31,6 +32,7 @@ void PicoInit(void)
   // Blank space for state:\r
   memset(&Pico,0,sizeof(Pico));\r
   memset(&PicoPad,0,sizeof(PicoPad));\r
+  memset(&PicoPadInt,0,sizeof(PicoPadInt));\r
 \r
   // Init CPUs:\r
   SekInit();\r
@@ -145,6 +147,7 @@ int PicoReset(void)
 \r
   PicoMemReset();\r
   SekReset();\r
+  memset(&PicoPadInt,0,sizeof(PicoPadInt));\r
   // s68k doesn't have the TAS quirk, so we just globally set normal TAS handler in MCD mode (used by Batman games).\r
   SekSetRealTAS(PicoAHW & PAHW_MCD);\r
   SekCycleCntT=0;\r
@@ -168,16 +171,16 @@ int PicoReset(void)
   if (Pico.m.dma_xfers == 0 && !(PicoOpt&POPT_DIS_VDP_FIFO))\r
     Pico.m.dma_xfers = rand() & 0x1fff;\r
 \r
+  SekFinishIdleDet();\r
+\r
   if (PicoAHW & PAHW_MCD) {\r
     PicoResetMCD();\r
     return 0;\r
   }\r
-  else {\r
-    // reinit, so that checksum checks pass\r
-    SekFinishIdleDet();\r
-    if (!(PicoOpt & POPT_DIS_IDLE_DET))\r
-      SekInitIdleDet();\r
-  }\r
+\r
+  // reinit, so that checksum checks pass\r
+  if (!(PicoOpt & POPT_DIS_IDLE_DET))\r
+    SekInitIdleDet();\r
 \r
   // reset sram state; enable sram access by default if it doesn't overlap with ROM\r
   Pico.m.sram_reg=sram_reg&0x14;\r
@@ -250,7 +253,7 @@ static __inline void SekRunM68k(int cyc)
 #elif defined(EMU_M68K)\r
   SekCycleCnt+=m68k_execute(cyc_do);\r
 #elif defined(EMU_F68K)\r
-  SekCycleCnt+=fm68k_emulate(cyc_do+1, 0);\r
+  SekCycleCnt+=fm68k_emulate(cyc_do+1, 0, 0);\r
 #endif\r
 }\r
 \r
@@ -308,20 +311,25 @@ PICO_INTERNAL void PicoSyncZ80(int m68k_cycles_done)
 }\r
 \r
 \r
-// TODO: rm from asm too\r
-int idle_hit_counter = 0;\r
-\r
 void PicoFrame(void)\r
 {\r
+  Pico.m.frame_count++;\r
+\r
 #if 0\r
-  if ((Pico.m.frame_count&0x3f) == 0) {\r
-    elprintf(EL_STATUS, "ihits: %i", idle_hit_counter);\r
-    idle_hit_counter = 0;\r
+  if ((Pico.m.frame_count & 0x3f) == 0)\r
+  {\r
+    extern int idlehit_addrs[], idlehit_counts[];\r
+    int i;\r
+    printf("--\n");\r
+    for (i = 0; i < 128 && idlehit_addrs[i] != 0; i++) {\r
+      if (idlehit_counts[i] != 0) {\r
+        printf("%06x %i %i\n", idlehit_addrs[i], idlehit_counts[i],  idlehit_counts[i] >> 6);\r
+        idlehit_counts[i] = 0;\r
+      }\r
+    }\r
   }\r
 #endif\r
 \r
-  Pico.m.frame_count++;\r
-\r
   if (PicoAHW & PAHW_MCD) {\r
     PicoFrameMCD();\r
     return;\r
@@ -355,97 +363,3 @@ void PicoGetInternal(pint_t which, pint_ret_t *r)
 // callback to output message from emu\r
 void (*PicoMessage)(const char *msg)=NULL;\r
 \r
-#if 1 // defined(__DEBUG_PRINT)\r
-#define bit(r, x) ((r>>x)&1)\r
-void z80_debug(char *dstr);\r
-char *debugString(void)\r
-{\r
-#if 1\r
-  static char dstr[1024];\r
-  struct PicoVideo *pv=&Pico.video;\r
-  unsigned char *reg=pv->reg, r;\r
-  extern int HighPreSpr[];\r
-  int i, sprites_lo, sprites_hi;\r
-  char *dstrp;\r
-\r
-  sprites_lo = sprites_hi = 0;\r
-  for (i = 0; HighPreSpr[i] != 0; i+=2)\r
-    if (HighPreSpr[i+1] & 0x8000)\r
-         sprites_hi++;\r
-    else sprites_lo++;\r
-\r
-  dstrp = dstr;\r
-  sprintf(dstrp, "mode set 1: %02x       spr lo: %2i, spr hi: %2i\n", (r=reg[0]), sprites_lo, sprites_hi);\r
-  dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "display_disable: %i, M3: %i, palette: %i, ?, hints: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,4));\r
-  dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "mode set 2: %02x\n", (r=reg[1])); dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "SMS/gen: %i, pal: %i, dma: %i, vints: %i, disp: %i, TMS: %i\n", bit(r,2), bit(r,3), bit(r,4),\r
-       bit(r,5), bit(r,6), bit(r,7)); dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "mode set 3: %02x\n", (r=reg[0xB])); dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "LSCR: %i, HSCR: %i, 2cell vscroll: %i, IE2: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,3)); dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "mode set 4: %02x\n", (r=reg[0xC])); dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "interlace: %i%i, cells: %i, shadow: %i\n", bit(r,2), bit(r,1), (r&0x80) ? 40 : 32,  bit(r,3));\r
-  dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "scroll size: w: %i, h: %i  SRAM: %i; eeprom: %i (%i)\n", reg[0x10]&3, (reg[0x10]&0x30)>>4,\r
-       bit(Pico.m.sram_reg, 4), bit(Pico.m.sram_reg, 2), SRam.eeprom_type); dstrp+=strlen(dstrp);\r
-  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
-#if defined(EMU_C68K)\r
-  sprintf(dstrp, "M68k: PC: %06x, st_flg: %x, cycles: %u\n", SekPc, PicoCpuCM68k.state_flags, SekCyclesDoneT());\r
-  dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "d0=%08x, a0=%08x, osp=%08x, irql=%i\n", PicoCpuCM68k.d[0], PicoCpuCM68k.a[0], PicoCpuCM68k.osp, PicoCpuCM68k.irq); dstrp+=strlen(dstrp);\r
-  sprintf(dstrp, "d1=%08x, a1=%08x,  sr=%04x\n", PicoCpuCM68k.d[1], PicoCpuCM68k.a[1], CycloneGetSr(&PicoCpuCM68k)); dstrp+=strlen(dstrp);\r
-  for(r=2; r < 8; r++) {\r
-    sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, PicoCpuCM68k.d[r], r, PicoCpuCM68k.a[r]); dstrp+=strlen(dstrp);\r
-  }\r
-#elif defined(EMU_M68K)\r
-  sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuMM68k.int_level>>8); dstrp+=strlen(dstrp);\r
-#elif defined(EMU_F68K)\r
-  sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuFM68k.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
-  if (strlen(dstr) > sizeof(dstr))\r
-    printf("warning: debug buffer overflow (%i/%i)\n", strlen(dstr), sizeof(dstr));\r
-\r
-#else\r
-  struct PicoVideo *pvid=&Pico.video;\r
-  int table=0;\r
-  int i,u,n,link=0;\r
-  static char dstr[1024*8];\r
-  dstr[0] = 0;\r
-\r
-  table=pvid->reg[5]&0x7f;\r
-  if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode\r
-  table<<=8; // Get sprite table address/2\r
-\r
-  for (i=u=n=0; u < 80 && n < 20; u++)\r
-  {\r
-    unsigned int *sprite;\r
-    int code, code2, sx, sy, height;\r
-\r
-    sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
-\r
-    // get sprite info\r
-    code = sprite[0];\r
-\r
-    // check if it is on this line\r
-    sy = (code&0x1ff);//-0x80;\r
-    height = ((code>>24)&3)+1;\r
-\r
-    // masking sprite?\r
-    code2 = sprite[1];\r
-    sx = (code2>>16)&0x1ff;\r
-\r
-    printf("#%02i x: %03i y: %03i %ix%i\n", u, sx, sy, ((code>>26)&3)+1, height);\r
-\r
-    link=(code>>16)&0x7f;\r
-    if(!link) break; // End of sprites\r
-  }\r
-#endif\r
-\r
-  return dstr;\r
-}\r
-#endif\r