mmio (second round) 16/32 split

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



the good sides of the patch
- 32 bit mmio is now only using 32 bit APIs
- 16 bit mmio can be compiled out winmm when win16 is disabled
the bad sides of the patch
- the 16 bit ioProc support hasn't been tested (if someone has such a
program, I'd be happy to toy with it)
  anyway, this support was broken before, and noone complained, so I
think we can life with it for now

A+
Name:          mm1632_3
ChangeLog:     keep on moving 16 bit code out of winmm
now only using linear addresses for buffers
License:       X11
GenDate:       2002/10/13 20:01:57 UTC
ModifiedFiles: dlls/winmm/mmio.c dlls/winmm/mmsystem.c dlls/winmm/mmsystem.spec dlls/winmm/winemm.h
AddedFiles:    
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/winmm/mmio.c,v
retrieving revision 1.34
diff -u -u -r1.34 mmio.c
--- dlls/winmm/mmio.c	9 Aug 2002 19:51:01 -0000	1.34
+++ dlls/winmm/mmio.c	13 Oct 2002 19:26:48 -0000
@@ -2,9 +2,9 @@
 /*
  * MMIO functions
  *
- * Copyright 1998 Andrew Taylor
- * Copyright 1998 Ove Kåven
- * Copyright 2000 Eric Pouech
+ * Copyright 1998      Andrew Taylor
+ * Copyright 1998      Ove Kåven
+ * Copyright 2000-2002 Eric Pouech
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,11 +24,13 @@
 /* Still to be done:
  * 	+ correct handling of global/local IOProcs
  *	+ mode of mmio objects is not used (read vs write vs readwrite)
- *	+ optimization of internal buffers (seg / lin)
- *	+ even in 32 bit only, a seg ptr IO buffer is allocated (after this is
- *	  fixed, we'll have a proper 32/16 separation)
  *	+ thread safeness
  *	+ rename operation is broken
+ *
+ * Note:
+ *      In internal info struct (wm->info):
+ *      - the dwReserved1 field is used to store the segmented address of the
+ *        wm->info.pchBuffer buffer.
  */
 
 #include <ctype.h>
@@ -39,9 +41,6 @@
 
 #include "mmsystem.h"
 #include "windef.h"
-
-#include "wine/mmsystem16.h"
-#include "wine/winbase16.h"
 #include "heap.h"
 #include "winemm.h"
 
@@ -64,7 +63,7 @@
 	{
 	    /* Parameters:
 	     * lParam1 = szFileName parameter from mmioOpen
-	     * lParam2 = reserved (we use it for 16-bitness)
+	     * lParam2 = reserved
 	     * Returns: zero on success, error code on error
 	     * NOTE: lDiskOffset automatically set to zero
 	     */
@@ -77,12 +76,10 @@
 	    }
 
 	    /* if filename NULL, assume open file handle in adwInfo[0] */
-	    if (!szFileName) {
-		if (lParam2)
-		    lpmmioinfo->adwInfo[0] = DosFileHandleToWin32Handle(lpmmioinfo->adwInfo[0]);
-		break;
-	    }
-	    lpmmioinfo->adwInfo[0] = (DWORD)OpenFile(szFileName, &ofs, lpmmioinfo->dwFlags & 0xFFFF);
+	    if (szFileName == NULL && lpmmioinfo->adwInfo[0] != 0)
+                lpmmioinfo->adwInfo[0] = DosFileHandleToWin32Handle(lpmmioinfo->adwInfo[0]);
+	    else
+                lpmmioinfo->adwInfo[0] = (DWORD)OpenFile(szFileName, &ofs, lpmmioinfo->dwFlags & 0xFFFF);
 	    if (lpmmioinfo->adwInfo[0] == (DWORD)HFILE_ERROR)
 		ret = MMIOERR_CANNOTOPEN;
 	}
@@ -168,7 +165,7 @@
     case MMIOM_OPEN:
 	/* Parameters:
 	 * lParam1 = filename (must be NULL)
-	 * lParam2 = reserved (we use it for 16-bitness)
+	 * lParam2 = reserved
 	 * Returns: zero on success, error code on error
 	 * NOTE: lDiskOffset automatically set to zero
 	 */
@@ -229,15 +226,14 @@
     return 0;
 }
 
-
-enum mmioProcType {MMIO_PROC_16,MMIO_PROC_32A,MMIO_PROC_32W};
+enum mmioProcType {MMIO_PROC_32A, MMIO_PROC_32W};
 
 struct IOProcList
 {
     struct IOProcList*pNext;       /* Next item in linked list */
     FOURCC            fourCC;      /* four-character code identifying IOProc */
     LPMMIOPROC	      pIOProc;     /* pointer to IProc */
-    enum mmioProcType type;        /* 16, 32A or 32W */
+    enum mmioProcType type;        /* 32A or 32W */
     int		      count;	   /* number of objects linked to it */
 };
 
@@ -270,8 +266,8 @@
 /****************************************************************
  *       	MMIO_InstallIOProc 			[INTERNAL]
  */
