Link to ntdll.
[wine.git] / dlls / winmm / message16.c
blobfaaca59a850c23a6aa8b7e7a5b8b170730a5accf
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MMSYTEM MCI and low level mapping functions
6 * Copyright 1999 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <string.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <assert.h>
27 #include "wine/winbase16.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winver.h"
32 #include "wownt32.h"
33 #include "winemm16.h"
34 #include "digitalv.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
39 /**************************************************************************
40 * MMDRV_Callback [internal]
42 static void MMDRV_Callback(LPWINE_MLD mld, HDRVR hDev, UINT uMsg, DWORD dwParam1, DWORD dwParam2)
44 TRACE("CB (*%08lx)(%p %08x %08lx %08lx %08lx\n",
45 mld->dwCallback, hDev, uMsg, mld->dwClientInstance, dwParam1, dwParam2);
47 if (!mld->bFrom32 && (mld->dwFlags & DCB_TYPEMASK) == DCB_FUNCTION)
49 WORD args[8];
50 /* 16 bit func, call it */
51 TRACE("Function (16 bit) !\n");
53 args[7] = HDRVR_16(hDev);
54 args[6] = uMsg;
55 args[5] = HIWORD(mld->dwClientInstance);
56 args[4] = LOWORD(mld->dwClientInstance);
57 args[3] = HIWORD(dwParam1);
58 args[2] = LOWORD(dwParam1);
59 args[1] = HIWORD(dwParam2);
60 args[0] = LOWORD(dwParam2);
61 WOWCallback16Ex( mld->dwCallback, WCB16_PASCAL, sizeof(args), args, NULL );
62 } else {
63 DriverCallback(mld->dwCallback, mld->dwFlags, hDev, uMsg,
64 mld->dwClientInstance, dwParam1, dwParam2);
68 /* =================================
69 * A U X M A P P E R S
70 * ================================= */
72 /**************************************************************************
73 * MMDRV_Aux_Map16To32A [internal]
75 static WINMM_MapType MMDRV_Aux_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
77 return WINMM_MAP_MSGERROR;
80 /**************************************************************************
81 * MMDRV_Aux_UnMap16To32A [internal]
83 static WINMM_MapType MMDRV_Aux_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
85 return WINMM_MAP_MSGERROR;
88 /**************************************************************************
89 * MMDRV_Aux_Map32ATo16 [internal]
91 static WINMM_MapType MMDRV_Aux_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
93 return WINMM_MAP_MSGERROR;
96 /**************************************************************************
97 * MMDRV_Aux_UnMap32ATo16 [internal]
99 static WINMM_MapType MMDRV_Aux_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
101 #if 0
102 case AUXDM_GETDEVCAPS:
103 lpCaps->wMid = ac16.wMid;
104 lpCaps->wPid = ac16.wPid;
105 lpCaps->vDriverVersion = ac16.vDriverVersion;
106 strcpy(lpCaps->szPname, ac16.szPname);
107 lpCaps->wTechnology = ac16.wTechnology;
108 lpCaps->dwSupport = ac16.dwSupport;
109 #endif
110 return WINMM_MAP_MSGERROR;
113 /**************************************************************************
114 * MMDRV_Aux_Callback [internal]
116 static void CALLBACK MMDRV_Aux_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
118 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
120 FIXME("NIY\n");
121 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
124 /* =================================
125 * M I X E R M A P P E R S
126 * ================================= */
128 /**************************************************************************
129 * xMMDRV_Mixer_Map16To32A [internal]
131 static WINMM_MapType MMDRV_Mixer_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
133 return WINMM_MAP_MSGERROR;
136 /**************************************************************************
137 * MMDRV_Mixer_UnMap16To32A [internal]
139 static WINMM_MapType MMDRV_Mixer_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
141 #if 0
142 MIXERCAPSA micA;
143 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
145 if (ret == MMSYSERR_NOERROR) {
146 mixcaps->wMid = micA.wMid;
147 mixcaps->wPid = micA.wPid;
148 mixcaps->vDriverVersion = micA.vDriverVersion;
149 strcpy(mixcaps->szPname, micA.szPname);
150 mixcaps->fdwSupport = micA.fdwSupport;
151 mixcaps->cDestinations = micA.cDestinations;
153 return ret;
154 #endif
155 return WINMM_MAP_MSGERROR;
158 /**************************************************************************
159 * MMDRV_Mixer_Map32ATo16 [internal]
161 static WINMM_MapType MMDRV_Mixer_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
163 return WINMM_MAP_MSGERROR;
166 /**************************************************************************
167 * MMDRV_Mixer_UnMap32ATo16 [internal]
169 static WINMM_MapType MMDRV_Mixer_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
171 return WINMM_MAP_MSGERROR;
174 /**************************************************************************
175 * MMDRV_Mixer_Callback [internal]
177 static void CALLBACK MMDRV_Mixer_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
179 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
181 FIXME("NIY\n");
182 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
185 /* =================================
186 * M I D I I N M A P P E R S
187 * ================================= */
189 /**************************************************************************
190 * MMDRV_MidiIn_Map16To32A [internal]
192 static WINMM_MapType MMDRV_MidiIn_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
194 return WINMM_MAP_MSGERROR;
197 /**************************************************************************
198 * MMDRV_MidiIn_UnMap16To32A [internal]
200 static WINMM_MapType MMDRV_MidiIn_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
202 return WINMM_MAP_MSGERROR;
205 /**************************************************************************
206 * MMDRV_MidiIn_Map32ATo16 [internal]
208 static WINMM_MapType MMDRV_MidiIn_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
210 return WINMM_MAP_MSGERROR;
213 /**************************************************************************
214 * MMDRV_MidiIn_UnMap32ATo16 [internal]
216 static WINMM_MapType MMDRV_MidiIn_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
218 return WINMM_MAP_MSGERROR;
221 /**************************************************************************
222 * MMDRV_MidiIn_Callback [internal]
224 static void CALLBACK MMDRV_MidiIn_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
226 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
228 switch (uMsg) {
229 case MIM_OPEN:
230 case MIM_CLOSE:
231 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
233 case MIM_DATA:
234 case MIM_MOREDATA:
235 case MIM_ERROR:
236 /* dwParam1 & dwParam2 are are data, nothing to do */
237 break;
238 case MIM_LONGDATA:
239 case MIM_LONGERROR:
240 /* dwParam1 points to a MidiHdr, work to be done !!! */
241 if (mld->bFrom32 && !MMDRV_Is32(mld->mmdIndex)) {
242 /* initial map is: 32 => 16 */
243 LPMIDIHDR mh16 = MapSL(dwParam1);
244 LPMIDIHDR mh32 = *(LPMIDIHDR*)((LPSTR)mh16 - sizeof(LPMIDIHDR));
246 dwParam1 = (DWORD)mh32;
247 mh32->dwFlags = mh16->dwFlags;
248 mh32->dwBytesRecorded = mh16->dwBytesRecorded;
249 if (mh32->reserved >= sizeof(MIDIHDR))
250 mh32->dwOffset = mh16->dwOffset;
251 } else if (!mld->bFrom32 && MMDRV_Is32(mld->mmdIndex)) {
252 /* initial map is: 16 => 32 */
253 LPMIDIHDR mh32 = (LPMIDIHDR)(dwParam1);
254 SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR));
255 LPMIDIHDR mh16 = MapSL(segmh16);
257 dwParam1 = (DWORD)segmh16;
258 mh16->dwFlags = mh32->dwFlags;
259 mh16->dwBytesRecorded = mh32->dwBytesRecorded;
260 if (mh16->reserved >= sizeof(MIDIHDR))
261 mh16->dwOffset = mh32->dwOffset;
263 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
264 break;
265 /* case MOM_POSITIONCB: */
266 default:
267 ERR("Unknown msg %u\n", uMsg);
270 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
273 /* =================================
274 * M I D I O U T M A P P E R S
275 * ================================= */
277 /**************************************************************************
278 * MMDRV_MidiOut_Map16To32A [internal]
280 static WINMM_MapType MMDRV_MidiOut_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
282 WINMM_MapType ret = WINMM_MAP_MSGERROR;
284 switch (wMsg) {
285 case MODM_GETNUMDEVS:
286 case MODM_DATA:
287 case MODM_RESET:
288 case MODM_SETVOLUME:
289 ret = WINMM_MAP_OK;
290 break;
292 case MODM_OPEN:
293 case MODM_CLOSE:
294 case MODM_GETVOLUME:
295 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
296 break;
298 case MODM_GETDEVCAPS:
300 LPMIDIOUTCAPSA moc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPS16) + sizeof(MIDIOUTCAPSA));
301 LPMIDIOUTCAPS16 moc16 = MapSL(*lpParam1);
303 if (moc32) {
304 *(LPMIDIOUTCAPS16*)moc32 = moc16;
305 moc32 = (LPMIDIOUTCAPSA)((LPSTR)moc32 + sizeof(LPMIDIOUTCAPS16));
306 *lpParam1 = (DWORD)moc32;
307 *lpParam2 = sizeof(MIDIOUTCAPSA);
309 ret = WINMM_MAP_OKMEM;
310 } else {
311 ret = WINMM_MAP_NOMEM;
314 break;
315 case MODM_PREPARE:
317 LPMIDIHDR mh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIHDR) + sizeof(MIDIHDR));
318 LPMIDIHDR mh16 = MapSL(*lpParam1);
320 if (mh32) {
321 *(LPMIDIHDR*)mh32 = (LPMIDIHDR)*lpParam1;
322 mh32 = (LPMIDIHDR)((LPSTR)mh32 + sizeof(LPMIDIHDR));
323 mh32->lpData = MapSL((SEGPTR)mh16->lpData);
324 mh32->dwBufferLength = mh16->dwBufferLength;
325 mh32->dwBytesRecorded = mh16->dwBytesRecorded;
326 mh32->dwUser = mh16->dwUser;
327 mh32->dwFlags = mh16->dwFlags;
328 /* FIXME: nothing on mh32->lpNext */
329 /* could link the mh32->lpNext at this level for memory house keeping */
330 mh32->dwOffset = (*lpParam2 >= sizeof(MIDIHDR)) ? ((LPMIDIHDR)mh16)->dwOffset : 0;
331 mh16->lpNext = mh32; /* for reuse in unprepare and write */
332 /* store size of passed MIDIHDR?? structure to know if dwOffset is available or not */
333 mh16->reserved = *lpParam2;
334 *lpParam1 = (DWORD)mh32;
335 *lpParam2 = sizeof(MIDIHDR);
337 ret = WINMM_MAP_OKMEM;
338 } else {
339 ret = WINMM_MAP_NOMEM;
342 break;
343 case MODM_UNPREPARE:
344 case MODM_LONGDATA:
346 LPMIDIHDR mh16 = MapSL(*lpParam1);
347 LPMIDIHDR mh32 = (LPMIDIHDR)mh16->lpNext;
349 *lpParam1 = (DWORD)mh32;
350 *lpParam2 = sizeof(MIDIHDR);
351 /* dwBufferLength can be reduced between prepare & write */
352 if (wMsg == MODM_LONGDATA && mh32->dwBufferLength < mh16->dwBufferLength) {
353 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
354 mh32->dwBufferLength, mh16->dwBufferLength);
355 } else
356 mh32->dwBufferLength = mh16->dwBufferLength;
357 ret = WINMM_MAP_OKMEM;
359 break;
361 case MODM_CACHEPATCHES:
362 case MODM_CACHEDRUMPATCHES:
363 default:
364 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
365 break;
367 return ret;
370 /**************************************************************************
371 * MMDRV_MidiOut_UnMap16To32A [internal]
373 static WINMM_MapType MMDRV_MidiOut_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
375 WINMM_MapType ret = WINMM_MAP_MSGERROR;
377 switch (wMsg) {
378 case MODM_GETNUMDEVS:
379 case MODM_DATA:
380 case MODM_RESET:
381 case MODM_SETVOLUME:
382 ret = WINMM_MAP_OK;
383 break;
385 case MODM_OPEN:
386 case MODM_CLOSE:
387 case MODM_GETVOLUME:
388 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
389 break;
391 case MODM_GETDEVCAPS:
393 LPMIDIOUTCAPSA moc32 = (LPMIDIOUTCAPSA)(*lpParam1);
394 LPMIDIOUTCAPS16 moc16 = *(LPMIDIOUTCAPS16*)((LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
396 moc16->wMid = moc32->wMid;
397 moc16->wPid = moc32->wPid;
398 moc16->vDriverVersion = moc32->vDriverVersion;
399 strcpy(moc16->szPname, moc32->szPname);
400 moc16->wTechnology = moc32->wTechnology;
401 moc16->wVoices = moc32->wVoices;
402 moc16->wNotes = moc32->wNotes;
403 moc16->wChannelMask = moc32->wChannelMask;
404 moc16->dwSupport = moc32->dwSupport;
405 HeapFree(GetProcessHeap(), 0, (LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
406 ret = WINMM_MAP_OK;
408 break;
409 case MODM_PREPARE:
410 case MODM_UNPREPARE:
411 case MODM_LONGDATA:
413 LPMIDIHDR mh32 = (LPMIDIHDR)(*lpParam1);
414 LPMIDIHDR mh16 = MapSL(*(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR)));
416 assert(mh16->lpNext == mh32);
417 mh16->dwBufferLength = mh32->dwBufferLength;
418 mh16->dwBytesRecorded = mh32->dwBytesRecorded;
419 mh16->dwUser = mh32->dwUser;
420 mh16->dwFlags = mh32->dwFlags;
421 if (mh16->reserved >= sizeof(MIDIHDR))
422 mh16->dwOffset = mh32->dwOffset;
424 if (wMsg == MODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
425 HeapFree(GetProcessHeap(), 0, (LPSTR)mh32 - sizeof(LPMIDIHDR));
426 mh16->lpNext = 0;
428 ret = WINMM_MAP_OK;
430 break;
432 case MODM_CACHEPATCHES:
433 case MODM_CACHEDRUMPATCHES:
434 default:
435 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
436 break;
438 return ret;
441 /**************************************************************************
442 * MMDRV_MidiOut_Map32ATo16 [internal]
444 static WINMM_MapType MMDRV_MidiOut_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
446 WINMM_MapType ret = WINMM_MAP_MSGERROR;
448 switch (wMsg) {
449 case MODM_CLOSE:
450 case MODM_GETNUMDEVS:
451 case MODM_DATA:
452 case MODM_RESET:
453 case MODM_SETVOLUME:
454 ret = WINMM_MAP_OK;
455 break;
456 case MODM_GETDEVCAPS:
458 LPMIDIOUTCAPSA moc32 = (LPMIDIOUTCAPSA)*lpParam1;
459 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPSA)+sizeof(MIDIOUTCAPS16));
461 if (ptr) {
462 *(LPMIDIOUTCAPSA*)ptr = moc32;
463 ret = WINMM_MAP_OKMEM;
464 } else {
465 ret = WINMM_MAP_NOMEM;
467 *lpParam1 = (DWORD)MapLS(ptr) + sizeof(LPMIDIOUTCAPSA);
468 *lpParam2 = sizeof(MIDIOUTCAPS16);
470 break;
471 case MODM_PREPARE:
473 LPMIDIHDR mh32 = (LPMIDIHDR)*lpParam1;
474 LPMIDIHDR mh16;
475 LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
476 sizeof(LPMIDIHDR) + sizeof(MIDIHDR) + mh32->dwBufferLength);
478 if (ptr) {
479 *(LPMIDIHDR*)ptr = mh32;
480 mh16 = (LPMIDIHDR)((LPSTR)ptr + sizeof(LPMIDIHDR));
481 *lpParam1 = MapLS(mh16);
482 mh16->lpData = (LPSTR)*lpParam1 + sizeof(MIDIHDR);
483 /* data will be copied on WODM_WRITE */
484 mh16->dwBufferLength = mh32->dwBufferLength;
485 mh16->dwBytesRecorded = mh32->dwBytesRecorded;
486 mh16->dwUser = mh32->dwUser;
487 mh16->dwFlags = mh32->dwFlags;
488 /* FIXME: nothing on mh32->lpNext */
489 /* could link the mh32->lpNext at this level for memory house keeping */
490 mh16->dwOffset = (*lpParam2 >= sizeof(MIDIHDR)) ? mh32->dwOffset : 0;
492 mh32->lpNext = (LPMIDIHDR)mh16; /* for reuse in unprepare and write */
493 mh32->reserved = *lpParam2;
495 TRACE("mh16=%08lx mh16->lpData=%08lx mh32->buflen=%lu mh32->lpData=%08lx\n",
496 *lpParam1, (DWORD)mh16->lpData,
497 mh32->dwBufferLength, (DWORD)mh32->lpData);
498 *lpParam2 = sizeof(MIDIHDR);
500 ret = WINMM_MAP_OKMEM;
501 } else {
502 ret = WINMM_MAP_NOMEM;
505 break;
506 case MODM_UNPREPARE:
507 case MODM_LONGDATA:
509 LPMIDIHDR mh32 = (LPMIDIHDR)(*lpParam1);
510 LPMIDIHDR mh16 = (LPMIDIHDR)mh32->lpNext;
511 LPSTR ptr = (LPSTR)mh16 - sizeof(LPMIDIHDR);
513 assert(*(LPMIDIHDR*)ptr == mh32);
515 if (wMsg == MODM_LONGDATA)
516 memcpy((LPSTR)mh16 + sizeof(MIDIHDR), mh32->lpData, mh32->dwBufferLength);
518 *lpParam1 = MapLS(mh16);
519 *lpParam2 = sizeof(MIDIHDR);
520 TRACE("mh16=%08lx mh16->lpData=%08lx mh32->buflen=%lu mh32->lpData=%08lx\n",
521 *lpParam1, (DWORD)mh16->lpData, mh32->dwBufferLength, (DWORD)mh32->lpData);
523 /* dwBufferLength can be reduced between prepare & write */
524 if (wMsg == MODM_LONGDATA && mh16->dwBufferLength < mh32->dwBufferLength) {
525 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
526 mh16->dwBufferLength, mh32->dwBufferLength);
527 } else
528 mh16->dwBufferLength = mh32->dwBufferLength;
529 ret = WINMM_MAP_OKMEM;
531 break;
532 case MODM_OPEN:
534 LPMIDIOPENDESC mod32 = (LPMIDIOPENDESC)*lpParam1;
535 LPVOID ptr;
536 LPMIDIOPENDESC16 mod16;
538 /* allocated data are mapped as follows:
539 LPMIDIOPENDESC ptr to orig lParam1
540 DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
541 DWORD dwUser passed to driver
542 MIDIOPENDESC16 mod16: openDesc passed to driver
543 MIDIOPENSTRMID cIds
545 ptr = HeapAlloc( GetProcessHeap(), 0,
546 sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD) + sizeof(MIDIOPENDESC16) +
547 mod32->cIds ? (mod32->cIds - 1) * sizeof(MIDIOPENSTRMID) : 0);
549 if (ptr) {
550 SEGPTR segptr = MapLS(ptr);
551 *(LPMIDIOPENDESC*)ptr = mod32;
552 *(LPDWORD)((char*)ptr + sizeof(LPMIDIOPENDESC)) = *lpdwUser;
553 mod16 = (LPMIDIOPENDESC16)((LPSTR)ptr + sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD));
555 mod16->hMidi = HMIDI_16(mod32->hMidi);
556 mod16->dwCallback = mod32->dwCallback;
557 mod16->dwInstance = mod32->dwInstance;
558 mod16->dnDevNode = mod32->dnDevNode;
559 mod16->cIds = mod32->cIds;
560 memcpy(&mod16->rgIds, &mod32->rgIds, mod32->cIds * sizeof(MIDIOPENSTRMID));
562 *lpParam1 = (DWORD)segptr + sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD);
563 *lpdwUser = (DWORD)segptr + sizeof(LPMIDIOPENDESC) + sizeof(DWORD);
565 ret = WINMM_MAP_OKMEM;
566 } else {
567 ret = WINMM_MAP_NOMEM;
570 break;
571 case MODM_GETVOLUME:
572 case MODM_CACHEPATCHES:
573 case MODM_CACHEDRUMPATCHES:
574 default:
575 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
576 break;
578 return ret;
581 /**************************************************************************
582 * MMDRV_MidiOut_UnMap32ATo16 [internal]
584 static WINMM_MapType MMDRV_MidiOut_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
586 WINMM_MapType ret = WINMM_MAP_MSGERROR;
588 switch (wMsg) {
589 case MODM_CLOSE:
590 case MODM_GETNUMDEVS:
591 case MODM_DATA:
592 case MODM_RESET:
593 case MODM_SETVOLUME:
594 ret = WINMM_MAP_OK;
595 break;
596 case MODM_GETDEVCAPS:
598 LPMIDIOUTCAPS16 moc16 = MapSL(*lpParam1);
599 LPSTR ptr = (LPSTR)moc16 - sizeof(LPMIDIOUTCAPSA);
600 LPMIDIOUTCAPSA moc32 = *(LPMIDIOUTCAPSA*)ptr;
602 moc32->wMid = moc16->wMid;
603 moc32->wPid = moc16->wPid;
604 moc32->vDriverVersion = moc16->vDriverVersion;
605 strcpy(moc32->szPname, moc16->szPname);
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 );
613 ret = WINMM_MAP_OK;
615 break;
616 case MODM_PREPARE:
617 case MODM_UNPREPARE:
618 case MODM_LONGDATA:
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 );
632 mh32->lpNext = 0;
634 ret = WINMM_MAP_OK;
636 break;
637 case MODM_OPEN:
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 );
645 ret = WINMM_MAP_OK;
647 break;
648 case MODM_GETVOLUME:
649 case MODM_CACHEPATCHES:
650 case MODM_CACHEDRUMPATCHES:
651 default:
652 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
653 break;
655 return ret;
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;
665 switch (uMsg) {
666 case MOM_OPEN:
667 case MOM_CLOSE:
668 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
669 break;
670 case MOM_DONE:
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 }*/
693 break;
694 /* case MOM_POSITIONCB: */
695 default:
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_Map16To32A [internal]
709 static WINMM_MapType MMDRV_WaveIn_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
711 WINMM_MapType ret = WINMM_MAP_MSGERROR;
713 switch (wMsg) {
714 case WIDM_GETNUMDEVS:
715 case WIDM_RESET:
716 case WIDM_START:
717 case WIDM_STOP:
718 ret = WINMM_MAP_OK;
719 break;
720 case WIDM_OPEN:
721 case WIDM_CLOSE:
722 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
723 break;
724 case WIDM_GETDEVCAPS:
726 LPWAVEINCAPSA wic32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEINCAPS16) + sizeof(WAVEINCAPSA));
727 LPWAVEINCAPS16 wic16 = MapSL(*lpParam1);
729 if (wic32) {
730 *(LPWAVEINCAPS16*)wic32 = wic16;
731 wic32 = (LPWAVEINCAPSA)((LPSTR)wic32 + sizeof(LPWAVEINCAPS16));
732 *lpParam1 = (DWORD)wic32;
733 *lpParam2 = sizeof(WAVEINCAPSA);
735 ret = WINMM_MAP_OKMEM;
736 } else {
737 ret = WINMM_MAP_NOMEM;
740 break;
741 case WIDM_GETPOS:
743 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
744 LPMMTIME16 mmt16 = MapSL(*lpParam1);
746 if (mmt32) {
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;
755 } else {
756 ret = WINMM_MAP_NOMEM;
759 break;
760 case WIDM_PREPARE:
762 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
763 LPWAVEHDR wh16 = MapSL(*lpParam1);
765 if (wh32) {
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;
781 } else {
782 ret = WINMM_MAP_NOMEM;
785 break;
786 case WIDM_ADDBUFFER:
787 case WIDM_UNPREPARE:
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);
798 } else
799 wh32->dwBufferLength = wh16->dwBufferLength;
800 ret = WINMM_MAP_OKMEM;
802 break;
803 case WIDM_MAPPER_STATUS:
804 /* just a single DWORD */
805 *lpParam2 = (DWORD)MapSL(*lpParam2);
806 ret = WINMM_MAP_OK;
807 break;
808 default:
809 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
810 break;
812 return ret;
815 /**************************************************************************
816 * MMDRV_WaveIn_UnMap16To32A [internal]
818 static WINMM_MapType MMDRV_WaveIn_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
820 WINMM_MapType ret = WINMM_MAP_MSGERROR;
822 switch (wMsg) {
823 case WIDM_GETNUMDEVS:
824 case WIDM_RESET:
825 case WIDM_START:
826 case WIDM_STOP:
827 case WIDM_MAPPER_STATUS:
828 ret = WINMM_MAP_OK;
829 break;
830 case WIDM_OPEN:
831 case WIDM_CLOSE:
832 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
833 break;
834 case WIDM_GETDEVCAPS:
836 LPWAVEINCAPSA wic32 = (LPWAVEINCAPSA)(*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 strcpy(wic16->szPname, wic32->szPname);
843 wic16->dwFormats = wic32->dwFormats;
844 wic16->wChannels = wic32->wChannels;
845 HeapFree(GetProcessHeap(), 0, (LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
846 ret = WINMM_MAP_OK;
848 break;
849 case WIDM_GETPOS:
851 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
852 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
854 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
855 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
856 ret = WINMM_MAP_OK;
858 break;
859 case WIDM_ADDBUFFER:
860 case WIDM_PREPARE:
861 case WIDM_UNPREPARE:
863 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
864 LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
866 assert(wh16->lpNext == wh32);
867 wh16->dwBufferLength = wh32->dwBufferLength;
868 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
869 wh16->dwUser = wh32->dwUser;
870 wh16->dwFlags = wh32->dwFlags;
871 wh16->dwLoops = wh32->dwLoops;
873 if (wMsg == WIDM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
874 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
875 wh16->lpNext = 0;
877 ret = WINMM_MAP_OK;
879 break;
880 default:
881 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
882 break;
884 return ret;
887 /**************************************************************************
888 * MMDRV_WaveIn_Map32ATo16 [internal]
890 static WINMM_MapType MMDRV_WaveIn_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
892 WINMM_MapType ret = WINMM_MAP_MSGERROR;
894 switch (wMsg) {
895 case WIDM_CLOSE:
896 case WIDM_GETNUMDEVS:
897 case WIDM_RESET:
898 case WIDM_START:
899 case WIDM_STOP:
900 ret = WINMM_MAP_OK;
901 break;
903 case WIDM_OPEN:
905 LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
906 int sz = sizeof(WAVEFORMATEX);
907 LPVOID ptr;
908 LPWAVEOPENDESC16 wod16;
910 /* allocated data are mapped as follows:
911 LPWAVEOPENDESC ptr to orig lParam1
912 DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
913 DWORD dwUser passed to driver
914 WAVEOPENDESC16 wod16: openDesc passed to driver
915 WAVEFORMATEX openDesc->lpFormat passed to driver
916 xxx extra bytes to WAVEFORMATEX
918 if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
919 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize, wod32->lpFormat->wFormatTag);
920 sz += ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize;
923 ptr = HeapAlloc( GetProcessHeap(), 0,
924 sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
926 if (ptr) {
927 SEGPTR seg_ptr = MapLS( ptr );
928 *(LPWAVEOPENDESC*)ptr = wod32;
929 *(LPDWORD)((char*)ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
930 wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
932 wod16->hWave = HWAVE_16(wod32->hWave);
933 wod16->lpFormat = (LPWAVEFORMATEX)(seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
934 memcpy(wod16 + 1, wod32->lpFormat, sz);
936 wod16->dwCallback = wod32->dwCallback;
937 wod16->dwInstance = wod32->dwInstance;
938 wod16->uMappedDeviceID = wod32->uMappedDeviceID;
939 wod16->dnDevNode = wod32->dnDevNode;
941 *lpParam1 = seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
942 *lpdwUser = seg_ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
944 ret = WINMM_MAP_OKMEM;
945 } else {
946 ret = WINMM_MAP_NOMEM;
949 break;
950 case WIDM_PREPARE:
952 LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
953 LPWAVEHDR wh16;
954 LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
955 sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
957 if (ptr) {
958 SEGPTR seg_ptr = MapLS( ptr );
959 *(LPWAVEHDR*)ptr = wh32;
960 wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
961 wh16->lpData = (LPSTR)seg_ptr + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
962 /* data will be copied on WODM_WRITE */
963 wh16->dwBufferLength = wh32->dwBufferLength;
964 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
965 wh16->dwUser = wh32->dwUser;
966 wh16->dwFlags = wh32->dwFlags;
967 wh16->dwLoops = wh32->dwLoops;
968 /* FIXME: nothing on wh32->lpNext */
969 /* could link the wh32->lpNext at this level for memory house keeping */
970 wh32->lpNext = wh16; /* for reuse in unprepare and write */
971 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
972 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
973 wh32->dwBufferLength, (DWORD)wh32->lpData);
974 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
975 *lpParam2 = sizeof(WAVEHDR);
977 ret = WINMM_MAP_OKMEM;
978 } else {
979 ret = WINMM_MAP_NOMEM;
982 break;
983 case WIDM_ADDBUFFER:
984 case WIDM_UNPREPARE:
986 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
987 LPWAVEHDR wh16 = wh32->lpNext;
988 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
989 SEGPTR seg_ptr = MapLS( ptr );
991 assert(*(LPWAVEHDR*)ptr == wh32);
993 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
994 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
995 wh32->dwBufferLength, (DWORD)wh32->lpData);
997 if (wMsg == WIDM_ADDBUFFER)
998 memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
1000 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
1001 *lpParam2 = sizeof(WAVEHDR);
1002 /* dwBufferLength can be reduced between prepare & write */
1003 if (wMsg == WIDM_ADDBUFFER && wh16->dwBufferLength < wh32->dwBufferLength) {
1004 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
1005 wh16->dwBufferLength, wh32->dwBufferLength);
1006 } else
1007 wh16->dwBufferLength = wh32->dwBufferLength;
1008 ret = WINMM_MAP_OKMEM;
1010 break;
1011 case WIDM_GETDEVCAPS:
1013 LPWAVEINCAPSA wic32 = (LPWAVEINCAPSA)*lpParam1;
1014 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0 ,sizeof(LPWAVEINCAPSA) + sizeof(WAVEINCAPS16));
1016 if (ptr) {
1017 *(LPWAVEINCAPSA*)ptr = wic32;
1018 ret = WINMM_MAP_OKMEM;
1019 } else {
1020 ret = WINMM_MAP_NOMEM;
1022 *lpParam1 = MapLS(ptr) + sizeof(LPWAVEINCAPSA);
1023 *lpParam2 = sizeof(WAVEINCAPS16);
1025 break;
1026 case WIDM_GETPOS:
1028 LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
1029 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMMTIME) + sizeof(MMTIME16));
1030 LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
1032 if (ptr) {
1033 *(LPMMTIME*)ptr = mmt32;
1034 mmt16->wType = mmt32->wType;
1035 ret = WINMM_MAP_OKMEM;
1036 } else {
1037 ret = WINMM_MAP_NOMEM;
1039 *lpParam1 = MapLS(ptr) + sizeof(LPMMTIME);
1040 *lpParam2 = sizeof(MMTIME16);
1042 break;
1043 case DRVM_MAPPER_STATUS:
1045 LPDWORD p32 = (LPDWORD)*lpParam2;
1046 *lpParam2 = MapLS(p32);
1047 ret = WINMM_MAP_OKMEM;
1049 break;
1050 default:
1051 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1052 break;
1054 return ret;
1057 /**************************************************************************
1058 * MMDRV_WaveIn_UnMap32ATo16 [internal]
1060 static WINMM_MapType MMDRV_WaveIn_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
1062 WINMM_MapType ret = WINMM_MAP_MSGERROR;
1064 switch (wMsg) {
1065 case WIDM_CLOSE:
1066 case WIDM_GETNUMDEVS:
1067 case WIDM_RESET:
1068 case WIDM_START:
1069 case WIDM_STOP:
1070 ret = WINMM_MAP_OK;
1071 break;
1073 case WIDM_OPEN:
1075 LPWAVEOPENDESC16 wod16 = MapSL(*lpParam1);
1076 LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
1077 LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
1079 UnMapLS( *lpParam1 );
1080 wod32->uMappedDeviceID = wod16->uMappedDeviceID;
1081 **(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
1082 HeapFree( GetProcessHeap(), 0, ptr );
1083 ret = WINMM_MAP_OK;
1085 break;
1087 case WIDM_ADDBUFFER:
1088 case WIDM_PREPARE:
1089 case WIDM_UNPREPARE:
1091 LPWAVEHDR wh16 = MapSL(*lpParam1);
1092 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1093 LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
1095 assert(wh32->lpNext == wh16);
1096 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1097 wh32->dwUser = wh16->dwUser;
1098 wh32->dwFlags = wh16->dwFlags;
1099 wh32->dwLoops = wh16->dwLoops;
1100 UnMapLS( *lpParam1 );
1102 if (wMsg == WIDM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
1103 HeapFree( GetProcessHeap(), 0, ptr );
1104 wh32->lpNext = 0;
1106 ret = WINMM_MAP_OK;
1108 break;
1109 case WIDM_GETDEVCAPS:
1111 LPWAVEINCAPS16 wic16 = MapSL(*lpParam1);
1112 LPSTR ptr = (LPSTR)wic16 - sizeof(LPWAVEINCAPSA);
1113 LPWAVEINCAPSA wic32 = *(LPWAVEINCAPSA*)ptr;
1115 wic32->wMid = wic16->wMid;
1116 wic32->wPid = wic16->wPid;
1117 wic32->vDriverVersion = wic16->vDriverVersion;
1118 strcpy(wic32->szPname, wic16->szPname);
1119 wic32->dwFormats = wic16->dwFormats;
1120 wic32->wChannels = wic16->wChannels;
1121 UnMapLS( *lpParam1 );
1122 HeapFree( GetProcessHeap(), 0, ptr );
1123 ret = WINMM_MAP_OK;
1125 break;
1126 case WIDM_GETPOS:
1128 LPMMTIME16 mmt16 = MapSL(*lpParam1);
1129 LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
1130 LPMMTIME mmt32 = *(LPMMTIME*)ptr;
1132 MMSYSTEM_MMTIME16to32(mmt32, mmt16);
1133 UnMapLS( *lpParam1 );
1134 HeapFree( GetProcessHeap(), 0, ptr );
1135 ret = WINMM_MAP_OK;
1137 break;
1138 case DRVM_MAPPER_STATUS:
1140 UnMapLS( *lpParam2 );
1141 ret = WINMM_MAP_OK;
1143 break;
1144 default:
1145 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1146 break;
1148 return ret;
1151 /**************************************************************************
1152 * MMDRV_WaveIn_Callback [internal]
1154 static void CALLBACK MMDRV_WaveIn_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
1156 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
1158 switch (uMsg) {
1159 case WIM_OPEN:
1160 case WIM_CLOSE:
1161 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1162 break;
1163 case WIM_DATA:
1164 if (mld->bFrom32 && !MMDRV_Is32(mld->mmdIndex)) {
1165 /* initial map is: 32 => 16 */
1166 LPWAVEHDR wh16 = MapSL(dwParam1);
1167 LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
1169 dwParam1 = (DWORD)wh32;
1170 wh32->dwFlags = wh16->dwFlags;
1171 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1172 } else if (!mld->bFrom32 && MMDRV_Is32(mld->mmdIndex)) {
1173 /* initial map is: 16 => 32 */
1174 LPWAVEHDR wh32 = (LPWAVEHDR)(dwParam1);
1175 SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
1176 LPWAVEHDR wh16 = MapSL(segwh16);
1178 dwParam1 = (DWORD)segwh16;
1179 wh16->dwFlags = wh32->dwFlags;
1180 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1182 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1183 break;
1184 default:
1185 ERR("Unknown msg %u\n", uMsg);
1188 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
1191 /* =================================
1192 * W A V E O U T M A P P E R S
1193 * ================================= */
1195 /**************************************************************************
1196 * MMDRV_WaveOut_Map16To32A [internal]
1198 static WINMM_MapType MMDRV_WaveOut_Map16To32A (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1200 WINMM_MapType ret = WINMM_MAP_MSGERROR;
1202 switch (wMsg) {
1203 /* nothing to do */
1204 case WODM_BREAKLOOP:
1205 case WODM_CLOSE:
1206 case WODM_GETNUMDEVS:
1207 case WODM_PAUSE:
1208 case WODM_RESET:
1209 case WODM_RESTART:
1210 case WODM_SETPITCH:
1211 case WODM_SETPLAYBACKRATE:
1212 case WODM_SETVOLUME:
1213 ret = WINMM_MAP_OK;
1214 break;
1216 case WODM_GETPITCH:
1217 case WODM_GETPLAYBACKRATE:
1218 case WODM_GETVOLUME:
1219 case WODM_OPEN:
1220 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
1221 break;
1223 case WODM_GETDEVCAPS:
1225 LPWAVEOUTCAPSA woc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEOUTCAPS16) + sizeof(WAVEOUTCAPSA));
1226 LPWAVEOUTCAPS16 woc16 = MapSL(*lpParam1);
1228 if (woc32) {
1229 *(LPWAVEOUTCAPS16*)woc32 = woc16;
1230 woc32 = (LPWAVEOUTCAPSA)((LPSTR)woc32 + sizeof(LPWAVEOUTCAPS16));
1231 *lpParam1 = (DWORD)woc32;
1232 *lpParam2 = sizeof(WAVEOUTCAPSA);
1234 ret = WINMM_MAP_OKMEM;
1235 } else {
1236 ret = WINMM_MAP_NOMEM;
1239 break;
1240 case WODM_GETPOS:
1242 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
1243 LPMMTIME16 mmt16 = MapSL(*lpParam1);
1245 if (mmt32) {
1246 *(LPMMTIME16*)mmt32 = mmt16;
1247 mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
1249 mmt32->wType = mmt16->wType;
1250 *lpParam1 = (DWORD)mmt32;
1251 *lpParam2 = sizeof(MMTIME);
1253 ret = WINMM_MAP_OKMEM;
1254 } else {
1255 ret = WINMM_MAP_NOMEM;
1258 break;
1259 case WODM_PREPARE:
1261 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
1262 LPWAVEHDR wh16 = MapSL(*lpParam1);
1264 if (wh32) {
1265 *(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
1266 wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
1267 wh32->lpData = MapSL((SEGPTR)wh16->lpData);
1268 wh32->dwBufferLength = wh16->dwBufferLength;
1269 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1270 wh32->dwUser = wh16->dwUser;
1271 wh32->dwFlags = wh16->dwFlags;
1272 wh32->dwLoops = wh16->dwLoops;
1273 /* FIXME: nothing on wh32->lpNext */
1274 /* could link the wh32->lpNext at this level for memory house keeping */
1275 wh16->lpNext = wh32; /* for reuse in unprepare and write */
1276 *lpParam1 = (DWORD)wh32;
1277 *lpParam2 = sizeof(WAVEHDR);
1279 ret = WINMM_MAP_OKMEM;
1280 } else {
1281 ret = WINMM_MAP_NOMEM;
1284 break;
1285 case WODM_UNPREPARE:
1286 case WODM_WRITE:
1288 LPWAVEHDR wh16 = MapSL(*lpParam1);
1289 LPWAVEHDR wh32 = (LPWAVEHDR)wh16->lpNext;
1291 *lpParam1 = (DWORD)wh32;
1292 *lpParam2 = sizeof(WAVEHDR);
1293 /* dwBufferLength can be reduced between prepare & write */
1294 if (wMsg == WODM_WRITE && wh32->dwBufferLength < wh16->dwBufferLength) {
1295 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
1296 wh32->dwBufferLength, wh16->dwBufferLength);
1297 } else
1298 wh32->dwBufferLength = wh16->dwBufferLength;
1299 ret = WINMM_MAP_OKMEM;
1301 break;
1302 case WODM_MAPPER_STATUS:
1303 *lpParam2 = (DWORD)MapSL(*lpParam2);
1304 ret = WINMM_MAP_OK;
1305 break;
1306 default:
1307 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1308 break;
1310 return ret;
1313 /**************************************************************************
1314 * MMDRV_WaveOut_UnMap16To32A [internal]
1316 static WINMM_MapType MMDRV_WaveOut_UnMap16To32A(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
1318 WINMM_MapType ret = WINMM_MAP_MSGERROR;
1320 switch (wMsg) {
1321 /* nothing to do */
1322 case WODM_BREAKLOOP:
1323 case WODM_CLOSE:
1324 case WODM_GETNUMDEVS:
1325 case WODM_PAUSE:
1326 case WODM_RESET:
1327 case WODM_RESTART:
1328 case WODM_SETPITCH:
1329 case WODM_SETPLAYBACKRATE:
1330 case WODM_SETVOLUME:
1331 case WODM_MAPPER_STATUS:
1332 ret = WINMM_MAP_OK;
1333 break;
1335 case WODM_GETPITCH:
1336 case WODM_GETPLAYBACKRATE:
1337 case WODM_GETVOLUME:
1338 case WODM_OPEN:
1339 FIXME("Shouldn't be used: those 16 bit functions use the 32 bit interface\n");
1340 break;
1342 case WODM_GETDEVCAPS:
1344 LPWAVEOUTCAPSA woc32 = (LPWAVEOUTCAPSA)(*lpParam1);
1345 LPWAVEOUTCAPS16 woc16 = *(LPWAVEOUTCAPS16*)((LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
1347 woc16->wMid = woc32->wMid;
1348 woc16->wPid = woc32->wPid;
1349 woc16->vDriverVersion = woc32->vDriverVersion;
1350 strcpy(woc16->szPname, woc32->szPname);
1351 woc16->dwFormats = woc32->dwFormats;
1352 woc16->wChannels = woc32->wChannels;
1353 woc16->dwSupport = woc32->dwSupport;
1354 HeapFree(GetProcessHeap(), 0, (LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
1355 ret = WINMM_MAP_OK;
1357 break;
1358 case WODM_GETPOS:
1360 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
1361 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
1363 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
1364 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
1365 ret = WINMM_MAP_OK;
1367 break;
1368 case WODM_PREPARE:
1369 case WODM_UNPREPARE:
1370 case WODM_WRITE:
1372 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
1373 LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
1375 assert(wh16->lpNext == wh32);
1376 wh16->dwBufferLength = wh32->dwBufferLength;
1377 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1378 wh16->dwUser = wh32->dwUser;
1379 wh16->dwFlags = wh32->dwFlags;
1380 wh16->dwLoops = wh32->dwLoops;
1382 if (wMsg == WODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
1383 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
1384 wh16->lpNext = 0;
1386 ret = WINMM_MAP_OK;
1388 break;
1389 default:
1390 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
1391 break;
1393 return ret;
1396 /**************************************************************************
1397 * MMDRV_WaveOut_Map32ATo16 [internal]
1399 static WINMM_MapType MMDRV_WaveOut_Map32ATo16 (UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2)
1401 WINMM_MapType ret;
1403 switch (wMsg) {
1404 /* nothing to do */
1405 case WODM_BREAKLOOP:
1406 case WODM_CLOSE:
1407 case WODM_GETNUMDEVS:
1408 case WODM_PAUSE:
1409 case WODM_RESET:
1410 case WODM_RESTART:
1411 case WODM_SETPITCH:
1412 case WODM_SETPLAYBACKRATE:
1413 case WODM_SETVOLUME:
1414 ret = WINMM_MAP_OK;
1415 break;
1417 case WODM_GETDEVCAPS:
1419 LPWAVEOUTCAPSA woc32 = (LPWAVEOUTCAPSA)*lpParam1;
1420 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0,
1421 sizeof(LPWAVEOUTCAPSA) + sizeof(WAVEOUTCAPS16));
1423 if (ptr) {
1424 *(LPWAVEOUTCAPSA*)ptr = woc32;
1425 ret = WINMM_MAP_OKMEM;
1426 } else {
1427 ret = WINMM_MAP_NOMEM;
1429 *lpParam1 = MapLS(ptr) + sizeof(LPWAVEOUTCAPSA);
1430 *lpParam2 = sizeof(WAVEOUTCAPS16);
1432 break;
1433 case WODM_GETPITCH:
1434 FIXME("NIY: no conversion yet\n");
1435 ret = WINMM_MAP_MSGERROR;
1436 break;
1437 case WODM_GETPLAYBACKRATE:
1438 FIXME("NIY: no conversion yet\n");
1439 ret = WINMM_MAP_MSGERROR;
1440 break;
1441 case WODM_GETPOS:
1443 LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
1444 LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMMTIME) + sizeof(MMTIME16));
1445 LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
1447 if (ptr) {
1448 *(LPMMTIME*)ptr = mmt32;
1449 mmt16->wType = mmt32->wType;
1450 ret = WINMM_MAP_OKMEM;
1451 } else {
1452 ret = WINMM_MAP_NOMEM;
1454 *lpParam1 = MapLS(ptr) + sizeof(LPMMTIME);
1455 *lpParam2 = sizeof(MMTIME16);
1457 break;
1458 case WODM_GETVOLUME:
1459 FIXME("NIY: no conversion yet\n");
1460 ret = WINMM_MAP_MSGERROR;
1461 break;
1462 case WODM_OPEN:
1464 LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
1465 int sz = sizeof(WAVEFORMATEX);
1466 LPVOID ptr;
1467 LPWAVEOPENDESC16 wod16;
1469 /* allocated data are mapped as follows:
1470 LPWAVEOPENDESC ptr to orig lParam1
1471 DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
1472 DWORD dwUser passed to driver
1473 WAVEOPENDESC16 wod16: openDesc passed to driver
1474 WAVEFORMATEX openDesc->lpFormat passed to driver
1475 xxx extra bytes to WAVEFORMATEX
1477 if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
1478 TRACE("Allocating %u extra bytes (%d)\n", ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize, wod32->lpFormat->wFormatTag);
1479 sz += ((LPWAVEFORMATEX)wod32->lpFormat)->cbSize;
1482 ptr = HeapAlloc( GetProcessHeap(), 0,
1483 sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
1485 if (ptr) {
1486 SEGPTR seg_ptr = MapLS( ptr );
1487 *(LPWAVEOPENDESC*)ptr = wod32;
1488 *(LPDWORD)((char*)ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
1489 wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
1491 wod16->hWave = HWAVE_16(wod32->hWave);
1492 wod16->lpFormat = (LPWAVEFORMATEX)(seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
1493 memcpy(wod16 + 1, wod32->lpFormat, sz);
1495 wod16->dwCallback = wod32->dwCallback;
1496 wod16->dwInstance = wod32->dwInstance;
1497 wod16->uMappedDeviceID = wod32->uMappedDeviceID;
1498 wod16->dnDevNode = wod32->dnDevNode;
1500 *lpParam1 = seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
1501 *lpdwUser = seg_ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
1503 ret = WINMM_MAP_OKMEM;
1504 } else {
1505 ret = WINMM_MAP_NOMEM;
1508 break;
1509 case WODM_PREPARE:
1511 LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
1512 LPWAVEHDR wh16;
1513 LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
1514 sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
1516 if (ptr) {
1517 SEGPTR seg_ptr = MapLS( ptr );
1518 *(LPWAVEHDR*)ptr = wh32;
1519 wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
1520 wh16->lpData = (LPSTR)seg_ptr + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
1521 /* data will be copied on WODM_WRITE */
1522 wh16->dwBufferLength = wh32->dwBufferLength;
1523 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
1524 wh16->dwUser = wh32->dwUser;
1525 wh16->dwFlags = wh32->dwFlags;
1526 wh16->dwLoops = wh32->dwLoops;
1527 /* FIXME: nothing on wh32->lpNext */
1528 /* could link the wh32->lpNext at this level for memory house keeping */
1529 wh32->lpNext = wh16; /* for reuse in unprepare and write */
1530 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1531 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
1532 wh32->dwBufferLength, (DWORD)wh32->lpData);
1533 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
1534 *lpParam2 = sizeof(WAVEHDR);
1536 ret = WINMM_MAP_OKMEM;
1537 } else {
1538 ret = WINMM_MAP_NOMEM;
1541 break;
1542 case WODM_UNPREPARE:
1543 case WODM_WRITE:
1545 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
1546 LPWAVEHDR wh16 = wh32->lpNext;
1547 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1548 SEGPTR seg_ptr = MapLS( ptr );
1550 assert(*(LPWAVEHDR*)ptr == wh32);
1552 TRACE("wh16=%08lx wh16->lpData=%08lx wh32->buflen=%lu wh32->lpData=%08lx\n",
1553 seg_ptr + sizeof(LPWAVEHDR), (DWORD)wh16->lpData,
1554 wh32->dwBufferLength, (DWORD)wh32->lpData);
1556 if (wMsg == WODM_WRITE)
1557 memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
1559 *lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
1560 *lpParam2 = sizeof(WAVEHDR);
1561 /* dwBufferLength can be reduced between prepare & write */
1562 if (wMsg == WODM_WRITE && wh16->dwBufferLength < wh32->dwBufferLength) {
1563 ERR("Size of buffer has been increased from %ld to %ld, keeping initial value\n",
1564 wh16->dwBufferLength, wh32->dwBufferLength);
1565 } else
1566 wh16->dwBufferLength = wh32->dwBufferLength;
1567 ret = WINMM_MAP_OKMEM;
1569 break;
1570 case DRVM_MAPPER_STATUS:
1572 LPDWORD p32 = (LPDWORD)*lpParam2;
1573 *lpParam2 = MapLS(p32);
1574 ret = WINMM_MAP_OKMEM;
1576 break;
1577 default:
1578 FIXME("NIY: no conversion yet\n");
1579 ret = WINMM_MAP_MSGERROR;
1580 break;
1582 return ret;
1585 /**************************************************************************
1586 * MMDRV_WaveOut_UnMap32ATo16 [internal]
1588 static WINMM_MapType MMDRV_WaveOut_UnMap32ATo16(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT fn_ret)
1590 WINMM_MapType ret;
1592 switch (wMsg) {
1593 /* nothing to do */
1594 case WODM_BREAKLOOP:
1595 case WODM_CLOSE:
1596 case WODM_GETNUMDEVS:
1597 case WODM_PAUSE:
1598 case WODM_RESET:
1599 case WODM_RESTART:
1600 case WODM_SETPITCH:
1601 case WODM_SETPLAYBACKRATE:
1602 case WODM_SETVOLUME:
1603 ret = WINMM_MAP_OK;
1604 break;
1606 case WODM_GETDEVCAPS:
1608 LPWAVEOUTCAPS16 woc16 = MapSL(*lpParam1);
1609 LPSTR ptr = (LPSTR)woc16 - sizeof(LPWAVEOUTCAPSA);
1610 LPWAVEOUTCAPSA woc32 = *(LPWAVEOUTCAPSA*)ptr;
1612 woc32->wMid = woc16->wMid;
1613 woc32->wPid = woc16->wPid;
1614 woc32->vDriverVersion = woc16->vDriverVersion;
1615 strcpy(woc32->szPname, woc16->szPname);
1616 woc32->dwFormats = woc16->dwFormats;
1617 woc32->wChannels = woc16->wChannels;
1618 woc32->dwSupport = woc16->dwSupport;
1619 UnMapLS( *lpParam1 );
1620 HeapFree( GetProcessHeap(), 0, ptr );
1621 ret = WINMM_MAP_OK;
1623 break;
1624 case WODM_GETPITCH:
1625 FIXME("NIY: no conversion yet\n");
1626 ret = WINMM_MAP_MSGERROR;
1627 break;
1628 case WODM_GETPLAYBACKRATE:
1629 FIXME("NIY: no conversion yet\n");
1630 ret = WINMM_MAP_MSGERROR;
1631 break;
1632 case WODM_GETPOS:
1634 LPMMTIME16 mmt16 = MapSL(*lpParam1);
1635 LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
1636 LPMMTIME mmt32 = *(LPMMTIME*)ptr;
1638 MMSYSTEM_MMTIME16to32(mmt32, mmt16);
1639 UnMapLS( *lpParam1 );
1640 HeapFree( GetProcessHeap(), 0, ptr );
1641 ret = WINMM_MAP_OK;
1643 break;
1644 case WODM_OPEN:
1646 LPWAVEOPENDESC16 wod16 = MapSL(*lpParam1);
1647 LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
1648 LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
1650 wod32->uMappedDeviceID = wod16->uMappedDeviceID;
1651 **(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
1652 UnMapLS( *lpParam1 );
1653 HeapFree( GetProcessHeap(), 0, ptr );
1654 ret = WINMM_MAP_OK;
1656 break;
1657 case WODM_PREPARE:
1658 case WODM_UNPREPARE:
1659 case WODM_WRITE:
1661 LPWAVEHDR wh16 = MapSL(*lpParam1);
1662 LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
1663 LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
1665 assert(wh32->lpNext == wh16);
1666 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
1667 wh32->dwUser = wh16->dwUser;
1668 wh32->dwFlags = wh16->dwFlags;
1669 wh32->dwLoops = wh16->dwLoops;
1671 UnMapLS( *lpParam1 );
1672 if (wMsg == WODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
1673 HeapFree( GetProcessHeap(), 0, ptr );
1674 wh32->lpNext = 0;
1676 ret = WINMM_MAP_OK;
1678 break;
1679 case WODM_GETVOLUME:
1680 FIXME("NIY: no conversion yet\n");
1681 ret = WINMM_MAP_MSGERROR;
1682 break;
1683 case DRVM_MAPPER_STATUS:
1685 UnMapLS( *lpParam2 );
1686 ret = WINMM_MAP_OK;
1688 break;
1689 default:
1690 FIXME("NIY: no conversion yet\n");
1691 ret = WINMM_MAP_MSGERROR;
1692 break;
1694 return ret;
1697 /**************************************************************************
1698 * MMDRV_WaveOut_Callback [internal]
1700 static void CALLBACK MMDRV_WaveOut_Callback(HDRVR hDev, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
1702 LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
1704 switch (uMsg) {
1705 case WOM_OPEN:
1706 case WOM_CLOSE:
1707 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
1708 break;
1709 case WOM_DONE:
1710 if (mld->bFrom32 && !MMDRV_Is32(mld->mmdIndex)) {
1711 /* initial map is: 32 => 16 */
1712 LPWAVEHDR wh16 = MapSL(dwParam1);
1713 LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
1715 dwParam1 = (DWORD)wh32;
1716 wh32->dwFlags = wh16->dwFlags;
1717 } else if (!mld->bFrom32 && MMDRV_Is32(mld->mmdIndex)) {
1718 /* initial map is: 16 => 32 */
1719 LPWAVEHDR wh32 = (LPWAVEHDR)(dwParam1);
1720 SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
1721 LPWAVEHDR wh16 = MapSL(segwh16);
1723 dwParam1 = (DWORD)segwh16;
1724 wh16->dwFlags = wh32->dwFlags;
1726 /* else { 16 => 16 or 32 => 32, nothing to do, same struct is kept }*/
1727 break;
1728 default:
1729 ERR("Unknown msg %u\n", uMsg);
1732 MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
1735 /* =================================
1736 * M A P P E R S H A N D L I N G
1737 * ================================= */
1739 static LRESULT MMDRV_CallMMDrvFunc16(DWORD fp16, WORD dev, WORD msg, LONG instance,
1740 LONG lp1, LONG lp2)
1742 WORD args[8];
1743 DWORD ret;
1745 args[7] = dev;
1746 args[6] = msg;
1747 args[5] = HIWORD(instance);
1748 args[4] = LOWORD(instance);
1749 args[3] = HIWORD(lp1);
1750 args[2] = LOWORD(lp1);
1751 args[1] = HIWORD(lp2);
1752 args[0] = LOWORD(lp2);
1753 WOWCallback16Ex( fp16, WCB16_PASCAL, sizeof(args), args, &ret );
1754 return LOWORD(ret);
1757 /**************************************************************************
1758 * MMDRV_GetDescription16 [internal]
1760 static BOOL MMDRV_GetDescription16(const char* fname, char* buf, int buflen)
1762 OFSTRUCT ofs;
1763 HFILE hFile;
1764 WORD w;
1765 DWORD dw;
1766 BOOL ret = FALSE;
1768 if ((hFile = OpenFile(fname, &ofs, OF_READ | OF_SHARE_DENY_WRITE)) == HFILE_ERROR) {
1769 ERR("Can't open file %s (builtin driver ?)\n", fname);
1770 return FALSE;
1773 #define E(_x) do {TRACE _x;goto theEnd;} while(0)
1775 if (_lread(hFile, &w, 2) != 2) E(("Can't read sig\n"));
1776 if (w != ('Z' * 256 + 'M')) E(("Bad sig %04x\n", w));
1777 if (_llseek(hFile, 0x3C, SEEK_SET) < 0) E(("Can't seek to ext header offset\n"));
1778 if (_lread(hFile, &dw, 4) != 4) E(("Can't read ext header offset\n"));
1779 if (_llseek(hFile, dw + 0x2C, SEEK_SET) < 0) E(("Can't seek to ext header.nr table %lu\n", dw+0x2C));
1780 if (_lread(hFile, &dw, 4) != 4) E(("Can't read nr table offset\n"));
1781 if (_llseek(hFile, dw, SEEK_SET) < 0) E(("Can't seek to nr table %lu\n", dw));
1782 if (_lread(hFile, buf, 1) != 1) E(("Can't read descr length\n"));
1783 buflen = min((int)(unsigned)(BYTE)buf[0], buflen - 1);
1784 if (_lread(hFile, buf, buflen) != buflen) E(("Can't read descr (%d)\n", buflen));
1785 buf[buflen] = '\0';
1786 ret = TRUE;
1787 TRACE("Got '%s' [%d]\n", buf, buflen);
1788 theEnd:
1789 _lclose(hFile);
1790 return ret;
1793 /******************************************************************
1794 * MMDRV_LoadMMDrvFunc16
1797 unsigned MMDRV_LoadMMDrvFunc16(LPCSTR drvName, LPWINE_DRIVER d,
1798 LPWINE_MM_DRIVER lpDrv)
1800 WINEMM_msgFunc16 func;
1801 unsigned count = 0;
1802 char buffer[128];
1804 * DESCRIPTION 'wave,aux,mixer:Creative Labs Sound Blaster 16 Driver'
1805 * The beginning of the module description indicates the driver supports
1806 * waveform, auxiliary, and mixer devices. Use one of the following
1807 * device-type names, followed by a colon (:) to indicate the type of
1808 * device your driver supports. If the driver supports more than one
1809 * type of device, separate each device-type name with a comma (,).
1811 * wave for waveform audio devices
1812 * wavemapper for wave mappers
1813 * midi for MIDI audio devices
1814 * midimapper for midi mappers
1815 * aux for auxiliary audio devices
1816 * mixer for mixer devices
1819 if (d->d.d16.hDriver16) {
1820 HMODULE16 hMod16 = GetDriverModuleHandle16(d->d.d16.hDriver16);
1822 #define AA(_h,_w,_x,_y,_z) \
1823 func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
1824 if (func != NULL) \
1825 { lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
1826 TRACE("Got %d bit func '%s'\n", _y, #_x); }
1828 #define A(_x,_y) AA(hMod16,_x,_y,16,GetProcAddress16)
1829 A(MMDRV_AUX, auxMessage);
1830 A(MMDRV_MIXER, mxdMessage);
1831 A(MMDRV_MIDIIN, midMessage);
1832 A(MMDRV_MIDIOUT,modMessage);
1833 A(MMDRV_WAVEIN, widMessage);
1834 A(MMDRV_WAVEOUT,wodMessage);
1835 #undef A
1836 #undef AA
1838 if (TRACE_ON(winmm)) {
1839 if (MMDRV_GetDescription16(drvName, buffer, sizeof(buffer)))
1840 TRACE("%s => %s\n", drvName, buffer);
1841 else
1842 TRACE("%s => No description\n", drvName);
1845 return count;
1848 /* =================================
1849 * M C I
1850 * ================================= */
1852 /**************************************************************************
1853 * MCI_MapMsg16To32A [internal]
1855 static WINMM_MapType MCI_MapMsg16To32A(WORD uDevType, WORD wMsg, DWORD* lParam)
1857 if (*lParam == 0)
1858 return WINMM_MAP_OK;
1859 /* FIXME: to add also (with seg/linear modifications to do):
1860 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
1861 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
1863 switch (wMsg) {
1864 /* case MCI_CAPTURE */
1865 case MCI_CLOSE:
1866 case MCI_CLOSE_DRIVER:
1867 case MCI_CONFIGURE:
1868 case MCI_COPY:
1869 case MCI_CUE:
1870 case MCI_CUT:
1871 case MCI_DELETE:
1872 case MCI_FREEZE:
1873 case MCI_GETDEVCAPS:
1874 /* case MCI_INDEX: */
1875 /* case MCI_MARK: */
1876 /* case MCI_MONITOR: */
1877 case MCI_PASTE:
1878 case MCI_PAUSE:
1879 case MCI_PLAY:
1880 case MCI_PUT:
1881 case MCI_REALIZE:
1882 case MCI_RECORD:
1883 case MCI_RESUME:
1884 case MCI_SEEK:
1885 case MCI_SET:
1886 /* case MCI_SETTIMECODE:*/
1887 /* case MCI_SIGNAL:*/
1888 case MCI_SPIN:
1889 case MCI_STATUS: /* FIXME: is wrong for digital video */
1890 case MCI_STEP:
1891 case MCI_STOP:
1892 /* case MCI_UNDO: */
1893 case MCI_UNFREEZE:
1894 case MCI_UPDATE:
1895 case MCI_WHERE:
1896 *lParam = (DWORD)MapSL(*lParam);
1897 return WINMM_MAP_OK;
1898 case MCI_WINDOW:
1899 /* in fact, I would also need the dwFlags... to see
1900 * which members of lParam are effectively used
1902 *lParam = (DWORD)MapSL(*lParam);
1903 FIXME("Current mapping may be wrong\n");
1904 break;
1905 case MCI_BREAK:
1907 LPMCI_BREAK_PARMS mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_BREAK_PARMS));
1908 LPMCI_BREAK_PARMS16 mbp16 = MapSL(*lParam);
1910 if (mbp32) {
1911 mbp32->dwCallback = mbp16->dwCallback;
1912 mbp32->nVirtKey = mbp16->nVirtKey;
1913 mbp32->hwndBreak = HWND_32(mbp16->hwndBreak);
1914 } else {
1915 return WINMM_MAP_NOMEM;
1917 *lParam = (DWORD)mbp32;
1919 return WINMM_MAP_OKMEM;
1920 case MCI_ESCAPE:
1922 LPMCI_VD_ESCAPE_PARMSA mvep32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_VD_ESCAPE_PARMSA));
1923 LPMCI_VD_ESCAPE_PARMS16 mvep16 = MapSL(*lParam);
1925 if (mvep32a) {
1926 mvep32a->dwCallback = mvep16->dwCallback;
1927 mvep32a->lpstrCommand = MapSL(mvep16->lpstrCommand);
1928 } else {
1929 return WINMM_MAP_NOMEM;
1931 *lParam = (DWORD)mvep32a;
1933 return WINMM_MAP_OKMEM;
1934 case MCI_INFO:
1936 LPMCI_INFO_PARMSA mip32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_INFO_PARMSA));
1937 LPMCI_INFO_PARMS16 mip16 = MapSL(*lParam);
1939 /* FIXME this is wrong if device is of type
1940 * MCI_DEVTYPE_DIGITAL_VIDEO, some members are not mapped
1942 if (mip32a) {
1943 mip32a->dwCallback = mip16->dwCallback;
1944 mip32a->lpstrReturn = MapSL(mip16->lpstrReturn);
1945 mip32a->dwRetSize = mip16->dwRetSize;
1946 } else {
1947 return WINMM_MAP_NOMEM;
1949 *lParam = (DWORD)mip32a;
1951 return WINMM_MAP_OKMEM;
1952 case MCI_OPEN:
1953 case MCI_OPEN_DRIVER:
1955 LPMCI_OPEN_PARMSA mop32a = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_OPEN_PARMSA) + 2 * sizeof(DWORD));
1956 LPMCI_OPEN_PARMS16 mop16 = MapSL(*lParam);
1958 if (mop32a) {
1959 *(LPMCI_OPEN_PARMS16*)(mop32a) = mop16;
1960 mop32a = (LPMCI_OPEN_PARMSA)((char*)mop32a + sizeof(LPMCI_OPEN_PARMS16));
1961 mop32a->dwCallback = mop16->dwCallback;
1962 mop32a->wDeviceID = mop16->wDeviceID;
1963 mop32a->lpstrDeviceType = MapSL(mop16->lpstrDeviceType);
1964 mop32a->lpstrElementName = MapSL(mop16->lpstrElementName);
1965 mop32a->lpstrAlias = MapSL(mop16->lpstrAlias);
1966 /* copy extended information if any...
1967 * FIXME: this may seg fault if initial structure does not contain them and
1968 * the reads after msip16 fail under LDT limits...
1969 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
1970 * should not take care of extended parameters, and should be used by MCI_Open
1971 * to fetch uDevType. When, this is known, the mapping for sending the
1972 * MCI_OPEN_DRIVER shall be done depending on uDevType.
1974 memcpy(mop32a + 1, mop16 + 1, 2 * sizeof(DWORD));
1975 } else {
1976 return WINMM_MAP_NOMEM;
1978 *lParam = (DWORD)mop32a;
1980 return WINMM_MAP_OKMEM;
1981 case MCI_SYSINFO:
1983 LPMCI_SYSINFO_PARMSA msip32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_SYSINFO_PARMSA));
1984 LPMCI_SYSINFO_PARMS16 msip16 = MapSL(*lParam);
1986 if (msip32a) {
1987 msip32a->dwCallback = msip16->dwCallback;
1988 msip32a->lpstrReturn = MapSL(msip16->lpstrReturn);
1989 msip32a->dwRetSize = msip16->dwRetSize;
1990 msip32a->dwNumber = msip16->dwNumber;
1991 msip32a->wDeviceType = msip16->wDeviceType;
1992 } else {
1993 return WINMM_MAP_NOMEM;
1995 *lParam = (DWORD)msip32a;
1997 return WINMM_MAP_OKMEM;
1998 case MCI_SOUND:
2000 LPMCI_SOUND_PARMS mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_SOUND_PARMS));
2001 LPMCI_SOUND_PARMS16 mbp16 = MapSL(*lParam);
2003 if (mbp32) {
2004 mbp32->dwCallback = mbp16->dwCallback;
2005 mbp32->lpstrSoundName = MapSL(mbp16->lpstrSoundName);
2006 } else {
2007 return WINMM_MAP_NOMEM;
2009 *lParam = (DWORD)mbp32;
2011 return WINMM_MAP_OKMEM;
2012 case DRV_LOAD:
2013 case DRV_ENABLE:
2014 case DRV_OPEN:
2015 case DRV_CLOSE:
2016 case DRV_DISABLE:
2017 case DRV_FREE:
2018 case DRV_CONFIGURE:
2019 case DRV_QUERYCONFIGURE:
2020 case DRV_INSTALL:
2021 case DRV_REMOVE:
2022 case DRV_EXITSESSION:
2023 case DRV_EXITAPPLICATION:
2024 case DRV_POWER:
2025 FIXME("This is a hack\n");
2026 return WINMM_MAP_OK;
2028 default:
2029 WARN("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
2031 return WINMM_MAP_MSGERROR;
2034 /**************************************************************************
2035 * MCI_UnMapMsg16To32A [internal]
2037 static WINMM_MapType MCI_UnMapMsg16To32A(WORD uDevType, WORD wMsg, DWORD lParam)
2039 switch (wMsg) {
2040 /* case MCI_CAPTURE */
2041 case MCI_CLOSE:
2042 case MCI_CLOSE_DRIVER:
2043 case MCI_CONFIGURE:
2044 case MCI_COPY:
2045 case MCI_CUE:
2046 case MCI_CUT:
2047 case MCI_DELETE:
2048 case MCI_FREEZE:
2049 case MCI_GETDEVCAPS:
2050 /* case MCI_INDEX: */
2051 /* case MCI_MARK: */
2052 /* case MCI_MONITOR: */
2053 case MCI_PASTE:
2054 case MCI_PAUSE:
2055 case MCI_PLAY:
2056 case MCI_PUT:
2057 case MCI_REALIZE:
2058 case MCI_RECORD:
2059 case MCI_RESUME:
2060 case MCI_SEEK:
2061 case MCI_SET:
2062 /* case MCI_SETTIMECODE:*/
2063 /* case MCI_SIGNAL:*/
2064 case MCI_SPIN:
2065 case MCI_STATUS:
2066 case MCI_STEP:
2067 case MCI_STOP:
2068 /* case MCI_UNDO: */
2069 case MCI_UNFREEZE:
2070 case MCI_UPDATE:
2071 case MCI_WHERE:
2072 return WINMM_MAP_OK;
2074 case MCI_WINDOW:
2075 /* FIXME ?? see Map function */
2076 return WINMM_MAP_OK;
2078 case MCI_BREAK:
2079 case MCI_ESCAPE:
2080 case MCI_INFO:
2081 case MCI_SYSINFO:
2082 case MCI_SOUND:
2083 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
2084 return WINMM_MAP_OK;
2085 case MCI_OPEN:
2086 case MCI_OPEN_DRIVER:
2087 if (lParam) {
2088 LPMCI_OPEN_PARMSA mop32a = (LPMCI_OPEN_PARMSA)lParam;
2089 LPMCI_OPEN_PARMS16 mop16 = *(LPMCI_OPEN_PARMS16*)((char*)mop32a - sizeof(LPMCI_OPEN_PARMS16));
2091 mop16->wDeviceID = mop32a->wDeviceID;
2092 if (!HeapFree(GetProcessHeap(), 0, (LPVOID)(lParam - sizeof(LPMCI_OPEN_PARMS16))))
2093 FIXME("bad free line=%d\n", __LINE__);
2095 return WINMM_MAP_OK;
2096 case DRV_LOAD:
2097 case DRV_ENABLE:
2098 case DRV_OPEN:
2099 case DRV_CLOSE:
2100 case DRV_DISABLE:
2101 case DRV_FREE:
2102 case DRV_CONFIGURE:
2103 case DRV_QUERYCONFIGURE:
2104 case DRV_INSTALL:
2105 case DRV_REMOVE:
2106 case DRV_EXITSESSION:
2107 case DRV_EXITAPPLICATION:
2108 case DRV_POWER:
2109 FIXME("This is a hack\n");
2110 return WINMM_MAP_OK;
2111 default:
2112 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
2114 return WINMM_MAP_MSGERROR;
2118 * 0000 stop
2119 * 0001 squeeze signed 4 bytes to 2 bytes *( LPINT16)D = ( INT16)*( LPINT16)S; D += 2; S += 4
2120 * 0010 squeeze unsigned 4 bytes to 2 bytes *(LPUINT16)D = (UINT16)*(LPUINT16)S; D += 2; S += 4
2121 * 0100
2122 * 0101
2123 * 0110 zero 4 bytes *(DWORD)D = 0 D += 4; S += 4
2124 * 0111 copy string *(LPSTR*)D = seg dup(*(LPSTR*)S) D += 4; S += 4
2125 * 1xxx copy xxx + 1 bytes memcpy(D, S, xxx + 1); D += xxx+1; S += xxx+1
2128 /**************************************************************************
2129 * MCI_MsgMapper32To16_Create [internal]
2131 * Helper for MCI_MapMsg32ATo16.
2132 * Maps the 32 bit pointer (*ptr), of size bytes, to an allocated 16 bit
2133 * segmented pointer.
2134 * map contains a list of action to be performed for the mapping (see list
2135 * above)
2136 * if keep is TRUE, keeps track of in 32 bit ptr in allocated 16 bit area.
2138 static WINMM_MapType MCI_MsgMapper32To16_Create(void** ptr, int size16, DWORD map, BOOLEAN keep)
2140 void* lp = HeapAlloc( GetProcessHeap(), 0, (keep ? sizeof(void**) : 0) + size16 );
2141 LPBYTE p16, p32;
2143 if (!lp) {
2144 return WINMM_MAP_NOMEM;
2146 p32 = (LPBYTE)(*ptr);
2147 if (keep) {
2148 *(void**)lp = *ptr;
2149 p16 = (LPBYTE)lp + sizeof(void**);
2150 *ptr = (char*)MapLS(lp) + sizeof(void**);
2151 } else {
2152 p16 = lp;
2153 *ptr = (void*)MapLS(lp);
2156 if (map == 0) {
2157 memcpy(p16, p32, size16);
2158 } else {
2159 unsigned nibble;
2160 unsigned sz;
2162 while (map & 0xF) {
2163 nibble = map & 0xF;
2164 if (nibble & 0x8) {
2165 sz = (nibble & 7) + 1;
2166 memcpy(p16, p32, sz);
2167 p16 += sz;
2168 p32 += sz;
2169 size16 -= sz; /* DEBUG only */
2170 } else {
2171 switch (nibble) {
2172 case 0x1:
2173 *(LPINT16)p16 = *(LPINT)p32;
2174 p16 += sizeof(INT16);
2175 p32 += sizeof(INT);
2176 size16 -= sizeof(INT16);
2177 break;
2178 case 0x2:
2179 *(LPUINT16)p16 = *(LPUINT)p32;
2180 p16 += sizeof(UINT16);
2181 p32 += sizeof(UINT);
2182 size16 -= sizeof(UINT16);
2183 break;
2184 case 0x6:
2185 *(LPDWORD)p16 = 0;
2186 p16 += sizeof(DWORD);
2187 p32 += sizeof(DWORD);
2188 size16 -= sizeof(DWORD);
2189 break;
2190 case 0x7:
2191 *(SEGPTR *)p16 = MapLS( *(LPSTR *)p32 );
2192 p16 += sizeof(SEGPTR);
2193 p32 += sizeof(LPSTR);
2194 size16 -= sizeof(SEGPTR);
2195 break;
2196 default:
2197 FIXME("Unknown nibble for mapping (%x)\n", nibble);
2200 map >>= 4;
2202 if (size16 != 0) /* DEBUG only */
2203 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
2205 return WINMM_MAP_OKMEM;
2208 /**************************************************************************
2209 * MCI_MsgMapper32To16_Destroy [internal]
2211 * Helper for MCI_UnMapMsg32ATo16.
2213 static WINMM_MapType MCI_MsgMapper32To16_Destroy(void* ptr, int size16, DWORD map, BOOLEAN kept)
2215 if (ptr) {
2216 void* msg16 = MapSL((SEGPTR)ptr);
2217 void* alloc;
2218 LPBYTE p32, p16;
2219 unsigned nibble;
2221 UnMapLS( (SEGPTR)ptr );
2222 if (kept) {
2223 alloc = (char*)msg16 - sizeof(void**);
2224 p32 = *(void**)alloc;
2225 p16 = msg16;
2227 if (map == 0) {
2228 memcpy(p32, p16, size16);
2229 } else {
2230 while (map & 0xF) {
2231 nibble = map & 0xF;
2232 if (nibble & 0x8) {
2233 memcpy(p32, p16, (nibble & 7) + 1);
2234 p16 += (nibble & 7) + 1;
2235 p32 += (nibble & 7) + 1;
2236 size16 -= (nibble & 7) + 1;
2237 } else {
2238 switch (nibble) {
2239 case 0x1:
2240 *(LPINT)p32 = *(LPINT16)p16;
2241 p16 += sizeof(INT16);
2242 p32 += sizeof(INT);
2243 size16 -= sizeof(INT16);
2244 break;
2245 case 0x2:
2246 *(LPUINT)p32 = *(LPUINT16)p16;
2247 p16 += sizeof(UINT16);
2248 p32 += sizeof(UINT);
2249 size16 -= sizeof(UINT16);
2250 break;
2251 case 0x6:
2252 p16 += sizeof(UINT);
2253 p32 += sizeof(UINT);
2254 size16 -= sizeof(UINT);
2255 break;
2256 case 0x7:
2257 UnMapLS( *(SEGPTR *)p16 );
2258 p16 += sizeof(SEGPTR);
2259 p32 += sizeof(char*);
2260 size16 -= sizeof(SEGPTR);
2261 break;
2262 default:
2263 FIXME("Unknown nibble for mapping (%x)\n", nibble);
2266 map >>= 4;
2268 if (size16 != 0) /* DEBUG only */
2269 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
2271 } else {
2272 alloc = msg16;
2275 HeapFree( GetProcessHeap(), 0, alloc );
2277 return WINMM_MAP_OK;
2280 /**************************************************************************
2281 * MCI_MapMsg32ATo16 [internal]
2283 * Map a 32-A bit MCI message to a 16 bit MCI message.
2285 static WINMM_MapType MCI_MapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD* lParam)
2287 int size;
2288 BOOLEAN keep = FALSE;
2289 DWORD map = 0;
2291 if (*lParam == 0)
2292 return WINMM_MAP_OK;
2294 /* FIXME: to add also (with seg/linear modifications to do):
2295 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
2296 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
2298 switch (wMsg) {
2299 case MCI_BREAK:
2300 size = sizeof(MCI_BREAK_PARMS);
2301 break;
2302 /* case MCI_CAPTURE */
2303 case MCI_CLOSE:
2304 case MCI_CLOSE_DRIVER:
2305 case MCI_CONFIGURE:
2306 size = sizeof(MCI_GENERIC_PARMS);
2307 break;
2308 /* case MCI_COPY: */
2309 case MCI_CUE:
2310 switch (uDevType) {
2311 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_CUE_PARMS); break;
2312 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_CUE_PARMS); break;*/ FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2313 default: size = sizeof(MCI_GENERIC_PARMS); break;
2315 break;
2316 /* case MCI_CUT:*/
2317 case MCI_DELETE:
2318 switch (uDevType) {
2319 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_DELETE_PARMS16); map = 0x0F1111FB; break;
2320 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_DELETE_PARMS); break;
2321 default: size = sizeof(MCI_GENERIC_PARMS); break;
2323 break;
2324 /* case MCI_ESCAPE: */
2325 case MCI_FREEZE:
2326 switch (uDevType) {
2327 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_FREEZE_PARMS); map = 0x0001111B; break;
2328 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
2329 default: size = sizeof(MCI_GENERIC_PARMS); break;
2331 break;
2332 case MCI_GETDEVCAPS:
2333 keep = TRUE;
2334 size = sizeof(MCI_GETDEVCAPS_PARMS);
2335 break;
2336 /* case MCI_INDEX: */
2337 case MCI_INFO:
2339 LPMCI_INFO_PARMSA mip32a = (LPMCI_INFO_PARMSA)(*lParam);
2340 LPMCI_INFO_PARMS16 mip16;
2342 switch (uDevType) {
2343 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_INFO_PARMS16); break;
2344 default: size = sizeof(MCI_INFO_PARMS16); break;
2346 mip16 = HeapAlloc( GetProcessHeap(), 0, size);
2347 if (mip16)
2349 mip16->dwCallback = mip32a->dwCallback;
2350 mip16->lpstrReturn = MapLS( mip32a->lpstrReturn );
2351 mip16->dwRetSize = mip32a->dwRetSize;
2352 if (uDevType == MCI_DEVTYPE_DIGITAL_VIDEO) {
2353 ((LPMCI_DGV_INFO_PARMS16)mip16)->dwItem = ((LPMCI_DGV_INFO_PARMSA)mip32a)->dwItem;
2355 } else {
2356 return WINMM_MAP_NOMEM;
2358 *lParam = MapLS(mip16);
2360 return WINMM_MAP_OKMEM;
2361 /* case MCI_MARK: */
2362 /* case MCI_MONITOR: */
2363 case MCI_OPEN:
2364 case MCI_OPEN_DRIVER:
2366 LPMCI_OPEN_PARMSA mop32a = (LPMCI_OPEN_PARMSA)(*lParam);
2367 char* ptr = HeapAlloc( GetProcessHeap(), 0,
2368 sizeof(LPMCI_OPEN_PARMSA) + sizeof(MCI_OPEN_PARMS16) + 2 * sizeof(DWORD));
2369 LPMCI_OPEN_PARMS16 mop16;
2372 if (ptr) {
2373 *(LPMCI_OPEN_PARMSA*)(ptr) = mop32a;
2374 mop16 = (LPMCI_OPEN_PARMS16)(ptr + sizeof(LPMCI_OPEN_PARMSA));
2375 mop16->dwCallback = mop32a->dwCallback;
2376 mop16->wDeviceID = mop32a->wDeviceID;
2377 if (dwFlags & MCI_OPEN_TYPE) {
2378 if (dwFlags & MCI_OPEN_TYPE_ID) {
2379 /* dword "transparent" value */
2380 mop16->lpstrDeviceType = (SEGPTR)mop32a->lpstrDeviceType;
2381 } else {
2382 /* string */
2383 mop16->lpstrDeviceType = MapLS( mop32a->lpstrDeviceType );
2385 } else {
2386 /* nuthin' */
2387 mop16->lpstrDeviceType = 0;
2389 if (dwFlags & MCI_OPEN_ELEMENT) {
2390 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
2391 mop16->lpstrElementName = (SEGPTR)mop32a->lpstrElementName;
2392 } else {
2393 mop16->lpstrElementName = MapLS( mop32a->lpstrElementName );
2395 } else {
2396 mop16->lpstrElementName = 0;
2398 if (dwFlags & MCI_OPEN_ALIAS) {
2399 mop16->lpstrAlias = MapLS( mop32a->lpstrAlias );
2400 } else {
2401 mop16->lpstrAlias = 0;
2403 /* copy extended information if any...
2404 * FIXME: this may seg fault if initial structure does not contain them and
2405 * the reads after msip16 fail under LDT limits...
2406 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
2407 * should not take care of extended parameters, and should be used by MCI_Open
2408 * to fetch uDevType. When, this is known, the mapping for sending the
2409 * MCI_OPEN_DRIVER shall be done depending on uDevType.
2411 memcpy(mop16 + 1, mop32a + 1, 2 * sizeof(DWORD));
2412 } else {
2413 return WINMM_MAP_NOMEM;
2415 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_PARMSA);
2417 return WINMM_MAP_OKMEM;
2418 /* case MCI_PASTE:*/
2419 case MCI_PAUSE:
2420 size = sizeof(MCI_GENERIC_PARMS);
2421 break;
2422 case MCI_PLAY:
2423 size = sizeof(MCI_PLAY_PARMS);
2424 break;
2425 case MCI_PUT:
2426 switch (uDevType) {
2427 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
2428 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
2429 default: size = sizeof(MCI_GENERIC_PARMS); break;
2431 break;
2432 case MCI_REALIZE:
2433 size = sizeof(MCI_GENERIC_PARMS);
2434 break;
2435 case MCI_RECORD:
2436 switch (uDevType) {
2437 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECORD_PARMS16); map = 0x0F1111FB; break;
2438 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_RECORD_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2439 default: size = sizeof(MCI_RECORD_PARMS); break;
2441 break;
2442 case MCI_RESUME:
2443 size = sizeof(MCI_GENERIC_PARMS);
2444 break;
2445 case MCI_SEEK:
2446 switch (uDevType) {
2447 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SEEK_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2448 default: size = sizeof(MCI_SEEK_PARMS); break;
2450 break;
2451 case MCI_SET:
2452 switch (uDevType) {
2453 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SET_PARMS); break;
2454 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SET_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2455 case MCI_DEVTYPE_SEQUENCER: size = sizeof(MCI_SEQ_SET_PARMS); break;
2456 /* FIXME: normally the 16 and 32 bit structures are byte by byte aligned,
2457 * so not doing anything should work...
2459 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_SET_PARMS); break;
2460 default: size = sizeof(MCI_SET_PARMS); break;
2462 break;
2463 case MCI_SETAUDIO:
2464 switch (uDevType) {
2465 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SETAUDIO_PARMS16);map = 0x0000077FF; break;
2466 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2467 default: size = sizeof(MCI_GENERIC_PARMS); break;
2469 break;
2470 /* case MCI_SETTIMECODE:*/
2471 /* case MCI_SIGNAL:*/
2472 /* case MCI_SOUND:*/
2473 case MCI_SPIN:
2474 size = sizeof(MCI_SET_PARMS);
2475 break;
2476 case MCI_STATUS:
2477 keep = TRUE;
2478 switch (uDevType) {
2479 /* FIXME:
2480 * don't know if buffer for value is the one passed through lpstrDevice
2481 * or is provided by MCI driver.
2482 * Assuming solution 2: provided by MCI driver, so zeroing on entry
2484 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STATUS_PARMS16); map = 0x0B6FF; break;
2485 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2486 default: size = sizeof(MCI_STATUS_PARMS); break;
2488 break;
2489 case MCI_STEP:
2490 switch (uDevType) {
2491 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STEP_PARMS); break;
2492 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STEP_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2493 case MCI_DEVTYPE_VIDEODISC: size = sizeof(MCI_VD_STEP_PARMS); break;
2494 default: size = sizeof(MCI_GENERIC_PARMS); break;
2496 break;
2497 case MCI_STOP:
2498 size = sizeof(MCI_SET_PARMS);
2499 break;
2500 case MCI_SYSINFO:
2502 LPMCI_SYSINFO_PARMSA msip32a = (LPMCI_SYSINFO_PARMSA)(*lParam);
2503 LPMCI_SYSINFO_PARMS16 msip16;
2504 char* ptr = HeapAlloc( GetProcessHeap(), 0,
2505 sizeof(LPMCI_SYSINFO_PARMSA) + sizeof(MCI_SYSINFO_PARMS16) );
2507 if (ptr) {
2508 *(LPMCI_SYSINFO_PARMSA*)(ptr) = msip32a;
2509 msip16 = (LPMCI_SYSINFO_PARMS16)(ptr + sizeof(LPMCI_SYSINFO_PARMSA));
2511 msip16->dwCallback = msip32a->dwCallback;
2512 msip16->lpstrReturn = MapLS( msip32a->lpstrReturn );
2513 msip16->dwRetSize = msip32a->dwRetSize;
2514 msip16->dwNumber = msip32a->dwNumber;
2515 msip16->wDeviceType = msip32a->wDeviceType;
2516 } else {
2517 return WINMM_MAP_NOMEM;
2519 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_SYSINFO_PARMSA);
2521 return WINMM_MAP_OKMEM;
2522 /* case MCI_UNDO: */
2523 case MCI_UNFREEZE:
2524 switch (uDevType) {
2525 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
2526 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; break;
2527 default: size = sizeof(MCI_GENERIC_PARMS); break;
2529 break;
2530 case MCI_UPDATE:
2531 switch (uDevType) {
2532 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_UPDATE_PARMS16); map = 0x000B1111B; break;
2533 default: size = sizeof(MCI_GENERIC_PARMS); break;
2535 break;
2536 case MCI_WHERE:
2537 switch (uDevType) {
2538 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
2539 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
2540 default: size = sizeof(MCI_GENERIC_PARMS); break;
2542 break;
2543 case MCI_WINDOW:
2544 switch (uDevType) {
2545 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7FB; break;
2546 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7FB; break;
2547 default: size = sizeof(MCI_GENERIC_PARMS); break;
2549 break;
2550 case DRV_OPEN:
2552 LPMCI_OPEN_DRIVER_PARMSA modp32a = (LPMCI_OPEN_DRIVER_PARMSA)(*lParam);
2553 LPMCI_OPEN_DRIVER_PARMS16 modp16;
2554 char *ptr = HeapAlloc( GetProcessHeap(), 0,
2555 sizeof(LPMCI_OPEN_DRIVER_PARMSA) + sizeof(MCI_OPEN_DRIVER_PARMS16));
2557 if (ptr) {
2558 *(LPMCI_OPEN_DRIVER_PARMSA*)(ptr) = modp32a;
2559 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSA));
2560 modp16->wDeviceID = modp32a->wDeviceID;
2561 modp16->lpstrParams = MapLS( modp32a->lpstrParams );
2562 /* other fields are gonna be filled by the driver, don't copy them */
2563 } else {
2564 return WINMM_MAP_NOMEM;
2566 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_DRIVER_PARMSA);
2568 return WINMM_MAP_OKMEM;
2569 case DRV_LOAD:
2570 case DRV_ENABLE:
2571 case DRV_CLOSE:
2572 case DRV_DISABLE:
2573 case DRV_FREE:
2574 case DRV_CONFIGURE:
2575 case DRV_QUERYCONFIGURE:
2576 case DRV_INSTALL:
2577 case DRV_REMOVE:
2578 case DRV_EXITSESSION:
2579 case DRV_EXITAPPLICATION:
2580 case DRV_POWER:
2581 return WINMM_MAP_OK;
2583 default:
2584 WARN("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
2585 return WINMM_MAP_MSGERROR;
2587 return MCI_MsgMapper32To16_Create((void**)lParam, size, map, keep);
2590 /**************************************************************************
2591 * MCI_UnMapMsg32ATo16 [internal]
2593 static WINMM_MapType MCI_UnMapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD lParam)
2595 int size = 0;
2596 BOOLEAN kept = FALSE; /* there is no need to compute size when kept is FALSE */
2597 DWORD map = 0;
2599 switch (wMsg) {
2600 case MCI_BREAK:
2601 break;
2602 /* case MCI_CAPTURE */
2603 case MCI_CLOSE:
2604 case MCI_CLOSE_DRIVER:
2605 case MCI_CONFIGURE:
2606 break;
2607 /* case MCI_COPY: */
2608 case MCI_CUE:
2609 break;
2610 /* case MCI_CUT: */
2611 case MCI_DELETE:
2612 break;
2613 /* case MCI_ESCAPE: */
2614 case MCI_FREEZE:
2615 break;
2616 case MCI_GETDEVCAPS:
2617 kept = TRUE;
2618 size = sizeof(MCI_GETDEVCAPS_PARMS);
2619 break;
2620 /* case MCI_INDEX: */
2621 case MCI_INFO:
2623 LPMCI_INFO_PARMS16 mip16 = (LPMCI_INFO_PARMS16)MapSL(lParam);
2624 UnMapLS( lParam );
2625 UnMapLS( mip16->lpstrReturn );
2626 HeapFree( GetProcessHeap(), 0, mip16 );
2628 return WINMM_MAP_OK;
2629 /* case MCI_MARK: */
2630 /* case MCI_MONITOR: */
2631 case MCI_OPEN:
2632 case MCI_OPEN_DRIVER:
2633 if (lParam) {
2634 LPMCI_OPEN_PARMS16 mop16 = (LPMCI_OPEN_PARMS16)MapSL(lParam);
2635 LPMCI_OPEN_PARMSA mop32a = *(LPMCI_OPEN_PARMSA*)((char*)mop16 - sizeof(LPMCI_OPEN_PARMSA));
2636 UnMapLS( lParam );
2637 mop32a->wDeviceID = mop16->wDeviceID;
2638 if ((dwFlags & MCI_OPEN_TYPE) && !(dwFlags & MCI_OPEN_TYPE_ID))
2639 UnMapLS( mop16->lpstrDeviceType );
2640 if ((dwFlags & MCI_OPEN_ELEMENT) && !(dwFlags & MCI_OPEN_ELEMENT_ID))
2641 UnMapLS( mop16->lpstrElementName );
2642 if (dwFlags & MCI_OPEN_ALIAS)
2643 UnMapLS( mop16->lpstrAlias );
2644 HeapFree( GetProcessHeap(), 0, (char*)mop16 - sizeof(LPMCI_OPEN_PARMSA) );
2646 return WINMM_MAP_OK;
2647 /* case MCI_PASTE:*/
2648 case MCI_PAUSE:
2649 break;
2650 case MCI_PLAY:
2651 break;
2652 case MCI_PUT:
2653 break;
2654 case MCI_REALIZE:
2655 break;
2656 case MCI_RECORD:
2657 break;
2658 case MCI_RESUME:
2659 break;
2660 case MCI_SEEK:
2661 break;
2662 case MCI_SET:
2663 break;
2664 case MCI_SETAUDIO:
2665 switch (uDevType) {
2666 case MCI_DEVTYPE_DIGITAL_VIDEO: map = 0x0000077FF; break;
2667 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2669 break;
2670 /* case MCI_SETTIMECODE:*/
2671 /* case MCI_SIGNAL:*/
2672 /* case MCI_SOUND:*/
2673 case MCI_SPIN:
2674 break;
2675 case MCI_STATUS:
2676 kept = TRUE;
2677 switch (uDevType) {
2678 case MCI_DEVTYPE_DIGITAL_VIDEO:
2679 if (lParam) {
2680 LPMCI_DGV_STATUS_PARMS16 mdsp16 = (LPMCI_DGV_STATUS_PARMS16)MapSL(lParam);
2681 LPMCI_DGV_STATUS_PARMSA mdsp32a = *(LPMCI_DGV_STATUS_PARMSA*)((char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA));
2683 UnMapLS( lParam );
2684 if (mdsp16) {
2685 mdsp32a->dwReturn = mdsp16->dwReturn;
2686 if (dwFlags & MCI_DGV_STATUS_DISKSPACE) {
2687 TRACE("MCI_STATUS (DGV) lpstrDrive=%08lx\n", mdsp16->lpstrDrive);
2688 TRACE("MCI_STATUS (DGV) lpstrDrive=%s\n", (LPSTR)MapSL(mdsp16->lpstrDrive));
2689 UnMapLS( mdsp16->lpstrDrive );
2691 HeapFree( GetProcessHeap(), 0, (char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA) );
2692 } else {
2693 return WINMM_MAP_NOMEM;
2696 return WINMM_MAP_OKMEM;
2697 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return WINMM_MAP_NOMEM;
2698 default: size = sizeof(MCI_STATUS_PARMS); break;
2700 break;
2701 case MCI_STEP:
2702 break;
2703 case MCI_STOP:
2704 break;
2705 case MCI_SYSINFO:
2706 if (lParam) {
2707 LPMCI_SYSINFO_PARMS16 msip16 = (LPMCI_SYSINFO_PARMS16)MapSL(lParam);
2708 LPMCI_SYSINFO_PARMSA msip32a = *(LPMCI_SYSINFO_PARMSA*)((char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA));
2710 UnMapLS( lParam );
2711 if (msip16) {
2712 msip16->dwCallback = msip32a->dwCallback;
2713 UnMapLS( msip16->lpstrReturn );
2714 HeapFree( GetProcessHeap(), 0, (char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA) );
2715 } else {
2716 return WINMM_MAP_NOMEM;
2719 return WINMM_MAP_OKMEM;
2720 /* case MCI_UNDO: */
2721 case MCI_UNFREEZE:
2722 break;
2723 case MCI_UPDATE:
2724 break;
2725 case MCI_WHERE:
2726 switch (uDevType) {
2727 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
2728 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
2729 default: break;
2731 break;
2732 case MCI_WINDOW:
2733 switch (uDevType) {
2734 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7666; break;
2735 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7666; break;
2736 default: break;
2738 /* FIXME: see map function */
2739 break;
2741 case DRV_OPEN:
2742 if (lParam) {
2743 LPMCI_OPEN_DRIVER_PARMS16 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)MapSL(lParam);
2744 LPMCI_OPEN_DRIVER_PARMSA modp32a = *(LPMCI_OPEN_DRIVER_PARMSA*)((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA));
2746 UnMapLS( lParam );
2747 modp32a->wCustomCommandTable = modp16->wCustomCommandTable;
2748 modp32a->wType = modp16->wType;
2749 UnMapLS( modp16->lpstrParams );
2750 HeapFree( GetProcessHeap(), 0, (char *)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA) );
2752 return WINMM_MAP_OK;
2753 case DRV_LOAD:
2754 case DRV_ENABLE:
2755 case DRV_CLOSE:
2756 case DRV_DISABLE:
2757 case DRV_FREE:
2758 case DRV_CONFIGURE:
2759 case DRV_QUERYCONFIGURE:
2760 case DRV_INSTALL:
2761 case DRV_REMOVE:
2762 case DRV_EXITSESSION:
2763 case DRV_EXITAPPLICATION:
2764 case DRV_POWER:
2765 FIXME("This is a hack\n");
2766 return WINMM_MAP_OK;
2767 default:
2768 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
2769 return WINMM_MAP_MSGERROR;
2771 return MCI_MsgMapper32To16_Destroy((void*)lParam, size, map, kept);
2774 void MMDRV_Init16(void)
2776 #define A(_x,_y) MMDRV_InstallMap(_x, \
2777 MMDRV_##_y##_Map16To32A, MMDRV_##_y##_UnMap16To32A, \
2778 MMDRV_##_y##_Map32ATo16, MMDRV_##_y##_UnMap32ATo16, \
2779 MMDRV_##_y##_Callback)
2780 A(MMDRV_AUX, Aux);
2781 A(MMDRV_MIXER, Mixer);
2782 A(MMDRV_MIDIIN, MidiIn);
2783 A(MMDRV_MIDIOUT, MidiOut);
2784 A(MMDRV_WAVEIN, WaveIn);
2785 A(MMDRV_WAVEOUT, WaveOut);
2786 #undef A
2788 pFnCallMMDrvFunc16 = MMDRV_CallMMDrvFunc16;
2789 pFnLoadMMDrvFunc16 = MMDRV_LoadMMDrvFunc16;
2791 pFnMciMapMsg16To32A = MCI_MapMsg16To32A;
2792 pFnMciUnMapMsg16To32A = MCI_UnMapMsg16To32A;
2793 pFnMciMapMsg32ATo16 = MCI_MapMsg32ATo16;
2794 pFnMciUnMapMsg32ATo16 = MCI_UnMapMsg32ATo16;