/[projet1]/public/pc/tools/osdk/main/Ym2Mym/sources/lzh.h
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Ym2Mym/sources/lzh.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1075 - (show annotations)
Sun Jan 12 20:13:41 2014 UTC (5 years, 11 months ago) by dbug
File MIME type: text/plain
File size: 5334 byte(s)
PictConv 0.016
- New option to skip the conversion if the target file is more recent than the source file (-u)
- New option to enable/disable information about what happens (-v)

Ym2Mym 1.1
- The tool is now able to extract LHA compressed YM files directly, should make the process much easier :)
1 /*-----------------------------------------------------------------------------
2
3 ST-Sound ( YM files player library )
4
5 Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr )
6
7 LZH depacking routine
8 Original LZH code by Haruhiko Okumura (1991) and Kerwin F. Medina (1996)
9
10 I changed to C++ object to remove global vars, so it should be thread safe now.
11
12 -----------------------------------------------------------------------------*/
13
14 /*-----------------------------------------------------------------------------
15
16 This file is part of ST-Sound
17
18 ST-Sound is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
22
23 ST-Sound is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with ST-Sound; if not, write to the Free Software
30 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
32 -----------------------------------------------------------------------------*/
33
34
35 #ifndef LZH_H
36 #define LZH_H
37
38
39 #define BUFSIZE (1024 * 4)
40
41 #if defined(_WIN32) || defined(_WIN64)
42
43 typedef unsigned char lzh_uchar; /* 8 bits or more */
44 typedef unsigned int lzh_uint; /* 16 bits or more */
45 typedef unsigned short lzh_ushort; /* 16 bits or more */
46 typedef unsigned long lzh_ulong; /* 32 bits or more */
47
48 #else
49
50 #ifdef HAVE_INTTYPES_H
51 #include <inttypes.h>
52 #endif
53
54 #ifdef HAVE_STDINT_H
55 #include <stdint.h>
56 #endif
57
58 typedef uint8_t lzh_uchar;
59 typedef uint16_t lzh_ushort;
60 typedef uint_fast32_t lzh_uint;
61 typedef uint_fast32_t lzh_ulong;
62
63 #endif
64
65 #ifndef CHAR_BIT
66 #define CHAR_BIT 8
67 #endif
68
69 #ifndef UCHAR_MAX
70 #define UCHAR_MAX 255
71 #endif
72
73 typedef lzh_ushort BITBUFTYPE;
74
75 #define BITBUFSIZ (CHAR_BIT * sizeof (BITBUFTYPE))
76 #define DICBIT 13 /* 12(-lh4-) or 13(-lh5-) */
77 #define DICSIZ (1U << DICBIT)
78 #define MAXMATCH 256 /* formerly F (not more than UCHAR_MAX + 1) */
79 #define THRESHOLD 3 /* choose optimal value */
80 #define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD) /* alphabet = {0, 1, 2, ..., NC - 1} */
81 #define CBIT 9 /* $\lfloor \log_2 NC \rfloor + 1$ */
82 #define CODE_BIT 16 /* codeword length */
83
84 #define MAX_HASH_VAL (3 * DICSIZ + (DICSIZ / 512 + 1) * UCHAR_MAX)
85
86 #define NP (DICBIT + 1)
87 #define NT (CODE_BIT + 3)
88 #define PBIT 4 /* smallest integer such that (1U << PBIT) > NP */
89 #define TBIT 5 /* smallest integer such that (1U << TBIT) > NT */
90 #if NT > NP
91 #define NPT NT
92 #else
93 #define NPT NP
94 #endif
95
96
97
98 #ifdef _WIN32
99 #define PACKED
100 #pragma pack(push)
101 #pragma pack(1)
102 #else
103 //warning: be sure to the following struct is 1 byte aligned and exactly 22 bytes long. ( FILE header )
104 #define PACKED __attribute__ ((packed)) // (added by Grzegorz T. Stanczyk)
105 #endif // ifdef _WIN32
106
107 typedef struct
108 {
109 lzh_uchar size;
110 lzh_uchar sum;
111 char id[5];
112 lzh_ulong packed;
113 lzh_ulong original;
114 lzh_uchar reserved[5];
115 lzh_uchar level;
116 lzh_uchar name_lenght;
117 } PACKED lzhHeader_t;
118
119
120 #ifdef _WIN32
121 #pragma pack(pop)
122 #endif // ifdef _WIN32
123
124
125 class CLzhDepacker
126 {
127 public:
128
129 bool LzUnpack(const void *pSrc,int srcSize,void *pDst,int dstSize);
130
131 private:
132
133 //----------------------------------------------
134 // New stuff to handle memory IO
135 //----------------------------------------------
136 lzh_uchar * m_pSrc;
137 int m_srcSize;
138 lzh_uchar * m_pDst;
139 int m_dstSize;
140
141 int DataIn(void *pBuffer,int nBytes);
142 int DataOut(void *pOut,int nBytes);
143
144
145
146 //----------------------------------------------
147 // Original Lzhxlib static func
148 //----------------------------------------------
149 void fillbuf (int n);
150 lzh_ushort getbits (int n);
151 void init_getbits (void);
152 int make_table (int nchar, lzh_uchar *bitlen,int tablebits, lzh_ushort *table);
153 void read_pt_len (int nn, int nbit, int i_special);
154 void read_c_len (void);
155 lzh_ushort decode_c(void);
156 lzh_ushort decode_p(void);
157 void huf_decode_start (void);
158 void decode_start (void);
159 void decode (lzh_uint count, lzh_uchar buffer[]);
160
161
162 //----------------------------------------------
163 // Original Lzhxlib static vars
164 //----------------------------------------------
165 int fillbufsize;
166 lzh_uchar buf[BUFSIZE];
167 lzh_uchar outbuf[DICSIZ];
168 lzh_ushort left [2 * NC - 1];
169 lzh_ushort right[2 * NC - 1];
170 BITBUFTYPE bitbuf;
171 lzh_uint subbitbuf;
172 int bitcount;
173 int decode_j; /* remaining bytes to copy */
174 lzh_uchar c_len[NC];
175 lzh_uchar pt_len[NPT];
176 lzh_uint blocksize;
177 lzh_ushort c_table[4096];
178 lzh_ushort pt_table[256];
179 int with_error;
180
181 lzh_uint fillbuf_i; // NOTE: these ones are not initialized at constructor time but inside the fillbuf and decode func.
182 lzh_uint decode_i;
183 };
184
185
186 #endif /* ifndef LZH_H */

  ViewVC Help
Powered by ViewVC 1.1.26