Begining re-adding 2.44 code (this time cleanly for DOS)
authorDavid Griffith <dave@661.org>
Tue, 10 Jan 2012 09:58:15 +0000 (01:58 -0800)
committerDavid Griffith <dave@661.org>
Tue, 10 Jan 2012 09:58:15 +0000 (01:58 -0800)
14 files changed:
Makefile
src/blorb/blorblib.o [deleted file]
src/common/buffer.c
src/common/fastmem.c
src/common/frotz.h
src/common/input.c
src/common/setup.h
src/curses/ux_frotz.h
src/curses/ux_init.c
src/curses/ux_setup.h
src/dos/bcfrotz.h
src/dos/bcinit.c
src/dos/bcsample.c
src/sdl/sf_frotz.h

index 64b4d96c20b68ba99afd375f17a0639d445149cc..28e871c5431ab0092751940aceefcaa2755056dc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -150,29 +150,56 @@ DUMB_OBJECT =     $(DUMB_DIR)/dumb_init.o \
                $(DUMB_DIR)/dumb_output.o \
                $(DUMB_DIR)/dumb_pic.o
 
-TARGETS = $(COMMON_TARGET) $(CURSES_TARGET)
+SDL_DIR = $(SRCDIR)/sdl
+SDL_TARGET = $(SRCDIR)/frotz_sdl.a
+SDL_OBJECT =   $(SDL_DIR)/sf_aiffwav.o \
+               $(SDL_DIR)/sf_deffont.o \
+               $(SDL_DIR)/sf_font3.o \
+               $(SDL_DIR)/sf_fonts.o \
+               $(SDL_DIR)/sf_ftype.o \
+               $(SDL_DIR)/sf_images.o \
+               $(SDL_DIR)/sf_msg_en.o \
+               $(SDL_DIR)/sf_osfdlg.o \
+               $(SDL_DIR)/sf_resample.o \
+               $(SDL_DIR)/sf_resource.o \
+               $(SDL_DIR)/sf_sig.o \
+               $(SDL_DIR)/sf_sound.o \
+               $(SDL_DIR)/sf_util.o \
+               $(SDL_DIR)/sf_video.o
+
+# Blorb file handling
+#
+BLORB_DIR = $(SRCDIR)/blorb
+BLORB_TARGET =  $(SRCDIR)/blorblib.a
+BLORB_OBJECT =  $(BLORB_DIR)/blorblib.o
+
+
+TARGETS = $(COMMON_TARGET) $(CURSES_TARGET) $(BLORB_TARGET)
 
 OPT_DEFS = -DCONFIG_DIR="\"$(CONFIG_DIR)\"" $(CURSES_DEF) \
-       -DVERSION="\"$(VERSION)\"" -DSOUND_DEV="\"$(SOUND_DEV)\""
+       -DVERSION="\"$(VERSION)\""
 
-COMP_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \
+CURSES_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \
        $(MEMMOVE_DEF)
 
-FLAGS = $(OPTS) $(COMP_DEFS) $(INCL)
+FLAGS = $(OPTS) $(CURSES_DEFS) $(INCL)
 
 $(NAME): $(NAME)-curses
-
-$(NAME)-curses:                soundcard.h  $(COMMON_TARGET) $(CURSES_TARGET)
-       $(CC) -o $(BINNAME)$(EXTENSION) $(TARGETS) $(LIB) $(CURSES) \
-               $(SOUND_LIB)
+curses:  $(NAME)-curses
+$(NAME)-curses:                soundcard.h  $(COMMON_TARGET) $(CURSES_TARGET) $(BLORB_TARGET)
+       $(CC) -o $(BINNAME)$(EXTENSION) $(TARGETS) $(LIB) $(CURSES) $(SOUND_LIB)
 
 all:   $(NAME) d$(NAME)
 
 dumb:          $(NAME)-dumb
 d$(NAME):      $(NAME)-dumb
 $(NAME)-dumb:          $(COMMON_TARGET) $(DUMB_TARGET)
