chd 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +30 -0
  3. data/chd.gemspec +29 -0
  4. data/ext/chd.c +1008 -0
  5. data/ext/extconf.rb +60 -0
  6. data/lib/chd/cd.rb +272 -0
  7. data/lib/chd/metadata.rb +196 -0
  8. data/lib/chd/version.rb +4 -0
  9. data/lib/chd.rb +21 -0
  10. data/libchdr/CMakeLists.txt +104 -0
  11. data/libchdr/LICENSE.txt +24 -0
  12. data/libchdr/README.md +7 -0
  13. data/libchdr/deps/lzma-19.00/CMakeLists.txt +33 -0
  14. data/libchdr/deps/lzma-19.00/LICENSE +3 -0
  15. data/libchdr/deps/lzma-19.00/include/7zTypes.h +375 -0
  16. data/libchdr/deps/lzma-19.00/include/Alloc.h +51 -0
  17. data/libchdr/deps/lzma-19.00/include/Bra.h +64 -0
  18. data/libchdr/deps/lzma-19.00/include/Compiler.h +33 -0
  19. data/libchdr/deps/lzma-19.00/include/CpuArch.h +336 -0
  20. data/libchdr/deps/lzma-19.00/include/Delta.h +19 -0
  21. data/libchdr/deps/lzma-19.00/include/LzFind.h +121 -0
  22. data/libchdr/deps/lzma-19.00/include/LzHash.h +57 -0
  23. data/libchdr/deps/lzma-19.00/include/Lzma86.h +111 -0
  24. data/libchdr/deps/lzma-19.00/include/LzmaDec.h +234 -0
  25. data/libchdr/deps/lzma-19.00/include/LzmaEnc.h +76 -0
  26. data/libchdr/deps/lzma-19.00/include/LzmaLib.h +131 -0
  27. data/libchdr/deps/lzma-19.00/include/Precomp.h +10 -0
  28. data/libchdr/deps/lzma-19.00/include/Sort.h +18 -0
  29. data/libchdr/deps/lzma-19.00/lzma-history.txt +446 -0
  30. data/libchdr/deps/lzma-19.00/lzma.txt +328 -0
  31. data/libchdr/deps/lzma-19.00/lzma.vcxproj +543 -0
  32. data/libchdr/deps/lzma-19.00/lzma.vcxproj.filters +17 -0
  33. data/libchdr/deps/lzma-19.00/src/Alloc.c +455 -0
  34. data/libchdr/deps/lzma-19.00/src/Bra86.c +82 -0
  35. data/libchdr/deps/lzma-19.00/src/BraIA64.c +53 -0
  36. data/libchdr/deps/lzma-19.00/src/CpuArch.c +218 -0
  37. data/libchdr/deps/lzma-19.00/src/Delta.c +64 -0
  38. data/libchdr/deps/lzma-19.00/src/LzFind.c +1127 -0
  39. data/libchdr/deps/lzma-19.00/src/Lzma86Dec.c +54 -0
  40. data/libchdr/deps/lzma-19.00/src/LzmaDec.c +1185 -0
  41. data/libchdr/deps/lzma-19.00/src/LzmaEnc.c +1330 -0
  42. data/libchdr/deps/lzma-19.00/src/Sort.c +141 -0
  43. data/libchdr/deps/zlib-1.2.11/CMakeLists.txt +29 -0
  44. data/libchdr/deps/zlib-1.2.11/ChangeLog +1515 -0
  45. data/libchdr/deps/zlib-1.2.11/FAQ +368 -0
  46. data/libchdr/deps/zlib-1.2.11/INDEX +68 -0
  47. data/libchdr/deps/zlib-1.2.11/Makefile +5 -0
  48. data/libchdr/deps/zlib-1.2.11/Makefile.in +410 -0
  49. data/libchdr/deps/zlib-1.2.11/README +115 -0
  50. data/libchdr/deps/zlib-1.2.11/adler32.c +186 -0
  51. data/libchdr/deps/zlib-1.2.11/compress.c +86 -0
  52. data/libchdr/deps/zlib-1.2.11/configure +921 -0
  53. data/libchdr/deps/zlib-1.2.11/crc32.c +442 -0
  54. data/libchdr/deps/zlib-1.2.11/crc32.h +441 -0
  55. data/libchdr/deps/zlib-1.2.11/deflate.c +2163 -0
  56. data/libchdr/deps/zlib-1.2.11/deflate.h +349 -0
  57. data/libchdr/deps/zlib-1.2.11/doc/algorithm.txt +209 -0
  58. data/libchdr/deps/zlib-1.2.11/doc/rfc1950.txt +619 -0
  59. data/libchdr/deps/zlib-1.2.11/doc/rfc1951.txt +955 -0
  60. data/libchdr/deps/zlib-1.2.11/doc/rfc1952.txt +675 -0
  61. data/libchdr/deps/zlib-1.2.11/doc/txtvsbin.txt +107 -0
  62. data/libchdr/deps/zlib-1.2.11/gzclose.c +25 -0
  63. data/libchdr/deps/zlib-1.2.11/gzguts.h +218 -0
  64. data/libchdr/deps/zlib-1.2.11/gzlib.c +637 -0
  65. data/libchdr/deps/zlib-1.2.11/gzread.c +654 -0
  66. data/libchdr/deps/zlib-1.2.11/gzwrite.c +665 -0
  67. data/libchdr/deps/zlib-1.2.11/infback.c +640 -0
  68. data/libchdr/deps/zlib-1.2.11/inffast.c +323 -0
  69. data/libchdr/deps/zlib-1.2.11/inffast.h +11 -0
  70. data/libchdr/deps/zlib-1.2.11/inffixed.h +94 -0
  71. data/libchdr/deps/zlib-1.2.11/inflate.c +1561 -0
  72. data/libchdr/deps/zlib-1.2.11/inflate.h +125 -0
  73. data/libchdr/deps/zlib-1.2.11/inftrees.c +304 -0
  74. data/libchdr/deps/zlib-1.2.11/inftrees.h +62 -0
  75. data/libchdr/deps/zlib-1.2.11/make_vms.com +867 -0
  76. data/libchdr/deps/zlib-1.2.11/treebuild.xml +116 -0
  77. data/libchdr/deps/zlib-1.2.11/trees.c +1203 -0
  78. data/libchdr/deps/zlib-1.2.11/trees.h +128 -0
  79. data/libchdr/deps/zlib-1.2.11/uncompr.c +93 -0
  80. data/libchdr/deps/zlib-1.2.11/zconf.h +534 -0
  81. data/libchdr/deps/zlib-1.2.11/zconf.h.cmakein +536 -0
  82. data/libchdr/deps/zlib-1.2.11/zconf.h.in +534 -0
  83. data/libchdr/deps/zlib-1.2.11/zlib.3 +149 -0
  84. data/libchdr/deps/zlib-1.2.11/zlib.3.pdf +0 -0
  85. data/libchdr/deps/zlib-1.2.11/zlib.h +1912 -0
  86. data/libchdr/deps/zlib-1.2.11/zlib.map +94 -0
  87. data/libchdr/deps/zlib-1.2.11/zlib.pc.cmakein +13 -0
  88. data/libchdr/deps/zlib-1.2.11/zlib.pc.in +13 -0
  89. data/libchdr/deps/zlib-1.2.11/zlib2ansi +152 -0
  90. data/libchdr/deps/zlib-1.2.11/zutil.c +325 -0
  91. data/libchdr/deps/zlib-1.2.11/zutil.h +271 -0
  92. data/libchdr/include/dr_libs/dr_flac.h +12280 -0
  93. data/libchdr/include/libchdr/bitstream.h +43 -0
  94. data/libchdr/include/libchdr/cdrom.h +110 -0
  95. data/libchdr/include/libchdr/chd.h +427 -0
  96. data/libchdr/include/libchdr/chdconfig.h +10 -0
  97. data/libchdr/include/libchdr/coretypes.h +60 -0
  98. data/libchdr/include/libchdr/flac.h +50 -0
  99. data/libchdr/include/libchdr/huffman.h +90 -0
  100. data/libchdr/pkg-config.pc.in +10 -0
  101. data/libchdr/src/libchdr_bitstream.c +125 -0
  102. data/libchdr/src/libchdr_cdrom.c +415 -0
  103. data/libchdr/src/libchdr_chd.c +2744 -0
  104. data/libchdr/src/libchdr_flac.c +302 -0
  105. data/libchdr/src/libchdr_huffman.c +545 -0
  106. data/libchdr/src/link.T +5 -0
  107. data/libchdr/tests/CMakeLists.txt +2 -0
  108. data/libchdr/tests/benchmark.c +52 -0
  109. metadata +183 -0
