Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / apps / plugins / frotz / frotz.h
blobbc8869cd2400aded10d08fc96042c65ad24f141f
1 /*
2 * frotz.h
4 * Global declarations and definitions
6 */
8 #include "frotzplugin.h"
10 #ifndef TRUE
11 #define TRUE 1
12 #endif
14 #ifndef FALSE
15 #define FALSE 0
16 #endif
18 typedef unsigned char zbyte;
19 typedef unsigned short zword;
21 enum story {
22 BEYOND_ZORK,
23 SHERLOCK,
24 ZORK_ZERO,
25 SHOGUN,
26 ARTHUR,
27 JOURNEY,
28 LURKING_HORROR,
29 UNKNOWN
32 typedef unsigned char zchar;
34 /*** Constants that may be set at compile time ***/
36 #ifndef MAX_UNDO_SLOTS
37 #define MAX_UNDO_SLOTS 500
38 #endif
39 #ifndef TEXT_BUFFER_SIZE
40 #define TEXT_BUFFER_SIZE 200
41 #endif
42 #ifndef INPUT_BUFFER_SIZE
43 #define INPUT_BUFFER_SIZE 200
44 #endif
45 #ifndef STACK_SIZE
46 #define STACK_SIZE 1024
47 #endif
49 /*** Story file header format ***/
51 #define H_VERSION 0
52 #define H_CONFIG 1
53 #define H_RELEASE 2
54 #define H_RESIDENT_SIZE 4
55 #define H_START_PC 6
56 #define H_DICTIONARY 8
57 #define H_OBJECTS 10
58 #define H_GLOBALS 12
59 #define H_DYNAMIC_SIZE 14
60 #define H_FLAGS 16
61 #define H_SERIAL 18
62 #define H_ABBREVIATIONS 24
63 #define H_FILE_SIZE 26
64 #define H_CHECKSUM 28
65 #define H_INTERPRETER_NUMBER 30
66 #define H_INTERPRETER_VERSION 31
67 #define H_SCREEN_ROWS 32
68 #define H_SCREEN_COLS 33
69 #define H_SCREEN_WIDTH 34
70 #define H_SCREEN_HEIGHT 36
71 #define H_FONT_HEIGHT 38 /* this is the font width in V5 */
72 #define H_FONT_WIDTH 39 /* this is the font height in V5 */
73 #define H_FUNCTIONS_OFFSET 40
74 #define H_STRINGS_OFFSET 42
75 #define H_DEFAULT_BACKGROUND 44
76 #define H_DEFAULT_FOREGROUND 45
77 #define H_TERMINATING_KEYS 46
78 #define H_LINE_WIDTH 48
79 #define H_STANDARD_HIGH 50
80 #define H_STANDARD_LOW 51
81 #define H_ALPHABET 52
82 #define H_EXTENSION_TABLE 54
83 #define H_USER_NAME 56
85 #define HX_TABLE_SIZE 0
86 #define HX_MOUSE_X 1
87 #define HX_MOUSE_Y 2
88 #define HX_UNICODE_TABLE 3
90 /*** Various Z-machine constants ***/
92 #define V1 1
93 #define V2 2
94 #define V3 3
95 #define V4 4
96 #define V5 5
97 #define V6 6
98 #define V7 7
99 #define V8 8
101 #define CONFIG_BYTE_SWAPPED 0x01 /* Story file is byte swapped - V3 */
102 #define CONFIG_TIME 0x02 /* Status line displays time - V3 */
103 #define CONFIG_TWODISKS 0x04 /* Story file occupied two disks - V3 */
104 #define CONFIG_TANDY 0x08 /* Tandy licensed game - V3 */
105 #define CONFIG_NOSTATUSLINE 0x10 /* Interpr can't support status lines - V3 */
106 #define CONFIG_SPLITSCREEN 0x20 /* Interpr supports split screen mode - V3 */
107 #define CONFIG_PROPORTIONAL 0x40 /* Interpr uses proportional font - V3 */
109 #define CONFIG_COLOUR 0x01 /* Interpr supports colour - V5+ */
110 #define CONFIG_PICTURES 0x02 /* Interpr supports pictures - V6 */
111 #define CONFIG_BOLDFACE 0x04 /* Interpr supports boldface style - V4+ */
112 #define CONFIG_EMPHASIS 0x08 /* Interpr supports emphasis style - V4+ */
113 #define CONFIG_FIXED 0x10 /* Interpr supports fixed width style - V4+ */
114 #define CONFIG_SOUND 0x20 /* Interpr supports sound - V6 */
116 #define CONFIG_TIMEDINPUT 0x80 /* Interpr supports timed input - V4+ */
118 #define SCRIPTING_FLAG 0x0001 /* Outputting to transscription file - V1+ */
119 #define FIXED_FONT_FLAG 0x0002 /* Use fixed width font - V3+ */
120 #define REFRESH_FLAG 0x0004 /* Refresh the screen - V6 */
121 #define GRAPHICS_FLAG 0x0008 /* Game wants to use graphics - V5+ */
122 #define OLD_SOUND_FLAG 0x0010 /* Game wants to use sound effects - V3 */
123 #define UNDO_FLAG 0x0010 /* Game wants to use UNDO feature - V5+ */
124 #define MOUSE_FLAG 0x0020 /* Game wants to use a mouse - V5+ */
125 #define COLOUR_FLAG 0x0040 /* Game wants to use colours - V5+ */
126 #define SOUND_FLAG 0x0080 /* Game wants to use sound effects - V5+ */
127 #define MENU_FLAG 0x0100 /* Game wants to use menus - V6 */
129 #define INTERP_DEFAULT 0
130 #define INTERP_DEC_20 1
131 #define INTERP_APPLE_IIE 2
132 #define INTERP_MACINTOSH 3
133 #define INTERP_AMIGA 4
134 #define INTERP_ATARI_ST 5
135 #define INTERP_MSDOS 6
136 #define INTERP_CBM_128 7
137 #define INTERP_CBM_64 8
138 #define INTERP_APPLE_IIC 9
139 #define INTERP_APPLE_IIGS 10
140 #define INTERP_TANDY 11
142 #define BLACK_COLOUR 2
143 #define RED_COLOUR 3
144 #define GREEN_COLOUR 4
145 #define YELLOW_COLOUR 5
146 #define BLUE_COLOUR 6
147 #define MAGENTA_COLOUR 7
148 #define CYAN_COLOUR 8
149 #define WHITE_COLOUR 9
150 #define GREY_COLOUR 10 /* INTERP_MSDOS only */
151 #define LIGHTGREY_COLOUR 10 /* INTERP_AMIGA only */
152 #define MEDIUMGREY_COLOUR 11 /* INTERP_AMIGA only */
153 #define DARKGREY_COLOUR 12 /* INTERP_AMIGA only */
155 #define REVERSE_STYLE 1
156 #define BOLDFACE_STYLE 2
157 #define EMPHASIS_STYLE 4
158 #define FIXED_WIDTH_STYLE 8
160 #define TEXT_FONT 1
161 #define PICTURE_FONT 2
162 #define GRAPHICS_FONT 3
163 #define FIXED_WIDTH_FONT 4
165 #define BEEP_HIGH 1
166 #define BEEP_LOW 2
168 /*** Constants for os_restart_game */
170 #define RESTART_BEGIN 0
171 #define RESTART_WPROP_SET 1
172 #define RESTART_END 2
174 /*** Character codes ***/
176 #define ZC_TIME_OUT 0x00
177 #define ZC_NEW_STYLE 0x01
178 #define ZC_NEW_FONT 0x02
179 #define ZC_BACKSPACE 0x08
180 #define ZC_INDENT 0x09
181 #define ZC_GAP 0x0b
182 #define ZC_RETURN 0x0d
183 #define ZC_HKEY_MIN 0x0e
184 #define ZC_HKEY_RECORD 0x0e
185 #define ZC_HKEY_PLAYBACK 0x0f
186 #define ZC_HKEY_SEED 0x10
187 #define ZC_HKEY_UNDO 0x11
188 #define ZC_HKEY_RESTART 0x12
189 #define ZC_HKEY_QUIT 0x13
190 #define ZC_HKEY_DEBUG 0x14
191 #define ZC_HKEY_HELP 0x15
192 #define ZC_HKEY_MAX 0x15
193 #define ZC_ESCAPE 0x1b
194 #define ZC_ASCII_MIN 0x20
195 #define ZC_ASCII_MAX 0x7e
196 #define ZC_BAD 0x7f
197 #define ZC_ARROW_MIN 0x81
198 #define ZC_ARROW_UP 0x81
199 #define ZC_ARROW_DOWN 0x82
200 #define ZC_ARROW_LEFT 0x83
201 #define ZC_ARROW_RIGHT 0x84
202 #define ZC_ARROW_MAX 0x84
203 #define ZC_FKEY_MIN 0x85
204 #define ZC_FKEY_MAX 0x90
205 #define ZC_NUMPAD_MIN 0x91
206 #define ZC_NUMPAD_MAX 0x9a
207 #define ZC_SINGLE_CLICK 0x9b
208 #define ZC_DOUBLE_CLICK 0x9c
209 #define ZC_MENU_CLICK 0x9d
210 #define ZC_LATIN1_MIN 0xa0
211 #define ZC_LATIN1_MAX 0xff
213 /*** File types ***/
215 #define FILE_RESTORE 0
216 #define FILE_SAVE 1
217 #define FILE_SCRIPT 2
218 #define FILE_PLAYBACK 3
219 #define FILE_RECORD 4
220 #define FILE_LOAD_AUX 5
221 #define FILE_SAVE_AUX 6
223 /*** Data access macros ***/
225 #define SET_BYTE(addr,v) { zmp[addr] = v; }
226 #define LOW_BYTE(addr,v) { v = zmp[addr]; }
227 #define CODE_BYTE(v) { v = *pcp++; }
229 #if defined (AMIGA)
231 extern zbyte *pcp;
232 extern zbyte *zmp;
234 #define lo(v) ((zbyte *)&v)[1]
235 #define hi(v) ((zbyte *)&v)[0]
237 #define SET_WORD(addr,v) { zmp[addr] = hi(v); zmp[addr+1] = lo(v); }
238 #define LOW_WORD(addr,v) { hi(v) = zmp[addr]; lo(v) = zmp[addr+1]; }
239 #define HIGH_WORD(addr,v) { hi(v) = zmp[addr]; lo(v) = zmp[addr+1]; }
240 #define CODE_WORD(v) { hi(v) = *pcp++; lo(v) = *pcp++; }
241 #define GET_PC(v) { v = pcp - zmp; }
242 #define SET_PC(v) { pcp = zmp + v; }
244 #endif
246 /* A bunch of x86 assembly code previously appeared here. */
248 #if !defined (AMIGA) && !defined (MSDOS_16BIT)
250 extern zbyte *pcp;
251 extern zbyte *zmp;
253 #define lo(v) (v & 0xff)
254 #define hi(v) (v >> 8)
256 #define SET_WORD(addr,v) { zmp[addr] = hi(v); zmp[addr+1] = lo(v); }
257 #define LOW_WORD(addr,v) { v = ((zword) zmp[addr] << 8) | zmp[addr+1]; }
258 #define HIGH_WORD(addr,v) { v = ((zword) zmp[addr] << 8) | zmp[addr+1]; }
259 #define CODE_WORD(v) { v = ((zword) pcp[0] << 8) | pcp[1]; pcp += 2; }
260 #define GET_PC(v) { v = pcp - zmp; }
261 #define SET_PC(v) { pcp = zmp + v; }
263 #endif
266 /*** Story file header data ***/
268 extern zbyte h_version;
269 extern zbyte h_config;
270 extern zword h_release;
271 extern zword h_resident_size;
272 extern zword h_start_pc;
273 extern zword h_dictionary;
274 extern zword h_objects;
275 extern zword h_globals;
276 extern zword h_dynamic_size;
277 extern zword h_flags;
278 extern zbyte h_serial[6];
279 extern zword h_abbreviations;
280 extern zword h_file_size;
281 extern zword h_checksum;
282 extern zbyte h_interpreter_number;
283 extern zbyte h_interpreter_version;
284 extern zbyte h_screen_rows;
285 extern zbyte h_screen_cols;
286 extern zword h_screen_width;
287 extern zword h_screen_height;
288 extern zbyte h_font_height;
289 extern zbyte h_font_width;
290 extern zword h_functions_offset;
291 extern zword h_strings_offset;
292 extern zbyte h_default_background;
293 extern zbyte h_default_foreground;
294 extern zword h_terminating_keys;
295 extern zword h_line_width;
296 extern zbyte h_standard_high;
297 extern zbyte h_standard_low;
298 extern zword h_alphabet;
299 extern zword h_extension_table;
300 extern zbyte h_user_name[8];
302 extern zword hx_table_size;
303 extern zword hx_mouse_x;
304 extern zword hx_mouse_y;
305 extern zword hx_unicode_table;
307 /*** Various data ***/
309 extern const char *story_name;
311 extern enum story story_id;
312 extern long story_size;
314 extern zword stack[STACK_SIZE];
315 extern zword *sp;
316 extern zword *fp;
317 extern zword frame_count;
319 extern zword zargs[8];
320 extern int zargc;
322 extern bool ostream_screen;
323 extern bool ostream_script;
324 extern bool ostream_memory;
325 extern bool ostream_record;
326 extern bool istream_replay;
327 extern bool message;
329 extern int cwin;
330 extern int mwin;
332 extern int mouse_x;
333 extern int mouse_y;
335 extern bool enable_wrapping;
336 extern bool enable_scripting;
337 extern bool enable_scrolling;
338 extern bool enable_buffering;
341 extern char *option_zcode_path; /* dg */
344 /*** Blorb stuff ***/
346 bb_err_t blorb_err;
347 bb_map_t *blorb_map;
350 /*** Z-machine opcodes ***/
352 void z_add (void);
353 void z_and (void);
354 void z_art_shift (void);
355 void z_buffer_mode (void);
356 void z_call_n (void);
357 void z_call_s (void);
358 void z_catch (void);
359 void z_check_arg_count (void);
360 void z_check_unicode (void);
361 void z_clear_attr (void);
362 void z_copy_table (void);
363 void z_dec (void);
364 void z_dec_chk (void);
365 void z_div (void);
366 void z_draw_picture (void);
367 void z_encode_text (void);
368 void z_erase_line (void);
369 void z_erase_picture (void);
370 void z_erase_window (void);
371 void z_get_child (void);
372 void z_get_cursor (void);
373 void z_get_next_prop (void);
374 void z_get_parent (void);
375 void z_get_prop (void);
376 void z_get_prop_addr (void);
377 void z_get_prop_len (void);
378 void z_get_sibling (void);
379 void z_get_wind_prop (void);
380 void z_inc (void);
381 void z_inc_chk (void);
382 void z_input_stream (void);
383 void z_insert_obj (void);
384 void z_je (void);
385 void z_jg (void);
386 void z_jin (void);
387 void z_jl (void);
388 void z_jump (void);
389 void z_jz (void);
390 void z_load (void);
391 void z_loadb (void);
392 void z_loadw (void);
393 void z_log_shift (void);
394 void z_make_menu (void);
395 void z_mod (void);
396 void z_mouse_window (void);
397 void z_move_window (void);
398 void z_mul (void);
399 void z_new_line (void);
400 void z_nop (void);
401 void z_not (void);
402 void z_or (void);
403 void z_output_stream (void);
404 void z_picture_data (void);
405 void z_picture_table (void);
406 void z_piracy (void);
407 void z_pop (void);
408 void z_pop_stack (void);
409 void z_print (void);
410 void z_print_addr (void);
411 void z_print_char (void);
412 void z_print_form (void);
413 void z_print_num (void);
414 void z_print_obj (void);
415 void z_print_paddr (void);
416 void z_print_ret (void);
417 void z_print_table (void);
418 void z_print_unicode (void);
419 void z_pull (void);
420 void z_push (void);
421 void z_push_stack (void);
422 void z_put_prop (void);
423 void z_put_wind_prop (void);
424 void z_quit (void);
425 void z_random (void);
426 void z_read (void);
427 void z_read_char (void);
428 void z_read_mouse (void);
429 void z_remove_obj (void);
430 void z_restart (void);
431 void z_restore (void);
432 void z_restore_undo (void);
433 void z_ret (void);
434 void z_ret_popped (void);
435 void z_rfalse (void);
436 void z_rtrue (void);
437 void z_save (void);
438 void z_save_undo (void);
439 void z_scan_table (void);
440 void z_scroll_window (void);
441 void z_set_attr (void);
442 void z_set_font (void);
443 void z_set_colour (void);
444 void z_set_cursor (void);
445 void z_set_margins (void);
446 void z_set_window (void);
447 void z_set_text_style (void);
448 void z_show_status (void);
449 void z_sound_effect (void);
450 void z_split_window (void);
451 void z_store (void);
452 void z_storeb (void);
453 void z_storew (void);
454 void z_sub (void);
455 void z_test (void);
456 void z_test_attr (void);
457 void z_throw (void);
458 void z_tokenise (void);
459 void z_verify (void);
460 void z_window_size (void);
461 void z_window_style (void);
463 /* Definitions for error handling functions and error codes. */
465 /* extern int err_report_mode; */
467 void init_err (void);
468 void runtime_error (int);
470 /* Error codes */
471 #define ERR_TEXT_BUF_OVF 1 /* Text buffer overflow */
472 #define ERR_STORE_RANGE 2 /* Store out of dynamic memory */
473 #define ERR_DIV_ZERO 3 /* Division by zero */
474 #define ERR_ILL_OBJ 4 /* Illegal object */
475 #define ERR_ILL_ATTR 5 /* Illegal attribute */
476 #define ERR_NO_PROP 6 /* No such property */
477 #define ERR_STK_OVF 7 /* Stack overflow */
478 #define ERR_ILL_CALL_ADDR 8 /* Call to illegal address */
479 #define ERR_CALL_NON_RTN 9 /* Call to non-routine */
480 #define ERR_STK_UNDF 10 /* Stack underflow */
481 #define ERR_ILL_OPCODE 11 /* Illegal opcode */
482 #define ERR_BAD_FRAME 12 /* Bad stack frame */
483 #define ERR_ILL_JUMP_ADDR 13 /* Jump to illegal address */
484 #define ERR_SAVE_IN_INTER 14 /* Can't save while in interrupt */
485 #define ERR_STR3_NESTING 15 /* Nesting stream #3 too deep */
486 #define ERR_ILL_WIN 16 /* Illegal window */
487 #define ERR_ILL_WIN_PROP 17 /* Illegal window property */
488 #define ERR_ILL_PRINT_ADDR 18 /* Print at illegal address */
489 #define ERR_MAX_FATAL 18
491 /* Less serious errors */
492 #define ERR_JIN_0 19 /* @jin called with object 0 */
493 #define ERR_GET_CHILD_0 20 /* @get_child called with object 0 */
494 #define ERR_GET_PARENT_0 21 /* @get_parent called with object 0 */
495 #define ERR_GET_SIBLING_0 22 /* @get_sibling called with object 0 */
496 #define ERR_GET_PROP_ADDR_0 23 /* @get_prop_addr called with object 0 */
497 #define ERR_GET_PROP_0 24 /* @get_prop called with object 0 */
498 #define ERR_PUT_PROP_0 25 /* @put_prop called with object 0 */
499 #define ERR_CLEAR_ATTR_0 26 /* @clear_attr called with object 0 */
500 #define ERR_SET_ATTR_0 27 /* @set_attr called with object 0 */
501 #define ERR_TEST_ATTR_0 28 /* @test_attr called with object 0 */
502 #define ERR_MOVE_OBJECT_0 29 /* @move_object called moving object 0 */
503 #define ERR_MOVE_OBJECT_TO_0 30 /* @move_object called moving into object 0 */
504 #define ERR_REMOVE_OBJECT_0 31 /* @remove_object called with object 0 */
505 #define ERR_GET_NEXT_PROP_0 32 /* @get_next_prop called with object 0 */
506 #define ERR_NUM_ERRORS (32)
508 /* There are four error reporting modes: never report errors;
509 report only the first time a given error type occurs; report
510 every time an error occurs; or treat all errors as fatal
511 errors, killing the interpreter. I strongly recommend
512 "report once" as the default. But you can compile in a
513 different default by changing the definition of
514 ERR_DEFAULT_REPORT_MODE. In any case, the player can
515 specify a report mode on the command line by typing "-Z 0"
516 through "-Z 3". */
518 #define ERR_REPORT_NEVER (0)
519 #define ERR_REPORT_ONCE (1)
520 #define ERR_REPORT_ALWAYS (2)
521 #define ERR_REPORT_FATAL (3)
523 #define ERR_DEFAULT_REPORT_MODE ERR_REPORT_ONCE
526 /*** Various global functions ***/
528 zchar translate_from_zscii (zbyte);
529 zbyte translate_to_zscii (zchar);
531 void flush_buffer (void);
532 void new_line (void);
533 void print_char (zchar);
534 void print_num (zword);
535 void print_object (zword);
536 void print_string (const char *);
538 void stream_mssg_on (void);
539 void stream_mssg_off (void);
541 void ret (zword);
542 void store (zword);
543 void branch (bool);
545 void storeb (zword, zbyte);
546 void storew (zword, zword);
548 /*** Interface functions ***/
550 void os_beep (int);
551 int os_char_width (zchar);
552 void os_display_char (zchar);
553 void os_display_string (const zchar *);
554 void os_draw_picture (int, int, int);
555 void os_erase_area (int, int, int, int);
556 void os_fatal (const char *) __attribute__((noreturn));
557 void os_finish_with_sample (int);
558 int os_font_data (int, int *, int *);
559 void os_init_screen (void);
560 void os_more_prompt (void);
561 int os_peek_colour (void);
562 bool os_picture_data (int, int *, int *);
563 void os_prepare_sample (int);
564 void os_process_arguments (int, char *[]);
565 int os_random_seed (void);
566 int os_read_file_name (char *, const char *, int);
567 zchar os_read_key (int, bool);
568 zchar os_read_line (int, zchar *, int, int, int);
569 zchar os_read_mouse (void);
570 void os_reset_screen (void);
571 void os_restart_game (int);
572 void os_scroll_area (int, int, int, int, int);
573 void os_set_colour (int, int);
574 void os_set_cursor (int, int);
575 void os_set_font (int);
576 void os_set_text_style (int);
577 void os_start_sample (int, int, int, zword);
578 void os_stop_sample (int);
579 int os_string_width (const zchar *);
580 void os_init_setup (void);
581 int os_speech_output(const zchar *);
583 #include "setup.h"