-       $(CC) -o d$(BINNAME)$(EXTENSION) $(COMMON_TARGET) \
-               $(DUMB_TARGET) $(LIB)
+       $(CC) -o d$(BINNAME)$(EXTENSION) $(COMMON_TARGET) $(DUMB_TARGET) $(LIB)
+
+sdl:           $(NAME)-sdl
+s$(NAME):      $(NAME)-sdl
+$(NAME)-sdl:   $(COMMON_TARGET) $(SDL_TARGET)
+       $(CC) -o s$(BINNAME) $(COMMON_TARGET) $(SDL_TARGET) $(SDL_LIBS)
 
 .SUFFIXES:
 .SUFFIXES: .c .o .h
@@ -207,6 +234,23 @@ $(DUMB_TARGET): $(DUMB_OBJECT)
        ranlib $(DUMB_TARGET)
        @echo
 
+sdl_lib:       $(SDL_TARGET)
+$(SDL_TARGET): $(SDL_OBJECT)
+       @echo
+       @echo "Archiving SDL interface code..."
+       ar rc $(SDL_TARGET) $(SDL_OBJECT)
+       ranlib $(SDL_TARGET)
+       @echo
+
+blorb_lib:     $(BLORB_TARGET)
+$(BLORB_TARGET): $(BLORB_OBJECT)
+       @echo
+       @echo "Archiving Blorb file handling code..."
+       ar rc $(BLORB_TARGET) $(BLORB_OBJECT)
+       ranlib $(BLORB_TARGET)
+       @echo
+
+
 soundcard.h:
        @if [ ! -f $(SRCDIR)/soundcard.h ] ; then \
                 sh $(SRCDIR)/misc/findsound.sh $(SRCDIR); \
@@ -257,10 +301,10 @@ dist: distclean
 
 clean:
        rm -f $(SRCDIR)/*.h $(SRCDIR)/*.a
-       rm -f $(COMMON_DIR)/*.o $(CURSES_DIR)/*.o $(DUMB_DIR)/*.o
+       rm -f $(COMMON_DIR)/*.o $(CURSES_DIR)/*.o $(DUMB_DIR)/*.o $(BLORB_DIR)/*.o $(SDL_DIR)/*.o
 
 distclean: clean
-       rm -f $(BINNAME)$(EXTENSION) d$(BINNAME)$(EXTENSION)
+       rm -f $(BINNAME)$(EXTENSION) d$(BINNAME)$(EXTENSION) s$(BINNAME)
        rm -f $(BINNAME).exe $(BINNAME).bak $(BINNAME).lib
        rm -f *core $(SRCDIR)/*core
        -rm -rf $(distdir)
diff --git a/src/blorb/blorblib.o b/src/blorb/blorblib.o
deleted file mode 100644 (file)
index 4dfc2c9..0000000
Binary files a/src/blorb/blorblib.o and /dev/null differ
index 5800a6bc811be956b29840c277276fabaf803b89..1feb98be8be3ecd683fa2bf7397334498643fde7 100644 (file)
@@ -18,6 +18,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <string.h>
 #include "frotz.h"
 
 extern void stream_char (zchar);
index 12ab84b887b30854e7c8cda28cd941af7e505540..694c42185afb0162405de6a931a3fb924de39dc7 100644 (file)
@@ -58,6 +58,7 @@ extern void script_open (void);
 extern void script_close (void);
 
 extern FILE *os_path_open (const char *, const char *);
+extern FILE *os_load_story (void);
 
 extern zword save_quetzal (FILE *, FILE *);
 extern zword restore_quetzal (FILE *, FILE *);
index debcbe4f34f1c1a8342acdcfad8288a563a93835..a1c1a41a738e6230c2a3c5129fd5284db9224cf0 100644 (file)
@@ -65,6 +65,14 @@ typedef unsigned char zchar;
 #define STACK_SIZE 1024
 #endif
 
+/* Assorted filename extensions */
+
+#define EXT_SAVE       ".qzl"
+#define EXT_SCRIPT     ".scr"
+#define EXT_BLORB      ".blb"
+#define EXT_COMMAND    ".rec"
+#define EXT_AUX                ".aux"
+
 #ifndef DEFAULT_SAVE_NAME
 #define DEFAULT_SAVE_NAME "story.sav"
 #endif
