Mercurial > sdl-ios-xcode
annotate src/cdrom/macos/SDL_syscdrom.c @ 1521:9b9212e4810c
CFLAGS are separate from EXTRA_CFLAGS
Fixed iconv.h detection on Cygwin32
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 14 Mar 2006 02:46:26 +0000 |
parents | d910939febfa |
children | 92947e3a18db |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* MacOS functions for system-level CD-ROM audio control */ | |
25 | |
26 #include <Devices.h> | |
27 #include <Files.h> | |
28 #include <LowMem.h> /* Use entry table macros, not functions in InterfaceLib */ | |
29 | |
30 #include "SDL_cdrom.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
31 #include "../SDL_syscdrom.h" |
0 | 32 #include "SDL_syscdrom_c.h" |
33 | |
34 /* Added by Matt Slot */ | |
35 #if !defined(LMGetUnitTableEntryCount) | |
36 #define LMGetUnitTableEntryCount() *(short *)0x01D2 | |
37 #endif | |
38 | |
39 /* The maximum number of CD-ROM drives we'll detect */ | |
40 #define MAX_DRIVES 26 | |
41 | |
42 /* A list of available CD-ROM drives */ | |
43 static long SDL_cdversion = 0; | |
44 static struct { | |
45 short dRefNum; | |
46 short driveNum; | |
47 long frames; | |
48 char name[256]; | |
49 Boolean hasAudio; | |
50 } SDL_cdlist[MAX_DRIVES]; | |
51 static StringPtr gDriverName = "\p.AppleCD"; | |
52 | |
53 /* The system-dependent CD control functions */ | |
54 static const char *SDL_SYS_CDName(int drive); | |
55 static int SDL_SYS_CDOpen(int drive); | |
56 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
57 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
58 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
59 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
60 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
61 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
62 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
63 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
64 | |
65 static short SDL_SYS_ShortToBCD(short value) | |
66 { | |
67 return((value % 10) + (value / 10) * 0x10); /* Convert value to BCD */ | |
68 } | |
69 | |
70 static short SDL_SYS_BCDToShort(short value) | |
71 { | |
72 return((value % 0x10) + (value / 0x10) * 10); /* Convert value from BCD */ | |
73 } | |
74 | |
75 int SDL_SYS_CDInit(void) | |
76 { | |
77 SInt16 dRefNum = 0; | |
78 SInt16 first, last; | |
79 | |
80 SDL_numcds = 0; | |
81 | |
82 /* Check that the software is available */ | |
83 if (Gestalt(kGestaltAudioCDSelector, &SDL_cdversion) || | |
84 !SDL_cdversion) return(0); | |
85 | |
86 /* Fill in our driver capabilities */ | |
87 SDL_CDcaps.Name = SDL_SYS_CDName; | |
88 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
89 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
90 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
91 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
92 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
93 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
94 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
95 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
96 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
97 | |
98 /* Walk the list, count each AudioCD driver, and save the refnums */ | |
99 first = -1; | |
100 last = 0 - LMGetUnitTableEntryCount(); | |
101 for(dRefNum = first; dRefNum >= last; dRefNum--) { | |
102 Str255 driverName; | |
103 StringPtr namePtr; | |
104 DCtlHandle deviceEntry; | |
105 | |
106 deviceEntry = GetDCtlEntry(dRefNum); | |
107 if (! deviceEntry) continue; | |
108 | |
109 /* Is this an .AppleCD ? */ | |
110 namePtr = (*deviceEntry)->dCtlFlags & (1L << dRAMBased) ? | |
111 ((StringPtr) ((DCtlPtr) deviceEntry)->dCtlDriver + 18) : | |
112 ((StringPtr) (*deviceEntry)->dCtlDriver + 18); | |
113 BlockMoveData(namePtr, driverName, namePtr[0]+1); | |
114 if (driverName[0] > gDriverName[0]) driverName[0] = gDriverName[0]; | |
115 if (! EqualString(driverName, gDriverName, false, false)) continue; | |
116 | |
117 /* Record the basic info for each drive */ | |
118 SDL_cdlist[SDL_numcds].dRefNum = dRefNum; | |
119 BlockMoveData(namePtr + 1, SDL_cdlist[SDL_numcds].name, namePtr[0]); | |
120 SDL_cdlist[SDL_numcds].name[namePtr[0]] = 0; | |
121 SDL_cdlist[SDL_numcds].hasAudio = false; | |
122 SDL_numcds++; | |
123 } | |
124 return(0); | |
125 } | |
126 | |
127 static const char *SDL_SYS_CDName(int drive) | |
128 { | |
129 return(SDL_cdlist[drive].name); | |
130 } | |
131 | |
132 static int get_drivenum(int drive) | |
133 { | |
134 QHdr *driveQ = GetDrvQHdr(); | |
135 DrvQEl *driveElem; | |
136 | |
137 /* Update the drive number */ | |
138 SDL_cdlist[drive].driveNum = 0; | |
139 if ( driveQ->qTail ) { | |
140 driveQ->qTail->qLink = 0; | |
141 } | |
142 for ( driveElem=(DrvQEl *)driveQ->qHead; driveElem; | |
143 driveElem = (DrvQEl *)driveElem->qLink ) { | |
144 if ( driveElem->dQRefNum == SDL_cdlist[drive].dRefNum ) { | |
145 SDL_cdlist[drive].driveNum = driveElem->dQDrive; | |
146 break; | |
147 } | |
148 } | |
149 return(SDL_cdlist[drive].driveNum); | |
150 } | |
151 | |
152 static int SDL_SYS_CDOpen(int drive) | |
153 { | |
154 return(drive); | |
155 } | |
156 | |
157 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
158 { | |
159 CDCntrlParam cdpb; | |
160 CDTrackData tracks[SDL_MAX_TRACKS]; | |
161 long i, leadout; | |
162 | |
163 /* Get the number of tracks on the CD by examining the TOC */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
164 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 165 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
166 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
167 cdpb.csCode = kReadTOC; | |
168 cdpb.csParam.words[0] = kGetTrackRange; | |
169 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
170 SDL_SetError("PBControlSync() failed"); | |
171 return(-1); | |
172 } | |
173 | |
174 cdrom->numtracks = | |
175 SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - | |
176 SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1; | |
177 if ( cdrom->numtracks > SDL_MAX_TRACKS ) | |
178 cdrom->numtracks = SDL_MAX_TRACKS; | |
179 cdrom->status = CD_STOPPED; | |
180 cdrom->cur_track = 0; /* Apparently these are set elsewhere */ | |
181 cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ | |
182 | |
183 | |
184 /* Get the lead out area of the CD by examining the TOC */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
185 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 186 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
187 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
188 cdpb.csCode = kReadTOC; | |
189 cdpb.csParam.words[0] = kGetLeadOutArea; | |
190 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
191 SDL_SetError("PBControlSync() failed"); | |
192 return(-1); | |
193 } | |
194 | |
195 leadout = MSF_TO_FRAMES( | |
196 SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]), | |
197 SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]), | |
198 SDL_SYS_BCDToShort(cdpb.csParam.bytes[2])); | |
199 | |
200 /* Get an array of track locations by examining the TOC */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
201 SDL_memset(tracks, 0, sizeof(tracks)); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
202 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 203 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
204 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
205 cdpb.csCode = kReadTOC; | |
206 cdpb.csParam.words[0] = kGetTrackEntries; /* Type of Query */ | |
207 * ((long *) (cdpb.csParam.words+1)) = (long) tracks; | |
208 cdpb.csParam.words[3] = cdrom->numtracks * sizeof(tracks[0]); | |
209 * ((char *) (cdpb.csParam.words+4)) = 1; /* First track */ | |
210 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
211 SDL_SetError("PBControlSync() failed"); | |
212 return(-1); | |
213 } | |
214 | |
215 /* Read all the track TOC entries */ | |
216 SDL_cdlist[cdrom->id].hasAudio = false; | |
217 for ( i=0; i<cdrom->numtracks; ++i ) | |
218 { | |
219 cdrom->track[i].id = i+1; | |
220 if (tracks[i].entry.control & kDataTrackMask) | |
221 cdrom->track[i].type = SDL_DATA_TRACK; | |
222 else | |
223 { | |
224 cdrom->track[i].type = SDL_AUDIO_TRACK; | |
225 SDL_cdlist[SDL_numcds].hasAudio = true; | |
226 } | |
227 | |
228 cdrom->track[i].offset = MSF_TO_FRAMES( | |
229 SDL_SYS_BCDToShort(tracks[i].entry.min), | |
230 SDL_SYS_BCDToShort(tracks[i].entry.min), | |
231 SDL_SYS_BCDToShort(tracks[i].entry.frame)); | |
232 cdrom->track[i].length = MSF_TO_FRAMES( | |
233 SDL_SYS_BCDToShort(tracks[i+1].entry.min), | |
234 SDL_SYS_BCDToShort(tracks[i+1].entry.min), | |
235 SDL_SYS_BCDToShort(tracks[i+1].entry.frame)) - | |
236 cdrom->track[i].offset; | |
237 } | |
238 | |
239 /* Apparently SDL wants a fake last entry */ | |
240 cdrom->track[i].offset = leadout; | |
241 cdrom->track[i].length = 0; | |
242 | |
243 return(0); | |
244 } | |
245 | |
246 /* Get CD-ROM status */ | |
247 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
248 { | |
249 CDCntrlParam cdpb; | |
250 CDstatus status = CD_ERROR; | |
251 Boolean spinning = false; | |
252 | |
253 if (position) *position = 0; | |
254 | |
255 /* Get the number of tracks on the CD by examining the TOC */ | |
256 if ( ! get_drivenum(cdrom->id) ) { | |
257 return(CD_TRAYEMPTY); | |
258 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
259 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 260 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
261 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
262 cdpb.csCode = kReadTOC; | |
263 cdpb.csParam.words[0] = kGetTrackRange; | |
264 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
265 SDL_SetError("PBControlSync() failed"); | |
266 return(CD_ERROR); | |
267 } | |
268 | |
269 cdrom->numtracks = | |
270 SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - | |
271 SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1; | |
272 if ( cdrom->numtracks > SDL_MAX_TRACKS ) | |
273 cdrom->numtracks = SDL_MAX_TRACKS; | |
274 cdrom->cur_track = 0; /* Apparently these are set elsewhere */ | |
275 cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ | |
276 | |
277 | |
278 if (1 || SDL_cdlist[cdrom->id].hasAudio) { | |
279 /* Get the current playback status */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
280 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 281 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
282 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
283 cdpb.csCode = kAudioStatus; | |
284 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
285 SDL_SetError("PBControlSync() failed"); | |
286 return(-1); | |
287 } | |
288 | |
289 switch(cdpb.csParam.cd.status) { | |
290 case kStatusPlaying: | |
291 status = CD_PLAYING; | |
292 spinning = true; | |
293 break; | |
294 case kStatusPaused: | |
295 status = CD_PAUSED; | |
296 spinning = true; | |
297 break; | |
298 case kStatusMuted: | |
299 status = CD_PLAYING; /* What should I do here? */ | |
300 spinning = true; | |
301 break; | |
302 case kStatusDone: | |
303 status = CD_STOPPED; | |
304 spinning = true; | |
305 break; | |
306 case kStatusStopped: | |
307 status = CD_STOPPED; | |
308 spinning = false; | |
309 break; | |
310 case kStatusError: | |
311 default: | |
312 status = CD_ERROR; | |
313 spinning = false; | |
314 break; | |
315 } | |
316 | |
317 if (spinning && position) *position = MSF_TO_FRAMES( | |
318 SDL_SYS_BCDToShort(cdpb.csParam.cd.minute), | |
319 SDL_SYS_BCDToShort(cdpb.csParam.cd.second), | |
320 SDL_SYS_BCDToShort(cdpb.csParam.cd.frame)); | |
321 } | |
322 else | |
323 status = CD_ERROR; /* What should I do here? */ | |
324 | |
325 return(status); | |
326 } | |
327 | |
328 /* Start play */ | |
329 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
330 { | |
331 CDCntrlParam cdpb; | |
332 | |
333 /* Pause the current audio playback to avoid audible artifacts */ | |
334 if ( SDL_SYS_CDPause(cdrom) < 0 ) { | |
335 return(-1); | |
336 } | |
337 | |
338 /* Specify the AudioCD playback mode */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
339 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 340 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
341 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
342 cdpb.csCode = kSetPlayMode; | |
343 cdpb.csParam.bytes[0] = false; /* Repeat? */ | |
344 cdpb.csParam.bytes[1] = kPlayModeSequential; /* Play mode */ | |
345 /* ¥¥¥ÊTreat as soft error, NEC Drive doesnt support this call ¥¥¥ */ | |
346 PBControlSync((ParmBlkPtr) &cdpb); | |
347 | |
348 #if 1 | |
349 /* Specify the end of audio playback */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
350 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 351 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
352 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
353 cdpb.csCode = kAudioStop; | |
354 cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ | |
355 *(long *) (cdpb.csParam.words + 1) = start+length-1; /* Search Address */ | |
356 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
357 SDL_SetError("PBControlSync() failed"); | |
358 return(-1); | |
359 } | |
360 | |
361 /* Specify the start of audio playback, and start it */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
362 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 363 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
364 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
365 cdpb.csCode = kAudioPlay; | |
366 cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ | |
367 *(long *) (cdpb.csParam.words + 1) = start+1; /* Search Address */ | |
368 cdpb.csParam.words[3] = false; /* Stop address? */ | |
369 cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ | |
370 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
371 SDL_SetError("PBControlSync() failed"); | |
372 return(-1); | |
373 } | |
374 #else | |
375 /* Specify the end of audio playback */ | |
376 FRAMES_TO_MSF(start+length, &m, &s, &f); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
377 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 378 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
379 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
380 cdpb.csCode = kAudioStop; | |
381 cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ | |
382 cdpb.csParam.words[1] = 0; /* Search Address (hiword)*/ | |
383 cdpb.csParam.words[2] = /* Search Address (loword)*/ | |
384 SDL_SYS_ShortToBCD(cdrom->numtracks); | |
385 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
386 SDL_SetError("PBControlSync() failed"); | |
387 return(-1); | |
388 } | |
389 | |
390 /* Specify the start of audio playback, and start it */ | |
391 FRAMES_TO_MSF(start, &m, &s, &f); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
392 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 393 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
394 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
395 cdpb.csCode = kAudioPlay; | |
396 cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ | |
397 cdpb.csParam.words[1] = 0; /* Search Address (hiword)*/ | |
398 cdpb.csParam.words[2] = SDL_SYS_ShortToBCD(1); /* Search Address (loword)*/ | |
399 cdpb.csParam.words[3] = false; /* Stop address? */ | |
400 cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ | |
401 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
402 SDL_SetError("PBControlSync() failed"); | |
403 return(-1); | |
404 } | |
405 #endif | |
406 | |
407 return(0); | |
408 } | |
409 | |
410 /* Pause play */ | |
411 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
412 { | |
413 CDCntrlParam cdpb; | |
414 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
415 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 416 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
417 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
418 cdpb.csCode = kAudioPause; | |
419 cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ | |
420 cdpb.csParam.words[1] = 1; /* Pause/Continue Flag (loword) */ | |
421 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
422 SDL_SetError("PBControlSync() failed"); | |
423 return(-1); | |
424 } | |
425 return(0); | |
426 } | |
427 | |
428 /* Resume play */ | |
429 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
430 { | |
431 CDCntrlParam cdpb; | |
432 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
433 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 434 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
435 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
436 cdpb.csCode = kAudioPause; | |
437 cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ | |
438 cdpb.csParam.words[1] = 0; /* Pause/Continue Flag (loword) */ | |
439 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
440 SDL_SetError("PBControlSync() failed"); | |
441 return(-1); | |
442 } | |
443 return(0); | |
444 } | |
445 | |
446 /* Stop play */ | |
447 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
448 { | |
449 CDCntrlParam cdpb; | |
450 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
451 SDL_memset(&cdpb, 0, sizeof(cdpb)); |
0 | 452 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; |
453 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
454 cdpb.csCode = kAudioStop; | |
455 cdpb.csParam.words[0] = 0; /* Position Mode */ | |
456 cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ | |
457 cdpb.csParam.words[2] = 0; /* Search Address (loword) */ | |
458 if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { | |
459 SDL_SetError("PBControlSync() failed"); | |
460 return(-1); | |
461 } | |
462 return(0); | |
463 } | |
464 | |
465 /* Eject the CD-ROM */ | |
466 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
467 { | |
468 Boolean disk = false; | |
469 QHdr *driveQ = GetDrvQHdr(); | |
470 DrvQEl *driveElem; | |
471 HParamBlockRec hpb; | |
472 ParamBlockRec cpb; | |
473 | |
474 for ( driveElem = (DrvQEl *) driveQ->qHead; driveElem; driveElem = | |
475 (driveElem) ? ((DrvQEl *) driveElem->qLink) : | |
476 ((DrvQEl *) driveQ->qHead) ) { | |
477 if ( driveQ->qTail ) { | |
478 driveQ->qTail->qLink = 0; | |
479 } | |
480 if ( driveElem->dQRefNum != SDL_cdlist[cdrom->id].dRefNum ) { | |
481 continue; | |
482 } | |
483 | |
484 /* Does drive contain mounted volume? If not, skip */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
485 SDL_memset(&hpb, 0, sizeof(hpb)); |
0 | 486 hpb.volumeParam.ioVRefNum = driveElem->dQDrive; |
487 if ( PBHGetVInfoSync(&hpb) != noErr ) { | |
488 continue; | |
489 } | |
490 if ( (UnmountVol(0, driveElem->dQDrive) == noErr) && | |
491 (Eject(0, driveElem->dQDrive) == noErr) ) { | |
492 driveElem = 0; /* Clear pointer to reset our loop */ | |
493 disk = true; | |
494 } | |
495 } | |
496 | |
497 /* If no disk is present, just eject the tray */ | |
498 if (! disk) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
499 SDL_memset(&cpb, 0, sizeof(cpb)); |
0 | 500 cpb.cntrlParam.ioVRefNum = 0; /* No Drive */ |
501 cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; | |
502 cpb.cntrlParam.csCode = kEjectTheDisc; | |
503 if ( PBControlSync((ParmBlkPtr)&cpb) != noErr ) { | |
504 SDL_SetError("PBControlSync() failed"); | |
505 return(-1); | |
506 } | |
507 } | |
508 return(0); | |
509 } | |
510 | |
511 /* Close the CD-ROM handle */ | |
512 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
513 { | |
514 return; | |
515 } | |
516 | |
517 void SDL_SYS_CDQuit(void) | |
518 { | |
519 while(SDL_numcds--) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
520 SDL_memset(SDL_cdlist + SDL_numcds, 0, sizeof(SDL_cdlist[0])); |
0 | 521 } |
522 |