Mercurial > sdl-ios-xcode
comparison src/cdrom/os2/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 |
---|---|
34 | 34 |
35 /* Size of MCI result buffer (in bytes) */ | 35 /* Size of MCI result buffer (in bytes) */ |
36 #define MCI_CMDRETBUFSIZE 128 | 36 #define MCI_CMDRETBUFSIZE 128 |
37 | 37 |
38 /* The maximum number of CD-ROM drives we'll detect */ | 38 /* The maximum number of CD-ROM drives we'll detect */ |
39 #define MAX_DRIVES 16 | 39 #define MAX_DRIVES 16 |
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 dev_t SDL_cdmode[MAX_DRIVES]; | 43 //static dev_t SDL_cdmode[MAX_DRIVES]; |
44 | 44 |
45 /* The system-dependent CD control functions */ | 45 /* The system-dependent CD control functions */ |
46 static const char *SDL_SYS_CDName(int drive); | 46 static const char *SDL_SYS_CDName(int drive); |
47 static int SDL_SYS_CDOpen(int drive); | 47 static int SDL_SYS_CDOpen(int drive); |
48 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | 48 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom); |
49 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | 49 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position); |
50 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | 50 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length); |
51 static int SDL_SYS_CDPause(SDL_CD *cdrom); | 51 static int SDL_SYS_CDPause(SDL_CD * cdrom); |
52 static int SDL_SYS_CDResume(SDL_CD *cdrom); | 52 static int SDL_SYS_CDResume(SDL_CD * cdrom); |
53 static int SDL_SYS_CDStop(SDL_CD *cdrom); | 53 static int SDL_SYS_CDStop(SDL_CD * cdrom); |
54 static int SDL_SYS_CDEject(SDL_CD *cdrom); | 54 static int SDL_SYS_CDEject(SDL_CD * cdrom); |
55 static void SDL_SYS_CDClose(SDL_CD *cdrom); | 55 static void SDL_SYS_CDClose(SDL_CD * cdrom); |
56 | 56 |
57 /* MCI Timing Functions */ | 57 /* MCI Timing Functions */ |
58 #define MCI_MMTIMEPERSECOND 3000 | 58 #define MCI_MMTIMEPERSECOND 3000 |
59 #define FRAMESFROMMM(mmtime) (((mmtime)*CD_FPS)/MCI_MMTIMEPERSECOND) | 59 #define FRAMESFROMMM(mmtime) (((mmtime)*CD_FPS)/MCI_MMTIMEPERSECOND) |
60 | 60 |
61 | 61 |
62 /* Ready for MCI CDAudio Devices */ | 62 /* Ready for MCI CDAudio Devices */ |
63 int SDL_SYS_CDInit(void) | 63 int |
64 { | 64 SDL_SYS_CDInit(void) |
65 int i; /* generig counter */ | 65 { |
66 MCI_SYSINFO_PARMS msp; /* Structure to MCI SysInfo parameters */ | 66 int i; /* generig counter */ |
67 CHAR SysInfoRet[MCI_CMDRETBUFSIZE]; /* Buffer for MCI Command result */ | 67 MCI_SYSINFO_PARMS msp; /* Structure to MCI SysInfo parameters */ |
68 CHAR SysInfoRet[MCI_CMDRETBUFSIZE]; /* Buffer for MCI Command result */ | |
68 | 69 |
69 /* Fill in our driver capabilities */ | 70 /* Fill in our driver capabilities */ |
70 SDL_CDcaps.Name = SDL_SYS_CDName; | 71 SDL_CDcaps.Name = SDL_SYS_CDName; |
71 SDL_CDcaps.Open = SDL_SYS_CDOpen; | 72 SDL_CDcaps.Open = SDL_SYS_CDOpen; |
72 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | 73 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; |
73 SDL_CDcaps.Status = SDL_SYS_CDStatus; | 74 SDL_CDcaps.Status = SDL_SYS_CDStatus; |
74 SDL_CDcaps.Play = SDL_SYS_CDPlay; | 75 SDL_CDcaps.Play = SDL_SYS_CDPlay; |
75 SDL_CDcaps.Pause = SDL_SYS_CDPause; | 76 SDL_CDcaps.Pause = SDL_SYS_CDPause; |
76 SDL_CDcaps.Resume = SDL_SYS_CDResume; | 77 SDL_CDcaps.Resume = SDL_SYS_CDResume; |
77 SDL_CDcaps.Stop = SDL_SYS_CDStop; | 78 SDL_CDcaps.Stop = SDL_SYS_CDStop; |
78 SDL_CDcaps.Eject = SDL_SYS_CDEject; | 79 SDL_CDcaps.Eject = SDL_SYS_CDEject; |
79 SDL_CDcaps.Close = SDL_SYS_CDClose; | 80 SDL_CDcaps.Close = SDL_SYS_CDClose; |
80 | 81 |
81 /* Get the number of CD ROMs in the System */ | 82 /* Get the number of CD ROMs in the System */ |
82 /* Clean SysInfo structure */ | 83 /* Clean SysInfo structure */ |
83 SDL_memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS)); | 84 SDL_memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS)); |
84 /* Prepare structure to Ask Numer of Audio CDs */ | 85 /* Prepare structure to Ask Numer of Audio CDs */ |
85 msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO; /* CD Audio Type */ | 86 msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO; /* CD Audio Type */ |
86 msp.pszReturn = (PSZ)&SysInfoRet; /* Return Structure */ | 87 msp.pszReturn = (PSZ) & SysInfoRet; /* Return Structure */ |
87 msp.ulRetSize = MCI_CMDRETBUFSIZE; /* Size of ret struct */ | 88 msp.ulRetSize = MCI_CMDRETBUFSIZE; /* Size of ret struct */ |
88 if (LOUSHORT(mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID)&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR); | 89 if (LOUSHORT |
89 SDL_numcds = atoi(SysInfoRet); | 90 (mciSendCommand |
90 if (SDL_numcds > MAX_DRIVES) SDL_numcds = MAX_DRIVES; /* Limit maximum CD number */ | 91 (0, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID) & msp, |
92 0)) != MCIERR_SUCCESS) | |
93 return (CD_ERROR); | |
94 SDL_numcds = atoi(SysInfoRet); | |
95 if (SDL_numcds > MAX_DRIVES) | |
96 SDL_numcds = MAX_DRIVES; /* Limit maximum CD number */ | |
91 | 97 |
92 /* Get and Add their system name to the SDL_cdlist */ | 98 /* Get and Add their system name to the SDL_cdlist */ |
93 msp.pszReturn = (PSZ)&SysInfoRet; /* Return Structure */ | 99 msp.pszReturn = (PSZ) & SysInfoRet; /* Return Structure */ |
94 msp.ulRetSize = MCI_CMDRETBUFSIZE; /* Size of ret struct */ | 100 msp.ulRetSize = MCI_CMDRETBUFSIZE; /* Size of ret struct */ |
95 msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO; /* CD Audio Type */ | 101 msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO; /* CD Audio Type */ |
96 for (i=0; i<SDL_numcds; i++) | 102 for (i = 0; i < SDL_numcds; i++) { |
97 { | 103 msp.ulNumber = i + 1; |
98 msp.ulNumber = i+1; | 104 mciSendCommand(0, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT, &msp, 0); |
99 mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT,&msp, 0); | 105 SDL_cdlist[i] = SDL_strdup(SysInfoRet); |
100 SDL_cdlist[i] = SDL_strdup(SysInfoRet); | 106 if (SDL_cdlist[i] == NULL) { |
101 if ( SDL_cdlist[i] == NULL ) | 107 SDL_OutOfMemory(); |
102 { | 108 return (-1); |
103 SDL_OutOfMemory(); | 109 } |
104 return(-1); | 110 } |
105 } | 111 return (0); |
106 } | |
107 return(0); | |
108 } | 112 } |
109 | 113 |
110 /* Return CDAudio System Dependent Device Name - Ready for MCI*/ | 114 /* Return CDAudio System Dependent Device Name - Ready for MCI*/ |
111 static const char *SDL_SYS_CDName(int drive) | 115 static const char * |
112 { | 116 SDL_SYS_CDName(int drive) |
113 return(SDL_cdlist[drive]); | 117 { |
118 return (SDL_cdlist[drive]); | |
114 } | 119 } |
115 | 120 |
116 /* Open CDAudio Device - Ready for MCI */ | 121 /* Open CDAudio Device - Ready for MCI */ |
117 static int SDL_SYS_CDOpen(int drive) | 122 static int |
118 { | 123 SDL_SYS_CDOpen(int drive) |
119 MCI_OPEN_PARMS mop; | 124 { |
120 MCI_SET_PARMS msp; | 125 MCI_OPEN_PARMS mop; |
121 MCI_GENERIC_PARMS mgp; | 126 MCI_SET_PARMS msp; |
127 MCI_GENERIC_PARMS mgp; | |
122 | 128 |
123 /* Open the device */ | 129 /* Open the device */ |
124 mop.hwndCallback = (HWND)NULL; // None | 130 mop.hwndCallback = (HWND) NULL; // None |
125 mop.usDeviceID = (USHORT)NULL; // Will be returned. | 131 mop.usDeviceID = (USHORT) NULL; // Will be returned. |
126 mop.pszDeviceType = (PSZ)SDL_cdlist[drive]; // CDAudio Device | 132 mop.pszDeviceType = (PSZ) SDL_cdlist[drive]; // CDAudio Device |
127 if (LOUSHORT(mciSendCommand(0,MCI_OPEN,MCI_WAIT,&mop, 0)) != MCIERR_SUCCESS) return(CD_ERROR); | 133 if (LOUSHORT(mciSendCommand(0, MCI_OPEN, MCI_WAIT, &mop, 0)) != |
134 MCIERR_SUCCESS) | |
135 return (CD_ERROR); | |
128 /* Set time format */ | 136 /* Set time format */ |
129 msp.hwndCallback = (HWND)NULL; // None | 137 msp.hwndCallback = (HWND) NULL; // None |
130 msp.ulTimeFormat = MCI_FORMAT_MSF; // Minute : Second : Frame structure | 138 msp.ulTimeFormat = MCI_FORMAT_MSF; // Minute : Second : Frame structure |
131 msp.ulSpeedFormat = (ULONG)NULL; // No change | 139 msp.ulSpeedFormat = (ULONG) NULL; // No change |
132 msp.ulAudio = (ULONG)NULL; // No Channel | 140 msp.ulAudio = (ULONG) NULL; // No Channel |
133 msp.ulLevel = (ULONG)NULL; // No Volume | 141 msp.ulLevel = (ULONG) NULL; // No Volume |
134 msp.ulOver = (ULONG)NULL; // No Delay | 142 msp.ulOver = (ULONG) NULL; // No Delay |
135 msp.ulItem = (ULONG)NULL; // No item | 143 msp.ulItem = (ULONG) NULL; // No item |
136 msp.ulValue = (ULONG)NULL; // No value for item flag | 144 msp.ulValue = (ULONG) NULL; // No value for item flag |
137 if (LOUSHORT(mciSendCommand(mop.usDeviceID,MCI_SET,MCI_WAIT | MCI_SET_TIME_FORMAT,&msp, 0)) == MCIERR_SUCCESS) return (mop.usDeviceID); | 145 if (LOUSHORT |
146 (mciSendCommand | |
147 (mop.usDeviceID, MCI_SET, MCI_WAIT | MCI_SET_TIME_FORMAT, &msp, | |
148 0)) == MCIERR_SUCCESS) | |
149 return (mop.usDeviceID); | |
138 /* Error setting time format? - Close opened device */ | 150 /* Error setting time format? - Close opened device */ |
139 mgp.hwndCallback = (HWND)NULL; // None | 151 mgp.hwndCallback = (HWND) NULL; // None |
140 mciSendCommand(mop.usDeviceID,MCI_CLOSE,MCI_WAIT,&mgp, 0); | 152 mciSendCommand(mop.usDeviceID, MCI_CLOSE, MCI_WAIT, &mgp, 0); |
141 return(CD_ERROR); | 153 return (CD_ERROR); |
142 } | 154 } |
143 | 155 |
144 /* Get CD Table Of Contents - Ready for MCI */ | 156 /* Get CD Table Of Contents - Ready for MCI */ |
145 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | 157 static int |
146 { | 158 SDL_SYS_CDGetTOC(SDL_CD * cdrom) |
147 MCI_TOC_PARMS mtp; | 159 { |
148 MCI_STATUS_PARMS msp; | 160 MCI_TOC_PARMS mtp; |
149 MCI_TOC_REC * mtr; | 161 MCI_STATUS_PARMS msp; |
150 INT i; | 162 MCI_TOC_REC *mtr; |
163 INT i; | |
151 | 164 |
152 /* Correction because MCI cannot read TOC while CD is playing (it'll stop!) */ | 165 /* Correction because MCI cannot read TOC while CD is playing (it'll stop!) */ |
153 if (cdrom->status == CD_PLAYING || cdrom->status == CD_PAUSED) return 0; | 166 if (cdrom->status == CD_PLAYING || cdrom->status == CD_PAUSED) |
167 return 0; | |
154 | 168 |
155 /* Get Number of Tracks */ | 169 /* Get Number of Tracks */ |
156 msp.hwndCallback = (HWND)NULL; /* None */ | 170 msp.hwndCallback = (HWND) NULL; /* None */ |
157 msp.ulReturn = (ULONG)NULL; /* We want this information */ | 171 msp.ulReturn = (ULONG) NULL; /* We want this information */ |
158 msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS; | 172 msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS; |
159 msp.ulValue = (ULONG)NULL; /* No additional information */ | 173 msp.ulValue = (ULONG) NULL; /* No additional information */ |
160 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR); | 174 if (LOUSHORT |
161 cdrom->numtracks = msp.ulReturn; | 175 (mciSendCommand |
162 if ( cdrom->numtracks > SDL_MAX_TRACKS ) | 176 (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, |
163 { | 177 0)) != MCIERR_SUCCESS) |
164 cdrom->numtracks = SDL_MAX_TRACKS; | 178 return (CD_ERROR); |
165 } | 179 cdrom->numtracks = msp.ulReturn; |
180 if (cdrom->numtracks > SDL_MAX_TRACKS) { | |
181 cdrom->numtracks = SDL_MAX_TRACKS; | |
182 } | |
166 /* Alocate space for TOC data */ | 183 /* Alocate space for TOC data */ |
167 mtr = (MCI_TOC_REC *)SDL_malloc(cdrom->numtracks*sizeof(MCI_TOC_REC)); | 184 mtr = (MCI_TOC_REC *) SDL_malloc(cdrom->numtracks * sizeof(MCI_TOC_REC)); |
168 if ( mtr == NULL ) | 185 if (mtr == NULL) { |
169 { | 186 SDL_OutOfMemory(); |
170 SDL_OutOfMemory(); | 187 return (-1); |
171 return(-1); | 188 } |
172 } | |
173 /* Get TOC from CD */ | 189 /* Get TOC from CD */ |
174 mtp.pBuf = mtr; | 190 mtp.pBuf = mtr; |
175 mtp.ulBufSize = cdrom->numtracks*sizeof(MCI_TOC_REC); | 191 mtp.ulBufSize = cdrom->numtracks * sizeof(MCI_TOC_REC); |
176 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_GETTOC,MCI_WAIT,&mtp, 0)) != MCIERR_SUCCESS) | 192 if (LOUSHORT(mciSendCommand(cdrom->id, MCI_GETTOC, MCI_WAIT, &mtp, 0)) |
177 { | 193 != MCIERR_SUCCESS) { |
178 SDL_OutOfMemory(); | 194 SDL_OutOfMemory(); |
179 SDL_free(mtr); | 195 SDL_free(mtr); |
180 return(CD_ERROR); | 196 return (CD_ERROR); |
181 } | 197 } |
182 /* Fill SDL Tracks Structure */ | 198 /* Fill SDL Tracks Structure */ |
183 for (i=0; i<cdrom->numtracks; i++) | 199 for (i = 0; i < cdrom->numtracks; i++) { |
184 { | 200 /* Set Track ID */ |
185 /* Set Track ID */ | 201 cdrom->track[i].id = (mtr + i)->TrackNum; |
186 cdrom->track[i].id = (mtr+i)->TrackNum; | 202 /* Set Track Type */ |
187 /* Set Track Type */ | 203 msp.hwndCallback = (HWND) NULL; /* None */ |
188 msp.hwndCallback = (HWND)NULL; /* None */ | 204 msp.ulReturn = (ULONG) NULL; /* We want this information */ |
189 msp.ulReturn = (ULONG)NULL; /* We want this information */ | 205 msp.ulItem = MCI_CD_STATUS_TRACK_TYPE; |
190 msp.ulItem = MCI_CD_STATUS_TRACK_TYPE; | 206 msp.ulValue = (ULONG) ((mtr + i)->TrackNum); /* Track Number? */ |
191 msp.ulValue = (ULONG)((mtr+i)->TrackNum); /* Track Number? */ | 207 if (LOUSHORT |
192 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) | 208 (mciSendCommand |
193 { | 209 (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM, |
194 SDL_free(mtr); | 210 &msp, 0)) != MCIERR_SUCCESS) { |
195 return (CD_ERROR); | 211 SDL_free(mtr); |
196 } | 212 return (CD_ERROR); |
197 if (msp.ulReturn==MCI_CD_TRACK_AUDIO) cdrom->track[i].type = SDL_AUDIO_TRACK; | 213 } |
198 else cdrom->track[i].type = SDL_DATA_TRACK; | 214 if (msp.ulReturn == MCI_CD_TRACK_AUDIO) |
199 /* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */ | 215 cdrom->track[i].type = SDL_AUDIO_TRACK; |
200 cdrom->track[i].length = FRAMESFROMMM((mtr+i)->ulEndAddr - (mtr+i)->ulStartAddr); | 216 else |
201 /* Set Track Offset */ | 217 cdrom->track[i].type = SDL_DATA_TRACK; |
202 cdrom->track[i].offset = FRAMESFROMMM((mtr+i)->ulStartAddr); | 218 /* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */ |
203 } | 219 cdrom->track[i].length = |
204 SDL_free(mtr); | 220 FRAMESFROMMM((mtr + i)->ulEndAddr - (mtr + i)->ulStartAddr); |
205 return(0); | 221 /* Set Track Offset */ |
222 cdrom->track[i].offset = FRAMESFROMMM((mtr + i)->ulStartAddr); | |
223 } | |
224 SDL_free(mtr); | |
225 return (0); | |
206 } | 226 } |
207 | 227 |
208 | 228 |
209 /* Get CD-ROM status - Ready for MCI */ | 229 /* Get CD-ROM status - Ready for MCI */ |
210 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | 230 static CDstatus |
211 { | 231 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position) |
212 CDstatus status; | 232 { |
213 MCI_STATUS_PARMS msp; | 233 CDstatus status; |
234 MCI_STATUS_PARMS msp; | |
214 | 235 |
215 /* Get Status from MCI */ | 236 /* Get Status from MCI */ |
216 msp.hwndCallback = (HWND)NULL; /* None */ | 237 msp.hwndCallback = (HWND) NULL; /* None */ |
217 msp.ulReturn = (ULONG)NULL; /* We want this information */ | 238 msp.ulReturn = (ULONG) NULL; /* We want this information */ |
218 msp.ulItem = MCI_STATUS_MODE; | 239 msp.ulItem = MCI_STATUS_MODE; |
219 msp.ulValue = (ULONG)NULL; /* No additional information */ | 240 msp.ulValue = (ULONG) NULL; /* No additional information */ |
220 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) status = CD_ERROR; | 241 if (LOUSHORT |
221 else | 242 (mciSendCommand |
222 { | 243 (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, |
223 switch(msp.ulReturn) | 244 0)) != MCIERR_SUCCESS) |
224 { | 245 status = CD_ERROR; |
225 case MCI_MODE_NOT_READY: | 246 else { |
226 status = CD_TRAYEMPTY; | 247 switch (msp.ulReturn) { |
227 break; | 248 case MCI_MODE_NOT_READY: |
228 case MCI_MODE_PAUSE: | 249 status = CD_TRAYEMPTY; |
229 status = CD_PAUSED; | 250 break; |
230 break; | 251 case MCI_MODE_PAUSE: |
231 case MCI_MODE_PLAY: | 252 status = CD_PAUSED; |
232 status = CD_PLAYING; | 253 break; |
233 break; | 254 case MCI_MODE_PLAY: |
234 case MCI_MODE_STOP: | 255 status = CD_PLAYING; |
235 status = CD_STOPPED; | 256 break; |
236 break; | 257 case MCI_MODE_STOP: |
237 /* These cases should not occour */ | 258 status = CD_STOPPED; |
238 case MCI_MODE_RECORD: | 259 break; |
239 case MCI_MODE_SEEK: | 260 /* These cases should not occour */ |
240 default: | 261 case MCI_MODE_RECORD: |
241 status = CD_ERROR; | 262 case MCI_MODE_SEEK: |
242 break; | 263 default: |
243 } | 264 status = CD_ERROR; |
244 } | 265 break; |
266 } | |
267 } | |
245 | 268 |
246 /* Determine position */ | 269 /* Determine position */ |
247 if (position != NULL) /* The SDL $&$&%# CDROM call sends NULL pointer here! */ | 270 if (position != NULL) { /* The SDL $&$&%# CDROM call sends NULL pointer here! */ |
248 { | 271 if ((status == CD_PLAYING) || (status == CD_PAUSED)) { |
249 if ((status == CD_PLAYING) || (status == CD_PAUSED)) | 272 /* Get Position */ |
250 { | 273 msp.hwndCallback = (HWND) NULL; /* None */ |
251 /* Get Position */ | 274 msp.ulReturn = (ULONG) NULL; /* We want this information */ |
252 msp.hwndCallback = (HWND)NULL; /* None */ | 275 msp.ulItem = MCI_STATUS_POSITION; |
253 msp.ulReturn = (ULONG)NULL; /* We want this information */ | 276 msp.ulValue = (ULONG) NULL; /* No additiona info */ |
254 msp.ulItem = MCI_STATUS_POSITION; | 277 if (LOUSHORT |
255 msp.ulValue = (ULONG)NULL; /* No additiona info */ | 278 (mciSendCommand |
256 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return (CD_ERROR); | 279 (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, |
257 /* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */ | 280 0)) != MCIERR_SUCCESS) |
258 *position = MSF_TO_FRAMES(MSF_MINUTE(msp.ulReturn),MSF_SECOND(msp.ulReturn),MSF_FRAME(msp.ulReturn)); | 281 return (CD_ERROR); |
259 } | 282 /* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */ |
260 else *position = 0; | 283 *position = |
261 } | 284 MSF_TO_FRAMES(MSF_MINUTE(msp.ulReturn), |
262 return(status); | 285 MSF_SECOND(msp.ulReturn), |
286 MSF_FRAME(msp.ulReturn)); | |
287 } else | |
288 *position = 0; | |
289 } | |
290 return (status); | |
263 } | 291 } |
264 | 292 |
265 /* Start play - Ready for MCI */ | 293 /* Start play - Ready for MCI */ |
266 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | 294 static int |
267 { | 295 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length) |
268 MCI_GENERIC_PARMS mgp; | 296 { |
269 MCI_STATUS_PARMS msp; | 297 MCI_GENERIC_PARMS mgp; |
270 MCI_PLAY_PARMS mpp; | 298 MCI_STATUS_PARMS msp; |
271 ULONG min,sec,frm; | 299 MCI_PLAY_PARMS mpp; |
300 ULONG min, sec, frm; | |
272 | 301 |
273 /* Start MSF */ | 302 /* Start MSF */ |
274 FRAMES_TO_MSF(start, &min, &sec, &frm); | 303 FRAMES_TO_MSF(start, &min, &sec, &frm); |
275 MSF_MINUTE(mpp.ulFrom) = min; | 304 MSF_MINUTE(mpp.ulFrom) = min; |
276 MSF_SECOND(mpp.ulFrom) = sec; | 305 MSF_SECOND(mpp.ulFrom) = sec; |
277 MSF_FRAME(mpp.ulFrom) = frm; | 306 MSF_FRAME(mpp.ulFrom) = frm; |
278 /* End MSF */ | 307 /* End MSF */ |
279 FRAMES_TO_MSF(start+length, &min, &sec, &frm); | 308 FRAMES_TO_MSF(start + length, &min, &sec, &frm); |
280 MSF_MINUTE(mpp.ulTo) = min; | 309 MSF_MINUTE(mpp.ulTo) = min; |
281 MSF_SECOND(mpp.ulTo) = sec; | 310 MSF_SECOND(mpp.ulTo) = sec; |
282 MSF_FRAME(mpp.ulTo) = frm; | 311 MSF_FRAME(mpp.ulTo) = frm; |
283 #ifdef DEBUG_CDROM | 312 #ifdef DEBUG_CDROM |
284 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", | 313 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", |
285 playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, | 314 playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, |
286 playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); | 315 playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); |
287 #endif | 316 #endif |
288 /* Verifies if it is paused first... and if it is, unpause before stopping it. */ | 317 /* Verifies if it is paused first... and if it is, unpause before stopping it. */ |
289 msp.hwndCallback = (HWND)NULL; /* None */ | 318 msp.hwndCallback = (HWND) NULL; /* None */ |
290 msp.ulReturn = (ULONG)NULL; /* We want this information */ | 319 msp.ulReturn = (ULONG) NULL; /* We want this information */ |
291 msp.ulItem = MCI_STATUS_MODE; | 320 msp.ulItem = MCI_STATUS_MODE; |
292 msp.ulValue = (ULONG)NULL; /* No additional information */ | 321 msp.ulValue = (ULONG) NULL; /* No additional information */ |
293 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS) | 322 if (LOUSHORT |
294 { | 323 (mciSendCommand |
295 if (msp.ulReturn == MCI_MODE_PAUSE) | 324 (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, |
296 { | 325 0)) == MCIERR_SUCCESS) { |
297 mgp.hwndCallback = (HWND)NULL; // None | 326 if (msp.ulReturn == MCI_MODE_PAUSE) { |
298 mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0); | 327 mgp.hwndCallback = (HWND) NULL; // None |
299 } | 328 mciSendCommand(cdrom->id, MCI_RESUME, 0, &mgp, 0); |
300 } | 329 } |
330 } | |
301 /* Now play it. */ | 331 /* Now play it. */ |
302 mpp.hwndCallback = (HWND)NULL; // We do not want the info. temp | 332 mpp.hwndCallback = (HWND) NULL; // We do not want the info. temp |
303 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PLAY,MCI_FROM | MCI_TO,&mpp, 0)) == MCIERR_SUCCESS) return 0; | 333 if (LOUSHORT |
304 return (CD_ERROR); | 334 (mciSendCommand(cdrom->id, MCI_PLAY, MCI_FROM | MCI_TO, &mpp, 0)) == |
335 MCIERR_SUCCESS) | |
336 return 0; | |
337 return (CD_ERROR); | |
305 } | 338 } |
306 | 339 |
307 /* Pause play - Ready for MCI */ | 340 /* Pause play - Ready for MCI */ |
308 static int SDL_SYS_CDPause(SDL_CD *cdrom) | 341 static int |
309 { | 342 SDL_SYS_CDPause(SDL_CD * cdrom) |
310 MCI_GENERIC_PARMS mgp; | 343 { |
311 | 344 MCI_GENERIC_PARMS mgp; |
312 mgp.hwndCallback = (HWND)NULL; // None | 345 |
313 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PAUSE,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0; | 346 mgp.hwndCallback = (HWND) NULL; // None |
314 return(CD_ERROR); | 347 if (LOUSHORT(mciSendCommand(cdrom->id, MCI_PAUSE, MCI_WAIT, &mgp, 0)) == |
348 MCIERR_SUCCESS) | |
349 return 0; | |
350 return (CD_ERROR); | |
315 } | 351 } |
316 | 352 |
317 /* Resume play - Ready for MCI */ | 353 /* Resume play - Ready for MCI */ |
318 static int SDL_SYS_CDResume(SDL_CD *cdrom) | 354 static int |
319 { | 355 SDL_SYS_CDResume(SDL_CD * cdrom) |
320 MCI_GENERIC_PARMS mgp; | 356 { |
321 | 357 MCI_GENERIC_PARMS mgp; |
322 mgp.hwndCallback = (HWND)NULL; // None | 358 |
323 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_RESUME,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0; | 359 mgp.hwndCallback = (HWND) NULL; // None |
324 return(CD_ERROR); | 360 if (LOUSHORT(mciSendCommand(cdrom->id, MCI_RESUME, MCI_WAIT, &mgp, 0)) |
361 == MCIERR_SUCCESS) | |
362 return 0; | |
363 return (CD_ERROR); | |
325 } | 364 } |
326 | 365 |
327 /* Stop play - Ready for MCI */ | 366 /* Stop play - Ready for MCI */ |
328 static int SDL_SYS_CDStop(SDL_CD *cdrom) | 367 static int |
329 { | 368 SDL_SYS_CDStop(SDL_CD * cdrom) |
330 MCI_GENERIC_PARMS mgp; | 369 { |
331 MCI_STATUS_PARMS msp; | 370 MCI_GENERIC_PARMS mgp; |
371 MCI_STATUS_PARMS msp; | |
332 | 372 |
333 /* Verifies if it is paused first... and if it is, unpause before stopping it. */ | 373 /* Verifies if it is paused first... and if it is, unpause before stopping it. */ |
334 msp.hwndCallback = (HWND)NULL; /* None */ | 374 msp.hwndCallback = (HWND) NULL; /* None */ |
335 msp.ulReturn = (ULONG)NULL; /* We want this information */ | 375 msp.ulReturn = (ULONG) NULL; /* We want this information */ |
336 msp.ulItem = MCI_STATUS_MODE; | 376 msp.ulItem = MCI_STATUS_MODE; |
337 msp.ulValue = (ULONG)NULL; /* No additional information */ | 377 msp.ulValue = (ULONG) NULL; /* No additional information */ |
338 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS) | 378 if (LOUSHORT |
339 { | 379 (mciSendCommand |
340 if (msp.ulReturn == MCI_MODE_PAUSE) | 380 (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, |
341 { | 381 0)) == MCIERR_SUCCESS) { |
342 mgp.hwndCallback = (HWND)NULL; // None | 382 if (msp.ulReturn == MCI_MODE_PAUSE) { |
343 mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0); | 383 mgp.hwndCallback = (HWND) NULL; // None |
344 } | 384 mciSendCommand(cdrom->id, MCI_RESUME, 0, &mgp, 0); |
345 } | 385 } |
386 } | |
346 /* Now stops the media */ | 387 /* Now stops the media */ |
347 mgp.hwndCallback = (HWND)NULL; // None | 388 mgp.hwndCallback = (HWND) NULL; // None |
348 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STOP,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0; | 389 if (LOUSHORT(mciSendCommand(cdrom->id, MCI_STOP, MCI_WAIT, &mgp, 0)) == |
349 return(CD_ERROR); | 390 MCIERR_SUCCESS) |
391 return 0; | |
392 return (CD_ERROR); | |
350 } | 393 } |
351 | 394 |
352 /* Eject the CD-ROM - Ready for MCI */ | 395 /* Eject the CD-ROM - Ready for MCI */ |
353 static int SDL_SYS_CDEject(SDL_CD *cdrom) | 396 static int |
354 { | 397 SDL_SYS_CDEject(SDL_CD * cdrom) |
355 MCI_SET_PARMS msp; | 398 { |
356 | 399 MCI_SET_PARMS msp; |
357 msp.hwndCallback = (HWND)NULL; // None | 400 |
358 msp.ulTimeFormat = (ULONG)NULL; // No change | 401 msp.hwndCallback = (HWND) NULL; // None |
359 msp.ulSpeedFormat = (ULONG)NULL; // No change | 402 msp.ulTimeFormat = (ULONG) NULL; // No change |
360 msp.ulAudio = (ULONG)NULL; // No Channel | 403 msp.ulSpeedFormat = (ULONG) NULL; // No change |
361 msp.ulLevel = (ULONG)NULL; // No Volume | 404 msp.ulAudio = (ULONG) NULL; // No Channel |
362 msp.ulOver = (ULONG)NULL; // No Delay | 405 msp.ulLevel = (ULONG) NULL; // No Volume |
363 msp.ulItem = (ULONG)NULL; // No item | 406 msp.ulOver = (ULONG) NULL; // No Delay |
364 msp.ulValue = (ULONG)NULL; // No value for item flag | 407 msp.ulItem = (ULONG) NULL; // No item |
365 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_SET,MCI_WAIT | MCI_SET_DOOR_OPEN,&msp, 0)) == MCIERR_SUCCESS) return 0; | 408 msp.ulValue = (ULONG) NULL; // No value for item flag |
366 return(CD_ERROR); | 409 if (LOUSHORT |
410 (mciSendCommand | |
411 (cdrom->id, MCI_SET, MCI_WAIT | MCI_SET_DOOR_OPEN, &msp, | |
412 0)) == MCIERR_SUCCESS) | |
413 return 0; | |
414 return (CD_ERROR); | |
367 } | 415 } |
368 | 416 |
369 /* Close the CD-ROM handle - Ready for MCI */ | 417 /* Close the CD-ROM handle - Ready for MCI */ |
370 static void SDL_SYS_CDClose(SDL_CD *cdrom) | 418 static void |
371 { | 419 SDL_SYS_CDClose(SDL_CD * cdrom) |
372 MCI_GENERIC_PARMS mgp; | 420 { |
373 | 421 MCI_GENERIC_PARMS mgp; |
374 mgp.hwndCallback = (HWND)NULL; // None | 422 |
375 mciSendCommand(cdrom->id,MCI_CLOSE,MCI_WAIT,&mgp, 0); | 423 mgp.hwndCallback = (HWND) NULL; // None |
424 mciSendCommand(cdrom->id, MCI_CLOSE, MCI_WAIT, &mgp, 0); | |
376 } | 425 } |
377 | 426 |
378 /* Finalize CDROM Subsystem - Ready for MCI */ | 427 /* Finalize CDROM Subsystem - Ready for MCI */ |
379 void SDL_SYS_CDQuit(void) | 428 void |
380 { | 429 SDL_SYS_CDQuit(void) |
381 int i; | 430 { |
382 | 431 int i; |
383 if ( SDL_numcds > 0 ) | 432 |
384 { | 433 if (SDL_numcds > 0) { |
385 for ( i=0; i<SDL_numcds; ++i ) | 434 for (i = 0; i < SDL_numcds; ++i) { |
386 { | 435 SDL_free(SDL_cdlist[i]); |
387 SDL_free(SDL_cdlist[i]); | 436 } |
388 } | 437 SDL_numcds = 0; |
389 SDL_numcds = 0; | 438 } |
390 } | |
391 } | 439 } |
392 | 440 |
393 #endif /* SDL_CDROM_OS2 */ | 441 #endif /* SDL_CDROM_OS2 */ |
442 /* vi: set ts=4 sw=4 expandtab: */ |