Mercurial > sdl-ios-xcode
annotate src/cdrom/win32/SDL_syscdrom.c @ 1394:e57f8d1344b6
Set the install permissions correctly
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 20 Feb 2006 20:11:08 +0000 |
parents | c0a74f199ecf |
children | d910939febfa |
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:
904
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:
904
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:
904
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:
904
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:
904
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:
904
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:
904
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:
201
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* Functions for system-level CD-ROM audio control */ | |
24 | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
25 #include "SDL_windows.h" |
0 | 26 #include <mmsystem.h> |
27 | |
28 #include "SDL_cdrom.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
29 #include "../SDL_syscdrom.h" |
0 | 30 |
31 /* This really broken?? */ | |
32 #define BROKEN_MCI_PAUSE /* Pausing actually stops play -- Doh! */ | |
33 | |
34 /* The maximum number of CD-ROM drives we'll detect (Don't change!) */ | |
35 #define MAX_DRIVES 26 | |
36 | |
37 /* A list of available CD-ROM drives */ | |
38 static char *SDL_cdlist[MAX_DRIVES]; | |
39 static MCIDEVICEID SDL_mciID[MAX_DRIVES]; | |
40 #ifdef BROKEN_MCI_PAUSE | |
41 static int SDL_paused[MAX_DRIVES]; | |
42 #endif | |
904
34af7946130a
Date: Fri, 16 Jul 2004 17:25:45 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
43 static int SDL_CD_end_position; |
0 | 44 |
45 /* The system-dependent CD control functions */ | |
46 static const char *SDL_SYS_CDName(int drive); | |
47 static int SDL_SYS_CDOpen(int drive); | |
48 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
49 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
50 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
51 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
52 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
53 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
54 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
55 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
56 | |
57 | |
58 /* Add a CD-ROM drive to our list of valid drives */ | |
59 static void AddDrive(char *drive) | |
60 { | |
61 int i; | |
62 | |
63 if ( SDL_numcds < MAX_DRIVES ) { | |
64 /* Add this drive to our list */ | |
65 i = SDL_numcds; | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
66 SDL_cdlist[i] = SDL_strdup(drive); |
0 | 67 if ( SDL_cdlist[i] == NULL ) { |
68 SDL_OutOfMemory(); | |
69 return; | |
70 } | |
71 ++SDL_numcds; | |
72 #ifdef CDROM_DEBUG | |
73 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); | |
74 #endif | |
75 } | |
76 } | |
77 | |
78 int SDL_SYS_CDInit(void) | |
79 { | |
80 /* checklist: Drive 'A' - 'Z' */ | |
81 int i; | |
82 char drive[4]; | |
83 | |
84 /* Fill in our driver capabilities */ | |
85 SDL_CDcaps.Name = SDL_SYS_CDName; | |
86 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
87 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
88 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
89 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
90 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
91 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
92 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
93 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
94 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
95 | |
96 /* Scan the system for CD-ROM drives */ | |
97 for ( i='A'; i<='Z'; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
98 SDL_snprintf(drive, SDL_arraysize(drive), "%c:\\", i); |
0 | 99 if ( GetDriveType(drive) == DRIVE_CDROM ) { |
100 AddDrive(drive); | |
101 } | |
102 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
103 SDL_memset(SDL_mciID, 0, sizeof(SDL_mciID)); |
0 | 104 return(0); |
105 } | |
106 | |
107 /* General ioctl() CD-ROM command function */ | |
108 static int SDL_SYS_CDioctl(int id, UINT msg, DWORD flags, void *arg) | |
109 { | |
110 MCIERROR mci_error; | |
111 | |
112 mci_error = mciSendCommand(SDL_mciID[id], msg, flags, (DWORD)arg); | |
113 if ( mci_error ) { | |
114 char error[256]; | |
115 | |
116 mciGetErrorString(mci_error, error, 256); | |
117 SDL_SetError("mciSendCommand() error: %s", error); | |
118 } | |
119 return(!mci_error ? 0 : -1); | |
120 } | |
121 | |
122 static const char *SDL_SYS_CDName(int drive) | |
123 { | |
124 return(SDL_cdlist[drive]); | |
125 } | |
126 | |
127 static int SDL_SYS_CDOpen(int drive) | |
128 { | |
129 MCI_OPEN_PARMS mci_open; | |
130 MCI_SET_PARMS mci_set; | |
131 char device[3]; | |
132 DWORD flags; | |
133 | |
134 /* Open the requested device */ | |
135 mci_open.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO; | |
136 device[0] = *SDL_cdlist[drive]; | |
137 device[1] = ':'; | |
138 device[2] = '\0'; | |
139 mci_open.lpstrElementName = device; | |
140 flags = | |
141 (MCI_OPEN_TYPE|MCI_OPEN_SHAREABLE|MCI_OPEN_TYPE_ID|MCI_OPEN_ELEMENT); | |
142 if ( SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0 ) { | |
143 flags &= ~MCI_OPEN_SHAREABLE; | |
144 if ( SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0 ) { | |
145 return(-1); | |
146 } | |
147 } | |
148 SDL_mciID[drive] = mci_open.wDeviceID; | |
149 | |
150 /* Set the minute-second-frame time format */ | |
151 mci_set.dwTimeFormat = MCI_FORMAT_MSF; | |
152 SDL_SYS_CDioctl(drive, MCI_SET, MCI_SET_TIME_FORMAT, &mci_set); | |
153 | |
154 #ifdef BROKEN_MCI_PAUSE | |
155 SDL_paused[drive] = 0; | |
156 #endif | |
157 return(drive); | |
158 } | |
159 | |
160 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
161 { | |
162 MCI_STATUS_PARMS mci_status; | |
163 int i, okay; | |
164 DWORD flags; | |
165 | |
166 okay = 0; | |
167 mci_status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS; | |
168 flags = MCI_STATUS_ITEM | MCI_WAIT; | |
169 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0 ) { | |
170 cdrom->numtracks = mci_status.dwReturn; | |
171 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { | |
172 cdrom->numtracks = SDL_MAX_TRACKS; | |
173 } | |
174 /* Read all the track TOC entries */ | |
175 flags = MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT; | |
176 for ( i=0; i<cdrom->numtracks; ++i ) { | |
177 cdrom->track[i].id = i+1; | |
178 mci_status.dwTrack = cdrom->track[i].id; | |
179 #ifdef MCI_CDA_STATUS_TYPE_TRACK | |
180 mci_status.dwItem = MCI_CDA_STATUS_TYPE_TRACK; | |
181 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, | |
182 &mci_status) < 0 ) { | |
183 break; | |
184 } | |
185 if ( mci_status.dwReturn == MCI_CDA_TRACK_AUDIO ) { | |
186 cdrom->track[i].type = SDL_AUDIO_TRACK; | |
187 } else { | |
188 cdrom->track[i].type = SDL_DATA_TRACK; | |
189 } | |
190 #else | |
191 cdrom->track[i].type = SDL_AUDIO_TRACK; | |
192 #endif | |
193 mci_status.dwItem = MCI_STATUS_POSITION; | |
194 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, | |
195 &mci_status) < 0 ) { | |
196 break; | |
197 } | |
198 cdrom->track[i].offset = MSF_TO_FRAMES( | |
199 MCI_MSF_MINUTE(mci_status.dwReturn), | |
200 MCI_MSF_SECOND(mci_status.dwReturn), | |
201 MCI_MSF_FRAME(mci_status.dwReturn)); | |
202 cdrom->track[i].length = 0; | |
203 if ( i > 0 ) { | |
204 cdrom->track[i-1].length = | |
205 cdrom->track[i].offset- | |
206 cdrom->track[i-1].offset; | |
207 } | |
208 } | |
209 if ( i == cdrom->numtracks ) { | |
201
ddee60057806
Fixed last track time calculation (thanks Tchi Southivong)
Sam Lantinga <slouken@libsdl.org>
parents:
192
diff
changeset
|
210 mci_status.dwTrack = cdrom->track[i - 1].id; |
0 | 211 mci_status.dwItem = MCI_STATUS_LENGTH; |
212 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, | |
213 &mci_status) == 0 ) { | |
201
ddee60057806
Fixed last track time calculation (thanks Tchi Southivong)
Sam Lantinga <slouken@libsdl.org>
parents:
192
diff
changeset
|
214 cdrom->track[i - 1].length = MSF_TO_FRAMES( |
0 | 215 MCI_MSF_MINUTE(mci_status.dwReturn), |
216 MCI_MSF_SECOND(mci_status.dwReturn), | |
201
ddee60057806
Fixed last track time calculation (thanks Tchi Southivong)
Sam Lantinga <slouken@libsdl.org>
parents:
192
diff
changeset
|
217 MCI_MSF_FRAME(mci_status.dwReturn)) + 1; /* +1 to fix */ |
ddee60057806
Fixed last track time calculation (thanks Tchi Southivong)
Sam Lantinga <slouken@libsdl.org>
parents:
192
diff
changeset
|
218 /* MCI last track length bug */ |
ddee60057806
Fixed last track time calculation (thanks Tchi Southivong)
Sam Lantinga <slouken@libsdl.org>
parents:
192
diff
changeset
|
219 /* compute lead-out offset */ |
ddee60057806
Fixed last track time calculation (thanks Tchi Southivong)
Sam Lantinga <slouken@libsdl.org>
parents:
192
diff
changeset
|
220 cdrom->track[i].offset = cdrom->track[i - 1].offset + |
ddee60057806
Fixed last track time calculation (thanks Tchi Southivong)
Sam Lantinga <slouken@libsdl.org>
parents:
192
diff
changeset
|
221 cdrom->track[i - 1].length; |
0 | 222 cdrom->track[i].length = 0; |
223 okay = 1; | |
224 } | |
225 } | |
226 } | |
227 return(okay ? 0 : -1); | |
228 } | |
229 | |
230 /* Get CD-ROM status */ | |
231 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
232 { | |
233 CDstatus status; | |
234 MCI_STATUS_PARMS mci_status; | |
235 DWORD flags; | |
236 | |
237 flags = MCI_STATUS_ITEM | MCI_WAIT; | |
238 mci_status.dwItem = MCI_STATUS_MODE; | |
239 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) < 0 ) { | |
240 status = CD_ERROR; | |
241 } else { | |
242 switch (mci_status.dwReturn) { | |
243 case MCI_MODE_NOT_READY: | |
244 case MCI_MODE_OPEN: | |
245 status = CD_TRAYEMPTY; | |
246 break; | |
247 case MCI_MODE_STOP: | |
248 #ifdef BROKEN_MCI_PAUSE | |
249 if ( SDL_paused[cdrom->id] ) { | |
250 status = CD_PAUSED; | |
251 } else { | |
252 status = CD_STOPPED; | |
253 } | |
254 #else | |
255 status = CD_STOPPED; | |
256 #endif /* BROKEN_MCI_PAUSE */ | |
257 break; | |
258 case MCI_MODE_PLAY: | |
192
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
259 #ifdef BROKEN_MCI_PAUSE |
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
260 if ( SDL_paused[cdrom->id] ) { |
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
261 status = CD_PAUSED; |
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
262 } else { |
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
263 status = CD_PLAYING; |
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
264 } |
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
265 #else |
0 | 266 status = CD_PLAYING; |
192
e31f8d815aaa
Fixed resuming a paused CD on Win2K (thanks Aragorn)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
267 #endif /* BROKEN_MCI_PAUSE */ |
0 | 268 break; |
269 case MCI_MODE_PAUSE: | |
270 status = CD_PAUSED; | |
271 break; | |
272 default: | |
273 status = CD_ERROR; | |
274 break; | |
275 } | |
276 } | |
277 if ( position ) { | |
278 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { | |
279 mci_status.dwItem = MCI_STATUS_POSITION; | |
280 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, | |
281 &mci_status) == 0 ) { | |
282 *position = MSF_TO_FRAMES( | |
283 MCI_MSF_MINUTE(mci_status.dwReturn), | |
284 MCI_MSF_SECOND(mci_status.dwReturn), | |
285 MCI_MSF_FRAME(mci_status.dwReturn)); | |
286 } else { | |
287 *position = 0; | |
288 } | |
289 } else { | |
290 *position = 0; | |
291 } | |
292 } | |
293 return(status); | |
294 } | |
295 | |
296 /* Start play */ | |
297 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
298 { | |
299 MCI_PLAY_PARMS mci_play; | |
300 int m, s, f; | |
301 DWORD flags; | |
302 | |
303 flags = MCI_FROM | MCI_TO | MCI_NOTIFY; | |
304 mci_play.dwCallback = 0; | |
305 FRAMES_TO_MSF(start, &m, &s, &f); | |
306 mci_play.dwFrom = MCI_MAKE_MSF(m, s, f); | |
307 FRAMES_TO_MSF(start+length, &m, &s, &f); | |
308 mci_play.dwTo = MCI_MAKE_MSF(m, s, f); | |
904
34af7946130a
Date: Fri, 16 Jul 2004 17:25:45 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
309 SDL_CD_end_position = mci_play.dwTo; |
0 | 310 return(SDL_SYS_CDioctl(cdrom->id, MCI_PLAY, flags, &mci_play)); |
311 } | |
312 | |
313 /* Pause play */ | |
314 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
315 { | |
316 #ifdef BROKEN_MCI_PAUSE | |
317 SDL_paused[cdrom->id] = 1; | |
318 #endif | |
319 return(SDL_SYS_CDioctl(cdrom->id, MCI_PAUSE, MCI_WAIT, NULL)); | |
320 } | |
321 | |
322 /* Resume play */ | |
323 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
324 { | |
325 #ifdef BROKEN_MCI_PAUSE | |
326 MCI_STATUS_PARMS mci_status; | |
327 int okay; | |
328 int flags; | |
329 | |
330 okay = 0; | |
904
34af7946130a
Date: Fri, 16 Jul 2004 17:25:45 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
331 /* Play from the current play position to the end position set earlier */ |
0 | 332 flags = MCI_STATUS_ITEM | MCI_WAIT; |
333 mci_status.dwItem = MCI_STATUS_POSITION; | |
334 if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0 ) { | |
335 MCI_PLAY_PARMS mci_play; | |
336 | |
904
34af7946130a
Date: Fri, 16 Jul 2004 17:25:45 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
337 flags = MCI_FROM | MCI_TO | MCI_NOTIFY; |
0 | 338 mci_play.dwCallback = 0; |
339 mci_play.dwFrom = mci_status.dwReturn; | |
904
34af7946130a
Date: Fri, 16 Jul 2004 17:25:45 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
340 mci_play.dwTo = SDL_CD_end_position; |
0 | 341 if (SDL_SYS_CDioctl(cdrom->id,MCI_PLAY,flags,&mci_play) == 0) { |
342 okay = 1; | |
343 SDL_paused[cdrom->id] = 0; | |
344 } | |
345 } | |
346 return(okay ? 0 : -1); | |
347 #else | |
348 return(SDL_SYS_CDioctl(cdrom->id, MCI_RESUME, MCI_WAIT, NULL)); | |
349 #endif /* BROKEN_MCI_PAUSE */ | |
350 } | |
351 | |
352 /* Stop play */ | |
353 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
354 { | |
355 return(SDL_SYS_CDioctl(cdrom->id, MCI_STOP, MCI_WAIT, NULL)); | |
356 } | |
357 | |
358 /* Eject the CD-ROM */ | |
359 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
360 { | |
361 return(SDL_SYS_CDioctl(cdrom->id, MCI_SET, MCI_SET_DOOR_OPEN, NULL)); | |
362 } | |
363 | |
364 /* Close the CD-ROM handle */ | |
365 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
366 { | |
367 SDL_SYS_CDioctl(cdrom->id, MCI_CLOSE, MCI_WAIT, NULL); | |
368 } | |
369 | |
370 void SDL_SYS_CDQuit(void) | |
371 { | |
372 int i; | |
373 | |
374 if ( SDL_numcds > 0 ) { | |
375 for ( i=0; i<SDL_numcds; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
376 SDL_free(SDL_cdlist[i]); |
0 | 377 } |
378 SDL_numcds = 0; | |
379 } | |
380 } |