Debian Codegraph @

mednafen/cdrom/cdromif.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 <string.h>
20 #include <sys/types.h>
21 #include "cdromif.h"cxx . . $ `<file>/mednafen/cdrom/cdromif.h`/
22 #include "CDAccess.h"cxx . . $ `<file>/mednafen/cdrom/CDAccess.h`/
23 #include "../general.h"cxx . . $ `<file>/mednafen/general.h`/
24
25 #include <algorithm>
26 #include "../../libretro.h"cxx . . $ `<file>/libretro.h`/
27
28 extern retro_log_printf_t log_cbcxx . . $ log_cb.;
29
30 using namespace CDUtility;
31
32 enumcxx . . $ $anonymous_type_38614f1f019e5fd4_0#
33 {
34 // Status/Error messages
35 CDIF_MSG_DONEcxx . . $ CDIF_MSG_DONE. = 0, // Read -> emu. args: No args.
36 CDIF_MSG_INFOcxx . . $ CDIF_MSG_INFO., // Read -> emu. args: str_message
37 CDIF_MSG_FATAL_ERRORcxx . . $ CDIF_MSG_FATAL_ERROR., // Read -> emu. args: *TODO ARGS*
38
39 //
40 // Command messages.
41 //
42 CDIF_MSG_DIEDIEDIEcxx . . $ CDIF_MSG_DIEDIEDIE., // Emu -> read
43
44 CDIF_MSG_READ_SECTORcxx . . $ CDIF_MSG_READ_SECTOR., /* Emu -> read
45 args[0] = lba
46 */
47
48 CDIF_MSG_EJECTcxx . . $ CDIF_MSG_EJECT., // Emu -> read, args[0]; 0=insert, 1=eject
49 };
50
51 class CDIF_Messagecxx . . $ CDIF_Message#
52 {
53 public:
54
55 CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(49f6e7a06ebc5aa8).();
56 CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(a9b0a938867453dc).(unsigned int message_, uint32cxx . . $ uint32# arg0 = 0, uint32cxx . . $ uint32# arg1 = 0, uint32cxx . . $ uint32# arg2 = 0, uint32cxx . . $ uint32# arg3 = 0);
57 CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(7cdd6fa636f85550).(unsigned int message_, const stdcxx . . $ std/::stringcxx . . $ std/string# &str);
58 ~cxx . . $ CDIF_Message#`~CDIF_Message`(ced63f7c635d850d).CDIF_Messagecxx . . $ CDIF_Message#();
59
60 unsigned int messagecxx . . $ CDIF_Message#message.;
61 uint32cxx . . $ uint32# argscxx . . $ CDIF_Message#args.[4];
62 void *pargcxx . . $ CDIF_Message#parg.;
63 stdcxx . . $ std/::stringcxx . . $ std/string# str_messagecxx . . $ CDIF_Message#str_message.;
64 };
65
66 class CDIF_Queuecxx . . $ CDIF_Queue#
67 {
68 public:
69
70 CDIF_Queuecxx . . $ CDIF_Queue#CDIF_Queue(49f6e7a06ebc5aa8).();
71 ~cxx . . $ CDIF_Queue#`~CDIF_Queue`(ced63f7c635d850d).CDIF_Queuecxx . . $ CDIF_Queue#();
72
73 bool Readcxx . . $ CDIF_Queue#Read(f6630fdc412dcb41).(CDIF_Messagecxx . . $ CDIF_Message# *message, bool blocking = TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!);
74
75 void Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(const CDIF_Messagecxx . . $ CDIF_Message# &message);
76
77 private:
78 stdcxx . . $ std/::queuecxx . . $ std/queue#<CDIF_Messagecxx . . $ CDIF_Message#> ze_queuecxx . . $ CDIF_Queue#ze_queue.;
79 MDFN_Mutexcxx . . $ MDFN_Mutex# *ze_mutexcxx . . $ CDIF_Queue#ze_mutex.;
80 MDFN_Condcxx . . $ MDFN_Cond# *ze_condcxx . . $ CDIF_Queue#ze_cond.;
81 };
82
83
84 typedef structcxx . . $ $anonymous_type_38614f1f019e5fd4_1#
85 {
86 bool validcxx . . $ $anonymous_type_38614f1f019e5fd4_1#valid.;
87 bool errorcxx . . $ $anonymous_type_38614f1f019e5fd4_1#error.;
88 uint32cxx . . $ uint32# lbacxx . . $ $anonymous_type_38614f1f019e5fd4_1#lba.;
89 uint8cxx . . $ uint8# datacxx . . $ $anonymous_type_38614f1f019e5fd4_1#data.[2352 + 96];
90 } CDIF_Sector_Buffercxx . . $ CDIF_Sector_Buffer#;
91
92 // TODO: prohibit copy constructor
93 class CDIF_MTcxx . . $ CDIF_MT# : public CDIFcxx . . $ CDIF#
94 {
95 public:
96
97 CDIF_MTcxx . . $ CDIF_MT#CDIF_MT(c29fe23b09a86004).(CDAccesscxx . . $ CDAccess# *cda);
98 virtual ~cxx . . $ CDIF_MT#`~CDIF_MT`(ced63f7c635d850d).CDIF_MTcxx . . $ CDIF_MT#();
99
100 virtual void HintReadSectorcxx . . $ CDIF_MT#HintReadSector(cb2f890c2fdad230).(uint32cxx . . $ uint32# lba);
101 virtual bool ReadRawSectorcxx . . $ CDIF_MT#ReadRawSector(f3e7299796ab6c6f).(uint8cxx . . $ uint8# *buf, uint32cxx . . $ uint32# lba);
102
103 // Return true if operation succeeded or it was a NOP(either due to not being implemented, or the current status matches eject_status).
104 // Returns false on failure(usually drive error of some kind; not completely fatal, can try again).
105 virtual bool Ejectcxx . . $ CDIF_MT#Eject(efaadfb7dc14930a).(bool eject_status);
106
107 // FIXME: Semi-private:
108 int ReadThreadStartcxx . . $ CDIF_MT#ReadThreadStart(b126dc7c1de90089).(void);
109
110 private:
111
112 CDAccesscxx . . $ CDAccess# *disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.;
113
114 MDFN_Threadcxx . . $ MDFN_Thread# *CDReadThreadcxx . . $ CDIF_MT#CDReadThread.;
115
116 // Queue for messages to the read thread.
117 CDIF_Queuecxx . . $ CDIF_Queue# ReadThreadQueuecxx . . $ CDIF_MT#ReadThreadQueue.;
118
119 // Queue for messages to the emu thread.
120 CDIF_Queuecxx . . $ CDIF_Queue# EmuThreadQueuecxx . . $ CDIF_MT#EmuThreadQueue.;
121
122
123 enumcxx . . $ CDIF_MT#$anonymous_type_2# { SBSizecxx . . $ CDIF_MT#SBSize. = 256 };
124 CDIF_Sector_Buffercxx . . $ CDIF_Sector_Buffer# SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[SBSizecxx . . $ CDIF_MT#SBSize.];
125
126 uint32cxx . . $ uint32# SBWritePoscxx . . $ CDIF_MT#SBWritePos.;
127
128 MDFN_Mutexcxx . . $ MDFN_Mutex# *SBMutexcxx . . $ CDIF_MT#SBMutex.;
129 MDFN_Condcxx . . $ MDFN_Cond# *SBCondcxx . . $ CDIF_MT#SBCond.;
130
131
132 //
133 // Read-thread-only:
134 //
135 void RT_EjectDisccxx . . $ CDIF_MT#RT_EjectDisc(b0b38cda41d4ede4).(bool eject_status, bool skip_actual_eject = false);
136
137 uint32cxx . . $ uint32# ra_lbacxx . . $ CDIF_MT#ra_lba.;
138 int ra_countcxx . . $ CDIF_MT#ra_count.;
139 uint32cxx . . $ uint32# last_read_lbacxx . . $ CDIF_MT#last_read_lba.;
140 };
141
142
143 // TODO: prohibit copy constructor
144 class CDIF_STcxx . . $ CDIF_ST# : public CDIFcxx . . $ CDIF#
145 {
146 public:
147
148 CDIF_STcxx . . $ CDIF_ST#CDIF_ST(c29fe23b09a86004).(CDAccesscxx . . $ CDAccess# *cda);
149 virtual ~cxx . . $ CDIF_ST#`~CDIF_ST`(ced63f7c635d850d).CDIF_STcxx . . $ CDIF_ST#();
150
151 virtual void HintReadSectorcxx . . $ CDIF_ST#HintReadSector(cb2f890c2fdad230).(uint32cxx . . $ uint32# lba);
152 virtual bool ReadRawSectorcxx . . $ CDIF_ST#ReadRawSector(f3e7299796ab6c6f).(uint8cxx . . $ uint8# *buf, uint32cxx . . $ uint32# lba);
153 virtual bool Ejectcxx . . $ CDIF_ST#Eject(efaadfb7dc14930a).(bool eject_status);
154
155 private:
156 CDAccesscxx . . $ CDAccess# *disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.;
157 };
158
159 CDIFcxx . . $ CDIF#::CDIFcxx . . $ CDIF#CDIF(49f6e7a06ebc5aa8).() : UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError.(false), is_phys_cachecxx . . $ CDIF#is_phys_cache.(false), DiscEjectedcxx . . $ CDIF#DiscEjected.(false)
160 {
161
162 }
163
164 CDIFcxx . . $ CDIF#::~cxx . . $ CDIF#`~CDIF`(ced63f7c635d850d).CDIFcxx . . $ CDIF#()
165 {
166
167 }
168
169
170 CDIF_Messagecxx . . $ CDIF_Message#::CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(49f6e7a06ebc5aa8).()
171 {
172 messagecxx . . $ CDIF_Message#message. = 0;
173
174 memset(argscxx . . $ CDIF_Message#args., 0, sizeof(argscxx . . $ CDIF_Message#args.));
175 }
176
177 CDIF_Messagecxx . . $ CDIF_Message#::CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(a9b0a938867453dc).(unsigned int message_, uint32cxx . . $ uint32# arg0, uint32cxx . . $ uint32# arg1, uint32cxx . . $ uint32# arg2, uint32cxx . . $ uint32# arg3)
178 {
179 messagecxx . . $ CDIF_Message#message. = message_;
180 argscxx . . $ CDIF_Message#args.[0] = arg0;
181 argscxx . . $ CDIF_Message#args.[1] = arg1;
182 argscxx . . $ CDIF_Message#args.[2] = arg2;
183 argscxx . . $ CDIF_Message#args.[3] = arg3;
184 }
185
186 CDIF_Messagecxx . . $ CDIF_Message#::CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(7cdd6fa636f85550).(unsigned int message_, const stdcxx . . $ std/::stringcxx . . $ std/string# &str)
187 {
188 messagecxx . . $ CDIF_Message#message. = message_;
189 str_messagecxx . . $ CDIF_Message#str_message. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). str;
190 }
191
192 CDIF_Messagecxx . . $ CDIF_Message#::~cxx . . $ CDIF_Message#`~CDIF_Message`(ced63f7c635d850d).CDIF_Messagecxx . . $ CDIF_Message#()
193 {
194
195 }
196
197 CDIF_Queuecxx . . $ CDIF_Queue#::CDIF_Queuecxx . . $ CDIF_Queue#CDIF_Queue(49f6e7a06ebc5aa8).()
198 {
199 ze_mutexcxx . . $ CDIF_Queue#ze_mutex. = MDFND_CreateMutexcxx . . $ MDFND_CreateMutex(f7c2dfbe153feeb5).();
200 ze_condcxx . . $ CDIF_Queue#ze_cond. = MDFND_CreateCondcxx . . $ MDFND_CreateCond(23e52bc52ccd0781).();
201 }
202
203 CDIF_Queuecxx . . $ CDIF_Queue#::~cxx . . $ CDIF_Queue#`~CDIF_Queue`(ced63f7c635d850d).CDIF_Queuecxx . . $ CDIF_Queue#()
204 {
205 MDFND_DestroyMutexcxx . . $ MDFND_DestroyMutex(502f45e477e15126).(ze_mutexcxx . . $ CDIF_Queue#ze_mutex.);
206 MDFND_DestroyCondcxx . . $ MDFND_DestroyCond(141e1457c38d37d).(ze_condcxx . . $ CDIF_Queue#ze_cond.);
207 }
208
209 // Returns FALSE if message not read, TRUE if it was read. Will always return TRUE if "blocking" is set.
210 // Will throw MDFN_Error if the read message code is CDIF_MSG_FATAL_ERROR
211 bool CDIF_Queuecxx . . $ CDIF_Queue#::Readcxx . . $ CDIF_Queue#Read(f6630fdc412dcb41).(CDIF_Messagecxx . . $ CDIF_Message# *message, bool blocking)
212 {
213 bool ret = true;
214
215 //
216 //
217 //
218 MDFND_LockMutexcxx . . $ MDFND_LockMutex(79be6db43f041c4c).(ze_mutexcxx . . $ CDIF_Queue#ze_mutex.);
219
220 if(blocking)
221 {
222 while(ze_queuecxx . . $ CDIF_Queue#ze_queue..sizecxx . . $ std/queue#size(71e6dd9020568ee8).() == 0) // while, not just if.
223 MDFND_WaitCondcxx . . $ MDFND_WaitCond(97039b30e819d6aa).(ze_condcxx . . $ CDIF_Queue#ze_cond., ze_mutexcxx . . $ CDIF_Queue#ze_mutex.);
224 }
225
226 if(ze_queuecxx . . $ CDIF_Queue#ze_queue..sizecxx . . $ std/queue#size(71e6dd9020568ee8).() == 0)
227 ret = false;
228 else
229 {
230 *message =cxx . . $ CDIF_Message#`operator=`(890a4cde041b540a). ze_queuecxx . . $ CDIF_Queue#ze_queue..frontcxx . . $ std/queue#front(d8c1a3bbdff15733).();
231 ze_queuecxx . . $ CDIF_Queue#ze_queue..popcxx . . $ std/queue#pop(49f6e7a06ebc5aa8).();
232 }
233
234 MDFND_UnlockMutexcxx . . $ MDFND_UnlockMutex(79be6db43f041c4c).(ze_mutexcxx . . $ CDIF_Queue#ze_mutex.);
235 //
236 //
237 //
238
239 if(ret && message->messagecxx . . $ CDIF_Message#message. == CDIF_MSG_FATAL_ERRORcxx . . $ CDIF_MSG_FATAL_ERROR.)
240 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, "%s", message->str_messagecxx . . $ CDIF_Message#str_message..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
241
242 return(ret);
243 }
244
245 void CDIF_Queuecxx . . $ CDIF_Queue#::Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(const CDIF_Messagecxx . . $ CDIF_Message# &message)
246 {
247 MDFND_LockMutexcxx . . $ MDFND_LockMutex(79be6db43f041c4c).(ze_mutexcxx . . $ CDIF_Queue#ze_mutex.);
248
249 ze_queuecxx . . $ CDIF_Queue#ze_queue..pushcxx . . $ std/queue#push(5cd2eaf705c8bad3).(message);
250
251 MDFND_SignalCondcxx . . $ MDFND_SignalCond(81be31d010abce54).(ze_condcxx . . $ CDIF_Queue#ze_cond.); // Signal while the mutex is held to prevent icky race conditions
252
253 MDFND_UnlockMutexcxx . . $ MDFND_UnlockMutex(79be6db43f041c4c).(ze_mutexcxx . . $ CDIF_Queue#ze_mutex.);
254 }
255
256
257 void CDIF_MTcxx . . $ CDIF_MT#::RT_EjectDisccxx . . $ CDIF_MT#RT_EjectDisc(b0b38cda41d4ede4).(bool eject_status, bool skip_actual_eject)
258 {
259 int32cxx . . $ int32# old_de = DiscEjectedcxx . . $ CDIF#DiscEjected.;
260
261 DiscEjectedcxx . . $ CDIF#DiscEjected. = eject_status;
262
263 if(old_de != DiscEjectedcxx . . $ CDIF#DiscEjected.)
264 {
265 if(!skip_actual_eject)
266 disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.->Ejectcxx . . $ CDAccess#Eject(b45ddcbc8423892c).(eject_status);
267
268 if(!eject_status) // Re-read the TOC
269 {
270 disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.->Read_TOCcxx . . $ CDAccess#Read_TOC(421bcafe44c737e9).(&disc_toccxx . . $ CDIF#disc_toc.);
271
272 if(disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track. < 1 || disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track. > 99 || disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track. > disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track.)
273 {
274 throw(MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("TOC first(%d)/last(%d) track numbers bad."), disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track., disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track.));
275 }
276 }
277
278 SBWritePoscxx . . $ CDIF_MT#SBWritePos. = 0;
279 ra_lbacxx . . $ CDIF_MT#ra_lba. = 0;
280 ra_countcxx . . $ CDIF_MT#ra_count. = 0;
281 last_read_lbacxx . . $ CDIF_MT#last_read_lba. = ~0U;
282 memset(SectorBufferscxx . . $ CDIF_MT#SectorBuffers., 0, SBSizecxx . . $ CDIF_MT#SBSize. * sizeof(CDIF_Sector_Buffercxx . . $ CDIF_Sector_Buffer#));
283 }
284 }
285
286 struct RTS_Argscxx . . $ RTS_Args#
287 {
288 CDIF_MTcxx . . $ CDIF_MT# *cdif_ptrcxx . . $ RTS_Args#cdif_ptr.;
289 };
290
291 static int ReadThreadStart_Ccxx . . $ ReadThreadStart_C(dedf1e9b1c614a07).(void *v_arg)
292 {
293 RTS_Argscxx . . $ RTS_Args# *args = (RTS_Argscxx . . $ RTS_Args# *)v_arg;
294
295 return args->cdif_ptrcxx . . $ RTS_Args#cdif_ptr.->ReadThreadStartcxx . . $ CDIF_MT#ReadThreadStart(b126dc7c1de90089).();
296 }
297
298 int CDIF_MTcxx . . $ CDIF_MT#::ReadThreadStartcxx . . $ CDIF_MT#ReadThreadStart(b126dc7c1de90089).()
299 {
300 bool Running = TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!;
301
302 DiscEjectedcxx . . $ CDIF#DiscEjected. = true;
303 SBWritePoscxx . . $ CDIF_MT#SBWritePos. = 0;
304 ra_lbacxx . . $ CDIF_MT#ra_lba. = 0;
305 ra_countcxx . . $ CDIF_MT#ra_count. = 0;
306 last_read_lbacxx . . $ CDIF_MT#last_read_lba. = ~0U;
307
308 try
309 {
310 RT_EjectDisccxx . . $ CDIF_MT#RT_EjectDisc(b0b38cda41d4ede4).(false, true);
311 }
312 catch(stdcxx . . $ std/::exception &e)
313 {
314 EmuThreadQueuecxx . . $ CDIF_MT#EmuThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(7cdd6fa636f85550).(CDIF_MSG_FATAL_ERRORcxx . . $ CDIF_MSG_FATAL_ERROR., stdcxx . . $ std/::stringcxx . . $ std/string#(e.what())));
315 return(0);
316 }
317
318 is_phys_cachecxx . . $ CDIF#is_phys_cache. = false;
319
320 EmuThreadQueuecxx . . $ CDIF_MT#EmuThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#(CDIF_MSG_DONEcxx . . $ CDIF_MSG_DONE.));
321
322 while(Running)
323 {
324 CDIF_Messagecxx . . $ CDIF_Message# msgcxx . . $ CDIF_Message#CDIF_Message(49f6e7a06ebc5aa8).;
325
326 // Only do a blocking-wait for a message if we don't have any sectors to read-ahead.
327 // MDFN_DispMessage("%d %d %d\n", last_read_lba, ra_lba, ra_count);
328 if(ReadThreadQueuecxx . . $ CDIF_MT#ReadThreadQueue..Readcxx . . $ CDIF_Queue#Read(f6630fdc412dcb41).(&msg, ra_countcxx . . $ CDIF_MT#ra_count. ? FALSEcxx . . $ `mednafen/mednafen-types.h:109:9`! : TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!))
329 {
330 switch(msg.messagecxx . . $ CDIF_Message#message.)
331 {
332 case CDIF_MSG_DIEDIEDIEcxx . . $ CDIF_MSG_DIEDIEDIE.:
333 Running = FALSEcxx . . $ `mednafen/mednafen-types.h:109:9`!;
334 break;
335
336 case CDIF_MSG_EJECTcxx . . $ CDIF_MSG_EJECT.:
337 try
338 {
339 RT_EjectDisccxx . . $ CDIF_MT#RT_EjectDisc(b0b38cda41d4ede4).(msg.argscxx . . $ CDIF_Message#args.[0]);
340 EmuThreadQueuecxx . . $ CDIF_MT#EmuThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#(CDIF_MSG_DONEcxx . . $ CDIF_MSG_DONE.));
341 }
342 catch(stdcxx . . $ std/::exception &e)
343 {
344 EmuThreadQueuecxx . . $ CDIF_MT#EmuThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(7cdd6fa636f85550).(CDIF_MSG_FATAL_ERRORcxx . . $ CDIF_MSG_FATAL_ERROR., stdcxx . . $ std/::stringcxx . . $ std/string#(e.what())));
345 }
346 break;
347
348 case CDIF_MSG_READ_SECTORcxx . . $ CDIF_MSG_READ_SECTOR.:
349 {
350 static const int max_ra = 16;
351 static const int initial_ra = 1;
352 static const int speedmult_ra = 2;
353 uint32cxx . . $ uint32# new_lba = msg.argscxx . . $ CDIF_Message#args.[0];
354
355 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!((unsigned int)max_ra < (SBSize / 4));
356
357 if(last_read_lbacxx . . $ CDIF_MT#last_read_lba. != ~0U && new_lba == (last_read_lbacxx . . $ CDIF_MT#last_read_lba. + 1))
358 {
359 int how_far_ahead = ra_lbacxx . . $ CDIF_MT#ra_lba. - new_lba;
360
361 if(how_far_ahead <= max_ra)
362 ra_countcxx . . $ CDIF_MT#ra_count. = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(speedmult_ra, 1 + max_ra - how_far_ahead);
363 else
364 ra_countcxx . . $ CDIF_MT#ra_count.++;
365 }
366 else if(new_lba != last_read_lbacxx . . $ CDIF_MT#last_read_lba.)
367 {
368 ra_lbacxx . . $ CDIF_MT#ra_lba. = new_lba;
369 ra_countcxx . . $ CDIF_MT#ra_count. = initial_ra;
370 }
371
372 last_read_lbacxx . . $ CDIF_MT#last_read_lba. = new_lba;
373 }
374 break;
375 }
376 }
377
378 // Don't read >= the "end" of the disc, silly snake. Slither.
379 if(ra_countcxx . . $ CDIF_MT#ra_count. && ra_lbacxx . . $ CDIF_MT#ra_lba. == disc_toccxx . . $ CDIF#disc_toc..trackscxx . . $ CDUtility/TOC#tracks.[100].lbacxx . . $ CDUtility/TOC_Track#lba.)
380 {
381 ra_countcxx . . $ CDIF_MT#ra_count. = 0;
382 //printf("Ephemeral scarabs: %d!\n", ra_lba);
383 }
384
385 if(ra_countcxx . . $ CDIF_MT#ra_count.)
386 {
387 uint8cxx . . $ uint8# tmpbuf[2352 + 96];
388 bool error_condition = false;
389
390 try
391 {
392 disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.->Read_Raw_Sectorcxx . . $ CDAccess#Read_Raw_Sector(fc0f0e1646c32816).(tmpbuf, ra_lbacxx . . $ CDIF_MT#ra_lba.);
393 }
394 catch(stdcxx . . $ std/::exception &e)
395 {
396 if (log_cbcxx . . $ log_cb.)
397 log_cbcxx . . $ log_cb.(RETRO_LOG_ERROR, "Sector %u read error: %s\n", ra_lbacxx . . $ CDIF_MT#ra_lba., e.what());
398 memset(tmpbuf, 0, sizeof(tmpbuf));
399 error_condition = true;
400 }
401
402 MDFND_LockMutexcxx . . $ MDFND_LockMutex(79be6db43f041c4c).(SBMutexcxx . . $ CDIF_MT#SBMutex.);
403
404 SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[SBWritePoscxx . . $ CDIF_MT#SBWritePos.].lbacxx . . $ $anonymous_type_38614f1f019e5fd4_1#lba. = ra_lbacxx . . $ CDIF_MT#ra_lba.;
405 memcpy(SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[SBWritePoscxx . . $ CDIF_MT#SBWritePos.].datacxx . . $ $anonymous_type_38614f1f019e5fd4_1#data., tmpbuf, 2352 + 96);
406 SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[SBWritePoscxx . . $ CDIF_MT#SBWritePos.].validcxx . . $ $anonymous_type_38614f1f019e5fd4_1#valid. = TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!;
407 SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[SBWritePoscxx . . $ CDIF_MT#SBWritePos.].errorcxx . . $ $anonymous_type_38614f1f019e5fd4_1#error. = error_condition;
408 SBWritePoscxx . . $ CDIF_MT#SBWritePos. = (SBWritePoscxx . . $ CDIF_MT#SBWritePos. + 1) % SBSizecxx . . $ CDIF_MT#SBSize.;
409
410 MDFND_SignalCondcxx . . $ MDFND_SignalCond(81be31d010abce54).(SBCondcxx . . $ CDIF_MT#SBCond.);
411
412 MDFND_UnlockMutexcxx . . $ MDFND_UnlockMutex(79be6db43f041c4c).(SBMutexcxx . . $ CDIF_MT#SBMutex.);
413
414 ra_lbacxx . . $ CDIF_MT#ra_lba.++;
415 ra_countcxx . . $ CDIF_MT#ra_count.--;
416 }
417 }
418
419 return(1);
420 }
421
422 CDIF_MTcxx . . $ CDIF_MT#::CDIF_MTcxx . . $ CDIF_MT#CDIF_MT(c29fe23b09a86004).(CDAccesscxx . . $ CDAccess# *cda) : disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.(cda), CDReadThreadcxx . . $ CDIF_MT#CDReadThread.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), SBMutexcxx . . $ CDIF_MT#SBMutex.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), SBCondcxx . . $ CDIF_MT#SBCond.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
423 {
424 try
425 {
426 CDIF_Messagecxx . . $ CDIF_Message# msgcxx . . $ CDIF_Message#CDIF_Message(49f6e7a06ebc5aa8).;
427 RTS_Argscxx . . $ RTS_Args# s;
428
429 SBMutexcxx . . $ CDIF_MT#SBMutex. = MDFND_CreateMutexcxx . . $ MDFND_CreateMutex(f7c2dfbe153feeb5).();
430 SBCondcxx . . $ CDIF_MT#SBCond. = MDFND_CreateCondcxx . . $ MDFND_CreateCond(23e52bc52ccd0781).();
431 UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError. = false;
432
433 s.cdif_ptrcxx . . $ RTS_Args#cdif_ptr. = this;
434
435 CDReadThreadcxx . . $ CDIF_MT#CDReadThread. = MDFND_CreateThreadcxx . . $ MDFND_CreateThread(b48b9d196977390a).(ReadThreadStart_Ccxx . . $ ReadThreadStart_C(dedf1e9b1c614a07)., &s);
436 EmuThreadQueuecxx . . $ CDIF_MT#EmuThreadQueue..Readcxx . . $ CDIF_Queue#Read(f6630fdc412dcb41).(&msg);
437 }
438 catch(...)
439 {
440 if(CDReadThreadcxx . . $ CDIF_MT#CDReadThread.)
441 {
442 MDFND_WaitThreadcxx . . $ MDFND_WaitThread(f485867f39a32832).(CDReadThreadcxx . . $ CDIF_MT#CDReadThread., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
443 CDReadThreadcxx . . $ CDIF_MT#CDReadThread. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
444 }
445
446 if(SBMutexcxx . . $ CDIF_MT#SBMutex.)
447 {
448 MDFND_DestroyMutexcxx . . $ MDFND_DestroyMutex(502f45e477e15126).(SBMutexcxx . . $ CDIF_MT#SBMutex.);
449 SBMutexcxx . . $ CDIF_MT#SBMutex. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
450 }
451
452 if(SBCondcxx . . $ CDIF_MT#SBCond.)
453 {
454 MDFND_DestroyCondcxx . . $ MDFND_DestroyCond(141e1457c38d37d).(SBCondcxx . . $ CDIF_MT#SBCond.);
455 SBCondcxx . . $ CDIF_MT#SBCond. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
456 }
457
458 if(disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.)
459 {
460 delete disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.;
461 disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
462 }
463
464 throw;
465 }
466 }
467
468
469 CDIF_MTcxx . . $ CDIF_MT#::~cxx . . $ CDIF_MT#`~CDIF_MT`(ced63f7c635d850d).CDIF_MTcxx . . $ CDIF_MT#()
470 {
471 bool thread_deaded_failed = false;
472
473 try
474 {
475 ReadThreadQueuecxx . . $ CDIF_MT#ReadThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#(CDIF_MSG_DIEDIEDIEcxx . . $ CDIF_MSG_DIEDIEDIE.));
476 }
477 catch(stdcxx . . $ std/::exception &e)
478 {
479 if (log_cbcxx . . $ log_cb.)
480 log_cbcxx . . $ log_cb.(RETRO_LOG_ERROR, "%s.\n", e.what());
481 thread_deaded_failed = true;
482 }
483
484 if(!thread_deaded_failed)
485 MDFND_WaitThreadcxx . . $ MDFND_WaitThread(f485867f39a32832).(CDReadThreadcxx . . $ CDIF_MT#CDReadThread., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
486
487 if(SBMutexcxx . . $ CDIF_MT#SBMutex.)
488 {
489 MDFND_DestroyMutexcxx . . $ MDFND_DestroyMutex(502f45e477e15126).(SBMutexcxx . . $ CDIF_MT#SBMutex.);
490 SBMutexcxx . . $ CDIF_MT#SBMutex. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
491 }
492
493 if(disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.)
494 {
495 delete disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess.;
496 disc_cdaccesscxx . . $ CDIF_MT#disc_cdaccess. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
497 }
498 }
499
500 bool CDIFcxx . . $ CDIF#::ValidateRawSectorcxx . . $ CDIF#ValidateRawSector(8c2a43c3cf3cca3e).(uint8cxx . . $ uint8# *buf)
501 {
502 int mode = buf[12 + 3];
503
504 if(mode != 0x1 && mode != 0x2)
505 return(false);
506
507 if(!edc_lec_check_and_correctcxx . . $ CDUtility/edc_lec_check_and_correct(ecc5f6bcf4eac26).(buf, mode == 2))
508 return(false);
509
510 return(true);
511 }
512
513 bool CDIF_MTcxx . . $ CDIF_MT#::ReadRawSectorcxx . . $ CDIF_MT#ReadRawSector(f3e7299796ab6c6f).(uint8cxx . . $ uint8# *buf, uint32cxx . . $ uint32# lba)
514 {
515 bool found = FALSEcxx . . $ `mednafen/mednafen-types.h:109:9`!;
516 bool error_condition = false;
517
518 if(UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError.)
519 {
520 memset(buf, 0, 2352 + 96);
521 return(false);
522 }
523
524 // This shouldn't happen, the emulated-system-specific CDROM emulation code should make sure the emulated program doesn't try
525 // to read past the last "real" sector of the disc.
526 if(lba >= disc_toccxx . . $ CDIF#disc_toc..trackscxx . . $ CDUtility/TOC#tracks.[100].lbacxx . . $ CDUtility/TOC_Track#lba.)
527 {
528 printf("Attempt to read LBA %d, >= LBA %d\n", lba, disc_toccxx . . $ CDIF#disc_toc..trackscxx . . $ CDUtility/TOC#tracks.[100].lbacxx . . $ CDUtility/TOC_Track#lba.);
529 return(FALSEcxx . . $ `mednafen/mednafen-types.h:109:9`!);
530 }
531
532 ReadThreadQueuecxx . . $ CDIF_MT#ReadThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(a9b0a938867453dc).(CDIF_MSG_READ_SECTORcxx . . $ CDIF_MSG_READ_SECTOR., lba));
533
534 MDFND_LockMutexcxx . . $ MDFND_LockMutex(79be6db43f041c4c).(SBMutexcxx . . $ CDIF_MT#SBMutex.);
535
536 do
537 {
538
539 for(int i = 0; i < SBSizecxx . . $ CDIF_MT#SBSize.; i++)
540 {
541 if(SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[i].validcxx . . $ $anonymous_type_38614f1f019e5fd4_1#valid. && SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[i].lbacxx . . $ $anonymous_type_38614f1f019e5fd4_1#lba. == lba)
542 {
543 error_condition = SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[i].errorcxx . . $ $anonymous_type_38614f1f019e5fd4_1#error.;
544 memcpy(buf, SectorBufferscxx . . $ CDIF_MT#SectorBuffers.[i].datacxx . . $ $anonymous_type_38614f1f019e5fd4_1#data., 2352 + 96);
545 found = TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!;
546 }
547 }
548
549 if(!found)
550 {
551 //int32 swt = MDFND_GetTime();
552 MDFND_WaitCondcxx . . $ MDFND_WaitCond(97039b30e819d6aa).(SBCondcxx . . $ CDIF_MT#SBCond., SBMutexcxx . . $ CDIF_MT#SBMutex.);
553 //printf("SB Waited: %d\n", MDFND_GetTime() - swt);
554 }
555 } while(!found);
556
557 MDFND_UnlockMutexcxx . . $ MDFND_UnlockMutex(79be6db43f041c4c).(SBMutexcxx . . $ CDIF_MT#SBMutex.);
558
559 return(!error_condition);
560 }
561
562 void CDIF_MTcxx . . $ CDIF_MT#::HintReadSectorcxx . . $ CDIF_MT#HintReadSector(cb2f890c2fdad230).(uint32cxx . . $ uint32# lba)
563 {
564 if(UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError.)
565 return;
566
567 ReadThreadQueuecxx . . $ CDIF_MT#ReadThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(a9b0a938867453dc).(CDIF_MSG_READ_SECTORcxx . . $ CDIF_MSG_READ_SECTOR., lba));
568 }
569
570 int CDIFcxx . . $ CDIF#::ReadSectorcxx . . $ CDIF#ReadSector(47d6add1f5feae6f).(uint8cxx . . $ uint8#* pBuf, uint32cxx . . $ uint32# lba, uint32cxx . . $ uint32# nSectors)
571 {
572 int ret = 0;
573
574 if(UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError.)
575 return(false);
576
577 while(nSectors--)
578 {
579 uint8cxx . . $ uint8# tmpbuf[2352 + 96];
580
581 if(!ReadRawSectorcxx . . $ CDIF#ReadRawSector(f3e7299796ab6c6f).(tmpbuf, lba))
582 {
583 puts("CDIF Raw Read error");
584 return(FALSEcxx . . $ `mednafen/mednafen-types.h:109:9`!);
585 }
586
587 if(!ValidateRawSectorcxx . . $ CDIF#ValidateRawSector(8c2a43c3cf3cca3e).(tmpbuf))
588 {
589 if (log_cbcxx . . $ log_cb.)
590 {
591 log_cbcxx . . $ log_cb.(RETRO_LOG_ERROR, "Uncorrectable data at sector %d\n", lba);
592 log_cbcxx . . $ log_cb.(RETRO_LOG_ERROR, "Uncorrectable data at sector %d\n", lba);
593 }
594 return(false);
595 }
596
597 const int mode = tmpbuf[12 + 3];
598
599 if(!ret)
600 ret = mode;
601
602 if(mode == 1)
603 {
604 memcpy(pBuf, &tmpbuf[12 + 4], 2048);
605 }
606 else if(mode == 2)
607 {
608 memcpy(pBuf, &tmpbuf[12 + 4 + 8], 2048);
609 }
610 else
611 {
612 printf("CDIF_ReadSector() invalid sector type at LBA=%u\n", (unsigned int)lba);
613 return(false);
614 }
615
616 pBuf += 2048;
617 lba++;
618 }
619
620 return(ret);
621 }
622
623 bool CDIF_MTcxx . . $ CDIF_MT#::Ejectcxx . . $ CDIF_MT#Eject(efaadfb7dc14930a).(bool eject_status)
624 {
625 if(UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError.)
626 return(false);
627
628 try
629 {
630 CDIF_Messagecxx . . $ CDIF_Message# msgcxx . . $ CDIF_Message#CDIF_Message(49f6e7a06ebc5aa8).;
631
632 ReadThreadQueuecxx . . $ CDIF_MT#ReadThreadQueue..Writecxx . . $ CDIF_Queue#Write(d0d0103b49d0f1dd).(CDIF_Messagecxx . . $ CDIF_Message#CDIF_Message(a9b0a938867453dc).(CDIF_MSG_EJECTcxx . . $ CDIF_MSG_EJECT., eject_status));
633 EmuThreadQueuecxx . . $ CDIF_MT#EmuThreadQueue..Readcxx . . $ CDIF_Queue#Read(f6630fdc412dcb41).(&msg);
634 }
635 catch(stdcxx . . $ std/::exception &e)
636 {
637 log_cbcxx . . $ log_cb.(RETRO_LOG_ERROR, "Error on eject/insert attempt: %s\n", e.what());
638 return(false);
639 }
640
641 return(true);
642 }
643
644 //
645 //
646 // Single-threaded implementation follows.
647 //
648 //
649
650 CDIF_STcxx . . $ CDIF_ST#::CDIF_STcxx . . $ CDIF_ST#CDIF_ST(c29fe23b09a86004).(CDAccesscxx . . $ CDAccess# *cda) : disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.(cda)
651 {
652 //puts("***WARNING USING SINGLE-THREADED CD READER***");
653
654 is_phys_cachecxx . . $ CDIF#is_phys_cache. = false;
655 UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError. = false;
656 DiscEjectedcxx . . $ CDIF#DiscEjected. = false;
657
658 disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.->Read_TOCcxx . . $ CDAccess#Read_TOC(421bcafe44c737e9).(&disc_toccxx . . $ CDIF#disc_toc.);
659
660 if(disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track. < 1 || disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track. > 99 || disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track. > disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track.)
661 {
662 throw(MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("TOC first(%d)/last(%d) track numbers bad."), disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track., disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track.));
663 }
664 }
665
666 CDIF_STcxx . . $ CDIF_ST#::~cxx . . $ CDIF_ST#`~CDIF_ST`(ced63f7c635d850d).CDIF_STcxx . . $ CDIF_ST#()
667 {
668 if(disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.)
669 {
670 delete disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.;
671 disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
672 }
673 }
674
675 void CDIF_STcxx . . $ CDIF_ST#::HintReadSectorcxx . . $ CDIF_ST#HintReadSector(cb2f890c2fdad230).(uint32cxx . . $ uint32# lba)
676 {
677 // TODO: disc_cdaccess seek hint? (probably not, would require asynchronousitycamel)
678 }
679
680 bool CDIF_STcxx . . $ CDIF_ST#::ReadRawSectorcxx . . $ CDIF_ST#ReadRawSector(f3e7299796ab6c6f).(uint8cxx . . $ uint8# *buf, uint32cxx . . $ uint32# lba)
681 {
682 if(UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError.)
683 {
684 memset(buf, 0, 2352 + 96);
685 return(false);
686 }
687
688 try
689 {
690 disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.->Read_Raw_Sectorcxx . . $ CDAccess#Read_Raw_Sector(fc0f0e1646c32816).(buf, lba);
691 }
692 catch(stdcxx . . $ std/::exception &e)
693 {
694 if (log_cbcxx . . $ log_cb.)
695 log_cbcxx . . $ log_cb.(RETRO_LOG_ERROR, "Sector %u read error: %s\n", lba, e.what());
696 memset(buf, 0, 2352 + 96);
697 return(false);
698 }
699
700 return(true);
701 }
702
703 bool CDIF_STcxx . . $ CDIF_ST#::Ejectcxx . . $ CDIF_ST#Eject(efaadfb7dc14930a).(bool eject_status)
704 {
705 if(UnrecoverableErrorcxx . . $ CDIF#UnrecoverableError.)
706 return(false);
707
708 try
709 {
710 int32cxx . . $ int32# old_de = DiscEjectedcxx . . $ CDIF#DiscEjected.;
711
712 DiscEjectedcxx . . $ CDIF#DiscEjected. = eject_status;
713
714 if(old_de != DiscEjectedcxx . . $ CDIF#DiscEjected.)
715 {
716 disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.->Ejectcxx . . $ CDAccess#Eject(b45ddcbc8423892c).(eject_status);
717
718 if(!eject_status) // Re-read the TOC
719 {
720 disc_cdaccesscxx . . $ CDIF_ST#disc_cdaccess.->Read_TOCcxx . . $ CDAccess#Read_TOC(421bcafe44c737e9).(&disc_toccxx . . $ CDIF#disc_toc.);
721
722 if(disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track. < 1 || disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track. > 99 || disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track. > disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track.)
723 {
724 throw(MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("TOC first(%d)/last(%d) track numbers bad."), disc_toccxx . . $ CDIF#disc_toc..first_trackcxx . . $ CDUtility/TOC#first_track., disc_toccxx . . $ CDIF#disc_toc..last_trackcxx . . $ CDUtility/TOC#last_track.));
725 }
726 }
727 }
728 }
729 catch(stdcxx . . $ std/::exception &e)
730 {
731 if (log_cbcxx . . $ log_cb.)
732 log_cbcxx . . $ log_cb.(RETRO_LOG_ERROR, "%s\n", e.what());
733 return(false);
734 }
735
736 return(true);
737 }
738
739
740 class CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing# : public Streamcxx . . $ Stream#
741 {
742 public:
743
744 CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#CDIF_Stream_Thing(505ccbaa5c787c6e).(CDIFcxx . . $ CDIF# *cdintf_arg, uint32cxx . . $ uint32# lba_arg, uint32cxx . . $ uint32# sector_count_arg);
745 ~cxx . . $ CDIF_Stream_Thing#`~CDIF_Stream_Thing`(ced63f7c635d850d).CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#();
746
747 virtual uint64cxx . . $ uint64# attributescxx . . $ CDIF_Stream_Thing#attributes(f708dce9a8856c70).(void);
748 virtual uint8cxx . . $ uint8# *mapcxx . . $ CDIF_Stream_Thing#map(37d8967d10cb1e7b).(void);
749 virtual void unmapcxx . . $ CDIF_Stream_Thing#unmap(49f6e7a06ebc5aa8).(void);
750
751 virtual uint64cxx . . $ uint64# readcxx . . $ CDIF_Stream_Thing#read(a1f03d5c460544d4).(void *data, uint64cxx . . $ uint64# count, bool error_on_eos = true);
752 virtual void writecxx . . $ CDIF_Stream_Thing#write(8c7266571c1d65cc).(const void *data, uint64cxx . . $ uint64# count);
753
754 virtual void seekcxx . . $ CDIF_Stream_Thing#seek(3b75d2d14f60ac6a).(int64cxx . . $ int64# offset, int whence);
755 virtual int64cxx . . $ int64# tellcxx . . $ CDIF_Stream_Thing#tell(da6335ded91d79c2).(void);
756 virtual int64cxx . . $ int64# sizecxx . . $ CDIF_Stream_Thing#size(da6335ded91d79c2).(void);
757 virtual void closecxx . . $ CDIF_Stream_Thing#close(49f6e7a06ebc5aa8).(void);
758
759 private:
760 CDIFcxx . . $ CDIF# *cdintfcxx . . $ CDIF_Stream_Thing#cdintf.;
761 const uint32cxx . . $ uint32# start_lbacxx . . $ CDIF_Stream_Thing#start_lba.;
762 const uint32cxx . . $ uint32# sector_countcxx . . $ CDIF_Stream_Thing#sector_count.;
763 int64cxx . . $ int64# positioncxx . . $ CDIF_Stream_Thing#position.;
764 };
765
766 CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#CDIF_Stream_Thing(505ccbaa5c787c6e).(CDIFcxx . . $ CDIF# *cdintf_arg, uint32cxx . . $ uint32# start_lba_arg, uint32cxx . . $ uint32# sector_count_arg) : cdintfcxx . . $ CDIF_Stream_Thing#cdintf.(cdintf_arg), start_lbacxx . . $ CDIF_Stream_Thing#start_lba.(start_lba_arg), sector_countcxx . . $ CDIF_Stream_Thing#sector_count.(sector_count_arg)
767 {
768
769 }
770
771 CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::~cxx . . $ CDIF_Stream_Thing#`~CDIF_Stream_Thing`(ced63f7c635d850d).CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#()
772 {
773
774 }
775
776 uint64cxx . . $ uint64# CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::attributescxx . . $ CDIF_Stream_Thing#attributes(f708dce9a8856c70).(void)
777 {
778 return(ATTRIBUTE_READABLEcxx . . $ Stream#ATTRIBUTE_READABLE. | ATTRIBUTE_SEEKABLEcxx . . $ Stream#ATTRIBUTE_SEEKABLE.);
779 }
780
781 uint8cxx . . $ uint8# *CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::mapcxx . . $ CDIF_Stream_Thing#map(37d8967d10cb1e7b).(void)
782 {
783 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
784 }
785
786 void CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::unmapcxx . . $ CDIF_Stream_Thing#unmap(49f6e7a06ebc5aa8).(void)
787 {
788
789 }
790
791 uint64cxx . . $ uint64# CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::readcxx . . $ CDIF_Stream_Thing#read(a1f03d5c460544d4).(void *data, uint64cxx . . $ uint64# count, bool error_on_eos)
792 {
793 if(count > (((uint64cxx . . $ uint64#)sector_countcxx . . $ CDIF_Stream_Thing#sector_count. * 2048) - positioncxx . . $ CDIF_Stream_Thing#position.))
794 {
795 if(error_on_eos)
796 {
797 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, "EOF");
798 }
799
800 count = ((uint64cxx . . $ uint64#)sector_countcxx . . $ CDIF_Stream_Thing#sector_count. * 2048) - positioncxx . . $ CDIF_Stream_Thing#position.;
801 }
802
803 if(!count)
804 return(0);
805
806 for(uint64cxx . . $ uint64# rp = positioncxx . . $ CDIF_Stream_Thing#position.; rp < (positioncxx . . $ CDIF_Stream_Thing#position. + count); rp = (rp &~ 2047) + 2048)
807 {
808 uint8cxx . . $ uint8# buf[2048];
809
810 if(!cdintfcxx . . $ CDIF_Stream_Thing#cdintf.->ReadSectorcxx . . $ CDIF#ReadSector(47d6add1f5feae6f).(buf, start_lbacxx . . $ CDIF_Stream_Thing#start_lba. + (rp / 2048), 1))
811 {
812 throw MDFN_Errorcxx . . $ MDFN_Error#(ErrnoHoldercxx . . $ ErrnoHolder#ErrnoHolder(d4f767463ce0a6b3).(EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!));
813 }
814
815 //::printf("Meow: %08llx -- %08llx\n", count, (rp - position) + std::min<uint64>(2048 - (rp & 2047), count - (rp - position)));
816 memcpy((uint8cxx . . $ uint8#*)data + (rp - positioncxx . . $ CDIF_Stream_Thing#position.), buf + (rp & 2047), stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).<uint64cxx . . $ uint64#>(2048 - (rp & 2047), count - (rp - positioncxx . . $ CDIF_Stream_Thing#position.)));
817 }
818
819 positioncxx . . $ CDIF_Stream_Thing#position. += count;
820
821 return count;
822 }
823
824 void CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::writecxx . . $ CDIF_Stream_Thing#write(8c7266571c1d65cc).(const void *data, uint64cxx . . $ uint64# count)
825 {
826 throw MDFN_Errorcxx . . $ MDFN_Error#(ErrnoHoldercxx . . $ ErrnoHolder#ErrnoHolder(d4f767463ce0a6b3).(EBADFcxx . . $ `<external>/8987895939074593727/errno-base.h:13:9`!));
827 }
828
829 void CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::seekcxx . . $ CDIF_Stream_Thing#seek(3b75d2d14f60ac6a).(int64cxx . . $ int64# offset, int whence)
830 {
831 int64cxx . . $ int64# new_position;
832
833 switch(whence)
834 {
835 default:
836 throw MDFN_Errorcxx . . $ MDFN_Error#(ErrnoHoldercxx . . $ ErrnoHolder#ErrnoHolder(d4f767463ce0a6b3).(EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!));
837 break;
838
839 case SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!:
840 new_position = offset;
841 break;
842
843 case SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!:
844 new_position = positioncxx . . $ CDIF_Stream_Thing#position. + offset;
845 break;
846
847 case SEEK_ENDcxx . . $ `<external>/232824719582829767/stdio.h:112:9`!:
848 new_position = ((int64cxx . . $ int64#)sector_countcxx . . $ CDIF_Stream_Thing#sector_count. * 2048) + offset;
849 break;
850 }
851
852 if(new_position < 0 || new_position > ((int64cxx . . $ int64#)sector_countcxx . . $ CDIF_Stream_Thing#sector_count. * 2048))
853 throw MDFN_Errorcxx . . $ MDFN_Error#(ErrnoHoldercxx . . $ ErrnoHolder#ErrnoHolder(d4f767463ce0a6b3).(EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!));
854
855 positioncxx . . $ CDIF_Stream_Thing#position. = new_position;
856 }
857
858 int64cxx . . $ int64# CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::tellcxx . . $ CDIF_Stream_Thing#tell(da6335ded91d79c2).(void)
859 {
860 return positioncxx . . $ CDIF_Stream_Thing#position.;
861 }
862
863 int64cxx . . $ int64# CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::sizecxx . . $ CDIF_Stream_Thing#size(da6335ded91d79c2).(void)
864 {
865 return(sector_countcxx . . $ CDIF_Stream_Thing#sector_count. * 2048);
866 }
867
868 void CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#::closecxx . . $ CDIF_Stream_Thing#close(49f6e7a06ebc5aa8).(void)
869 {
870
871 }
872
873
874 Streamcxx . . $ Stream# *CDIFcxx . . $ CDIF#::MakeStreamcxx . . $ CDIF#MakeStream(4c1ca53b286bb8cf).(uint32cxx . . $ uint32# lba, uint32cxx . . $ uint32# sector_count)
875 {
876 return new CDIF_Stream_Thingcxx . . $ CDIF_Stream_Thing#(this, lba, sector_count);
877 }
878
879
880 CDIFcxx . . $ CDIF# *CDIF_Opencxx . . $ CDIF_Open(c10ccd82c5204030).(const char *path, const bool is_device, bool image_memcache)
881 {
882 CDAccesscxx . . $ CDAccess# *cda = cdaccess_open_imagecxx . . $ cdaccess_open_image(e9ea66fc932e99e6).(path, image_memcache);
883
884 if(!image_memcache)
885 return new CDIF_MTcxx . . $ CDIF_MT#(cda);
886 else
887 return new CDIF_STcxx . . $ CDIF_ST#(cda);
888 }