comparison src/cdrom/macos/SDL_syscdrom.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
52 Boolean hasAudio; 52 Boolean hasAudio;
53 } SDL_cdlist[MAX_DRIVES]; 53 } SDL_cdlist[MAX_DRIVES];
54 static StringPtr gDriverName = "\p.AppleCD"; 54 static StringPtr gDriverName = "\p.AppleCD";
55 55
56 /* The system-dependent CD control functions */ 56 /* The system-dependent CD control functions */
57 static const char *SDL_SYS_CDName (int drive); 57 static const char *SDL_SYS_CDName(int drive);
58 static int SDL_SYS_CDOpen (int drive); 58 static int SDL_SYS_CDOpen(int drive);
59 static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); 59 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
60 static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); 60 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
61 static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); 61 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
62 static int SDL_SYS_CDPause (SDL_CD * cdrom); 62 static int SDL_SYS_CDPause(SDL_CD * cdrom);
63 static int SDL_SYS_CDResume (SDL_CD * cdrom); 63 static int SDL_SYS_CDResume(SDL_CD * cdrom);
64 static int SDL_SYS_CDStop (SDL_CD * cdrom); 64 static int SDL_SYS_CDStop(SDL_CD * cdrom);
65 static int SDL_SYS_CDEject (SDL_CD * cdrom); 65 static int SDL_SYS_CDEject(SDL_CD * cdrom);
66 static void SDL_SYS_CDClose (SDL_CD * cdrom); 66 static void SDL_SYS_CDClose(SDL_CD * cdrom);
67 67
68 static short 68 static short
69 SDL_SYS_ShortToBCD (short value) 69 SDL_SYS_ShortToBCD(short value)
70 { 70 {
71 return ((value % 10) + (value / 10) * 0x10); /* Convert value to BCD */ 71 return ((value % 10) + (value / 10) * 0x10); /* Convert value to BCD */
72 } 72 }
73 73
74 static short 74 static short
75 SDL_SYS_BCDToShort (short value) 75 SDL_SYS_BCDToShort(short value)
76 { 76 {
77 return ((value % 0x10) + (value / 0x10) * 10); /* Convert value from BCD */ 77 return ((value % 0x10) + (value / 0x10) * 10); /* Convert value from BCD */
78 } 78 }
79 79
80 int 80 int
81 SDL_SYS_CDInit (void) 81 SDL_SYS_CDInit(void)
82 { 82 {
83 SInt16 dRefNum = 0; 83 SInt16 dRefNum = 0;
84 SInt16 first, last; 84 SInt16 first, last;
85 85
86 SDL_numcds = 0; 86 SDL_numcds = 0;
87 87
88 /* Check that the software is available */ 88 /* Check that the software is available */
89 if (Gestalt (kGestaltAudioCDSelector, &SDL_cdversion) || !SDL_cdversion) 89 if (Gestalt(kGestaltAudioCDSelector, &SDL_cdversion) || !SDL_cdversion)
90 return (0); 90 return (0);
91 91
92 /* Fill in our driver capabilities */ 92 /* Fill in our driver capabilities */
93 SDL_CDcaps.Name = SDL_SYS_CDName; 93 SDL_CDcaps.Name = SDL_SYS_CDName;
94 SDL_CDcaps.Open = SDL_SYS_CDOpen; 94 SDL_CDcaps.Open = SDL_SYS_CDOpen;
101 SDL_CDcaps.Eject = SDL_SYS_CDEject; 101 SDL_CDcaps.Eject = SDL_SYS_CDEject;
102 SDL_CDcaps.Close = SDL_SYS_CDClose; 102 SDL_CDcaps.Close = SDL_SYS_CDClose;
103 103
104 /* Walk the list, count each AudioCD driver, and save the refnums */ 104 /* Walk the list, count each AudioCD driver, and save the refnums */
105 first = -1; 105 first = -1;
106 last = 0 - LMGetUnitTableEntryCount (); 106 last = 0 - LMGetUnitTableEntryCount();
107 for (dRefNum = first; dRefNum >= last; dRefNum--) { 107 for (dRefNum = first; dRefNum >= last; dRefNum--) {
108 Str255 driverName; 108 Str255 driverName;
109 StringPtr namePtr; 109 StringPtr namePtr;
110 DCtlHandle deviceEntry; 110 DCtlHandle deviceEntry;
111 111
112 deviceEntry = GetDCtlEntry (dRefNum); 112 deviceEntry = GetDCtlEntry(dRefNum);
113 if (!deviceEntry) 113 if (!deviceEntry)
114 continue; 114 continue;
115 115
116 /* Is this an .AppleCD ? */ 116 /* Is this an .AppleCD ? */
117 namePtr = (*deviceEntry)->dCtlFlags & (1L << dRAMBased) ? 117 namePtr = (*deviceEntry)->dCtlFlags & (1L << dRAMBased) ?
118 ((StringPtr) ((DCtlPtr) deviceEntry)->dCtlDriver + 18) : 118 ((StringPtr) ((DCtlPtr) deviceEntry)->dCtlDriver + 18) :
119 ((StringPtr) (*deviceEntry)->dCtlDriver + 18); 119 ((StringPtr) (*deviceEntry)->dCtlDriver + 18);
120 BlockMoveData (namePtr, driverName, namePtr[0] + 1); 120 BlockMoveData(namePtr, driverName, namePtr[0] + 1);
121 if (driverName[0] > gDriverName[0]) 121 if (driverName[0] > gDriverName[0])
122 driverName[0] = gDriverName[0]; 122 driverName[0] = gDriverName[0];
123 if (!EqualString (driverName, gDriverName, false, false)) 123 if (!EqualString(driverName, gDriverName, false, false))
124 continue; 124 continue;
125 125
126 /* Record the basic info for each drive */ 126 /* Record the basic info for each drive */
127 SDL_cdlist[SDL_numcds].dRefNum = dRefNum; 127 SDL_cdlist[SDL_numcds].dRefNum = dRefNum;
128 BlockMoveData (namePtr + 1, SDL_cdlist[SDL_numcds].name, namePtr[0]); 128 BlockMoveData(namePtr + 1, SDL_cdlist[SDL_numcds].name, namePtr[0]);
129 SDL_cdlist[SDL_numcds].name[namePtr[0]] = 0; 129 SDL_cdlist[SDL_numcds].name[namePtr[0]] = 0;
130 SDL_cdlist[SDL_numcds].hasAudio = false; 130 SDL_cdlist[SDL_numcds].hasAudio = false;
131 SDL_numcds++; 131 SDL_numcds++;
132 } 132 }
133 return (0); 133 return (0);
134 } 134 }
135 135
136 static const char * 136 static const char *
137 SDL_SYS_CDName (int drive) 137 SDL_SYS_CDName(int drive)
138 { 138 {
139 return (SDL_cdlist[drive].name); 139 return (SDL_cdlist[drive].name);
140 } 140 }
141 141
142 static int 142 static int
143 get_drivenum (int drive) 143 get_drivenum(int drive)
144 { 144 {
145 QHdr *driveQ = GetDrvQHdr (); 145 QHdr *driveQ = GetDrvQHdr();
146 DrvQEl *driveElem; 146 DrvQEl *driveElem;
147 147
148 /* Update the drive number */ 148 /* Update the drive number */
149 SDL_cdlist[drive].driveNum = 0; 149 SDL_cdlist[drive].driveNum = 0;
150 if (driveQ->qTail) { 150 if (driveQ->qTail) {
159 } 159 }
160 return (SDL_cdlist[drive].driveNum); 160 return (SDL_cdlist[drive].driveNum);
161 } 161 }
162 162
163 static int 163 static int
164 SDL_SYS_CDOpen (int drive) 164 SDL_SYS_CDOpen(int drive)
165 { 165 {
166 return (drive); 166 return (drive);
167 } 167 }
168 168
169 static int 169 static int
170 SDL_SYS_CDGetTOC (SDL_CD * cdrom) 170 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
171 { 171 {
172 CDCntrlParam cdpb; 172 CDCntrlParam cdpb;
173 CDTrackData tracks[SDL_MAX_TRACKS]; 173 CDTrackData tracks[SDL_MAX_TRACKS];
174 long i, leadout; 174 long i, leadout;
175 175
176 /* Get the number of tracks on the CD by examining the TOC */ 176 /* Get the number of tracks on the CD by examining the TOC */
177 SDL_memset (&cdpb, 0, sizeof (cdpb)); 177 SDL_memset(&cdpb, 0, sizeof(cdpb));
178 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 178 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
179 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 179 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
180 cdpb.csCode = kReadTOC; 180 cdpb.csCode = kReadTOC;
181 cdpb.csParam.words[0] = kGetTrackRange; 181 cdpb.csParam.words[0] = kGetTrackRange;
182 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 182 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
183 SDL_SetError ("PBControlSync() failed"); 183 SDL_SetError("PBControlSync() failed");
184 return (-1); 184 return (-1);
185 } 185 }
186 186
187 cdrom->numtracks = 187 cdrom->numtracks =
188 SDL_SYS_BCDToShort (cdpb.csParam.bytes[1]) - 188 SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) -
189 SDL_SYS_BCDToShort (cdpb.csParam.bytes[0]) + 1; 189 SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1;
190 if (cdrom->numtracks > SDL_MAX_TRACKS) 190 if (cdrom->numtracks > SDL_MAX_TRACKS)
191 cdrom->numtracks = SDL_MAX_TRACKS; 191 cdrom->numtracks = SDL_MAX_TRACKS;
192 cdrom->status = CD_STOPPED; 192 cdrom->status = CD_STOPPED;
193 cdrom->cur_track = 0; /* Apparently these are set elsewhere */ 193 cdrom->cur_track = 0; /* Apparently these are set elsewhere */
194 cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ 194 cdrom->cur_frame = 0; /* Apparently these are set elsewhere */
195 195
196 196
197 /* Get the lead out area of the CD by examining the TOC */ 197 /* Get the lead out area of the CD by examining the TOC */
198 SDL_memset (&cdpb, 0, sizeof (cdpb)); 198 SDL_memset(&cdpb, 0, sizeof(cdpb));
199 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 199 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
200 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 200 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
201 cdpb.csCode = kReadTOC; 201 cdpb.csCode = kReadTOC;
202 cdpb.csParam.words[0] = kGetLeadOutArea; 202 cdpb.csParam.words[0] = kGetLeadOutArea;
203 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 203 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
204 SDL_SetError ("PBControlSync() failed"); 204 SDL_SetError("PBControlSync() failed");
205 return (-1); 205 return (-1);
206 } 206 }
207 207
208 leadout = MSF_TO_FRAMES (SDL_SYS_BCDToShort (cdpb.csParam.bytes[0]), 208 leadout = MSF_TO_FRAMES(SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]),
209 SDL_SYS_BCDToShort (cdpb.csParam.bytes[1]), 209 SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]),
210 SDL_SYS_BCDToShort (cdpb.csParam.bytes[2])); 210 SDL_SYS_BCDToShort(cdpb.csParam.bytes[2]));
211 211
212 /* Get an array of track locations by examining the TOC */ 212 /* Get an array of track locations by examining the TOC */
213 SDL_memset (tracks, 0, sizeof (tracks)); 213 SDL_memset(tracks, 0, sizeof(tracks));
214 SDL_memset (&cdpb, 0, sizeof (cdpb)); 214 SDL_memset(&cdpb, 0, sizeof(cdpb));
215 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 215 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
216 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 216 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
217 cdpb.csCode = kReadTOC; 217 cdpb.csCode = kReadTOC;
218 cdpb.csParam.words[0] = kGetTrackEntries; /* Type of Query */ 218 cdpb.csParam.words[0] = kGetTrackEntries; /* Type of Query */
219 *((long *) (cdpb.csParam.words + 1)) = (long) tracks; 219 *((long *) (cdpb.csParam.words + 1)) = (long) tracks;
220 cdpb.csParam.words[3] = cdrom->numtracks * sizeof (tracks[0]); 220 cdpb.csParam.words[3] = cdrom->numtracks * sizeof(tracks[0]);
221 *((char *) (cdpb.csParam.words + 4)) = 1; /* First track */ 221 *((char *) (cdpb.csParam.words + 4)) = 1; /* First track */
222 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 222 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
223 SDL_SetError ("PBControlSync() failed"); 223 SDL_SetError("PBControlSync() failed");
224 return (-1); 224 return (-1);
225 } 225 }
226 226
227 /* Read all the track TOC entries */ 227 /* Read all the track TOC entries */
228 SDL_cdlist[cdrom->id].hasAudio = false; 228 SDL_cdlist[cdrom->id].hasAudio = false;
234 cdrom->track[i].type = SDL_AUDIO_TRACK; 234 cdrom->track[i].type = SDL_AUDIO_TRACK;
235 SDL_cdlist[SDL_numcds].hasAudio = true; 235 SDL_cdlist[SDL_numcds].hasAudio = true;
236 } 236 }
237 237
238 cdrom->track[i].offset = 238 cdrom->track[i].offset =
239 MSF_TO_FRAMES (SDL_SYS_BCDToShort (tracks[i].entry.min), 239 MSF_TO_FRAMES(SDL_SYS_BCDToShort(tracks[i].entry.min),
240 SDL_SYS_BCDToShort (tracks[i].entry.min), 240 SDL_SYS_BCDToShort(tracks[i].entry.min),
241 SDL_SYS_BCDToShort (tracks[i].entry.frame)); 241 SDL_SYS_BCDToShort(tracks[i].entry.frame));
242 cdrom->track[i].length = 242 cdrom->track[i].length =
243 MSF_TO_FRAMES (SDL_SYS_BCDToShort (tracks[i + 1].entry.min), 243 MSF_TO_FRAMES(SDL_SYS_BCDToShort(tracks[i + 1].entry.min),
244 SDL_SYS_BCDToShort (tracks[i + 1].entry.min), 244 SDL_SYS_BCDToShort(tracks[i + 1].entry.min),
245 SDL_SYS_BCDToShort (tracks[i + 1].entry.frame)) - 245 SDL_SYS_BCDToShort(tracks[i + 1].entry.frame)) -
246 cdrom->track[i].offset; 246 cdrom->track[i].offset;
247 } 247 }
248 248
249 /* Apparently SDL wants a fake last entry */ 249 /* Apparently SDL wants a fake last entry */
250 cdrom->track[i].offset = leadout; 250 cdrom->track[i].offset = leadout;
253 return (0); 253 return (0);
254 } 254 }
255 255
256 /* Get CD-ROM status */ 256 /* Get CD-ROM status */
257 static CDstatus 257 static CDstatus
258 SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) 258 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
259 { 259 {
260 CDCntrlParam cdpb; 260 CDCntrlParam cdpb;
261 CDstatus status = CD_ERROR; 261 CDstatus status = CD_ERROR;
262 Boolean spinning = false; 262 Boolean spinning = false;
263 263
264 if (position) 264 if (position)
265 *position = 0; 265 *position = 0;
266 266
267 /* Get the number of tracks on the CD by examining the TOC */ 267 /* Get the number of tracks on the CD by examining the TOC */
268 if (!get_drivenum (cdrom->id)) { 268 if (!get_drivenum(cdrom->id)) {
269 return (CD_TRAYEMPTY); 269 return (CD_TRAYEMPTY);
270 } 270 }
271 SDL_memset (&cdpb, 0, sizeof (cdpb)); 271 SDL_memset(&cdpb, 0, sizeof(cdpb));
272 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 272 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
273 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 273 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
274 cdpb.csCode = kReadTOC; 274 cdpb.csCode = kReadTOC;
275 cdpb.csParam.words[0] = kGetTrackRange; 275 cdpb.csParam.words[0] = kGetTrackRange;
276 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 276 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
277 SDL_SetError ("PBControlSync() failed"); 277 SDL_SetError("PBControlSync() failed");
278 return (CD_ERROR); 278 return (CD_ERROR);
279 } 279 }
280 280
281 cdrom->numtracks = 281 cdrom->numtracks =
282 SDL_SYS_BCDToShort (cdpb.csParam.bytes[1]) - 282 SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) -
283 SDL_SYS_BCDToShort (cdpb.csParam.bytes[0]) + 1; 283 SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1;
284 if (cdrom->numtracks > SDL_MAX_TRACKS) 284 if (cdrom->numtracks > SDL_MAX_TRACKS)
285 cdrom->numtracks = SDL_MAX_TRACKS; 285 cdrom->numtracks = SDL_MAX_TRACKS;
286 cdrom->cur_track = 0; /* Apparently these are set elsewhere */ 286 cdrom->cur_track = 0; /* Apparently these are set elsewhere */
287 cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ 287 cdrom->cur_frame = 0; /* Apparently these are set elsewhere */
288 288
289 289
290 if (1 || SDL_cdlist[cdrom->id].hasAudio) { 290 if (1 || SDL_cdlist[cdrom->id].hasAudio) {
291 /* Get the current playback status */ 291 /* Get the current playback status */
292 SDL_memset (&cdpb, 0, sizeof (cdpb)); 292 SDL_memset(&cdpb, 0, sizeof(cdpb));
293 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 293 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
294 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 294 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
295 cdpb.csCode = kAudioStatus; 295 cdpb.csCode = kAudioStatus;
296 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 296 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
297 SDL_SetError ("PBControlSync() failed"); 297 SDL_SetError("PBControlSync() failed");
298 return (-1); 298 return (-1);
299 } 299 }
300 300
301 switch (cdpb.csParam.cd.status) { 301 switch (cdpb.csParam.cd.status) {
302 case kStatusPlaying: 302 case kStatusPlaying:
326 break; 326 break;
327 } 327 }
328 328
329 if (spinning && position) 329 if (spinning && position)
330 *position = 330 *position =
331 MSF_TO_FRAMES (SDL_SYS_BCDToShort (cdpb.csParam.cd.minute), 331 MSF_TO_FRAMES(SDL_SYS_BCDToShort(cdpb.csParam.cd.minute),
332 SDL_SYS_BCDToShort (cdpb.csParam.cd.second), 332 SDL_SYS_BCDToShort(cdpb.csParam.cd.second),
333 SDL_SYS_BCDToShort (cdpb.csParam.cd.frame)); 333 SDL_SYS_BCDToShort(cdpb.csParam.cd.frame));
334 } else 334 } else
335 status = CD_ERROR; /* What should I do here? */ 335 status = CD_ERROR; /* What should I do here? */
336 336
337 return (status); 337 return (status);
338 } 338 }
339 339
340 /* Start play */ 340 /* Start play */
341 static int 341 static int
342 SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) 342 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
343 { 343 {
344 CDCntrlParam cdpb; 344 CDCntrlParam cdpb;
345 345
346 /* Pause the current audio playback to avoid audible artifacts */ 346 /* Pause the current audio playback to avoid audible artifacts */
347 if (SDL_SYS_CDPause (cdrom) < 0) { 347 if (SDL_SYS_CDPause(cdrom) < 0) {
348 return (-1); 348 return (-1);
349 } 349 }
350 350
351 /* Specify the AudioCD playback mode */ 351 /* Specify the AudioCD playback mode */
352 SDL_memset (&cdpb, 0, sizeof (cdpb)); 352 SDL_memset(&cdpb, 0, sizeof(cdpb));
353 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 353 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
354 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 354 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
355 cdpb.csCode = kSetPlayMode; 355 cdpb.csCode = kSetPlayMode;
356 cdpb.csParam.bytes[0] = false; /* Repeat? */ 356 cdpb.csParam.bytes[0] = false; /* Repeat? */
357 cdpb.csParam.bytes[1] = kPlayModeSequential; /* Play mode */ 357 cdpb.csParam.bytes[1] = kPlayModeSequential; /* Play mode */
358 /* ¥¥¥ÊTreat as soft error, NEC Drive doesnt support this call ¥¥¥ */ 358 /* ¥¥¥ÊTreat as soft error, NEC Drive doesnt support this call ¥¥¥ */
359 PBControlSync ((ParmBlkPtr) & cdpb); 359 PBControlSync((ParmBlkPtr) & cdpb);
360 360
361 #if 1 361 #if 1
362 /* Specify the end of audio playback */ 362 /* Specify the end of audio playback */
363 SDL_memset (&cdpb, 0, sizeof (cdpb)); 363 SDL_memset(&cdpb, 0, sizeof(cdpb));
364 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 364 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
365 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 365 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
366 cdpb.csCode = kAudioStop; 366 cdpb.csCode = kAudioStop;
367 cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ 367 cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */
368 *(long *) (cdpb.csParam.words + 1) = start + length - 1; /* Search Address */ 368 *(long *) (cdpb.csParam.words + 1) = start + length - 1; /* Search Address */
369 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 369 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
370 SDL_SetError ("PBControlSync() failed"); 370 SDL_SetError("PBControlSync() failed");
371 return (-1); 371 return (-1);
372 } 372 }
373 373
374 /* Specify the start of audio playback, and start it */ 374 /* Specify the start of audio playback, and start it */
375 SDL_memset (&cdpb, 0, sizeof (cdpb)); 375 SDL_memset(&cdpb, 0, sizeof(cdpb));
376 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 376 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
377 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 377 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
378 cdpb.csCode = kAudioPlay; 378 cdpb.csCode = kAudioPlay;
379 cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ 379 cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */
380 *(long *) (cdpb.csParam.words + 1) = start + 1; /* Search Address */ 380 *(long *) (cdpb.csParam.words + 1) = start + 1; /* Search Address */
381 cdpb.csParam.words[3] = false; /* Stop address? */ 381 cdpb.csParam.words[3] = false; /* Stop address? */
382 cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ 382 cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */
383 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 383 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
384 SDL_SetError ("PBControlSync() failed"); 384 SDL_SetError("PBControlSync() failed");
385 return (-1); 385 return (-1);
386 } 386 }
387 #else 387 #else
388 /* Specify the end of audio playback */ 388 /* Specify the end of audio playback */
389 FRAMES_TO_MSF (start + length, &m, &s, &f); 389 FRAMES_TO_MSF(start + length, &m, &s, &f);
390 SDL_memset (&cdpb, 0, sizeof (cdpb)); 390 SDL_memset(&cdpb, 0, sizeof(cdpb));
391 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 391 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
392 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 392 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
393 cdpb.csCode = kAudioStop; 393 cdpb.csCode = kAudioStop;
394 cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ 394 cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */
395 cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ 395 cdpb.csParam.words[1] = 0; /* Search Address (hiword) */
396 cdpb.csParam.words[2] = /* Search Address (loword) */ 396 cdpb.csParam.words[2] = /* Search Address (loword) */
397 SDL_SYS_ShortToBCD (cdrom->numtracks); 397 SDL_SYS_ShortToBCD(cdrom->numtracks);
398 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 398 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
399 SDL_SetError ("PBControlSync() failed"); 399 SDL_SetError("PBControlSync() failed");
400 return (-1); 400 return (-1);
401 } 401 }
402 402
403 /* Specify the start of audio playback, and start it */ 403 /* Specify the start of audio playback, and start it */
404 FRAMES_TO_MSF (start, &m, &s, &f); 404 FRAMES_TO_MSF(start, &m, &s, &f);
405 SDL_memset (&cdpb, 0, sizeof (cdpb)); 405 SDL_memset(&cdpb, 0, sizeof(cdpb));
406 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 406 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
407 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 407 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
408 cdpb.csCode = kAudioPlay; 408 cdpb.csCode = kAudioPlay;
409 cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ 409 cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */
410 cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ 410 cdpb.csParam.words[1] = 0; /* Search Address (hiword) */
411 cdpb.csParam.words[2] = SDL_SYS_ShortToBCD (1); /* Search Address (loword) */ 411 cdpb.csParam.words[2] = SDL_SYS_ShortToBCD(1); /* Search Address (loword) */
412 cdpb.csParam.words[3] = false; /* Stop address? */ 412 cdpb.csParam.words[3] = false; /* Stop address? */
413 cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ 413 cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */
414 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 414 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
415 SDL_SetError ("PBControlSync() failed"); 415 SDL_SetError("PBControlSync() failed");
416 return (-1); 416 return (-1);
417 } 417 }
418 #endif 418 #endif
419 419
420 return (0); 420 return (0);
421 } 421 }
422 422
423 /* Pause play */ 423 /* Pause play */
424 static int 424 static int
425 SDL_SYS_CDPause (SDL_CD * cdrom) 425 SDL_SYS_CDPause(SDL_CD * cdrom)
426 { 426 {
427 CDCntrlParam cdpb; 427 CDCntrlParam cdpb;
428 428
429 SDL_memset (&cdpb, 0, sizeof (cdpb)); 429 SDL_memset(&cdpb, 0, sizeof(cdpb));
430 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 430 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
431 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 431 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
432 cdpb.csCode = kAudioPause; 432 cdpb.csCode = kAudioPause;
433 cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ 433 cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */
434 cdpb.csParam.words[1] = 1; /* Pause/Continue Flag (loword) */ 434 cdpb.csParam.words[1] = 1; /* Pause/Continue Flag (loword) */
435 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 435 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
436 SDL_SetError ("PBControlSync() failed"); 436 SDL_SetError("PBControlSync() failed");
437 return (-1); 437 return (-1);
438 } 438 }
439 return (0); 439 return (0);
440 } 440 }
441 441
442 /* Resume play */ 442 /* Resume play */
443 static int 443 static int
444 SDL_SYS_CDResume (SDL_CD * cdrom) 444 SDL_SYS_CDResume(SDL_CD * cdrom)
445 { 445 {
446 CDCntrlParam cdpb; 446 CDCntrlParam cdpb;
447 447
448 SDL_memset (&cdpb, 0, sizeof (cdpb)); 448 SDL_memset(&cdpb, 0, sizeof(cdpb));
449 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 449 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
450 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 450 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
451 cdpb.csCode = kAudioPause; 451 cdpb.csCode = kAudioPause;
452 cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ 452 cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */
453 cdpb.csParam.words[1] = 0; /* Pause/Continue Flag (loword) */ 453 cdpb.csParam.words[1] = 0; /* Pause/Continue Flag (loword) */
454 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 454 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
455 SDL_SetError ("PBControlSync() failed"); 455 SDL_SetError("PBControlSync() failed");
456 return (-1); 456 return (-1);
457 } 457 }
458 return (0); 458 return (0);
459 } 459 }
460 460
461 /* Stop play */ 461 /* Stop play */
462 static int 462 static int
463 SDL_SYS_CDStop (SDL_CD * cdrom) 463 SDL_SYS_CDStop(SDL_CD * cdrom)
464 { 464 {
465 CDCntrlParam cdpb; 465 CDCntrlParam cdpb;
466 466
467 SDL_memset (&cdpb, 0, sizeof (cdpb)); 467 SDL_memset(&cdpb, 0, sizeof(cdpb));
468 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; 468 cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
469 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 469 cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
470 cdpb.csCode = kAudioStop; 470 cdpb.csCode = kAudioStop;
471 cdpb.csParam.words[0] = 0; /* Position Mode */ 471 cdpb.csParam.words[0] = 0; /* Position Mode */
472 cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ 472 cdpb.csParam.words[1] = 0; /* Search Address (hiword) */
473 cdpb.csParam.words[2] = 0; /* Search Address (loword) */ 473 cdpb.csParam.words[2] = 0; /* Search Address (loword) */
474 if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { 474 if (PBControlSync((ParmBlkPtr) & cdpb) != noErr) {
475 SDL_SetError ("PBControlSync() failed"); 475 SDL_SetError("PBControlSync() failed");
476 return (-1); 476 return (-1);
477 } 477 }
478 return (0); 478 return (0);
479 } 479 }
480 480
481 /* Eject the CD-ROM */ 481 /* Eject the CD-ROM */
482 static int 482 static int
483 SDL_SYS_CDEject (SDL_CD * cdrom) 483 SDL_SYS_CDEject(SDL_CD * cdrom)
484 { 484 {
485 Boolean disk = false; 485 Boolean disk = false;
486 QHdr *driveQ = GetDrvQHdr (); 486 QHdr *driveQ = GetDrvQHdr();
487 DrvQEl *driveElem; 487 DrvQEl *driveElem;
488 HParamBlockRec hpb; 488 HParamBlockRec hpb;
489 ParamBlockRec cpb; 489 ParamBlockRec cpb;
490 490
491 for (driveElem = (DrvQEl *) driveQ->qHead; driveElem; driveElem = 491 for (driveElem = (DrvQEl *) driveQ->qHead; driveElem; driveElem =
497 if (driveElem->dQRefNum != SDL_cdlist[cdrom->id].dRefNum) { 497 if (driveElem->dQRefNum != SDL_cdlist[cdrom->id].dRefNum) {
498 continue; 498 continue;
499 } 499 }
500 500
501 /* Does drive contain mounted volume? If not, skip */ 501 /* Does drive contain mounted volume? If not, skip */
502 SDL_memset (&hpb, 0, sizeof (hpb)); 502 SDL_memset(&hpb, 0, sizeof(hpb));
503 hpb.volumeParam.ioVRefNum = driveElem->dQDrive; 503 hpb.volumeParam.ioVRefNum = driveElem->dQDrive;
504 if (PBHGetVInfoSync (&hpb) != noErr) { 504 if (PBHGetVInfoSync(&hpb) != noErr) {
505 continue; 505 continue;
506 } 506 }
507 if ((UnmountVol (0, driveElem->dQDrive) == noErr) && 507 if ((UnmountVol(0, driveElem->dQDrive) == noErr) &&
508 (Eject (0, driveElem->dQDrive) == noErr)) { 508 (Eject(0, driveElem->dQDrive) == noErr)) {
509 driveElem = 0; /* Clear pointer to reset our loop */ 509 driveElem = 0; /* Clear pointer to reset our loop */
510 disk = true; 510 disk = true;
511 } 511 }
512 } 512 }
513 513
514 /* If no disk is present, just eject the tray */ 514 /* If no disk is present, just eject the tray */
515 if (!disk) { 515 if (!disk) {
516 SDL_memset (&cpb, 0, sizeof (cpb)); 516 SDL_memset(&cpb, 0, sizeof(cpb));
517 cpb.cntrlParam.ioVRefNum = 0; /* No Drive */ 517 cpb.cntrlParam.ioVRefNum = 0; /* No Drive */
518 cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; 518 cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
519 cpb.cntrlParam.csCode = kEjectTheDisc; 519 cpb.cntrlParam.csCode = kEjectTheDisc;
520 if (PBControlSync ((ParmBlkPtr) & cpb) != noErr) { 520 if (PBControlSync((ParmBlkPtr) & cpb) != noErr) {
521 SDL_SetError ("PBControlSync() failed"); 521 SDL_SetError("PBControlSync() failed");
522 return (-1); 522 return (-1);
523 } 523 }
524 } 524 }
525 return (0); 525 return (0);
526 } 526 }
527 527
528 /* Close the CD-ROM handle */ 528 /* Close the CD-ROM handle */
529 static void 529 static void
530 SDL_SYS_CDClose (SDL_CD * cdrom) 530 SDL_SYS_CDClose(SDL_CD * cdrom)
531 { 531 {
532 return; 532 return;
533 } 533 }
534 534
535 void 535 void
536 SDL_SYS_CDQuit (void) 536 SDL_SYS_CDQuit(void)
537 { 537 {
538 while (SDL_numcds--) 538 while (SDL_numcds--)
539 SDL_memset (SDL_cdlist + SDL_numcds, 0, sizeof (SDL_cdlist[0])); 539 SDL_memset(SDL_cdlist + SDL_numcds, 0, sizeof(SDL_cdlist[0]));
540 } 540 }
541 541
542 #endif /* SDL_CDROM_MACOS */ 542 #endif /* SDL_CDROM_MACOS */
543 /* vi: set ts=4 sw=4 expandtab: */ 543 /* vi: set ts=4 sw=4 expandtab: */