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,43 @@
1
+ /* license:BSD-3-Clause
2
+ * copyright-holders:Aaron Giles
3
+ ***************************************************************************
4
+
5
+ bitstream.h
6
+
7
+ Helper classes for reading/writing at the bit level.
8
+
9
+ ***************************************************************************/
10
+
11
+ #pragma once
12
+
13
+ #ifndef __BITSTREAM_H__
14
+ #define __BITSTREAM_H__
15
+
16
+ #include <stdint.h>
17
+
18
+ /***************************************************************************
19
+ * TYPE DEFINITIONS
20
+ ***************************************************************************
21
+ */
22
+
23
+ /* helper class for reading from a bit buffer */
24
+ struct bitstream
25
+ {
26
+ uint32_t buffer; /* current bit accumulator */
27
+ int bits; /* number of bits in the accumulator */
28
+ const uint8_t * read; /* read pointer */
29
+ uint32_t doffset; /* byte offset within the data */
30
+ uint32_t dlength; /* length of the data */
31
+ };
32
+
33
+ struct bitstream* create_bitstream(const void *src, uint32_t srclength);
34
+ int bitstream_overflow(struct bitstream* bitstream);
35
+ uint32_t bitstream_read_offset(struct bitstream* bitstream);
36
+
37
+ uint32_t bitstream_read(struct bitstream* bitstream, int numbits);
38
+ uint32_t bitstream_peek(struct bitstream* bitstream, int numbits);
39
+ void bitstream_remove(struct bitstream* bitstream, int numbits);
40
+ uint32_t bitstream_flush(struct bitstream* bitstream);
41
+
42
+
43
+ #endif
@@ -0,0 +1,110 @@
1
+ /* license:BSD-3-Clause
2
+ * copyright-holders:Aaron Giles
3
+ ***************************************************************************
4
+
5
+ cdrom.h
6
+
7
+ Generic MAME cd-rom implementation
8
+
9
+ ***************************************************************************/
10
+
11
+ #pragma once
12
+
13
+ #ifndef __CDROM_H__
14
+ #define __CDROM_H__
15
+
16
+ #include <stdint.h>
17
+ #include <libchdr/chdconfig.h>
18
+
19
+ /***************************************************************************
20
+ CONSTANTS
21
+ ***************************************************************************/
22
+
23
+ /* tracks are padded to a multiple of this many frames */
24
+ #define CD_TRACK_PADDING (4)
25
+ #define CD_MAX_TRACKS (99) /* AFAIK the theoretical limit */
26
+ #define CD_MAX_SECTOR_DATA (2352)
27
+ #define CD_MAX_SUBCODE_DATA (96)
28
+
29
+ #define CD_FRAME_SIZE (CD_MAX_SECTOR_DATA + CD_MAX_SUBCODE_DATA)
30
+ #define CD_FRAMES_PER_HUNK (8)
31
+
32
+ #define CD_METADATA_WORDS (1+(CD_MAX_TRACKS * 6))
33
+
34
+ enum
35
+ {
36
+ CD_TRACK_MODE1 = 0, /* mode 1 2048 bytes/sector */
37
+ CD_TRACK_MODE1_RAW, /* mode 1 2352 bytes/sector */
38
+ CD_TRACK_MODE2, /* mode 2 2336 bytes/sector */
39
+ CD_TRACK_MODE2_FORM1, /* mode 2 2048 bytes/sector */
40
+ CD_TRACK_MODE2_FORM2, /* mode 2 2324 bytes/sector */
41
+ CD_TRACK_MODE2_FORM_MIX, /* mode 2 2336 bytes/sector */
42
+ CD_TRACK_MODE2_RAW, /* mode 2 2352 bytes / sector */
43
+ CD_TRACK_AUDIO, /* redbook audio track 2352 bytes/sector (588 samples) */
44
+
45
+ CD_TRACK_RAW_DONTCARE /* special flag for cdrom_read_data: just return me whatever is there */
46
+ };
47
+
48
+ enum
49
+ {
50
+ CD_SUB_NORMAL = 0, /* "cooked" 96 bytes per sector */
51
+ CD_SUB_RAW, /* raw uninterleaved 96 bytes per sector */
52
+ CD_SUB_NONE /* no subcode data stored */
53
+ };
54
+
55
+ #define CD_FLAG_GDROM 0x00000001 /* disc is a GD-ROM, all tracks should be stored with GD-ROM metadata */
56
+ #define CD_FLAG_GDROMLE 0x00000002 /* legacy GD-ROM, with little-endian CDDA data */
57
+
58
+ /***************************************************************************
59
+ FUNCTION PROTOTYPES
60
+ ***************************************************************************/
61
+
62
+ #ifdef WANT_RAW_DATA_SECTOR
63
+ /* ECC utilities */
64
+ int ecc_verify(const uint8_t *sector);
65
+ void ecc_generate(uint8_t *sector);
66
+ void ecc_clear(uint8_t *sector);
67
+ #endif
68
+
69
+
70
+
71
+ /***************************************************************************
72
+ INLINE FUNCTIONS
73
+ ***************************************************************************/
74
+
75
+ static inline uint32_t msf_to_lba(uint32_t msf)
76
+ {
77
+ return ( ((msf&0x00ff0000)>>16) * 60 * 75) + (((msf&0x0000ff00)>>8) * 75) + ((msf&0x000000ff)>>0);
78
+ }
79
+
80
+ static inline uint32_t lba_to_msf(uint32_t lba)
81
+ {
82
+ uint8_t m, s, f;
83
+
84
+ m = lba / (60 * 75);
85
+ lba -= m * (60 * 75);
86
+ s = lba / 75;
87
+ f = lba % 75;
88
+
89
+ return ((m / 10) << 20) | ((m % 10) << 16) |
90
+ ((s / 10) << 12) | ((s % 10) << 8) |
91
+ ((f / 10) << 4) | ((f % 10) << 0);
92
+ }
93
+
94
+ /**
95
+ * segacd needs it like this.. investigate
96
+ * Angelo also says PCE tracks often start playing at the
97
+ * wrong address.. related?
98
+ **/
99
+ static inline uint32_t lba_to_msf_alt(int lba)
100
+ {
101
+ uint32_t ret = 0;
102
+
103
+ ret |= ((lba / (60 * 75))&0xff)<<16;
104
+ ret |= (((lba / 75) % 60)&0xff)<<8;
105
+ ret |= ((lba % 75)&0xff)<<0;
106
+
107
+ return ret;
108
+ }
109
+
110
+ #endif /* __CDROM_H__ */
@@ -0,0 +1,427 @@
1
+ /***************************************************************************
2
+
3
+ chd.h
4
+
5
+ MAME Compressed Hunks of Data file format
6
+
7
+ ****************************************************************************
8
+
9
+ Copyright Aaron Giles
10
+ All rights reserved.
11
+
12
+ Redistribution and use in source and binary forms, with or without
13
+ modification, are permitted provided that the following conditions are
14
+ met:
15
+
16
+ * Redistributions of source code must retain the above copyright
17
+ notice, this list of conditions and the following disclaimer.
18
+ * Redistributions in binary form must reproduce the above copyright
19
+ notice, this list of conditions and the following disclaimer in
20
+ the documentation and/or other materials provided with the
21
+ distribution.
22
+ * Neither the name 'MAME' nor the names of its contributors may be
23
+ used to endorse or promote products derived from this software
24
+ without specific prior written permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
+ DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
+ POSSIBILITY OF SUCH DAMAGE.
37
+
38
+ ***************************************************************************/
39
+
40
+ #pragma once
41
+
42
+ #ifndef __CHD_H__
43
+ #define __CHD_H__
44
+
45
+ #ifdef __cplusplus
46
+ extern "C" {
47
+ #endif
48
+
49
+ #include <libchdr/coretypes.h>
50
+ #include <libchdr/chdconfig.h>
51
+
52
+ /***************************************************************************
53
+
54
+ Compressed Hunks of Data header format. All numbers are stored in
55
+ Motorola (big-endian) byte ordering. The header is 76 (V1) or 80 (V2)
56
+ bytes long.
57
+
58
+ V1 header:
59
+
60
+ [ 0] char tag[8]; // 'MComprHD'
61
+ [ 8] UINT32 length; // length of header (including tag and length fields)
62
+ [ 12] UINT32 version; // drive format version
63
+ [ 16] UINT32 flags; // flags (see below)
64
+ [ 20] UINT32 compression; // compression type
65
+ [ 24] UINT32 hunksize; // 512-byte sectors per hunk
66
+ [ 28] UINT32 totalhunks; // total # of hunks represented
67
+ [ 32] UINT32 cylinders; // number of cylinders on hard disk
68
+ [ 36] UINT32 heads; // number of heads on hard disk
69
+ [ 40] UINT32 sectors; // number of sectors on hard disk
70
+ [ 44] UINT8 md5[16]; // MD5 checksum of raw data
71
+ [ 60] UINT8 parentmd5[16]; // MD5 checksum of parent file
72
+ [ 76] (V1 header length)
73
+
74
+ V2 header:
75
+
76
+ [ 0] char tag[8]; // 'MComprHD'
77
+ [ 8] UINT32 length; // length of header (including tag and length fields)
78
+ [ 12] UINT32 version; // drive format version
79
+ [ 16] UINT32 flags; // flags (see below)
80
+ [ 20] UINT32 compression; // compression type
81
+ [ 24] UINT32 hunksize; // seclen-byte sectors per hunk
82
+ [ 28] UINT32 totalhunks; // total # of hunks represented
83
+ [ 32] UINT32 cylinders; // number of cylinders on hard disk
84
+ [ 36] UINT32 heads; // number of heads on hard disk
85
+ [ 40] UINT32 sectors; // number of sectors on hard disk
86
+ [ 44] UINT8 md5[16]; // MD5 checksum of raw data
87
+ [ 60] UINT8 parentmd5[16]; // MD5 checksum of parent file
88
+ [ 76] UINT32 seclen; // number of bytes per sector
89
+ [ 80] (V2 header length)
90
+
91
+ V3 header:
92
+
93
+ [ 0] char tag[8]; // 'MComprHD'
94
+ [ 8] UINT32 length; // length of header (including tag and length fields)
95
+ [ 12] UINT32 version; // drive format version
96
+ [ 16] UINT32 flags; // flags (see below)
97
+ [ 20] UINT32 compression; // compression type
98
+ [ 24] UINT32 totalhunks; // total # of hunks represented
99
+ [ 28] UINT64 logicalbytes; // logical size of the data (in bytes)
100
+ [ 36] UINT64 metaoffset; // offset to the first blob of metadata
101
+ [ 44] UINT8 md5[16]; // MD5 checksum of raw data
102
+ [ 60] UINT8 parentmd5[16]; // MD5 checksum of parent file
103
+ [ 76] UINT32 hunkbytes; // number of bytes per hunk
104
+ [ 80] UINT8 sha1[20]; // SHA1 checksum of raw data
105
+ [100] UINT8 parentsha1[20];// SHA1 checksum of parent file
106
+ [120] (V3 header length)
107
+
108
+ V4 header:
109
+
110
+ [ 0] char tag[8]; // 'MComprHD'
111
+ [ 8] UINT32 length; // length of header (including tag and length fields)
112
+ [ 12] UINT32 version; // drive format version
113
+ [ 16] UINT32 flags; // flags (see below)
114
+ [ 20] UINT32 compression; // compression type
115
+ [ 24] UINT32 totalhunks; // total # of hunks represented
116
+ [ 28] UINT64 logicalbytes; // logical size of the data (in bytes)
117
+ [ 36] UINT64 metaoffset; // offset to the first blob of metadata
118
+ [ 44] UINT32 hunkbytes; // number of bytes per hunk
119
+ [ 48] UINT8 sha1[20]; // combined raw+meta SHA1
120
+ [ 68] UINT8 parentsha1[20];// combined raw+meta SHA1 of parent
121
+ [ 88] UINT8 rawsha1[20]; // raw data SHA1
122
+ [108] (V4 header length)
123
+
124
+ Flags:
125
+ 0x00000001 - set if this drive has a parent
126
+ 0x00000002 - set if this drive allows writes
127
+
128
+ =========================================================================
129
+
130
+ V5 header:
131
+
132
+ [ 0] char tag[8]; // 'MComprHD'
133
+ [ 8] uint32_t length; // length of header (including tag and length fields)
134
+ [ 12] uint32_t version; // drive format version
135
+ [ 16] uint32_t compressors[4];// which custom compressors are used?
136
+ [ 32] uint64_t logicalbytes; // logical size of the data (in bytes)
137
+ [ 40] uint64_t mapoffset; // offset to the map
138
+ [ 48] uint64_t metaoffset; // offset to the first blob of metadata
139
+ [ 56] uint32_t hunkbytes; // number of bytes per hunk (512k maximum)
140
+ [ 60] uint32_t unitbytes; // number of bytes per unit within each hunk
141
+ [ 64] uint8_t rawsha1[20]; // raw data SHA1
142
+ [ 84] uint8_t sha1[20]; // combined raw+meta SHA1
143
+ [104] uint8_t parentsha1[20];// combined raw+meta SHA1 of parent
144
+ [124] (V5 header length)
145
+
146
+ If parentsha1 != 0, we have a parent (no need for flags)
147
+ If compressors[0] == 0, we are uncompressed (including maps)
148
+
149
+ V5 uncompressed map format:
150
+
151
+ [ 0] uint32_t offset; // starting offset / hunk size
152
+
153
+ V5 compressed map format header:
154
+
155
+ [ 0] uint32_t length; // length of compressed map
156
+ [ 4] UINT48 datastart; // offset of first block
157
+ [ 10] uint16_t crc; // crc-16 of the map
158
+ [ 12] uint8_t lengthbits; // bits used to encode complength
159
+ [ 13] uint8_t hunkbits; // bits used to encode self-refs
160
+ [ 14] uint8_t parentunitbits; // bits used to encode parent unit refs
161
+ [ 15] uint8_t reserved; // future use
162
+ [ 16] (compressed header length)
163
+
164
+ Each compressed map entry, once expanded, looks like:
165
+
166
+ [ 0] uint8_t compression; // compression type
167
+ [ 1] UINT24 complength; // compressed length
168
+ [ 4] UINT48 offset; // offset
169
+ [ 10] uint16_t crc; // crc-16 of the data
170
+
171
+ ***************************************************************************/
172
+
173
+
174
+ /***************************************************************************
175
+ CONSTANTS
176
+ ***************************************************************************/
177
+
178
+ /* header information */
179
+ #define CHD_HEADER_VERSION 5
180
+ #define CHD_V1_HEADER_SIZE 76
181
+ #define CHD_V2_HEADER_SIZE 80
182
+ #define CHD_V3_HEADER_SIZE 120
183
+ #define CHD_V4_HEADER_SIZE 108
184
+ #define CHD_V5_HEADER_SIZE 124
185
+
186
+ #define CHD_MAX_HEADER_SIZE CHD_V5_HEADER_SIZE
187
+
188
+ /* checksumming information */
189
+ #define CHD_MD5_BYTES 16
190
+ #define CHD_SHA1_BYTES 20
191
+
192
+ /* CHD global flags */
193
+ #define CHDFLAGS_HAS_PARENT 0x00000001
194
+ #define CHDFLAGS_IS_WRITEABLE 0x00000002
195
+ #define CHDFLAGS_UNDEFINED 0xfffffffc
196
+
197
+ #define CHD_MAKE_TAG(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
198
+
199
+ /* compression types */
200
+ #define CHDCOMPRESSION_NONE 0
201
+ #define CHDCOMPRESSION_ZLIB 1
202
+ #define CHDCOMPRESSION_ZLIB_PLUS 2
203
+ #define CHDCOMPRESSION_AV 3
204
+
205
+ #define CHD_CODEC_NONE 0
206
+ #define CHD_CODEC_ZLIB CHD_MAKE_TAG('z','l','i','b')
207
+ /* general codecs with CD frontend */
208
+ #define CHD_CODEC_CD_ZLIB CHD_MAKE_TAG('c','d','z','l')
209
+ #define CHD_CODEC_CD_LZMA CHD_MAKE_TAG('c','d','l','z')
210
+ #define CHD_CODEC_CD_FLAC CHD_MAKE_TAG('c','d','f','l')
211
+
212
+ /* A/V codec configuration parameters */
213
+ #define AV_CODEC_COMPRESS_CONFIG 1
214
+ #define AV_CODEC_DECOMPRESS_CONFIG 2
215
+
216
+ /* metadata parameters */
217
+ #define CHDMETATAG_WILDCARD 0
218
+ #define CHD_METAINDEX_APPEND ((UINT32)-1)
219
+
220
+ /* metadata flags */
221
+ #define CHD_MDFLAGS_CHECKSUM 0x01 /* indicates data is checksummed */
222
+
223
+ /* standard hard disk metadata */
224
+ #define HARD_DISK_METADATA_TAG CHD_MAKE_TAG('G','D','D','D')
225
+ #define HARD_DISK_METADATA_FORMAT "CYLS:%d,HEADS:%d,SECS:%d,BPS:%d"
226
+
227
+ /* hard disk identify information */
228
+ #define HARD_DISK_IDENT_METADATA_TAG CHD_MAKE_TAG('I','D','N','T')
229
+
230
+ /* hard disk key information */
231
+ #define HARD_DISK_KEY_METADATA_TAG CHD_MAKE_TAG('K','E','Y',' ')
232
+
233
+ /* pcmcia CIS information */
234
+ #define PCMCIA_CIS_METADATA_TAG CHD_MAKE_TAG('C','I','S',' ')
235
+
236
+ /* standard CD-ROM metadata */
237
+ #define CDROM_OLD_METADATA_TAG CHD_MAKE_TAG('C','H','C','D')
238
+ #define CDROM_TRACK_METADATA_TAG CHD_MAKE_TAG('C','H','T','R')
239
+ #define CDROM_TRACK_METADATA_FORMAT "TRACK:%d TYPE:%s SUBTYPE:%s FRAMES:%d"
240
+ #define CDROM_TRACK_METADATA2_TAG CHD_MAKE_TAG('C','H','T','2')
241
+ #define CDROM_TRACK_METADATA2_FORMAT "TRACK:%d TYPE:%s SUBTYPE:%s FRAMES:%d PREGAP:%d PGTYPE:%s PGSUB:%s POSTGAP:%d"
242
+ #define GDROM_OLD_METADATA_TAG CHD_MAKE_TAG('C','H','G','T')
243
+ #define GDROM_TRACK_METADATA_TAG CHD_MAKE_TAG('C', 'H', 'G', 'D')
244
+ #define GDROM_TRACK_METADATA_FORMAT "TRACK:%d TYPE:%s SUBTYPE:%s FRAMES:%d PAD:%d PREGAP:%d PGTYPE:%s PGSUB:%s POSTGAP:%d"
245
+
246
+ /* standard A/V metadata */
247
+ #define AV_METADATA_TAG CHD_MAKE_TAG('A','V','A','V')
248
+ #define AV_METADATA_FORMAT "FPS:%d.%06d WIDTH:%d HEIGHT:%d INTERLACED:%d CHANNELS:%d SAMPLERATE:%d"
249
+
250
+ /* A/V laserdisc frame metadata */
251
+ #define AV_LD_METADATA_TAG CHD_MAKE_TAG('A','V','L','D')
252
+
253
+ /* CHD open values */
254
+ #define CHD_OPEN_READ 1
255
+ #define CHD_OPEN_READWRITE 2
256
+
257
+ /* error types */
258
+ enum _chd_error
259
+ {
260
+ CHDERR_NONE,
261
+ CHDERR_NO_INTERFACE,
262
+ CHDERR_OUT_OF_MEMORY,
263
+ CHDERR_INVALID_FILE,
264
+ CHDERR_INVALID_PARAMETER,
265
+ CHDERR_INVALID_DATA,
266
+ CHDERR_FILE_NOT_FOUND,
267
+ CHDERR_REQUIRES_PARENT,
268
+ CHDERR_FILE_NOT_WRITEABLE,
269
+ CHDERR_READ_ERROR,
270
+ CHDERR_WRITE_ERROR,
271
+ CHDERR_CODEC_ERROR,
272
+ CHDERR_INVALID_PARENT,
273
+ CHDERR_HUNK_OUT_OF_RANGE,
274
+ CHDERR_DECOMPRESSION_ERROR,
275
+ CHDERR_COMPRESSION_ERROR,
276
+ CHDERR_CANT_CREATE_FILE,
277
+ CHDERR_CANT_VERIFY,
278
+ CHDERR_NOT_SUPPORTED,
279
+ CHDERR_METADATA_NOT_FOUND,
280
+ CHDERR_INVALID_METADATA_SIZE,
281
+ CHDERR_UNSUPPORTED_VERSION,
282
+ CHDERR_VERIFY_INCOMPLETE,
283
+ CHDERR_INVALID_METADATA,
284
+ CHDERR_INVALID_STATE,
285
+ CHDERR_OPERATION_PENDING,
286
+ CHDERR_NO_ASYNC_OPERATION,
287
+ CHDERR_UNSUPPORTED_FORMAT
288
+ };
289
+ typedef enum _chd_error chd_error;
290
+
291
+
292
+
293
+ /***************************************************************************
294
+ TYPE DEFINITIONS
295
+ ***************************************************************************/
296
+
297
+ /* opaque types */
298
+ typedef struct _chd_file chd_file;
299
+
300
+
301
+ /* extract header structure (NOT the on-disk header structure) */
302
+ typedef struct _chd_header chd_header;
303
+ struct _chd_header
304
+ {
305
+ UINT32 length; /* length of header data */
306
+ UINT32 version; /* drive format version */
307
+ UINT32 flags; /* flags field */
308
+ UINT32 compression[4]; /* compression type */
309
+ UINT32 hunkbytes; /* number of bytes per hunk */
310
+ UINT32 totalhunks; /* total # of hunks represented */
311
+ UINT64 logicalbytes; /* logical size of the data */
312
+ UINT64 metaoffset; /* offset in file of first metadata */
313
+ UINT64 mapoffset; /* TOOD V5 */
314
+ UINT8 md5[CHD_MD5_BYTES]; /* overall MD5 checksum */
315
+ UINT8 parentmd5[CHD_MD5_BYTES]; /* overall MD5 checksum of parent */
316
+ UINT8 sha1[CHD_SHA1_BYTES]; /* overall SHA1 checksum */
317
+ UINT8 rawsha1[CHD_SHA1_BYTES]; /* SHA1 checksum of raw data */
318
+ UINT8 parentsha1[CHD_SHA1_BYTES]; /* overall SHA1 checksum of parent */
319
+ UINT32 unitbytes; /* TODO V5 */
320
+ UINT64 unitcount; /* TODO V5 */
321
+ UINT32 hunkcount; /* TODO V5 */
322
+
323
+ /* map information */
324
+ UINT32 mapentrybytes; /* length of each entry in a map (V5) */
325
+ UINT8* rawmap; /* raw map data */
326
+
327
+ UINT32 obsolete_cylinders; /* obsolete field -- do not use! */
328
+ UINT32 obsolete_sectors; /* obsolete field -- do not use! */
329
+ UINT32 obsolete_heads; /* obsolete field -- do not use! */
330
+ UINT32 obsolete_hunksize; /* obsolete field -- do not use! */
331
+ };
332
+
333
+
334
+ /* structure for returning information about a verification pass */
335
+ typedef struct _chd_verify_result chd_verify_result;
336
+ struct _chd_verify_result
337
+ {
338
+ UINT8 md5[CHD_MD5_BYTES]; /* overall MD5 checksum */
339
+ UINT8 sha1[CHD_SHA1_BYTES]; /* overall SHA1 checksum */
340
+ UINT8 rawsha1[CHD_SHA1_BYTES]; /* SHA1 checksum of raw data */
341
+ UINT8 metasha1[CHD_SHA1_BYTES]; /* SHA1 checksum of metadata */
342
+ };
343
+
344
+
345
+
346
+ /***************************************************************************
347
+ FUNCTION PROTOTYPES
348
+ ***************************************************************************/
349
+
350
+ #ifdef _MSC_VER
351
+ #ifdef CHD_DLL
352
+ #ifdef CHD_DLL_EXPORTS
353
+ #define CHD_EXPORT __declspec(dllexport)
354
+ #else
355
+ #define CHD_EXPORT __declspec(dllimport)
356
+ #endif
357
+ #else
358
+ #define CHD_EXPORT
359
+ #endif
360
+ #else
361
+ #define CHD_EXPORT __attribute__ ((visibility("default")))
362
+ #endif
363
+
364
+ /* ----- CHD file management ----- */
365
+
366
+ /* create a new CHD file fitting the given description */
367
+ /* chd_error chd_create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent); */
368
+
369
+ /* same as chd_create(), but accepts an already-opened core_file object */
370
+ /* chd_error chd_create_file(core_file *file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent); */
371
+
372
+ /* open an existing CHD file */
373
+ CHD_EXPORT chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **chd);
374
+ CHD_EXPORT chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd);
375
+
376
+ /* precache underlying file */
377
+ CHD_EXPORT chd_error chd_precache(chd_file *chd);
378
+
379
+ /* close a CHD file */
380
+ CHD_EXPORT void chd_close(chd_file *chd);
381
+
382
+ /* return the associated core_file */
383
+ CHD_EXPORT core_file *chd_core_file(chd_file *chd);
384
+
385
+ /* return an error string for the given CHD error */
386
+ CHD_EXPORT const char *chd_error_string(chd_error err);
387
+
388
+
389
+
390
+ /* ----- CHD header management ----- */
391
+
392
+ /* return a pointer to the extracted CHD header data */
393
+ CHD_EXPORT const chd_header *chd_get_header(chd_file *chd);
394
+
395
+ /* read CHD header data from file into the pointed struct */
396
+ CHD_EXPORT chd_error chd_read_header(const char *filename, chd_header *header);
397
+
398
+
399
+
400
+ /* ----- core data read/write ----- */
401
+
402
+ /* read one hunk from the CHD file */
403
+ CHD_EXPORT chd_error chd_read(chd_file *chd, UINT32 hunknum, void *buffer);
404
+
405
+
406
+
407
+ /* ----- metadata management ----- */
408
+
409
+ /* get indexed metadata of a particular sort */
410
+ CHD_EXPORT chd_error chd_get_metadata(chd_file *chd, UINT32 searchtag, UINT32 searchindex, void *output, UINT32 outputlen, UINT32 *resultlen, UINT32 *resulttag, UINT8 *resultflags);
411
+
412
+
413
+
414
+
415
+ /* ----- codec interfaces ----- */
416
+
417
+ /* set internal codec parameters */
418
+ CHD_EXPORT chd_error chd_codec_config(chd_file *chd, int param, void *config);
419
+
420
+ /* return a string description of a codec */
421
+ CHD_EXPORT const char *chd_get_codec_name(UINT32 codec);
422
+
423
+ #ifdef __cplusplus
424
+ }
425
+ #endif
426
+
427
+ #endif /* __CHD_H__ */
@@ -0,0 +1,10 @@
1
+ #ifndef __CHDCONFIG_H__
2
+ #define __CHDCONFIG_H__
3
+
4
+ /* Configure CHDR features here */
5
+ #define WANT_RAW_DATA_SECTOR 1
6
+ #define WANT_SUBCODE 1
7
+ #define NEED_CACHE_HUNK 1
8
+ #define VERIFY_BLOCK_CRC 1
9
+
10
+ #endif
@@ -0,0 +1,60 @@
1
+ #ifndef __CORETYPES_H__
2
+ #define __CORETYPES_H__
3
+
4
+ #include <stdint.h>
5
+ #include <stdio.h>
6
+
7
+ #ifdef USE_LIBRETRO_VFS
8
+ #include <streams/file_stream_transforms.h>
9
+ #endif
10
+
11
+ #define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))
12
+
13
+ #if defined(__PS3__) || defined(__PSL1GHT__)
14
+ #undef UINT32
15
+ #undef UINT16
16
+ #undef UINT8
17
+ #undef INT32
18
+ #undef INT16
19
+ #undef INT8
20
+ #endif
21
+
22
+ typedef uint64_t UINT64;
23
+ typedef uint32_t UINT32;
24
+ typedef uint16_t UINT16;
25
+ typedef uint8_t UINT8;
26
+
27
+ typedef int64_t INT64;
28
+ typedef int32_t INT32;
29
+ typedef int16_t INT16;
30
+ typedef int8_t INT8;
31
+
32
+ #define core_file FILE
33
+ #define core_fopen(file) fopen(file, "rb")
34
+ #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN64__)
35
+ #define core_fseek _fseeki64
36
+ #define core_ftell _ftelli64
37
+ #elif defined(_LARGEFILE_SOURCE) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
38
+ #define core_fseek fseeko64
39
+ #define core_ftell ftello64
40
+ #elif defined(__PS3__) && !defined(__PSL1GHT__) || defined(__SWITCH__)
41
+ #define core_fseek(x,y,z) fseek(x,(off_t)y,z)
42
+ #define core_ftell(x) (off_t)ftell(x)
43
+ #else
44
+ #define core_fseek fseeko
45
+ #define core_ftell ftello
46
+ #endif
47
+ #define core_fread(fc, buff, len) fread(buff, 1, len, fc)
48
+ #define core_fclose fclose
49
+
50
+ static UINT64 core_fsize(core_file *f)
51
+ {
52
+ UINT64 rv;
53
+ UINT64 p = core_ftell(f);
54
+ core_fseek(f, 0, SEEK_END);
55
+ rv = core_ftell(f);
56
+ core_fseek(f, p, SEEK_SET);
57
+ return rv;
58
+ }
59
+
60
+ #endif