Debian Codegraph @

src/dos/cdrom.h

raw symbols SCIP
1
2 #ifndef __CDROM_INTERFACE__
3 #define __CDROM_INTERFACE__
4
5 #define MAX_ASPI_CDROM 5
6
7 #include <string.h>
8 #include <string>
9 #include <iostream>
10 #include <vector>
11 #include <fstream>
12 #include <sstream>
13 #include "dosbox.h"
14 #include "mem.h"
15 #include "mixer.h"
16 #include "SDL.h"
17 #include "SDL_thread.h"
18
19 #if defined(C_SDL_SOUND)
20 #include "SDL_sound.h"
21 #endif
22
23 #define RAW_SECTOR_SIZE 2352
24 #define COOKED_SECTOR_SIZE 2048
25
26 enum { CDROM_USE_SDL, CDROM_USE_ASPI, CDROM_USE_IOCTL_DIO, CDROM_USE_IOCTL_DX, CDROM_USE_IOCTL_MCI };
27
28 typedef struct SMSF {
29 unsigned char min;
30 unsigned char sec;
31 unsigned char fr;
32 } TMSF;
33
34 extern int CDROM_GetMountType(char* path, int force);
35
36 class CDROM_Interface
37 {
38 public:
39 // CDROM_Interface (void);
40 virtual ~CDROM_Interface (void) {};
41
42 virtual bool SetDevice (char* path, int forceCD) = 0;
43
44 virtual bool GetUPC (unsigned char& attr, char* upc) = 0;
45
46 virtual bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut) = 0;
47 virtual bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr) = 0;
48 virtual bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) = 0;
49 virtual bool GetAudioStatus (bool& playing, bool& pause) = 0;
50 virtual bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen) = 0;
51
52 virtual bool PlayAudioSector (unsigned long start,unsigned long len) = 0;
53 virtual bool PauseAudio (bool resume) = 0;
54 virtual bool StopAudio (void) = 0;
55
56 virtual bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num) = 0;
57
58 virtual bool LoadUnloadMedia (bool unload) = 0;
59
60 virtual void InitNewMedia (void) {};
61 };
62
63 class CDROM_Interface_SDL : public CDROM_Interface
64 {
65 public:
66 CDROM_Interface_SDL (void);
67 virtual ~CDROM_Interface_SDL(void);
68
69 virtual bool SetDevice (char* path, int forceCD);
70 virtual bool GetUPC (unsigned char& attr, char* upc) { attr = 0; strcpy(upc,"UPC"); return true; };
71 virtual bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
72 virtual bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
73 virtual bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
74 virtual bool GetAudioStatus (bool& playing, bool& pause);
75 virtual bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
76 virtual bool PlayAudioSector (unsigned long start,unsigned long len);
77 virtual bool PauseAudio (bool resume);
78 virtual bool StopAudio (void);
79 virtual bool ReadSectors (PhysPt /*buffer*/, bool /*raw*/, unsigned long /*sector*/, unsigned long /*num*/) { return false; };
80 virtual bool LoadUnloadMedia (bool unload);
81
82 private:
83 bool Open (void);
84 void Close (void);
85
86 SDL_CD* cd;
87 int driveID;
88 Uint32 oldLeadOut;
89 };
90
91 class CDROM_Interface_Fake : public CDROM_Interface
92 {
93 public:
94 bool SetDevice (char* /*path*/, int /*forceCD*/) { return true; };
95 bool GetUPC (unsigned char& attr, char* upc) { attr = 0; strcpy(upc,"UPC"); return true; };
96 bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
97 bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
98 bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
99 bool GetAudioStatus (bool& playing, bool& pause);
100 bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
101 bool PlayAudioSector (unsigned long /*start*/,unsigned long /*len*/) { return true; };
102 bool PauseAudio (bool /*resume*/) { return true; };
103 bool StopAudio (void) { return true; };
104 bool ReadSectors (PhysPt /*buffer*/, bool /*raw*/, unsigned long /*sector*/, unsigned long /*num*/) { return true; };
105 bool LoadUnloadMedia (bool /*unload*/) { return true; };
106 };
107
108 class CDROM_Interface_Image : public CDROM_Interface
109 {
110 private:
111 class TrackFile {
112 public:
113 virtual bool read(Bit8u *buffer, int seek, int count) = 0;
114 virtual int getLength() = 0;
115 virtual ~TrackFile() { };
116 };
117
118 class BinaryFile : public TrackFile {
119 public:
120 BinaryFile(const char *filename, bool &error);
121 ~BinaryFile();
122 bool read(Bit8u *buffer, int seek, int count);
123 int getLength();
124 private:
125 BinaryFile();
126 std::ifstream *file;
127 };
128
129 #if defined(C_SDL_SOUND)
130 class AudioFile : public TrackFile {
131 public:
132 AudioFile(const char *filename, bool &error);
133 ~AudioFile();
134 bool read(Bit8u *buffer, int seek, int count);
135 int getLength();
136 private:
137 AudioFile();
138 Sound_Sample *sample;
139 int lastCount;
140 int lastSeek;
141 };
142 #endif
143
144 struct Track {
145 int number;
146 int attr;
147 int start;
148 int length;
149 int skip;
150 int sectorSize;
151 bool mode2;
152 TrackFile *file;
153 };
154
155 public:
156 CDROM_Interface_Image (Bit8u subUnit);
157 virtual ~CDROM_Interface_Image (void);
158 void InitNewMedia (void);
159 bool SetDevice (char* path, int forceCD);
160 bool GetUPC (unsigned char& attr, char* upc);
161 bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
162 bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
163 bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
164 bool GetAudioStatus (bool& playing, bool& pause);
165 bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
166 bool PlayAudioSector (unsigned long start,unsigned long len);
167 bool PauseAudio (bool resume);
168 bool StopAudio (void);
169 bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num);
170 bool LoadUnloadMedia (bool unload);
171 bool ReadSector (Bit8u *buffer, bool raw, unsigned long sector);
172 bool HasDataTrack (void);
173
174 static CDROM_Interface_Image* images[26];
175
176 private:
177 // player
178 static void CDAudioCallBack(Bitu len);
179 int GetTrack(int sector);
180
181 static struct imagePlayer {
182 CDROM_Interface_Image *cd;
183 MixerChannel *channel;
184 SDL_mutex *mutex;
185 Bit8u buffer[8192];
186 int bufLen;
187 int currFrame;
188 int targetFrame;
189 bool isPlaying;
190 bool isPaused;
191 } player;
192
193 void ClearTracks();
194 bool LoadIsoFile(char *filename);
195 bool CanReadPVD(TrackFile *file, int sectorSize, bool mode2);
196 // cue sheet processing
197 bool LoadCueSheet(char *cuefile);
198 bool GetRealFileName(std::string& filename, std::string& pathname);
199 bool GetCueKeyword(std::string &keyword, std::istream &in);
200 bool GetCueFrame(int &frames, std::istream &in);
201 bool GetCueString(std::string &str, std::istream &in);
202 bool AddTrack(Track &curr, int &shift, int prestart, int &totalPregap, int currPregap);
203
204 static int refCount;
205 std::vector<Track> tracks;
206 typedef std::vector<Track>::iterator track_it;
207 std::string mcn;
208 Bit8u subUnit;
209 };
210
211 #if defined (WIN32) /* Win 32 */
212
213 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
214
215 #include <windows.h>
216 #include "wnaspi32.h" // Aspi stuff
217
218 class CDROM_Interface_Aspi : public CDROM_Interface
219 {
220 public:
221 CDROM_Interface_Aspi (void);
222 virtual ~CDROM_Interface_Aspi(void);
223
224 bool SetDevice (char* path, int forceCD);
225
226 bool GetUPC (unsigned char& attr, char* upc);
227
228 bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
229 bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
230 bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
231 bool GetAudioStatus (bool& playing, bool& pause);
232 bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
233
234 bool PlayAudioSector (unsigned long start,unsigned long len);
235 bool PauseAudio (bool resume);
236 bool StopAudio (void);
237
238 bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num);
239
240 bool LoadUnloadMedia (bool unload);
241
242 private:
243 DWORD GetTOC (LPTOC toc);
244 HANDLE OpenIOCTLFile (char cLetter, BOOL bAsync);
245 void GetIOCTLAdapter (HANDLE hF,int * iDA,int * iDT,int * iDL);
246 bool ScanRegistryFindKey (HKEY& hKeyBase);
247 bool ScanRegistry (HKEY& hKeyBase);
248 BYTE GetHostAdapter (char* hardwareID);
249 bool GetVendor (BYTE HA_num, BYTE SCSI_Id, BYTE SCSI_Lun, char* szBuffer);
250
251 // ASPI stuff
252 BYTE haId;
253 BYTE target;
254 BYTE lun;
255 char letter;
256
257 // Windows stuff
258 HINSTANCE hASPI;
259 HANDLE hEvent; // global event
260 DWORD (*pGetASPI32SupportInfo) (void); // ptrs to aspi funcs
261 DWORD (*pSendASPI32Command) (LPSRB);
262 TMSF oldLeadOut;
263 };
264
265 class CDROM_Interface_Ioctl : public CDROM_Interface
266 {
267 public:
268 enum cdioctl_cdatype { CDIOCTL_CDA_DIO, CDIOCTL_CDA_MCI, CDIOCTL_CDA_DX };
269 cdioctl_cdatype cdioctl_cda_selected;
270
271 CDROM_Interface_Ioctl (cdioctl_cdatype ioctl_cda);
272 virtual ~CDROM_Interface_Ioctl(void);
273
274 bool SetDevice (char* path, int forceCD);
275
276 bool GetUPC (unsigned char& attr, char* upc);
277
278 bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
279 bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
280 bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
281 bool GetAudioStatus (bool& playing, bool& pause);
282 bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
283
284 bool PlayAudioSector (unsigned long start,unsigned long len);
285 bool PauseAudio (bool resume);
286 bool StopAudio (void);
287
288 bool ReadSector (Bit8u *buffer, bool raw, unsigned long sector);
289 bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num);
290
291 bool LoadUnloadMedia (bool unload);
292
293 void InitNewMedia (void) { Close(); Open(); };
294 private:
295
296 bool Open (void);
297 void Close (void);
298
299 char pathname[32];
300 HANDLE hIOCTL;
301 TMSF oldLeadOut;
302
303
304 /* track start/length data */
305 bool track_start_valid;
306 int track_start_first,track_start_last;
307 int track_start[128];
308
309 bool GetAudioTracksAll (void);
310
311
312 /* mci audio cd interface */
313 bool use_mciplay;
314 int mci_devid;
315
316 bool mci_CDioctl (UINT msg, DWORD flags, void *arg);
317 bool mci_CDOpen (char drive);
318 bool mci_CDClose (void);
319 bool mci_CDPlay (int start, int length);
320 bool mci_CDPause (void);
321 bool mci_CDResume (void);
322 bool mci_CDStop (void);
323 int mci_CDStatus (void);
324 bool mci_CDPosition (int *position);
325
326
327 /* digital audio extraction cd interface */
328 static void dx_CDAudioCallBack(Bitu len);
329
330 bool use_dxplay;
331 static struct dxPlayer {
332 CDROM_Interface_Ioctl *cd;
333 MixerChannel *channel;
334 SDL_mutex *mutex;
335 Bit8u buffer[8192];
336 int bufLen;
337 int currFrame;
338 int targetFrame;
339 bool isPlaying;
340 bool isPaused;
341 } player;
342
343 };
344
345 #endif /* WIN 32 */
346
347 #if defined (LINUX) || defined(OS2)
348
349 class CDROM_Interface_Ioctl : public CDROM_Interface_SDL
350 {
351 public:
352 CDROM_Interface_Ioctl (void);
353
354 bool SetDevice (char* path, int forceCD);
355 bool GetUPC (unsigned char& attr, char* upc);
356 bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num);
357
358 private:
359 char device_name[512];
360 };
361
362 #endif /* LINUX */
363
364 #endif /* __CDROM_INTERFACE__ */