Fixed crash with mapper loading.
[wine/testsucceed.git] / multimedia / lolvldrv.c
blob1942870053c5317a40c3bd2e53e1d59d9da7885e
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MMSYTEM low level drivers handling functions
6 * Copyright 1999 Eric Pouech
7 */
9 #include <string.h>
10 #include <assert.h>
11 #include "heap.h"
12 #include "user.h" /* should be removed asap; used in MMDRV_(Get|Alloc|Free) */
13 #include "selectors.h"
14 #include "driver.h"
15 #include "winver.h"
16 #include "module.h"
17 #include "winemm.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(mmsys)
22 typedef DWORD CALLBACK (*WINEMM_msgFunc16)(UINT16, WORD, DWORD, DWORD, DWORD);
23 typedef DWORD CALLBACK (*WINEMM_msgFunc32)(UINT , UINT, DWORD, DWORD, DWORD);
25 /* for each loaded driver and each known type of driver, this structure contains
26 * the information needed to access it
28 typedef struct tagWINE_MM_DRIVER_PART {
29 int nIDMin; /* lower bound of global indexes for this type */
30 int nIDMax; /* hhigher bound of global indexes for this type */
31 union {
32 WINEMM_msgFunc32 fnMessage32; /* pointer to fonction */
33 WINEMM_msgFunc16 fnMessage16;
34 } u;
35 } WINE_MM_DRIVER_PART;
37 /* each low-level .drv will be associated with an instance of this structure */
38 typedef struct tagWINE_MM_DRIVER {
39 HDRVR hDrvr; /* handle of loader driver */
40 LPSTR name; /* name of the driver */
41 BOOL bIs32 : 1, /* TRUE if 32 bit driver, FALSE for 16 */
42 bIsMapper : 1; /* TRUE if mapper */
43 WINE_MM_DRIVER_PART parts[MMDRV_MAX];/* Information for all known types */
44 } WINE_MM_DRIVER, *LPWINE_MM_DRIVER;
46 typedef enum {
47 MMDRV_MAP_NOMEM, /* ko, memory problem */
48 MMDRV_MAP_MSGERROR, /* ko, unknown message */
49 MMDRV_MAP_OK, /* ok, no memory allocated. to be sent to the proc. */
50 MMDRV_MAP_OKMEM, /* ok, some memory allocated, need to call UnMapMsg. to be sent to the proc. */
51 MMDRV_MAP_PASS /* not handled (no memory allocated) to be sent to the driver */
52 } MMDRV_MapType;
54 typedef MMDRV_MapType (*MMDRV_MAPFUNC )(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2);
56 /* each known type of driver has an instance of this structure */
57 typedef struct tagWINE_LLTYPE {
58 /* those attributes depend on the specification of the type */
59 LPSTR name; /* name (for debugging) */
60 BOOL bSupportMapper; /* if type is allowed to support mapper */
61 MMDRV_MAPFUNC Map16To32A; /* those are function pointers to handle */
62 MMDRV_MAPFUNC UnMap16To32A; /* the parameter conversion (16 vs 32 bit) */
63 MMDRV_MAPFUNC Map32ATo16; /* when hi-func (in mmsystem or winmm) and */
64 MMDRV_MAPFUNC UnMap32ATo16; /* low-func (in .drv) do not match */
65 LPDRVCALLBACK Callback; /* handles callback for a specified type */
66 /* those attributes reflect the loaded/current situation for the type */
67 UINT wMaxId; /* number of loaded devices (sum across all loaded drivers */
68 LPWINE_MLD lpMlds; /* "static" mlds to access the part though device IDs */
69 int nMapper; /* index to mapper */
70 } WINE_LLTYPE;
72 static WINE_MM_DRIVER MMDrvs[3];
74 /* ### start build ### */
75 extern WORD CALLBACK MMDRV_CallTo16_word_wwlll(FARPROC16,WORD,WORD,LONG,LONG,LONG);
76 /* ### stop build ### */
78 /**************************************************************************
79 * MMDRV_GetDescription16 [internal]
81 static BOOL MMDRV_GetDescription16(const char* fname, char* buf, int buflen)
83 OFSTRUCT ofs;
84 HFILE hFile;
85 WORD w;
86 DWORD dw;
87 BOOL ret = FALSE;
89 if ((hFile = OpenFile(fname, &ofs, OF_READ | OF_SHARE_DENY_WRITE)) == HFILE_ERROR) {
90 ERR("Can't open file %s\n", fname);
91 return FALSE;
94 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
96 if (_lread(hFile, &w, 2) != 2) E(("Can't read sig\n"));
97 if (w != ('Z' * 256 + 'M')) E(("Bad sig %04x\n", w));
98 if (_llseek(hFile, 0x3C, SEEK_SET) < 0) E(("Can't seek to ext header offset\n"));
99 if (_lread(hFile, &dw, 4) != 4) E(("Can't read ext header offset\n"));
100 if (_llseek(hFile, dw + 0x2C, SEEK_SET) < 0) E(("Can't seek to ext header.nr table %lu\n", dw+0x2C));
101 if (_lread(hFile, &dw, 4) != 4) E(("Can't read nr table offset\n"));
102 if (_llseek(hFile, dw, SEEK_SET) < 0) E(("Can't seek to nr table %lu\n", dw));
103 if (_lread(hFile, buf, 1) != 1) E(("Can't read descr length\n"));
104 buflen = MIN((BYTE)buf[0], buflen - 1);
105 if (_lread(hFile, buf, buflen) != buflen) E(("Can't read descr (%d)\n", buflen));
106 buf[buflen] = '\0';
107 ret = TRUE;
108 TRACE("Got '%s' [%d]\n", buf, buflen);
109 theEnd:
110 CloseHandle(hFile);
111 return ret;
114 /**************************************************************************
115 * MMDRV_GetDescription32 [internal]
117 static BOOL MMDRV_GetDescription32(const char* fname, char* buf, int buflen)
119 OFSTRUCT ofs;
120 DWORD h;
121 LPVOID ptr = 0;
122 LPVOID val;
123 DWORD dw;
124 BOOL ret = FALSE;
125 UINT u;
127 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
129 if (OpenFile(fname, &ofs, OF_EXIST)==HFILE_ERROR) E(("Can't find file %s\n", fname));
131 /* should load version.dll */
132 if (!(dw = GetFileVersionInfoSizeA(ofs.szPathName, &h))) E(("Can't get FVIS\n"));
133 if (!(ptr = HeapAlloc(GetProcessHeap(), 0, dw))) E(("OOM\n"));
134 if (!GetFileVersionInfoA(ofs.szPathName, h, dw, ptr)) E(("Can't get FVI\n"));
136 #define A(_x) if (VerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\" #_x, &val, &u)) \
137 TRACE(#_x " => %s\n", (LPSTR)val); else TRACE(#_x " @\n")
139 A(CompanyName);
140 A(FileDescription);
141 A(FileVersion);
142 A(InternalName);
143 A(LegalCopyright);
144 A(OriginalFilename);
145 A(ProductName);
146 A(ProductVersion);
147 A(Comments);
148 A(LegalTrademarks);
149 A(PrivateBuild);
150 A(SpecialBuild);
151 #undef A
153 if (!VerQueryValueA(ptr, "\\StringFileInfo\\040904B0\\ProductName", &val, &u)) E(("Can't get product name\n"));
154 strncpy(buf, val, buflen - 1);
155 buf[buflen - 1] = '\0';
157 #undef E
158 ret = TRUE;
159 theEnd:
160 HeapFree(GetProcessHeap(), 0, ptr);
161 return ret;
164 /**************************************************************************
165 * MMDRV_Callback [internal]
167 static void MMDRV_Callback(LPWINE_MLD mld, HDRVR hDev, UINT uMsg, DWORD dwParam1, DWORD dwParam2)
169 TRACE("CB (*%08lx)(%08x %08x %08lx %08lx %08lx\n",
170 mld->dwCallback, hDev, uMsg, mld->dwClientInstance, dwParam1, dwParam2);
172 if (!mld->bFrom32 && (mld->dwFlags & DCB_TYPEMASK) == DCB_FUNCTION) {
173 /* 16 bit func, call it */
174 TRACE("Function (16 bit) !\n");
175 MMDRV_CallTo16_word_wwlll((FARPROC16)mld->dwCallback, hDev, uMsg,
176 mld->dwClientInstance, dwParam1, dwParam2);
177 } else {
178 DriverCallback(mld->dwCallback, mld->dwFlags, hDev, uMsg,
179 mld->dwClientInstance, dwParam1, dwParam2);
183 /* =================================
184 * A U X M A P P E R S
185 * ================================= */
187 /**************************************************************************
188 * MMDRV_Aux_Map16To32A [internal]
190 static MMDRV_MapType MMDRV_Aux_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
192 return MMDRV_MAP_MSGERROR;
195 /**************************************************************************
196 * MMDRV_Aux_UnMap16To32A [internal]
198 static MMDRV_MapType MMDRV_Aux_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
200 return MMDRV_MAP_MSGERROR;
203 /**************************************************************************
204 * MMDRV_Aux_Map32ATo16 [internal]
206 static MMDRV_MapType MMDRV_Aux_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
208 return MMDRV_MAP_MSGERROR;
211 /**************************************************************************
212 * MMDRV_Aux_UnMap32ATo16 [internal]
214 static MMDRV_MapType MMDRV_Aux_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
216 #if 0
217 case AUXDM_GETDEVCAPS:
218 lpCaps->wMid = ac16.wMid;
219 lpCaps->wPid = ac16.wPid;
220 lpCaps->vDriverVersion = ac16.vDriverVersion;
221 strcpy(lpCaps->szPname, ac16.szPname);
222 lpCaps->wTechnology = ac16.wTechnology;
223 lpCaps->dwSupport = ac16.dwSupport;
224 #endif
225 return MMDRV_MAP_MSGERROR;
228 /**************************************************************************
229 * MMDRV_Aux_Callback [internal]
231 static void CALLBACK MMDRV_Aux_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
233 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
235 FIXME("NIY\n");
236 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
239 /* =================================
240 * M I X E R M A P P E R S
241 * ================================= */
243 /**************************************************************************
244 * xMMDRV_Mixer_Map16To32A [internal]
246 static MMDRV_MapType MMDRV_Mixer_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
248 return MMDRV_MAP_MSGERROR;
251 /**************************************************************************
252 * MMDRV_Mixer_UnMap16To32A [internal]
254 static MMDRV_MapType MMDRV_Mixer_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
256 #if 0
257 MIXERCAPSA micA;
258 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
260 if (ret == MMSYSERR_NOERROR) {
261 mixcaps->wMid = micA.wMid;
262 mixcaps->wPid = micA.wPid;
263 mixcaps->vDriverVersion = micA.vDriverVersion;
264 strcpy(mixcaps->szPname, micA.szPname);
265 mixcaps->fdwSupport = micA.fdwSupport;
266 mixcaps->cDestinations = micA.cDestinations;
268 return ret;
269 #endif
270 return MMDRV_MAP_MSGERROR;
273 /**************************************************************************
274 * MMDRV_Mixer_Map32ATo16 [internal]
276 static MMDRV_MapType MMDRV_Mixer_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
278 return MMDRV_MAP_MSGERROR;
281 /**************************************************************************
282 * MMDRV_Mixer_UnMap32ATo16 [internal]
284 static MMDRV_MapType MMDRV_Mixer_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
286 return MMDRV_MAP_MSGERROR;
289 /**************************************************************************
290 * MMDRV_Mixer_Callback [internal]
292 static void CALLBACK MMDRV_Mixer_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
294 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
296 FIXME("NIY\n");
297 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
300 /* =================================
301 * M I D I I N M A P P E R S
302 * ================================= */
304 /**************************************************************************
305 * MMDRV_MidiIn_Map16To32A [internal]
307 static MMDRV_MapType MMDRV_MidiIn_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
309 return MMDRV_MAP_MSGERROR;
312 /**************************************************************************
313 * MMDRV_MidiIn_UnMap16To32A [internal]
315 static MMDRV_MapType MMDRV_MidiIn_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
317 return MMDRV_MAP_MSGERROR;
320 /**************************************************************************
321 * MMDRV_MidiIn_Map32ATo16 [internal]
323 static MMDRV_MapType MMDRV_MidiIn_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
325 return MMDRV_MAP_MSGERROR;
328 /**************************************************************************
329 * MMDRV_MidiIn_UnMap32ATo16 [internal]
331 static MMDRV_MapType MMDRV_MidiIn_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
333 return MMDRV_MAP_MSGERROR;
336 /**************************************************************************
337 * MMDRV_MidiIn_Callback [internal]
339 static void CALLBACK MMDRV_MidiIn_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
341 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
343 FIXME("NIY\n");
344 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
347 /* =================================
348 * M I D I O U T M A P P E R S
349 * ================================= */
351 /**************************************************************************
352 * MMDRV_MidiOut_Map16To32A [internal]
354 static MMDRV_MapType MMDRV_MidiOut_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
356 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
358 switch (wMsg) {
359 case MODM_GETNUMDEVS:
360 case MODM_DATA:
361 case MODM_RESET:
362 case MODM_SETVOLUME:
363 ret = MMDRV_MAP_OK;
364 break;
366 case MODM_OPEN:
367 case MODM_CLOSE:
368 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
369 break;
371 case MODM_GETDEVCAPS:
373 LPMIDIOUTCAPSA moc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPS16) + sizeof(MIDIOUTCAPSA));
374 LPMIDIOUTCAPS16 moc16 = PTR_SEG_TO_LIN(*lpParam1);
376 if (moc32) {
377 *(LPMIDIOUTCAPS16*)moc32 = moc16;
378 moc32 = (LPMIDIOUTCAPSA)((LPSTR)moc32 + sizeof(LPMIDIOUTCAPS16));
379 *lpParam1 = (DWORD)moc32;
380 *lpParam2 = sizeof(MIDIOUTCAPSA);
382 ret = MMDRV_MAP_OKMEM;
383 } else {
384 ret = MMDRV_MAP_NOMEM;
387 break;
388 case MODM_PREPARE:
389 case MODM_UNPREPARE:
390 case MODM_LONGDATA:
391 case MODM_GETVOLUME:
392 case MODM_CACHEPATCHES:
393 case MODM_CACHEDRUMPATCHES:
394 default:
395 FIXME("NIY: no conversion yet for %u\n", wMsg);
396 break;
398 return ret;
401 /**************************************************************************
402 * MMDRV_MidiOut_UnMap16To32A [internal]
404 static MMDRV_MapType MMDRV_MidiOut_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
406 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
408 switch (wMsg) {
409 case MODM_GETNUMDEVS:
410 case MODM_DATA:
411 case MODM_RESET:
412 case MODM_SETVOLUME:
413 ret = MMDRV_MAP_OK;
414 break;
416 case MODM_OPEN:
417 case MODM_CLOSE:
418 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
419 break;
421 case MODM_GETDEVCAPS:
423 LPMIDIOUTCAPSA moc32 = (LPMIDIOUTCAPSA)(*lpParam1);
424 LPMIDIOUTCAPS16 moc16 = *(LPMIDIOUTCAPS16*)((LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
426 moc16->wMid = moc32->wMid;
427 moc16->wPid = moc32->wPid;
428 moc16->vDriverVersion = moc32->vDriverVersion;
429 strcpy(moc16->szPname, moc32->szPname);
430 moc16->wTechnology = moc32->wTechnology;
431 moc16->wVoices = moc32->wVoices;
432 moc16->wNotes = moc32->wNotes;
433 moc16->wChannelMask = moc32->wChannelMask;
434 moc16->dwSupport = moc32->dwSupport;
435 HeapFree(GetProcessHeap(), 0, (LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
436 ret = MMDRV_MAP_OK;
438 break;
439 case MODM_PREPARE:
440 case MODM_UNPREPARE:
441 case MODM_LONGDATA:
442 case MODM_GETVOLUME:
443 case MODM_CACHEPATCHES:
444 case MODM_CACHEDRUMPATCHES:
445 default:
446 FIXME("NIY: no conversion yet for %u\n", wMsg);
447 break;
449 return ret;
452 /**************************************************************************
453 * MMDRV_MidiOut_Map32ATo16 [internal]
455 static MMDRV_MapType MMDRV_MidiOut_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
457 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
459 switch (wMsg) {
460 case MODM_CLOSE:
461 case MODM_GETNUMDEVS:
462 case MODM_DATA:
463 case MODM_RESET:
464 case MODM_SETVOLUME:
465 ret = MMDRV_MAP_OK;
466 break;
467 case MODM_GETDEVCAPS:
469 LPMIDIOUTCAPSA moc32 = (LPMIDIOUTCAPSA)*lpParam1;
470 LPSTR ptr = SEGPTR_ALLOC(sizeof(LPMIDIOUTCAPSA) + sizeof(MIDIOUTCAPS16));
472 if (ptr) {
473 *(LPMIDIOUTCAPSA*)ptr = moc32;
474 ret = MMDRV_MAP_OKMEM;
475 } else {
476 ret = MMDRV_MAP_NOMEM;
478 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPMIDIOUTCAPSA);
479 *lpParam2 = sizeof(MIDIOUTCAPS16);
481 break;
482 case MODM_OPEN:
483 case MODM_PREPARE:
484 case MODM_UNPREPARE:
485 case MODM_LONGDATA:
486 case MODM_GETVOLUME:
487 case MODM_CACHEPATCHES:
488 case MODM_CACHEDRUMPATCHES:
489 default:
490 FIXME("NIY: no conversion yet for %u\n", wMsg);
491 break;
493 return ret;
496 /**************************************************************************
497 * MMDRV_MidiOut_UnMap32ATo16 [internal]
499 static MMDRV_MapType MMDRV_MidiOut_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
501 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
503 switch (wMsg) {
504 case MODM_CLOSE:
505 case MODM_GETNUMDEVS:
506 case MODM_DATA:
507 case MODM_RESET:
508 case MODM_SETVOLUME:
509 ret = MMDRV_MAP_OK;
510 break;
511 case MODM_GETDEVCAPS:
513 LPMIDIOUTCAPS16 moc16 = (LPMIDIOUTCAPS16)PTR_SEG_TO_LIN(*lpParam1);
514 LPSTR ptr = (LPSTR)moc16 - sizeof(LPMIDIOUTCAPSA);
515 LPMIDIOUTCAPSA moc32 = *(LPMIDIOUTCAPSA*)ptr;
517 moc32->wMid = moc16->wMid;
518 moc32->wPid = moc16->wPid;
519 moc32->vDriverVersion = moc16->vDriverVersion;
520 strcpy(moc32->szPname, moc16->szPname);
521 moc32->wTechnology = moc16->wTechnology;
522 moc32->wVoices = moc16->wVoices;
523 moc32->wNotes = moc16->wNotes;
524 moc32->wChannelMask = moc16->wChannelMask;
525 moc32->dwSupport = moc16->dwSupport;
527 if (!SEGPTR_FREE(ptr))
528 FIXME("bad free line=%d\n", __LINE__);
529 ret = MMDRV_MAP_OK;
531 break;
532 case MODM_OPEN:
533 case MODM_PREPARE:
534 case MODM_UNPREPARE:
535 case MODM_LONGDATA:
536 case MODM_GETVOLUME:
537 case MODM_CACHEPATCHES:
538 case MODM_CACHEDRUMPATCHES:
539 default:
540 FIXME("NIY: no conversion yet for %u\n", wMsg);
541 break;
543 return ret;
546 /**************************************************************************
547 * MMDRV_MidiOut_Callback [internal]
549 static void CALLBACK MMDRV_MidiOut_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
551 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
553 switch (uMsg) {
554 case MOM_OPEN:
555 case MOM_CLOSE:
556 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
557 break;
558 case MOM_DONE:
559 if (mld->bFrom32 && !MMDrvs[mld->mmdIndex].bIs32) {
560 /* initial map is: 32 => 16 */
561 LPMIDIHDR wh16 = (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1);
562 LPMIDIHDR wh32 = *(LPMIDIHDR*)((LPSTR)wh16 - sizeof(LPMIDIHDR));
564 dwParam1 = (DWORD)wh32;
565 wh32->dwFlags = wh16->dwFlags;
566 } else if (!mld->bFrom32 && MMDrvs[mld->mmdIndex].bIs32) {
567 /* initial map is: 16 => 32 */
568 LPMIDIHDR wh32 = (LPMIDIHDR)(dwParam1);
569 LPMIDIHDR segwh16 = *(LPMIDIHDR*)((LPSTR)wh32 - sizeof(LPMIDIHDR));
570 LPMIDIHDR wh16 = PTR_SEG_TO_LIN(segwh16);
572 dwParam1 = (DWORD)segwh16;
573 wh16->dwFlags = wh32->dwFlags;
575 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
576 break;
577 /* case MOM_POSITIONCB: */
578 default:
579 ERR("Unknown msg %u\n", uMsg);
582 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
585 /* =================================
586 * W A V E I N M A P P E R S
587 * ================================= */
589 /**************************************************************************
590 * MMDRV_WaveIn_Map16To32A [internal]
592 static MMDRV_MapType MMDRV_WaveIn_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
594 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
596 switch (wMsg) {
597 case WIDM_GETNUMDEVS:
598 case WIDM_RESET:
599 case WIDM_START:
600 case WIDM_STOP:
601 ret = MMDRV_MAP_OK;
602 break;
603 case WIDM_OPEN:
604 case WIDM_CLOSE:
605 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
606 break;
607 case WIDM_GETDEVCAPS:
609 LPWAVEINCAPSA wic32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEINCAPS16) + sizeof(WAVEINCAPSA));
610 LPWAVEINCAPS16 wic16 = PTR_SEG_TO_LIN(*lpParam1);
612 if (wic32) {
613 *(LPWAVEINCAPS16*)wic32 = wic16;
614 wic32 = (LPWAVEINCAPSA)((LPSTR)wic32 + sizeof(LPWAVEINCAPS16));
615 *lpParam1 = (DWORD)wic32;
616 *lpParam2 = sizeof(WAVEINCAPSA);
618 ret = MMDRV_MAP_OKMEM;
619 } else {
620 ret = MMDRV_MAP_NOMEM;
623 break;
624 case WIDM_GETPOS:
626 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
627 LPMMTIME16 mmt16 = PTR_SEG_TO_LIN(*lpParam1);
629 if (mmt32) {
630 *(LPMMTIME16*)mmt32 = mmt16;
631 mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
633 mmt32->wType = mmt16->wType;
634 *lpParam1 = (DWORD)mmt32;
635 *lpParam2 = sizeof(MMTIME);
637 ret = MMDRV_MAP_OKMEM;
638 } else {
639 ret = MMDRV_MAP_NOMEM;
642 break;
643 case WIDM_PREPARE:
645 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
646 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(*lpParam1);
648 if (wh32) {
649 *(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
650 wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
651 wh32->lpData = PTR_SEG_TO_LIN(wh16->lpData);
652 wh32->dwBufferLength = wh16->dwBufferLength;
653 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
654 wh32->dwUser = wh16->dwUser;
655 wh32->dwFlags = wh16->dwFlags;
656 wh32->dwLoops = wh16->dwLoops;
657 /* FIXME: nothing on wh32->lpNext */
658 /* could link the wh32->lpNext at this level for memory house keeping */
659 wh16->lpNext = wh32; /* for reuse in unprepare and write */
660 *lpParam1 = (DWORD)wh32;
661 *lpParam2 = sizeof(WAVEHDR);
663 ret = MMDRV_MAP_OKMEM;
664 } else {
665 ret = MMDRV_MAP_NOMEM;
668 break;
669 case WIDM_ADDBUFFER:
670 case WIDM_UNPREPARE:
672 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(*lpParam1);
673 LPWAVEHDR wh32 = (LPWAVEHDR)wh16->lpNext;
675 *lpParam1 = (DWORD)wh32;
676 *lpParam2 = sizeof(WAVEHDR);
677 ret = MMDRV_MAP_OKMEM;
679 break;
680 default:
681 FIXME("NIY: no conversion yet for %u\n", wMsg);
682 break;
684 return ret;
687 /**************************************************************************
688 * MMDRV_WaveIn_UnMap16To32A [internal]
690 static MMDRV_MapType MMDRV_WaveIn_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
692 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
694 switch (wMsg) {
695 case WIDM_GETNUMDEVS:
696 case WIDM_RESET:
697 case WIDM_START:
698 case WIDM_STOP:
699 ret = MMDRV_MAP_OK;
700 break;
701 case WIDM_OPEN:
702 case WIDM_CLOSE:
703 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
704 break;
705 case WIDM_GETDEVCAPS:
707 LPWAVEINCAPSA wic32 = (LPWAVEINCAPSA)(*lpParam1);
708 LPWAVEINCAPS16 wic16 = *(LPWAVEINCAPS16*)((LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
710 wic16->wMid = wic32->wMid;
711 wic16->wPid = wic32->wPid;
712 wic16->vDriverVersion = wic32->vDriverVersion;
713 strcpy(wic16->szPname, wic32->szPname);
714 wic16->dwFormats = wic32->dwFormats;
715 wic16->wChannels = wic32->wChannels;
716 HeapFree(GetProcessHeap(), 0, (LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
717 ret = MMDRV_MAP_OK;
719 break;
720 case WIDM_GETPOS:
722 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
723 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
725 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
726 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
727 ret = MMDRV_MAP_OK;
729 break;
730 case WIDM_ADDBUFFER:
731 case WIDM_PREPARE:
732 case WIDM_UNPREPARE:
734 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
735 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(*(LPWAVEHDR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
737 assert(wh16->lpNext == wh32);
738 wh16->dwBufferLength = wh32->dwBufferLength;
739 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
740 wh16->dwUser = wh32->dwUser;
741 wh16->dwFlags = wh32->dwFlags;
742 wh16->dwLoops = wh32->dwLoops;
744 if (wMsg == WIDM_UNPREPARE) {
745 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
746 wh16->lpNext = 0;
748 ret = MMDRV_MAP_OK;
750 break;
751 default:
752 FIXME("NIY: no conversion yet for %u\n", wMsg);
753 break;
755 return ret;
758 /**************************************************************************
759 * MMDRV_WaveIn_Map32ATo16 [internal]
761 static MMDRV_MapType MMDRV_WaveIn_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
763 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
765 switch (wMsg) {
766 case WIDM_CLOSE:
767 case WIDM_GETNUMDEVS:
768 case WIDM_RESET:
769 case WIDM_START:
770 case WIDM_STOP:
771 ret = MMDRV_MAP_OK;
772 break;
774 case WIDM_OPEN:
776 LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
777 int sz = sizeof(WAVEFORMATEX);
778 LPVOID ptr;
779 LPWAVEOPENDESC16 wod16;
781 /* allocated data are mapped as follows:
782 LPWAVEOPENDESC ptr to orig lParam1
783 DWORD ptr to orig dwUser, which is a pointer to DWORD:driver dwInstance
784 DWORD dwUser passed to driver
785 WAVEOPENDESC16 wod16: openDesc passed to driver
786 WAVEFORMATEX openDesc->lpFormat passed to driver
787 xxx extra bytes to WAVEFORMATEX
789 if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
790 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize, wod32->lpFormat->wFormatTag);
791 sz += ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize;
794 ptr = SEGPTR_ALLOC(sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
796 if (ptr) {
797 *(LPWAVEOPENDESC*)ptr = wod32;
798 *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
799 wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
801 wod16->hWave = wod32->hWave;
802 wod16->lpFormat = (LPWAVEFORMATEX)((DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
803 memcpy(wod16 + 1, wod32->lpFormat, sz);
805 wod16->dwCallback = wod32->dwCallback;
806 wod16->dwInstance = wod32->dwInstance;
807 wod16->uMappedDeviceID = wod32->uMappedDeviceID;
808 wod16->dnDevNode = wod32->dnDevNode;
810 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
811 *lpdwUser = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
813 ret = MMDRV_MAP_OKMEM;
814 } else {
815 ret = MMDRV_MAP_NOMEM;
818 break;
819 case WIDM_PREPARE:
821 LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
822 LPWAVEHDR wh16;
823 LPVOID ptr = SEGPTR_ALLOC(sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
825 if (ptr) {
826 *(LPWAVEHDR*)ptr = wh32;
827 wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
828 wh16->lpData = (LPSTR)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
829 /* data will be copied on WODM_WRITE */
830 wh16->dwBufferLength = wh32->dwBufferLength;
831 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
832 wh16->dwUser = wh32->dwUser;
833 wh16->dwFlags = wh32->dwFlags;
834 wh16->dwLoops = wh32->dwLoops;
835 /* FIXME: nothing on wh32->lpNext */
836 /* could link the wh32->lpNext at this level for memory house keeping */
837 wh32->lpNext = wh16; /* for reuse in unprepare and write */
838 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
839 (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
840 wh32->dwBufferLength, (DWORD)wh32->lpData);
841 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR);
842 *lpParam2 = sizeof(WAVEHDR);
844 ret = MMDRV_MAP_OKMEM;
845 } else {
846 ret = MMDRV_MAP_NOMEM;
849 break;
850 case WIDM_ADDBUFFER:
851 case WIDM_UNPREPARE:
853 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
854 LPWAVEHDR wh16 = wh32->lpNext;
855 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
857 assert(*(LPWAVEHDR*)ptr == wh32);
859 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
860 (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
861 wh32->dwBufferLength, (DWORD)wh32->lpData);
863 if (wMsg == WODM_WRITE)
864 memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
866 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR);
867 *lpParam2 = sizeof(WAVEHDR);
868 ret = MMDRV_MAP_OKMEM;
870 break;
871 case WIDM_GETDEVCAPS:
873 LPWAVEINCAPSA wic32 = (LPWAVEINCAPSA)*lpParam1;
874 LPSTR ptr = SEGPTR_ALLOC(sizeof(LPWAVEINCAPSA) + sizeof(WAVEINCAPS16));
876 if (ptr) {
877 *(LPWAVEINCAPSA*)ptr = wic32;
878 ret = MMDRV_MAP_OKMEM;
879 } else {
880 ret = MMDRV_MAP_NOMEM;
882 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEINCAPSA);
883 *lpParam2 = sizeof(WAVEINCAPS16);
885 break;
886 case WIDM_GETPOS:
888 LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
889 LPSTR ptr = SEGPTR_ALLOC(sizeof(LPMMTIME) + sizeof(MMTIME16));
890 LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
892 if (ptr) {
893 *(LPMMTIME*)ptr = mmt32;
894 mmt16->wType = mmt32->wType;
895 ret = MMDRV_MAP_OKMEM;
896 } else {
897 ret = MMDRV_MAP_NOMEM;
899 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPMMTIME);
900 *lpParam2 = sizeof(MMTIME16);
902 break;
903 default:
904 FIXME("NIY: no conversion yet for %u\n", wMsg);
905 break;
907 return ret;
910 /**************************************************************************
911 * MMDRV_WaveIn_UnMap32ATo16 [internal]
913 static MMDRV_MapType MMDRV_WaveIn_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
915 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
917 switch (wMsg) {
918 case WIDM_CLOSE:
919 case WIDM_GETNUMDEVS:
920 case WIDM_RESET:
921 case WIDM_START:
922 case WIDM_STOP:
923 ret = MMDRV_MAP_OK;
924 break;
926 case WIDM_OPEN:
928 LPWAVEOPENDESC16 wod16 = (LPWAVEOPENDESC16)PTR_SEG_TO_LIN(*lpParam1);
929 LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
930 LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
932 wod32->uMappedDeviceID = wod16->uMappedDeviceID;
933 **(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
935 if (!SEGPTR_FREE(ptr))
936 FIXME("bad free line=%d\n", __LINE__);
938 ret = MMDRV_MAP_OK;
940 break;
942 case WIDM_ADDBUFFER:
943 case WIDM_PREPARE:
944 case WIDM_UNPREPARE:
946 LPWAVEHDR wh16 = (LPWAVEHDR)PTR_SEG_TO_LIN(*lpParam1);
947 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
948 LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
950 assert(wh32->lpNext == wh16);
951 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
952 wh32->dwUser = wh16->dwUser;
953 wh32->dwFlags = wh16->dwFlags;
954 wh32->dwLoops = wh16->dwLoops;
956 if (wMsg == WODM_UNPREPARE) {
957 if (!SEGPTR_FREE(ptr))
958 FIXME("bad free line=%d\n", __LINE__);
959 wh32->lpNext = 0;
961 ret = MMDRV_MAP_OK;
963 break;
964 case WIDM_GETDEVCAPS:
966 LPWAVEINCAPS16 wic16 = (LPWAVEINCAPS16)PTR_SEG_TO_LIN(*lpParam1);
967 LPSTR ptr = (LPSTR)wic16 - sizeof(LPWAVEINCAPSA);
968 LPWAVEINCAPSA wic32 = *(LPWAVEINCAPSA*)ptr;
970 wic32->wMid = wic16->wMid;
971 wic32->wPid = wic16->wPid;
972 wic32->vDriverVersion = wic16->vDriverVersion;
973 strcpy(wic32->szPname, wic16->szPname);
974 wic32->dwFormats = wic16->dwFormats;
975 wic32->wChannels = wic16->wChannels;
976 if (!SEGPTR_FREE(ptr))
977 FIXME("bad free line=%d\n", __LINE__);
978 ret = MMDRV_MAP_OK;
980 break;
981 case WIDM_GETPOS:
983 LPMMTIME16 mmt16 = (LPMMTIME16)PTR_SEG_TO_LIN(*lpParam1);
984 LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
985 LPMMTIME mmt32 = *(LPMMTIME*)ptr;
987 MMSYSTEM_MMTIME16to32(mmt32, mmt16);
989 if (!SEGPTR_FREE(ptr))
990 FIXME("bad free line=%d\n", __LINE__);
992 ret = MMDRV_MAP_OK;
994 break;
995 default:
996 FIXME("NIY: no conversion yet for %u\n", wMsg);
997 break;
999 return ret;
1002 /**************************************************************************
1003 * MMDRV_WaveIn_Callback [internal]
1005 static void CALLBACK MMDRV_WaveIn_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
1007 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
1009 switch (uMsg) {
1010 case WIM_OPEN:
1011 case WIM_CLOSE:
1012 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1013 break;
1014 case WIM_DATA:
1015 if (mld->bFrom32 && !MMDrvs[mld->mmdIndex].bIs32) {
1016 /* initial map is: 32 => 16 */
1017 LPWAVEHDR wh16 = (LPWAVEHDR)PTR_SEG_TO_LIN(dwParam1);
1018 LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
1020 dwParam1 = (DWORD)wh32;
1021 wh32->dwFlags = wh16->dwFlags;
1022 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1023 } else if (!mld->bFrom32 && MMDrvs[mld->mmdIndex].bIs32) {
1024 /* initial map is: 16 => 32 */
1025 LPWAVEHDR wh32 = (LPWAVEHDR)(dwParam1);
1026 LPWAVEHDR segwh16 = *(LPWAVEHDR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
1027 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(segwh16);
1029 dwParam1 = (DWORD)segwh16;
1030 wh16->dwFlags = wh32->dwFlags;
1031 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1033 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1034 break;
1035 default:
1036 ERR("Unknown msg %u\n", uMsg);
1039 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
1042 /* =================================
1043 * W A V E O U T M A P P E R S
1044 * ================================= */
1046 /**************************************************************************
1047 * MMDRV_WaveOut_Map16To32A [internal]
1049 static MMDRV_MapType MMDRV_WaveOut_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1051 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
1053 switch (wMsg) {
1054 /* nothing to do */
1055 case WODM_BREAKLOOP:
1056 case WODM_CLOSE:
1057 case WODM_GETNUMDEVS:
1058 case WODM_PAUSE:
1059 case WODM_RESET:
1060 case WODM_RESTART:
1061 case WODM_SETPITCH:
1062 case WODM_SETPLAYBACKRATE:
1063 case WODM_SETVOLUME:
1064 ret = MMDRV_MAP_OK;
1065 break;
1067 case WODM_GETPITCH:
1068 case WODM_GETPLAYBACKRATE:
1069 case WODM_GETVOLUME:
1070 case WODM_OPEN:
1071 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
1072 break;
1074 case WODM_GETDEVCAPS:
1076 LPWAVEOUTCAPSA woc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEOUTCAPS16) + sizeof(WAVEOUTCAPSA));
1077 LPWAVEOUTCAPS16 woc16 = PTR_SEG_TO_LIN(*lpParam1);
1079 if (woc32) {
1080 *(LPWAVEOUTCAPS16*)woc32 = woc16;
1081 woc32 = (LPWAVEOUTCAPSA)((LPSTR)woc32 + sizeof(LPWAVEOUTCAPS16));
1082 *lpParam1 = (DWORD)woc32;
1083 *lpParam2 = sizeof(WAVEOUTCAPSA);
1085 ret = MMDRV_MAP_OKMEM;
1086 } else {
1087 ret = MMDRV_MAP_NOMEM;
1090 break;
1091 case WODM_GETPOS:
1093 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
1094 LPMMTIME16 mmt16 = PTR_SEG_TO_LIN(*lpParam1);
1096 if (mmt32) {
1097 *(LPMMTIME16*)mmt32 = mmt16;
1098 mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
1100 mmt32->wType = mmt16->wType;
1101 *lpParam1 = (DWORD)mmt32;
1102 *lpParam2 = sizeof(MMTIME);
1104 ret = MMDRV_MAP_OKMEM;
1105 } else {
1106 ret = MMDRV_MAP_NOMEM;
1109 break;
1110 case WODM_PREPARE:
1112 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
1113 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(*lpParam1);
1115 if (wh32) {
1116 *(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
1117 wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
1118 wh32->lpData = PTR_SEG_TO_LIN(wh16->lpData);
1119 wh32->dwBufferLength = wh16->dwBufferLength;
1120 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1121 wh32->dwUser = wh16->dwUser;
1122 wh32->dwFlags = wh16->dwFlags;
1123 wh32->dwLoops = wh16->dwLoops;
1124 /* FIXME: nothing on wh32->lpNext */
1125 /* could link the wh32->lpNext at this level for memory house keeping */
1126 wh16->lpNext = wh32; /* for reuse in unprepare and write */
1127 *lpParam1 = (DWORD)wh32;
1128 *lpParam2 = sizeof(WAVEHDR);
1130 ret = MMDRV_MAP_OKMEM;
1131 } else {
1132 ret = MMDRV_MAP_NOMEM;
1135 break;
1136 case WODM_UNPREPARE:
1137 case WODM_WRITE:
1139 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(*lpParam1);
1140 LPWAVEHDR wh32 = (LPWAVEHDR)wh16->lpNext;
1142 *lpParam1 = (DWORD)wh32;
1143 *lpParam2 = sizeof(WAVEHDR);
1144 ret = MMDRV_MAP_OKMEM;
1146 break;
1147 default:
1148 FIXME("NIY: no conversion yet for %u\n", wMsg);
1149 break;
1151 return ret;
1154 /**************************************************************************
1155 * MMDRV_WaveOut_UnMap16To32A [internal]
1157 static MMDRV_MapType MMDRV_WaveOut_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1159 MMDRV_MapType ret = MMDRV_MAP_MSGERROR;
1161 switch (wMsg) {
1162 /* nothing to do */
1163 case WODM_BREAKLOOP:
1164 case WODM_CLOSE:
1165 case WODM_GETNUMDEVS:
1166 case WODM_PAUSE:
1167 case WODM_RESET:
1168 case WODM_RESTART:
1169 case WODM_SETPITCH:
1170 case WODM_SETPLAYBACKRATE:
1171 case WODM_SETVOLUME:
1172 ret = MMDRV_MAP_OK;
1173 break;
1175 case WODM_GETPITCH:
1176 case WODM_GETPLAYBACKRATE:
1177 case WODM_GETVOLUME:
1178 case WODM_OPEN:
1179 FIXME("Shouldn't be used: those 16 bit functions use the 32 bit interface\n");
1180 break;
1182 case WODM_GETDEVCAPS:
1184 LPWAVEOUTCAPSA woc32 = (LPWAVEOUTCAPSA)(*lpParam1);
1185 LPWAVEOUTCAPS16 woc16 = *(LPWAVEOUTCAPS16*)((LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
1187 woc16->wMid = woc32->wMid;
1188 woc16->wPid = woc32->wPid;
1189 woc16->vDriverVersion = woc32->vDriverVersion;
1190 strcpy(woc16->szPname, woc32->szPname);
1191 woc16->dwFormats = woc32->dwFormats;
1192 woc16->wChannels = woc32->wChannels;
1193 woc16->dwSupport = woc32->dwSupport;
1194 HeapFree(GetProcessHeap(), 0, (LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
1195 ret = MMDRV_MAP_OK;
1197 break;
1198 case WODM_GETPOS:
1200 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
1201 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
1203 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
1204 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
1205 ret = MMDRV_MAP_OK;
1207 break;
1208 case WODM_PREPARE:
1209 case WODM_UNPREPARE:
1210 case WODM_WRITE:
1212 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
1213 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(*(LPWAVEHDR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
1215 assert(wh16->lpNext == wh32);
1216 wh16->dwBufferLength = wh32->dwBufferLength;
1217 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1218 wh16->dwUser = wh32->dwUser;
1219 wh16->dwFlags = wh32->dwFlags;
1220 wh16->dwLoops = wh32->dwLoops;
1222 if (wMsg == WODM_UNPREPARE) {
1223 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
1224 wh16->lpNext = 0;
1226 ret = MMDRV_MAP_OK;
1228 break;
1229 default:
1230 FIXME("NIY: no conversion yet for %u\n", wMsg);
1231 break;
1233 return ret;
1236 /**************************************************************************
1237 * MMDRV_WaveOut_Map32ATo16 [internal]
1239 static MMDRV_MapType MMDRV_WaveOut_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1241 MMDRV_MapType ret;
1243 switch (wMsg) {
1244 /* nothing to do */
1245 case WODM_BREAKLOOP:
1246 case WODM_CLOSE:
1247 case WODM_GETNUMDEVS:
1248 case WODM_PAUSE:
1249 case WODM_RESET:
1250 case WODM_RESTART:
1251 case WODM_SETPITCH:
1252 case WODM_SETPLAYBACKRATE:
1253 case WODM_SETVOLUME:
1254 ret = MMDRV_MAP_OK;
1255 break;
1257 case WODM_GETDEVCAPS:
1259 LPWAVEOUTCAPSA woc32 = (LPWAVEOUTCAPSA)*lpParam1;
1260 LPSTR ptr = SEGPTR_ALLOC(sizeof(LPWAVEOUTCAPSA) + sizeof(WAVEOUTCAPS16));
1262 if (ptr) {
1263 *(LPWAVEOUTCAPSA*)ptr = woc32;
1264 ret = MMDRV_MAP_OKMEM;
1265 } else {
1266 ret = MMDRV_MAP_NOMEM;
1268 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEOUTCAPSA);
1269 *lpParam2 = sizeof(WAVEOUTCAPS16);
1271 break;
1272 case WODM_GETPITCH:
1273 FIXME("NIY: no conversion yet\n");
1274 ret = MMDRV_MAP_MSGERROR;
1275 break;
1276 case WODM_GETPLAYBACKRATE:
1277 FIXME("NIY: no conversion yet\n");
1278 ret = MMDRV_MAP_MSGERROR;
1279 break;
1280 case WODM_GETPOS:
1282 LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
1283 LPSTR ptr = SEGPTR_ALLOC(sizeof(LPMMTIME) + sizeof(MMTIME16));
1284 LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
1286 if (ptr) {
1287 *(LPMMTIME*)ptr = mmt32;
1288 mmt16->wType = mmt32->wType;
1289 ret = MMDRV_MAP_OKMEM;
1290 } else {
1291 ret = MMDRV_MAP_NOMEM;
1293 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPMMTIME);
1294 *lpParam2 = sizeof(MMTIME16);
1296 break;
1297 case WODM_GETVOLUME:
1298 FIXME("NIY: no conversion yet\n");
1299 ret = MMDRV_MAP_MSGERROR;
1300 break;
1301 case WODM_OPEN:
1303 LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
1304 int sz = sizeof(WAVEFORMATEX);
1305 LPVOID ptr;
1306 LPWAVEOPENDESC16 wod16;
1308 /* allocated data are mapped as follows:
1309 LPWAVEOPENDESC ptr to orig lParam1
1310 DWORD ptr to orig dwUser, which is a pointer to DWORD:driver dwInstance
1311 DWORD dwUser passed to driver
1312 WAVEOPENDESC16 wod16: openDesc passed to driver
1313 WAVEFORMATEX openDesc->lpFormat passed to driver
1314 xxx extra bytes to WAVEFORMATEX
1316 if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
1317 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize, wod32->lpFormat->wFormatTag);
1318 sz += ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize;
1321 ptr = SEGPTR_ALLOC(sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
1323 if (ptr) {
1324 *(LPWAVEOPENDESC*)ptr = wod32;
1325 *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
1326 wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
1328 wod16->hWave = wod32->hWave;
1329 wod16->lpFormat = (LPWAVEFORMATEX)((DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
1330 memcpy(wod16 + 1, wod32->lpFormat, sz);
1332 wod16->dwCallback = wod32->dwCallback;
1333 wod16->dwInstance = wod32->dwInstance;
1334 wod16->uMappedDeviceID = wod32->uMappedDeviceID;
1335 wod16->dnDevNode = wod32->dnDevNode;
1337 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
1338 *lpdwUser = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
1340 ret = MMDRV_MAP_OKMEM;
1341 } else {
1342 ret = MMDRV_MAP_NOMEM;
1345 break;
1346 case WODM_PREPARE:
1348 LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
1349 LPWAVEHDR wh16;
1350 LPVOID ptr = SEGPTR_ALLOC(sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
1352 if (ptr) {
1353 *(LPWAVEHDR*)ptr = wh32;
1354 wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
1355 wh16->lpData = (LPSTR)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
1356 /* data will be copied on WODM_WRITE */
1357 wh16->dwBufferLength = wh32->dwBufferLength;
1358 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1359 wh16->dwUser = wh32->dwUser;
1360 wh16->dwFlags = wh32->dwFlags;
1361 wh16->dwLoops = wh32->dwLoops;
1362 /* FIXME: nothing on wh32->lpNext */
1363 /* could link the wh32->lpNext at this level for memory house keeping */
1364 wh32->lpNext = wh16; /* for reuse in unprepare and write */
1365 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1366 (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
1367 wh32->dwBufferLength, (DWORD)wh32->lpData);
1368 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR);
1369 *lpParam2 = sizeof(WAVEHDR);
1371 ret = MMDRV_MAP_OKMEM;
1372 } else {
1373 ret = MMDRV_MAP_NOMEM;
1376 break;
1377 case WODM_UNPREPARE:
1378 case WODM_WRITE:
1380 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
1381 LPWAVEHDR wh16 = wh32->lpNext;
1382 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1384 assert(*(LPWAVEHDR*)ptr == wh32);
1386 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1387 (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
1388 wh32->dwBufferLength, (DWORD)wh32->lpData);
1390 if (wMsg == WODM_WRITE)
1391 memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
1393 *lpParam1 = (DWORD)SEGPTR_GET(ptr) + sizeof(LPWAVEHDR);
1394 *lpParam2 = sizeof(WAVEHDR);
1395 ret = MMDRV_MAP_OKMEM;
1397 break;
1398 default:
1399 FIXME("NIY: no conversion yet\n");
1400 ret = MMDRV_MAP_MSGERROR;
1401 break;
1403 return ret;
1406 /**************************************************************************
1407 * MMDRV_WaveOut_UnMap32ATo16 [internal]
1409 static MMDRV_MapType MMDRV_WaveOut_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1411 MMDRV_MapType ret;
1413 switch (wMsg) {
1414 /* nothing to do */
1415 case WODM_BREAKLOOP:
1416 case WODM_CLOSE:
1417 case WODM_GETNUMDEVS:
1418 case WODM_PAUSE:
1419 case WODM_RESET:
1420 case WODM_RESTART:
1421 case WODM_SETPITCH:
1422 case WODM_SETPLAYBACKRATE:
1423 case WODM_SETVOLUME:
1424 ret = MMDRV_MAP_OK;
1425 break;
1427 case WODM_GETDEVCAPS:
1429 LPWAVEOUTCAPS16 woc16 = (LPWAVEOUTCAPS16)PTR_SEG_TO_LIN(*lpParam1);
1430 LPSTR ptr = (LPSTR)woc16 - sizeof(LPWAVEOUTCAPSA);
1431 LPWAVEOUTCAPSA woc32 = *(LPWAVEOUTCAPSA*)ptr;
1433 woc32->wMid = woc16->wMid;
1434 woc32->wPid = woc16->wPid;
1435 woc32->vDriverVersion = woc16->vDriverVersion;
1436 strcpy(woc32->szPname, woc16->szPname);
1437 woc32->dwFormats = woc16->dwFormats;
1438 woc32->wChannels = woc16->wChannels;
1439 woc32->dwSupport = woc16->dwSupport;
1440 if (!SEGPTR_FREE(ptr))
1441 FIXME("bad free line=%d\n", __LINE__);
1442 ret = MMDRV_MAP_OK;
1444 break;
1445 case WODM_GETPITCH:
1446 FIXME("NIY: no conversion yet\n");
1447 ret = MMDRV_MAP_MSGERROR;
1448 break;
1449 case WODM_GETPLAYBACKRATE:
1450 FIXME("NIY: no conversion yet\n");
1451 ret = MMDRV_MAP_MSGERROR;
1452 break;
1453 case WODM_GETPOS:
1455 LPMMTIME16 mmt16 = (LPMMTIME16)PTR_SEG_TO_LIN(*lpParam1);
1456 LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
1457 LPMMTIME mmt32 = *(LPMMTIME*)ptr;
1459 MMSYSTEM_MMTIME16to32(mmt32, mmt16);
1461 if (!SEGPTR_FREE(ptr))
1462 FIXME("bad free line=%d\n", __LINE__);
1464 ret = MMDRV_MAP_OK;
1466 break;
1467 case WODM_OPEN:
1469 LPWAVEOPENDESC16 wod16 = (LPWAVEOPENDESC16)PTR_SEG_TO_LIN(*lpParam1);
1470 LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
1471 LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
1473 wod32->uMappedDeviceID = wod16->uMappedDeviceID;
1474 **(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
1476 if (!SEGPTR_FREE(ptr))
1477 FIXME("bad free line=%d\n", __LINE__);
1479 ret = MMDRV_MAP_OK;
1481 break;
1482 case WODM_PREPARE:
1483 case WODM_UNPREPARE:
1484 case WODM_WRITE:
1486 LPWAVEHDR wh16 = (LPWAVEHDR)PTR_SEG_TO_LIN(*lpParam1);
1487 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1488 LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
1490 assert(wh32->lpNext == wh16);
1491 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1492 wh32->dwUser = wh16->dwUser;
1493 wh32->dwFlags = wh16->dwFlags;
1494 wh32->dwLoops = wh16->dwLoops;
1496 if (wMsg == WODM_UNPREPARE) {
1497 if (!SEGPTR_FREE(ptr))
1498 FIXME("bad free line=%d\n", __LINE__);
1499 wh32->lpNext = 0;
1501 ret = MMDRV_MAP_OK;
1503 break;
1504 case WODM_GETVOLUME:
1505 FIXME("NIY: no conversion yet\n");
1506 ret = MMDRV_MAP_MSGERROR;
1507 break;
1508 default:
1509 FIXME("NIY: no conversion yet\n");
1510 ret = MMDRV_MAP_MSGERROR;
1511 break;
1513 return ret;
1516 /**************************************************************************
1517 * MMDRV_WaveOut_Callback [internal]
1519 static void CALLBACK MMDRV_WaveOut_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
1521 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
1523 switch (uMsg) {
1524 case WOM_OPEN:
1525 case WOM_CLOSE:
1526 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1527 break;
1528 case WOM_DONE:
1529 if (mld->bFrom32 && !MMDrvs[mld->mmdIndex].bIs32) {
1530 /* initial map is: 32 => 16 */
1531 LPWAVEHDR wh16 = (LPWAVEHDR)PTR_SEG_TO_LIN(dwParam1);
1532 LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
1534 dwParam1 = (DWORD)wh32;
1535 wh32->dwFlags = wh16->dwFlags;
1536 } else if (!mld->bFrom32 && MMDrvs[mld->mmdIndex].bIs32) {
1537 /* initial map is: 16 => 32 */
1538 LPWAVEHDR wh32 = (LPWAVEHDR)(dwParam1);
1539 LPWAVEHDR segwh16 = *(LPWAVEHDR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
1540 LPWAVEHDR wh16 = PTR_SEG_TO_LIN(segwh16);
1542 dwParam1 = (DWORD)segwh16;
1543 wh16->dwFlags = wh32->dwFlags;
1545 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1546 break;
1547 default:
1548 ERR("Unknown msg %u\n", uMsg);
1551 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
1554 #define A(_x,_y) {#_y, _x, \
1555 MMDRV_##_y##_Map16To32A, MMDRV_##_y##_UnMap16To32A, \
1556 MMDRV_##_y##_Map32ATo16, MMDRV_##_y##_UnMap32ATo16, \
1557 MMDRV_##_y##_Callback, 0, NULL, -1}
1559 /* Note: the indices of this array must match the definitions
1560 * of the MMDRV_???? manifest constants
1562 static WINE_LLTYPE llTypes[MMDRV_MAX] = {
1563 A(TRUE, Aux),
1564 A(FALSE, Mixer),
1565 A(TRUE, MidiIn),
1566 A(TRUE, MidiOut),
1567 A(TRUE, WaveIn),
1568 A(TRUE, WaveOut),
1570 #undef A
1572 /**************************************************************************
1573 * MMDRV_GetNum [internal]
1575 UINT MMDRV_GetNum(UINT type)
1577 assert(type < MMDRV_MAX);
1578 return llTypes[type].wMaxId;
1581 /**************************************************************************
1582 * WINE_Message [internal]
1584 DWORD MMDRV_Message(LPWINE_MLD mld, WORD wMsg, DWORD dwParam1,
1585 DWORD dwParam2, BOOL bFrom32)
1587 LPWINE_MM_DRIVER lpDrv;
1588 DWORD ret;
1589 WINE_MM_DRIVER_PART* part;
1590 WINE_LLTYPE* llType = &llTypes[mld->type];
1591 MMDRV_MapType map;
1592 int devID;
1594 TRACE("(%s %u %u 0x%08lx 0x%08lx 0x%08lx %c)!\n",
1595 llTypes[mld->type].name, mld->uDeviceID, wMsg,
1596 mld->dwDriverInstance, dwParam1, dwParam2, bFrom32?'Y':'N');
1598 if (mld->uDeviceID == (UINT16)-1) {
1599 if (!llType->bSupportMapper) {
1600 WARN("uDev=-1 requested on non-mappable ll type %s\n",
1601 llTypes[mld->type].name);
1602 return MMSYSERR_BADDEVICEID;
1604 devID = -1;
1605 } else {
1606 if (mld->uDeviceID >= llType->wMaxId) {
1607 WARN("uDev(%u) requested >= max (%d)\n", mld->uDeviceID, llType->wMaxId);
1608 return MMSYSERR_BADDEVICEID;
1610 devID = mld->uDeviceID;
1613 lpDrv = &MMDrvs[mld->mmdIndex];
1614 part = &lpDrv->parts[mld->type];
1616 #if 0
1617 /* some sanity checks */
1618 if (!(part->nIDMin <= devID))
1619 ERR("!(part->nIDMin(%d) <= devID(%d))\n", part->nIDMin, devID);
1620 if (!(devID < part->nIDMax))
1621 ERR("!(devID(%d) < part->nIDMax(%d))\n", devID, part->nIDMax);
1622 #endif
1624 if (lpDrv->bIs32) {
1625 assert(part->u.fnMessage32);
1627 if (bFrom32) {
1628 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1629 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
1630 ret = part->u.fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
1631 TRACE("=> %lu\n", ret);
1632 } else {
1633 map = llType->Map16To32A(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
1634 switch (map) {
1635 case MMDRV_MAP_NOMEM:
1636 ret = MMSYSERR_NOMEM;
1637 break;
1638 case MMDRV_MAP_MSGERROR:
1639 FIXME("NIY: no conversion yet 16->32 (%u)\n", wMsg);
1640 ret = MMSYSERR_ERROR;
1641 break;
1642 case MMDRV_MAP_OK:
1643 case MMDRV_MAP_OKMEM:
1644 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1645 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
1646 ret = part->u.fnMessage32(mld->uDeviceID, wMsg, mld->dwDriverInstance,
1647 dwParam1, dwParam2);
1648 TRACE("=> %lu\n", ret);
1649 if (map == MMDRV_MAP_OKMEM)
1650 llType->UnMap16To32A(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
1651 break;
1652 default:
1653 case MMDRV_MAP_PASS:
1654 FIXME("NIY: pass used ?\n");
1655 ret = MMSYSERR_NOTSUPPORTED;
1656 break;
1659 } else {
1660 assert(part->u.fnMessage16);
1662 if (bFrom32) {
1663 map = llType->Map32ATo16(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
1664 switch (map) {
1665 case MMDRV_MAP_NOMEM:
1666 ret = MMSYSERR_NOMEM;
1667 break;
1668 case MMDRV_MAP_MSGERROR:
1669 FIXME("NIY: no conversion yet 32->16 (%u)\n", wMsg);
1670 ret = MMSYSERR_ERROR;
1671 break;
1672 case MMDRV_MAP_OK:
1673 case MMDRV_MAP_OKMEM:
1674 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1675 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
1676 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16, mld->uDeviceID,
1677 wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
1678 TRACE("=> %lu\n", ret);
1679 if (map == MMDRV_MAP_OKMEM)
1680 llType->UnMap32ATo16(wMsg, &mld->dwDriverInstance, &dwParam1, &dwParam2);
1681 break;
1682 default:
1683 case MMDRV_MAP_PASS:
1684 FIXME("NIY: pass used ?\n");
1685 ret = MMSYSERR_NOTSUPPORTED;
1686 break;
1688 } else {
1689 TRACE("Calling message(dev=%u msg=%u usr=0x%08lx p1=0x%08lx p2=0x%08lx\n",
1690 mld->uDeviceID, wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
1691 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16, mld->uDeviceID,
1692 wMsg, mld->dwDriverInstance, dwParam1, dwParam2);
1693 TRACE("=> %lu\n", ret);
1696 return ret;
1699 /**************************************************************************
1700 * MMDRV_Alloc [internal]
1702 LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
1703 DWORD* dwCallback, DWORD* dwInstance, BOOL bFrom32)
1705 LPWINE_MLD mld;
1707 if ((*hndl = USER_HEAP_ALLOC(size)) == 0)
1708 return NULL;
1710 mld = (LPWINE_MLD) USER_HEAP_LIN_ADDR(*hndl);
1711 if (!mld) return NULL;
1712 mld->type = type;
1713 if ((UINT)*hndl < MMDRV_GetNum(type) || HIWORD(*hndl) != 0) {
1714 /* FIXME: those conditions must be fulfilled so that:
1715 * - we can distinguish between device IDs and handles
1716 * - we can use handles as 16 or 32 bit entities
1718 ERR("Shouldn't happen. Bad allocation scheme\n");
1721 mld->bFrom32 = bFrom32;
1722 mld->dwFlags = HIWORD(*dwFlags);
1723 mld->dwCallback = *dwCallback;
1724 mld->dwClientInstance = *dwInstance;
1726 *dwFlags = LOWORD(*dwFlags) | CALLBACK_FUNCTION;
1727 *dwCallback = (DWORD)llTypes[type].Callback;
1728 *dwInstance = (DWORD)mld; /* FIXME: wouldn't some 16 bit drivers only use the loword ? */
1730 return mld;
1733 /**************************************************************************
1734 * MMDRV_Free [internal]
1736 void MMDRV_Free(HANDLE hndl, LPWINE_MLD mld)
1738 USER_HEAP_FREE(hndl);
1741 /**************************************************************************
1742 * MMDRV_Open [internal]
1744 DWORD MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwFlags)
1746 DWORD dwRet = MMSYSERR_BADDEVICEID;
1747 DWORD dwInstance;
1748 WINE_LLTYPE* llType = &llTypes[mld->type];
1750 mld->dwDriverInstance = (DWORD)&dwInstance;
1752 if (mld->uDeviceID == (UINT)-1) {
1753 TRACE("MAPPER mode requested !\n");
1754 /* check if mapper is supported by type */
1755 if (llType->bSupportMapper) {
1756 if (llType->nMapper == -1) {
1757 /* no driver for mapper has been loaded, try a dumb implementation */
1758 TRACE("No mapper loaded, doing it by hand\n");
1759 for (mld->uDeviceID = 0; mld->uDeviceID < llType->wMaxId; mld->uDeviceID++) {
1760 if ((dwRet = MMDRV_Open(mld, wMsg, dwParam1, dwFlags)) == MMSYSERR_NOERROR) {
1761 /* to share this function epilog */
1762 dwInstance = mld->dwDriverInstance;
1763 break;
1766 } else {
1767 mld->uDeviceID = (UINT16)0/*-1*/;
1768 mld->mmdIndex = llType->lpMlds[-1].mmdIndex;
1769 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
1770 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags, TRUE);
1773 } else {
1774 if (mld->uDeviceID < llType->wMaxId) {
1775 mld->mmdIndex = llType->lpMlds[mld->uDeviceID].mmdIndex;
1776 TRACE("Setting mmdIndex to %u\n", mld->mmdIndex);
1777 dwRet = MMDRV_Message(mld, wMsg, dwParam1, dwFlags, TRUE);
1780 if (dwRet == MMSYSERR_NOERROR)
1781 mld->dwDriverInstance = dwInstance;
1782 return dwRet;
1785 /**************************************************************************
1786 * MMDRV_Close [internal]
1788 DWORD MMDRV_Close(LPWINE_MLD mld, UINT wMsg)
1790 return MMDRV_Message(mld, wMsg, 0L, 0L, TRUE);
1793 /**************************************************************************
1794 * MMDRV_GetVByID [internal]
1796 LPWINE_MLD MMDRV_GetByID(UINT uDevID, UINT type)
1798 return (uDevID < llTypes[type].wMaxId) ?
1799 &llTypes[type].lpMlds[uDevID] : NULL;
1802 /**************************************************************************
1803 * MMDRV_Get [internal]
1805 LPWINE_MLD MMDRV_Get(HANDLE hndl, UINT type, BOOL bCanBeID)
1807 LPWINE_MLD mld = NULL;
1809 assert(type < MMDRV_MAX);
1811 if ((UINT)hndl >= llTypes[type].wMaxId) {
1812 mld = (LPWINE_MLD)USER_HEAP_LIN_ADDR(hndl);
1814 if (mld && mld->type != type) mld = NULL;
1815 } else if (bCanBeID) {
1816 mld = MMDRV_GetByID((UINT)hndl, type);
1818 return mld;
1821 /**************************************************************************
1822 * MMDRV_GetRelated [internal]
1824 LPWINE_MLD MMDRV_GetRelated(HANDLE hndl, UINT srcType,
1825 BOOL bSrcCanBeID, UINT dstType)
1827 LPWINE_MLD mld;
1829 if ((mld = MMDRV_Get(hndl, srcType, bSrcCanBeID)) != NULL) {
1830 WINE_MM_DRIVER_PART* part = &MMDrvs[mld->mmdIndex].parts[dstType];
1831 if (part->nIDMin < part->nIDMax)
1832 return MMDRV_GetByID(part->nIDMin, dstType);
1834 return NULL;
1837 /**************************************************************************
1838 * MMDRV_PhysicalFeatures [internal]
1840 UINT MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1,
1841 DWORD dwParam2)
1843 WINE_MM_DRIVER* lpDrv = &MMDrvs[mld->mmdIndex];
1845 TRACE("(%p, %04x, %08lx, %08lx)\n", mld, uMsg, dwParam1, dwParam2);
1847 /* all those function calls are undocumented */
1848 switch (uMsg) {
1849 case 0x801:
1850 strncpy((LPSTR)dwParam1, lpDrv->name, LOWORD(dwParam2));
1851 break;
1852 case 0x802:
1853 *(LPDWORD)dwParam1 = 0L; /* should be DevNode */
1854 break;
1855 case 0x803: /* dont know */
1856 WARN("NIY 0x803\n");
1857 break;
1858 case 0x804:
1859 WARN("NIY call VxD\n");
1860 /* should call VxD MMDEVLDR with (DevNode, dwParam1 and dwParam2) as pmts
1861 * dwParam1 is buffer and dwParam2 is sizeof buffer
1862 * I don't know where the result is stored though
1864 break;
1865 case 0x805:
1866 return (lpDrv->bIsMapper) ? 2 : 0;
1867 default:
1868 WARN("Unknown call %04x\n", uMsg);
1869 return MMSYSERR_INVALPARAM;
1871 return 0L;
1874 /**************************************************************************
1875 * MMDRV_InitPerType [internal]
1877 static BOOL MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv, UINT num,
1878 UINT type, UINT wMsg)
1880 WINE_MM_DRIVER_PART* part = &lpDrv->parts[type];
1881 DWORD ret;
1882 UINT count = 0;
1883 int i, k;
1885 part->nIDMin = part->nIDMax = 0;
1887 /* for DRVM_INIT and DRVM_ENABLE, dwParam2 should be PnP node */
1888 /* the DRVM_ENABLE is only required when the PnP node is non zero */
1890 if (lpDrv->bIs32 && part->u.fnMessage32) {
1891 ret = part->u.fnMessage32(0, DRVM_INIT, 0L, 0L, 0L);
1892 TRACE("DRVM_INIT => %08lx\n", ret);
1893 #if 0
1894 ret = part->u.fnMessage32(0, DRVM_ENABLE, 0L, 0L, 0L);
1895 TRACE("DRVM_ENABLE => %08lx\n", ret);
1896 #endif
1897 count = part->u.fnMessage32(0, wMsg, 0L, 0L, 0L);
1900 if (!lpDrv->bIs32 && part->u.fnMessage16) {
1901 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16,
1902 0, DRVM_INIT, 0L, 0L, 0L);
1903 TRACE("DRVM_INIT => %08lx\n", ret);
1904 #if 0
1905 ret = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16,
1906 0, DRVM_ENABLE, 0L, 0L, 0L);
1907 TRACE("DRVM_ENABLE => %08lx\n", ret);
1908 #endif
1909 count = MMDRV_CallTo16_word_wwlll((FARPROC16)part->u.fnMessage16,
1910 0, wMsg, 0L, 0L, 0L);
1913 TRACE("Got %u dev for (%s:%s)\n", count, lpDrv->name, llTypes[type].name);
1914 if (count == 0)
1915 return FALSE;
1917 /* got some drivers */
1918 if (lpDrv->bIsMapper) {
1919 if (llTypes[type].nMapper != -1)
1920 ERR("Two mappers for type %s (%d, %s)\n",
1921 llTypes[type].name, llTypes[type].nMapper, lpDrv->name);
1922 if (count > 1)
1923 ERR("Strange: mapper with %d > 1 devices\n", count);
1924 llTypes[type].nMapper = num;
1925 } else {
1926 part->nIDMin = llTypes[type].wMaxId;
1927 llTypes[type].wMaxId += count;
1928 part->nIDMax = llTypes[type].wMaxId;
1930 TRACE("Setting min=%d max=%d (ttop=%d) for (%s:%s)\n",
1931 part->nIDMin, part->nIDMax, llTypes[type].wMaxId,
1932 lpDrv->name, llTypes[type].name);
1933 /* realloc translation table */
1934 llTypes[type].lpMlds = (LPWINE_MLD)
1935 HeapReAlloc(SystemHeap, 0, (llTypes[type].lpMlds) ? llTypes[type].lpMlds - 1 : NULL,
1936 sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
1937 /* re-build the translation table */
1938 if (llTypes[type].nMapper != -1) {
1939 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].name, -1, MMDrvs[llTypes[type].nMapper].name);
1940 llTypes[type].lpMlds[-1].uDeviceID = -1;
1941 llTypes[type].lpMlds[-1].type = type;
1942 llTypes[type].lpMlds[-1].mmdIndex = llTypes[type].nMapper;
1943 llTypes[type].lpMlds[-1].dwDriverInstance = 0;
1945 for (i = k = 0; i <= num; i++) {
1946 while (MMDrvs[i].parts[type].nIDMin <= k && k < MMDrvs[i].parts[type].nIDMax) {
1947 TRACE("%s:Trans[%d] -> %s\n", llTypes[type].name, k, MMDrvs[i].name);
1948 llTypes[type].lpMlds[k].uDeviceID = k;
1949 llTypes[type].lpMlds[k].type = type;
1950 llTypes[type].lpMlds[k].mmdIndex = i;
1951 llTypes[type].lpMlds[k].dwDriverInstance = 0;
1952 k++;
1955 return TRUE;
1958 /**************************************************************************
1959 * MMDRV_Install [internal]
1961 static BOOL MMDRV_Install(LPCSTR name, int num, BOOL bIsMapper)
1963 int count = 0;
1964 char buffer[128];
1965 HMODULE hModule;
1966 LPWINE_MM_DRIVER lpDrv = &MMDrvs[num];
1968 TRACE("('%s');\n", name);
1970 memset(lpDrv, 0, sizeof(*lpDrv));
1972 /* First load driver */
1973 if ((lpDrv->hDrvr = OpenDriverA(name, 0, 0)) == 0) {
1974 WARN("Couldn't open driver '%s'\n", name);
1975 return FALSE;
1978 /* Then look for xxxMessage functions */
1979 #define AA(_w,_x,_y,_z) \
1980 func = (WINEMM_msgFunc##_y) _z (hModule, #_x); \
1981 if (func != NULL) \
1982 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
1983 TRACE("Got %d bit func '%s'\n", _y, #_x); }
1985 if ((DRIVER_GetType(lpDrv->hDrvr) & WINE_DI_TYPE_MASK) == WINE_DI_TYPE_32) {
1986 WINEMM_msgFunc32 func;
1988 lpDrv->bIs32 = TRUE;
1989 if ((hModule = GetDriverModuleHandle(lpDrv->hDrvr))) {
1990 #define A(_x,_y) AA(_x,_y,32,GetProcAddress)
1991 A(MMDRV_AUX, auxMessage);
1992 A(MMDRV_MIXER, mixMessage);
1993 A(MMDRV_MIDIIN, midMessage);
1994 A(MMDRV_MIDIOUT, modMessage);
1995 A(MMDRV_WAVEIN, widMessage);
1996 A(MMDRV_WAVEOUT, wodMessage);
1997 #undef A
1999 } else {
2000 WINEMM_msgFunc16 func;
2003 * DESCRIPTION 'wave,aux,mixer:Creative Labs Sound Blaster 16 Driver'
2004 * The beginning of the module description indicates the driver supports
2005 * waveform, auxiliary, and mixer devices. Use one of the following
2006 * device-type names, followed by a colon (:) to indicate the type of
2007 * device your driver supports. If the driver supports more than one
2008 * type of device, separate each device-type name with a comma (,).
2010 * wave for waveform audio devices
2011 * wavemapper for wave mappers
2012 * midi for MIDI audio devices
2013 * midimapper for midi mappers
2014 * aux for auxiliary audio devices
2015 * mixer for mixer devices
2018 lpDrv->bIs32 = FALSE;
2019 if ((hModule = GetDriverModuleHandle16(lpDrv->hDrvr))) {
2020 #define A(_x,_y) AA(_x,_y,16,WIN32_GetProcAddress16)
2021 A(MMDRV_AUX, auxMessage);
2022 A(MMDRV_MIXER, mixMessage);
2023 A(MMDRV_MIDIIN, midMessage);
2024 A(MMDRV_MIDIOUT, modMessage);
2025 A(MMDRV_WAVEIN, widMessage);
2026 A(MMDRV_WAVEOUT, wodMessage);
2027 #undef A
2030 #undef AA
2032 if (TRACE_ON(mmsys)) {
2033 if ((lpDrv->bIs32) ? MMDRV_GetDescription32(name, buffer, sizeof(buffer)) :
2034 MMDRV_GetDescription16(name, buffer, sizeof(buffer)))
2035 TRACE("%s => %s\n", name, buffer);
2036 else
2037 TRACE("%s => No description\n", name);
2040 if (!count) {
2041 CloseDriver(lpDrv->hDrvr, 0, 0);
2042 WARN("No message functions found\n");
2043 return FALSE;
2046 /* FIXME: being a mapper or not should be known by another way */
2047 /* it's known for NE drvs (the description is of the form '*mapper: *'
2048 * I don't have any clue for PE drvs
2049 * on Win 9x, the value is gotten from the key mappable under
2050 * HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\MediaResources\
2052 lpDrv->bIsMapper = bIsMapper;
2053 lpDrv->name = HEAP_strdupA(GetProcessHeap(), 0, name);
2055 /* Finish init and get the count of the devices */
2056 MMDRV_InitPerType(lpDrv, num, MMDRV_AUX, AUXDM_GETNUMDEVS);
2057 MMDRV_InitPerType(lpDrv, num, MMDRV_MIXER, MXDM_GETNUMDEVS);
2058 MMDRV_InitPerType(lpDrv, num, MMDRV_MIDIIN, MIDM_GETNUMDEVS);
2059 MMDRV_InitPerType(lpDrv, num, MMDRV_MIDIOUT, MODM_GETNUMDEVS);
2060 MMDRV_InitPerType(lpDrv, num, MMDRV_WAVEIN, WIDM_GETNUMDEVS);
2061 MMDRV_InitPerType(lpDrv, num, MMDRV_WAVEOUT, WODM_GETNUMDEVS);
2062 /* FIXME: if all those func calls return FALSE, then the driver must be unloaded */
2063 return TRUE;
2066 /**************************************************************************
2067 * MMDRV_Init [internal]
2069 BOOL MMDRV_Init(void)
2071 int num = 0;
2073 /* FIXME: this should be moved to init files;
2074 * - either .winerc/wine.conf
2075 * - or made of registry keys
2076 * this is a temporary hack, shall be removed anytime now
2078 /* first load hardware drivers */
2079 if (MMDRV_Install("wineoss.drv", num, FALSE)) num++;
2081 /* finish with mappers */
2082 if (MMDRV_Install("msacm.drv", num, TRUE )) num++;
2083 if (MMDRV_Install("midimap.drv", num, TRUE )) num++;
2086 /* be sure that size of MMDrvs matches the max number of loadable drivers !!
2087 * if not just increase size of MMDrvs */
2088 assert(num <= sizeof(MMDrvs)/sizeof(MMDrvs[0]));
2090 return TRUE;