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