Changeset 4709 for trunk/src/winmm/mcicda/cdrom.cpp
- Timestamp:
- Dec 2, 2000, 12:37:34 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/winmm/mcicda/cdrom.cpp
r2473 r4709 1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */ 2 /* 3 * MCI CDAUDIO Driver for OS/2. Interface to OS/2 DosIOCtrl() 4 * 5 * Copyright 2000 Chris Wohlgemuth 6 * 7 * Project Odin Software License can be found in LICENSE.TXT 8 * 9 */ 10 11 1 12 #include <os2win.h> 2 13 #include "cdrom.h" 14 #include <debugtools.h> 15 #include <string.h> 16 17 /* 18 * FIXME: Should use the right errorcodes for SetLastError if a function fails. 19 */ 3 20 4 21 int CDAUDIO_Open(WINE_CDAUDIO* wcda) 5 22 { 6 dprintf(("MCICDA-CDROM: CDAUDIO_Open not implemented.\n")); 7 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 8 return FALSE; 9 } 10 11 int CDAUDIO_Close(WINE_CDAUDIO* wcda) 12 { 13 dprintf(("MCICDA-CDROM: CDAUDIO_Close not implemented.\n")); 14 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 15 return FALSE; 23 ULONG yyrc; 24 USHORT sel; 25 HFILE hFile; 26 int iNumCD; 27 char chrFirstCD[3]={0}; 28 int i; 29 30 dprintf(("MCICDA-CDROM: Trying to open drive %s...\n",wcda->chrDrive)); 31 32 if(strlen(wcda->chrDrive)==2) { 33 if((wcda->hfOS2Handle=os2CDOpen(wcda->chrDrive))==NULL) { 34 SetLastError(ERROR_WRONG_DISK); 35 /* We always return TRUE because we want to open the driver not the disk */ 36 } 37 return TRUE; 38 } 39 40 if(!strcmpi(wcda->chrDeviceType,"cdaudio")) { 41 /* We try any CDROM in the system until one can be opened */ 42 if(!os2CDQueryCDDrives(&iNumCD, chrFirstCD)) { 43 SetLastError(ERROR_WRONG_DISK); 44 return FALSE;/* Can't get drives in system */ 45 } 46 47 chrFirstCD[1]=':'; 48 for(i=0;i<iNumCD;i++) { 49 chrFirstCD[0]++; 50 if((wcda->hfOS2Handle=os2CDOpen(chrFirstCD))!=NULL) { 51 return TRUE; 52 } 53 } 54 SetLastError(ERROR_WRONG_DISK); 55 /* We always return TRUE because we want to open the driver not the disk */ 56 /* Can't open CD */ 57 } 58 /* We always return TRUE because we want to open the driver not the disk */ 59 return TRUE; 60 } 61 62 int CDAUDIO_Close(WINE_CDAUDIO* wcda) 63 { 64 ULONG rc; 65 66 dprintf(("MCICDA-CDROM: CDAUDIO_Close: Closing drive: %s...\n",wcda->chrDrive)); 67 68 if(wcda->hfOS2Handle==NULL) { 69 SetLastError(ERROR_INVALID_PARAMETER); 70 return FALSE; 71 } 72 73 if((rc=os2CDClose(wcda->hfOS2Handle))!=0) { 74 dprintf(("MCICDA-CDROM: CDAUDIO_Close:rc=%d \n",rc)); 75 SetLastError(ERROR_INVALID_PARAMETER); 76 return FALSE; 77 } 78 wcda->hfOS2Handle=NULL; 79 dprintf(("MCICDA-CDROM: CDAUDIO_Close: Drive %s closed\n",wcda->chrDrive)); 80 return TRUE; 16 81 } 17 82 … … 25 90 int CDAUDIO_Play(WINE_CDAUDIO* wcda, DWORD start, DWORD stop) 26 91 { 27 dprintf(("MCICDA-CDROM: CDAUDIO_Play not implemented.\n")); 28 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 29 return FALSE; 92 ULONG rc; 93 94 /* FIXME: error handling is missing */ 95 //SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 96 if(!wcda->hfOS2Handle) { 97 CDAUDIO_Open(wcda);/* Get new handle */ 98 if(!wcda->hfOS2Handle) { 99 WARN("hfOS2Handle isn't valid and can't get new one\n"); 100 SetLastError(ERROR_INVALID_PARAMETER); 101 return 1; 102 } 103 } 104 105 CDAUDIO_GetCDStatus(wcda); 106 if(wcda->cdaMode==WINE_CDA_PLAY||wcda->cdaMode==WINE_CDA_PAUSE) 107 CDAUDIO_Stop(wcda); 108 rc=os2CDPlayRange(wcda->hfOS2Handle , start, stop); 109 return 0; 30 110 } 31 111 32 112 int CDAUDIO_Stop(WINE_CDAUDIO* wcda) 33 113 { 34 dprintf(("MCICDA-CDROM: CDAUDIO_Stop not implemented.\n")); 35 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 36 return FALSE; 114 // SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 115 /* FIXME: error handling is missing */ 116 if(!wcda->hfOS2Handle) { 117 CDAUDIO_Open(wcda);/* Get new handle */ 118 if(!wcda->hfOS2Handle) { 119 WARN("hfOS2Handle isn't valid and can't get new one\n"); 120 SetLastError(ERROR_INVALID_PARAMETER); 121 return 1; 122 } 123 } 124 125 os2CDStop(wcda->hfOS2Handle); 126 return 0; 37 127 } 38 128 39 129 int CDAUDIO_Pause(WINE_CDAUDIO* wcda, int pauseOn) 40 130 { 41 dprintf(("MCICDA-CDROM: CDAUDIO_Pause not implemented.\n")); 42 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 43 return FALSE; 131 132 //SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 133 /* FIXME: error handling is missing */ 134 if(!wcda->hfOS2Handle) { 135 CDAUDIO_Open(wcda);/* Get new handle */ 136 if(!wcda->hfOS2Handle) { 137 WARN("hfOS2Handle isn't valid and can't get new one\n"); 138 SetLastError(ERROR_INVALID_PARAMETER); 139 return 1; 140 } 141 } 142 143 if(pauseOn) 144 os2CDStop(wcda->hfOS2Handle); 145 else 146 os2CDResume(wcda->hfOS2Handle); 147 return 0; 44 148 } 45 149 46 150 int CDAUDIO_Seek(WINE_CDAUDIO* wcda, DWORD at) 47 151 { 48 dprintf(("MCICDA-CDROM: CDAUDIO_Seek not implemented.\n")); 49 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 50 return FALSE; 152 /* FIXME: error handling is missing */ 153 //SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 154 if(!wcda->hfOS2Handle) { 155 CDAUDIO_Open(wcda);/* Get new handle */ 156 if(!wcda->hfOS2Handle) { 157 WARN("hfOS2Handle isn't valid and can't get new one\n"); 158 SetLastError(ERROR_INVALID_PARAMETER); 159 return 1; 160 } 161 } 162 163 os2CDSeek(wcda->hfOS2Handle, at); 164 return 0; 51 165 } 52 166 53 167 int CDAUDIO_SetDoor(WINE_CDAUDIO* wcda, int open) 54 168 { 55 dprintf(("MCICDA-CDROM: CDAUDIO_SetDoor not implemented.\n")); 56 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 57 return FALSE; 58 } 59 60 UINT16 CDAUDIO_GetNumberOfTracks(WINE_CDAUDIO* wcda) 61 { 62 dprintf(("MCICDA-CDROM: CDAUDIO_GetNumberOfTracks not implemented.\n")); 63 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 64 return FALSE; 169 170 /* FIXME: error handling is missing */ 171 if(!wcda->hfOS2Handle) { 172 CDAUDIO_Open(wcda);/* Get new handle */ 173 if(!wcda->hfOS2Handle) { 174 WARN("hfOS2Handle isn't valid and can't get new one\n"); 175 SetLastError(ERROR_INVALID_PARAMETER); 176 return 1; 177 } 178 } 179 180 CDAUDIO_Stop(wcda); 181 if(open) { 182 os2CDEject(wcda->hfOS2Handle); 183 } 184 else 185 BOOL os2CDCloseTray(HFILE hfDrive); 186 187 return 0; 188 } 189 190 191 /******************************************/ 192 /* Result: 193 0: Error 194 -1: CD is Data Disk 195 other: # Audio tracks */ 196 /******************************************/ 197 int CDAUDIO_GetNumberOfTracks(WINE_CDAUDIO* wcda) 198 { 199 int rcOS2; 200 201 if(!wcda->hfOS2Handle) { 202 CDAUDIO_Open(wcda);/* Get new handle */ 203 if(!wcda->hfOS2Handle) { 204 WARN("hfOS2Handle isn't valid and can't get new one\n"); 205 SetLastError(ERROR_INVALID_PARAMETER); 206 return 0; 207 } 208 } 209 210 rcOS2=os2GetNumTracks(wcda->hfOS2Handle,&wcda->ulLeadOut); 211 switch(rcOS2) 212 { 213 case -1: 214 SetLastError(ERROR_INVALID_PARAMETER); 215 return -1; 216 case 0: 217 SetLastError(ERROR_WRONG_DISK); 218 return -1; 219 default: 220 break; 221 } 222 223 wcda->nTracks=rcOS2; 224 wcda->nFirstTrack=1; 225 wcda->nLastTrack=rcOS2; 226 return rcOS2; 65 227 } 66 228 67 229 BOOL CDAUDIO_GetTracksInfo(WINE_CDAUDIO* wcda) 68 230 { 69 dprintf(("MCICDA-CDROM: CDAUDIO_GetTracksInfo not implemented.\n")); 70 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 71 return FALSE; 72 } 231 232 int i, length; 233 ULONG start, last_start = 0; 234 int total_length = 0; 235 236 if(!wcda->hfOS2Handle) { 237 CDAUDIO_Open(wcda);/* Get new handle */ 238 if(!wcda->hfOS2Handle) { 239 WARN("hfOS2Handle isn't valid and can't get new one\n"); 240 SetLastError(ERROR_INVALID_PARAMETER); 241 return FALSE; 242 } 243 } 244 245 if (wcda->nTracks == 0) { 246 if (CDAUDIO_GetNumberOfTracks(wcda) <= 0) 247 return FALSE; 248 } 249 250 TRACE("nTracks=%u\n", wcda->nTracks); 251 252 SetLastError(ERROR_INVALID_PARAMETER); 253 254 if (wcda->lpdwTrackLen != NULL) 255 free(wcda->lpdwTrackLen); 256 wcda->lpdwTrackLen = (LPDWORD)malloc((wcda->nTracks + 1) * sizeof(DWORD)); 257 if (wcda->lpdwTrackPos != NULL) 258 free(wcda->lpdwTrackPos); 259 wcda->lpdwTrackPos = (LPDWORD)malloc((wcda->nTracks + 1) * sizeof(DWORD)); 260 if (wcda->lpbTrackFlags != NULL) 261 free(wcda->lpbTrackFlags); 262 wcda->lpbTrackFlags = (LPBYTE)malloc((wcda->nTracks + 1) * sizeof(BYTE)); 263 264 if (wcda->lpdwTrackLen == NULL || wcda->lpdwTrackPos == NULL || 265 wcda->lpbTrackFlags == NULL) { 266 WARN("error allocating track table !\n"); 267 /* Freeing the already allocated mem */ 268 if (wcda->lpdwTrackLen != NULL) 269 free(wcda->lpdwTrackLen); 270 if (wcda->lpdwTrackPos != NULL) 271 free(wcda->lpdwTrackPos); 272 if (wcda->lpbTrackFlags != NULL) 273 free(wcda->lpbTrackFlags); 274 wcda->lpbTrackFlags=NULL; 275 wcda->lpdwTrackPos=NULL; 276 wcda->lpdwTrackLen= NULL; 277 return FALSE; 278 } 279 memset(wcda->lpdwTrackLen, 0, (wcda->nTracks + 1) * sizeof(DWORD)); 280 memset(wcda->lpdwTrackPos, 0, (wcda->nTracks + 1) * sizeof(DWORD)); 281 memset(wcda->lpbTrackFlags, 0, (wcda->nTracks + 1) * sizeof(BYTE)); 282 283 for (i = 0; i <= wcda->nTracks; i++) { 284 if((start=os2CDQueryTrackStartSector(wcda->hfOS2Handle,i))==0) 285 { 286 WARN("error reading start sector for track %d\n", i+1); 287 /* Freeing the already allocated mem */ 288 if (wcda->lpdwTrackLen != NULL) 289 free(wcda->lpdwTrackLen); 290 if (wcda->lpdwTrackPos != NULL) 291 free(wcda->lpdwTrackPos); 292 if (wcda->lpbTrackFlags != NULL) 293 free(wcda->lpbTrackFlags); 294 wcda->lpbTrackFlags=NULL; 295 wcda->lpdwTrackPos=NULL; 296 wcda->lpdwTrackLen= NULL; 297 return FALSE; 298 } 299 start-=150; 300 301 if (i == 0) { 302 last_start = start; 303 wcda->dwFirstFrame = start; 304 TRACE("dwFirstOffset=%u\n", start); 305 } else { 306 length = start - last_start; 307 last_start = start; 308 start = last_start - length; 309 total_length += length; 310 wcda->lpdwTrackLen[i - 1] = length; 311 wcda->lpdwTrackPos[i - 1] = start; 312 TRACE("track #%u start=%u len=%u\n", i, start, length); 313 } 314 //if(wcda->ulCDROMStatus & ) 315 wcda->lpbTrackFlags[i] = 0; 316 //TRACE("track #%u flags=%02x\n", i + 1, wcda->lpbTrackFlags[i]); 317 }/* for */ 318 319 wcda->dwLastFrame = last_start; 320 TRACE("total_len=%u Leaving CDAUDIO_GetTracksInfo...\n", total_length); 321 322 return TRUE; 323 324 dprintf(("MCICDA-CDROM: CDAUDIO_GetTracksInfo not implemented.\n")); 325 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 326 return FALSE; 327 } 328 73 329 74 330 BOOL CDAUDIO_GetCDStatus(WINE_CDAUDIO* wcda) 75 331 { 76 dprintf(("MCICDA-CDROM: CDAUDIO_GetCDStatus not implemented.\n")); 77 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 78 return FALSE; 79 } 80 81 332 ULONG ulRet; 333 int oldmode = wcda->cdaMode; 334 335 if(!wcda->hfOS2Handle) { 336 CDAUDIO_Open(wcda);/* Get new handle */ 337 if(!wcda->hfOS2Handle) { 338 WARN("hfOS2Handle isn't valid and can't get new one\n"); 339 SetLastError(ERROR_INVALID_PARAMETER); 340 return FALSE; 341 } 342 } 343 344 if(!os2GetCDStatus(wcda->hfOS2Handle, &wcda->ulCDROMStatus)) { 345 WARN("os2GetCDStatus(wcda->hfOS2Handle, &wcda->ulCDROMStatus) returned FALSE\n"); 346 return FALSE; 347 } 348 /* Current mode */ 349 //wcda->cdaMode=WINE_CDA_STOP; 350 if(wcda->ulCDROMStatus & 0x1L) 351 wcda->cdaMode=WINE_CDA_OPEN; /* Door open */ 352 else if(wcda->ulCDROMStatus & 0x1000L) 353 wcda->cdaMode=WINE_CDA_PLAY; /* Playing */ 354 else if(wcda->ulCDROMStatus & 0x800L) 355 wcda->cdaMode=WINE_CDA_NOTREADY; 356 else 357 wcda->cdaMode=WINE_CDA_STOP; 358 359 if(wcda->cdaMode==WINE_CDA_OPEN && wcda->hfOS2Handle) { 360 CDAUDIO_Close(wcda); 361 return FALSE; 362 } 363 364 if(!os2GetCDAudioStatus(wcda->hfOS2Handle, &wcda->usCDAudioStatus)) { 365 WARN("os2GetCDAudioStatus(wcda->hfOS2Handle, &wcda->usCDAudioStatus) returned FALSE rc=%x %d\n",wcda->usCDAudioStatus,wcda->usCDAudioStatus); 366 return FALSE; 367 368 } 369 else { 370 if(wcda->usCDAudioStatus & 1) 371 wcda->cdaMode=WINE_CDA_PAUSE; 372 os2CDGetHeadLocation(wcda->hfOS2Handle,&wcda->dwCurFrame); 373 os2CDQueryCurTrack(wcda->hfOS2Handle, &wcda->nCurTrack); 374 } 375 376 if (oldmode != wcda->cdaMode && oldmode == WINE_CDA_OPEN) { 377 TRACE("Updating TracksInfo !\n"); 378 if (!CDAUDIO_GetTracksInfo(wcda)) { 379 WARN("error updating TracksInfo !\n"); 380 return FALSE; 381 } 382 } 383 384 dprintf(("MCICDA-CDROM: Leaving CDAUDIO_GetCDStatus... cdaMode: %x\n",wcda->cdaMode)); 385 if (wcda->cdaMode != WINE_CDA_OPEN) 386 return TRUE; 387 else 388 return FALSE; 389 } 390 391 392 393 394 395 396 397 398 399 400
Note:
See TracChangeset
for help on using the changeset viewer.