reset behavior changed, Puggsy detection added
[picodrive.git] / Pico / Pico.c
index 2ebe9c9..7978fed 100644 (file)
@@ -52,10 +52,32 @@ void PicoExit(void)
     PicoExitMCD();\r
   z80_exit();\r
 \r
-  if(SRam.data) free(SRam.data); SRam.data=0;\r
+  if (SRam.data) free(SRam.data); SRam.data=0;\r
 }\r
 \r
-int PicoReset(int hard)\r
+void PicoPower(void)\r
+{\r
+  // clear all memory of the emulated machine\r
+  memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);\r
+\r
+  memset(&Pico.video,0,sizeof(Pico.video));\r
+  memset(&Pico.m,0,sizeof(Pico.m));\r
+\r
+  Pico.video.pending_ints=0;\r
+  z80_reset();\r
+\r
+  // default VDP register values (based on Fusion)\r
+  Pico.video.reg[0] = Pico.video.reg[1] = 0x04;\r
+  Pico.video.reg[0xc] = 0x81;\r
+  Pico.video.reg[0xf] = 0x02;\r
+\r
+  if (PicoMCD & 1)\r
+    PicoPowerMCD();\r
+\r
+  PicoReset();\r
+}\r
+\r
+int PicoReset(void)\r
 {\r
   unsigned int region=0;\r
   int support=0,hw=0,i=0;\r
@@ -72,25 +94,12 @@ int PicoReset(int hard)
   // s68k doesn't have the TAS quirk, so we just globally set normal TAS handler in MCD mode (used by Batman games).\r
   SekSetRealTAS(PicoMCD & 1);\r
   SekCycleCntT=0;\r
-  z80_reset();\r
 \r
-  // reset VDP state, VRAM and PicoMisc\r
-  //memset(&Pico.video,0,sizeof(Pico.video));\r
-  //memset(&Pico.vram,0,sizeof(Pico.vram));\r
-  memset(Pico.ioports,0,sizeof(Pico.ioports)); // needed for MCD to reset properly\r
-  memset(&Pico.m,0,sizeof(Pico.m));\r
-  Pico.video.pending_ints=0;\r
+  if (PicoMCD & 1)\r
+    // needed for MCD to reset properly, probably some bug hides behind this..\r
+    memset(Pico.ioports,0,sizeof(Pico.ioports));\r
   emustatus = 0;\r
 \r
-  if (hard) {\r
-    // clear all memory of the emulated machine\r
-    memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);\r
-  }\r
-\r
-  // default VDP register values (based on Fusion)\r
-  Pico.video.reg[0] = Pico.video.reg[1] = 0x04;\r
-  Pico.video.reg[0xc] = 0x81;\r
-  Pico.video.reg[0xf] = 0x02;\r
   Pico.m.dirtyPal = 1;\r
 \r
   if(PicoRegionOverride)\r
@@ -141,12 +150,16 @@ int PicoReset(int hard)
 \r
   Pico.m.hardware=(unsigned char)(hw|0x20); // No disk attached\r
   Pico.m.pal=pal;\r
-  Pico.video.status = 0x3408 | pal; // always set bits | vblank | pal\r
+  Pico.video.status = 0x3408 | pal; // 'always set' bits | vblank | pal\r
 \r
   PsndReset(); // pal must be known here\r
 \r
+  // create an empty "dma" to cause 68k exec start at random frame location\r
+  if (Pico.m.dma_xfers == 0 && !(PicoOpt&0x10000))\r
+    Pico.m.dma_xfers = rand() & 0x1fff;\r
+\r
   if (PicoMCD & 1) {\r
-    PicoResetMCD(hard);\r
+    PicoResetMCD();\r
     return 0;\r
   }\r
 \r