4 * Global declarations and definitions
21 typedef unsigned char zbyte;
22 typedef unsigned short zword;
36 typedef unsigned char zchar;
38 /*** Constants that may be set at compile time ***/
40 #ifndef MAX_UNDO_SLOTS
41 #define MAX_UNDO_SLOTS 500
44 #define MAX_FILE_NAME 80
46 #ifndef TEXT_BUFFER_SIZE
47 #define TEXT_BUFFER_SIZE 200
49 #ifndef INPUT_BUFFER_SIZE
50 #define INPUT_BUFFER_SIZE 200
53 #define STACK_SIZE 60000
56 #ifndef DEFAULT_SAVE_NAME
57 #define DEFAULT_SAVE_NAME "story.sav"
59 #ifndef DEFAULT_SCRIPT_NAME
60 #define DEFAULT_SCRIPT_NAME "story.scr"
62 #ifndef DEFAULT_COMMAND_NAME
63 #define DEFAULT_COMMAND_NAME "story.rec"
65 #ifndef DEFAULT_AUXILARY_NAME
66 #define DEFAULT_AUXILARY_NAME "story.aux"
68 #ifndef DEFAULT_SAVE_DIR /* DG */
69 #define DEFAULT_SAVE_DIR ".frotz-saves"
72 /*** Story file header format ***/
77 #define H_RESIDENT_SIZE 4
79 #define H_DICTIONARY 8
82 #define H_DYNAMIC_SIZE 14
85 #define H_ABBREVIATIONS 24
86 #define H_FILE_SIZE 26
88 #define H_INTERPRETER_NUMBER 30
89 #define H_INTERPRETER_VERSION 31
90 #define H_SCREEN_ROWS 32
91 #define H_SCREEN_COLS 33
92 #define H_SCREEN_WIDTH 34
93 #define H_SCREEN_HEIGHT 36
94 #define H_FONT_HEIGHT 38 /* this is the font width in V5 */
95 #define H_FONT_WIDTH 39 /* this is the font height in V5 */
96 #define H_FUNCTIONS_OFFSET 40
97 #define H_STRINGS_OFFSET 42
98 #define H_DEFAULT_BACKGROUND 44
99 #define H_DEFAULT_FOREGROUND 45
100 #define H_TERMINATING_KEYS 46
101 #define H_LINE_WIDTH 48
102 #define H_STANDARD_HIGH 50
103 #define H_STANDARD_LOW 51
104 #define H_ALPHABET 52
105 #define H_EXTENSION_TABLE 54
106 #define H_USER_NAME 56
108 #define HX_TABLE_SIZE 0
111 #define HX_UNICODE_TABLE 3
113 /*** Various Z-machine constants ***/
124 #define CONFIG_BYTE_SWAPPED 0x01 /* Story file is byte swapped - V3 */
125 #define CONFIG_TIME 0x02 /* Status line displays time - V3 */
126 #define CONFIG_TWODISKS 0x04 /* Story file occupied two disks - V3 */
127 #define CONFIG_TANDY 0x08 /* Tandy licensed game - V3 */
128 #define CONFIG_NOSTATUSLINE 0x10 /* Interpr can't support status lines - V3 */
129 #define CONFIG_SPLITSCREEN 0x20 /* Interpr supports split screen mode - V3 */
130 #define CONFIG_PROPORTIONAL 0x40 /* Interpr uses proportional font - V3 */
132 #define CONFIG_COLOUR 0x01 /* Interpr supports colour - V5+ */
133 #define CONFIG_PICTURES 0x02 /* Interpr supports pictures - V6 */
134 #define CONFIG_BOLDFACE 0x04 /* Interpr supports boldface style - V4+ */
135 #define CONFIG_EMPHASIS 0x08 /* Interpr supports emphasis style - V4+ */
136 #define CONFIG_FIXED 0x10 /* Interpr supports fixed width style - V4+ */
137 #define CONFIG_SOUND 0x20 /* Interpr supports sound - V6 */
139 #define CONFIG_TIMEDINPUT 0x80 /* Interpr supports timed input - V4+ */
141 #define SCRIPTING_FLAG 0x0001 /* Outputting to transscription file - V1+ */
142 #define FIXED_FONT_FLAG 0x0002 /* Use fixed width font - V3+ */
143 #define REFRESH_FLAG 0x0004 /* Refresh the screen - V6 */
144 #define GRAPHICS_FLAG 0x0008 /* Game wants to use graphics - V5+ */
145 #define OLD_SOUND_FLAG 0x0010 /* Game wants to use sound effects - V3 */
146 #define UNDO_FLAG 0x0010 /* Game wants to use UNDO feature - V5+ */
147 #define MOUSE_FLAG 0x0020 /* Game wants to use a mouse - V5+ */
148 #define COLOUR_FLAG 0x0040 /* Game wants to use colours - V5+ */
149 #define SOUND_FLAG 0x0080 /* Game wants to use sound effects - V5+ */
150 #define MENU_FLAG 0x0100 /* Game wants to use menus - V6 */
152 #define INTERP_DEFAULT 0
153 #define INTERP_DEC_20 1
154 #define INTERP_APPLE_IIE 2
155 #define INTERP_MACINTOSH 3
156 #define INTERP_AMIGA 4
157 #define INTERP_ATARI_ST 5
158 #define INTERP_MSDOS 6
159 #define INTERP_CBM_128 7
160 #define INTERP_CBM_64 8
161 #define INTERP_APPLE_IIC 9
162 #define INTERP_APPLE_IIGS 10
163 #define INTERP_TANDY 11
165 #define BLACK_COLOUR 2
167 #define GREEN_COLOUR 4
168 #define YELLOW_COLOUR 5
169 #define BLUE_COLOUR 6
170 #define MAGENTA_COLOUR 7
171 #define CYAN_COLOUR 8
172 #define WHITE_COLOUR 9
173 #define GREY_COLOUR 10 /* INTERP_MSDOS only */
174 #define LIGHTGREY_COLOUR 10 /* INTERP_AMIGA only */
175 #define MEDIUMGREY_COLOUR 11 /* INTERP_AMIGA only */
176 #define DARKGREY_COLOUR 12 /* INTERP_AMIGA only */
178 #define REVERSE_STYLE 1
179 #define BOLDFACE_STYLE 2
180 #define EMPHASIS_STYLE 4
181 #define FIXED_WIDTH_STYLE 8
184 #define PICTURE_FONT 2
185 #define GRAPHICS_FONT 3
186 #define FIXED_WIDTH_FONT 4
191 /*** Constants for os_restart_game */
193 #define RESTART_BEGIN 0
194 #define RESTART_WPROP_SET 1
195 #define RESTART_END 2
197 /*** Character codes ***/
199 #define ZC_TIME_OUT 0x00
200 #define ZC_NEW_STYLE 0x01
201 #define ZC_NEW_FONT 0x02
202 #define ZC_BACKSPACE 0x08
203 #define ZC_INDENT 0x09
205 #define ZC_RETURN 0x0d
206 #define ZC_HKEY_MIN 0x0e
207 #define ZC_HKEY_RECORD 0x0e
208 #define ZC_HKEY_PLAYBACK 0x0f
209 #define ZC_HKEY_SEED 0x10
210 #define ZC_HKEY_UNDO 0x11
211 #define ZC_HKEY_RESTART 0x12
212 #define ZC_HKEY_QUIT 0x13
213 #define ZC_HKEY_DEBUG 0x14
214 #define ZC_HKEY_HELP 0x15
215 #define ZC_HKEY_MAX 0x15
216 #define ZC_ESCAPE 0x1b
217 #define ZC_ASCII_MIN 0x20
218 #define ZC_ASCII_MAX 0x7e
220 #define ZC_ARROW_MIN 0x81
221 #define ZC_ARROW_UP 0x81
222 #define ZC_ARROW_DOWN 0x82
223 #define ZC_ARROW_LEFT 0x83
224 #define ZC_ARROW_RIGHT 0x84
225 #define ZC_ARROW_MAX 0x84
226 #define ZC_FKEY_MIN 0x85
227 #define ZC_FKEY_MAX 0x90
228 #define ZC_NUMPAD_MIN 0x91
229 #define ZC_NUMPAD_MAX 0x9a
230 #define ZC_SINGLE_CLICK 0x9b
231 #define ZC_DOUBLE_CLICK 0x9c
232 #define ZC_MENU_CLICK 0x9d
233 #define ZC_LATIN1_MIN 0xa0
234 #define ZC_LATIN1_MAX 0xff
238 #define FILE_RESTORE 0
240 #define FILE_SCRIPT 2
241 #define FILE_PLAYBACK 3
242 #define FILE_RECORD 4
243 #define FILE_LOAD_AUX 5
244 #define FILE_SAVE_AUX 6
246 /*** Data access macros ***/
248 #define SET_BYTE(addr,v) { zmp[addr] = v; }
249 #define LOW_BYTE(addr,v) { v = zmp[addr]; }
250 #define CODE_BYTE(v) { v = *pcp++; }
257 #define lo(v) ((zbyte *)&v)[1]
258 #define hi(v) ((zbyte *)&v)[0]
260 #define SET_WORD(addr,v) { zmp[addr] = hi(v); zmp[addr+1] = lo(v); }
261 #define LOW_WORD(addr,v) { hi(v) = zmp[addr]; lo(v) = zmp[addr+1]; }
262 #define HIGH_WORD(addr,v) { hi(v) = zmp[addr]; lo(v) = zmp[addr+1]; }
263 #define CODE_WORD(v) { hi(v) = *pcp++; lo(v) = *pcp++; }
264 #define GET_PC(v) { v = pcp - zmp; }
265 #define SET_PC(v) { pcp = zmp + v; }
269 /* A bunch of x86 assembly code previously appeared here. */
271 #if !defined (AMIGA) && !defined (MSDOS_16BIT)
276 #define lo(v) (v & 0xff)
277 #define hi(v) (v >> 8)
279 #define SET_WORD(addr,v) { zmp[addr] = hi(v); zmp[addr+1] = lo(v); }
280 #define LOW_WORD(addr,v) { v = ((zword) zmp[addr] << 8) | zmp[addr+1]; }
281 #define HIGH_WORD(addr,v) { v = ((zword) zmp[addr] << 8) | zmp[addr+1]; }
282 #define CODE_WORD(v) { v = ((zword) pcp[0] << 8) | pcp[1]; pcp += 2; }
283 #define GET_PC(v) { v = pcp - zmp; }
284 #define SET_PC(v) { pcp = zmp + v; }
289 /*** Story file header data ***/
291 extern zbyte h_version;
292 extern zbyte h_config;
293 extern zword h_release;
294 extern zword h_resident_size;
295 extern zword h_start_pc;
296 extern zword h_dictionary;
297 extern zword h_objects;
298 extern zword h_globals;
299 extern zword h_dynamic_size;
300 extern zword h_flags;
301 extern zbyte h_serial[6];
302 extern zword h_abbreviations;
303 extern zword h_file_size;
304 extern zword h_checksum;
305 extern zbyte h_interpreter_number;
306 extern zbyte h_interpreter_version;
307 extern zbyte h_screen_rows;
308 extern zbyte h_screen_cols;
309 extern zword h_screen_width;
310 extern zword h_screen_height;
311 extern zbyte h_font_height;
312 extern zbyte h_font_width;
313 extern zword h_functions_offset;
314 extern zword h_strings_offset;
315 extern zbyte h_default_background;
316 extern zbyte h_default_foreground;
317 extern zword h_terminating_keys;
318 extern zword h_line_width;
319 extern zbyte h_standard_high;
320 extern zbyte h_standard_low;
321 extern zword h_alphabet;
322 extern zword h_extension_table;
323 extern zbyte h_user_name[8];
325 extern zword hx_table_size;
326 extern zword hx_mouse_x;
327 extern zword hx_mouse_y;
328 extern zword hx_unicode_table;
330 /*** Various data ***/
332 extern char *story_name;
334 extern enum story story_id;
335 extern long story_size;
337 extern zword stack[STACK_SIZE];
340 extern zword frame_count;
342 extern zword zargs[8];
345 extern bool ostream_screen;
346 extern bool ostream_script;
347 extern bool ostream_memory;
348 extern bool ostream_record;
349 extern bool istream_replay;
358 extern bool enable_wrapping;
359 extern bool enable_scripting;
360 extern bool enable_scrolling;
361 extern bool enable_buffering;
364 extern char *option_zcode_path; /* dg */
366 extern long reserve_mem;
369 /*** Z-machine opcodes ***/
373 void z_art_shift (void);
374 void z_buffer_mode (void);
375 void z_call_n (void);
376 void z_call_s (void);
378 void z_check_arg_count (void);
379 void z_check_unicode (void);
380 void z_clear_attr (void);
381 void z_copy_table (void);
383 void z_dec_chk (void);
385 void z_draw_picture (void);
386 void z_encode_text (void);
387 void z_erase_line (void);
388 void z_erase_picture (void);
389 void z_erase_window (void);
390 void z_get_child (void);
391 void z_get_cursor (void);
392 void z_get_next_prop (void);
393 void z_get_parent (void);
394 void z_get_prop (void);
395 void z_get_prop_addr (void);
396 void z_get_prop_len (void);
397 void z_get_sibling (void);
398 void z_get_wind_prop (void);
400 void z_inc_chk (void);
401 void z_input_stream (void);
402 void z_insert_obj (void);
412 void z_log_shift (void);
413 void z_make_menu (void);
415 void z_mouse_window (void);
416 void z_move_window (void);
418 void z_new_line (void);
422 void z_output_stream (void);
423 void z_picture_data (void);
424 void z_picture_table (void);
425 void z_piracy (void);
427 void z_pop_stack (void);
429 void z_print_addr (void);
430 void z_print_char (void);
431 void z_print_form (void);
432 void z_print_num (void);
433 void z_print_obj (void);
434 void z_print_paddr (void);
435 void z_print_ret (void);
436 void z_print_table (void);
437 void z_print_unicode (void);
440 void z_push_stack (void);
441 void z_put_prop (void);
442 void z_put_wind_prop (void);
444 void z_random (void);
446 void z_read_char (void);
447 void z_read_mouse (void);
448 void z_remove_obj (void);
449 void z_restart (void);
450 void z_restore (void);
451 void z_restore_undo (void);
453 void z_ret_popped (void);
454 void z_rfalse (void);
457 void z_save_undo (void);
458 void z_scan_table (void);
459 void z_scroll_window (void);
460 void z_set_attr (void);
461 void z_set_font (void);
462 void z_set_colour (void);
463 void z_set_cursor (void);
464 void z_set_margins (void);
465 void z_set_window (void);
466 void z_set_text_style (void);
467 void z_show_status (void);
468 void z_sound_effect (void);
469 void z_split_window (void);
471 void z_storeb (void);
472 void z_storew (void);
475 void z_test_attr (void);
477 void z_tokenise (void);
478 void z_verify (void);
479 void z_window_size (void);
480 void z_window_style (void);
482 /* Definitions for error handling functions and error codes. */
484 /* extern int err_report_mode; */
486 void init_err (void);
487 void runtime_error (int);
490 #define ERR_TEXT_BUF_OVF 1 /* Text buffer overflow */
491 #define ERR_STORE_RANGE 2 /* Store out of dynamic memory */
492 #define ERR_DIV_ZERO 3 /* Division by zero */
493 #define ERR_ILL_OBJ 4 /* Illegal object */
494 #define ERR_ILL_ATTR 5 /* Illegal attribute */
495 #define ERR_NO_PROP 6 /* No such property */
496 #define ERR_STK_OVF 7 /* Stack overflow */
497 #define ERR_ILL_CALL_ADDR 8 /* Call to illegal address */
498 #define ERR_CALL_NON_RTN 9 /* Call to non-routine */
499 #define ERR_STK_UNDF 10 /* Stack underflow */
500 #define ERR_ILL_OPCODE 11 /* Illegal opcode */
501 #define ERR_BAD_FRAME 12 /* Bad stack frame */
502 #define ERR_ILL_JUMP_ADDR 13 /* Jump to illegal address */
503 #define ERR_SAVE_IN_INTER 14 /* Can't save while in interrupt */
504 #define ERR_STR3_NESTING 15 /* Nesting stream #3 too deep */
505 #define ERR_ILL_WIN 16 /* Illegal window */
506 #define ERR_ILL_WIN_PROP 17 /* Illegal window property */
507 #define ERR_ILL_PRINT_ADDR 18 /* Print at illegal address */
508 #define ERR_MAX_FATAL 18
510 /* Less serious errors */
511 #define ERR_JIN_0 19 /* @jin called with object 0 */
512 #define ERR_GET_CHILD_0 20 /* @get_child called with object 0 */
513 #define ERR_GET_PARENT_0 21 /* @get_parent called with object 0 */
514 #define ERR_GET_SIBLING_0 22 /* @get_sibling called with object 0 */
515 #define ERR_GET_PROP_ADDR_0 23 /* @get_prop_addr called with object 0 */
516 #define ERR_GET_PROP_0 24 /* @get_prop called with object 0 */
517 #define ERR_PUT_PROP_0 25 /* @put_prop called with object 0 */
518 #define ERR_CLEAR_ATTR_0 26 /* @clear_attr called with object 0 */
519 #define ERR_SET_ATTR_0 27 /* @set_attr called with object 0 */
520 #define ERR_TEST_ATTR_0 28 /* @test_attr called with object 0 */
521 #define ERR_MOVE_OBJECT_0 29 /* @move_object called moving object 0 */
522 #define ERR_MOVE_OBJECT_TO_0 30 /* @move_object called moving into object 0 */
523 #define ERR_REMOVE_OBJECT_0 31 /* @remove_object called with object 0 */
524 #define ERR_GET_NEXT_PROP_0 32 /* @get_next_prop called with object 0 */
525 #define ERR_NUM_ERRORS (32)
527 /* There are four error reporting modes: never report errors;
528 report only the first time a given error type occurs; report
529 every time an error occurs; or treat all errors as fatal
530 errors, killing the interpreter. I strongly recommend
531 "report once" as the default. But you can compile in a
532 different default by changing the definition of
533 ERR_DEFAULT_REPORT_MODE. In any case, the player can
534 specify a report mode on the command line by typing "-Z 0"
537 #define ERR_REPORT_NEVER (0)
538 #define ERR_REPORT_ONCE (1)
539 #define ERR_REPORT_ALWAYS (2)
540 #define ERR_REPORT_FATAL (3)
542 #define ERR_DEFAULT_REPORT_MODE ERR_REPORT_NEVER
545 /*** Various global functions ***/
547 /* MacOSX libm defines this */
548 #define init_process frotz_process
550 void init_process(void);
551 void init_sound(void);
553 zchar translate_from_zscii (zbyte);
554 zbyte translate_to_zscii (zchar);
556 void init_buffer(void);
557 void flush_buffer(void);
558 void new_line (void);
559 void print_char (zchar);
560 void print_num (zword);
561 void print_object (zword);
562 void print_string (const char *);
564 void stream_mssg_on (void);
565 void stream_mssg_off (void);
571 void storeb (zword, zbyte);
572 void storew (zword, zword);
574 /*** Interface functions ***/
577 int os_char_width (zchar);
578 void os_display_char (zchar);
579 void os_display_string (const zchar *);
581 void os_draw_picture (int, int, int);
582 void os_erase_area (int, int, int, int);
584 void os_fatal (char *);
585 void os_finish_with_sample (int);
587 int os_font_data (int, int *, int *);
588 void os_init_screen (void);
589 void os_more_prompt (void);
590 int os_peek_colour (void);
591 int os_picture_data (int, int *, int *);
593 void os_prepare_sample (int);
594 void os_process_arguments (int, char *[]);
595 int os_random_seed (void);
596 int os_read_file_name (char *, const char *, int);
597 zchar os_read_key (int, int);
598 zchar os_read_line (int, zchar *, int, int, int);
599 void os_reset_screen (void);
600 void os_restart_game (int);
602 void os_scroll_area (int, int, int, int, int);
603 void os_set_colour (int, int);
604 void os_set_cursor (int, int);
605 void os_set_font (int);
607 void os_set_text_style (int);
609 void os_start_sample (int, int, int, zword);
610 void os_stop_sample (int);
611 int os_string_width (const zchar *);
612 void os_init_setup (void);
613 int os_speech_output(const zchar *);