comparison src/cdrom/win32/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
45 static int SDL_paused[MAX_DRIVES]; 45 static int SDL_paused[MAX_DRIVES];
46 #endif 46 #endif
47 static int SDL_CD_end_position; 47 static int SDL_CD_end_position;
48 48
49 /* The system-dependent CD control functions */ 49 /* The system-dependent CD control functions */
50 static const char *SDL_SYS_CDName (int drive); 50 static const char *SDL_SYS_CDName(int drive);
51 static int SDL_SYS_CDOpen (int drive); 51 static int SDL_SYS_CDOpen(int drive);
52 static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); 52 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
53 static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); 53 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
54 static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); 54 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
55 static int SDL_SYS_CDPause (SDL_CD * cdrom); 55 static int SDL_SYS_CDPause(SDL_CD * cdrom);
56 static int SDL_SYS_CDResume (SDL_CD * cdrom); 56 static int SDL_SYS_CDResume(SDL_CD * cdrom);
57 static int SDL_SYS_CDStop (SDL_CD * cdrom); 57 static int SDL_SYS_CDStop(SDL_CD * cdrom);
58 static int SDL_SYS_CDEject (SDL_CD * cdrom); 58 static int SDL_SYS_CDEject(SDL_CD * cdrom);
59 static void SDL_SYS_CDClose (SDL_CD * cdrom); 59 static void SDL_SYS_CDClose(SDL_CD * cdrom);
60 60
61 61
62 /* Add a CD-ROM drive to our list of valid drives */ 62 /* Add a CD-ROM drive to our list of valid drives */
63 static void 63 static void
64 AddDrive (char *drive) 64 AddDrive(char *drive)
65 { 65 {
66 int i; 66 int i;
67 67
68 if (SDL_numcds < MAX_DRIVES) { 68 if (SDL_numcds < MAX_DRIVES) {
69 /* Add this drive to our list */ 69 /* Add this drive to our list */
70 i = SDL_numcds; 70 i = SDL_numcds;
71 SDL_cdlist[i] = SDL_strdup (drive); 71 SDL_cdlist[i] = SDL_strdup(drive);
72 if (SDL_cdlist[i] == NULL) { 72 if (SDL_cdlist[i] == NULL) {
73 SDL_OutOfMemory (); 73 SDL_OutOfMemory();
74 return; 74 return;
75 } 75 }
76 ++SDL_numcds; 76 ++SDL_numcds;
77 #ifdef CDROM_DEBUG 77 #ifdef CDROM_DEBUG
78 fprintf (stderr, "Added CD-ROM drive: %s\n", drive); 78 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
79 #endif 79 #endif
80 } 80 }
81 } 81 }
82 82
83 int 83 int
84 SDL_SYS_CDInit (void) 84 SDL_SYS_CDInit(void)
85 { 85 {
86 /* checklist: Drive 'A' - 'Z' */ 86 /* checklist: Drive 'A' - 'Z' */
87 int i; 87 int i;
88 char drive[4]; 88 char drive[4];
89 89
99 SDL_CDcaps.Eject = SDL_SYS_CDEject; 99 SDL_CDcaps.Eject = SDL_SYS_CDEject;
100 SDL_CDcaps.Close = SDL_SYS_CDClose; 100 SDL_CDcaps.Close = SDL_SYS_CDClose;
101 101
102 /* Scan the system for CD-ROM drives */ 102 /* Scan the system for CD-ROM drives */
103 for (i = 'A'; i <= 'Z'; ++i) { 103 for (i = 'A'; i <= 'Z'; ++i) {
104 SDL_snprintf (drive, SDL_arraysize (drive), "%c:\\", i); 104 SDL_snprintf(drive, SDL_arraysize(drive), "%c:\\", i);
105 if (GetDriveType (drive) == DRIVE_CDROM) { 105 if (GetDriveType(drive) == DRIVE_CDROM) {
106 AddDrive (drive); 106 AddDrive(drive);
107 } 107 }
108 } 108 }
109 SDL_memset (SDL_mciID, 0, sizeof (SDL_mciID)); 109 SDL_memset(SDL_mciID, 0, sizeof(SDL_mciID));
110 return (0); 110 return (0);
111 } 111 }
112 112
113 /* General ioctl() CD-ROM command function */ 113 /* General ioctl() CD-ROM command function */
114 static int 114 static int
115 SDL_SYS_CDioctl (int id, UINT msg, DWORD flags, void *arg) 115 SDL_SYS_CDioctl(int id, UINT msg, DWORD flags, void *arg)
116 { 116 {
117 MCIERROR mci_error; 117 MCIERROR mci_error;
118 118
119 mci_error = mciSendCommand (SDL_mciID[id], msg, flags, (DWORD_PTR) arg); 119 mci_error = mciSendCommand(SDL_mciID[id], msg, flags, (DWORD_PTR) arg);
120 if (mci_error) { 120 if (mci_error) {
121 char error[256]; 121 char error[256];
122 122
123 mciGetErrorString (mci_error, error, 256); 123 mciGetErrorString(mci_error, error, 256);
124 SDL_SetError ("mciSendCommand() error: %s", error); 124 SDL_SetError("mciSendCommand() error: %s", error);
125 } 125 }
126 return (!mci_error ? 0 : -1); 126 return (!mci_error ? 0 : -1);
127 } 127 }
128 128
129 static const char * 129 static const char *
130 SDL_SYS_CDName (int drive) 130 SDL_SYS_CDName(int drive)
131 { 131 {
132 return (SDL_cdlist[drive]); 132 return (SDL_cdlist[drive]);
133 } 133 }
134 134
135 static int 135 static int
136 SDL_SYS_CDOpen (int drive) 136 SDL_SYS_CDOpen(int drive)
137 { 137 {
138 MCI_OPEN_PARMS mci_open; 138 MCI_OPEN_PARMS mci_open;
139 MCI_SET_PARMS mci_set; 139 MCI_SET_PARMS mci_set;
140 char device[3]; 140 char device[3];
141 DWORD flags; 141 DWORD flags;
147 device[2] = '\0'; 147 device[2] = '\0';
148 mci_open.lpstrElementName = device; 148 mci_open.lpstrElementName = device;
149 flags = 149 flags =
150 (MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE | MCI_OPEN_TYPE_ID | 150 (MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE | MCI_OPEN_TYPE_ID |
151 MCI_OPEN_ELEMENT); 151 MCI_OPEN_ELEMENT);
152 if (SDL_SYS_CDioctl (0, MCI_OPEN, flags, &mci_open) < 0) { 152 if (SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0) {
153 flags &= ~MCI_OPEN_SHAREABLE; 153 flags &= ~MCI_OPEN_SHAREABLE;
154 if (SDL_SYS_CDioctl (0, MCI_OPEN, flags, &mci_open) < 0) { 154 if (SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0) {
155 return (-1); 155 return (-1);
156 } 156 }
157 } 157 }
158 SDL_mciID[drive] = mci_open.wDeviceID; 158 SDL_mciID[drive] = mci_open.wDeviceID;
159 159
160 /* Set the minute-second-frame time format */ 160 /* Set the minute-second-frame time format */
161 mci_set.dwTimeFormat = MCI_FORMAT_MSF; 161 mci_set.dwTimeFormat = MCI_FORMAT_MSF;
162 SDL_SYS_CDioctl (drive, MCI_SET, MCI_SET_TIME_FORMAT, &mci_set); 162 SDL_SYS_CDioctl(drive, MCI_SET, MCI_SET_TIME_FORMAT, &mci_set);
163 163
164 #ifdef BROKEN_MCI_PAUSE 164 #ifdef BROKEN_MCI_PAUSE
165 SDL_paused[drive] = 0; 165 SDL_paused[drive] = 0;
166 #endif 166 #endif
167 return (drive); 167 return (drive);
168 } 168 }
169 169
170 static int 170 static int
171 SDL_SYS_CDGetTOC (SDL_CD * cdrom) 171 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
172 { 172 {
173 MCI_STATUS_PARMS mci_status; 173 MCI_STATUS_PARMS mci_status;
174 int i, okay; 174 int i, okay;
175 DWORD flags; 175 DWORD flags;
176 176
177 okay = 0; 177 okay = 0;
178 mci_status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS; 178 mci_status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
179 flags = MCI_STATUS_ITEM | MCI_WAIT; 179 flags = MCI_STATUS_ITEM | MCI_WAIT;
180 if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, &mci_status) == 0) { 180 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0) {
181 cdrom->numtracks = mci_status.dwReturn; 181 cdrom->numtracks = mci_status.dwReturn;
182 if (cdrom->numtracks > SDL_MAX_TRACKS) { 182 if (cdrom->numtracks > SDL_MAX_TRACKS) {
183 cdrom->numtracks = SDL_MAX_TRACKS; 183 cdrom->numtracks = SDL_MAX_TRACKS;
184 } 184 }
185 /* Read all the track TOC entries */ 185 /* Read all the track TOC entries */
187 for (i = 0; i < cdrom->numtracks; ++i) { 187 for (i = 0; i < cdrom->numtracks; ++i) {
188 cdrom->track[i].id = i + 1; 188 cdrom->track[i].id = i + 1;
189 mci_status.dwTrack = cdrom->track[i].id; 189 mci_status.dwTrack = cdrom->track[i].id;
190 #ifdef MCI_CDA_STATUS_TYPE_TRACK 190 #ifdef MCI_CDA_STATUS_TYPE_TRACK
191 mci_status.dwItem = MCI_CDA_STATUS_TYPE_TRACK; 191 mci_status.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
192 if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, 192 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
193 &mci_status) < 0) { 193 &mci_status) < 0) {
194 break; 194 break;
195 } 195 }
196 if (mci_status.dwReturn == MCI_CDA_TRACK_AUDIO) { 196 if (mci_status.dwReturn == MCI_CDA_TRACK_AUDIO) {
197 cdrom->track[i].type = SDL_AUDIO_TRACK; 197 cdrom->track[i].type = SDL_AUDIO_TRACK;
198 } else { 198 } else {
200 } 200 }
201 #else 201 #else
202 cdrom->track[i].type = SDL_AUDIO_TRACK; 202 cdrom->track[i].type = SDL_AUDIO_TRACK;
203 #endif 203 #endif
204 mci_status.dwItem = MCI_STATUS_POSITION; 204 mci_status.dwItem = MCI_STATUS_POSITION;
205 if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, 205 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
206 &mci_status) < 0) { 206 &mci_status) < 0) {
207 break; 207 break;
208 } 208 }
209 cdrom->track[i].offset = 209 cdrom->track[i].offset =
210 MSF_TO_FRAMES (MCI_MSF_MINUTE (mci_status.dwReturn), 210 MSF_TO_FRAMES(MCI_MSF_MINUTE(mci_status.dwReturn),
211 MCI_MSF_SECOND (mci_status.dwReturn), 211 MCI_MSF_SECOND(mci_status.dwReturn),
212 MCI_MSF_FRAME (mci_status.dwReturn)); 212 MCI_MSF_FRAME(mci_status.dwReturn));
213 cdrom->track[i].length = 0; 213 cdrom->track[i].length = 0;
214 if (i > 0) { 214 if (i > 0) {
215 cdrom->track[i - 1].length = 215 cdrom->track[i - 1].length =
216 cdrom->track[i].offset - cdrom->track[i - 1].offset; 216 cdrom->track[i].offset - cdrom->track[i - 1].offset;
217 } 217 }
218 } 218 }
219 if (i == cdrom->numtracks) { 219 if (i == cdrom->numtracks) {
220 mci_status.dwTrack = cdrom->track[i - 1].id; 220 mci_status.dwTrack = cdrom->track[i - 1].id;
221 mci_status.dwItem = MCI_STATUS_LENGTH; 221 mci_status.dwItem = MCI_STATUS_LENGTH;
222 if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, 222 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
223 &mci_status) == 0) { 223 &mci_status) == 0) {
224 cdrom->track[i - 1].length = 224 cdrom->track[i - 1].length =
225 MSF_TO_FRAMES (MCI_MSF_MINUTE (mci_status.dwReturn), 225 MSF_TO_FRAMES(MCI_MSF_MINUTE(mci_status.dwReturn),
226 MCI_MSF_SECOND (mci_status.dwReturn), 226 MCI_MSF_SECOND(mci_status.dwReturn),
227 MCI_MSF_FRAME (mci_status.dwReturn)); 227 MCI_MSF_FRAME(mci_status.dwReturn));
228 /* compute lead-out offset */ 228 /* compute lead-out offset */
229 cdrom->track[i].offset = cdrom->track[i - 1].offset + 229 cdrom->track[i].offset = cdrom->track[i - 1].offset +
230 cdrom->track[i - 1].length; 230 cdrom->track[i - 1].length;
231 cdrom->track[i].length = 0; 231 cdrom->track[i].length = 0;
232 okay = 1; 232 okay = 1;
236 return (okay ? 0 : -1); 236 return (okay ? 0 : -1);
237 } 237 }
238 238
239 /* Get CD-ROM status */ 239 /* Get CD-ROM status */
240 static CDstatus 240 static CDstatus
241 SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) 241 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
242 { 242 {
243 CDstatus status; 243 CDstatus status;
244 MCI_STATUS_PARMS mci_status; 244 MCI_STATUS_PARMS mci_status;
245 DWORD flags; 245 DWORD flags;
246 246
247 flags = MCI_STATUS_ITEM | MCI_WAIT; 247 flags = MCI_STATUS_ITEM | MCI_WAIT;
248 mci_status.dwItem = MCI_STATUS_MODE; 248 mci_status.dwItem = MCI_STATUS_MODE;
249 if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, &mci_status) < 0) { 249 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) < 0) {
250 status = CD_ERROR; 250 status = CD_ERROR;
251 } else { 251 } else {
252 switch (mci_status.dwReturn) { 252 switch (mci_status.dwReturn) {
253 case MCI_MODE_NOT_READY: 253 case MCI_MODE_NOT_READY:
254 case MCI_MODE_OPEN: 254 case MCI_MODE_OPEN:
285 } 285 }
286 } 286 }
287 if (position) { 287 if (position) {
288 if (status == CD_PLAYING || (status == CD_PAUSED)) { 288 if (status == CD_PLAYING || (status == CD_PAUSED)) {
289 mci_status.dwItem = MCI_STATUS_POSITION; 289 mci_status.dwItem = MCI_STATUS_POSITION;
290 if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, 290 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
291 &mci_status) == 0) { 291 &mci_status) == 0) {
292 *position = 292 *position =
293 MSF_TO_FRAMES (MCI_MSF_MINUTE (mci_status.dwReturn), 293 MSF_TO_FRAMES(MCI_MSF_MINUTE(mci_status.dwReturn),
294 MCI_MSF_SECOND (mci_status.dwReturn), 294 MCI_MSF_SECOND(mci_status.dwReturn),
295 MCI_MSF_FRAME (mci_status.dwReturn)); 295 MCI_MSF_FRAME(mci_status.dwReturn));
296 } else { 296 } else {
297 *position = 0; 297 *position = 0;
298 } 298 }
299 } else { 299 } else {
300 *position = 0; 300 *position = 0;
303 return (status); 303 return (status);
304 } 304 }
305 305
306 /* Start play */ 306 /* Start play */
307 static int 307 static int
308 SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) 308 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
309 { 309 {
310 MCI_PLAY_PARMS mci_play; 310 MCI_PLAY_PARMS mci_play;
311 int m, s, f; 311 int m, s, f;
312 DWORD flags; 312 DWORD flags;
313 313
314 flags = MCI_FROM | MCI_TO | MCI_NOTIFY; 314 flags = MCI_FROM | MCI_TO | MCI_NOTIFY;
315 mci_play.dwCallback = 0; 315 mci_play.dwCallback = 0;
316 FRAMES_TO_MSF (start, &m, &s, &f); 316 FRAMES_TO_MSF(start, &m, &s, &f);
317 mci_play.dwFrom = MCI_MAKE_MSF (m, s, f); 317 mci_play.dwFrom = MCI_MAKE_MSF(m, s, f);
318 FRAMES_TO_MSF (start + length, &m, &s, &f); 318 FRAMES_TO_MSF(start + length, &m, &s, &f);
319 mci_play.dwTo = MCI_MAKE_MSF (m, s, f); 319 mci_play.dwTo = MCI_MAKE_MSF(m, s, f);
320 SDL_CD_end_position = mci_play.dwTo; 320 SDL_CD_end_position = mci_play.dwTo;
321 return (SDL_SYS_CDioctl (cdrom->id, MCI_PLAY, flags, &mci_play)); 321 return (SDL_SYS_CDioctl(cdrom->id, MCI_PLAY, flags, &mci_play));
322 } 322 }
323 323
324 /* Pause play */ 324 /* Pause play */
325 static int 325 static int
326 SDL_SYS_CDPause (SDL_CD * cdrom) 326 SDL_SYS_CDPause(SDL_CD * cdrom)
327 { 327 {
328 #ifdef BROKEN_MCI_PAUSE 328 #ifdef BROKEN_MCI_PAUSE
329 SDL_paused[cdrom->id] = 1; 329 SDL_paused[cdrom->id] = 1;
330 #endif 330 #endif
331 return (SDL_SYS_CDioctl (cdrom->id, MCI_PAUSE, MCI_WAIT, NULL)); 331 return (SDL_SYS_CDioctl(cdrom->id, MCI_PAUSE, MCI_WAIT, NULL));
332 } 332 }
333 333
334 /* Resume play */ 334 /* Resume play */
335 static int 335 static int
336 SDL_SYS_CDResume (SDL_CD * cdrom) 336 SDL_SYS_CDResume(SDL_CD * cdrom)
337 { 337 {
338 #ifdef BROKEN_MCI_PAUSE 338 #ifdef BROKEN_MCI_PAUSE
339 MCI_STATUS_PARMS mci_status; 339 MCI_STATUS_PARMS mci_status;
340 int okay; 340 int okay;
341 int flags; 341 int flags;
342 342
343 okay = 0; 343 okay = 0;
344 /* Play from the current play position to the end position set earlier */ 344 /* Play from the current play position to the end position set earlier */
345 flags = MCI_STATUS_ITEM | MCI_WAIT; 345 flags = MCI_STATUS_ITEM | MCI_WAIT;
346 mci_status.dwItem = MCI_STATUS_POSITION; 346 mci_status.dwItem = MCI_STATUS_POSITION;
347 if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, &mci_status) == 0) { 347 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0) {
348 MCI_PLAY_PARMS mci_play; 348 MCI_PLAY_PARMS mci_play;
349 349
350 flags = MCI_FROM | MCI_TO | MCI_NOTIFY; 350 flags = MCI_FROM | MCI_TO | MCI_NOTIFY;
351 mci_play.dwCallback = 0; 351 mci_play.dwCallback = 0;
352 mci_play.dwFrom = mci_status.dwReturn; 352 mci_play.dwFrom = mci_status.dwReturn;
353 mci_play.dwTo = SDL_CD_end_position; 353 mci_play.dwTo = SDL_CD_end_position;
354 if (SDL_SYS_CDioctl (cdrom->id, MCI_PLAY, flags, &mci_play) == 0) { 354 if (SDL_SYS_CDioctl(cdrom->id, MCI_PLAY, flags, &mci_play) == 0) {
355 okay = 1; 355 okay = 1;
356 SDL_paused[cdrom->id] = 0; 356 SDL_paused[cdrom->id] = 0;
357 } 357 }
358 } 358 }
359 return (okay ? 0 : -1); 359 return (okay ? 0 : -1);
360 #else 360 #else
361 return (SDL_SYS_CDioctl (cdrom->id, MCI_RESUME, MCI_WAIT, NULL)); 361 return (SDL_SYS_CDioctl(cdrom->id, MCI_RESUME, MCI_WAIT, NULL));
362 #endif /* BROKEN_MCI_PAUSE */ 362 #endif /* BROKEN_MCI_PAUSE */
363 } 363 }
364 364
365 /* Stop play */ 365 /* Stop play */
366 static int 366 static int
367 SDL_SYS_CDStop (SDL_CD * cdrom) 367 SDL_SYS_CDStop(SDL_CD * cdrom)
368 { 368 {
369 return (SDL_SYS_CDioctl (cdrom->id, MCI_STOP, MCI_WAIT, NULL)); 369 return (SDL_SYS_CDioctl(cdrom->id, MCI_STOP, MCI_WAIT, NULL));
370 } 370 }
371 371
372 /* Eject the CD-ROM */ 372 /* Eject the CD-ROM */
373 static int 373 static int
374 SDL_SYS_CDEject (SDL_CD * cdrom) 374 SDL_SYS_CDEject(SDL_CD * cdrom)
375 { 375 {
376 return (SDL_SYS_CDioctl (cdrom->id, MCI_SET, MCI_SET_DOOR_OPEN, NULL)); 376 return (SDL_SYS_CDioctl(cdrom->id, MCI_SET, MCI_SET_DOOR_OPEN, NULL));
377 } 377 }
378 378
379 /* Close the CD-ROM handle */ 379 /* Close the CD-ROM handle */
380 static void 380 static void
381 SDL_SYS_CDClose (SDL_CD * cdrom) 381 SDL_SYS_CDClose(SDL_CD * cdrom)
382 { 382 {
383 SDL_SYS_CDioctl (cdrom->id, MCI_CLOSE, MCI_WAIT, NULL); 383 SDL_SYS_CDioctl(cdrom->id, MCI_CLOSE, MCI_WAIT, NULL);
384 } 384 }
385 385
386 void 386 void
387 SDL_SYS_CDQuit (void) 387 SDL_SYS_CDQuit(void)
388 { 388 {
389 int i; 389 int i;
390 390
391 if (SDL_numcds > 0) { 391 if (SDL_numcds > 0) {
392 for (i = 0; i < SDL_numcds; ++i) { 392 for (i = 0; i < SDL_numcds; ++i) {
393 SDL_free (SDL_cdlist[i]); 393 SDL_free(SDL_cdlist[i]);
394 } 394 }
395 SDL_numcds = 0; 395 SDL_numcds = 0;
396 } 396 }
397 } 397 }
398 398