annotate src/cdrom/macosx/SDL_syscdrom.c @ 616:12c746afbc27

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