1 /*
2  * frotz.h
3  *
4  * Global declarations and definitions
5  *
6  */
7 
8 #ifndef FROTZ_H_
9 #define FROTZ_H_
10 
11 
12 /* For now we assume DOS Frotz is always 16-bit */
13 #ifdef __TURBOC__
14 #define MSDOS_16BIT
15 #endif
16 
17 #ifdef MSDOS_16BIT
18 #include "..\dos\defs.h"
19 #ifdef USE_UTF8
20 #error UTF-8 is not supported in DOS Frotz
21 #endif
22 #endif
23 
24 #ifndef MSDOS_16BIT
25 #include "defs.h"
26 #include "git_hash.h"
27 #endif
28 
29 #ifndef __UNIX_PORT_FILE
30 #include <signal.h>
31 typedef int bool;
32 #endif /* __UNIX_PORT_FILE */
33 
34 #include <stdio.h>
35 
36 #ifndef TRUE
37 #define TRUE 1
38 #endif
39 
40 #ifndef FALSE
41 #define FALSE 0
42 #endif
43 
44 #ifndef PATH_MAX
45 #  ifdef MAXPATHLEN                /* defined in <sys/param.h> some systems */
46 #    define PATH_MAX      MAXPATHLEN
47 #  else
48 #    if FILENAME_MAX > 255         /* used like PATH_MAX on some systems */
49 #      define PATH_MAX    FILENAME_MAX
50 #    else
51 #      define PATH_MAX    (FILNAMSIZ - 1)
52 #    endif
53 #  endif /* ?MAXPATHLEN */
54 #endif /* !PATH_MAX */
55 
56 
57 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) || defined (__CYGWIN__)
58 #define PATH_SEPARATOR '\\'
59 #else
60 #define PATH_SEPARATOR '/'
61 #endif
62 
63 /* typedef unsigned short zbyte; */
64 typedef unsigned char zbyte;
65 typedef unsigned short zword;
66 
67 #ifndef USE_UTF8
68 typedef unsigned char zchar;
69 #else
70 typedef unsigned short zchar;
71 #endif
72 
73 enum story {
74 	ZORK1,
75 	ZORK2,
76 	ZORK3,
77 	ZORK1G,
78 	MINIZORK,
79 	SAMPLER1,
80 	SAMPLER2,
81 	ENCHANTER,
82 	SORCERER,
83 	SPELLBREAKER,
84 	PLANETFALL,
85 	STATIONFALL,
86 	BALLYHOO,
87 	BORDER_ZONE,
88 	AMFV,
89 	HHGG,
90 	LGOP,
91 	SUSPECT,
92 	BEYOND_ZORK,
93 	SHERLOCK,
94 	ZORK_ZERO,
95 	SHOGUN,
96 	ARTHUR,
97 	JOURNEY,
98 	LURKING_HORROR,
99 	BUREAUCRACY,
100 	TRINITY,
101 	CUTTHROATS,
102 	UNKNOWN
103 };
104 
105 /*** screen window ***/
106 typedef struct {
107 	zword y_pos;
108 	zword x_pos;
109 	zword y_size;
110 	zword x_size;
111 	zword y_cursor;
112 	zword x_cursor;
113 	zword left;
114 	zword right;
115 	zword nl_routine;
116 	zword nl_countdown;
117 	zword style;
118 	zword colour;
119 	zword font;
120 	zword font_size;
121 	zword attribute;
122 	zword line_count;
123 	zword true_fore;
124 	zword true_back;
125 } Zwindow;
126 
127 
128 #include "setup.h"
129 #include "missing.h"
130 #include "unused.h"
131 
132 /*** Constants that may be set at compile time ***/
133 #ifndef MAX_UNDO_SLOTS
134 #define MAX_UNDO_SLOTS 500
135 #endif
136 #ifndef MAX_FILE_NAME
137 #define MAX_FILE_NAME 80
138 #endif
139 #ifndef TEXT_BUFFER_SIZE
140 #define TEXT_BUFFER_SIZE 275
141 #endif
142 #ifndef INPUT_BUFFER_SIZE
143 #define INPUT_BUFFER_SIZE 200
144 #endif
145 #ifndef STACK_SIZE
146 #define STACK_SIZE 1024
147 #endif
148 
149 extern const char build_timestamp[];
150 
151 /* Assorted filename extensions */
152 #define EXT_SAVE	".qzl"
153 #define EXT_SCRIPT	".scr"
154 #define EXT_BLORB	".blb"
155 #define EXT_BLORB2	".zblb"
156 #define EXT_BLORB3	".blorb"
157 #define EXT_BLORB4	".zblorb"
158 #define EXT_COMMAND	".rec"
159 #define EXT_AUX		".aux"
160 
161 #ifndef DEFAULT_SAVE_NAME
162 #define DEFAULT_SAVE_NAME "story.sav"
163 #endif
164 #ifndef DEFAULT_SCRIPT_NAME
165 #define DEFAULT_SCRIPT_NAME "story.scr"
166 #endif
167 #ifndef DEFAULT_COMMAND_NAME
168 #define DEFAULT_COMMAND_NAME "story.rec"
169 #endif
170 #ifndef DEFAULT_AUXILARY_NAME
171 #define DEFAULT_AUXILARY_NAME "story.aux"
172 #endif
173 #ifndef DEFAULT_SAVE_DIR	/* DG */
174 #define DEFAULT_SAVE_DIR ".frotz-saves"
175 #endif
176 
177 /*** Story file header format ***/
178 #define H_VERSION 0
179 #define H_CONFIG 1
180 #define H_RELEASE 2
181 #define H_RESIDENT_SIZE 4
182 #define H_START_PC 6
183 #define H_DICTIONARY 8
184 #define H_OBJECTS 10
185 #define H_GLOBALS 12
186 #define H_DYNAMIC_SIZE 14
187 #define H_FLAGS 16
188 #define H_SERIAL 18
189 #define H_ABBREVIATIONS 24
190 #define H_FILE_SIZE 26
191 #define H_CHECKSUM 28
192 #define H_INTERPRETER_NUMBER 30
193 #define H_INTERPRETER_VERSION 31
194 #define H_SCREEN_ROWS 32
195 #define H_SCREEN_COLS 33
196 #define H_SCREEN_WIDTH 34
197 #define H_SCREEN_HEIGHT 36
198 #define H_FONT_HEIGHT 38 /* this is the font width in V5 */
199 #define H_FONT_WIDTH 39 /* this is the font height in V5 */
200 #define H_FUNCTIONS_OFFSET 40
201 #define H_STRINGS_OFFSET 42
202 #define H_DEFAULT_BACKGROUND 44
203 #define H_DEFAULT_FOREGROUND 45
204 #define H_TERMINATING_KEYS 46
205 #define H_LINE_WIDTH 48
206 #define H_STANDARD_HIGH 50
207 #define H_STANDARD_LOW 51
208 #define H_ALPHABET 52
209 #define H_EXTENSION_TABLE 54
210 #define H_USER_NAME 56
211 
212 #define HX_TABLE_SIZE 0
213 #define HX_MOUSE_X 1
214 #define HX_MOUSE_Y 2
215 #define HX_UNICODE_TABLE 3
216 
217 /*** Various Z-machine constants ***/
218 #define V1 1
219 #define V2 2
220 #define V3 3
221 #define V4 4
222 #define V5 5
223 #define V6 6
224 #define V7 7
225 #define V8 8
226 
227 #define CONFIG_BYTE_SWAPPED 0x01 /* Story file is byte swapped         - V3  */
228 #define CONFIG_TIME         0x02 /* Status line displays time          - V3  */
229 #define CONFIG_TWODISKS     0x04 /* Story file occupied two disks      - V3  */
230 #define CONFIG_TANDY        0x08 /* Tandy licensed game                - V3  */
231 #define CONFIG_NOSTATUSLINE 0x10 /* Interpr can't support status lines - V3  */
232 #define CONFIG_SPLITSCREEN  0x20 /* Interpr supports split screen mode - V3  */
233 #define CONFIG_PROPORTIONAL 0x40 /* Interpr uses proportional font     - V3  */
234 
235 #define CONFIG_COLOUR       0x01 /* Interpr supports colour            - V5+ */
236 #define CONFIG_PICTURES	    0x02 /* Interpr supports pictures	       - V6  */
237 #define CONFIG_BOLDFACE     0x04 /* Interpr supports boldface style    - V4+ */
238 #define CONFIG_EMPHASIS     0x08 /* Interpr supports emphasis style    - V4+ */
239 #define CONFIG_FIXED        0x10 /* Interpr supports fixed width style - V4+ */
240 #define CONFIG_SOUND	    0x20 /* Interpr supports sound             - V6  */
241 
242 #define CONFIG_TIMEDINPUT   0x80 /* Interpr supports timed input       - V4+ */
243 
244 #define SCRIPTING_FLAG	  0x0001 /* Outputting to transcription file  - V1+ */
245 #define FIXED_FONT_FLAG   0x0002 /* Use fixed width font               - V3+ */
246 #define REFRESH_FLAG 	  0x0004 /* Refresh the screen                 - V6  */
247 #define GRAPHICS_FLAG	  0x0008 /* Game wants to use graphics         - V5+ */
248 #define OLD_SOUND_FLAG	  0x0010 /* Game wants to use sound effects    - V3  */
249 #define UNDO_FLAG	  0x0010 /* Game wants to use UNDO feature     - V5+ */
250 #define MOUSE_FLAG	  0x0020 /* Game wants to use a mouse          - V5+ */
251 #define COLOUR_FLAG	  0x0040 /* Game wants to use colours          - V5+ */
252 #define SOUND_FLAG	  0x0080 /* Game wants to use sound effects    - V5+ */
253 #define MENU_FLAG	  0x0100 /* Game wants to use menus            - V6  */
254 
255 #define TRANSPARENT_FLAG  0x0001 /* Game wants to use transparency     - V6  */
256 
257 #define INTERP_DEFAULT 0
258 #define INTERP_DEC_20 1
259 #define INTERP_APPLE_IIE 2
260 #define INTERP_MACINTOSH 3
261 #define INTERP_AMIGA 4
262 #define INTERP_ATARI_ST 5
263 #define INTERP_MSDOS 6
264 #define INTERP_CBM_128 7
265 #define INTERP_CBM_64 8
266 #define INTERP_APPLE_IIC 9
267 #define INTERP_APPLE_IIGS 10
268 #define INTERP_TANDY 11
269 
270 #define DEFAULT_COLOUR 1
271 #define BLACK_COLOUR 2
272 #define RED_COLOUR 3
273 #define GREEN_COLOUR 4
274 #define YELLOW_COLOUR 5
275 #define BLUE_COLOUR 6
276 #define MAGENTA_COLOUR 7
277 #define CYAN_COLOUR 8
278 #define WHITE_COLOUR 9
279 #define GREY_COLOUR 10		/* INTERP_MSDOS only */
280 #define LIGHTGREY_COLOUR 10 	/* INTERP_AMIGA only */
281 #define MEDIUMGREY_COLOUR 11 	/* INTERP_AMIGA only */
282 #define DARKGREY_COLOUR 12 	/* INTERP_AMIGA only */
283 
284 #define NORMAL_STYLE 0
285 #define REVERSE_STYLE 1
286 #define BOLDFACE_STYLE 2
287 #define EMPHASIS_STYLE 4
288 #define FIXED_WIDTH_STYLE 8
289 #define PICTURE_STYLE 16
290 
291 #define TEXT_FONT 1
292 #define PICTURE_FONT 2
293 #define GRAPHICS_FONT 3
294 #define FIXED_WIDTH_FONT 4
295 
296 #define BEEP_HIGH	1
297 #define BEEP_LOW	2
298 
299 /*** Constants for os_restart_game */
300 #define RESTART_BEGIN 0
301 #define RESTART_WPROP_SET 1
302 #define RESTART_END 2
303 
304 /*** Character codes ***/
305 #define ZC_TIME_OUT 0x00
306 #define ZC_NEW_STYLE 0x01
307 #define ZC_NEW_FONT 0x02
308 #define ZC_BACKSPACE 0x08
309 #define ZC_INDENT 0x09
310 #define ZC_GAP 0x0b
311 #define ZC_RETURN 0x0d
312 #define ZC_HKEY_MIN 0x0e
313 #define ZC_HKEY_RECORD 0x0e
314 #define ZC_HKEY_PLAYBACK 0x0f
315 #define ZC_HKEY_SEED 0x10
316 #define ZC_HKEY_UNDO 0x11
317 #define ZC_HKEY_RESTART 0x12
318 #define ZC_HKEY_QUIT 0x13
319 #define ZC_HKEY_DEBUG 0x14
320 #define ZC_HKEY_HELP 0x15
321 #define ZC_HKEY_MAX 0x15
322 #define ZC_ESCAPE 0x1b
323 #define ZC_DEL_WORD 0x1c
324 #define ZC_WORD_RIGHT 0x1d
325 #define ZC_WORD_LEFT 0x1e
326 #define ZC_DEL_TO_BOL 0x1f
327 #define ZC_ASCII_MIN 0x20
328 #define ZC_ASCII_MAX 0x7e
329 #define ZC_BAD 0x7f
330 #define ZC_ARROW_MIN 0x81
331 #define ZC_ARROW_UP 0x81
332 #define ZC_ARROW_DOWN 0x82
333 #define ZC_ARROW_LEFT 0x83
334 #define ZC_ARROW_RIGHT 0x84
335 #define ZC_ARROW_MAX 0x84
336 #define ZC_FKEY_MIN 0x85
337 #define ZC_FKEY_F1 0x85
338 #define ZC_FKEY_F2 0x86
339 #define ZC_FKEY_F3 0x87
340 #define ZC_FKEY_F4 0x88
341 #define ZC_FKEY_F5 0x89
342 #define ZC_FKEY_F6 0x8a
343 #define ZC_FKEY_F7 0x8b
344 #define ZC_FKEY_F8 0x8c
345 #define ZC_FKEY_F9 0x8d
346 #define ZC_FKEY_F10 0x8e
347 #define ZC_FKEY_F11 0x8f
348 #define ZC_FKEY_F12 0x90
349 #define ZC_FKEY_MAX 0x90
350 #define ZC_NUMPAD_MIN 0x91
351 #define ZC_NUMPAD_0 0x91
352 #define ZC_NUMPAD_1 0x92
353 #define ZC_NUMPAD_2 0x93
354 #define ZC_NUMPAD_3 0x94
355 #define ZC_NUMPAD_4 0x95
356 #define ZC_NUMPAD_5 0x96
357 #define ZC_NUMPAD_6 0x97
358 #define ZC_NUMPAD_7 0x98
359 #define ZC_NUMPAD_8 0x99
360 #define ZC_NUMPAD_9 0x9a
361 #define ZC_NUMPAD_MAX 0x9a
362 #define ZC_SINGLE_CLICK 0x9b
363 #define ZC_DOUBLE_CLICK 0x9c
364 #define ZC_MENU_CLICK 0x9d
365 #define ZC_LATIN1_MIN 0xa0
366 #define ZC_LATIN1_MAX 0xff
367 
368 /*** File types ***/
369 
370 #define FILE_RESTORE 0
371 #define FILE_SAVE 1
372 #define FILE_SCRIPT 2
373 #define FILE_PLAYBACK 3
374 #define FILE_RECORD 4
375 #define FILE_LOAD_AUX 5
376 #define FILE_SAVE_AUX 6
377 
378 /*** Data access macros ***/
379 
380 #define SET_BYTE(addr,v)  { zmp[addr] = v; }
381 #define LOW_BYTE(addr,v)  { v = zmp[addr]; }
382 #define CODE_BYTE(v)	  { v = *pcp++;    }
383 
384 #if defined (AMIGA)
385 
386 extern zbyte *pcp;
387 extern zbyte *zmp;
388 
389 #define lo(v)	((zbyte *)&v)[1]
390 #define hi(v)	((zbyte *)&v)[0]
391 
392 #define SET_WORD(addr,v)  { zmp[addr] = hi(v); zmp[addr+1] = lo(v); }
393 #define LOW_WORD(addr,v)  { hi(v) = zmp[addr]; lo(v) = zmp[addr+1]; }
394 #define HIGH_WORD(addr,v) { hi(v) = zmp[addr]; lo(v) = zmp[addr+1]; }
395 #define CODE_WORD(v)      { hi(v) = *pcp++; lo(v) = *pcp++; }
396 #define GET_PC(v)         { v = pcp - zmp; }
397 #define SET_PC(v)         { pcp = zmp + v; }
398 
399 #endif
400 
401 #if defined (MSDOS_16BIT)
402 extern zbyte *pcp;
403 extern zbyte *zmp;
404 
405 #define lo(v)   ((zbyte *)&v)[0]
406 #define hi(v)   ((zbyte *)&v)[1]
407 
408 /*
409  * Turbo C has a strange limitation with passing members of structs to
410  * assembly code within a macro.  If more than one struct have members
411  * of the same name, then Turbo C is unable to tell the difference.  In
412  * other words, suppose you have foo.a and bar.a.  Doing
413  * "SET_WORD(H_STUFF, foo.a);" will make Turbo C complain about
414  * "Ambiguous member name 'a' in function frobnitz".  The solution is to
415  * use the "pseudoregister" _AX to pass values in and out a macro.  Right
416  * now, just SET_WORD() and LOW_WORD() are being passed troublesome
417  * struct members.
418  *
419  */
420 
421 #define SET_WORD(addr, v) do {\
422 	asm les bx,zmp;\
423 	asm add bx,addr;\
424 	_AX = (v); \
425 	asm xchg al,ah;\
426 	asm mov es:[bx],ax; } while (0);
427 
428 #define LOW_WORD(addr,v) do {\
429 	asm les bx,zmp;\
430 	asm add bx,addr;\
431 	asm mov ax,es:[bx];\
432 	asm xchg al,ah;\
433 	(v) = _AX; } while (0);
434 
435 #define HIGH_WORD(addr,v) asm {\
436 	mov bx,word ptr zmp;\
437 	add bx,word ptr addr;\
438 	mov al,bh;\
439 	mov bh,0;\
440 	mov ah,0;\
441 	adc ah,byte ptr addr+2;\
442 	mov cl,4;\
443 	shl ax,cl;\
444 	add ax,word ptr zmp+2;\
445 	mov es,ax;\
446 	mov ax,es:[bx];\
447 	xchg al,ah;\
448 	mov v,ax }
449 
450 #define CODE_WORD(v) asm {\
451 	les bx,pcp;\
452 	mov ax,es:[bx];\
453 	xchg al,ah;\
454 	mov v,ax;\
455 	add word ptr pcp,2 }
456 
457 #define GET_PC(v) asm {\
458 	mov bx,word ptr pcp+2;\
459 	sub bx,word ptr zmp+2;\
460 	mov ax,bx;\
461 	mov cl,4;\
462 	shl bx,cl;\
463 	mov cl,12;\
464 	shr ax,cl;\
465 	add bx,word ptr pcp;\
466 	adc al,0;\
467 	sub bx,word ptr zmp;\
468 	sbb al,0;\
469 	mov word ptr v,bx;\
470 	mov word ptr v+2,ax }
471 
472 #define SET_PC(v) asm {\
473 	mov bx,word ptr zmp;\
474 	add bx,word ptr v;\
475 	mov al,bh;\
476 	mov bh,0;\
477 	mov ah,0;\
478 	adc ah,byte ptr v+2;\
479 	mov cl,4;\
480 	shl ax,cl;\
481 	add ax,word ptr zmp+2;\
482 	mov word ptr pcp,bx;\
483 	mov word ptr pcp+2,ax }
484 
485 #endif /* MSDOS_16BIT */
486 
487 
488 #if !defined (AMIGA) && !defined (MSDOS_16BIT)
489 
490 extern zbyte *pcp;
491 extern zbyte *zmp;
492 
493 #define lo(v)	(v & 0xff)
494 #define hi(v)	(v >> 8)
495 
496 #define SET_WORD(addr,v)  { zmp[addr] = hi(v); zmp[addr+1] = lo(v); }
497 #define LOW_WORD(addr,v)  { v = ((zword) zmp[addr] << 8) | zmp[addr+1]; }
498 #define HIGH_WORD(addr,v) { v = ((zword) zmp[addr] << 8) | zmp[addr+1]; }
499 #define CODE_WORD(v)      { v = ((zword) pcp[0] << 8) | pcp[1]; pcp += 2; }
500 #define GET_PC(v)         { v = pcp - zmp; }
501 #define SET_PC(v)         { pcp = zmp + v; }
502 
503 #endif
504 
505 
506 /*** Various data ***/
507 
508 extern enum story story_id;
509 extern long story_size;
510 
511 extern zword stack[STACK_SIZE];
512 extern zword *sp;
513 extern zword *fp;
514 extern zword frame_count;
515 
516 extern zword zargs[8];
517 extern int zargc;
518 
519 extern bool ostream_screen;
520 extern bool ostream_script;
521 extern bool ostream_memory;
522 extern bool ostream_record;
523 extern bool istream_replay;
524 extern bool message;
525 
526 extern int cwin;
527 extern int mwin;
528 
529 extern int mouse_x;
530 extern int mouse_y;
531 extern int menu_selected;
532 extern int mouse_button;
533 
534 extern bool enable_wrapping;
535 extern bool enable_scripting;
536 extern bool enable_scrolling;
537 extern bool enable_buffering;
538 
539 extern bool need_newline_at_exit;
540 
541 extern char *option_zcode_path;	/* dg */
542 
543 extern long reserve_mem;
544 
545 extern int zoptind;
546 extern int zoptopt;
547 extern char *zoptarg;
548 
549 /*** Z-machine opcodes ***/
550 void 	z_add(void);
551 void 	z_and(void);
552 void 	z_art_shift(void);
553 void 	z_buffer_mode(void);
554 void 	z_call_n(void);
555 void 	z_call_s(void);
556 void 	z_catch(void);
557 void 	z_check_arg_count(void);
558 void	z_check_unicode(void);
559 void 	z_clear_attr(void);
560 void 	z_copy_table(void);
561 void 	z_dec(void);
562 void 	z_dec_chk(void);
563 void 	z_div(void);
564 void 	z_draw_picture(void);
565 void 	z_encode_text(void);
566 void 	z_erase_line(void);
567 void 	z_erase_picture(void);
568 void 	z_erase_window(void);
569 void 	z_get_child(void);
570 void 	z_get_cursor(void);
571 void 	z_get_next_prop(void);
572 void 	z_get_parent(void);
573 void 	z_get_prop(void);
574 void 	z_get_prop_addr(void);
575 void 	z_get_prop_len(void);
576 void 	z_get_sibling(void);
577 void 	z_get_wind_prop(void);
578 void 	z_inc(void);
579 void 	z_inc_chk(void);
580 void 	z_input_stream(void);
581 void 	z_insert_obj(void);
582 void 	z_je(void);
583 void 	z_jg(void);
584 void 	z_jin(void);
585 void 	z_jl(void);
586 void 	z_jump(void);
587 void 	z_jz(void);
588 void 	z_load(void);
589 void 	z_loadb(void);
590 void 	z_loadw(void);
591 void 	z_log_shift(void);
592 void 	z_make_menu(void);
593 void 	z_mod(void);
594 void 	z_mouse_window(void);
595 void 	z_move_window(void);
596 void 	z_mul(void);
597 void 	z_new_line(void);
598 void 	z_nop(void);
599 void 	z_not(void);
600 void 	z_or(void);
601 void 	z_output_stream(void);
602 void 	z_picture_data(void);
603 void 	z_picture_table(void);
604 void 	z_piracy(void);
605 void 	z_pop(void);
606 void 	z_pop_stack(void);
607 void 	z_print(void);
608 void 	z_print_addr(void);
609 void 	z_print_char(void);
610 void 	z_print_form(void);
611 void 	z_print_num(void);
612 void 	z_print_obj(void);
613 void 	z_print_paddr(void);
614 void 	z_print_ret(void);
615 void 	z_print_table(void);
616 void	z_print_unicode(void);
617 void 	z_pull(void);
618 void 	z_push(void);
619 void 	z_push_stack(void);
620 void 	z_put_prop(void);
621 void 	z_put_wind_prop(void);
622 void 	z_quit(void);
623 void 	z_random(void);
624 void 	z_read(void);
625 void 	z_read_char(void);
626 void 	z_read_mouse(void);
627 void 	z_remove_obj(void);
628 void 	z_restart(void);
629 void 	z_restore(void);
630 void 	z_restore_undo(void);
631 void 	z_ret(void);
632 void 	z_ret_popped(void);
633 void 	z_rfalse(void);
634 void 	z_rtrue(void);
635 void 	z_save(void);
636 void 	z_save_undo(void);
637 void 	z_scan_table(void);
638 void 	z_scroll_window(void);
639 void 	z_set_attr(void);
640 void 	z_set_font(void);
641 void 	z_set_colour(void);
642 void 	z_set_cursor(void);
643 void 	z_set_margins(void);
644 void 	z_set_window(void);
645 void 	z_set_text_style(void);
646 void 	z_show_status(void);
647 void 	z_sound_effect(void);
648 void 	z_split_window(void);
649 void 	z_store(void);
650 void 	z_storeb(void);
651 void 	z_storew(void);
652 void 	z_sub(void);
653 void 	z_test(void);
654 void 	z_test_attr(void);
655 void 	z_throw(void);
656 void 	z_tokenise(void);
657 void 	z_verify(void);
658 void 	z_window_size(void);
659 void 	z_window_style(void);
660 
661 
662 /* Definitions for error handling functions and error codes. */
663 /* extern int err_report_mode; */
664 void	init_err(void);
665 void	runtime_error(int);
666 
667 /* Error codes */
668 #define ERR_TEXT_BUF_OVF 1	/* Text buffer overflow */
669 #define ERR_STORE_RANGE 2	/* Store out of dynamic memory */
670 #define ERR_DIV_ZERO 3		/* Division by zero */
671 #define ERR_ILL_OBJ 4		/* Illegal object */
672 #define ERR_ILL_ATTR 5		/* Illegal attribute */
673 #define ERR_NO_PROP 6		/* No such property */
674 #define ERR_STK_OVF 7		/* Stack overflow */
675 #define ERR_ILL_CALL_ADDR 8	/* Call to illegal address */
676 #define ERR_CALL_NON_RTN 9	/* Call to non-routine */
677 #define ERR_STK_UNDF 10		/* Stack underflow */
678 #define ERR_ILL_OPCODE 11	/* Illegal opcode */
679 #define ERR_BAD_FRAME 12	/* Bad stack frame */
680 #define ERR_ILL_JUMP_ADDR 13	/* Jump to illegal address */
681 #define ERR_SAVE_IN_INTER 14	/* Can't save while in interrupt */
682 #define ERR_STR3_NESTING 15	/* Nesting stream #3 too deep */
683 #define ERR_ILL_WIN 16		/* Illegal window */
684 #define ERR_ILL_WIN_PROP 17	/* Illegal window property */
685 #define ERR_ILL_PRINT_ADDR 18	/* Print at illegal address */
686 #define ERR_MAX_FATAL 18
687 
688 /* Less serious errors */
689 #define ERR_JIN_0 19		/* @jin called with object 0 */
690 #define ERR_GET_CHILD_0 20	/* @get_child called with object 0 */
691 #define ERR_GET_PARENT_0 21	/* @get_parent called with object 0 */
692 #define ERR_GET_SIBLING_0 22	/* @get_sibling called with object 0 */
693 #define ERR_GET_PROP_ADDR_0 23	/* @get_prop_addr called with object 0 */
694 #define ERR_GET_PROP_0 24	/* @get_prop called with object 0 */
695 #define ERR_PUT_PROP_0 25	/* @put_prop called with object 0 */
696 #define ERR_CLEAR_ATTR_0 26	/* @clear_attr called with object 0 */
697 #define ERR_SET_ATTR_0 27	/* @set_attr called with object 0 */
698 #define ERR_TEST_ATTR_0 28	/* @test_attr called with object 0 */
699 #define ERR_MOVE_OBJECT_0 29	/* @move_object called moving object 0 */
700 #define ERR_MOVE_OBJECT_TO_0 30	/* @move_object called moving into object 0 */
701 #define ERR_REMOVE_OBJECT_0 31	/* @remove_object called with object 0 */
702 #define ERR_GET_NEXT_PROP_0 32	/* @get_next_prop called with object 0 */
703 #define ERR_PLAY_SOUND 33	/* @play_sound called without SOUND_FLAG or OLD_SOUND_FLAG set */
704 #define ERR_NUM_ERRORS (33)
705 
706 /*
707  * There are four error reporting modes: never report errors;
708  * report only the first time a given error type occurs; report
709  * every time an error occurs; or treat all errors as fatal
710  * errors, killing the interpreter. I strongly recommend
711  * "report once" as the default. But you can compile in a
712  * different default by changing the definition of
713  * ERR_DEFAULT_REPORT_MODE. In any case, the player can
714  * specify a report mode on the command line by typing "-Z 0"
715  * through "-Z 3".
716  *
717  */
718 #define ERR_REPORT_NEVER (0)
719 #define ERR_REPORT_ONCE (1)
720 #define ERR_REPORT_ALWAYS (2)
721 #define ERR_REPORT_FATAL (3)
722 #define ERR_DEFAULT_REPORT_MODE ERR_REPORT_ONCE
723 
724 /*** Assorted initialization functions ***/
725 void   init_header(void);
726 void   init_setup(void);
727 void   init_buffer(void);
728 void   init_process(void);
729 void   init_sound(void);
730 
731 /*** Various global functions ***/
732 zchar	translate_from_zscii(zbyte);
733 zbyte	translate_to_zscii(zchar);
734 
735 void 	flush_buffer(void);
736 void	new_line(void);
737 void	print_char(zchar);
738 void	print_num(zword);
739 void	print_object(zword);
740 void 	print_string(const char *);
741 
742 void 	stream_mssg_on(void);
743 void 	stream_mssg_off(void);
744 
745 void	ret(zword);
746 void 	store(zword);
747 void 	branch(bool);
748 
749 void	storeb(zword, zbyte);
750 void	storew(zword, zword);
751 
752 void	end_of_sound(void);
753 
754 int	completion(const zchar *buffer, zchar *result);
755 
756 bool is_terminator(zchar);
757 void read_string(int max, zchar *buffer);
758 bool read_yes_or_no(const char *);
759 
760 void screen_new_line(void);
761 
762 #ifndef MSDOS_16BIT
763 #define cdecl
764 #endif
765 
766 int cdecl zgetopt(int, char **, const char *);
767 
768 /*** returns the current window ***/
769 Zwindow * curwinrec(void);
770 
771 
772 /*** Interface functions ***/
773 void 	os_beep(int);
774 int  	os_char_width(zchar);
775 int  	os_check_unicode(int, zchar);
776 void 	os_display_char(zchar);
777 void 	os_display_string(const zchar *);
778 void 	os_draw_picture(int, int, int);
779 void 	os_erase_area(int, int, int, int, int);
780 void 	os_fatal(const char *, ...);
781 void 	os_finish_with_sample(int);
782 int  	os_font_data(int, int *, int *);
783 void 	os_init_screen(void);
784 void	os_init_sound(void);
785 FILE	*os_load_story(void);
786 void 	os_more_prompt(void);
787 int  	os_peek_colour(void);
788 int  	os_picture_data(int, int *, int *);
789 void 	os_prepare_sample(int);
790 void 	os_process_arguments(int, char *[]);
791 int	os_random_seed(void);
792 char  	*os_read_file_name(const char *, int);
793 zchar	os_read_key(int, int);
794 zchar	os_read_line(int, zchar *, int, int, int);
795 void 	os_reset_screen(void);
796 void 	os_restart_game(int);
797 void 	os_scroll_area(int, int, int, int, int);
798 void 	os_set_colour(int, int);
799 void 	os_set_cursor(int, int);
800 void 	os_set_font(int);
801 void 	os_set_text_style(int);
802 void 	os_start_sample(int, int, int, zword);
803 void 	os_stop_sample(int);
804 int	os_storyfile_seek(FILE *, long, int);
805 int	os_storyfile_tell(FILE *);
806 int  	os_string_width(const zchar *);
807 void	os_init_setup(void);
808 void 	os_warn(const char *, ...);
809 void	os_quit(int);
810 
811 /**
812  * Called regularly by the interpreter, at least every few instructions
813  * (only when interpreting: e.g., not when waiting for input).
814  */
815 void    os_tick(void);
816 
817 /* Front ends call this if the terminal size changes. */
818 void    resize_screen(void);
819 
820 /* This is callable only from resize_screen. */
821 bool    os_repaint_window(int win, int ypos_old, int ypos_new, int xpos,
822 				int ysize, int xsize);
823 
824 #endif
825