@@ -0,0 +1,218 @@
1
+ /* CpuArch.c -- CPU specific code
2
+ 2018-02-18: Igor Pavlov : Public domain */
3
+
4
+ #include "Precomp.h"
5
+
6
+ #include "CpuArch.h"
7
+
8
+ #ifdef MY_CPU_X86_OR_AMD64
9
+
10
+ #if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__)
11
+ #define USE_ASM
12
+ #endif
13
+
14
+ #if !defined(USE_ASM) && _MSC_VER >= 1500
15
+ #include <intrin.h>
16
+ #endif
17
+
18
+ #if defined(USE_ASM) && !defined(MY_CPU_AMD64)
19
+ static UInt32 CheckFlag(UInt32 flag)
20
+ {
21
+ #ifdef _MSC_VER
22
+ __asm pushfd;
23
+ __asm pop EAX;
24
+ __asm mov EDX, EAX;
25
+ __asm xor EAX, flag;
26
+ __asm push EAX;
27
+ __asm popfd;
28
+ __asm pushfd;
29
+ __asm pop EAX;
30
+ __asm xor EAX, EDX;
31
+ __asm push EDX;
32
+ __asm popfd;
33
+ __asm and flag, EAX;
34
+ #else
35
+ __asm__ __volatile__ (
36
+ "pushf\n\t"
37
+ "pop %%EAX\n\t"
38
+ "movl %%EAX,%%EDX\n\t"
39
+ "xorl %0,%%EAX\n\t"
40
+ "push %%EAX\n\t"
41
+ "popf\n\t"
42
+ "pushf\n\t"
43
+ "pop %%EAX\n\t"
44
+ "xorl %%EDX,%%EAX\n\t"
45
+ "push %%EDX\n\t"
46
+ "popf\n\t"
47
+ "andl %%EAX, %0\n\t":
48
+ "=c" (flag) : "c" (flag) :
49
+ "%eax", "%edx");
50
+ #endif
51
+ return flag;
52
+ }
53
+ #define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;
54
+ #else
55
+ #define CHECK_CPUID_IS_SUPPORTED
56
+ #endif
57
+
58
+ void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
59
+ {
60
+ #ifdef USE_ASM
61
+
62
+ #ifdef _MSC_VER
63
+
64
+ UInt32 a2, b2, c2, d2;
65
+ __asm xor EBX, EBX;
66
+ __asm xor ECX, ECX;
67
+ __asm xor EDX, EDX;
68
+ __asm mov EAX, function;
69
+ __asm cpuid;
70
+ __asm mov a2, EAX;
71
+ __asm mov b2, EBX;
72
+ __asm mov c2, ECX;
73
+ __asm mov d2, EDX;
74
+
75
+ *a = a2;
76
+ *b = b2;
77
+ *c = c2;
78
+ *d = d2;
79
+
80
+ #else
81
+
82
+ __asm__ __volatile__ (
83
+ #if defined(MY_CPU_AMD64) && defined(__PIC__)
84
+ "mov %%rbx, %%rdi;"
85
+ "cpuid;"
86
+ "xchg %%rbx, %%rdi;"
87
+ : "=a" (*a) ,
88
+ "=D" (*b) ,
89
+ #elif defined(MY_CPU_X86) && defined(__PIC__)
90
+ "mov %%ebx, %%edi;"
91
+ "cpuid;"
92
+ "xchgl %%ebx, %%edi;"
93
+ : "=a" (*a) ,
94
+ "=D" (*b) ,
95
+ #else
96
+ "cpuid"
97
+ : "=a" (*a) ,
98
+ "=b" (*b) ,
99
+ #endif
100
+ "=c" (*c) ,
101
+ "=d" (*d)
102
+ : "0" (function)) ;
103
+
104
+ #endif
105
+
106
+ #else
107
+
108
+ int CPUInfo[4];
109
+ __cpuid(CPUInfo, function);
110
+ *a = CPUInfo[0];
111
+ *b = CPUInfo[1];
112
+ *c = CPUInfo[2];
113
+ *d = CPUInfo[3];
114
+
115
+ #endif
116
+ }
117
+
118
+ BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p)
119
+ {
120
+ CHECK_CPUID_IS_SUPPORTED
121
+ MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
122
+ MyCPUID(1, &p->ver, &p->b, &p->c, &p->d);
123
+ return True;
124
+ }
125
+
126
+ static const UInt32 kVendors[][3] =
127
+ {
128
+ { 0x756E6547, 0x49656E69, 0x6C65746E},
129
+ { 0x68747541, 0x69746E65, 0x444D4163},
130
+ { 0x746E6543, 0x48727561, 0x736C7561}
131
+ };
132
+
133
+ int x86cpuid_GetFirm(const Cx86cpuid *p)
134
+ {
135
+ unsigned i;
136
+ for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)
137
+ {
138
+ const UInt32 *v = kVendors[i];
139
+ if (v[0] == p->vendor[0] &&
140
+ v[1] == p->vendor[1] &&
141
+ v[2] == p->vendor[2])
142
+ return (int)i;
143
+ }
144
+ return -1;
145
+ }
146
+
147
+ BoolInt CPU_Is_InOrder()
148
+ {
149
+ Cx86cpuid p;
150
+ int firm;
151
+ UInt32 family, model;
152
+ if (!x86cpuid_CheckAndRead(&p))
153
+ return True;
154
+
155
+ family = x86cpuid_GetFamily(p.ver);
156
+ model = x86cpuid_GetModel(p.ver);
157
+
158
+ firm = x86cpuid_GetFirm(&p);
159
+
160
+ switch (firm)
161
+ {
162
+ case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (
163
+ /* In-Order Atom CPU */
164
+ model == 0x1C /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */
165
+ || model == 0x26 /* 45 nm, Z6xx */
166
+ || model == 0x27 /* 32 nm, Z2460 */
167
+ || model == 0x35 /* 32 nm, Z2760 */
168
+ || model == 0x36 /* 32 nm, N2xxx, D2xxx */
169
+ )));
170
+ case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));
171
+ case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));
172
+ }
173
+ return True;
174
+ }
175
+
176
+ #if !defined(MY_CPU_AMD64) && defined(_WIN32)
177
+ #include <windows.h>
178
+ static BoolInt CPU_Sys_Is_SSE_Supported()
179
+ {
180
+ OSVERSIONINFO vi;
181
+ vi.dwOSVersionInfoSize = sizeof(vi);
182
+ if (!GetVersionEx(&vi))
183
+ return False;
184
+ return (vi.dwMajorVersion >= 5);
185
+ }
186
+ #define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;
187
+ #else
188
+ #define CHECK_SYS_SSE_SUPPORT
189
+ #endif
190
+
191
+ BoolInt CPU_Is_Aes_Supported()
192
+ {
193
+ Cx86cpuid p;
194
+ CHECK_SYS_SSE_SUPPORT
195
+ if (!x86cpuid_CheckAndRead(&p))
196
+ return False;
197
+ return (p.c >> 25) & 1;
198
+ }
199
+
200
+ BoolInt CPU_IsSupported_PageGB()
201
+ {
202
+ Cx86cpuid cpuid;
203
+ if (!x86cpuid_CheckAndRead(&cpuid))
204
+ return False;
205
+ {
206
+ UInt32 d[4] = { 0 };
207
+ MyCPUID(0x80000000, &d[0], &d[1], &d[2], &d[3]);
208
+ if (d[0] < 0x80000001)
209
+ return False;
210
+ }
211
+ {
212
+ UInt32 d[4] = { 0 };
213
+ MyCPUID(0x80000001, &d[0], &d[1], &d[2], &d[3]);
214
+ return (d[3] >> 26) & 1;
215
+ }
216
+ }
217
+
218
+ #endif
@@ -0,0 +1,64 @@
1
+ /* Delta.c -- Delta converter
2
+ 2009-05-26 : Igor Pavlov : Public domain */
3
+
4
+ #include "Precomp.h"
5
+
6
+ #include "Delta.h"
7
+
8
+ void Delta_Init(Byte *state)
9
+ {
10
+ unsigned i;
11
+ for (i = 0; i < DELTA_STATE_SIZE; i++)
12
+ state[i] = 0;
13
+ }
14
+
15
+ static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
16
+ {
17
+ unsigned i;
18
+ for (i = 0; i < size; i++)
19
+ dest[i] = src[i];
20
+ }
21
+
22
+ void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
23
+ {
24
+ Byte buf[DELTA_STATE_SIZE];
25
+ unsigned j = 0;
26
+ MyMemCpy(buf, state, delta);
27
+ {
28
+ SizeT i;
29
+ for (i = 0; i < size;)
30
+ {
31
+ for (j = 0; j < delta && i < size; i++, j++)
32
+ {
33
+ Byte b = data[i];
34
+ data[i] = (Byte)(b - buf[j]);
35
+ buf[j] = b;
36
+ }
37
+ }
38
+ }
39
+ if (j == delta)
40
+ j = 0;
41
+ MyMemCpy(state, buf + j, delta - j);
42
+ MyMemCpy(state + delta - j, buf, j);
43
+ }
44
+
45
+ void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
46
+ {
47
+ Byte buf[DELTA_STATE_SIZE];
48
+ unsigned j = 0;
49
+ MyMemCpy(buf, state, delta);
50
+ {
51
+ SizeT i;
52
+ for (i = 0; i < size;)
53
+ {
54
+ for (j = 0; j < delta && i < size; i++, j++)
55
+ {
56
+ buf[j] = data[i] = (Byte)(buf[j] + data[i]);
57
+ }
58
+ }
59
+ }
60
+ if (j == delta)
61
+ j = 0;
62
+ MyMemCpy(state, buf + j, delta - j);
63
+ MyMemCpy(state + delta - j, buf, j);
64
+ }