1 /* main.c: Glulxe top-level code.
2 Designed by Andrew Plotkin <erkyrath@eblong.com>
3 http://eblong.com/zarf/glulx/index.html
9 strid_t gamefile = NULL; /* The stream containing the Glulx file. */
10 glui32 gamefile_start = 0; /* The position within the stream. (This will not
11 be zero if the Glulx file is a chunk inside a Blorb archive.) */
12 glui32 gamefile_len = 0; /* The length within the stream. */
13 char *init_err = NULL;
14 char *init_err2 = NULL;
16 static winid_t get_error_win(void);
17 static void stream_hexnum(glsi32 val);
20 The top-level routine. This does everything, and consequently is
26 fatal_error_2(init_err, init_err2);
30 if (!is_gamefile_valid()) {
31 /* The fatal error has already been displayed. */
40 #endif /* FLOAT_SUPPORT */
41 if (!init_dispatch()) {
44 if (!init_profile()) {
57 Return a window in which to display errors. The first time this is called,
58 it creates a new window; after that it returns the window it first
61 static winid_t get_error_win()
63 static winid_t errorwin = NULL;
66 winid_t rootwin = glk_window_get_root();
68 errorwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
71 errorwin = glk_window_open(rootwin, winmethod_Below | winmethod_Fixed,
72 3, wintype_TextBuffer, 0);
81 /* fatal_error_handler():
82 Display an error in the error window, and then exit.
84 void fatal_error_handler(char *str, char *arg, int useval, glsi32 val)
86 winid_t win = get_error_win();
89 glk_put_string("Glulxe fatal error: ");
101 glk_put_string("\n");
106 /* nonfatal_warning_handler():
107 Display a warning in the error window, and then continue.
109 void nonfatal_warning_handler(char *str, char *arg, int useval, glsi32 val)
111 winid_t win = get_error_win();
113 strid_t oldstr = glk_stream_get_current();
115 glk_put_string("Glulxe warning: ");
118 glk_put_string(" (");
127 glk_put_string("\n");
128 glk_stream_set_current(oldstr);
133 Write a signed integer to the current Glk output stream.
135 static void stream_hexnum(glsi32 val)
156 buf[ix] = (ival % 16) + '0';
158 buf[ix] += ('A' - ('9' + 1));
165 glk_put_char(buf[ix]);