wbemprox: Implement more properties of Win32_DiskDrive.
[wine/wine-gecko.git] / dlls / mmsystem.dll16 / message16.c
blob012d3dca869614bebef4a680c12d3ba6bcb77a07
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <string.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <assert.h>
25 #include "wine/winbase16.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wownt32.h"
30 #include "winemm16.h"
31 #include "digitalv.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
36 /* =================================
37 * A U X M A P P E R S
38 * ================================= */
40 /* =================================
41 * M I X E R M A P P E R S
42 * ================================= */
44 /**************************************************************************
45 * MMSYSTDRV_Mixer_Map16To32W [internal]
47 static MMSYSTEM_MapType MMSYSTDRV_Mixer_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
49 return MMSYSTEM_MAP_MSGERROR;
52 /**************************************************************************
53 * MMSYSTDRV_Mixer_UnMap16To32W [internal]
55 static MMSYSTEM_MapType MMSYSTDRV_Mixer_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
57 #if 0
58 MIXERCAPSA micA;
59 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
61 if (ret == MMSYSERR_NOERROR) {
62 mixcaps->wMid = micA.wMid;
63 mixcaps->wPid = micA.wPid;
64 mixcaps->vDriverVersion = micA.vDriverVersion;
65 strcpy(mixcaps->szPname, micA.szPname);
66 mixcaps->fdwSupport = micA.fdwSupport;
67 mixcaps->cDestinations = micA.cDestinations;
69 return ret;
70 #endif
71 return MMSYSTEM_MAP_MSGERROR;
74 /**************************************************************************
75 * MMSYSTDRV_Mixer_MapCB
77 static void MMSYSTDRV_Mixer_MapCB(DWORD uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
79 FIXME("NIY\n");
82 /* =================================
83 * M I D I I N M A P P E R S
84 * ================================= */
86 /**************************************************************************
87 * MMSYSTDRV_MidiIn_Map16To32W [internal]
89 static MMSYSTEM_MapType MMSYSTDRV_MidiIn_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
91 return MMSYSTEM_MAP_MSGERROR;
94 /**************************************************************************
95 * MMSYSTDRV_MidiIn_UnMap16To32W [internal]
97 static MMSYSTEM_MapType MMSYSTDRV_MidiIn_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
99 return MMSYSTEM_MAP_MSGERROR;
102 /**************************************************************************
103 * MMSYSTDRV_MidiIn_MapCB [internal]
105 static void MMSYSTDRV_MidiIn_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
107 switch (uMsg) {
108 case MIM_OPEN:
109 case MIM_CLOSE:
110 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
112 case MIM_DATA:
113 case MIM_MOREDATA:
114 case MIM_ERROR:
115 /* dwParam1 & dwParam2 are data, nothing to do */
116 break;
117 case MIM_LONGDATA:
118 case MIM_LONGERROR:
120 LPMIDIHDR mh32 = (LPMIDIHDR)(*dwParam1);
121 SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR));
122 LPMIDIHDR16 mh16 = MapSL(segmh16);
124 *dwParam1 = (DWORD)segmh16;
125 mh16->dwFlags = mh32->dwFlags;
126 mh16->dwBytesRecorded = mh32->dwBytesRecorded;
128 break;
129 default:
130 ERR("Unknown msg %u\n", uMsg);
134 /* =================================
135 * M I D I O U T M A P P E R S
136 * ================================= */
138 /**************************************************************************
139 * MMSYSTDRV_MidiOut_Map16To32W [internal]
141 static MMSYSTEM_MapType MMSYSTDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
143 MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
145 switch (wMsg) {
146 case MODM_GETNUMDEVS:
147 case MODM_DATA:
148 case MODM_RESET:
149 case MODM_SETVOLUME:
150 ret = MMSYSTEM_MAP_OK;
151 break;
153 case MODM_OPEN:
154 case MODM_CLOSE:
155 case MODM_GETVOLUME:
156 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
157 break;
159 case MODM_GETDEVCAPS:
161 LPMIDIOUTCAPSW moc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPS16) + sizeof(MIDIOUTCAPSW));
162 LPMIDIOUTCAPS16 moc16 = MapSL(*lpParam1);
164 if (moc32) {
165 *(LPMIDIOUTCAPS16*)moc32 = moc16;
166 moc32 = (LPMIDIOUTCAPSW)((LPSTR)moc32 + sizeof(LPMIDIOUTCAPS16));
167 *lpParam1 = (DWORD)moc32;
168 *lpParam2 = sizeof(MIDIOUTCAPSW);
170 ret = MMSYSTEM_MAP_OKMEM;
171 } else {
172 ret = MMSYSTEM_MAP_NOMEM;
175 break;
176 case MODM_PREPARE:
178 LPMIDIHDR mh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIHDR) + sizeof(MIDIHDR));
179 LPMIDIHDR16 mh16 = MapSL(*lpParam1);
181 if (mh32) {
182 *(LPMIDIHDR*)mh32 = (LPMIDIHDR)*lpParam1;
183 mh32 = (LPMIDIHDR)((LPSTR)mh32 + sizeof(LPMIDIHDR));
184 mh32->lpData = MapSL((SEGPTR)mh16->lpData);
185 mh32->dwBufferLength = mh16->dwBufferLength;
186 mh32->dwBytesRecorded = mh16->dwBytesRecorded;
187 mh32->dwUser = mh16->dwUser;
188 mh32->dwFlags = mh16->dwFlags;
189 mh16->lpNext = (MIDIHDR16*)mh32; /* for reuse in unprepare and write */
190 *lpParam1 = (DWORD)mh32;
191 *lpParam2 = offsetof(MIDIHDR,dwOffset); /* old size, without dwOffset */
193 ret = MMSYSTEM_MAP_OKMEM;
194 } else {
195 ret = MMSYSTEM_MAP_NOMEM;
198 break;
199 case MODM_UNPREPARE:
200 case MODM_LONGDATA:
202 LPMIDIHDR16 mh16 = MapSL(*lpParam1);
203 LPMIDIHDR mh32 = (MIDIHDR*)mh16->lpNext;
205 *lpParam1 = (DWORD)mh32;
206 *lpParam2 = offsetof(MIDIHDR,dwOffset);
207 /* dwBufferLength can be reduced between prepare & write */
208 if (wMsg == MODM_LONGDATA && mh32->dwBufferLength < mh16->dwBufferLength) {
209 ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
210 mh32->dwBufferLength, mh16->dwBufferLength);
211 } else
212 mh32->dwBufferLength = mh16->dwBufferLength;
213 ret = MMSYSTEM_MAP_OKMEM;
215 break;
217 case MODM_CACHEPATCHES:
218 case MODM_CACHEDRUMPATCHES:
219 default:
220 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
221 break;
223 return ret;
226 /**************************************************************************
227 * MMSYSTDRV_MidiOut_UnMap16To32W [internal]
229 static MMSYSTEM_MapType MMSYSTDRV_MidiOut_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
231 MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
233 switch (wMsg) {
234 case MODM_GETNUMDEVS:
235 case MODM_DATA:
236 case MODM_RESET:
237 case MODM_SETVOLUME:
238 ret = MMSYSTEM_MAP_OK;
239 break;
241 case MODM_OPEN:
242 case MODM_CLOSE:
243 case MODM_GETVOLUME:
244 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
245 break;
247 case MODM_GETDEVCAPS:
249 LPMIDIOUTCAPSW moc32 = (LPMIDIOUTCAPSW)(*lpParam1);
250 LPMIDIOUTCAPS16 moc16 = *(LPMIDIOUTCAPS16*)((LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
252 moc16->wMid = moc32->wMid;
253 moc16->wPid = moc32->wPid;
254 moc16->vDriverVersion = moc32->vDriverVersion;
255 WideCharToMultiByte( CP_ACP, 0, moc32->szPname, -1, moc16->szPname,
256 sizeof(moc16->szPname), NULL, NULL );
257 moc16->wTechnology = moc32->wTechnology;
258 moc16->wVoices = moc32->wVoices;
259 moc16->wNotes = moc32->wNotes;
260 moc16->wChannelMask = moc32->wChannelMask;
261 moc16->dwSupport = moc32->dwSupport;
262 HeapFree(GetProcessHeap(), 0, (LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
263 ret = MMSYSTEM_MAP_OK;
265 break;
266 case MODM_PREPARE:
267 case MODM_UNPREPARE:
268 case MODM_LONGDATA:
270 LPMIDIHDR mh32 = (LPMIDIHDR)(*lpParam1);
271 LPMIDIHDR16 mh16 = MapSL(*(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR)));
273 assert((MIDIHDR*)mh16->lpNext == mh32);
274 mh16->dwFlags = mh32->dwFlags;
276 if (wMsg == MODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
277 HeapFree(GetProcessHeap(), 0, (LPSTR)mh32 - sizeof(LPMIDIHDR));
278 mh16->lpNext = 0;
280 ret = MMSYSTEM_MAP_OK;
282 break;
284 case MODM_CACHEPATCHES:
285 case MODM_CACHEDRUMPATCHES:
286 default:
287 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
288 break;
290 return ret;
293 /******************************************************************
294 * MMSYSTDRV_MidiOut_MapCB
296 static void MMSYSTDRV_MidiOut_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
298 switch (uMsg) {
299 case MOM_OPEN:
300 case MOM_CLOSE:
301 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
302 break;
303 case MOM_POSITIONCB:
304 /* MIDIHDR.dwOffset exists since Win 32 only */
305 FIXME("MOM_POSITIONCB/MEVT_F_CALLBACK wants MIDIHDR.dwOffset in 16 bit code\n");
306 /* fall through */
307 case MOM_DONE:
309 /* initial map is: 16 => 32 */
310 LPMIDIHDR mh32 = (LPMIDIHDR)(*dwParam1);
311 SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR));
312 LPMIDIHDR16 mh16 = MapSL(segmh16);
314 *dwParam1 = (DWORD)segmh16;
315 mh16->dwFlags = mh32->dwFlags;
317 break;
318 default:
319 ERR("Unknown msg %u\n", uMsg);
323 /* =================================
324 * W A V E I N M A P P E R S
325 * ================================= */
327 /**************************************************************************
328 * MMSYSTDRV_WaveIn_Map16To32W [internal]
330 static MMSYSTEM_MapType MMSYSTDRV_WaveIn_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
332 MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
334 switch (wMsg) {
335 case WIDM_GETNUMDEVS:
336 case WIDM_RESET:
337 case WIDM_START:
338 case WIDM_STOP:
339 ret = MMSYSTEM_MAP_OK;
340 break;
341 case WIDM_OPEN:
342 case WIDM_CLOSE:
343 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
344 break;
345 case WIDM_GETDEVCAPS:
347 LPWAVEINCAPSW wic32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEINCAPS16) + sizeof(WAVEINCAPSW));
348 LPWAVEINCAPS16 wic16 = MapSL(*lpParam1);
350 if (wic32) {
351 *(LPWAVEINCAPS16*)wic32 = wic16;
352 wic32 = (LPWAVEINCAPSW)((LPSTR)wic32 + sizeof(LPWAVEINCAPS16));
353 *lpParam1 = (DWORD)wic32;
354 *lpParam2 = sizeof(WAVEINCAPSW);
356 ret = MMSYSTEM_MAP_OKMEM;
357 } else {
358 ret = MMSYSTEM_MAP_NOMEM;
361 break;
362 case WIDM_GETPOS:
364 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
365 LPMMTIME16 mmt16 = MapSL(*lpParam1);
367 if (mmt32) {
368 *(LPMMTIME16*)mmt32 = mmt16;
369 mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
371 mmt32->wType = mmt16->wType;
372 *lpParam1 = (DWORD)mmt32;
373 *lpParam2 = sizeof(MMTIME);
375 ret = MMSYSTEM_MAP_OKMEM;
376 } else {
377 ret = MMSYSTEM_MAP_NOMEM;
380 break;
381 case WIDM_PREPARE:
383 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
384 LPWAVEHDR wh16 = MapSL(*lpParam1);
386 if (wh32) {
387 *(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
388 wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
389 wh32->lpData = MapSL((SEGPTR)wh16->lpData);
390 wh32->dwBufferLength = wh16->dwBufferLength;
391 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
392 wh32->dwUser = wh16->dwUser;
393 wh32->dwFlags = wh16->dwFlags;
394 wh32->dwLoops = wh16->dwLoops;
395 /* FIXME: nothing on wh32->lpNext */
396 /* could link the wh32->lpNext at this level for memory house keeping */
397 wh16->lpNext = wh32; /* for reuse in unprepare and write */
398 *lpParam1 = (DWORD)wh32;
399 *lpParam2 = sizeof(WAVEHDR);
401 ret = MMSYSTEM_MAP_OKMEM;
402 } else {
403 ret = MMSYSTEM_MAP_NOMEM;
406 break;
407 case WIDM_ADDBUFFER:
408 case WIDM_UNPREPARE:
410 LPWAVEHDR wh16 = MapSL(*lpParam1);
411 LPWAVEHDR wh32 = wh16->lpNext;
413 *lpParam1 = (DWORD)wh32;
414 *lpParam2 = sizeof(WAVEHDR);
415 /* dwBufferLength can be reduced between prepare & write */
416 if (wMsg == WIDM_ADDBUFFER && wh32->dwBufferLength < wh16->dwBufferLength) {
417 ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
418 wh32->dwBufferLength, wh16->dwBufferLength);
419 } else
420 wh32->dwBufferLength = wh16->dwBufferLength;
421 ret = MMSYSTEM_MAP_OKMEM;
423 break;
424 case WIDM_MAPPER_STATUS:
425 /* just a single DWORD */
426 *lpParam2 = (DWORD)MapSL(*lpParam2);
427 ret = MMSYSTEM_MAP_OK;
428 break;
429 default:
430 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
431 break;
433 return ret;
436 /**************************************************************************
437 * MMSYSTDRV_WaveIn_UnMap16To32W [internal]
439 static MMSYSTEM_MapType MMSYSTDRV_WaveIn_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
441 MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
443 switch (wMsg) {
444 case WIDM_GETNUMDEVS:
445 case WIDM_RESET:
446 case WIDM_START:
447 case WIDM_STOP:
448 case WIDM_MAPPER_STATUS:
449 ret = MMSYSTEM_MAP_OK;
450 break;
451 case WIDM_OPEN:
452 case WIDM_CLOSE:
453 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
454 break;
455 case WIDM_GETDEVCAPS:
457 LPWAVEINCAPSW wic32 = (LPWAVEINCAPSW)(*lpParam1);
458 LPWAVEINCAPS16 wic16 = *(LPWAVEINCAPS16*)((LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
460 wic16->wMid = wic32->wMid;
461 wic16->wPid = wic32->wPid;
462 wic16->vDriverVersion = wic32->vDriverVersion;
463 WideCharToMultiByte( CP_ACP, 0, wic32->szPname, -1, wic16->szPname,
464 sizeof(wic16->szPname), NULL, NULL );
465 wic16->dwFormats = wic32->dwFormats;
466 wic16->wChannels = wic32->wChannels;
467 HeapFree(GetProcessHeap(), 0, (LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
468 ret = MMSYSTEM_MAP_OK;
470 break;
471 case WIDM_GETPOS:
473 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
474 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
476 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
477 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
478 ret = MMSYSTEM_MAP_OK;
480 break;
481 case WIDM_ADDBUFFER:
482 case WIDM_PREPARE:
483 case WIDM_UNPREPARE:
485 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
486 LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
488 assert(wh16->lpNext == wh32);
489 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
490 wh16->dwFlags = wh32->dwFlags;
492 if (wMsg == WIDM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
493 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
494 wh16->lpNext = 0;
496 ret = MMSYSTEM_MAP_OK;
498 break;
499 default:
500 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
501 break;
503 return ret;
506 /**************************************************************************
507 * MMSYSTDRV_WaveIn_MapCB [internal]
509 static void MMSYSTDRV_WaveIn_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
511 switch (uMsg) {
512 case WIM_OPEN:
513 case WIM_CLOSE:
514 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
515 break;
516 case WIM_DATA:
518 /* initial map is: 16 => 32 */
519 LPWAVEHDR wh32 = (LPWAVEHDR)(*dwParam1);
520 SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
521 LPWAVEHDR wh16 = MapSL(segwh16);
523 *dwParam1 = (DWORD)segwh16;
524 wh16->dwFlags = wh32->dwFlags;
525 wh16->dwBytesRecorded = wh32->dwBytesRecorded;
527 break;
528 default:
529 ERR("Unknown msg %u\n", uMsg);
533 /* =================================
534 * W A V E O U T M A P P E R S
535 * ================================= */
537 /**************************************************************************
538 * MMSYSTDRV_WaveOut_Map16To32W [internal]
540 static MMSYSTEM_MapType MMSYSTDRV_WaveOut_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
542 MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
544 switch (wMsg) {
545 /* nothing to do */
546 case WODM_BREAKLOOP:
547 case WODM_CLOSE:
548 case WODM_GETNUMDEVS:
549 case WODM_PAUSE:
550 case WODM_RESET:
551 case WODM_RESTART:
552 case WODM_SETPITCH:
553 case WODM_SETPLAYBACKRATE:
554 case WODM_SETVOLUME:
555 ret = MMSYSTEM_MAP_OK;
556 break;
558 case WODM_GETPITCH:
559 case WODM_GETPLAYBACKRATE:
560 case WODM_GETVOLUME:
561 case WODM_OPEN:
562 FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
563 break;
565 case WODM_GETDEVCAPS:
567 LPWAVEOUTCAPSW woc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEOUTCAPS16) + sizeof(WAVEOUTCAPSW));
568 LPWAVEOUTCAPS16 woc16 = MapSL(*lpParam1);
570 if (woc32) {
571 *(LPWAVEOUTCAPS16*)woc32 = woc16;
572 woc32 = (LPWAVEOUTCAPSW)((LPSTR)woc32 + sizeof(LPWAVEOUTCAPS16));
573 *lpParam1 = (DWORD)woc32;
574 *lpParam2 = sizeof(WAVEOUTCAPSW);
576 ret = MMSYSTEM_MAP_OKMEM;
577 } else {
578 ret = MMSYSTEM_MAP_NOMEM;
581 break;
582 case WODM_GETPOS:
584 LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
585 LPMMTIME16 mmt16 = MapSL(*lpParam1);
587 if (mmt32) {
588 *(LPMMTIME16*)mmt32 = mmt16;
589 mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
591 mmt32->wType = mmt16->wType;
592 *lpParam1 = (DWORD)mmt32;
593 *lpParam2 = sizeof(MMTIME);
595 ret = MMSYSTEM_MAP_OKMEM;
596 } else {
597 ret = MMSYSTEM_MAP_NOMEM;
600 break;
601 case WODM_PREPARE:
603 LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
604 LPWAVEHDR wh16 = MapSL(*lpParam1);
606 if (wh32) {
607 *(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
608 wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
609 wh32->lpData = MapSL((SEGPTR)wh16->lpData);
610 wh32->dwBufferLength = wh16->dwBufferLength;
611 wh32->dwBytesRecorded = wh16->dwBytesRecorded;
612 wh32->dwUser = wh16->dwUser;
613 wh32->dwFlags = wh16->dwFlags;
614 wh32->dwLoops = wh16->dwLoops;
615 /* FIXME: nothing on wh32->lpNext */
616 /* could link the wh32->lpNext at this level for memory house keeping */
617 wh16->lpNext = wh32; /* for reuse in unprepare and write */
618 *lpParam1 = (DWORD)wh32;
619 *lpParam2 = sizeof(WAVEHDR);
621 ret = MMSYSTEM_MAP_OKMEM;
622 } else {
623 ret = MMSYSTEM_MAP_NOMEM;
626 break;
627 case WODM_UNPREPARE:
628 case WODM_WRITE:
630 LPWAVEHDR wh16 = MapSL(*lpParam1);
631 LPWAVEHDR wh32 = wh16->lpNext;
633 *lpParam1 = (DWORD)wh32;
634 *lpParam2 = sizeof(WAVEHDR);
635 /* dwBufferLength can be reduced between prepare & write */
636 if (wMsg == WODM_WRITE && wh32->dwBufferLength < wh16->dwBufferLength) {
637 ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
638 wh32->dwBufferLength, wh16->dwBufferLength);
639 } else
640 wh32->dwBufferLength = wh16->dwBufferLength;
641 ret = MMSYSTEM_MAP_OKMEM;
643 break;
644 case WODM_MAPPER_STATUS:
645 *lpParam2 = (DWORD)MapSL(*lpParam2);
646 ret = MMSYSTEM_MAP_OK;
647 break;
648 default:
649 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
650 break;
652 return ret;
655 /**************************************************************************
656 * MMSYSTDRV_WaveOut_UnMap16To32W [internal]
658 static MMSYSTEM_MapType MMSYSTDRV_WaveOut_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
660 MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
662 switch (wMsg) {
663 /* nothing to do */
664 case WODM_BREAKLOOP:
665 case WODM_CLOSE:
666 case WODM_GETNUMDEVS:
667 case WODM_PAUSE:
668 case WODM_RESET:
669 case WODM_RESTART:
670 case WODM_SETPITCH:
671 case WODM_SETPLAYBACKRATE:
672 case WODM_SETVOLUME:
673 case WODM_MAPPER_STATUS:
674 ret = MMSYSTEM_MAP_OK;
675 break;
677 case WODM_GETPITCH:
678 case WODM_GETPLAYBACKRATE:
679 case WODM_GETVOLUME:
680 case WODM_OPEN:
681 FIXME("Shouldn't be used: those 16 bit functions use the 32 bit interface\n");
682 break;
684 case WODM_GETDEVCAPS:
686 LPWAVEOUTCAPSW woc32 = (LPWAVEOUTCAPSW)(*lpParam1);
687 LPWAVEOUTCAPS16 woc16 = *(LPWAVEOUTCAPS16*)((LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
689 woc16->wMid = woc32->wMid;
690 woc16->wPid = woc32->wPid;
691 woc16->vDriverVersion = woc32->vDriverVersion;
692 WideCharToMultiByte( CP_ACP, 0, woc32->szPname, -1, woc16->szPname,
693 sizeof(woc16->szPname), NULL, NULL );
694 woc16->dwFormats = woc32->dwFormats;
695 woc16->wChannels = woc32->wChannels;
696 woc16->dwSupport = woc32->dwSupport;
697 HeapFree(GetProcessHeap(), 0, (LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
698 ret = MMSYSTEM_MAP_OK;
700 break;
701 case WODM_GETPOS:
703 LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
704 LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
706 MMSYSTEM_MMTIME32to16(mmt16, mmt32);
707 HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
708 ret = MMSYSTEM_MAP_OK;
710 break;
711 case WODM_PREPARE:
712 case WODM_UNPREPARE:
713 case WODM_WRITE:
715 LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
716 LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
718 assert(wh16->lpNext == wh32);
719 wh16->dwFlags = wh32->dwFlags;
721 if (wMsg == WODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
722 HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
723 wh16->lpNext = 0;
725 ret = MMSYSTEM_MAP_OK;
727 break;
728 default:
729 FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
730 break;
732 return ret;
735 /**************************************************************************
736 * MMDRV_WaveOut_Callback [internal]
738 static void MMSYSTDRV_WaveOut_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
740 switch (uMsg) {
741 case WOM_OPEN:
742 case WOM_CLOSE:
743 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
744 break;
745 case WOM_DONE:
747 /* initial map is: 16 => 32 */
748 LPWAVEHDR wh32 = (LPWAVEHDR)(*dwParam1);
749 SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
750 LPWAVEHDR wh16 = MapSL(segwh16);
752 *dwParam1 = (DWORD)segwh16;
753 wh16->dwFlags = wh32->dwFlags;
755 break;
756 default:
757 ERR("Unknown msg %u\n", uMsg);
761 /* ###################################################
762 * # DRIVER THUNKING #
763 * ###################################################
765 typedef MMSYSTEM_MapType (*MMSYSTDRV_MAPMSG)(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2);
766 typedef MMSYSTEM_MapType (*MMSYSTDRV_UNMAPMSG)(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT ret);
767 typedef void (*MMSYSTDRV_MAPCB)(DWORD wMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2);
769 #include <pshpack1.h>
770 #define MMSYSTDRV_MAX_THUNKS 32
772 static struct mmsystdrv_thunk
774 BYTE popl_eax; /* popl %eax (return address) */
775 BYTE pushl_this; /* pushl this (this very thunk) */
776 struct mmsystdrv_thunk* this;
777 BYTE pushl_eax; /* pushl %eax */
778 BYTE jmp; /* ljmp MMDRV_Callback3216 */
779 DWORD callback3216;
780 DWORD callback; /* callback value (function, window, event...) */
781 DWORD flags; /* flags to control callback value (CALLBACK_???) */
782 void* hMmdrv; /* Handle to 32bit mmdrv object */
783 enum MMSYSTEM_DriverType kind;
784 } *MMSYSTDRV_Thunks;
786 #include <poppack.h>
788 static struct MMSYSTDRV_Type
790 MMSYSTDRV_MAPMSG mapmsg16to32W;
791 MMSYSTDRV_UNMAPMSG unmapmsg16to32W;
792 MMSYSTDRV_MAPCB mapcb;
793 } MMSYSTEM_DriversType[MMSYSTDRV_MAX] =
795 {MMSYSTDRV_Mixer_Map16To32W, MMSYSTDRV_Mixer_UnMap16To32W, MMSYSTDRV_Mixer_MapCB},
796 {MMSYSTDRV_MidiIn_Map16To32W, MMSYSTDRV_MidiIn_UnMap16To32W, MMSYSTDRV_MidiIn_MapCB},
797 {MMSYSTDRV_MidiOut_Map16To32W, MMSYSTDRV_MidiOut_UnMap16To32W, MMSYSTDRV_MidiOut_MapCB},
798 {MMSYSTDRV_WaveIn_Map16To32W, MMSYSTDRV_WaveIn_UnMap16To32W, MMSYSTDRV_WaveIn_MapCB},
799 {MMSYSTDRV_WaveOut_Map16To32W, MMSYSTDRV_WaveOut_UnMap16To32W, MMSYSTDRV_WaveOut_MapCB},
802 /******************************************************************
803 * MMSYSTDRV_Callback3216
806 static LRESULT CALLBACK MMSYSTDRV_Callback3216(struct mmsystdrv_thunk* thunk, HDRVR hDev,
807 DWORD wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1,
808 DWORD_PTR dwParam2)
810 WORD args[8];
812 assert(thunk->kind < MMSYSTDRV_MAX);
813 assert(MMSYSTEM_DriversType[thunk->kind].mapcb);
815 MMSYSTEM_DriversType[thunk->kind].mapcb(wMsg, &dwUser, &dwParam1, &dwParam2);
817 switch (thunk->flags & CALLBACK_TYPEMASK) {
818 case CALLBACK_NULL:
819 TRACE("Null !\n");
820 break;
821 case CALLBACK_WINDOW:
822 TRACE("Window(%04X) handle=%p!\n", thunk->callback, hDev);
823 PostMessageA((HWND)thunk->callback, wMsg, (WPARAM)hDev, dwParam1);
824 break;
825 case CALLBACK_TASK: /* aka CALLBACK_THREAD */
826 TRACE("Task(%04x) !\n", thunk->callback);
827 PostThreadMessageA(thunk->callback, wMsg, (WPARAM)hDev, dwParam1);
828 break;
829 case CALLBACK_FUNCTION:
830 /* 16 bit func, call it */
831 TRACE("Function (16 bit) %x!\n", thunk->callback);
833 args[7] = HDRVR_16(hDev);
834 args[6] = wMsg;
835 args[5] = HIWORD(dwUser);
836 args[4] = LOWORD(dwUser);
837 args[3] = HIWORD(dwParam1);
838 args[2] = LOWORD(dwParam1);
839 args[1] = HIWORD(dwParam2);
840 args[0] = LOWORD(dwParam2);
841 return WOWCallback16Ex(thunk->callback, WCB16_PASCAL, sizeof(args), args, NULL);
842 case CALLBACK_EVENT:
843 TRACE("Event(%08x) !\n", thunk->callback);
844 SetEvent((HANDLE)thunk->callback);
845 break;
846 default:
847 WARN("Unknown callback type %x\n", thunk->flags & CALLBACK_TYPEMASK);
848 return FALSE;
850 TRACE("Done\n");
851 return TRUE;
854 /******************************************************************
855 * MMSYSTDRV_AddThunk
858 struct mmsystdrv_thunk* MMSYSTDRV_AddThunk(DWORD callback, DWORD flags, enum MMSYSTEM_DriverType kind)
860 struct mmsystdrv_thunk* thunk;
862 EnterCriticalSection(&mmdrv_cs);
863 if (!MMSYSTDRV_Thunks)
865 MMSYSTDRV_Thunks = VirtualAlloc(NULL, MMSYSTDRV_MAX_THUNKS * sizeof(*MMSYSTDRV_Thunks),
866 MEM_COMMIT, PAGE_EXECUTE_READWRITE);
867 if (!MMSYSTDRV_Thunks)
869 LeaveCriticalSection(&mmdrv_cs);
870 return NULL;
872 for (thunk = MMSYSTDRV_Thunks; thunk < &MMSYSTDRV_Thunks[MMSYSTDRV_MAX_THUNKS]; thunk++)
874 thunk->popl_eax = 0x58; /* popl %eax */
875 thunk->pushl_this = 0x68; /* pushl this */
876 thunk->this = thunk;
877 thunk->pushl_eax = 0x50; /* pushl %eax */
878 thunk->jmp = 0xe9; /* jmp MMDRV_Callback3216 */
879 thunk->callback3216 = (char *)MMSYSTDRV_Callback3216 - (char *)(&thunk->callback3216 + 1);
880 thunk->callback = 0;
881 thunk->flags = CALLBACK_NULL;
882 thunk->hMmdrv = NULL;
883 thunk->kind = MMSYSTDRV_MAX;
886 for (thunk = MMSYSTDRV_Thunks; thunk < &MMSYSTDRV_Thunks[MMSYSTDRV_MAX_THUNKS]; thunk++)
888 if (thunk->callback == 0 && thunk->hMmdrv == NULL)
890 thunk->callback = callback;
891 thunk->flags = flags;
892 thunk->hMmdrv = NULL;
893 thunk->kind = kind;
894 LeaveCriticalSection(&mmdrv_cs);
895 return thunk;
898 LeaveCriticalSection(&mmdrv_cs);
899 FIXME("Out of mmdrv-thunks. Bump MMDRV_MAX_THUNKS\n");
900 return NULL;
903 /******************************************************************
904 * MMSYSTDRV_FindHandle
906 * Must be called with lock set
908 static void* MMSYSTDRV_FindHandle(void* h)
910 struct mmsystdrv_thunk* thunk;
912 for (thunk = MMSYSTDRV_Thunks; thunk < &MMSYSTDRV_Thunks[MMSYSTDRV_MAX_THUNKS]; thunk++)
914 if (thunk->hMmdrv == h)
916 if (thunk->kind >= MMSYSTDRV_MAX) FIXME("Kind isn't properly initialized %x\n", thunk->kind);
917 return thunk;
920 return NULL;
923 /******************************************************************
924 * MMSYSTDRV_SetHandle
927 void MMSYSTDRV_SetHandle(struct mmsystdrv_thunk* thunk, void* h)
929 if (MMSYSTDRV_FindHandle(h)) FIXME("Already has a thunk for this handle %p!!!\n", h);
930 thunk->hMmdrv = h;
933 /******************************************************************
934 * MMSYSTDRV_DeleteThunk
936 void MMSYSTDRV_DeleteThunk(struct mmsystdrv_thunk* thunk)
938 thunk->callback = 0;
939 thunk->flags = CALLBACK_NULL;
940 thunk->hMmdrv = NULL;
941 thunk->kind = MMSYSTDRV_MAX;
944 /******************************************************************
945 * MMSYSTDRV_CloseHandle
947 void MMSYSTDRV_CloseHandle(void* h)
949 struct mmsystdrv_thunk* thunk;
951 EnterCriticalSection(&mmdrv_cs);
952 if ((thunk = MMSYSTDRV_FindHandle(h)))
954 MMSYSTDRV_DeleteThunk(thunk);
956 LeaveCriticalSection(&mmdrv_cs);
959 /******************************************************************
960 * MMSYSTDRV_Message
962 DWORD MMSYSTDRV_Message(void* h, UINT msg, DWORD_PTR param1, DWORD_PTR param2)
964 struct mmsystdrv_thunk* thunk = MMSYSTDRV_FindHandle(h);
965 struct MMSYSTDRV_Type* drvtype;
966 MMSYSTEM_MapType map;
967 DWORD ret;
969 if (!thunk) return MMSYSERR_INVALHANDLE;
970 drvtype = &MMSYSTEM_DriversType[thunk->kind];
972 map = drvtype->mapmsg16to32W(msg, &param1, &param2);
973 switch (map) {
974 case MMSYSTEM_MAP_NOMEM:
975 ret = MMSYSERR_NOMEM;
976 break;
977 case MMSYSTEM_MAP_MSGERROR:
978 FIXME("NIY: no conversion yet 16->32 kind=%u msg=%u\n", thunk->kind, msg);
979 ret = MMSYSERR_ERROR;
980 break;
981 case MMSYSTEM_MAP_OK:
982 case MMSYSTEM_MAP_OKMEM:
983 TRACE("Calling message(msg=%u p1=0x%08lx p2=0x%08lx)\n",
984 msg, param1, param2);
985 switch (thunk->kind)
987 case MMSYSTDRV_MIXER: ret = mixerMessage (h, msg, param1, param2); break;
988 case MMSYSTDRV_MIDIIN:
989 switch (msg)
991 case MIDM_ADDBUFFER: ret = midiInAddBuffer(h, (LPMIDIHDR)param1, param2); break;
992 case MIDM_PREPARE: ret = midiInPrepareHeader(h, (LPMIDIHDR)param1, param2); break;
993 case MIDM_UNPREPARE: ret = midiInUnprepareHeader(h, (LPMIDIHDR)param1, param2); break;
994 default: ret = midiInMessage(h, msg, param1, param2); break;
996 break;
997 case MMSYSTDRV_MIDIOUT:
998 switch (msg)
1000 case MODM_PREPARE: ret = midiOutPrepareHeader(h, (LPMIDIHDR)param1, param2); break;
1001 case MODM_UNPREPARE: ret = midiOutUnprepareHeader(h, (LPMIDIHDR)param1, param2); break;
1002 case MODM_LONGDATA: ret = midiOutLongMsg(h, (LPMIDIHDR)param1, param2); break;
1003 default: ret = midiOutMessage(h, msg, param1, param2); break;
1005 break;
1006 case MMSYSTDRV_WAVEIN:
1007 switch (msg)
1009 case WIDM_ADDBUFFER: ret = waveInAddBuffer(h, (LPWAVEHDR)param1, param2); break;
1010 case WIDM_PREPARE: ret = waveInPrepareHeader(h, (LPWAVEHDR)param1, param2); break;
1011 case WIDM_UNPREPARE: ret = waveInUnprepareHeader(h, (LPWAVEHDR)param1, param2); break;
1012 default: ret = waveInMessage(h, msg, param1, param2); break;
1014 break;
1015 case MMSYSTDRV_WAVEOUT:
1016 switch (msg)
1018 case WODM_PREPARE: ret = waveOutPrepareHeader(h, (LPWAVEHDR)param1, param2); break;
1019 case WODM_UNPREPARE: ret = waveOutUnprepareHeader(h, (LPWAVEHDR)param1, param2); break;
1020 case WODM_WRITE: ret = waveOutWrite(h, (LPWAVEHDR)param1, param2); break;
1021 default: ret = waveOutMessage(h, msg, param1, param2); break;
1023 break;
1024 default: ret = MMSYSERR_INVALHANDLE; break; /* should never be reached */
1026 if (map == MMSYSTEM_MAP_OKMEM)
1027 drvtype->unmapmsg16to32W(msg, &param1, &param2, ret);
1028 break;
1029 default:
1030 FIXME("NIY\n");
1031 ret = MMSYSERR_NOTSUPPORTED;
1032 break;
1034 return ret;