comparison src/cdrom/macosx/SDL_syscdrom.c @ 768:de1b2c3063b9

Max has been reworking this code so it works on MacOS X 10.1
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Jan 2004 16:20:28 +0000
parents 12c746afbc27
children b8d311d90021
comparison
equal deleted inserted replaced
767:d9e79e31a7b7 768:de1b2c3063b9
263 } 263 }
264 264
265 /* Get the Unix disk name of the volume */ 265 /* Get the Unix disk name of the volume */
266 static const char *SDL_SYS_CDName (int drive) 266 static const char *SDL_SYS_CDName (int drive)
267 { 267 {
268 CFStringRef diskID;
269 OSStatus err = noErr; 268 OSStatus err = noErr;
270 269 HParamBlockRec pb;
270 GetVolParmsInfoBuffer volParmsInfo;
271
271 if (fakeCD) 272 if (fakeCD)
272 return "Fake CD-ROM Device"; 273 return "Fake CD-ROM Device";
273 274
274 err = FSCopyDiskIDForVolume (volumes[drive], &diskID); 275 pb.ioParam.ioNamePtr = NULL;
276 pb.ioParam.ioVRefNum = volumes[drive];
277 pb.ioParam.ioBuffer = (Ptr)&volParmsInfo;
278 pb.ioParam.ioReqCount = (SInt32)sizeof(volParmsInfo);
279 err = PBHGetVolParmsSync(&pb);
280
275 if (err != noErr) { 281 if (err != noErr) {
276 SDL_SetError ("FSCopyDiskIDForVolume returned %d", err); 282 SDL_SetError ("PBHGetVolParmsSync returned %d", err);
277 return NULL; 283 return NULL;
278 } 284 }
279 285
280 return CFStringGetCStringPtr (diskID, 0); 286 return volParmsInfo.vMDeviceID;
281 } 287 }
282 288
283 /* Open the "device" */ 289 /* Open the "device" */
284 static int SDL_SYS_CDOpen (int drive) 290 static int SDL_SYS_CDOpen (int drive)
285 { 291 {
316 } 322 }
317 323
318 /* Get CD-ROM status */ 324 /* Get CD-ROM status */
319 static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position) 325 static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position)
320 { 326 {
321 int trackFrame; 327 if (position) {
322 328 int trackFrame;
323 Lock (); 329
324 trackFrame = GetCurrentFrame (); 330 Lock ();
325 Unlock (); 331 trackFrame = GetCurrentFrame ();
326 332 Unlock ();
327 if (position) 333
328 *position = cdrom->track[currentTrack].offset + trackFrame; 334 *position = cdrom->track[currentTrack].offset + trackFrame;
335 }
329 336
330 return status; 337 return status;
331 } 338 }
332 339
333 /* Start playback */ 340 /* Start playback */
381 return -1; 388 return -1;
382 } 389 }
383 390
384 Lock (); 391 Lock ();
385 392
386 if (PauseFile () < 0) 393 if (PauseFile () < 0) {
394 Unlock ();
387 return -2; 395 return -2;
396 }
388 397
389 status = CD_PAUSED; 398 status = CD_PAUSED;
390 399
391 Unlock (); 400 Unlock ();
392 401
401 return -1; 410 return -1;
402 } 411 }
403 412
404 Lock (); 413 Lock ();
405 414
406 if (PlayFile () < 0) 415 if (PauseFile () < 0) {
416 Unlock ();
407 return -2; 417 return -2;
418 }
408 419
409 status = CD_PLAYING; 420 status = CD_PLAYING;
410 421
411 Unlock (); 422 Unlock ();
412 423
421 return -1; 432 return -1;
422 } 433 }
423 434
424 Lock (); 435 Lock ();
425 436
426 if (PauseFile () < 0) 437 if (PauseFile () < 0) {
438 Unlock ();
427 return -2; 439 return -2;
428 440 }
429 if (ReleaseFile () < 0) 441
442 if (ReleaseFile () < 0) {
443 Unlock ();
430 return -3; 444 return -3;
445 }
431 446
432 status = CD_STOPPED; 447 status = CD_STOPPED;
433 448
434 Unlock (); 449 Unlock ();
435 450
438 453
439 /* Eject the CD-ROM (Unmount the volume) */ 454 /* Eject the CD-ROM (Unmount the volume) */
440 static int SDL_SYS_CDEject(SDL_CD *cdrom) 455 static int SDL_SYS_CDEject(SDL_CD *cdrom)
441 { 456 {
442 OSStatus err; 457 OSStatus err;
458 HParamBlockRec pb;
443 459
444 if (fakeCD) { 460 if (fakeCD) {
445 SDL_SetError (kErrorFakeDevice); 461 SDL_SetError (kErrorFakeDevice);
446 return -1; 462 return -1;
447 } 463 }
448 464
449 Lock (); 465 Lock ();
450 466
451 if (PauseFile () < 0) 467 if (PauseFile () < 0) {
468 Unlock ();
452 return -2; 469 return -2;
453 470 }
454 if (ReleaseFile () < 0) 471
472 if (ReleaseFile () < 0) {
473 Unlock ();
455 return -3; 474 return -3;
475 }
456 476
457 status = CD_STOPPED; 477 status = CD_STOPPED;
458 478
459 err = FSEjectVolumeSync (volumes[cdrom->id], 0, NULL); 479 // Eject the volume
460 480 pb.ioParam.ioNamePtr = NULL;
461 if (err != noErr) { 481 pb.ioParam.ioVRefNum = volumes[cdrom->id];
462 SDL_SetError ("FSEjectVolumeSync returned %d", err); 482 err = PBUnmountVol((ParamBlockRec *) &pb);
463 return -4; 483
464 } 484 if (err != noErr) {
485 Unlock ();
486 SDL_SetError ("PBUnmountVol returned %d", err);
487 return -4;
488 }
465 489
466 status = CD_TRAYEMPTY; 490 status = CD_TRAYEMPTY;
467 491
468 /* Invalidate volume and track info */ 492 /* Invalidate volume and track info */
469 volumes[cdrom->id] = 0; 493 volumes[cdrom->id] = 0;