ScummVM API documentation
pack.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  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MADS_CORE_PACK_H
23 #define MADS_CORE_PACK_H
24 
25 #include "common/stream.h"
26 #include "mads/madsv2/core/general.h"
27 
28 namespace MADS {
29 namespace MADSV2 {
30 
31 #define PACK_ID_STRING "MADSPACK 2.0\032"
32 #define PACK_ID_LENGTH 14
33 #define PACK_ID_CHECK 12
34 
35 #define PACK_IMPLODE 0 /* Currently imploding */
36 #define PACK_EXPLODE 1 /* Currently exploding */
37 #define PACK_RAW_COPY 2 /* Currently copying */
38 
39 #define FROM_MEMORY 0 /* Read memory */
40 #define FROM_DISK 1 /* Read disk */
41 #define TO_MEMORY 0 /* Write memory */
42 #define TO_DISK 1 /* Write disk */
43 #define TO_EMS 2 /* Write EMS */
44 
45 #define PACK_NONE 0 /* No compression */
46 #define PACK_PFAB 1 /* Dave's Stuff */
47 #define PACK_ZIP 2 /* Zipped */
48 
49 #define PACK_IMPLODE_SIZE 35256 /* pkzip implode buffer */
50 #define PACK_EXPLODE_SIZE 12574 /* pkzip explode buffer */
51 
52 #define PACK_PFABCOMP_SIZE 0x71be
53 #define PACK_PFABEXP0_SIZE 0x382c
54 #define PACK_PFABEXP1_SIZE 0x0820
55 #define PACK_PFABEXP2_SIZE 0x0004
56 /*
57 #define PACK_PFABCOMP_SIZE 0xd1d0
58 #define PACK_PFABEXP0_SIZE 0x382e
59 #define PACK_PFABEXP1_SIZE 0x0822
60 #define PACK_PFABEXP2_SIZE 0x0004
61 */
62 
63 #define PACK_RAW_COPY_SIZE 0x1000
64 
65 #define PACK_WINDOW_SIZE 4096 /* sliding window size */
66 #define PACK_MIN_WINDOW_SIZE 1024 /* minimum possible size */
67 
68 #define PACK_MAX_PACKET_SIZE 0xfc00 /* Max size of a packet */
69 
70 #define PACK_MAX_LIST_LENGTH 16 /* Max # blocks in one file */
71 
72 
73 #define PACK_PRIORITY_SPRITE_SERIES 4
74 #define PACK_PRIORITY_ANIMATIONS 5
75 
76 #define PACK_PRIORITY_FONTS 7
77 #define PACK_PRIORITY_ROOM_DATA 8
78 #define PACK_PRIORITY_ROOM_HOTSPOTS 9
79 #define PACK_PRIORITY_INTERFACES 10
80 #define PACK_PRIORITY_ROOM_ART 11
81 
82 #define PACK_OVERHEAD PackList::SIZE
83 
84 struct PackStrategy {
85  byte type;
86  byte priority;
87  long size;
88  long compressed_size;
89 
90  void load(Common::SeekableReadStream *src);
91  static constexpr int SIZE = 1 + 1 + 4 + 4;
92 };
93 
95 
96 #define PACK_HEADER (PACK_ID_LENGTH + 2)
97 
98 struct PackList {
99  char id_string[PACK_ID_LENGTH];
100  word num_records;
101  PackStrategy strategy[PACK_MAX_LIST_LENGTH];
102 
103  bool load(Common::SeekableReadStream *src);
104  static constexpr int SIZE = PACK_HEADER + PackStrategy::SIZE * PACK_MAX_LIST_LENGTH;
105 };
106 
107 typedef PackList *PackListPtr;
108 
109 
110 extern byte *pack_read_memory_ptr; /* Current read memory location */
111 extern byte *pack_write_memory_ptr; /* Current write memory location */
112 
113 extern Common::SeekableReadStream *pack_read_file_handle; /* Current read file handle */
114 extern Common::WriteStream *pack_write_file_handle; /* Current write file handle */
115 
116 extern long pack_read_size; /* Size left to read */
117 extern long pack_read_count; /* Size read so */
118 extern long pack_write_size; /* Size left to write */
119 extern long pack_write_count; /* Size written so */
120 
121 /* Pointer to read routine */
122 extern word(*pack_read_routine)(char *buffer, word *size);
123 /* Pointer to write routine */
124 extern word(*pack_write_routine)(char *buffer, word *size);
125 
126 extern word pack_mode; /* Packing mode (zip/none) */
127 extern byte *pack_buffer; /* Packing scrap buffer */
128 extern word pack_buffer_size; /* Size of packing buffer */
129 
130 extern int pack_default; /* Default packing mode */
131 
132 extern byte pack_zip_enabled; /* ZIP packing enabled */
133 extern byte pack_pfab_enabled; /* PFAB packing enabled */
134 extern int pack_strategy; /* Current packing strategy */
135 
136 extern int pack_ems_page_handle;
137 extern int pack_ems_page_marker;
138 extern int pack_ems_page_offset;
139 
140 /* All compression routines called through function pointers, so that */
141 /* we can determine at compile time which compression modules will be */
142 /* linked. */
143 
144 extern word (*pack_implode_routine)(
145  word (*read_buff)(char *buffer, word *size),
146  word (*write_buff)(char *buffer, word *size),
147  char *work_buff,
148  word *type,
149  word *dsize);
150 
151 extern word (*pack_explode_routine)(
152  word (*read_buff)(char *buffer, word *size),
153  word (*write_buff)(char *buffer, word *size),
154  char *work_buff);
155 
156 extern word (*pack_pFABcomp_routine)(
157  word (*read_buff)(char *buffer, word *size),
158  word (*write_buff)(char *buffer, word *size),
159  char *work_buff,
160  word *type,
161  word *dsize);
162 
163 extern word (*pack_pFABexp0_routine)(
164  word (*read_buff)(char *buffer, word *size),
165  word (*write_buff)(char *buffer, word *size),
166  char *work_buff);
167 
168 extern word (*pack_pFABexp1_routine)(
169  word (*read_buff)(char *buffer, word *size),
170  char *write_buf,
171  char *work_buff);
172 
173 extern word (*pack_pFABexp2_routine)(
174  byte *read_buf,
175  byte *write_buf,
176  char *work_buff);
177 
178 
179 extern byte *pack_special_buffer;
180 extern void (*pack_special_function)();
181 
182 
183 extern word pack_read_memory(char *buffer, word *size);
184 extern word pack_write_memory(char *buffer, word *size);
185 extern word pack_read_file(char *buffer, word *size);
186 extern word pack_write_file(char *buffer, word *size);
187 /*
188  * pack_a_packet()
189  * Given that our packing parameters are set up (i.e.
190  * pack_read_size, pack_write_size, and so forth), this
191  * routine uses the specified packing strategy to move
192  * a record.
193  *
194  * @param packing_flag
195  * @param explode_mode
196  * @return
197  */
198 extern word pack_a_packet(int packing_flag, int explode_mode);
199 /*
200  * pack_data()
201  * Transfers a data packet from the specified source to the specified
202  * destination, using the specified packing strategy.
203  * packing_flag Specifies the packing strategy:
204  * PACK_IMPLODE (Compresses data)
205  * PACK_EXPLODE (Decompresses data)
206  * PACK_RAW_COPY (Copies data)
207  * size # of bytes to move
208  * source_type Specifies the source type:
209  * FROM_DISK or FROM_MEMORY.
210  * source If FROM_DISK, then this is a FILE *handle.
211  * If FROM_MEMORY, this is a far memory pointer.
212  * dest_type Specifies the destination type:
213  * TO_DISK, TO_MEMORY, or TO_EMS.
214  * dest Same as "source" but for destination. For
215  * TO_EMS, "dest" is a far pointer to an
216  * EmsPtr structure.
217  * Example:
218  * result =pack_data (PACK_EXPLODE, 132000,
219  * FROM_DISK, file_handle,
220  * TO_MEMORY, memory_pointer);
221  * (Decompresses 132000 bytes from the already open
222  * disk file "file_handle", and writes it to memory
223  * far the specified address. Size is always the
224  * uncompressed size of the data. Result will be
225  * the # of bytes actually written -- 132000 if successful).
226  *
227  * @param packing_flag
228  * @param size
229  * @param source_type
230  * @param source
231  * @param dest_type
232  * @param dest
233  * @return
234  */
235 extern long pack_data(int packing_flag, long size, int source_type, void *source,
236  int dest_type, void *dest);
237 extern void pack_set_special_buffer(byte *buffer_address,
238  void (*(special_function))());
239 /*
240  * pack_check()
241  * Asks user to choose between compressed and uncompressed data
242  * formats.
243  *
244  * @return
245  */
246 extern int pack_check(void);
247 extern void pack_enable_zip(void);
248 extern void pack_enable_pfab(void);
249 extern void pack_enable_pfab_explode(void);
250 extern void pack_enable_zip_explode(void);
251 extern long pack_rle(byte *target, byte *source, word source_size);
252 extern word pack_write_ems(char *buffer, word *mysize);
253 
254 } // namespace MADSV2
255 } // namespace MADS
256 
257 #endif
Definition: stream.h:77
Definition: pack.h:98
Definition: stream.h:745
Definition: pack.h:84
Definition: sound_manager.h:38