Mercurial > sdl-ios-xcode
annotate src/cdrom/aix/SDL_syscdrom.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | c9b51268668f |
children | 604d73db6802 |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Carsten Griwodz | |
20 griff@kom.tu-darmstadt.de | |
21 | |
22 based on linux/SDL_syscdrom.c by Sam Lantinga | |
23 */ | |
24 | |
25 /* Functions for system-level CD-ROM audio control */ | |
26 | |
27 #define DEBUG_CDROM 1 | |
28 | |
29 #include <sys/types.h> | |
30 #include <stdlib.h> | |
31 #include <sys/stat.h> | |
32 #include <fcntl.h> | |
33 #include <stdio.h> | |
34 #include <string.h> | |
35 #include <errno.h> | |
36 #include <unistd.h> | |
37 | |
38 #include <sys/ioctl.h> | |
39 #include <sys/devinfo.h> | |
40 #include <sys/mntctl.h> | |
41 #include <sys/statfs.h> | |
42 #include <sys/vmount.h> | |
43 #include <fstab.h> | |
44 #include <sys/scdisk.h> | |
45 | |
46 #include "SDL_error.h" | |
47 #include "SDL_cdrom.h" | |
48 #include "SDL_syscdrom.h" | |
49 | |
50 /* The maximum number of CD-ROM drives we'll detect */ | |
51 #define MAX_DRIVES 16 | |
52 | |
53 /* A list of available CD-ROM drives */ | |
54 static char *SDL_cdlist[MAX_DRIVES]; | |
55 static dev_t SDL_cdmode[MAX_DRIVES]; | |
56 | |
57 /* The system-dependent CD control functions */ | |
58 static const char *SDL_SYS_CDName(int drive); | |
59 static int SDL_SYS_CDOpen(int drive); | |
60 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
61 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
62 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
63 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
64 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
65 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
66 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
67 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
68 static int SDL_SYS_CDioctl(int id, int command, void *arg); | |
69 | |
70 /* Check a drive to see if it is a CD-ROM */ | |
71 static int CheckDrive(char *drive, struct stat *stbuf) | |
72 { | |
73 int is_cd; | |
74 int cdfd; | |
75 int ret; | |
76 struct devinfo info; | |
77 | |
78 /* If it doesn't exist, return -1 */ | |
79 if ( stat(drive, stbuf) < 0 ) { | |
80 return -1; | |
81 } | |
82 | |
83 /* If it does exist, verify that it's an available CD-ROM */ | |
84 is_cd = 0; | |
85 if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { | |
86 cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); | |
87 if ( cdfd >= 0 ) { | |
88 ret = SDL_SYS_CDioctl( cdfd, IOCINFO, &info ); | |
89 if ( ret < 0 ) { | |
90 /* Some kind of error */ | |
91 is_cd = 0; | |
92 } else { | |
93 if ( info.devtype == DD_CDROM ) { | |
94 is_cd = 1; | |
95 } else { | |
96 is_cd = 0; | |
97 } | |
98 } | |
99 close(cdfd); | |
100 } | |
101 #ifdef DEBUG_CDROM | |
102 else | |
103 { | |
104 fprintf(stderr, "Could not open drive %s (%s)\n", drive, strerror(errno)); | |
105 } | |
106 #endif | |
107 } | |
108 return is_cd; | |
109 } | |
110 | |
111 /* Add a CD-ROM drive to our list of valid drives */ | |
112 static void AddDrive(char *drive, struct stat *stbuf) | |
113 { | |
114 int i; | |
115 | |
116 if ( SDL_numcds < MAX_DRIVES ) { | |
117 /* Check to make sure it's not already in our list. | |
118 This can happen when we see a drive via symbolic link. | |
119 */ | |
120 for ( i=0; i<SDL_numcds; ++i ) { | |
121 if ( stbuf->st_rdev == SDL_cdmode[i] ) { | |
122 #ifdef DEBUG_CDROM | |
123 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); | |
124 #endif | |
125 return; | |
126 } | |
127 } | |
128 | |
129 /* Add this drive to our list */ | |
130 i = SDL_numcds; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
131 SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); |
0 | 132 if ( SDL_cdlist[i] == NULL ) { |
133 SDL_OutOfMemory(); | |
134 return; | |
135 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
136 SDL_strcpy(SDL_cdlist[i], drive); |
0 | 137 SDL_cdmode[i] = stbuf->st_rdev; |
138 ++SDL_numcds; | |
139 #ifdef DEBUG_CDROM | |
140 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); | |
141 #endif | |
142 } | |
143 } | |
144 | |
145 static void CheckMounts() | |
146 { | |
147 char* buffer; | |
148 int bufsz; | |
149 struct vmount* ptr; | |
150 int ret; | |
151 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
152 buffer = (char*)SDL_malloc(10); |
0 | 153 bufsz = 10; |
154 if ( buffer==NULL ) | |
155 { | |
156 fprintf(stderr, "Could not allocate 10 bytes in aix/SDL_syscdrom.c:CheckMounts\n" ); | |
157 exit ( -10 ); | |
158 } | |
159 | |
160 do | |
161 { | |
162 /* mntctrl() returns an array of all mounted filesystems */ | |
163 ret = mntctl ( MCTL_QUERY, bufsz, buffer ); | |
164 if ( ret == 0 ) | |
165 { | |
166 /* Buffer was too small, realloc. */ | |
167 bufsz = *(int*)buffer; /* Required size is in first word. */ | |
168 /* (whatever a word is in AIX 4.3.3) */ | |
169 /* int seems to be OK in 32bit mode. */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
170 SDL_free(buffer); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
171 buffer = (char*)SDL_malloc(bufsz); |
0 | 172 if ( buffer==NULL ) |
173 { | |
174 fprintf(stderr, | |
175 "Could not allocate %d bytes in aix/SDL_syscdrom.c:CheckMounts\n", | |
176 bufsz ); | |
177 exit ( -10 ); | |
178 } | |
179 } | |
180 else if ( ret < 0 ) | |
181 { | |
182 #ifdef DEBUG_CDROM | |
183 fprintf(stderr, "Error reading vmount structures\n"); | |
184 #endif | |
185 return; | |
186 } | |
187 } | |
188 while ( ret == 0 ); | |
189 | |
190 #ifdef DEBUG_CDROM | |
191 fprintf ( stderr, "Read %d vmount structures\n",ret ); | |
192 #endif | |
193 ptr = (struct vmount*)buffer; | |
194 do | |
195 { | |
196 switch(ptr->vmt_gfstype) | |
197 { | |
198 case MNT_CDROM : | |
199 { | |
200 struct stat stbuf; | |
201 char* text; | |
202 | |
203 text = (char*)ptr + ptr->vmt_data[VMT_OBJECT].vmt_off; | |
204 #ifdef DEBUG_CDROM | |
205 fprintf(stderr, "Checking mount path: %s mounted on %s\n", | |
206 text, (char*)ptr + ptr->vmt_data[VMT_STUB].vmt_off ); | |
207 #endif | |
208 if ( CheckDrive( text, &stbuf) > 0) | |
209 { | |
210 AddDrive( text, &stbuf); | |
211 } | |
212 } | |
213 break; | |
214 default : | |
215 break; | |
216 } | |
217 ptr = (struct vmount*)((char*)ptr + ptr->vmt_length); | |
218 ret--; | |
219 } | |
220 while ( ret > 0 ); | |
221 | |
222 free ( buffer ); | |
223 } | |
224 | |
225 static int CheckNonmounts() | |
226 { | |
227 #ifdef _THREAD_SAFE | |
228 AFILE_t fsFile = NULL; | |
229 int passNo = 0; | |
230 int ret; | |
231 struct fstab entry; | |
232 struct stat stbuf; | |
233 | |
234 ret = setfsent_r( &fsFile, &passNo ); | |
235 if ( ret != 0 ) return -1; | |
236 do | |
237 { | |
238 ret = getfsent_r ( &entry, &fsFile, &passNo ); | |
239 if ( ret == 0 ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
240 char* l = SDL_strrchr(entry.fs_spec,'/'); |
0 | 241 if ( l != NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
242 if ( !SDL_strncmp("cd",++l,2) ) { |
0 | 243 #ifdef DEBUG_CDROM |
244 fprintf(stderr, | |
245 "Found unmounted CD ROM drive with device name %s\n", | |
246 entry.fs_spec); | |
247 #endif | |
248 if ( CheckDrive( entry.fs_spec, &stbuf) > 0) | |
249 { | |
250 AddDrive( entry.fs_spec, &stbuf); | |
251 } | |
252 } | |
253 } | |
254 } | |
255 } | |
256 while ( ret == 0 ); | |
257 ret = endfsent_r ( &fsFile ); | |
258 if ( ret != 0 ) return -1; | |
259 return 0; | |
260 #else | |
261 struct fstab* entry; | |
262 struct stat stbuf; | |
263 | |
264 setfsent(); | |
265 do | |
266 { | |
267 entry = getfsent(); | |
268 if ( entry != NULL ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
269 char* l = SDL_strrchr(entry->fs_spec,'/'); |
0 | 270 if ( l != NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
271 if ( !SDL_strncmp("cd",++l,2) ) { |
0 | 272 #ifdef DEBUG_CDROM |
273 fprintf(stderr,"Found unmounted CD ROM drive with device name %s", entry->fs_spec); | |
274 #endif | |
275 if ( CheckDrive( entry->fs_spec, &stbuf) > 0) | |
276 { | |
277 AddDrive( entry->fs_spec, &stbuf); | |
278 } | |
279 } | |
280 } | |
281 } | |
282 } | |
283 while ( entry != NULL ); | |
284 endfsent(); | |
285 #endif | |
286 } | |
287 | |
288 int SDL_SYS_CDInit(void) | |
289 { | |
290 char *SDLcdrom; | |
291 struct stat stbuf; | |
292 | |
293 /* Fill in our driver capabilities */ | |
294 SDL_CDcaps.Name = SDL_SYS_CDName; | |
295 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
296 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
297 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
298 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
299 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
300 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
301 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
302 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
303 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
304 | |
305 /* Look in the environment for our CD-ROM drive list */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
306 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ |
0 | 307 if ( SDLcdrom != NULL ) { |
308 char *cdpath, *delim; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
309 cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1); |
0 | 310 if ( cdpath != NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
311 SDL_strcpy(cdpath, SDLcdrom); |
0 | 312 SDLcdrom = cdpath; |
313 do { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
314 delim = SDL_strchr(SDLcdrom, ':'); |
0 | 315 if ( delim ) { |
316 *delim++ = '\0'; | |
317 } | |
318 #ifdef DEBUG_CDROM | |
319 fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); | |
320 #endif | |
321 if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { | |
322 AddDrive(SDLcdrom, &stbuf); | |
323 } | |
324 if ( delim ) { | |
325 SDLcdrom = delim; | |
326 } else { | |
327 SDLcdrom = NULL; | |
328 } | |
329 } while ( SDLcdrom ); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
330 SDL_free(cdpath); |
0 | 331 } |
332 | |
333 /* If we found our drives, there's nothing left to do */ | |
334 if ( SDL_numcds > 0 ) { | |
335 return(0); | |
336 } | |
337 } | |
338 | |
339 CheckMounts(); | |
340 CheckNonmounts(); | |
341 | |
342 return 0; | |
343 } | |
344 | |
345 /* General ioctl() CD-ROM command function */ | |
346 static int SDL_SYS_CDioctl(int id, int command, void *arg) | |
347 { | |
348 int retval; | |
349 | |
350 retval = ioctl(id, command, arg); | |
351 if ( retval < 0 ) { | |
352 SDL_SetError("ioctl() error: %s", strerror(errno)); | |
353 } | |
354 return retval; | |
355 } | |
356 | |
357 static const char *SDL_SYS_CDName(int drive) | |
358 { | |
359 return(SDL_cdlist[drive]); | |
360 } | |
361 | |
362 static int SDL_SYS_CDOpen(int drive) | |
363 { | |
364 int fd; | |
365 char* lastsl; | |
366 char* cdromname; | |
367 | |
368 /* | |
369 * We found /dev/cd? drives and that is in our list. But we can | |
370 * open only the /dev/rcd? versions of those devices for Audio CD. | |
371 */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
372 cdromname = (char*)SDL_malloc( SDL_strlen(SDL_cdlist[drive]+2) ); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
373 SDL_strcpy(cdromname,SDL_cdlist[drive]); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
374 lastsl = SDL_strrchr(cdromname,'/'); |
0 | 375 if (lastsl) { |
376 *lastsl = 0; | |
377 strcat(cdromname,"/r"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
378 lastsl = SDL_strrchr(SDL_cdlist[drive],'/'); |
0 | 379 if (lastsl) { |
380 lastsl++; | |
381 strcat(cdromname,lastsl); | |
382 } | |
383 } | |
384 | |
385 #ifdef DEBUG_CDROM | |
386 fprintf(stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive], cdromname); | |
387 #endif | |
388 | |
389 /* | |
390 * Use exclusive access. Don't use SC_DIAGNOSTICS as xmcd does because they | |
391 * require root priviledges, and we don't want that. SC_SINGLE provides | |
392 * exclusive access with less trouble. | |
393 */ | |
394 fd = openx(cdromname, O_RDONLY, NULL, SC_SINGLE); | |
395 if ( fd < 0 ) | |
396 { | |
397 #ifdef DEBUG_CDROM | |
398 fprintf(stderr, "Could not open drive %s (%s)\n", cdromname, strerror(errno)); | |
399 #endif | |
400 } | |
401 else | |
402 { | |
403 struct mode_form_op cdMode; | |
404 int ret; | |
405 #ifdef DEBUG_CDROM | |
406 cdMode.action = CD_GET_MODE; | |
407 ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode); | |
408 if ( ret < 0 ) { | |
409 fprintf(stderr, | |
410 "Could not get drive mode for %s (%s)\n", | |
411 cdromname, strerror(errno)); | |
412 } else { | |
413 switch(cdMode.cd_mode_form) { | |
414 case CD_MODE1 : | |
415 fprintf(stderr, | |
416 "Drive mode for %s is %s\n", | |
417 cdromname, "CD-ROM Data Mode 1"); | |
418 break; | |
419 case CD_MODE2_FORM1 : | |
420 fprintf(stderr, | |
421 "Drive mode for %s is %s\n", | |
422 cdromname, "CD-ROM XA Data Mode 2 Form 1"); | |
423 break; | |
424 case CD_MODE2_FORM2 : | |
425 fprintf(stderr, | |
426 "Drive mode for %s is %s\n", | |
427 cdromname, "CD-ROM XA Data Mode 2 Form 2"); | |
428 break; | |
429 case CD_DA : | |
430 fprintf(stderr, | |
431 "Drive mode for %s is %s\n", | |
432 cdromname, "CD-DA"); | |
433 break; | |
434 default : | |
435 fprintf(stderr, | |
436 "Drive mode for %s is %s\n", | |
437 cdromname, "unknown"); | |
438 break; | |
439 } | |
440 } | |
441 #endif | |
442 | |
443 cdMode.action = CD_CHG_MODE; | |
444 cdMode.cd_mode_form = CD_DA; | |
445 ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode); | |
446 if ( ret < 0 ) { | |
447 #ifdef DEBUG_CDROM | |
448 fprintf(stderr, | |
449 "Could not set drive mode for %s (%s)\n", | |
450 cdromname, strerror(errno)); | |
451 #endif | |
452 SDL_SetError("ioctl() error: Could not set CD drive mode, %s", | |
453 strerror(errno)); | |
454 } else { | |
455 #ifdef DEBUG_CDROM | |
456 fprintf(stderr, | |
457 "Drive mode for %s set to CD_DA\n", | |
458 cdromname); | |
459 #endif | |
460 } | |
461 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
462 SDL_free(cdromname); |
0 | 463 return fd; |
464 } | |
465 | |
466 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
467 { | |
468 struct cd_audio_cmd cmd; | |
469 struct cd_audio_cmd entry; | |
470 int i; | |
471 int okay; | |
472 | |
473 cmd.audio_cmds = CD_TRK_INFO_AUDIO; | |
474 cmd.msf_flag = FALSE; | |
475 if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0 ) { | |
476 return -1; | |
477 } | |
478 | |
479 okay = 0; | |
480 cdrom->numtracks = cmd.indexing.track_index.last_track | |
481 - cmd.indexing.track_index.first_track+1; | |
482 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { | |
483 cdrom->numtracks = SDL_MAX_TRACKS; | |
484 } | |
485 | |
486 /* Read all the track TOC entries */ | |
487 for ( i=0; i<=cdrom->numtracks; ++i ) { | |
488 if ( i == cdrom->numtracks ) { | |
489 cdrom->track[i].id = 0xAA;; | |
490 } else { | |
491 cdrom->track[i].id = cmd.indexing.track_index.first_track+i; | |
492 } | |
493 entry.audio_cmds = CD_GET_TRK_MSF; | |
494 entry.indexing.track_msf.track = cdrom->track[i].id; | |
495 if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &entry) < 0 ) { | |
496 break; | |
497 } else { | |
498 cdrom->track[i].type = 0; /* don't know how to detect 0x04 data track */ | |
499 cdrom->track[i].offset = MSF_TO_FRAMES( | |
500 entry.indexing.track_msf.mins, | |
501 entry.indexing.track_msf.secs, | |
502 entry.indexing.track_msf.frames); | |
503 cdrom->track[i].length = 0; | |
504 if ( i > 0 ) { | |
505 cdrom->track[i-1].length = cdrom->track[i].offset | |
506 - cdrom->track[i-1].offset; | |
507 } | |
508 } | |
509 } | |
510 if ( i == (cdrom->numtracks+1) ) { | |
511 okay = 1; | |
512 } | |
513 return(okay ? 0 : -1); | |
514 } | |
515 | |
516 /* Get CD-ROM status */ | |
517 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
518 { | |
519 CDstatus status; | |
520 struct cd_audio_cmd cmd; | |
521 cmd.audio_cmds = CD_INFO_AUDIO; | |
522 | |
523 if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0 ) { | |
524 #ifdef DEBUG_CDROM | |
525 fprintf(stderr, "ioctl failed in SDL_SYS_CDStatus (%s)\n", SDL_GetError()); | |
526 #endif | |
527 status = CD_ERROR; | |
528 } else { | |
529 switch (cmd.status) { | |
530 case CD_NO_AUDIO: | |
531 case CD_COMPLETED: | |
532 status = CD_STOPPED; | |
533 break; | |
534 case CD_PLAY_AUDIO: | |
535 status = CD_PLAYING; | |
536 break; | |
537 case CD_PAUSE_AUDIO: | |
538 status = CD_PAUSED; | |
539 break; | |
540 case CD_NOT_VALID: | |
541 #ifdef DEBUG_CDROM | |
542 fprintf(stderr, "cdStatus failed with CD_NOT_VALID\n"); | |
543 #endif | |
544 status = CD_ERROR; | |
545 break; | |
546 case CD_STATUS_ERROR: | |
547 #ifdef DEBUG_CDROM | |
548 fprintf(stderr, "cdStatus failed with CD_STATUS_ERROR\n"); | |
549 #endif | |
550 status = CD_ERROR; | |
551 break; | |
552 default: | |
553 #ifdef DEBUG_CDROM | |
554 fprintf(stderr, "cdStatus failed with unknown error\n"); | |
555 #endif | |
556 status = CD_ERROR; | |
557 break; | |
558 } | |
559 } | |
560 if ( position ) { | |
561 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { | |
562 *position = MSF_TO_FRAMES( cmd.indexing.info_audio.current_mins, | |
563 cmd.indexing.info_audio.current_secs, | |
564 cmd.indexing.info_audio.current_frames); | |
565 } else { | |
566 *position = 0; | |
567 } | |
568 } | |
569 return status; | |
570 } | |
571 | |
572 /* Start play */ | |
573 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
574 { | |
575 struct cd_audio_cmd cmd; | |
576 | |
577 /* | |
578 * My CD Rom is muted by default. I think I read that this is new with | |
579 * AIX 4.3. SDL does not change the volume, so I need a kludge. Maybe | |
580 * its better to do this elsewhere? | |
581 */ | |
582 cmd.audio_cmds = CD_PLAY_AUDIO | CD_SET_VOLUME; | |
583 cmd.msf_flag = TRUE; | |
584 FRAMES_TO_MSF(start, | |
585 &cmd.indexing.msf.first_mins, | |
586 &cmd.indexing.msf.first_secs, | |
587 &cmd.indexing.msf.first_frames); | |
588 FRAMES_TO_MSF(start+length, | |
589 &cmd.indexing.msf.last_mins, | |
590 &cmd.indexing.msf.last_secs, | |
591 &cmd.indexing.msf.last_frames); | |
592 cmd.volume_type = CD_VOLUME_ALL; | |
593 cmd.all_channel_vol = 255; /* This is a uchar. What is a good value? No docu! */ | |
594 cmd.out_port_0_sel = CD_AUDIO_CHNL_0; | |
595 cmd.out_port_1_sel = CD_AUDIO_CHNL_1; | |
596 cmd.out_port_2_sel = CD_AUDIO_CHNL_2; | |
597 cmd.out_port_3_sel = CD_AUDIO_CHNL_3; | |
598 | |
599 #ifdef DEBUG_CDROM | |
600 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", | |
601 cmd.indexing.msf.first_mins, | |
602 cmd.indexing.msf.first_secs, | |
603 cmd.indexing.msf.first_frames, | |
604 cmd.indexing.msf.last_mins, | |
605 cmd.indexing.msf.last_secs, | |
606 cmd.indexing.msf.last_frames); | |
607 #endif | |
608 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
609 } | |
610 | |
611 /* Pause play */ | |
612 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
613 { | |
614 struct cd_audio_cmd cmd; | |
615 cmd.audio_cmds = CD_PAUSE_AUDIO; | |
616 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
617 } | |
618 | |
619 /* Resume play */ | |
620 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
621 { | |
622 struct cd_audio_cmd cmd; | |
623 cmd.audio_cmds = CD_RESUME_AUDIO; | |
624 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
625 } | |
626 | |
627 /* Stop play */ | |
628 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
629 { | |
630 struct cd_audio_cmd cmd; | |
631 cmd.audio_cmds = CD_STOP_AUDIO; | |
632 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
633 } | |
634 | |
635 /* Eject the CD-ROM */ | |
636 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
637 { | |
638 return(SDL_SYS_CDioctl(cdrom->id, DKEJECT, 0)); | |
639 } | |
640 | |
641 /* Close the CD-ROM handle */ | |
642 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
643 { | |
644 close(cdrom->id); | |
645 } | |
646 | |
647 void SDL_SYS_CDQuit(void) | |
648 { | |
649 int i; | |
650 | |
651 if ( SDL_numcds > 0 ) { | |
652 for ( i=0; i<SDL_numcds; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
653 SDL_free(SDL_cdlist[i]); |
0 | 654 } |
655 SDL_numcds = 0; | |
656 } | |
657 } | |
658 |