All MCI functions are now cleanly separated.
[wine/multimedia.git] / dlls / winmm / mmsystem.c
blob1a6ef21db2e3cc24bb58a744bc479f4d4025c998
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MMSYTEM functions
6 * Copyright 1993 Martin Ayotte
7 * 1998-2002 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Eric POUECH :
26 * 99/4 added mmTask and mmThread functions support
29 /* FIXME: I think there are some segmented vs. linear pointer weirdnesses
30 * and long term pointers to 16 bit space in here
33 #include <string.h>
35 #include "mmsystem.h"
36 #include "winbase.h"
38 #include "wine/mmsystem16.h"
39 #include "wine/winuser16.h"
40 #include "winemm.h"
41 #include "heap.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
47 /* ### start build ### */
48 extern LONG CALLBACK MMSYSTEM_CallTo16_long_l (FARPROC16,LONG);
49 extern LONG CALLBACK MMSYSTEM_CallTo16_long_lwll (LPMMIOPROC16,LONG,WORD,LONG,LONG);
50 /* ### stop build ### */
52 static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16);
53 static LPWINE_DRIVER DRIVER_OpenDriver16(LPCSTR, LPCSTR, LPARAM);
54 static LRESULT DRIVER_CloseDriver16(HDRVR16, LPARAM, LPARAM);
55 static LRESULT DRIVER_SendMessage16(HDRVR16, UINT, LPARAM, LPARAM);
56 static LRESULT MMIO_Callback16(SEGPTR, LPMMIOINFO, UINT, LPARAM, LPARAM);
58 /* ###################################################
59 * # LIBRARY #
60 * ###################################################
63 /**************************************************************************
64 * DllEntryPoint (MMSYSTEM.2046)
66 * MMSYSTEM DLL entry point
69 BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
70 WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
72 TRACE("0x%x 0x%lx\n", hinstDLL, fdwReason);
74 switch (fdwReason) {
75 case DLL_PROCESS_ATTACH:
76 /* need to load WinMM in order to:
77 * - initiate correctly shared variables (WINMM_Init())
79 if (!GetModuleHandleA("WINMM.DLL") && !LoadLibraryA("WINMM.DLL"))
81 ERR("Could not load sibling WinMM.dll\n");
82 return FALSE;
84 WINMM_IData->hWinMM16Instance = hinstDLL;
85 /* hook in our 16 bit function pointers */
86 pFnGetMMThread16 = WINMM_GetmmThread;
87 pFnOpenDriver16 = DRIVER_OpenDriver16;
88 pFnCloseDriver16 = DRIVER_CloseDriver16;
89 pFnSendMessage16 = DRIVER_SendMessage16;
90 pFnMmioCallback16 = MMIO_Callback16;
91 MMDRV_Init16();
92 break;
93 case DLL_PROCESS_DETACH:
94 WINMM_IData->hWinMM16Instance = 0;
95 pFnGetMMThread16 = NULL;
96 pFnOpenDriver16 = NULL;
97 pFnCloseDriver16 = NULL;
98 pFnSendMessage16 = NULL;
99 pFnMmioCallback16 = NULL;
100 /* FIXME: add equivalent for MMDRV_Init16() */
101 break;
102 case DLL_THREAD_ATTACH:
103 case DLL_THREAD_DETACH:
104 break;
106 return TRUE;
109 /**************************************************************************
110 * MMSYSTEM_WEP [MMSYSTEM.1]
112 int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
113 WORD cbHeapSize, LPSTR lpCmdLine)
115 FIXME("STUB: Unloading MMSystem DLL ... hInst=%04X \n", hInstance);
116 return TRUE;
119 /* ###################################################
120 * # PlaySound #
121 * ###################################################
124 /**************************************************************************
125 * PlaySound [MMSYSTEM.3]
127 BOOL16 WINAPI PlaySound16(LPCSTR pszSound, HMODULE16 hmod, DWORD fdwSound)
129 BOOL16 retv;
130 DWORD lc;
132 ReleaseThunkLock(&lc);
133 retv = PlaySoundA(pszSound, hmod, fdwSound);
134 RestoreThunkLock(lc);
136 return retv;
139 /**************************************************************************
140 * sndPlaySound [MMSYSTEM.2]
142 BOOL16 WINAPI sndPlaySound16(LPCSTR lpszSoundName, UINT16 uFlags)
144 BOOL16 retv;
145 DWORD lc;
147 ReleaseThunkLock(&lc);
148 retv = sndPlaySoundA(lpszSoundName, uFlags);
149 RestoreThunkLock(lc);
151 return retv;
154 /* ###################################################
155 * # MISC #
156 * ###################################################
159 /**************************************************************************
160 * mmsystemGetVersion [MMSYSTEM.5]
163 UINT16 WINAPI mmsystemGetVersion16(void)
165 return mmsystemGetVersion();
168 /**************************************************************************
169 * DriverCallback [MMSYSTEM.31]
171 BOOL16 WINAPI DriverCallback16(DWORD dwCallBack, UINT16 uFlags, HDRVR16 hDev,
172 WORD wMsg, DWORD dwUser, DWORD dwParam1,
173 DWORD dwParam2)
175 return DriverCallback(dwCallBack, uFlags, HDRVR_32(hDev), wMsg, dwUser, dwParam1, dwParam2);
178 /**************************************************************************
179 * OutputDebugStr [MMSYSTEM.30]
181 void WINAPI OutputDebugStr16(LPCSTR str)
183 OutputDebugStringA( str );
187 /* ###################################################
188 * # MIXER #
189 * ###################################################
192 /**************************************************************************
193 * Mixer devices. New to Win95
196 /**************************************************************************
197 * mixerGetNumDevs [MMSYSTEM.800]
199 UINT16 WINAPI mixerGetNumDevs16(void)
201 return MMDRV_GetNum(MMDRV_MIXER);
204 /**************************************************************************
205 * mixerGetDevCaps [MMSYSTEM.801]
207 UINT16 WINAPI mixerGetDevCaps16(UINT16 devid, LPMIXERCAPS16 mixcaps,
208 UINT16 size)
210 MIXERCAPSA micA;
211 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
213 if (ret == MMSYSERR_NOERROR) {
214 mixcaps->wMid = micA.wMid;
215 mixcaps->wPid = micA.wPid;
216 mixcaps->vDriverVersion = micA.vDriverVersion;
217 strcpy(mixcaps->szPname, micA.szPname);
218 mixcaps->fdwSupport = micA.fdwSupport;
219 mixcaps->cDestinations = micA.cDestinations;
221 return ret;
224 /**************************************************************************
225 * mixerOpen [MMSYSTEM.802]
227 UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix, UINT16 uDeviceID, DWORD dwCallback,
228 DWORD dwInstance, DWORD fdwOpen)
230 HMIXER hmix;
231 UINT ret;
233 ret = MMSYSTEM_mixerOpen(&hmix, uDeviceID,
234 dwCallback, dwInstance, fdwOpen, FALSE);
235 if (lphmix) *lphmix = HMIXER_16(hmix);
236 return ret;
239 /**************************************************************************
240 * mixerClose [MMSYSTEM.803]
242 UINT16 WINAPI mixerClose16(HMIXER16 hMix)
244 return mixerClose(HMIXER_32(hMix));
247 /**************************************************************************
248 * mixerGetID (MMSYSTEM.806)
250 UINT16 WINAPI mixerGetID16(HMIXEROBJ16 hmix, LPUINT16 lpid, DWORD fdwID)
252 UINT xid;
253 UINT ret = mixerGetID(HMIXEROBJ_32(hmix), &xid, fdwID);
255 if (lpid)
256 *lpid = xid;
257 return ret;
260 /**************************************************************************
261 * mixerGetControlDetails [MMSYSTEM.808]
263 UINT16 WINAPI mixerGetControlDetails16(HMIXEROBJ16 hmix,
264 LPMIXERCONTROLDETAILS16 lpmcd,
265 DWORD fdwDetails)
267 DWORD ret = MMSYSERR_NOTENABLED;
268 SEGPTR sppaDetails;
270 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
272 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
273 return MMSYSERR_INVALPARAM;
275 sppaDetails = (SEGPTR)lpmcd->paDetails;
276 lpmcd->paDetails = MapSL(sppaDetails);
277 ret = mixerGetControlDetailsA(HMIXEROBJ_32(hmix),
278 (LPMIXERCONTROLDETAILS)lpmcd, fdwDetails);
279 lpmcd->paDetails = (LPVOID)sppaDetails;
281 return ret;
284 /**************************************************************************
285 * mixerGetLineControls [MMSYSTEM.807]
287 UINT16 WINAPI mixerGetLineControls16(HMIXEROBJ16 hmix,
288 LPMIXERLINECONTROLS16 lpmlc16,
289 DWORD fdwControls)
291 MIXERLINECONTROLSA mlcA;
292 DWORD ret;
293 int i;
294 LPMIXERCONTROL16 lpmc16;
296 TRACE("(%04x, %p, %08lx)\n", hmix, lpmlc16, fdwControls);
298 if (lpmlc16 == NULL || lpmlc16->cbStruct != sizeof(*lpmlc16) ||
299 lpmlc16->cbmxctrl != sizeof(MIXERCONTROL16))
300 return MMSYSERR_INVALPARAM;
302 mlcA.cbStruct = sizeof(mlcA);
303 mlcA.dwLineID = lpmlc16->dwLineID;
304 mlcA.u.dwControlID = lpmlc16->u.dwControlID;
305 mlcA.u.dwControlType = lpmlc16->u.dwControlType;
306 mlcA.cControls = lpmlc16->cControls;
307 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
308 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
309 mlcA.cControls * mlcA.cbmxctrl);
311 ret = mixerGetLineControlsA(HMIXEROBJ_32(hmix), &mlcA, fdwControls);
313 if (ret == MMSYSERR_NOERROR) {
314 lpmlc16->dwLineID = mlcA.dwLineID;
315 lpmlc16->u.dwControlID = mlcA.u.dwControlID;
316 lpmlc16->u.dwControlType = mlcA.u.dwControlType;
317 lpmlc16->cControls = mlcA.cControls;
319 lpmc16 = MapSL(lpmlc16->pamxctrl);
321 for (i = 0; i < mlcA.cControls; i++) {
322 lpmc16[i].cbStruct = sizeof(MIXERCONTROL16);
323 lpmc16[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
324 lpmc16[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
325 lpmc16[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
326 lpmc16[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
327 strcpy(lpmc16[i].szShortName, mlcA.pamxctrl[i].szShortName);
328 strcpy(lpmc16[i].szName, mlcA.pamxctrl[i].szName);
329 /* sizeof(lpmc16[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
330 memcpy(&lpmc16[i].Bounds, &mlcA.pamxctrl[i].Bounds,
331 sizeof(mlcA.pamxctrl[i].Bounds));
332 /* sizeof(lpmc16[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
333 memcpy(&lpmc16[i].Metrics, &mlcA.pamxctrl[i].Metrics,
334 sizeof(mlcA.pamxctrl[i].Metrics));
338 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
340 return ret;
343 /**************************************************************************
344 * mixerGetLineInfo [MMSYSTEM.805]
346 UINT16 WINAPI mixerGetLineInfo16(HMIXEROBJ16 hmix, LPMIXERLINE16 lpmli16,
347 DWORD fdwInfo)
349 MIXERLINEA mliA;
350 UINT ret;
352 TRACE("(%04x, %p, %08lx)\n", hmix, lpmli16, fdwInfo);
354 if (lpmli16 == NULL || lpmli16->cbStruct != sizeof(*lpmli16))
355 return MMSYSERR_INVALPARAM;
357 mliA.cbStruct = sizeof(mliA);
358 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
359 case MIXER_GETLINEINFOF_COMPONENTTYPE:
360 mliA.dwComponentType = lpmli16->dwComponentType;
361 break;
362 case MIXER_GETLINEINFOF_DESTINATION:
363 mliA.dwDestination = lpmli16->dwDestination;
364 break;
365 case MIXER_GETLINEINFOF_LINEID:
366 mliA.dwLineID = lpmli16->dwLineID;
367 break;
368 case MIXER_GETLINEINFOF_SOURCE:
369 mliA.dwDestination = lpmli16->dwDestination;
370 mliA.dwSource = lpmli16->dwSource;
371 break;
372 case MIXER_GETLINEINFOF_TARGETTYPE:
373 mliA.Target.dwType = lpmli16->Target.dwType;
374 mliA.Target.wMid = lpmli16->Target.wMid;
375 mliA.Target.wPid = lpmli16->Target.wPid;
376 mliA.Target.vDriverVersion = lpmli16->Target.vDriverVersion;
377 strcpy(mliA.Target.szPname, lpmli16->Target.szPname);
378 break;
379 default:
380 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo);
383 ret = mixerGetLineInfoA(HMIXEROBJ_32(hmix), &mliA, fdwInfo);
385 lpmli16->dwDestination = mliA.dwDestination;
386 lpmli16->dwSource = mliA.dwSource;
387 lpmli16->dwLineID = mliA.dwLineID;
388 lpmli16->fdwLine = mliA.fdwLine;
389 lpmli16->dwUser = mliA.dwUser;
390 lpmli16->dwComponentType = mliA.dwComponentType;
391 lpmli16->cChannels = mliA.cChannels;
392 lpmli16->cConnections = mliA.cConnections;
393 lpmli16->cControls = mliA.cControls;
394 strcpy(lpmli16->szShortName, mliA.szShortName);
395 strcpy(lpmli16->szName, mliA.szName);
396 lpmli16->Target.dwType = mliA.Target.dwType;
397 lpmli16->Target.dwDeviceID = mliA.Target.dwDeviceID;
398 lpmli16->Target.wMid = mliA.Target.wMid;
399 lpmli16->Target.wPid = mliA.Target.wPid;
400 lpmli16->Target.vDriverVersion = mliA.Target.vDriverVersion;
401 strcpy(lpmli16->Target.szPname, mliA.Target.szPname);
403 return ret;
406 /**************************************************************************
407 * mixerSetControlDetails [MMSYSTEM.809]
409 UINT16 WINAPI mixerSetControlDetails16(HMIXEROBJ16 hmix,
410 LPMIXERCONTROLDETAILS16 lpmcd,
411 DWORD fdwDetails)
413 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
414 return MMSYSERR_NOTENABLED;
417 /**************************************************************************
418 * mixerMessage [MMSYSTEM.804]
420 DWORD WINAPI mixerMessage16(HMIXER16 hmix, UINT16 uMsg, DWORD dwParam1,
421 DWORD dwParam2)
423 return mixerMessage(HMIXER_32(hmix), uMsg, dwParam1, dwParam2);
426 /**************************************************************************
427 * auxGetNumDevs [MMSYSTEM.350]
429 UINT16 WINAPI auxGetNumDevs16(void)
431 return MMDRV_GetNum(MMDRV_AUX);
434 /* ###################################################
435 * # AUX #
436 * ###################################################
439 /**************************************************************************
440 * auxGetDevCaps [MMSYSTEM.351]
442 UINT16 WINAPI auxGetDevCaps16(UINT16 uDeviceID, LPAUXCAPS16 lpCaps, UINT16 uSize)
444 LPWINE_MLD wmld;
446 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
448 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
449 return MMSYSERR_INVALHANDLE;
450 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
453 /**************************************************************************
454 * auxGetVolume [MMSYSTEM.352]
456 UINT16 WINAPI auxGetVolume16(UINT16 uDeviceID, LPDWORD lpdwVolume)
458 LPWINE_MLD wmld;
460 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
462 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
463 return MMSYSERR_INVALHANDLE;
464 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD)lpdwVolume, 0L, TRUE);
467 /**************************************************************************
468 * auxSetVolume [MMSYSTEM.353]
470 UINT16 WINAPI auxSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
472 LPWINE_MLD wmld;
474 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
476 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
477 return MMSYSERR_INVALHANDLE;
478 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
481 /**************************************************************************
482 * auxOutMessage [MMSYSTEM.354]
484 DWORD WINAPI auxOutMessage16(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
486 LPWINE_MLD wmld;
488 TRACE("(%04X, %04X, %08lX, %08lX)\n", uDeviceID, uMessage, dw1, dw2);
490 switch (uMessage) {
491 case AUXDM_GETNUMDEVS:
492 case AUXDM_SETVOLUME:
493 /* no argument conversion needed */
494 break;
495 case AUXDM_GETVOLUME:
496 return auxGetVolume16(uDeviceID, MapSL(dw1));
497 case AUXDM_GETDEVCAPS:
498 return auxGetDevCaps16(uDeviceID, MapSL(dw1), dw2);
499 default:
500 TRACE("(%04x, %04x, %08lx, %08lx): unhandled message\n",
501 uDeviceID, uMessage, dw1, dw2);
502 break;
504 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
505 return MMSYSERR_INVALHANDLE;
507 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
510 /* ###################################################
511 * # MCI #
512 * ###################################################
515 /**************************************************************************
516 * mciGetErrorString [MMSYSTEM.706]
518 BOOL16 WINAPI mciGetErrorString16(DWORD wError, LPSTR lpstrBuffer, UINT16 uLength)
520 return mciGetErrorStringA(wError, lpstrBuffer, uLength);
523 /**************************************************************************
524 * mciDriverNotify [MMSYSTEM.711]
526 BOOL16 WINAPI mciDriverNotify16(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
528 TRACE("(%04X, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
530 return PostMessageA(HWND_32(hWndCallBack), MM_MCINOTIFY, wStatus, wDevID);
533 /**************************************************************************
534 * mciGetDriverData [MMSYSTEM.708]
536 DWORD WINAPI mciGetDriverData16(UINT16 uDeviceID)
538 return mciGetDriverData(uDeviceID);
541 /**************************************************************************
542 * mciSetDriverData [MMSYSTEM.707]
544 BOOL16 WINAPI mciSetDriverData16(UINT16 uDeviceID, DWORD data)
546 return mciSetDriverData(uDeviceID, data);
549 /**************************************************************************
550 * mciSendCommand [MMSYSTEM.701]
552 DWORD WINAPI mciSendCommand16(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
554 DWORD dwRet;
556 TRACE("(%04X, %s, %08lX, %08lX)\n",
557 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
559 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, FALSE);
560 dwRet = MCI_CleanUp(dwRet, wMsg, (DWORD)MapSL(dwParam2));
561 TRACE("=> %ld\n", dwRet);
562 return dwRet;
565 /**************************************************************************
566 * mciGetDeviceID [MMSYSTEM.703]
568 UINT16 WINAPI mciGetDeviceID16(LPCSTR lpstrName)
570 TRACE("(\"%s\")\n", lpstrName);
572 return MCI_GetDriverFromString(lpstrName);
575 /**************************************************************************
576 * mciSetYieldProc [MMSYSTEM.714]
578 BOOL16 WINAPI mciSetYieldProc16(UINT16 uDeviceID, YIELDPROC16 fpYieldProc, DWORD dwYieldData)
580 LPWINE_MCIDRIVER wmd;
582 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
584 if (!(wmd = MCI_GetDriver(uDeviceID))) {
585 WARN("Bad uDeviceID\n");
586 return FALSE;
589 wmd->lpfnYieldProc = (YIELDPROC)fpYieldProc;
590 wmd->dwYieldData = dwYieldData;
591 wmd->bIs32 = FALSE;
593 return TRUE;
596 /**************************************************************************
597 * mciGetDeviceIDFromElementID [MMSYSTEM.715]
599 UINT16 WINAPI mciGetDeviceIDFromElementID16(DWORD dwElementID, LPCSTR lpstrType)
601 FIXME("(%lu, %s) stub\n", dwElementID, lpstrType);
602 return 0;
605 /**************************************************************************
606 * mciGetYieldProc [MMSYSTEM.716]
608 YIELDPROC16 WINAPI mciGetYieldProc16(UINT16 uDeviceID, DWORD* lpdwYieldData)
610 LPWINE_MCIDRIVER wmd;
612 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
614 if (!(wmd = MCI_GetDriver(uDeviceID))) {
615 WARN("Bad uDeviceID\n");
616 return NULL;
618 if (!wmd->lpfnYieldProc) {
619 WARN("No proc set\n");
620 return NULL;
622 if (wmd->bIs32) {
623 WARN("Proc is 32 bit\n");
624 return NULL;
626 return (YIELDPROC16)wmd->lpfnYieldProc;
629 /**************************************************************************
630 * mciGetCreatorTask [MMSYSTEM.717]
632 HTASK16 WINAPI mciGetCreatorTask16(UINT16 uDeviceID)
634 LPWINE_MCIDRIVER wmd;
635 HTASK16 ret = 0;
637 if ((wmd = MCI_GetDriver(uDeviceID))) ret = K32WOWHandle16(wmd->CreatorThread, WOW_TYPE_HTASK);
639 TRACE("(%u) => %04x\n", uDeviceID, ret);
640 return ret;
643 /**************************************************************************
644 * mciDriverYield [MMSYSTEM.710]
646 UINT16 WINAPI mciDriverYield16(UINT16 uDeviceID)
648 LPWINE_MCIDRIVER wmd;
649 UINT16 ret = 0;
651 /* TRACE("(%04x)\n", uDeviceID); */
653 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || wmd->bIs32) {
654 UserYield16();
655 } else {
656 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
659 return ret;
662 /* ###################################################
663 * # MIDI #
664 * ###################################################
667 /**************************************************************************
668 * midiOutGetNumDevs [MMSYSTEM.201]
670 UINT16 WINAPI midiOutGetNumDevs16(void)
672 return MMDRV_GetNum(MMDRV_MIDIOUT);
675 /**************************************************************************
676 * midiOutGetDevCaps [MMSYSTEM.202]
678 UINT16 WINAPI midiOutGetDevCaps16(UINT16 uDeviceID, LPMIDIOUTCAPS16 lpCaps,
679 UINT16 uSize)
681 MIDIOUTCAPSA capsA;
682 UINT dwRet;
684 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
686 dwRet = midiOutGetDevCapsA(uDeviceID, &capsA, sizeof(capsA));
687 if (dwRet == MMSYSERR_NOERROR) {
688 lpCaps->wMid = capsA.wMid;
689 lpCaps->wPid = capsA.wPid;
690 lpCaps->vDriverVersion = capsA.vDriverVersion;
691 strcpy(lpCaps->szPname, capsA.szPname);
692 lpCaps->wTechnology = capsA.wTechnology;
693 lpCaps->wVoices = capsA.wVoices;
694 lpCaps->wNotes = capsA.wNotes;
695 lpCaps->wChannelMask = capsA.wChannelMask;
696 lpCaps->dwSupport = capsA.dwSupport;
698 return dwRet;
701 /**************************************************************************
702 * midiOutGetErrorText [MMSYSTEM.203]
704 UINT16 WINAPI midiOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
706 return midiOutGetErrorTextA(uError, lpText, uSize);
709 /**************************************************************************
710 * midiOutOpen [MMSYSTEM.204]
712 UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID,
713 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
715 HMIDIOUT hmo;
716 UINT ret;
718 ret = MMSYSTEM_midiOutOpen(&hmo, uDeviceID, dwCallback, dwInstance,
719 dwFlags, FALSE);
721 if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo);
722 return ret;
725 /**************************************************************************
726 * midiOutClose [MMSYSTEM.205]
728 UINT16 WINAPI midiOutClose16(HMIDIOUT16 hMidiOut)
730 return midiOutClose(HMIDIOUT_32(hMidiOut));
733 /**************************************************************************
734 * midiOutPrepareHeader [MMSYSTEM.206]
736 UINT16 WINAPI midiOutPrepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
737 SEGPTR lpsegMidiOutHdr, /* [???] */
738 UINT16 uSize) /* [in] */
740 LPWINE_MLD wmld;
742 TRACE("(%04X, %08lx, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
744 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
745 return MMSYSERR_INVALHANDLE;
747 return MMDRV_Message(wmld, MODM_PREPARE, lpsegMidiOutHdr, uSize, FALSE);
750 /**************************************************************************
751 * midiOutUnprepareHeader [MMSYSTEM.207]
753 UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
754 SEGPTR lpsegMidiOutHdr, /* [???] */
755 UINT16 uSize) /* [in] */
757 LPWINE_MLD wmld;
758 LPMIDIHDR16 lpMidiOutHdr = MapSL(lpsegMidiOutHdr);
760 TRACE("(%04X, %08lx, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
762 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
763 return MMSYSERR_NOERROR;
766 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
767 return MMSYSERR_INVALHANDLE;
769 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD)lpsegMidiOutHdr, uSize, FALSE);
772 /**************************************************************************
773 * midiOutShortMsg [MMSYSTEM.208]
775 UINT16 WINAPI midiOutShortMsg16(HMIDIOUT16 hMidiOut, DWORD dwMsg)
777 return midiOutShortMsg(HMIDIOUT_32(hMidiOut), dwMsg);
780 /**************************************************************************
781 * midiOutLongMsg [MMSYSTEM.209]
783 UINT16 WINAPI midiOutLongMsg16(HMIDIOUT16 hMidiOut, /* [in] */
784 LPMIDIHDR16 lpsegMidiOutHdr, /* [???] NOTE: SEGPTR */
785 UINT16 uSize) /* [in] */
787 LPWINE_MLD wmld;
789 TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
791 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
792 return MMSYSERR_INVALHANDLE;
794 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD)lpsegMidiOutHdr, uSize, FALSE);
797 /**************************************************************************
798 * midiOutReset [MMSYSTEM.210]
800 UINT16 WINAPI midiOutReset16(HMIDIOUT16 hMidiOut)
802 return midiOutReset(HMIDIOUT_32(hMidiOut));
805 /**************************************************************************
806 * midiOutGetVolume [MMSYSTEM.211]
808 UINT16 WINAPI midiOutGetVolume16(UINT16 uDeviceID, DWORD* lpdwVolume)
810 return midiOutGetVolume(uDeviceID, lpdwVolume);
813 /**************************************************************************
814 * midiOutSetVolume [MMSYSTEM.212]
816 UINT16 WINAPI midiOutSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
818 return midiOutSetVolume(uDeviceID, dwVolume);
821 /**************************************************************************
822 * midiOutCachePatches [MMSYSTEM.213]
824 UINT16 WINAPI midiOutCachePatches16(HMIDIOUT16 hMidiOut, UINT16 uBank,
825 WORD* lpwPatchArray, UINT16 uFlags)
827 return midiOutCachePatches(HMIDIOUT_32(hMidiOut), uBank, lpwPatchArray,
828 uFlags);
831 /**************************************************************************
832 * midiOutCacheDrumPatches [MMSYSTEM.214]
834 UINT16 WINAPI midiOutCacheDrumPatches16(HMIDIOUT16 hMidiOut, UINT16 uPatch,
835 WORD* lpwKeyArray, UINT16 uFlags)
837 return midiOutCacheDrumPatches(HMIDIOUT_32(hMidiOut), uPatch, lpwKeyArray, uFlags);
840 /**************************************************************************
841 * midiOutGetID [MMSYSTEM.215]
843 UINT16 WINAPI midiOutGetID16(HMIDIOUT16 hMidiOut, UINT16* lpuDeviceID)
845 LPWINE_MLD wmld;
847 TRACE("(%04X, %p)\n", hMidiOut, lpuDeviceID);
849 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
850 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
851 return MMSYSERR_INVALHANDLE;
853 *lpuDeviceID = wmld->uDeviceID;
854 return MMSYSERR_NOERROR;
857 /**************************************************************************
858 * midiOutMessage [MMSYSTEM.216]
860 DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage,
861 DWORD dwParam1, DWORD dwParam2)
863 LPWINE_MLD wmld;
865 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
867 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
868 return MMSYSERR_INVALHANDLE;
870 switch (uMessage) {
871 case MODM_OPEN:
872 case MODM_CLOSE:
873 FIXME("can't handle OPEN or CLOSE message!\n");
874 return MMSYSERR_NOTSUPPORTED;
876 case MODM_GETVOLUME:
877 return midiOutGetVolume16(hMidiOut, MapSL(dwParam1));
878 case MODM_LONGDATA:
879 return midiOutLongMsg16(hMidiOut, MapSL(dwParam1), dwParam2);
880 case MODM_PREPARE:
881 /* lpMidiOutHdr is still a segmented pointer for this function */
882 return midiOutPrepareHeader16(hMidiOut, dwParam1, dwParam2);
883 case MODM_UNPREPARE:
884 return midiOutUnprepareHeader16(hMidiOut, dwParam1, dwParam2);
886 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
889 /**************************************************************************
890 * midiInGetNumDevs [MMSYSTEM.301]
892 UINT16 WINAPI midiInGetNumDevs16(void)
894 return MMDRV_GetNum(MMDRV_MIDIIN);
897 /**************************************************************************
898 * midiInGetDevCaps [MMSYSTEM.302]
900 UINT16 WINAPI midiInGetDevCaps16(UINT16 uDeviceID, LPMIDIINCAPS16 lpCaps,
901 UINT16 uSize)
903 MIDIINCAPSA micA;
904 UINT ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
906 if (ret == MMSYSERR_NOERROR) {
907 lpCaps->wMid = micA.wMid;
908 lpCaps->wPid = micA.wPid;
909 lpCaps->vDriverVersion = micA.vDriverVersion;
910 strcpy(lpCaps->szPname, micA.szPname);
911 lpCaps->dwSupport = micA.dwSupport;
914 return ret;
917 /**************************************************************************
918 * midiInGetErrorText [MMSYSTEM.303]
920 UINT16 WINAPI midiInGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
922 return midiInGetErrorTextA(uError, lpText, uSize);
925 /**************************************************************************
926 * midiInOpen [MMSYSTEM.304]
928 UINT16 WINAPI midiInOpen16(HMIDIIN16* lphMidiIn, UINT16 uDeviceID,
929 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
931 HMIDIIN xhmid;
932 UINT ret;
934 ret = MMSYSTEM_midiInOpen(&xhmid, uDeviceID, dwCallback, dwInstance,
935 dwFlags, FALSE);
937 if (lphMidiIn) *lphMidiIn = HMIDIIN_16(xhmid);
938 return ret;
941 /**************************************************************************
942 * midiInClose [MMSYSTEM.305]
944 UINT16 WINAPI midiInClose16(HMIDIIN16 hMidiIn)
946 return midiInClose(HMIDIIN_32(hMidiIn));
949 /**************************************************************************
950 * midiInPrepareHeader [MMSYSTEM.306]
952 UINT16 WINAPI midiInPrepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
953 SEGPTR lpsegMidiInHdr, /* [???] */
954 UINT16 uSize) /* [in] */
956 LPWINE_MLD wmld;
958 TRACE("(%04X, %08lx, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
960 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
961 return MMSYSERR_INVALHANDLE;
963 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD)lpsegMidiInHdr, uSize, FALSE);
966 /**************************************************************************
967 * midiInUnprepareHeader [MMSYSTEM.307]
969 UINT16 WINAPI midiInUnprepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
970 SEGPTR lpsegMidiInHdr, /* [???] */
971 UINT16 uSize) /* [in] */
973 LPWINE_MLD wmld;
974 LPMIDIHDR16 lpMidiInHdr = MapSL(lpsegMidiInHdr);
976 TRACE("(%04X, %08lx, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
978 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
979 return MMSYSERR_NOERROR;
982 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
983 return MMSYSERR_INVALHANDLE;
985 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD)lpsegMidiInHdr, uSize, FALSE);
988 /**************************************************************************
989 * midiInAddBuffer [MMSYSTEM.308]
991 UINT16 WINAPI midiInAddBuffer16(HMIDIIN16 hMidiIn, /* [in] */
992 MIDIHDR16* lpsegMidiInHdr, /* [???] NOTE: SEGPTR */
993 UINT16 uSize) /* [in] */
995 LPWINE_MLD wmld;
997 TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
999 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1000 return MMSYSERR_INVALHANDLE;
1002 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD)lpsegMidiInHdr, uSize, FALSE);
1005 /**************************************************************************
1006 * midiInStart [MMSYSTEM.309]
1008 UINT16 WINAPI midiInStart16(HMIDIIN16 hMidiIn)
1010 return midiInStart(HMIDIIN_32(hMidiIn));
1013 /**************************************************************************
1014 * midiInStop [MMSYSTEM.310]
1016 UINT16 WINAPI midiInStop16(HMIDIIN16 hMidiIn)
1018 return midiInStop(HMIDIIN_32(hMidiIn));
1021 /**************************************************************************
1022 * midiInReset [MMSYSTEM.311]
1024 UINT16 WINAPI midiInReset16(HMIDIIN16 hMidiIn)
1026 return midiInReset(HMIDIIN_32(hMidiIn));
1029 /**************************************************************************
1030 * midiInGetID [MMSYSTEM.312]
1032 UINT16 WINAPI midiInGetID16(HMIDIIN16 hMidiIn, UINT16* lpuDeviceID)
1034 LPWINE_MLD wmld;
1036 TRACE("(%04X, %p)\n", hMidiIn, lpuDeviceID);
1038 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1040 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, TRUE)) == NULL)
1041 return MMSYSERR_INVALHANDLE;
1043 *lpuDeviceID = wmld->uDeviceID;
1045 return MMSYSERR_NOERROR;
1048 /**************************************************************************
1049 * midiInMessage [MMSYSTEM.313]
1051 DWORD WINAPI midiInMessage16(HMIDIIN16 hMidiIn, UINT16 uMessage,
1052 DWORD dwParam1, DWORD dwParam2)
1054 LPWINE_MLD wmld;
1056 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1058 switch (uMessage) {
1059 case MIDM_OPEN:
1060 case MIDM_CLOSE:
1061 FIXME("can't handle OPEN or CLOSE message!\n");
1062 return MMSYSERR_NOTSUPPORTED;
1064 case MIDM_GETDEVCAPS:
1065 return midiInGetDevCaps16(hMidiIn, MapSL(dwParam1), dwParam2);
1066 case MIDM_PREPARE:
1067 return midiInPrepareHeader16(hMidiIn, dwParam1, dwParam2);
1068 case MIDM_UNPREPARE:
1069 return midiInUnprepareHeader16(hMidiIn, dwParam1, dwParam2);
1070 case MIDM_ADDBUFFER:
1071 return midiInAddBuffer16(hMidiIn, MapSL(dwParam1), dwParam2);
1074 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1075 return MMSYSERR_INVALHANDLE;
1077 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1080 /**************************************************************************
1081 * midiStreamClose [MMSYSTEM.252]
1083 MMRESULT16 WINAPI midiStreamClose16(HMIDISTRM16 hMidiStrm)
1085 return midiStreamClose(HMIDISTRM_32(hMidiStrm));
1088 /**************************************************************************
1089 * midiStreamOpen [MMSYSTEM.251]
1091 MMRESULT16 WINAPI midiStreamOpen16(HMIDISTRM16* phMidiStrm, LPUINT16 devid,
1092 DWORD cMidi, DWORD dwCallback,
1093 DWORD dwInstance, DWORD fdwOpen)
1095 HMIDISTRM hMidiStrm32;
1096 MMRESULT ret;
1097 UINT devid32;
1099 if (!phMidiStrm || !devid)
1100 return MMSYSERR_INVALPARAM;
1101 devid32 = *devid;
1102 ret = MMSYSTEM_MidiStream_Open(&hMidiStrm32, &devid32, cMidi, dwCallback,
1103 dwInstance, fdwOpen, FALSE);
1104 *phMidiStrm = HMIDISTRM_16(hMidiStrm32);
1105 *devid = devid32;
1106 return ret;
1109 /**************************************************************************
1110 * midiStreamOut [MMSYSTEM.254]
1112 MMRESULT16 WINAPI midiStreamOut16(HMIDISTRM16 hMidiStrm, LPMIDIHDR16 lpMidiHdr, UINT16 cbMidiHdr)
1114 return midiStreamOut(HMIDISTRM_32(hMidiStrm), (LPMIDIHDR)lpMidiHdr,
1115 cbMidiHdr);
1118 /**************************************************************************
1119 * midiStreamPause [MMSYSTEM.255]
1121 MMRESULT16 WINAPI midiStreamPause16(HMIDISTRM16 hMidiStrm)
1123 return midiStreamPause(HMIDISTRM_32(hMidiStrm));
1126 /**************************************************************************
1127 * midiStreamPosition [MMSYSTEM.253]
1129 MMRESULT16 WINAPI midiStreamPosition16(HMIDISTRM16 hMidiStrm, LPMMTIME16 lpmmt16, UINT16 cbmmt)
1131 MMTIME mmt32;
1132 MMRESULT ret;
1134 if (!lpmmt16)
1135 return MMSYSERR_INVALPARAM;
1136 MMSYSTEM_MMTIME16to32(&mmt32, lpmmt16);
1137 ret = midiStreamPosition(HMIDISTRM_32(hMidiStrm), &mmt32, sizeof(MMTIME));
1138 MMSYSTEM_MMTIME32to16(lpmmt16, &mmt32);
1139 return ret;
1142 /**************************************************************************
1143 * midiStreamProperty [MMSYSTEM.250]
1145 MMRESULT16 WINAPI midiStreamProperty16(HMIDISTRM16 hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1147 return midiStreamProperty(HMIDISTRM_32(hMidiStrm), lpPropData, dwProperty);
1150 /**************************************************************************
1151 * midiStreamRestart [MMSYSTEM.256]
1153 MMRESULT16 WINAPI midiStreamRestart16(HMIDISTRM16 hMidiStrm)
1155 return midiStreamRestart(HMIDISTRM_32(hMidiStrm));
1158 /**************************************************************************
1159 * midiStreamStop [MMSYSTEM.257]
1161 MMRESULT16 WINAPI midiStreamStop16(HMIDISTRM16 hMidiStrm)
1163 return midiStreamStop(HMIDISTRM_32(hMidiStrm));
1166 /* ###################################################
1167 * # WAVE #
1168 * ###################################################
1171 /**************************************************************************
1172 * waveOutGetNumDevs [MMSYSTEM.401]
1174 UINT16 WINAPI waveOutGetNumDevs16(void)
1176 return MMDRV_GetNum(MMDRV_WAVEOUT);
1179 /**************************************************************************
1180 * waveOutGetDevCaps [MMSYSTEM.402]
1182 UINT16 WINAPI waveOutGetDevCaps16(UINT16 uDeviceID,
1183 LPWAVEOUTCAPS16 lpCaps, UINT16 uSize)
1185 WAVEOUTCAPSA wocA;
1186 UINT ret;
1188 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
1189 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1191 ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
1193 if (ret == MMSYSERR_NOERROR) {
1194 lpCaps->wMid = wocA.wMid;
1195 lpCaps->wPid = wocA.wPid;
1196 lpCaps->vDriverVersion = wocA.vDriverVersion;
1197 strcpy(lpCaps->szPname, wocA.szPname);
1198 lpCaps->dwFormats = wocA.dwFormats;
1199 lpCaps->wChannels = wocA.wChannels;
1200 lpCaps->dwSupport = wocA.dwSupport;
1202 return ret;
1205 /**************************************************************************
1206 * waveOutGetErrorText [MMSYSTEM.403]
1208 UINT16 WINAPI waveOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
1210 return waveOutGetErrorTextA(uError, lpText, uSize);
1213 /**************************************************************************
1214 * waveOutOpen [MMSYSTEM.404]
1216 UINT16 WINAPI waveOutOpen16(HWAVEOUT16* lphWaveOut, UINT16 uDeviceID,
1217 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
1218 DWORD dwInstance, DWORD dwFlags)
1220 HWAVEOUT hWaveOut;
1221 UINT ret;
1223 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1224 * call the 32 bit version
1225 * however, we need to promote correctly the wave mapper id
1226 * (0xFFFFFFFF and not 0x0000FFFF)
1228 ret = MMSYSTEM_waveOpen(&hWaveOut, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1229 MMDRV_WAVEOUT, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1231 if (lphWaveOut != NULL) *lphWaveOut = HWAVEOUT_16(hWaveOut);
1232 return ret;
1235 /**************************************************************************
1236 * waveOutClose [MMSYSTEM.405]
1238 UINT16 WINAPI waveOutClose16(HWAVEOUT16 hWaveOut)
1240 DWORD level;
1241 UINT16 ret;
1243 ReleaseThunkLock(&level);
1244 ret = waveOutClose(HWAVEOUT_32(hWaveOut));
1245 RestoreThunkLock(level);
1246 return ret;
1249 /**************************************************************************
1250 * waveOutPrepareHeader [MMSYSTEM.406]
1252 UINT16 WINAPI waveOutPrepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1253 SEGPTR lpsegWaveOutHdr, /* [???] */
1254 UINT16 uSize) /* [in] */
1256 LPWINE_MLD wmld;
1257 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1259 TRACE("(%04X, %08lx, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1261 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
1263 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1264 return MMSYSERR_INVALHANDLE;
1266 return MMDRV_Message(wmld, WODM_PREPARE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
1269 /**************************************************************************
1270 * waveOutUnprepareHeader [MMSYSTEM.407]
1272 UINT16 WINAPI waveOutUnprepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1273 SEGPTR lpsegWaveOutHdr, /* [???] */
1274 UINT16 uSize) /* [in] */
1276 LPWINE_MLD wmld;
1277 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1279 TRACE("(%04X, %08lx, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1281 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
1282 return MMSYSERR_NOERROR;
1285 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1286 return MMSYSERR_INVALHANDLE;
1288 return MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
1291 /**************************************************************************
1292 * waveOutWrite [MMSYSTEM.408]
1294 UINT16 WINAPI waveOutWrite16(HWAVEOUT16 hWaveOut, /* [in] */
1295 LPWAVEHDR lpsegWaveOutHdr, /* [???] NOTE: SEGPTR */
1296 UINT16 uSize) /* [in] */
1298 LPWINE_MLD wmld;
1300 TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1302 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1303 return MMSYSERR_INVALHANDLE;
1305 return MMDRV_Message(wmld, WODM_WRITE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
1308 /**************************************************************************
1309 * waveOutBreakLoop [MMSYSTEM.419]
1311 UINT16 WINAPI waveOutBreakLoop16(HWAVEOUT16 hWaveOut16)
1313 DWORD level;
1314 UINT16 ret;
1316 ReleaseThunkLock(&level);
1317 ret = waveOutBreakLoop(HWAVEOUT_32(hWaveOut16));
1318 RestoreThunkLock(level);
1319 return ret;
1322 /**************************************************************************
1323 * waveOutPause [MMSYSTEM.409]
1325 UINT16 WINAPI waveOutPause16(HWAVEOUT16 hWaveOut16)
1327 DWORD level;
1328 UINT16 ret;
1330 ReleaseThunkLock(&level);
1331 ret = waveOutPause(HWAVEOUT_32(hWaveOut16));
1332 RestoreThunkLock(level);
1333 return ret;
1336 /**************************************************************************
1337 * waveOutReset [MMSYSTEM.411]
1339 UINT16 WINAPI waveOutReset16(HWAVEOUT16 hWaveOut16)
1341 DWORD level;
1342 UINT16 ret;
1344 ReleaseThunkLock(&level);
1345 ret = waveOutReset(HWAVEOUT_32(hWaveOut16));
1346 RestoreThunkLock(level);
1347 return ret;
1350 /**************************************************************************
1351 * waveOutRestart [MMSYSTEM.410]
1353 UINT16 WINAPI waveOutRestart16(HWAVEOUT16 hWaveOut16)
1355 DWORD level;
1356 UINT16 ret;
1358 ReleaseThunkLock(&level);
1359 ret = waveOutRestart(HWAVEOUT_32(hWaveOut16));
1360 RestoreThunkLock(level);
1361 return ret;
1364 /**************************************************************************
1365 * waveOutGetPosition [MMSYSTEM.412]
1367 UINT16 WINAPI waveOutGetPosition16(HWAVEOUT16 hWaveOut, LPMMTIME16 lpTime,
1368 UINT16 uSize)
1370 UINT ret;
1371 MMTIME mmt;
1373 mmt.wType = lpTime->wType;
1374 ret = waveOutGetPosition(HWAVEOUT_32(hWaveOut), &mmt, sizeof(mmt));
1375 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1376 return ret;
1379 /**************************************************************************
1380 * waveOutGetPitch [MMSYSTEM.413]
1382 UINT16 WINAPI waveOutGetPitch16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1384 return waveOutGetPitch(HWAVEOUT_32(hWaveOut16), lpdw);
1387 /**************************************************************************
1388 * waveOutSetPitch [MMSYSTEM.414]
1390 UINT16 WINAPI waveOutSetPitch16(HWAVEOUT16 hWaveOut16, DWORD dw)
1392 return waveOutSetPitch(HWAVEOUT_32(hWaveOut16), dw);
1395 /**************************************************************************
1396 * waveOutGetPlaybackRate [MMSYSTEM.417]
1398 UINT16 WINAPI waveOutGetPlaybackRate16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1400 return waveOutGetPlaybackRate(HWAVEOUT_32(hWaveOut16), lpdw);
1403 /**************************************************************************
1404 * waveOutSetPlaybackRate [MMSYSTEM.418]
1406 UINT16 WINAPI waveOutSetPlaybackRate16(HWAVEOUT16 hWaveOut16, DWORD dw)
1408 return waveOutSetPlaybackRate(HWAVEOUT_32(hWaveOut16), dw);
1411 /**************************************************************************
1412 * waveOutGetVolume [MMSYSTEM.415]
1414 UINT16 WINAPI waveOutGetVolume16(UINT16 devid, LPDWORD lpdw)
1416 return waveOutGetVolume(devid, lpdw);
1419 /**************************************************************************
1420 * waveOutSetVolume [MMSYSTEM.416]
1422 UINT16 WINAPI waveOutSetVolume16(UINT16 devid, DWORD dw)
1424 return waveOutSetVolume(devid, dw);
1427 /**************************************************************************
1428 * waveOutGetID [MMSYSTEM.420]
1430 UINT16 WINAPI waveOutGetID16(HWAVEOUT16 hWaveOut, UINT16* lpuDeviceID)
1432 LPWINE_MLD wmld;
1434 TRACE("(%04X, %p);\n", hWaveOut, lpuDeviceID);
1436 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1438 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1439 return MMSYSERR_INVALHANDLE;
1441 *lpuDeviceID = wmld->uDeviceID;
1442 return 0;
1445 /**************************************************************************
1446 * waveOutMessage [MMSYSTEM.421]
1448 DWORD WINAPI waveOutMessage16(HWAVEOUT16 hWaveOut, UINT16 uMessage,
1449 DWORD dwParam1, DWORD dwParam2)
1451 LPWINE_MLD wmld;
1453 TRACE("(%04x, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
1455 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL) {
1456 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, TRUE)) != NULL) {
1457 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1459 return MMSYSERR_INVALHANDLE;
1462 /* from M$ KB */
1463 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1464 return MMSYSERR_INVALPARAM;
1466 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1469 /**************************************************************************
1470 * waveInGetNumDevs [MMSYSTEM.501]
1472 UINT16 WINAPI waveInGetNumDevs16(void)
1474 return MMDRV_GetNum(MMDRV_WAVEIN);
1477 /**************************************************************************
1478 * waveInGetDevCaps [MMSYSTEM.502]
1480 UINT16 WINAPI waveInGetDevCaps16(UINT16 uDeviceID, LPWAVEINCAPS16 lpCaps,
1481 UINT16 uSize)
1483 WAVEINCAPSA wicA;
1484 UINT ret = waveInGetDevCapsA(uDeviceID, &wicA, sizeof(wicA));
1486 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1488 if (ret == MMSYSERR_NOERROR) {
1489 lpCaps->wMid = wicA.wMid;
1490 lpCaps->wPid = wicA.wPid;
1491 lpCaps->vDriverVersion = wicA.vDriverVersion;
1492 strcpy(lpCaps->szPname, wicA.szPname);
1493 lpCaps->dwFormats = wicA.dwFormats;
1494 lpCaps->wChannels = wicA.wChannels;
1496 return ret;
1499 /**************************************************************************
1500 * waveInGetErrorText [MMSYSTEM.503]
1502 UINT16 WINAPI waveInGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
1504 return waveInGetErrorTextA(uError, lpText, uSize);
1507 /**************************************************************************
1508 * waveInOpen [MMSYSTEM.504]
1510 UINT16 WINAPI waveInOpen16(HWAVEIN16* lphWaveIn, UINT16 uDeviceID,
1511 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
1512 DWORD dwInstance, DWORD dwFlags)
1514 HWAVEIN hWaveIn;
1515 UINT ret;
1517 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1518 * call the 32 bit version
1519 * however, we need to promote correctly the wave mapper id
1520 * (0xFFFFFFFF and not 0x0000FFFF)
1522 ret = MMSYSTEM_waveOpen(&hWaveIn, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1523 MMDRV_WAVEIN, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1525 if (lphWaveIn != NULL) *lphWaveIn = HWAVEIN_16(hWaveIn);
1526 return ret;
1529 /**************************************************************************
1530 * waveInClose [MMSYSTEM.505]
1532 UINT16 WINAPI waveInClose16(HWAVEIN16 hWaveIn)
1534 DWORD level;
1535 UINT16 ret;
1537 ReleaseThunkLock(&level);
1538 ret = waveInClose(HWAVEIN_32(hWaveIn));
1539 RestoreThunkLock(level);
1540 return ret;
1543 /**************************************************************************
1544 * waveInPrepareHeader [MMSYSTEM.506]
1546 UINT16 WINAPI waveInPrepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1547 SEGPTR lpsegWaveInHdr, /* [???] */
1548 UINT16 uSize) /* [in] */
1550 LPWINE_MLD wmld;
1551 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1552 UINT16 ret;
1554 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
1556 if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
1557 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1558 return MMSYSERR_INVALHANDLE;
1560 lpWaveInHdr->dwBytesRecorded = 0;
1562 ret = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD)lpsegWaveInHdr, uSize, FALSE);
1563 return ret;
1566 /**************************************************************************
1567 * waveInUnprepareHeader [MMSYSTEM.507]
1569 UINT16 WINAPI waveInUnprepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1570 SEGPTR lpsegWaveInHdr, /* [???] */
1571 UINT16 uSize) /* [in] */
1573 LPWINE_MLD wmld;
1574 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1576 TRACE("(%04X, %08lx, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1578 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1580 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
1581 return MMSYSERR_NOERROR;
1584 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1585 return MMSYSERR_INVALHANDLE;
1587 return MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD)lpsegWaveInHdr, uSize, FALSE);
1590 /**************************************************************************
1591 * waveInAddBuffer [MMSYSTEM.508]
1593 UINT16 WINAPI waveInAddBuffer16(HWAVEIN16 hWaveIn, /* [in] */
1594 WAVEHDR* lpsegWaveInHdr, /* [???] NOTE: SEGPTR */
1595 UINT16 uSize) /* [in] */
1597 LPWINE_MLD wmld;
1599 TRACE("(%04X, %p, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1601 if (lpsegWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1602 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1603 return MMSYSERR_INVALHANDLE;
1605 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD)lpsegWaveInHdr, uSize, FALSE);
1608 /**************************************************************************
1609 * waveInReset [MMSYSTEM.511]
1611 UINT16 WINAPI waveInReset16(HWAVEIN16 hWaveIn16)
1613 DWORD level;
1614 UINT16 ret;
1616 ReleaseThunkLock(&level);
1617 ret = waveInReset(HWAVEIN_32(hWaveIn16));
1618 RestoreThunkLock(level);
1619 return ret;
1622 /**************************************************************************
1623 * waveInStart [MMSYSTEM.509]
1625 UINT16 WINAPI waveInStart16(HWAVEIN16 hWaveIn16)
1627 DWORD level;
1628 UINT16 ret;
1630 ReleaseThunkLock(&level);
1631 ret = waveInStart(HWAVEIN_32(hWaveIn16));
1632 RestoreThunkLock(level);
1633 return ret;
1636 /**************************************************************************
1637 * waveInStop [MMSYSTEM.510]
1639 UINT16 WINAPI waveInStop16(HWAVEIN16 hWaveIn16)
1641 DWORD level;
1642 UINT16 ret;
1644 ReleaseThunkLock(&level);
1645 ret = waveInStop(HWAVEIN_32(hWaveIn16));
1646 RestoreThunkLock(level);
1647 return ret;
1650 /**************************************************************************
1651 * waveInGetPosition [MMSYSTEM.512]
1653 UINT16 WINAPI waveInGetPosition16(HWAVEIN16 hWaveIn, LPMMTIME16 lpTime,
1654 UINT16 uSize)
1656 UINT ret;
1657 MMTIME mmt;
1659 mmt.wType = lpTime->wType;
1660 ret = waveInGetPosition(HWAVEIN_32(hWaveIn), &mmt, sizeof(mmt));
1661 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1662 return ret;
1665 /**************************************************************************
1666 * waveInGetID [MMSYSTEM.513]
1668 UINT16 WINAPI waveInGetID16(HWAVEIN16 hWaveIn, UINT16* lpuDeviceID)
1670 LPWINE_MLD wmld;
1672 TRACE("(%04X, %p);\n", hWaveIn, lpuDeviceID);
1674 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1676 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1677 return MMSYSERR_INVALHANDLE;
1679 *lpuDeviceID = wmld->uDeviceID;
1680 return MMSYSERR_NOERROR;
1683 /**************************************************************************
1684 * waveInMessage [MMSYSTEM.514]
1686 DWORD WINAPI waveInMessage16(HWAVEIN16 hWaveIn, UINT16 uMessage,
1687 DWORD dwParam1, DWORD dwParam2)
1689 LPWINE_MLD wmld;
1691 TRACE("(%04x, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
1693 /* from M$ KB */
1694 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1695 return MMSYSERR_INVALPARAM;
1697 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1698 return MMSYSERR_INVALHANDLE;
1700 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1703 /* ###################################################
1704 * # TASK #
1705 * ###################################################
1708 /*#define USE_MM_TSK_WINE*/
1710 /**************************************************************************
1711 * mmTaskCreate [MMSYSTEM.900]
1713 * Creates a 16 bit MM task. It's entry point is lpFunc, and it should be
1714 * called upon creation with dwPmt as parameter.
1716 HINSTANCE16 WINAPI mmTaskCreate16(SEGPTR spProc, HINSTANCE16 *lphMmTask, DWORD dwPmt)
1718 HINSTANCE16 ret;
1719 HINSTANCE16 handle;
1720 char cmdline[16];
1721 DWORD showCmd = 0x40002;
1722 LOADPARAMS16 lp;
1724 TRACE("(%08lx, %p, %08lx);\n", spProc, lphMmTask, dwPmt);
1725 /* This to work requires NE modules to be started with a binary command line
1726 * which is not currently the case. A patch exists but has never been committed.
1727 * A workaround would be to integrate code for mmtask.tsk into Wine, but
1728 * this requires tremendous work (starting with patching tools/build to
1729 * create NE executables (and not only DLLs) for builtins modules.
1730 * EP 99/04/25
1732 FIXME("This is currently broken. It will fail\n");
1734 cmdline[0] = 0x0d;
1735 *(LPDWORD)(cmdline + 1) = (DWORD)spProc;
1736 *(LPDWORD)(cmdline + 5) = dwPmt;
1737 *(LPDWORD)(cmdline + 9) = 0;
1739 lp.hEnvironment = 0;
1740 lp.cmdLine = MapLS(cmdline);
1741 lp.showCmd = MapLS(&showCmd);
1742 lp.reserved = 0;
1744 #ifndef USE_MM_TSK_WINE
1745 handle = LoadModule16("c:\\windows\\system\\mmtask.tsk", &lp);
1746 #else
1747 handle = LoadModule16("mmtask.tsk", &lp);
1748 #endif
1749 if (handle < 32) {
1750 ret = (handle) ? 1 : 2;
1751 handle = 0;
1752 } else {
1753 ret = 0;
1755 if (lphMmTask)
1756 *lphMmTask = handle;
1758 UnMapLS( lp.cmdLine );
1759 UnMapLS( lp.showCmd );
1760 TRACE("=> 0x%04x/%d\n", handle, ret);
1761 return ret;
1764 #ifdef USE_MM_TSK_WINE
1765 /* C equivalent to mmtask.tsk binary content */
1766 void mmTaskEntryPoint16(LPSTR cmdLine, WORD di, WORD si)
1768 int len = cmdLine[0x80];
1770 if (len / 2 == 6) {
1771 void (*fpProc)(DWORD) = MapSL(*((DWORD*)(cmdLine + 1)));
1772 DWORD dwPmt = *((DWORD*)(cmdLine + 5));
1774 #if 0
1775 InitTask16(); /* FIXME: pmts / from context ? */
1776 InitApp(di);
1777 #endif
1778 if (SetMessageQueue16(0x40)) {
1779 WaitEvent16(0);
1780 if (HIWORD(fpProc)) {
1781 OldYield16();
1782 /* EPP StackEnter16(); */
1783 (fpProc)(dwPmt);
1787 OldYield16();
1788 OldYield16();
1789 OldYield16();
1790 ExitProcess(0);
1792 #endif
1794 /**************************************************************************
1795 * mmTaskBlock [MMSYSTEM.902]
1797 void WINAPI mmTaskBlock16(HINSTANCE16 WINE_UNUSED hInst)
1799 MSG msg;
1801 do {
1802 GetMessageA(&msg, 0, 0, 0);
1803 if (msg.hwnd) {
1804 TranslateMessage(&msg);
1805 DispatchMessageA(&msg);
1807 } while (msg.message < 0x3A0);
1810 /**************************************************************************
1811 * mmTaskSignal [MMSYSTEM.903]
1813 LRESULT WINAPI mmTaskSignal16(HTASK16 ht)
1815 TRACE("(%04x);\n", ht);
1816 return PostAppMessage16(ht, WM_USER, 0, 0);
1819 /**************************************************************************
1820 * mmGetCurrentTask [MMSYSTEM.904]
1822 HTASK16 WINAPI mmGetCurrentTask16(void)
1824 return GetCurrentTask();
1827 /**************************************************************************
1828 * mmTaskYield [MMSYSTEM.905]
1830 void WINAPI mmTaskYield16(void)
1832 MSG msg;
1834 if (PeekMessageA(&msg, 0, 0, 0, 0)) {
1835 K32WOWYield16();
1839 extern DWORD WINAPI GetProcessFlags(DWORD);
1841 /******************************************************************
1842 * WINMM_GetmmThread
1846 static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16 h)
1848 return (WINE_MMTHREAD*)MapSL( MAKESEGPTR(h, 0) );
1851 void WINAPI WINE_mmThreadEntryPoint(DWORD);
1853 /**************************************************************************
1854 * mmThreadCreate [MMSYSTEM.1120]
1856 * undocumented
1857 * Creates a MM thread, calling fpThreadAddr(dwPmt).
1858 * dwFlags:
1859 * bit.0 set means create a 16 bit task instead of thread calling a 16 bit proc
1860 * bit.1 set means to open a VxD for this thread (unsupported)
1862 LRESULT WINAPI mmThreadCreate16(FARPROC16 fpThreadAddr, LPHANDLE lpHndl, DWORD dwPmt, DWORD dwFlags)
1864 HANDLE16 hndl;
1865 LRESULT ret;
1867 TRACE("(%p, %p, %08lx, %08lx)!\n", fpThreadAddr, lpHndl, dwPmt, dwFlags);
1869 hndl = GlobalAlloc16(sizeof(WINE_MMTHREAD), GMEM_SHARE|GMEM_ZEROINIT);
1871 if (hndl == 0) {
1872 ret = 2;
1873 } else {
1874 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
1876 #if 0
1877 /* force mmtask routines even if mmthread is required */
1878 /* this will work only if the patch about binary cmd line and NE tasks
1879 * is committed
1881 dwFlags |= 1;
1882 #endif
1884 lpMMThd->dwSignature = WINE_MMTHREAD_CREATED;
1885 lpMMThd->dwCounter = 0;
1886 lpMMThd->hThread = 0;
1887 lpMMThd->dwThreadID = 0;
1888 lpMMThd->fpThread = fpThreadAddr;
1889 lpMMThd->dwThreadPmt = dwPmt;
1890 lpMMThd->dwSignalCount = 0;
1891 lpMMThd->hEvent = 0;
1892 lpMMThd->hVxD = 0;
1893 lpMMThd->dwStatus = 0;
1894 lpMMThd->dwFlags = dwFlags;
1895 lpMMThd->hTask = 0;
1897 if ((dwFlags & 1) == 0 && (GetProcessFlags(GetCurrentThreadId()) & 8) == 0) {
1898 lpMMThd->hEvent = CreateEventA(0, 0, 1, 0);
1900 TRACE("Let's go crazy... trying new MM thread. lpMMThd=%p\n", lpMMThd);
1901 if (lpMMThd->dwFlags & 2) {
1902 /* as long as we don't support MM VxD in wine, we don't need
1903 * to care about this flag
1905 /* FIXME("Don't know how to properly open VxD handles\n"); */
1906 /* lpMMThd->hVxD = OpenVxDHandle(lpMMThd->hEvent); */
1909 lpMMThd->hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)WINE_mmThreadEntryPoint,
1910 (LPVOID)(DWORD)hndl, CREATE_SUSPENDED, &lpMMThd->dwThreadID);
1911 if (lpMMThd->hThread == 0) {
1912 WARN("Couldn't create thread\n");
1913 /* clean-up(VxDhandle...); devicedirectio... */
1914 if (lpMMThd->hEvent != 0)
1915 CloseHandle(lpMMThd->hEvent);
1916 ret = 2;
1917 } else {
1918 TRACE("Got a nice thread hndl=0x%04x id=0x%08lx\n", lpMMThd->hThread, lpMMThd->dwThreadID);
1919 ret = 0;
1921 } else {
1922 /* get WINE_mmThreadEntryPoint()
1923 * 2047 is its ordinal in mmsystem.spec
1925 FARPROC16 fp = GetProcAddress16(GetModuleHandle16("MMSYSTEM"), (LPCSTR)2047);
1927 TRACE("farproc seg=0x%08lx lin=%p\n", (DWORD)fp, MapSL((SEGPTR)fp));
1929 ret = (fp == 0) ? 2 : mmTaskCreate16((DWORD)fp, 0, hndl);
1932 if (ret == 0) {
1933 if (lpMMThd->hThread && !ResumeThread(lpMMThd->hThread))
1934 WARN("Couldn't resume thread\n");
1936 while (lpMMThd->dwStatus != 0x10) { /* test also HIWORD of dwStatus */
1937 UserYield16();
1942 if (ret != 0) {
1943 GlobalFree16(hndl);
1944 hndl = 0;
1947 if (lpHndl)
1948 *lpHndl = hndl;
1950 TRACE("ok => %ld\n", ret);
1951 return ret;
1954 /**************************************************************************
1955 * mmThreadSignal [MMSYSTEM.1121]
1957 void WINAPI mmThreadSignal16(HANDLE16 hndl)
1959 TRACE("(%04x)!\n", hndl);
1961 if (hndl) {
1962 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
1964 lpMMThd->dwCounter++;
1965 if (lpMMThd->hThread != 0) {
1966 InterlockedIncrement(&lpMMThd->dwSignalCount);
1967 SetEvent(lpMMThd->hEvent);
1968 } else {
1969 mmTaskSignal16(lpMMThd->hTask);
1971 lpMMThd->dwCounter--;
1975 static void MMSYSTEM_ThreadBlock(WINE_MMTHREAD* lpMMThd)
1977 MSG msg;
1978 DWORD ret;
1980 if (lpMMThd->dwThreadID != GetCurrentThreadId())
1981 ERR("Not called by thread itself\n");
1983 for (;;) {
1984 ResetEvent(lpMMThd->hEvent);
1985 if (InterlockedDecrement(&lpMMThd->dwSignalCount) >= 0)
1986 break;
1987 InterlockedIncrement(&lpMMThd->dwSignalCount);
1989 TRACE("S1\n");
1991 ret = MsgWaitForMultipleObjects(1, &lpMMThd->hEvent, FALSE, INFINITE, QS_ALLINPUT);
1992 switch (ret) {
1993 case WAIT_OBJECT_0: /* Event */
1994 TRACE("S2.1\n");
1995 break;
1996 case WAIT_OBJECT_0 + 1: /* Msg */
1997 TRACE("S2.2\n");
1998 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1999 TranslateMessage(&msg);
2000 DispatchMessageA(&msg);
2002 break;
2003 default:
2004 WARN("S2.x unsupported ret val 0x%08lx\n", ret);
2006 TRACE("S3\n");
2010 /**************************************************************************
2011 * mmThreadBlock [MMSYSTEM.1122]
2013 void WINAPI mmThreadBlock16(HANDLE16 hndl)
2015 TRACE("(%04x)!\n", hndl);
2017 if (hndl) {
2018 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2020 if (lpMMThd->hThread != 0) {
2021 DWORD lc;
2023 ReleaseThunkLock(&lc);
2024 MMSYSTEM_ThreadBlock(lpMMThd);
2025 RestoreThunkLock(lc);
2026 } else {
2027 mmTaskBlock16(lpMMThd->hTask);
2030 TRACE("done\n");
2033 /**************************************************************************
2034 * mmThreadIsCurrent [MMSYSTEM.1123]
2036 BOOL16 WINAPI mmThreadIsCurrent16(HANDLE16 hndl)
2038 BOOL16 ret = FALSE;
2040 TRACE("(%04x)!\n", hndl);
2042 if (hndl && mmThreadIsValid16(hndl)) {
2043 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2044 ret = (GetCurrentThreadId() == lpMMThd->dwThreadID);
2046 TRACE("=> %d\n", ret);
2047 return ret;
2050 /**************************************************************************
2051 * mmThreadIsValid [MMSYSTEM.1124]
2053 BOOL16 WINAPI mmThreadIsValid16(HANDLE16 hndl)
2055 BOOL16 ret = FALSE;
2057 TRACE("(%04x)!\n", hndl);
2059 if (hndl) {
2060 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2062 if (!IsBadWritePtr(lpMMThd, sizeof(WINE_MMTHREAD)) &&
2063 lpMMThd->dwSignature == WINE_MMTHREAD_CREATED &&
2064 IsTask16(lpMMThd->hTask)) {
2065 lpMMThd->dwCounter++;
2066 if (lpMMThd->hThread != 0) {
2067 DWORD dwThreadRet;
2068 if (GetExitCodeThread(lpMMThd->hThread, &dwThreadRet) &&
2069 dwThreadRet == STATUS_PENDING) {
2070 ret = TRUE;
2072 } else {
2073 ret = TRUE;
2075 lpMMThd->dwCounter--;
2078 TRACE("=> %d\n", ret);
2079 return ret;
2082 /**************************************************************************
2083 * mmThreadGetTask [MMSYSTEM.1125]
2085 HANDLE16 WINAPI mmThreadGetTask16(HANDLE16 hndl)
2087 HANDLE16 ret = 0;
2089 TRACE("(%04x)\n", hndl);
2091 if (mmThreadIsValid16(hndl)) {
2092 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2093 ret = lpMMThd->hTask;
2095 return ret;
2098 /**************************************************************************
2099 * WINE_mmThreadEntryPoint (MMSYSTEM.2047)
2101 void WINAPI WINE_mmThreadEntryPoint(DWORD _pmt)
2103 HANDLE16 hndl = (HANDLE16)_pmt;
2104 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2106 TRACE("(%04x %p)\n", hndl, lpMMThd);
2108 lpMMThd->hTask = LOWORD(GetCurrentTask());
2109 TRACE("[10-%08x] setting hTask to 0x%08x\n", lpMMThd->hThread, lpMMThd->hTask);
2110 lpMMThd->dwStatus = 0x10;
2111 MMSYSTEM_ThreadBlock(lpMMThd);
2112 TRACE("[20-%08x]\n", lpMMThd->hThread);
2113 lpMMThd->dwStatus = 0x20;
2114 if (lpMMThd->fpThread) {
2115 MMSYSTEM_CallTo16_long_l(lpMMThd->fpThread, lpMMThd->dwThreadPmt);
2117 lpMMThd->dwStatus = 0x30;
2118 TRACE("[30-%08x]\n", lpMMThd->hThread);
2119 while (lpMMThd->dwCounter) {
2120 Sleep(1);
2121 /* K32WOWYield16();*/
2123 TRACE("[XX-%08x]\n", lpMMThd->hThread);
2124 /* paranoia */
2125 lpMMThd->dwSignature = WINE_MMTHREAD_DELETED;
2126 /* close lpMMThread->hVxD directIO */
2127 if (lpMMThd->hEvent)
2128 CloseHandle(lpMMThd->hEvent);
2129 GlobalFree16(hndl);
2130 TRACE("done\n");
2133 typedef BOOL16 (WINAPI *MMCPLCALLBACK)(HWND, LPCSTR, LPCSTR, LPCSTR);
2135 /**************************************************************************
2136 * mmShowMMCPLPropertySheet [MMSYSTEM.1150]
2138 BOOL16 WINAPI mmShowMMCPLPropertySheet16(HWND hWnd, LPCSTR lpStrDevice,
2139 LPCSTR lpStrTab, LPCSTR lpStrTitle)
2141 HANDLE hndl;
2142 BOOL16 ret = FALSE;
2144 TRACE("(%04x \"%s\" \"%s\" \"%s\")\n", hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2146 hndl = LoadLibraryA("MMSYS.CPL");
2147 if (hndl != 0) {
2148 MMCPLCALLBACK fp = (MMCPLCALLBACK)GetProcAddress(hndl, "ShowMMCPLPropertySheet");
2149 if (fp != NULL) {
2150 DWORD lc;
2151 ReleaseThunkLock(&lc);
2152 ret = (fp)(hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2153 RestoreThunkLock(lc);
2155 FreeLibrary(hndl);
2158 return ret;
2161 /**************************************************************************
2162 * StackEnter [MMSYSTEM.32]
2164 void WINAPI StackEnter16(void)
2166 #ifdef __i386__
2167 /* mmsystem.dll from Win 95 does only this: so does Wine */
2168 __asm__("stc");
2169 #endif
2172 /**************************************************************************
2173 * StackLeave [MMSYSTEM.33]
2175 void WINAPI StackLeave16(void)
2177 #ifdef __i386__
2178 /* mmsystem.dll from Win 95 does only this: so does Wine */
2179 __asm__("stc");
2180 #endif
2183 /**************************************************************************
2184 * WMMMidiRunOnce [MMSYSTEM.8]
2186 void WINAPI WMMMidiRunOnce16(void)
2188 FIXME("(), stub!\n");
2191 /* ###################################################
2192 * # DRIVER #
2193 * ###################################################
2196 /**************************************************************************
2197 * DRIVER_MapMsg32To16 [internal]
2199 * Map a 32 bit driver message to a 16 bit driver message.
2201 static WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
2203 WINMM_MapType ret = WINMM_MAP_MSGERROR;
2205 switch (wMsg) {
2206 case DRV_LOAD:
2207 case DRV_ENABLE:
2208 case DRV_DISABLE:
2209 case DRV_FREE:
2210 case DRV_QUERYCONFIGURE:
2211 case DRV_REMOVE:
2212 case DRV_EXITSESSION:
2213 case DRV_EXITAPPLICATION:
2214 case DRV_POWER:
2215 case DRV_CLOSE: /* should be 0/0 */
2216 case DRV_OPEN: /* pass through */
2217 /* lParam1 and lParam2 are not used */
2218 ret = WINMM_MAP_OK;
2219 break;
2220 case DRV_CONFIGURE:
2221 case DRV_INSTALL:
2222 /* lParam1 is a handle to a window (conf) or to a driver (inst) or not used,
2223 * lParam2 is a pointer to DRVCONFIGINFO
2225 if (*lParam2) {
2226 LPDRVCONFIGINFO16 dci16 = HeapAlloc( GetProcessHeap(), 0, sizeof(*dci16) );
2227 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2);
2229 if (dci16) {
2230 LPSTR str1;
2232 dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
2234 if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCISectionName)) != NULL)
2236 dci16->lpszDCISectionName = MapLS( str1 );
2237 } else {
2238 return WINMM_MAP_NOMEM;
2240 if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCIAliasName)) != NULL)
2242 dci16->lpszDCIAliasName = MapLS( str1 );
2243 } else {
2244 return WINMM_MAP_NOMEM;
2246 } else {
2247 return WINMM_MAP_NOMEM;
2249 *lParam2 = MapLS( dci16 );
2250 ret = WINMM_MAP_OKMEM;
2251 } else {
2252 ret = WINMM_MAP_OK;
2254 break;
2255 default:
2256 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2257 FIXME("Unknown message 0x%04x\n", wMsg);
2259 ret = WINMM_MAP_OK;
2261 return ret;
2264 /**************************************************************************
2265 * DRIVER_UnMapMsg32To16 [internal]
2267 * UnMap a 32 bit driver message to a 16 bit driver message.
2269 static WINMM_MapType DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
2271 WINMM_MapType ret = WINMM_MAP_MSGERROR;
2273 switch (wMsg) {
2274 case DRV_LOAD:
2275 case DRV_ENABLE:
2276 case DRV_DISABLE:
2277 case DRV_FREE:
2278 case DRV_QUERYCONFIGURE:
2279 case DRV_REMOVE:
2280 case DRV_EXITSESSION:
2281 case DRV_EXITAPPLICATION:
2282 case DRV_POWER:
2283 case DRV_OPEN:
2284 case DRV_CLOSE:
2285 /* lParam1 and lParam2 are not used */
2286 break;
2287 case DRV_CONFIGURE:
2288 case DRV_INSTALL:
2289 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
2290 if (lParam2) {
2291 LPDRVCONFIGINFO16 dci16 = MapSL(lParam2);
2292 HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCISectionName) );
2293 HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCIAliasName) );
2294 UnMapLS( lParam2 );
2295 UnMapLS( dci16->lpszDCISectionName );
2296 UnMapLS( dci16->lpszDCIAliasName );
2297 HeapFree( GetProcessHeap(), 0, dci16 );
2299 ret = WINMM_MAP_OK;
2300 break;
2301 default:
2302 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2303 FIXME("Unknown message 0x%04x\n", wMsg);
2305 ret = WINMM_MAP_OK;
2307 return ret;
2310 /**************************************************************************
2311 * DRIVER_TryOpenDriver16 [internal]
2313 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
2315 static LPWINE_DRIVER DRIVER_OpenDriver16(LPCSTR fn, LPCSTR sn, LPARAM lParam2)
2317 LPWINE_DRIVER lpDrv = NULL;
2318 LPCSTR cause = 0;
2320 TRACE("(%s, %08lX);\n", debugstr_a(sn), lParam2);
2322 lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
2323 if (lpDrv == NULL) {cause = "OOM"; goto exit;}
2325 /* FIXME: shall we do some black magic here on sn ?
2326 * drivers32 => drivers
2327 * mci32 => mci
2328 * ...
2330 lpDrv->d.d16.hDriver16 = OpenDriver16(fn, sn, lParam2);
2331 if (lpDrv->d.d16.hDriver16 == 0) {cause = "Not a 16 bit driver"; goto exit;}
2332 lpDrv->dwFlags = WINE_GDF_16BIT;
2334 TRACE("=> %p\n", lpDrv);
2335 return lpDrv;
2336 exit:
2337 HeapFree(GetProcessHeap(), 0, lpDrv);
2338 TRACE("Unable to load 16 bit module %s: %s\n", debugstr_a(fn), cause);
2339 return NULL;
2342 /******************************************************************
2343 * DRIVER_SendMessage16
2347 static LRESULT DRIVER_SendMessage16(HDRVR16 hDrv16, UINT msg,
2348 LPARAM lParam1, LPARAM lParam2)
2350 LRESULT ret = 0;
2351 WINMM_MapType map;
2353 TRACE("Before sdm16 call hDrv=%04x wMsg=%04x p1=%08lx p2=%08lx\n",
2354 hDrv16, msg, lParam1, lParam2);
2356 switch (map = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2)) {
2357 case WINMM_MAP_OKMEM:
2358 case WINMM_MAP_OK:
2359 ret = SendDriverMessage16(hDrv16, msg, lParam1, lParam2);
2360 if (map == WINMM_MAP_OKMEM)
2361 DRIVER_UnMapMsg32To16(msg, lParam1, lParam2);
2362 default:
2363 break;
2365 return ret;
2368 /******************************************************************
2369 * DRIVER_CloseDriver16
2373 static LRESULT DRIVER_CloseDriver16(HDRVR16 hDrv16, LPARAM lParam1, LPARAM lParam2)
2375 return CloseDriver16(hDrv16, lParam1, lParam2);
2378 /**************************************************************************
2379 * DrvOpen [MMSYSTEM.1100]
2381 HDRVR16 WINAPI DrvOpen16(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
2383 return OpenDriver16(lpDriverName, lpSectionName, lParam);
2386 /**************************************************************************
2387 * DrvClose [MMSYSTEM.1101]
2389 LRESULT WINAPI DrvClose16(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
2391 return CloseDriver16(hDrv, lParam1, lParam2);
2394 /**************************************************************************
2395 * DrvSendMessage [MMSYSTEM.1102]
2397 LRESULT WINAPI DrvSendMessage16(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
2398 LPARAM lParam2)
2400 return SendDriverMessage16(hDrv, msg, lParam1, lParam2);
2403 /**************************************************************************
2404 * DrvGetModuleHandle [MMSYSTEM.1103]
2406 HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
2408 return GetDriverModuleHandle16(hDrv);
2411 /**************************************************************************
2412 * DrvDefDriverProc [MMSYSTEM.1104]
2414 LRESULT WINAPI DrvDefDriverProc16(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg,
2415 DWORD dwParam1, DWORD dwParam2)
2417 return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
2420 /**************************************************************************
2421 * DriverProc [MMSYSTEM.6]
2423 LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
2424 DWORD dwParam1, DWORD dwParam2)
2426 TRACE("dwDevID=%08lx hDrv=%04x wMsg=%04x dwParam1=%08lx dwParam2=%08lx\n",
2427 dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2429 return DrvDefDriverProc16(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2432 /* ###################################################
2433 * # TIME #
2434 * ###################################################
2437 /**************************************************************************
2438 * timeGetSystemTime [MMSYSTEM.601]
2440 MMRESULT16 WINAPI timeGetSystemTime16(LPMMTIME16 lpTime, UINT16 wSize)
2442 TRACE("(%p, %u);\n", lpTime, wSize);
2444 if (wSize >= sizeof(*lpTime)) {
2445 lpTime->wType = TIME_MS;
2446 TIME_MMTimeStart();
2447 lpTime->u.ms = WINMM_IData->mmSysTimeMS;
2449 TRACE("=> %lu\n", lpTime->u.ms);
2452 return 0;
2455 /**************************************************************************
2456 * timeSetEvent [MMSYSTEM.602]
2458 MMRESULT16 WINAPI timeSetEvent16(UINT16 wDelay, UINT16 wResol, LPTIMECALLBACK16 lpFunc,
2459 DWORD dwUser, UINT16 wFlags)
2461 if (wFlags & WINE_TIMER_IS32)
2462 WARN("Unknown windows flag... wine internally used.. ooch\n");
2464 return timeSetEventInternal(wDelay, wResol, (FARPROC16)lpFunc,
2465 dwUser, wFlags & ~WINE_TIMER_IS32);
2468 /**************************************************************************
2469 * timeKillEvent [MMSYSTEM.603]
2471 MMRESULT16 WINAPI timeKillEvent16(UINT16 wID)
2473 return timeKillEvent(wID);
2476 /**************************************************************************
2477 * timeGetDevCaps [MMSYSTEM.604]
2479 MMRESULT16 WINAPI timeGetDevCaps16(LPTIMECAPS16 lpCaps, UINT16 wSize)
2481 TIMECAPS caps;
2482 MMRESULT ret;
2484 TRACE("(%p, %u) !\n", lpCaps, wSize);
2486 ret = timeGetDevCaps(&caps, sizeof(caps));
2487 lpCaps->wPeriodMin = caps.wPeriodMin;
2488 lpCaps->wPeriodMax = caps.wPeriodMax;
2489 return 0;
2492 /**************************************************************************
2493 * timeBeginPeriod [MMSYSTEM.605]
2495 MMRESULT16 WINAPI timeBeginPeriod16(UINT16 wPeriod)
2497 TRACE("(%u) !\n", wPeriod);
2499 return timeBeginPeriod(wPeriod);
2502 /**************************************************************************
2503 * timeEndPeriod [MMSYSTEM.606]
2505 MMRESULT16 WINAPI timeEndPeriod16(UINT16 wPeriod)
2507 TRACE("(%u) !\n", wPeriod);
2509 return timeEndPeriod(wPeriod);
2512 /**************************************************************************
2513 * mciSendString [MMSYSTEM.702]
2515 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
2516 UINT16 uRetLen, HWND16 hwndCallback)
2518 return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback));
2521 /**************************************************************************
2522 * mciLoadCommandResource [MMSYSTEM.705]
2524 UINT16 WINAPI mciLoadCommandResource16(HANDLE16 hInst, LPCSTR resname, UINT16 type)
2526 LPCWSTR ptr = HEAP_strdupAtoW(GetProcessHeap(), 0, resname);
2527 UINT ret = mciLoadCommandResource(hInst, ptr, type);
2528 HeapFree(GetProcessHeap(), 0, (LPWSTR)ptr);
2529 return ret;
2532 /**************************************************************************
2533 * mciFreeCommandResource [MMSYSTEM.713]
2535 BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
2537 TRACE("(%04x)!\n", uTable);
2539 return mciFreeCommandResource(uTable);
2542 /* ###################################################
2543 * # MMIO #
2544 * ###################################################
2547 /****************************************************************
2548 * MMIO_Map32To16 [INTERNAL]
2550 static LRESULT MMIO_Map32To16(DWORD wMsg, LPARAM* lp1, LPARAM* lp2)
2552 switch (wMsg) {
2553 case MMIOM_CLOSE:
2554 case MMIOM_SEEK:
2555 /* nothing to do */
2556 break;
2557 case MMIOM_OPEN:
2558 case MMIOM_READ:
2559 case MMIOM_WRITE:
2560 case MMIOM_WRITEFLUSH:
2561 *lp1 = MapLS( (void *)*lp1 );
2562 break;
2563 case MMIOM_RENAME:
2564 *lp1 = MapLS( (void *)*lp1 );
2565 *lp2 = MapLS( (void *)*lp2 );
2566 break;
2567 default:
2568 if (wMsg < MMIOM_USER)
2569 TRACE("Not a mappable message (%ld)\n", wMsg);
2571 return MMSYSERR_NOERROR;
2574 /****************************************************************
2575 * MMIO_UnMap32To16 [INTERNAL]
2577 static LRESULT MMIO_UnMap32To16(DWORD wMsg, LPARAM lParam1, LPARAM lParam2,
2578 LPARAM lp1, LPARAM lp2)
2580 switch (wMsg) {
2581 case MMIOM_CLOSE:
2582 case MMIOM_SEEK:
2583 /* nothing to do */
2584 break;
2585 case MMIOM_OPEN:
2586 case MMIOM_READ:
2587 case MMIOM_WRITE:
2588 case MMIOM_WRITEFLUSH:
2589 UnMapLS( lp1 );
2590 break;
2591 case MMIOM_RENAME:
2592 UnMapLS( lp1 );
2593 UnMapLS( lp2 );
2594 break;
2595 default:
2596 if (wMsg < MMIOM_USER)
2597 TRACE("Not a mappable message (%ld)\n", wMsg);
2599 return MMSYSERR_NOERROR;
2602 /******************************************************************
2603 * MMIO_Callback16
2607 static LRESULT MMIO_Callback16(SEGPTR cb16, LPMMIOINFO lpmmioinfo, UINT uMessage,
2608 LPARAM lParam1, LPARAM lParam2)
2610 LRESULT result;
2611 MMIOINFO16 mmioInfo16;
2612 SEGPTR segmmioInfo16;
2613 LPARAM lp1 = lParam1, lp2 = lParam2;
2615 memset(&mmioInfo16, 0, sizeof(MMIOINFO16));
2616 mmioInfo16.lDiskOffset = lpmmioinfo->lDiskOffset;
2617 mmioInfo16.adwInfo[0] = lpmmioinfo->adwInfo[0];
2618 mmioInfo16.adwInfo[1] = lpmmioinfo->adwInfo[1];
2619 mmioInfo16.adwInfo[2] = lpmmioinfo->adwInfo[2];
2620 mmioInfo16.adwInfo[3] = lpmmioinfo->adwInfo[3];
2621 /* map (lParam1, lParam2) into (lp1, lp2) 32=>16 */
2622 if ((result = MMIO_Map32To16(uMessage, &lp1, &lp2)) != MMSYSERR_NOERROR)
2623 return result;
2625 segmmioInfo16 = MapLS(&mmioInfo16);
2627 result = MMSYSTEM_CallTo16_long_lwll((LPMMIOPROC16)cb16, segmmioInfo16, uMessage, lp1, lp2);
2628 UnMapLS(segmmioInfo16);
2629 MMIO_UnMap32To16(uMessage, lParam1, lParam2, lp1, lp2);
2631 lpmmioinfo->lDiskOffset = mmioInfo16.lDiskOffset;
2632 lpmmioinfo->adwInfo[0] = mmioInfo16.adwInfo[0];
2633 lpmmioinfo->adwInfo[1] = mmioInfo16.adwInfo[1];
2634 lpmmioinfo->adwInfo[2] = mmioInfo16.adwInfo[2];
2635 lpmmioinfo->adwInfo[3] = mmioInfo16.adwInfo[3];
2637 return result;
2640 /******************************************************************
2641 * MMIO_ResetSegmentedData
2644 static LRESULT MMIO_SetSegmentedBuffer(HMMIO hmmio, SEGPTR ptr)
2646 LPWINE_MMIO wm;
2648 if ((wm = MMIO_Get(hmmio)) == NULL)
2649 return MMSYSERR_INVALHANDLE;
2650 wm->segBuffer16 = ptr;
2651 return MMSYSERR_NOERROR;
2654 /**************************************************************************
2655 * mmioOpen [MMSYSTEM.1210]
2657 HMMIO16 WINAPI mmioOpen16(LPSTR szFileName, MMIOINFO16* lpmmioinfo16,
2658 DWORD dwOpenFlags)
2660 HMMIO ret;
2662 if (lpmmioinfo16) {
2663 MMIOINFO mmioinfo;
2665 memset(&mmioinfo, 0, sizeof(mmioinfo));
2667 mmioinfo.dwFlags = lpmmioinfo16->dwFlags;
2668 mmioinfo.fccIOProc = lpmmioinfo16->fccIOProc;
2669 mmioinfo.pIOProc = (LPMMIOPROC)lpmmioinfo16->pIOProc;
2670 mmioinfo.cchBuffer = lpmmioinfo16->cchBuffer;
2671 mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo16->pchBuffer);
2672 mmioinfo.adwInfo[0] = lpmmioinfo16->adwInfo[0];
2673 /* if we don't have a file name, it's likely a passed open file descriptor */
2674 if (!szFileName)
2675 mmioinfo.adwInfo[0] = DosFileHandleToWin32Handle(mmioinfo.adwInfo[0]);
2676 mmioinfo.adwInfo[1] = lpmmioinfo16->adwInfo[1];
2677 mmioinfo.adwInfo[2] = lpmmioinfo16->adwInfo[2];
2678 mmioinfo.adwInfo[3] = lpmmioinfo16->adwInfo[3];
2680 ret = MMIO_Open(szFileName, &mmioinfo, dwOpenFlags, MMIO_PROC_16);
2681 MMIO_SetSegmentedBuffer(mmioinfo.hmmio, (SEGPTR)lpmmioinfo16->pchBuffer);
2683 lpmmioinfo16->wErrorRet = mmioinfo.wErrorRet;
2684 lpmmioinfo16->hmmio = HMMIO_16(mmioinfo.hmmio);
2685 } else {
2686 ret = MMIO_Open(szFileName, NULL, dwOpenFlags, MMIO_PROC_32A);
2688 return HMMIO_16(ret);
2691 /**************************************************************************
2692 * mmioClose [MMSYSTEM.1211]
2694 MMRESULT16 WINAPI mmioClose16(HMMIO16 hmmio, UINT16 uFlags)
2696 return mmioClose(HMMIO_32(hmmio), uFlags);
2699 /**************************************************************************
2700 * mmioRead [MMSYSTEM.1212]
2702 LONG WINAPI mmioRead16(HMMIO16 hmmio, HPSTR pch, LONG cch)
2704 return mmioRead(HMMIO_32(hmmio), pch, cch);
2707 /**************************************************************************
2708 * mmioWrite [MMSYSTEM.1213]
2710 LONG WINAPI mmioWrite16(HMMIO16 hmmio, HPCSTR pch, LONG cch)
2712 return mmioWrite(HMMIO_32(hmmio),pch,cch);
2715 /**************************************************************************
2716 * mmioSeek [MMSYSTEM.1214]
2718 LONG WINAPI mmioSeek16(HMMIO16 hmmio, LONG lOffset, INT16 iOrigin)
2720 return mmioSeek(HMMIO_32(hmmio), lOffset, iOrigin);
2723 /**************************************************************************
2724 * mmioGetInfo [MMSYSTEM.1215]
2726 MMRESULT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2728 MMIOINFO mmioinfo;
2729 MMRESULT ret;
2730 LPWINE_MMIO wm;
2732 TRACE("(0x%04x,%p,0x%08x)\n", hmmio, lpmmioinfo, uFlags);
2734 if ((wm = MMIO_Get(hmmio)) == NULL)
2735 return MMSYSERR_INVALHANDLE;
2737 ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2738 if (ret != MMSYSERR_NOERROR) return ret;
2740 lpmmioinfo->dwFlags = mmioinfo.dwFlags;
2741 lpmmioinfo->fccIOProc = mmioinfo.fccIOProc;
2742 lpmmioinfo->pIOProc = (wm->ioProc->type == MMIO_PROC_16) ?
2743 (LPMMIOPROC16)wm->ioProc->pIOProc : NULL;
2744 lpmmioinfo->wErrorRet = mmioinfo.wErrorRet;
2745 lpmmioinfo->hTask = mmioinfo.hTask;
2746 lpmmioinfo->cchBuffer = mmioinfo.cchBuffer;
2747 lpmmioinfo->pchBuffer = (void*)wm->segBuffer16;
2748 lpmmioinfo->pchNext = (void*)(wm->segBuffer16 + (mmioinfo.pchNext - mmioinfo.pchBuffer));
2749 lpmmioinfo->pchEndRead = (void*)(wm->segBuffer16 + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
2750 lpmmioinfo->pchEndWrite = (void*)(wm->segBuffer16 + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
2751 lpmmioinfo->lBufOffset = mmioinfo.lBufOffset;
2752 lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
2753 lpmmioinfo->adwInfo[0] = mmioinfo.adwInfo[0];
2754 lpmmioinfo->adwInfo[1] = mmioinfo.adwInfo[1];
2755 lpmmioinfo->adwInfo[2] = mmioinfo.adwInfo[2];
2756 lpmmioinfo->adwInfo[3] = mmioinfo.adwInfo[3];
2757 lpmmioinfo->dwReserved1 = 0;
2758 lpmmioinfo->dwReserved2 = 0;
2759 lpmmioinfo->hmmio = HMMIO_16(mmioinfo.hmmio);
2761 return MMSYSERR_NOERROR;
2764 /**************************************************************************
2765 * mmioSetInfo [MMSYSTEM.1216]
2767 MMRESULT16 WINAPI mmioSetInfo16(HMMIO16 hmmio, const MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2769 MMIOINFO mmioinfo;
2770 MMRESULT ret;
2772 TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
2774 ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, 0);
2775 if (ret != MMSYSERR_NOERROR) return ret;
2777 /* check if seg and lin buffers are the same */
2778 if (mmioinfo.cchBuffer != lpmmioinfo->cchBuffer ||
2779 mmioinfo.pchBuffer != MapSL((DWORD)lpmmioinfo->pchBuffer))
2780 return MMSYSERR_INVALPARAM;
2782 /* check pointers coherence */
2783 if (lpmmioinfo->pchNext < lpmmioinfo->pchBuffer ||
2784 lpmmioinfo->pchNext > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2785 lpmmioinfo->pchEndRead < lpmmioinfo->pchBuffer ||
2786 lpmmioinfo->pchEndRead > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2787 lpmmioinfo->pchEndWrite < lpmmioinfo->pchBuffer ||
2788 lpmmioinfo->pchEndWrite > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer)
2789 return MMSYSERR_INVALPARAM;
2791 mmioinfo.pchNext = mmioinfo.pchBuffer + (lpmmioinfo->pchNext - lpmmioinfo->pchBuffer);
2792 mmioinfo.pchEndRead = mmioinfo.pchBuffer + (lpmmioinfo->pchEndRead - lpmmioinfo->pchBuffer);
2793 mmioinfo.pchEndWrite = mmioinfo.pchBuffer + (lpmmioinfo->pchEndWrite - lpmmioinfo->pchBuffer);
2795 return mmioSetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2798 /**************************************************************************
2799 * mmioSetBuffer [MMSYSTEM.1217]
2801 MMRESULT16 WINAPI mmioSetBuffer16(HMMIO16 hmmio, LPSTR pchBuffer,
2802 LONG cchBuffer, UINT16 uFlags)
2804 MMRESULT ret = mmioSetBuffer(HMMIO_32(hmmio), MapSL((DWORD)pchBuffer),
2805 cchBuffer, uFlags);
2807 if (ret == MMSYSERR_NOERROR)
2808 MMIO_SetSegmentedBuffer(HMMIO_32(hmmio), (DWORD)pchBuffer);
2809 return ret;
2812 /**************************************************************************
2813 * mmioFlush [MMSYSTEM.1218]
2815 MMRESULT16 WINAPI mmioFlush16(HMMIO16 hmmio, UINT16 uFlags)
2817 return mmioFlush(HMMIO_32(hmmio), uFlags);
2820 /***********************************************************************
2821 * mmioAdvance [MMSYSTEM.1219]
2823 MMRESULT16 WINAPI mmioAdvance16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2825 MMIOINFO mmioinfo;
2826 LRESULT ret;
2828 /* WARNING: this heavily relies on mmioAdvance implementation (for choosing which
2829 * fields to init
2831 if (lpmmioinfo)
2833 mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo->pchBuffer);
2834 mmioinfo.pchNext = MapSL((DWORD)lpmmioinfo->pchNext);
2835 mmioinfo.dwFlags = lpmmioinfo->dwFlags;
2836 mmioinfo.lBufOffset = lpmmioinfo->lBufOffset;
2837 ret = mmioAdvance(HMMIO_32(hmmio), &mmioinfo, uFlags);
2839 else
2840 ret = mmioAdvance(HMMIO_32(hmmio), NULL, uFlags);
2842 if (ret != MMSYSERR_NOERROR) return ret;
2844 if (lpmmioinfo)
2846 lpmmioinfo->dwFlags = mmioinfo.dwFlags;
2847 lpmmioinfo->pchNext = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchNext - mmioinfo.pchBuffer));
2848 lpmmioinfo->pchEndRead = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
2849 lpmmioinfo->pchEndWrite = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
2850 lpmmioinfo->lBufOffset = mmioinfo.lBufOffset;
2851 lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
2854 return MMSYSERR_NOERROR;
2857 /**************************************************************************
2858 * mmioStringToFOURCC [MMSYSTEM.1220]
2860 FOURCC WINAPI mmioStringToFOURCC16(LPCSTR sz, UINT16 uFlags)
2862 return mmioStringToFOURCCA(sz, uFlags);
2865 /**************************************************************************
2866 * mmioInstallIOProc [MMSYSTEM.1221]
2868 LPMMIOPROC16 WINAPI mmioInstallIOProc16(FOURCC fccIOProc, LPMMIOPROC16 pIOProc,
2869 DWORD dwFlags)
2871 return (LPMMIOPROC16)MMIO_InstallIOProc(fccIOProc, (LPMMIOPROC)pIOProc,
2872 dwFlags, MMIO_PROC_16);
2875 /**************************************************************************
2876 * mmioSendMessage [MMSYSTEM.1222]
2878 LRESULT WINAPI mmioSendMessage16(HMMIO16 hmmio, UINT16 uMessage,
2879 LPARAM lParam1, LPARAM lParam2)
2881 return MMIO_SendMessage(HMMIO_32(hmmio), uMessage,
2882 lParam1, lParam2, MMIO_PROC_16);
2885 /**************************************************************************
2886 * mmioDescend [MMSYSTEM.1223]
2888 MMRESULT16 WINAPI mmioDescend16(HMMIO16 hmmio, LPMMCKINFO lpck,
2889 const MMCKINFO* lpckParent, UINT16 uFlags)
2891 return mmioDescend(HMMIO_32(hmmio), lpck, lpckParent, uFlags);
2894 /**************************************************************************
2895 * mmioAscend [MMSYSTEM.1224]
2897 MMRESULT16 WINAPI mmioAscend16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
2899 return mmioAscend(HMMIO_32(hmmio),lpck,uFlags);
2902 /**************************************************************************
2903 * mmioCreateChunk [MMSYSTEM.1225]
2905 MMRESULT16 WINAPI mmioCreateChunk16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
2907 return mmioCreateChunk(HMMIO_32(hmmio), lpck, uFlags);
2910 /**************************************************************************
2911 * mmioRename [MMSYSTEM.1226]
2913 MMRESULT16 WINAPI mmioRename16(LPCSTR szFileName, LPCSTR szNewFileName,
2914 MMIOINFO16* lpmmioinfo, DWORD dwRenameFlags)
2916 BOOL inst = FALSE;
2917 MMRESULT ret;
2918 MMIOINFO mmioinfo;
2920 if (lpmmioinfo != NULL && lpmmioinfo->pIOProc != NULL &&
2921 lpmmioinfo->fccIOProc == 0) {
2922 FIXME("Can't handle this case yet\n");
2923 return MMSYSERR_ERROR;
2926 /* this is a bit hacky, but it'll work if we get a fourCC code or nothing.
2927 * but a non installed ioproc without a fourcc won't do
2929 if (lpmmioinfo && lpmmioinfo->fccIOProc && lpmmioinfo->pIOProc) {
2930 MMIO_InstallIOProc(lpmmioinfo->fccIOProc, (LPMMIOPROC)lpmmioinfo->pIOProc,
2931 MMIO_INSTALLPROC, MMIO_PROC_16);
2932 inst = TRUE;
2934 memset(&mmioinfo, 0, sizeof(mmioinfo));
2935 mmioinfo.fccIOProc = lpmmioinfo->fccIOProc;
2936 ret = mmioRenameA(szFileName, szNewFileName, &mmioinfo, dwRenameFlags);
2937 if (inst) {
2938 MMIO_InstallIOProc(lpmmioinfo->fccIOProc, NULL,
2939 MMIO_REMOVEPROC, MMIO_PROC_16);
2941 return ret;