@@ -371,7 +379,6 @@ extern zbyte *zmp;
 
 
 /*** Story file header data ***/
-
 extern zbyte h_version;
 extern zbyte h_config;
 extern zword h_release;
@@ -631,6 +638,10 @@ void       runtime_error (int);
 
 #define ERR_DEFAULT_REPORT_MODE ERR_REPORT_ONCE
 
+/*** Assorted initialization functions ***/
+void   init_buffer (void);
+void   init_process (void);
+void   init_sound (void);
 
 /*** Various global functions ***/
 
index 370d554fe7c4f7b811d384fd8a2e8580f9c25564..ae65d03f3d077780dca04cf36bca840860190591 100644 (file)
@@ -294,8 +294,14 @@ void z_read_char (void)
 
     /* Store key */
 
-    store (translate_to_zscii (key));
-
+    /* For timeouts, make sure translate_to_zscii() won't try to convert
+     * 0x00.  We should instead return 0x00 as is.
+     * Thanks to Peter Seebach.
+     */
+    if (key == 0)
+       store(key);
+    else
+       store (translate_to_zscii (key));
 }/* z_read_char */
 
 /*
index a9b93601226ea9ecc6fb6ddffc66d126056a25c3..28e0d259b633a0a4fe81fa4507c8712c7dc8aa9e 100644 (file)
@@ -24,44 +24,47 @@ typedef struct frotz_setup_struct {
 
 extern f_setup_t f_setup;
 
-
+/*** Story file header data ***/
+/*
 typedef struct zcode_header_struct {
-       zbyte h_version;
-       zbyte h_config;
-       zword h_release;
-       zword h_resident_size;
-       zword h_start_pc;
-       zword h_dictionary;
-       zword h_objects;
-       zword h_globals;
-       zword h_dynamic_size;
-       zword h_flags;
-       zbyte h_serial[6];
-       zword h_abbreviations;
-       zword h_file_size;
-       zword h_checksum;
-       zbyte h_interpreter_number;
-       zbyte h_interpreter_version;
-       zbyte h_screen_rows;
-       zbyte h_screen_cols;
-       zword h_screen_width;
-       zword h_screen_height;
-       zbyte h_font_height;
-       zbyte h_font_width;
-       zword h_functions_offset;
-       zword h_strings_offset;
-       zbyte h_default_background;
-       zbyte h_default_foreground;
-       zword h_terminating_keys;
-       zword h_line_width;
-       zbyte h_standard_high;
-       zbyte h_standard_low;
-       zword h_alphabet;
-       zword h_extension_table;
-       zbyte h_user_name[8];
+       zbyte version;
+       zbyte config;
+       zword release;
+       zword resident_size;
+       zword start_pc;
+       zword dictionary;
+       zword objects;
+       zword globals;
+       zword dynamic_size;
+       zword flags;
+       zbyte serial[6];
+       zword abbreviations;
+       zword file_size;
+       zword checksum;
+       zbyte interpreter_number;
+       zbyte interpreter_version;
+       zbyte screen_rows;
+       zbyte screen_cols;
+       zword screen_width;
+       zword screen_height;
+       zbyte font_height;
+       zbyte font_width;
+       zword functions_offset;
+       zword strings_offset;
+       zbyte default_background;
+       zbyte default_foreground;
+       zword terminating_keys;
+       zword line_width;
+       zbyte standard_high;
+       zbyte standard_low;
+       zword alphabet;
+       zword extension_table;
+       zbyte user_name[8];
 
        zword hx_table_size;
        zword hx_mouse_x;
        zword hx_mouse_y;
        zword hx_unicode_table;
 } z_header_t;
+extern z_header_t z_header;
+*/
index f055b73c4c56009fb246682c98c945b086d6fadf..19855eb683ff7d6c3e650b0250f991606e709089 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "../common/frotz.h"
+#include "../blorb/blorb.h"
 #include "ux_setup.h"
 
 #define MASTER_CONFIG          "frotz.conf"
@@ -78,15 +79,29 @@ extern f_setup_t f_setup;
 extern u_setup_t u_setup;
 
 
