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