comparison src/cdrom/aix/SDL_syscdrom.c @ 1668:4da1ee79c9af SDL-1.3

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