Debian Codegraph @

mednafen/cdrom/CDAccess_CCD.cpp

raw symbols SCIP
1 /* Mednafen - Multi-system Emulator
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #include "../mednafen.h"cxx . . $ `<file>/mednafen/mednafen.h`/
19 #include "../general.h"cxx . . $ `<file>/mednafen/general.h`/
20 #include "../msvc_compat.h"cxx . . $ `<file>/mednafen/msvc_compat.h`/
21 #include "CDAccess_CCD.h"cxx . . $ `<file>/mednafen/cdrom/CDAccess_CCD.h`/
22
23 #include <limits>
24 #include <limits.h>
25 #include <map>
26
27 using namespace CDUtility;
28
29 static void MDFN_strtouppercxx . . $ MDFN_strtoupper(80d0450aec2fd74).(stdcxx . . $ std/::stringcxx . . $ std/string# &str)
30 {
31 const size_t len = str.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).();
32
33 for(size_t x = 0; x < len; x++)
34 {
35 if(str[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] >= 'a' && str[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] <= 'z')
36 {
37 str[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] = str[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] - 'a' + 'A';
38 }
39 }
40 }
41
42 typedef stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#> CCD_Sectioncxx . . $ CCD_Section#;
43
44 template<typename T>
45 static T CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).(CCD_Sectioncxx . . $ CCD_Section# &s, const stdcxx . . $ std/::stringcxx . . $ std/string# &propname, const bool have_defval = false, const int defval = 0)
46 {
47 CCD_Sectioncxx . . $ CCD_Section#::iteratorcxx . . $ std/map#iterator# zit = s.findcxx . . $ std/map#find(36f8d56706583706).(propname);
48
49 if(zit ==cxx . . $ std/`operator==`(be6a71a859368080). s.endcxx . . $ std/map#end(7e4de33083b6e738).())
50 {
51 if(have_defval)
52 return defval;
53 else
54 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Missing property: %s"), propname.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
55 }
56
57 const stdcxx . . $ std/::stringcxx . . $ std/string# &v = zit->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.;
58 int scan_base = 10;
59 size_t scan_offset = 0;
60 long ret = 0;
61
62 if(v.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() >= 3 && v[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0] == '0' && v[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).1] == 'x')
63 {
64 scan_base = 16;
65 scan_offset = 2;
66 }
67
68 const char *vp = v.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).() + scan_offset;
69 char *ep = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
70
71 if(stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::is_signed)
72 ret = strtolcxx . . $ strtol(8cc4c7acb13e570c).(vp, &ep, scan_base);
73 else
74 ret = strtoulcxx . . $ strtoul(335a43d87d12a1b6).(vp, &ep, scan_base);
75
76 if(!vp[0] || ep[0])
77 {
78 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Property %s: Malformed integer: %s"), propname.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), v.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
79 }
80
81 //if(ret < minv || ret > maxv)
82 //{
83 // throw MDFN_Error(0, _("Property %s: Integer %ld out of range(accepted: %d through %d)."), propname.c_str(), ret, minv, maxv);
84 //}
85
86 return ret;
87 }
88
89
90 CDAccess_CCDcxx . . $ CDAccess_CCD#::CDAccess_CCDcxx . . $ CDAccess_CCD#CDAccess_CCD(90ef5b561fbcb8de).(const char *path, bool image_memcache) : img_streamcxx . . $ CDAccess_CCD#img_stream.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), sub_streamcxx . . $ CDAccess_CCD#sub_stream.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), img_numsectorscxx . . $ CDAccess_CCD#img_numsectors.(0)
91 {
92 try
93 {
94 Loadcxx . . $ CDAccess_CCD#Load(90ef5b561fbcb8de).(path, image_memcache);
95 }
96 catch(...)
97 {
98 Cleanupcxx . . $ CDAccess_CCD#Cleanup(49f6e7a06ebc5aa8).();
99 throw;
100 }
101 }
102
103 void CDAccess_CCDcxx . . $ CDAccess_CCD#::Loadcxx . . $ CDAccess_CCD#Load(90ef5b561fbcb8de).(const char *path, bool image_memcache)
104 {
105 FileStreamcxx . . $ FileStream# cfcxx . . $ FileStream#FileStream(34d26762b42c433a).(path, MODE_READcxx . . $ `mednafen/Stream.h:13:9`!);
106 stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, CCD_Sectioncxx . . $ CCD_Section#> Sectionscxx . . $ std/map#map(49f6e7a06ebc5aa8).;
107 stdcxx . . $ std/::stringcxx . . $ std/string# linebufcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
108 stdcxx . . $ std/::stringcxx . . $ std/string# cur_section_namecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
109 stdcxx . . $ std/::stringcxx . . $ std/string# dir_pathcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., file_basecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., file_extcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
110 char img_extsd[4] = { 'i', 'm', 'g', 0 };
111 char sub_extsd[4] = { 's', 'u', 'b', 0 };
112
113 MDFN_GetFilePathComponentscxx . . $ MDFN_GetFilePathComponents(f608b903cc9a02a6).(pathcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., &dir_path, &file_base, &file_ext);
114
115 if(file_ext.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() == 4 && file_ext[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '.')
116 {
117 signed char extupt[3] = { -1, -1, -1 };
118
119 for(int i = 1; i < 4; i++)
120 {
121 if(file_ext[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i] >= 'A' && file_ext[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i] <= 'Z')
122 extupt[i - 1] = 'A' - 'a';
123 else if(file_ext[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i] >= 'a' && file_ext[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i] <= 'z')
124 extupt[i - 1] = 0;
125 }
126
127 signed char av = -1;
128 for(int i = 0; i < 3; i++)
129 {
130 if(extupt[i] != -1)
131 av = extupt[i];
132 else
133 extupt[i] = av;
134 }
135
136 if(av == -1)
137 av = 0;
138
139 for(int i = 0; i < 3; i++)
140 {
141 if(extupt[i] == -1)
142 extupt[i] = av;
143 }
144
145 for(int i = 0; i < 3; i++)
146 {
147 img_extsd[i] += extupt[i];
148 sub_extsd[i] += extupt[i];
149 }
150 }
151
152 //printf("%s %d %d %d\n", file_ext.c_str(), extupt[0], extupt[1], extupt[2]);
153
154 linebuf.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(256);
155
156 while(cf.get_linecxx . . $ Stream#get_line(9b8588921b9c6c2f).(linebuf) >= 0)
157 {
158 MDFN_trimcxx . . $ MDFN_trim(80d0450aec2fd74).(linebuf);
159
160 if(linebuf.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() == 0) // Skip blank lines.
161 continue;
162
163 if(linebuf[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '[')
164 {
165 if(linebuf.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() < 3 || linebuf[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).linebuf.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() - 1] != ']')
166 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Malformed section specifier: %s"), linebuf.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
167
168 cur_section_name =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). linebuf.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(1, linebuf.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() - 2);
169 MDFN_strtouppercxx . . $ MDFN_strtoupper(80d0450aec2fd74).(cur_section_name);
170 }
171 else
172 {
173 const size_t feqpos = linebuf.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('=');
174 const size_t leqpos = linebuf.rfindcxx . . $ std/__cxx11/basic_string#rfind(2dda2fc6b78abe68).('=');
175 stdcxx . . $ std/::stringcxx . . $ std/string# kcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., vcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
176
177 if(feqpos == stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos. || feqpos != leqpos)
178 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Malformed value pair specifier: %s"), linebuf.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
179
180 k =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). linebuf.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0, feqpos);
181 v =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). linebuf.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(feqpos + 1);
182
183 MDFN_trimcxx . . $ MDFN_trim(80d0450aec2fd74).(k);
184 MDFN_trimcxx . . $ MDFN_trim(80d0450aec2fd74).(v);
185
186 MDFN_strtouppercxx . . $ MDFN_strtoupper(80d0450aec2fd74).(k);
187
188 Sections[cxx . . $ std/map#`operator[]`(bbd415b616967878).cur_section_name][cxx . . $ std/map#`operator[]`(bbd415b616967878).k] =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). v;
189 }
190 }
191
192 {
193 CCD_Sectioncxx . . $ CCD_Section#& ds = Sections[cxx . . $ std/map#`operator[]`(da459db78e6e18a3)."DISC"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).];
194 unsigned toc_entries = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<unsigned>(ds, "TOCENTRIES"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
195 unsigned num_sessions = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<unsigned>(ds, "SESSIONS"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
196 bool data_tracks_scrambled = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<unsigned>(ds, "DATATRACKSSCRAMBLED"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
197
198 if(num_sessions != 1)
199 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Unsupported number of sessions: %u"), num_sessions);
200
201 if(data_tracks_scrambled)
202 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Scrambled CCD data tracks currently not supported."));
203
204 //printf("MOO: %d\n", toc_entries);
205
206 for(unsigned te = 0; te < toc_entries; te++)
207 {
208 char tmpbuf[64];
209 snprintf(tmpbuf, sizeof(tmpbuf), "ENTRY %u", te);
210 CCD_Sectioncxx . . $ CCD_Section#& ts = Sections[cxx . . $ std/map#`operator[]`(da459db78e6e18a3).stdcxx . . $ std/::stringcxx . . $ std/string#(tmpbuf)];
211 unsigned session = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<unsigned>(ts, "SESSION"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
212 uint8cxx . . $ uint8# point = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<uint8cxx . . $ uint8#>(ts, "POINT"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
213 uint8cxx . . $ uint8# adr = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<uint8cxx . . $ uint8#>(ts, "ADR"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
214 uint8cxx . . $ uint8# control = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<uint8cxx . . $ uint8#>(ts, "CONTROL"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
215 uint8cxx . . $ uint8# pmin = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<uint8cxx . . $ uint8#>(ts, "PMIN"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
216 uint8cxx . . $ uint8# psec = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<uint8cxx . . $ uint8#>(ts, "PSEC"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
217 uint8cxx . . $ uint8# pframe = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<uint8cxx . . $ uint8#>(ts, "PFRAME"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
218 signed plba = CCD_ReadIntcxx . . $ CCD_ReadInt(522c25e435d36896).<signed>(ts, "PLBA"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
219
220 if(session != 1)
221 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, "Unsupported TOC entry Session value: %u", session);
222
223 // Reference: ECMA-394, page 5-14
224 switch(point)
225 {
226 default:
227 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, "Unsupported TOC entry Point value: %u", point);
228 break;
229
230 case 0xA0:
231 tocdcxx . . $ CDAccess_CCD#tocd..first_trackcxx . . $ CDUtility/TOC#first_track. = pmin;
232 tocdcxx . . $ CDAccess_CCD#tocd..disc_typecxx . . $ CDUtility/TOC#disc_type. = psec;
233 break;
234
235 case 0xA1:
236 tocdcxx . . $ CDAccess_CCD#tocd..last_trackcxx . . $ CDUtility/TOC#last_track. = pmin;
237 break;
238
239 case 0xA2:
240 tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[100].adrcxx . . $ CDUtility/TOC_Track#adr. = adr;
241 tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[100].controlcxx . . $ CDUtility/TOC_Track#control. = control;
242 tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[100].lbacxx . . $ CDUtility/TOC_Track#lba. = plba;
243 break;
244
245 case 99:
246 case 98:
247 case 97:
248 case 96:
249 case 95:
250 case 94:
251 case 93:
252 case 92:
253 case 91:
254 case 90:
255 case 89:
256 case 88:
257 case 87:
258 case 86:
259 case 85:
260 case 84:
261 case 83:
262 case 82:
263 case 81:
264 case 80:
265 case 79:
266 case 78:
267 case 77:
268 case 76:
269 case 75:
270 case 74:
271 case 73:
272 case 72:
273 case 71:
274 case 70:
275 case 69:
276 case 68:
277 case 67:
278 case 66:
279 case 65:
280 case 64:
281 case 63:
282 case 62:
283 case 61:
284 case 60:
285 case 59:
286 case 58:
287 case 57:
288 case 56:
289 case 55:
290 case 54:
291 case 53:
292 case 52:
293 case 51:
294 case 50:
295 case 49:
296 case 48:
297 case 47:
298 case 46:
299 case 45:
300 case 44:
301 case 43:
302 case 42:
303 case 41:
304 case 40:
305 case 39:
306 case 38:
307 case 37:
308 case 36:
309 case 35:
310 case 34:
311 case 33:
312 case 32:
313 case 31:
314 case 30:
315 case 29:
316 case 28:
317 case 27:
318 case 26:
319 case 25:
320 case 24:
321 case 23:
322 case 22:
323 case 21:
324 case 20:
325 case 19:
326 case 18:
327 case 17:
328 case 16:
329 case 15:
330 case 14:
331 case 13:
332 case 12:
333 case 11:
334 case 10:
335 case 9:
336 case 8:
337 case 7:
338 case 6:
339 case 5:
340 case 4:
341 case 3:
342 case 2:
343 case 1:
344 tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[point].adrcxx . . $ CDUtility/TOC_Track#adr. = adr;
345 tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[point].controlcxx . . $ CDUtility/TOC_Track#control. = control;
346 tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[point].lbacxx . . $ CDUtility/TOC_Track#lba. = plba;
347 break;
348 }
349 }
350 }
351
352 // Convenience leadout track duplication.
353 if(tocdcxx . . $ CDAccess_CCD#tocd..last_trackcxx . . $ CDUtility/TOC#last_track. < 99)
354 tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[tocdcxx . . $ CDAccess_CCD#tocd..last_trackcxx . . $ CDUtility/TOC#last_track. + 1] =cxx . . $ CDUtility/TOC_Track#`operator=`(a51e2e1bd6284b65). tocdcxx . . $ CDAccess_CCD#tocd..trackscxx . . $ CDUtility/TOC#tracks.[100];
355
356 //
357 // Open image stream.
358 {
359 stdcxx . . $ std/::stringcxx . . $ std/string# image_path = MDFN_EvalFIPcxx . . $ MDFN_EvalFIP(2007729dd81cc85).(dir_path, file_base +cxx . . $ std/operator+(ee59693d670ab61e). stdcxx . . $ std/::stringcxx . . $ std/string#(".") +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::stringcxx . . $ std/string#(img_extsd), true);
360
361 if(image_memcache)
362 {
363 img_streamcxx . . $ CDAccess_CCD#img_stream. = new MemoryStreamcxx . . $ MemoryStream#(new FileStreamcxx . . $ FileStream#(image_path.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), MODE_READcxx . . $ `mednafen/Stream.h:13:9`!));
364 }
365 else
366 {
367 img_streamcxx . . $ CDAccess_CCD#img_stream. = new FileStreamcxx . . $ FileStream#(image_path.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), MODE_READcxx . . $ `mednafen/Stream.h:13:9`!);
368 }
369
370 int64cxx . . $ int64# ss = img_streamcxx . . $ CDAccess_CCD#img_stream.->sizecxx . . $ Stream#size(da6335ded91d79c2).();
371
372 if(ss % 2352)
373 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("CCD image size is not evenly divisible by 2352."));
374
375 img_numsectorscxx . . $ CDAccess_CCD#img_numsectors. = ss / 2352;
376 }
377
378 //
379 // Open subchannel stream
380 {
381 stdcxx . . $ std/::stringcxx . . $ std/string# sub_path = MDFN_EvalFIPcxx . . $ MDFN_EvalFIP(2007729dd81cc85).(dir_path, file_base +cxx . . $ std/operator+(ee59693d670ab61e). stdcxx . . $ std/::stringcxx . . $ std/string#(".") +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::stringcxx . . $ std/string#(sub_extsd), true);
382
383 if(image_memcache)
384 sub_streamcxx . . $ CDAccess_CCD#sub_stream. = new MemoryStreamcxx . . $ MemoryStream#(new FileStreamcxx . . $ FileStream#(sub_path.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), MODE_READcxx . . $ `mednafen/Stream.h:13:9`!));
385 else
386 sub_streamcxx . . $ CDAccess_CCD#sub_stream. = new FileStreamcxx . . $ FileStream#(sub_path.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), MODE_READcxx . . $ `mednafen/Stream.h:13:9`!);
387
388 if(sub_streamcxx . . $ CDAccess_CCD#sub_stream.->sizecxx . . $ Stream#size(da6335ded91d79c2).() != (int64cxx . . $ int64#)img_numsectorscxx . . $ CDAccess_CCD#img_numsectors. * 96)
389 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("CCD SUB file size mismatch."));
390 }
391
392 CheckSubQSanitycxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).();
393 }
394
395 //
396 // Checks for Q subchannel mode 1(current time) data that has a correct checksum, but the data is nonsensical or corrupted nonetheless; this is the
397 // case for some bad rips floating around on the Internet. Allowing these bad rips to be used will cause all sorts of problems during emulation, so we
398 // error out here if a bad rip is detected.
399 //
400 // This check is not as aggressive or exhaustive as it could be, and will not detect all potential Q subchannel rip errors; as such, it should definitely NOT be
401 // used in an effort to "repair" a broken rip.
402 //
403 void CDAccess_CCDcxx . . $ CDAccess_CCD#::CheckSubQSanitycxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).(void)
404 {
405 size_t checksum_pass_counter = 0;
406 int prev_lba = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
407 uint8cxx . . $ uint8# prev_track = 0;
408
409 for(size_t s = 0; s < img_numsectorscxx . . $ CDAccess_CCD#img_numsectors.; s++)
410 {
411 unioncxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#
412 {
413 uint8cxx . . $ uint8# fullcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#full.[96];
414 structcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#
415 {
416 uint8cxx . . $ uint8# pbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#pbuf.[12];
417 uint8cxx . . $ uint8# qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[12];
418 };
419 } buf;
420
421 sub_streamcxx . . $ CDAccess_CCD#sub_stream.->seekcxx . . $ Stream#seek(3b75d2d14f60ac6a).(s * 96, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
422 sub_streamcxx . . $ CDAccess_CCD#sub_stream.->readcxx . . $ Stream#read(a1f03d5c460544d4).(buf.fullcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#full., 96);
423
424 if(subq_check_checksumcxx . . $ CDUtility/subq_check_checksum(190063cf6fb4afb1).(buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.))
425 {
426 uint8cxx . . $ uint8# adr = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[0] & 0xF;
427
428 if(adr == 0x01)
429 {
430 uint8cxx . . $ uint8# track_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[1];
431 uint8cxx . . $ uint8# index_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[2];
432 uint8cxx . . $ uint8# rm_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[3];
433 uint8cxx . . $ uint8# rs_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[4];
434 uint8cxx . . $ uint8# rf_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[5];
435 uint8cxx . . $ uint8# am_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[7];
436 uint8cxx . . $ uint8# as_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[8];
437 uint8cxx . . $ uint8# af_bcd = buf.qbufcxx . . $ CDAccess_CCD#CheckSubQSanity(49f6e7a06ebc5aa8).$anonymous_type_0#$anonymous_type_1#qbuf.[9];
438
439 //printf("%2x %2x %2x\n", am_bcd, as_bcd, af_bcd);
440
441 if(!BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(track_bcd) || !BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(index_bcd) || !BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(rm_bcd) || !BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(rs_bcd) || !BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(rf_bcd) ||
442 !BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(am_bcd) || !BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(as_bcd) || !BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(af_bcd) ||
443 rs_bcd > 0x59 || rf_bcd > 0x74 || as_bcd > 0x59 || af_bcd > 0x74)
444 {
445 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Garbage subchannel Q data detected(bad BCD/out of range): %02x:%02x:%02x %02x:%02x:%02x"), rm_bcd, rs_bcd, rf_bcd, am_bcd, as_bcd, af_bcd);
446 }
447 else
448 {
449 int lba = ((BCD_to_U8cxx . . $ CDUtility/BCD_to_U8(50106d451684defa).(am_bcd) * 60 + BCD_to_U8cxx . . $ CDUtility/BCD_to_U8(50106d451684defa).(as_bcd)) * 75 + BCD_to_U8cxx . . $ CDUtility/BCD_to_U8(50106d451684defa).(af_bcd)) - 150;
450 uint8cxx . . $ uint8# track = BCD_to_U8cxx . . $ CDUtility/BCD_to_U8(50106d451684defa).(track_bcd);
451
452 prev_lba = lba;
453
454 if(track < prev_track)
455 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Garbage subchannel Q data detected(bad track number)"));
456 //else if(prev_track && track - pre
457
458 prev_track = track;
459 }
460 checksum_pass_counter++;
461 }
462 }
463 }
464
465 //printf("%u/%u\n", checksum_pass_counter, img_numsectors);
466 }
467
468 void CDAccess_CCDcxx . . $ CDAccess_CCD#::Cleanupcxx . . $ CDAccess_CCD#Cleanup(49f6e7a06ebc5aa8).(void)
469 {
470 if(img_streamcxx . . $ CDAccess_CCD#img_stream.)
471 {
472 delete img_streamcxx . . $ CDAccess_CCD#img_stream.;
473 img_streamcxx . . $ CDAccess_CCD#img_stream. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
474 }
475
476 if(sub_streamcxx . . $ CDAccess_CCD#sub_stream.)
477 {
478 delete sub_streamcxx . . $ CDAccess_CCD#sub_stream.;
479 sub_streamcxx . . $ CDAccess_CCD#sub_stream. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
480 }
481 }
482
483 CDAccess_CCDcxx . . $ CDAccess_CCD#::~cxx . . $ CDAccess_CCD#`~CDAccess_CCD`(ced63f7c635d850d).CDAccess_CCDcxx . . $ CDAccess_CCD#()
484 {
485 Cleanupcxx . . $ CDAccess_CCD#Cleanup(49f6e7a06ebc5aa8).();
486 }
487
488 void CDAccess_CCDcxx . . $ CDAccess_CCD#::Read_Raw_Sectorcxx . . $ CDAccess_CCD#Read_Raw_Sector(fc0f0e1646c32816).(uint8cxx . . $ uint8# *buf, int32cxx . . $ int32# lba)
489 {
490 if(lba < 0 || (size_t)lba >= img_numsectorscxx . . $ CDAccess_CCD#img_numsectors.)
491 throw(MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("LBA out of range.")));
492
493 uint8cxx . . $ uint8# sub_buf[96];
494
495 img_streamcxx . . $ CDAccess_CCD#img_stream.->seekcxx . . $ Stream#seek(3b75d2d14f60ac6a).(lba * 2352, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
496 img_streamcxx . . $ CDAccess_CCD#img_stream.->readcxx . . $ Stream#read(a1f03d5c460544d4).(buf, 2352);
497
498 sub_streamcxx . . $ CDAccess_CCD#sub_stream.->seekcxx . . $ Stream#seek(3b75d2d14f60ac6a).(lba * 96, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
499 sub_streamcxx . . $ CDAccess_CCD#sub_stream.->readcxx . . $ Stream#read(a1f03d5c460544d4).(sub_buf, 96);
500
501 subpw_interleavecxx . . $ CDUtility/subpw_interleave(b1fdb6ced7ea43e9).(sub_buf, buf + 2352);
502 }
503
504
505 void CDAccess_CCDcxx . . $ CDAccess_CCD#::Read_TOCcxx . . $ CDAccess_CCD#Read_TOC(421bcafe44c737e9).(CDUtilitycxx . . $ CDUtility/::TOCcxx . . $ CDUtility/TOC# *toc)
506 {
507 *toc =cxx . . $ CDUtility/TOC#`operator=`(fe59811e31128dd7). tocdcxx . . $ CDAccess_CCD#tocd.;
508 }
509
510 bool CDAccess_CCDcxx . . $ CDAccess_CCD#::Is_Physicalcxx . . $ CDAccess_CCD#Is_Physical(77ce49a7840d23c7).(void) throw()
511 {
512 return false;
513 }
514
515 void CDAccess_CCDcxx . . $ CDAccess_CCD#::Ejectcxx . . $ CDAccess_CCD#Eject(b45ddcbc8423892c).(bool eject_status)
516 {
517
518 }
519