+/*** Blorb related stuff ***/
+bb_err_t       blorb_err;
+bb_map_t       *blorb_map;
+bb_result_t    blorb_res;
+
+
 /*** Functions specific to the Unix port of Frotz ***/
 
-bool   unix_init_pictures(void);       /* ux_pic */
+bool unix_init_pictures(void);         /* ux_pic.c */
+bool unix_init_pictures(void);         /* ux_pic.c */
+void unix_init_scrollback(void);       /* ux_screen.c */
+void unix_save_screen(int);            /* ux_screen.c */
+void unix_do_scrollback(void);         /* ux_screen.c */
+
+
+
 int     getconfig(char *);
 int     geterrmode(char *);
 int     getcolor(char *);
 int     getbool(char *);
 FILE   *pathopen(const char *, const char *, const char *, char *);
-void   sig_winch_handler(int);
+void   sigwinch_handler(int);
+void    sigint_handler(int);
 void   redraw(void);
 
 
index 9f5b12fc97c1e0a702a12b97eea55df2cba06f29..95cd6f71eb2c5b03054af86d4b4bb545f6f19edc 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <unistd.h>
 #include <ctype.h>
+#include <signal.h>
 
 /* We will use our own private getopt functions. */
 #include "getopt.h"
@@ -55,9 +56,9 @@ Syntax: frotz [options] story-file\n\
   -a   watch attribute setting  \t -O   watch object locating\n\
   -A   watch attribute testing  \t -p   plain ASCII output only\n\
   -b # background color         \t -P   alter piracy opcode\n\
-  -c # context lines            \t -r # right margin\n\
-  -d   disable color            \t -q   quiet (disable sound effects)\n\
-  -e   enable sound             \t -Q   use old-style save format\n\
+  -c # context lines            \t -q   quiet (disable sound effects)\n\
+  -d   disable color            \t -Q   use old-style save format\n\
+  -e   enable sound             \t -r # right margin\n\
   -f # foreground color         \t -s # random number seed value\n\
   -F   Force color mode         \t -S # transscript width\n\
   -h # screen height            \t -t   set Tandy bit\n\
@@ -161,9 +162,12 @@ void os_process_arguments (int argc, char *argv[])
 
 /*
     if (signal(SIGWINCH, SIG_IGN) != SIG_IGN)
-       signal(SIGWINCH, sig_winch_handler);
+       signal(SIGWINCH, sigwinch_handler);
 */
 
+    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+       signal(SIGINT, sigint_handler);
+
     /* First check for a "$HOME/.frotzrc". */
     /* If not found, look for CONFIG_DIR/frotz.conf */
     /* $HOME/.frotzrc overrides CONFIG_DIR/frotz.conf */
@@ -188,6 +192,8 @@ void os_process_arguments (int argc, char *argv[])
          case 'A': f_setup.attribute_testing = 1; break;
 
          case 'b': u_setup.background_color = atoi(optarg);
+               u_setup.force_color = 1;
+               u_setup.disable_color = 0;
                if ((u_setup.background_color < 2) ||
                    (u_setup.background_color > 9))
                  u_setup.background_color = -1;
@@ -195,11 +201,15 @@ void os_process_arguments (int argc, char *argv[])
          case 'c': f_setup.context_lines = atoi(optarg); break;
          case 'd': u_setup.disable_color = 1; break;
          case 'e': f_setup.sound = 1; break;
-         case 'f': u_setup.foreground_color = atoi(optarg);
+         case 'f': u_setup.foreground_color = getcolor(optarg);
+                   u_setup.force_color = 1;
+                   u_setup.disable_color = 0;
                    if ((u_setup.foreground_color < 2) ||
                        (u_setup.foreground_color > 9))
-                     u_setup.foreground_color = -1;
+                       u_setup.foreground_color = -1;
                    break;
+
+
          case 'F': u_setup.force_color = 1;
                    u_setup.disable_color = 0;
                    break;
