ScummVM API documentation
header.h
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  * Additional copyright for this file:
8  * Copyright (C) 1994-1998 Revolution Software Ltd.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef SWORD2_HEADER_H
25 #define SWORD2_HEADER_H
26 
27 #include "common/endian.h"
28 
29 namespace Sword2 {
30 
31 //----------------------------------------------------------
32 // SYSTEM FILE & FRAME HEADERS
33 //----------------------------------------------------------
34 
35 //----------------------------------------------------------
36 // ALL FILES
37 //----------------------------------------------------------
38 
39 // Standard File Header
40 
41 #define NAME_LEN 34
42 
43 struct ResHeader {
44  uint8 fileType; // Byte to define file type (see below)
45  uint8 compType; // Type of file compression used ie.
46  // on whole file (see below)
47  uint32 compSize; // Length of compressed file (ie.
48  // length on disk)
49  uint32 decompSize; // Length of decompressed file held in
50  // memory (NB. frames still held
51  // compressed)
52  byte name[NAME_LEN]; // Name of object
53 
54  static int size() {
55  return 44;
56  }
57 
58  void read(const byte *addr);
59  void write(byte *addr);
60 };
61 
62 // fileType
63 
64 enum {
65  // 0 something's wrong!
66  ANIMATION_FILE = 1, // All normal animations & sprites
67  // including mega-sets & font files
68  // which are the same format (but all
69  // frames always uncompressed)
70  SCREEN_FILE = 2, // Each contains background, palette,
71  // layer sprites, parallax layers &
72  // shading mask
73  GAME_OBJECT = 3, // Each contains object hub +
74  // structures + script data
75  WALK_GRID_FILE = 4, // Walk-grid data
76  GLOBAL_VAR_FILE = 5, // All the global script variables in
77  // one file; "there can be only one"
78  PARALLAX_FILE_null = 6, // NOT USED
79  RUN_LIST = 7, // Each contains a list of object
80  // resource id's
81  TEXT_FILE = 8, // Each contains all the lines of text
82  // for a location or a character's
83  // conversation script
84  SCREEN_MANAGER = 9, // One for each location; this contains
85  // special startup scripts
86  MOUSE_FILE = 10, // Mouse pointers and luggage icons
87  // (sprites in General / Mouse pointers
88  // & Luggage icons)
89  WAV_FILE = 11, // WAV file
90  ICON_FILE = 12, // Menu icon (sprites in General / Menu
91  // icons)
92  PALETTE_FILE = 13 // separate palette file (see also
93  // _paletteHeader)
94 };
95 
96 // compType
97 
98 enum {
99  NO_COMPRESSION = 0,
100  FILE_COMPRESSION = 1 // standard whole-file compression
101  // (not yet devised!)
102 };
103 
104 //----------------------------------------------------------
105 // (1) ANIMATION FILES
106 //----------------------------------------------------------
107 
108 // an animation file consists of:
109 //
110 // standard file header
111 // animation header
112 // a string of CDT entries (one per frame of the anim)
113 // a 16-byte color table ONLY if (runTimeComp==RLE16)
114 // a string of groups of (frame header + frame data)
115 
116 // Animation Header
117 
118 struct AnimHeader {
119  uint8 runTimeComp; // Type of runtime compression used for the
120  // frame data (see below)
121  uint16 noAnimFrames; // Number of frames in the anim (ie. no. of
122  // CDT entries)
123  uint16 feetStartX; // Start coords for mega to walk to, before
124  uint16 feetStartY; // running anim
125  uint8 feetStartDir; // Direction to start in before running anim
126  uint16 feetEndX; // End coords for mega to stand at after
127  uint16 feetEndY; // running anim (vital if anim starts from an
128  // off-screen position, or ends in a different
129  // place from the start)
130  uint8 feetEndDir; // Direction to start in after running anim
131  uint16 blend;
132 
133  static int size() {
134  return 15;
135  }
136 
137  void read(const byte *addr);
138  void write(byte *addr);
139 
140 };
141 
142 // runtimeComp - compression used on each frame of the anim
143 
144 enum {
145  NONE = 0, // No frame compression
146  RLE256 = 1, // James's RLE for 256-color sprites
147  RLE16 = 2 // James's RLE for 16- or 17-color sprites
148  // (raw blocks have max 16 colors for 2 pixels
149  // per byte, so '0's are encoded only as FLAT
150  // for 17-color sprites eg. George's mega-set)
151 };
152 
153 // CDT Entry
154 
155 struct CdtEntry {
156  int16 x; // sprite x-coord OR offset to add to mega's
157  // feet x-coord to calc sprite y-coord
158  int16 y; // sprite y-coord OR offset to add to mega's
159  // feet y-coord to calc sprite y-coord
160  uint32 frameOffset; // points to start of frame header (from start
161  // of file header)
162  uint8 frameType; // 0 = print sprite normally with top-left
163  // corner at (x,y), otherwise see below...
164 
165  static int size();
166 
167  void read(const byte *addr);
168  void write(byte *addr);
169 };
170 
171 // 'frameType' bit values
172 
173 enum {
174  FRAME_OFFSET = 1, // Print at (feetX + x, feetY + y), with
175  // scaling according to feetY
176  FRAME_FLIPPED = 2, // Print the frame flipped Left->Right
177  FRAME_256_FAST = 4 // Frame has been compressed using Pauls fast
178  // RLE 256 compression.
179 };
180 
181 // Frame Header
182 
183 struct FrameHeader {
184  uint32 compSize; // Compressed size of frame - NB. compression
185  // type is now in Anim Header
186  uint16 width; // Dimensions of frame
187  uint16 height;
188 
189  static int size() {
190  return 8;
191  }
192 
193  void read(const byte *addr);
194  void write(byte *addr);
195 };
196 
197 //----------------------------------------------------------
198 // (2) SCREEN FILES
199 //----------------------------------------------------------
200 // a screen file consists of:
201 //
202 // standard file header
203 // multi screen header
204 // 4 * 256 bytes of palette data
205 // 256k palette match table
206 // 2 background parallax layers
207 // 1 background layer with screen header
208 // 2 foreground parallax layers
209 // a string of layer headers
210 // a string of layer masks
211 
212 // Multi screen header
213 // Goes at the beginning of a screen file after the standard header.
214 // Gives offsets from start of table of each of the components
215 
217  uint32 palette;
218  uint32 bg_parallax[2];
219  uint32 screen;
220  uint32 fg_parallax[2];
221  uint32 layers;
222  uint32 paletteTable;
223  uint32 maskOffset;
224 
225  static int size() {
226  return 36;
227  }
228 
229  void read(const byte *addr);
230  void write(byte *addr);
231 };
232 
233 // Screen Header
234 
235 struct ScreenHeader {
236  uint16 width; // dimensions of the background screen
237  uint16 height;
238  uint16 noLayers; // number of layer areas
239 
240  static int size() {
241  return 6;
242  }
243 
244  void read(const byte *addr);
245  void write(byte *addr);
246 };
247 
248 // Layer Header
249 
250 // Note that all the layer headers are kept together, rather than being placed
251 // before each layer mask, in order to simplify the sort routine.
252 
253 struct LayerHeader {
254  uint16 x; // coordinates of top-left pixel of area
255  uint16 y;
256  uint16 width;
257  uint16 height;
258  uint32 maskSize;
259  uint32 offset; // where to find mask data (from start of
260  // standard file header)
261 
262  static int size() {
263  return 16;
264  }
265 
266  void read(const byte *addr);
267  void write(byte *addr);
268 };
269 
270 //----------------------------------------------------------
271 // (3) SCRIPT OBJECT FILES
272 //----------------------------------------------------------
273 // a script object file consists of:
274 //
275 // standard file header
276 // script object header
277 // script object data
278 
279 //----------------------------------------------------------
280 // (5) PALETTE FILES
281 //----------------------------------------------------------
282 // a palette file consists of:
283 //
284 // standard file header
285 // 4 * 256 bytes of palette data
286 // 256k palette match table
287 
288 // an object hub - which represents all that remains of the compact concept
289 
290 class ObjectHub {
291  // int32 type; // type of object
292  // uint32 logic_level; // what level?
293  // uint32 logic[3] // NOT USED
294  // uint32 script_id[3] // need this if script
295  // uint32 script_pc[3] // need this also
296 
297 private:
298  byte *_addr;
299 
300 public:
301  ObjectHub() {
302  _addr = nullptr;
303  }
304 
305  static int size() {
306  return 44;
307  }
308 
309  byte *data() {
310  return _addr;
311  }
312 
313  void setAddress(byte *addr) {
314  _addr = addr;
315  }
316 
317  byte *getScriptPcPtr(int level) {
318  return _addr + 32 + 4 * level;
319  }
320 
321  uint32 getLogicLevel() {
322  return READ_LE_UINT32(_addr + 4);
323  }
324  uint32 getScriptId(int level) {
325  return READ_LE_UINT32(_addr + 20 + 4 * level);
326  }
327  uint32 getScriptPc(int level) {
328  return READ_LE_UINT32(_addr + 32 + 4 * level);
329  }
330 
331  void setLogicLevel(uint32 x) {
332  WRITE_LE_UINT32(_addr + 4, x);
333  }
334  void setScriptId(int level, uint32 x) {
335  WRITE_LE_UINT32(_addr + 20 + 4 * level, x);
336  }
337  void setScriptPc(int level, uint32 x) {
338  WRITE_LE_UINT32(_addr + 32 + 4 * level, x);
339  }
340 };
341 
342 // (6) text module header
343 
344 struct TextHeader {
345  uint32 noOfLines; // how many lines of text are there in this
346  // module
347 
348  static int size() {
349  return 4;
350  }
351 
352  void read(const byte *addr);
353  void write(byte *addr);
354 };
355 
356 // a text file has:
357 //
358 // ResHeader
359 // TextHeader
360 // look up table, to
361 // line of text,0
362 // line of text,0
363 
364 //----------------------------------------------------------
365 // SCREENS.CLU file
366 //----------------------------------------------------------
367 // This file is present in PSX version of the game only.
368 // It keeps parallax and background images, aligned at 1024 bytes
369 // for faster access by the psx cd drive.
370 //
371 // SCREENS.CLU structure:
372 // In first 2048 Bytes there's an offset table. Each entry is an
373 // 32bit offset for a background/parallax group. If entry is 0, screen
374 // does not exist.
375 // To find matching screen for the location, you must count LOCATION_NO
376 // words and then go to the corresponding offset indicated by last 32bit
377 // word.
378 // Each screen then begins with a PSXScreensEntry entry:
379 
381  uint16 fgPlxXres; // If these values are 0, subsequent fgPlx* values must be
382  uint16 fgPlxYres; // ignored, as this means foreground parallax is not present.
383  uint32 fgPlxOffset; // This offset is relative, counting from the beginning of Resource Header
384  uint32 fgPlxSize; // Size of parallax, the size is aligned at 1024 bytes.
385  // fgPlxSize/1024 gives number of sector the parallax is divided into.
386  uint16 bgXres;
387  uint16 bgYres;
388  uint32 bgOffset; // relative
389  uint32 bgSize;
390  uint16 bgPlxXres; // same considerations for fg parallaxes apply
391  uint16 bgPlxYres;
392  uint32 bgPlxOffset; // relative
393  uint32 bgPlxSize;
394 
395  static int size() {
396  return 36;
397  }
398 
399  void read(const byte *addr);
400  void write(byte *addr);
401 };
402 
403 // PSXFontEntry is present in font resource file, it is used
404 // to address a single char in the character atlas image.
405 
406 struct PSXFontEntry {
407  uint16 offset;
408  uint16 skipLines;
409  uint16 charWidth;
410  uint16 charHeight;
411 
412  static int size() {
413  return 8;
414  }
415 
416  void read(const byte *addr);
417  void write(byte *addr);
418 };
419 
420 } // End of namespace Sword2
421 
422 #endif
Definition: header.h:235
Definition: header.h:406
Definition: header.h:183
Definition: animation.h:37
Definition: header.h:216
Definition: header.h:380
Definition: header.h:118
Definition: header.h:253
Definition: header.h:43
Definition: header.h:290
Definition: header.h:155
Definition: header.h:344