1 /******************************************************************************/ 2 /* Mednafen - Multi-system Emulator */ 3 /******************************************************************************/ 4 /* CDInterface.h: 5 ** Copyright (C) 2018 Mednafen Team 6 ** 7 ** This program is free software; you can redistribute it and/or 8 ** modify it under the terms of the GNU General Public License 9 ** as published by the Free Software Foundation; either version 2 10 ** of the License, or (at your option) any later version. 11 ** 12 ** This program is distributed in the hope that it will be useful, 13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ** GNU General Public License for more details. 16 ** 17 ** You should have received a copy of the GNU General Public License 18 ** along with this program; if not, write to the Free Software Foundation, Inc., 19 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef __MDFN_CDROM_CDINTERFACE_H 23 #define __MDFN_CDROM_CDINTERFACE_H 24 25 #include <mednafen/types.h> 26 #include <mednafen/Stream.h> 27 #include <mednafen/cdrom/CDUtility.h> 28 29 namespace Mednafen 30 { 31 32 class CDInterface 33 { 34 public: 35 36 // 37 // Creates a multi-threaded or single-threaded CD interface object, depending 38 // on the value of "image_memcache", to read the CD image at "path". 39 // 40 static CDInterface* Open(VirtualFS* vfs, const std::string& path, bool image_memcache, const uint64 affinity); 41 42 CDInterface(); 43 virtual ~CDInterface(); 44 45 // 46 // LBA range limits for sector reading functions; MSF 00:00:00 to 99:57:74 47 // 48 enum : int32 { LBA_Read_Minimum = -150 }; 49 enum : int32 { LBA_Read_Maximum = 449849 }; 50 51 // 52 // Hint that the sector's data will be needed soon(ish); intended to be 53 // called at the start of an emulated seek sequence. 54 // 55 virtual void HintReadSector(int32 lba) = 0; 56 57 // 58 // Reads 2352+96 bytes of data into buf. The data for "data" sectors is 59 // currently returned descrambled(TODO: probably want to change that someday). 60 // 61 // May block for a while, especially for non-sequential reads, though if an 62 // appropriate call was made to HintReadSector() early enough, it shouldn't 63 // be too bad. 64 // 65 virtual bool ReadRawSector(uint8* buf, int32 lba) = 0; 66 67 // 68 // Reads 96 bytes of raw subchannel PW data into pwbuf. Will be relatively 69 // fast and nonblocking, unless the underlying CD (image) access method does 70 // not permit it. 71 // 72 // Intended to be used for seek emulation, but can be used for other purposes 73 // as appropriate. 74 // 75 virtual bool ReadRawSectorPWOnly(uint8* pwbuf, int32 lba, bool hint_fullread) = 0; 76 77 // For experimental and special use cases. 78 virtual bool NonDeterministic_CheckSectorReady(int32 lba); 79 ReadTOC(CDUtility::TOC * read_target)80 INLINE void ReadTOC(CDUtility::TOC* read_target) 81 { 82 *read_target = disc_toc; 83 } 84 85 // 86 // Reads 2048 bytes per mode 1 and mode 2 form 1 sectors. 87 // 88 // Returns the mode(1 or 2) of the first sector read starting 89 // from the LBA specified, 0 on error(or when sector_count == 0). 90 // 91 // Calls ReadRawSector() internally. 92 // 93 uint8 ReadSectors(uint8* buf, int32 lba, uint32 sector_count); 94 95 // 96 // 'Stream' wrapper for mode 1 and mode 2 form 1 sectors. 97 // 98 // Specify the start LBA and the number of sectors from that position 99 // to be accessible by the Stream object. 100 // 101 // No reference counting is done, so be sure to delete the returned 102 // Stream object BEFORE destroying the underlying CDInterface object. 103 // 104 Stream* MakeStream(int32 lba, uint32 sector_count); 105 106 protected: 107 bool UnrecoverableError; 108 CDUtility::TOC disc_toc; 109 }; 110 111 } 112 #endif 113