-static LPMMIOPROC MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
-				     DWORD dwFlags, enum mmioProcType type)
+LPMMIOPROC MMSYSTEM_mmioInstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
+                                      DWORD dwFlags, enum mmioProcType type)
 {
     LPMMIOPROC	        lpProc = NULL;
     struct IOProcList*  pListNode;
@@ -347,59 +343,12 @@
 }
 
 /****************************************************************
- *       		MMIO_Map32To16			[INTERNAL]
- */
-static LRESULT	MMIO_Map32To16(DWORD wMsg, LPARAM* lp1, LPARAM* lp2)
-{
-    switch (wMsg) {
-    case MMIOM_CLOSE:
-    case MMIOM_SEEK:
-	/* nothing to do */
-	break;
-    case MMIOM_OPEN:
-    case MMIOM_READ:
-    case MMIOM_WRITE:
-    case MMIOM_WRITEFLUSH:
-        *lp1 = MapLS( (void *)*lp1 );
-	break;
-    default:
-	TRACE("Not a mappable message (%ld)\n", wMsg);
-    }
-    return MMSYSERR_NOERROR;
-}
-
-/****************************************************************
- *       	MMIO_UnMap32To16 			[INTERNAL]
- */
-static LRESULT	MMIO_UnMap32To16(DWORD wMsg, LPARAM lParam1, LPARAM lParam2,
-				 LPARAM lp1, LPARAM lp2)
-{
-    switch (wMsg) {
-    case MMIOM_CLOSE:
-    case MMIOM_SEEK:
-	/* nothing to do */
-	break;
-    case MMIOM_OPEN:
-    case MMIOM_READ:
-    case MMIOM_WRITE:
-    case MMIOM_WRITEFLUSH:
-        UnMapLS( lp1 );
-	break;
-    default:
-	TRACE("Not a mappable message (%ld)\n", wMsg);
-    }
-    return MMSYSERR_NOERROR;
-}
-
-/****************************************************************
  *       	MMIO_SendMessage			[INTERNAL]
  */
 static LRESULT	MMIO_SendMessage(LPWINE_MMIO wm, DWORD wMsg, LPARAM lParam1,
 				 LPARAM lParam2, enum mmioProcType type)
 {
-    MMIOINFO16 mmioInfo16;
     LRESULT 		result;
-    SEGPTR		segmmioInfo16;
     LPARAM		lp1 = lParam1, lp2 = lParam2;
 
     if (!wm->ioProc || !wm->info.pIOProc) {
@@ -408,44 +357,17 @@
     }
 
     switch (wm->ioProc->type) {
-    case MMIO_PROC_16:
-        memset( &mmioInfo16, 0, sizeof(MMIOINFO16));
-        mmioInfo16.lDiskOffset = wm->info.lDiskOffset;
-        mmioInfo16.adwInfo[0]  = wm->info.adwInfo[0];
-        mmioInfo16.adwInfo[1]  = wm->info.adwInfo[1];
-        mmioInfo16.adwInfo[2]  = wm->info.adwInfo[2];
-        mmioInfo16.adwInfo[3]  = wm->info.adwInfo[3];
-	if (wm->ioProc->type != type) {
-	    /* map (lParam1, lParam2) into (lp1, lp2) 32=>16 */
-	    if ((result = MMIO_Map32To16(wMsg, &lp1, &lp2)) != MMSYSERR_NOERROR)
-		return result;
-	}
-	/* FIXME: is wm->info.pIOProc a segmented or a linear address ?
-	 * sounds to me it's a segmented one, should use a thunk somewhere
-	 */
-        segmmioInfo16 = MapLS( &mmioInfo16 );
-        result = ((LPMMIOPROC16)wm->info.pIOProc)((LPSTR)segmmioInfo16, wMsg, lp1, lp2);
-        UnMapLS( segmmioInfo16 );
-	if (wm->ioProc->type != type) {
-	    MMIO_UnMap32To16(wMsg, lParam1, lParam2, lp1, lp2);
-	}
-        wm->info.lDiskOffset = mmioInfo16.lDiskOffset;
-        wm->info.adwInfo[0]  = mmioInfo16.adwInfo[0];
-        wm->info.adwInfo[1]  = mmioInfo16.adwInfo[1];
-        wm->info.adwInfo[2]  = mmioInfo16.adwInfo[2];
-        wm->info.adwInfo[3]  = mmioInfo16.adwInfo[3];
-	break;
     case MMIO_PROC_32A:
     case MMIO_PROC_32W:
 	if (wm->ioProc->type != type) {
-	    /* map (lParam1, lParam2) into (lp1, lp2) 16=>32 */
+	    /* map (lParam1, lParam2) into (lp1, lp2) 32 A/W */
 	    WARN("NIY\n");
 	}
 	result = (wm->info.pIOProc)((LPSTR)&wm->info, wMsg, lp1, lp2);
 
 #if 0
 	if (wm->ioProc->type != type) {
-	    /* unmap (lParam1, lParam2) into (lp1, lp2) 16=>32 */
+	    /* unmap (lParam1, lParam2) into (lp1, lp2) 32 A/W */
 	}
 #endif
 	break;
@@ -497,7 +419,7 @@
 
 	    if (extEnd - extStart - 1 > 4)
 		WARN("Extension length > 4\n");
-	    lstrcpynA(ext,extStart + 1,min(extEnd-extStart,5));
+	    lstrcpynA(ext,extStart + 1, min(extEnd - extStart, 5));
 	    TRACE("Got extension: %s\n", debugstr_a(ext));
 	    /* FOURCC codes identifying file-extensions must be uppercase */
 	    ret = mmioStringToFOURCCA(ext, MMIO_TOUPPER);
@@ -626,9 +548,9 @@
  *       		MMIO_SetBuffer 				[INTERNAL]
  */
 static MMRESULT MMIO_SetBuffer(WINE_MMIO* wm, void* pchBuffer, LONG cchBuffer,
-			       UINT uFlags, BOOL bFrom32)
+			       UINT uFlags)
 {
-    TRACE("(%p %p %ld %u %d)\n", wm, pchBuffer, cchBuffer, uFlags, bFrom32);
+    TRACE("(%p %p %ld %u)\n", wm, pchBuffer, cchBuffer, uFlags);
 
     if (uFlags)			return MMSYSERR_INVALPARAM;
     if (cchBuffer > 0xFFFF)
@@ -637,35 +559,21 @@
     if (MMIO_Flush(wm, 0) != MMSYSERR_NOERROR)
 	return MMIOERR_CANNOTWRITE;
 
-    if (wm->hMem && (wm->info.dwFlags & MMIO_ALLOCBUF)) {
-	GlobalUnlock16(wm->hMem);
-	GlobalFree16(wm->hMem);
-	wm->hMem = 0;
+    /* free previous buffer if allocated */
+    if (wm->info.dwFlags & MMIO_ALLOCBUF) {
+        HeapFree(GetProcessHeap(), 0, wm->info.pchBuffer);
+        wm->info.pchBuffer = NULL;
 	wm->info.dwFlags &= ~MMIO_ALLOCBUF;
     }
 
     if (pchBuffer) {
-	if (bFrom32) {
-	    wm->info.pchBuffer = pchBuffer;
-	    wm->buffer16 = 0;
-	} else {
-	    wm->info.pchBuffer = MapSL((SEGPTR)pchBuffer);
-	    wm->buffer16 = (SEGPTR)pchBuffer;
-	}
-	wm->hMem = 0;
+        wm->info.pchBuffer = pchBuffer;
     } else if (cchBuffer) {
-	if (!(wm->hMem = GlobalAlloc16(GMEM_MOVEABLE, cchBuffer)))
+	if (!(wm->info.pchBuffer = HeapAlloc(GetProcessHeap(), 0, cchBuffer)))
 	    return MMIOERR_OUTOFMEMORY;
 	wm->info.dwFlags |= MMIO_ALLOCBUF;
     } else {
 	wm->info.pchBuffer = NULL;
-	wm->hMem = 0;
-	wm->buffer16 = 0;
-    }
-
-    if (wm->hMem) {
-	wm->buffer16 = K32WOWGlobalLock16(wm->hMem);
-	wm->info.pchBuffer = MapSL(wm->buffer16);
     }
 
     wm->info.cchBuffer = cchBuffer;
@@ -679,10 +587,10 @@
 }
 
 /**************************************************************************
- * 			MMIO_Open      				[internal]
+ * 			MMSYSTEM_mmioOpen			[internal]
  */
 static HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo,
-		       DWORD dwOpenFlags, enum mmioProcType type)
+                       DWORD dwOpenFlags, enum mmioProcType type)
 {
     LPWINE_MMIO		wm;
 
@@ -692,7 +600,7 @@
 	char	buffer[MAX_PATH];
 
 	if (GetFullPathNameA(szFileName, sizeof(buffer), buffer, NULL) >= sizeof(buffer))
-	    return (HMMIO16)FALSE;
+	    return (HMMIO)FALSE;
 	if ((dwOpenFlags & MMIO_EXIST) && (GetFileAttributesA(buffer) == -1))
 	    return (HMMIO)FALSE;
 	strcpy(szFileName, buffer);
@@ -723,8 +631,8 @@
     else {
 	wm->info.fccIOProc = refmminfo->fccIOProc;
 	wm->info.pIOProc = refmminfo->pIOProc;
-	MMIO_InstallIOProc(wm->info.fccIOProc, wm->info.pIOProc,
-			   MMIO_INSTALLPROC, type);
+	MMSYSTEM_mmioInstallIOProc(wm->info.fccIOProc, wm->info.pIOProc,
+                                   MMIO_INSTALLPROC, type);
 	if (!(wm->ioProc = MMIO_FindProcNode(wm->info.fccIOProc))) goto error2;
 	assert(wm->ioProc->pIOProc == refmminfo->pIOProc);
 	wm->info.pIOProc = wm->ioProc->pIOProc;
@@ -735,13 +643,10 @@
     wm->ioProc->count++;
 
     if (dwOpenFlags & MMIO_ALLOCBUF) {
-	if ((refmminfo->wErrorRet = MMIO_SetBuffer(wm, NULL, MMIO_DEFAULTBUFFER, 0,
-                                                   type != MMIO_PROC_16)))
+	if ((refmminfo->wErrorRet = MMIO_SetBuffer(wm, NULL, MMIO_DEFAULTBUFFER, 0)))
 	    goto error1;
     } else if (wm->info.fccIOProc == FOURCC_MEM) {
-	refmminfo->wErrorRet = MMIO_SetBuffer(wm, refmminfo->pchBuffer,
-					      refmminfo->cchBuffer, 0,
-					      type != MMIO_PROC_16);
+        refmminfo->wErrorRet = MMIO_SetBuffer(wm, refmminfo->pchBuffer, refmminfo->cchBuffer, 0);
 	if (refmminfo->wErrorRet != MMSYSERR_NOERROR)
 	    goto error1;
 	wm->bBufferLoaded = TRUE;
@@ -750,10 +655,14 @@
     /* see mmioDosIOProc for that one */
     wm->info.adwInfo[0] = refmminfo->adwInfo[0];
     wm->info.dwFlags = dwOpenFlags;
+    
+    /* copy 16 bit information (if any) */
+    wm->info.dwReserved1 = refmminfo->dwReserved1;
+    wm->info.dwReserved2 = 0;
 
     /* call IO proc to actually open file */
     refmminfo->wErrorRet = MMIO_SendMessage(wm, MMIOM_OPEN, (LPARAM)szFileName,
-                                            type == MMIO_PROC_16, MMIO_PROC_32A);
+                                            0, MMIO_PROC_32A);
 
     /* grab file size, when possible */
     wm->dwFileSize = GetFileSize(wm->info.adwInfo[0], NULL);
@@ -777,16 +686,19 @@
     LPSTR	szFn = HEAP_strdupWtoA(GetProcessHeap(), 0, szFileName);
 
     if (lpmmioinfo) {
+        lpmmioinfo->dwReserved1 = 0;
+
 	ret = MMIO_Open(szFn, lpmmioinfo, dwOpenFlags, MMIO_PROC_32W);
     } else {
 	MMIOINFO	mmioinfo;
 
+        memset(&mmioinfo, 0, sizeof(mmioinfo));
 	mmioinfo.fccIOProc = 0;
 	mmioinfo.pIOProc = NULL;
 	mmioinfo.pchBuffer = NULL;
 	mmioinfo.cchBuffer = 0;
 
-	ret = MMIO_Open(szFn, &mmioinfo, dwOpenFlags, MMIO_PROC_32W);
+	ret = MMIO_Open(szFn, &mmioinfo, dwOpenFlags, MMIO_PROC_32A);
     }
 
     HeapFree(GetProcessHeap(), 0, szFn);
@@ -802,10 +714,14 @@
     HMMIO 	ret;
 
     if (lpmmioinfo) {
+        lpmmioinfo->dwReserved1 = 0;
+
 	ret = MMIO_Open(szFileName, lpmmioinfo, dwOpenFlags, MMIO_PROC_32A);
     } else {
 	MMIOINFO	mmioinfo;
 
+        memset(&mmioinfo, 0, sizeof(mmioinfo));
+
 	mmioinfo.fccIOProc = 0;
 	mmioinfo.pIOProc = NULL;
 	mmioinfo.pchBuffer = NULL;
@@ -817,45 +733,6 @@
 }
 
 /**************************************************************************
- * 				mmioOpen       		[MMSYSTEM.1210]
- */
-HMMIO16 WINAPI mmioOpen16(LPSTR szFileName, MMIOINFO16* lpmmioinfo16,
-			  DWORD dwOpenFlags)
-{
-    HMMIO 	ret;
-    MMIOINFO	mmio;
-
-    if (lpmmioinfo16) {
-	MMIOINFO	mmioinfo;
-
-	memset(&mmioinfo, 0, sizeof(mmioinfo));
-
-	mmioinfo.dwFlags     = lpmmioinfo16->dwFlags;
-	mmioinfo.fccIOProc   = lpmmioinfo16->fccIOProc;
-	mmioinfo.pIOProc     = (LPMMIOPROC)lpmmioinfo16->pIOProc;
-	mmioinfo.cchBuffer   = lpmmioinfo16->cchBuffer;
-	mmioinfo.pchBuffer   = lpmmioinfo16->pchBuffer;
-	mmioinfo.adwInfo[0]  = lpmmioinfo16->adwInfo[0];
-	mmioinfo.adwInfo[1]  = lpmmioinfo16->adwInfo[1];
-	mmioinfo.adwInfo[2]  = lpmmioinfo16->adwInfo[2];
-	mmioinfo.adwInfo[3]  = lpmmioinfo16->adwInfo[3];
-
-	ret = MMIO_Open(szFileName, &mmioinfo, dwOpenFlags, MMIO_PROC_16);
-
-	mmioGetInfo16(HMMIO_16(mmioinfo.hmmio), lpmmioinfo16, 0);
-	lpmmioinfo16->wErrorRet = HMMIO_16(ret);
-    } else {
-	mmio.fccIOProc = 0;
-	mmio.pIOProc = NULL;
-	mmio.pchBuffer = NULL;
-	mmio.cchBuffer = 0;
-	ret = MMIO_Open(szFileName, &mmio, dwOpenFlags, FALSE);
-    }
-    return HMMIO_16(ret);
-}
-
-
-/**************************************************************************
  * 				mmioClose      		[WINMM.@]
  */
 MMRESULT WINAPI mmioClose(HMMIO hmmio, UINT uFlags)
@@ -873,13 +750,13 @@
 
     result = MMIO_SendMessage(wm, MMIOM_CLOSE, uFlags, 0, MMIO_PROC_32A);
 
-    MMIO_SetBuffer(wm, NULL, 0, 0, TRUE);
+    MMIO_SetBuffer(wm, NULL, 0, 0);
 
     wm->ioProc->count--;
 
     if (wm->bTmpIOProc)
-	MMIO_InstallIOProc(wm->info.fccIOProc, NULL,
-			   MMIO_REMOVEPROC, wm->ioProc->type);
+	MMSYSTEM_mmioInstallIOProc(wm->info.fccIOProc, NULL,
+                                   MMIO_REMOVEPROC, wm->ioProc->type);
 
     MMIO_Destroy(wm);
 
@@ -887,14 +764,6 @@
 }
 
 /**************************************************************************
- * 				mmioClose      		[MMSYSTEM.1211]
- */
-MMRESULT16 WINAPI mmioClose16(HMMIO16 hmmio, UINT16 uFlags)
-{
-    return mmioClose(HMMIO_32(hmmio), uFlags);
-}
-
-/**************************************************************************
  * 				mmioRead	       	[WINMM.@]
  */
 LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
@@ -944,14 +813,6 @@
 }
 
 /**************************************************************************
- * 				mmioRead	       	[MMSYSTEM.1212]
- */
-LONG WINAPI mmioRead16(HMMIO16 hmmio, HPSTR pch, LONG cch)
-{
-    return mmioRead(HMMIO_32(hmmio), pch, cch);
-}
-
-/**************************************************************************
  * 				mmioWrite      		[WINMM.@]
  */
 LONG WINAPI mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch)
