comparison src/cdrom/freebsd/SDL_syscdrom.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 92947e3a18db
children e27bdcc80744
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
35 #include "SDL_cdrom.h" 35 #include "SDL_cdrom.h"
36 #include "../SDL_syscdrom.h" 36 #include "../SDL_syscdrom.h"
37 37
38 38
39 /* The maximum number of CD-ROM drives we'll detect */ 39 /* The maximum number of CD-ROM drives we'll detect */
40 #define MAX_DRIVES 16 40 #define MAX_DRIVES 16
41 41
42 /* A list of available CD-ROM drives */ 42 /* A list of available CD-ROM drives */
43 static char *SDL_cdlist[MAX_DRIVES]; 43 static char *SDL_cdlist[MAX_DRIVES];
44 static dev_t SDL_cdmode[MAX_DRIVES]; 44 static dev_t SDL_cdmode[MAX_DRIVES];
45 45
46 /* The system-dependent CD control functions */ 46 /* The system-dependent CD control functions */
47 static const char *SDL_SYS_CDName(int drive); 47 static const char *SDL_SYS_CDName(int drive);
48 static int SDL_SYS_CDOpen(int drive); 48 static int SDL_SYS_CDOpen(int drive);
49 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); 49 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
50 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); 50 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
51 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); 51 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
52 static int SDL_SYS_CDPause(SDL_CD *cdrom); 52 static int SDL_SYS_CDPause(SDL_CD * cdrom);
53 static int SDL_SYS_CDResume(SDL_CD *cdrom); 53 static int SDL_SYS_CDResume(SDL_CD * cdrom);
54 static int SDL_SYS_CDStop(SDL_CD *cdrom); 54 static int SDL_SYS_CDStop(SDL_CD * cdrom);
55 static int SDL_SYS_CDEject(SDL_CD *cdrom); 55 static int SDL_SYS_CDEject(SDL_CD * cdrom);
56 static void SDL_SYS_CDClose(SDL_CD *cdrom); 56 static void SDL_SYS_CDClose(SDL_CD * cdrom);
57 57
58 /* Some ioctl() errno values which occur when the tray is empty */ 58 /* Some ioctl() errno values which occur when the tray is empty */
59 #define ERRNO_TRAYEMPTY(errno) \ 59 #define ERRNO_TRAYEMPTY(errno) \
60 ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL)) 60 ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
61 61
62 /* Check a drive to see if it is a CD-ROM */ 62 /* Check a drive to see if it is a CD-ROM */
63 static int CheckDrive(char *drive, struct stat *stbuf) 63 static int
64 { 64 CheckDrive(char *drive, struct stat *stbuf)
65 int is_cd, cdfd; 65 {
66 struct ioc_read_subchannel info; 66 int is_cd, cdfd;
67 67 struct ioc_read_subchannel info;
68 /* If it doesn't exist, return -1 */ 68
69 if ( stat(drive, stbuf) < 0 ) { 69 /* If it doesn't exist, return -1 */
70 return(-1); 70 if (stat(drive, stbuf) < 0) {
71 } 71 return (-1);
72 72 }
73 /* If it does exist, verify that it's an available CD-ROM */ 73
74 is_cd = 0; 74 /* If it does exist, verify that it's an available CD-ROM */
75 if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { 75 is_cd = 0;
76 cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); 76 if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
77 if ( cdfd >= 0 ) { 77 cdfd = open(drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0);
78 info.address_format = CD_MSF_FORMAT; 78 if (cdfd >= 0) {
79 info.data_format = CD_CURRENT_POSITION; 79 info.address_format = CD_MSF_FORMAT;
80 info.data_len = 0; 80 info.data_format = CD_CURRENT_POSITION;
81 info.data = NULL; 81 info.data_len = 0;
82 /* Under Linux, EIO occurs when a disk is not present. 82 info.data = NULL;
83 This isn't 100% reliable, so we use the USE_MNTENT 83 /* Under Linux, EIO occurs when a disk is not present.
84 code above instead. 84 This isn't 100% reliable, so we use the USE_MNTENT
85 */ 85 code above instead.
86 if ( (ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) || 86 */
87 ERRNO_TRAYEMPTY(errno) ) { 87 if ((ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) ||
88 is_cd = 1; 88 ERRNO_TRAYEMPTY(errno)) {
89 } 89 is_cd = 1;
90 close(cdfd); 90 }
91 } 91 close(cdfd);
92 } 92 }
93 return(is_cd); 93 }
94 return (is_cd);
94 } 95 }
95 96
96 /* Add a CD-ROM drive to our list of valid drives */ 97 /* Add a CD-ROM drive to our list of valid drives */
97 static void AddDrive(char *drive, struct stat *stbuf) 98 static void
98 { 99 AddDrive(char *drive, struct stat *stbuf)
99 int i; 100 {
100 101 int i;
101 if ( SDL_numcds < MAX_DRIVES ) { 102
102 /* Check to make sure it's not already in our list. 103 if (SDL_numcds < MAX_DRIVES) {
103 This can happen when we see a drive via symbolic link. 104 /* Check to make sure it's not already in our list.
104 */ 105 This can happen when we see a drive via symbolic link.
105 for ( i=0; i<SDL_numcds; ++i ) { 106 */
106 if ( stbuf->st_rdev == SDL_cdmode[i] ) { 107 for (i = 0; i < SDL_numcds; ++i) {
108 if (stbuf->st_rdev == SDL_cdmode[i]) {
107 #ifdef DEBUG_CDROM 109 #ifdef DEBUG_CDROM
108 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); 110 fprintf(stderr, "Duplicate drive detected: %s == %s\n",
111 drive, SDL_cdlist[i]);
109 #endif 112 #endif
110 return; 113 return;
111 } 114 }
112 } 115 }
113 116
114 /* Add this drive to our list */ 117 /* Add this drive to our list */
115 i = SDL_numcds; 118 i = SDL_numcds;
116 SDL_cdlist[i] = SDL_strdup(drive); 119 SDL_cdlist[i] = SDL_strdup(drive);
117 if ( SDL_cdlist[i] == NULL ) { 120 if (SDL_cdlist[i] == NULL) {
118 SDL_OutOfMemory(); 121 SDL_OutOfMemory();
119 return; 122 return;
120 } 123 }
121 SDL_cdmode[i] = stbuf->st_rdev; 124 SDL_cdmode[i] = stbuf->st_rdev;
122 ++SDL_numcds; 125 ++SDL_numcds;
123 #ifdef DEBUG_CDROM 126 #ifdef DEBUG_CDROM
124 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); 127 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
125 #endif 128 #endif
126 } 129 }
127 } 130 }
128 131
129 int SDL_SYS_CDInit(void) 132 int
130 { 133 SDL_SYS_CDInit(void)
131 /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c 134 {
132 /dev/matcd?c /dev/mcd?c /dev/scd?c */ 135 /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c
133 static char *checklist[] = { 136 /dev/matcd?c /dev/mcd?c /dev/scd?c */
134 "cdrom", "?0 cd?", "?0 acd?", "?0 matcd?", "?0 mcd?", "?0 scd?",NULL 137 static char *checklist[] = {
135 }; 138 "cdrom", "?0 cd?", "?0 acd?", "?0 matcd?", "?0 mcd?", "?0 scd?", NULL
136 char *SDLcdrom; 139 };
137 int i, j, exists; 140 char *SDLcdrom;
138 char drive[32]; 141 int i, j, exists;
139 struct stat stbuf; 142 char drive[32];
140 143 struct stat stbuf;
141 /* Fill in our driver capabilities */ 144
142 SDL_CDcaps.Name = SDL_SYS_CDName; 145 /* Fill in our driver capabilities */
143 SDL_CDcaps.Open = SDL_SYS_CDOpen; 146 SDL_CDcaps.Name = SDL_SYS_CDName;
144 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; 147 SDL_CDcaps.Open = SDL_SYS_CDOpen;
145 SDL_CDcaps.Status = SDL_SYS_CDStatus; 148 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
146 SDL_CDcaps.Play = SDL_SYS_CDPlay; 149 SDL_CDcaps.Status = SDL_SYS_CDStatus;
147 SDL_CDcaps.Pause = SDL_SYS_CDPause; 150 SDL_CDcaps.Play = SDL_SYS_CDPlay;
148 SDL_CDcaps.Resume = SDL_SYS_CDResume; 151 SDL_CDcaps.Pause = SDL_SYS_CDPause;
149 SDL_CDcaps.Stop = SDL_SYS_CDStop; 152 SDL_CDcaps.Resume = SDL_SYS_CDResume;
150 SDL_CDcaps.Eject = SDL_SYS_CDEject; 153 SDL_CDcaps.Stop = SDL_SYS_CDStop;
151 SDL_CDcaps.Close = SDL_SYS_CDClose; 154 SDL_CDcaps.Eject = SDL_SYS_CDEject;
152 155 SDL_CDcaps.Close = SDL_SYS_CDClose;
153 /* Look in the environment for our CD-ROM drive list */ 156
154 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ 157 /* Look in the environment for our CD-ROM drive list */
155 if ( SDLcdrom != NULL ) { 158 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
156 char *cdpath, *delim; 159 if (SDLcdrom != NULL) {
157 size_t len = SDL_strlen(SDLcdrom)+1; 160 char *cdpath, *delim;
158 cdpath = SDL_stack_alloc(char, len); 161 size_t len = SDL_strlen(SDLcdrom) + 1;
159 if ( cdpath != NULL ) { 162 cdpath = SDL_stack_alloc(char, len);
160 SDL_strlcpy(cdpath, SDLcdrom, len); 163 if (cdpath != NULL) {
161 SDLcdrom = cdpath; 164 SDL_strlcpy(cdpath, SDLcdrom, len);
162 do { 165 SDLcdrom = cdpath;
163 delim = SDL_strchr(SDLcdrom, ':'); 166 do {
164 if ( delim ) { 167 delim = SDL_strchr(SDLcdrom, ':');
165 *delim++ = '\0'; 168 if (delim) {
166 } 169 *delim++ = '\0';
167 if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { 170 }
168 AddDrive(SDLcdrom, &stbuf); 171 if (CheckDrive(SDLcdrom, &stbuf) > 0) {
169 } 172 AddDrive(SDLcdrom, &stbuf);
170 if ( delim ) { 173 }
171 SDLcdrom = delim; 174 if (delim) {
172 } else { 175 SDLcdrom = delim;
173 SDLcdrom = NULL; 176 } else {
174 } 177 SDLcdrom = NULL;
175 } while ( SDLcdrom ); 178 }
176 SDL_stack_free(cdpath); 179 }
177 } 180 while (SDLcdrom);
178 181 SDL_stack_free(cdpath);
179 /* If we found our drives, there's nothing left to do */ 182 }
180 if ( SDL_numcds > 0 ) { 183
181 return(0); 184 /* If we found our drives, there's nothing left to do */
182 } 185 if (SDL_numcds > 0) {
183 } 186 return (0);
184 187 }
185 /* Scan the system for CD-ROM drives */ 188 }
186 for ( i=0; checklist[i]; ++i ) { 189
187 if ( checklist[i][0] == '?' ) { 190 /* Scan the system for CD-ROM drives */
188 char *insert; 191 for (i = 0; checklist[i]; ++i) {
189 exists = 1; 192 if (checklist[i][0] == '?') {
190 for ( j=checklist[i][1]; exists; ++j ) { 193 char *insert;
191 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc", &checklist[i][3]); 194 exists = 1;
192 insert = SDL_strchr(drive, '?'); 195 for (j = checklist[i][1]; exists; ++j) {
193 if ( insert != NULL ) { 196 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc",
194 *insert = j; 197 &checklist[i][3]);
195 } 198 insert = SDL_strchr(drive, '?');
196 switch (CheckDrive(drive, &stbuf)) { 199 if (insert != NULL) {
197 /* Drive exists and is a CD-ROM */ 200 *insert = j;
198 case 1: 201 }
199 AddDrive(drive, &stbuf); 202 switch (CheckDrive(drive, &stbuf)) {
200 break; 203 /* Drive exists and is a CD-ROM */
201 /* Drive exists, but isn't a CD-ROM */ 204 case 1:
202 case 0: 205 AddDrive(drive, &stbuf);
203 break; 206 break;
204 /* Drive doesn't exist */ 207 /* Drive exists, but isn't a CD-ROM */
205 case -1: 208 case 0:
206 exists = 0; 209 break;
207 break; 210 /* Drive doesn't exist */
208 } 211 case -1:
209 } 212 exists = 0;
210 } else { 213 break;
211 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); 214 }
212 if ( CheckDrive(drive, &stbuf) > 0 ) { 215 }
213 AddDrive(drive, &stbuf); 216 } else {
214 } 217 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
215 } 218 checklist[i]);
216 } 219 if (CheckDrive(drive, &stbuf) > 0) {
217 return(0); 220 AddDrive(drive, &stbuf);
221 }
222 }
223 }
224 return (0);
218 } 225 }
219 226
220 /* General ioctl() CD-ROM command function */ 227 /* General ioctl() CD-ROM command function */
221 static int SDL_SYS_CDioctl(int id, int command, void *arg) 228 static int
222 { 229 SDL_SYS_CDioctl(int id, int command, void *arg)
223 int retval; 230 {
224 231 int retval;
225 retval = ioctl(id, command, arg); 232
226 if ( retval < 0 ) { 233 retval = ioctl(id, command, arg);
227 SDL_SetError("ioctl() error: %s", strerror(errno)); 234 if (retval < 0) {
228 } 235 SDL_SetError("ioctl() error: %s", strerror(errno));
229 return(retval); 236 }
230 } 237 return (retval);
231 238 }
232 static const char *SDL_SYS_CDName(int drive) 239
233 { 240 static const char *
234 return(SDL_cdlist[drive]); 241 SDL_SYS_CDName(int drive)
235 } 242 {
236 243 return (SDL_cdlist[drive]);
237 static int SDL_SYS_CDOpen(int drive) 244 }
238 { 245
239 return(open(SDL_cdlist[drive], (O_RDONLY|O_EXCL|O_NONBLOCK), 0)); 246 static int
240 } 247 SDL_SYS_CDOpen(int drive)
241 248 {
242 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) 249 return (open(SDL_cdlist[drive], (O_RDONLY | O_EXCL | O_NONBLOCK), 0));
243 { 250 }
244 struct ioc_toc_header toc; 251
245 int i, okay; 252 static int
246 struct ioc_read_toc_entry entry; 253 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
247 struct cd_toc_entry data; 254 {
248 255 struct ioc_toc_header toc;
249 okay = 0; 256 int i, okay;
250 if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0 ) { 257 struct ioc_read_toc_entry entry;
251 cdrom->numtracks = toc.ending_track-toc.starting_track+1; 258 struct cd_toc_entry data;
252 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { 259
253 cdrom->numtracks = SDL_MAX_TRACKS; 260 okay = 0;
254 } 261 if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0) {
255 /* Read all the track TOC entries */ 262 cdrom->numtracks = toc.ending_track - toc.starting_track + 1;
256 for ( i=0; i<=cdrom->numtracks; ++i ) { 263 if (cdrom->numtracks > SDL_MAX_TRACKS) {
257 if ( i == cdrom->numtracks ) { 264 cdrom->numtracks = SDL_MAX_TRACKS;
258 cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */ 265 }
259 } else { 266 /* Read all the track TOC entries */
260 cdrom->track[i].id = toc.starting_track+i; 267 for (i = 0; i <= cdrom->numtracks; ++i) {
261 } 268 if (i == cdrom->numtracks) {
262 entry.starting_track = cdrom->track[i].id; 269 cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */
263 entry.address_format = CD_MSF_FORMAT; 270 } else {
264 entry.data_len = sizeof(data); 271 cdrom->track[i].id = toc.starting_track + i;
265 entry.data = &data; 272 }
266 if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, 273 entry.starting_track = cdrom->track[i].id;
267 &entry) < 0 ) { 274 entry.address_format = CD_MSF_FORMAT;
268 break; 275 entry.data_len = sizeof(data);
269 } else { 276 entry.data = &data;
270 cdrom->track[i].type = data.control; 277 if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, &entry) < 0) {
271 cdrom->track[i].offset = MSF_TO_FRAMES( 278 break;
272 data.addr.msf.minute, 279 } else {
273 data.addr.msf.second, 280 cdrom->track[i].type = data.control;
274 data.addr.msf.frame); 281 cdrom->track[i].offset =
275 cdrom->track[i].length = 0; 282 MSF_TO_FRAMES(data.addr.msf.minute,
276 if ( i > 0 ) { 283 data.addr.msf.second, data.addr.msf.frame);
277 cdrom->track[i-1].length = 284 cdrom->track[i].length = 0;
278 cdrom->track[i].offset- 285 if (i > 0) {
279 cdrom->track[i-1].offset; 286 cdrom->track[i - 1].length =
280 } 287 cdrom->track[i].offset - cdrom->track[i - 1].offset;
281 } 288 }
282 } 289 }
283 if ( i == (cdrom->numtracks+1) ) { 290 }
284 okay = 1; 291 if (i == (cdrom->numtracks + 1)) {
285 } 292 okay = 1;
286 } 293 }
287 return(okay ? 0 : -1); 294 }
295 return (okay ? 0 : -1);
288 } 296 }
289 297
290 /* Get CD-ROM status */ 298 /* Get CD-ROM status */
291 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) 299 static CDstatus
292 { 300 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
293 CDstatus status; 301 {
294 struct ioc_toc_header toc; 302 CDstatus status;
295 struct ioc_read_subchannel info; 303 struct ioc_toc_header toc;
296 struct cd_sub_channel_info data; 304 struct ioc_read_subchannel info;
297 305 struct cd_sub_channel_info data;
298 info.address_format = CD_MSF_FORMAT; 306
299 info.data_format = CD_CURRENT_POSITION; 307 info.address_format = CD_MSF_FORMAT;
300 info.track = 0; 308 info.data_format = CD_CURRENT_POSITION;
301 info.data_len = sizeof(data); 309 info.track = 0;
302 info.data = &data; 310 info.data_len = sizeof(data);
303 if ( ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0 ) { 311 info.data = &data;
304 if ( ERRNO_TRAYEMPTY(errno) ) { 312 if (ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0) {
305 status = CD_TRAYEMPTY; 313 if (ERRNO_TRAYEMPTY(errno)) {
306 } else { 314 status = CD_TRAYEMPTY;
307 status = CD_ERROR; 315 } else {
308 } 316 status = CD_ERROR;
309 } else { 317 }
310 switch (data.header.audio_status) { 318 } else {
311 case CD_AS_AUDIO_INVALID: 319 switch (data.header.audio_status) {
312 case CD_AS_NO_STATUS: 320 case CD_AS_AUDIO_INVALID:
313 /* Try to determine if there's a CD available */ 321 case CD_AS_NO_STATUS:
314 if (ioctl(cdrom->id,CDIOREADTOCHEADER,&toc)==0) 322 /* Try to determine if there's a CD available */
315 status = CD_STOPPED; 323 if (ioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0)
316 else 324 status = CD_STOPPED;
317 status = CD_TRAYEMPTY; 325 else
318 break; 326 status = CD_TRAYEMPTY;
319 case CD_AS_PLAY_COMPLETED: 327 break;
320 status = CD_STOPPED; 328 case CD_AS_PLAY_COMPLETED:
321 break; 329 status = CD_STOPPED;
322 case CD_AS_PLAY_IN_PROGRESS: 330 break;
323 status = CD_PLAYING; 331 case CD_AS_PLAY_IN_PROGRESS:
324 break; 332 status = CD_PLAYING;
325 case CD_AS_PLAY_PAUSED: 333 break;
326 status = CD_PAUSED; 334 case CD_AS_PLAY_PAUSED:
327 break; 335 status = CD_PAUSED;
328 default: 336 break;
329 status = CD_ERROR; 337 default:
330 break; 338 status = CD_ERROR;
331 } 339 break;
332 } 340 }
333 if ( position ) { 341 }
334 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { 342 if (position) {
335 *position = MSF_TO_FRAMES( 343 if (status == CD_PLAYING || (status == CD_PAUSED)) {
336 data.what.position.absaddr.msf.minute, 344 *position =
337 data.what.position.absaddr.msf.second, 345 MSF_TO_FRAMES(data.what.position.absaddr.msf.minute,
338 data.what.position.absaddr.msf.frame); 346 data.what.position.absaddr.msf.second,
339 } else { 347 data.what.position.absaddr.msf.frame);
340 *position = 0; 348 } else {
341 } 349 *position = 0;
342 } 350 }
343 return(status); 351 }
352 return (status);
344 } 353 }
345 354
346 /* Start play */ 355 /* Start play */
347 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 356 static int
348 { 357 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
349 struct ioc_play_msf playtime; 358 {
350 359 struct ioc_play_msf playtime;
351 FRAMES_TO_MSF(start, 360
352 &playtime.start_m, &playtime.start_s, &playtime.start_f); 361 FRAMES_TO_MSF(start,
353 FRAMES_TO_MSF(start+length, 362 &playtime.start_m, &playtime.start_s, &playtime.start_f);
354 &playtime.end_m, &playtime.end_s, &playtime.end_f); 363 FRAMES_TO_MSF(start + length,
364 &playtime.end_m, &playtime.end_s, &playtime.end_f);
355 #ifdef DEBUG_CDROM 365 #ifdef DEBUG_CDROM
356 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", 366 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
357 playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, 367 playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
358 playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); 368 playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
359 #endif 369 #endif
360 ioctl(cdrom->id, CDIOCSTART, 0); 370 ioctl(cdrom->id, CDIOCSTART, 0);
361 return(SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime)); 371 return (SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime));
362 } 372 }
363 373
364 /* Pause play */ 374 /* Pause play */
365 static int SDL_SYS_CDPause(SDL_CD *cdrom) 375 static int
366 { 376 SDL_SYS_CDPause(SDL_CD * cdrom)
367 return(SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0)); 377 {
378 return (SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0));
368 } 379 }
369 380
370 /* Resume play */ 381 /* Resume play */
371 static int SDL_SYS_CDResume(SDL_CD *cdrom) 382 static int
372 { 383 SDL_SYS_CDResume(SDL_CD * cdrom)
373 return(SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0)); 384 {
385 return (SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0));
374 } 386 }
375 387
376 /* Stop play */ 388 /* Stop play */
377 static int SDL_SYS_CDStop(SDL_CD *cdrom) 389 static int
378 { 390 SDL_SYS_CDStop(SDL_CD * cdrom)
379 return(SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0)); 391 {
392 return (SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0));
380 } 393 }
381 394
382 /* Eject the CD-ROM */ 395 /* Eject the CD-ROM */
383 static int SDL_SYS_CDEject(SDL_CD *cdrom) 396 static int
384 { 397 SDL_SYS_CDEject(SDL_CD * cdrom)
385 return(SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0)); 398 {
399 return (SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0));
386 } 400 }
387 401
388 /* Close the CD-ROM handle */ 402 /* Close the CD-ROM handle */
389 static void SDL_SYS_CDClose(SDL_CD *cdrom) 403 static void
390 { 404 SDL_SYS_CDClose(SDL_CD * cdrom)
391 close(cdrom->id); 405 {
392 } 406 close(cdrom->id);
393 407 }
394 void SDL_SYS_CDQuit(void) 408
395 { 409 void
396 int i; 410 SDL_SYS_CDQuit(void)
397 411 {
398 if ( SDL_numcds > 0 ) { 412 int i;
399 for ( i=0; i<SDL_numcds; ++i ) { 413
400 SDL_free(SDL_cdlist[i]); 414 if (SDL_numcds > 0) {
401 } 415 for (i = 0; i < SDL_numcds; ++i) {
402 SDL_numcds = 0; 416 SDL_free(SDL_cdlist[i]);
403 } 417 }
418 SDL_numcds = 0;
419 }
404 } 420 }
405 421
406 #endif /* SDL_CDROM_FREEBSD */ 422 #endif /* SDL_CDROM_FREEBSD */
423 /* vi: set ts=4 sw=4 expandtab: */