From: Bill Lash Date: Fri, 15 May 2015 01:42:05 +0000 (-0500) Subject: Fixing restart in games that have zcode in blorb files. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=7dc88dcebd295056956df441b5c80cc02afe0b6a;p=liskon_frotz.git Fixing restart in games that have zcode in blorb files. --- diff --git a/src/common/fastmem.c b/src/common/fastmem.c index 07a254e..f29ff2d 100644 --- a/src/common/fastmem.c +++ b/src/common/fastmem.c @@ -59,6 +59,8 @@ extern void script_close (void); extern FILE *os_path_open (const char *, const char *); extern FILE *os_load_story (void); +extern int os_storyfile_seek (FILE * fp, long offset, int whence); +extern int os_storyfile_tell (FILE * fp); extern zword save_quetzal (FILE *, FILE *); extern zword restore_quetzal (FILE *, FILE *); @@ -327,9 +329,9 @@ void init_memory (void) } else { /* some old games lack the file size entry */ - fseek (story_fp, 0, SEEK_END); - story_size = ftell (story_fp); - fseek (story_fp, 64, SEEK_SET); + os_storyfile_seek (story_fp, 0, SEEK_END); + story_size = os_storyfile_tell (story_fp); + os_storyfile_seek (story_fp, 64, SEEK_SET); } @@ -539,7 +541,7 @@ void z_restart (void) if (!first_restart) { - fseek (story_fp, 0, SEEK_SET); + os_storyfile_seek (story_fp, 0, SEEK_SET); if (fread (zmp, 1, h_dynamic_size, story_fp) != h_dynamic_size) os_fatal ("Story file read error"); @@ -697,7 +699,7 @@ void z_restore (void) stack[i] |= fgetc (gfp); } - fseek (story_fp, 0, SEEK_SET); + os_storyfile_seek (story_fp, 0, SEEK_SET); for (addr = 0; addr < h_dynamic_size; addr++) { int skip = fgetc (gfp); @@ -986,7 +988,7 @@ void z_save (void) fputc ((int) lo (stack[i]), gfp); } - fseek (story_fp, 0, SEEK_SET); + os_storyfile_seek (story_fp, 0, SEEK_SET); for (addr = 0, skip = 0; addr < h_dynamic_size; addr++) if (zmp[addr] != fgetc (story_fp) || skip == 255 || addr + 1 == h_dynamic_size) { @@ -1112,7 +1114,8 @@ void z_verify (void) /* Sum all bytes in story file except header bytes */ - fseek (story_fp, 64, SEEK_SET); + os_storyfile_seek (story_fp, 64, SEEK_SET); + for (i = 64; i < story_size; i++) checksum += fgetc (story_fp); diff --git a/src/common/quetzal.c b/src/common/quetzal.c index c2e9f1e..ac06055 100644 --- a/src/common/quetzal.c +++ b/src/common/quetzal.c @@ -48,6 +48,12 @@ #define get_c fgetc #define put_c fputc +/* + * externs + */ + +extern int os_storyfile_seek(FILE * fp, long offset, int whence); + typedef unsigned long zlong; /* @@ -321,7 +327,7 @@ zword restore_quetzal (FILE *svf, FILE *stf) case ID_CMem: if (!(progress & GOT_MEMORY)) /* Don't complain if two. */ { - (void) fseek (stf, 0, SEEK_SET); + (void) os_storyfile_seek (stf, 0, SEEK_SET); i=0; /* Bytes written to data area. */ for (; currlen > 0; --currlen) { @@ -442,7 +448,7 @@ zword save_quetzal (FILE *svf, FILE *stf) /* Write `CMem' chunk. */ if ((cmempos = ftell (svf)) < 0) return 0; if (!write_chnk (svf, ID_CMem, 0)) return 0; - (void) fseek (stf, 0, SEEK_SET); + (void) os_storyfile_seek (stf, 0, SEEK_SET); /* j holds current run length. */ for (i=0, j=0, cmemlen=0; i < h_dynamic_size; ++i) { diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index b7bf62b..b11b195 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -622,6 +622,53 @@ FILE *os_load_story(void) return fp; } +/* + * Seek into a storyfile, either a standalone file or the + * ZCODE chunk of a blorb file + */ +int os_storyfile_seek(FILE * fp, long offset, int whence) +{ + /* Is this a Blorb file containing Zcode? */ + if (u_setup.exec_in_blorb) + { + switch (whence) + { + case SEEK_END: + return fseek(fp, blorb_res.data.startpos + blorb_res.length + offset, SEEK_SET); + break; + case SEEK_CUR: + return fseek(fp, offset, SEEK_CUR); + break; + case SEEK_SET: + default: + return fseek(fp, blorb_res.data.startpos + offset, SEEK_SET); + break; + } + } + else + { + return fseek(fp, offset, whence); + } + +} + +/* + * Tell the position in a storyfile, either a standalone file + * or the ZCODE chunk of a blorb file + */ +int os_storyfile_tell(FILE * fp) +{ + /* Is this a Blorb file containing Zcode? */ + if (u_setup.exec_in_blorb) + { + return ftell(fp) - blorb_res.data.startpos; + } + else + { + return ftell(fp); + } + +} /* * pathopen diff --git a/src/dos/bcinit.c b/src/dos/bcinit.c index 4671e85..2d426bc 100644 --- a/src/dos/bcinit.c +++ b/src/dos/bcinit.c @@ -949,3 +949,51 @@ int dos_init_blorb(void) return 0; } +/* + * Seek into a storyfile, either a standalone file or the + * ZCODE chunk of a blorb file + */ +int os_storyfile_seek(FILE * fp, long offset, int whence) +{ + /* Is this a Blorb file containing Zcode? */ + if (exec_in_blorb) + { + switch (whence) + { + case SEEK_END: + return fseek(fp, blorb_res.data.startpos + blorb_res.length + offset, SEEK_SET); + break; + case SEEK_CUR: + return fseek(fp, offset, SEEK_CUR); + break; + case SEEK_SET: + default: + return fseek(fp, blorb_res.data.startpos + offset, SEEK_SET); + break; + } + } + else + { + return fseek(fp, offset, whence); + } + +} + +/* + * Tell the position in a storyfile, either a standalone file + * or the ZCODE chunk of a blorb file + */ +int os_storyfile_tell(FILE * fp) +{ + /* Is this a Blorb file containing Zcode? */ + if (exec_in_blorb) + { + return ftell(fp) - blorb_res.data.startpos; + } + else + { + return ftell(fp); + } + +} + diff --git a/src/dumb/dumb_init.c b/src/dumb/dumb_init.c index ec900dd..2256687 100644 --- a/src/dumb/dumb_init.c +++ b/src/dumb/dumb_init.c @@ -175,6 +175,27 @@ FILE *os_load_story(void) return fopen(f_setup.story_file, "rb"); } +/* + * Seek into a storyfile, either a standalone file or the + * ZCODE chunk of a blorb file (dumb does not support blorb + * so this is just a wrapper for fseek) + */ +int os_storyfile_seek(FILE * fp, long offset, int whence) +{ + return fseek(fp, offset, whence); +} + +/* + * Tell the position in a storyfile, either a standalone file + * or the ZCODE chunk of a blorb file (dumb does not support + * blorb so this is just a wrapper for fseek) + */ +int os_storyfile_tell(FILE * fp) +{ + return ftell(fp); +} + + void os_init_setup(void) { f_setup.attribute_assignment = 0;