@@ -1006,14 +867,6 @@
 }
 
 /**************************************************************************
- * 				mmioWrite      		[MMSYSTEM.1213]
- */
-LONG WINAPI mmioWrite16(HMMIO16 hmmio, HPCSTR pch, LONG cch)
-{
-    return mmioWrite(HMMIO_32(hmmio),pch,cch);
-}
-
-/**************************************************************************
  * 				mmioSeek		[WINMM.@]
  */
 LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, INT iOrigin)
@@ -1079,52 +932,6 @@
 }
 
 /**************************************************************************
- * 				mmioSeek       		[MMSYSTEM.1214]
- */
-LONG WINAPI mmioSeek16(HMMIO16 hmmio, LONG lOffset, INT16 iOrigin)
-{
-    return mmioSeek(HMMIO_32(hmmio), lOffset, iOrigin);
-}
-
-/**************************************************************************
- * 				mmioGetInfo	       	[MMSYSTEM.1215]
- */
-MMRESULT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
-{
-    LPWINE_MMIO	wm;
-
-    TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
-
-    if ((wm = MMIO_Get(NULL, HMMIO_32(hmmio))) == NULL)
-	return MMSYSERR_INVALHANDLE;
-
-    if (!wm->buffer16)
-	return MMSYSERR_ERROR;
-
-    lpmmioinfo->dwFlags     = wm->info.dwFlags;
-    lpmmioinfo->fccIOProc   = wm->info.fccIOProc;
-    lpmmioinfo->pIOProc     = (LPMMIOPROC16)wm->info.pIOProc;
-    lpmmioinfo->wErrorRet   = wm->info.wErrorRet;
-    lpmmioinfo->hTask       = wm->info.hTask;
-    lpmmioinfo->cchBuffer   = wm->info.cchBuffer;
-    lpmmioinfo->pchBuffer   = (void*)wm->buffer16;
-    lpmmioinfo->pchNext     = (void*)(wm->buffer16 + (wm->info.pchNext - wm->info.pchBuffer));
-    lpmmioinfo->pchEndRead  = (void*)(wm->buffer16 + (wm->info.pchEndRead - wm->info.pchBuffer));
-    lpmmioinfo->pchEndWrite = (void*)(wm->buffer16 + (wm->info.pchEndWrite - wm->info.pchBuffer));
-    lpmmioinfo->lBufOffset  = wm->info.lBufOffset;
-    lpmmioinfo->lDiskOffset = wm->info.lDiskOffset;
-    lpmmioinfo->adwInfo[0]  = wm->info.adwInfo[0];
-    lpmmioinfo->adwInfo[1]  = wm->info.adwInfo[1];
-    lpmmioinfo->adwInfo[2]  = wm->info.adwInfo[2];
-    lpmmioinfo->adwInfo[3]  = wm->info.adwInfo[3];
-    lpmmioinfo->dwReserved1 = 0;
-    lpmmioinfo->dwReserved2 = 0;
-    lpmmioinfo->hmmio = HMMIO_16(wm->info.hmmio);
-
-    return MMSYSERR_NOERROR;
-}
-
-/**************************************************************************
  * 				mmioGetInfo	       	[WINMM.@]
  */
 MMRESULT WINAPI mmioGetInfo(HMMIO hmmio, MMIOINFO* lpmmioinfo, UINT uFlags)
