comparison src/cdrom/macosx/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 14717b52abc0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
25 25
26 #include "SDL_syscdrom_c.h" 26 #include "SDL_syscdrom_c.h"
27 27
28 #pragma mark -- Globals -- 28 #pragma mark -- Globals --
29 29
30 static FSRef** tracks; 30 static FSRef **tracks;
31 static FSVolumeRefNum* volumes; 31 static FSVolumeRefNum *volumes;
32 static CDstatus status; 32 static CDstatus status;
33 static int nextTrackFrame; 33 static int nextTrackFrame;
34 static int nextTrackFramesRemaining; 34 static int nextTrackFramesRemaining;
35 static int fakeCD; 35 static int fakeCD;
36 static int currentTrack; 36 static int currentTrack;
37 static int didReadTOC; 37 static int didReadTOC;
38 static int cacheTOCNumTracks; 38 static int cacheTOCNumTracks;
39 static int currentDrive; /* Only allow 1 drive in use at a time */ 39 static int currentDrive; /* Only allow 1 drive in use at a time */
40 40
41 #pragma mark -- Prototypes -- 41 #pragma mark -- Prototypes --
42 42
43 static const char *SDL_SYS_CDName (int drive); 43 static const char *SDL_SYS_CDName (int drive);
44 static int SDL_SYS_CDOpen (int drive); 44 static int SDL_SYS_CDOpen (int drive);
45 static int SDL_SYS_CDGetTOC (SDL_CD *cdrom); 45 static int SDL_SYS_CDGetTOC (SDL_CD * cdrom);
46 static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position); 46 static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position);
47 static int SDL_SYS_CDPlay (SDL_CD *cdrom, int start, int length); 47 static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length);
48 static int SDL_SYS_CDPause (SDL_CD *cdrom); 48 static int SDL_SYS_CDPause (SDL_CD * cdrom);
49 static int SDL_SYS_CDResume (SDL_CD *cdrom); 49 static int SDL_SYS_CDResume (SDL_CD * cdrom);
50 static int SDL_SYS_CDStop (SDL_CD *cdrom); 50 static int SDL_SYS_CDStop (SDL_CD * cdrom);
51 static int SDL_SYS_CDEject (SDL_CD *cdrom); 51 static int SDL_SYS_CDEject (SDL_CD * cdrom);
52 static void SDL_SYS_CDClose (SDL_CD *cdrom); 52 static void SDL_SYS_CDClose (SDL_CD * cdrom);
53 53
54 #pragma mark -- Helper Functions -- 54 #pragma mark -- Helper Functions --
55 55
56 /* Read a list of tracks from the volume */ 56 /* Read a list of tracks from the volume */
57 static int LoadTracks (SDL_CD *cdrom) 57 static int
58 LoadTracks (SDL_CD * cdrom)
58 { 59 {
59 /* Check if tracks are already loaded */ 60 /* Check if tracks are already loaded */
60 if ( tracks[cdrom->id] != NULL ) 61 if (tracks[cdrom->id] != NULL)
61 return 0; 62 return 0;
62 63
63 /* Allocate memory for tracks */ 64 /* Allocate memory for tracks */
64 tracks[cdrom->id] = (FSRef*) SDL_calloc (1, sizeof(**tracks) * cdrom->numtracks); 65 tracks[cdrom->id] =
66 (FSRef *) SDL_calloc (1, sizeof (**tracks) * cdrom->numtracks);
65 if (tracks[cdrom->id] == NULL) { 67 if (tracks[cdrom->id] == NULL) {
66 SDL_OutOfMemory (); 68 SDL_OutOfMemory ();
67 return -1; 69 return -1;
68 } 70 }
69 71
70 /* Load tracks */ 72 /* Load tracks */
71 if (ListTrackFiles (volumes[cdrom->id], tracks[cdrom->id], cdrom->numtracks) < 0) 73 if (ListTrackFiles
74 (volumes[cdrom->id], tracks[cdrom->id], cdrom->numtracks) < 0)
72 return -1; 75 return -1;
73 76
74 return 0; 77 return 0;
75 } 78 }
76 79
77 /* Find a file for a given start frame and length */ 80 /* Find a file for a given start frame and length */
78 static FSRef* GetFileForOffset (SDL_CD *cdrom, int start, int length, int *outStartFrame, int *outStopFrame) 81 static FSRef *
82 GetFileForOffset (SDL_CD * cdrom, int start, int length, int *outStartFrame,
83 int *outStopFrame)
79 { 84 {
80 int i; 85 int i;
81 86
82 for (i = 0; i < cdrom->numtracks; i++) { 87 for (i = 0; i < cdrom->numtracks; i++) {
83 88
84 if (cdrom->track[i].offset <= start && 89 if (cdrom->track[i].offset <= start &&
85 start < (cdrom->track[i].offset + cdrom->track[i].length)) 90 start < (cdrom->track[i].offset + cdrom->track[i].length))
86 break; 91 break;
87 } 92 }
88 93
89 if (i == cdrom->numtracks) 94 if (i == cdrom->numtracks)
90 return NULL; 95 return NULL;
91 96
92 currentTrack = i; 97 currentTrack = i;
93 98
94 *outStartFrame = start - cdrom->track[i].offset; 99 *outStartFrame = start - cdrom->track[i].offset;
95 100
96 if ((*outStartFrame + length) < cdrom->track[i].length) { 101 if ((*outStartFrame + length) < cdrom->track[i].length) {
97 *outStopFrame = *outStartFrame + length; 102 *outStopFrame = *outStartFrame + length;
98 length = 0; 103 length = 0;
99 nextTrackFrame = -1; 104 nextTrackFrame = -1;
100 nextTrackFramesRemaining = -1; 105 nextTrackFramesRemaining = -1;
101 } 106 } else {
102 else {
103 *outStopFrame = -1; 107 *outStopFrame = -1;
104 length -= cdrom->track[i].length - *outStartFrame; 108 length -= cdrom->track[i].length - *outStartFrame;
105 nextTrackFrame = cdrom->track[i+1].offset; 109 nextTrackFrame = cdrom->track[i + 1].offset;
106 nextTrackFramesRemaining = length; 110 nextTrackFramesRemaining = length;
107 } 111 }
108 112
109 return &tracks[cdrom->id][i]; 113 return &tracks[cdrom->id][i];
110 } 114 }
111 115
112 /* Setup another file for playback, or stop playback (called from another thread) */ 116 /* Setup another file for playback, or stop playback (called from another thread) */
113 static void CompletionProc (SDL_CD *cdrom) 117 static void
114 { 118 CompletionProc (SDL_CD * cdrom)
115 119 {
120
116 Lock (); 121 Lock ();
117 122
118 if (nextTrackFrame > 0 && nextTrackFramesRemaining > 0) { 123 if (nextTrackFrame > 0 && nextTrackFramesRemaining > 0) {
119 124
120 /* Load the next file to play */ 125 /* Load the next file to play */
121 int startFrame, stopFrame; 126 int startFrame, stopFrame;
122 FSRef *file; 127 FSRef *file;
123 128
124 PauseFile (); 129 PauseFile ();
125 ReleaseFile (); 130 ReleaseFile ();
126 131
127 file = GetFileForOffset (cdrom, nextTrackFrame, 132 file = GetFileForOffset (cdrom, nextTrackFrame,
128 nextTrackFramesRemaining, &startFrame, &stopFrame); 133 nextTrackFramesRemaining, &startFrame,
129 134 &stopFrame);
135
130 if (file == NULL) { 136 if (file == NULL) {
131 status = CD_STOPPED; 137 status = CD_STOPPED;
132 Unlock (); 138 Unlock ();
133 return; 139 return;
134 } 140 }
135 141
136 LoadFile (file, startFrame, stopFrame); 142 LoadFile (file, startFrame, stopFrame);
137 143
138 SetCompletionProc (CompletionProc, cdrom); 144 SetCompletionProc (CompletionProc, cdrom);
139 145
140 PlayFile (); 146 PlayFile ();
141 } 147 } else {
142 else { 148
143
144 /* Release the current file */ 149 /* Release the current file */
145 PauseFile (); 150 PauseFile ();
146 ReleaseFile (); 151 ReleaseFile ();
147 status = CD_STOPPED; 152 status = CD_STOPPED;
148 } 153 }
149 154
150 Unlock (); 155 Unlock ();
151 } 156 }
152 157
153 158
154 #pragma mark -- Driver Functions -- 159 #pragma mark -- Driver Functions --
155 160
156 /* Initialize */ 161 /* Initialize */
157 int SDL_SYS_CDInit (void) 162 int
163 SDL_SYS_CDInit (void)
158 { 164 {
159 /* Initialize globals */ 165 /* Initialize globals */
160 volumes = NULL; 166 volumes = NULL;
161 tracks = NULL; 167 tracks = NULL;
162 status = CD_STOPPED; 168 status = CD_STOPPED;
163 nextTrackFrame = -1; 169 nextTrackFrame = -1;
164 nextTrackFramesRemaining = -1; 170 nextTrackFramesRemaining = -1;
165 fakeCD = SDL_FALSE; 171 fakeCD = SDL_FALSE;
166 currentTrack = -1; 172 currentTrack = -1;
167 didReadTOC = SDL_FALSE; 173 didReadTOC = SDL_FALSE;
168 cacheTOCNumTracks = -1; 174 cacheTOCNumTracks = -1;
169 currentDrive = -1; 175 currentDrive = -1;
170 176
171 /* Fill in function pointers */ 177 /* Fill in function pointers */
172 SDL_CDcaps.Name = SDL_SYS_CDName; 178 SDL_CDcaps.Name = SDL_SYS_CDName;
173 SDL_CDcaps.Open = SDL_SYS_CDOpen; 179 SDL_CDcaps.Open = SDL_SYS_CDOpen;
174 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; 180 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
175 SDL_CDcaps.Status = SDL_SYS_CDStatus; 181 SDL_CDcaps.Status = SDL_SYS_CDStatus;
176 SDL_CDcaps.Play = SDL_SYS_CDPlay; 182 SDL_CDcaps.Play = SDL_SYS_CDPlay;
177 SDL_CDcaps.Pause = SDL_SYS_CDPause; 183 SDL_CDcaps.Pause = SDL_SYS_CDPause;
178 SDL_CDcaps.Resume = SDL_SYS_CDResume; 184 SDL_CDcaps.Resume = SDL_SYS_CDResume;
179 SDL_CDcaps.Stop = SDL_SYS_CDStop; 185 SDL_CDcaps.Stop = SDL_SYS_CDStop;
180 SDL_CDcaps.Eject = SDL_SYS_CDEject; 186 SDL_CDcaps.Eject = SDL_SYS_CDEject;
181 SDL_CDcaps.Close = SDL_SYS_CDClose; 187 SDL_CDcaps.Close = SDL_SYS_CDClose;
182 188
183 /* 189 /*
184 Read the list of "drives" 190 Read the list of "drives"
185 191
186 This is currently a hack that infers drives from 192 This is currently a hack that infers drives from
187 mounted audio CD volumes, rather than 193 mounted audio CD volumes, rather than
188 actual CD-ROM devices - which means it may not 194 actual CD-ROM devices - which means it may not
189 act as expected sometimes. 195 act as expected sometimes.
190 */ 196 */
191 197
192 /* Find out how many cd volumes are mounted */ 198 /* Find out how many cd volumes are mounted */
193 SDL_numcds = DetectAudioCDVolumes (NULL, 0); 199 SDL_numcds = DetectAudioCDVolumes (NULL, 0);
194 200
195 /* 201 /*
196 If there are no volumes, fake a cd device 202 If there are no volumes, fake a cd device
197 so tray empty can be reported. 203 so tray empty can be reported.
198 */ 204 */
199 if (SDL_numcds == 0) { 205 if (SDL_numcds == 0) {
200 206
201 fakeCD = SDL_TRUE; 207 fakeCD = SDL_TRUE;
202 SDL_numcds = 1; 208 SDL_numcds = 1;
203 status = CD_TRAYEMPTY; 209 status = CD_TRAYEMPTY;
204 210
205 return 0; 211 return 0;
206 } 212 }
207 213
208 /* Allocate space for volumes */ 214 /* Allocate space for volumes */
209 volumes = (FSVolumeRefNum*) SDL_calloc (1, sizeof(*volumes) * SDL_numcds); 215 volumes =
216 (FSVolumeRefNum *) SDL_calloc (1, sizeof (*volumes) * SDL_numcds);
210 if (volumes == NULL) { 217 if (volumes == NULL) {
211 SDL_OutOfMemory (); 218 SDL_OutOfMemory ();
212 return -1; 219 return -1;
213 } 220 }
214 221
215 /* Allocate space for tracks */ 222 /* Allocate space for tracks */
216 tracks = (FSRef**) SDL_calloc (1, sizeof(*tracks) * (SDL_numcds + 1)); 223 tracks = (FSRef **) SDL_calloc (1, sizeof (*tracks) * (SDL_numcds + 1));
217 if (tracks == NULL) { 224 if (tracks == NULL) {
218 SDL_OutOfMemory (); 225 SDL_OutOfMemory ();
219 return -1; 226 return -1;
220 } 227 }
221 228
222 /* Mark the end of the tracks array */ 229 /* Mark the end of the tracks array */
223 tracks[ SDL_numcds ] = (FSRef*)-1; 230 tracks[SDL_numcds] = (FSRef *) - 1;
224 231
225 /* 232 /*
226 Redetect, now save all volumes for later 233 Redetect, now save all volumes for later
227 Update SDL_numcds just in case it changed 234 Update SDL_numcds just in case it changed
228 */ 235 */
229 { 236 {
230 int numVolumes = SDL_numcds; 237 int numVolumes = SDL_numcds;
231 238
232 SDL_numcds = DetectAudioCDVolumes (volumes, numVolumes); 239 SDL_numcds = DetectAudioCDVolumes (volumes, numVolumes);
233 240
234 /* If more cds suddenly show up, ignore them */ 241 /* If more cds suddenly show up, ignore them */
235 if (SDL_numcds > numVolumes) { 242 if (SDL_numcds > numVolumes) {
236 SDL_SetError ("Some CD's were added but they will be ignored"); 243 SDL_SetError ("Some CD's were added but they will be ignored");
237 SDL_numcds = numVolumes; 244 SDL_numcds = numVolumes;
238 } 245 }
239 } 246 }
240 247
241 return 0; 248 return 0;
242 } 249 }
243 250
244 /* Shutdown and cleanup */ 251 /* Shutdown and cleanup */
245 void SDL_SYS_CDQuit(void) 252 void
246 { 253 SDL_SYS_CDQuit (void)
247 ReleaseFile(); 254 {
248 255 ReleaseFile ();
256
249 if (volumes != NULL) 257 if (volumes != NULL)
250 free (volumes); 258 free (volumes);
251 259
252 if (tracks != NULL) { 260 if (tracks != NULL) {
253 261
254 FSRef **ptr; 262 FSRef **ptr;
255 for (ptr = tracks; *ptr != (FSRef*)-1; ptr++) 263 for (ptr = tracks; *ptr != (FSRef *) - 1; ptr++)
256 if (*ptr != NULL) 264 if (*ptr != NULL)
257 free (*ptr); 265 free (*ptr);
258 266
259 free (tracks); 267 free (tracks);
260 } 268 }
261 } 269 }
262 270
263 /* Get the Unix disk name of the volume */ 271 /* Get the Unix disk name of the volume */
264 static const char *SDL_SYS_CDName (int drive) 272 static const char *
265 { 273 SDL_SYS_CDName (int drive)
266 OSStatus err = noErr; 274 {
267 HParamBlockRec pb; 275 OSStatus err = noErr;
268 GetVolParmsInfoBuffer volParmsInfo; 276 HParamBlockRec pb;
269 277 GetVolParmsInfoBuffer volParmsInfo;
278
270 if (fakeCD) 279 if (fakeCD)
271 return "Fake CD-ROM Device"; 280 return "Fake CD-ROM Device";
272 281
273 pb.ioParam.ioNamePtr = NULL; 282 pb.ioParam.ioNamePtr = NULL;
274 pb.ioParam.ioVRefNum = volumes[drive]; 283 pb.ioParam.ioVRefNum = volumes[drive];
275 pb.ioParam.ioBuffer = (Ptr)&volParmsInfo; 284 pb.ioParam.ioBuffer = (Ptr) & volParmsInfo;
276 pb.ioParam.ioReqCount = (SInt32)sizeof(volParmsInfo); 285 pb.ioParam.ioReqCount = (SInt32) sizeof (volParmsInfo);
277 err = PBHGetVolParmsSync(&pb); 286 err = PBHGetVolParmsSync (&pb);
278 287
279 if (err != noErr) { 288 if (err != noErr) {
280 SDL_SetError ("PBHGetVolParmsSync returned %d", err); 289 SDL_SetError ("PBHGetVolParmsSync returned %d", err);
281 return NULL; 290 return NULL;
282 } 291 }
283 292
284 return volParmsInfo.vMDeviceID; 293 return volParmsInfo.vMDeviceID;
285 } 294 }
286 295
287 /* Open the "device" */ 296 /* Open the "device" */
288 static int SDL_SYS_CDOpen (int drive) 297 static int
298 SDL_SYS_CDOpen (int drive)
289 { 299 {
290 /* Only allow 1 device to be open */ 300 /* Only allow 1 device to be open */
291 if (currentDrive >= 0) { 301 if (currentDrive >= 0) {
292 SDL_SetError ("Only one cdrom is supported"); 302 SDL_SetError ("Only one cdrom is supported");
293 return -1; 303 return -1;
294 } 304 } else
295 else
296 currentDrive = drive; 305 currentDrive = drive;
297 306
298 return drive; 307 return drive;
299 } 308 }
300 309
301 /* Get the table of contents */ 310 /* Get the table of contents */
302 static int SDL_SYS_CDGetTOC (SDL_CD *cdrom) 311 static int
312 SDL_SYS_CDGetTOC (SDL_CD * cdrom)
303 { 313 {
304 if (fakeCD) { 314 if (fakeCD) {
305 SDL_SetError (kErrorFakeDevice); 315 SDL_SetError (kErrorFakeDevice);
306 return -1; 316 return -1;
307 } 317 }
308 318
309 if (didReadTOC) { 319 if (didReadTOC) {
310 cdrom->numtracks = cacheTOCNumTracks; 320 cdrom->numtracks = cacheTOCNumTracks;
311 return 0; 321 return 0;
312 } 322 }
313 323
314 324
315 ReadTOCData (volumes[cdrom->id], cdrom); 325 ReadTOCData (volumes[cdrom->id], cdrom);
316 didReadTOC = SDL_TRUE; 326 didReadTOC = SDL_TRUE;
317 cacheTOCNumTracks = cdrom->numtracks; 327 cacheTOCNumTracks = cdrom->numtracks;
318 328
319 return 0; 329 return 0;
320 } 330 }
321 331
322 /* Get CD-ROM status */ 332 /* Get CD-ROM status */
323 static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position) 333 static CDstatus
334 SDL_SYS_CDStatus (SDL_CD * cdrom, int *position)
324 { 335 {
325 if (position) { 336 if (position) {
326 int trackFrame; 337 int trackFrame;
327 338
328 Lock (); 339 Lock ();
329 trackFrame = GetCurrentFrame (); 340 trackFrame = GetCurrentFrame ();
330 Unlock (); 341 Unlock ();
331 342
332 *position = cdrom->track[currentTrack].offset + trackFrame; 343 *position = cdrom->track[currentTrack].offset + trackFrame;
333 } 344 }
334 345
335 return status; 346 return status;
336 } 347 }
337 348
338 /* Start playback */ 349 /* Start playback */
339 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 350 static int
351 SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length)
340 { 352 {
341 int startFrame, stopFrame; 353 int startFrame, stopFrame;
342 FSRef *ref; 354 FSRef *ref;
343 355
344 if (fakeCD) { 356 if (fakeCD) {
345 SDL_SetError (kErrorFakeDevice); 357 SDL_SetError (kErrorFakeDevice);
346 return -1; 358 return -1;
347 } 359 }
348 360
349 Lock(); 361 Lock ();
350 362
351 if (LoadTracks (cdrom) < 0) 363 if (LoadTracks (cdrom) < 0)
352 return -2; 364 return -2;
353 365
354 if (PauseFile () < 0) 366 if (PauseFile () < 0)
355 return -3; 367 return -3;
356 368
357 if (ReleaseFile () < 0) 369 if (ReleaseFile () < 0)
358 return -4; 370 return -4;
359 371
360 ref = GetFileForOffset (cdrom, start, length, &startFrame, &stopFrame); 372 ref = GetFileForOffset (cdrom, start, length, &startFrame, &stopFrame);
361 if (ref == NULL) { 373 if (ref == NULL) {
362 SDL_SetError ("SDL_SYS_CDPlay: No file for start=%d, length=%d", start, length); 374 SDL_SetError ("SDL_SYS_CDPlay: No file for start=%d, length=%d",
375 start, length);
363 return -5; 376 return -5;
364 } 377 }
365 378
366 if (LoadFile (ref, startFrame, stopFrame) < 0) 379 if (LoadFile (ref, startFrame, stopFrame) < 0)
367 return -6; 380 return -6;
368 381
369 SetCompletionProc (CompletionProc, cdrom); 382 SetCompletionProc (CompletionProc, cdrom);
370 383
371 if (PlayFile () < 0) 384 if (PlayFile () < 0)
372 return -7; 385 return -7;
373 386
374 status = CD_PLAYING; 387 status = CD_PLAYING;
375 388
376 Unlock(); 389 Unlock ();
377 390
378 return 0; 391 return 0;
379 } 392 }
380 393
381 /* Pause playback */ 394 /* Pause playback */
382 static int SDL_SYS_CDPause(SDL_CD *cdrom) 395 static int
396 SDL_SYS_CDPause (SDL_CD * cdrom)
383 { 397 {
384 if (fakeCD) { 398 if (fakeCD) {
385 SDL_SetError (kErrorFakeDevice); 399 SDL_SetError (kErrorFakeDevice);
386 return -1; 400 return -1;
387 } 401 }
388 402
389 Lock (); 403 Lock ();
390 404
391 if (PauseFile () < 0) { 405 if (PauseFile () < 0) {
392 Unlock (); 406 Unlock ();
393 return -2; 407 return -2;
394 } 408 }
395 409
396 status = CD_PAUSED; 410 status = CD_PAUSED;
397 411
398 Unlock (); 412 Unlock ();
399 413
400 return 0; 414 return 0;
401 } 415 }
402 416
403 /* Resume playback */ 417 /* Resume playback */
404 static int SDL_SYS_CDResume(SDL_CD *cdrom) 418 static int
419 SDL_SYS_CDResume (SDL_CD * cdrom)
405 { 420 {
406 if (fakeCD) { 421 if (fakeCD) {
407 SDL_SetError (kErrorFakeDevice); 422 SDL_SetError (kErrorFakeDevice);
408 return -1; 423 return -1;
409 } 424 }
410 425
411 Lock (); 426 Lock ();
412 427
413 if (PlayFile () < 0) { 428 if (PlayFile () < 0) {
414 Unlock (); 429 Unlock ();
415 return -2; 430 return -2;
416 } 431 }
417 432
418 status = CD_PLAYING; 433 status = CD_PLAYING;
419 434
420 Unlock (); 435 Unlock ();
421 436
422 return 0; 437 return 0;
423 } 438 }
424 439
425 /* Stop playback */ 440 /* Stop playback */
426 static int SDL_SYS_CDStop(SDL_CD *cdrom) 441 static int
442 SDL_SYS_CDStop (SDL_CD * cdrom)
427 { 443 {
428 if (fakeCD) { 444 if (fakeCD) {
429 SDL_SetError (kErrorFakeDevice); 445 SDL_SetError (kErrorFakeDevice);
430 return -1; 446 return -1;
431 } 447 }
432 448
433 Lock (); 449 Lock ();
434 450
435 if (PauseFile () < 0) { 451 if (PauseFile () < 0) {
436 Unlock (); 452 Unlock ();
437 return -2; 453 return -2;
438 } 454 }
439 455
440 if (ReleaseFile () < 0) { 456 if (ReleaseFile () < 0) {
441 Unlock (); 457 Unlock ();
442 return -3; 458 return -3;
443 } 459 }
444 460
445 status = CD_STOPPED; 461 status = CD_STOPPED;
446 462
447 Unlock (); 463 Unlock ();
448 464
449 return 0; 465 return 0;
450 } 466 }
451 467
452 /* Eject the CD-ROM (Unmount the volume) */ 468 /* Eject the CD-ROM (Unmount the volume) */
453 static int SDL_SYS_CDEject(SDL_CD *cdrom) 469 static int
470 SDL_SYS_CDEject (SDL_CD * cdrom)
454 { 471 {
455 OSStatus err; 472 OSStatus err;
456 pid_t dissenter; 473 pid_t dissenter;
457 474
458 if (fakeCD) { 475 if (fakeCD) {
459 SDL_SetError (kErrorFakeDevice); 476 SDL_SetError (kErrorFakeDevice);
460 return -1; 477 return -1;
461 } 478 }
462 479
463 Lock (); 480 Lock ();
464 481
465 if (PauseFile () < 0) { 482 if (PauseFile () < 0) {
466 Unlock (); 483 Unlock ();
467 return -2; 484 return -2;
468 } 485 }
469 486
470 if (ReleaseFile () < 0) { 487 if (ReleaseFile () < 0) {
471 Unlock (); 488 Unlock ();
472 return -3; 489 return -3;
473 } 490 }
474 491
475 status = CD_STOPPED; 492 status = CD_STOPPED;
476 493
477 /* Eject the volume */ 494 /* Eject the volume */
478 err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter); 495 err = FSEjectVolumeSync (volumes[cdrom->id], kNilOptions, &dissenter);
479 496
480 if (err != noErr) { 497 if (err != noErr) {
481 Unlock (); 498 Unlock ();
482 SDL_SetError ("PBUnmountVol returned %d", err); 499 SDL_SetError ("PBUnmountVol returned %d", err);
483 return -4; 500 return -4;
484 } 501 }
485 502
486 status = CD_TRAYEMPTY; 503 status = CD_TRAYEMPTY;
487 504
488 /* Invalidate volume and track info */ 505 /* Invalidate volume and track info */
489 volumes[cdrom->id] = 0; 506 volumes[cdrom->id] = 0;
490 free (tracks[cdrom->id]); 507 free (tracks[cdrom->id]);
491 tracks[cdrom->id] = NULL; 508 tracks[cdrom->id] = NULL;
492 509
493 Unlock (); 510 Unlock ();
494 511
495 return 0; 512 return 0;
496 } 513 }
497 514
498 /* Close the CD-ROM */ 515 /* Close the CD-ROM */
499 static void SDL_SYS_CDClose(SDL_CD *cdrom) 516 static void
517 SDL_SYS_CDClose (SDL_CD * cdrom)
500 { 518 {
501 currentDrive = -1; 519 currentDrive = -1;
502 return; 520 return;
503 } 521 }
504 522
505 #endif /* SDL_CDROM_MACOSX */ 523 #endif /* SDL_CDROM_MACOSX */
524 /* vi: set ts=4 sw=4 expandtab: */