From: David Griffith Date: Mon, 13 Aug 2012 07:32:29 +0000 (-0700) Subject: A first stab at getting Blorb to work for DOS. Not there yet. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=7184732894d8012e6f90afbebdb0b9134e1a8fd1;p=liskon_frotz.git A first stab at getting Blorb to work for DOS. Not there yet. --- diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index c5d5aa0..2b6afb9 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -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 */ /* diff --git a/src/dos/bcinit.c b/src/dos/bcinit.c index 59a6f88..742fd6e 100644 --- a/src/dos/bcinit.c +++ b/src/dos/bcinit.c @@ -12,6 +12,7 @@ #include #include "frotz.h" #include "bcfrotz.h" +#include "bcblorb.h" f_setup_t f_setup; @@ -71,6 +72,13 @@ int user_tandy_bit = -1; int user_random_seed = -1; int user_font = 1; + +/* Blorb-related things */ +char *blorb_name; +char *blorb_file; +bool use_blorb; +bool exec_in_blorb; + static byte old_video_mode = 0; static void interrupt (*oldvect) () = NULL; @@ -154,6 +162,27 @@ int hextoi (const char *s) }/* hextoi */ +/* + * basename + * + * A generic and spartan bit of code to extract the filename from a path. + * This one is so trivial that it's okay to steal. + */ +char *basename(const char *path) +{ + const char *s; + const char *p; + p = s = path; + + while (*s) { + if (*s++ == '\\') { + p = s; + } + } + return (char *) p; +} /* basename */ + + /* * cleanup * @@ -377,6 +406,16 @@ void os_process_arguments (int argc, char *argv[]) progname = argv[0]; + blorb_file = strdup(f_setup.story_name); + strcat(blorb_file, ".blb"); + + switch (dos_init_blorb()) { + case bb_err_Format: + printf("Blorb file loaded, but unable to build map.\n\n"); + break; + default: + printf("Blorb error code %i\n\n"); + } }/* os_process_arguments */ /* @@ -846,3 +885,67 @@ FILE *os_path_open (const char *name, const char *mode) return NULL; }/* os_path_open */ +/* + * os_load_story + * + * This is different from os_path_open() because we need to see if the + * story file is actually a chunk inside a blorb file. Right now we're + * looking only at the exact path we're given on the command line. + * + * Open a file in the current directory. If this fails, then search the + * directories in the ZCODE_PATH environmental variable. If that's not + * defined, search INFOCOM_PATH. + * + */ + +FILE *os_load_story(void) +{ + FILE *fp; + + /* Did we build a valid blorb map? */ + if (exec_in_blorb) { + fp = fopen(blorb_file, "rb"); + fseek(fp, blorb_res.data.startpos, SEEK_SET); + } else { + fp = fopen(f_setup.story_file, "rb"); + } + return fp; +} + +int dos_init_blorb(void) +{ + FILE *blorbfile; + + /* If the filename given on the command line is the same as our + * computed blorb filename, then we will assume the executable + * is contained in the blorb file. + */ + + printf("blorb_file %s\n", blorb_file); + printf("story_file %s\n", f_setup.story_file); + + if (strncmp((char *)basename(f_setup.story_file), + (char *)basename(blorb_file), 55) == 0) { + if ((blorbfile = fopen(blorb_file, "rb")) == NULL) + return bb_err_Read; + blorb_err = bb_create_map(blorbfile, &blorb_map); + + if (blorb_err != bb_err_None) { + return blorb_err; + } + + /* Now we need to locate the EXEC chunk within the blorb file + * and present it to the rest of the program as a file stream. + */ + + blorb_err = bb_load_chunk_by_type(blorb_map, bb_method_FilePos, + &blorb_res, bb_make_id('Z','C','O','D'), 0); + + if (blorb_err == bb_err_None) { + exec_in_blorb = 1; + use_blorb = 1; + } + } + return 0; +} +