comparison src/cdrom/aix/SDL_syscdrom.c @ 1662:782fd950bd46 SDL-1.3

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