SekStepM68k restored, pad read issues with D&D fixed
[picodrive.git] / Pico / Pico.c
index aae914b..f1ee455 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
@@ -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,18 +311,8 @@ 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
-#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
-  }\r
-#endif\r
-\r
   Pico.m.frame_count++;\r
 \r
   if (PicoAHW & PAHW_MCD) {\r
@@ -357,6 +350,7 @@ void (*PicoMessage)(const char *msg)=NULL;
 \r
 #if 1 // defined(__DEBUG_PRINT)\r
 #define bit(r, x) ((r>>x)&1)\r
+#define MVP dstrp+=strlen(dstrp)\r
 void z80_debug(char *dstr);\r
 char *debugString(void)\r
 {\r
@@ -375,38 +369,33 @@ char *debugString(void)
     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, "mode set 1: %02x       spr lo: %2i, spr hi: %2i\n", (r=reg[0]), sprites_lo, sprites_hi); MVP;\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)); MVP;\r
+  sprintf(dstrp, "mode set 2: %02x                            hcnt: %i\n", (r=reg[1]), pv->reg[10]); MVP;\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),bit(r,5),bit(r,6),bit(r,7)); MVP;\r
+  sprintf(dstrp, "mode set 3: %02x\n", (r=reg[0xB])); MVP;\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)); MVP;\r
+  sprintf(dstrp, "mode set 4: %02x\n", (r=reg[0xC])); MVP;\r
+  sprintf(dstrp, "interlace: %i%i, cells: %i, shadow: %i\n", bit(r,2), bit(r,1), (r&0x80) ? 40 : 32, bit(r,3)); MVP;\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
+       bit(Pico.m.sram_reg, 4), bit(Pico.m.sram_reg, 2), SRam.eeprom_type); MVP;\r
+  sprintf(dstrp, "sram range: %06x-%06x, reg: %02x\n", SRam.start, SRam.end, Pico.m.sram_reg); MVP;\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); MVP;\r
+  sprintf(dstrp, "pal: %i, hw: %02x, frame#: %i\n", Pico.m.pal, Pico.m.hardware, Pico.m.frame_count); MVP;\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
+  sprintf(dstrp, "M68k: PC: %06x, st_flg: %x, cycles: %u\n", SekPc, PicoCpuCM68k.state_flags, SekCyclesDoneT()); MVP;\r
+  sprintf(dstrp, "d0=%08x, a0=%08x, osp=%08x, irql=%i\n", PicoCpuCM68k.d[0], PicoCpuCM68k.a[0], PicoCpuCM68k.osp, PicoCpuCM68k.irq); MVP;\r
+  sprintf(dstrp, "d1=%08x, a1=%08x,  sr=%04x\n", PicoCpuCM68k.d[1], PicoCpuCM68k.a[1], CycloneGetSr(&PicoCpuCM68k)); dstrp+=strlen(dstrp); MVP;\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
+    sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, PicoCpuCM68k.d[r], r, PicoCpuCM68k.a[r]); MVP;\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
+  sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuMM68k.int_level>>8); MVP;\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
+  sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuFM68k.interrupts[0]); MVP;\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
+  sprintf(dstrp, "z80Run: %i, z80_reset: %i, z80_bnk: %06x\n", Pico.m.z80Run, Pico.m.z80_reset, Pico.m.z80_bank68k<<15); MVP;\r
+  z80_debug(dstrp); MVP;\r
   if (strlen(dstr) > sizeof(dstr))\r
     printf("warning: debug buffer overflow (%i/%i)\n", strlen(dstr), sizeof(dstr));\r
 \r