comparison src/cdrom/win32/SDL_syscdrom.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 92947e3a18db
children 99210400e8b9
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
31 31
32 #include "SDL_cdrom.h" 32 #include "SDL_cdrom.h"
33 #include "../SDL_syscdrom.h" 33 #include "../SDL_syscdrom.h"
34 34
35 /* This really broken?? */ 35 /* This really broken?? */
36 #define BROKEN_MCI_PAUSE /* Pausing actually stops play -- Doh! */ 36 #define BROKEN_MCI_PAUSE /* Pausing actually stops play -- Doh! */
37 37
38 /* The maximum number of CD-ROM drives we'll detect (Don't change!) */ 38 /* The maximum number of CD-ROM drives we'll detect (Don't change!) */
39 #define MAX_DRIVES 26 39 #define MAX_DRIVES 26
40 40
41 /* A list of available CD-ROM drives */ 41 /* A list of available CD-ROM drives */
42 static char *SDL_cdlist[MAX_DRIVES]; 42 static char *SDL_cdlist[MAX_DRIVES];
43 static MCIDEVICEID SDL_mciID[MAX_DRIVES]; 43 static MCIDEVICEID SDL_mciID[MAX_DRIVES];
44 #ifdef BROKEN_MCI_PAUSE 44 #ifdef BROKEN_MCI_PAUSE
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 AddDrive(char *drive) 63 static void
64 { 64 AddDrive(char *drive)
65 int i; 65 {
66 66 int i;
67 if ( SDL_numcds < MAX_DRIVES ) { 67
68 /* Add this drive to our list */ 68 if (SDL_numcds < MAX_DRIVES) {
69 i = SDL_numcds; 69 /* Add this drive to our list */
70 SDL_cdlist[i] = SDL_strdup(drive); 70 i = SDL_numcds;
71 if ( SDL_cdlist[i] == NULL ) { 71 SDL_cdlist[i] = SDL_strdup(drive);
72 SDL_OutOfMemory(); 72 if (SDL_cdlist[i] == NULL) {
73 return; 73 SDL_OutOfMemory();
74 } 74 return;
75 ++SDL_numcds; 75 }
76 ++SDL_numcds;
76 #ifdef CDROM_DEBUG 77 #ifdef CDROM_DEBUG
77 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); 78 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
78 #endif 79 #endif
79 } 80 }
80 } 81 }
81 82
82 int SDL_SYS_CDInit(void) 83 int
83 { 84 SDL_SYS_CDInit(void)
84 /* checklist: Drive 'A' - 'Z' */ 85 {
85 int i; 86 /* checklist: Drive 'A' - 'Z' */
86 char drive[4]; 87 int i;
87 88 char drive[4];
88 /* Fill in our driver capabilities */ 89
89 SDL_CDcaps.Name = SDL_SYS_CDName; 90 /* Fill in our driver capabilities */
90 SDL_CDcaps.Open = SDL_SYS_CDOpen; 91 SDL_CDcaps.Name = SDL_SYS_CDName;
91 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; 92 SDL_CDcaps.Open = SDL_SYS_CDOpen;
92 SDL_CDcaps.Status = SDL_SYS_CDStatus; 93 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
93 SDL_CDcaps.Play = SDL_SYS_CDPlay; 94 SDL_CDcaps.Status = SDL_SYS_CDStatus;
94 SDL_CDcaps.Pause = SDL_SYS_CDPause; 95 SDL_CDcaps.Play = SDL_SYS_CDPlay;
95 SDL_CDcaps.Resume = SDL_SYS_CDResume; 96 SDL_CDcaps.Pause = SDL_SYS_CDPause;
96 SDL_CDcaps.Stop = SDL_SYS_CDStop; 97 SDL_CDcaps.Resume = SDL_SYS_CDResume;
97 SDL_CDcaps.Eject = SDL_SYS_CDEject; 98 SDL_CDcaps.Stop = SDL_SYS_CDStop;
98 SDL_CDcaps.Close = SDL_SYS_CDClose; 99 SDL_CDcaps.Eject = SDL_SYS_CDEject;
99 100 SDL_CDcaps.Close = SDL_SYS_CDClose;
100 /* Scan the system for CD-ROM drives */ 101
101 for ( i='A'; i<='Z'; ++i ) { 102 /* Scan the system for CD-ROM drives */
102 SDL_snprintf(drive, SDL_arraysize(drive), "%c:\\", i); 103 for (i = 'A'; i <= 'Z'; ++i) {
103 if ( GetDriveType(drive) == DRIVE_CDROM ) { 104 SDL_snprintf(drive, SDL_arraysize(drive), "%c:\\", i);
104 AddDrive(drive); 105 if (GetDriveType(drive) == DRIVE_CDROM) {
105 } 106 AddDrive(drive);
106 } 107 }
107 SDL_memset(SDL_mciID, 0, sizeof(SDL_mciID)); 108 }
108 return(0); 109 SDL_memset(SDL_mciID, 0, sizeof(SDL_mciID));
110 return (0);
109 } 111 }
110 112
111 /* General ioctl() CD-ROM command function */ 113 /* General ioctl() CD-ROM command function */
112 static int SDL_SYS_CDioctl(int id, UINT msg, DWORD flags, void *arg) 114 static int
113 { 115 SDL_SYS_CDioctl(int id, UINT msg, DWORD flags, void *arg)
114 MCIERROR mci_error; 116 {
115 117 MCIERROR mci_error;
116 mci_error = mciSendCommand(SDL_mciID[id], msg, flags, (DWORD_PTR)arg); 118
117 if ( mci_error ) { 119 mci_error = mciSendCommand(SDL_mciID[id], msg, flags, (DWORD_PTR) arg);
118 char error[256]; 120 if (mci_error) {
119 121 char error[256];
120 mciGetErrorString(mci_error, error, 256); 122
121 SDL_SetError("mciSendCommand() error: %s", error); 123 mciGetErrorString(mci_error, error, 256);
122 } 124 SDL_SetError("mciSendCommand() error: %s", error);
123 return(!mci_error ? 0 : -1); 125 }
124 } 126 return (!mci_error ? 0 : -1);
125 127 }
126 static const char *SDL_SYS_CDName(int drive) 128
127 { 129 static const char *
128 return(SDL_cdlist[drive]); 130 SDL_SYS_CDName(int drive)
129 } 131 {
130 132 return (SDL_cdlist[drive]);
131 static int SDL_SYS_CDOpen(int drive) 133 }
132 { 134
133 MCI_OPEN_PARMS mci_open; 135 static int
134 MCI_SET_PARMS mci_set; 136 SDL_SYS_CDOpen(int drive)
135 char device[3]; 137 {
136 DWORD flags; 138 MCI_OPEN_PARMS mci_open;
137 139 MCI_SET_PARMS mci_set;
138 /* Open the requested device */ 140 char device[3];
139 mci_open.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO; 141 DWORD flags;
140 device[0] = *SDL_cdlist[drive]; 142
141 device[1] = ':'; 143 /* Open the requested device */
142 device[2] = '\0'; 144 mci_open.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO;
143 mci_open.lpstrElementName = device; 145 device[0] = *SDL_cdlist[drive];
144 flags = 146 device[1] = ':';
145 (MCI_OPEN_TYPE|MCI_OPEN_SHAREABLE|MCI_OPEN_TYPE_ID|MCI_OPEN_ELEMENT); 147 device[2] = '\0';
146 if ( SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0 ) { 148 mci_open.lpstrElementName = device;
147 flags &= ~MCI_OPEN_SHAREABLE; 149 flags =
148 if ( SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0 ) { 150 (MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE | MCI_OPEN_TYPE_ID |
149 return(-1); 151 MCI_OPEN_ELEMENT);
150 } 152 if (SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0) {
151 } 153 flags &= ~MCI_OPEN_SHAREABLE;
152 SDL_mciID[drive] = mci_open.wDeviceID; 154 if (SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0) {
153 155 return (-1);
154 /* Set the minute-second-frame time format */ 156 }
155 mci_set.dwTimeFormat = MCI_FORMAT_MSF; 157 }
156 SDL_SYS_CDioctl(drive, MCI_SET, MCI_SET_TIME_FORMAT, &mci_set); 158 SDL_mciID[drive] = mci_open.wDeviceID;
157 159
158 #ifdef BROKEN_MCI_PAUSE 160 /* Set the minute-second-frame time format */
159 SDL_paused[drive] = 0; 161 mci_set.dwTimeFormat = MCI_FORMAT_MSF;
162 SDL_SYS_CDioctl(drive, MCI_SET, MCI_SET_TIME_FORMAT, &mci_set);
163
164 #ifdef BROKEN_MCI_PAUSE
165 SDL_paused[drive] = 0;
160 #endif 166 #endif
161 return(drive); 167 return (drive);
162 } 168 }
163 169
164 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) 170 static int
165 { 171 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
166 MCI_STATUS_PARMS mci_status; 172 {
167 int i, okay; 173 MCI_STATUS_PARMS mci_status;
168 DWORD flags; 174 int i, okay;
169 175 DWORD flags;
170 okay = 0; 176
171 mci_status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS; 177 okay = 0;
172 flags = MCI_STATUS_ITEM | MCI_WAIT; 178 mci_status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
173 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0 ) { 179 flags = MCI_STATUS_ITEM | MCI_WAIT;
174 cdrom->numtracks = mci_status.dwReturn; 180 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0) {
175 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { 181 cdrom->numtracks = mci_status.dwReturn;
176 cdrom->numtracks = SDL_MAX_TRACKS; 182 if (cdrom->numtracks > SDL_MAX_TRACKS) {
177 } 183 cdrom->numtracks = SDL_MAX_TRACKS;
178 /* Read all the track TOC entries */ 184 }
179 flags = MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT; 185 /* Read all the track TOC entries */
180 for ( i=0; i<cdrom->numtracks; ++i ) { 186 flags = MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT;
181 cdrom->track[i].id = i+1; 187 for (i = 0; i < cdrom->numtracks; ++i) {
182 mci_status.dwTrack = cdrom->track[i].id; 188 cdrom->track[i].id = i + 1;
189 mci_status.dwTrack = cdrom->track[i].id;
183 #ifdef MCI_CDA_STATUS_TYPE_TRACK 190 #ifdef MCI_CDA_STATUS_TYPE_TRACK
184 mci_status.dwItem = MCI_CDA_STATUS_TYPE_TRACK; 191 mci_status.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
185 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, 192 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
186 &mci_status) < 0 ) { 193 &mci_status) < 0) {
187 break; 194 break;
188 } 195 }
189 if ( mci_status.dwReturn == MCI_CDA_TRACK_AUDIO ) { 196 if (mci_status.dwReturn == MCI_CDA_TRACK_AUDIO) {
190 cdrom->track[i].type = SDL_AUDIO_TRACK; 197 cdrom->track[i].type = SDL_AUDIO_TRACK;
191 } else { 198 } else {
192 cdrom->track[i].type = SDL_DATA_TRACK; 199 cdrom->track[i].type = SDL_DATA_TRACK;
193 } 200 }
194 #else 201 #else
195 cdrom->track[i].type = SDL_AUDIO_TRACK; 202 cdrom->track[i].type = SDL_AUDIO_TRACK;
196 #endif 203 #endif
197 mci_status.dwItem = MCI_STATUS_POSITION; 204 mci_status.dwItem = MCI_STATUS_POSITION;
198 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, 205 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
199 &mci_status) < 0 ) { 206 &mci_status) < 0) {
200 break; 207 break;
201 } 208 }
202 cdrom->track[i].offset = MSF_TO_FRAMES( 209 cdrom->track[i].offset =
203 MCI_MSF_MINUTE(mci_status.dwReturn), 210 MSF_TO_FRAMES(MCI_MSF_MINUTE(mci_status.dwReturn),
204 MCI_MSF_SECOND(mci_status.dwReturn), 211 MCI_MSF_SECOND(mci_status.dwReturn),
205 MCI_MSF_FRAME(mci_status.dwReturn)); 212 MCI_MSF_FRAME(mci_status.dwReturn));
206 cdrom->track[i].length = 0; 213 cdrom->track[i].length = 0;
207 if ( i > 0 ) { 214 if (i > 0) {
208 cdrom->track[i-1].length = 215 cdrom->track[i - 1].length =
209 cdrom->track[i].offset- 216 cdrom->track[i].offset - cdrom->track[i - 1].offset;
210 cdrom->track[i-1].offset; 217 }
211 } 218 }
212 } 219 if (i == cdrom->numtracks) {
213 if ( i == cdrom->numtracks ) { 220 mci_status.dwTrack = cdrom->track[i - 1].id;
214 mci_status.dwTrack = cdrom->track[i - 1].id; 221 mci_status.dwItem = MCI_STATUS_LENGTH;
215 mci_status.dwItem = MCI_STATUS_LENGTH; 222 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
216 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, 223 &mci_status) == 0) {
217 &mci_status) == 0 ) { 224 cdrom->track[i - 1].length =
218 cdrom->track[i - 1].length = MSF_TO_FRAMES( 225 MSF_TO_FRAMES(MCI_MSF_MINUTE(mci_status.dwReturn),
219 MCI_MSF_MINUTE(mci_status.dwReturn), 226 MCI_MSF_SECOND(mci_status.dwReturn),
220 MCI_MSF_SECOND(mci_status.dwReturn), 227 MCI_MSF_FRAME(mci_status.dwReturn));
221 MCI_MSF_FRAME(mci_status.dwReturn)); 228 /* compute lead-out offset */
222 /* compute lead-out offset */ 229 cdrom->track[i].offset = cdrom->track[i - 1].offset +
223 cdrom->track[i].offset = cdrom->track[i - 1].offset + 230 cdrom->track[i - 1].length;
224 cdrom->track[i - 1].length; 231 cdrom->track[i].length = 0;
225 cdrom->track[i].length = 0; 232 okay = 1;
226 okay = 1; 233 }
227 } 234 }
228 } 235 }
229 } 236 return (okay ? 0 : -1);
230 return(okay ? 0 : -1);
231 } 237 }
232 238
233 /* Get CD-ROM status */ 239 /* Get CD-ROM status */
234 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) 240 static CDstatus
235 { 241 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
236 CDstatus status; 242 {
237 MCI_STATUS_PARMS mci_status; 243 CDstatus status;
238 DWORD flags; 244 MCI_STATUS_PARMS mci_status;
239 245 DWORD flags;
240 flags = MCI_STATUS_ITEM | MCI_WAIT; 246
241 mci_status.dwItem = MCI_STATUS_MODE; 247 flags = MCI_STATUS_ITEM | MCI_WAIT;
242 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) < 0 ) { 248 mci_status.dwItem = MCI_STATUS_MODE;
243 status = CD_ERROR; 249 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) < 0) {
244 } else { 250 status = CD_ERROR;
245 switch (mci_status.dwReturn) { 251 } else {
246 case MCI_MODE_NOT_READY: 252 switch (mci_status.dwReturn) {
247 case MCI_MODE_OPEN: 253 case MCI_MODE_NOT_READY:
248 status = CD_TRAYEMPTY; 254 case MCI_MODE_OPEN:
249 break; 255 status = CD_TRAYEMPTY;
250 case MCI_MODE_STOP: 256 break;
251 #ifdef BROKEN_MCI_PAUSE 257 case MCI_MODE_STOP:
252 if ( SDL_paused[cdrom->id] ) { 258 #ifdef BROKEN_MCI_PAUSE
253 status = CD_PAUSED; 259 if (SDL_paused[cdrom->id]) {
254 } else { 260 status = CD_PAUSED;
255 status = CD_STOPPED; 261 } else {
256 } 262 status = CD_STOPPED;
263 }
257 #else 264 #else
258 status = CD_STOPPED; 265 status = CD_STOPPED;
259 #endif /* BROKEN_MCI_PAUSE */ 266 #endif /* BROKEN_MCI_PAUSE */
260 break; 267 break;
261 case MCI_MODE_PLAY: 268 case MCI_MODE_PLAY:
262 #ifdef BROKEN_MCI_PAUSE 269 #ifdef BROKEN_MCI_PAUSE
263 if ( SDL_paused[cdrom->id] ) { 270 if (SDL_paused[cdrom->id]) {
264 status = CD_PAUSED; 271 status = CD_PAUSED;
265 } else { 272 } else {
266 status = CD_PLAYING; 273 status = CD_PLAYING;
267 } 274 }
268 #else 275 #else
269 status = CD_PLAYING; 276 status = CD_PLAYING;
270 #endif /* BROKEN_MCI_PAUSE */ 277 #endif /* BROKEN_MCI_PAUSE */
271 break; 278 break;
272 case MCI_MODE_PAUSE: 279 case MCI_MODE_PAUSE:
273 status = CD_PAUSED; 280 status = CD_PAUSED;
274 break; 281 break;
275 default: 282 default:
276 status = CD_ERROR; 283 status = CD_ERROR;
277 break; 284 break;
278 } 285 }
279 } 286 }
280 if ( position ) { 287 if (position) {
281 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { 288 if (status == CD_PLAYING || (status == CD_PAUSED)) {
282 mci_status.dwItem = MCI_STATUS_POSITION; 289 mci_status.dwItem = MCI_STATUS_POSITION;
283 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, 290 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags,
284 &mci_status) == 0 ) { 291 &mci_status) == 0) {
285 *position = MSF_TO_FRAMES( 292 *position =
286 MCI_MSF_MINUTE(mci_status.dwReturn), 293 MSF_TO_FRAMES(MCI_MSF_MINUTE(mci_status.dwReturn),
287 MCI_MSF_SECOND(mci_status.dwReturn), 294 MCI_MSF_SECOND(mci_status.dwReturn),
288 MCI_MSF_FRAME(mci_status.dwReturn)); 295 MCI_MSF_FRAME(mci_status.dwReturn));
289 } else { 296 } else {
290 *position = 0; 297 *position = 0;
291 } 298 }
292 } else { 299 } else {
293 *position = 0; 300 *position = 0;
294 } 301 }
295 } 302 }
296 return(status); 303 return (status);
297 } 304 }
298 305
299 /* Start play */ 306 /* Start play */
300 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 307 static int
301 { 308 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
302 MCI_PLAY_PARMS mci_play; 309 {
303 int m, s, f; 310 MCI_PLAY_PARMS mci_play;
304 DWORD flags; 311 int m, s, f;
305 312 DWORD flags;
306 flags = MCI_FROM | MCI_TO | MCI_NOTIFY; 313
307 mci_play.dwCallback = 0; 314 flags = MCI_FROM | MCI_TO | MCI_NOTIFY;
308 FRAMES_TO_MSF(start, &m, &s, &f); 315 mci_play.dwCallback = 0;
309 mci_play.dwFrom = MCI_MAKE_MSF(m, s, f); 316 FRAMES_TO_MSF(start, &m, &s, &f);
310 FRAMES_TO_MSF(start+length, &m, &s, &f); 317 mci_play.dwFrom = MCI_MAKE_MSF(m, s, f);
311 mci_play.dwTo = MCI_MAKE_MSF(m, s, f); 318 FRAMES_TO_MSF(start + length, &m, &s, &f);
312 SDL_CD_end_position = mci_play.dwTo; 319 mci_play.dwTo = MCI_MAKE_MSF(m, s, f);
313 return(SDL_SYS_CDioctl(cdrom->id, MCI_PLAY, flags, &mci_play)); 320 SDL_CD_end_position = mci_play.dwTo;
321 return (SDL_SYS_CDioctl(cdrom->id, MCI_PLAY, flags, &mci_play));
314 } 322 }
315 323
316 /* Pause play */ 324 /* Pause play */
317 static int SDL_SYS_CDPause(SDL_CD *cdrom) 325 static int
318 { 326 SDL_SYS_CDPause(SDL_CD * cdrom)
319 #ifdef BROKEN_MCI_PAUSE 327 {
320 SDL_paused[cdrom->id] = 1; 328 #ifdef BROKEN_MCI_PAUSE
329 SDL_paused[cdrom->id] = 1;
321 #endif 330 #endif
322 return(SDL_SYS_CDioctl(cdrom->id, MCI_PAUSE, MCI_WAIT, NULL)); 331 return (SDL_SYS_CDioctl(cdrom->id, MCI_PAUSE, MCI_WAIT, NULL));
323 } 332 }
324 333
325 /* Resume play */ 334 /* Resume play */
326 static int SDL_SYS_CDResume(SDL_CD *cdrom) 335 static int
327 { 336 SDL_SYS_CDResume(SDL_CD * cdrom)
328 #ifdef BROKEN_MCI_PAUSE 337 {
329 MCI_STATUS_PARMS mci_status; 338 #ifdef BROKEN_MCI_PAUSE
330 int okay; 339 MCI_STATUS_PARMS mci_status;
331 int flags; 340 int okay;
332 341 int flags;
333 okay = 0; 342
334 /* Play from the current play position to the end position set earlier */ 343 okay = 0;
335 flags = MCI_STATUS_ITEM | MCI_WAIT; 344 /* Play from the current play position to the end position set earlier */
336 mci_status.dwItem = MCI_STATUS_POSITION; 345 flags = MCI_STATUS_ITEM | MCI_WAIT;
337 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0 ) { 346 mci_status.dwItem = MCI_STATUS_POSITION;
338 MCI_PLAY_PARMS mci_play; 347 if (SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0) {
339 348 MCI_PLAY_PARMS mci_play;
340 flags = MCI_FROM | MCI_TO | MCI_NOTIFY; 349
341 mci_play.dwCallback = 0; 350 flags = MCI_FROM | MCI_TO | MCI_NOTIFY;
342 mci_play.dwFrom = mci_status.dwReturn; 351 mci_play.dwCallback = 0;
343 mci_play.dwTo = SDL_CD_end_position; 352 mci_play.dwFrom = mci_status.dwReturn;
344 if (SDL_SYS_CDioctl(cdrom->id,MCI_PLAY,flags,&mci_play) == 0) { 353 mci_play.dwTo = SDL_CD_end_position;
345 okay = 1; 354 if (SDL_SYS_CDioctl(cdrom->id, MCI_PLAY, flags, &mci_play) == 0) {
346 SDL_paused[cdrom->id] = 0; 355 okay = 1;
347 } 356 SDL_paused[cdrom->id] = 0;
348 } 357 }
349 return(okay ? 0 : -1); 358 }
359 return (okay ? 0 : -1);
350 #else 360 #else
351 return(SDL_SYS_CDioctl(cdrom->id, MCI_RESUME, MCI_WAIT, NULL)); 361 return (SDL_SYS_CDioctl(cdrom->id, MCI_RESUME, MCI_WAIT, NULL));
352 #endif /* BROKEN_MCI_PAUSE */ 362 #endif /* BROKEN_MCI_PAUSE */
353 } 363 }
354 364
355 /* Stop play */ 365 /* Stop play */
356 static int SDL_SYS_CDStop(SDL_CD *cdrom) 366 static int
357 { 367 SDL_SYS_CDStop(SDL_CD * cdrom)
358 return(SDL_SYS_CDioctl(cdrom->id, MCI_STOP, MCI_WAIT, NULL)); 368 {
369 return (SDL_SYS_CDioctl(cdrom->id, MCI_STOP, MCI_WAIT, NULL));
359 } 370 }
360 371
361 /* Eject the CD-ROM */ 372 /* Eject the CD-ROM */
362 static int SDL_SYS_CDEject(SDL_CD *cdrom) 373 static int
363 { 374 SDL_SYS_CDEject(SDL_CD * cdrom)
364 return(SDL_SYS_CDioctl(cdrom->id, MCI_SET, MCI_SET_DOOR_OPEN, NULL)); 375 {
376 return (SDL_SYS_CDioctl(cdrom->id, MCI_SET, MCI_SET_DOOR_OPEN, NULL));
365 } 377 }
366 378
367 /* Close the CD-ROM handle */ 379 /* Close the CD-ROM handle */
368 static void SDL_SYS_CDClose(SDL_CD *cdrom) 380 static void
369 { 381 SDL_SYS_CDClose(SDL_CD * cdrom)
370 SDL_SYS_CDioctl(cdrom->id, MCI_CLOSE, MCI_WAIT, NULL); 382 {
371 } 383 SDL_SYS_CDioctl(cdrom->id, MCI_CLOSE, MCI_WAIT, NULL);
372 384 }
373 void SDL_SYS_CDQuit(void) 385
374 { 386 void
375 int i; 387 SDL_SYS_CDQuit(void)
376 388 {
377 if ( SDL_numcds > 0 ) { 389 int i;
378 for ( i=0; i<SDL_numcds; ++i ) { 390
379 SDL_free(SDL_cdlist[i]); 391 if (SDL_numcds > 0) {
380 } 392 for (i = 0; i < SDL_numcds; ++i) {
381 SDL_numcds = 0; 393 SDL_free(SDL_cdlist[i]);
382 } 394 }
395 SDL_numcds = 0;
396 }
383 } 397 }
384 398
385 #endif /* SDL_CDROM_WIN32 */ 399 #endif /* SDL_CDROM_WIN32 */
400 /* vi: set ts=4 sw=4 expandtab: */