1 /*---------------------------------------------------------------------------* 2 Project: Compress/uncompress library 3 File: CXSecureUncompression.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: CXSecureUncompression.h,v $ 14 Revision 1.6 2007/10/31 12:52:11 takano_makoto 15 Appended the LH and LRC formats. 16 17 Revision 1.5 2007/05/30 04:20:25 takano_makoto 18 Minor fixes. 19 20 Revision 1.4 2007/05/18 10:50:39 yasuh-to 21 Rollback to SYSTEMMENU2_DEV_BRANCH(HEAD) 22 23 Revision 1.1.2.1 2006/12/06 09:55:16 yasuh-to 24 initial commit 25 26 Revision 1.1 2006/12/04 13:34:46 takano_makoto 27 Initial update. 28 29 $NoKeywords: $ 30 *---------------------------------------------------------------------------*/ 31 32 #ifndef __CX_SECURE_UNCOMPRESSION_H__ 33 #define __CX_SECURE_UNCOMPRESSION_H__ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #include <dolphin/types.h> 40 #include <revolution/cx/CXUncompression.h> 41 42 #define CX_ERR_SUCCESS 0 43 #define CX_ERR_UNSUPPORTED -1 44 #define CX_ERR_SRC_SHORTAGE -2 45 #define CX_ERR_SRC_REMAINDER -3 46 #define CX_ERR_DEST_OVERRUN -4 47 #define CX_ERR_ILLEGAL_TABLE -5 48 49 //====================================================================== 50 // Expanding compressed data 51 //====================================================================== 52 53 /*---------------------------------------------------------------------------* 54 Name: CXSecureUncompressAny 55 56 Description: Determines the compression type from the data header and performs the appropriate decompression. 57 58 Since decompression processing is linked for all types of compression, it may be better to execute a separate function for each compression type when only a specific compression format is used. 59 60 61 62 Arguments: srcp Source address 63 srcSize Source data size 64 destp Destination address 65 66 Returns: Returns 0 when conversion succeeds 67 Returns a negative error code if failed. 68 *---------------------------------------------------------------------------*/ 69 s32 CXSecureUncompressAny( const void* srcp, u32 srcSize, void* destp ); 70 71 72 /*---------------------------------------------------------------------------* 73 Name: CXSecureUncompressRL 74 75 Description: 8-bit decompression of run-length compressed data 76 77 - Decompresses run-length compressed data, writing in 8-bit units. 78 - Use 4 byte alignment for the source address. 79 80 - Data header 81 u32 :4 : Reserved 82 compType:4 Compression type( = 3) 83 destSize:24 : Data size after decompression 84 85 - Flag data format 86 u8 length:7 : Decompressed data length - 1 (When not compressed) 87 Decompressed data length - 3 (only compress when the contiguous length is 3 bytes or greater) 88 flag:1 : (0, 1) = (not compressed, compressed) 89 90 Arguments: *srcp Source address 91 srcSize Source data size 92 *destp Destination address 93 94 Returns: Returns 0 when conversion succeeds 95 Returns a negative error code if failed. 96 *---------------------------------------------------------------------------*/ 97 s32 CXSecureUncompressRL( const void *srcp, u32 srcSize, void *destp ); 98 99 100 /*---------------------------------------------------------------------------* 101 Name: CXSecureUncompressLZ 102 103 Description: 8-bit decompression of LZ77 compressed data 104 105 - Expands LZ77 compressed data, and writes it in 8-bit units. 106 - Use 4 byte alignment for the source address. 107 108 - Data header 109 u32 :4 : Reserved 110 compType:4 : Compression type( = 1) 111 destSize:24 : Data size after decompression 112 113 - Flag data format 114 u8 flags : Compression/no compression flag 115 (0, 1) = (not compressed, compressed) 116 - Code data format (Big Endian) 117 u16 length:4 : Decompressed data length - 3 (only compress when the match length is 3 bytes or greater) 118 offset:12 : Match data offset - 1 119 120 Arguments: *srcp Source address 121 srcSize Source data size 122 *destp Destination address 123 124 Returns: Returns 0 when conversion succeeds 125 Returns a negative error code if failed. 126 *---------------------------------------------------------------------------*/ 127 s32 CXSecureUncompressLZ( const void *srcp, u32 srcSize, void *destp ); 128 129 130 /*---------------------------------------------------------------------------* 131 Name: CXSecureUncompressHuffman 132 133 Description: Decompression of Huffman compressed data 134 135 - Decompresses Huffman compressed data, writing in 32 bit units. 136 - Use 4 byte alignment for the source address. 137 - Use 4 byte alignment for the destination address. 138 - The target decompression buffer size must be prepared in 4 byte multiples. 139 140 - Data header 141 u32 bitSize:4 : Bit size of 1 data (Normally 4|8) 142 compType:4 Compression type( = 2) 143 destSize:24 : Data size after decompression 144 145 - Tree table 146 u8 treeSize : tree table size/2 - 1 147 TreeNodeData nodeRoot : Root node 148 149 TreeNodeData nodeLeft : Root left node 150 TreeNodeData nodeRight : Root right node 151 152 TreeNodeData nodeLeftLeft : Left left node 153 TreeNodeData nodeLeftRight : Left right node 154 155 TreeNodeData nodeRightLeft : Right left node 156 TreeNodeData nodeRightRight : Right right node 157 158 . 159 . 160 161 The compressed data itself follows 162 163 - TreeNodeData structure 164 u8 nodeNextOffset:6 : Offset to the next node data - 1 (2 byte units) 165 rightEndFlag:1 : Right node end flag 166 leftEndzflag:1 : Left node end flag 167 When the end flag is set 168 There is data in next node 169 170 Arguments: *srcp Source address 171 srcSize Source data size 172 *destp Destination address 173 174 Returns: Returns 0 when conversion succeeds 175 Returns a negative error code if failed. 176 *---------------------------------------------------------------------------*/ 177 s32 CXSecureUncompressHuffman( const void *srcp, u32 srcSize, void *destp ); 178 179 /*---------------------------------------------------------------------------* 180 Name: CXUncompressLH 181 182 Description: Decompress LZ-Huffman (combined) compression. 183 184 Arguments: *srcp Source address 185 srcSize Source size 186 *destp Destination address 187 *work Working buffer 188 The required size is CX_UNCOMPRESS_LH_WORK_SIZE (2176B) 189 190 Returns: None. 191 *---------------------------------------------------------------------------*/ 192 s32 CXSecureUncompressLH( const u8* srcp, u32 srcSize, u8* dstp, void* work ); 193 194 195 /*---------------------------------------------------------------------------* 196 Name: CXUncompressLRC 197 198 Description: Decompress LZ-RangeCoder (combined) compression. 199 200 Arguments: *srcp Source address 201 srcSize Source size 202 *destp Destination address 203 *work Working buffer 204 The required size is CX_UNCOMPRESS_LRC_WORK_SIZE (36864B) 205 206 Returns: None. 207 *---------------------------------------------------------------------------*/ 208 s32 CXSecureUncompressLRC( const u8* srcp, u32 srcSize, u8* dstp, void* work ); 209 210 211 212 /*---------------------------------------------------------------------------* 213 Name: CXSecureUnfilterDiff 214 215 Description: 8-bit decompression to restore differential filter conversion. 216 217 - Decompresses a differential filter, writing in 8 bit units. 218 - Cannot decode directly into VRAM. 219 - If the compressed data size was not a multiple of four, adjust by padding with 0s as much as possible. 220 221 - Use 4 byte alignment for the source address. 222 223 Arguments: *srcp Source address 224 srcSize Source size 225 *destp Destination address 226 227 Returns: Returns 0 when conversion succeeds 228 Returns a negative error code if failed. 229 *---------------------------------------------------------------------------*/ 230 s32 CXSecureUnfilterDiff( register const void *srcp, u32 srcSize, register void *destp ); 231 232 233 234 //================================================================================ 235 236 237 /*---------------------------------------------------------------------------* 238 Name: CXiUncompressBackward 239 240 Description: Uncompress special archive for module compression. 241 242 Arguments: bottom = Bottom adrs of packed archive + 1 243 bottom[-12] = offset for top of compressed data 244 inp_top = bottom + bottom[-12] 245 bottom[ -8] = offset for bottom of compressed data 246 inp = bottom + bottom[ -8] 247 bottom[ -4] = offset for bottom of original data 248 outp = bottom + bottom[ -4] 249 250 typedef struct 251 { 252 int bufferTop; 253 int compressBottom; 254 int originalBottom; 255 } CompFooter; 256 257 Returns: Error Codes 258 *---------------------------------------------------------------------------*/ 259 // !!!! Coded in libraries/init/ARM9/crt0.c 260 // void CXiUncompressBackward( void *bottom ); 261 262 263 264 265 #ifdef __cplusplus 266 } /* extern "C" */ 267 #endif 268 269 /* __CX_SECURE_UNCOMPRESSION_H__ */ 270 #endif 271