Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
523 lines (404 loc) · 10.9 KB

SDL_syscdrom.c

File metadata and controls

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