1 /* Sarien - A Sierra AGI resource interpreter engine 2 * Copyright (C) 1999-2001 Stuart George and Claudio Matsuoka 3 * 4 * $Id: agi.h,v 1.47 2001/11/04 02:33:45 cmatsuoka Exp $ 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; see docs/COPYING for further details. 9 */ 10 11 #ifndef __AGI_H 12 #define __AGI_H 13 14 #ifdef __cplusplus 15 extern "C"{ 16 #endif 17 18 /* AGI resources */ 19 #include "view.h" 20 #include "picture.h" 21 #include "logic.h" 22 #include "sound.h" 23 24 #define WIN_TO_PIC_X(x) ((x) / 2) 25 #define WIN_TO_PIC_Y(y) ((y) < 8 ? 999 : (y) >= (8 + _HEIGHT) ? 999 : (y) - 8) 26 27 /** 28 * AGI variables. 29 */ 30 enum { 31 V_cur_room = 0, /* 0 */ 32 V_prev_room, 33 V_border_touch_ego, 34 V_score, 35 V_border_code, 36 V_border_touch_obj, /* 5 */ 37 V_ego_dir, 38 V_max_score, 39 V_free_pages, 40 V_word_not_found, 41 V_time_delay, /* 10 */ 42 V_seconds, 43 V_minutes, 44 V_hours, 45 V_days, 46 V_joystick_sensitivity, /* 15 */ 47 V_ego_view_resource, 48 V_agi_err_code, 49 V_agi_err_code_info, 50 V_key, 51 V_computer, /* 20 */ 52 V_window_reset, 53 V_soundgen, 54 V_Volume, 55 V_max_input_chars, 56 V_sel_item, /* 25 */ 57 V_monitor 58 }; 59 60 /** 61 * AGI flags 62 */ 63 enum { 64 F_ego_water = 0, /* 0 */ 65 F_ego_invisible, 66 F_entered_cli, 67 F_ego_touched_p2, 68 F_said_accepted_input, 69 F_new_room_exec, /* 5 */ 70 F_restart_game, 71 F_script_blocked, 72 F_joy_sensitivity, 73 F_sound_on, 74 F_debugger_on, /* 10 */ 75 F_logic_zero_firsttime, 76 F_restore_just_ran, 77 F_status_selects_items, 78 F_menus_work, 79 F_output_mode /* 15 */ 80 /* Add F16 used in restart.game */ 81 }; 82 83 struct agi_event { 84 UINT8 occured; 85 UINT16 data; 86 }; 87 88 struct agi_word { 89 int id; 90 char *word; 91 }; 92 93 struct agi_dir { 94 UINT8 volume; 95 UINT32 offset; 96 UINT32 len; 97 UINT32 clen; 98 UINT8 flags; 99 /* 0 = not in mem, can be freed 100 * 1 = in mem, can be released 101 * 2 = not in mem, cant be released 102 * 3 = in mem, cant be released 103 * 0x40 = was compressed 104 */ 105 }; 106 107 struct agi_block { 108 int active; 109 int x1, y1; 110 int x2, y2; 111 UINT8 *buffer; /* used for window background */ 112 }; 113 114 #define EGO_VIEW_TABLE 0 115 #define HORIZON 36 116 #define _WIDTH 160 117 #define _HEIGHT 168 118 119 /** 120 * AGI game structure. 121 * This structure contains all global data of an AGI game executed 122 * by the interpreter. 123 */ 124 struct agi_game { 125 #define STATE_INIT 0x00 126 #define STATE_LOADED 0x01 127 #define STATE_RUNNING 0x02 128 int state; /**< state of the interpreter */ 129 130 char name[8]; /**< lead in id (e.g. `GR' for goldrush) */ 131 char id[8]; /**< game id */ 132 char dir[MAX_PATH]; /**< game dir */ 133 UINT32 crc; /**< game CRC */ 134 UINT32 ver; /**< detected game version */ 135 136 /* game flags and variables */ 137 UINT8 flags[MAX_FLAGS]; /**< 256 1-bit flags */ 138 UINT8 vars[MAX_VARS]; /**< 256 variables */ 139 140 /* internal variables */ 141 int horizon; /**< horizon y coordinate */ 142 int line_status; /**< line number to put status on */ 143 int line_user_input; /**< line to put user input on */ 144 int line_min_print; /**< num lines to print on */ 145 int cursor_pos; /**< column where the input cursor is */ 146 UINT8 input_buffer[40]; /**< buffer for user input */ 147 UINT8 echo_buffer[40]; /**< buffer for echo.line */ 148 int keypress; 149 #define INPUT_NORMAL 0x01 150 #define INPUT_GETSTRING 0x02 151 #define INPUT_MENU 0x03 152 #define INPUT_NONE 0x04 153 int input_mode; /**< keyboard input mode */ 154 int lognum; /**< current logic number */ 155 156 /* internal flags */ 157 int player_control; /**< player is in control */ 158 int quit_prog_now; /**< quit now */ 159 int status_line; /**< status line on/off */ 160 int clock_enabled; /**< clock is on/off */ 161 int exit_all_logics; /**< break cycle after new.room */ 162 int picture_shown; /**< show.pic has been issued */ 163 int has_prompt; /**< input prompt has been printed */ 164 #define ID_AGDS 0x00000001 165 #define ID_AMIGA 0x00000002 166 int game_flags; /**< Sarien options flags */ 167 168 /* priority table */ 169 int alt_pri; 170 UINT8 pri_table[_HEIGHT]; 171 172 /* windows */ 173 UINT32 msg_box_ticks; /**< timed message box tick counter */ 174 struct agi_block block; 175 struct agi_block window; 176 int has_window; 177 178 /* graphics & text*/ 179 int gfx_mode; 180 char cursor_char; 181 unsigned int color_fg; 182 unsigned int color_bg; 183 #ifdef USE_HIRES 184 UINT8 hires[_WIDTH * 2 * _HEIGHT]; 185 #endif 186 UINT8 sbuf[_WIDTH * _HEIGHT]; /**< 160x168 AGI screen buffer */ 187 188 /* player command line */ 189 struct agi_word ego_words[MAX_WORDS]; 190 int num_ego_words; 191 192 unsigned int num_objects; 193 194 struct agi_event ev_keyp[MAX_DIRS]; /**< keyboard keypress events */ 195 struct agi_event ev_scan[MAX_DIRS]; /**< keyboard scan events */ 196 char strings[MAX_WORDS1][MAX_WORDS2]; /**< strings */ 197 198 /* directory entries for resources */ 199 struct agi_dir dir_logic[MAX_DIRS]; 200 struct agi_dir dir_pic[MAX_DIRS]; 201 struct agi_dir dir_view[MAX_DIRS]; 202 struct agi_dir dir_sound[MAX_DIRS]; 203 204 /* resources */ 205 struct agi_picture pictures[MAX_DIRS]; /**< AGI picture resources */ 206 struct agi_logic logics[MAX_DIRS]; /**< AGI logic resources */ 207 struct agi_view views[MAX_DIRS]; /**< AGI view resources */ 208 struct agi_sound sounds[MAX_DIRS]; /**< AGI sound resources */ 209 210 /* view table */ 211 struct vt_entry view_table[MAX_VIEWTABLE]; 212 }; 213 214 /** 215 * 216 */ 217 struct agi_loader { 218 int version; 219 int int_version; 220 int (*init)(void); 221 int (*deinit)(void); 222 int (*detect_game)(char *); 223 int (*load_resource)(int, int); 224 int (*unload_resource)(int, int); 225 int (*load_objects)(char *); 226 int (*load_words)(char *); 227 }; 228 229 230 extern struct agi_game game; 231 232 int agi_init (void); 233 int agi_deinit (void); 234 int agi_version (void); 235 int agi_get_release (void); 236 void agi_set_release (int); 237 int agi_detect_game (char *); 238 int agi_load_resource (int, int); 239 int agi_unload_resource (int, int); 240 241 /* words */ 242 int show_words (void); 243 int load_words (char *); 244 void unload_words (void); 245 int find_word (char *); 246 void dictionary_words(char *); 247 248 /* objects */ 249 int show_objects (void); 250 int load_objects (char *fname); 251 void unload_objects (void); 252 char* object_name (unsigned int); 253 int object_get_location (unsigned int); 254 void object_set_location (unsigned int, int); 255 256 void new_input_mode (int); 257 void old_input_mode (void); 258 259 int run_logic (int); 260 261 #ifdef __cplusplus 262 }; 263 #endif 264 265 #endif /* __AGI_H */ 266 267