# Define your optimization flags. Most compilers understand -O and -O2,
# Standard (note: Solaris on UltraSparc using gcc 2.8.x might not like this.)
#
-OPTS = -O2
+OPTS = -O2 -g
# Pentium with gcc 2.7.0 or better
#OPTS = -O2 -fomit-frame-pointer -malign-functions=2 -malign-loops=2 \
$(CURSES_DIR)/ux_screen.o \
$(CURSES_DIR)/ux_text.o \
$(CURSES_DIR)/ux_blorb.o \
- $(CURSES_DIR)/ux_audio.o
+ $(CURSES_DIR)/ux_audio.o \
+ $(CURSES_DIR)/ux_resource.o
# $(CURSES_DIR)/ux_audio_none.o \
# $(CURSES_DIR)/ux_audio_oss.o
FLAGS = $(OPTS) $(CURSES_DEFS) $(INCL)
+SOUND_LIB = -lao -ldl -lm
+
$(NAME): $(NAME)-curses
curses: $(NAME)-curses
$(NAME)-curses: $(COMMON_TARGET) $(CURSES_TARGET) $(BLORB_TARGET)
/*
- * ux_init_blorb
+ * ux_blorb_init
*
* Check if we're opening a Blorb file directly. If not, check
* to see if there's a seperate Blorb file that looks like it goes
* other, make a Blorb map. If we opened a Blorb file directly, that
* means that our executable is in that file and therefore we will look
* for a ZCOD chunk and record its location so os_load_story() can find it.
- *
+ * Make sure the Blorb file is opened and with the file pointer blorb_fp.
*/
-bb_err_t ux_init_blorb(char *filename)
+bb_err_t ux_blorb_init(char *filename)
{
FILE *fp;
char *p;
bb_err_t blorb_err;
+/*
+ blorb_map = NULL;
+ blorb_res = NULL;
+*/
+
if ((fp = fopen(filename, "rb")) == NULL)
return bb_err_Read;
- printf("filename: %s\n", filename);
-
/* Is this really a Blorb file? If not, maybe we're loading a naked
* zcode file and our resources are in a seperate blorb file.
*/
if (isblorb(fp)) { /* Now we know to look */
u_setup.exec_in_blorb = 1; /* for zcode in the blorb */
+ blorb_fp = fopen(filename, "rb");
} else {
len1 = strlen(filename) + strlen(EXT_BLORB);
len2 = strlen(filename) + strlen(EXT_BLORBLONG);
strncat(mystring, EXT_BLORB, len1 * sizeof(char));
+ /* Done monkeying with the initial file. */
+ fclose(fp);
+ fp = NULL;
+
+
/* Check if foo.blb is there. */
- if ((fp = fopen(mystring, "rb")) == NULL) {
+ if ((blorb_fp = fopen(mystring, "rb")) == NULL) {
p = rindex(mystring, '.');
*p = '\0';
strncat(mystring, EXT_BLORBLONG, len2 * sizeof(char));
- fp = fopen(mystring, "rb");
+ blorb_fp = fopen(mystring, "rb");
+ printf("Got a blorb_fp\n");
}
- if (fp == NULL || !isblorb(fp)) /* No matching blorbs found. */
+
+ if (blorb_fp == NULL || !isblorb(fp)) /* No matching blorbs found. */
return bb_err_NoBlorb;
- u_setup.exec_in_blorb = 0; /* Using naked zcode with */
- } /* resources in seperate blorb. */
+ /* At this point we know that we're using a naked zcode file */
+ /* with resources in a seperate Blorb file. */
+ u_setup.use_blorb = 1;
+ }
/* Create a Blorb map from this file.
* This will fail if the file is not a valid Blorb file.
if (u_setup.exec_in_blorb) {
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) {
u_setup.exec_in_blorb = 1;
- u_setup.use_blorb = 1;
}
fclose(fp);
return blorb_err;
}
+/*
+ * ux_stop_blorb
+ *
+ * Basically just close the Blorb file.
+ *
+ */
+void ux_stop_blorb(void)
+{
+ if (blorb_fp != NULL)
+ fclose(blorb_fp);
+ blorb_fp = NULL;
+}
char *findchunk(char *data, char *string, int length)
{
} blorb_data_t;
*/
+/*
+ * The bb_result_t struct lacks a few members that would make things a
+ * bit easier. The myresource struct takes encapsulates the bb_result_t
+ * struct and adds a type member and a filepointer. I would like to
+ * convince Andrew Plotkin to make a change in the reference Blorb code
+ * to add these members.
+ *
+ */
typedef struct {
bb_result_t bbres;
ulong type;
- FILE *file;
+ FILE *fp;
} myresource;
//bb_err_t blorb_err;
bb_map_t *blorb_map;
bb_result_t blorb_res;
+FILE *blorb_fp;
+
+
+int sf_getresource( int num, int ispic, int method, myresource * res);
+void sf_freeresource( myresource *res);
/* uint32 *findchunk(uint32 *data, char *chunkID, int length); */
char *findchunk(char *pstart, char *fourcc, int n);
{
if (u_setup.curses_active) {
- /* Solaris 2.6's cc complains if the below cast is missing */
- os_display_string((zchar *)"\n\n");
- os_beep(BEEP_HIGH);
- os_set_text_style(BOLDFACE_STYLE);
- os_display_string((zchar *)"Fatal error: ");
- os_set_text_style(0);
- os_display_string((zchar *)s);
- os_display_string((zchar *)"\n");
- new_line();
- os_reset_screen();
- exit(1);
+ /* Solaris 2.6's cc complains if the below cast is missing */
+ os_display_string((zchar *)"\n\n");
+ os_beep(BEEP_HIGH);
+ os_set_text_style(BOLDFACE_STYLE);
+ os_display_string((zchar *)"Fatal error: ");
+ os_set_text_style(0);
+ os_display_string((zchar *)s);
+ os_display_string((zchar *)"\n");
+ new_line();
+ os_reset_screen();
+ ux_stop_blorb();
+ exit(1);
}
fputs ("\nFatal error: ", stderr);
#ifndef WIN32
if ((getuid() == 0) || (geteuid() == 0)) {
- printf("I won't run as root!\n");
- exit(1);
+ printf("I won't run as root!\n");
+ exit(1);
}
#endif
#endif
if ((home = getenv(HOMEDIR)) == NULL) {
- printf("Hard drive on fire!\n");
- exit(1);
+ printf("Hard drive on fire!\n");
+ exit(1);
}
/*
printf("f_setup.story_path %s\n", f_setup.story_path);
*/
- switch (c = ux_init_blorb(f_setup.story_file)) {
- case bb_err_Format:
- printf("Blorb file loaded, but unable to build map.\n\n");
- break;
- case bb_err_NotFound:
- printf("Blorb file loaded, but lacks executable chunk.\n\n");
- break;
- }
-
}/* os_process_arguments */
{
FILE *fp;
-printf("Loading %s\n", f_setup.story_file);
+ switch (ux_blorb_init(f_setup.story_file)) {
+ case bb_err_NoBlorb:
+ printf("No blorb file found.\n\n");
+ break;
+ case bb_err_Format:
+ printf("Blorb file loaded, but unable to build map.\n\n");
+ break;
+ case bb_err_NotFound:
+ printf("Blorb file loaded, but lacks executable chunk.\n\n");
+ break;
+ case bb_err_None:
+ printf("No blorb errors.\n\n");
+ break;
+ }
- fp = fopen(f_setup.story_file, "rb");
+ ux_initsound();
+// os_start_sample(3, 8, 1, 0);
+// exit(1);
+ printf("Loading %s\n", f_setup.story_file);
+
+ fp = fopen(f_setup.story_file, "rb");
- /* Did we build a valid blorb map? */
+ /* Is this a Blorb file containing Zcode? */
if (u_setup.exec_in_blorb)
fseek(fp, blorb_res.data.startpos, SEEK_SET);
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "ux_frotz.h"
+#include "ux_blorb.h"
+
+/*
+ * ux_getresource
+ *
+ * Load a bb_result_t struct (encapsulated within myresource struct)
+ * with information about a resource. We need two other facts about the
+ * chunk to do something intelligent later: a filepointer and type
+ * (gotten from the bb_map_t struct). I'll have to talk to Zarf about
+ * possibly modifying the bb_result_t struct in the reference version of
+ * the Blorb library.
+ *
+ */
+int ux_getresource( int num, int ispic, int method, myresource * res)
+{
+ int st;
+ ulong usage;
+
+ res->bbres.data.ptr = NULL;
+ res->fp = NULL;
+
+ if (!blorb_map) return bb_err_NotFound;
+
+ if (ispic)
+ usage = bb_ID_Pict;
+ else
+ usage = bb_ID_Snd;
+
+ st = bb_load_resource(blorb_map, method, (bb_result_t *) res, usage, num);
+
+ if (st == bb_err_None) {
+ res->type = blorb_map->chunks[res->bbres.chunknum].type;
+ if (method == bb_method_FilePos)
+ res->fp = blorb_fp;
+ }
+ return st;
+}
+
+/*
+ * ux_freeresource
+ *
+ * Destroys a myresource struct and returns the memory to the heap.
+ *
+ */
+
+int ux_freeresource(myresource *res)
+{
+ if (res == NULL)
+ return;
+
+ if (blorb_map != NULL)
+ return bb_unload_chunk(blorb_map, res->bbres.chunknum);
+}