@@ -529,6 +539,33 @@ FILE *os_path_open(const char *name, const char *mode)
        return NULL;    /* give up */
 } /* 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 (u_setup.exec_in_blorb) {
+       fp = fopen(u_setup.blorb_file, "rb");
+       fseek(fp, blorb_res.data.startpos, SEEK_SET);
+    } else {
+       fp = fopen(story_name, "rb");
+    }
+    return fp;
+}
+
+
 /*
  * pathopen
  *
@@ -826,14 +863,14 @@ int geterrmode(char *value)
 
 
 /*
- * sig_winch_handler
+ * sigwinch_handler
  *
  * Called whenever Frotz recieves a SIGWINCH signal to make curses
  * cleanly resize the window.
  *
  */
 
-void sig_winch_handler(int sig)
+void sigwinch_handler(int sig)
 {
 /*
 There are some significant problems involved in getting resizes to work
@@ -843,13 +880,22 @@ explaination for this.  Because of this trouble, this function currently
 does nothing.
 */
 
+}
+
 /*
-       signal(sig, SIG_DFL);
-       signal(sig, SIG_IGN);
+ * sigint_handler
+ * Sometimes the screen will be left in a weird state if the following
+ * is not done.
+ *
+ */
+void sigint_handler(int dummy)
+{
+    signal(SIGINT, sigint_handler);
 
+    scrollok(stdscr, TRUE); scroll(stdscr);
+    refresh(); endwin();
 
-       signal(SIGWINCH, sig_winch_handler);
-*/
+    exit(1);
 }
 
 void redraw(void)
index 1a1677099fab06644eeed8a789b5f2cd3cc37f48..a3329198497b319c04e680ac07d8b89757a8bbdc 100644 (file)
@@ -13,6 +13,11 @@ typedef struct unix_setup_struct {
        int current_color;              /* ux_text.c ux_screen.c */
        bool color_enabled;             /* ux_init.c ux_pic.c ux_text.c */
 
+       char *blorb_name;
+       char *blorb_file;
+       bool use_blorb;
+       bool exec_in_blorb;
+
        int interpreter;                /* see frotz.h */
 } u_setup_t;
 
index fe5f00e07b0524286d56bc814f9442f27d23a8ca..26c642c87bc8eab3b9515d6cb2f7d906d07998d6 100644 (file)
@@ -92,8 +92,8 @@ extern volatile int end_of_sound_flag;
 /* BCpic   */  void    reset_pictures (void);
 
 #ifdef SOUND_SUPPORT
-/* BCsmpl  */  bool    init_sound (void);
-/* BCsmpl  */  void    reset_sound (void);
+/* BCsmpl  */  bool    dos_init_sound (void);
+/* BCsmpl  */  void    dos_reset_sound (void);
 #endif
 /* BCtext  */  void    switch_scrn_attr (bool);
 /* BCtext  */  void    load_fonts (void);
index 817708f4a24a1455b479a2ecd41091a6d1df220d..8136ba3002d5f0879db56bd877e1eef81891f49a 100644 (file)
@@ -169,7 +169,7 @@ static void cleanup (void)
 {\r
 \r
 #ifdef SOUND_SUPPORT\r
-    reset_sound ();\r
+    dos_reset_sound ();\r
 #endif\r
     reset_pictures ();\r
 \r
index fd1c44f3252339b7ed4826f00df1fa0059a04a53..33c41a4a95504c560fe6068c5064dfcbbfff977b 100644 (file)
@@ -198,13 +198,13 @@ bool dos_init_sound (void)
 }/* init_sound */
 
 /*
- * reset_sound
+ * dos_reset_sound
  *
  * Free resources allocated for playing samples.
  *
  */
 
-void reset_sound (void)
+void dos_reset_sound (void)
 {
 
     os_stop_sample ();
@@ -218,7 +218,7 @@ void reset_sound (void)
        sound_adr = 0;
     }
 
-}/* reset_sound */
+}/* dos_reset_sound */
 
 #endif /* SOUND_SUPPORT */
 
index d1b9d716617cbc0a8e36232fdd55f04cee71ef30..393d697b9b605302f0970d9cb026fb9e9240689d 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef _SF_FROTZ_H
 #define _SF_FROTZ_H
 
-#include "frotz.h"
-#include "blorb.h"
+#include "../common/frotz.h"
+#include "../blorb/blorb.h"
 
 // version info
 #define SFROTZ_MAJOR 0