summaryrefslogtreecommitdiff
path: root/apps/plugins/frotz/frotz.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/frotz/frotz.h')
-rw-r--r--apps/plugins/frotz/frotz.h583
1 files changed, 583 insertions, 0 deletions
diff --git a/apps/plugins/frotz/frotz.h b/apps/plugins/frotz/frotz.h
new file mode 100644
index 0000000000..bc8869cd24
--- /dev/null
+++ b/apps/plugins/frotz/frotz.h
@@ -0,0 +1,583 @@
1/*
2 * frotz.h
3 *
4 * Global declarations and definitions
5 *
6 */
7
8#include "frotzplugin.h"
9
10#ifndef TRUE
11#define TRUE 1
12#endif
13
14#ifndef FALSE
15#define FALSE 0
16#endif
17
18typedef unsigned char zbyte;
19typedef unsigned short zword;
20
21enum story {
22 BEYOND_ZORK,
23 SHERLOCK,
24 ZORK_ZERO,
25 SHOGUN,
26 ARTHUR,
27 JOURNEY,
28 LURKING_HORROR,
29 UNKNOWN
30};
31
32typedef unsigned char zchar;
33
34/*** Constants that may be set at compile time ***/
35
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
48
49/*** Story file header format ***/
50
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
84
85#define HX_TABLE_SIZE 0
86#define HX_MOUSE_X 1
87#define HX_MOUSE_Y 2
88#define HX_UNICODE_TABLE 3
89
90/*** Various Z-machine constants ***/
91
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
100
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 */
108
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 */
115
116#define CONFIG_TIMEDINPUT 0x80 /* Interpr supports timed input - V4+ */
117
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 */
128
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
141
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 */
154
155#define REVERSE_STYLE 1
156#define BOLDFACE_STYLE 2
157#define EMPHASIS_STYLE 4
158#define FIXED_WIDTH_STYLE 8
159
160#define TEXT_FONT 1
161#define PICTURE_FONT 2
162#define GRAPHICS_FONT 3
163#define FIXED_WIDTH_FONT 4
164
165#define BEEP_HIGH 1
166#define BEEP_LOW 2
167
168/*** Constants for os_restart_game */
169
170#define RESTART_BEGIN 0
171#define RESTART_WPROP_SET 1
172#define RESTART_END 2
173
174/*** Character codes ***/
175
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
212
213/*** File types ***/
214
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
222
223/*** Data access macros ***/
224
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++; }
228
229#if defined (AMIGA)
230
231extern zbyte *pcp;
232extern zbyte *zmp;
233
234#define lo(v) ((zbyte *)&v)[1]
235#define hi(v) ((zbyte *)&v)[0]
236
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; }
243
244#endif
245
246/* A bunch of x86 assembly code previously appeared here. */
247
248#if !defined (AMIGA) && !defined (MSDOS_16BIT)
249
250extern zbyte *pcp;
251extern zbyte *zmp;
252
253#define lo(v) (v & 0xff)
254#define hi(v) (v >> 8)
255
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; }
262
263#endif
264
265
266/*** Story file header data ***/
267
268extern zbyte h_version;
269extern zbyte h_config;
270extern zword h_release;
271extern zword h_resident_size;
272extern zword h_start_pc;
273extern zword h_dictionary;
274extern zword h_objects;
275extern zword h_globals;
276extern zword h_dynamic_size;
277extern zword h_flags;
278extern zbyte h_serial[6];
279extern zword h_abbreviations;
280extern zword h_file_size;
281extern zword h_checksum;
282extern zbyte h_interpreter_number;
283extern zbyte h_interpreter_version;
284extern zbyte h_screen_rows;
285extern zbyte h_screen_cols;
286extern zword h_screen_width;
287extern zword h_screen_height;
288extern zbyte h_font_height;
289extern zbyte h_font_width;
290extern zword h_functions_offset;
291extern zword h_strings_offset;
292extern zbyte h_default_background;
293extern zbyte h_default_foreground;
294extern zword h_terminating_keys;
295extern zword h_line_width;
296extern zbyte h_standard_high;
297extern zbyte h_standard_low;
298extern zword h_alphabet;
299extern zword h_extension_table;
300extern zbyte h_user_name[8];
301
302extern zword hx_table_size;
303extern zword hx_mouse_x;
304extern zword hx_mouse_y;
305extern zword hx_unicode_table;
306
307/*** Various data ***/
308
309extern const char *story_name;
310
311extern enum story story_id;
312extern long story_size;
313
314extern zword stack[STACK_SIZE];
315extern zword *sp;
316extern zword *fp;
317extern zword frame_count;
318
319extern zword zargs[8];
320extern int zargc;
321
322extern bool ostream_screen;
323extern bool ostream_script;
324extern bool ostream_memory;
325extern bool ostream_record;
326extern bool istream_replay;
327extern bool message;
328
329extern int cwin;
330extern int mwin;
331
332extern int mouse_x;
333extern int mouse_y;
334
335extern bool enable_wrapping;
336extern bool enable_scripting;
337extern bool enable_scrolling;
338extern bool enable_buffering;
339
340
341extern char *option_zcode_path; /* dg */
342
343
344/*** Blorb stuff ***/
345/*
346bb_err_t blorb_err;
347bb_map_t *blorb_map;
348*/
349
350/*** Z-machine opcodes ***/
351
352void z_add (void);
353void z_and (void);
354void z_art_shift (void);
355void z_buffer_mode (void);
356void z_call_n (void);
357void z_call_s (void);
358void z_catch (void);
359void z_check_arg_count (void);
360void z_check_unicode (void);
361void z_clear_attr (void);
362void z_copy_table (void);
363void z_dec (void);
364void z_dec_chk (void);
365void z_div (void);
366void z_draw_picture (void);
367void z_encode_text (void);
368void z_erase_line (void);
369void z_erase_picture (void);
370void z_erase_window (void);
371void z_get_child (void);
372void z_get_cursor (void);
373void z_get_next_prop (void);
374void z_get_parent (void);
375void z_get_prop (void);
376void z_get_prop_addr (void);
377void z_get_prop_len (void);
378void z_get_sibling (void);
379void z_get_wind_prop (void);
380void z_inc (void);
381void z_inc_chk (void);
382void z_input_stream (void);
383void z_insert_obj (void);
384void z_je (void);
385void z_jg (void);
386void z_jin (void);
387void z_jl (void);
388void z_jump (void);
389void z_jz (void);
390void z_load (void);
391void z_loadb (void);
392void z_loadw (void);
393void z_log_shift (void);
394void z_make_menu (void);
395void z_mod (void);
396void z_mouse_window (void);
397void z_move_window (void);
398void z_mul (void);
399void z_new_line (void);
400void z_nop (void);
401void z_not (void);
402void z_or (void);
403void z_output_stream (void);
404void z_picture_data (void);
405void z_picture_table (void);
406void z_piracy (void);
407void z_pop (void);
408void z_pop_stack (void);
409void z_print (void);
410void z_print_addr (void);
411void z_print_char (void);
412void z_print_form (void);
413void z_print_num (void);
414void z_print_obj (void);
415void z_print_paddr (void);
416void z_print_ret (void);
417void z_print_table (void);
418void z_print_unicode (void);
419void z_pull (void);
420void z_push (void);
421void z_push_stack (void);
422void z_put_prop (void);
423void z_put_wind_prop (void);
424void z_quit (void);
425void z_random (void);
426void z_read (void);
427void z_read_char (void);
428void z_read_mouse (void);
429void z_remove_obj (void);
430void z_restart (void);
431void z_restore (void);
432void z_restore_undo (void);
433void z_ret (void);
434void z_ret_popped (void);
435void z_rfalse (void);
436void z_rtrue (void);
437void z_save (void);
438void z_save_undo (void);
439void z_scan_table (void);
440void z_scroll_window (void);
441void z_set_attr (void);
442void z_set_font (void);
443void z_set_colour (void);
444void z_set_cursor (void);
445void z_set_margins (void);
446void z_set_window (void);
447void z_set_text_style (void);
448void z_show_status (void);
449void z_sound_effect (void);
450void z_split_window (void);
451void z_store (void);
452void z_storeb (void);
453void z_storew (void);
454void z_sub (void);
455void z_test (void);
456void z_test_attr (void);
457void z_throw (void);
458void z_tokenise (void);
459void z_verify (void);
460void z_window_size (void);
461void z_window_style (void);
462
463/* Definitions for error handling functions and error codes. */
464
465/* extern int err_report_mode; */
466
467void init_err (void);
468void runtime_error (int);
469
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
490
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)
507
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". */
517
518#define ERR_REPORT_NEVER (0)
519#define ERR_REPORT_ONCE (1)
520#define ERR_REPORT_ALWAYS (2)
521#define ERR_REPORT_FATAL (3)
522
523#define ERR_DEFAULT_REPORT_MODE ERR_REPORT_ONCE
524
525
526/*** Various global functions ***/
527
528zchar translate_from_zscii (zbyte);
529zbyte translate_to_zscii (zchar);
530
531void flush_buffer (void);
532void new_line (void);
533void print_char (zchar);
534void print_num (zword);
535void print_object (zword);
536void print_string (const char *);
537
538void stream_mssg_on (void);
539void stream_mssg_off (void);
540
541void ret (zword);
542void store (zword);
543void branch (bool);
544
545void storeb (zword, zbyte);
546void storew (zword, zword);
547
548/*** Interface functions ***/
549
550void os_beep (int);
551int os_char_width (zchar);
552void os_display_char (zchar);
553void os_display_string (const zchar *);
554void os_draw_picture (int, int, int);
555void os_erase_area (int, int, int, int);
556void os_fatal (const char *) __attribute__((noreturn));
557void os_finish_with_sample (int);
558int os_font_data (int, int *, int *);
559void os_init_screen (void);
560void os_more_prompt (void);
561int os_peek_colour (void);
562bool os_picture_data (int, int *, int *);
563void os_prepare_sample (int);
564void os_process_arguments (int, char *[]);
565int os_random_seed (void);
566int os_read_file_name (char *, const char *, int);
567zchar os_read_key (int, bool);
568zchar os_read_line (int, zchar *, int, int, int);
569zchar os_read_mouse (void);
570void os_reset_screen (void);
571void os_restart_game (int);
572void os_scroll_area (int, int, int, int, int);
573void os_set_colour (int, int);
574void os_set_cursor (int, int);
575void os_set_font (int);
576void os_set_text_style (int);
577void os_start_sample (int, int, int, zword);
578void os_stop_sample (int);
579int os_string_width (const zchar *);
580void os_init_setup (void);
581int os_speech_output(const zchar *);
582
583#include "setup.h"