A first stab at getting Blorb to work for DOS. Not there yet.
authorDavid Griffith <dave@661.org>
Mon, 13 Aug 2012 07:32:29 +0000 (00:32 -0700)
committerDavid Griffith <dave@661.org>
Mon, 13 Aug 2012 07:32:29 +0000 (00:32 -0700)
src/curses/ux_init.c
src/dos/bcinit.c

index c5d5aa050171de4a47383cfe33b52649f34091bb..2b6afb969cf824cccb0fee6fd951eb6ebd10e97f 100644 (file)
@@ -333,6 +333,10 @@ void os_process_arguments (int argc, char *argv[])
          printf("Blorb file loaded, but unable to build map.\n\n");
          break;
     }
+
+  printf("u_setup.blorb_file %s\n", u_setup.blorb_file);
+  printf("u_setup.blorb_name %s\n", u_setup.blorb_name);
+
 }/* os_process_arguments */
 
 /*
index 59a6f888099de2f8a88b2fdcb9f75c92eb0d81cc..742fd6e57b9fa04bef4466323fa1ab2559aca2bc 100644 (file)
@@ -12,6 +12,7 @@
 #include <string.h>\r
 #include "frotz.h"\r
 #include "bcfrotz.h"\r
+#include "bcblorb.h"\r
 \r
 f_setup_t f_setup;\r
 \r
@@ -71,6 +72,13 @@ int user_tandy_bit = -1;
 int user_random_seed = -1;\r
 int user_font = 1;\r
 \r
+\r
+/* Blorb-related things */\r
+char *blorb_name;\r
+char *blorb_file;\r
+bool use_blorb;\r
+bool exec_in_blorb;\r
+\r
 static byte old_video_mode = 0;\r
 \r
 static void interrupt (*oldvect) () = NULL;\r
@@ -154,6 +162,27 @@ int hextoi (const char *s)
 \r
 }/* hextoi */\r
 \r
+/*\r
+ * basename\r
+ *\r
+ * A generic and spartan bit of code to extract the filename from a path.\r
+ * This one is so trivial that it's okay to steal.\r
+ */\r
+char *basename(const char *path)\r
+{\r
+    const char *s;\r
+    const char *p;\r
+    p = s = path;\r
+\r
+    while (*s) {\r
+        if (*s++ == '\\') {\r
+            p = s;\r
+        }\r
+    }\r
+    return (char *) p;\r
+} /* basename */\r
+\r
+\r
 /*\r
  * cleanup\r
  *\r
@@ -377,6 +406,16 @@ void os_process_arguments (int argc, char *argv[])
 \r
     progname = argv[0];\r
 \r
+    blorb_file = strdup(f_setup.story_name);\r
+    strcat(blorb_file, ".blb");\r
+\r
+    switch (dos_init_blorb()) {\r
+       case bb_err_Format:\r
+           printf("Blorb file loaded, but unable to build map.\n\n");\r
+           break;\r
+       default:\r
+           printf("Blorb error code %i\n\n");\r
+    }\r
 }/* os_process_arguments */\r
 \r
 /*\r
@@ -846,3 +885,67 @@ FILE *os_path_open (const char *name, const char *mode)
     return NULL;\r
 }/* os_path_open */\r
 \r
+/*\r
+ * os_load_story\r
+ *\r
+ * This is different from os_path_open() because we need to see if the\r
+ * story file is actually a chunk inside a blorb file.  Right now we're\r
+ * looking only at the exact path we're given on the command line.\r
+ *\r
+ * Open a file in the current directory.  If this fails, then search the\r
+ * directories in the ZCODE_PATH environmental variable.  If that's not\r
+ * defined, search INFOCOM_PATH.\r
+ *\r
+ */\r
+\r
+FILE *os_load_story(void)\r
+{\r
+    FILE *fp;\r
+\r
+    /* Did we build a valid blorb map? */\r
+    if (exec_in_blorb) {\r
+        fp = fopen(blorb_file, "rb");\r
+        fseek(fp, blorb_res.data.startpos, SEEK_SET);\r
+    } else {\r
+        fp = fopen(f_setup.story_file, "rb");\r
+    }\r
+    return fp;\r
+}\r
+\r
+int dos_init_blorb(void)\r
+{\r
+    FILE *blorbfile;\r
+\r
+    /* If the filename given on the command line is the same as our\r
+     * computed blorb filename, then we will assume the executable\r
+     * is contained in the blorb file.\r
+     */\r
+\r
+    printf("blorb_file %s\n", blorb_file);\r
+    printf("story_file %s\n", f_setup.story_file);\r
+\r
+    if (strncmp((char *)basename(f_setup.story_file),\r
+     (char *)basename(blorb_file), 55) == 0) {\r
+       if ((blorbfile = fopen(blorb_file, "rb")) == NULL)\r
+           return bb_err_Read;\r
+       blorb_err = bb_create_map(blorbfile, &blorb_map);\r
+\r
+       if (blorb_err != bb_err_None) {\r
+           return blorb_err;\r
+       }\r
+\r
+    /* Now we need to locate the EXEC chunk within the blorb file\r
+     * and present it to the rest of the program as a file stream.\r
+     */\r
+\r
+       blorb_err = bb_load_chunk_by_type(blorb_map, bb_method_FilePos,\r
+                       &blorb_res, bb_make_id('Z','C','O','D'), 0);\r
+\r
+       if (blorb_err == bb_err_None) {\r
+           exec_in_blorb = 1;\r
+           use_blorb = 1;\r
+       }\r
+    }\r
+    return 0;\r
+}\r
+\r