@@ -1142,39 +949,6 @@
 }
 
 /**************************************************************************
- * 				mmioSetInfo  		[MMSYSTEM.1216]
- */
-MMRESULT16 WINAPI mmioSetInfo16(HMMIO16 hmmio, const MMIOINFO16* lpmmioinfo, UINT16 uFlags)
-{
-    LPWINE_MMIO		wm;
-
-    TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
-
-    if ((wm = MMIO_Get(NULL, HMMIO_32(hmmio))) == NULL)
-	return MMSYSERR_INVALHANDLE;
-
-    /* check if seg and lin buffers are the same */
-    if (wm->info.cchBuffer != lpmmioinfo->cchBuffer ||
-	wm->info.pchBuffer != MapSL(wm->buffer16))
-	return MMSYSERR_INVALPARAM;
-
-    /* check pointers coherence */
-    if (lpmmioinfo->pchNext < lpmmioinfo->pchBuffer ||
-	lpmmioinfo->pchNext > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
-	lpmmioinfo->pchEndRead < lpmmioinfo->pchBuffer ||
-	lpmmioinfo->pchEndRead > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
-	lpmmioinfo->pchEndWrite < lpmmioinfo->pchBuffer ||
-	lpmmioinfo->pchEndWrite > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer)
-	return MMSYSERR_INVALPARAM;
-
-    wm->info.pchNext     = wm->info.pchBuffer + (lpmmioinfo->pchNext     - lpmmioinfo->pchBuffer);
-    wm->info.pchEndRead  = wm->info.pchBuffer + (lpmmioinfo->pchEndRead  - lpmmioinfo->pchBuffer);
-    wm->info.pchEndWrite = wm->info.pchBuffer + (lpmmioinfo->pchEndWrite - lpmmioinfo->pchBuffer);
-
-    return MMSYSERR_NOERROR;
-}
-
-/**************************************************************************
  * 				mmioSetInfo    		[WINMM.@]
  */
 MMRESULT WINAPI mmioSetInfo(HMMIO hmmio, const MMIOINFO* lpmmioinfo, UINT uFlags)
@@ -1214,24 +988,7 @@
     if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
 	return MMSYSERR_INVALHANDLE;
 
-    return MMIO_SetBuffer(wm, pchBuffer, cchBuffer, uFlags, TRUE);
-}
-
-/**************************************************************************
- * 				mmioSetBuffer		[MMSYSTEM.1217]
- */
-MMRESULT16 WINAPI mmioSetBuffer16(HMMIO16 hmmio, LPSTR segpchBuffer,
-                                  LONG cchBuffer, UINT16 uFlags)
-{
-    LPWINE_MMIO		wm;
-
-    TRACE("(hmmio=%04x, segpchBuf=%p, cchBuf=%ld, uFlags=%#08x)\n",
-	  hmmio, segpchBuffer, cchBuffer, uFlags);
-
-    if ((wm = MMIO_Get(NULL, HMMIO_32(hmmio))) == NULL)
-	return MMSYSERR_INVALHANDLE;
-
-    return MMIO_SetBuffer(wm, segpchBuffer, cchBuffer, uFlags, FALSE);
+    return MMIO_SetBuffer(wm, pchBuffer, cchBuffer, uFlags);
 }
 
 /**************************************************************************
@@ -1250,14 +1007,6 @@
 }
 
 /**************************************************************************
- * 				mmioFlush      		[MMSYSTEM.1218]
- */
-MMRESULT16 WINAPI mmioFlush16(HMMIO16 hmmio, UINT16 uFlags)
-{
-    return mmioFlush(HMMIO_32(hmmio), uFlags);
-}
-
-/**************************************************************************
  * 				mmioAdvance      	[WINMM.@]
  */
 MMRESULT WINAPI mmioAdvance(HMMIO hmmio, MMIOINFO* lpmmioinfo, UINT uFlags)
@@ -1266,6 +1015,9 @@
 
     TRACE("hmmio=%04X, lpmmioinfo=%p, uFlags=%04X\n", hmmio, lpmmioinfo, uFlags);
 
+    /* NOTE: mmioAdvance16 heavily relies on parameters from lpmmioinfo we're using
+     * here. be sure if you change something here to check mmioAdvance16 as well
+     */
     if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
 	return MMSYSERR_INVALHANDLE;
 
@@ -1286,7 +1038,8 @@
 	return MMIOERR_CANNOTWRITE;
 
     if (lpmmioinfo) {
-	wm->dwFileSize = max(wm->dwFileSize, lpmmioinfo->lBufOffset + (lpmmioinfo->pchNext - lpmmioinfo->pchBuffer));
+	wm->dwFileSize = max(wm->dwFileSize, lpmmioinfo->lBufOffset + 
+                             (lpmmioinfo->pchNext - lpmmioinfo->pchBuffer));
     }
     MMIO_GrabNextBuffer(wm, uFlags == MMIO_READ);
 
@@ -1302,40 +1055,6 @@
     return MMSYSERR_NOERROR;
 }
 
-/***********************************************************************
- * 				mmioAdvance    		[MMSYSTEM.1219]
- */
-MMRESULT16 WINAPI mmioAdvance16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
-{
-    LPWINE_MMIO		wm;
-
-    TRACE("hmmio=%04X, lpmmioinfo=%p, uFlags=%04X\n", hmmio, lpmmioinfo, uFlags);
-
-    if ((wm = MMIO_Get(NULL, HMMIO_32(hmmio))) == NULL)
-	return MMSYSERR_INVALHANDLE;
-
-    if (!wm->info.cchBuffer)
-	return MMIOERR_UNBUFFERED;
-
-    if (uFlags != MMIO_READ && uFlags != MMIO_WRITE)
-	return MMSYSERR_INVALPARAM;
-
-    if (MMIO_Flush(wm, 0) != MMSYSERR_NOERROR)
-	return MMIOERR_CANNOTWRITE;
-
-    MMIO_GrabNextBuffer(wm, uFlags == MMIO_READ);
-
-    lpmmioinfo->pchNext = lpmmioinfo->pchBuffer;
-    lpmmioinfo->pchEndRead  = lpmmioinfo->pchBuffer +
-	(wm->info.pchEndRead - wm->info.pchBuffer);
-    lpmmioinfo->pchEndWrite = lpmmioinfo->pchBuffer +
-	(wm->info.pchEndWrite - wm->info.pchBuffer);
-    lpmmioinfo->lDiskOffset = wm->info.lDiskOffset;
-    lpmmioinfo->lBufOffset = wm->info.lBufOffset;
-
-    return MMSYSERR_NOERROR;
-}
-
 /**************************************************************************
  * 				mmioStringToFOURCCA	[WINMM.@]
  */
@@ -1372,30 +1091,12 @@
 }
 
 /**************************************************************************
- * 				mmioStringToFOURCC	[MMSYSTEM.1220]
- */
-FOURCC WINAPI mmioStringToFOURCC16(LPCSTR sz, UINT16 uFlags)
-{
-    return mmioStringToFOURCCA(sz, uFlags);
-}
-
-/**************************************************************************
- *              mmioInstallIOProc    [MMSYSTEM.1221]
- */
-LPMMIOPROC16 WINAPI mmioInstallIOProc16(FOURCC fccIOProc, LPMMIOPROC16 pIOProc,
-                                        DWORD dwFlags)
-{
-    return (LPMMIOPROC16)MMIO_InstallIOProc(fccIOProc, (LPMMIOPROC)pIOProc,
-					    dwFlags, MMIO_PROC_16);
-}
-
-/**************************************************************************
  * 				mmioInstallIOProcA	   [WINMM.@]
  */
 LPMMIOPROC WINAPI mmioInstallIOProcA(FOURCC fccIOProc,
 				     LPMMIOPROC pIOProc, DWORD dwFlags)
 {
-    return MMIO_InstallIOProc(fccIOProc, pIOProc, dwFlags, MMIO_PROC_32A);
+    return MMSYSTEM_mmioInstallIOProc(fccIOProc, pIOProc, dwFlags, MMIO_PROC_32A);
 }
 
 /**************************************************************************
@@ -1404,26 +1105,28 @@
 LPMMIOPROC WINAPI mmioInstallIOProcW(FOURCC fccIOProc,
 				     LPMMIOPROC pIOProc, DWORD dwFlags)
 {
-    return MMIO_InstallIOProc(fccIOProc, pIOProc, dwFlags, MMIO_PROC_32W);
+    return MMSYSTEM_mmioInstallIOProc(fccIOProc, pIOProc, dwFlags, MMIO_PROC_32W);
 }
 
-/**************************************************************************
- * 				mmioSendMessage	[MMSYSTEM.1222]
+/******************************************************************
+ *		MMSYSTEM_mmioSendMessage
+ *
+ *
  */
