32x: add preliminary hint emulation
[picodrive.git] / pico / cart.c
index fa283c8..db742a8 100644 (file)
@@ -1,11 +1,11 @@
-// This is part of Pico Library\r
-\r
-// (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
-\r
+/*\r
+ * PicoDrive\r
+ * (c) Copyright Dave, 2004\r
+ * (C) notaz, 2006-2010\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
 \r
 #include "pico_int.h"\r
 #include "../zlib/zlib.h"\r
@@ -23,6 +23,8 @@ void (*PicoCartMemSetup)(void);
 void (*PicoCartLoadProgressCB)(int percent) = NULL;\r
 void (*PicoCDLoadProgressCB)(const char *fname, int percent) = NULL; // handled in Pico/cd/cd_file.c\r
 \r
+int PicoGameLoaded;\r
+\r
 static void PicoCartDetect(const char *carthw_cfg);\r
 \r
 /* cso struct */\r
@@ -439,6 +441,9 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms)
     if (filesize > (1 << s))\r
       s++;\r
     rom_alloc_size = 1 << s;\r
+    // be sure we can cover all address space\r
+    if (rom_alloc_size < 0x10000)\r
+      rom_alloc_size = 0x10000;\r
   }\r
   else {\r
     // make alloc size at least sizeof(mcd_state),\r
@@ -455,7 +460,7 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms)
 \r
   // Allocate space for the rom plus padding\r
   // use special address for 32x dynarec\r
-  rom = plat_mmap(0x02000000, rom_alloc_size);\r
+  rom = plat_mmap(0x02000000, rom_alloc_size, 0, 0);\r
   return rom;\r
 }\r
 \r
@@ -589,6 +594,7 @@ int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_
   else\r
     PicoPower();\r
 \r
+  PicoGameLoaded = 1;\r
   return 0;\r
 }\r
 \r
@@ -618,6 +624,7 @@ void PicoCartUnload(void)
     plat_munmap(Pico.rom, rom_alloc_size);\r
     Pico.rom = NULL;\r
   }\r
+  PicoGameLoaded = 0;\r
 }\r
 \r
 static unsigned int rom_crc32(void)\r
@@ -702,21 +709,45 @@ static int is_expr(const char *expr, char **pr)
   return 1;\r
 }\r
 \r
+#include "carthw_cfg.c"\r
+\r
 static void parse_carthw(const char *carthw_cfg, int *fill_sram)\r
 {\r
   int line = 0, any_checks_passed = 0, skip_sect = 0;\r
+  const char *s, *builtin = builtin_carthw_cfg;\r
   int tmp, rom_crc = 0;\r
   char buff[256], *p, *r;\r
   FILE *f;\r
 \r
   f = fopen(carthw_cfg, "r");\r
-  if (f == NULL) {\r
+  if (f == NULL)\r
+    f = fopen("pico/carthw.cfg", "r");\r
+  if (f == NULL)\r
     elprintf(EL_STATUS, "couldn't open carthw.cfg!");\r
-    return;\r
-  }\r
 \r
-  while ((p = fgets(buff, sizeof(buff), f)))\r
+  for (;;)\r
   {\r
+    if (f != NULL) {\r
+      p = fgets(buff, sizeof(buff), f);\r
+      if (p == NULL)\r
+        break;\r
+    }\r
+    else {\r
+      if (*builtin == 0)\r
+        break;\r
+      for (s = builtin; *s != 0 && *s != '\n'; s++)\r
+        ;\r
+      while (*s == '\n')\r
+        s++;\r
+      tmp = s - builtin;\r
+      if (tmp > sizeof(buff) - 1)\r
+        tmp = sizeof(buff) - 1;\r
+      memcpy(buff, builtin, tmp);\r
+      buff[tmp] = 0;\r
+      p = buff;\r
+      builtin = s;\r
+    }\r
+\r
     line++;\r
     p = sskip(p);\r
     if (*p == 0 || *p == '#')\r
@@ -820,6 +851,8 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram)
         carthw_realtec_startup();\r
       else if (strcmp(p, "radica_mapper") == 0)\r
         carthw_radica_startup();\r
+      else if (strcmp(p, "piersolar_mapper") == 0)\r
+        carthw_pier_startup();\r
       else if (strcmp(p, "prot_lk3") == 0)\r
         carthw_prot_lk3_startup();\r
       else {\r
@@ -925,7 +958,9 @@ no_checks:
     skip_sect = 1;\r
     continue;\r
   }\r
-  fclose(f);\r
+\r
+  if (f != NULL)\r
+    fclose(f);\r
 }\r
 \r
 /*\r
@@ -990,3 +1025,4 @@ static void PicoCartDetect(const char *carthw_cfg)
     *(int *) (Pico.rom + 0x1f0) = 0x20204520;\r
 }\r
 \r
+// vim:shiftwidth=2:expandtab\r