idle loop detection (Cyclone only, with debug stuff)
[picodrive.git] / Pico / Cart.c
index 47ea1cc..e65b509 100644 (file)
@@ -418,7 +418,7 @@ static unsigned char *PicoCartAlloc(int filesize)
   int alloc_size;\r
   unsigned char *rom;\r
 \r
-  if (PicoMCD & 1) return cd_realloc(NULL, filesize);\r
+  if (PicoAHW & PAHW_MCD) return cd_realloc(NULL, filesize);\r
 \r
   alloc_size=filesize+0x7ffff;\r
   if((filesize&0x3fff)==0x200) alloc_size-=0x200;\r
@@ -474,13 +474,17 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize)
   }\r
 \r
   // maybe we are loading MegaCD BIOS?\r
-  if (!(PicoMCD&1) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || !strncmp((char *)rom+0x128, "BOOT", 4))) {\r
-    PicoMCD |= 1;\r
+  if (!(PicoAHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) ||\r
+       !strncmp((char *)rom+0x128, "BOOT", 4))) {\r
+    PicoAHW |= PAHW_MCD;\r
     rom = cd_realloc(rom, size);\r
   }\r
 \r
   // Check for SMD:\r
-  if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD\r
+  if (size >= 0x4200 && (size&0x3fff)==0x200 &&\r
+      ((rom[0x2280] == 'S' && rom[0x280] == 'E') || (rom[0x280] == 'S' && rom[0x2281] == 'E'))) {\r
+    DecodeSmd(rom,size); size-=0x200; // Decode and byteswap SMD\r
+  }\r
   else Byteswap(rom,size); // Just byteswap\r
 \r
   if (prom)  *prom=rom;\r
@@ -511,6 +515,8 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize)
     PicoCartUnloadHook = NULL;\r
   }\r
 \r
+  PicoAHW &= PAHW_MCD;\r
+\r
   PicoMemResetHooks();\r
   PicoDmaHook = NULL;\r
   PicoResetHook = NULL;\r
@@ -520,22 +526,29 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize)
 \r
   PicoMemReset();\r
 \r
-  if (!(PicoMCD & 1))\r
+  if (!(PicoAHW & PAHW_MCD))\r
     PicoCartDetect();\r
 \r
   // setup correct memory map for loaded ROM\r
   // call PicoMemReset again due to possible memmap change\r
-  if (PicoMCD & 1)\r
-       PicoMemSetupCD();\r
-  else PicoMemSetup();\r
+  switch (PicoAHW) {\r
+    default:\r
+      elprintf(EL_STATUS|EL_ANOMALY, "starting in unknown hw configuration: %x", PicoAHW);\r
+    case 0:\r
+    case PAHW_SVP:  PicoMemSetup(); break;\r
+    case PAHW_MCD:  PicoMemSetupCD(); break;\r
+    case PAHW_PICO: PicoMemSetupPico(); break;\r
+  }\r
   PicoMemReset();\r
 \r
-  return PicoReset(1);\r
+  PicoPower();\r
+  return 0;\r
 }\r
 \r
 int PicoCartUnload(void)\r
 {\r
   if (Pico.rom != NULL) {\r
+    SekFinishIdleDet();\r
     free(Pico.rom);\r
     Pico.rom=NULL;\r
   }\r
@@ -597,6 +610,12 @@ static void PicoCartDetect(void)
     sram_size  = 0x004000;\r
   }\r
 \r
+  // this game actually doesn't have SRAM, but some weird protection\r
+  if (rom_strcmp(0x120, "PUGGSY") == 0)\r
+  {\r
+    SRam.start = SRam.end = sram_size = 0;\r
+  }\r
+\r
   if (sram_size)\r
   {\r
     SRam.data = (unsigned char *) calloc(sram_size, 1);\r
@@ -664,6 +683,13 @@ static void PicoCartDetect(void)
     PicoSVPStartup();\r
   }\r
 \r
+  // Pico\r
+  else if (rom_strcmp(0x100, "SEGA PICO") == 0 ||\r
+           rom_strcmp(0x100, "IMA IKUNOUJYUKU") == 0) // what is that supposed to mean?\r
+  {\r
+    PicoInitPico();\r
+  }\r
+\r
   // Detect 12-in-1 mapper\r
   else if ((name_cmp("ROBOCOP 3") == 0 && Pico.romsize == 0x200000) ||\r
     (rom_strcmp(0x160, "FLICKY") == 0 && Pico.romsize >= 0x200000)  ||\r
@@ -682,6 +708,12 @@ static void PicoCartDetect(void)
     carthw_realtec_startup();\r
   }\r
 \r
+  // Radica mapper\r
+  else if (name_cmp("KID CHAMELEON") == 0 && Pico.romsize > 0x100000)\r
+  {\r
+    carthw_radica_startup();\r
+  }\r
+\r
   // Some games malfunction if SRAM is not filled with 0xff\r
   if (name_cmp("DINO DINI'S SOCCER") == 0 ||\r
       name_cmp("MICRO MACHINES II") == 0)\r
@@ -690,7 +722,7 @@ static void PicoCartDetect(void)
   }\r
 \r
   // Unusual region 'code'\r
-  if (rom_strcmp(0x1f0, "EUROPE") == 0)\r
+  if (rom_strcmp(0x1f0, "EUROPE") == 0 || rom_strcmp(0x1f0, "Europe") == 0)\r
     *(int *) (Pico.rom+0x1f0) = 0x20204520;\r
 }\r
 \r