1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GLK_ZCODE_CONFIG
24 #define GLK_ZCODE_CONFIG
25 
26 #include "glk/zcode/frotz_types.h"
27 
28 namespace Glk {
29 namespace ZCode {
30 
31 /**
32  * Configuration flags
33  */
34 enum ConfigFlag {
35 	CONFIG_BYTE_SWAPPED = 0x01, ///< Story file is byte swapped         - V3
36 	CONFIG_TIME         = 0x02, ///< Status line displays time          - V3
37 	CONFIG_TWODISKS     = 0x04, ///< Story file occupied two disks      - V3
38 	CONFIG_TANDY        = 0x08, ///< Tandy licensed game                - V3
39 	CONFIG_NOSTATUSLINE = 0x10, ///< Interpr can't support status lines - V3
40 	CONFIG_SPLITSCREEN  = 0x20, ///< Interpr supports split screen mode - V3
41 	CONFIG_PROPORTIONAL = 0x40, ///< Interpr uses proportional font     - V3
42 
43 	CONFIG_COLOUR       = 0x01, ///< Interpr supports colour            - V5+
44 	CONFIG_PICTURES	    = 0x02, ///< Interpr supports pictures	        - V6
45 	CONFIG_BOLDFACE     = 0x04, ///< Interpr supports boldface style    - V4+
46 	CONFIG_EMPHASIS     = 0x08, ///< Interpr supports emphasis style    - V4+
47 	CONFIG_FIXED        = 0x10, ///< Interpr supports fixed width style - V4+
48 	CONFIG_SOUND	    = 0x20, ///< Interpr supports sound             - V6
49 	CONFIG_TIMEDINPUT   = 0x80, ///< Interpr supports timed input       - V4+
50 
51 	SCRIPTING_FLAG	  = 0x0001, ///< Outputting to transscription file  - V1+
52 	FIXED_FONT_FLAG   = 0x0002, ///< Use fixed width font               - V3+
53 	REFRESH_FLAG 	  = 0x0004, ///< Refresh the screen                 - V6
54 	GRAPHICS_FLAG	  = 0x0008, ///< Game wants to use graphics         - V5+
55 	OLD_SOUND_FLAG	  = 0x0010, ///< Game wants to use sound effects    - V3
56 	UNDO_FLAG	  = 0x0010, ///< Game wants to use UNDO feature     - V5+
57 	MOUSE_FLAG	  = 0x0020, ///< Game wants to use a mouse          - V5+
58 	COLOUR_FLAG	  = 0x0040, ///< Game wants to use colours          - V5+
59 	SOUND_FLAG	  = 0x0080, ///< Game wants to use sound effects    - V5+
60 	MENU_FLAG	  = 0x0100  ///< Game wants to use menus            - V6
61 };
62 
63 /**
64  * There are four error reporting modes: never report errors;
65  * report only the first time a given error type occurs;
66  * report every time an error occurs;
67  * or treat all errors as fatal errors, killing the interpreter.
68  * I strongly recommend "report once" as the default. But you can compile in a
69  * different default by changing the definition of ERR_DEFAULT_REPORT_MODE.
70  */
71 enum ErrorReport {
72 	ERR_REPORT_NEVER  = 0,
73 	ERR_REPORT_ONCE   = 1,
74 	ERR_REPORT_ALWAYS = 2,
75 	ERR_REPORT_FATAL  = 3,
76 
77 	ERR_DEFAULT_REPORT_MODE = ERR_REPORT_NEVER
78 };
79 
80 /**
81  * Enumeration of the game header byte indexes
82  */
83 enum HeaderByte {
84 	H_VERSION             = 0,
85 	H_CONFIG              = 1,
86 	H_RELEASE             = 2,
87 	H_RESIDENT_SIZE       = 4,
88 	H_START_PC            = 6,
89 	H_DICTIONARY          = 8,
90 	H_OBJECTS             = 10,
91 	H_GLOBALS             = 12,
92 	H_DYNAMIC_SIZE        = 14,
93 	H_FLAGS               = 16,
94 	H_SERIAL              = 18,
95 	H_ABBREVIATIONS       = 24,
96 	H_FILE_SIZE           = 26,
97 	H_CHECKSUM            = 28,
98 	H_INTERPRETER_NUMBER  = 30,
99 	H_INTERPRETER_VERSION = 31,
100 	H_SCREEN_ROWS         = 32,
101 	H_SCREEN_COLS         = 33,
102 	H_SCREEN_WIDTH        = 34,
103 	H_SCREEN_HEIGHT       = 36,
104 	H_FONT_HEIGHT         = 38,		///< this is the font width in V5
105 	H_FONT_WIDTH          = 39,		///< this is the font height in V5
106 	H_FUNCTIONS_OFFSET    = 40,
107 	H_STRINGS_OFFSET      = 42,
108 	H_DEFAULT_BACKGROUND  = 44,
109 	H_DEFAULT_FOREGROUND  = 45,
110 	H_TERMINATING_KEYS    = 46,
111 	H_LINE_WIDTH          = 48,
112 	H_STANDARD_HIGH       = 50,
113 	H_STANDARD_LOW        = 51,
114 	H_ALPHABET            = 52,
115 	H_EXTENSION_TABLE     = 54,
116 	H_USER_NAME           = 56
117 };
118 
119 /**
120  * Header extension fields
121  */
122 enum {
123 	HX_TABLE_SIZE    = 0,
124 	HX_MOUSE_X       = 1,
125 	HX_MOUSE_Y       = 2,
126 	HX_UNICODE_TABLE = 3,
127 	HX_FLAGS         = 4,
128 	HX_FORE_COLOUR   = 5,
129 	HX_BACK_COLOUR   = 6
130 };
131 
132 /**
133  * User options
134  */
135 struct UserOptions {
136 	bool _attribute_assignment;
137 	bool _attribute_testing;
138 	bool _object_locating;
139 	bool _object_movement;
140 	bool _expand_abbreviations;
141 	bool _ignore_errors;
142 	bool _piracy;
143 	bool _quetzal;
144 	bool _sound;
145 	bool _tandyBit;
146 	int _left_margin;
147 	int _right_margin;
148 	int _undo_slots;
149 	int _script_cols;
150 	int _err_report_mode;
151 	uint _defaultForeground;
152 	uint _defaultBackground;
153 	bool _color_enabled;
154 
155 	/**
156 	 * Constructor
157 	 */
158 	UserOptions();
159 
160 	/**
161 	 * Initializes the options
162 	 */
163 	void initialize(uint hVersion, uint storyId);
164 
165 	/**
166 	 * Returns true if the game being played is one of the original Infocom releases
167 	 */
168 	bool isInfocom() const;
169 };
170 
171 /**
172  * Story file header data
173  */
174 struct Header {
175 private:
176 	struct StoryEntry {
177 		Story _storyId;
178 		zword _release;
179 		char _serial[7];
180 	};
181 	static const StoryEntry RECORDS[26];
182 public:
183 	zbyte h_version;
184 	zbyte h_config;
185 	zword h_release;
186 	zword h_resident_size;
187 	zword h_start_pc;
188 	zword h_dictionary;
189 	zword h_objects;
190 	zword h_globals;
191 	zword h_dynamic_size;
192 	zword h_flags;
193 	zbyte h_serial[6];
194 	zword h_abbreviations;
195 	zword h_file_size;
196 	zword h_checksum;
197 	zbyte h_interpreter_number;
198 	zbyte h_interpreter_version;
199 	zbyte h_screen_rows;
200 	zbyte h_screen_cols;
201 	zword h_screen_width;
202 	zword h_screen_height;
203 	zbyte h_font_height;
204 	zbyte h_font_width;
205 	zword h_functions_offset;
206 	zword h_strings_offset;
207 	zbyte h_default_background;
208 	zbyte h_default_foreground;
209 	zword h_terminating_keys;
210 	zword h_line_width;
211 	zbyte h_standard_high;
212 	zbyte h_standard_low;
213 	zword h_alphabet;
214 	zword h_extension_table;
215 	zbyte h_user_name[8];
216 
217 	zword hx_table_size;
218 	zword hx_mouse_x;
219 	zword hx_mouse_y;
220 	zword hx_unicode_table;
221 	zword hx_flags;
222 	zword hx_fore_colour;
223 	zword hx_back_colour;
224 
225 	Story _storyId;
226 
227 	/**
228 	 * Constructor
229 	 */
230 	Header();
231 
232 	/**
233 	 * Load the header
234 	 */
235 	void loadHeader(Common::SeekableReadStream &f);
236 };
237 
238 } // End of namespace ZCode
239 } // End of namespace Glk
240 
241 #endif
242