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