Use $(AS) instead of $(CC) to compile .s files.
[wine] / multimedia / mcicda.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3  * Sample MCI CDAUDIO Wine Driver for Linux
4  *
5  * Copyright 1994 Martin Ayotte
6  */
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "windows.h"
14 #include "user.h"
15 #include "driver.h"
16 #include "mmsystem.h"
17 #include "debug.h"
18
19 #ifdef HAVE_LINUX_CDROM_H
20 # include <linux/cdrom.h>
21 #endif
22 #ifdef HAVE_MACHINE_SOUNDCARD_H
23 # include <machine/soundcard.h>
24 #endif
25 #ifdef HAVE_SYS_CDIO_H
26 # include <sys/cdio.h>
27 #endif
28
29 #ifdef __FreeBSD__
30 # define CDAUDIO_DEV "/dev/rcd0c"
31 #else
32 # define CDAUDIO_DEV "/dev/cdrom"
33 #endif
34
35 #ifdef SOUND_VERSION
36 # define IOCTL(a,b,c)           ioctl(a,b,&c)
37 #else
38 # define IOCTL(a,b,c)           (c = ioctl(a,b,c) )
39 #endif
40
41 #define MAX_CDAUDIODRV          (1)
42 #define MAX_CDAUDIO_TRACKS      256
43
44 #define CDFRAMES_PERSEC         75
45 #define CDFRAMES_PERMIN         4500
46 #define SECONDS_PERMIN          60
47
48 #if defined(linux) || defined(__FreeBSD__)
49 typedef struct {
50     int                 nUseCount;          /* Incremented for each shared open */
51     BOOL16              fShareable;         /* TRUE if first open was shareable */
52     WORD                wNotifyDeviceID;    /* MCI device ID with a pending notification */
53     HANDLE16            hCallback;          /* Callback handle for pending notification */
54     MCI_OPEN_PARMS16    openParms;
55     DWORD               dwTimeFormat;
56     int                 unixdev;
57 #ifdef linux
58     struct cdrom_subchnl        sc;
59 #elif __FreeBSD__
60     struct cd_sub_channel_info  sc;
61 #endif
62     int                 mode;
63     UINT16              nCurTrack;
64     DWORD               dwCurFrame;
65     UINT16              nTracks;
66     DWORD               dwTotalLen;
67     LPDWORD             lpdwTrackLen;
68     LPDWORD             lpdwTrackPos;
69     DWORD               dwFirstOffset;
70 } WINE_CDAUDIO;
71
72 static WINE_CDAUDIO     CDADev[MAX_CDAUDIODRV];
73 #endif
74
75 /*-----------------------------------------------------------------------*/
76
77
78 /**************************************************************************
79  *                              CDAUDIO_GetNumberOfTracks               [internal]
80  */
81 static UINT16 CDAUDIO_GetNumberOfTracks(UINT16 wDevID)
82 {
83 #if defined(linux) || defined(__FreeBSD__)
84 #ifdef linux
85     struct cdrom_tochdr hdr;
86 #elif __FreeBSD__
87     struct ioc_toc_header       hdr;
88 #endif
89     
90     if (CDADev[wDevID].nTracks == 0) {
91         if (ioctl(CDADev[wDevID].unixdev,
92 #ifdef linux
93                   CDROMREADTOCHDR
94 #elif __FreeBSD__
95                   CDIOREADTOCHEADER
96 #endif
97                   , &hdr)) {
98             WARN(cdaudio, "(%04X) -- Error occured !\n", 
99                  wDevID);
100             return (WORD)-1;
101         }
102 #ifdef linux
103         CDADev[wDevID].nTracks = hdr.cdth_trk1;
104 #elif __FreeBSD__
105         CDADev[wDevID].nTracks = hdr.ending_track - hdr.starting_track + 1;
106 #endif
107     }
108     return CDADev[wDevID].nTracks;
109 #else
110     return (WORD)-1;
111 #endif
112 }
113
114
115 /**************************************************************************
116  *                              CDAUDIO_GetTracksInfo                   [internal]
117  */
118 static BOOL32 CDAUDIO_GetTracksInfo(UINT16 wDevID)
119 {
120 #if defined(linux) || defined(__FreeBSD__)
121     int         i, length;
122     int         start, last_start = 0;
123     int         total_length = 0;
124 #ifdef linux
125     struct cdrom_tocentry       entry;
126 #elif __FreeBSD__
127     struct ioc_read_toc_entry   entry;
128     struct cd_toc_entry             toc_buffer;
129 #endif
130     
131     if (CDADev[wDevID].nTracks == 0) {
132         if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE;
133     }
134     TRACE(cdaudio,"nTracks=%u\n", 
135           CDADev[wDevID].nTracks);
136     if (CDADev[wDevID].lpdwTrackLen != NULL) 
137         free(CDADev[wDevID].lpdwTrackLen);
138     CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc(
139                                                   (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
140     if (CDADev[wDevID].lpdwTrackPos != NULL) 
141         free(CDADev[wDevID].lpdwTrackPos);
142     CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc(
143                                                   (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
144     if (CDADev[wDevID].lpdwTrackLen == NULL ||
145         CDADev[wDevID].lpdwTrackPos == NULL) {
146         WARN(cdaudio, "error allocating track table !\n");
147         return FALSE;
148     }
149     memset(CDADev[wDevID].lpdwTrackLen, 0, 
150            (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
151     memset(CDADev[wDevID].lpdwTrackPos, 0, 
152            (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
153     for (i = 0; i <= CDADev[wDevID].nTracks; i++) {
154         if (i == CDADev[wDevID].nTracks)
155 #ifdef linux
156             entry.cdte_track = CDROM_LEADOUT;
157 #elif __FreeBSD__
158 #define LEADOUT 0xaa
159         entry.starting_track = LEADOUT; /* XXX */
160 #endif
161         else
162 #ifdef linux
163             entry.cdte_track = i + 1;
164 #elif __FreeBSD__
165         entry.starting_track = i + 1;
166 #endif
167 #ifdef linux
168         entry.cdte_format = CDROM_MSF;
169 #elif __FreeBSD__
170         bzero((char *)&toc_buffer, sizeof(toc_buffer));
171         entry.address_format = CD_MSF_FORMAT;
172         entry.data_len = sizeof(toc_buffer);
173         entry.data = &toc_buffer;
174 #endif
175         if (ioctl(CDADev[wDevID].unixdev, 
176 #ifdef linux
177                   CDROMREADTOCENTRY
178 #elif __FreeBSD__
179                   CDIOREADTOCENTRYS
180 #endif
181                   , &entry)) {
182             WARN(cdaudio, "error read entry\n");
183             return FALSE;
184         }
185 #ifdef linux
186         start = CDFRAMES_PERSEC * (SECONDS_PERMIN * 
187                                    entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) + 
188             entry.cdte_addr.msf.frame;
189 #elif __FreeBSD__
190         start = CDFRAMES_PERSEC * (SECONDS_PERMIN *
191                                    toc_buffer.addr.msf.minute + toc_buffer.addr.msf.second) +
192             toc_buffer.addr.msf.frame;
193 #endif
194         if (i == 0) {
195             last_start = start;
196             CDADev[wDevID].dwFirstOffset = start;
197             TRACE(cdaudio, "dwFirstOffset=%u\n", 
198                   start);
199         }
200         else {
201             length = start - last_start;
202             last_start = start;
203             start = last_start - length;
204             total_length += length;
205             CDADev[wDevID].lpdwTrackLen[i - 1] = length;
206             CDADev[wDevID].lpdwTrackPos[i - 1] = start;
207             TRACE(cdaudio, "track #%u start=%u len=%u\n",
208                   i, start, length);
209         }
210     }
211     CDADev[wDevID].dwTotalLen = total_length;
212     TRACE(cdaudio,"total_len=%u\n", 
213           total_length);
214     return TRUE;
215 #else
216     return FALSE;
217 #endif
218 }
219
220
221 /**************************************************************************
222  *                              CDAUDIO_mciOpen                 [internal]
223  */
224 static DWORD CDAUDIO_mciOpen(UINT16 wDevID, DWORD dwFlags, void* lp, BOOL32 is32)
225 {
226 #if defined(linux) || defined(__FreeBSD__)
227     DWORD       dwDeviceID;
228
229     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
230           wDevID, dwFlags, lp);
231     if (lp == NULL) return MCIERR_INTERNAL;
232     
233     if (is32)   dwDeviceID = ((LPMCI_OPEN_PARMS32A)lp)->wDeviceID;
234     else        dwDeviceID = ((LPMCI_OPEN_PARMS16)lp)->wDeviceID;
235
236     if (CDADev[wDevID].nUseCount > 0) {
237         /* The driver already open on this channel */
238         /* If the driver was opened shareable before and this open specifies */
239         /* shareable then increment the use count */
240         if (CDADev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
241             ++CDADev[wDevID].nUseCount;
242         else
243             return MCIERR_MUST_USE_SHAREABLE;
244     } else {
245         CDADev[wDevID].nUseCount = 1;
246         CDADev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE;
247     }
248     if (dwFlags & MCI_OPEN_ELEMENT) {
249         TRACE(cdaudio,"MCI_OPEN_ELEMENT !\n");
250         /*              return MCIERR_NO_ELEMENT_ALLOWED; */
251     }
252     memcpy(&CDADev[wDevID].openParms, lp, sizeof(MCI_OPEN_PARMS16));
253     CDADev[wDevID].wNotifyDeviceID = dwDeviceID;
254     CDADev[wDevID].unixdev = open (CDAUDIO_DEV, O_RDONLY, 0);
255     if (CDADev[wDevID].unixdev == -1) {
256         WARN(cdaudio,"can't open '%s' !\n", CDAUDIO_DEV);
257         return MCIERR_HARDWARE;
258     }
259     CDADev[wDevID].mode = 0;
260     CDADev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF;
261     CDADev[wDevID].nCurTrack = 0;
262     CDADev[wDevID].nTracks = 0;
263     CDADev[wDevID].dwTotalLen = 0;
264     CDADev[wDevID].dwFirstOffset = 0;
265     CDADev[wDevID].lpdwTrackLen = NULL;
266     CDADev[wDevID].lpdwTrackPos = NULL;
267     if (!CDAUDIO_GetTracksInfo(wDevID)) {
268         WARN(cdaudio,"error reading TracksInfo !\n");
269         /*              return MCIERR_INTERNAL; */
270     }
271     
272     /*
273       Moved to mmsystem.c mciOpen routine
274       
275       if (dwFlags & MCI_NOTIFY) {
276       TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
277       lpParms->dwCallback);
278       mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
279       CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
280       }
281     */
282     return 0;
283 #else
284     return MCIERR_HARDWARE;
285 #endif
286 }
287
288 /**************************************************************************
289  *                              CDAUDIO_mciClose                [internal]
290  */
291 static DWORD CDAUDIO_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
292 {
293 #if defined(linux) || defined(__FreeBSD__)
294     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
295           wDevID, dwParam, lpParms);
296     if (--CDADev[wDevID].nUseCount == 0) {
297         if (CDADev[wDevID].lpdwTrackLen != NULL) free(CDADev[wDevID].lpdwTrackLen);
298         if (CDADev[wDevID].lpdwTrackPos != NULL) free(CDADev[wDevID].lpdwTrackPos);
299         close(CDADev[wDevID].unixdev);
300     }
301 #endif
302     return 0;
303 }
304
305 /**************************************************************************
306  *                              CDAUDIO_mciGetDevCaps   [internal]
307  */
308 static DWORD CDAUDIO_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags, 
309                                    LPMCI_GETDEVCAPS_PARMS lpParms)
310 {
311 #if defined(linux) || defined(__FreeBSD__)
312     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
313           wDevID, dwFlags, lpParms);
314     if (lpParms == NULL) return MCIERR_INTERNAL;
315     if (dwFlags & MCI_GETDEVCAPS_ITEM) {
316         TRACE(cdaudio, "MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n",
317               lpParms->dwItem);
318         switch(lpParms->dwItem) {
319         case MCI_GETDEVCAPS_CAN_RECORD:
320             lpParms->dwReturn = FALSE;
321             break;
322         case MCI_GETDEVCAPS_HAS_AUDIO:
323             lpParms->dwReturn = TRUE;
324             break;
325         case MCI_GETDEVCAPS_HAS_VIDEO:
326             lpParms->dwReturn = FALSE;
327             break;
328         case MCI_GETDEVCAPS_DEVICE_TYPE:
329             lpParms->dwReturn = MCI_DEVTYPE_CD_AUDIO;
330             break;
331         case MCI_GETDEVCAPS_USES_FILES:
332             lpParms->dwReturn = FALSE;
333             break;
334         case MCI_GETDEVCAPS_COMPOUND_DEVICE:
335             lpParms->dwReturn = FALSE;
336             break;
337         case MCI_GETDEVCAPS_CAN_EJECT:
338             lpParms->dwReturn = TRUE;
339             break;
340         case MCI_GETDEVCAPS_CAN_PLAY:
341             lpParms->dwReturn = TRUE;
342             break;
343         case MCI_GETDEVCAPS_CAN_SAVE:
344             lpParms->dwReturn = FALSE;
345             break;
346         default:
347             return MCIERR_UNRECOGNIZED_COMMAND;
348         }
349     }
350     TRACE(cdaudio, "lpParms->dwReturn=%08lX;\n", 
351           lpParms->dwReturn);
352     return 0;
353 #else
354     return MCIERR_INTERNAL;
355 #endif
356 }
357
358 /**************************************************************************
359  *                              CDAUDIO_mciInfo                 [internal]
360  */
361 static DWORD CDAUDIO_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpParms)
362 {
363 #if defined(linux) || defined(__FreeBSD__)
364     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
365           wDevID, dwFlags, lpParms);
366     if (lpParms == NULL) return MCIERR_INTERNAL;
367     lpParms->lpstrReturn = NULL;
368     switch(dwFlags) {
369     case MCI_INFO_PRODUCT:
370         lpParms->lpstrReturn = "Linux CDROM 0.5";
371         break;
372     default:
373         return MCIERR_UNRECOGNIZED_COMMAND;
374     }
375     if (lpParms->lpstrReturn != NULL)
376         lpParms->dwRetSize = strlen(lpParms->lpstrReturn);
377     else
378         lpParms->dwRetSize = 0;
379     return 0;
380 #else
381     return MCIERR_INTERNAL;
382 #endif
383 }
384
385
386 /**************************************************************************
387  *                              CDAUDIO_CalcFrame                       [internal]
388  */
389 static DWORD CDAUDIO_CalcFrame(UINT16 wDevID, DWORD dwFormatType, DWORD dwTime)
390 {
391     DWORD       dwFrame = 0;
392 #if defined(linux) || defined(__FreeBSD__)
393     UINT16      wTrack;
394     
395     TRACE(cdaudio,"(%04X, %08lX, %lu);\n", 
396           wDevID, dwFormatType, dwTime);
397     
398     switch (dwFormatType) {
399     case MCI_FORMAT_MILLISECONDS:
400         dwFrame = dwTime * CDFRAMES_PERSEC / 1000;
401         TRACE(cdaudio, "MILLISECONDS %lu\n", 
402               dwFrame);
403         break;
404     case MCI_FORMAT_MSF:
405         TRACE(cdaudio, "MSF %02u:%02u:%02u\n",
406               MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), 
407               MCI_MSF_FRAME(dwTime));
408         dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
409         dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
410         dwFrame += MCI_MSF_FRAME(dwTime);
411         break;
412     default:
413         /* unknown format ! force TMSF ! ... */
414         dwFormatType = MCI_FORMAT_TMSF;
415     case MCI_FORMAT_TMSF:
416         wTrack = MCI_TMSF_TRACK(dwTime);
417         TRACE(cdaudio, "MSF %02u-%02u:%02u:%02u\n",
418               MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), 
419               MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
420         TRACE(cdaudio, "TMSF trackpos[%u]=%lu\n",
421               wTrack, CDADev[wDevID].lpdwTrackPos[wTrack - 1]);
422         dwFrame = CDADev[wDevID].lpdwTrackPos[wTrack - 1];
423         dwFrame += CDFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime);
424         dwFrame += CDFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime);
425         dwFrame += MCI_TMSF_FRAME(dwTime);
426         break;
427     }
428 #endif
429     return dwFrame;
430 }
431
432
433 /**************************************************************************
434  *                              CDAUDIO_GetCDStatus                             [internal]
435  */
436 static BOOL32 CDAUDIO_GetCDStatus(UINT16 wDevID)
437 {
438 #if defined(linux) || defined(__FreeBSD__)
439     int         oldmode = CDADev[wDevID].mode;
440 #ifdef __FreeBSD__
441     struct ioc_read_subchannel  read_sc;
442     
443     read_sc.address_format = CD_MSF_FORMAT;
444     read_sc.data_format    = CD_CURRENT_POSITION;
445     read_sc.track          = 0;
446     read_sc.data_len       = sizeof(CDADev[wDevID].sc);
447     read_sc.data               = (struct cd_sub_channel_info *)&CDADev[wDevID].sc;
448 #elif linux
449     CDADev[wDevID].sc.cdsc_format = CDROM_MSF;
450 #endif
451     if (ioctl(CDADev[wDevID].unixdev,
452 #ifdef linux
453               CDROMSUBCHNL, &CDADev[wDevID].sc
454 #elif __FreeBSD__
455               CDIOCREADSUBCHANNEL, &read_sc
456 #endif
457               )) {
458         TRACE(cdaudio,"opened or no_media !\n");
459         CDADev[wDevID].mode = MCI_MODE_NOT_READY;
460         return TRUE;
461     }
462     switch (
463 #ifdef linux
464             CDADev[wDevID].sc.cdsc_audiostatus
465 #elif __FreeBSD__
466             CDADev[wDevID].sc.header.audio_status
467 #endif
468             ) {
469 #ifdef linux
470     case CDROM_AUDIO_INVALID:
471 #elif __FreeBSD__
472     case CD_AS_AUDIO_INVALID:
473 #endif
474         WARN(cdaudio, "device doesn't support status, returning NOT_READY.\n");
475 #ifdef linux
476         CDADev[wDevID].mode = MCI_MODE_NOT_READY;
477 #elif __FreeBSD__
478         CDADev[wDevID].mode = MCI_MODE_STOP;
479 #endif
480         break;
481 #ifdef linux
482     case CDROM_AUDIO_NO_STATUS: 
483 #elif __FreeBSD__
484     case CD_AS_NO_STATUS:
485 #endif
486         CDADev[wDevID].mode = MCI_MODE_STOP;
487         TRACE(cdaudio,"MCI_MODE_STOP !\n");
488         break;
489 #ifdef linux
490     case CDROM_AUDIO_PLAY: 
491 #elif __FreeBSD__
492     case CD_AS_PLAY_IN_PROGRESS:
493 #endif
494         CDADev[wDevID].mode = MCI_MODE_PLAY;
495         TRACE(cdaudio,"MCI_MODE_PLAY !\n");
496         break;
497 #ifdef linux
498     case CDROM_AUDIO_PAUSED:
499 #elif __FreeBSD__
500     case CD_AS_PLAY_PAUSED:
501 #endif
502         CDADev[wDevID].mode = MCI_MODE_PAUSE;
503         TRACE(cdaudio,"MCI_MODE_PAUSE !\n");
504         break;
505     default:
506 #ifdef linux
507         TRACE(cdaudio,"status=%02X !\n",
508               CDADev[wDevID].sc.cdsc_audiostatus);
509 #elif __FreeBSD__
510         TRACE(cdaudio,"status=%02X !\n",
511               CDADev[wDevID].sc.header.audio_status);
512 #endif
513     }
514 #ifdef linux
515     CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk;
516     CDADev[wDevID].dwCurFrame = 
517         CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute +
518         CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second +
519         CDADev[wDevID].sc.cdsc_absaddr.msf.frame;
520 #elif __FreeBSD__
521     CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.what.position.track_number;
522     CDADev[wDevID].dwCurFrame = 
523         CDFRAMES_PERMIN * CDADev[wDevID].sc.what.position.absaddr.msf.minute +
524         CDFRAMES_PERSEC * CDADev[wDevID].sc.what.position.absaddr.msf.second +
525         CDADev[wDevID].sc.what.position.absaddr.msf.frame;
526 #endif
527 #ifdef linux
528     TRACE(cdaudio,"%02u-%02u:%02u:%02u \n",
529           CDADev[wDevID].sc.cdsc_trk,
530           CDADev[wDevID].sc.cdsc_absaddr.msf.minute,
531           CDADev[wDevID].sc.cdsc_absaddr.msf.second,
532           CDADev[wDevID].sc.cdsc_absaddr.msf.frame);
533 #elif __FreeBSD__
534     TRACE(cdaudio,"%02u-%02u:%02u:%02u \n",
535           CDADev[wDevID].sc.what.position.track_number,
536           CDADev[wDevID].sc.what.position.absaddr.msf.minute,
537           CDADev[wDevID].sc.what.position.absaddr.msf.second,
538           CDADev[wDevID].sc.what.position.absaddr.msf.frame);
539 #endif
540     
541     if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) {
542         if (!CDAUDIO_GetTracksInfo(wDevID)) {
543             WARN(cdaudio, "error updating TracksInfo !\n");
544             return MCIERR_INTERNAL;
545         }
546     }
547     return TRUE;
548 #else
549     return FALSE;
550 #endif
551 }
552
553
554 /**************************************************************************
555  *                              CDAUDIO_CalcTime                        [internal]
556  */
557 static DWORD CDAUDIO_CalcTime(UINT16 wDevID, DWORD dwFormatType, DWORD dwFrame)
558 {
559     DWORD       dwTime = 0;
560 #if defined(linux) || defined(__FreeBSD__)
561     UINT16      wTrack;
562     UINT16      wMinutes;
563     UINT16      wSeconds;
564     UINT16      wFrames;
565     
566     TRACE(cdaudio,"(%04X, %08lX, %lu);\n", 
567           wDevID, dwFormatType, dwFrame);
568     
569     switch (dwFormatType) {
570     case MCI_FORMAT_MILLISECONDS:
571         dwTime = dwFrame / CDFRAMES_PERSEC * 1000;
572         TRACE(cdaudio, "MILLISECONDS %lu\n", 
573               dwTime);
574         break;
575     case MCI_FORMAT_MSF:
576         wMinutes = dwFrame / CDFRAMES_PERMIN;
577         wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
578         wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - 
579             CDFRAMES_PERSEC * wSeconds;
580         dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
581         TRACE(cdaudio,"MSF %02u:%02u:%02u -> dwTime=%lu\n",
582               wMinutes, wSeconds, wFrames, dwTime);
583         break;
584     default:
585         /* unknown format ! force TMSF ! ... */
586         dwFormatType = MCI_FORMAT_TMSF;
587     case MCI_FORMAT_TMSF:
588         for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) {
589             /*                          dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
590                                         TRACE(cdaudio, "Adding trk#%u curpos=%u \n", dwTime);
591                                         if (dwTime >= dwFrame) break; */
592             if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
593         }
594         wMinutes = dwFrame / CDFRAMES_PERMIN;
595         wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
596         wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - 
597             CDFRAMES_PERSEC * wSeconds;
598         dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
599         TRACE(cdaudio, "%02u-%02u:%02u:%02u\n",
600               wTrack, wMinutes, wSeconds, wFrames);
601         break;
602     }
603 #endif
604     return dwTime;
605 }
606
607
608 /**************************************************************************
609  *                              CDAUDIO_mciStatus               [internal]
610  */
611 static DWORD CDAUDIO_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
612 {
613 #if defined(linux) || defined(__FreeBSD__)
614     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
615           wDevID, dwFlags, lpParms);
616     if (lpParms == NULL) return MCIERR_INTERNAL;
617     if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
618     if (dwFlags & MCI_NOTIFY) {
619         TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
620               lpParms->dwCallback);
621         mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
622                         CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
623     }
624     if (dwFlags & MCI_STATUS_ITEM) {
625         switch(lpParms->dwItem) {
626         case MCI_STATUS_CURRENT_TRACK:
627             if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
628             lpParms->dwReturn = CDADev[wDevID].nCurTrack;
629             TRACE(cdaudio,"CURRENT_TRACK=%lu!\n", lpParms->dwReturn);
630             return 0;
631         case MCI_STATUS_LENGTH:
632             if (CDADev[wDevID].nTracks == 0) {
633                 if (!CDAUDIO_GetTracksInfo(wDevID)) {
634                     WARN(cdaudio, "error reading TracksInfo !\n");
635                     return MCIERR_INTERNAL;
636                 }
637             }
638             if (dwFlags & MCI_TRACK) {
639                 TRACE(cdaudio,"MCI_TRACK #%lu LENGTH=??? !\n",
640                       lpParms->dwTrack);
641                 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
642                     return MCIERR_OUTOFRANGE;
643                 lpParms->dwReturn = CDADev[wDevID].lpdwTrackLen[lpParms->dwTrack];
644             }
645             else
646                 lpParms->dwReturn = CDADev[wDevID].dwTotalLen;
647             lpParms->dwReturn = CDAUDIO_CalcTime(wDevID, 
648                                                  CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
649             TRACE(cdaudio,"LENGTH=%lu !\n", lpParms->dwReturn);
650             return 0;
651         case MCI_STATUS_MODE:
652             if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
653             lpParms->dwReturn = CDADev[wDevID].mode;
654             TRACE(cdaudio,"MCI_STATUS_MODE=%08lX !\n",
655                   lpParms->dwReturn);
656             return 0;
657         case MCI_STATUS_MEDIA_PRESENT:
658             lpParms->dwReturn = (CDADev[wDevID].nTracks > 0) ? TRUE : FALSE;
659             if (lpParms->dwReturn == FALSE)
660                 TRACE(cdaudio,"MEDIA_NOT_PRESENT !\n");
661             else
662                 TRACE(cdaudio,"MCI_STATUS_MEDIA_PRESENT !\n");
663             return 0;
664         case MCI_STATUS_NUMBER_OF_TRACKS:
665             lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(wDevID);
666             TRACE(cdaudio,"MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n",
667                   lpParms->dwReturn);
668             if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL;
669             return 0;
670         case MCI_STATUS_POSITION:
671             if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
672             lpParms->dwReturn = CDADev[wDevID].dwCurFrame;
673             if (dwFlags & MCI_STATUS_START) {
674                 lpParms->dwReturn = CDADev[wDevID].dwFirstOffset;
675                 TRACE(cdaudio,"get MCI_STATUS_START !\n");
676             }
677             if (dwFlags & MCI_TRACK) {
678                 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
679                     return MCIERR_OUTOFRANGE;
680                 lpParms->dwReturn = CDADev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1];
681                 TRACE(cdaudio,"get MCI_TRACK #%lu !\n", lpParms->dwTrack);
682             }
683             lpParms->dwReturn = CDAUDIO_CalcTime(wDevID,
684                                                  CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
685             TRACE(cdaudio,"MCI_STATUS_POSITION=%08lX !\n",
686                   lpParms->dwReturn);
687             return 0;
688         case MCI_STATUS_READY:
689             TRACE(cdaudio,"MCI_STATUS_READY !\n");
690             lpParms->dwReturn = TRUE;
691             return 0;
692         case MCI_STATUS_TIME_FORMAT:
693             TRACE(cdaudio,"MCI_STATUS_TIME_FORMAT !\n");
694             lpParms->dwReturn = CDADev[wDevID].dwTimeFormat;
695             return 0;
696         default:
697             WARN(cdaudio, "unknown command %08lX !\n", lpParms->dwItem);
698             return MCIERR_UNRECOGNIZED_COMMAND;
699         }
700     }
701     WARN(cdaudio, "not MCI_STATUS_ITEM !\n");
702     return 0;
703 #else
704     return MMSYSERR_NOTENABLED;
705 #endif
706 }
707
708
709 /**************************************************************************
710  *                              CDAUDIO_mciPlay                 [internal]
711  */
712 static DWORD CDAUDIO_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
713 {
714 #if defined(linux) || defined(__FreeBSD__)
715     int         start, end;
716 #ifdef linux
717     struct      cdrom_msf       msf;
718 #elif __FreeBSD__
719     struct      ioc_play_msf    msf;
720 #endif
721     
722     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
723           wDevID, dwFlags, lpParms);
724     if (lpParms == NULL) return MCIERR_INTERNAL;
725     if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
726     start = 0;          end = CDADev[wDevID].dwTotalLen;
727     CDADev[wDevID].nCurTrack = 1;
728     if (dwFlags & MCI_FROM) {
729         start = CDAUDIO_CalcFrame(wDevID, 
730                                   CDADev[wDevID].dwTimeFormat, lpParms->dwFrom); 
731         TRACE(cdaudio,"MCI_FROM=%08lX -> %u \n",
732               lpParms->dwFrom, start);
733     }
734     if (dwFlags & MCI_TO) {
735         end = CDAUDIO_CalcFrame(wDevID, 
736                                 CDADev[wDevID].dwTimeFormat, lpParms->dwTo);
737         TRACE(cdaudio, "MCI_TO=%08lX -> %u \n",
738               lpParms->dwTo, end);
739     }
740     start += CDADev[wDevID].dwFirstOffset;      
741     end += CDADev[wDevID].dwFirstOffset;
742 #ifdef linux
743     msf.cdmsf_min0 = start / CDFRAMES_PERMIN;
744     msf.cdmsf_sec0 = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
745     msf.cdmsf_frame0 = start % CDFRAMES_PERSEC;
746     msf.cdmsf_min1 = end / CDFRAMES_PERMIN;
747     msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
748     msf.cdmsf_frame1 = end % CDFRAMES_PERSEC;
749 #elif __FreeBSD__
750     msf.start_m     = start / CDFRAMES_PERMIN;
751     msf.start_s     = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
752     msf.start_f     = start % CDFRAMES_PERSEC;
753     msf.end_m       = end / CDFRAMES_PERMIN;
754     msf.end_s       = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
755     msf.end_f       = end % CDFRAMES_PERSEC;
756 #endif
757     if (ioctl(CDADev[wDevID].unixdev,
758 #ifdef linux
759               CDROMSTART
760 #elif __FreeBSD__
761               CDIOCSTART
762 #endif
763               )) {
764         WARN(cdaudio, "motor doesn't start !\n");
765         return MCIERR_HARDWARE;
766     }
767     if (ioctl(CDADev[wDevID].unixdev, 
768 #ifdef linux
769               CDROMPLAYMSF
770 #elif __FreeBSD__
771               CDIOCPLAYMSF
772 #endif
773               , &msf)) {
774         WARN(cdaudio, "device doesn't play !\n");
775         return MCIERR_HARDWARE;
776     }
777 #ifdef linux
778     TRACE(cdaudio,"msf = %d:%d:%d %d:%d:%d\n",
779           msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
780           msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1);
781 #elif __FreeBSD__
782     TRACE(cdaudio,"msf = %d:%d:%d %d:%d:%d\n",
783           msf.start_m, msf.start_s, msf.start_f,
784           msf.end_m,   msf.end_s,   msf.end_f);
785 #endif
786     CDADev[wDevID].mode = MCI_MODE_PLAY;
787     if (dwFlags & MCI_NOTIFY) {
788         TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
789               lpParms->dwCallback);
790         /*
791           mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
792           CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
793         */
794     }
795     return 0;
796 #else
797     return MCIERR_HARDWARE;
798 #endif
799 }
800
801 /**************************************************************************
802  *                              CDAUDIO_mciStop                 [internal]
803  */
804 static DWORD CDAUDIO_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
805 {
806 #if defined(linux) || defined(__FreeBSD__)
807     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
808           wDevID, dwFlags, lpParms);
809     if (lpParms == NULL) return MCIERR_INTERNAL;
810     if (ioctl(CDADev[wDevID].unixdev,
811 #ifdef linux
812               CDROMSTOP
813 #elif __FreeBSD__
814               CDIOCSTOP
815 #endif
816               )) return MCIERR_HARDWARE;
817     CDADev[wDevID].mode = MCI_MODE_STOP;
818     if (dwFlags & MCI_NOTIFY) {
819         TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
820               lpParms->dwCallback);
821         mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
822                         CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
823     }
824     return 0;
825 #else
826     return MCIERR_HARDWARE;
827 #endif
828 }
829
830 /**************************************************************************
831  *                              CDAUDIO_mciPause                [internal]
832  */
833 static DWORD CDAUDIO_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
834 {
835 #if defined(linux) || defined(__FreeBSD__)
836     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
837           wDevID, dwFlags, lpParms);
838     if (lpParms == NULL) return MCIERR_INTERNAL;
839     if (ioctl(CDADev[wDevID].unixdev,
840 #ifdef linux
841               CDROMPAUSE
842 #elif __FreeBSD__
843               CDIOCPAUSE
844 #endif
845               )) return MCIERR_HARDWARE;
846     CDADev[wDevID].mode = MCI_MODE_PAUSE;
847     if (dwFlags & MCI_NOTIFY) {
848         TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
849               lpParms->dwCallback);
850         mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
851                         CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
852     }
853     return 0;
854 #else
855     return MCIERR_HARDWARE;
856 #endif
857 }
858
859 /**************************************************************************
860  *                              CDAUDIO_mciResume               [internal]
861  */
862 static DWORD CDAUDIO_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
863 {
864 #if defined(linux) || defined(__FreeBSD__)
865     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
866           wDevID, dwFlags, lpParms);
867     if (lpParms == NULL) return MCIERR_INTERNAL;
868     if (ioctl(CDADev[wDevID].unixdev, 
869 #ifdef linux
870               CDROMRESUME
871 #elif __FreeBSD__
872               CDIOCRESUME
873 #endif
874               )) return MCIERR_HARDWARE;
875     CDADev[wDevID].mode = MCI_MODE_STOP;
876     if (dwFlags & MCI_NOTIFY) {
877         TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
878               lpParms->dwCallback);
879         mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
880                         CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
881     }
882     return 0;
883 #else
884     return MCIERR_HARDWARE;
885 #endif
886 }
887
888 /**************************************************************************
889  *                              CDAUDIO_mciSeek                 [internal]
890  */
891 static DWORD CDAUDIO_mciSeek(UINT16 wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
892 {
893 #if defined(linux) || defined(__FreeBSD__)
894     DWORD       dwRet;
895     MCI_PLAY_PARMS PlayParms;
896     TRACE(cdaudio,"(%04X, %08lX, %p);\n", 
897           wDevID, dwFlags, lpParms);
898     if (lpParms == NULL) return MCIERR_INTERNAL;
899     if (ioctl(CDADev[wDevID].unixdev,
900 #ifdef linux
901               CDROMRESUME
902 #elif __FreeBSD__
903               CDIOCRESUME
904 #endif
905               )) {
906         perror("ioctl CDROMRESUME");
907         return MCIERR_HARDWARE;
908     }
909     CDADev[wDevID].mode = MCI_MODE_SEEK;
910     switch(dwFlags) {
911     case MCI_SEEK_TO_START:
912         PlayParms.dwFrom = 0;
913         break;
914     case MCI_SEEK_TO_END:
915         PlayParms.dwFrom = CDADev[wDevID].dwTotalLen;
916         break;
917     case MCI_TO:
918         PlayParms.dwFrom = lpParms->dwTo;
919         break;
920     }
921     dwRet = CDAUDIO_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms);
922     if (dwRet != 0) return dwRet;
923     dwRet = CDAUDIO_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms);
924     if (dwFlags & MCI_NOTIFY) {
925         TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
926               lpParms->dwCallback);
927         mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
928                         CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
929     }
930     return dwRet;
931 #else
932     return MCIERR_HARDWARE;
933 #endif
934 }
935
936
937 /**************************************************************************
938  *                              CDAUDIO_mciSet                  [internal]
939  */
940 static DWORD CDAUDIO_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
941 {
942 #if defined(linux) || defined(__FreeBSD__)
943     TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
944     if (lpParms == NULL) return MCIERR_INTERNAL;
945     /*
946       TRACE(cdaudio,"dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
947       TRACE(cdaudio,"dwAudio=%08lX\n", lpParms->dwAudio);
948     */
949     if (dwFlags & MCI_SET_TIME_FORMAT) {
950         switch (lpParms->dwTimeFormat) {
951         case MCI_FORMAT_MILLISECONDS:
952             TRACE(cdaudio, "MCI_FORMAT_MILLISECONDS !\n");
953             break;
954         case MCI_FORMAT_MSF:
955             TRACE(cdaudio,"MCI_FORMAT_MSF !\n");
956             break;
957         case MCI_FORMAT_TMSF:
958             TRACE(cdaudio,"MCI_FORMAT_TMSF !\n");
959             break;
960         default:
961             WARN(cdaudio, "bad time format !\n");
962             return MCIERR_BAD_TIME_FORMAT;
963         }
964         CDADev[wDevID].dwTimeFormat = lpParms->dwTimeFormat;
965     }
966     if (dwFlags & MCI_SET_DOOR_OPEN) {
967         TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n");
968 #ifdef __FreeBSD__
969         if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
970         if (ioctl(CDADev[wDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
971         if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
972 #elif linux
973         if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
974 #endif
975         CDADev[wDevID].nTracks = 0;
976     }
977     if (dwFlags & MCI_SET_DOOR_CLOSED) {
978         TRACE(cdaudio, "MCI_SET_DOOR_CLOSED !\n");
979 #ifdef __FreeBSD__
980         if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
981         if (ioctl(CDADev[wDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
982         if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
983 #elif linux
984         if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
985         /* XXX should it be ",1" ??? */
986 #endif
987         CDADev[wDevID].nTracks = 0;
988     }
989     if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION;
990     if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION;
991     if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION;
992     if (dwFlags & MCI_NOTIFY) {
993         TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
994               lpParms->dwCallback);
995         mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), 
996                         CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
997     }
998     return 0;
999 #else
1000     return MCIERR_HARDWARE;
1001 #endif
1002 }
1003
1004
1005 /**************************************************************************
1006  *                              CDAUDIO_DriverProc16            [sample driver]
1007  */
1008 LONG CDAUDIO_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
1009                           DWORD dwParam1, DWORD dwParam2)
1010 {
1011 #if defined(linux) || defined(__FreeBSD__)
1012     switch(wMsg) {
1013     case DRV_LOAD:              return 1;
1014     case DRV_FREE:              return 1;
1015     case DRV_OPEN:
1016     case MCI_OPEN_DRIVER:       
1017     case MCI_OPEN:              return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2), FALSE); 
1018     case DRV_CLOSE:
1019     case MCI_CLOSE_DRIVER:
1020     case MCI_CLOSE:             return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1021     case DRV_ENABLE:            return 1;       
1022     case DRV_DISABLE:           return 1;
1023     case DRV_QUERYCONFIGURE:    return 1;
1024     case DRV_CONFIGURE:         MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1;
1025     case DRV_INSTALL:           return DRVCNF_RESTART;
1026     case DRV_REMOVE:            return DRVCNF_RESTART;
1027     case MCI_GETDEVCAPS:        return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1028     case MCI_INFO:              return CDAUDIO_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2));
1029     case MCI_STATUS:            return CDAUDIO_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1030     case MCI_SET:               return CDAUDIO_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
1031     case MCI_PLAY:              return CDAUDIO_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
1032     case MCI_STOP:              return CDAUDIO_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1033     case MCI_PAUSE:             return CDAUDIO_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1034     case MCI_RESUME:            return CDAUDIO_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1035     case MCI_SEEK:              return CDAUDIO_mciSeek(dwDevID, dwParam1, (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2));
1036     case MCI_SET_DOOR_OPEN:     TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n");
1037 #ifdef __FreeBSD__
1038         if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1039         if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
1040         if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1041 #elif linux
1042         if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
1043 #endif
1044         CDADev[dwDevID].nTracks = 0;
1045         return 0;
1046     case MCI_SET_DOOR_CLOSED:   TRACE(cdaudio,"MCI_SET_DOOR_CLOSED !\n");
1047 #ifdef __FreeBSD__
1048         if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1049         if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
1050         if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1051 #elif linux
1052         if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE;
1053 #endif
1054         CDADev[dwDevID].nTracks = 0;
1055         return 0;
1056     default:
1057         return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1058     }
1059 #else
1060     return MCIERR_HARDWARE;
1061 #endif
1062 }
1063 /**************************************************************************
1064  *                              CDAUDIO_DriverProc32            [sample driver]
1065  */
1066 LONG CDAUDIO_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, 
1067                           DWORD dwParam1, DWORD dwParam2)
1068 {
1069 #if defined(linux) || defined(__FreeBSD__)
1070     switch(wMsg) {
1071     case DRV_LOAD:              return 1;
1072     case DRV_FREE:              return 1;
1073     case DRV_OPEN:
1074     case MCI_OPEN_DRIVER:       
1075     case MCI_OPEN:              return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS32A)dwParam2, TRUE); 
1076     case DRV_CLOSE:
1077     case MCI_CLOSE_DRIVER:
1078     case MCI_CLOSE:             return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1079     case DRV_ENABLE:            return 1;       
1080     case DRV_DISABLE:           return 1;
1081     case DRV_QUERYCONFIGURE:    return 1;
1082     case DRV_CONFIGURE:         MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1;
1083     case DRV_INSTALL:           return DRVCNF_RESTART;
1084     case DRV_REMOVE:            return DRVCNF_RESTART;
1085     case MCI_GETDEVCAPS:        return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1086     case MCI_INFO:              return CDAUDIO_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)dwParam2);
1087     case MCI_STATUS:            return CDAUDIO_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)dwParam2);
1088     case MCI_SET:               return CDAUDIO_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)dwParam2);
1089     case MCI_PLAY:              return CDAUDIO_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)dwParam2);
1090     case MCI_STOP:              return CDAUDIO_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1091     case MCI_PAUSE:             return CDAUDIO_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1092     case MCI_RESUME:            return CDAUDIO_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1093     case MCI_SEEK:              return CDAUDIO_mciSeek(dwDevID, dwParam1, (LPMCI_SEEK_PARMS)dwParam2);
1094     case MCI_SET_DOOR_OPEN:     TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n");
1095 #ifdef __FreeBSD__
1096         if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1097         if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
1098         if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1099 #elif linux
1100         if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
1101 #endif
1102         CDADev[dwDevID].nTracks = 0;
1103         return 0;
1104     case MCI_SET_DOOR_CLOSED:   TRACE(cdaudio,"MCI_SET_DOOR_CLOSED !\n");
1105 #ifdef __FreeBSD__
1106         if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1107         if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
1108         if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1109 #elif linux
1110         if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE;
1111 #endif
1112         CDADev[dwDevID].nTracks = 0;
1113         return 0;
1114     default:
1115         return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1116     }
1117 #else
1118     return MCIERR_HARDWARE;
1119 #endif
1120 }
1121
1122
1123 /*-----------------------------------------------------------------------*/