2169 lines
67 KiB
C
2169 lines
67 KiB
C
/*
|
|
* MMSYSTEM MCI and low level mapping functions
|
|
*
|
|
* Copyright 1999 Eric Pouech
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
#include "wine/winbase16.h"
|
|
#include "windef.h"
|
|
#include "winbase.h"
|
|
#include "wownt32.h"
|
|
#include "winemm.h"
|
|
#include "winemm16.h"
|
|
#include "digitalv.h"
|
|
#include "wine/debug.h"
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winmm);
|
|
|
|
/******************************************************************
|
|
* WINMM_MMTIME16to32
|
|
*/
|
|
static void WINMM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16)
|
|
{
|
|
mmt32->wType = mmt16->wType;
|
|
/* layout of rest is the same for 32/16,
|
|
* Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
|
|
*/
|
|
memcpy(&(mmt32->u), &(mmt16->u), sizeof(mmt16->u));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* MMDRV_Callback [internal]
|
|
*/
|
|
static void MMDRV_Callback(LPWINE_MLD mld, HDRVR hDev, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
{
|
|
TRACE("CB (*%08lx)(%p %08x %08lx %08lx %08lx\n",
|
|
mld->dwCallback, hDev, uMsg, mld->dwClientInstance, dwParam1, dwParam2);
|
|
|
|
if ((mld->dwFlags & DCB_TYPEMASK) == DCB_FUNCTION)
|
|
{
|
|
WORD args[8];
|
|
/* 16 bit func, call it */
|
|
TRACE("Function (16 bit) !\n");
|
|
|
|
args[7] = HDRVR_16(hDev);
|
|
args[6] = uMsg;
|
|
args[5] = HIWORD(mld->dwClientInstance);
|
|
args[4] = LOWORD(mld->dwClientInstance);
|
|
args[3] = HIWORD(dwParam1);
|
|
args[2] = LOWORD(dwParam1);
|
|
args[1] = HIWORD(dwParam2);
|
|
args[0] = LOWORD(dwParam2);
|
|
WOWCallback16Ex( mld->dwCallback, WCB16_PASCAL, sizeof(args), args, NULL );
|
|
} else {
|
|
DriverCallback(mld->dwCallback, mld->dwFlags, hDev, uMsg,
|
|
mld->dwClientInstance, dwParam1, dwParam2);
|
|
}
|
|
}
|
|
|
|
/* =================================
|
|
* A U X M A P P E R S
|
|
* ================================= */
|
|
|
|
/**************************************************************************
|
|
* MMDRV_Aux_Map32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_Aux_Map32WTo16 (UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
return WINMM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_Aux_UnMap32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_Aux_UnMap32WTo16(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
#if 0
|
|
case AUXDM_GETDEVCAPS:
|
|
lpCaps->wMid = ac16.wMid;
|
|
lpCaps->wPid = ac16.wPid;
|
|
lpCaps->vDriverVersion = ac16.vDriverVersion;
|
|
strcpy(lpCaps->szPname, ac16.szPname);
|
|
lpCaps->wTechnology = ac16.wTechnology;
|
|
lpCaps->dwSupport = ac16.dwSupport;
|
|
#endif
|
|
return WINMM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_Aux_Callback [internal]
|
|
*/
|
|
static void CALLBACK MMDRV_Aux_Callback(HDRVR hDev, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
{
|
|
LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
|
|
|
|
FIXME("NIY\n");
|
|
MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
|
|
}
|
|
|
|
/* =================================
|
|
* M I X E R M A P P E R S
|
|
* ================================= */
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_Mixer_Map16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_Mixer_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
return MMSYSTEM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_Mixer_UnMap16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_Mixer_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
#if 0
|
|
MIXERCAPSA micA;
|
|
UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
|
|
|
|
if (ret == MMSYSERR_NOERROR) {
|
|
mixcaps->wMid = micA.wMid;
|
|
mixcaps->wPid = micA.wPid;
|
|
mixcaps->vDriverVersion = micA.vDriverVersion;
|
|
strcpy(mixcaps->szPname, micA.szPname);
|
|
mixcaps->fdwSupport = micA.fdwSupport;
|
|
mixcaps->cDestinations = micA.cDestinations;
|
|
}
|
|
return ret;
|
|
#endif
|
|
return MMSYSTEM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_Mixer_Map32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_Mixer_Map32WTo16 (UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
return WINMM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_Mixer_UnMap32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_Mixer_UnMap32WTo16(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
return WINMM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_Mixer_Callback [internal]
|
|
*/
|
|
static void CALLBACK MMDRV_Mixer_Callback(HDRVR hDev, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
{
|
|
LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
|
|
|
|
FIXME("NIY\n");
|
|
MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_Mixer_MapCB
|
|
*/
|
|
static void MMSYSTDRV_Mixer_MapCB(DWORD uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
|
|
{
|
|
FIXME("NIY\n");
|
|
}
|
|
|
|
/* =================================
|
|
* M I D I I N M A P P E R S
|
|
* ================================= */
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_MidiIn_Map16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_MidiIn_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
return MMSYSTEM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_MidiIn_UnMap16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_MidiIn_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
return MMSYSTEM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_MidiIn_Map32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_MidiIn_Map32WTo16 (UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
return WINMM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_MidiIn_UnMap32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_MidiIn_UnMap32WTo16(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
return WINMM_MAP_MSGERROR;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_MidiIn_Callback [internal]
|
|
*/
|
|
static void CALLBACK MMDRV_MidiIn_Callback(HDRVR hDev, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
{
|
|
LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
|
|
|
|
switch (uMsg) {
|
|
case MIM_OPEN:
|
|
case MIM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
|
|
case MIM_DATA:
|
|
case MIM_MOREDATA:
|
|
case MIM_ERROR:
|
|
/* dwParam1 & dwParam2 are data, nothing to do */
|
|
break;
|
|
case MIM_LONGDATA:
|
|
case MIM_LONGERROR:
|
|
/* dwParam1 points to a MidiHdr, work to be done !!! */
|
|
if (!MMDRV_Is32(mld->mmdIndex)) {
|
|
/* initial map is: 32 => 16 */
|
|
LPMIDIHDR mh16 = MapSL(dwParam1);
|
|
LPMIDIHDR mh32 = *(LPMIDIHDR*)((LPSTR)mh16 - sizeof(LPMIDIHDR));
|
|
|
|
dwParam1 = (DWORD)mh32;
|
|
mh32->dwFlags = mh16->dwFlags;
|
|
mh32->dwBytesRecorded = mh16->dwBytesRecorded;
|
|
if (mh32->reserved >= sizeof(MIDIHDR))
|
|
mh32->dwOffset = mh16->dwOffset;
|
|
}
|
|
/* else { 32 => 32, nothing to do, same struct is kept }*/
|
|
break;
|
|
/* case MOM_POSITIONCB: */
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
|
|
MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_MidiIn_MapCB [internal]
|
|
*/
|
|
static void MMSYSTDRV_MidiIn_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
|
|
{
|
|
switch (uMsg) {
|
|
case MIM_OPEN:
|
|
case MIM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
|
|
case MIM_DATA:
|
|
case MIM_MOREDATA:
|
|
case MIM_ERROR:
|
|
/* dwParam1 & dwParam2 are data, nothing to do */
|
|
break;
|
|
case MIM_LONGDATA:
|
|
case MIM_LONGERROR:
|
|
{
|
|
LPMIDIHDR mh32 = (LPMIDIHDR)(*dwParam1);
|
|
SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR));
|
|
LPMIDIHDR mh16 = MapSL(segmh16);
|
|
|
|
*dwParam1 = (DWORD)segmh16;
|
|
mh16->dwFlags = mh32->dwFlags;
|
|
mh16->dwBytesRecorded = mh32->dwBytesRecorded;
|
|
if (mh16->reserved >= sizeof(MIDIHDR))
|
|
mh16->dwOffset = mh32->dwOffset;
|
|
}
|
|
break;
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
}
|
|
|
|
/* =================================
|
|
* M I D I O U T M A P P E R S
|
|
* ================================= */
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_MidiOut_Map16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case MODM_GETNUMDEVS:
|
|
case MODM_DATA:
|
|
case MODM_RESET:
|
|
case MODM_SETVOLUME:
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
|
|
case MODM_OPEN:
|
|
case MODM_CLOSE:
|
|
case MODM_GETVOLUME:
|
|
FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
|
|
break;
|
|
|
|
case MODM_GETDEVCAPS:
|
|
{
|
|
LPMIDIOUTCAPSW moc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPS16) + sizeof(MIDIOUTCAPSW));
|
|
LPMIDIOUTCAPS16 moc16 = MapSL(*lpParam1);
|
|
|
|
if (moc32) {
|
|
*(LPMIDIOUTCAPS16*)moc32 = moc16;
|
|
moc32 = (LPMIDIOUTCAPSW)((LPSTR)moc32 + sizeof(LPMIDIOUTCAPS16));
|
|
*lpParam1 = (DWORD)moc32;
|
|
*lpParam2 = sizeof(MIDIOUTCAPSW);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case MODM_PREPARE:
|
|
{
|
|
LPMIDIHDR mh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMIDIHDR) + sizeof(MIDIHDR));
|
|
LPMIDIHDR mh16 = MapSL(*lpParam1);
|
|
|
|
if (mh32) {
|
|
*(LPMIDIHDR*)mh32 = (LPMIDIHDR)*lpParam1;
|
|
mh32 = (LPMIDIHDR)((LPSTR)mh32 + sizeof(LPMIDIHDR));
|
|
mh32->lpData = MapSL((SEGPTR)mh16->lpData);
|
|
mh32->dwBufferLength = mh16->dwBufferLength;
|
|
mh32->dwBytesRecorded = mh16->dwBytesRecorded;
|
|
mh32->dwUser = mh16->dwUser;
|
|
mh32->dwFlags = mh16->dwFlags;
|
|
/* FIXME: nothing on mh32->lpNext */
|
|
/* could link the mh32->lpNext at this level for memory house keeping */
|
|
mh32->dwOffset = (*lpParam2 >= sizeof(MIDIHDR)) ? mh16->dwOffset : 0;
|
|
mh16->lpNext = mh32; /* for reuse in unprepare and write */
|
|
/* store size of passed MIDIHDR?? structure to know if dwOffset is available or not */
|
|
mh16->reserved = *lpParam2;
|
|
*lpParam1 = (DWORD)mh32;
|
|
*lpParam2 = sizeof(MIDIHDR);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case MODM_UNPREPARE:
|
|
case MODM_LONGDATA:
|
|
{
|
|
LPMIDIHDR mh16 = MapSL(*lpParam1);
|
|
LPMIDIHDR mh32 = mh16->lpNext;
|
|
|
|
*lpParam1 = (DWORD)mh32;
|
|
*lpParam2 = sizeof(MIDIHDR);
|
|
/* dwBufferLength can be reduced between prepare & write */
|
|
if (wMsg == MODM_LONGDATA && mh32->dwBufferLength < mh16->dwBufferLength) {
|
|
ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
|
|
mh32->dwBufferLength, mh16->dwBufferLength);
|
|
} else
|
|
mh32->dwBufferLength = mh16->dwBufferLength;
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
|
|
case MODM_CACHEPATCHES:
|
|
case MODM_CACHEDRUMPATCHES:
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_MidiOut_UnMap16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_MidiOut_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case MODM_GETNUMDEVS:
|
|
case MODM_DATA:
|
|
case MODM_RESET:
|
|
case MODM_SETVOLUME:
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
|
|
case MODM_OPEN:
|
|
case MODM_CLOSE:
|
|
case MODM_GETVOLUME:
|
|
FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
|
|
break;
|
|
|
|
case MODM_GETDEVCAPS:
|
|
{
|
|
LPMIDIOUTCAPSW moc32 = (LPMIDIOUTCAPSW)(*lpParam1);
|
|
LPMIDIOUTCAPS16 moc16 = *(LPMIDIOUTCAPS16*)((LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
|
|
|
|
moc16->wMid = moc32->wMid;
|
|
moc16->wPid = moc32->wPid;
|
|
moc16->vDriverVersion = moc32->vDriverVersion;
|
|
WideCharToMultiByte( CP_ACP, 0, moc32->szPname, -1, moc16->szPname,
|
|
sizeof(moc16->szPname), NULL, NULL );
|
|
moc16->wTechnology = moc32->wTechnology;
|
|
moc16->wVoices = moc32->wVoices;
|
|
moc16->wNotes = moc32->wNotes;
|
|
moc16->wChannelMask = moc32->wChannelMask;
|
|
moc16->dwSupport = moc32->dwSupport;
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16));
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
case MODM_PREPARE:
|
|
case MODM_UNPREPARE:
|
|
case MODM_LONGDATA:
|
|
{
|
|
LPMIDIHDR mh32 = (LPMIDIHDR)(*lpParam1);
|
|
LPMIDIHDR mh16 = MapSL(*(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR)));
|
|
|
|
assert(mh16->lpNext == mh32);
|
|
mh16->dwBufferLength = mh32->dwBufferLength;
|
|
mh16->dwBytesRecorded = mh32->dwBytesRecorded;
|
|
mh16->dwUser = mh32->dwUser;
|
|
mh16->dwFlags = mh32->dwFlags;
|
|
if (mh16->reserved >= sizeof(MIDIHDR))
|
|
mh16->dwOffset = mh32->dwOffset;
|
|
|
|
if (wMsg == MODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)mh32 - sizeof(LPMIDIHDR));
|
|
mh16->lpNext = 0;
|
|
}
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
|
|
case MODM_CACHEPATCHES:
|
|
case MODM_CACHEDRUMPATCHES:
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_MidiOut_Map32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_MidiOut_Map32WTo16 (UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
WINMM_MapType ret = WINMM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case MODM_CLOSE:
|
|
case MODM_GETNUMDEVS:
|
|
case MODM_DATA:
|
|
case MODM_RESET:
|
|
case MODM_SETVOLUME:
|
|
ret = WINMM_MAP_OK;
|
|
break;
|
|
case MODM_GETDEVCAPS:
|
|
{
|
|
LPMIDIOUTCAPSW moc32 = (LPMIDIOUTCAPSW)*lpParam1;
|
|
LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMIDIOUTCAPSW)+sizeof(MIDIOUTCAPS16));
|
|
|
|
if (ptr) {
|
|
*(LPMIDIOUTCAPSW*)ptr = moc32;
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
*lpParam1 = (DWORD)MapLS(ptr) + sizeof(LPMIDIOUTCAPSW);
|
|
*lpParam2 = sizeof(MIDIOUTCAPS16);
|
|
}
|
|
break;
|
|
case MODM_PREPARE:
|
|
{
|
|
LPMIDIHDR mh32 = (LPMIDIHDR)*lpParam1;
|
|
LPMIDIHDR mh16;
|
|
LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
|
|
sizeof(LPMIDIHDR) + sizeof(MIDIHDR) + mh32->dwBufferLength);
|
|
|
|
if (ptr) {
|
|
*(LPMIDIHDR*)ptr = mh32;
|
|
mh16 = (LPMIDIHDR)((LPSTR)ptr + sizeof(LPMIDIHDR));
|
|
*lpParam1 = MapLS(mh16);
|
|
mh16->lpData = (LPSTR)*lpParam1 + sizeof(MIDIHDR);
|
|
/* data will be copied on WODM_WRITE */
|
|
mh16->dwBufferLength = mh32->dwBufferLength;
|
|
mh16->dwBytesRecorded = mh32->dwBytesRecorded;
|
|
mh16->dwUser = mh32->dwUser;
|
|
mh16->dwFlags = mh32->dwFlags;
|
|
/* FIXME: nothing on mh32->lpNext */
|
|
/* could link the mh32->lpNext at this level for memory house keeping */
|
|
mh16->dwOffset = (*lpParam2 >= sizeof(MIDIHDR)) ? mh32->dwOffset : 0;
|
|
|
|
mh32->lpNext = mh16; /* for reuse in unprepare and write */
|
|
mh32->reserved = *lpParam2;
|
|
|
|
TRACE("mh16=%08lx mh16->lpData=%p mh32->buflen=%u mh32->lpData=%p\n",
|
|
*lpParam1, mh16->lpData, mh32->dwBufferLength, mh32->lpData);
|
|
*lpParam2 = sizeof(MIDIHDR);
|
|
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case MODM_UNPREPARE:
|
|
case MODM_LONGDATA:
|
|
{
|
|
LPMIDIHDR mh32 = (LPMIDIHDR)(*lpParam1);
|
|
LPMIDIHDR mh16 = mh32->lpNext;
|
|
LPSTR ptr = (LPSTR)mh16 - sizeof(LPMIDIHDR);
|
|
|
|
assert(*(LPMIDIHDR*)ptr == mh32);
|
|
|
|
if (wMsg == MODM_LONGDATA)
|
|
memcpy((LPSTR)mh16 + sizeof(MIDIHDR), mh32->lpData, mh32->dwBufferLength);
|
|
|
|
*lpParam1 = MapLS(mh16);
|
|
*lpParam2 = sizeof(MIDIHDR);
|
|
TRACE("mh16=%08lx mh16->lpData=%p mh32->buflen=%u mh32->lpData=%p\n",
|
|
*lpParam1, mh16->lpData, mh32->dwBufferLength, mh32->lpData);
|
|
|
|
/* dwBufferLength can be reduced between prepare & write */
|
|
if (wMsg == MODM_LONGDATA && mh16->dwBufferLength < mh32->dwBufferLength) {
|
|
ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
|
|
mh16->dwBufferLength, mh32->dwBufferLength);
|
|
} else
|
|
mh16->dwBufferLength = mh32->dwBufferLength;
|
|
ret = WINMM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
case MODM_OPEN:
|
|
{
|
|
LPMIDIOPENDESC mod32 = (LPMIDIOPENDESC)*lpParam1;
|
|
LPVOID ptr;
|
|
LPMIDIOPENDESC16 mod16;
|
|
|
|
/* allocated data are mapped as follows:
|
|
LPMIDIOPENDESC ptr to orig lParam1
|
|
DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
|
|
DWORD dwUser passed to driver
|
|
MIDIOPENDESC16 mod16: openDesc passed to driver
|
|
MIDIOPENSTRMID cIds
|
|
*/
|
|
ptr = HeapAlloc( GetProcessHeap(), 0,
|
|
sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD) + sizeof(MIDIOPENDESC16) +
|
|
mod32->cIds ? (mod32->cIds - 1) * sizeof(MIDIOPENSTRMID) : 0);
|
|
|
|
if (ptr) {
|
|
SEGPTR segptr = MapLS(ptr);
|
|
*(LPMIDIOPENDESC*)ptr = mod32;
|
|
*(LPDWORD)((char*)ptr + sizeof(LPMIDIOPENDESC)) = *lpdwUser;
|
|
mod16 = (LPMIDIOPENDESC16)((LPSTR)ptr + sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD));
|
|
|
|
mod16->hMidi = HMIDI_16(mod32->hMidi);
|
|
mod16->dwCallback = mod32->dwCallback;
|
|
mod16->dwInstance = mod32->dwInstance;
|
|
mod16->dnDevNode = mod32->dnDevNode;
|
|
mod16->cIds = mod32->cIds;
|
|
memcpy(&mod16->rgIds, &mod32->rgIds, mod32->cIds * sizeof(MIDIOPENSTRMID));
|
|
|
|
*lpParam1 = (DWORD)segptr + sizeof(LPMIDIOPENDESC) + 2*sizeof(DWORD);
|
|
*lpdwUser = (DWORD)segptr + sizeof(LPMIDIOPENDESC) + sizeof(DWORD);
|
|
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case MODM_GETVOLUME:
|
|
case MODM_CACHEPATCHES:
|
|
case MODM_CACHEDRUMPATCHES:
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_MidiOut_UnMap32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_MidiOut_UnMap32WTo16(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
WINMM_MapType ret = WINMM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case MODM_CLOSE:
|
|
case MODM_GETNUMDEVS:
|
|
case MODM_DATA:
|
|
case MODM_RESET:
|
|
case MODM_SETVOLUME:
|
|
ret = WINMM_MAP_OK;
|
|
break;
|
|
case MODM_GETDEVCAPS:
|
|
{
|
|
LPMIDIOUTCAPS16 moc16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)moc16 - sizeof(LPMIDIOUTCAPSW);
|
|
LPMIDIOUTCAPSW moc32 = *(LPMIDIOUTCAPSW*)ptr;
|
|
|
|
moc32->wMid = moc16->wMid;
|
|
moc32->wPid = moc16->wPid;
|
|
moc32->vDriverVersion = moc16->vDriverVersion;
|
|
WideCharToMultiByte( CP_ACP, 0, moc32->szPname, -1, moc16->szPname,
|
|
sizeof(moc16->szPname), NULL, NULL );
|
|
moc32->wTechnology = moc16->wTechnology;
|
|
moc32->wVoices = moc16->wVoices;
|
|
moc32->wNotes = moc16->wNotes;
|
|
moc32->wChannelMask = moc16->wChannelMask;
|
|
moc32->dwSupport = moc16->dwSupport;
|
|
UnMapLS( *lpParam1 );
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case MODM_PREPARE:
|
|
case MODM_UNPREPARE:
|
|
case MODM_LONGDATA:
|
|
{
|
|
LPMIDIHDR mh16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)mh16 - sizeof(LPMIDIHDR);
|
|
LPMIDIHDR mh32 = *(LPMIDIHDR*)ptr;
|
|
|
|
assert(mh32->lpNext == mh16);
|
|
UnMapLS( *lpParam1 );
|
|
mh32->dwBytesRecorded = mh16->dwBytesRecorded;
|
|
mh32->dwUser = mh16->dwUser;
|
|
mh32->dwFlags = mh16->dwFlags;
|
|
|
|
if (wMsg == MODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
mh32->lpNext = 0;
|
|
}
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case MODM_OPEN:
|
|
{
|
|
LPMIDIOPENDESC16 mod16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)mod16 - sizeof(LPMIDIOPENDESC) - 2*sizeof(DWORD);
|
|
UnMapLS( *lpParam1 );
|
|
**(DWORD**)(ptr + sizeof(LPMIDIOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPMIDIOPENDESC) + sizeof(DWORD));
|
|
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case MODM_GETVOLUME:
|
|
case MODM_CACHEPATCHES:
|
|
case MODM_CACHEDRUMPATCHES:
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_MidiOut_Callback [internal]
|
|
*/
|
|
static void CALLBACK MMDRV_MidiOut_Callback(HDRVR hDev, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
{
|
|
LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
|
|
|
|
switch (uMsg) {
|
|
case MOM_OPEN:
|
|
case MOM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
break;
|
|
case MOM_DONE:
|
|
if (!MMDRV_Is32(mld->mmdIndex)) {
|
|
/* initial map is: 32 => 16 */
|
|
LPMIDIHDR mh16 = MapSL(dwParam1);
|
|
LPMIDIHDR mh32 = *(LPMIDIHDR*)((LPSTR)mh16 - sizeof(LPMIDIHDR));
|
|
|
|
dwParam1 = (DWORD)mh32;
|
|
mh32->dwFlags = mh16->dwFlags;
|
|
mh32->dwOffset = mh16->dwOffset;
|
|
if (mh32->reserved >= sizeof(MIDIHDR))
|
|
mh32->dwOffset = mh16->dwOffset;
|
|
}
|
|
/* else { 32 => 32, nothing to do, same struct is kept }*/
|
|
break;
|
|
/* case MOM_POSITIONCB: */
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
|
|
MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_MidiOut_MapCB
|
|
*/
|
|
static void MMSYSTDRV_MidiOut_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
|
|
{
|
|
switch (uMsg) {
|
|
case MOM_OPEN:
|
|
case MOM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
break;
|
|
case MOM_DONE:
|
|
{
|
|
/* initial map is: 16 => 32 */
|
|
LPMIDIHDR mh32 = (LPMIDIHDR)(*dwParam1);
|
|
SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR));
|
|
LPMIDIHDR mh16 = MapSL(segmh16);
|
|
|
|
*dwParam1 = (DWORD)segmh16;
|
|
mh16->dwFlags = mh32->dwFlags;
|
|
if (mh16->reserved >= sizeof(MIDIHDR))
|
|
mh16->dwOffset = mh32->dwOffset;
|
|
}
|
|
break;
|
|
case MOM_POSITIONCB:
|
|
FIXME("NIY\n");
|
|
/* FIXME: would require to recreate a 16bit MIDIHDR here */
|
|
*dwParam1 = *dwParam2 = 0;
|
|
break;
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
}
|
|
|
|
/* =================================
|
|
* W A V E I N M A P P E R S
|
|
* ================================= */
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_WaveIn_Map16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_WaveIn_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case WIDM_GETNUMDEVS:
|
|
case WIDM_RESET:
|
|
case WIDM_START:
|
|
case WIDM_STOP:
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
case WIDM_OPEN:
|
|
case WIDM_CLOSE:
|
|
FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
|
|
break;
|
|
case WIDM_GETDEVCAPS:
|
|
{
|
|
LPWAVEINCAPSW wic32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEINCAPS16) + sizeof(WAVEINCAPSW));
|
|
LPWAVEINCAPS16 wic16 = MapSL(*lpParam1);
|
|
|
|
if (wic32) {
|
|
*(LPWAVEINCAPS16*)wic32 = wic16;
|
|
wic32 = (LPWAVEINCAPSW)((LPSTR)wic32 + sizeof(LPWAVEINCAPS16));
|
|
*lpParam1 = (DWORD)wic32;
|
|
*lpParam2 = sizeof(WAVEINCAPSW);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WIDM_GETPOS:
|
|
{
|
|
LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
|
|
LPMMTIME16 mmt16 = MapSL(*lpParam1);
|
|
|
|
if (mmt32) {
|
|
*(LPMMTIME16*)mmt32 = mmt16;
|
|
mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
|
|
|
|
mmt32->wType = mmt16->wType;
|
|
*lpParam1 = (DWORD)mmt32;
|
|
*lpParam2 = sizeof(MMTIME);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WIDM_PREPARE:
|
|
{
|
|
LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
|
|
LPWAVEHDR wh16 = MapSL(*lpParam1);
|
|
|
|
if (wh32) {
|
|
*(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
|
|
wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
|
|
wh32->lpData = MapSL((SEGPTR)wh16->lpData);
|
|
wh32->dwBufferLength = wh16->dwBufferLength;
|
|
wh32->dwBytesRecorded = wh16->dwBytesRecorded;
|
|
wh32->dwUser = wh16->dwUser;
|
|
wh32->dwFlags = wh16->dwFlags;
|
|
wh32->dwLoops = wh16->dwLoops;
|
|
/* FIXME: nothing on wh32->lpNext */
|
|
/* could link the wh32->lpNext at this level for memory house keeping */
|
|
wh16->lpNext = wh32; /* for reuse in unprepare and write */
|
|
*lpParam1 = (DWORD)wh32;
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WIDM_ADDBUFFER:
|
|
case WIDM_UNPREPARE:
|
|
{
|
|
LPWAVEHDR wh16 = MapSL(*lpParam1);
|
|
LPWAVEHDR wh32 = wh16->lpNext;
|
|
|
|
*lpParam1 = (DWORD)wh32;
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
/* dwBufferLength can be reduced between prepare & write */
|
|
if (wMsg == WIDM_ADDBUFFER && wh32->dwBufferLength < wh16->dwBufferLength) {
|
|
ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
|
|
wh32->dwBufferLength, wh16->dwBufferLength);
|
|
} else
|
|
wh32->dwBufferLength = wh16->dwBufferLength;
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
case WIDM_MAPPER_STATUS:
|
|
/* just a single DWORD */
|
|
*lpParam2 = (DWORD)MapSL(*lpParam2);
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_WaveIn_UnMap16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_WaveIn_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case WIDM_GETNUMDEVS:
|
|
case WIDM_RESET:
|
|
case WIDM_START:
|
|
case WIDM_STOP:
|
|
case WIDM_MAPPER_STATUS:
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
case WIDM_OPEN:
|
|
case WIDM_CLOSE:
|
|
FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
|
|
break;
|
|
case WIDM_GETDEVCAPS:
|
|
{
|
|
LPWAVEINCAPSW wic32 = (LPWAVEINCAPSW)(*lpParam1);
|
|
LPWAVEINCAPS16 wic16 = *(LPWAVEINCAPS16*)((LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
|
|
|
|
wic16->wMid = wic32->wMid;
|
|
wic16->wPid = wic32->wPid;
|
|
wic16->vDriverVersion = wic32->vDriverVersion;
|
|
WideCharToMultiByte( CP_ACP, 0, wic32->szPname, -1, wic16->szPname,
|
|
sizeof(wic16->szPname), NULL, NULL );
|
|
wic16->dwFormats = wic32->dwFormats;
|
|
wic16->wChannels = wic32->wChannels;
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)wic32 - sizeof(LPWAVEINCAPS16));
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
case WIDM_GETPOS:
|
|
{
|
|
LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
|
|
LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
|
|
|
|
MMSYSTEM_MMTIME32to16(mmt16, mmt32);
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
case WIDM_ADDBUFFER:
|
|
case WIDM_PREPARE:
|
|
case WIDM_UNPREPARE:
|
|
{
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
|
|
LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
|
|
|
|
assert(wh16->lpNext == wh32);
|
|
wh16->dwBufferLength = wh32->dwBufferLength;
|
|
wh16->dwBytesRecorded = wh32->dwBytesRecorded;
|
|
wh16->dwUser = wh32->dwUser;
|
|
wh16->dwFlags = wh32->dwFlags;
|
|
wh16->dwLoops = wh32->dwLoops;
|
|
|
|
if (wMsg == WIDM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
|
|
wh16->lpNext = 0;
|
|
}
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_WaveIn_Map32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_WaveIn_Map32WTo16 (UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
WINMM_MapType ret = WINMM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case WIDM_CLOSE:
|
|
case WIDM_GETNUMDEVS:
|
|
case WIDM_RESET:
|
|
case WIDM_START:
|
|
case WIDM_STOP:
|
|
ret = WINMM_MAP_OK;
|
|
break;
|
|
|
|
case WIDM_OPEN:
|
|
{
|
|
LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
|
|
int sz = sizeof(WAVEFORMATEX);
|
|
LPVOID ptr;
|
|
LPWAVEOPENDESC16 wod16;
|
|
|
|
/* allocated data are mapped as follows:
|
|
LPWAVEOPENDESC ptr to orig lParam1
|
|
DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
|
|
DWORD dwUser passed to driver
|
|
WAVEOPENDESC16 wod16: openDesc passed to driver
|
|
WAVEFORMATEX openDesc->lpFormat passed to driver
|
|
xxx extra bytes to WAVEFORMATEX
|
|
*/
|
|
if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
|
|
TRACE("Allocating %u extra bytes (%d)\n", wod32->lpFormat->cbSize, wod32->lpFormat->wFormatTag);
|
|
sz += wod32->lpFormat->cbSize;
|
|
}
|
|
|
|
ptr = HeapAlloc( GetProcessHeap(), 0,
|
|
sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
|
|
|
|
if (ptr) {
|
|
SEGPTR seg_ptr = MapLS( ptr );
|
|
*(LPWAVEOPENDESC*)ptr = wod32;
|
|
*(LPDWORD)((char*)ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
|
|
wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
|
|
|
|
wod16->hWave = HWAVE_16(wod32->hWave);
|
|
wod16->lpFormat = (LPWAVEFORMATEX)(seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
|
|
memcpy(wod16 + 1, wod32->lpFormat, sz);
|
|
|
|
wod16->dwCallback = wod32->dwCallback;
|
|
wod16->dwInstance = wod32->dwInstance;
|
|
wod16->uMappedDeviceID = wod32->uMappedDeviceID;
|
|
wod16->dnDevNode = wod32->dnDevNode;
|
|
|
|
*lpParam1 = seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
|
|
*lpdwUser = seg_ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
|
|
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WIDM_PREPARE:
|
|
{
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
|
|
LPWAVEHDR wh16;
|
|
LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
|
|
sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
|
|
|
|
if (ptr) {
|
|
SEGPTR seg_ptr = MapLS( ptr );
|
|
*(LPWAVEHDR*)ptr = wh32;
|
|
wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
|
|
wh16->lpData = (LPSTR)seg_ptr + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
|
|
/* data will be copied on WODM_WRITE */
|
|
wh16->dwBufferLength = wh32->dwBufferLength;
|
|
wh16->dwBytesRecorded = wh32->dwBytesRecorded;
|
|
wh16->dwUser = wh32->dwUser;
|
|
wh16->dwFlags = wh32->dwFlags;
|
|
wh16->dwLoops = wh32->dwLoops;
|
|
/* FIXME: nothing on wh32->lpNext */
|
|
/* could link the wh32->lpNext at this level for memory house keeping */
|
|
wh32->lpNext = wh16; /* for reuse in unprepare and write */
|
|
*lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
TRACE("wh16=%08lx wh16->lpData=%p wh32->buflen=%u wh32->lpData=%p\n",
|
|
*lpParam1, wh16->lpData, wh32->dwBufferLength, wh32->lpData);
|
|
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WIDM_ADDBUFFER:
|
|
case WIDM_UNPREPARE:
|
|
{
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
|
|
LPWAVEHDR wh16 = wh32->lpNext;
|
|
LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
|
|
SEGPTR seg_ptr = MapLS( ptr );
|
|
|
|
assert(*(LPWAVEHDR*)ptr == wh32);
|
|
|
|
if (wMsg == WIDM_ADDBUFFER)
|
|
memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
|
|
|
|
*lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
TRACE("wh16=%08lx wh16->lpData=%p wh32->buflen=%u wh32->lpData=%p\n",
|
|
*lpParam1, wh16->lpData, wh32->dwBufferLength, wh32->lpData);
|
|
|
|
/* dwBufferLength can be reduced between prepare & write */
|
|
if (wMsg == WIDM_ADDBUFFER && wh16->dwBufferLength < wh32->dwBufferLength) {
|
|
ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
|
|
wh16->dwBufferLength, wh32->dwBufferLength);
|
|
} else
|
|
wh16->dwBufferLength = wh32->dwBufferLength;
|
|
ret = WINMM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
case WIDM_GETDEVCAPS:
|
|
{
|
|
LPWAVEINCAPSW wic32 = (LPWAVEINCAPSW)*lpParam1;
|
|
LPSTR ptr = HeapAlloc( GetProcessHeap(), 0 ,sizeof(LPWAVEINCAPSW) + sizeof(WAVEINCAPS16));
|
|
|
|
if (ptr) {
|
|
*(LPWAVEINCAPSW*)ptr = wic32;
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
*lpParam1 = MapLS(ptr) + sizeof(LPWAVEINCAPSW);
|
|
*lpParam2 = sizeof(WAVEINCAPS16);
|
|
}
|
|
break;
|
|
case WIDM_GETPOS:
|
|
{
|
|
LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
|
|
LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMMTIME) + sizeof(MMTIME16));
|
|
LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
|
|
|
|
if (ptr) {
|
|
*(LPMMTIME*)ptr = mmt32;
|
|
mmt16->wType = mmt32->wType;
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
*lpParam1 = MapLS(ptr) + sizeof(LPMMTIME);
|
|
*lpParam2 = sizeof(MMTIME16);
|
|
}
|
|
break;
|
|
case DRVM_MAPPER_STATUS:
|
|
{
|
|
LPDWORD p32 = (LPDWORD)*lpParam2;
|
|
*lpParam2 = MapLS(p32);
|
|
ret = WINMM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_WaveIn_UnMap32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_WaveIn_UnMap32WTo16(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
WINMM_MapType ret = WINMM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
case WIDM_CLOSE:
|
|
case WIDM_GETNUMDEVS:
|
|
case WIDM_RESET:
|
|
case WIDM_START:
|
|
case WIDM_STOP:
|
|
ret = WINMM_MAP_OK;
|
|
break;
|
|
|
|
case WIDM_OPEN:
|
|
{
|
|
LPWAVEOPENDESC16 wod16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
|
|
LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
|
|
|
|
UnMapLS( *lpParam1 );
|
|
wod32->uMappedDeviceID = wod16->uMappedDeviceID;
|
|
**(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
|
|
case WIDM_ADDBUFFER:
|
|
case WIDM_PREPARE:
|
|
case WIDM_UNPREPARE:
|
|
{
|
|
LPWAVEHDR wh16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
|
|
LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
|
|
|
|
assert(wh32->lpNext == wh16);
|
|
wh32->dwBytesRecorded = wh16->dwBytesRecorded;
|
|
wh32->dwUser = wh16->dwUser;
|
|
wh32->dwFlags = wh16->dwFlags;
|
|
wh32->dwLoops = wh16->dwLoops;
|
|
UnMapLS( *lpParam1 );
|
|
|
|
if (wMsg == WIDM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
wh32->lpNext = 0;
|
|
}
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case WIDM_GETDEVCAPS:
|
|
{
|
|
LPWAVEINCAPS16 wic16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)wic16 - sizeof(LPWAVEINCAPSW);
|
|
LPWAVEINCAPSW wic32 = *(LPWAVEINCAPSW*)ptr;
|
|
|
|
wic32->wMid = wic16->wMid;
|
|
wic32->wPid = wic16->wPid;
|
|
wic32->vDriverVersion = wic16->vDriverVersion;
|
|
WideCharToMultiByte( CP_ACP, 0, wic32->szPname, -1, wic16->szPname,
|
|
sizeof(wic16->szPname), NULL, NULL );
|
|
wic32->dwFormats = wic16->dwFormats;
|
|
wic32->wChannels = wic16->wChannels;
|
|
UnMapLS( *lpParam1 );
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case WIDM_GETPOS:
|
|
{
|
|
LPMMTIME16 mmt16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
|
|
LPMMTIME mmt32 = *(LPMMTIME*)ptr;
|
|
|
|
WINMM_MMTIME16to32(mmt32, mmt16);
|
|
UnMapLS( *lpParam1 );
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case DRVM_MAPPER_STATUS:
|
|
{
|
|
UnMapLS( *lpParam2 );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_WaveIn_Callback [internal]
|
|
*/
|
|
static void CALLBACK MMDRV_WaveIn_Callback(HDRVR hDev, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
{
|
|
LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
|
|
|
|
switch (uMsg) {
|
|
case WIM_OPEN:
|
|
case WIM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
break;
|
|
case WIM_DATA:
|
|
if (!MMDRV_Is32(mld->mmdIndex)) {
|
|
/* initial map is: 32 => 16 */
|
|
LPWAVEHDR wh16 = MapSL(dwParam1);
|
|
LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
|
|
|
|
dwParam1 = (DWORD)wh32;
|
|
wh32->dwFlags = wh16->dwFlags;
|
|
wh32->dwBytesRecorded = wh16->dwBytesRecorded;
|
|
}
|
|
/* else { 32 => 32, nothing to do, same struct is kept }*/
|
|
break;
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
|
|
MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_WaveIn_MapCB [internal]
|
|
*/
|
|
static void MMSYSTDRV_WaveIn_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
|
|
{
|
|
switch (uMsg) {
|
|
case WIM_OPEN:
|
|
case WIM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
break;
|
|
case WIM_DATA:
|
|
{
|
|
/* initial map is: 16 => 32 */
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)(*dwParam1);
|
|
SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
|
|
LPWAVEHDR wh16 = MapSL(segwh16);
|
|
|
|
*dwParam1 = (DWORD)segwh16;
|
|
wh16->dwFlags = wh32->dwFlags;
|
|
wh16->dwBytesRecorded = wh32->dwBytesRecorded;
|
|
}
|
|
break;
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
}
|
|
|
|
/* =================================
|
|
* W A V E O U T M A P P E R S
|
|
* ================================= */
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_WaveOut_Map16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_WaveOut_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
/* nothing to do */
|
|
case WODM_BREAKLOOP:
|
|
case WODM_CLOSE:
|
|
case WODM_GETNUMDEVS:
|
|
case WODM_PAUSE:
|
|
case WODM_RESET:
|
|
case WODM_RESTART:
|
|
case WODM_SETPITCH:
|
|
case WODM_SETPLAYBACKRATE:
|
|
case WODM_SETVOLUME:
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
|
|
case WODM_GETPITCH:
|
|
case WODM_GETPLAYBACKRATE:
|
|
case WODM_GETVOLUME:
|
|
case WODM_OPEN:
|
|
FIXME("Shouldn't be used: the corresponding 16 bit functions use the 32 bit interface\n");
|
|
break;
|
|
|
|
case WODM_GETDEVCAPS:
|
|
{
|
|
LPWAVEOUTCAPSW woc32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEOUTCAPS16) + sizeof(WAVEOUTCAPSW));
|
|
LPWAVEOUTCAPS16 woc16 = MapSL(*lpParam1);
|
|
|
|
if (woc32) {
|
|
*(LPWAVEOUTCAPS16*)woc32 = woc16;
|
|
woc32 = (LPWAVEOUTCAPSW)((LPSTR)woc32 + sizeof(LPWAVEOUTCAPS16));
|
|
*lpParam1 = (DWORD)woc32;
|
|
*lpParam2 = sizeof(WAVEOUTCAPSW);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WODM_GETPOS:
|
|
{
|
|
LPMMTIME mmt32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMMTIME16) + sizeof(MMTIME));
|
|
LPMMTIME16 mmt16 = MapSL(*lpParam1);
|
|
|
|
if (mmt32) {
|
|
*(LPMMTIME16*)mmt32 = mmt16;
|
|
mmt32 = (LPMMTIME)((LPSTR)mmt32 + sizeof(LPMMTIME16));
|
|
|
|
mmt32->wType = mmt16->wType;
|
|
*lpParam1 = (DWORD)mmt32;
|
|
*lpParam2 = sizeof(MMTIME);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WODM_PREPARE:
|
|
{
|
|
LPWAVEHDR wh32 = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWAVEHDR) + sizeof(WAVEHDR));
|
|
LPWAVEHDR wh16 = MapSL(*lpParam1);
|
|
|
|
if (wh32) {
|
|
*(LPWAVEHDR*)wh32 = (LPWAVEHDR)*lpParam1;
|
|
wh32 = (LPWAVEHDR)((LPSTR)wh32 + sizeof(LPWAVEHDR));
|
|
wh32->lpData = MapSL((SEGPTR)wh16->lpData);
|
|
wh32->dwBufferLength = wh16->dwBufferLength;
|
|
wh32->dwBytesRecorded = wh16->dwBytesRecorded;
|
|
wh32->dwUser = wh16->dwUser;
|
|
wh32->dwFlags = wh16->dwFlags;
|
|
wh32->dwLoops = wh16->dwLoops;
|
|
/* FIXME: nothing on wh32->lpNext */
|
|
/* could link the wh32->lpNext at this level for memory house keeping */
|
|
wh16->lpNext = wh32; /* for reuse in unprepare and write */
|
|
*lpParam1 = (DWORD)wh32;
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
} else {
|
|
ret = MMSYSTEM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WODM_UNPREPARE:
|
|
case WODM_WRITE:
|
|
{
|
|
LPWAVEHDR wh16 = MapSL(*lpParam1);
|
|
LPWAVEHDR wh32 = wh16->lpNext;
|
|
|
|
*lpParam1 = (DWORD)wh32;
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
/* dwBufferLength can be reduced between prepare & write */
|
|
if (wMsg == WODM_WRITE && wh32->dwBufferLength < wh16->dwBufferLength) {
|
|
ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
|
|
wh32->dwBufferLength, wh16->dwBufferLength);
|
|
} else
|
|
wh32->dwBufferLength = wh16->dwBufferLength;
|
|
ret = MMSYSTEM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
case WODM_MAPPER_STATUS:
|
|
*lpParam2 = (DWORD)MapSL(*lpParam2);
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMSYSTDRV_WaveOut_UnMap16To32W [internal]
|
|
*/
|
|
static MMSYSTEM_MapType MMSYSTDRV_WaveOut_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR;
|
|
|
|
switch (wMsg) {
|
|
/* nothing to do */
|
|
case WODM_BREAKLOOP:
|
|
case WODM_CLOSE:
|
|
case WODM_GETNUMDEVS:
|
|
case WODM_PAUSE:
|
|
case WODM_RESET:
|
|
case WODM_RESTART:
|
|
case WODM_SETPITCH:
|
|
case WODM_SETPLAYBACKRATE:
|
|
case WODM_SETVOLUME:
|
|
case WODM_MAPPER_STATUS:
|
|
ret = MMSYSTEM_MAP_OK;
|
|
break;
|
|
|
|
case WODM_GETPITCH:
|
|
case WODM_GETPLAYBACKRATE:
|
|
case WODM_GETVOLUME:
|
|
case WODM_OPEN:
|
|
FIXME("Shouldn't be used: those 16 bit functions use the 32 bit interface\n");
|
|
break;
|
|
|
|
case WODM_GETDEVCAPS:
|
|
{
|
|
LPWAVEOUTCAPSW woc32 = (LPWAVEOUTCAPSW)(*lpParam1);
|
|
LPWAVEOUTCAPS16 woc16 = *(LPWAVEOUTCAPS16*)((LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
|
|
|
|
woc16->wMid = woc32->wMid;
|
|
woc16->wPid = woc32->wPid;
|
|
woc16->vDriverVersion = woc32->vDriverVersion;
|
|
WideCharToMultiByte( CP_ACP, 0, woc32->szPname, -1, woc16->szPname,
|
|
sizeof(woc16->szPname), NULL, NULL );
|
|
woc16->dwFormats = woc32->dwFormats;
|
|
woc16->wChannels = woc32->wChannels;
|
|
woc16->dwSupport = woc32->dwSupport;
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)woc32 - sizeof(LPWAVEOUTCAPS16));
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
case WODM_GETPOS:
|
|
{
|
|
LPMMTIME mmt32 = (LPMMTIME)(*lpParam1);
|
|
LPMMTIME16 mmt16 = *(LPMMTIME16*)((LPSTR)mmt32 - sizeof(LPMMTIME16));
|
|
|
|
MMSYSTEM_MMTIME32to16(mmt16, mmt32);
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)mmt32 - sizeof(LPMMTIME16));
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
case WODM_PREPARE:
|
|
case WODM_UNPREPARE:
|
|
case WODM_WRITE:
|
|
{
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
|
|
LPWAVEHDR wh16 = MapSL(*(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR)));
|
|
|
|
assert(wh16->lpNext == wh32);
|
|
wh16->dwBufferLength = wh32->dwBufferLength;
|
|
wh16->dwBytesRecorded = wh32->dwBytesRecorded;
|
|
wh16->dwUser = wh32->dwUser;
|
|
wh16->dwFlags = wh32->dwFlags;
|
|
wh16->dwLoops = wh32->dwLoops;
|
|
|
|
if (wMsg == WODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
|
|
HeapFree(GetProcessHeap(), 0, (LPSTR)wh32 - sizeof(LPWAVEHDR));
|
|
wh16->lpNext = 0;
|
|
}
|
|
ret = MMSYSTEM_MAP_OK;
|
|
}
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet for %u [%lx,%lx]\n", wMsg, *lpParam1, *lpParam2);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_WaveOut_Map32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_WaveOut_Map32WTo16 (UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2)
|
|
{
|
|
WINMM_MapType ret;
|
|
|
|
switch (wMsg) {
|
|
/* nothing to do */
|
|
case WODM_BREAKLOOP:
|
|
case WODM_CLOSE:
|
|
case WODM_GETNUMDEVS:
|
|
case WODM_PAUSE:
|
|
case WODM_RESET:
|
|
case WODM_RESTART:
|
|
case WODM_SETPITCH:
|
|
case WODM_SETPLAYBACKRATE:
|
|
case WODM_SETVOLUME:
|
|
ret = WINMM_MAP_OK;
|
|
break;
|
|
|
|
case WODM_GETDEVCAPS:
|
|
{
|
|
LPWAVEOUTCAPSW woc32 = (LPWAVEOUTCAPSW)*lpParam1;
|
|
LPSTR ptr = HeapAlloc( GetProcessHeap(), 0,
|
|
sizeof(LPWAVEOUTCAPSW) + sizeof(WAVEOUTCAPS16));
|
|
|
|
if (ptr) {
|
|
*(LPWAVEOUTCAPSW*)ptr = woc32;
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
*lpParam1 = MapLS(ptr) + sizeof(LPWAVEOUTCAPSW);
|
|
*lpParam2 = sizeof(WAVEOUTCAPS16);
|
|
}
|
|
break;
|
|
case WODM_GETPITCH:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
case WODM_GETPLAYBACKRATE:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
case WODM_GETPOS:
|
|
{
|
|
LPMMTIME mmt32 = (LPMMTIME)*lpParam1;
|
|
LPSTR ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPMMTIME) + sizeof(MMTIME16));
|
|
LPMMTIME16 mmt16 = (LPMMTIME16)(ptr + sizeof(LPMMTIME));
|
|
|
|
if (ptr) {
|
|
*(LPMMTIME*)ptr = mmt32;
|
|
mmt16->wType = mmt32->wType;
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
*lpParam1 = MapLS(ptr) + sizeof(LPMMTIME);
|
|
*lpParam2 = sizeof(MMTIME16);
|
|
}
|
|
break;
|
|
case WODM_GETVOLUME:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
case WODM_OPEN:
|
|
{
|
|
LPWAVEOPENDESC wod32 = (LPWAVEOPENDESC)*lpParam1;
|
|
int sz = sizeof(WAVEFORMATEX);
|
|
LPVOID ptr;
|
|
LPWAVEOPENDESC16 wod16;
|
|
|
|
/* allocated data are mapped as follows:
|
|
LPWAVEOPENDESC ptr to orig lParam1
|
|
DWORD orig dwUser, which is a pointer to DWORD:driver dwInstance
|
|
DWORD dwUser passed to driver
|
|
WAVEOPENDESC16 wod16: openDesc passed to driver
|
|
WAVEFORMATEX openDesc->lpFormat passed to driver
|
|
xxx extra bytes to WAVEFORMATEX
|
|
*/
|
|
if (wod32->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
|
|
TRACE("Allocating %u extra bytes (%d)\n", wod32->lpFormat->cbSize, wod32->lpFormat->wFormatTag);
|
|
sz += wod32->lpFormat->cbSize;
|
|
}
|
|
|
|
ptr = HeapAlloc( GetProcessHeap(), 0,
|
|
sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16) + sz);
|
|
|
|
if (ptr) {
|
|
SEGPTR seg_ptr = MapLS( ptr );
|
|
*(LPWAVEOPENDESC*)ptr = wod32;
|
|
*(LPDWORD)((char*)ptr + sizeof(LPWAVEOPENDESC)) = *lpdwUser;
|
|
wod16 = (LPWAVEOPENDESC16)((LPSTR)ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD));
|
|
|
|
wod16->hWave = HWAVE_16(wod32->hWave);
|
|
wod16->lpFormat = (LPWAVEFORMATEX)(seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD) + sizeof(WAVEOPENDESC16));
|
|
memcpy(wod16 + 1, wod32->lpFormat, sz);
|
|
|
|
wod16->dwCallback = wod32->dwCallback;
|
|
wod16->dwInstance = wod32->dwInstance;
|
|
wod16->uMappedDeviceID = wod32->uMappedDeviceID;
|
|
wod16->dnDevNode = wod32->dnDevNode;
|
|
|
|
*lpParam1 = seg_ptr + sizeof(LPWAVEOPENDESC) + 2*sizeof(DWORD);
|
|
*lpdwUser = seg_ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD);
|
|
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WODM_PREPARE:
|
|
{
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)*lpParam1;
|
|
LPWAVEHDR wh16;
|
|
LPVOID ptr = HeapAlloc( GetProcessHeap(), 0,
|
|
sizeof(LPWAVEHDR) + sizeof(WAVEHDR) + wh32->dwBufferLength);
|
|
|
|
if (ptr) {
|
|
SEGPTR seg_ptr = MapLS( ptr );
|
|
*(LPWAVEHDR*)ptr = wh32;
|
|
wh16 = (LPWAVEHDR)((LPSTR)ptr + sizeof(LPWAVEHDR));
|
|
wh16->lpData = (LPSTR)seg_ptr + sizeof(LPWAVEHDR) + sizeof(WAVEHDR);
|
|
/* data will be copied on WODM_WRITE */
|
|
wh16->dwBufferLength = wh32->dwBufferLength;
|
|
wh16->dwBytesRecorded = wh32->dwBytesRecorded;
|
|
wh16->dwUser = wh32->dwUser;
|
|
wh16->dwFlags = wh32->dwFlags;
|
|
wh16->dwLoops = wh32->dwLoops;
|
|
/* FIXME: nothing on wh32->lpNext */
|
|
/* could link the wh32->lpNext at this level for memory house keeping */
|
|
wh32->lpNext = wh16; /* for reuse in unprepare and write */
|
|
*lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
TRACE("wh16=%08lx wh16->lpData=%p wh32->buflen=%u wh32->lpData=%p\n",
|
|
*lpParam1, wh16->lpData, wh32->dwBufferLength, wh32->lpData);
|
|
|
|
ret = WINMM_MAP_OKMEM;
|
|
} else {
|
|
ret = WINMM_MAP_NOMEM;
|
|
}
|
|
}
|
|
break;
|
|
case WODM_UNPREPARE:
|
|
case WODM_WRITE:
|
|
{
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)(*lpParam1);
|
|
LPWAVEHDR wh16 = wh32->lpNext;
|
|
LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
|
|
SEGPTR seg_ptr = MapLS( ptr );
|
|
|
|
assert(*(LPWAVEHDR*)ptr == wh32);
|
|
|
|
if (wMsg == WODM_WRITE)
|
|
memcpy((LPSTR)wh16 + sizeof(WAVEHDR), wh32->lpData, wh32->dwBufferLength);
|
|
|
|
*lpParam1 = seg_ptr + sizeof(LPWAVEHDR);
|
|
*lpParam2 = sizeof(WAVEHDR);
|
|
TRACE("wh16=%08lx wh16->lpData=%p wh32->buflen=%u wh32->lpData=%p\n",
|
|
*lpParam1, wh16->lpData, wh32->dwBufferLength, wh32->lpData);
|
|
|
|
/* dwBufferLength can be reduced between prepare & write */
|
|
if (wMsg == WODM_WRITE && wh16->dwBufferLength < wh32->dwBufferLength) {
|
|
ERR("Size of buffer has been increased from %d to %d, keeping initial value\n",
|
|
wh16->dwBufferLength, wh32->dwBufferLength);
|
|
} else
|
|
wh16->dwBufferLength = wh32->dwBufferLength;
|
|
ret = WINMM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
case DRVM_MAPPER_STATUS:
|
|
{
|
|
LPDWORD p32 = (LPDWORD)*lpParam2;
|
|
*lpParam2 = MapLS(p32);
|
|
ret = WINMM_MAP_OKMEM;
|
|
}
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_WaveOut_UnMap32WTo16 [internal]
|
|
*/
|
|
static WINMM_MapType MMDRV_WaveOut_UnMap32WTo16(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret)
|
|
{
|
|
WINMM_MapType ret;
|
|
|
|
switch (wMsg) {
|
|
/* nothing to do */
|
|
case WODM_BREAKLOOP:
|
|
case WODM_CLOSE:
|
|
case WODM_GETNUMDEVS:
|
|
case WODM_PAUSE:
|
|
case WODM_RESET:
|
|
case WODM_RESTART:
|
|
case WODM_SETPITCH:
|
|
case WODM_SETPLAYBACKRATE:
|
|
case WODM_SETVOLUME:
|
|
ret = WINMM_MAP_OK;
|
|
break;
|
|
|
|
case WODM_GETDEVCAPS:
|
|
{
|
|
LPWAVEOUTCAPS16 woc16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)woc16 - sizeof(LPWAVEOUTCAPSW);
|
|
LPWAVEOUTCAPSW woc32 = *(LPWAVEOUTCAPSW*)ptr;
|
|
|
|
woc32->wMid = woc16->wMid;
|
|
woc32->wPid = woc16->wPid;
|
|
woc32->vDriverVersion = woc16->vDriverVersion;
|
|
WideCharToMultiByte( CP_ACP, 0, woc32->szPname, -1, woc16->szPname,
|
|
sizeof(woc16->szPname), NULL, NULL );
|
|
woc32->dwFormats = woc16->dwFormats;
|
|
woc32->wChannels = woc16->wChannels;
|
|
woc32->dwSupport = woc16->dwSupport;
|
|
UnMapLS( *lpParam1 );
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case WODM_GETPITCH:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
case WODM_GETPLAYBACKRATE:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
case WODM_GETPOS:
|
|
{
|
|
LPMMTIME16 mmt16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)mmt16 - sizeof(LPMMTIME);
|
|
LPMMTIME mmt32 = *(LPMMTIME*)ptr;
|
|
|
|
WINMM_MMTIME16to32(mmt32, mmt16);
|
|
UnMapLS( *lpParam1 );
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case WODM_OPEN:
|
|
{
|
|
LPWAVEOPENDESC16 wod16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)wod16 - sizeof(LPWAVEOPENDESC) - 2*sizeof(DWORD);
|
|
LPWAVEOPENDESC wod32 = *(LPWAVEOPENDESC*)ptr;
|
|
|
|
wod32->uMappedDeviceID = wod16->uMappedDeviceID;
|
|
**(DWORD**)(ptr + sizeof(LPWAVEOPENDESC)) = *(LPDWORD)(ptr + sizeof(LPWAVEOPENDESC) + sizeof(DWORD));
|
|
UnMapLS( *lpParam1 );
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case WODM_PREPARE:
|
|
case WODM_UNPREPARE:
|
|
case WODM_WRITE:
|
|
{
|
|
LPWAVEHDR wh16 = MapSL(*lpParam1);
|
|
LPSTR ptr = (LPSTR)wh16 - sizeof(LPWAVEHDR);
|
|
LPWAVEHDR wh32 = *(LPWAVEHDR*)ptr;
|
|
|
|
assert(wh32->lpNext == wh16);
|
|
wh32->dwBytesRecorded = wh16->dwBytesRecorded;
|
|
wh32->dwUser = wh16->dwUser;
|
|
wh32->dwFlags = wh16->dwFlags;
|
|
wh32->dwLoops = wh16->dwLoops;
|
|
|
|
UnMapLS( *lpParam1 );
|
|
if (wMsg == WODM_UNPREPARE && fn_ret == MMSYSERR_NOERROR) {
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
wh32->lpNext = 0;
|
|
}
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
case WODM_GETVOLUME:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
case DRVM_MAPPER_STATUS:
|
|
{
|
|
UnMapLS( *lpParam2 );
|
|
ret = WINMM_MAP_OK;
|
|
}
|
|
break;
|
|
default:
|
|
FIXME("NIY: no conversion yet\n");
|
|
ret = WINMM_MAP_MSGERROR;
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_WaveOut_Callback [internal]
|
|
*/
|
|
static void CALLBACK MMDRV_WaveOut_Callback(HDRVR hDev, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
{
|
|
LPWINE_MLD mld = (LPWINE_MLD)dwInstance;
|
|
|
|
switch (uMsg) {
|
|
case WOM_OPEN:
|
|
case WOM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
break;
|
|
case WOM_DONE:
|
|
if (!MMDRV_Is32(mld->mmdIndex)) {
|
|
/* initial map is: 32 => 16 */
|
|
LPWAVEHDR wh16 = MapSL(dwParam1);
|
|
LPWAVEHDR wh32 = *(LPWAVEHDR*)((LPSTR)wh16 - sizeof(LPWAVEHDR));
|
|
|
|
dwParam1 = (DWORD)wh32;
|
|
wh32->dwFlags = wh16->dwFlags;
|
|
}
|
|
/* else { 32 => 32, nothing to do, same struct is kept }*/
|
|
break;
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
|
|
MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2);
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_WaveOut_Callback [internal]
|
|
*/
|
|
static void MMSYSTDRV_WaveOut_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2)
|
|
{
|
|
switch (uMsg) {
|
|
case WOM_OPEN:
|
|
case WOM_CLOSE:
|
|
/* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
|
|
break;
|
|
case WOM_DONE:
|
|
{
|
|
/* initial map is: 16 => 32 */
|
|
LPWAVEHDR wh32 = (LPWAVEHDR)(*dwParam1);
|
|
SEGPTR segwh16 = *(SEGPTR*)((LPSTR)wh32 - sizeof(LPWAVEHDR));
|
|
LPWAVEHDR wh16 = MapSL(segwh16);
|
|
|
|
*dwParam1 = (DWORD)segwh16;
|
|
wh16->dwFlags = wh32->dwFlags;
|
|
}
|
|
break;
|
|
default:
|
|
ERR("Unknown msg %u\n", uMsg);
|
|
}
|
|
}
|
|
|
|
/* =================================
|
|
* M A P P E R S H A N D L I N G
|
|
* ================================= */
|
|
|
|
static LRESULT MMDRV_CallMMDrvFunc16(DWORD fp16, WORD dev, WORD msg, LONG instance,
|
|
LONG lp1, LONG lp2)
|
|
{
|
|
WORD args[8];
|
|
DWORD ret;
|
|
|
|
args[7] = dev;
|
|
args[6] = msg;
|
|
args[5] = HIWORD(instance);
|
|
args[4] = LOWORD(instance);
|
|
args[3] = HIWORD(lp1);
|
|
args[2] = LOWORD(lp1);
|
|
args[1] = HIWORD(lp2);
|
|
args[0] = LOWORD(lp2);
|
|
WOWCallback16Ex( fp16, WCB16_PASCAL, sizeof(args), args, &ret );
|
|
return LOWORD(ret);
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MMDRV_GetDescription16 [internal]
|
|
*/
|
|
static BOOL MMDRV_GetDescription16(const char* fname, char* buf, int buflen)
|
|
{
|
|
OFSTRUCT ofs;
|
|
HFILE hFile;
|
|
WORD w;
|
|
DWORD dw;
|
|
BOOL ret = FALSE;
|
|
|
|
if ((hFile = OpenFile(fname, &ofs, OF_READ | OF_SHARE_DENY_WRITE)) == HFILE_ERROR) {
|
|
ERR("Can't open file %s (builtin driver ?)\n", fname);
|
|
return FALSE;
|
|
}
|
|
|
|
#define E(_x) do {TRACE _x;goto theEnd;} while(0)
|
|
|
|
if (_lread(hFile, &w, 2) != 2) E(("Can't read sig\n"));
|
|
if (w != ('Z' * 256 + 'M')) E(("Bad sig %04x\n", w));
|
|
if (_llseek(hFile, 0x3C, SEEK_SET) < 0) E(("Can't seek to ext header offset\n"));
|
|
if (_lread(hFile, &dw, 4) != 4) E(("Can't read ext header offset\n"));
|
|
if (_llseek(hFile, dw + 0x2C, SEEK_SET) < 0) E(("Can't seek to ext header.nr table %u\n", dw+0x2C));
|
|
if (_lread(hFile, &dw, 4) != 4) E(("Can't read nr table offset\n"));
|
|
if (_llseek(hFile, dw, SEEK_SET) < 0) E(("Can't seek to nr table %u\n", dw));
|
|
if (_lread(hFile, buf, 1) != 1) E(("Can't read descr length\n"));
|
|
buflen = min((int)(unsigned)(BYTE)buf[0], buflen - 1);
|
|
if (_lread(hFile, buf, buflen) != buflen) E(("Can't read descr (%d)\n", buflen));
|
|
buf[buflen] = '\0';
|
|
ret = TRUE;
|
|
TRACE("Got '%s' [%d]\n", buf, buflen);
|
|
theEnd:
|
|
_lclose(hFile);
|
|
return ret;
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMDRV_LoadMMDrvFunc16
|
|
*
|
|
*/
|
|
static unsigned MMDRV_LoadMMDrvFunc16(LPCSTR drvName, LPWINE_DRIVER d,
|
|
LPWINE_MM_DRIVER lpDrv)
|
|
{
|
|
WINEMM_msgFunc16 func;
|
|
unsigned count = 0;
|
|
char buffer[128];
|
|
/*
|
|
* DESCRIPTION 'wave,aux,mixer:Creative Labs Sound Blaster 16 Driver'
|
|
* The beginning of the module description indicates the driver supports
|
|
* waveform, auxiliary, and mixer devices. Use one of the following
|
|
* device-type names, followed by a colon (:) to indicate the type of
|
|
* device your driver supports. If the driver supports more than one
|
|
* type of device, separate each device-type name with a comma (,).
|
|
*
|
|
* wave for waveform audio devices
|
|
* wavemapper for wave mappers
|
|
* midi for MIDI audio devices
|
|
* midimapper for midi mappers
|
|
* aux for auxiliary audio devices
|
|
* mixer for mixer devices
|
|
*/
|
|
|
|
if (d->d.d16.hDriver16) {
|
|
HMODULE16 hMod16 = GetDriverModuleHandle16(d->d.d16.hDriver16);
|
|
|
|
#define AA(_h,_w,_x,_y,_z) \
|
|
func = (WINEMM_msgFunc##_y) _z ((_h), #_x); \
|
|
if (func != NULL) \
|
|
{ lpDrv->parts[_w].u.fnMessage##_y = func; count++; \
|
|
TRACE("Got %d bit func '%s'\n", _y, #_x); }
|
|
|
|
#define A(_x,_y) AA(hMod16,_x,_y,16,GetProcAddress16)
|
|
A(MMDRV_AUX, auxMessage);
|
|
A(MMDRV_MIXER, mxdMessage);
|
|
A(MMDRV_MIDIIN, midMessage);
|
|
A(MMDRV_MIDIOUT,modMessage);
|
|
A(MMDRV_WAVEIN, widMessage);
|
|
A(MMDRV_WAVEOUT,wodMessage);
|
|
#undef A
|
|
#undef AA
|
|
}
|
|
if (TRACE_ON(winmm)) {
|
|
if (MMDRV_GetDescription16(drvName, buffer, sizeof(buffer)))
|
|
TRACE("%s => %s\n", drvName, buffer);
|
|
else
|
|
TRACE("%s => No description\n", drvName);
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
void MMDRV_Init16(void)
|
|
{
|
|
#define A(_x,_y) MMDRV_InstallMap(_x, \
|
|
MMDRV_##_y##_Map32WTo16, MMDRV_##_y##_UnMap32WTo16, \
|
|
MMDRV_##_y##_Callback)
|
|
A(MMDRV_AUX, Aux);
|
|
A(MMDRV_MIXER, Mixer);
|
|
A(MMDRV_MIDIIN, MidiIn);
|
|
A(MMDRV_MIDIOUT, MidiOut);
|
|
A(MMDRV_WAVEIN, WaveIn);
|
|
A(MMDRV_WAVEOUT, WaveOut);
|
|
#undef A
|
|
|
|
pFnCallMMDrvFunc16 = MMDRV_CallMMDrvFunc16;
|
|
pFnLoadMMDrvFunc16 = MMDRV_LoadMMDrvFunc16;
|
|
}
|
|
|
|
/* ###################################################
|
|
* # DRIVER THUNKING #
|
|
* ###################################################
|
|
*/
|
|
typedef MMSYSTEM_MapType (*MMSYSTDRV_MAPMSG)(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2);
|
|
typedef MMSYSTEM_MapType (*MMSYSTDRV_UNMAPMSG)(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT ret);
|
|
typedef void (*MMSYSTDRV_MAPCB)(DWORD wMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2);
|
|
|
|
#include <pshpack1.h>
|
|
#define MMSYSTDRV_MAX_THUNKS 32
|
|
|
|
static struct mmsystdrv_thunk
|
|
{
|
|
BYTE popl_eax; /* popl %eax (return address) */
|
|
BYTE pushl_func; /* pushl $pfn16 (16bit callback function) */
|
|
struct mmsystdrv_thunk* this;
|
|
BYTE pushl_eax; /* pushl %eax */
|
|
BYTE jmp; /* ljmp MMDRV_Callback1632 */
|
|
DWORD callback;
|
|
DWORD pfn16;
|
|
void* hMmdrv; /* Handle to 32bit mmdrv object */
|
|
enum MMSYSTEM_DriverType kind;
|
|
} *MMSYSTDRV_Thunks;
|
|
|
|
#include <poppack.h>
|
|
|
|
static struct MMSYSTDRV_Type
|
|
{
|
|
MMSYSTDRV_MAPMSG mapmsg16to32W;
|
|
MMSYSTDRV_UNMAPMSG unmapmsg16to32W;
|
|
MMSYSTDRV_MAPCB mapcb;
|
|
} MMSYSTEM_DriversType[MMSYSTDRV_MAX] =
|
|
{
|
|
{MMSYSTDRV_Mixer_Map16To32W, MMSYSTDRV_Mixer_UnMap16To32W, MMSYSTDRV_Mixer_MapCB},
|
|
{MMSYSTDRV_MidiIn_Map16To32W, MMSYSTDRV_MidiIn_UnMap16To32W, MMSYSTDRV_MidiIn_MapCB},
|
|
{MMSYSTDRV_MidiOut_Map16To32W, MMSYSTDRV_MidiOut_UnMap16To32W, MMSYSTDRV_MidiOut_MapCB},
|
|
{MMSYSTDRV_WaveIn_Map16To32W, MMSYSTDRV_WaveIn_UnMap16To32W, MMSYSTDRV_WaveIn_MapCB},
|
|
{MMSYSTDRV_WaveOut_Map16To32W, MMSYSTDRV_WaveOut_UnMap16To32W, MMSYSTDRV_WaveOut_MapCB},
|
|
};
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_Callback3216
|
|
*
|
|
*/
|
|
static LRESULT CALLBACK MMSYSTDRV_Callback3216(struct mmsystdrv_thunk* thunk, DWORD uFlags, HDRVR hDev,
|
|
DWORD wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1,
|
|
DWORD_PTR dwParam2)
|
|
{
|
|
assert(thunk->kind < MMSYSTDRV_MAX);
|
|
assert(MMSYSTEM_DriversType[thunk->kind].mapcb);
|
|
|
|
MMSYSTEM_DriversType[thunk->kind].mapcb(wMsg, &dwUser, &dwParam1, &dwParam2);
|
|
|
|
if ((uFlags & DCB_TYPEMASK) == DCB_FUNCTION)
|
|
{
|
|
WORD args[8];
|
|
/* 16 bit func, call it */
|
|
TRACE("Function (16 bit) !\n");
|
|
|
|
args[7] = HDRVR_16(hDev);
|
|
args[6] = wMsg;
|
|
args[5] = HIWORD(dwUser);
|
|
args[4] = LOWORD(dwUser);
|
|
args[3] = HIWORD(dwParam1);
|
|
args[2] = LOWORD(dwParam1);
|
|
args[1] = HIWORD(dwParam2);
|
|
args[0] = LOWORD(dwParam2);
|
|
return WOWCallback16Ex(thunk->pfn16, WCB16_PASCAL, sizeof(args), args, NULL);
|
|
}
|
|
return DriverCallback(thunk->pfn16, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_AddThunk
|
|
*
|
|
*/
|
|
struct mmsystdrv_thunk* MMSYSTDRV_AddThunk(DWORD pfn16, enum MMSYSTEM_DriverType kind)
|
|
{
|
|
struct mmsystdrv_thunk* thunk;
|
|
|
|
EnterCriticalSection(&mmdrv_cs);
|
|
if (!MMSYSTDRV_Thunks)
|
|
{
|
|
MMSYSTDRV_Thunks = VirtualAlloc(NULL, MMSYSTDRV_MAX_THUNKS * sizeof(*MMSYSTDRV_Thunks),
|
|
MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
if (!MMSYSTDRV_Thunks)
|
|
{
|
|
LeaveCriticalSection(&mmdrv_cs);
|
|
return NULL;
|
|
}
|
|
for (thunk = MMSYSTDRV_Thunks; thunk < &MMSYSTDRV_Thunks[MMSYSTDRV_MAX_THUNKS]; thunk++)
|
|
{
|
|
thunk->popl_eax = 0x58; /* popl %eax */
|
|
thunk->pushl_func = 0x68; /* pushl $pfn16 */
|
|
thunk->this = thunk;
|
|
thunk->pushl_eax = 0x50; /* pushl %eax */
|
|
thunk->jmp = 0xe9; /* jmp MMDRV_Callback3216 */
|
|
thunk->callback = (char *)MMSYSTDRV_Callback3216 - (char *)(&thunk->callback + 1);
|
|
thunk->pfn16 = 0;
|
|
thunk->hMmdrv = NULL;
|
|
thunk->kind = MMSYSTDRV_MAX;
|
|
}
|
|
}
|
|
for (thunk = MMSYSTDRV_Thunks; thunk < &MMSYSTDRV_Thunks[MMSYSTDRV_MAX_THUNKS]; thunk++)
|
|
{
|
|
if (thunk->pfn16 == 0 && thunk->hMmdrv == NULL)
|
|
{
|
|
thunk->pfn16 = pfn16;
|
|
thunk->hMmdrv = NULL;
|
|
thunk->kind = kind;
|
|
LeaveCriticalSection(&mmdrv_cs);
|
|
return thunk;
|
|
}
|
|
}
|
|
LeaveCriticalSection(&mmdrv_cs);
|
|
FIXME("Out of mmdrv-thunks. Bump MMDRV_MAX_THUNKS\n");
|
|
return NULL;
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_FindHandle
|
|
*
|
|
* Must be called with lock set
|
|
*/
|
|
static void* MMSYSTDRV_FindHandle(void* h)
|
|
{
|
|
struct mmsystdrv_thunk* thunk;
|
|
|
|
for (thunk = MMSYSTDRV_Thunks; thunk < &MMSYSTDRV_Thunks[MMSYSTDRV_MAX_THUNKS]; thunk++)
|
|
{
|
|
if (thunk->hMmdrv == h)
|
|
{
|
|
if (thunk->kind >= MMSYSTDRV_MAX) FIXME("Kind isn't properly initialized %x\n", thunk->kind);
|
|
return thunk;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_SetHandle
|
|
*
|
|
*/
|
|
void MMSYSTDRV_SetHandle(struct mmsystdrv_thunk* thunk, void* h)
|
|
{
|
|
if (MMSYSTDRV_FindHandle(h)) FIXME("Already has a thunk for this handle %p!!!\n", h);
|
|
thunk->hMmdrv = h;
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_DeleteThunk
|
|
*/
|
|
void MMSYSTDRV_DeleteThunk(struct mmsystdrv_thunk* thunk)
|
|
{
|
|
thunk->pfn16 = 0;
|
|
thunk->hMmdrv = NULL;
|
|
thunk->kind = MMSYSTDRV_MAX;
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_CloseHandle
|
|
*/
|
|
void MMSYSTDRV_CloseHandle(void* h)
|
|
{
|
|
struct mmsystdrv_thunk* thunk;
|
|
|
|
EnterCriticalSection(&mmdrv_cs);
|
|
if ((thunk = MMSYSTDRV_FindHandle(h)))
|
|
{
|
|
MMSYSTDRV_DeleteThunk(thunk);
|
|
}
|
|
LeaveCriticalSection(&mmdrv_cs);
|
|
}
|
|
|
|
/******************************************************************
|
|
* MMSYSTDRV_Message
|
|
*/
|
|
DWORD MMSYSTDRV_Message(void* h, UINT msg, DWORD_PTR param1, DWORD_PTR param2)
|
|
{
|
|
struct mmsystdrv_thunk* thunk = MMSYSTDRV_FindHandle(h);
|
|
struct MMSYSTDRV_Type* drvtype;
|
|
MMSYSTEM_MapType map;
|
|
DWORD ret;
|
|
|
|
if (!thunk) return MMSYSERR_INVALHANDLE;
|
|
drvtype = &MMSYSTEM_DriversType[thunk->kind];
|
|
|
|
map = drvtype->mapmsg16to32W(msg, ¶m1, ¶m2);
|
|
switch (map) {
|
|
case MMSYSTEM_MAP_NOMEM:
|
|
ret = MMSYSERR_NOMEM;
|
|
break;
|
|
case MMSYSTEM_MAP_MSGERROR:
|
|
FIXME("NIY: no conversion yet 16->32 kind=%u msg=%u\n", thunk->kind, msg);
|
|
ret = MMSYSERR_ERROR;
|
|
break;
|
|
case MMSYSTEM_MAP_OK:
|
|
case MMSYSTEM_MAP_OKMEM:
|
|
TRACE("Calling message(msg=%u p1=0x%08lx p2=0x%08lx)\n",
|
|
msg, param1, param2);
|
|
switch (thunk->kind)
|
|
{
|
|
case MMSYSTDRV_MIXER: ret = mixerMessage (h, msg, param1, param2); break;
|
|
case MMSYSTDRV_MIDIIN: ret = midiInMessage (h, msg, param1, param2); break;
|
|
case MMSYSTDRV_MIDIOUT: ret = midiOutMessage(h, msg, param1, param2); break;
|
|
case MMSYSTDRV_WAVEIN: ret = waveInMessage (h, msg, param1, param2); break;
|
|
case MMSYSTDRV_WAVEOUT: ret = waveOutMessage(h, msg, param1, param2); break;
|
|
default: ret = MMSYSERR_INVALHANDLE; break; /* should never be reached */
|
|
}
|
|
if (map == MMSYSTEM_MAP_OKMEM)
|
|
drvtype->unmapmsg16to32W(msg, ¶m1, ¶m2, ret);
|
|
break;
|
|
default:
|
|
FIXME("NIY\n");
|
|
ret = MMSYSERR_NOTSUPPORTED;
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|