comparison src/cdrom/qnx/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
44 #define QNX_CD_OPENMODE O_RDONLY | O_EXCL 44 #define QNX_CD_OPENMODE O_RDONLY | O_EXCL
45 45
46 /* A list of available CD-ROM drives */ 46 /* A list of available CD-ROM drives */
47 static char *SDL_cdlist[MAX_DRIVES]; 47 static char *SDL_cdlist[MAX_DRIVES];
48 static dev_t SDL_cdmode[MAX_DRIVES]; 48 static dev_t SDL_cdmode[MAX_DRIVES];
49 static int SDL_cdopen[MAX_DRIVES]; 49 static int SDL_cdopen[MAX_DRIVES];
50 50
51 /* The system-dependent CD control functions */ 51 /* The system-dependent CD control functions */
52 static const char *SDL_SYS_CDName(int drive); 52 static const char *SDL_SYS_CDName(int drive);
53 static int SDL_SYS_CDOpen(int drive); 53 static int SDL_SYS_CDOpen(int drive);
54 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); 54 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
55 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); 55 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
56 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); 56 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
57 static int SDL_SYS_CDPause(SDL_CD *cdrom); 57 static int SDL_SYS_CDPause(SDL_CD * cdrom);
58 static int SDL_SYS_CDResume(SDL_CD *cdrom); 58 static int SDL_SYS_CDResume(SDL_CD * cdrom);
59 static int SDL_SYS_CDStop(SDL_CD *cdrom); 59 static int SDL_SYS_CDStop(SDL_CD * cdrom);
60 static int SDL_SYS_CDEject(SDL_CD *cdrom); 60 static int SDL_SYS_CDEject(SDL_CD * cdrom);
61 static void SDL_SYS_CDClose(SDL_CD *cdrom); 61 static void SDL_SYS_CDClose(SDL_CD * cdrom);
62 62
63 /* Check a drive to see if it is a CD-ROM */ 63 /* Check a drive to see if it is a CD-ROM */
64 static int CheckDrive(char *drive, struct stat *stbuf) 64 static int
65 CheckDrive(char *drive, struct stat *stbuf)
65 { 66 {
66 int is_cd, cdfd; 67 int is_cd, cdfd;
67 cam_devinfo_t dinfo; 68 cam_devinfo_t dinfo;
68 int devctlret=0; 69 int devctlret = 0;
69 70
70 int atapi; 71 int atapi;
71 int removable; 72 int removable;
72 int cdb10; 73 int cdb10;
73 74
74 /* If it doesn't exist, return -1 */ 75 /* If it doesn't exist, return -1 */
75 if (stat(drive, stbuf) < 0) 76 if (stat(drive, stbuf) < 0) {
76 { 77 return (-1);
77 return(-1);
78 } 78 }
79 79
80 /* If it does exist, verify that it's an available CD-ROM */ 80 /* If it does exist, verify that it's an available CD-ROM */
81 is_cd = 0; 81 is_cd = 0;
82 82
83 if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) 83 if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
84 {
85 cdfd = open(drive, QNX_CD_OPENMODE); 84 cdfd = open(drive, QNX_CD_OPENMODE);
86 if ( cdfd >= 0 ) 85 if (cdfd >= 0) {
87 { 86 devctlret =
88 devctlret=devctl(cdfd, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t), NULL); 87 devctl(cdfd, DCMD_CAM_DEVINFO, &dinfo,
89 88 sizeof(cam_devinfo_t), NULL);
90 if (devctlret==EOK) 89
91 { 90 if (devctlret == EOK) {
92 atapi=dinfo.flags & DEV_ATAPI; 91 atapi = dinfo.flags & DEV_ATAPI;
93 removable=dinfo.flags & DEV_REMOVABLE; 92 removable = dinfo.flags & DEV_REMOVABLE;
94 cdb10=dinfo.flags & DEV_CDB_10; /* I'm not sure about that flag */ 93 cdb10 = dinfo.flags & DEV_CDB_10; /* I'm not sure about that flag */
95 94
96 /* in the near future need to add more checks for splitting cdroms from other devices */ 95 /* in the near future need to add more checks for splitting cdroms from other devices */
97 if ((atapi)&&(removable)) 96 if ((atapi) && (removable)) {
98 { 97 is_cd = 1;
99 is_cd = 1; 98 }
100 }
101 } 99 }
102 100
103 close(cdfd); 101 close(cdfd);
104 } 102 }
105 } 103 }
106 return(is_cd); 104 return (is_cd);
107 } 105 }
108 106
109 /* Add a CD-ROM drive to our list of valid drives */ 107 /* Add a CD-ROM drive to our list of valid drives */
110 static void AddDrive(char *drive, struct stat *stbuf) 108 static void
109 AddDrive(char *drive, struct stat *stbuf)
111 { 110 {
112 int i; 111 int i;
113 112
114 if (SDL_numcds < MAX_DRIVES) 113 if (SDL_numcds < MAX_DRIVES) {
115 {
116 /* Check to make sure it's not already in our list. 114 /* Check to make sure it's not already in our list.
117 This can happen when we see a drive via symbolic link. */ 115 This can happen when we see a drive via symbolic link. */
118 116
119 for (i=0; i<SDL_numcds; ++i) 117 for (i = 0; i < SDL_numcds; ++i) {
120 { 118 if (stbuf->st_rdev == SDL_cdmode[i]) {
121 if (stbuf->st_rdev == SDL_cdmode[i])
122 {
123 return; 119 return;
124 } 120 }
125 } 121 }
126 122
127 /* Add this drive to our list */ 123 /* Add this drive to our list */
128 124
129 i = SDL_numcds; 125 i = SDL_numcds;
130 SDL_cdlist[i] = SDL_strdup(drive); 126 SDL_cdlist[i] = SDL_strdup(drive);
131 if (SDL_cdlist[i] == NULL) 127 if (SDL_cdlist[i] == NULL) {
132 {
133 SDL_OutOfMemory(); 128 SDL_OutOfMemory();
134 return; 129 return;
135 } 130 }
136 SDL_cdmode[i] = stbuf->st_rdev; 131 SDL_cdmode[i] = stbuf->st_rdev;
137 ++SDL_numcds; 132 ++SDL_numcds;
138 } 133 }
139 } 134 }
140 135
141 int SDL_SYS_CDInit(void) 136 int
137 SDL_SYS_CDInit(void)
142 { 138 {
143 /* checklist: /dev/cdrom, /dev/cd?, /dev/scd? */ 139 /* checklist: /dev/cdrom, /dev/cd?, /dev/scd? */
144 static char *checklist[]={"cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL}; 140 static char *checklist[] =
141 { "cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL };
145 142
146 char *SDLcdrom; 143 char *SDLcdrom;
147 int i, j, exists; 144 int i, j, exists;
148 char drive[32]; 145 char drive[32];
149 struct stat stbuf; 146 struct stat stbuf;
159 SDL_CDcaps.Stop = SDL_SYS_CDStop; 156 SDL_CDcaps.Stop = SDL_SYS_CDStop;
160 SDL_CDcaps.Eject = SDL_SYS_CDEject; 157 SDL_CDcaps.Eject = SDL_SYS_CDEject;
161 SDL_CDcaps.Close = SDL_SYS_CDClose; 158 SDL_CDcaps.Close = SDL_SYS_CDClose;
162 159
163 /* clearing device open status */ 160 /* clearing device open status */
164 for (i=0; i<MAX_DRIVES; i++) 161 for (i = 0; i < MAX_DRIVES; i++) {
165 { 162 SDL_cdopen[i] = 0;
166 SDL_cdopen[i]=0;
167 } 163 }
168 164
169 /* Look in the environment for our CD-ROM drive list */ 165 /* Look in the environment for our CD-ROM drive list */
170 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ 166 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
171 if ( SDLcdrom != NULL ) 167 if (SDLcdrom != NULL) {
172 {
173 char *cdpath, *delim; 168 char *cdpath, *delim;
174 size_t len = SDL_strlen(SDLcdrom)+1; 169 size_t len = SDL_strlen(SDLcdrom) + 1;
175 cdpath = SDL_stack_alloc(char, len); 170 cdpath = SDL_stack_alloc(char, len);
176 if (cdpath != NULL) 171 if (cdpath != NULL) {
177 {
178 SDL_strlcpy(cdpath, SDLcdrom, len); 172 SDL_strlcpy(cdpath, SDLcdrom, len);
179 SDLcdrom = cdpath; 173 SDLcdrom = cdpath;
180 do { 174 do {
181 delim = SDL_strchr(SDLcdrom, ':'); 175 delim = SDL_strchr(SDLcdrom, ':');
182 if (delim) 176 if (delim) {
183 {
184 *delim++ = '\0'; 177 *delim++ = '\0';
185 } 178 }
186 if (CheckDrive(SDLcdrom, &stbuf) > 0) 179 if (CheckDrive(SDLcdrom, &stbuf) > 0) {
187 {
188 AddDrive(SDLcdrom, &stbuf); 180 AddDrive(SDLcdrom, &stbuf);
189 } 181 }
190 if (delim) 182 if (delim) {
191 {
192 SDLcdrom = delim; 183 SDLcdrom = delim;
193 } 184 } else {
194 else
195 {
196 SDLcdrom = NULL; 185 SDLcdrom = NULL;
197 } 186 }
198 } while (SDLcdrom); 187 }
188 while (SDLcdrom);
199 SDL_stack_free(cdpath); 189 SDL_stack_free(cdpath);
200 } 190 }
201 191
202 /* If we found our drives, there's nothing left to do */ 192 /* If we found our drives, there's nothing left to do */
203 if (SDL_numcds > 0) 193 if (SDL_numcds > 0) {
204 { 194 return (0);
205 return(0);
206 } 195 }
207 } 196 }
208 197
209 /* Scan the system for CD-ROM drives */ 198 /* Scan the system for CD-ROM drives */
210 for ( i=0; checklist[i]; ++i ) 199 for (i = 0; checklist[i]; ++i) {
211 { 200 if (checklist[i][0] == '?') {
212 if (checklist[i][0] == '?') 201 char *insert;
213 {
214 char* insert;
215 exists = 1; 202 exists = 1;
216 203
217 for ( j=checklist[i][1]; exists; ++j ) 204 for (j = checklist[i][1]; exists; ++j) {
218 { 205 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
219 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]); 206 &checklist[i][3]);
220 insert = SDL_strchr(drive, '?'); 207 insert = SDL_strchr(drive, '?');
221 if (insert != NULL) 208 if (insert != NULL) {
222 {
223 *insert = j; 209 *insert = j;
224 } 210 }
225 switch (CheckDrive(drive, &stbuf)) 211 switch (CheckDrive(drive, &stbuf)) {
226 {
227 /* Drive exists and is a CD-ROM */ 212 /* Drive exists and is a CD-ROM */
228 case 1: 213 case 1:
229 AddDrive(drive, &stbuf); 214 AddDrive(drive, &stbuf);
230 break; 215 break;
231 /* Drive exists, but isn't a CD-ROM */ 216 /* Drive exists, but isn't a CD-ROM */
232 case 0: 217 case 0:
233 break; 218 break;
234 /* Drive doesn't exist */ 219 /* Drive doesn't exist */
235 case -1: 220 case -1:
236 exists = 0; 221 exists = 0;
237 break; 222 break;
238 } 223 }
239 } 224 }
240 } 225 } else {
241 else 226 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
242 { 227 checklist[i]);
243 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); 228 if (CheckDrive(drive, &stbuf) > 0) {
244 if (CheckDrive(drive, &stbuf) > 0)
245 {
246 AddDrive(drive, &stbuf); 229 AddDrive(drive, &stbuf);
247 } 230 }
248 } 231 }
249 } 232 }
250 return(0); 233 return (0);
251 } 234 }
252 235
253 static const char *SDL_SYS_CDName(int drive) 236 static const char *
254 { 237 SDL_SYS_CDName(int drive)
255 return(SDL_cdlist[drive]); 238 {
256 } 239 return (SDL_cdlist[drive]);
257 240 }
258 static int SDL_SYS_CDOpen(int drive) 241
242 static int
243 SDL_SYS_CDOpen(int drive)
259 { 244 {
260 int handle; 245 int handle;
261 246
262 handle=open(SDL_cdlist[drive], QNX_CD_OPENMODE); 247 handle = open(SDL_cdlist[drive], QNX_CD_OPENMODE);
263 248
264 if (handle>0) 249 if (handle > 0) {
265 { 250 SDL_cdopen[drive] = handle;
266 SDL_cdopen[drive]=handle;
267 } 251 }
268 252
269 return (handle); 253 return (handle);
270 } 254 }
271 255
272 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) 256 static int
257 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
273 { 258 {
274 cdrom_read_toc_t toc; 259 cdrom_read_toc_t toc;
275 int i, okay; 260 int i, okay;
276 261
277 okay = 0; 262 okay = 0;
278 if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL) == 0) 263 if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL) ==
279 { 264 0) {
280 cdrom->numtracks = toc.last_track - toc.first_track + 1; 265 cdrom->numtracks = toc.last_track - toc.first_track + 1;
281 if (cdrom->numtracks > SDL_MAX_TRACKS) 266 if (cdrom->numtracks > SDL_MAX_TRACKS) {
282 {
283 cdrom->numtracks = SDL_MAX_TRACKS; 267 cdrom->numtracks = SDL_MAX_TRACKS;
284 } 268 }
285 /* Read all the track TOC entries */ 269 /* Read all the track TOC entries */
286 for (i=0; i<=cdrom->numtracks; ++i) 270 for (i = 0; i <= cdrom->numtracks; ++i) {
287 { 271 if (i == cdrom->numtracks) {
288 if (i == cdrom->numtracks)
289 {
290 cdrom->track[i].id = CDROM_LEADOUT; 272 cdrom->track[i].id = CDROM_LEADOUT;
291 } 273 } else {
292 else 274 cdrom->track[i].id = toc.first_track + i;
293 {
294 cdrom->track[i].id = toc.first_track+i;
295 } 275 }
296 276
297 cdrom->track[i].type = toc.toc_entry[i].control_adr & 0x0F; 277 cdrom->track[i].type = toc.toc_entry[i].control_adr & 0x0F;
298 cdrom->track[i].offset = toc.toc_entry[i].addr.lba; 278 cdrom->track[i].offset = toc.toc_entry[i].addr.lba;
299 cdrom->track[i].length = 0; 279 cdrom->track[i].length = 0;
300 280
301 if (i > 0) 281 if (i > 0) {
302 { 282 cdrom->track[i - 1].length =
303 cdrom->track[i-1].length = cdrom->track[i].offset-cdrom->track[i-1].offset; 283 cdrom->track[i].offset - cdrom->track[i - 1].offset;
304 } 284 }
305 } 285 }
306 if (i == (cdrom->numtracks+1)) 286 if (i == (cdrom->numtracks + 1)) {
307 {
308 okay = 1; 287 okay = 1;
309 } 288 }
310 } 289 }
311 return (okay ? 0 : -1); 290 return (okay ? 0 : -1);
312 } 291 }
313 292
314 /* Get CD-ROM status */ 293 /* Get CD-ROM status */
315 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) 294 static CDstatus
295 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
316 { 296 {
317 CDstatus status; 297 CDstatus status;
318 298
319 cdrom_read_toc_t toc; 299 cdrom_read_toc_t toc;
320 cdrom_subch_data_t info; 300 cdrom_subch_data_t info;
321 cam_devinfo_t dinfo; 301 cam_devinfo_t dinfo;
322 302
323 int devctlret=0; 303 int devctlret = 0;
324 int drive=-1; 304 int drive = -1;
325 int i; 305 int i;
326 int eagaincnt=0; 306 int eagaincnt = 0;
327 307
328 /* check media presence before read subchannel call, some cdroms can lockups */ 308 /* check media presence before read subchannel call, some cdroms can lockups */
329 /* if no media, while calling read subchannel functions. */ 309 /* if no media, while calling read subchannel functions. */
330 devctlret=devctl(cdrom->id, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t), NULL); 310 devctlret =
331 311 devctl(cdrom->id, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t),
332 if (devctlret==EOK) 312 NULL);
333 { 313
334 if ((dinfo.flags & DEV_NO_MEDIA)!=0) 314 if (devctlret == EOK) {
335 { 315 if ((dinfo.flags & DEV_NO_MEDIA) != 0) {
336 status = CD_TRAYEMPTY; 316 status = CD_TRAYEMPTY;
337 if (position) 317 if (position) {
338 {
339 *position = 0; 318 *position = 0;
340 } 319 }
341 return (status); 320 return (status);
342 } 321 }
343 } 322 }
346 325
347 SDL_memset(&info, 0x00, sizeof(info)); 326 SDL_memset(&info, 0x00, sizeof(info));
348 info.subch_command.data_format = CDROM_SUBCH_CURRENT_POSITION; 327 info.subch_command.data_format = CDROM_SUBCH_CURRENT_POSITION;
349 328
350 do { 329 do {
351 devctlret=devctl(cdrom->id, DCMD_CAM_CDROMSUBCHNL, &info, sizeof(info), NULL); 330 devctlret =
352 if (devctlret==EIO) 331 devctl(cdrom->id, DCMD_CAM_CDROMSUBCHNL, &info, sizeof(info),
353 { 332 NULL);
333 if (devctlret == EIO) {
354 /* big workaround for media change, handle is unusable after that, 334 /* big workaround for media change, handle is unusable after that,
355 that bug was found in QNX 6.2, 6.2.1 is not released yet. */ 335 that bug was found in QNX 6.2, 6.2.1 is not released yet. */
356 336
357 for (i=0; i<MAX_DRIVES; i++) 337 for (i = 0; i < MAX_DRIVES; i++) {
358 { 338 if (SDL_cdopen[i] == cdrom->id) {
359 if (SDL_cdopen[i]==cdrom->id) 339 drive = i;
360 {
361 drive=i;
362 break; 340 break;
363 } 341 }
364 } 342 }
365 if (drive==-1) 343 if (drive == -1) {
366 { 344 /* that cannot happen, but ... */
367 /* that cannot happen, but ... */ 345 break;
368 break;
369 } 346 }
370 close(cdrom->id); 347 close(cdrom->id);
371 cdrom->id=open(SDL_cdlist[drive], QNX_CD_OPENMODE); 348 cdrom->id = open(SDL_cdlist[drive], QNX_CD_OPENMODE);
372 devctlret=EAGAIN; 349 devctlret = EAGAIN;
373 } 350 }
374 if (devctlret==EAGAIN) 351 if (devctlret == EAGAIN) {
375 {
376 eagaincnt++; 352 eagaincnt++;
377 } 353 }
378 if (eagaincnt==2) 354 if (eagaincnt == 2) {
379 {
380 /* workaround for broken cdroms, which can return always EAGAIN when its not ready, */ 355 /* workaround for broken cdroms, which can return always EAGAIN when its not ready, */
381 /* that mean errornous media or just no media avail */ 356 /* that mean errornous media or just no media avail */
382 devctlret=ENXIO; 357 devctlret = ENXIO;
383 break; 358 break;
384 } 359 }
385 } while ((devctlret==EAGAIN)||(devctlret==ESTALE)); 360 }
386 361 while ((devctlret == EAGAIN) || (devctlret == ESTALE));
387 if (devctlret != 0) 362
388 { 363 if (devctlret != 0) {
389 if (devctlret==ENXIO) 364 if (devctlret == ENXIO) {
390 {
391 status = CD_TRAYEMPTY; 365 status = CD_TRAYEMPTY;
392 } 366 } else {
393 else
394 {
395 status = CD_ERROR; 367 status = CD_ERROR;
396 } 368 }
397 } 369 } else {
398 else 370 switch (info.current_position.header.audio_status) {
399 { 371 case CDROM_AUDIO_INVALID:
400 switch (info.current_position.header.audio_status) 372 case CDROM_AUDIO_NO_STATUS:
401 { 373 /* Try to determine if there's a CD available */
402 case CDROM_AUDIO_INVALID: 374 if (devctl
403 case CDROM_AUDIO_NO_STATUS: 375 (cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc),
404 /* Try to determine if there's a CD available */ 376 NULL) == 0)
405 if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL)==0) 377 status = CD_STOPPED;
406 status = CD_STOPPED; 378 else
407 else 379 status = CD_TRAYEMPTY;
408 status = CD_TRAYEMPTY; 380 break;
409 break; 381 case CDROM_AUDIO_COMPLETED:
410 case CDROM_AUDIO_COMPLETED: 382 status = CD_STOPPED;
411 status = CD_STOPPED; 383 break;
412 break; 384 case CDROM_AUDIO_PLAY:
413 case CDROM_AUDIO_PLAY: 385 status = CD_PLAYING;
414 status = CD_PLAYING; 386 break;
415 break; 387 case CDROM_AUDIO_PAUSED:
416 case CDROM_AUDIO_PAUSED: 388 /* Workaround buggy CD-ROM drive */
417 /* Workaround buggy CD-ROM drive */ 389 if (info.current_position.data_format == CDROM_LEADOUT) {
418 if (info.current_position.data_format == CDROM_LEADOUT) 390 status = CD_STOPPED;
419 { 391 } else {
420 status = CD_STOPPED; 392 status = CD_PAUSED;
421 } 393 }
422 else 394 break;
423 { 395 default:
424 status = CD_PAUSED; 396 status = CD_ERROR;
425 } 397 break;
426 break; 398 }
427 default: 399 }
428 status = CD_ERROR; 400
429 break; 401 if (position) {
430 } 402 if (status == CD_PLAYING || (status == CD_PAUSED)) {
431 } 403 *position =
432 404 MSF_TO_FRAMES(info.current_position.addr.msf.minute,
433 if (position) 405 info.current_position.addr.msf.second,
434 { 406 info.current_position.addr.msf.frame);
435 if (status==CD_PLAYING || (status==CD_PAUSED)) 407 } else {
436 { 408 *position = 0;
437 *position = MSF_TO_FRAMES(info.current_position.addr.msf.minute, 409 }
438 info.current_position.addr.msf.second,
439 info.current_position.addr.msf.frame);
440 }
441 else
442 {
443 *position = 0;
444 }
445 } 410 }
446 411
447 return (status); 412 return (status);
448 } 413 }
449 414
450 /* Start play */ 415 /* Start play */
451 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 416 static int
417 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
452 { 418 {
453 cdrom_playmsf_t playtime; 419 cdrom_playmsf_t playtime;
454 420
455 FRAMES_TO_MSF(start, &playtime.start_minute, &playtime.start_second, &playtime.start_frame); 421 FRAMES_TO_MSF(start, &playtime.start_minute, &playtime.start_second,
456 FRAMES_TO_MSF(start+length, &playtime.end_minute, &playtime.end_second, &playtime.end_frame); 422 &playtime.start_frame);
457 423 FRAMES_TO_MSF(start + length, &playtime.end_minute, &playtime.end_second,
458 if (devctl(cdrom->id, DCMD_CAM_CDROMPLAYMSF, &playtime, sizeof(playtime), NULL) != 0) 424 &playtime.end_frame);
459 { 425
460 return -1; 426 if (devctl
461 } 427 (cdrom->id, DCMD_CAM_CDROMPLAYMSF, &playtime, sizeof(playtime),
462 else 428 NULL) != 0) {
463 { 429 return -1;
464 return 0; 430 } else {
431 return 0;
465 } 432 }
466 } 433 }
467 434
468 /* Pause play */ 435 /* Pause play */
469 static int SDL_SYS_CDPause(SDL_CD *cdrom) 436 static int
470 { 437 SDL_SYS_CDPause(SDL_CD * cdrom)
471 if (devctl(cdrom->id, DCMD_CAM_CDROMPAUSE, NULL, 0, NULL)!=0) 438 {
472 { 439 if (devctl(cdrom->id, DCMD_CAM_CDROMPAUSE, NULL, 0, NULL) != 0) {
473 return -1; 440 return -1;
474 } 441 } else {
475 else 442 return 0;
476 {
477 return 0;
478 } 443 }
479 } 444 }
480 445
481 /* Resume play */ 446 /* Resume play */
482 static int SDL_SYS_CDResume(SDL_CD *cdrom) 447 static int
483 { 448 SDL_SYS_CDResume(SDL_CD * cdrom)
484 if (devctl(cdrom->id, DCMD_CAM_CDROMRESUME, NULL, 0, NULL)!=0) 449 {
485 { 450 if (devctl(cdrom->id, DCMD_CAM_CDROMRESUME, NULL, 0, NULL) != 0) {
486 return -1; 451 return -1;
487 } 452 } else {
488 else 453 return 0;
489 {
490 return 0;
491 } 454 }
492 } 455 }
493 456
494 /* Stop play */ 457 /* Stop play */
495 static int SDL_SYS_CDStop(SDL_CD *cdrom) 458 static int
496 { 459 SDL_SYS_CDStop(SDL_CD * cdrom)
497 if (devctl(cdrom->id, DCMD_CAM_CDROMSTOP, NULL, 0, NULL)!=0) 460 {
498 { 461 if (devctl(cdrom->id, DCMD_CAM_CDROMSTOP, NULL, 0, NULL) != 0) {
499 return -1; 462 return -1;
500 } 463 } else {
501 else 464 return 0;
502 {
503 return 0;
504 } 465 }
505 } 466 }
506 467
507 /* Eject the CD-ROM */ 468 /* Eject the CD-ROM */
508 static int SDL_SYS_CDEject(SDL_CD *cdrom) 469 static int
509 { 470 SDL_SYS_CDEject(SDL_CD * cdrom)
510 if (devctl(cdrom->id, DCMD_CAM_EJECT_MEDIA, NULL, 0, NULL)!=0) 471 {
511 { 472 if (devctl(cdrom->id, DCMD_CAM_EJECT_MEDIA, NULL, 0, NULL) != 0) {
512 return -1; 473 return -1;
513 } 474 } else {
514 else 475 return 0;
515 {
516 return 0;
517 } 476 }
518 } 477 }
519 478
520 /* Close the CD-ROM handle */ 479 /* Close the CD-ROM handle */
521 static void SDL_SYS_CDClose(SDL_CD *cdrom) 480 static void
481 SDL_SYS_CDClose(SDL_CD * cdrom)
522 { 482 {
523 int i; 483 int i;
524 484
525 for (i=0; i<MAX_DRIVES; i++) 485 for (i = 0; i < MAX_DRIVES; i++) {
526 { 486 if (SDL_cdopen[i] == cdrom->id) {
527 if (SDL_cdopen[i]==cdrom->id) 487 SDL_cdopen[i] = 0;
528 { 488 break;
529 SDL_cdopen[i]=0; 489 }
530 break;
531 }
532 } 490 }
533 491
534 close(cdrom->id); 492 close(cdrom->id);
535 } 493 }
536 494
537 void SDL_SYS_CDQuit(void) 495 void
496 SDL_SYS_CDQuit(void)
538 { 497 {
539 int i; 498 int i;
540 499
541 if (SDL_numcds > 0) 500 if (SDL_numcds > 0) {
542 { 501 for (i = 0; i < SDL_numcds; ++i) {
543 for (i=0; i<SDL_numcds; ++i)
544 {
545 SDL_free(SDL_cdlist[i]); 502 SDL_free(SDL_cdlist[i]);
546 } 503 }
547 SDL_numcds = 0; 504 SDL_numcds = 0;
548 } 505 }
549 } 506 }
550 507
551 #endif /* SDL_CDROM_QNX */ 508 #endif /* SDL_CDROM_QNX */
509 /* vi: set ts=4 sw=4 expandtab: */