2 * MMSYSTEM MCI and low level mapping functions
4 * Copyright 1999 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/winbase16.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
37 /**************************************************************************
38 * MMDRV_Callback [internal]
40 static void MMDRV_Callback(LPWINE_MLD mld, HDRVR hDev, UINT uMsg, DWORD dwParam1, DWORD dwParam2)
42 TRACE("CB (*%08lx)(%p %08x %08lx %08lx %08lx\n",
43 mld->dwCallback, hDev, uMsg, mld->dwClientInstance, dwParam1, dwParam2);
45 if (!mld->bFrom32 && (mld->dwFlags & DCB_TYPEMASK) == DCB_FUNCTION)
48 /* 16 bit func, call it */
49 TRACE("Function (16 bit) !\n");
51 args[7] = HDRVR_16(hDev);
53 args[5] = HIWORD(mld->dwClientInstance);
54 args[4] = LOWORD(mld->dwClientInstance);
55 args[3] = HIWORD(dwParam1);
56 args[2] = LOWORD(dwParam1);
57 args[1] = HIWORD(dwParam2);
58 args[0] = LOWORD(dwParam2);
59 WOWCallback16Ex( mld->dwCallback, WCB16_PASCAL, sizeof(args), args, NULL );
61 DriverCallback(mld->dwCallback, mld->dwFlags, hDev, uMsg,
62 mld->dwClientInstance, dwParam1, dwParam2);
66 /* =================================
68 * ================================= */
70 /**************************************************************************
71 * MMDRV_Aux_Map16To32W [internal]
73 static WINMM_MapType MMDRV_Aux_Map16To32W (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
75 return WINMM_MAP_MSGERROR;
78 /**************************************************************************
79 * MMDRV_Aux_UnMap16To32W [internal]
81 static WINMM_MapType MMDRV_Aux_UnMap16To32W(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
83 return WINMM_MAP_MSGERROR;
86 /**************************************************************************
87 * MMDRV_Aux_Map32WTo16 [internal]
89 static WINMM_MapType MMDRV_Aux_Map32WTo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
91 return WINMM_MAP_MSGERROR;
94 /**************************************************************************
95 * MMDRV_Aux_UnMap32WTo16 [internal]
97 static WINMM_MapType MMDRV_Aux_UnMap32WTo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
100 case AUXDM_GETDEVCAPS:
101 lpCaps->wMid = ac16.wMid;
102 lpCaps->wPid = ac16.wPid;
103 lpCaps->vDriverVersion = ac16.vDriverVersion;
104 strcpy(lpCaps->szPname, ac16.szPname);
105 lpCaps->wTechnology = ac16.wTechnology;
106 lpCaps->dwSupport = ac16.dwSupport;
108 return WINMM_MAP_MSGERROR;
111 /**************************************************************************
112 * MMDRV_Aux_Callback [internal]
114 static void CALLBACK MMDRV_Aux_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
116 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
119 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
122 /* =================================
123 * M I X E R M A P P E R S
124 * ================================= */
126 /**************************************************************************
127 * xMMDRV_Mixer_Map16To32W [internal]
129 static WINMM_MapType MMDRV_Mixer_Map16To32W (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
131 return WINMM_MAP_MSGERROR;
134 /**************************************************************************
135 * MMDRV_Mixer_UnMap16To32W [internal]
137 static WINMM_MapType MMDRV_Mixer_UnMap16To32W(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
141 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
143 if (ret == MMSYSERR_NOERROR) {
144 mixcaps->wMid = micA.wMid;
145 mixcaps->wPid = micA.wPid;
146 mixcaps->vDriverVersion = micA.vDriverVersion;
147 strcpy(mixcaps->szPname, micA.szPname);
148 mixcaps->fdwSupport = micA.fdwSupport;
149 mixcaps->cDestinations = micA.cDestinations;
153 return WINMM_MAP_MSGERROR;
156 /**************************************************************************
157 * MMDRV_Mixer_Map32WTo16 [internal]
159 static WINMM_MapType MMDRV_Mixer_Map32WTo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
161 return WINMM_MAP_MSGERROR;
164 /**************************************************************************
165 * MMDRV_Mixer_UnMap32WTo16 [internal]
167 static WINMM_MapType MMDRV_Mixer_UnMap32WTo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
169 return WINMM_MAP_MSGERROR;
172 /**************************************************************************
173 * MMDRV_Mixer_Callback [internal]
175 static void CALLBACK MMDRV_Mixer_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
177 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
180 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
183 /* =================================
184 * M I D I I N M A P P E R S
185 * ================================= */
187 /**************************************************************************
188 * MMDRV_MidiIn_Map16To32W [internal]
190 static WINMM_MapType MMDRV_MidiIn_Map16To32W (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
192 return WINMM_MAP_MSGERROR;
195 /**************************************************************************
196 * MMDRV_MidiIn_UnMap16To32W [internal]
198 static WINMM_MapType MMDRV_MidiIn_UnMap16To32W(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
200 return WINMM_MAP_MSGERROR;
203 /**************************************************************************
204 * MMDRV_MidiIn_Map32WTo16 [internal]
206 static WINMM_MapType MMDRV_MidiIn_Map32WTo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
208 return WINMM_MAP_MSGERROR;
211 /**************************************************************************
212 * MMDRV_MidiIn_UnMap32WTo16 [internal]
214 static WINMM_MapType MMDRV_MidiIn_UnMap32WTo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
216 return WINMM_MAP_MSGERROR;
219 /**************************************************************************
220 * MMDRV_MidiIn_Callback [internal]
222 static void CALLBACK MMDRV_MidiIn_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
224 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
229 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
234 /* dwParam1 & dwParam2 are are data, nothing to do */
238 /* dwParam1 points to a MidiHdr, work to be done !!! */
239 if (mld->bFrom32 && !MMDRV_Is32(mld->mmdIndex)) {
240 /* initial map is: 32 => 16 */
241 LPMIDIHDR mh16 = MapSL(dwParam1);
242 LPMIDIHDR mh32 = *(LPMIDIHDR*)((LPSTR)mh16 - sizeof(LPMIDIHDR));
244 dwParam1 = (DWORD)mh32;
245 mh32->dwFlags = mh16->dwFlags;
246 mh32->dwBytesRecorded = mh16->dwBytesRecorded;
247 if (mh32->reserved >= sizeof(MIDIHDR))
248 mh32->dwOffset = mh16->dwOffset;
249 } else if (!mld->bFrom32 && MMDRV_Is32(mld->mmdIndex)) {
250 /* initial map is: 16 => 32 */
251 LPMIDIHDR mh32 = (LPMIDIHDR)(dwParam1);
252 SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR));
253 LPMIDIHDR mh16 = MapSL(segmh16);
255 dwParam1 = (DWORD)segmh16;
256 mh16->dwFlags = mh32->dwFlags;
257 mh16->dwBytesRecorded = mh32->dwBytesRecorded;
258 if (mh16->reserved >= sizeof(MIDIHDR))
259 mh16->dwOffset = mh32->dwOffset;
261 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
263 /* case MOM_POSITIONCB: */
265 ERR("Unknown msg %u\n", uMsg);
268 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
271 /* =================================
272 * M I D I O U T M A P P E R S
273 * ================================= */
275 /**************************************************************************
276 * MMDRV_MidiOut_Map16To32W [internal]
278 static WINMM_MapType MMDRV_MidiOut_Map16To32W (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
280 WINMM_MapType ret = WINMM_MAP_MSGERROR;
283 case MODM_GETNUMDEVS:
293 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
296 case MODM_GETDEVCAPS:
298 LPMIDIOUTCAPSW moc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPS16) + sizeof(MIDIOUTCAPSW));
299 LPMIDIOUTCAPS16 moc16 = MapSL(*lpParam1);
302 *(LPMIDIOUTCAPS16*)moc32 = moc16;
303 moc32 = (LPMIDIOUTCAPSW)((LPSTR)moc32 + sizeof(LPMIDIOUTCAPS16));
304 *lpParam1 = (DWORD)moc32;
305 *lpParam2 = sizeof(MIDIOUTCAPSW);
307 ret = WINMM_MAP_OKMEM;
309 ret = WINMM_MAP_NOMEM;
315 LPMIDIHDR mh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIHDR) + sizeof(MIDIHDR));
316 LPMIDIHDR mh16 = MapSL(*lpParam1);
319 *(LPMIDIHDR*)mh32 = (LPMIDIHDR)*lpParam1;
320 mh32 = (LPMIDIHDR)((LPSTR)mh32 + sizeof(LPMIDIHDR));
321 mh32->lpData = MapSL((SEGPTR)mh16->lpData);
322 mh32->dwBufferLength = mh16->dwBufferLength;
323 mh32->dwBytesRecorded = mh16->dwBytesRecorded;
324 mh32->dwUser = mh16->dwUser;
325 mh32->dwFlags = mh16->dwFlags;
326 /* FIXME: nothing on mh32->lpNext */
327 /* could link the mh32->lpNext at this level for memory house keeping */
328 mh32->dwOffset = (*lpParam2 >= sizeof(MIDIHDR)) ? ((LPMIDIHDR)mh16)->dwOffset : 0;
329 mh16->lpNext = mh32; /* for reuse in unprepare and write */
330 /* store size of passed MIDIHDR?? structure to know if dwOffset is available or not */
331 mh16->reserved = *lpParam2;
332 *lpParam1 = (DWORD)mh32;
333 *lpParam2 = sizeof(MIDIHDR);
335 ret = WINMM_MAP_OKMEM;
337 ret = WINMM_MAP_NOMEM;
344 LPMIDIHDR mh16 = MapSL(*lpParam1);
345 LPMIDIHDR mh32 = (LPMIDIHDR)mh16->lpNext;
347 *lpParam1 = (DWORD)mh32;
348 *lpParam2 = sizeof(MIDIHDR);
349 /* dwBufferLength can be reduced between prepare & write */
350 if (wMsg == MODM_LONGDATA && mh32->dwBufferLength < mh16->dwBufferLength) {
351 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
352 mh32->dwBufferLength, mh16->dwBufferLength);
354 mh32->dwBufferLength = mh16->dwBufferLength;
355 ret = WINMM_MAP_OKMEM;
359 case MODM_CACHEPATCHES:
360 case MODM_CACHEDRUMPATCHES:
362 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
368 /**************************************************************************
369 * MMDRV_MidiOut_UnMap16To32W [internal]
371 static WINMM_MapType MMDRV_MidiOut_UnMap16To32W(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
373 WINMM_MapType ret = WINMM_MAP_MSGERROR;
376 case MODM_GETNUMDEVS:
386 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
389 case MODM_GETDEVCAPS:
391 LPMIDIOUTCAPSW moc32 = (LPMIDIOUTCAPSW)(*lpParam1);
392 LPMIDIOUTCAPS16 moc16 = *(LPMIDIOUTCAPS16*)((LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
394 moc16->wMid = moc32->wMid;
395 moc16->wPid = moc32->wPid;
396 moc16->vDriverVersion = moc32->vDriverVersion;
397 WideCharToMultiByte( CP_ACP, 0, moc32->szPname, -1, moc16->szPname,
398 sizeof(moc16->szPname), NULL, NULL );
399 moc16->wTechnology = moc32->wTechnology;
400 moc16->wVoices = moc32->wVoices;
401 moc16->wNotes = moc32->wNotes;
402 moc16->wChannelMask = moc32->wChannelMask;
403 moc16->dwSupport = moc32->dwSupport;
404 HeapFree(GetProcessHeap(), 0, (LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
412 LPMIDIHDR mh32 = (LPMIDIHDR)(*lpParam1);
413 LPMIDIHDR mh16 = MapSL(*(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR)));
415 assert(mh16->lpNext == mh32);
416 mh16->dwBufferLength = mh32->dwBufferLength;
417 mh16->dwBytesRecorded = mh32->dwBytesRecorded;
418 mh16->dwUser = mh32->dwUser;
419 mh16->dwFlags = mh32->dwFlags;
420 if (mh16->reserved >= sizeof(MIDIHDR))
421 mh16->dwOffset = mh32->dwOffset;
423 if (wMsg == MODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
424 HeapFree(GetProcessHeap(), 0, (LPSTR)mh32 - sizeof(LPMIDIHDR));
431 case MODM_CACHEPATCHES:
432 case MODM_CACHEDRUMPATCHES:
434 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
440 /**************************************************************************
441 * MMDRV_MidiOut_Map32WTo16 [internal]
443 static WINMM_MapType MMDRV_MidiOut_Map32WTo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
445 WINMM_MapType ret = WINMM_MAP_MSGERROR;
449 case MODM_GETNUMDEVS:
455 case MODM_GETDEVCAPS:
457 LPMIDIOUTCAPSW moc32 = (LPMIDIOUTCAPSW)*lpParam1;
458 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPSW)+sizeof(MIDIOUTCAPS16));
461 *(LPMIDIOUTCAPSW*)ptr = moc32;
462 ret = WINMM_MAP_OKMEM;
464 ret = WINMM_MAP_NOMEM;
466 *lpParam1 = (DWORD)MapLS(ptr) + sizeof(LPMIDIOUTCAPSW);
467 *lpParam2 = sizeof(MIDIOUTCAPS16);
472 LPMIDIHDR mh32 = (LPMIDIHDR)*lpParam1;
474 LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
475 sizeof(LPMIDIHDR) + sizeof(MIDIHDR) + mh32->dwBufferLength);
478 *(LPMIDIHDR*)ptr = mh32;
479 mh16 = (LPMIDIHDR)((LPSTR)ptr + sizeof(LPMIDIHDR));
480 *lpParam1 = MapLS(mh16);
481 mh16->lpData = (LPSTR)*lpParam1 + sizeof(MIDIHDR);
482 /* data will be copied on WODM_WRITE */
483 mh16->dwBufferLength = mh32->dwBufferLength;
484 mh16->dwBytesRecorded = mh32->dwBytesRecorded;
485 mh16->dwUser = mh32->dwUser;
486 mh16->dwFlags = mh32->dwFlags;
487 /* FIXME: nothing on mh32->lpNext */
488 /* could link the mh32->lpNext at this level for memory house keeping */
489 mh16->dwOffset = (*lpParam2 >= sizeof(MIDIHDR)) ? mh32->dwOffset : 0;
491 mh32->lpNext = (LPMIDIHDR)mh16; /* for reuse in unprepare and write */
492 mh32->reserved = *lpParam2;
494 TRACE("mh16=%08lx mh16->lpData=%08lx mh32->buflen=%lu mh32->lpData=%08lx\n",
495 *lpParam1, (DWORD)mh16->lpData,
496 mh32->dwBufferLength, (DWORD)mh32->lpData);
497 *lpParam2 = sizeof(MIDIHDR);
499 ret = WINMM_MAP_OKMEM;
501 ret = WINMM_MAP_NOMEM;
508 LPMIDIHDR mh32 = (LPMIDIHDR)(*lpParam1);
509 LPMIDIHDR mh16 = (LPMIDIHDR)mh32->lpNext;
510 LPSTR ptr = (LPSTR)mh16 - sizeof(LPMIDIHDR);
512 assert(*(LPMIDIHDR*)ptr == mh32);
514 if (wMsg == MODM_LONGDATA)
515 memcpy((LPSTR)mh16 + sizeof(MIDIHDR), mh32->lpData, mh32->dwBufferLength);
517 *lpParam1 = MapLS(mh16);
518 *lpParam2 = sizeof(MIDIHDR);
519 TRACE("mh16=%08lx mh16->lpData=%08lx mh32->buflen=%lu mh32->lpData=%08lx\n",
520 *lpParam1, (DWORD)mh16->lpData, mh32->dwBufferLength, (DWORD)mh32->lpData);
522 /* dwBufferLength can be reduced between prepare & write */
523 if (wMsg == MODM_LONGDATA && mh16->dwBufferLength < mh32->dwBufferLength) {
524 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
525 mh16->dwBufferLength, mh32->dwBufferLength);
527 mh16->dwBufferLength = mh32->dwBufferLength;
528 ret = WINMM_MAP_OKMEM;
533 LPMIDIOPENDESC mod32 = (LPMIDIOPENDESC)*lpParam1;
535 LPMIDIOPENDESC16 mod16;
537 /* allocated data are mapped as follows:
538 LPMIDIOPENDESC ptr to orig lParam1
539 DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
540 DWORD dwUser passed to driver
541 MIDIOPENDESC16 mod16: openDesc passed to driver
544 ptr = HeapAlloc( GetProcessHeap(), 0,
545 sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD) + sizeof(MIDIOPENDESC16) +
546 mod32->cIds ? (mod32->cIds - 1) * sizeof(MIDIOPENSTRMID) : 0);
549 SEGPTR segptr = MapLS(ptr);
550 *(LPMIDIOPENDESC*)ptr = mod32;
551 *(LPDWORD)((char*)ptr + sizeof(LPMIDIOPENDESC)) = *lpdwUser;
552 mod16 = (LPMIDIOPENDESC16)((LPSTR)ptr + sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD));
554 mod16->hMidi = HMIDI_16(mod32->hMidi);
555 mod16->dwCallback = mod32->dwCallback;
556 mod16->dwInstance = mod32->dwInstance;
557 mod16->dnDevNode = mod32->dnDevNode;
558 mod16->cIds = mod32->cIds;
559 memcpy(&mod16->rgIds, &mod32->rgIds, mod32->cIds * sizeof(MIDIOPENSTRMID));
561 *lpParam1 = (DWORD)segptr + sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD);
562 *lpdwUser = (DWORD)segptr + sizeof(LPMIDIOPENDESC) + sizeof(DWORD);
564 ret = WINMM_MAP_OKMEM;
566 ret = WINMM_MAP_NOMEM;
571 case MODM_CACHEPATCHES:
572 case MODM_CACHEDRUMPATCHES:
574 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
580 /**************************************************************************
581 * MMDRV_MidiOut_UnMap32WTo16 [internal]
583 static WINMM_MapType MMDRV_MidiOut_UnMap32WTo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
585 WINMM_MapType ret = WINMM_MAP_MSGERROR;
589 case MODM_GETNUMDEVS:
595 case MODM_GETDEVCAPS:
597 LPMIDIOUTCAPS16 moc16 = MapSL(*lpParam1);
598 LPSTR ptr = (LPSTR)moc16 - sizeof(LPMIDIOUTCAPSW);
599 LPMIDIOUTCAPSW moc32 = *(LPMIDIOUTCAPSW*)ptr;
601 moc32->wMid = moc16->wMid;
602 moc32->wPid = moc16->wPid;
603 moc32->vDriverVersion = moc16->vDriverVersion;
604 WideCharToMultiByte( CP_ACP, 0, moc32->szPname, -1, moc16->szPname,
605 sizeof(moc16->szPname), NULL, NULL );
606 moc32->wTechnology = moc16->wTechnology;
607 moc32->wVoices = moc16->wVoices;
608 moc32->wNotes = moc16->wNotes;
609 moc32->wChannelMask = moc16->wChannelMask;
610 moc32->dwSupport = moc16->dwSupport;
611 UnMapLS( *lpParam1 );
612 HeapFree( GetProcessHeap(), 0, ptr );
620 LPMIDIHDR mh16 = MapSL(*lpParam1);
621 LPSTR ptr = (LPSTR)mh16 - sizeof(LPMIDIHDR);
622 LPMIDIHDR mh32 = *(LPMIDIHDR*)ptr;
624 assert(mh32->lpNext == (LPMIDIHDR)mh16);
625 UnMapLS( *lpParam1 );
626 mh32->dwBytesRecorded = mh16->dwBytesRecorded;
627 mh32->dwUser = mh16->dwUser;
628 mh32->dwFlags = mh16->dwFlags;
630 if (wMsg == MODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
631 HeapFree( GetProcessHeap(), 0, ptr );
639 LPMIDIOPENDESC16 mod16 = MapSL(*lpParam1);
640 LPSTR ptr = (LPSTR)mod16 - sizeof(LPMIDIOPENDESC) - 2*sizeof(DWORD);
641 UnMapLS( *lpParam1 );
642 **(DWORD**)(ptr + sizeof(LPMIDIOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPMIDIOPENDESC) + sizeof(DWORD));
644 HeapFree( GetProcessHeap(), 0, ptr );
649 case MODM_CACHEPATCHES:
650 case MODM_CACHEDRUMPATCHES:
652 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
658 /**************************************************************************
659 * MMDRV_MidiOut_Callback [internal]
661 static void CALLBACK MMDRV_MidiOut_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
663 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
668 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
671 if (mld->bFrom32 && !MMDRV_Is32(mld->mmdIndex)) {
672 /* initial map is: 32 => 16 */
673 LPMIDIHDR mh16 = MapSL(dwParam1);
674 LPMIDIHDR mh32 = *(LPMIDIHDR*)((LPSTR)mh16 - sizeof(LPMIDIHDR));
676 dwParam1 = (DWORD)mh32;
677 mh32->dwFlags = mh16->dwFlags;
678 mh32->dwOffset = mh16->dwOffset;
679 if (mh32->reserved >= sizeof(MIDIHDR))
680 mh32->dwOffset = mh16->dwOffset;
681 } else if (!mld->bFrom32 && MMDRV_Is32(mld->mmdIndex)) {
682 /* initial map is: 16 => 32 */
683 LPMIDIHDR mh32 = (LPMIDIHDR)(dwParam1);
684 SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR));
685 LPMIDIHDR mh16 = MapSL(segmh16);
687 dwParam1 = (DWORD)segmh16;
688 mh16->dwFlags = mh32->dwFlags;
689 if (mh16->reserved >= sizeof(MIDIHDR))
690 mh16->dwOffset = mh32->dwOffset;
692 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
694 /* case MOM_POSITIONCB: */
696 ERR("Unknown msg %u\n", uMsg);
699 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
702 /* =================================
703 * W A V E I N M A P P E R S
704 * ================================= */
706 /**************************************************************************
707 * MMDRV_WaveIn_Map16To32W [internal]
709 static WINMM_MapType MMDRV_WaveIn_Map16To32W (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
711 WINMM_MapType ret = WINMM_MAP_MSGERROR;
714 case WIDM_GETNUMDEVS:
722 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
724 case WIDM_GETDEVCAPS:
726 LPWAVEINCAPSW wic32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEINCAPS16) + sizeof(WAVEINCAPSW));
727 LPWAVEINCAPS16 wic16 = MapSL(*lpParam1);
730 *(LPWAVEINCAPS16*)wic32 = wic16;
731 wic32 = (LPWAVEINCAPSW)((LPSTR)wic32 + sizeof(LPWAVEINCAPS16));
732 *lpParam1 = (DWORD)wic32;
733 *lpParam2 = sizeof(WAVEINCAPSW);
735 ret = WINMM_MAP_OKMEM;
737 ret = WINMM_MAP_NOMEM;
743 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
744 LPMMTIME16 mmt16 = MapSL(*lpParam1);
747 *(LPMMTIME16*)mmt32 = mmt16;
748 mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
750 mmt32->wType = mmt16->wType;
751 *lpParam1 = (DWORD)mmt32;
752 *lpParam2 = sizeof(MMTIME);
754 ret = WINMM_MAP_OKMEM;
756 ret = WINMM_MAP_NOMEM;
762 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
763 LPWAVEHDR wh16 = MapSL(*lpParam1);
766 *(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
767 wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
768 wh32->lpData = MapSL((SEGPTR)wh16->lpData);
769 wh32->dwBufferLength = wh16->dwBufferLength;
770 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
771 wh32->dwUser = wh16->dwUser;
772 wh32->dwFlags = wh16->dwFlags;
773 wh32->dwLoops = wh16->dwLoops;
774 /* FIXME: nothing on wh32->lpNext */
775 /* could link the wh32->lpNext at this level for memory house keeping */
776 wh16->lpNext = wh32; /* for reuse in unprepare and write */
777 *lpParam1 = (DWORD)wh32;
778 *lpParam2 = sizeof(WAVEHDR);
780 ret = WINMM_MAP_OKMEM;
782 ret = WINMM_MAP_NOMEM;
789 LPWAVEHDR wh16 = MapSL(*lpParam1);
790 LPWAVEHDR wh32 = (LPWAVEHDR)wh16->lpNext;
792 *lpParam1 = (DWORD)wh32;
793 *lpParam2 = sizeof(WAVEHDR);
794 /* dwBufferLength can be reduced between prepare & write */
795 if (wMsg == WIDM_ADDBUFFER && wh32->dwBufferLength < wh16->dwBufferLength) {
796 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
797 wh32->dwBufferLength, wh16->dwBufferLength);
799 wh32->dwBufferLength = wh16->dwBufferLength;
800 ret = WINMM_MAP_OKMEM;
803 case WIDM_MAPPER_STATUS:
804 /* just a single DWORD */
805 *lpParam2 = (DWORD)MapSL(*lpParam2);
809 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
815 /**************************************************************************
816 * MMDRV_WaveIn_UnMap16To32W [internal]
818 static WINMM_MapType MMDRV_WaveIn_UnMap16To32W(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
820 WINMM_MapType ret = WINMM_MAP_MSGERROR;
823 case WIDM_GETNUMDEVS:
827 case WIDM_MAPPER_STATUS:
832 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
834 case WIDM_GETDEVCAPS:
836 LPWAVEINCAPSW wic32 = (LPWAVEINCAPSW)(*lpParam1);
837 LPWAVEINCAPS16 wic16 = *(LPWAVEINCAPS16*)((LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
839 wic16->wMid = wic32->wMid;
840 wic16->wPid = wic32->wPid;
841 wic16->vDriverVersion = wic32->vDriverVersion;
842 WideCharToMultiByte( CP_ACP, 0, wic32->szPname, -1, wic16->szPname,
843 sizeof(wic16->szPname), NULL, NULL );
844 wic16->dwFormats = wic32->dwFormats;
845 wic16->wChannels = wic32->wChannels;
846 HeapFree(GetProcessHeap(), 0, (LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
852 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
853 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
855 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
856 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
864 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
865 LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
867 assert(wh16->lpNext == wh32);
868 wh16->dwBufferLength = wh32->dwBufferLength;
869 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
870 wh16->dwUser = wh32->dwUser;
871 wh16->dwFlags = wh32->dwFlags;
872 wh16->dwLoops = wh32->dwLoops;
874 if (wMsg == WIDM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
875 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
882 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
888 /**************************************************************************
889 * MMDRV_WaveIn_Map32WTo16 [internal]
891 static WINMM_MapType MMDRV_WaveIn_Map32WTo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
893 WINMM_MapType ret = WINMM_MAP_MSGERROR;
897 case WIDM_GETNUMDEVS:
906 LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
907 int sz = sizeof(WAVEFORMATEX);
909 LPWAVEOPENDESC16 wod16;
911 /* allocated data are mapped as follows:
912 LPWAVEOPENDESC ptr to orig lParam1
913 DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
914 DWORD dwUser passed to driver
915 WAVEOPENDESC16 wod16: openDesc passed to driver
916 WAVEFORMATEX openDesc->lpFormat passed to driver
917 xxx extra bytes to WAVEFORMATEX
919 if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
920 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize, wod32->lpFormat->wFormatTag);
921 sz += ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize;
924 ptr = HeapAlloc( GetProcessHeap(), 0,
925 sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
928 SEGPTR seg_ptr = MapLS( ptr );
929 *(LPWAVEOPENDESC*)ptr = wod32;
930 *(LPDWORD)((char*)ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
931 wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
933 wod16->hWave = HWAVE_16(wod32->hWave);
934 wod16->lpFormat = (LPWAVEFORMATEX)(seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
935 memcpy(wod16 + 1, wod32->lpFormat, sz);
937 wod16->dwCallback = wod32->dwCallback;
938 wod16->dwInstance = wod32->dwInstance;
939 wod16->uMappedDeviceID = wod32->uMappedDeviceID;
940 wod16->dnDevNode = wod32->dnDevNode;
942 *lpParam1 = seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
943 *lpdwUser = seg_ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
945 ret = WINMM_MAP_OKMEM;
947 ret = WINMM_MAP_NOMEM;
953 LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
955 LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
956 sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
959 SEGPTR seg_ptr = MapLS( ptr );
960 *(LPWAVEHDR*)ptr = wh32;
961 wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
962 wh16->lpData = (LPSTR)seg_ptr + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
963 /* data will be copied on WODM_WRITE */
964 wh16->dwBufferLength = wh32->dwBufferLength;
965 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
966 wh16->dwUser = wh32->dwUser;
967 wh16->dwFlags = wh32->dwFlags;
968 wh16->dwLoops = wh32->dwLoops;
969 /* FIXME: nothing on wh32->lpNext */
970 /* could link the wh32->lpNext at this level for memory house keeping */
971 wh32->lpNext = wh16; /* for reuse in unprepare and write */
972 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
973 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
974 wh32->dwBufferLength, (DWORD)wh32->lpData);
975 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
976 *lpParam2 = sizeof(WAVEHDR);
978 ret = WINMM_MAP_OKMEM;
980 ret = WINMM_MAP_NOMEM;
987 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
988 LPWAVEHDR wh16 = wh32->lpNext;
989 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
990 SEGPTR seg_ptr = MapLS( ptr );
992 assert(*(LPWAVEHDR*)ptr == wh32);
994 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
995 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
996 wh32->dwBufferLength, (DWORD)wh32->lpData);
998 if (wMsg == WIDM_ADDBUFFER)
999 memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
1001 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
1002 *lpParam2 = sizeof(WAVEHDR);
1003 /* dwBufferLength can be reduced between prepare & write */
1004 if (wMsg == WIDM_ADDBUFFER && wh16->dwBufferLength < wh32->dwBufferLength) {
1005 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
1006 wh16->dwBufferLength, wh32->dwBufferLength);
1008 wh16->dwBufferLength = wh32->dwBufferLength;
1009 ret = WINMM_MAP_OKMEM;
1012 case WIDM_GETDEVCAPS:
1014 LPWAVEINCAPSW wic32 = (LPWAVEINCAPSW)*lpParam1;
1015 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0 ,sizeof(LPWAVEINCAPSW) + sizeof(WAVEINCAPS16));
1018 *(LPWAVEINCAPSW*)ptr = wic32;
1019 ret = WINMM_MAP_OKMEM;
1021 ret = WINMM_MAP_NOMEM;
1023 *lpParam1 = MapLS(ptr) + sizeof(LPWAVEINCAPSW);
1024 *lpParam2 = sizeof(WAVEINCAPS16);
1029 LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
1030 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMMTIME) + sizeof(MMTIME16));
1031 LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
1034 *(LPMMTIME*)ptr = mmt32;
1035 mmt16->wType = mmt32->wType;
1036 ret = WINMM_MAP_OKMEM;
1038 ret = WINMM_MAP_NOMEM;
1040 *lpParam1 = MapLS(ptr) + sizeof(LPMMTIME);
1041 *lpParam2 = sizeof(MMTIME16);
1044 case DRVM_MAPPER_STATUS:
1046 LPDWORD p32 = (LPDWORD)*lpParam2;
1047 *lpParam2 = MapLS(p32);
1048 ret = WINMM_MAP_OKMEM;
1052 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1058 /**************************************************************************
1059 * MMDRV_WaveIn_UnMap32WTo16 [internal]
1061 static WINMM_MapType MMDRV_WaveIn_UnMap32WTo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
1063 WINMM_MapType ret = WINMM_MAP_MSGERROR;
1067 case WIDM_GETNUMDEVS:
1076 LPWAVEOPENDESC16 wod16 = MapSL(*lpParam1);
1077 LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
1078 LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
1080 UnMapLS( *lpParam1 );
1081 wod32->uMappedDeviceID = wod16->uMappedDeviceID;
1082 **(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
1083 HeapFree( GetProcessHeap(), 0, ptr );
1088 case WIDM_ADDBUFFER:
1090 case WIDM_UNPREPARE:
1092 LPWAVEHDR wh16 = MapSL(*lpParam1);
1093 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1094 LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
1096 assert(wh32->lpNext == wh16);
1097 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1098 wh32->dwUser = wh16->dwUser;
1099 wh32->dwFlags = wh16->dwFlags;
1100 wh32->dwLoops = wh16->dwLoops;
1101 UnMapLS( *lpParam1 );
1103 if (wMsg == WIDM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
1104 HeapFree( GetProcessHeap(), 0, ptr );
1110 case WIDM_GETDEVCAPS:
1112 LPWAVEINCAPS16 wic16 = MapSL(*lpParam1);
1113 LPSTR ptr = (LPSTR)wic16 - sizeof(LPWAVEINCAPSW);
1114 LPWAVEINCAPSW wic32 = *(LPWAVEINCAPSW*)ptr;
1116 wic32->wMid = wic16->wMid;
1117 wic32->wPid = wic16->wPid;
1118 wic32->vDriverVersion = wic16->vDriverVersion;
1119 WideCharToMultiByte( CP_ACP, 0, wic32->szPname, -1, wic16->szPname,
1120 sizeof(wic16->szPname), NULL, NULL );
1121 wic32->dwFormats = wic16->dwFormats;
1122 wic32->wChannels = wic16->wChannels;
1123 UnMapLS( *lpParam1 );
1124 HeapFree( GetProcessHeap(), 0, ptr );
1130 LPMMTIME16 mmt16 = MapSL(*lpParam1);
1131 LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
1132 LPMMTIME mmt32 = *(LPMMTIME*)ptr;
1134 MMSYSTEM_MMTIME16to32(mmt32, mmt16);
1135 UnMapLS( *lpParam1 );
1136 HeapFree( GetProcessHeap(), 0, ptr );
1140 case DRVM_MAPPER_STATUS:
1142 UnMapLS( *lpParam2 );
1147 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1153 /**************************************************************************
1154 * MMDRV_WaveIn_Callback [internal]
1156 static void CALLBACK MMDRV_WaveIn_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
1158 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
1163 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1166 if (mld->bFrom32 && !MMDRV_Is32(mld->mmdIndex)) {
1167 /* initial map is: 32 => 16 */
1168 LPWAVEHDR wh16 = MapSL(dwParam1);
1169 LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
1171 dwParam1 = (DWORD)wh32;
1172 wh32->dwFlags = wh16->dwFlags;
1173 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1174 } else if (!mld->bFrom32 && MMDRV_Is32(mld->mmdIndex)) {
1175 /* initial map is: 16 => 32 */
1176 LPWAVEHDR wh32 = (LPWAVEHDR)(dwParam1);
1177 SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
1178 LPWAVEHDR wh16 = MapSL(segwh16);
1180 dwParam1 = (DWORD)segwh16;
1181 wh16->dwFlags = wh32->dwFlags;
1182 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1184 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1187 ERR("Unknown msg %u\n", uMsg);
1190 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
1193 /* =================================
1194 * W A V E O U T M A P P E R S
1195 * ================================= */
1197 /**************************************************************************
1198 * MMDRV_WaveOut_Map16To32W [internal]
1200 static WINMM_MapType MMDRV_WaveOut_Map16To32W (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1202 WINMM_MapType ret = WINMM_MAP_MSGERROR;
1206 case WODM_BREAKLOOP:
1208 case WODM_GETNUMDEVS:
1213 case WODM_SETPLAYBACKRATE:
1214 case WODM_SETVOLUME:
1219 case WODM_GETPLAYBACKRATE:
1220 case WODM_GETVOLUME:
1222 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
1225 case WODM_GETDEVCAPS:
1227 LPWAVEOUTCAPSW woc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEOUTCAPS16) + sizeof(WAVEOUTCAPSW));
1228 LPWAVEOUTCAPS16 woc16 = MapSL(*lpParam1);
1231 *(LPWAVEOUTCAPS16*)woc32 = woc16;
1232 woc32 = (LPWAVEOUTCAPSW)((LPSTR)woc32 + sizeof(LPWAVEOUTCAPS16));
1233 *lpParam1 = (DWORD)woc32;
1234 *lpParam2 = sizeof(WAVEOUTCAPSW);
1236 ret = WINMM_MAP_OKMEM;
1238 ret = WINMM_MAP_NOMEM;
1244 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
1245 LPMMTIME16 mmt16 = MapSL(*lpParam1);
1248 *(LPMMTIME16*)mmt32 = mmt16;
1249 mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
1251 mmt32->wType = mmt16->wType;
1252 *lpParam1 = (DWORD)mmt32;
1253 *lpParam2 = sizeof(MMTIME);
1255 ret = WINMM_MAP_OKMEM;
1257 ret = WINMM_MAP_NOMEM;
1263 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
1264 LPWAVEHDR wh16 = MapSL(*lpParam1);
1267 *(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
1268 wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
1269 wh32->lpData = MapSL((SEGPTR)wh16->lpData);
1270 wh32->dwBufferLength = wh16->dwBufferLength;
1271 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1272 wh32->dwUser = wh16->dwUser;
1273 wh32->dwFlags = wh16->dwFlags;
1274 wh32->dwLoops = wh16->dwLoops;
1275 /* FIXME: nothing on wh32->lpNext */
1276 /* could link the wh32->lpNext at this level for memory house keeping */
1277 wh16->lpNext = wh32; /* for reuse in unprepare and write */
1278 *lpParam1 = (DWORD)wh32;
1279 *lpParam2 = sizeof(WAVEHDR);
1281 ret = WINMM_MAP_OKMEM;
1283 ret = WINMM_MAP_NOMEM;
1287 case WODM_UNPREPARE:
1290 LPWAVEHDR wh16 = MapSL(*lpParam1);
1291 LPWAVEHDR wh32 = (LPWAVEHDR)wh16->lpNext;
1293 *lpParam1 = (DWORD)wh32;
1294 *lpParam2 = sizeof(WAVEHDR);
1295 /* dwBufferLength can be reduced between prepare & write */
1296 if (wMsg == WODM_WRITE && wh32->dwBufferLength < wh16->dwBufferLength) {
1297 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
1298 wh32->dwBufferLength, wh16->dwBufferLength);
1300 wh32->dwBufferLength = wh16->dwBufferLength;
1301 ret = WINMM_MAP_OKMEM;
1304 case WODM_MAPPER_STATUS:
1305 *lpParam2 = (DWORD)MapSL(*lpParam2);
1309 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1315 /**************************************************************************
1316 * MMDRV_WaveOut_UnMap16To32W [internal]
1318 static WINMM_MapType MMDRV_WaveOut_UnMap16To32W(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
1320 WINMM_MapType ret = WINMM_MAP_MSGERROR;
1324 case WODM_BREAKLOOP:
1326 case WODM_GETNUMDEVS:
1331 case WODM_SETPLAYBACKRATE:
1332 case WODM_SETVOLUME:
1333 case WODM_MAPPER_STATUS:
1338 case WODM_GETPLAYBACKRATE:
1339 case WODM_GETVOLUME:
1341 FIXME("Shouldn't be used: those 16 bit functions use the 32 bit interface\n");
1344 case WODM_GETDEVCAPS:
1346 LPWAVEOUTCAPSW woc32 = (LPWAVEOUTCAPSW)(*lpParam1);
1347 LPWAVEOUTCAPS16 woc16 = *(LPWAVEOUTCAPS16*)((LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
1349 woc16->wMid = woc32->wMid;
1350 woc16->wPid = woc32->wPid;
1351 woc16->vDriverVersion = woc32->vDriverVersion;
1352 WideCharToMultiByte( CP_ACP, 0, woc32->szPname, -1, woc16->szPname,
1353 sizeof(woc16->szPname), NULL, NULL );
1354 woc16->dwFormats = woc32->dwFormats;
1355 woc16->wChannels = woc32->wChannels;
1356 woc16->dwSupport = woc32->dwSupport;
1357 HeapFree(GetProcessHeap(), 0, (LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
1363 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
1364 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
1366 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
1367 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
1372 case WODM_UNPREPARE:
1375 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
1376 LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
1378 assert(wh16->lpNext == wh32);
1379 wh16->dwBufferLength = wh32->dwBufferLength;
1380 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1381 wh16->dwUser = wh32->dwUser;
1382 wh16->dwFlags = wh32->dwFlags;
1383 wh16->dwLoops = wh32->dwLoops;
1385 if (wMsg == WODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
1386 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
1393 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1399 /**************************************************************************
1400 * MMDRV_WaveOut_Map32WTo16 [internal]
1402 static WINMM_MapType MMDRV_WaveOut_Map32WTo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1408 case WODM_BREAKLOOP:
1410 case WODM_GETNUMDEVS:
1415 case WODM_SETPLAYBACKRATE:
1416 case WODM_SETVOLUME:
1420 case WODM_GETDEVCAPS:
1422 LPWAVEOUTCAPSW woc32 = (LPWAVEOUTCAPSW)*lpParam1;
1423 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0,
1424 sizeof(LPWAVEOUTCAPSW) + sizeof(WAVEOUTCAPS16));
1427 *(LPWAVEOUTCAPSW*)ptr = woc32;
1428 ret = WINMM_MAP_OKMEM;
1430 ret = WINMM_MAP_NOMEM;
1432 *lpParam1 = MapLS(ptr) + sizeof(LPWAVEOUTCAPSW);
1433 *lpParam2 = sizeof(WAVEOUTCAPS16);
1437 FIXME("NIY: no conversion yet\n");
1438 ret = WINMM_MAP_MSGERROR;
1440 case WODM_GETPLAYBACKRATE:
1441 FIXME("NIY: no conversion yet\n");
1442 ret = WINMM_MAP_MSGERROR;
1446 LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
1447 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMMTIME) + sizeof(MMTIME16));
1448 LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
1451 *(LPMMTIME*)ptr = mmt32;
1452 mmt16->wType = mmt32->wType;
1453 ret = WINMM_MAP_OKMEM;
1455 ret = WINMM_MAP_NOMEM;
1457 *lpParam1 = MapLS(ptr) + sizeof(LPMMTIME);
1458 *lpParam2 = sizeof(MMTIME16);
1461 case WODM_GETVOLUME:
1462 FIXME("NIY: no conversion yet\n");
1463 ret = WINMM_MAP_MSGERROR;
1467 LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
1468 int sz = sizeof(WAVEFORMATEX);
1470 LPWAVEOPENDESC16 wod16;
1472 /* allocated data are mapped as follows:
1473 LPWAVEOPENDESC ptr to orig lParam1
1474 DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
1475 DWORD dwUser passed to driver
1476 WAVEOPENDESC16 wod16: openDesc passed to driver
1477 WAVEFORMATEX openDesc->lpFormat passed to driver
1478 xxx extra bytes to WAVEFORMATEX
1480 if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
1481 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize, wod32->lpFormat->wFormatTag);
1482 sz += ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize;
1485 ptr = HeapAlloc( GetProcessHeap(), 0,
1486 sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
1489 SEGPTR seg_ptr = MapLS( ptr );
1490 *(LPWAVEOPENDESC*)ptr = wod32;
1491 *(LPDWORD)((char*)ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
1492 wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
1494 wod16->hWave = HWAVE_16(wod32->hWave);
1495 wod16->lpFormat = (LPWAVEFORMATEX)(seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
1496 memcpy(wod16 + 1, wod32->lpFormat, sz);
1498 wod16->dwCallback = wod32->dwCallback;
1499 wod16->dwInstance = wod32->dwInstance;
1500 wod16->uMappedDeviceID = wod32->uMappedDeviceID;
1501 wod16->dnDevNode = wod32->dnDevNode;
1503 *lpParam1 = seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
1504 *lpdwUser = seg_ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
1506 ret = WINMM_MAP_OKMEM;
1508 ret = WINMM_MAP_NOMEM;
1514 LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
1516 LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
1517 sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
1520 SEGPTR seg_ptr = MapLS( ptr );
1521 *(LPWAVEHDR*)ptr = wh32;
1522 wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
1523 wh16->lpData = (LPSTR)seg_ptr + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
1524 /* data will be copied on WODM_WRITE */
1525 wh16->dwBufferLength = wh32->dwBufferLength;
1526 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1527 wh16->dwUser = wh32->dwUser;
1528 wh16->dwFlags = wh32->dwFlags;
1529 wh16->dwLoops = wh32->dwLoops;
1530 /* FIXME: nothing on wh32->lpNext */
1531 /* could link the wh32->lpNext at this level for memory house keeping */
1532 wh32->lpNext = wh16; /* for reuse in unprepare and write */
1533 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1534 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
1535 wh32->dwBufferLength, (DWORD)wh32->lpData);
1536 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
1537 *lpParam2 = sizeof(WAVEHDR);
1539 ret = WINMM_MAP_OKMEM;
1541 ret = WINMM_MAP_NOMEM;
1545 case WODM_UNPREPARE:
1548 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
1549 LPWAVEHDR wh16 = wh32->lpNext;
1550 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1551 SEGPTR seg_ptr = MapLS( ptr );
1553 assert(*(LPWAVEHDR*)ptr == wh32);
1555 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1556 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
1557 wh32->dwBufferLength, (DWORD)wh32->lpData);
1559 if (wMsg == WODM_WRITE)
1560 memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
1562 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
1563 *lpParam2 = sizeof(WAVEHDR);
1564 /* dwBufferLength can be reduced between prepare & write */
1565 if (wMsg == WODM_WRITE && wh16->dwBufferLength < wh32->dwBufferLength) {
1566 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
1567 wh16->dwBufferLength, wh32->dwBufferLength);
1569 wh16->dwBufferLength = wh32->dwBufferLength;
1570 ret = WINMM_MAP_OKMEM;
1573 case DRVM_MAPPER_STATUS:
1575 LPDWORD p32 = (LPDWORD)*lpParam2;
1576 *lpParam2 = MapLS(p32);
1577 ret = WINMM_MAP_OKMEM;
1581 FIXME("NIY: no conversion yet\n");
1582 ret = WINMM_MAP_MSGERROR;
1588 /**************************************************************************
1589 * MMDRV_WaveOut_UnMap32WTo16 [internal]
1591 static WINMM_MapType MMDRV_WaveOut_UnMap32WTo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
1597 case WODM_BREAKLOOP:
1599 case WODM_GETNUMDEVS:
1604 case WODM_SETPLAYBACKRATE:
1605 case WODM_SETVOLUME:
1609 case WODM_GETDEVCAPS:
1611 LPWAVEOUTCAPS16 woc16 = MapSL(*lpParam1);
1612 LPSTR ptr = (LPSTR)woc16 - sizeof(LPWAVEOUTCAPSW);
1613 LPWAVEOUTCAPSW woc32 = *(LPWAVEOUTCAPSW*)ptr;
1615 woc32->wMid = woc16->wMid;
1616 woc32->wPid = woc16->wPid;
1617 woc32->vDriverVersion = woc16->vDriverVersion;
1618 WideCharToMultiByte( CP_ACP, 0, woc32->szPname, -1, woc16->szPname,
1619 sizeof(woc16->szPname), NULL, NULL );
1620 woc32->dwFormats = woc16->dwFormats;
1621 woc32->wChannels = woc16->wChannels;
1622 woc32->dwSupport = woc16->dwSupport;
1623 UnMapLS( *lpParam1 );
1624 HeapFree( GetProcessHeap(), 0, ptr );
1629 FIXME("NIY: no conversion yet\n");
1630 ret = WINMM_MAP_MSGERROR;
1632 case WODM_GETPLAYBACKRATE:
1633 FIXME("NIY: no conversion yet\n");
1634 ret = WINMM_MAP_MSGERROR;
1638 LPMMTIME16 mmt16 = MapSL(*lpParam1);
1639 LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
1640 LPMMTIME mmt32 = *(LPMMTIME*)ptr;
1642 MMSYSTEM_MMTIME16to32(mmt32, mmt16);
1643 UnMapLS( *lpParam1 );
1644 HeapFree( GetProcessHeap(), 0, ptr );
1650 LPWAVEOPENDESC16 wod16 = MapSL(*lpParam1);
1651 LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
1652 LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
1654 wod32->uMappedDeviceID = wod16->uMappedDeviceID;
1655 **(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
1656 UnMapLS( *lpParam1 );
1657 HeapFree( GetProcessHeap(), 0, ptr );
1662 case WODM_UNPREPARE:
1665 LPWAVEHDR wh16 = MapSL(*lpParam1);
1666 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1667 LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
1669 assert(wh32->lpNext == wh16);
1670 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1671 wh32->dwUser = wh16->dwUser;
1672 wh32->dwFlags = wh16->dwFlags;
1673 wh32->dwLoops = wh16->dwLoops;
1675 UnMapLS( *lpParam1 );
1676 if (wMsg == WODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
1677 HeapFree( GetProcessHeap(), 0, ptr );
1683 case WODM_GETVOLUME:
1684 FIXME("NIY: no conversion yet\n");
1685 ret = WINMM_MAP_MSGERROR;
1687 case DRVM_MAPPER_STATUS:
1689 UnMapLS( *lpParam2 );
1694 FIXME("NIY: no conversion yet\n");
1695 ret = WINMM_MAP_MSGERROR;
1701 /**************************************************************************
1702 * MMDRV_WaveOut_Callback [internal]
1704 static void CALLBACK MMDRV_WaveOut_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
1706 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
1711 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1714 if (mld->bFrom32 && !MMDRV_Is32(mld->mmdIndex)) {
1715 /* initial map is: 32 => 16 */
1716 LPWAVEHDR wh16 = MapSL(dwParam1);
1717 LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
1719 dwParam1 = (DWORD)wh32;
1720 wh32->dwFlags = wh16->dwFlags;
1721 } else if (!mld->bFrom32 && MMDRV_Is32(mld->mmdIndex)) {
1722 /* initial map is: 16 => 32 */
1723 LPWAVEHDR wh32 = (LPWAVEHDR)(dwParam1);
1724 SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
1725 LPWAVEHDR wh16 = MapSL(segwh16);
1727 dwParam1 = (DWORD)segwh16;
1728 wh16->dwFlags = wh32->dwFlags;
1730 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1733 ERR("Unknown msg %u\n", uMsg);
1736 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
1739 /* =================================
1740 * M A P P E R S H A N D L I N G
1741 * ================================= */
1743 static LRESULT MMDRV_CallMMDrvFunc16(DWORD fp16, WORD dev, WORD msg, LONG instance,
1751 args[5] = HIWORD(instance);
1752 args[4] = LOWORD(instance);
1753 args[3] = HIWORD(lp1);
1754 args[2] = LOWORD(lp1);
1755 args[1] = HIWORD(lp2);
1756 args[0] = LOWORD(lp2);
1757 WOWCallback16Ex( fp16, WCB16_PASCAL, sizeof(args), args, &ret );
1761 /**************************************************************************
1762 * MMDRV_GetDescription16 [internal]
1764 static BOOL MMDRV_GetDescription16(const char* fname, char* buf, int buflen)
1772 if ((hFile = OpenFile(fname, &ofs, OF_READ | OF_SHARE_DENY_WRITE)) == HFILE_ERROR) {
1773 ERR("Can't open file %s (builtin driver ?)\n", fname);
1777 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
1779 if (_lread(hFile, &w, 2) != 2) E(("Can't read sig\n"));
1780 if (w != ('Z' * 256 + 'M')) E(("Bad sig %04x\n", w));
1781 if (_llseek(hFile, 0x3C, SEEK_SET) < 0) E(("Can't seek to ext header offset\n"));
1782 if (_lread(hFile, &dw, 4) != 4) E(("Can't read ext header offset\n"));
1783 if (_llseek(hFile, dw + 0x2C, SEEK_SET) < 0) E(("Can't seek to ext header.nr table %lu\n", dw+0x2C));
1784 if (_lread(hFile, &dw, 4) != 4) E(("Can't read nr table offset\n"));
1785 if (_llseek(hFile, dw, SEEK_SET) < 0) E(("Can't seek to nr table %lu\n", dw));
1786 if (_lread(hFile, buf, 1) != 1) E(("Can't read descr length\n"));
1787 buflen = min((int)(unsigned)(BYTE)buf[0], buflen - 1);
1788 if (_lread(hFile, buf, buflen) != buflen) E(("Can't read descr (%d)\n", buflen));
1791 TRACE("Got '%s' [%d]\n", buf, buflen);
1797 /******************************************************************
1798 * MMDRV_LoadMMDrvFunc16
1801 unsigned MMDRV_LoadMMDrvFunc16(LPCSTR drvName, LPWINE_DRIVER d,
1802 LPWINE_MM_DRIVER lpDrv)
1804 WINEMM_msgFunc16 func;
1808 * DESCRIPTION 'wave,aux,mixer:Creative Labs Sound Blaster 16 Driver'
1809 * The beginning of the module description indicates the driver supports
1810 * waveform, auxiliary, and mixer devices. Use one of the following
1811 * device-type names, followed by a colon (:) to indicate the type of
1812 * device your driver supports. If the driver supports more than one
1813 * type of device, separate each device-type name with a comma (,).
1815 * wave for waveform audio devices
1816 * wavemapper for wave mappers
1817 * midi for MIDI audio devices
1818 * midimapper for midi mappers
1819 * aux for auxiliary audio devices
1820 * mixer for mixer devices
1823 if (d->d.d16.hDriver16) {
1824 HMODULE16 hMod16 = GetDriverModuleHandle16(d->d.d16.hDriver16);
1826 #define AA(_h,_w,_x,_y,_z) \
1827 func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
1829 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
1830 TRACE("Got %d bit func '%s'\n", _y, #_x); }
1832 #define A(_x,_y) AA(hMod16,_x,_y,16,GetProcAddress16)
1833 A(MMDRV_AUX, auxMessage);
1834 A(MMDRV_MIXER, mxdMessage);
1835 A(MMDRV_MIDIIN, midMessage);
1836 A(MMDRV_MIDIOUT,modMessage);
1837 A(MMDRV_WAVEIN, widMessage);
1838 A(MMDRV_WAVEOUT,wodMessage);
1842 if (TRACE_ON(winmm)) {
1843 if (MMDRV_GetDescription16(drvName, buffer, sizeof(buffer)))
1844 TRACE("%s => %s\n", drvName, buffer);
1846 TRACE("%s => No description\n", drvName);
1852 /* =================================
1854 * ================================= */
1857 /* FIXME: this code is kept for not yet implemented optimisation for an application
1858 * using the 32A MCI interface and calling a 16 bit driver.
1859 * For now, we're doing two conversions:
1860 * - 32A => 32W (in 32 bit MCI code)
1861 * - 32W => 16 in this file
1866 * 0001 squeeze signed 4 bytes to 2 bytes *( LPINT16)D = ( INT16)*( LPINT16)S; D += 2; S += 4
1867 * 0010 squeeze unsigned 4 bytes to 2 bytes *(LPUINT16)D = (UINT16)*(LPUINT16)S; D += 2; S += 4
1870 * 0110 zero 4 bytes *(DWORD)D = 0 D += 4; S += 4
1871 * 0111 copy string *(LPSTR*)D = seg dup(*(LPSTR*)S) D += 4; S += 4
1872 * 1xxx copy xxx + 1 bytes memcpy(D, S, xxx + 1); D += xxx+1; S += xxx+1
1875 /**************************************************************************
1876 * MCI_MsgMapper32ATo16_Create [internal]
1878 * Helper for MCI_MapMsg32ATo16.
1879 * Maps the 32 bit pointer (*ptr), of size bytes, to an allocated 16 bit
1880 * segmented pointer.
1881 * map contains a list of action to be performed for the mapping (see list
1883 * if keep is TRUE, keeps track of in 32 bit ptr in allocated 16 bit area.
1885 static WINMM_MapType MCI_MsgMapper32ATo16_Create(void** ptr, int size16, DWORD map, BOOLEAN keep)
1887 void* lp = HeapAlloc( GetProcessHeap(), 0, (keep ? sizeof(void**) : 0) + size16 );
1891 return WINMM_MAP_NOMEM;
1893 p32 = (LPBYTE)(*ptr);
1896 p16 = (LPBYTE)lp + sizeof(void**);
1897 *ptr = (char*)MapLS(lp) + sizeof(void**);
1900 *ptr = (void*)MapLS(lp);
1904 memcpy(p16, p32, size16);
1912 sz = (nibble & 7) + 1;
1913 memcpy(p16, p32, sz);
1916 size16 -= sz; /* DEBUG only */
1920 *(LPINT16)p16 = *(LPINT)p32;
1921 p16 += sizeof(INT16);
1923 size16 -= sizeof(INT16);
1926 *(LPUINT16)p16 = *(LPUINT)p32;
1927 p16 += sizeof(UINT16);
1928 p32 += sizeof(UINT);
1929 size16 -= sizeof(UINT16);
1933 p16 += sizeof(DWORD);
1934 p32 += sizeof(DWORD);
1935 size16 -= sizeof(DWORD);
1938 *(SEGPTR *)p16 = MapLS( *(LPSTR *)p32 );
1939 p16 += sizeof(SEGPTR);
1940 p32 += sizeof(LPSTR);
1941 size16 -= sizeof(SEGPTR);
1944 FIXME("Unknown nibble for mapping (%x)\n", nibble);
1949 if (size16 != 0) /* DEBUG only */
1950 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
1952 return WINMM_MAP_OKMEM;
1955 /**************************************************************************
1956 * MCI_MsgMapper32ATo16_Destroy [internal]
1958 * Helper for MCI_UnMapMsg32ATo16.
1960 static WINMM_MapType MCI_MsgMapper32ATo16_Destroy(void* ptr, int size16, DWORD map, BOOLEAN kept)
1963 void* msg16 = MapSL((SEGPTR)ptr);
1968 UnMapLS( (SEGPTR)ptr );
1970 alloc = (char*)msg16 - sizeof(void**);
1971 p32 = *(void**)alloc;
1975 memcpy(p32, p16, size16);
1980 memcpy(p32, p16, (nibble & 7) + 1);
1981 p16 += (nibble & 7) + 1;
1982 p32 += (nibble & 7) + 1;
1983 size16 -= (nibble & 7) + 1;
1987 *(LPINT)p32 = *(LPINT16)p16;
1988 p16 += sizeof(INT16);
1990 size16 -= sizeof(INT16);
1993 *(LPUINT)p32 = *(LPUINT16)p16;
1994 p16 += sizeof(UINT16);
1995 p32 += sizeof(UINT);
1996 size16 -= sizeof(UINT16);
1999 p16 += sizeof(UINT);
2000 p32 += sizeof(UINT);
2001 size16 -= sizeof(UINT);
2004 UnMapLS( *(SEGPTR *)p16 );
2005 p16 += sizeof(SEGPTR);
2006 p32 += sizeof(char*);
2007 size16 -= sizeof(SEGPTR);
2010 FIXME("Unknown nibble for mapping (%x)\n", nibble);
2015 if (size16 != 0) /* DEBUG only */
2016 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
2022 HeapFree( GetProcessHeap(), 0, alloc );
2024 return WINMM_MAP_OK;
2027 /**************************************************************************
2028 * MCI_MapMsg32ATo16 [internal]
2030 * Map a 32-A bit MCI message to a 16 bit MCI message.
2032 static WINMM_MapType MCI_MapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD* lParam)
2035 BOOLEAN keep = FALSE;
2039 return WINMM_MAP_OK;
2041 /* FIXME: to add also (with seg/linear modifications to do):
2042 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
2043 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
2047 size = sizeof(MCI_BREAK_PARMS);
2049 /* case MCI_CAPTURE */
2051 case MCI_CLOSE_DRIVER:
2053 size = sizeof(MCI_GENERIC_PARMS);
2055 /* case MCI_COPY: */
2058 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_CUE_PARMS); break;
2059 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_CUE_PARMS); break;*/ FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2060 default: size = sizeof(MCI_GENERIC_PARMS); break;
2066 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_DELETE_PARMS16); map = 0x0F1111FB; break;
2067 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_DELETE_PARMS); break;
2068 default: size = sizeof(MCI_GENERIC_PARMS); break;
2071 /* case MCI_ESCAPE: */
2074 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_FREEZE_PARMS); map = 0x0001111B; break;
2075 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
2076 default: size = sizeof(MCI_GENERIC_PARMS); break;
2079 case MCI_GETDEVCAPS:
2081 size = sizeof(MCI_GETDEVCAPS_PARMS);
2083 /* case MCI_INDEX: */
2086 LPMCI_INFO_PARMSA mip32a = (LPMCI_INFO_PARMSA)(*lParam);
2087 LPMCI_INFO_PARMS16 mip16;
2090 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_INFO_PARMS16); break;
2091 default: size = sizeof(MCI_INFO_PARMS16); break;
2093 mip16 = HeapAlloc( GetProcessHeap(), 0, size);
2096 mip16->dwCallback = mip32a->dwCallback;
2097 mip16->lpstrReturn = MapLS( mip32a->lpstrReturn );
2098 mip16->dwRetSize = mip32a->dwRetSize;
2099 if (uDevType == MCI_DEVTYPE_DIGITAL_VIDEO) {
2100 ((LPMCI_DGV_INFO_PARMS16)mip16)->dwItem = ((LPMCI_DGV_INFO_PARMSA)mip32a)->dwItem;
2103 return WINMM_MAP_NOMEM;
2105 *lParam = MapLS(mip16);
2107 return WINMM_MAP_OKMEM;
2108 /* case MCI_MARK: */
2109 /* case MCI_MONITOR: */
2111 case MCI_OPEN_DRIVER:
2113 LPMCI_OPEN_PARMSA mop32a = (LPMCI_OPEN_PARMSA)(*lParam);
2114 char* ptr = HeapAlloc( GetProcessHeap(), 0,
2115 sizeof(LPMCI_OPEN_PARMSA) + sizeof(MCI_OPEN_PARMS16) + 2 * sizeof(DWORD));
2116 LPMCI_OPEN_PARMS16 mop16;
2120 *(LPMCI_OPEN_PARMSA*)(ptr) = mop32a;
2121 mop16 = (LPMCI_OPEN_PARMS16)(ptr + sizeof(LPMCI_OPEN_PARMSA));
2122 mop16->dwCallback = mop32a->dwCallback;
2123 mop16->wDeviceID = mop32a->wDeviceID;
2124 if (dwFlags & MCI_OPEN_TYPE) {
2125 if (dwFlags & MCI_OPEN_TYPE_ID) {
2126 /* dword "transparent" value */
2127 mop16->lpstrDeviceType = (SEGPTR)mop32a->lpstrDeviceType;
2130 mop16->lpstrDeviceType = MapLS( mop32a->lpstrDeviceType );
2134 mop16->lpstrDeviceType = 0;
2136 if (dwFlags & MCI_OPEN_ELEMENT) {
2137 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
2138 mop16->lpstrElementName = (SEGPTR)mop32a->lpstrElementName;
2140 mop16->lpstrElementName = MapLS( mop32a->lpstrElementName );
2143 mop16->lpstrElementName = 0;
2145 if (dwFlags & MCI_OPEN_ALIAS) {
2146 mop16->lpstrAlias = MapLS( mop32a->lpstrAlias );
2148 mop16->lpstrAlias = 0;
2150 /* copy extended information if any...
2151 * FIXME: this may seg fault if initial structure does not contain them and
2152 * the reads after msip16 fail under LDT limits...
2153 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
2154 * should not take care of extended parameters, and should be used by MCI_Open
2155 * to fetch uDevType. When, this is known, the mapping for sending the
2156 * MCI_OPEN_DRIVER shall be done depending on uDevType.
2158 memcpy(mop16 + 1, mop32a + 1, 2 * sizeof(DWORD));
2160 return WINMM_MAP_NOMEM;
2162 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_PARMSA);
2164 return WINMM_MAP_OKMEM;
2165 /* case MCI_PASTE:*/
2167 size = sizeof(MCI_GENERIC_PARMS);
2170 size = sizeof(MCI_PLAY_PARMS);
2174 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
2175 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
2176 default: size = sizeof(MCI_GENERIC_PARMS); break;
2180 size = sizeof(MCI_GENERIC_PARMS);
2184 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECORD_PARMS16); map = 0x0F1111FB; break;
2185 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_RECORD_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2186 default: size = sizeof(MCI_RECORD_PARMS); break;
2190 size = sizeof(MCI_GENERIC_PARMS);
2194 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SEEK_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2195 default: size = sizeof(MCI_SEEK_PARMS); break;
2200 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SET_PARMS); break;
2201 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SET_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2202 case MCI_DEVTYPE_SEQUENCER: size = sizeof(MCI_SEQ_SET_PARMS); break;
2203 /* FIXME: normally the 16 and 32 bit structures are byte by byte aligned,
2204 * so not doing anything should work...
2206 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_SET_PARMS); break;
2207 default: size = sizeof(MCI_SET_PARMS); break;
2212 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SETAUDIO_PARMS16);map = 0x0000077FF; break;
2213 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2214 default: size = sizeof(MCI_GENERIC_PARMS); break;
2217 /* case MCI_SETTIMECODE:*/
2218 /* case MCI_SIGNAL:*/
2219 /* case MCI_SOUND:*/
2221 size = sizeof(MCI_SET_PARMS);
2227 * don't know if buffer for value is the one passed through lpstrDevice
2228 * or is provided by MCI driver.
2229 * Assuming solution 2: provided by MCI driver, so zeroing on entry
2231 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STATUS_PARMS16); map = 0x0B6FF; break;
2232 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2233 default: size = sizeof(MCI_STATUS_PARMS); break;
2238 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STEP_PARMS); break;
2239 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STEP_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2240 case MCI_DEVTYPE_VIDEODISC: size = sizeof(MCI_VD_STEP_PARMS); break;
2241 default: size = sizeof(MCI_GENERIC_PARMS); break;
2245 size = sizeof(MCI_SET_PARMS);
2249 LPMCI_SYSINFO_PARMSA msip32a = (LPMCI_SYSINFO_PARMSA)(*lParam);
2250 LPMCI_SYSINFO_PARMS16 msip16;
2251 char* ptr = HeapAlloc( GetProcessHeap(), 0,
2252 sizeof(LPMCI_SYSINFO_PARMSA) + sizeof(MCI_SYSINFO_PARMS16) );
2255 *(LPMCI_SYSINFO_PARMSA*)(ptr) = msip32a;
2256 msip16 = (LPMCI_SYSINFO_PARMS16)(ptr + sizeof(LPMCI_SYSINFO_PARMSA));
2258 msip16->dwCallback = msip32a->dwCallback;
2259 msip16->lpstrReturn = MapLS( msip32a->lpstrReturn );
2260 msip16->dwRetSize = msip32a->dwRetSize;
2261 msip16->dwNumber = msip32a->dwNumber;
2262 msip16->wDeviceType = msip32a->wDeviceType;
2264 return WINMM_MAP_NOMEM;
2266 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_SYSINFO_PARMSA);
2268 return WINMM_MAP_OKMEM;
2269 /* case MCI_UNDO: */
2272 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
2273 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; break;
2274 default: size = sizeof(MCI_GENERIC_PARMS); break;
2279 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_UPDATE_PARMS16); map = 0x000B1111B; break;
2280 default: size = sizeof(MCI_GENERIC_PARMS); break;
2285 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
2286 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
2287 default: size = sizeof(MCI_GENERIC_PARMS); break;
2292 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7FB; break;
2293 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7FB; break;
2294 default: size = sizeof(MCI_GENERIC_PARMS); break;
2299 LPMCI_OPEN_DRIVER_PARMSA modp32a = (LPMCI_OPEN_DRIVER_PARMSA)(*lParam);
2300 LPMCI_OPEN_DRIVER_PARMS16 modp16;
2301 char *ptr = HeapAlloc( GetProcessHeap(), 0,
2302 sizeof(LPMCI_OPEN_DRIVER_PARMSA) + sizeof(MCI_OPEN_DRIVER_PARMS16));
2305 *(LPMCI_OPEN_DRIVER_PARMSA*)(ptr) = modp32a;
2306 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSA));
2307 modp16->wDeviceID = modp32a->wDeviceID;
2308 modp16->lpstrParams = MapLS( modp32a->lpstrParams );
2309 /* other fields are gonna be filled by the driver, don't copy them */
2311 return WINMM_MAP_NOMEM;
2313 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_DRIVER_PARMSA);
2315 return WINMM_MAP_OKMEM;
2322 case DRV_QUERYCONFIGURE:
2325 case DRV_EXITSESSION:
2326 case DRV_EXITAPPLICATION:
2328 return WINMM_MAP_OK;
2331 FIXME("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
2332 return WINMM_MAP_MSGERROR;
2334 return MCI_MsgMapper32ATo16_Create((void**)lParam, size, map, keep);
2337 /**************************************************************************
2338 * MCI_UnMapMsg32ATo16 [internal]
2340 static WINMM_MapType MCI_UnMapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD lParam)
2343 BOOLEAN kept = FALSE; /* there is no need to compute size when kept is FALSE */
2349 /* case MCI_CAPTURE */
2351 case MCI_CLOSE_DRIVER:
2354 /* case MCI_COPY: */
2360 /* case MCI_ESCAPE: */
2363 case MCI_GETDEVCAPS:
2365 size = sizeof(MCI_GETDEVCAPS_PARMS);
2367 /* case MCI_INDEX: */
2370 LPMCI_INFO_PARMS16 mip16 = (LPMCI_INFO_PARMS16)MapSL(lParam);
2372 UnMapLS( mip16->lpstrReturn );
2373 HeapFree( GetProcessHeap(), 0, mip16 );
2375 return WINMM_MAP_OK;
2376 /* case MCI_MARK: */
2377 /* case MCI_MONITOR: */
2379 case MCI_OPEN_DRIVER:
2381 LPMCI_OPEN_PARMS16 mop16 = (LPMCI_OPEN_PARMS16)MapSL(lParam);
2382 LPMCI_OPEN_PARMSA mop32a = *(LPMCI_OPEN_PARMSA*)((char*)mop16 - sizeof(LPMCI_OPEN_PARMSA));
2384 mop32a->wDeviceID = mop16->wDeviceID;
2385 if ((dwFlags & MCI_OPEN_TYPE) && !(dwFlags & MCI_OPEN_TYPE_ID))
2386 UnMapLS( mop16->lpstrDeviceType );
2387 if ((dwFlags & MCI_OPEN_ELEMENT) && !(dwFlags & MCI_OPEN_ELEMENT_ID))
2388 UnMapLS( mop16->lpstrElementName );
2389 if (dwFlags & MCI_OPEN_ALIAS)
2390 UnMapLS( mop16->lpstrAlias );
2391 HeapFree( GetProcessHeap(), 0, (char*)mop16 - sizeof(LPMCI_OPEN_PARMSA) );
2393 return WINMM_MAP_OK;
2394 /* case MCI_PASTE:*/
2413 case MCI_DEVTYPE_DIGITAL_VIDEO: map = 0x0000077FF; break;
2414 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2417 /* case MCI_SETTIMECODE:*/
2418 /* case MCI_SIGNAL:*/
2419 /* case MCI_SOUND:*/
2425 case MCI_DEVTYPE_DIGITAL_VIDEO:
2427 LPMCI_DGV_STATUS_PARMS16 mdsp16 = (LPMCI_DGV_STATUS_PARMS16)MapSL(lParam);
2428 LPMCI_DGV_STATUS_PARMSA mdsp32a = *(LPMCI_DGV_STATUS_PARMSA*)((char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA));
2432 mdsp32a->dwReturn = mdsp16->dwReturn;
2433 if (dwFlags & MCI_DGV_STATUS_DISKSPACE) {
2434 TRACE("MCI_STATUS (DGV) lpstrDrive=%08lx\n", mdsp16->lpstrDrive);
2435 TRACE("MCI_STATUS (DGV) lpstrDrive=%s\n", (LPSTR)MapSL(mdsp16->lpstrDrive));
2436 UnMapLS( mdsp16->lpstrDrive );
2438 HeapFree( GetProcessHeap(), 0, (char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA) );
2440 return WINMM_MAP_NOMEM;
2443 return WINMM_MAP_OKMEM;
2444 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2445 default: size = sizeof(MCI_STATUS_PARMS); break;
2454 LPMCI_SYSINFO_PARMS16 msip16 = (LPMCI_SYSINFO_PARMS16)MapSL(lParam);
2455 LPMCI_SYSINFO_PARMSA msip32a = *(LPMCI_SYSINFO_PARMSA*)((char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA));
2459 msip16->dwCallback = msip32a->dwCallback;
2460 UnMapLS( msip16->lpstrReturn );
2461 HeapFree( GetProcessHeap(), 0, (char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA) );
2463 return WINMM_MAP_NOMEM;
2466 return WINMM_MAP_OKMEM;
2467 /* case MCI_UNDO: */
2474 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
2475 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
2481 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7666; break;
2482 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7666; break;
2485 /* FIXME: see map function */
2490 LPMCI_OPEN_DRIVER_PARMS16 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)MapSL(lParam);
2491 LPMCI_OPEN_DRIVER_PARMSA modp32a = *(LPMCI_OPEN_DRIVER_PARMSA*)((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA));
2494 modp32a->wCustomCommandTable = modp16->wCustomCommandTable;
2495 modp32a->wType = modp16->wType;
2496 UnMapLS( modp16->lpstrParams );
2497 HeapFree( GetProcessHeap(), 0, (char *)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA) );
2499 return WINMM_MAP_OK;
2506 case DRV_QUERYCONFIGURE:
2509 case DRV_EXITSESSION:
2510 case DRV_EXITAPPLICATION:
2512 FIXME("This is a hack\n");
2513 return WINMM_MAP_OK;
2515 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
2516 return WINMM_MAP_MSGERROR;
2518 return MCI_MsgMapper32ATo16_Destroy((void*)lParam, size, map, kept);
2522 /**************************************************************************
2523 * MCI_MapMsg16To32W [internal]
2525 static WINMM_MapType MCI_MapMsg16To32W(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD_PTR* lParam)
2528 return WINMM_MAP_OK;
2529 /* FIXME: to add also (with seg/linear modifications to do):
2530 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
2531 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
2534 /* case MCI_CAPTURE */
2536 case MCI_CLOSE_DRIVER:
2543 case MCI_GETDEVCAPS:
2544 /* case MCI_INDEX: */
2545 /* case MCI_MARK: */
2546 /* case MCI_MONITOR: */
2556 /* case MCI_SETTIMECODE:*/
2557 /* case MCI_SIGNAL:*/
2559 case MCI_STATUS: /* FIXME: is wrong for digital video */
2562 /* case MCI_UNDO: */
2566 *lParam = (DWORD)MapSL(*lParam);
2567 return WINMM_MAP_OK;
2569 /* in fact, I would also need the dwFlags... to see
2570 * which members of lParam are effectively used
2572 *lParam = (DWORD)MapSL(*lParam);
2573 FIXME("Current mapping may be wrong\n");
2577 LPMCI_BREAK_PARMS mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_BREAK_PARMS));
2578 LPMCI_BREAK_PARMS16 mbp16 = MapSL(*lParam);
2581 mbp32->dwCallback = mbp16->dwCallback;
2582 mbp32->nVirtKey = mbp16->nVirtKey;
2583 mbp32->hwndBreak = HWND_32(mbp16->hwndBreak);
2585 return WINMM_MAP_NOMEM;
2587 *lParam = (DWORD)mbp32;
2589 return WINMM_MAP_OKMEM;
2592 LPMCI_VD_ESCAPE_PARMSW mvep32w = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_VD_ESCAPE_PARMSW));
2593 LPMCI_VD_ESCAPE_PARMS16 mvep16 = MapSL(*lParam);
2596 mvep32w->dwCallback = mvep16->dwCallback;
2597 mvep32w->lpstrCommand = MCI_strdupAtoW(MapSL(mvep16->lpstrCommand));
2599 return WINMM_MAP_NOMEM;
2601 *lParam = (DWORD)mvep32w;
2603 return WINMM_MAP_OKMEM;
2606 LPMCI_INFO_PARMSW mip32w = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_INFO_PARMSW));
2607 LPMCI_INFO_PARMS16 mip16 = MapSL(*lParam);
2609 /* FIXME this is wrong if device is of type
2610 * MCI_DEVTYPE_DIGITAL_VIDEO, some members are not mapped
2613 *(LPMCI_INFO_PARMS16*)(mip32w) = mip16;
2614 mip32w = (LPMCI_INFO_PARMSW)((char*)mip32w + sizeof(LPMCI_INFO_PARMS16));
2615 mip32w->dwCallback = mip16->dwCallback;
2616 mip32w->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mip16->dwRetSize * sizeof(WCHAR));
2617 mip32w->dwRetSize = mip16->dwRetSize * sizeof(WCHAR);
2619 return WINMM_MAP_NOMEM;
2621 *lParam = (DWORD)mip32w;
2623 return WINMM_MAP_OKMEM;
2625 case MCI_OPEN_DRIVER:
2627 LPMCI_OPEN_PARMSW mop32w = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_OPEN_PARMSW) + 2 * sizeof(DWORD));
2628 LPMCI_OPEN_PARMS16 mop16 = MapSL(*lParam);
2631 *(LPMCI_OPEN_PARMS16*)(mop32w) = mop16;
2632 mop32w = (LPMCI_OPEN_PARMSW)((char*)mop32w + sizeof(LPMCI_OPEN_PARMS16));
2633 mop32w->dwCallback = mop16->dwCallback;
2634 mop32w->wDeviceID = mop16->wDeviceID;
2635 if( ( dwFlags & ( MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID)) == MCI_OPEN_TYPE)
2636 mop32w->lpstrDeviceType = MCI_strdupAtoW(MapSL(mop16->lpstrDeviceType));
2638 mop32w->lpstrDeviceType = (LPWSTR) mop16->lpstrDeviceType;
2639 if( ( dwFlags & ( MCI_OPEN_ELEMENT | MCI_OPEN_ELEMENT_ID)) == MCI_OPEN_ELEMENT)
2640 mop32w->lpstrElementName = MCI_strdupAtoW(MapSL(mop16->lpstrElementName));
2642 mop32w->lpstrElementName = (LPWSTR) mop16->lpstrElementName;
2643 if( ( dwFlags & MCI_OPEN_ALIAS))
2644 mop32w->lpstrAlias = MCI_strdupAtoW(MapSL(mop16->lpstrAlias));
2646 mop32w->lpstrAlias = (LPWSTR) mop16->lpstrAlias;
2647 /* copy extended information if any...
2648 * FIXME: this may seg fault if initial structure does not contain them and
2649 * the reads after msip16 fail under LDT limits...
2650 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
2651 * should not take care of extended parameters, and should be used by MCI_Open
2652 * to fetch uDevType. When, this is known, the mapping for sending the
2653 * MCI_OPEN_DRIVER shall be done depending on uDevType.
2655 memcpy(mop32w + 1, mop16 + 1, 2 * sizeof(DWORD));
2657 return WINMM_MAP_NOMEM;
2659 *lParam = (DWORD)mop32w;
2661 return WINMM_MAP_OKMEM;
2664 LPMCI_SYSINFO_PARMSW msip32w = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_SYSINFO_PARMSW));
2665 LPMCI_SYSINFO_PARMS16 msip16 = MapSL(*lParam);
2668 *(LPMCI_SYSINFO_PARMS16*)(msip32w) = msip16;
2669 msip32w = (LPMCI_SYSINFO_PARMSW)((char*)msip32w + sizeof(LPMCI_OPEN_PARMS16));
2670 msip32w->dwCallback = msip16->dwCallback;
2671 msip32w->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, msip16->dwRetSize * sizeof(WCHAR));
2672 msip32w->dwRetSize = msip16->dwRetSize;
2673 msip32w->dwNumber = msip16->dwNumber;
2674 msip32w->wDeviceType = msip16->wDeviceType;
2676 return WINMM_MAP_NOMEM;
2678 *lParam = (DWORD)msip32w;
2680 return WINMM_MAP_OKMEM;
2683 LPMCI_SOUND_PARMSW mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_SOUND_PARMSW));
2684 LPMCI_SOUND_PARMS16 mbp16 = MapSL(*lParam);
2687 mbp32->dwCallback = mbp16->dwCallback;
2688 mbp32->lpstrSoundName = MCI_strdupAtoW(MapSL(mbp16->lpstrSoundName));
2690 return WINMM_MAP_NOMEM;
2692 *lParam = (DWORD)mbp32;
2694 return WINMM_MAP_OKMEM;
2702 case DRV_QUERYCONFIGURE:
2705 case DRV_EXITSESSION:
2706 case DRV_EXITAPPLICATION:
2708 FIXME("This is a hack\n");
2709 return WINMM_MAP_OK;
2711 FIXME("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
2713 return WINMM_MAP_MSGERROR;
2716 /**************************************************************************
2717 * MCI_UnMapMsg16To32W [internal]
2719 static WINMM_MapType MCI_UnMapMsg16To32W(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD_PTR lParam)
2722 /* case MCI_CAPTURE */
2724 case MCI_CLOSE_DRIVER:
2731 case MCI_GETDEVCAPS:
2732 /* case MCI_INDEX: */
2733 /* case MCI_MARK: */
2734 /* case MCI_MONITOR: */
2744 /* case MCI_SETTIMECODE:*/
2745 /* case MCI_SIGNAL:*/
2750 /* case MCI_UNDO: */
2754 return WINMM_MAP_OK;
2757 /* FIXME ?? see Map function */
2758 return WINMM_MAP_OK;
2761 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
2762 return WINMM_MAP_OK;
2765 LPMCI_VD_ESCAPE_PARMSW mvep32W = (LPMCI_VD_ESCAPE_PARMSW)lParam;
2766 HeapFree(GetProcessHeap(), 0, (LPVOID)mvep32W->lpstrCommand);
2767 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
2769 return WINMM_MAP_OK;
2772 LPMCI_INFO_PARMSW mip32w = (LPMCI_INFO_PARMSW)lParam;
2773 LPMCI_INFO_PARMS16 mip16 = *(LPMCI_INFO_PARMS16*)((char*)mip32w - sizeof(LPMCI_INFO_PARMS16));
2775 WideCharToMultiByte(CP_ACP, 0,
2776 mip32w->lpstrReturn, mip32w->dwRetSize / sizeof(WCHAR),
2777 MapSL(mip16->lpstrReturn), mip16->dwRetSize,
2779 HeapFree(GetProcessHeap(), 0, (LPVOID)mip32w->lpstrReturn);
2780 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
2782 return WINMM_MAP_OK;
2785 LPMCI_SYSINFO_PARMSW msip32w = (LPMCI_SYSINFO_PARMSW)lParam;
2786 LPMCI_SYSINFO_PARMS16 msip16 = *(LPMCI_SYSINFO_PARMS16*)((char*)msip32w - sizeof(LPMCI_SYSINFO_PARMS16));
2788 WideCharToMultiByte(CP_ACP, 0,
2789 msip32w->lpstrReturn, msip32w->dwRetSize,
2790 MapSL(msip16->lpstrReturn), msip16->dwRetSize,
2792 HeapFree(GetProcessHeap(), 0, (LPVOID)msip32w->lpstrReturn);
2793 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
2795 return WINMM_MAP_OK;
2798 LPMCI_SOUND_PARMSW msp32W = (LPMCI_SOUND_PARMSW)lParam;
2799 HeapFree(GetProcessHeap(), 0, (LPVOID)msp32W->lpstrSoundName);
2800 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
2802 return WINMM_MAP_OK;
2804 case MCI_OPEN_DRIVER:
2806 LPMCI_OPEN_PARMSW mop32w = (LPMCI_OPEN_PARMSW)lParam;
2807 LPMCI_OPEN_PARMS16 mop16 = *(LPMCI_OPEN_PARMS16*)((char*)mop32w - sizeof(LPMCI_OPEN_PARMS16));
2809 mop16->wDeviceID = mop32w->wDeviceID;
2810 if( ( dwFlags & ( MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID)) == MCI_OPEN_TYPE)
2811 HeapFree(GetProcessHeap(), 0, (LPWSTR)mop32w->lpstrDeviceType);
2812 if( ( dwFlags & ( MCI_OPEN_ELEMENT | MCI_OPEN_ELEMENT_ID)) == MCI_OPEN_ELEMENT)
2813 HeapFree(GetProcessHeap(), 0, (LPWSTR)mop32w->lpstrElementName);
2814 if( ( dwFlags & MCI_OPEN_ALIAS))
2815 HeapFree(GetProcessHeap(), 0, (LPWSTR)mop32w->lpstrAlias);
2816 if (!HeapFree(GetProcessHeap(), 0, (LPVOID)(lParam - sizeof(LPMCI_OPEN_PARMS16))))
2817 FIXME("bad free line=%d\n", __LINE__);
2819 return WINMM_MAP_OK;
2827 case DRV_QUERYCONFIGURE:
2830 case DRV_EXITSESSION:
2831 case DRV_EXITAPPLICATION:
2833 FIXME("This is a hack\n");
2834 return WINMM_MAP_OK;
2836 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
2838 return WINMM_MAP_MSGERROR;
2843 * 0001 squeeze signed 4 bytes to 2 bytes *( LPINT16)D = ( INT16)*( LPINT16)S; D += 2; S += 4
2844 * 0010 squeeze unsigned 4 bytes to 2 bytes *(LPUINT16)D = (UINT16)*(LPUINT16)S; D += 2; S += 4
2847 * 0110 zero 4 bytes *(DWORD)D = 0 D += 4; S += 4
2848 * 0111 copy string *(LPSTR*)D = seg dup(*(LPSTR*)S) D += 4; S += 4
2849 * 1xxx copy xxx + 1 bytes memcpy(D, S, xxx + 1); D += xxx+1; S += xxx+1
2852 /**************************************************************************
2853 * MCI_MsgMapper32WTo16_Create [internal]
2855 * Helper for MCI_MapMsg32WTo16.
2856 * Maps the 32 bit pointer (*ptr), of size bytes, to an allocated 16 bit
2857 * segmented pointer.
2858 * map contains a list of action to be performed for the mapping (see list
2860 * if keep is TRUE, keeps track of in 32 bit ptr in allocated 16 bit area.
2862 static WINMM_MapType MCI_MsgMapper32WTo16_Create(void** ptr, int size16, DWORD map, BOOLEAN keep)
2864 void* lp = HeapAlloc( GetProcessHeap(), 0, (keep ? sizeof(void**) : 0) + size16 );
2868 return WINMM_MAP_NOMEM;
2870 p32 = (LPBYTE)(*ptr);
2873 p16 = (LPBYTE)lp + sizeof(void**);
2874 *ptr = (char*)MapLS(lp) + sizeof(void**);
2877 *ptr = (void*)MapLS(lp);
2881 memcpy(p16, p32, size16);
2889 sz = (nibble & 7) + 1;
2890 memcpy(p16, p32, sz);
2893 size16 -= sz; /* DEBUG only */
2897 *(LPINT16)p16 = *(LPINT)p32;
2898 p16 += sizeof(INT16);
2900 size16 -= sizeof(INT16);
2903 *(LPUINT16)p16 = *(LPUINT)p32;
2904 p16 += sizeof(UINT16);
2905 p32 += sizeof(UINT);
2906 size16 -= sizeof(UINT16);
2910 p16 += sizeof(DWORD);
2911 p32 += sizeof(DWORD);
2912 size16 -= sizeof(DWORD);
2915 *(SEGPTR *)p16 = MapLS( MCI_strdupWtoA( *(LPCWSTR *)p32 ) );
2916 p16 += sizeof(SEGPTR);
2917 p32 += sizeof(LPSTR);
2918 size16 -= sizeof(SEGPTR);
2921 FIXME("Unknown nibble for mapping (%x)\n", nibble);
2926 if (size16 != 0) /* DEBUG only */
2927 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
2929 return WINMM_MAP_OKMEM;
2932 /**************************************************************************
2933 * MCI_MsgMapper32WTo16_Destroy [internal]
2935 * Helper for MCI_UnMapMsg32WTo16.
2937 static WINMM_MapType MCI_MsgMapper32WTo16_Destroy(void* ptr, int size16, DWORD map, BOOLEAN kept)
2940 void* msg16 = MapSL((SEGPTR)ptr);
2945 UnMapLS( (SEGPTR)ptr );
2947 alloc = (char*)msg16 - sizeof(void**);
2948 p32 = *(void**)alloc;
2952 memcpy(p32, p16, size16);
2957 memcpy(p32, p16, (nibble & 7) + 1);
2958 p16 += (nibble & 7) + 1;
2959 p32 += (nibble & 7) + 1;
2960 size16 -= (nibble & 7) + 1;
2964 *(LPINT)p32 = *(LPINT16)p16;
2965 p16 += sizeof(INT16);
2967 size16 -= sizeof(INT16);
2970 *(LPUINT)p32 = *(LPUINT16)p16;
2971 p16 += sizeof(UINT16);
2972 p32 += sizeof(UINT);
2973 size16 -= sizeof(UINT16);
2976 p16 += sizeof(UINT);
2977 p32 += sizeof(UINT);
2978 size16 -= sizeof(UINT);
2981 HeapFree(GetProcessHeap(), 0, MapSL(*(SEGPTR *)p16));
2982 UnMapLS( *(SEGPTR *)p16 );
2983 p16 += sizeof(SEGPTR);
2984 p32 += sizeof(char*);
2985 size16 -= sizeof(SEGPTR);
2988 FIXME("Unknown nibble for mapping (%x)\n", nibble);
2993 if (size16 != 0) /* DEBUG only */
2994 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
3000 HeapFree( GetProcessHeap(), 0, alloc );
3002 return WINMM_MAP_OK;
3005 /**************************************************************************
3006 * MCI_MapMsg32WTo16 [internal]
3008 * Map a 32W bit MCI message to a 16 bit MCI message.
3010 static WINMM_MapType MCI_MapMsg32WTo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD_PTR* lParam)
3013 BOOLEAN keep = FALSE;
3017 return WINMM_MAP_OK;
3019 /* FIXME: to add also (with seg/linear modifications to do):
3020 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
3021 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
3025 size = sizeof(MCI_BREAK_PARMS);
3027 /* case MCI_CAPTURE */
3029 case MCI_CLOSE_DRIVER:
3031 size = sizeof(MCI_GENERIC_PARMS);
3033 /* case MCI_COPY: */
3036 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_CUE_PARMS); break;
3037 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_CUE_PARMS); break;*/ FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3038 default: size = sizeof(MCI_GENERIC_PARMS); break;
3044 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_DELETE_PARMS16); map = 0x0F1111FB; break;
3045 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_DELETE_PARMS); break;
3046 default: size = sizeof(MCI_GENERIC_PARMS); break;
3049 /* case MCI_ESCAPE: */
3052 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_FREEZE_PARMS); map = 0x0001111B; break;
3053 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
3054 default: size = sizeof(MCI_GENERIC_PARMS); break;
3057 case MCI_GETDEVCAPS:
3059 size = sizeof(MCI_GETDEVCAPS_PARMS);
3061 /* case MCI_INDEX: */
3064 LPMCI_INFO_PARMSW mip32w = (LPMCI_INFO_PARMSW)(*lParam);
3066 LPMCI_INFO_PARMS16 mip16;
3069 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_INFO_PARMS16); break;
3070 default: size = sizeof(MCI_INFO_PARMS16); break;
3072 ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMCI_INFO_PARMSW) + size);
3075 *(LPMCI_INFO_PARMSW*)ptr = mip32w;
3076 mip16 = (LPMCI_INFO_PARMS16)(ptr + sizeof(LPMCI_INFO_PARMSW));
3077 mip16->dwCallback = mip32w->dwCallback;
3078 mip16->lpstrReturn = MapLS( HeapAlloc(GetProcessHeap(), 0, mip32w->dwRetSize / sizeof(WCHAR)) );
3079 mip16->dwRetSize = mip32w->dwRetSize / sizeof(WCHAR);
3080 if (uDevType == MCI_DEVTYPE_DIGITAL_VIDEO) {
3081 ((LPMCI_DGV_INFO_PARMS16)mip16)->dwItem = ((LPMCI_DGV_INFO_PARMSW)mip32w)->dwItem;
3084 return WINMM_MAP_NOMEM;
3086 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_INFO_PARMSW);
3088 return WINMM_MAP_OKMEM;
3089 /* case MCI_MARK: */
3090 /* case MCI_MONITOR: */
3092 case MCI_OPEN_DRIVER:
3094 LPMCI_OPEN_PARMSW mop32w = (LPMCI_OPEN_PARMSW)(*lParam);
3095 char* ptr = HeapAlloc( GetProcessHeap(), 0,
3096 sizeof(LPMCI_OPEN_PARMSW) + sizeof(MCI_OPEN_PARMS16) + 2 * sizeof(DWORD));
3097 LPMCI_OPEN_PARMS16 mop16;
3101 *(LPMCI_OPEN_PARMSW*)(ptr) = mop32w;
3102 mop16 = (LPMCI_OPEN_PARMS16)(ptr + sizeof(LPMCI_OPEN_PARMSW));
3103 mop16->dwCallback = mop32w->dwCallback;
3104 mop16->wDeviceID = mop32w->wDeviceID;
3105 if (dwFlags & MCI_OPEN_TYPE) {
3106 if (dwFlags & MCI_OPEN_TYPE_ID) {
3107 /* dword "transparent" value */
3108 mop16->lpstrDeviceType = (SEGPTR)mop32w->lpstrDeviceType;
3111 mop16->lpstrDeviceType = MapLS( MCI_strdupWtoA(mop32w->lpstrDeviceType) );
3115 mop16->lpstrDeviceType = 0;
3117 if (dwFlags & MCI_OPEN_ELEMENT) {
3118 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
3119 mop16->lpstrElementName = (SEGPTR)mop32w->lpstrElementName;
3121 mop16->lpstrElementName = MapLS( MCI_strdupWtoA(mop32w->lpstrElementName) );
3124 mop16->lpstrElementName = 0;
3126 if (dwFlags & MCI_OPEN_ALIAS) {
3127 mop16->lpstrAlias = MapLS( MCI_strdupWtoA(mop32w->lpstrAlias) );
3129 mop16->lpstrAlias = 0;
3131 /* copy extended information if any...
3132 * FIXME: this may seg fault if initial structure does not contain them and
3133 * the reads after msip16 fail under LDT limits...
3134 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
3135 * should not take care of extended parameters, and should be used by MCI_Open
3136 * to fetch uDevType. When, this is known, the mapping for sending the
3137 * MCI_OPEN_DRIVER shall be done depending on uDevType.
3139 memcpy(mop16 + 1, mop32w + 1, 2 * sizeof(DWORD));
3141 return WINMM_MAP_NOMEM;
3143 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_PARMSW);
3145 return WINMM_MAP_OKMEM;
3146 /* case MCI_PASTE:*/
3148 size = sizeof(MCI_GENERIC_PARMS);
3151 size = sizeof(MCI_PLAY_PARMS);
3155 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
3156 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
3157 default: size = sizeof(MCI_GENERIC_PARMS); break;
3161 size = sizeof(MCI_GENERIC_PARMS);
3165 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECORD_PARMS16); map = 0x0F1111FB; break;
3166 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_RECORD_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3167 default: size = sizeof(MCI_RECORD_PARMS); break;
3171 size = sizeof(MCI_GENERIC_PARMS);
3175 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SEEK_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3176 default: size = sizeof(MCI_SEEK_PARMS); break;
3181 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SET_PARMS); break;
3182 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SET_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3183 case MCI_DEVTYPE_SEQUENCER: size = sizeof(MCI_SEQ_SET_PARMS); break;
3184 /* FIXME: normally the 16 and 32 bit structures are byte by byte aligned,
3185 * so not doing anything should work...
3187 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_SET_PARMS); break;
3188 default: size = sizeof(MCI_SET_PARMS); break;
3193 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SETAUDIO_PARMS16);map = 0x0000077FF; break;
3194 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3195 default: size = sizeof(MCI_GENERIC_PARMS); break;
3198 /* case MCI_SETTIMECODE:*/
3199 /* case MCI_SIGNAL:*/
3200 /* case MCI_SOUND:*/
3202 size = sizeof(MCI_SET_PARMS);
3208 * don't know if buffer for value is the one passed through lpstrDevice
3209 * or is provided by MCI driver.
3210 * Assuming solution 2: provided by MCI driver, so zeroing on entry
3212 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STATUS_PARMS16); map = 0x0B6FF; break;
3213 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3214 default: size = sizeof(MCI_STATUS_PARMS); break;
3219 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STEP_PARMS); break;
3220 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STEP_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3221 case MCI_DEVTYPE_VIDEODISC: size = sizeof(MCI_VD_STEP_PARMS); break;
3222 default: size = sizeof(MCI_GENERIC_PARMS); break;
3226 size = sizeof(MCI_SET_PARMS);
3230 LPMCI_SYSINFO_PARMSW msip32w = (LPMCI_SYSINFO_PARMSW)(*lParam);
3231 LPMCI_SYSINFO_PARMS16 msip16;
3232 char* ptr = HeapAlloc( GetProcessHeap(), 0,
3233 sizeof(LPMCI_SYSINFO_PARMSW) + sizeof(MCI_SYSINFO_PARMS16) );
3236 *(LPMCI_SYSINFO_PARMSW*)(ptr) = msip32w;
3237 msip16 = (LPMCI_SYSINFO_PARMS16)(ptr + sizeof(LPMCI_SYSINFO_PARMSW));
3239 msip16->dwCallback = msip32w->dwCallback;
3240 msip16->lpstrReturn = MapLS( HeapAlloc(GetProcessHeap(), 0, msip32w->dwRetSize) );
3241 msip16->dwRetSize = msip32w->dwRetSize;
3242 msip16->dwNumber = msip32w->dwNumber;
3243 msip16->wDeviceType = msip32w->wDeviceType;
3245 return WINMM_MAP_NOMEM;
3247 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_SYSINFO_PARMSW);
3249 return WINMM_MAP_OKMEM;
3250 /* case MCI_UNDO: */
3253 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
3254 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; break;
3255 default: size = sizeof(MCI_GENERIC_PARMS); break;
3260 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_UPDATE_PARMS16); map = 0x000B1111B; break;
3261 default: size = sizeof(MCI_GENERIC_PARMS); break;
3266 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
3267 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
3268 default: size = sizeof(MCI_GENERIC_PARMS); break;
3273 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7FB; break;
3274 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7FB; break;
3275 default: size = sizeof(MCI_GENERIC_PARMS); break;
3280 LPMCI_OPEN_DRIVER_PARMSW modp32w = (LPMCI_OPEN_DRIVER_PARMSW)(*lParam);
3281 LPMCI_OPEN_DRIVER_PARMS16 modp16;
3282 char *ptr = HeapAlloc( GetProcessHeap(), 0,
3283 sizeof(LPMCI_OPEN_DRIVER_PARMSW) + sizeof(MCI_OPEN_DRIVER_PARMS16));
3286 *(LPMCI_OPEN_DRIVER_PARMSW*)(ptr) = modp32w;
3287 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSW));
3288 modp16->wDeviceID = modp32w->wDeviceID;
3289 modp16->lpstrParams = MapLS( MCI_strdupWtoA(modp32w->lpstrParams) );
3290 /* other fields are gonna be filled by the driver, don't copy them */
3292 return WINMM_MAP_NOMEM;
3294 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_DRIVER_PARMSW);
3296 return WINMM_MAP_OKMEM;
3303 case DRV_QUERYCONFIGURE:
3306 case DRV_EXITSESSION:
3307 case DRV_EXITAPPLICATION:
3309 return WINMM_MAP_OK;
3312 FIXME("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
3313 return WINMM_MAP_MSGERROR;
3315 return MCI_MsgMapper32WTo16_Create((void**)lParam, size, map, keep);
3318 /**************************************************************************
3319 * MCI_UnMapMsg32WTo16 [internal]
3321 static WINMM_MapType MCI_UnMapMsg32WTo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD_PTR lParam)
3324 BOOLEAN kept = FALSE; /* there is no need to compute size when kept is FALSE */
3330 /* case MCI_CAPTURE */
3332 case MCI_CLOSE_DRIVER:
3335 /* case MCI_COPY: */
3341 /* case MCI_ESCAPE: */
3344 case MCI_GETDEVCAPS:
3346 size = sizeof(MCI_GETDEVCAPS_PARMS);
3348 /* case MCI_INDEX: */
3351 LPMCI_INFO_PARMS16 mip16 = (LPMCI_INFO_PARMS16)MapSL(lParam);
3352 LPMCI_INFO_PARMSW mip32w = *(LPMCI_INFO_PARMSW*)((char*)mip16 - sizeof(LPMCI_INFO_PARMSW));
3354 MultiByteToWideChar(CP_ACP, 0, MapSL(mip16->lpstrReturn), mip16->dwRetSize,
3355 mip32w->lpstrReturn, mip32w->dwRetSize / sizeof(WCHAR));
3357 UnMapLS( mip16->lpstrReturn );
3358 HeapFree( GetProcessHeap(), 0, (void*)MapSL(mip16->lpstrReturn) );
3359 HeapFree( GetProcessHeap(), 0, (char*)mip16 - sizeof(LPMCI_OPEN_PARMSW) );
3361 return WINMM_MAP_OK;
3362 /* case MCI_MARK: */
3363 /* case MCI_MONITOR: */
3365 case MCI_OPEN_DRIVER:
3367 LPMCI_OPEN_PARMS16 mop16 = (LPMCI_OPEN_PARMS16)MapSL(lParam);
3368 LPMCI_OPEN_PARMSW mop32w = *(LPMCI_OPEN_PARMSW*)((char*)mop16 - sizeof(LPMCI_OPEN_PARMSW));
3370 mop32w->wDeviceID = mop16->wDeviceID;
3371 if ((dwFlags & MCI_OPEN_TYPE) && !(dwFlags & MCI_OPEN_TYPE_ID))
3373 HeapFree(GetProcessHeap(), 0, MapSL(mop16->lpstrDeviceType));
3374 UnMapLS( mop16->lpstrDeviceType );
3376 if ((dwFlags & MCI_OPEN_ELEMENT) && !(dwFlags & MCI_OPEN_ELEMENT_ID))
3378 HeapFree(GetProcessHeap(), 0, MapSL(mop16->lpstrElementName));
3379 UnMapLS( mop16->lpstrElementName );
3381 if (dwFlags & MCI_OPEN_ALIAS)
3383 HeapFree(GetProcessHeap(), 0, MapSL(mop16->lpstrAlias));
3384 UnMapLS( mop16->lpstrAlias );
3386 HeapFree( GetProcessHeap(), 0, (char*)mop16 - sizeof(LPMCI_OPEN_PARMSW) );
3388 return WINMM_MAP_OK;
3389 /* case MCI_PASTE:*/
3408 case MCI_DEVTYPE_DIGITAL_VIDEO: map = 0x0000077FF; break;
3409 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3412 /* case MCI_SETTIMECODE:*/
3413 /* case MCI_SIGNAL:*/
3414 /* case MCI_SOUND:*/
3420 case MCI_DEVTYPE_DIGITAL_VIDEO:
3422 LPMCI_DGV_STATUS_PARMS16 mdsp16 = (LPMCI_DGV_STATUS_PARMS16)MapSL(lParam);
3423 LPMCI_DGV_STATUS_PARMSA mdsp32a = *(LPMCI_DGV_STATUS_PARMSA*)((char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA));
3427 mdsp32a->dwReturn = mdsp16->dwReturn;
3428 if (dwFlags & MCI_DGV_STATUS_DISKSPACE) {
3429 TRACE("MCI_STATUS (DGV) lpstrDrive=%08lx\n", mdsp16->lpstrDrive);
3430 TRACE("MCI_STATUS (DGV) lpstrDrive=%s\n", (LPSTR)MapSL(mdsp16->lpstrDrive));
3431 UnMapLS( mdsp16->lpstrDrive );
3433 HeapFree( GetProcessHeap(), 0, (char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA) );
3435 return WINMM_MAP_NOMEM;
3438 return WINMM_MAP_OKMEM;
3439 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
3440 default: size = sizeof(MCI_STATUS_PARMS); break;
3449 LPMCI_SYSINFO_PARMS16 msip16 = (LPMCI_SYSINFO_PARMS16)MapSL(lParam);
3450 LPMCI_SYSINFO_PARMSW msip32w = *(LPMCI_SYSINFO_PARMSW*)((char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSW));
3454 MultiByteToWideChar(CP_ACP, 0, MapSL(msip16->lpstrReturn), msip16->dwRetSize,
3455 msip32w->lpstrReturn, msip32w->dwRetSize);
3456 UnMapLS( msip16->lpstrReturn );
3457 HeapFree( GetProcessHeap(), 0, MapSL(msip16->lpstrReturn) );
3458 HeapFree( GetProcessHeap(), 0, (char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSW) );
3460 return WINMM_MAP_NOMEM;
3463 return WINMM_MAP_OKMEM;
3464 /* case MCI_UNDO: */
3471 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
3472 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
3478 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7666; break;
3479 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7666; break;
3482 /* FIXME: see map function */
3486 LPMCI_OPEN_DRIVER_PARMS16 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)MapSL(lParam);
3487 LPMCI_OPEN_DRIVER_PARMSW modp32w = *(LPMCI_OPEN_DRIVER_PARMSW*)((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSW));
3490 modp32w->wCustomCommandTable = modp16->wCustomCommandTable;
3491 modp32w->wType = modp16->wType;
3492 HeapFree(GetProcessHeap(), 0, MapSL(modp16->lpstrParams));
3493 UnMapLS( modp16->lpstrParams );
3494 HeapFree( GetProcessHeap(), 0, (char *)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSW) );
3496 return WINMM_MAP_OK;
3503 case DRV_QUERYCONFIGURE:
3506 case DRV_EXITSESSION:
3507 case DRV_EXITAPPLICATION:
3509 FIXME("This is a hack\n");
3510 return WINMM_MAP_OK;
3513 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
3514 return WINMM_MAP_MSGERROR;
3516 return MCI_MsgMapper32WTo16_Destroy((void*)lParam, size, map, kept);
3519 void MMDRV_Init16(void)
3521 #define A(_x,_y) MMDRV_InstallMap(_x, \
3522 MMDRV_##_y##_Map16To32W, MMDRV_##_y##_UnMap16To32W, \
3523 MMDRV_##_y##_Map32WTo16, MMDRV_##_y##_UnMap32WTo16, \
3524 MMDRV_##_y##_Callback)
3526 A(MMDRV_MIXER, Mixer);
3527 A(MMDRV_MIDIIN, MidiIn);
3528 A(MMDRV_MIDIOUT, MidiOut);
3529 A(MMDRV_WAVEIN, WaveIn);
3530 A(MMDRV_WAVEOUT, WaveOut);
3533 pFnCallMMDrvFunc16 = MMDRV_CallMMDrvFunc16;
3534 pFnLoadMMDrvFunc16 = MMDRV_LoadMMDrvFunc16;
3536 pFnMciMapMsg16To32W = MCI_MapMsg16To32W;
3537 pFnMciUnMapMsg16To32W = MCI_UnMapMsg16To32W;
3538 pFnMciMapMsg32WTo16 = MCI_MapMsg32WTo16;
3539 pFnMciUnMapMsg32WTo16 = MCI_UnMapMsg32WTo16;