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_STRING_V1 "MADSPACK 1.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 
44 #define PACK_NONE 0 /* No compression */
45 #define PACK_PFAB 1 /* Dave's Stuff */
46 #define PACK_ZIP 2 /* Zipped */
47 #define PACK_DCL 3 /* PKWARE DCL */
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 size_t 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 size_t 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 /* All compression routines called through function pointers, so that */
137 /* we can determine at compile time which compression modules will be */
138 /* linked. */
139 
140 extern word (*pack_implode_routine)(
141  word (*read_buff)(char *buffer, word *size),
142  word (*write_buff)(char *buffer, word *size),
143  char *work_buff,
144  word *type,
145  word *dsize);
146 
147 extern word (*pack_explode_routine)(
148  word (*read_buff)(char *buffer, word *size),
149  word (*write_buff)(char *buffer, word *size),
150  char *work_buff);
151 
152 extern word (*pack_pFABcomp_routine)(
153  word (*read_buff)(char *buffer, word *size),
154  word (*write_buff)(char *buffer, word *size),
155  char *work_buff,
156  word *type,
157  word *dsize);
158 
159 extern word (*pack_pFABexp0_routine)(
160  word (*read_buff)(char *buffer, word *size),
161  word (*write_buff)(char *buffer, word *size),
162  char *work_buff);
163 
164 extern word (*pack_pFABexp1_routine)(
165  word (*read_buff)(char *buffer, word *size),
166  char *write_buf,
167  char *work_buff);
168 
169 extern word (*pack_pFABexp2_routine)(
170  byte *read_buf,
171  byte *write_buf,
172  char *work_buff);
173 
174 
175 extern byte *pack_special_buffer;
176 extern void (*pack_special_function)();
177 
178 
179 extern word pack_read_memory(char *buffer, word *size);
180 extern word pack_write_memory(char *buffer, word *size);
181 extern word pack_read_file(char *buffer, word *size);
182 extern word pack_write_file(char *buffer, word *size);
183 /*
184  * pack_a_packet()
185  * Given that our packing parameters are set up (i.e.
186  * pack_read_size, pack_write_size, and so forth), this
187  * routine uses the specified packing strategy to move
188  * a record.
189  *
190  * @param packing_flag
191  * @param explode_mode
192  * @return
193  */
194 extern word pack_a_packet(int packing_flag, int explode_mode);
195 /*
196  * pack_data()
197  * Transfers a data packet from the specified source to the specified
198  * destination, using the specified packing strategy.
199  * packing_flag Specifies the packing strategy:
200  * PACK_IMPLODE (Compresses data)
201  * PACK_EXPLODE (Decompresses data)
202  * PACK_RAW_COPY (Copies data)
203  * size # of bytes to move
204  * source_type Specifies the source type:
205  * FROM_DISK or FROM_MEMORY.
206  * source If FROM_DISK, then this is a FILE *handle.
207  * If FROM_MEMORY, this is a far memory pointer.
208  * dest_type Specifies the destination type:
209  * TO_DISK or TO_MEMORY.
210  * dest Same as "source" but for destination.
211  * Example:
212  * result =pack_data (PACK_EXPLODE, 132000,
213  * FROM_DISK, file_handle,
214  * TO_MEMORY, memory_pointer);
215  * (Decompresses 132000 bytes from the already open
216  * disk file "file_handle", and writes it to memory
217  * far the specified address. Size is always the
218  * uncompressed size of the data. Result will be
219  * the # of bytes actually written -- 132000 if successful).
220  *
221  * @param packing_flag
222  * @param size
223  * @param source_type
224  * @param source
225  * @param dest_type
226  * @param dest
227  * @return
228  */
229 extern long pack_data(int packing_flag, long size, int source_type, void *source,
230  int dest_type, void *dest);
231 extern void pack_set_special_buffer(byte *buffer_address,
232  void (*(special_function))());
233 /*
234  * pack_check()
235  * Asks user to choose between compressed and uncompressed data
236  * formats.
237  *
238  * @return
239  */
240 extern int pack_check();
241 extern void pack_enable_zip();
242 extern void pack_enable_pfab();
243 extern void pack_enable_pfab_explode();
244 extern void pack_enable_zip_explode();
245 extern long pack_rle(byte *target, byte *source, word source_size);
246 
247 } // namespace MADS
248 
249 #endif
Definition: stream.h:77
Definition: stream.h:745
Definition: anim_timer.h:27
Definition: pack.h:98
Definition: pack.h:84