-LRESULT WINAPI mmioSendMessage16(HMMIO16 hmmio, UINT16 uMessage,
-				 LPARAM lParam1, LPARAM lParam2)
+static LRESULT MMSYSTEM_mmioSendMessage(HMMIO hmmio, UINT uMessage, LPARAM lParam1, 
+                                        LPARAM lParam2, enum mmioProcType type)
 {
     LPWINE_MMIO		wm;
 
-    TRACE("(%04X, %u, %ld, %ld)\n", hmmio, uMessage, lParam1, lParam2);
+    TRACE("(%04X, %u, %ld, %ld, %d)\n", hmmio, uMessage, lParam1, lParam2, type);
 
     if (uMessage < MMIOM_USER)
 	return MMSYSERR_INVALPARAM;
 
-    if ((wm = MMIO_Get(NULL, HMMIO_32(hmmio))) == NULL)
+    if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
 	return MMSYSERR_INVALHANDLE;
 
-    return MMIO_SendMessage(wm, uMessage, lParam1, lParam2, MMIO_PROC_16);
+    return MMIO_SendMessage(wm, uMessage, lParam1, lParam2, type);
 }
 
 /**************************************************************************
@@ -1432,17 +1135,7 @@
 LRESULT WINAPI mmioSendMessage(HMMIO hmmio, UINT uMessage,
 			       LPARAM lParam1, LPARAM lParam2)
 {
-    LPWINE_MMIO		wm;
-
-    TRACE("(%04X, %u, %ld, %ld)\n", hmmio, uMessage, lParam1, lParam2);
-
-    if (uMessage < MMIOM_USER)
-	return MMSYSERR_INVALPARAM;
-
-    if ((wm = MMIO_Get(NULL, hmmio)) == NULL)
-	return MMSYSERR_INVALHANDLE;
-
-    return MMIO_SendMessage(wm, uMessage, lParam1, lParam2, MMIO_PROC_32A);
+    return MMSYSTEM_mmioSendMessage(hmmio, uMessage, lParam1, lParam2, MMIO_PROC_32A);
 }
 
 /**************************************************************************
@@ -1455,7 +1148,6 @@
     FOURCC		srchCkId;
     FOURCC		srchType;
 
-
     TRACE("(%04X, %p, %p, %04X);\n", hmmio, lpck, lpckParent, uFlags);
 
     if (lpck == NULL)
@@ -1550,15 +1242,6 @@
 }
 
 /**************************************************************************
- * 				mmioDescend	       	[MMSYSTEM.1223]
- */
-MMRESULT16 WINAPI mmioDescend16(HMMIO16 hmmio, LPMMCKINFO lpck,
-                                const MMCKINFO* lpckParent, UINT16 uFlags)
-{
-    return mmioDescend(HMMIO_32(hmmio), lpck, lpckParent, uFlags);
-}
-
-/**************************************************************************
  * 				mmioAscend     		[WINMM.@]
  */
 MMRESULT WINAPI mmioAscend(HMMIO hmmio, LPMMCKINFO lpck, UINT uFlags)
@@ -1593,14 +1276,6 @@
 }
 
 /**************************************************************************
- * 				mmioAscend     		[MMSYSTEM.1224]
- */
-MMRESULT16 WINAPI mmioAscend16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
-{
-    return mmioAscend(HMMIO_32(hmmio),lpck,uFlags);
-}
-
-/**************************************************************************
  * 			mmioCreateChunk				[WINMM.@]
  */
 MMRESULT WINAPI mmioCreateChunk(HMMIO hmmio, MMCKINFO* lpck, UINT uFlags)
@@ -1640,50 +1315,6 @@
 }
 
 /**************************************************************************
- * 				mmioCreateChunk		[MMSYSTEM.1225]
- */
-MMRESULT16 WINAPI mmioCreateChunk16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
-{
-    return mmioCreateChunk(HMMIO_32(hmmio), lpck, uFlags);
-}
-
-/**************************************************************************
- * 				mmioRename     		[MMSYSTEM.1226]
- */
-MMRESULT16 WINAPI mmioRename16(LPCSTR szFileName, LPCSTR szNewFileName,
-                               MMIOINFO16* lpmmioinfo, DWORD dwRenameFlags)
-{
-    UINT16 		result = MMSYSERR_ERROR;
-    LPMMIOPROC16	ioProc;
-
-    TRACE("('%s', '%s', %p, %08lX);\n",
-	  szFileName, szNewFileName, lpmmioinfo, dwRenameFlags);
-
-    /* If both params are NULL, then parse the file name */
-    if (lpmmioinfo && lpmmioinfo->fccIOProc == 0 && lpmmioinfo->pIOProc == NULL)
-	lpmmioinfo->fccIOProc = MMIO_ParseExt(szFileName);
-
-    /* Handle any unhandled/error case from above. Assume DOS file */
-    if (!lpmmioinfo || (lpmmioinfo->fccIOProc == 0 && lpmmioinfo->pIOProc == NULL))
-	ioProc = (LPMMIOPROC16)mmioDosIOProc;
-    /* if just the four character code is present, look up IO proc */
-    else if (lpmmioinfo->pIOProc == NULL)
-	ioProc = mmioInstallIOProc16(lpmmioinfo->fccIOProc, NULL, MMIO_FINDPROC);
-    else
- 	ioProc = lpmmioinfo->pIOProc;
-
-    /* FIXME: ioProc is likely a segmented address, thus needing a
-     * thunk somewhere. The main issue is that Wine's current thunking
-     * 32 to 16 only supports pascal calling convention
-     */
-    if (ioProc)
-	result = (ioProc)(0, MMIOM_RENAME,
-			  (LPARAM)szFileName, (LPARAM)szNewFileName);
-
-    return result;
-}
-
-/**************************************************************************
  * 				mmioRenameA    			[WINMM.@]
  */
 MMRESULT WINAPI mmioRenameA(LPCSTR szFileName, LPCSTR szNewFileName,
@@ -1704,8 +1335,8 @@
 	ioProc = (LPMMIOPROC)mmioDosIOProc;
     /* if just the four character code is present, look up IO proc */
     else if (lpmmioinfo->pIOProc == NULL)
-	ioProc = MMIO_InstallIOProc(lpmmioinfo->fccIOProc, NULL,
-				    MMIO_FINDPROC, MMIO_PROC_32A);
+	ioProc = MMSYSTEM_mmioInstallIOProc(lpmmioinfo->fccIOProc, NULL,
+                                            MMIO_FINDPROC, MMIO_PROC_32A);
     else /* use relevant ioProc */
  	ioProc = lpmmioinfo->pIOProc;
 
@@ -1730,3 +1361,4 @@
     HeapFree(GetProcessHeap(),0,sznFn);
     return ret;
 }
+
Index: dlls/winmm/mmsystem.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/winmm/mmsystem.c,v
retrieving revision 1.72
diff -u -u -r1.72 mmsystem.c
--- dlls/winmm/mmsystem.c	10 Oct 2002 23:28:22 -0000	1.72
+++ dlls/winmm/mmsystem.c	13 Oct 2002 20:01:40 -0000
@@ -28,6 +28,8 @@
 
 /* FIXME: I think there are some segmented vs. linear pointer weirdnesses
  *        and long term pointers to 16 bit space in here
+ * MMIO: exporting 32 mmioProcs though 16 bit API isn't implemented (but I don't
+ *       know a program which uses them... if you do, please report)
  */
 
 #include <string.h>
@@ -44,6 +46,9 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
 
+static HANDLE MMSYSTEM_ProcHeap;
+static WORD   MMSYSTEM_ProcSel;
+
 /**************************************************************************
  * 			DllEntryPoint (MMSYSTEM.2046)
  *
@@ -73,6 +78,13 @@
 	iData = MULTIMEDIA_GetIData();
 	iData->hWinMM16Instance = hinstDLL;
 	iData->h16Module32 = hndl;
+        MMSYSTEM_ProcHeap = HeapCreate(0, 0x10000, 0x10000);
+        MMSYSTEM_ProcSel = SELECTOR_AllocBlock((void*)MMSYSTEM_ProcHeap, 0x10000,
+                                               WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
+        if (!MMSYSTEM_ProcHeap || !MMSYSTEM_ProcSel) {
+            WARN("Unable to create winproc heap\n" );
+            return FALSE;
+        }
 	break;
     case DLL_PROCESS_DETACH:
 	iData = MULTIMEDIA_GetIData();
@@ -95,6 +107,11 @@
     return TRUE;
 }
 
+/* ### start build ### */
+extern LONG CALLBACK MMSYSTEM_CallTo16_long_l    (FARPROC16,LONG);
+extern LONG CALLBACK MMSYSTEM_CallTo16_long_lwll (LPMMIOPROC16,LONG,WORD,LONG,LONG);
+/* ### stop build ### */
+
 /**************************************************************************
  * 				PlaySound		[MMSYSTEM.3]
  */
@@ -2013,10 +2030,6 @@
     return ret;
 }
 
-/* ### start build ### */
-extern LONG CALLBACK MMSYSTEM_CallTo16_long_l    (FARPROC16,LONG);
-/* ### stop build ### */
-
 /**************************************************************************
  * 				__wine_mmThreadEntryPoint (MMSYSTEM.2047)
  */
@@ -2276,3 +2289,566 @@
 
     return mciFreeCommandResource(uTable);
 }
