Mercurial > sdl-ios-xcode
comparison src/cdrom/beos/SDL_syscdrom.cc @ 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 |
---|---|
64 | 64 |
65 /* A list of available CD-ROM drives */ | 65 /* A list of available CD-ROM drives */ |
66 static char *SDL_cdlist[MAX_DRIVES]; | 66 static char *SDL_cdlist[MAX_DRIVES]; |
67 | 67 |
68 /* The system-dependent CD control functions */ | 68 /* The system-dependent CD control functions */ |
69 static const char *SDL_SYS_CDName (int drive); | 69 static const char *SDL_SYS_CDName(int drive); |
70 static int SDL_SYS_CDOpen (int drive); | 70 static int SDL_SYS_CDOpen(int drive); |
71 static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); | 71 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom); |
72 static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); | 72 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position); |
73 static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); | 73 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length); |
74 static int SDL_SYS_CDPause (SDL_CD * cdrom); | 74 static int SDL_SYS_CDPause(SDL_CD * cdrom); |
75 static int SDL_SYS_CDResume (SDL_CD * cdrom); | 75 static int SDL_SYS_CDResume(SDL_CD * cdrom); |
76 static int SDL_SYS_CDStop (SDL_CD * cdrom); | 76 static int SDL_SYS_CDStop(SDL_CD * cdrom); |
77 static int SDL_SYS_CDEject (SDL_CD * cdrom); | 77 static int SDL_SYS_CDEject(SDL_CD * cdrom); |
78 static void SDL_SYS_CDClose (SDL_CD * cdrom); | 78 static void SDL_SYS_CDClose(SDL_CD * cdrom); |
79 int try_dir (const char *directory); | 79 int try_dir(const char *directory); |
80 | 80 |
81 | 81 |
82 /* Check a drive to see if it is a CD-ROM */ | 82 /* Check a drive to see if it is a CD-ROM */ |
83 static int | 83 static int |
84 CheckDrive (char *drive) | 84 CheckDrive(char *drive) |
85 { | 85 { |
86 struct stat stbuf; | 86 struct stat stbuf; |
87 int is_cd, cdfd; | 87 int is_cd, cdfd; |
88 device_geometry info; | 88 device_geometry info; |
89 | 89 |
90 /* If it doesn't exist, return -1 */ | 90 /* If it doesn't exist, return -1 */ |
91 if (stat (drive, &stbuf) < 0) { | 91 if (stat(drive, &stbuf) < 0) { |
92 return (-1); | 92 return (-1); |
93 } | 93 } |
94 | 94 |
95 /* If it does exist, verify that it's an available CD-ROM */ | 95 /* If it does exist, verify that it's an available CD-ROM */ |
96 is_cd = 0; | 96 is_cd = 0; |
97 cdfd = open (drive, 0); | 97 cdfd = open(drive, 0); |
98 if (cdfd >= 0) { | 98 if (cdfd >= 0) { |
99 if (ioctl (cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR) { | 99 if (ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR) { |
100 if (info.device_type == B_CD) { | 100 if (info.device_type == B_CD) { |
101 is_cd = 1; | 101 is_cd = 1; |
102 } | 102 } |
103 } | 103 } |
104 close (cdfd); | 104 close(cdfd); |
105 } else { | 105 } else { |
106 /* This can happen when the drive is open .. (?) */ ; | 106 /* This can happen when the drive is open .. (?) */ ; |
107 is_cd = 1; | 107 is_cd = 1; |
108 } | 108 } |
109 return (is_cd); | 109 return (is_cd); |
110 } | 110 } |
111 | 111 |
112 /* Add a CD-ROM drive to our list of valid drives */ | 112 /* Add a CD-ROM drive to our list of valid drives */ |
113 static void | 113 static void |
114 AddDrive (char *drive) | 114 AddDrive(char *drive) |
115 { | 115 { |
116 int i; | 116 int i; |
117 size_t len; | 117 size_t len; |
118 | 118 |
119 if (SDL_numcds < MAX_DRIVES) { | 119 if (SDL_numcds < MAX_DRIVES) { |
120 /* Add this drive to our list */ | 120 /* Add this drive to our list */ |
121 i = SDL_numcds; | 121 i = SDL_numcds; |
122 len = SDL_strlen (drive) + 1; | 122 len = SDL_strlen(drive) + 1; |
123 SDL_cdlist[i] = (char *) SDL_malloc (len); | 123 SDL_cdlist[i] = (char *) SDL_malloc(len); |
124 if (SDL_cdlist[i] == NULL) { | 124 if (SDL_cdlist[i] == NULL) { |
125 SDL_OutOfMemory (); | 125 SDL_OutOfMemory(); |
126 return; | 126 return; |
127 } | 127 } |
128 SDL_strlcpy (SDL_cdlist[i], drive, len); | 128 SDL_strlcpy(SDL_cdlist[i], drive, len); |
129 ++SDL_numcds; | 129 ++SDL_numcds; |
130 #ifdef CDROM_DEBUG | 130 #ifdef CDROM_DEBUG |
131 fprintf (stderr, "Added CD-ROM drive: %s\n", drive); | 131 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); |
132 #endif | 132 #endif |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 /* IDE bus scanning magic */ | 136 /* IDE bus scanning magic */ |
151 int ide_1_master_type; | 151 int ide_1_master_type; |
152 int ide_1_slave_type; | 152 int ide_1_slave_type; |
153 }; | 153 }; |
154 | 154 |
155 int | 155 int |
156 SDL_SYS_CDInit (void) | 156 SDL_SYS_CDInit(void) |
157 { | 157 { |
158 char *SDLcdrom; | 158 char *SDLcdrom; |
159 int raw_fd; | 159 int raw_fd; |
160 struct ide_ctrl_info info; | 160 struct ide_ctrl_info info; |
161 | 161 |
170 SDL_CDcaps.Stop = SDL_SYS_CDStop; | 170 SDL_CDcaps.Stop = SDL_SYS_CDStop; |
171 SDL_CDcaps.Eject = SDL_SYS_CDEject; | 171 SDL_CDcaps.Eject = SDL_SYS_CDEject; |
172 SDL_CDcaps.Close = SDL_SYS_CDClose; | 172 SDL_CDcaps.Close = SDL_SYS_CDClose; |
173 | 173 |
174 /* Look in the environment for our CD-ROM drive list */ | 174 /* Look in the environment for our CD-ROM drive list */ |
175 SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ | 175 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ |
176 if (SDLcdrom != NULL) { | 176 if (SDLcdrom != NULL) { |
177 char *cdpath, *delim; | 177 char *cdpath, *delim; |
178 size_t len = SDL_strlen (SDLcdrom) + 1; | 178 size_t len = SDL_strlen(SDLcdrom) + 1; |
179 cdpath = SDL_stack_alloc (char, len); | 179 cdpath = SDL_stack_alloc(char, len); |
180 if (cdpath != NULL) { | 180 if (cdpath != NULL) { |
181 SDL_strlcpy (cdpath, SDLcdrom, len); | 181 SDL_strlcpy(cdpath, SDLcdrom, len); |
182 SDLcdrom = cdpath; | 182 SDLcdrom = cdpath; |
183 do { | 183 do { |
184 delim = SDL_strchr (SDLcdrom, ':'); | 184 delim = SDL_strchr(SDLcdrom, ':'); |
185 if (delim) { | 185 if (delim) { |
186 *delim++ = '\0'; | 186 *delim++ = '\0'; |
187 } | 187 } |
188 if (CheckDrive (SDLcdrom) > 0) { | 188 if (CheckDrive(SDLcdrom) > 0) { |
189 AddDrive (SDLcdrom); | 189 AddDrive(SDLcdrom); |
190 } | 190 } |
191 if (delim) { | 191 if (delim) { |
192 SDLcdrom = delim; | 192 SDLcdrom = delim; |
193 } else { | 193 } else { |
194 SDLcdrom = NULL; | 194 SDLcdrom = NULL; |
195 } | 195 } |
196 } | 196 } |
197 while (SDLcdrom); | 197 while (SDLcdrom); |
198 SDL_stack_free (cdpath); | 198 SDL_stack_free(cdpath); |
199 } | 199 } |
200 | 200 |
201 /* If we found our drives, there's nothing left to do */ | 201 /* If we found our drives, there's nothing left to do */ |
202 if (SDL_numcds > 0) { | 202 if (SDL_numcds > 0) { |
203 return (0); | 203 return (0); |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 /* Scan the system for CD-ROM drives */ | 207 /* Scan the system for CD-ROM drives */ |
208 try_dir ("/dev/disk"); | 208 try_dir("/dev/disk"); |
209 return 0; | 209 return 0; |
210 } | 210 } |
211 | 211 |
212 | 212 |
213 int | 213 int |
214 try_dir (const char *directory) | 214 try_dir(const char *directory) |
215 { | 215 { |
216 BDirectory dir; | 216 BDirectory dir; |
217 dir.SetTo (directory); | 217 dir.SetTo(directory); |
218 if (dir.InitCheck () != B_NO_ERROR) { | 218 if (dir.InitCheck() != B_NO_ERROR) { |
219 return false; | 219 return false; |
220 } | 220 } |
221 dir.Rewind (); | 221 dir.Rewind(); |
222 BEntry entry; | 222 BEntry entry; |
223 while (dir.GetNextEntry (&entry) >= 0) { | 223 while (dir.GetNextEntry(&entry) >= 0) { |
224 BPath path; | 224 BPath path; |
225 const char *name; | 225 const char *name; |
226 entry_ref e; | 226 entry_ref e; |
227 | 227 |
228 if (entry.GetPath (&path) != B_NO_ERROR) | 228 if (entry.GetPath(&path) != B_NO_ERROR) |
229 continue; | 229 continue; |
230 name = path.Path (); | 230 name = path.Path(); |
231 | 231 |
232 if (entry.GetRef (&e) != B_NO_ERROR) | 232 if (entry.GetRef(&e) != B_NO_ERROR) |
233 continue; | 233 continue; |
234 | 234 |
235 if (entry.IsDirectory ()) { | 235 if (entry.IsDirectory()) { |
236 if (SDL_strcmp (e.name, "floppy") == 0) | 236 if (SDL_strcmp(e.name, "floppy") == 0) |
237 continue; /* ignore floppy (it is not silent) */ | 237 continue; /* ignore floppy (it is not silent) */ |
238 int devfd = try_dir (name); | 238 int devfd = try_dir(name); |
239 if (devfd >= 0) | 239 if (devfd >= 0) |
240 return devfd; | 240 return devfd; |
241 } else { | 241 } else { |
242 int devfd; | 242 int devfd; |
243 device_geometry g; | 243 device_geometry g; |
244 | 244 |
245 if (SDL_strcmp (e.name, "raw") != 0) | 245 if (SDL_strcmp(e.name, "raw") != 0) |
246 continue; /* ignore partitions */ | 246 continue; /* ignore partitions */ |
247 | 247 |
248 devfd = open (name, O_RDONLY); | 248 devfd = open(name, O_RDONLY); |
249 if (devfd < 0) | 249 if (devfd < 0) |
250 continue; | 250 continue; |
251 | 251 |
252 if (ioctl (devfd, B_GET_GEOMETRY, &g, sizeof (g)) >= 0) { | 252 if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) { |
253 if (g.device_type == B_CD) { | 253 if (g.device_type == B_CD) { |
254 AddDrive (strdup (name)); | 254 AddDrive(strdup(name)); |
255 } | 255 } |
256 } | 256 } |
257 close (devfd); | 257 close(devfd); |
258 } | 258 } |
259 } | 259 } |
260 return B_ERROR; | 260 return B_ERROR; |
261 } | 261 } |
262 | 262 |
263 | 263 |
264 /* General ioctl() CD-ROM command function */ | 264 /* General ioctl() CD-ROM command function */ |
265 static int | 265 static int |
266 SDL_SYS_CDioctl (int index, int command, void *arg) | 266 SDL_SYS_CDioctl(int index, int command, void *arg) |
267 { | 267 { |
268 int okay; | 268 int okay; |
269 int fd; | 269 int fd; |
270 | 270 |
271 okay = 0; | 271 okay = 0; |
272 fd = open (SDL_cdlist[index], 0); | 272 fd = open(SDL_cdlist[index], 0); |
273 if (fd >= 0) { | 273 if (fd >= 0) { |
274 if (ioctl (fd, command, arg) == B_NO_ERROR) { | 274 if (ioctl(fd, command, arg) == B_NO_ERROR) { |
275 okay = 1; | 275 okay = 1; |
276 } | 276 } |
277 close (fd); | 277 close(fd); |
278 } | 278 } |
279 return (okay ? 0 : -1); | 279 return (okay ? 0 : -1); |
280 } | 280 } |
281 | 281 |
282 static const char * | 282 static const char * |
283 SDL_SYS_CDName (int drive) | 283 SDL_SYS_CDName(int drive) |
284 { | 284 { |
285 return (SDL_cdlist[drive]); | 285 return (SDL_cdlist[drive]); |
286 } | 286 } |
287 | 287 |
288 static int | 288 static int |
289 SDL_SYS_CDOpen (int drive) | 289 SDL_SYS_CDOpen(int drive) |
290 { | 290 { |
291 return (drive); | 291 return (drive); |
292 } | 292 } |
293 | 293 |
294 static int | 294 static int |
295 SDL_SYS_CDGetTOC (SDL_CD * cdrom) | 295 SDL_SYS_CDGetTOC(SDL_CD * cdrom) |
296 { | 296 { |
297 int i; | 297 int i; |
298 scsi_toc toc; | 298 scsi_toc toc; |
299 | 299 |
300 if (SDL_SYS_CDioctl (cdrom->id, B_SCSI_GET_TOC, &toc) == 0) { | 300 if (SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0) { |
301 cdrom->numtracks = CD_NUMTRACKS (toc); | 301 cdrom->numtracks = CD_NUMTRACKS(toc); |
302 if (cdrom->numtracks > SDL_MAX_TRACKS) { | 302 if (cdrom->numtracks > SDL_MAX_TRACKS) { |
303 cdrom->numtracks = SDL_MAX_TRACKS; | 303 cdrom->numtracks = SDL_MAX_TRACKS; |
304 } | 304 } |
305 for (i = 0; i <= cdrom->numtracks; ++i) { | 305 for (i = 0; i <= cdrom->numtracks; ++i) { |
306 cdrom->track[i].id = CD_TRACK_N (toc, i); | 306 cdrom->track[i].id = CD_TRACK_N(toc, i); |
307 /* FIXME: How do we tell on BeOS? */ | 307 /* FIXME: How do we tell on BeOS? */ |
308 cdrom->track[i].type = SDL_AUDIO_TRACK; | 308 cdrom->track[i].type = SDL_AUDIO_TRACK; |
309 cdrom->track[i].offset = MSF_TO_FRAMES (CD_TRACK_M (toc, i), | 309 cdrom->track[i].offset = MSF_TO_FRAMES(CD_TRACK_M(toc, i), |
310 CD_TRACK_S (toc, i), | 310 CD_TRACK_S(toc, i), |
311 CD_TRACK_F (toc, i)); | 311 CD_TRACK_F(toc, i)); |
312 cdrom->track[i].length = 0; | 312 cdrom->track[i].length = 0; |
313 if (i > 0) { | 313 if (i > 0) { |
314 cdrom->track[i - 1].length = | 314 cdrom->track[i - 1].length = |
315 cdrom->track[i].offset - cdrom->track[i - 1].offset; | 315 cdrom->track[i].offset - cdrom->track[i - 1].offset; |
316 } | 316 } |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 /* Get CD-ROM status */ | 324 /* Get CD-ROM status */ |
325 static CDstatus | 325 static CDstatus |
326 SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) | 326 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position) |
327 { | 327 { |
328 CDstatus status; | 328 CDstatus status; |
329 int fd; | 329 int fd; |
330 int cur_frame; | 330 int cur_frame; |
331 scsi_position pos; | 331 scsi_position pos; |
332 | 332 |
333 fd = open (SDL_cdlist[cdrom->id], 0); | 333 fd = open(SDL_cdlist[cdrom->id], 0); |
334 cur_frame = 0; | 334 cur_frame = 0; |
335 if (fd >= 0) { | 335 if (fd >= 0) { |
336 if (ioctl (fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR) { | 336 if (ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR) { |
337 cur_frame = | 337 cur_frame = |
338 MSF_TO_FRAMES (POS_ABS_M (pos), POS_ABS_S (pos), | 338 MSF_TO_FRAMES(POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos)); |
339 POS_ABS_F (pos)); | |
340 } | 339 } |
341 if (!pos.position[1] || (pos.position[1] >= 0x13) || | 340 if (!pos.position[1] || (pos.position[1] >= 0x13) || |
342 ((pos.position[1] == 0x12) && (!pos.position[6]))) { | 341 ((pos.position[1] == 0x12) && (!pos.position[6]))) { |
343 status = CD_STOPPED; | 342 status = CD_STOPPED; |
344 } else if (pos.position[1] == 0x11) { | 343 } else if (pos.position[1] == 0x11) { |
345 status = CD_PLAYING; | 344 status = CD_PLAYING; |
346 } else { | 345 } else { |
347 status = CD_PAUSED; | 346 status = CD_PAUSED; |
348 } | 347 } |
349 close (fd); | 348 close(fd); |
350 } else { | 349 } else { |
351 status = CD_TRAYEMPTY; | 350 status = CD_TRAYEMPTY; |
352 } | 351 } |
353 if (position) { | 352 if (position) { |
354 *position = cur_frame; | 353 *position = cur_frame; |
356 return (status); | 355 return (status); |
357 } | 356 } |
358 | 357 |
359 /* Start play */ | 358 /* Start play */ |
360 static int | 359 static int |
361 SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) | 360 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length) |
362 { | 361 { |
363 int okay; | 362 int okay; |
364 int fd; | 363 int fd; |
365 scsi_play_position pos; | 364 scsi_play_position pos; |
366 | 365 |
367 okay = 0; | 366 okay = 0; |
368 fd = open (SDL_cdlist[cdrom->id], 0); | 367 fd = open(SDL_cdlist[cdrom->id], 0); |
369 if (fd >= 0) { | 368 if (fd >= 0) { |
370 FRAMES_TO_MSF (start, &pos.start_m, &pos.start_s, &pos.start_f); | 369 FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f); |
371 FRAMES_TO_MSF (start + length, &pos.end_m, &pos.end_s, &pos.end_f); | 370 FRAMES_TO_MSF(start + length, &pos.end_m, &pos.end_s, &pos.end_f); |
372 if (ioctl (fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR) { | 371 if (ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR) { |
373 okay = 1; | 372 okay = 1; |
374 } | 373 } |
375 close (fd); | 374 close(fd); |
376 } | 375 } |
377 return (okay ? 0 : -1); | 376 return (okay ? 0 : -1); |
378 } | 377 } |
379 | 378 |
380 /* Pause play */ | 379 /* Pause play */ |
381 static int | 380 static int |
382 SDL_SYS_CDPause (SDL_CD * cdrom) | 381 SDL_SYS_CDPause(SDL_CD * cdrom) |
383 { | 382 { |
384 return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_PAUSE_AUDIO, 0)); | 383 return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0)); |
385 } | 384 } |
386 | 385 |
387 /* Resume play */ | 386 /* Resume play */ |
388 static int | 387 static int |
389 SDL_SYS_CDResume (SDL_CD * cdrom) | 388 SDL_SYS_CDResume(SDL_CD * cdrom) |
390 { | 389 { |
391 return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_RESUME_AUDIO, 0)); | 390 return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0)); |
392 } | 391 } |
393 | 392 |
394 /* Stop play */ | 393 /* Stop play */ |
395 static int | 394 static int |
396 SDL_SYS_CDStop (SDL_CD * cdrom) | 395 SDL_SYS_CDStop(SDL_CD * cdrom) |
397 { | 396 { |
398 return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_STOP_AUDIO, 0)); | 397 return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0)); |
399 } | 398 } |
400 | 399 |
401 /* Eject the CD-ROM */ | 400 /* Eject the CD-ROM */ |
402 static int | 401 static int |
403 SDL_SYS_CDEject (SDL_CD * cdrom) | 402 SDL_SYS_CDEject(SDL_CD * cdrom) |
404 { | 403 { |
405 return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_EJECT, 0)); | 404 return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0)); |
406 } | 405 } |
407 | 406 |
408 /* Close the CD-ROM handle */ | 407 /* Close the CD-ROM handle */ |
409 static void | 408 static void |
410 SDL_SYS_CDClose (SDL_CD * cdrom) | 409 SDL_SYS_CDClose(SDL_CD * cdrom) |
411 { | 410 { |
412 close (cdrom->id); | 411 close(cdrom->id); |
413 } | 412 } |
414 | 413 |
415 void | 414 void |
416 SDL_SYS_CDQuit (void) | 415 SDL_SYS_CDQuit(void) |
417 { | 416 { |
418 int i; | 417 int i; |
419 | 418 |
420 if (SDL_numcds > 0) { | 419 if (SDL_numcds > 0) { |
421 for (i = 0; i < SDL_numcds; ++i) { | 420 for (i = 0; i < SDL_numcds; ++i) { |
422 SDL_free (SDL_cdlist[i]); | 421 SDL_free(SDL_cdlist[i]); |
423 } | 422 } |
424 SDL_numcds = 0; | 423 SDL_numcds = 0; |
425 } | 424 } |
426 } | 425 } |
427 | 426 |