Debian Codegraph @

src/dos/cdrom.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: cdrom.cpp,v 1.27 2009-04-26 18:24:36 qbix79 Exp $ */
20
21 // ******************************************************
22 // SDL CDROM
23 // ******************************************************
24
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
28
29 #include "dosbox.h"
30 #include "SDL.h"
31 #include "support.h"
32 #include "cdrom.h"
33
34 CDROM_Interface_SDL::CDROM_Interface_SDL(void) {
35 driveID = 0;
36 oldLeadOut = 0;
37 cd = 0;
38 }
39
40 CDROM_Interface_SDL::~CDROM_Interface_SDL(void) {
41 StopAudio();
42 SDL_CDClose(cd);
43 cd = 0;
44 }
45
46 bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
47 char buffer[512];
48 strcpy(buffer,path);
49 upcase(buffer);
50
51 int num = SDL_CDNumDrives();
52 if ((forceCD>=0) && (forceCD<num)) {
53 driveID = forceCD;
54 cd = SDL_CDOpen(driveID);
55 SDL_CDStatus(cd);
56 return true;
57 };
58
59 const char* cdname = 0;
60 for (int i=0; i<num; i++) {
61 cdname = SDL_CDName(i);
62 if (strcmp(buffer,cdname)==0) {
63 cd = SDL_CDOpen(i);
64 SDL_CDStatus(cd);
65 driveID = i;
66 return true;
67 };
68 };
69 return false;
70 }
71
72 bool CDROM_Interface_SDL::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) {
73
74 if (CD_INDRIVE(SDL_CDStatus(cd))) {
75 stTrack = 1;
76 end = cd->numtracks;
77 FRAMES_TO_MSF(cd->track[cd->numtracks].offset,&leadOut.min,&leadOut.sec,&leadOut.fr);
78 }
79 return CD_INDRIVE(SDL_CDStatus(cd));
80 }
81
82 bool CDROM_Interface_SDL::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
83 if (CD_INDRIVE(SDL_CDStatus(cd))) {
84 FRAMES_TO_MSF(cd->track[track-1].offset,&start.min,&start.sec,&start.fr);
85 attr = cd->track[track-1].type<<4;//sdl uses 0 for audio and 4 for data. instead of 0x00 and 0x40
86 }
87 return CD_INDRIVE(SDL_CDStatus(cd));
88 }
89
90 bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) {
91 if (CD_INDRIVE(SDL_CDStatus(cd))) {
92 track = cd->cur_track;
93 index = cd->cur_track;
94 attr = cd->track[track].type<<4;
95 FRAMES_TO_MSF(cd->cur_frame,&relPos.min,&relPos.sec,&relPos.fr);
96 FRAMES_TO_MSF(cd->cur_frame+cd->track[track].offset,&absPos.min,&absPos.sec,&absPos.fr);
97 }
98 return CD_INDRIVE(SDL_CDStatus(cd));
99 }
100
101 bool CDROM_Interface_SDL::GetAudioStatus(bool& playing, bool& pause){
102 if (CD_INDRIVE(SDL_CDStatus(cd))) {
103 playing = (cd->status==CD_PLAYING);
104 pause = (cd->status==CD_PAUSED);
105 }
106 return CD_INDRIVE(SDL_CDStatus(cd));
107 }
108
109 bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
110 SDL_CDStatus(cd);
111 mediaPresent = (cd->status!=CD_TRAYEMPTY) && (cd->status!=CD_ERROR);
112 mediaChanged = (oldLeadOut!=cd->track[cd->numtracks].offset);
113 trayOpen = !mediaPresent;
114 oldLeadOut = cd->track[cd->numtracks].offset;
115 if (mediaChanged) SDL_CDStatus(cd);
116 return true;
117 }
118
119 bool CDROM_Interface_SDL::PlayAudioSector(unsigned long start,unsigned long len) {
120 // Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
121 SDL_CDClose(cd);
122 cd = SDL_CDOpen(driveID);
123 bool success = (SDL_CDPlay(cd,start+150,len)==0);
124 return success;
125 }
126
127 bool CDROM_Interface_SDL::PauseAudio(bool resume) {
128 bool success;
129 if (resume) success = (SDL_CDResume(cd)==0);
130 else success = (SDL_CDPause (cd)==0);
131 return success;
132 }
133
134 bool CDROM_Interface_SDL::StopAudio(void) {
135 // Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
136 SDL_CDClose(cd);
137 cd = SDL_CDOpen(driveID);
138 bool success = (SDL_CDStop(cd)==0);
139 return success;
140 }
141
142 bool CDROM_Interface_SDL::LoadUnloadMedia(bool unload) {
143 bool success = (SDL_CDEject(cd)==0);
144 return success;
145 }
146
147 int CDROM_GetMountType(char* path, int forceCD) {
148 // 0 - physical CDROM
149 // 1 - Iso file
150 // 2 - subdirectory
151 // 1. Smells like a real cdrom
152 // if ((strlen(path)<=3) && (path[2]=='\\') && (strchr(path,'\\')==strrchr(path,'\\')) && (GetDriveType(path)==DRIVE_CDROM)) return 0;
153
154 const char* cdName;
155 char buffer[512];
156 strcpy(buffer,path);
157 #if defined (WIN32) || defined(OS2)
158 upcase(buffer);
159 #endif
160
161 int num = SDL_CDNumDrives();
162 // If cd drive is forced then check if its in range and return 0
163 if ((forceCD>=0) && (forceCD<num)) {
164 LOG(LOG_ALL,LOG_ERROR)("CDROM: Using drive %d",forceCD);
165 return 0;
166 }
167
168 // compare names
169 for (int i=0; i<num; i++) {
170 cdName = SDL_CDName(i);
171 if (strcmp(buffer,cdName)==0) return 0;
172 };
173
174 // Detect ISO
175 struct stat file_stat;
176 if ((stat(path, &file_stat) == 0) && (file_stat.st_mode & S_IFREG)) return 1;
177 return 2;
178 }
179
180 // ******************************************************
181 // Fake CDROM
182 // ******************************************************
183
184 bool CDROM_Interface_Fake :: GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) {
185 stTrack = end = 1;
186 leadOut.min = 60;
187 leadOut.sec = leadOut.fr = 0;
188 return true;
189 }
190
191 bool CDROM_Interface_Fake :: GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
192 if (track>1) return false;
193 start.min = start.fr = 0;
194 start.sec = 2;
195 attr = 0x60; // data / permitted
196 return true;
197 }
198
199 bool CDROM_Interface_Fake :: GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos){
200 attr = 0;
201 track = index = 1;
202 relPos.min = relPos.fr = 0; relPos.sec = 2;
203 absPos.min = absPos.fr = 0; absPos.sec = 2;
204 return true;
205 }
206
207 bool CDROM_Interface_Fake :: GetAudioStatus(bool& playing, bool& pause) {
208 playing = pause = false;
209 return true;
210 }
211
212 bool CDROM_Interface_Fake :: GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
213 mediaPresent = true;
214 mediaChanged = false;
215 trayOpen = false;
216 return true;
217 }
218
219