1 /*---------------------------------------------------------------------------*
2 Project: compress/uncompress library
3 File: CXUncompression.h
4
5 Copyright 2005 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: CXUncompression.h,v $
14 Revision 1.10 07/14/2006 05:23:56 takano_makoto
15 Add CXUncompressAny()
16 Bug fix in CXGetCompressionType()
17
18 Revision 1.9 07/06/2006 09:19:14 takano_makoto
19 Changed the include guard to the REVOLUTION_SDK format
20
21 Revision 1.8 07/06/2006 05:29:48 takano_makoto
22 Added CXUnfilterDiff
23
24 Revision 1.7 07/06/2006 04:39:50 takano_makoto
25 revised duplicate definitions in CXGetCompressionType, CXGetUncompressedSize
26
27 Revision 1.6 07/06/2006 04:13:04 takano_makoto
28 added CXGetCompressionType, CXGetUncompressedSize
29
30 Revision 1.5 07/05/2006 11:14:43 takano_makoto
31 revised the include guard
32
33 Revision 1.4 07/05/2006 08:13:03 takano_makoto
34 revised comments
35
36 Revision 1.3 07/04/2006 08:38:39 takano_makoto
37 fix copyright header
38
39 $NoKeywords: $
40 *---------------------------------------------------------------------------*/
41
42 #ifndef __CX_UNCOMPRESSION_H__
43 #define __CX_UNCOMPRESSION_H__
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #include <dolphin/types.h>
50
51
52 //---- compression type
53 typedef enum
54 {
55 CX_COMPRESSION_LZ = 0x10, // LZ77
56 CX_COMPRESSION_HUFFMAN = 0x20, // Huffman
57 CX_COMPRESSION_RL = 0x30, // Run Length
58 CX_COMPRESSION_DIFF = 0x80, // Differential filter
59
60 CX_COMPRESSION_TYPE_MASK = 0xF0,
61 CX_COMPRESSION_TYPE_EX_MASK = 0xFF
62 }
63 CXCompressionType;
64
65
66 //----------------------------------------------------------------
67 // Compressed data header
68 //
69 typedef struct
70 {
71 u32 compParam : 4;
72 u32 compType : 4;
73 u32 destSize :24;
74
75 }
76 CXCompressionHeader;
77
78
79 /*---------------------------------------------------------------------------*
80 Name: CXGetCompressionHeader
81
82 Description: Gets header information from the first four bytes in the compression data
83
84 Arguments: data a pointer to the first four bytes of data in the compressed data
85
86 Returns: None.
87 *---------------------------------------------------------------------------*/
88 CXCompressionHeader CXGetCompressionHeader( const void *data );
89
90 /*---------------------------------------------------------------------------*
91 Name: CXGetCompressionType
92
93 Description: Gets compression data from the first one byte in the compressed data
94
95 Arguments: srcp : compressed data address
96
97 Returns: compression type.
98 CX_COMPREESION_LZ : LZ77 compressed data
99 CX_COMPREESION_HUFFMAN : Huffman compressed data
100 CX_COMPREESION_RL : Run-length compressed data
101 CX_COMPRESSION_DIFF : data converted with a differential filter
102 *---------------------------------------------------------------------------*/
CXGetCompressionType(const void * data)103 static inline CXCompressionType CXGetCompressionType( const void *data )
104 {
105 return (CXCompressionType)( *(u8*)data & 0xF0 );
106 }
107
108 //======================================================================
109 // Expanding compressed data
110 //======================================================================
111
112 /*---------------------------------------------------------------------------*
113 Name: CXGetUncompressedSize
114
115 Description: Gets the data size after decompression.
116 This function can be used for data in all compression formats handled by CX.
117
118 Arguments: srcp : a pointer to the first four bytes of data in the compressed data
119
120 Returns: Data size after expansion
121 *---------------------------------------------------------------------------*/
122 u32 CXGetUncompressedSize( const void *srcp );
123
124
125 /*---------------------------------------------------------------------------*
126 Name: CXUncompressAny
127
128 Description: Determines the compression type from the data header and
129 runs the appropriate decompression process.
130 As all the decompression for compression types are linked,
131 it would be good to run this function for each compression type unless
132 a special compression format is used.
133
134 Arguments: srcp source address
135 destp destination address
136
137 Returns: None.
138 *---------------------------------------------------------------------------*/
139 void CXUncompressAny( const void* srcp, void* destp );
140
141
142 /*---------------------------------------------------------------------------*
143 Name: CXUncompressRL
144
145 Description: 8-bit expanding runlength compressed data
146
147 * Expands runlength compressed data, and writes in 8-bit units.
148 - Align source address to a 4-byte boundary.
149
150 * Data header
151 u32 :4 reserved
152 compType:4 compression type ( = 3)
153 destSize:24 Data size after decoding
154
155 * Flag data format
156 u8 length:7 Expansion data length - 1 (When not compressed)
157 Expansion data length - 3 (Only compress when the contiguous length is 3-bytes or greater)
158 flag:1 (0, 1) = (not compressed, compressed)
159
160 Arguments: *srcp source address
161 *destp destination address
162
163 Returns: None.
164 *---------------------------------------------------------------------------*/
165 void CXUncompressRL( const void *srcp, void *destp );
166
167
168 /*---------------------------------------------------------------------------*
169 Name: CXUncompressLZ
170
171 Description: 8-bit expanding LZ77 compressed data
172
173 * Expands LZ77 compressed data, and writes in 8-bit units.
174 - Align source address to a 4-byte boundary.
175
176 * Data header
177 u32 :4 reserved
178 compType:4 compression type ( = 1)
179 destSize:24 Data size after decoding
180
181 * Flag data format
182 u8 flags compression/no compression flag
183 (0, 1) = (not compressed, compressed)
184 * Code data format (Big Endian)
185 u16 length:4 Expansion data length - 3(Only compress when the match length is 3-bytes or greater)
186 offset:12 match data offset - 1
187
188 Arguments: *srcp source address
189 *destp destination address
190
191 Returns: None.
192 *---------------------------------------------------------------------------*/
193 void CXUncompressLZ( const void *srcp, void *destp );
194
195
196 /*---------------------------------------------------------------------------*
197 Name: CXUncompressHuffman
198
199 Description: Expanding Huffman compressed data
200
201 * Expands Huffman compressed data, and writes in 32-bit units.
202 - Align source address to a 4-byte boundary.
203 - Align the destination address to a four byte boundary.
204 - The compression buffer size must be prepared in 4-byte multiples.
205
206 * Data header
207 u32 bitSize:4 1 data bit size (Normally 4|8)
208 compType:4 compression type ( = 2)
209 destSize:24 Data size after decoding
210
211 * Tree table
212 u8 treeSize tree table size/2 - 1
213 TreeNodeData nodeRoot root node
214
215 TreeNodeData nodeLeft root left node
216 TreeNodeData nodeRight root right node
217
218 TreeNodeData nodeLeftLeft left left node
219 TreeNodeData nodeLeftRight left ride node
220
221 TreeNodeData nodeRightLeft right left node
222 TreeNodeData nodeRightRight right right node
223
224 �E
225 �E
226
227 The compress data structure follows
228
229 * TreeNodeData structure
230 u8 nodeNextOffset:6 Offset to the next node data - 1 (2-byte units)
231 rightEndFlag:1 right node end flag
232 leftEndzflag:1 Left node end flag
233 when end flag is set
234 there is data in next node
235
236 Arguments: *srcp source address
237 *destp destination address
238
239 Returns: None.
240 *---------------------------------------------------------------------------*/
241 void CXUncompressHuffman( const void *srcp, void *destp );
242
243
244 /*---------------------------------------------------------------------------*
245 Name: CXUnfilterDiff
246
247 Description: Decode differential filter conversion. Use 8-bit decoding.
248
249 - Decodes a differential filter. Writes in 8-bit units.
250 - Cannot decode directly into VRAM
251 - If the size of compressed data is not a multiple of four,
252 adjust as necessary by padding with 0s.
253 - Align source address to a 4-byte boundary.
254
255 Arguments: *srcp source address
256 *destp destination address
257
258 Returns: None.
259 *---------------------------------------------------------------------------*/
260 void CXUnfilterDiff( register const void *srcp, register void *destp );
261
262
263 //================================================================================
264
265
266 /*---------------------------------------------------------------------------*
267 Name: CXiUncompressBackward
268
269 Description: Uncompress special archive for module compression
270
271 Arguments: bottom = Bottom adrs of packed archive + 1
272 bottom[-12] = offset for top of compressed data
273 inp_top = bottom + bottom[-12]
274 bottom[-8] = offset for bottom of compressed data
275 inp = bottom + bottom[ -8]
276 bottom[ -4] = offset for bottom of original data
277 outp = bottom + bottom[ -4]
278
279 typedef struct
280 {
281 int bufferTop;
282 int compressBottom;
283 int originalBottom;
284 } CompFooter;
285
286 Returns: None.
287 *---------------------------------------------------------------------------*/
288 // !!!! Coded in libraries/init/ARM9/crt0.c
289 // void CXiUncompressBackward( void *bottom );
290
291
292
293
294 #ifdef __cplusplus
295 } /* extern "C"*/
296 #endif
297
298 /* __CX_UNCOMPRESSION_H__*/
299 #endif
300