Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/mednadisc/cdrom/cdromif.cpp
2 views
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 <string.h>
19
#include <sys/types.h>
20
#include <trio/trio.h>
21
#include "emuware/emuware.h"
22
#include "cdromif.h"
23
#include "CDAccess.h"
24
#include "general.h"
25
#include "error.h"
26
27
//undo gettext stuff
28
#define _(X) X
29
#include <algorithm>
30
31
using namespace CDUtility;
32
33
enum
34
{
35
// Status/Error messages
36
CDIF_MSG_DONE = 0, // Read -> emu. args: No args.
37
CDIF_MSG_INFO, // Read -> emu. args: str_message
38
CDIF_MSG_FATAL_ERROR, // Read -> emu. args: *TODO ARGS*
39
40
//
41
// Command messages.
42
//
43
CDIF_MSG_DIEDIEDIE, // Emu -> read
44
45
CDIF_MSG_READ_SECTOR, /* Emu -> read
46
args[0] = lba
47
*/
48
};
49
50
class CDIF_Message
51
{
52
public:
53
54
CDIF_Message();
55
CDIF_Message(unsigned int message_, uint32 arg0 = 0, uint32 arg1 = 0, uint32 arg2 = 0, uint32 arg3 = 0);
56
CDIF_Message(unsigned int message_, const std::string &str);
57
~CDIF_Message();
58
59
unsigned int message;
60
uint32 args[4];
61
void *parg;
62
std::string str_message;
63
};
64
65
#ifdef WANT_QUEUE
66
class CDIF_Queue
67
{
68
public:
69
70
CDIF_Queue();
71
~CDIF_Queue();
72
73
bool Read(CDIF_Message *message, bool blocking = TRUE);
74
75
void Write(const CDIF_Message &message);
76
77
private:
78
std::queue<CDIF_Message> ze_queue;
79
MDFN_Mutex *ze_mutex;
80
MDFN_Cond *ze_cond;
81
};
82
#endif
83
84
85
typedef struct
86
{
87
bool valid;
88
bool error;
89
int32 lba;
90
uint8 data[2352 + 96];
91
} CDIF_Sector_Buffer;
92
93
#ifdef WANT_QUEUE
94
// TODO: prohibit copy constructor
95
class CDIF_MT : public CDIF
96
{
97
public:
98
99
CDIF_MT(CDAccess *cda);
100
virtual ~CDIF_MT();
101
102
virtual void HintReadSector(int32 lba);
103
virtual bool ReadRawSector(uint8 *buf, int32 lba);
104
virtual bool ReadRawSectorPWOnly(uint8* pwbuf, int32 lba, bool hint_fullread);
105
106
// FIXME: Semi-private:
107
int ReadThreadStart(void);
108
109
private:
110
111
CDAccess *disc_cdaccess;
112
113
MDFN_Thread *CDReadThread;
114
115
// Queue for messages to the read thread.
116
CDIF_Queue ReadThreadQueue;
117
118
// Queue for messages to the emu thread.
119
CDIF_Queue EmuThreadQueue;
120
121
122
enum { SBSize = 256 };
123
CDIF_Sector_Buffer SectorBuffers[SBSize];
124
125
uint32 SBWritePos;
126
127
MDFN_Mutex *SBMutex;
128
MDFN_Cond *SBCond;
129
130
131
//
132
// Read-thread-only:
133
//
134
int32 ra_lba;
135
int32 ra_count;
136
int32 last_read_lba;
137
};
138
#endif //WANT_QUEUE
139
140
141
// TODO: prohibit copy constructor
142
class CDIF_ST : public CDIF
143
{
144
public:
145
146
CDIF_ST(CDAccess *cda);
147
virtual ~CDIF_ST();
148
149
virtual void HintReadSector(int32 lba);
150
virtual bool ReadRawSector(uint8 *buf, int32 lba);
151
virtual bool ReadRawSectorPWOnly(uint8* pwbuf, int32 lba, bool hint_fullread);
152
153
private:
154
CDAccess *disc_cdaccess;
155
};
156
157
CDIF::CDIF() : UnrecoverableError(false)
158
{
159
160
}
161
162
CDIF::~CDIF()
163
{
164
165
}
166
167
168
CDIF_Message::CDIF_Message()
169
{
170
message = 0;
171
172
memset(args, 0, sizeof(args));
173
}
174
175
CDIF_Message::CDIF_Message(unsigned int message_, uint32 arg0, uint32 arg1, uint32 arg2, uint32 arg3)
176
{
177
message = message_;
178
args[0] = arg0;
179
args[1] = arg1;
180
args[2] = arg2;
181
args[3] = arg3;
182
}
183
184
CDIF_Message::CDIF_Message(unsigned int message_, const std::string &str)
185
{
186
message = message_;
187
str_message = str;
188
}
189
190
CDIF_Message::~CDIF_Message()
191
{
192
193
}
194
195
#ifdef WANT_QUEUE
196
CDIF_Queue::CDIF_Queue()
197
{
198
ze_mutex = MDFND_CreateMutex();
199
ze_cond = MDFND_CreateCond();
200
}
201
202
CDIF_Queue::~CDIF_Queue()
203
{
204
MDFND_DestroyMutex(ze_mutex);
205
MDFND_DestroyCond(ze_cond);
206
}
207
208
// Returns FALSE if message not read, TRUE if it was read. Will always return TRUE if "blocking" is set.
209
// Will throw MDFN_Error if the read message code is CDIF_MSG_FATAL_ERROR
210
bool CDIF_Queue::Read(CDIF_Message *message, bool blocking)
211
{
212
bool ret = true;
213
214
//
215
//
216
//
217
MDFND_LockMutex(ze_mutex);
218
219
if(blocking)
220
{
221
while(ze_queue.size() == 0) // while, not just if.
222
{
223
MDFND_WaitCond(ze_cond, ze_mutex);
224
}
225
}
226
227
if(ze_queue.size() == 0)
228
ret = false;
229
else
230
{
231
*message = ze_queue.front();
232
ze_queue.pop();
233
}
234
235
MDFND_UnlockMutex(ze_mutex);
236
//
237
//
238
//
239
240
if(ret && message->message == CDIF_MSG_FATAL_ERROR)
241
throw MDFN_Error(0, "%s", message->str_message.c_str());
242
243
return(ret);
244
}
245
246
void CDIF_Queue::Write(const CDIF_Message &message)
247
{
248
MDFND_LockMutex(ze_mutex);
249
250
try
251
{
252
ze_queue.push(message);
253
}
254
catch(...)
255
{
256
fprintf(stderr, "\n\nCDIF_Message queue push failed!!! (We now return you to your regularly unscheduled lockup)\n\n");
257
}
258
259
MDFND_SignalCond(ze_cond); // Signal while the mutex is held to prevent icky race conditions.
260
261
MDFND_UnlockMutex(ze_mutex);
262
}
263
264
struct RTS_Args
265
{
266
CDIF_MT *cdif_ptr;
267
};
268
269
static int ReadThreadStart_C(void *v_arg)
270
{
271
RTS_Args *args = (RTS_Args *)v_arg;
272
273
return args->cdif_ptr->ReadThreadStart();
274
}
275
276
int CDIF_MT::ReadThreadStart()
277
{
278
bool Running = TRUE;
279
280
SBWritePos = 0;
281
ra_lba = 0;
282
ra_count = 0;
283
last_read_lba = LBA_Read_Maximum + 1;
284
285
try
286
{
287
disc_cdaccess->Read_TOC(&disc_toc);
288
289
if(disc_toc.first_track < 1 || disc_toc.last_track > 99 || disc_toc.first_track > disc_toc.last_track)
290
{
291
throw(MDFN_Error(0, _("TOC first(%d)/last(%d) track numbers bad."), disc_toc.first_track, disc_toc.last_track));
292
}
293
294
SBWritePos = 0;
295
ra_lba = 0;
296
ra_count = 0;
297
last_read_lba = LBA_Read_Maximum + 1;
298
memset(SectorBuffers, 0, SBSize * sizeof(CDIF_Sector_Buffer));
299
}
300
catch(std::exception &e)
301
{
302
EmuThreadQueue.Write(CDIF_Message(CDIF_MSG_FATAL_ERROR, std::string(e.what())));
303
return(0);
304
}
305
306
EmuThreadQueue.Write(CDIF_Message(CDIF_MSG_DONE));
307
308
while(Running)
309
{
310
CDIF_Message msg;
311
312
// Only do a blocking-wait for a message if we don't have any sectors to read-ahead.
313
// MDFN_DispMessage("%d %d %d\n", last_read_lba, ra_lba, ra_count);
314
if(ReadThreadQueue.Read(&msg, ra_count ? FALSE : TRUE))
315
{
316
switch(msg.message)
317
{
318
case CDIF_MSG_DIEDIEDIE:
319
Running = FALSE;
320
break;
321
322
case CDIF_MSG_READ_SECTOR:
323
{
324
static const int max_ra = 16;
325
static const int initial_ra = 1;
326
static const int speedmult_ra = 2;
327
int32 new_lba = msg.args[0];
328
329
assert((unsigned int)max_ra < (SBSize / 4));
330
331
if(new_lba == (last_read_lba + 1))
332
{
333
int how_far_ahead = ra_lba - new_lba;
334
335
if(how_far_ahead <= max_ra)
336
ra_count = std::min(speedmult_ra, 1 + max_ra - how_far_ahead);
337
else
338
ra_count++;
339
}
340
else if(new_lba != last_read_lba)
341
{
342
ra_lba = new_lba;
343
ra_count = initial_ra;
344
}
345
346
last_read_lba = new_lba;
347
}
348
break;
349
}
350
}
351
352
//
353
// Don't read beyond what the disc (image) readers can handle sanely.
354
//
355
if(ra_count && ra_lba == LBA_Read_Maximum)
356
{
357
ra_count = 0;
358
//printf("Ephemeral scarabs: %d!\n", ra_lba);
359
}
360
361
if(ra_count)
362
{
363
uint8 tmpbuf[2352 + 96];
364
bool error_condition = false;
365
366
try
367
{
368
disc_cdaccess->Read_Raw_Sector(tmpbuf, ra_lba);
369
}
370
catch(std::exception &e)
371
{
372
MDFN_PrintError(_("Sector %u read error: %s"), ra_lba, e.what());
373
memset(tmpbuf, 0, sizeof(tmpbuf));
374
error_condition = true;
375
}
376
377
//
378
//
379
MDFND_LockMutex(SBMutex);
380
381
SectorBuffers[SBWritePos].lba = ra_lba;
382
memcpy(SectorBuffers[SBWritePos].data, tmpbuf, 2352 + 96);
383
SectorBuffers[SBWritePos].valid = TRUE;
384
SectorBuffers[SBWritePos].error = error_condition;
385
SBWritePos = (SBWritePos + 1) % SBSize;
386
387
MDFND_SignalCond(SBCond);
388
389
MDFND_UnlockMutex(SBMutex);
390
//
391
//
392
393
ra_lba++;
394
ra_count--;
395
}
396
}
397
398
return(1);
399
}
400
401
CDIF_MT::CDIF_MT(CDAccess *cda) : disc_cdaccess(cda), CDReadThread(NULL), SBMutex(NULL), SBCond(NULL)
402
{
403
try
404
{
405
CDIF_Message msg;
406
RTS_Args s;
407
408
if(!(SBMutex = MDFND_CreateMutex()))
409
throw MDFN_Error(0, _("Error creating CD read thread mutex."));
410
411
if(!(SBCond = MDFND_CreateCond()))
412
throw MDFN_Error(0, _("Error creating CD read thread condition variable."));
413
414
UnrecoverableError = false;
415
416
s.cdif_ptr = this;
417
418
if(!(CDReadThread = MDFND_CreateThread(ReadThreadStart_C, &s)))
419
throw MDFN_Error(0, _("Error creating CD read thread."));
420
421
EmuThreadQueue.Read(&msg);
422
}
423
catch(...)
424
{
425
if(CDReadThread)
426
{
427
MDFND_WaitThread(CDReadThread, NULL);
428
CDReadThread = NULL;
429
}
430
431
if(SBMutex)
432
{
433
MDFND_DestroyMutex(SBMutex);
434
SBMutex = NULL;
435
}
436
437
if(SBCond)
438
{
439
MDFND_DestroyCond(SBCond);
440
SBCond = NULL;
441
}
442
443
if(disc_cdaccess)
444
{
445
delete disc_cdaccess;
446
disc_cdaccess = NULL;
447
}
448
449
throw;
450
}
451
}
452
453
454
CDIF_MT::~CDIF_MT()
455
{
456
bool thread_deaded_failed = false;
457
458
try
459
{
460
ReadThreadQueue.Write(CDIF_Message(CDIF_MSG_DIEDIEDIE));
461
}
462
catch(std::exception &e)
463
{
464
MDFND_PrintError(e.what());
465
thread_deaded_failed = true;
466
}
467
468
if(!thread_deaded_failed)
469
MDFND_WaitThread(CDReadThread, NULL);
470
471
if(SBMutex)
472
{
473
MDFND_DestroyMutex(SBMutex);
474
SBMutex = NULL;
475
}
476
477
if(SBCond)
478
{
479
MDFND_DestroyCond(SBCond);
480
SBCond = NULL;
481
}
482
483
if(disc_cdaccess)
484
{
485
delete disc_cdaccess;
486
disc_cdaccess = NULL;
487
}
488
}
489
#endif //WANT_QUEUE
490
491
bool CDIF::ValidateRawSector(uint8 *buf)
492
{
493
int mode = buf[12 + 3];
494
495
if(mode != 0x1 && mode != 0x2)
496
return(false);
497
498
if(!edc_lec_check_and_correct(buf, mode == 2))
499
return(false);
500
501
return(true);
502
}
503
504
#ifdef WANT_QUEUE
505
bool CDIF_MT::ReadRawSector(uint8 *buf, int32 lba)
506
{
507
bool found = FALSE;
508
bool error_condition = false;
509
510
if(UnrecoverableError)
511
{
512
memset(buf, 0, 2352 + 96);
513
return(false);
514
}
515
516
if(lba < LBA_Read_Minimum || lba > LBA_Read_Maximum)
517
{
518
printf("Attempt to read sector out of bounds; LBA=%d\n", lba);
519
memset(buf, 0, 2352 + 96);
520
return(false);
521
}
522
523
ReadThreadQueue.Write(CDIF_Message(CDIF_MSG_READ_SECTOR, lba));
524
525
//
526
//
527
//
528
MDFND_LockMutex(SBMutex);
529
530
do
531
{
532
for(int i = 0; i < SBSize; i++)
533
{
534
if(SectorBuffers[i].valid && SectorBuffers[i].lba == lba)
535
{
536
error_condition = SectorBuffers[i].error;
537
memcpy(buf, SectorBuffers[i].data, 2352 + 96);
538
found = TRUE;
539
}
540
}
541
542
if(!found)
543
{
544
//int32 swt = MDFND_GetTime();
545
MDFND_WaitCond(SBCond, SBMutex);
546
//printf("SB Waited: %d\n", MDFND_GetTime() - swt);
547
}
548
} while(!found);
549
550
MDFND_UnlockMutex(SBMutex);
551
//
552
//
553
//
554
555
556
return(!error_condition);
557
}
558
559
bool CDIF_MT::ReadRawSectorPWOnly(uint8* pwbuf, int32 lba, bool hint_fullread)
560
{
561
if(UnrecoverableError)
562
{
563
memset(pwbuf, 0, 96);
564
return(false);
565
}
566
567
if(lba < LBA_Read_Minimum || lba > LBA_Read_Maximum)
568
{
569
printf("Attempt to read sector out of bounds; LBA=%d\n", lba);
570
memset(pwbuf, 0, 96);
571
return(false);
572
}
573
574
if(disc_cdaccess->Fast_Read_Raw_PW_TSRE(pwbuf, lba))
575
{
576
if(hint_fullread)
577
ReadThreadQueue.Write(CDIF_Message(CDIF_MSG_READ_SECTOR, lba));
578
579
return(true);
580
}
581
else
582
{
583
uint8 tmpbuf[2352 + 96];
584
bool ret;
585
586
ret = ReadRawSector(tmpbuf, lba);
587
memcpy(pwbuf, tmpbuf + 2352, 96);
588
589
return ret;
590
}
591
}
592
593
void CDIF_MT::HintReadSector(int32 lba)
594
{
595
if(UnrecoverableError)
596
return;
597
598
ReadThreadQueue.Write(CDIF_Message(CDIF_MSG_READ_SECTOR, lba));
599
}
600
#endif //WANT_QUEUE
601
602
603
int CDIF::ReadSector(uint8* buf, int32 lba, uint32 sector_count, bool suppress_uncorrectable_message)
604
{
605
int ret = 0;
606
607
if(UnrecoverableError)
608
return(false);
609
610
while(sector_count--)
611
{
612
uint8 tmpbuf[2352 + 96];
613
614
if(!ReadRawSector(tmpbuf, lba))
615
{
616
puts("CDIF Raw Read error");
617
return(FALSE_0);
618
}
619
620
if(!ValidateRawSector(tmpbuf))
621
{
622
if(!suppress_uncorrectable_message)
623
{
624
printf(_("Uncorrectable data at sector %d"), lba);
625
}
626
627
return(false);
628
}
629
630
const int mode = tmpbuf[12 + 3];
631
632
if(!ret)
633
ret = mode;
634
635
if(mode == 1)
636
{
637
memcpy(buf, &tmpbuf[12 + 4], 2048);
638
}
639
else if(mode == 2)
640
{
641
memcpy(buf, &tmpbuf[12 + 4 + 8], 2048);
642
}
643
else
644
{
645
printf("CDIF_ReadSector() invalid sector type at LBA=%u\n", (unsigned int)lba);
646
return(false);
647
}
648
649
buf += 2048;
650
lba++;
651
}
652
653
return(ret);
654
}
655
656
//
657
//
658
// Single-threaded implementation follows.
659
//
660
//
661
662
CDIF_ST::CDIF_ST(CDAccess *cda) : disc_cdaccess(cda)
663
{
664
//puts("***WARNING USING SINGLE-THREADED CD READER***");
665
666
UnrecoverableError = false;
667
668
disc_cdaccess->Read_TOC(&disc_toc);
669
670
if(disc_toc.first_track < 1 || disc_toc.last_track > 99 || disc_toc.first_track > disc_toc.last_track)
671
{
672
throw(MDFN_Error(0, _("TOC first(%d)/last(%d) track numbers bad."), disc_toc.first_track, disc_toc.last_track));
673
}
674
}
675
676
CDIF_ST::~CDIF_ST()
677
{
678
if(disc_cdaccess)
679
{
680
delete disc_cdaccess;
681
disc_cdaccess = NULL;
682
}
683
}
684
685
void CDIF_ST::HintReadSector(int32 lba)
686
{
687
// TODO: disc_cdaccess seek hint? (probably not, would require asynchronousitycamel)
688
}
689
690
bool CDIF_ST::ReadRawSector(uint8 *buf, int32 lba)
691
{
692
if(UnrecoverableError)
693
{
694
memset(buf, 0, 2352 + 96);
695
return(false);
696
}
697
698
if(lba < LBA_Read_Minimum || lba > LBA_Read_Maximum)
699
{
700
printf("Attempt to read sector out of bounds; LBA=%d\n", lba);
701
memset(buf, 0, 2352 + 96);
702
return(false);
703
}
704
705
try
706
{
707
disc_cdaccess->Read_Raw_Sector(buf, lba);
708
}
709
catch(std::exception &e)
710
{
711
printf(_("Sector %u read error: %s"), lba, e.what());
712
memset(buf, 0, 2352 + 96);
713
return(false);
714
}
715
716
return(true);
717
}
718
719
bool CDIF_ST::ReadRawSectorPWOnly(uint8* pwbuf, int32 lba, bool hint_fullread)
720
{
721
if(UnrecoverableError)
722
{
723
memset(pwbuf, 0, 96);
724
return(false);
725
}
726
727
if(lba < LBA_Read_Minimum || lba > LBA_Read_Maximum)
728
{
729
printf("Attempt to read sector out of bounds; LBA=%d\n", lba);
730
memset(pwbuf, 0, 96);
731
return(false);
732
}
733
734
if(disc_cdaccess->Fast_Read_Raw_PW_TSRE(pwbuf, lba))
735
return(true);
736
else
737
{
738
uint8 tmpbuf[2352 + 96];
739
bool ret;
740
741
ret = ReadRawSector(tmpbuf, lba);
742
memcpy(pwbuf, tmpbuf + 2352, 96);
743
744
return ret;
745
}
746
}
747
748
class CDIF_Stream_Thing : public Stream
749
{
750
public:
751
752
CDIF_Stream_Thing(CDIF *cdintf_arg, uint32 lba_arg, uint32 sector_count_arg);
753
~CDIF_Stream_Thing();
754
755
virtual uint64 attributes(void) override;
756
757
virtual uint64 read(void *data, uint64 count, bool error_on_eos = true) override;
758
virtual void write(const void *data, uint64 count) override;
759
virtual void truncate(uint64 length) override;
760
761
virtual void seek(int64 offset, int whence) override;
762
virtual uint64 tell(void) override;
763
virtual uint64 size(void) override;
764
virtual void flush(void) override;
765
virtual void close(void) override;
766
767
private:
768
CDIF *cdintf;
769
const uint32 start_lba;
770
const uint32 sector_count;
771
int64 position;
772
};
773
774
CDIF_Stream_Thing::CDIF_Stream_Thing(CDIF *cdintf_arg, uint32 start_lba_arg, uint32 sector_count_arg) : cdintf(cdintf_arg), start_lba(start_lba_arg), sector_count(sector_count_arg)
775
{
776
777
}
778
779
CDIF_Stream_Thing::~CDIF_Stream_Thing()
780
{
781
782
}
783
784
uint64 CDIF_Stream_Thing::attributes(void)
785
{
786
return(ATTRIBUTE_READABLE | ATTRIBUTE_SEEKABLE);
787
}
788
789
uint64 CDIF_Stream_Thing::read(void *data, uint64 count, bool error_on_eos)
790
{
791
if(count > (((uint64)sector_count * 2048) - position))
792
{
793
if(error_on_eos)
794
{
795
throw MDFN_Error(0, "EOF");
796
}
797
798
count = ((uint64)sector_count * 2048) - position;
799
}
800
801
if(!count)
802
return(0);
803
804
for(uint64 rp = position; rp < (position + count); rp = (rp &~ 2047) + 2048)
805
{
806
uint8 buf[2048];
807
808
if(!cdintf->ReadSector(buf, start_lba + (rp / 2048), 1))
809
{
810
throw MDFN_Error(ErrnoHolder(EIO));
811
}
812
813
//::printf("Meow: %08llx -- %08llx\n", count, (rp - position) + std::min<uint64>(2048 - (rp & 2047), count - (rp - position)));
814
memcpy((uint8*)data + (rp - position), buf + (rp & 2047), std::min<uint64>(2048 - (rp & 2047), count - (rp - position)));
815
}
816
817
position += count;
818
819
return count;
820
}
821
822
void CDIF_Stream_Thing::write(const void *data, uint64 count)
823
{
824
throw MDFN_Error(ErrnoHolder(EBADF));
825
}
826
827
void CDIF_Stream_Thing::truncate(uint64 length)
828
{
829
throw MDFN_Error(ErrnoHolder(EBADF));
830
}
831
832
void CDIF_Stream_Thing::seek(int64 offset, int whence)
833
{
834
int64 new_position;
835
836
switch(whence)
837
{
838
default:
839
throw MDFN_Error(ErrnoHolder(EINVAL));
840
break;
841
842
case SEEK_SET:
843
new_position = offset;
844
break;
845
846
case SEEK_CUR:
847
new_position = position + offset;
848
break;
849
850
case SEEK_END:
851
new_position = ((int64)sector_count * 2048) + offset;
852
break;
853
}
854
855
if(new_position < 0 || new_position > ((int64)sector_count * 2048))
856
throw MDFN_Error(ErrnoHolder(EINVAL));
857
858
position = new_position;
859
}
860
861
uint64 CDIF_Stream_Thing::tell(void)
862
{
863
return position;
864
}
865
866
uint64 CDIF_Stream_Thing::size(void)
867
{
868
return(sector_count * 2048);
869
}
870
871
void CDIF_Stream_Thing::flush(void)
872
{
873
874
}
875
876
void CDIF_Stream_Thing::close(void)
877
{
878
879
}
880
881
882
Stream *CDIF::MakeStream(int32 lba, uint32 sector_count)
883
{
884
return new CDIF_Stream_Thing(this, lba, sector_count);
885
}
886
887
888
CDIF *CDIF_Open(const std::string& path, bool image_memcache)
889
{
890
CDAccess *cda = CDAccess_Open(path, image_memcache);
891
892
#ifdef WANT_QUEUE
893
if(!image_memcache)
894
return new CDIF_MT(cda);
895
else
896
#endif
897
return new CDIF_ST(cda);
898
}
899
900