build carthw.cfg in
authornotaz <notasas@gmail.com>
Fri, 28 Jun 2013 00:01:53 +0000 (03:01 +0300)
committernotaz <notasas@gmail.com>
Fri, 28 Jun 2013 22:39:17 +0000 (01:39 +0300)
things like libretro don't want external files,
but we still look for one and prefer it if it's available

pico/cart.c
pico/carthw_cfg.c [new file with mode: 0644]
tools/make_carthw_c.c [new file with mode: 0644]

index d86af41..db742a8 100644 (file)
@@ -709,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
@@ -934,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
@@ -999,3 +1025,4 @@ static void PicoCartDetect(const char *carthw_cfg)
     *(int *) (Pico.rom + 0x1f0) = 0x20204520;\r
 }\r
 \r
+// vim:shiftwidth=2:expandtab\r
diff --git a/pico/carthw_cfg.c b/pico/carthw_cfg.c
new file mode 100644 (file)
index 0000000..68782e5
--- /dev/null
@@ -0,0 +1,225 @@
+/* generated by ./tools/make_carthw_c, do not modify */
+static const char builtin_carthw_cfg[] =
+  "[]\n"
+  "check_str=0x150,\"Virtua Racing\"\n"
+  "hw=svp\n"
+  "[]\n"
+  "check_str=0x150,\"VIRTUA RACING\"\n"
+  "hw=svp\n"
+  "[]\n"
+  "check_str=0x100,\"SEGA PICO\"\n"
+  "hw=pico\n"
+  "[]\n"
+  "check_str=0x100,\"IMA IKUNOUJYUKU\"\n"
+  "hw=pico\n"
+  "[]\n"
+  "check_str=0x120,\"PUGGSY\"\n"
+  "prop=no_sram\n"
+  "[]\n"
+  "check_str=0x150,\"DINO DINI'S SOCCER\"\n"
+  "prop=filled_sram\n"
+  "[]\n"
+  "check_str=0x150,\"MICRO MACHINES II\"\n"
+  "prop=filled_sram\n"
+  "[]\n"
+  "check_str=0x150,\"SUPER STREET FIGHTER2 The New Challengers\"\n"
+  "hw=ssf2_mapper\n"
+  "prop=no_sram\n"
+  "[]\n"
+  "check_str=0x150,\"PIER SOLAR\99&THE GREAT ARCHITECTS© WaterMelon\99\"\n"
+  "hw=piersolar_mapper\n"
+  "sram_range=0xa13009,0xa1300b\n"
+  "eeprom_type=3\n"
+  "eeprom_lines=2,1,0\n"
+  "[]\n"
+  "check_str=0x120,\"FLICKY\"\n"
+  "check_size_gt=0x020000\n"
+  "hw=x_in_1_mapper\n"
+  "[]\n"
+  "check_str=0x150,\"ROBOCOP 3\"\n"
+  "check_size_gt=0x080000\n"
+  "hw=x_in_1_mapper\n"
+  "[]\n"
+  "check_str=0x150,\"ALIEN 3\"\n"
+  "check_size_gt=0x080000\n"
+  "hw=x_in_1_mapper\n"
+  "[]\n"
+  "check_str=0x150,\" SHOVE IT!\"\n"
+  "check_size_gt=0x020000\n"
+  "hw=x_in_1_mapper\n"
+  "[]\n"
+  "check_str=0x150,\"MS PACMAN\"\n"
+  "check_size_gt=0x020000\n"
+  "hw=x_in_1_mapper\n"
+  "[]\n"
+  "check_str=0x150,\"KID CHAMELEON\"\n"
+  "check_size_gt=0x100000\n"
+  "hw=radica_mapper\n"
+  "[]\n"
+  "check_str=0x94,\"THE EARTH DEFEND\"\n"
+  "hw=realtec_mapper\n"
+  "[]\n"
+  "check_str=0xfe,\"WISEGAME 11-03-1993\"\n"
+  "hw=realtec_mapper\n"
+  "[]\n"
+  "check_str=0x95,\"MALLET LEGEND\"\n"
+  "hw=realtec_mapper\n"
+  "[]\n"
+  "check_str=0x150,\"COLLEGE SLAM\"\n"
+  "eeprom_type=3\n"
+  "eeprom_lines=8,0,0\n"
+  "[]\n"
+  "check_str=0x150,\"FRANK THOMAS BIGHURT BASEBAL\"\n"
+  "eeprom_type=3\n"
+  "eeprom_lines=8,0,0\n"
+  "[]\n"
+  "check_str=0x150,\"MICRO MACHINES II\"\n"
+  "sram_range=0x300000,0x380001\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=9,8,7\n"
+  "[]\n"
+  "check_str=0x150,\"                \"\n"
+  "check_csum=0x165e\n"
+  "sram_range=0x300000,0x380001\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=9,8,7\n"
+  "[]\n"
+  "check_str=0x150,\"                \"\n"
+  "check_csum=0x2c41\n"
+  "sram_range=0x300000,0x380001\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=9,8,7\n"
+  "[]\n"
+  "check_str=0x150,\"                \"\n"
+  "check_csum=0x168b\n"
+  "sram_range=0x300000,0x380001\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=9,8,7\n"
+  "[]\n"
+  "check_str=0x150,\"                \"\n"
+  "check_csum=0xcee0\n"
+  "sram_range=0x300000,0x380001\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=9,8,7\n"
+  "[]\n"
+  "check_str=0x150,\"NBA JAM         \"\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=1,0,1\n"
+  "[]\n"
+  "check_str=0x150,\"NBA JAM TOURNAMENT EDITION\"\n"
+  "sram_range=0x200000,0x200001\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=8,0,0\n"
+  "[]\n"
+  "check_str=0x150,\"NFL QUARTERBACK CLUB\"\n"
+  "eeprom_type=2\n"
+  "eeprom_lines=8,0,0\n"
+  "[]\n"
+  "check_str=0x150,\"NHLPA Hockey '93\"\n"
+  "sram_range=0x200000,0x200001\n"
+  "eeprom_type=1\n"
+  "eeprom_lines=6,7,7\n"
+  "[]\n"
+  "check_str=0x150,\"NHLPA HOCKEY '93\"\n"
+  "sram_range=0x200000,0x200001\n"
+  "eeprom_type=1\n"
+  "eeprom_lines=6,7,7\n"
+  "[]\n"
+  "check_str=0x150,\"RINGS OF POWER\"\n"
+  "sram_range=0x200000,0x200001\n"
+  "eeprom_type=1\n"
+  "eeprom_lines=6,7,7\n"
+  "[]\n"
+  "check_str=0x104,\"                \"\n"
+  "check_crc32=0x10458e09\n"
+  "hw=prot\n"
+  "prot_ro_value16=0xa13000,0xffff00,0x28\n"
+  "[]\n"
+  "check_str=0x172,\"GAME : ELF WOR\"\n"
+  "hw=prot\n"
+  "prot_ro_value16=0x400000,-2,0x5500\n"
+  "prot_ro_value16=0x400002,-2,0xc900#checkisdoneiftheaboveonefails\n"
+  "prot_ro_value16=0x400004,-2,0x0f00\n"
+  "prot_ro_value16=0x400006,-2,0x1800#similartoabove\n"
+  "[]\n"
+  "check_str=0x104,\"                \"\n"
+  "check_crc32=0xcbc38eea\n"
+  "hw=prot\n"
+  "prot_ro_value16=0x480000,0xff0000,0xaa00\n"
+  "prot_ro_value16=0x4a0000,0xff0000,0x0a00\n"
+  "prot_ro_value16=0x4c0000,0xff0000,0xf000\n"
+  "prot_ro_value16=0x400000,0xc00000,0x0000#defaultfor400000-7f0000\n"
+  "[]\n"
+  "check_str=0x104,\" are Registered  Trademarks\"\n"
+  "check_crc32=0xc004219d\n"
+  "hw=prot_lk3\n"
+  "[]\n"
+  "check_str=0x104,\" are Registered  Trademarks\"\n"
+  "check_crc32=0xaff46765\n"
+  "hw=prot\n"
+  "prot_rw_value16=0x400000,0xc00004,0\n"
+  "prot_rw_value16=0x400004,0xc00004,0\n"
+  "[]\n"
+  "check_str=0x118,\"CREATON. \"\n"
+  "check_crc32=0xddd02ba4\n"
+  "hw=prot\n"
+  "prot_ro_value16=0x400000,-2,0x9000\n"
+  "prot_ro_value16=0x401000,-2,0xd300\n"
+  "[]\n"
+  "check_str=0x104,\"                \"\n"
+  "check_crc32=0xf68f6367\n"
+  "hw=prot\n"
+  "prot_ro_value16=0xa13002,-2,0x01\n"
+  "prot_ro_value16=0xa1303e,-2,0x1f\n"
+  "[]\n"
+  "check_str=0x104,\"                \"\n"
+  "check_crc32=0xfb176667\n"
+  "hw=prot\n"
+  "prot_ro_value16=0xa13000,-2,0x14\n"
+  "prot_ro_value16=0xa13002,-2,0x01\n"
+  "prot_ro_value16=0xa1303e,-2,0x1f\n"
+  "[]\n"
+  "check_csum=0\n"
+  "check_crc32=0x3ee639f0\n"
+  "hw=prot\n"
+  "prot_ro_value16=0xa13000,-2,0x0c\n"
+  "[]\n"
+  "check_csum=0\n"
+  "check_crc32=0xdecdf740\n"
+  "hw=prot\n"
+  "prot_ro_value16=0x400000,-2,0x5500\n"
+  "prot_ro_value16=0x400002,-2,0x0f00\n"
+  "prot_ro_value16=0x400004,-2,0xaa00\n"
+  "prot_ro_value16=0x400006,-2,0xf000\n"
+  "[]\n"
+  "check_str=0x104,\"                \"\n"
+  "check_crc32=0xf26f88d1\n"
+  "hw=prot\n"
+  "prot_ro_value16=0x400002,-2,0x9800\n"
+  "prot_ro_value16=0x400004,-2,0xaa00#or0xc900\n"
+  "prot_ro_value16=0x400006,-2,0xf000\n"
+  "[]\n"
+  "check_str=0x104,\" are Registered  Trademarks\"\n"
+  "check_crc32=0x4820a161\n"
+  "hw=prot\n"
+  "prot_ro_value16=0x400000,-2,0x5500\n"
+  "prot_ro_value16=0x400002,-2,0x0f00\n"
+  "[]\n"
+  "check_str=0x104,\" are Registered  Trademarks\"\n"
+  "check_crc32=0x413dfee2\n"
+  "hw=prot_lk3\n"
+  "[]\n"
+  "check_str=0x140,\"SUPER MARIO BROS \"\n"
+  "hw=prot\n"
+  "prot_ro_value16=0xa13000,-2,0x0c\n"
+  "[]\n"
+  "check_str=0x104,\" are Registered  Trademarks\"\n"
+  "check_crc32=0xf7e1b3e1\n"
+  "hw=prot\n"
+  "prot_ro_value16=0xa13000,-2,0x0a\n"
+  "[]\n"
+  "check_str=0x104,\" are Registered  Trademarks\"\n"
+  "check_crc32=0xb8261ff5\n"
+  "hw=prot\n"
+  "prot_rw_value16=0x400000,0xc00000,0\n"
+;
diff --git a/tools/make_carthw_c.c b/tools/make_carthw_c.c
new file mode 100644 (file)
index 0000000..480a6fe
--- /dev/null
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+int main(int argc, char *argv[])
+{
+       FILE *fi, *fo;
+       char buf[256];
+
+       if (argc != 3) {
+               printf("usage:\n%s <carthw.cfg> <carthw.c>\n", argv[0]);
+               return 1;
+       }
+
+       fi = fopen(argv[1], "r");
+       fo = fopen(argv[2], "w");
+       if (fi == NULL || fo == NULL) {
+               printf("fopen failed\n");
+               return 1;
+       }
+
+       fprintf(fo, "/* generated by %s, do not modify */\n", argv[0]);
+       fprintf(fo, "static const char builtin_carthw_cfg[] =\n");
+
+       while ((fgets(buf, sizeof(buf), fi)))
+       {
+               char bufd[256];
+               char *d = bufd, *p = buf;
+               int quote = 0;
+
+               while (*p && isspace(*p))
+                       p++;
+
+               if (*p == 0 || *p == '#')
+                       continue;
+
+               /* section names not needed */
+               if (*p == '[')
+                       strcpy(p, "[]");
+
+               for (; *p != 0; p++) {
+                       if (!quote && isspace(*p))
+                               continue;
+                       if (*p == '"') {
+                               quote = !quote;
+                               *d++ = '\\';
+                       }
+                       *d++ = *p;
+               }
+               *d = 0;
+
+
+               fprintf(fo, "  \"%s\\n\"\n", bufd);
+       }
+
+       fprintf(fo, ";\n");
+
+       fclose(fi);
+       fclose(fo);
+
+       return 0;
+}