+
+/****************************************************************
+ *       		MMIO_Map32To16			[INTERNAL]
+ */
+static LRESULT	MMIO_Map32To16(DWORD wMsg, LPARAM* lp1, LPARAM* lp2)
+{
+    switch (wMsg) {
+    case MMIOM_CLOSE:
+    case MMIOM_SEEK:
+	/* nothing to do */
+	break;
+    case MMIOM_OPEN:
+    case MMIOM_READ:
+    case MMIOM_WRITE:
+    case MMIOM_WRITEFLUSH:
+        *lp1 = MapLS((void *)*lp1);
+	break;
+    case MMIOM_RENAME:
+        *lp1 = MapLS((void *)*lp1);
+        *lp2 = MapLS((void *)*lp2);
+        break;
+    default:
+	TRACE("Not a mappable message (%ld)\n", wMsg);
+    }
+    return MMSYSERR_NOERROR;
+}
+
+/****************************************************************
+ *       	MMIO_UnMap32To16 			[INTERNAL]
+ */
+static LRESULT	MMIO_UnMap32To16(DWORD wMsg, LPARAM lParam1, LPARAM lParam2,
+				 LPARAM lp1, LPARAM lp2)
+{
+    switch (wMsg) {
+    case MMIOM_CLOSE:
+    case MMIOM_SEEK:
+	/* nothing to do */
+	break;
+    case MMIOM_OPEN:
+    case MMIOM_READ:
+    case MMIOM_WRITE:
+    case MMIOM_WRITEFLUSH:
+        UnMapLS(lp1);
+	break;
+    case MMIOM_RENAME:
+        UnMapLS(lp1);
+        UnMapLS(lp2);
+	break;
+    default:
+	TRACE("Not a mappable message (%ld)\n", wMsg);
+    }
+    return MMSYSERR_NOERROR;
+}
+
+#include "pshpack1.h"
+
+typedef struct
+{
+    BYTE         popl_eax;             /* popl  %eax (return address) */
+    BYTE         pushl_func;           /* pushl $proc */
+    LPMMIOPROC16 proc;
+    BYTE         pushl_eax;            /* pushl %eax */
+    BYTE         jmp;                  /* jmp   relay (relative jump)*/
+    void       (*relay)();             /* MMIO_CallProc32ATo16() */
+} MMIOIOPROC_THUNK_FROM32;
+
+typedef struct
+{
+    BYTE       jmp;                  /* jmp  proc (relative jump) */
+    WNDPROC    proc;
+} MMIOIOPROC_JUMP;
+
+#include "poppack.h"
+
+#define MMIOIOPROC_BLOCK_MAGIC 0xF0917183
+
+typedef struct tagMMIOIOPROC_BLOCK
+{
+    MMIOIOPROC_THUNK_FROM32     from32; /* Thunk */
+    MMIOIOPROC_JUMP             jmp;    /* Jmp */
+    DWORD                       magic;
+}
+MMIOIOPROC_BLOCK;
+
+/******************************************************************
+ *		MMIO_IsThunk
+ *
+ *
+ */
+static BOOL     MMIO_IsThunk(void* ptr)
+{
+    if (!ptr) return FALSE;
+    /* first check thunk block itself */
+    if (HeapValidate(MMSYSTEM_ProcHeap, 0, ptr) && 
+        ((MMIOIOPROC_BLOCK*)ptr)->magic == MMIOIOPROC_BLOCK_MAGIC)
+        return TRUE;
+    return FALSE;
+}
+
+/******************************************************************
+ *		MMIO_CallProc32ATo16
+ *
+ * helper function used to call back a 16 bit ioProc from 32 bit code
+ */
+static LRESULT WINAPI MMIO_CallProc32ATo16(LPMMIOPROC16 ioProc,
+                                           LPMMIOINFO lpmmioinfo, UINT uMessage,
+                                           LPARAM lParam1, LPARAM lParam2)
+{
+    MMIOINFO16          mmioInfo16;
+    LRESULT 		result;
+    LPARAM		lp1 = lParam1, lp2 = lParam2;
+
+    FIXME("whoa\n");
+
+    memset(&mmioInfo16, 0, sizeof(MMIOINFO16));
+    mmioInfo16.lDiskOffset = lpmmioinfo->lDiskOffset;
+    mmioInfo16.adwInfo[0]  = lpmmioinfo->adwInfo[0];
+    mmioInfo16.adwInfo[1]  = lpmmioinfo->adwInfo[1];
+    mmioInfo16.adwInfo[2]  = lpmmioinfo->adwInfo[2];
+    mmioInfo16.adwInfo[3]  = lpmmioinfo->adwInfo[3];
+
+    /* map (lParam1, lParam2) into (lp1, lp2) 32=>16 */
+    if ((result = MMIO_Map32To16(uMessage, &lp1, &lp2)) == MMSYSERR_NOERROR)
+    {
+        SEGPTR  segmmioInfo16 = MapLS(&mmioInfo16);
+
+        result = MMSYSTEM_CallTo16_long_lwll(ioProc, 
+                                             segmmioInfo16, uMessage, lp1, lp2);
+        UnMapLS(segmmioInfo16);
+        MMIO_UnMap32To16(uMessage, lParam1, lParam2, lp1, lp2);
+
+        lpmmioinfo->lDiskOffset = mmioInfo16.lDiskOffset;
+        lpmmioinfo->adwInfo[0]  = mmioInfo16.adwInfo[0];
+        lpmmioinfo->adwInfo[1]  = mmioInfo16.adwInfo[1];
+        lpmmioinfo->adwInfo[2]  = mmioInfo16.adwInfo[2];
+        lpmmioinfo->adwInfo[3]  = mmioInfo16.adwInfo[3];
+        lpmmioinfo->wErrorRet   = mmioInfo16.wErrorRet;
+    }
+    return result;
+}
+
+/******************************************************************
+ *		MMIO_AllocThunk16To32A
+ *
+ *
+ */
+static  MMIOIOPROC_BLOCK* MMIO_AllocThunk16To32A(LPMMIOPROC16 proc)
+{
+    MMIOIOPROC_BLOCK*   ioproc;
+
+    /* should check that we haven't created yet a thunk for 
+     * lpmmioinfo16->pIOProc
+     */
+            
+    ioproc = HeapAlloc(MMSYSTEM_ProcHeap, 0, sizeof(*ioproc));
+    if (ioproc)
+    {
+        ioproc->from32.popl_eax    = 0x58;   /* popl  %eax */
+        ioproc->from32.pushl_func  = 0x68;   /* pushl $proc */
+        ioproc->from32.proc        = proc;
+        ioproc->from32.pushl_eax   = 0x50;   /* pushl %eax */
+        ioproc->from32.jmp         = 0xe9;   /* jmp   relay*/
+        ioproc->from32.relay =  /* relative jump */
+            (void(*)())((DWORD)MMIO_CallProc32ATo16 -
+                        (DWORD)(&ioproc->from32.relay + 1));
+        ioproc->magic = MMIOIOPROC_BLOCK_MAGIC;
+    }
+    return ioproc;
+}
+
+/******************************************************************
+ *		MMIO_AllocThunk32ATo16
+ *
+ *
+ */
+static  LPMMIOPROC16 /* FIXME */ MMIO_AllocThunk32ATo16(LPMMIOPROC proc)
+{
+    WARN("Cannot expose (yet) 32bit ioproc:s through 16 bit API\n");
+    return NULL;
+}
+
+/******************************************************************
+ *		MMIO_Convert16_32
+ *
+ * Convert a 16 bit MMIOINFO struct into its 32 bit equivalent
+ */
+static void     MMIO_Convert16_32(const MMIOINFO16* lpmmioinfo16, MMIOINFO* lpmmioinfo32)
+{
+    lpmmioinfo32->dwFlags     = lpmmioinfo16->dwFlags;
+    lpmmioinfo32->fccIOProc   = lpmmioinfo16->fccIOProc;
+    if (lpmmioinfo16->pIOProc == 0)
+    {
+        lpmmioinfo32->pIOProc = 0;
+    }
+    else
+    {
+        MMIOIOPROC_BLOCK*   ioproc;
+
+        ioproc = MMIO_AllocThunk16To32A(lpmmioinfo16->pIOProc);
+        lpmmioinfo32->pIOProc = (LPMMIOPROC)ioproc;
+    }
+    lpmmioinfo32->wErrorRet   = lpmmioinfo16->wErrorRet;
+    lpmmioinfo32->hTask       = lpmmioinfo16->hTask;
+    lpmmioinfo32->cchBuffer   = lpmmioinfo16->cchBuffer;
+    lpmmioinfo32->pchBuffer   = MapSL((DWORD)lpmmioinfo16->pchBuffer);
+    lpmmioinfo32->pchNext     = lpmmioinfo32->pchBuffer + (lpmmioinfo16->pchNext     - lpmmioinfo16->pchBuffer);
+    lpmmioinfo32->pchEndRead  = lpmmioinfo32->pchBuffer + (lpmmioinfo16->pchEndRead  - lpmmioinfo16->pchBuffer);
+    lpmmioinfo32->pchEndWrite = lpmmioinfo32->pchBuffer + (lpmmioinfo16->pchEndWrite - lpmmioinfo16->pchBuffer);
+    lpmmioinfo32->lBufOffset  = lpmmioinfo16->lBufOffset;
+    lpmmioinfo32->lDiskOffset = lpmmioinfo16->lDiskOffset;
+    lpmmioinfo32->adwInfo[0]  = lpmmioinfo16->adwInfo[0];
+    lpmmioinfo32->adwInfo[1]  = lpmmioinfo16->adwInfo[1];
+    lpmmioinfo32->adwInfo[2]  = lpmmioinfo16->adwInfo[2];
+    lpmmioinfo32->adwInfo[3]  = lpmmioinfo16->adwInfo[3];
+    /* store 16 bit entities for later usage */
+    lpmmioinfo32->dwReserved1 = (DWORD)lpmmioinfo16->pchBuffer;
+    lpmmioinfo32->dwReserved1 = 0;
+    lpmmioinfo32->hmmio       = HMMIO_32(lpmmioinfo16->hmmio);
+}
+
+/******************************************************************
+ *		MMIO_Convert32_16
+ *
+ * Convert a 32 bit MMIOINFO struct into its 16 bit equivalent
+ */
+static void     MMIO_Convert32_16(const MMIOINFO* lpmmioinfo32, MMIOINFO16* lpmmioinfo16)
+{
+    lpmmioinfo16->dwFlags     = lpmmioinfo32->dwFlags;
+    lpmmioinfo16->fccIOProc   = lpmmioinfo32->fccIOProc;
+    if (MMIO_IsThunk(lpmmioinfo32->pIOProc))
+        lpmmioinfo16->pIOProc = ((MMIOIOPROC_BLOCK*)(lpmmioinfo32->pIOProc))->from32.proc;
+    else
+        lpmmioinfo16->pIOProc = MMIO_AllocThunk32ATo16(lpmmioinfo32->pIOProc);
+    lpmmioinfo16->wErrorRet   = lpmmioinfo32->wErrorRet;
+    lpmmioinfo16->hTask       = lpmmioinfo32->hTask;
+    lpmmioinfo16->cchBuffer   = lpmmioinfo32->cchBuffer;
+    lpmmioinfo16->pchBuffer   = (void*)lpmmioinfo32->dwReserved1;
+    lpmmioinfo16->pchNext     = (void*)(lpmmioinfo32->dwReserved1 + (lpmmioinfo32->pchNext - lpmmioinfo32->pchBuffer));
+    lpmmioinfo16->pchEndRead  = (void*)(lpmmioinfo32->dwReserved1 + (lpmmioinfo32->pchEndRead - lpmmioinfo32->pchBuffer));
+    lpmmioinfo16->pchEndWrite = (void*)(lpmmioinfo32->dwReserved1 + (lpmmioinfo32->pchEndWrite - lpmmioinfo32->pchBuffer));
+    lpmmioinfo16->lBufOffset  = lpmmioinfo32->lBufOffset;
+    lpmmioinfo16->lDiskOffset = lpmmioinfo32->lDiskOffset;
+    lpmmioinfo16->adwInfo[0]  = lpmmioinfo32->adwInfo[0];
+    lpmmioinfo16->adwInfo[1]  = lpmmioinfo32->adwInfo[1];
+    lpmmioinfo16->adwInfo[2]  = lpmmioinfo32->adwInfo[2];
+    lpmmioinfo16->adwInfo[3]  = lpmmioinfo32->adwInfo[3];
+    lpmmioinfo16->dwReserved1 = 0;
+    lpmmioinfo16->dwReserved2 = 0;
+    lpmmioinfo16->hmmio       = HMMIO_16(lpmmioinfo32->hmmio);
+
+}
+
+/******************************************************************
+ *		MMIO_ResetSegmentedData
+ *
+ * reset internal dwReserved1 field to segmented address of newly
+ * allocated buffer
+ */
+static void     MMIO_ResetSegmentedData(HMMIO hmmio)
+{
+    MMIOINFO    mmioinfo;
+    BOOL        set = FALSE;
+
+    if (mmioGetInfo(hmmio, &mmioinfo, 0) == MMSYSERR_NOERROR)
+    {
+        /* free segmented ptr mapping, if any */
+        if (mmioinfo.dwReserved1 != 0L)
+        {
+            UnMapLS(mmioinfo.dwReserved1);
+            mmioinfo.dwReserved1 = 0L;
+            set = TRUE; 
+       }
+
+        /* recreate the mapping if needed */
+        if (mmioinfo.dwReserved1 == 0 && mmioinfo.pchBuffer != NULL)
+        {
+            mmioinfo.dwReserved1 = MapLS(mmioinfo.pchBuffer);
+            set = TRUE;
+        }
+        /* store final results */
+        if (set) mmioSetInfo(hmmio, &mmioinfo, 0);
+    }
+}
+
+/**************************************************************************
+ * 				mmioOpen       		[MMSYSTEM.1210]
+ */
+HMMIO16 WINAPI mmioOpen16(LPSTR szFileName, MMIOINFO16* lpmmioinfo16,
+			  DWORD dwOpenFlags)
+{
+    HMMIO 	ret;
+    MMIOINFO	mmioinfo;
+
+    memset(&mmioinfo, 0, sizeof(mmioinfo));
+
+    if (lpmmioinfo16) {
+        MMIO_Convert16_32(lpmmioinfo16, &mmioinfo);
+
+	ret = mmioOpenA(szFileName, &mmioinfo, dwOpenFlags);
+        
+        if (ret != 0) MMIO_ResetSegmentedData(mmioinfo.hmmio);
+
+        MMIO_Convert32_16(&mmioinfo, lpmmioinfo16);
+    } else {
+	mmioinfo.fccIOProc = 0;
+	mmioinfo.pIOProc = NULL;
+	mmioinfo.pchBuffer = NULL;
+	mmioinfo.cchBuffer = 0;
+	ret = mmioOpenA(szFileName, &mmioinfo, dwOpenFlags);
+        if (ret != 0) MMIO_ResetSegmentedData(mmioinfo.hmmio);
+    }
+
+    return HMMIO_16(ret);
+}
+
+/**************************************************************************
+ * 				mmioClose      		[MMSYSTEM.1211]
+ */
+MMRESULT16 WINAPI mmioClose16(HMMIO16 hmmio, UINT16 uFlags)
+{
+    MMIOINFO    mmioinfo;
+    MMRESULT    ret;
+
+    if (mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, 0) != MMSYSERR_NOERROR)
+        mmioinfo.dwReserved1 = 0;
+    ret = mmioClose(HMMIO_32(hmmio), uFlags);
+    if (mmioinfo.dwReserved1 != 0L)
+        UnMapLS(mmioinfo.dwReserved1);
+    if (MMIO_IsThunk(mmioinfo.pIOProc))
+        HeapFree(MMSYSTEM_ProcHeap, 0, mmioinfo.pIOProc);
+    return ret;
+}
+
+/**************************************************************************
+ * 				mmioRead	       	[MMSYSTEM.1212]
+ */
+LONG WINAPI mmioRead16(HMMIO16 hmmio, HPSTR pch, LONG cch)
+{
+    return mmioRead(HMMIO_32(hmmio), pch, cch);
+}
+
+/**************************************************************************
+ * 				mmioWrite      		[MMSYSTEM.1213]
+ */
+LONG WINAPI mmioWrite16(HMMIO16 hmmio, HPCSTR pch, LONG cch)
+{
+    return mmioWrite(HMMIO_32(hmmio), pch, cch);
+}
+
+/**************************************************************************
+ * 				mmioSeek       		[MMSYSTEM.1214]
+ */
+LONG WINAPI mmioSeek16(HMMIO16 hmmio, LONG lOffset, INT16 iOrigin)
+{
+    return mmioSeek(HMMIO_32(hmmio), lOffset, iOrigin);
+}
+
+/**************************************************************************
+ * 				mmioGetInfo	       	[MMSYSTEM.1215]
+ */
+MMRESULT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
+{
+    MMIOINFO    mmioinfo;
+    MMRESULT    ret;
+
+    TRACE("(0x%04x,%p,0x%08x)\n", hmmio, lpmmioinfo, uFlags);
+
+    ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
+    if (ret != MMSYSERR_NOERROR) return ret;
+
+    if (!mmioinfo.dwReserved1)
+        return MMSYSERR_ERROR; /* FIXME */
+
+    MMIO_Convert32_16(&mmioinfo, lpmmioinfo);
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				mmioSetInfo  		[MMSYSTEM.1216]
+ */
+MMRESULT16 WINAPI mmioSetInfo16(HMMIO16 hmmio, const MMIOINFO16* lpmmioinfo, UINT16 uFlags)
+{
+    MMIOINFO            mmioinfo;
+    MMRESULT            ret;
+
+    TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
+
+    ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, 0);
+    if (ret != MMSYSERR_NOERROR) return ret;
+
+    /* check if seg and lin buffers are the same */
+    if (mmioinfo.cchBuffer != lpmmioinfo->cchBuffer 
+        /* FIXME || wm->info.pchBuffer != MapSL(wm->buffer16) */) 
+	return MMSYSERR_INVALPARAM;
+
+    /* check pointers coherence */
+    if (lpmmioinfo->pchNext < lpmmioinfo->pchBuffer ||
+	lpmmioinfo->pchNext > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
+	lpmmioinfo->pchEndRead < lpmmioinfo->pchBuffer ||
+	lpmmioinfo->pchEndRead > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
+	lpmmioinfo->pchEndWrite < lpmmioinfo->pchBuffer ||
+	lpmmioinfo->pchEndWrite > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer)
+	return MMSYSERR_INVALPARAM;
+
+    MMIO_Convert16_32(lpmmioinfo, &mmioinfo);
+
+    return mmioSetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
+}
+
+/**************************************************************************
+ * 				mmioSetBuffer		[MMSYSTEM.1217]
+ */
+MMRESULT16 WINAPI mmioSetBuffer16(HMMIO16 hmmio, LPSTR pchBuffer,
+                                  LONG cchBuffer, UINT16 uFlags)
+{
+    MMRESULT    ret;
+
+    ret = mmioSetBuffer(HMMIO_32(hmmio), pchBuffer, cchBuffer, uFlags);
+    if (ret == MMSYSERR_NOERROR)
+        MMIO_ResetSegmentedData(HMMIO_32(hmmio));
+
+    return ret;
+}
+
+/**************************************************************************
+ * 				mmioFlush      		[MMSYSTEM.1218]
+ */
+MMRESULT16 WINAPI mmioFlush16(HMMIO16 hmmio, UINT16 uFlags)
+{
+    return mmioFlush(HMMIO_32(hmmio), uFlags);
+}
+
+/***********************************************************************
+ * 				mmioAdvance    		[MMSYSTEM.1219]
+ */
+MMRESULT16 WINAPI mmioAdvance16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
+{
+    MMIOINFO    mmioinfo;
+    LRESULT     ret;
+
+    /* FIXME: this heavily relies on mmioAdvance implementation (for choosing which
+     * fields to init
+     */
+    if (lpmmioinfo)
+    {
+        mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo->pchBuffer);
+        mmioinfo.pchNext = MapSL((DWORD)lpmmioinfo->pchNext);
+        mmioinfo.dwFlags = lpmmioinfo->dwFlags;
+        mmioinfo.lBufOffset = lpmmioinfo->lBufOffset;
+        ret = mmioAdvance(HMMIO_32(hmmio), &mmioinfo, uFlags);
+    }
+    else
+        ret = mmioAdvance(HMMIO_32(hmmio), NULL, uFlags);
+        
+    if (ret != MMSYSERR_NOERROR) return ret;
+
+    if (lpmmioinfo)
+    {
+        lpmmioinfo->dwFlags = mmioinfo.dwFlags;
+        lpmmioinfo->pchNext     = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchNext - mmioinfo.pchBuffer));
+        lpmmioinfo->pchEndRead  = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
+        lpmmioinfo->pchEndWrite = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
+        lpmmioinfo->lBufOffset  = mmioinfo.lBufOffset;
+        lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
+    }
+
+    return MMSYSERR_NOERROR;
+}
+
+/**************************************************************************
+ * 				mmioStringToFOURCC	[MMSYSTEM.1220]
+ */
+FOURCC WINAPI mmioStringToFOURCC16(LPCSTR sz, UINT16 uFlags)
+{
+    return mmioStringToFOURCCA(sz, uFlags);
+}
+
+/**************************************************************************
+ *              mmioInstallIOProc    [MMSYSTEM.1221]
+ */
+LPMMIOPROC16 WINAPI mmioInstallIOProc16(FOURCC fccIOProc, LPMMIOPROC16 pIOProc,
+                                        DWORD dwFlags)
+{
+    LPMMIOPROC          ioProc;
+    LPMMIOPROC16        ret = NULL;
+    switch (dwFlags & (MMIO_FINDPROC|MMIO_INSTALLPROC|MMIO_REMOVEPROC))
+    {
+    case MMIO_FINDPROC:
+        ioProc = mmioInstallIOProcA(fccIOProc, NULL, dwFlags);
+        break;
+    case MMIO_INSTALLPROC:
+        /* should check whether we've already allocated a thunk here */
+        ioProc = mmioInstallIOProcA(fccIOProc, 
+                                    (LPMMIOPROC)MMIO_AllocThunk16To32A(pIOProc),
+                                    dwFlags);
+        break;
+    case MMIO_REMOVEPROC:
+        ioProc = mmioInstallIOProcA(fccIOProc, NULL, dwFlags);
+        break;
+    default:
+        FIXME("Unsupported flag %08lx\n", dwFlags);
+        ioProc = NULL;
+        break;
+    }
+    if (MMIO_IsThunk(ioProc))
+    {
+        ret = ((MMIOIOPROC_BLOCK*)(ioProc))->from32.proc;
+        if (ret)
+            HeapFree(MMSYSTEM_ProcHeap, 0, ioProc);
+    }
+    else
+        ret = MMIO_AllocThunk32ATo16(ioProc);
+    return NULL;
+}
+
+/**************************************************************************
+ * 				mmioSendMessage	[MMSYSTEM.1222]
+ */
+LRESULT WINAPI mmioSendMessage16(HMMIO16 hmmio, UINT16 uMessage,
+				 LPARAM lParam1, LPARAM lParam2)
+{
+    return mmioSendMessage(HMMIO_32(hmmio), uMessage, 
+                           lParam1, lParam2);
+}
+
+/**************************************************************************
+ * 				mmioDescend	       	[MMSYSTEM.1223]
+ */
+MMRESULT16 WINAPI mmioDescend16(HMMIO16 hmmio, LPMMCKINFO lpck,
+                                const MMCKINFO* lpckParent, UINT16 uFlags)
+{
+    return mmioDescend(HMMIO_32(hmmio), lpck, lpckParent, uFlags);
+}
+
+/**************************************************************************
+ * 				mmioAscend     		[MMSYSTEM.1224]
+ */
+MMRESULT16 WINAPI mmioAscend16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
+{
+    return mmioAscend(HMMIO_32(hmmio),lpck,uFlags);
+}
+
+/**************************************************************************
+ * 				mmioCreateChunk		[MMSYSTEM.1225]
+ */
+MMRESULT16 WINAPI mmioCreateChunk16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
+{
+    return mmioCreateChunk(HMMIO_32(hmmio), lpck, uFlags);
+}
+
+/**************************************************************************
+ * 				mmioRename     		[MMSYSTEM.1226]
+ */
+MMRESULT16 WINAPI mmioRename16(LPCSTR szFileName, LPCSTR szNewFileName,
+                               MMIOINFO16* lpmmioinfo, DWORD dwRenameFlags)
+{
+    MMIOINFO    mmioinfo;
+
+    MMIO_Convert16_32(lpmmioinfo, &mmioinfo);
+    return mmioRenameA(szFileName, szNewFileName, &mmioinfo, dwRenameFlags);
+}
+
Index: dlls/winmm/mmsystem.spec
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/winmm/mmsystem.spec,v
retrieving revision 1.11
diff -u -u -r1.11 mmsystem.spec
--- dlls/winmm/mmsystem.spec	21 Jun 2002 19:15:50 -0000	1.11
+++ dlls/winmm/mmsystem.spec	12 Oct 2002 08:35:14 -0000
@@ -153,7 +153,7 @@
 1214   pascal  mmioSeek(word long word) mmioSeek16
 1215   pascal  mmioGetInfo(word ptr word) mmioGetInfo16
 1216   pascal  mmioSetInfo(word ptr word) mmioSetInfo16
-1217   pascal  mmioSetBuffer(word segptr long word) mmioSetBuffer16
+1217   pascal  mmioSetBuffer(word ptr long word) mmioSetBuffer16
 1218   pascal  mmioFlush(word word) mmioFlush16
 1219   pascal  mmioAdvance(word ptr word) mmioAdvance16
 1220   pascal  mmioStringToFOURCC(str word) mmioStringToFOURCC16
Index: dlls/winmm/winemm.h
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/winmm/winemm.h,v
retrieving revision 1.24
diff -u -u -r1.24 winemm.h
--- dlls/winmm/winemm.h	10 Oct 2002 23:28:22 -0000	1.24
+++ dlls/winmm/winemm.h	13 Oct 2002 15:27:02 -0000
@@ -149,8 +149,6 @@
     MMIOINFO			info;
     struct IOProcList*		ioProc;
     BOOL			bTmpIOProc;
-    HANDLE			hMem;
-    SEGPTR			buffer16;
     struct tagWINE_MMIO*	lpNext;
     BOOL			bBufferLoaded;
     DWORD                       dwFileSize;

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux