Release 950620

Mon Jun 19 20:29:50 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)

	* [debugger/*.c]
	Modified debugger to use segmented pointers everywhere.

	* [if1632/shell.spec] [if1632/sound.spec] [if1632/user.spec]
	Declared all functions that return only 16-bit as 'pascal16'.

	* [include/ldt.h] [memory/ldt.c]
	Export LDT_EntryToBytes (new) and LDT_BytesToEntry for DPMI.
	Maintain a copy of the selector flags, removing the need to make a
	system call to retrieve an LDT entry.

	* [loader/module.c]
	Fixed bug with module file handle cache.

	* [loader/ne_resource.c]
	Fixed file name bug in NE_AccessResource().

	* [loader/resource.c]
	Fixed bug in LoadIcon() that caused wrong colors to be used for
	the icon mask.

	* [loader/signal.c]
	Moved instruction emulation to miscemu/instr.c.

	* [misc/dos_fs.c] [miscemu/int21.c]
	Lots of small fixes, thanks to Morten Welinder.

	* [miscemu/dpmi.c]
	More complete DPMI emulation.

	* [miscemu/instr.c]
	Added support for prefixes in instructions to emulate.

	* [miscemu/int2f.c]
	Use register macros instead of destroying the high part of 32-bit
	registers.

	* [objects/dc.c]
	Fixed bug in GetDCState() that failed to clear the new DC.

	* [rc/sysres.rc]
	Removed dialogs 11 and 12 that were never used.

	* [tools/build.c]
	'pascal16' generated functions did not save %dx.
	Removed use of %fs to access the stack.
	%ds is no longer initialized before calling a 16-bit routine.

	* [windows/defwnd.c]
	Accept a NULL pointer as window title.

	* [windows/mdi.c]
	MDICascade: skip iconic windows.
	Implemented CalcChildScroll().
	
	* [windows/utility.c]
	Fixed MulDiv() for illegal values.

	* [windows/win.c]
	Fixed X error in CreateWindowEx() when WM_NCCALCSIZE returned
	a zero width or height.

Sun Jun 18 22:22:30 MET DST 1995  Fons Botman  (botman@inter.nl.net)

	* [controls/edit.c]
	Fixed "uninitalized" message which -Wall couldnt see to be ok
	in EDIT_WriteText.

	* [include/debug.h]
	Added define for extra checks in API definitions during debugging.

	* [loader/ne_image.c]
	Added newline in NE_FixupPrologs to avoid long lines.

	* [misc/dos_fs.c]
	Added extra safety check in DOS_ValidDrive.

	* [misc/exec.c]
	Fixed definition of ExitWindows.
	
Sun Jun 18 21:16:08 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>

	* [controls/edit.c]
	Some fixes, mostly for memory management, but also for text selection
	and tab postitions. General cleanup. Notepad.exe now works.

	* [controls/combo.c]
	Fix: the hwnd field of the DRAWITEMSTRUCT should always be that of
	the combo box, not the ComboLBox that belongs to it.

	* [controls/listbox.c]
	Handle itemID field correctly throughout.

	* [memory/local.c]
	Implemented flag LMEM_ZEROINIT.
	LocalReAlloc() could trash the heap. Fixed.

	* [objects/font.c]
	FONT_MatchFont(): don't get confused by negative widths.
	Fixed a segfault in EnumFonts().

	* [objects/text.c]
	DrawText(): DT_CALCRECT implies DT_NOCLIP.

	* [objects/dcvalues.c]
	MAKELONG was used with bad parameters in DC_GET_X_Y.

	* [windows/dialog.c]
	Don't show the dialog if WS_VISIBLE isn't set in the template.

	* [windows/utility.c]
	UTILITY_convertArgs(): Never pass an expression containing ++ into a
	macro...

	* [windows/win.c]
	SetParent() should unlink the window before changing the parent.

	* [windows/message.c]
	Don't call timer functions via CallWindowProc(), since it checks
	whether hwnd==0 and does not call the function in that case.

	* [miscemu/instr.c]
	Ignore interrupt 0x3D, for VBRUN300.DLL.

	* [misc/commdlg.c]
	Don't rely on the itemData field of the DRAWITEMSTRUCT to contain a
	pointer to the item text.

	* [if1632/relay.c]
	Disable OLE and DDEML DLLs by default, since they contain nothing but
	stubs anyway. SHELL, COMMDLG and WIN87EM are left enabled, although
	some programs may work better without them.
	
	* [multimedia/*.c] [include/multimedia.h] [include/driver.h]
	Begun cleaning things up a little. Replaced printfs with dprintf_
	macros, made functions static where possible, and some other minor
	changes.

Sun Jun 11 23:19:10 1995  Martin von Loewis  <martin@informatik.hu-berlin.de>

	* [debugger/dbg.y][debugger/dbg.l]
	Removed special handling for FILE_IDENTIFER, because it caused
	problems with x/<format> statements.

	* [debugger/info.c]
	Use SC_ESP instead of SC_EIP for stack dump.

	* [misc/compobj.c][if1632/compobj.spec]
	CoBuildVersion, CoInitialize, CoUninitialize: new functions

	* [misc/ole2.c][if1632/ole2.spec][misc/Imakefile][include/ole2.h]
	New files ole2.c, ole2.h
	OleBuildVersion, OleInitialize, OleUninitialize: new functions

	* [if1632/ole2disp.spec]
	Added missing ordinals above 109

	* [misc/ole2nls.c][if1632/ole2nls.spec][include/winnls.h]
	New file winnls.h
	GetLocaleInfoA: new function

	* [if1632/shell.spec]
	Added FindEnvironmentString as stub

	* [misc/olecli.c][if1632/olecli.spec]
	OleIsDcMeta: New function

	* [objects/font][misc/gdi.spec]
	GetKerningPairs: new function

	* [misc/shell.c]
	ShellExecute: Implemented support for starting programs

	* [if1632/user.spec]
	Inserted missing relay to GetClipCursor

Sun Jun 11 20:34:47 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
        
	* [controls/edit.c]
	Fix a problem with the local heap.

	* [include/wintypes.h]
	Fixed wrong declarations of CATCHBUF and LPCATCHBUF.
	
	* [include/mdi.h] [windows/mdi.c]
	This code still assumed segmented address==linear address. Fixed.

	* [include/msdos.h] [misc/dos_fs.c]
	The filemask field of the dosdirent structure could be overrun. Fixed.
	If you had a file called foobar and a file called foo, trying to 
	FindFile(foo) could accidentally find file foobar instead. Fixed.
	
	* [misc/file.c]
	OpenFile(): Always return the full pathname in ofs->szPathName. This 
	also fixes GetModuleFilename().
	Prevent _lclose() from closing stderr or stdout.

	* [misc/profile.c]
	Search for .ini files in the path of the current module as well.
	(Needed by Lotus Organizer.)

	* [loader/task.c] [loader/ne_image.c] [loader/module.c]
	[memory/local.c]
	Local heaps are now initialized by InitTask() for executables. DLLs
	have to call LocalInit() themselves, LocalInit() has to put the
	heap at the end of the segment when called with start==0. We no longer
	allocate the DGROUP with 64k on startup, but grow the local heap
	in LOCAL_GetBlock() when necessary.

        * [loader/module.c]
	LoadLibrary() should call LoadModule() in all cases, even if the
	DLL is already loaded, to ensure that the reference count is correct.

	* [loader/ne_image.c]
	Some changes to function prolog fixup. Does anyone know exactly how
	this is supposed to work? I am only guessing here.
	In NE_InitializeDLLs(), initialize the DLLs a module refers to before
	the module itself.
	
        * [loader/task.c]
	Initialize instance data at the beginning of the DGROUP in InitTask().

	* [memory/local.c]
	Some fixes for moveable blocks.

	* [memory/selector.c]
	All the IsBad*Pointer() functions returned exactly the wrong boolean
	value in all cases!
	
	* [objects/bitblt.c]
	Fixed another null pointer dereference in debugging output.
	
	* [objects/font.c]
	Some more recovery possibilities for FONT_MatchFont() if a specified
	font does not exist.
	
	* [windows/win.c]
	The dialog code may call CreateWindowEx with an integer in windowName.
	This happens for static icon controls that expect a resource ID as
	the window name. CreateWindowEx() used to crash. Fixed.
	
	* [windows/class.c] [windows/win.c]
	Window classes are owned by modules, not instances. Changed
	RegisterClass(), UnregisterClass(), GetClassInfo() and CreateWindowEx()
	accordingly.

Sat Jun 10 16:10:53 1995  Olaf Flebbe <o.flebbe@science-computing.uni-tuebingen.de>

	* [miscemu/int21.c]
	  clock.exe was displaying incorrect year.

Fri Jun 9 20:36:56 1995  Victor Schneider <tailor@crl.com>

	* [include/cursor.h] [windows/cursor.c]
	Implemented CreateCursorIconIndirect().
diff --git a/ANNOUNCE b/ANNOUNCE
index 1fbc97c..97b66e2 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,14 +1,15 @@
-This is release 950606 of Wine the MS Windows emulator.  This is still a
+This is release 950620 of Wine the MS Windows emulator.  This is still a
 developer's only release.  There are many bugs and many unimplemented API
 features.  Most applications still do not work.
 
 Patches should be submitted to "wine-new@amscons.com".  Please don't forget
 to include a ChangeLog entry.  I'll make a new release every other Sunday.
 
-WHAT'S NEW with Wine-950606: (see ChangeLog for details)
-	- Lots of module fixes.
-	- Better interrupt vectors emulation.
-	- Stack no longer limited to 64k when calling X bitmap functions.
+WHAT'S NEW with Wine-950620: (see ChangeLog for details)
+	- Many fixes to edit and listbox controls.
+	- Better MDI code.
+	- Many local heap fixes.
+	- Some built-in DLLs are now disabled by default.
 	- Lots of bug fixes.
 
 See the README file in the distribution for installation instructions.
@@ -17,11 +18,11 @@
 the release is available at the ftp sites.  The sources will be available
 from the following locations:
 
-    sunsite.unc.edu:/pub/Linux/ALPHA/wine/Wine-950606.tar.gz
-    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-950606.tar.gz
-    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-950606.tar.gz
-    ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-950606.tar.gz
-    aris.com:/pub/linux/ALPHA/Wine/development/Wine-950606.tar.gz
+    sunsite.unc.edu:/pub/Linux/ALPHA/wine/Wine-950620.tar.gz
+    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-950620.tar.gz
+    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-950620.tar.gz
+    ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-950620.tar.gz
+    aris.com:/pub/linux/ALPHA/Wine/development/Wine-950620.tar.gz
 
 It should also be available from any site that mirrors tsx-11 or sunsite.
 
diff --git a/ChangeLog b/ChangeLog
index 4cef5d6..3766178 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,263 @@
 ----------------------------------------------------------------------
+Mon Jun 19 20:29:50 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)
+
+	* [debugger/*.c]
+	Modified debugger to use segmented pointers everywhere.
+
+	* [if1632/shell.spec] [if1632/sound.spec] [if1632/user.spec]
+	Declared all functions that return only 16-bit as 'pascal16'.
+
+	* [include/ldt.h] [memory/ldt.c]
+	Export LDT_EntryToBytes (new) and LDT_BytesToEntry for DPMI.
+	Maintain a copy of the selector flags, removing the need to make a
+	system call to retrieve an LDT entry.
+
+	* [loader/module.c]
+	Fixed bug with module file handle cache.
+
+	* [loader/ne_resource.c]
+	Fixed file name bug in NE_AccessResource().
+
+	* [loader/resource.c]
+	Fixed bug in LoadIcon() that caused wrong colors to be used for
+	the icon mask.
+
+	* [loader/signal.c]
+	Moved instruction emulation to miscemu/instr.c.
+
+	* [misc/dos_fs.c] [miscemu/int21.c]
+	Lots of small fixes, thanks to Morten Welinder.
+
+	* [miscemu/dpmi.c]
+	More complete DPMI emulation.
+
+	* [miscemu/instr.c]
+	Added support for prefixes in instructions to emulate.
+
+	* [miscemu/int2f.c]
+	Use register macros instead of destroying the high part of 32-bit
+	registers.
+
+	* [objects/dc.c]
+	Fixed bug in GetDCState() that failed to clear the new DC.
+
+	* [rc/sysres.rc]
+	Removed dialogs 11 and 12 that were never used.
+
+	* [tools/build.c]
+	'pascal16' generated functions did not save %dx.
+	Removed use of %fs to access the stack.
+	%ds is no longer initialized before calling a 16-bit routine.
+
+	* [windows/defwnd.c]
+	Accept a NULL pointer as window title.
+
+	* [windows/mdi.c]
+	MDICascade: skip iconic windows.
+	Implemented CalcChildScroll().
+	
+	* [windows/utility.c]
+	Fixed MulDiv() for illegal values.
+
+	* [windows/win.c]
+	Fixed X error in CreateWindowEx() when WM_NCCALCSIZE returned
+	a zero width or height.
+
+Sun Jun 18 22:22:30 MET DST 1995  Fons Botman  (botman@inter.nl.net)
+
+	* [controls/edit.c]
+	Fixed "uninitalized" message which -Wall couldnt see to be ok
+	in EDIT_WriteText.
+
+	* [include/debug.h]
+	Added define for extra checks in API definitions during debugging.
+
+	* [loader/ne_image.c]
+	Added newline in NE_FixupPrologs to avoid long lines.
+
+	* [misc/dos_fs.c]
+	Added extra safety check in DOS_ValidDrive.
+
+	* [misc/exec.c]
+	Fixed definition of ExitWindows.
+	
+Sun Jun 18 21:16:08 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
+
+	* [controls/edit.c]
+	Some fixes, mostly for memory management, but also for text selection
+	and tab postitions. General cleanup. Notepad.exe now works.
+
+	* [controls/combo.c]
+	Fix: the hwnd field of the DRAWITEMSTRUCT should always be that of
+	the combo box, not the ComboLBox that belongs to it.
+
+	* [controls/listbox.c]
+	Handle itemID field correctly throughout.
+
+	* [memory/local.c]
+	Implemented flag LMEM_ZEROINIT.
+	LocalReAlloc() could trash the heap. Fixed.
+
+	* [objects/font.c]
+	FONT_MatchFont(): don't get confused by negative widths.
+	Fixed a segfault in EnumFonts().
+
+	* [objects/text.c]
+	DrawText(): DT_CALCRECT implies DT_NOCLIP.
+
+	* [objects/dcvalues.c]
+	MAKELONG was used with bad parameters in DC_GET_X_Y.
+
+	* [windows/dialog.c]
+	Don't show the dialog if WS_VISIBLE isn't set in the template.
+
+	* [windows/utility.c]
+	UTILITY_convertArgs(): Never pass an expression containing ++ into a
+	macro...
+
+	* [windows/win.c]
+	SetParent() should unlink the window before changing the parent.
+
+	* [windows/message.c]
+	Don't call timer functions via CallWindowProc(), since it checks
+	whether hwnd==0 and does not call the function in that case.
+
+	* [miscemu/instr.c]
+	Ignore interrupt 0x3D, for VBRUN300.DLL.
+
+	* [misc/commdlg.c]
+	Don't rely on the itemData field of the DRAWITEMSTRUCT to contain a
+	pointer to the item text.
+
+	* [if1632/relay.c]
+	Disable OLE and DDEML DLLs by default, since they contain nothing but
+	stubs anyway. SHELL, COMMDLG and WIN87EM are left enabled, although
+	some programs may work better without them.
+	
+	* [multimedia/*.c] [include/multimedia.h] [include/driver.h]
+	Begun cleaning things up a little. Replaced printfs with dprintf_
+	macros, made functions static where possible, and some other minor
+	changes.
+
+Sun Jun 11 23:19:10 1995  Martin von Loewis  <martin@informatik.hu-berlin.de>
+
+	* [debugger/dbg.y][debugger/dbg.l]
+	Removed special handling for FILE_IDENTIFER, because it caused
+	problems with x/<format> statements.
+
+	* [debugger/info.c]
+	Use SC_ESP instead of SC_EIP for stack dump.
+
+	* [misc/compobj.c][if1632/compobj.spec]
+	CoBuildVersion, CoInitialize, CoUninitialize: new functions
+
+	* [misc/ole2.c][if1632/ole2.spec][misc/Imakefile][include/ole2.h]
+	New files ole2.c, ole2.h
+	OleBuildVersion, OleInitialize, OleUninitialize: new functions
+
+	* [if1632/ole2disp.spec]
+	Added missing ordinals above 109
+
+	* [misc/ole2nls.c][if1632/ole2nls.spec][include/winnls.h]
+	New file winnls.h
+	GetLocaleInfoA: new function
+
+	* [if1632/shell.spec]
+	Added FindEnvironmentString as stub
+
+	* [misc/olecli.c][if1632/olecli.spec]
+	OleIsDcMeta: New function
+
+	* [objects/font][misc/gdi.spec]
+	GetKerningPairs: new function
+
+	* [misc/shell.c]
+	ShellExecute: Implemented support for starting programs
+
+	* [if1632/user.spec]
+	Inserted missing relay to GetClipCursor
+
+Sun Jun 11 20:34:47 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
+        
+	* [controls/edit.c]
+	Fix a problem with the local heap.
+
+	* [include/wintypes.h]
+	Fixed wrong declarations of CATCHBUF and LPCATCHBUF.
+	
+	* [include/mdi.h] [windows/mdi.c]
+	This code still assumed segmented address==linear address. Fixed.
+
+	* [include/msdos.h] [misc/dos_fs.c]
+	The filemask field of the dosdirent structure could be overrun. Fixed.
+	If you had a file called foobar and a file called foo, trying to 
+	FindFile(foo) could accidentally find file foobar instead. Fixed.
+	
+	* [misc/file.c]
+	OpenFile(): Always return the full pathname in ofs->szPathName. This 
+	also fixes GetModuleFilename().
+	Prevent _lclose() from closing stderr or stdout.
+
+	* [misc/profile.c]
+	Search for .ini files in the path of the current module as well.
+	(Needed by Lotus Organizer.)
+
+	* [loader/task.c] [loader/ne_image.c] [loader/module.c]
+	[memory/local.c]
+	Local heaps are now initialized by InitTask() for executables. DLLs
+	have to call LocalInit() themselves, LocalInit() has to put the
+	heap at the end of the segment when called with start==0. We no longer
+	allocate the DGROUP with 64k on startup, but grow the local heap
+	in LOCAL_GetBlock() when necessary.
+
+        * [loader/module.c]
+	LoadLibrary() should call LoadModule() in all cases, even if the
+	DLL is already loaded, to ensure that the reference count is correct.
+
+	* [loader/ne_image.c]
+	Some changes to function prolog fixup. Does anyone know exactly how
+	this is supposed to work? I am only guessing here.
+	In NE_InitializeDLLs(), initialize the DLLs a module refers to before
+	the module itself.
+	
+        * [loader/task.c]
+	Initialize instance data at the beginning of the DGROUP in InitTask().
+
+	* [memory/local.c]
+	Some fixes for moveable blocks.
+
+	* [memory/selector.c]
+	All the IsBad*Pointer() functions returned exactly the wrong boolean
+	value in all cases!
+	
+	* [objects/bitblt.c]
+	Fixed another null pointer dereference in debugging output.
+	
+	* [objects/font.c]
+	Some more recovery possibilities for FONT_MatchFont() if a specified
+	font does not exist.
+	
+	* [windows/win.c]
+	The dialog code may call CreateWindowEx with an integer in windowName.
+	This happens for static icon controls that expect a resource ID as
+	the window name. CreateWindowEx() used to crash. Fixed.
+	
+	* [windows/class.c] [windows/win.c]
+	Window classes are owned by modules, not instances. Changed
+	RegisterClass(), UnregisterClass(), GetClassInfo() and CreateWindowEx()
+	accordingly.
+
+Sat Jun 10 16:10:53 1995  Olaf Flebbe <o.flebbe@science-computing.uni-tuebingen.de>
+
+	* [miscemu/int21.c]
+	  clock.exe was displaying incorrect year.
+
+Fri Jun 9 20:36:56 1995  Victor Schneider <tailor@crl.com>
+
+	* [include/cursor.h] [windows/cursor.c]
+	Implemented CreateCursorIconIndirect().
+
+----------------------------------------------------------------------
 Tue Jun  6 12:11:41 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)
 
 	* [controls/menu.c]
diff --git a/controls/combo.c b/controls/combo.c
index 34111d7..abf7abb 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -17,7 +17,6 @@
 #include "user.h"
 #include "win.h"
 #include "stddebug.h"
-/* #define DEBUG_COMBO */
 #include "debug.h"
 #include "graphics.h"
 #include "listbox.h"
@@ -791,6 +790,7 @@
   PAINTSTRUCT  ps;
   HBRUSH       hBrush;
   HFONT        hOldFont;
+  HWND  combohwnd = CLBoxGetCombo(hwnd);
   HDC 	hdc;
   RECT 	rect;
   int   i, top, height;
@@ -829,15 +829,15 @@
 
       dprintf_listbox(stddeb,"drawing item: %d %d %d %d %d\n",rect.left,top,rect.right,top+height,lpls->itemState);
       if (OWNER_DRAWN(lphl)) {
-	ListBoxDrawItem (hwnd, lphl, hdc, lpls, &lpls->itemRect, ODA_DRAWENTIRE, 0);
+	ListBoxDrawItem (combohwnd, lphl, hdc, lpls, &lpls->itemRect, ODA_DRAWENTIRE, 0);
 	if (lpls->itemState)
-	  ListBoxDrawItem (hwnd, lphl, hdc, lpls, &lpls->itemRect, ODA_SELECT, ODS_SELECTED);
+	  ListBoxDrawItem (combohwnd, lphl, hdc, lpls, &lpls->itemRect, ODA_SELECT, ODS_SELECTED);
       } else {
-	ListBoxDrawItem (hwnd, lphl, hdc, lpls, &lpls->itemRect, ODA_DRAWENTIRE, 
+	ListBoxDrawItem (combohwnd, lphl, hdc, lpls, &lpls->itemRect, ODA_DRAWENTIRE, 
 			 lpls->itemState);
       }
       if ((lphl->ItemFocused == i) && GetFocus() == hwnd)
-	ListBoxDrawItem (hwnd,lphl, hdc, lpls, &lpls->itemRect, ODA_FOCUS, ODS_FOCUS);
+	ListBoxDrawItem (combohwnd, lphl, hdc, lpls, &lpls->itemRect, ODA_FOCUS, ODS_FOCUS);
 
       top += height;
       lphl->ItemsVisible++;
@@ -876,7 +876,6 @@
 static LONG CBLLButtonDown( HWND hwnd, WORD message, WORD wParam, LONG lParam )
 {
   LPHEADLIST lphl = CLBoxGetListHeader(hwnd);
-  WORD       wRet;
   int        y;
   RECT       rectsel;
 
diff --git a/controls/edit.c b/controls/edit.c
index 2109aa3..d860e84 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -5,9 +5,7 @@
  *
  * Release 3, July 1994
  * April 1995 bug fixes (William Magro)
-
-static char Copyright[] = "Copyright  David W. Metcalfe, 1994";
-*/
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -18,8 +16,6 @@
 #include "class.h"
 #include "user.h"
 #include "stddebug.h"
-/* #define DEBUG_EDIT */
-/* #undef  DEBUG_EDIT */
 #include "debug.h"
 
 
@@ -32,9 +28,6 @@
 #define ENTRYLEN     256   /* starting length for single line control */
 #define GROWLENGTH    64   /* buffers grow by this much */
 
-#define HSCROLLDIM (ClientWidth(wndPtr) / 3)
-                           /* "line" dimension for horizontal scroll */
-
 typedef struct
 {
     int wlines;              /* number of lines of text */
@@ -45,9 +38,9 @@
     RECT fmtrc;              /* rectangle in which to format text */
     int txtht;               /* height of text line in pixels */
     HANDLE hText;            /* handle to text buffer */
-    HANDLE hCharWidths;      /* widths of chars in font */
-    HANDLE hTextPtrs;        /* list of line offsets */
-    HANDLE hBlankLine;       /* to fill blank lines quickly */
+    short *CharWidths;       /* widths of chars in font */
+    unsigned int *textptrs;  /* list of line offsets */
+    char *BlankLine;         /* to fill blank lines quickly */
     int CurrCol;             /* current column */
     int CurrLine;            /* current line */
     int WndCol;              /* current window column */
@@ -65,32 +58,28 @@
     int DeletedCurrLine;     /* starting line from which text was deleted */
     int DeletedCurrCol;      /* starting col from which text was deleted */
     int NumTabStops;         /* number of tab stops in buffer hTabStops */
-    HANDLE hTabStops;        /* handle of tab stops buffer */
+    unsigned short *TabStops;/* tab stops buffer */
     BOOL HaveFocus;          /* TRUE if this edit has the focus */
+    int ClientWidth;         /* computed from the window's ClientRect */
+    int ClientHeight;        /* dito */
 } EDITSTATE;
 
-
-#define ClientWidth(wndPtr) \
-	(wndPtr->rectClient.right > wndPtr->rectClient.left ? \
-	wndPtr->rectClient.right - wndPtr->rectClient.left : 0)
-#define ClientHeight(wndPtr, es) \
-	(wndPtr->rectClient.bottom > wndPtr->rectClient.top ? \
-	(wndPtr->rectClient.bottom - wndPtr->rectClient.top) / es->txtht : 0)
-#define EditBufLen(wndPtr) (wndPtr->dwStyle & ES_MULTILINE \
-			    ? EDITLEN : ENTRYLEN)
+#define EditBufStartLen(hwnd) (GetWindowLong(hwnd,GWL_STYLE) & ES_MULTILINE \
+			       ? EDITLEN : ENTRYLEN)
 #define CurrChar (EDIT_TextLine(hwnd, es->CurrLine) + es->CurrCol)
-#define SelMarked(es) (es->SelBegLine != 0 || es->SelBegCol != 0 || \
-		       es->SelEndLine != 0 || es->SelEndCol != 0)
+#define SelMarked(es) ((es)->SelBegLine != 0 || (es)->SelBegCol != 0 || \
+		       (es)->SelEndLine != 0 || (es)->SelEndCol != 0)
 #define ROUNDUP(numer, denom) (((numer) % (denom)) \
 			       ? ((((numer) + (denom)) / (denom)) * (denom)) \
 			       : (numer) + (denom))
 
+/* "line" dimension for horizontal scroll */
+#define HSCROLLDIM(es) ((es)->ClientWidth / 3)
+
 /* macros to access window styles */
-#define IsAutoVScroll() (wndPtr->dwStyle & ES_AUTOVSCROLL)
-#define IsAutoHScroll() (wndPtr->dwStyle & ES_AUTOHSCROLL)
-#define IsMultiLine() (wndPtr->dwStyle & ES_MULTILINE)
-#define IsVScrollBar() (wndPtr->dwStyle & WS_VSCROLL)
-#define IsHScrollBar() (wndPtr->dwStyle & WS_HSCROLL)
+#define IsMultiLine(hwnd) (GetWindowLong(hwnd,GWL_STYLE) & ES_MULTILINE)
+#define IsVScrollBar(hwnd) (GetWindowLong(hwnd,GWL_STYLE) & WS_VSCROLL)
+#define IsHScrollBar(hwnd) (GetWindowLong(hwnd,GWL_STYLE) & WS_HSCROLL)
 
 /* internal variables */
 static BOOL TextMarking;         /* TRUE if text marking in progress */
@@ -98,92 +87,2528 @@
 static int ButtonRow;              /* row in text buffer when button pressed */
 static int ButtonCol;              /* col in text buffer when button pressed */
 
+#define SWAP_INT(x,y) do { int temp = (x); (x) = (y); (y) = temp; } while(0)
 
-LONG EditWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam);
-long EDIT_NCCreateMsg(HWND hwnd, LONG lParam);
-long EDIT_CreateMsg(HWND hwnd, LONG lParam);
-void EDIT_ClearTextPointers(HWND hwnd);
-void EDIT_BuildTextPointers(HWND hwnd);
-void EDIT_ModTextPointers(HWND hwnd, int lineno, int var);
-void EDIT_PaintMsg(HWND hwnd);
-HANDLE EDIT_GetTextLine(HWND hwnd, int selection);
-char *EDIT_TextLine(HWND hwnd, int sel);
-int EDIT_StrLength(HWND hwnd, unsigned char *str, int len, int pcol);
-int EDIT_LineLength(HWND hwnd, int num);
-void EDIT_WriteTextLine(HWND hwnd, RECT *rc, int y);
-void EDIT_WriteText(HWND hwnd, char *lp, int off, int len, int row, 
-		    int col, RECT *rc, BOOL blank, BOOL reverse);
-HANDLE EDIT_GetStr(HWND hwnd, char *lp, int off, int len, int *diff);
-void EDIT_CharMsg(HWND hwnd, WORD wParam);
-void EDIT_KeyTyped(HWND hwnd, short ch);
-int EDIT_CharWidth(HWND hwnd, short ch, int pcol);
-int EDIT_GetNextTabStop(HWND hwnd, int pcol);
-void EDIT_Forward(HWND hwnd);
-void EDIT_Downward(HWND hwnd);
-void EDIT_Upward(HWND hwnd);
-void EDIT_Backward(HWND hwnd);
-void EDIT_End(HWND hwnd);
-void EDIT_Home(HWND hwnd);
-void EDIT_StickEnd(HWND hwnd);
-void EDIT_KeyDownMsg(HWND hwnd, WORD wParam);
-void EDIT_KeyHScroll(HWND hwnd, WORD opt);
-void EDIT_KeyVScrollLine(HWND hwnd, WORD opt);
-void EDIT_KeyVScrollPage(HWND hwnd, WORD opt);
-void EDIT_KeyVScrollDoc(HWND hwnd, WORD opt);
-int EDIT_ComputeVScrollPos(HWND hwnd);
-int EDIT_ComputeHScrollPos(HWND hwnd);
-void EDIT_DelKey(HWND hwnd);
-void EDIT_VScrollMsg(HWND hwnd, WORD wParam, LONG lParam);
-void EDIT_VScrollLine(HWND hwnd, WORD opt);
-void EDIT_VScrollPage(HWND hwnd, WORD opt);
-void EDIT_HScrollMsg(HWND hwnd, WORD wParam, LONG lParam);
-void EDIT_SizeMsg(HWND hwnd, WORD wParam, LONG lParam);
-void EDIT_LButtonDownMsg(HWND hwnd, WORD wParam, LONG lParam);
-void EDIT_MouseMoveMsg(HWND hwnd, WORD wParam, LONG lParam);
-int EDIT_PixelToChar(HWND hwnd, int row, int *pixel);
-LONG EDIT_SetTextMsg(HWND hwnd, LONG lParam);
-void EDIT_ClearText(HWND hwnd);
-void EDIT_SetSelMsg(HWND hwnd, WORD wParam, LONG lParam);
-void EDIT_GetLineCol(HWND hwnd, int off, int *line, int *col);
-void EDIT_DeleteSel(HWND hwnd);
-void EDIT_ClearSel(HWND hwnd);
-int EDIT_TextLineNumber(HWND hwnd, char *lp);
-void EDIT_SetAnchor(HWND hwnd, int row, int col);
-void EDIT_ExtendSel(HWND hwnd, INT x, INT y);
-void EDIT_WriteSel(HWND hwnd, int y, int start, int end);
-void EDIT_StopMarking(HWND hwnd);
-LONG EDIT_GetLineMsg(HWND hwnd, WORD wParam, LONG lParam);
-LONG EDIT_GetSelMsg(HWND hwnd);
-void EDIT_ReplaceSel(HWND hwnd, LONG lParam);
-void EDIT_InsertText(HWND hwnd, char *str, int len);
-LONG EDIT_LineFromCharMsg(HWND hwnd, WORD wParam);
-LONG EDIT_LineIndexMsg(HWND hwnd, WORD wParam);
-LONG EDIT_LineLengthMsg(HWND hwnd, WORD wParam);
-void EDIT_SetFont(HWND hwnd, WORD wParam, LONG lParam);
-void EDIT_SaveDeletedText(HWND hwnd, char *deltext, int len, int line, 
-			  int col);
-void EDIT_ClearDeletedText(HWND hwnd);
-LONG EDIT_UndoMsg(HWND hwnd);
-unsigned int EDIT_HeapAlloc(HWND hwnd, int bytes);
-void *EDIT_HeapAddr(HWND hwnd, unsigned int handle);
-unsigned int EDIT_HeapReAlloc(HWND hwnd, unsigned int handle, int bytes);
-void EDIT_HeapFree(HWND hwnd, unsigned int handle);
-unsigned int EDIT_HeapSize(HWND hwnd, unsigned int handle);
-void EDIT_SetHandleMsg(HWND hwnd, WORD wParam);
-LONG EDIT_SetTabStopsMsg(HWND hwnd, WORD wParam, LONG lParam);
-void EDIT_CopyToClipboard(HWND hwnd);
-void EDIT_PasteMsg(HWND hwnd);
-void swap(int *a, int *b);
+/*********************************************************************
+ *  EDIT_HeapAlloc
+ *
+ *  Allocate the specified number of bytes on the specified local heap.
+ */
+static unsigned int EDIT_HeapAlloc(HWND hwnd, int bytes, WORD flags)
+{
+    unsigned int ret;
+
+    ret = LOCAL_Alloc( GetWindowWord(hwnd,GWW_HINSTANCE), flags, bytes );
+    if (ret == 0)
+        printf("EDIT_HeapAlloc: Out of heap-memory\n");
+    return ret;
+}
+
+/*********************************************************************
+ *  EDIT_HeapLock
+ *
+ *  Return the address of the memory pointed to by the handle.
+ */
+static void *EDIT_HeapLock(HWND hwnd, unsigned int handle)
+{
+    WORD hinstance = GetWindowWord( hwnd, GWW_HINSTANCE );
+    WORD offs;
+    
+    if (handle == 0) return 0;
+    offs = LOCAL_Lock( hinstance, handle );
+    return PTR_SEG_OFF_TO_LIN( hinstance, offs );
+}
+
+/*********************************************************************
+ *  EDIT_HeapUnlock
+ */
+static void EDIT_HeapUnlock(HWND hwnd, unsigned int handle)
+{
+    if (handle == 0) return;
+    LOCAL_Unlock( GetWindowWord( hwnd, GWW_HINSTANCE ), handle );
+}
+
+/*********************************************************************
+ *  EDIT_HeapReAlloc
+ *
+ *  Reallocate the memory pointed to by the handle.
+ */
+static unsigned int EDIT_HeapReAlloc(HWND hwnd, unsigned int handle, int bytes)
+{
+    return LOCAL_ReAlloc( GetWindowWord(hwnd,GWW_HINSTANCE), handle, bytes, 
+			  LMEM_FIXED );
+}
 
 
+/*********************************************************************
+ *  EDIT_HeapFree
+ *
+ *  Frees the memory pointed to by the handle.
+ */
+static void EDIT_HeapFree(HWND hwnd, unsigned int handle)
+{
+    LOCAL_Free( GetWindowWord(hwnd,GWW_HINSTANCE), handle );
+}
+
+
+/*********************************************************************
+ *  EDIT_HeapSize
+ *
+ *  Return the size of the given object on the local heap.
+ */
+static unsigned int EDIT_HeapSize(HWND hwnd, unsigned int handle)
+{
+    return LOCAL_Size( GetWindowWord(hwnd,GWW_HINSTANCE), handle );
+}
+
+/********************************************************************
+ * EDIT_RecalcSize
+ * 
+ * Sets the ClientWidth/ClientHeight fields of the EDITSTATE
+ * Called on WM_SIZE and WM_SetFont messages
+ */
+static void EDIT_RecalcSize(HWND hwnd, EDITSTATE *es)
+{
+    RECT rect;
+    GetClientRect(hwnd,&rect);
+    es->ClientWidth = rect.right > rect.left ? rect.right - rect.left : 0;
+    es->ClientHeight = rect.bottom > rect.top ? (rect.bottom - rect.top) / es->txtht : 0;
+}
+
+/*********************************************************************
+ * EDIT_GetEditState
+ */
+static EDITSTATE *EDIT_GetEditState(HWND hwnd)
+{
+    return (EDITSTATE *)GetWindowLong(hwnd,0);
+}
+
+/*********************************************************************
+ *  EDIT_GetNextTabStop
+ *
+ *  Return the next tab stop beyond _pcol_.
+ */
+static int EDIT_GetNextTabStop(HWND hwnd, int pcol)
+{
+    int i;
+    int baseUnitWidth = LOWORD(GetDialogBaseUnits());
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (es->NumTabStops == 0)
+	return ROUNDUP(pcol, 8 * baseUnitWidth);
+    if (es->NumTabStops == 1)
+	return ROUNDUP(pcol, es->TabStops[0] * baseUnitWidth / 4);
+    for (i = 0; i < es->NumTabStops; i++)
+    {
+	if (es->TabStops[i] * baseUnitWidth / 4 >= pcol)
+	    return es->TabStops[i] * baseUnitWidth / 4;
+    }
+    return pcol;
+}
+
+/*********************************************************************
+ *  EDIT_CharWidth
+ *
+ *  Return the width of the given character in pixels.
+ *  The current column offset in pixels _pcol_ is required to calculate 
+ *  the width of a tab.
+ */
+static int EDIT_CharWidth(HWND hwnd, short ch, int pcol)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (ch == VK_TAB) return EDIT_GetNextTabStop(hwnd, pcol) - pcol;
+    return es->CharWidths[ch];
+}
+
+/*********************************************************************
+ *  EDIT_ClearTextPointers
+ *
+ *  Clear and initialize text line pointer array.
+ */
+static void EDIT_ClearTextPointers(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    
+    dprintf_edit( stddeb, "EDIT_ClerTextPointers\n" );
+    es->textptrs = realloc(es->textptrs, sizeof(int));
+    es->textptrs[0] = 0;
+}
+
+/*********************************************************************
+ *  EDIT_BuildTextPointers
+ *
+ *  Build array of pointers to text lines.
+ */
+static void EDIT_BuildTextPointers(HWND hwnd)
+{
+    char *text, *cp;
+    unsigned int off, len, line;
+    EDITSTATE *es;
+
+    es = EDIT_GetEditState(hwnd);
+    text = EDIT_HeapLock(hwnd, es->hText);
+
+    es->textwidth = 0;
+    if (IsMultiLine(hwnd)) {
+	es->wlines = 0;
+	cp = text;
+	while ((cp = strchr(cp,'\n')) != NULL) {
+	    es->wlines++; cp++;
+	}
+    } else es->wlines = 1;
+    
+    dprintf_edit( stddeb, "EDIT_BuildTextPointers: realloc\n" );
+    es->textptrs = realloc(es->textptrs, (es->wlines + 2) * sizeof(int));
+    
+    cp = text;
+    dprintf_edit(stddeb,"BuildTextPointers: %d lines, pointer %p\n", 
+		 es->wlines, es->textptrs);
+
+    /* advance through text buffer */
+    line = 0;
+    while (*cp)
+    {
+	off = cp - text;     /* offset of beginning of line */
+        dprintf_edit(stddeb,"BuildTextPointers: line %d offs %d\n", line, off);
+	es->textptrs[line] = off;
+	line++;
+	len = 0;
+	
+	/* advance through current line */
+	while (*cp && *cp != '\n')
+	{
+	    len += EDIT_CharWidth(hwnd, (BYTE)*cp, len);
+	                                     /* width of line in pixels */
+	    cp++;
+	}
+	es->textwidth = max(es->textwidth, len);
+	if (*cp)
+	    cp++;                            /* skip '\n' */
+    }
+    off = cp - text;
+    es->textptrs[line] = off;
+    EDIT_HeapUnlock(hwnd, es->hText);
+}
+
+/*********************************************************************
+ *  EDIT_ModTextPointers
+ *
+ *  Modify text pointers from a specified position.
+ */
+static void EDIT_ModTextPointers(HWND hwnd, int lineno, int var)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    for(;lineno < es->wlines; lineno++) es->textptrs[lineno] += var;
+}
+
+/*********************************************************************
+ *  EDIT_TextLine
+ *
+ *  Return a pointer to the text in the specified line.
+ */
+static char *EDIT_TextLine(HWND hwnd, int sel)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    char *text = EDIT_HeapLock(hwnd, es->hText);
+
+    if (sel > es->wlines) return NULL;
+    dprintf_edit(stddeb,"EDIT_TextLine: text %p, line %d offs %d\n", 
+		 text, sel, es->textptrs[sel]);
+    return text + es->textptrs[sel];
+}
+    
+/*********************************************************************
+ *  EDIT_GetTextLine
+ *
+ *  Get a copy of the text in the specified line.
+ */
+static char *EDIT_GetTextLine(HWND hwnd, int selection)
+{
+    int len;
+    char *cp, *cp1;
+
+    dprintf_edit(stddeb,"GetTextLine %d\n", selection);
+    cp1 = EDIT_TextLine(hwnd, selection);
+
+    /* Find end of line */
+    cp = strchr( cp1, '\r' );
+    if (cp == NULL) len = strlen(cp1);
+    else len = cp - cp1;
+    
+    /* store selected line and return handle */
+    cp = malloc( len + 1 );
+    strncpy( cp, cp1, len);
+    cp[len] = 0;
+    return cp;
+}
+
+/*********************************************************************
+ *  EDIT_StrWidth
+ *
+ *  Return length of string _str_ of length _len_ characters in pixels.
+ *  The current column offset in pixels _pcol_ is required to calculate 
+ *  the width of a tab.
+ */
+static int EDIT_StrWidth(HWND hwnd, unsigned char *str, int len, int pcol)
+{
+    int i, plen = 0;
+
+    for (i = 0; i < len; i++)
+	plen += EDIT_CharWidth(hwnd, (BYTE)(*(str + i)), pcol + plen);
+
+    dprintf_edit(stddeb,"EDIT_StrWidth: returning %d, len=%d\n", plen,len);
+    return plen;
+}
+
+/*********************************************************************
+ *  EDIT_LineLength
+ *
+ *  Return length of line _num_ in characters.
+ */
+static int EDIT_LineLength(HWND hwnd, int num)
+{
+    char *cp = EDIT_TextLine(hwnd, num);
+    char *cp1;
+
+    if(!cp)return 0;
+    cp1 = strchr(cp, '\r');
+    return cp1 ? (cp1 - cp) : strlen(cp);
+}
+
+/*********************************************************************
+ *  EDIT_GetStr
+ *
+ *  Return sub-string starting at pixel _off_ of length _len_ pixels.
+ *  If _off_ is part way through a character, the negative offset of
+ *  the beginning of the character is returned in _diff_, else _diff_ 
+ *  will be zero.
+ */
+static HANDLE EDIT_GetStr(HWND hwnd, char *lp, int off, int len, int *diff)
+{
+    HANDLE hStr;
+    char *str;
+    int ch = 0, i = 0, j, s_i=0;
+    int ch1;
+
+    dprintf_edit(stddeb,"EDIT_GetStr lp='%s'  off=%d  len=%d\n", lp, off, len);
+
+    if (off < 0) off = 0;
+    while (i < off)
+    {
+	s_i = i;
+	i += EDIT_CharWidth(hwnd, (BYTE)(*(lp + ch)), i);
+	ch++;
+    }
+    /* if stepped past _off_, go back a character */
+    if (i > off)
+    {
+	i = s_i;
+	ch--;
+    }
+    *diff = off - i;
+    ch1 = ch;
+    while (i < len + off)
+    {
+	if (*(lp + ch) == '\r' || *(lp + ch) == '\n')
+	    break;
+	i += EDIT_CharWidth(hwnd, (BYTE)(*(lp + ch)), i);
+	ch++;
+    }
+    
+    hStr = EDIT_HeapAlloc(hwnd, ch - ch1 + 3, LMEM_FIXED);
+    str = (char *)EDIT_HeapLock(hwnd, hStr);
+    for (i = ch1, j = 0; i < ch; i++, j++)
+	str[j] = lp[i];
+    str[j] = '\0';
+    dprintf_edit(stddeb,"EDIT_GetStr: returning %s\n", str);
+    return hStr;
+}
+
+/*********************************************************************
+ *  EDIT_WriteText
+ *
+ *  Write text to a window
+ *     lp  - text line
+ *     off - offset in text line (in pixels)
+ *     len - length from off (in pixels)
+ *     row - line in window
+ *     col - column in window
+ *     rc  - rectangle in which to display line
+ *     blank - blank remainder of line?
+ *     reverse - reverse color of line?
+ */
+static void EDIT_WriteText(HWND hwnd, char *lp, int off, int len, int row, 
+			   int col, RECT *rc, BOOL blank, BOOL reverse)
+{
+    HDC hdc;
+    HANDLE hStr;
+    char *str, *cp, *cp1;
+    int diff=0, num_spaces, tabwidth, scol;
+    HRGN hrgnClip;
+    COLORREF oldTextColor, oldBkgdColor;
+    HFONT oldfont;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit(stddeb,"EDIT_WriteText lp=%s, off=%d, len=%d, row=%d, col=%d, reverse=%d\n", lp, off, len, row, col, reverse);
+
+    if( off < 0 ) {
+      len += off;
+      col -= off;
+      off = 0;
+    }
+	
+    hdc = GetDC(hwnd);
+    hStr = EDIT_GetStr(hwnd, lp, off, len, &diff);
+    str = (char *)EDIT_HeapLock(hwnd, hStr);
+    hrgnClip = CreateRectRgnIndirect(rc);
+    SelectClipRgn(hdc, hrgnClip);
+
+    if (es->hFont)
+	oldfont = (HFONT)SelectObject(hdc, (HANDLE)es->hFont);
+    else
+        oldfont = 0;		/* -Wall does not see the use of if */
+
+    SendMessage(GetParent(hwnd), WM_CTLCOLOR, (WORD)hdc,
+		MAKELPARAM(hwnd, CTLCOLOR_EDIT));
+
+    if (reverse)
+    {
+	oldBkgdColor = GetBkColor(hdc);
+	oldTextColor = GetTextColor(hdc);
+	SetBkColor(hdc, oldTextColor);
+	SetTextColor(hdc, oldBkgdColor);
+    }
+    else			/* -Wall does not see the use of if */
+        oldTextColor = oldBkgdColor = 0;
+
+    if (strlen(es->BlankLine) < (es->ClientWidth / es->CharWidths[32]) + 2)
+    {
+	dprintf_edit( stddeb, "EDIT_WriteText: realloc\n" );
+        es->BlankLine = realloc(es->BlankLine, 
+				(es->ClientWidth / es->CharWidths[32]) + 2);
+        memset(es->BlankLine, ' ', (es->ClientWidth / es->CharWidths[32]) + 2);
+	es->BlankLine[(es->ClientWidth / es->CharWidths[32]) + 1] = 0;
+    }
+
+    if (!(cp = strchr(str, VK_TAB)))
+	TextOut(hdc, col - diff, row * es->txtht, str, strlen(str));
+    else
+    {
+	TextOut(hdc, col - diff, row * es->txtht, str, (int)(cp - str));
+	scol = EDIT_StrWidth(hwnd, str, (int)(cp - str), 0);
+	tabwidth = EDIT_CharWidth(hwnd, VK_TAB, scol);
+	num_spaces = tabwidth / es->CharWidths[32] + 1;
+	TextOut(hdc, scol, row * es->txtht, es->BlankLine, num_spaces);
+	cp++;
+	scol += tabwidth;
+
+	while ((cp1 = strchr(cp, VK_TAB)))
+	{
+	    TextOut(hdc, scol, row * es->txtht, cp, (int)(cp1 - cp));
+	    scol += EDIT_StrWidth(hwnd, cp, (int)(cp1 - cp), scol);
+	    tabwidth = EDIT_CharWidth(hwnd, VK_TAB, scol);
+	    num_spaces = tabwidth / es->CharWidths[32] + 1;
+	    TextOut(hdc, scol, row * es->txtht, es->BlankLine, num_spaces);
+	    cp = ++cp1;
+	    scol += tabwidth;
+	}
+
+	TextOut(hdc, scol, row * es->txtht, cp, strlen(cp));
+    }
+
+    if (reverse)
+    {
+	SetBkColor(hdc, oldBkgdColor);
+	SetTextColor(hdc, oldTextColor);
+    }
+
+    /* blank out remainder of line if appropriate */
+    if (blank)
+    {
+	if ((rc->right - col) > len)
+	{
+	    num_spaces = (rc->right - col - len) / es->CharWidths[32];
+	    TextOut(hdc, col + len, row * es->txtht, es->BlankLine, num_spaces);
+	}
+    }
+
+    if (es->hFont)
+	SelectObject(hdc, (HANDLE)oldfont);
+
+    EDIT_HeapFree(hwnd, hStr);
+    ReleaseDC(hwnd, hdc);
+}
+
+/*********************************************************************
+ *  EDIT_WriteTextLine
+ *
+ *  Write the line of text at offset _y_ in text buffer to a window.
+ */
+static void EDIT_WriteTextLine(HWND hwnd, RECT *rect, int y)
+{
+    int len = 0;
+    unsigned char *lp;
+    int lnlen, lnlen1;
+    int col, off = 0;
+    int sbl, sel, sbc, sec;
+    RECT rc;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    /* initialize rectangle if NULL, else copy */
+    if (rect)
+	CopyRect(&rc, rect);
+    else
+	GetClientRect(hwnd, &rc);
+
+    dprintf_edit(stddeb,"WriteTextLine %d\n", y);
+
+    /* make sure y is inside the window */
+    if (y < es->wtop || y > (es->wtop + es->ClientHeight))
+    {
+	dprintf_edit(stddeb,"EDIT_WriteTextLine: y (%d) is not a displayed line\n", y);
+	return;
+    }
+
+    /* make sure rectangle is within window */
+    if (rc.left >= es->ClientWidth - 1)
+    {
+	dprintf_edit(stddeb,"EDIT_WriteTextLine: rc.left (%d) is greater than right edge\n",
+	       rc.left);
+	return;
+    }
+    if (rc.right <= 0)
+    {
+	dprintf_edit(stddeb,"EDIT_WriteTextLine: rc.right (%d) is less than left edge\n",
+	       rc.right);
+	return;
+    }
+    if (y - es->wtop < (rc.top / es->txtht) || 
+	y - es->wtop > (rc.bottom / es->txtht))
+    {
+	dprintf_edit(stddeb,"EDIT_WriteTextLine: y (%d) is outside window\n", y);
+	return;
+    }
+
+    /* get the text and length of line */
+    lp = EDIT_GetTextLine( hwnd, y );
+    if (lp == NULL) return;
+    
+    lnlen = EDIT_StrWidth( hwnd, lp, strlen(lp), 0 );
+    lnlen1 = lnlen;
+
+    /* build the line to display */
+    if (lnlen < (es->wleft + rc.left))
+    {
+	lnlen = 0;
+        return;
+    }
+    else
+    {
+	off += es->wleft;
+	lnlen -= off;
+    }
+
+    if (lnlen > rc.left)
+    {
+	off += rc.left;
+	lnlen = lnlen1 - off;
+    }
+    len = min(lnlen, rc.right - rc.left);
+
+    if (SelMarked(es))
+    {
+	sbl = es->SelBegLine;
+	sel = es->SelEndLine;
+	sbc = es->SelBegCol;
+	sec = es->SelEndCol;
+
+	/* put lowest marker first */
+	if (sbl > sel)
+	{
+	    SWAP_INT(sbl, sel);
+	    SWAP_INT(sbc, sec);
+	}
+	if (sbl == sel && sbc > sec)
+	    SWAP_INT(sbc, sec);
+
+	if (y < sbl || y > sel)
+	    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, rc.left, &rc,
+			   TRUE, FALSE);
+	else if (y > sbl && y < sel)
+	    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, rc.left, &rc,
+			   TRUE, TRUE);
+	else if (y == sbl)
+	{
+	    col = EDIT_StrWidth(hwnd, lp, sbc, 0);
+	    if (col > (es->wleft + rc.left))
+	    {
+		len = min(col - off, rc.right - off);
+		EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, 
+			       rc.left, &rc, FALSE, FALSE);
+		off = col;
+	    }
+	    if (y == sel)
+	    {
+		col = EDIT_StrWidth(hwnd, lp, sec, 0);
+		if (col < (es->wleft + rc.right))
+		{
+		    len = min(col - off, rc.right - off);
+		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
+				   off - es->wleft, &rc, FALSE, TRUE);
+		    off = col;
+		    len = min(lnlen - off, rc.right - off);
+		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
+				   off - es->wleft, &rc, TRUE, FALSE);
+		}
+		else
+		{
+		    len = min(lnlen - off, rc.right - off);
+		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
+				   off - es->wleft, &rc, TRUE, TRUE);
+		}
+	    }
+	    else
+	    {
+		len = min(lnlen - off, rc.right - off);
+		if (col < (es->wleft + rc.right))
+		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
+				   off - es->wleft, &rc, TRUE, TRUE);
+	    }
+	}
+	else if (y == sel)
+	{
+	    col = EDIT_StrWidth(hwnd, lp, sec, 0);
+	    if (col < (es->wleft + rc.right))
+	    {
+		len = min(col - off, rc.right - off);
+		EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
+			       off - es->wleft, &rc, FALSE, TRUE);
+		off = col;
+		len = min(lnlen - off, rc.right - off);
+		EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
+			       off - es->wleft, &rc, TRUE, FALSE);
+	    }
+	}
+    }
+    else 
+	EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, rc.left, &rc,
+		       TRUE, FALSE);
+
+    free( lp );
+}
+
+/*********************************************************************
+ *  EDIT_ComputeVScrollPos
+ *
+ *  Compute the vertical scroll bar position from the window
+ *  position and text width.
+ */
+static int EDIT_ComputeVScrollPos(HWND hwnd)
+{
+    int vscrollpos;
+    short minpos, maxpos;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    GetScrollRange(hwnd, SB_VERT, &minpos, &maxpos);
+
+    if (es->wlines > es->ClientHeight)
+	vscrollpos = (double)(es->wtop) / (double)(es->wlines - 
+		     es->ClientHeight) * (maxpos - minpos);
+    else
+	vscrollpos = minpos;
+
+    return vscrollpos;
+}
+
+/*********************************************************************
+ *  EDIT_ComputeHScrollPos
+ *
+ *  Compute the horizontal scroll bar position from the window
+ *  position and text width.
+ */
+static int EDIT_ComputeHScrollPos(HWND hwnd)
+{
+    int hscrollpos;
+    short minpos, maxpos;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    GetScrollRange(hwnd, SB_HORZ, &minpos, &maxpos);
+
+    if (es->textwidth > es->ClientWidth)
+	hscrollpos = (double)(es->wleft) / (double)(es->textwidth - 
+		     es->ClientWidth) * (maxpos - minpos);
+    else
+	hscrollpos = minpos;
+
+    return hscrollpos;
+}
+
+/*********************************************************************
+ *  EDIT_KeyHScroll
+ *
+ *  Scroll text horizontally using cursor keys.
+ */
+static void EDIT_KeyHScroll(HWND hwnd, WORD opt)
+{
+    int hscrollpos;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (opt == SB_LINEDOWN)
+    {
+	es->wleft += HSCROLLDIM(es);
+	es->WndCol -= HSCROLLDIM(es);
+    }
+    else
+    {
+	if (es->wleft == 0)
+	    return;
+	if (es->wleft - HSCROLLDIM(es) < 0)
+	{
+	    es->WndCol += es->wleft;
+	    es->wleft = 0;
+	}	    
+	else
+	{
+	    es->wleft -= HSCROLLDIM(es);
+	    es->WndCol += HSCROLLDIM(es);
+	}
+    }
+
+    InvalidateRect(hwnd, NULL, FALSE);
+    UpdateWindow(hwnd);
+
+    if (IsHScrollBar(hwnd))
+    {
+	hscrollpos = EDIT_ComputeHScrollPos(hwnd);
+	SetScrollPos(hwnd, SB_HORZ, hscrollpos, TRUE);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_KeyVScrollLine
+ *
+ *  Scroll text vertically by one line using keyboard.
+ */
+static void EDIT_KeyVScrollLine(HWND hwnd, WORD opt)
+{
+    RECT rc;
+    int y, vscrollpos;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (!IsMultiLine(hwnd))
+	return;
+
+    if (opt == SB_LINEDOWN)
+    {
+	/* move down one line */
+	if (es->wtop + es->ClientHeight >= es->wlines)
+	    return;
+	es->wtop++;
+    }
+    else
+    {
+	/* move up one line */
+	if (es->wtop == 0)
+	    return;
+	--es->wtop;
+    }
+
+    if (IsWindowVisible(hwnd))
+    {
+	/* adjust client bottom to nearest whole line */
+	GetClientRect(hwnd, &rc);
+	rc.bottom = (rc.bottom / es->txtht) * es->txtht;
+
+	if (opt == SB_LINEUP)
+	{
+	    /* move up one line (scroll window down) */
+	    ScrollWindow(hwnd, 0, es->txtht, &rc, &rc);
+	    /* write top line */
+	    EDIT_WriteTextLine(hwnd, NULL, es->wtop);
+	    es->WndRow++;
+	}
+	else
+	{
+	    /* move down one line (scroll window up) */
+	    ScrollWindow(hwnd, 0, -(es->txtht), &rc, &rc);
+	    /* write bottom line */
+	    y = (((rc.bottom - rc.top) / es->txtht) - 1);
+	    EDIT_WriteTextLine(hwnd, NULL, es->wtop + y);
+	    --es->WndRow;
+	}
+    }
+
+    /* reset the vertical scroll bar */
+    if (IsVScrollBar(hwnd))
+    {
+	vscrollpos = EDIT_ComputeVScrollPos(hwnd);
+	SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_End
+ *
+ *  End key: move to end of line.
+ */
+static void EDIT_End(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    while (*CurrChar && *CurrChar != '\r')
+    {
+	es->WndCol += EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), es->WndCol + es->wleft);
+	es->CurrCol++;
+    }
+
+    if (es->WndCol >= es->ClientWidth)
+    {
+	es->wleft = es->WndCol - es->ClientWidth + HSCROLLDIM(es);
+	es->WndCol -= es->wleft;
+	InvalidateRect(hwnd, NULL, FALSE);
+	UpdateWindow(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_Home
+ *
+ *  Home key: move to beginning of line.
+ */
+static void EDIT_Home(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    es->CurrCol = es->WndCol = 0;
+    if (es->wleft != 0)
+    {
+	es->wleft = 0;
+	InvalidateRect(hwnd, NULL, FALSE);
+	UpdateWindow(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_StickEnd
+ *
+ *  Stick the cursor to the end of the line.
+ */
+static void EDIT_StickEnd(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    int len = EDIT_LineLength(hwnd, es->CurrLine);
+    char *cp = EDIT_TextLine(hwnd, es->CurrLine);
+    int currpel;
+
+    es->CurrCol = min(len, es->CurrCol);
+    es->WndCol = min(EDIT_StrWidth(hwnd, cp, len, 0) - es->wleft, es->WndCol);
+    currpel = EDIT_StrWidth(hwnd, cp, es->CurrCol, 0);
+
+    if (es->wleft > currpel)
+    {
+	es->wleft = max(0, currpel - 20);
+	es->WndCol = currpel - es->wleft;
+	UpdateWindow(hwnd);
+    }
+    else if (currpel - es->wleft >= es->ClientWidth)
+    {
+	es->wleft = currpel - (es->ClientWidth - 5);
+	es->WndCol = currpel - es->wleft;
+	UpdateWindow(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_Downward
+ *
+ *  Cursor down key: move down one line.
+ */
+static void EDIT_Downward(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit(stddeb,"EDIT_Downward: WndRow=%d, wtop=%d, wlines=%d\n", 
+	     es->WndRow, es->wtop, es->wlines);
+
+    if (IsMultiLine(hwnd) && (es->WndRow + es->wtop + 1 < es->wlines))
+    {
+	es->CurrLine++;
+	if (es->WndRow == es->ClientHeight - 1)
+	{
+	    es->WndRow++;
+	    EDIT_KeyVScrollLine(hwnd, SB_LINEDOWN);
+	}
+	else
+	    es->WndRow++;
+	EDIT_StickEnd(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_Upward
+ *
+ *  Cursor up key: move up one line.
+ */
+static void EDIT_Upward(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (IsMultiLine(hwnd) && es->CurrLine != 0)
+    {
+	--es->CurrLine;
+	if (es->WndRow == 0)
+	{
+	    --es->WndRow;
+	    EDIT_KeyVScrollLine(hwnd, SB_LINEUP);
+	}
+	else
+	    --es->WndRow;
+	EDIT_StickEnd(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_Forward
+ *
+ *  Cursor right key: move right one character position.
+ */
+static void EDIT_Forward(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (*CurrChar == '\0')
+	return;
+
+    if (*CurrChar == '\r')
+    {
+        if (es->CurrLine < (es->wlines - 1))
+        {
+	    EDIT_Home(hwnd);
+	    EDIT_Downward(hwnd);
+        }
+    }
+    else
+    {
+	es->WndCol += EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), es->WndCol + es->wleft);
+	es->CurrCol++;
+	if (es->WndCol >= es->ClientWidth)
+	    EDIT_KeyHScroll(hwnd, SB_LINEDOWN);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_Backward
+ *
+ *  Cursor left key: move left one character position.
+ */
+static void EDIT_Backward(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (es->CurrCol)
+    {
+	--es->CurrCol;
+	if (*CurrChar == VK_TAB)
+	    es->WndCol -= EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), 
+					 EDIT_StrWidth(hwnd, 
+					 EDIT_TextLine(hwnd, es->CurrLine), 
+					 es->CurrCol, 0));
+	else
+	    es->WndCol -= EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), 0);
+	if (es->WndCol < 0)
+	    EDIT_KeyHScroll(hwnd, SB_LINEUP);
+    }
+    else if (IsMultiLine(hwnd) && es->CurrLine != 0)
+    {
+	EDIT_Upward(hwnd);
+	EDIT_End(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_KeyVScrollPage
+ *
+ *  Scroll text vertically by one page using keyboard.
+ */
+static void EDIT_KeyVScrollPage(HWND hwnd, WORD opt)
+{
+    int vscrollpos;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (IsMultiLine(hwnd))
+    {
+	if (opt == SB_PAGEUP)
+	{
+	    if (es->wtop > es->ClientHeight) es->wtop -= es->ClientHeight;
+	}
+	else
+	{
+	    if (es->wtop + es->ClientHeight < es->wlines)
+	    {
+		es->wtop += es->ClientHeight;
+		if (es->wtop > es->wlines - es->ClientHeight)
+		    es->wtop = es->wlines - es->ClientHeight;
+	    }
+	}
+	if (es->wtop < 0)
+	    es->wtop = 0;
+
+	es->CurrLine = es->wtop + es->WndRow;
+	EDIT_StickEnd(hwnd);
+	InvalidateRect(hwnd, NULL, TRUE);
+	UpdateWindow(hwnd);
+
+	/* reset the vertical scroll bar */
+	if (IsVScrollBar(hwnd))
+	{
+	    vscrollpos = EDIT_ComputeVScrollPos(hwnd);
+	    SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
+	}
+    }
+}
+
+/*********************************************************************
+ *  EDIT_KeyVScrollDoc
+ *
+ *  Scroll text to top and bottom of document using keyboard.
+ */
+static void EDIT_KeyVScrollDoc(HWND hwnd, WORD opt)
+{
+    int vscrollpos;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (!IsMultiLine(hwnd))
+	return;
+
+    if (opt == SB_TOP)
+	es->wtop = es->wleft = 0;
+    else if (es->wtop + es->ClientHeight < es->wlines)
+    {
+	es->wtop = es->wlines - es->ClientHeight;
+	es->wleft = 0;
+    }
+
+    es->CurrLine = es->wlines;
+    es->WndRow = es->wlines - es->wtop;
+    EDIT_End(hwnd);
+    InvalidateRect(hwnd, NULL, TRUE);
+    UpdateWindow(hwnd);
+
+    /* reset the vertical scroll bar */
+    if (IsVScrollBar(hwnd))
+    {
+	vscrollpos = EDIT_ComputeVScrollPos(hwnd);
+	SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_DelKey
+ *
+ *  Delete character to right of cursor.
+ */
+static void EDIT_DelKey(HWND hwnd)
+{
+    RECT rc;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    char *currchar = CurrChar;
+    BOOL repaint = *currchar == '\n';
+
+    if (IsMultiLine(hwnd) && *currchar == '\n' && *(currchar + 1) == '\0')
+	return;
+    strcpy(currchar, currchar + 1);
+    NOTIFY_PARENT(hwnd, EN_UPDATE);
+    
+    if (repaint)
+    {
+	EDIT_BuildTextPointers(hwnd);
+	GetClientRect(hwnd, &rc);
+	rc.top = es->WndRow * es->txtht;
+	InvalidateRect(hwnd, &rc, FALSE);
+	UpdateWindow(hwnd);
+    }
+    else
+    {
+	EDIT_ModTextPointers(hwnd, es->CurrLine + 1, -1);
+	EDIT_WriteTextLine(hwnd, NULL, es->WndRow + es->wtop);
+    }
+
+    es->TextChanged = TRUE;
+    NOTIFY_PARENT(hwnd, EN_CHANGE);
+}
+
+/*********************************************************************
+ *  EDIT_VScrollLine
+ *
+ *  Scroll text vertically by one line using scrollbars.
+ */
+static void EDIT_VScrollLine(HWND hwnd, WORD opt)
+{
+    RECT rc;
+    int y;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit(stddeb,"EDIT_VScrollLine: direction=%d\n", opt);
+
+    if (opt == SB_LINEDOWN)
+    {
+	/* move down one line */
+	if (es->wtop + es->ClientHeight >= es->wlines)
+	    return;
+	es->wtop++;
+    }
+    else
+    {
+	/* move up one line */
+	if (es->wtop == 0)
+	    return;
+	--es->wtop;
+    }
+
+    if (IsWindowVisible(hwnd))
+    {
+	/* adjust client bottom to nearest whole line */
+	GetClientRect(hwnd, &rc);
+	rc.bottom = (rc.bottom / es->txtht) * es->txtht;
+
+	if (opt == SB_LINEUP)
+	{
+	    /* move up one line (scroll window down) */
+	    ScrollWindow(hwnd, 0, es->txtht, &rc, &rc);
+	    /* write top line */
+	    EDIT_WriteTextLine(hwnd, NULL, es->wtop);
+	    es->WndRow++;
+	}
+	else
+	{
+	    /* move down one line (scroll window up) */
+	    ScrollWindow(hwnd, 0, -(es->txtht), &rc, &rc);
+	    /* write bottom line */
+	    y = ((rc.bottom - rc.top / es->txtht) - 1);
+	    EDIT_WriteTextLine(hwnd, NULL, es->wtop + y);
+	    --es->WndRow;
+	}
+    }
+}
+
+
+/*********************************************************************
+ *  EDIT_VScrollPage
+ *
+ *  Scroll text vertically by one page using keyboard.
+ */
+static void EDIT_VScrollPage(HWND hwnd, WORD opt)
+{
+    int vscrollpos;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (opt == SB_PAGEUP)
+    {
+	if (es->wtop)
+	    es->wtop -= es->ClientHeight;
+    }
+    else
+    {
+	if (es->wtop + es->ClientHeight < es->wlines)
+	{
+	    es->wtop += es->ClientHeight;
+	    if (es->wtop > es->wlines - es->ClientHeight)
+		es->wtop = es->wlines - es->ClientHeight;
+	}
+    }
+    if (es->wtop < 0)
+	es->wtop = 0;
+    
+    InvalidateRect(hwnd, NULL, TRUE);
+    UpdateWindow(hwnd);
+
+    /* reset the vertical scroll bar */
+    if (IsVScrollBar(hwnd))
+    {
+	vscrollpos = EDIT_ComputeVScrollPos(hwnd);
+	SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_PixelToChar
+ *
+ *  Convert a pixel offset in the given row to a character offset,
+ *  adjusting the pixel offset to the nearest whole character if
+ *  necessary.
+ */
+static int EDIT_PixelToChar(HWND hwnd, int row, int *pixel)
+{
+    int ch = 0, i = 0, s_i = 0;
+    char *text;
+
+    dprintf_edit(stddeb,"EDIT_PixelToChar: row=%d, pixel=%d\n", row, *pixel);
+
+    text = EDIT_TextLine(hwnd, row);
+    while (i < *pixel)
+    {
+	s_i = i;
+	i += EDIT_CharWidth(hwnd, (BYTE)(*(text + ch)), i);
+	ch++;
+    }
+
+    /* if stepped past _pixel_, go back a character */
+    if (i - *pixel)
+    {
+	i = s_i;
+	--ch;
+    }
+    *pixel = i;
+    return ch;
+}
+
+/*********************************************************************
+ *  EDIT_ClearText
+ *
+ *  Clear text from text buffer.
+ */
+static void EDIT_ClearText(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    unsigned int blen = EditBufStartLen(hwnd) + 2;
+    char *text;
+
+    dprintf_edit(stddeb,"EDIT_ClearText %d\n",blen);
+    es->hText = EDIT_HeapReAlloc(hwnd, es->hText, blen);
+    text = EDIT_HeapLock(hwnd, es->hText);
+    memset(text, 0, blen);
+    es->textlen = 0;
+    es->wlines = 0;
+    es->CurrLine = es->CurrCol = 0;
+    es->WndRow = es->WndCol = 0;
+    es->wleft = es->wtop = 0;
+    es->textwidth = 0;
+    es->TextChanged = FALSE;
+    EDIT_ClearTextPointers(hwnd);
+}
+
+/*********************************************************************
+ *  EDIT_GetLineCol
+ *
+ *  Return line and column in text buffer from character offset.
+ */
+static void EDIT_GetLineCol(HWND hwnd, int off, int *line, int *col)
+{
+    int lineno;
+    char *cp, *cp1;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    char *text = EDIT_HeapLock(hwnd, es->hText);
+
+    /* check for (0,0) */
+    if (!off || !es->wlines)
+    {
+	*line = 0;
+	*col = 0;
+	return;
+    }
+
+    if (off < 0 || off > strlen(text)) off = strlen(text);
+    cp1 = text;
+    for (lineno = 0; lineno < es->wlines; lineno++)
+    {
+	cp = text + es->textptrs[lineno];
+	if (off == (int)(cp - text))
+	{
+	    *line = lineno;
+	    *col = 0;
+	    return;
+	}
+	if (off < (int)(cp - text))
+	    break;
+	cp1 = cp;
+    }
+    *line = lineno - 1;
+    *col = off - (int)(cp1 - text);
+#if 0
+    if (*(text + *col) == '\0')
+	(*col)--;
+#endif
+}
+
+/*********************************************************************
+ *  EDIT_ClearSel
+ *
+ *  Clear the current selection.
+ */
+static void EDIT_ClearSel(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    es->SelBegLine = es->SelBegCol = 0;
+    es->SelEndLine = es->SelEndCol = 0;
+
+    InvalidateRect(hwnd, NULL, TRUE);
+    UpdateWindow(hwnd);
+}
+
+/*********************************************************************
+ *  EDIT_SaveDeletedText
+ *
+ *  Save deleted text in deleted text buffer.
+ */
+static void EDIT_SaveDeletedText(HWND hwnd, char *deltext, int len,
+				 int line, int col)
+{
+    char *text;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit( stddeb, "EDIT_SaveDeletedText\n" );
+    if (!es->hDeletedText)
+        es->hDeletedText = GlobalAlloc( GMEM_MOVEABLE, len );
+    else 
+        es->hDeletedText = GlobalReAlloc(es->hDeletedText, len, GMEM_MOVEABLE);
+    if (!es->hDeletedText) return;
+    text = (char *)GlobalLock(es->hDeletedText);
+    memcpy(text, deltext, len);
+    GlobalUnlock(es->hDeletedText);
+    es->DeletedLength = len;
+    es->DeletedCurrLine = line;
+    es->DeletedCurrCol = col;
+}
+
+/*********************************************************************
+ *  EDIT_DeleteSel
+ *
+ *  Delete the current selected text (if any)
+ */
+static void EDIT_DeleteSel(HWND hwnd)
+{
+    char *bbl, *bel;
+    int len;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (SelMarked(es))
+    {
+	bbl = EDIT_TextLine(hwnd, es->SelBegLine) + es->SelBegCol;
+	bel = EDIT_TextLine(hwnd, es->SelEndLine) + es->SelEndCol;
+	len = (int)(bel - bbl);
+	EDIT_SaveDeletedText(hwnd, bbl, len, es->SelBegLine, es->SelBegCol);
+	es->TextChanged = TRUE;
+	strcpy(bbl, bel);
+
+	es->CurrLine = es->SelBegLine;
+	es->CurrCol = es->SelBegCol;
+	es->WndRow = es->SelBegLine - es->wtop;
+	if (es->WndRow < 0)
+	{
+	    es->wtop = es->SelBegLine;
+	    es->WndRow = 0;
+	}
+	es->WndCol = EDIT_StrWidth(hwnd, bbl - es->SelBegCol, 
+				     es->SelBegCol, 0) - es->wleft;
+
+	EDIT_BuildTextPointers(hwnd);
+	es->PaintBkgd = TRUE;
+	EDIT_ClearSel(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_TextLineNumber
+ *
+ *  Return the line number in the text buffer of the supplied
+ *  character pointer.
+ */
+static int EDIT_TextLineNumber(HWND hwnd, char *lp)
+{
+    int lineno;
+    char *cp;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    char *text = EDIT_HeapLock(hwnd, es->hText);
+
+    for (lineno = 0; lineno < es->wlines; lineno++)
+    {
+	cp = text + es->textptrs[lineno];
+	if (cp == lp)
+	    return lineno;
+	if (cp > lp)
+	    break;
+    }
+    return lineno - 1;
+}
+
+/*********************************************************************
+ *  EDIT_SetAnchor
+ *
+ *  Set down anchor for text marking.
+ */
+static void EDIT_SetAnchor(HWND hwnd, int row, int col)
+{
+    BOOL sel = FALSE;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (SelMarked(es))
+    {
+	sel = TRUE;
+        EDIT_ClearSel(hwnd);
+    }
+    es->SelBegLine = es->SelEndLine = row;
+    es->SelBegCol = es->SelEndCol = col;
+    if (sel)
+    {
+	InvalidateRect(hwnd, NULL, FALSE);
+	UpdateWindow(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_WriteSel
+ *
+ *  Display selection by reversing pixels in selected text.
+ *  If end == -1, selection applies to end of line.
+ */
+static void EDIT_WriteSel(HWND hwnd, int y, int start, int end)
+{
+    RECT rc, rcInvert;
+    int scol, ecol;
+    char *cp;
+    HDC hdc;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit(stddeb,"EDIT_WriteSel: y=%d start=%d end=%d\n", y, start,end);
+    GetClientRect(hwnd, &rc);
+
+    /* make sure y is within the window */
+    if (y < es->wtop || y > (es->wtop + es->ClientHeight))
+	return;
+
+    /* get pointer to text */
+    cp = EDIT_TextLine(hwnd, y);
+
+    /* get length of line if end == -1 */
+    if (end == -1)
+	end = EDIT_LineLength(hwnd, y);
+
+    scol = EDIT_StrWidth(hwnd, cp, start, 0) - es->wleft;
+    if (scol > rc.right) return;
+    if (scol < rc.left) scol = rc.left;
+    ecol = EDIT_StrWidth(hwnd, cp, end, 0) - es->wleft;
+    if (ecol < rc.left) return;
+    if (ecol > rc.right) ecol = rc.right;
+
+    hdc = GetDC(hwnd);
+    rcInvert.left = scol;
+    rcInvert.top = (y - es->wtop) * es->txtht;
+    rcInvert.right = ecol;
+    rcInvert.bottom = (y - es->wtop + 1) * es->txtht;
+    InvertRect(hdc, (LPRECT) &rcInvert);
+    ReleaseDC(hwnd, hdc);
+}
+
+/*********************************************************************
+ *  EDIT_ExtendSel
+ *
+ *  Extend selection to the given screen co-ordinates.
+ */
+static void EDIT_ExtendSel(HWND hwnd, INT x, INT y)
+{
+    int bbl, bel, bbc, bec;
+    char *cp;
+    int len, line;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit(stddeb,"EDIT_ExtendSel: x=%d, y=%d\n", x, y);
+
+    bbl = es->SelEndLine;
+    bbc = es->SelEndCol;
+    y = max(y,0);
+    if (IsMultiLine(hwnd))
+    {
+        if ((line = es->wtop + y / es->txtht) >= es->wlines)
+	    line = es->wlines - 1;
+    }
+    else
+        line = 0;
+        
+    cp = EDIT_TextLine(hwnd, line);
+    len = EDIT_LineLength(hwnd, line);
+
+    es->WndRow = y / es->txtht;
+    if (!IsMultiLine(hwnd))
+	    es->WndRow = 0;
+    else if (es->WndRow > es->wlines - es->wtop - 1)
+	    es->WndRow = es->wlines - es->wtop - 1;
+    es->CurrLine = es->wtop + es->WndRow;
+    es->SelEndLine = es->CurrLine;
+
+    es->WndCol = es->wleft + max(x,0);
+    if (es->WndCol > EDIT_StrWidth(hwnd, cp, len, 0))
+	es->WndCol = EDIT_StrWidth(hwnd, cp, len, 0);
+    es->CurrCol = EDIT_PixelToChar(hwnd, es->CurrLine, &(es->WndCol));
+    es->WndCol -= es->wleft;
+    es->SelEndCol = es->CurrCol;
+
+    bel = es->SelEndLine;
+    bec = es->SelEndCol;
+
+    /* return if no new characters to mark */
+    if (bbl == bel && bbc == bec)
+	return;
+
+    /* put lowest marker first */
+    if (bbl > bel)
+    {
+	SWAP_INT(bbl, bel);
+	SWAP_INT(bbc, bec);
+    }
+    if (bbl == bel && bbc > bec)
+	SWAP_INT(bbc, bec);
+
+    for (y = bbl; y <= bel; y++)
+    {
+	if (y == bbl && y == bel)
+	    EDIT_WriteSel(hwnd, y, bbc, bec);
+	else if (y == bbl)
+	    EDIT_WriteSel(hwnd, y, bbc, -1);
+	else if (y == bel)
+	    EDIT_WriteSel(hwnd, y, 0, bec);
+	else
+	    EDIT_WriteSel(hwnd, y, 0, -1);
+    }
+}
+
+/*********************************************************************
+ *  EDIT_StopMarking
+ *
+ *  Stop text marking (selection).
+ */
+static void EDIT_StopMarking(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    TextMarking = FALSE;
+    if (es->SelBegLine > es->SelEndLine)
+    {
+	SWAP_INT((es->SelBegLine), (es->SelEndLine));
+	SWAP_INT((es->SelBegCol), (es->SelEndCol));
+    }
+    if (es->SelBegLine == es->SelEndLine && es->SelBegCol > es->SelEndCol)
+	SWAP_INT((es->SelBegCol), (es->SelEndCol));
+}
+
+/*********************************************************************
+ *  EDIT_InsertText
+ *
+ *  Insert text at current line and column.
+ */
+static void EDIT_InsertText(HWND hwnd, char *str, int len)
+{
+    int plen;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    char *text = EDIT_HeapLock(hwnd, es->hText);
+    
+    plen = strlen(text) + len;
+    if (plen + 1 > es->textlen)
+    {
+      dprintf_edit(stddeb,"InsertText: Realloc\n");
+      es->hText = EDIT_HeapReAlloc(hwnd, es->hText, es->textlen + len);
+      text = EDIT_HeapLock(hwnd, es->hText);
+      es->textlen = plen + 1;
+    }
+    memmove(CurrChar + len, CurrChar, strlen(CurrChar) + 1);
+    memcpy(CurrChar, str, len);
+
+    EDIT_BuildTextPointers(hwnd);
+    es->PaintBkgd = TRUE;
+    es->TextChanged = TRUE;
+
+    EDIT_GetLineCol(hwnd, (int)((CurrChar + len) - text), &(es->CurrLine),
+		                                    &(es->CurrCol));
+    es->WndRow = es->CurrLine - es->wtop;
+    es->WndCol = EDIT_StrWidth(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
+				 es->CurrCol, 0) - es->wleft;
+}
+
+/*********************************************************************
+ *  EDIT_ClearDeletedText
+ *
+ *  Clear deleted text buffer.
+ */
+static void EDIT_ClearDeletedText(HWND hwnd)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    GlobalFree(es->hDeletedText);
+    es->hDeletedText = 0;
+    es->DeletedLength = 0;
+}
+
+/*********************************************************************
+ *  EDIT_CopyToClipboard
+ *
+ *  Copy the specified text to the clipboard.
+ */
+static void EDIT_CopyToClipboard(HWND hwnd)
+{
+    HANDLE hMem;
+    char *lpMem;
+    int i, len;
+    char *bbl, *bel;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    bbl = EDIT_TextLine(hwnd, es->SelBegLine) + es->SelBegCol;
+    bel = EDIT_TextLine(hwnd, es->SelEndLine) + es->SelEndCol;
+    len = (int)(bel - bbl);
+
+    hMem = GlobalAlloc(GHND, (DWORD)(len + 1));
+    lpMem = GlobalLock(hMem);
+
+    for (i = 0; i < len; i++)
+	*lpMem++ = *bbl++;
+
+    GlobalUnlock(hMem);
+    OpenClipboard(hwnd);
+    EmptyClipboard();
+    SetClipboardData(CF_TEXT, hMem);
+    CloseClipboard();
+}
+
+/*********************************************************************
+ *  EDIT_KeyTyped
+ *
+ *  Process keystrokes that produce displayable characters.
+ */
+static void EDIT_KeyTyped(HWND hwnd, short ch)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    char *text = EDIT_HeapLock(hwnd, es->hText);
+    char *currchar;
+    RECT rc;
+    BOOL FullPaint = FALSE;
+
+    dprintf_edit(stddeb,"EDIT_KeyTyped: ch=%c\n", (char)ch);
+
+    /* delete selected text (if any) */
+    if (SelMarked(es))
+	EDIT_DeleteSel(hwnd);
+
+    /* currchar must be assigned after deleting the selection */
+    currchar = CurrChar;
+
+    /* test for typing at end of maximum buffer size */
+    if (currchar == text + es->MaxTextLen)
+    {
+	NOTIFY_PARENT(hwnd, EN_ERRSPACE);
+	return;
+    }
+
+    if (*currchar == '\0' && IsMultiLine(hwnd))
+    {
+	/* insert a newline at end of text */
+	*currchar = '\r';
+	*(currchar + 1) = '\n';
+	*(currchar + 2) = '\0';
+	EDIT_BuildTextPointers(hwnd);
+    }
+
+    /* insert the typed character */
+    if (text[es->textlen - 1] != '\0')
+    {
+	/* current text buffer is full */
+	if (es->textlen == es->MaxTextLen)
+	{
+	    /* text buffer is at maximum size */
+	    NOTIFY_PARENT(hwnd, EN_ERRSPACE);
+	    return;
+	}
+
+	/* increase the text buffer size */
+	es->textlen += GROWLENGTH;
+	/* but not above maximum size */
+	if (es->textlen > es->MaxTextLen)
+	    es->textlen = es->MaxTextLen;
+	dprintf_edit( stddeb, "EDIT_KeyTyped: realloc\n" );
+	es->hText = EDIT_HeapReAlloc(hwnd, es->hText, es->textlen + 2);
+	if (!es->hText)
+	    NOTIFY_PARENT(hwnd, EN_ERRSPACE);
+	text = EDIT_HeapLock(hwnd, es->hText);
+	text[es->textlen - 1] = '\0';
+	currchar = CurrChar;
+    }
+    /* make space for new character and put char in buffer */
+    if (ch == '\n')
+    {
+	memmove(currchar + 2, currchar, strlen(currchar) + 1);
+	*currchar = '\r';
+	*(currchar + 1) = '\n';
+	EDIT_ModTextPointers(hwnd, es->CurrLine + 1, 2);
+    }
+    else
+    {
+	memmove(currchar + 1, currchar, strlen(currchar) + 1);
+	*currchar = ch;
+	EDIT_ModTextPointers(hwnd, es->CurrLine + 1, 1);
+    }
+    es->TextChanged = TRUE;
+    NOTIFY_PARENT(hwnd, EN_UPDATE);
+
+    /* re-adjust textwidth, if necessary, and redraw line */
+    HideCaret(hwnd);
+    if (IsMultiLine(hwnd) && es->wlines > 1)
+    {
+	es->textwidth = max(es->textwidth,
+		    EDIT_StrWidth(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
+		    (int)(EDIT_TextLine(hwnd, es->CurrLine + 1) -
+			  EDIT_TextLine(hwnd, es->CurrLine)), 0));
+    } else {
+      es->textwidth = max(es->textwidth,
+			  EDIT_StrWidth(hwnd, text, strlen(text), 0));
+    }
+
+    if (ch == '\n')
+    {
+	if (es->wleft > 0)
+	    FullPaint = TRUE;
+	es->wleft = 0;
+	EDIT_BuildTextPointers(hwnd);
+	EDIT_End(hwnd);
+	EDIT_Forward(hwnd);
+
+	/* invalidate rest of window */
+	GetClientRect(hwnd, &rc);
+	if (!FullPaint)
+	    rc.top = es->WndRow * es->txtht;
+	InvalidateRect(hwnd, &rc, FALSE);
+
+	SetCaretPos(es->WndCol, es->WndRow * es->txtht);
+	ShowCaret(hwnd);
+	UpdateWindow(hwnd);
+	NOTIFY_PARENT(hwnd, EN_CHANGE);
+	return;
+    }
+
+    /* test end of window */
+    if (es->WndCol >= es->ClientWidth - 
+	                    EDIT_CharWidth(hwnd, (BYTE)ch, es->WndCol + es->wleft))
+    {
+	/* TODO:- Word wrap to be handled here */
+
+/*	if (!(currchar == text + es->MaxTextLen - 2)) */
+	    EDIT_KeyHScroll(hwnd, SB_LINEDOWN);
+    }
+    es->WndCol += EDIT_CharWidth(hwnd, (BYTE)ch, es->WndCol + es->wleft);
+    es->CurrCol++;
+    EDIT_WriteTextLine(hwnd, NULL, es->wtop + es->WndRow);
+    SetCaretPos(es->WndCol, es->WndRow * es->txtht);
+    ShowCaret(hwnd);
+    NOTIFY_PARENT(hwnd, EN_CHANGE);
+    dprintf_edit(stddeb,"KeyTyped O.K.\n");
+}
+
+/*********************************************************************
+ *  EM_UNDO message function
+ */
+static LONG EDIT_UndoMsg(HWND hwnd)
+{
+    char *text;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    
+    if (es->hDeletedText)
+    {
+	text = (char *)GlobalLock(es->hDeletedText);
+	es->CurrLine = es->DeletedCurrLine;
+	es->CurrCol = es->DeletedCurrCol;
+	EDIT_InsertText(hwnd, text, es->DeletedLength);
+	GlobalUnlock(es->hDeletedText);
+	EDIT_ClearDeletedText(hwnd);
+
+	es->SelBegLine = es->CurrLine;
+	es->SelBegCol = es->CurrCol;
+	EDIT_GetLineCol(hwnd, (int)((CurrChar + es->DeletedLength) - text), 
+			&(es->CurrLine), &(es->CurrCol));
+	es->WndRow = es->CurrLine - es->wtop;
+	es->WndCol = EDIT_StrWidth(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
+				     es->CurrCol, 0) - es->wleft;
+	es->SelEndLine = es->CurrLine;
+	es->SelEndCol = es->CurrCol;
+
+	InvalidateRect(hwnd, NULL, TRUE);
+	UpdateWindow(hwnd);
+	return 1;
+    }
+    else
+	return 0;
+}
+
+/*********************************************************************
+ *  EM_SETHANDLE message function
+ */
+static void EDIT_SetHandleMsg(HWND hwnd, WORD wParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (IsMultiLine(hwnd))
+    {
+	es->hText = wParam;
+	es->textlen = EDIT_HeapSize(hwnd, es->hText);
+	es->wlines = 0;
+	es->wtop = es->wleft = 0;
+	es->CurrLine = es->CurrCol = 0;
+	es->WndRow = es->WndCol = 0;
+	es->TextChanged = FALSE;
+	es->textwidth = 0;
+	es->SelBegLine = es->SelBegCol = 0;
+	es->SelEndLine = es->SelEndCol = 0;
+	dprintf_edit(stddeb, "EDIT_SetHandleMsg: handle %04x, textlen=%d\n",
+		     wParam, es->textlen);
+
+	EDIT_BuildTextPointers(hwnd);
+	es->PaintBkgd = TRUE;
+	InvalidateRect(hwnd, NULL, TRUE);
+	UpdateWindow(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  EM_SETTABSTOPS message function
+ */
+static LONG EDIT_SetTabStopsMsg(HWND hwnd, WORD wParam, LONG lParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit( stddeb, "EDIT_SetTabStops\n" );
+    es->NumTabStops = wParam;
+    if (wParam == 0)
+	es->TabStops = realloc(es->TabStops, 2);
+    else if (wParam == 1)
+    {
+	es->TabStops = realloc(es->TabStops, 2);
+	es->TabStops[0] = LOWORD(lParam);
+    }
+    else
+    {
+	es->TabStops = realloc(es->TabStops, wParam * sizeof(*es->TabStops));
+	memcpy(es->TabStops, (unsigned short *)PTR_SEG_TO_LIN(lParam), wParam);
+    }
+    return 0;
+}
+
+/*********************************************************************
+ *  EM_GETLINE message function
+ */
+static LONG EDIT_GetLineMsg(HWND hwnd, WORD wParam, LONG lParam)
+{
+    char *cp, *cp1;
+    int len;
+    unsigned char *buffer = (char *)lParam;
+
+    cp = EDIT_TextLine(hwnd, wParam);
+    cp1 = EDIT_TextLine(hwnd, wParam + 1);
+    len = min((int)(cp1 - cp), (WORD)(*buffer));
+    dprintf_edit( stddeb, "EDIT_GetLineMsg: %d %d, len %d\n", (int)(WORD)(*buffer), (int)(WORD)(*(char *)buffer), len);
+    strncpy(buffer, cp, len);
+
+    return (LONG)len;
+}
+
+/*********************************************************************
+ *  EM_GETSEL message function
+ */
+static LONG EDIT_GetSelMsg(HWND hwnd)
+{
+    int so, eo;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    so = es->textptrs[es->SelBegLine] + es->SelBegCol;
+    eo = es->textptrs[es->SelEndLine] + es->SelEndCol;
+
+    return MAKELONG(so, eo);
+}
+
+/*********************************************************************
+ *  EM_REPLACESEL message function
+ */
+static void EDIT_ReplaceSel(HWND hwnd, LONG lParam)
+{
+    EDIT_DeleteSel(hwnd);
+    EDIT_InsertText(hwnd, (char *)PTR_SEG_TO_LIN(lParam),
+                    strlen((char *)PTR_SEG_TO_LIN(lParam)));
+    InvalidateRect(hwnd, NULL, TRUE);
+    UpdateWindow(hwnd);
+}
+
+/*********************************************************************
+ *  EM_LINEFROMCHAR message function
+ */
+static LONG EDIT_LineFromCharMsg(HWND hwnd, WORD wParam)
+{
+    int row, col;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (wParam == (WORD)-1)
+	return (LONG)(es->SelBegLine);
+    else
+	EDIT_GetLineCol(hwnd, wParam, &row, &col);
+
+    return (LONG)row;
+}
+
+
+/*********************************************************************
+ *  EM_LINEINDEX message function
+ */
+static LONG EDIT_LineIndexMsg(HWND hwnd, WORD wParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (wParam == (WORD)-1) wParam = es->CurrLine;
+    return es->textptrs[wParam];
+}
+
+
+/*********************************************************************
+ *  EM_LINELENGTH message function
+ */
+static LONG EDIT_LineLengthMsg(HWND hwnd, WORD wParam)
+{
+    int row, col, len;
+    int sbl, sbc, sel, sec;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (wParam == (WORD)-1)
+    {
+	if (SelMarked(es))
+	{
+	    sbl = es->SelBegLine;
+	    sbc = es->SelBegCol;
+	    sel = es->SelEndLine;
+	    sec = es->SelEndCol;
+
+	    if (sbl > sel)
+	    {
+		SWAP_INT(sbl, sel);
+		SWAP_INT(sbc, sec);
+	    }
+	    if (sbl == sel && sbc > sec)
+		SWAP_INT(sbc, sec);
+
+	    if (sbc == sel)
+	    {
+		len = es->textptrs[sbl + 1] - es->textptrs[sbl] - 1;
+		return len - sec - sbc;
+	    }
+
+	    len = es->textptrs[sel + 1] - es->textptrs[sel] - sec - 1;
+	    return len + sbc;
+	}
+	else    /* no selection marked */
+	{
+	    len = es->textptrs[es->CurrLine + 1] - es->textptrs[es->CurrLine] - 1;
+	    return len;
+	}
+    }
+    else    /* line number specified */
+    {
+	EDIT_GetLineCol(hwnd, wParam, &row, &col);
+	len = es->textptrs[row + 1] - es->textptrs[row];
+	return len;
+    }
+}
+
+/*********************************************************************
+ *  EM_SETSEL message function
+ */
+static void EDIT_SetSelMsg(HWND hwnd, WORD wParam, LONG lParam)
+{
+    INT so, eo;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    so = LOWORD(lParam);
+    eo = HIWORD(lParam);
+
+    if (so == -1)       /* if so == -1, clear selection */
+    {
+	EDIT_ClearSel(hwnd);
+	return;
+    }
+
+    if (so == eo)       /* if so == eo, set caret only */
+    {
+	EDIT_GetLineCol(hwnd, (int) so, &(es->CurrLine), &(es->CurrCol));
+	es->WndRow = es->CurrLine - es->wtop;
+
+	if (!wParam)
+	{
+	    if (es->WndRow < 0 || es->WndRow > es->ClientHeight)
+	    {
+		es->wtop = es->CurrLine;
+		es->WndRow = 0;
+	    }
+	    es->WndCol = EDIT_StrWidth(hwnd, 
+					EDIT_TextLine(hwnd, es->CurrLine), 
+					es->CurrCol, 0) - es->wleft;
+	    if (es->WndCol > es->ClientWidth)
+	    {
+		es->wleft = es->WndCol;
+		es->WndCol = 0;
+	    }
+	    else if (es->WndCol < 0)
+	    {
+		es->wleft += es->WndCol;
+		es->WndCol = 0;
+	    }
+	}
+    }
+    else                /* otherwise set selection */
+    {
+	if (eo >= 0 && so > eo)	  /* eo == -1 flag to extend to end of text */
+        {
+            INT tmp;
+            tmp = so;
+            so = eo;
+            eo = tmp;
+        }
+
+	EDIT_GetLineCol(hwnd, (int) so, &(es->SelBegLine), &(es->SelBegCol));
+	EDIT_GetLineCol(hwnd, (int) eo, &(es->SelEndLine), &(es->SelEndCol));
+	es->CurrLine = es->SelEndLine;
+	es->CurrCol = es->SelEndCol;
+	es->WndRow = es->SelEndLine - es->wtop;
+
+	if (!wParam)          /* don't suppress scrolling of text */
+	{
+	    if (es->WndRow < 0)
+	    {
+		es->wtop = es->SelEndLine;
+		es->WndRow = 0;
+	    }
+	    else if (es->WndRow > es->ClientHeight)
+	    {
+		es->wtop += es->WndRow - es->ClientHeight;
+		es->WndRow = es->ClientHeight;
+	    }
+	    es->WndCol = EDIT_StrWidth(hwnd, 
+					EDIT_TextLine(hwnd, es->SelEndLine), 
+					es->SelEndCol, 0) - es->wleft;
+	    if (es->WndCol > es->ClientWidth)
+	    {
+		es->wleft += es->WndCol - es->ClientWidth;
+		es->WndCol = es->ClientWidth;
+	    }
+	    else if (es->WndCol < 0)
+	    {
+		es->wleft += es->WndCol;
+		es->WndCol = 0;
+	    }
+	}
+
+	InvalidateRect(hwnd, NULL, TRUE);
+	UpdateWindow(hwnd);
+    }
+}
+
+/*********************************************************************
+ *  WM_SETFONT
+ */
+static void EDIT_WM_SetFont(HWND hwnd, WORD wParam, LONG lParam)
+{
+    HDC hdc;
+    TEXTMETRIC tm;
+    HFONT oldfont;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    es->hFont = wParam;
+    hdc = GetDC(hwnd);
+    oldfont = (HFONT)SelectObject(hdc, (HANDLE)es->hFont);
+    GetCharWidth(hdc, 0, 255, es->CharWidths);
+    GetTextMetrics(hdc, &tm);
+    es->txtht = tm.tmHeight + tm.tmExternalLeading;
+    SelectObject(hdc, (HANDLE)oldfont);
+    ReleaseDC(hwnd, hdc);
+
+    es->WndRow = (es->CurrLine - es->wtop) / es->txtht;
+    es->WndCol = EDIT_StrWidth(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
+				 es->CurrCol, 0) - es->wleft;
+
+    InvalidateRect(hwnd, NULL, TRUE);
+    es->PaintBkgd = TRUE;
+    if (lParam) UpdateWindow(hwnd);
+    EDIT_RecalcSize(hwnd,es);
+}
+
+/*********************************************************************
+ *  WM_PASTE
+ */
+static void EDIT_WM_Paste(HWND hwnd)
+{
+    HANDLE hClipMem;
+    char *lpClipMem;
+
+    OpenClipboard(hwnd);
+    if (!(hClipMem = GetClipboardData(CF_TEXT)))
+    {
+	/* no text in clipboard */
+	CloseClipboard();
+	return;
+    }
+    lpClipMem = GlobalLock(hClipMem);
+    EDIT_InsertText(hwnd, lpClipMem, strlen(lpClipMem));
+    GlobalUnlock(hClipMem);
+    CloseClipboard();
+    InvalidateRect(hwnd, NULL, TRUE);
+    UpdateWindow(hwnd);
+}
+
+/*********************************************************************
+ *  WM_PAINT
+ */
+static void EDIT_WM_Paint(HWND hwnd)
+{
+    PAINTSTRUCT ps;
+    HDC hdc;
+    int y;
+    RECT rc;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    hdc = BeginPaint(hwnd, &ps);
+    rc = ps.rcPaint;
+
+    dprintf_edit(stddeb,"WM_PAINT: rc=(%d,%d), (%d,%d)\n", rc.left, rc.top, 
+	   rc.right, rc.bottom);
+
+    if (es->PaintBkgd)
+	FillWindow(GetParent(hwnd), hwnd, hdc, CTLCOLOR_EDIT);
+
+    for (y = (rc.top / es->txtht); y <= (rc.bottom / es->txtht); y++)
+    {
+	if (y < (IsMultiLine(hwnd) ? es->wlines : 1) - es->wtop)
+	    EDIT_WriteTextLine(hwnd, &rc, y + es->wtop);
+    }
+
+    EndPaint(hwnd, &ps);
+}
+
+/*********************************************************************
+ *  WM_NCCREATE
+ */
+static long EDIT_WM_NCCreate(HWND hwnd, LONG lParam)
+{
+    CREATESTRUCT *createStruct = (CREATESTRUCT *)PTR_SEG_TO_LIN(lParam);
+    WND *wndPtr = WIN_FindWndPtr(hwnd);
+    EDITSTATE *es;
+    char *text;
+
+    /* store pointer to local or global heap in window structure so that */
+    /* EDITSTATE structure itself can be stored on local heap  */
+
+    /* allocate space for state variable structure */
+    es = malloc( sizeof(EDITSTATE) );
+    SetWindowLong( hwnd, 0, (LONG)es );
+    es->textptrs = malloc(sizeof(int));
+    es->CharWidths = malloc(256 * sizeof(short));
+    es->ClientWidth = es->ClientHeight = 1;
+    /* --- text buffer */
+    es->MaxTextLen = MAXTEXTLEN + 1;
+    if (!(createStruct->lpszName))
+    {
+	dprintf_edit( stddeb, "EDIT_WM_NCCREATE: lpszName == 0\n" );
+	es->textlen = EditBufStartLen(hwnd) + 1;
+	es->hText = EDIT_HeapAlloc(hwnd, es->textlen + 2, LMEM_MOVEABLE);
+	text = EDIT_HeapLock(hwnd, es->hText);
+	memset(text, 0, es->textlen + 2);
+        es->wlines = 0;
+        es->textwidth = 0;
+	EDIT_ClearTextPointers(hwnd);
+	if (IsMultiLine(hwnd)) strcpy(text, "\r\n");
+	EDIT_BuildTextPointers(hwnd);
+    }
+    else
+    {
+        char *windowName = (char *)PTR_SEG_TO_LIN( createStruct->lpszName );
+	dprintf_edit( stddeb, "EDIT_WM_NCCREATE: lpszName != 0\n" );
+	if (strlen(windowName) < EditBufStartLen(hwnd))
+	{
+	    es->textlen = EditBufStartLen(hwnd) + 3;
+	    es->hText = EDIT_HeapAlloc(hwnd, es->textlen + 2, LMEM_MOVEABLE);
+	    text = EDIT_HeapLock(hwnd, es->hText);
+	    strcpy(text, windowName);
+	    if(IsMultiLine(hwnd)) {
+		strcat(text, "\r\n");
+	    }
+	    *(text + es->textlen) = '\0';
+	}
+	else
+	{
+	    es->textlen = strlen(windowName) + 3;
+	    es->hText = EDIT_HeapAlloc(hwnd, es->textlen + 2, LMEM_MOVEABLE);
+	    text = EDIT_HeapLock(hwnd, es->hText);
+	    strcpy(text, windowName);
+	    if(IsMultiLine(hwnd)) strcat(text, "\r\n");
+	    *(text + es->textlen) = '\0';
+	}
+	*(text + es->textlen + 1) = '\0';
+	EDIT_BuildTextPointers(hwnd);
+    }
+
+    /* ES_AUTOVSCROLL and ES_AUTOHSCROLL are automatically applied if */
+    /* the corresponding WS_* style is set                            */
+    if (createStruct->style & WS_VSCROLL)
+	wndPtr->dwStyle |= ES_AUTOVSCROLL;
+    if (createStruct->style & WS_HSCROLL)
+	wndPtr->dwStyle |= ES_AUTOHSCROLL;
+
+    /* remove the WS_CAPTION style if it has been set - this is really a  */
+    /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */
+    if (wndPtr->dwStyle & WS_BORDER && wndPtr->dwStyle & WS_DLGFRAME)
+	wndPtr->dwStyle ^= WS_DLGFRAME;
+
+    return 1;
+}
+
+/*********************************************************************
+ *  WM_CREATE
+ */
+static long EDIT_WM_Create(HWND hwnd, LONG lParam)
+{
+    HDC hdc;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+    CLASS *classPtr;
+    TEXTMETRIC tm;
+
+    /* initialize state variable structure */
+    hdc = GetDC(hwnd);
+
+    /* --- char width array                                        */
+    /*     only initialise chars <= 32 as X returns strange widths */
+    /*     for other chars                                         */
+    memset(es->CharWidths, 0, 256 * sizeof(short));
+    GetCharWidth(hdc, 32, 254, &es->CharWidths[32]);
+
+    /* --- other structure variables */
+    GetTextMetrics(hdc, &tm);
+    es->txtht = tm.tmHeight + tm.tmExternalLeading;
+    EDIT_RecalcSize(hwnd,es);
+    es->wtop = es->wleft = 0;
+    es->CurrCol = es->CurrLine = 0;
+    es->WndCol = es->WndRow = 0;
+    es->TextChanged = FALSE;
+    es->SelBegLine = es->SelBegCol = 0;
+    es->SelEndLine = es->SelEndCol = 0;
+    es->hFont = 0;
+    es->hDeletedText = 0;
+    es->DeletedLength = 0;
+    es->NumTabStops = 0;
+    es->TabStops = malloc( sizeof(short) );
+
+    /* allocate space for a line full of blanks to speed up */
+    /* line filling */
+    es->BlankLine = malloc( (es->ClientWidth / es->CharWidths[32]) + 2);
+    memset(es->BlankLine, ' ', (es->ClientWidth / es->CharWidths[32]) + 2);
+    es->BlankLine[(es->ClientWidth / es->CharWidths[32]) + 1] = 0;
+
+    /* set up text cursor for edit class */
+    CLASS_FindClassByName("EDIT", 0, &classPtr);
+    classPtr->wc.hCursor = LoadCursor(0, IDC_IBEAM);
+
+    /* paint background on first WM_PAINT */
+    es->PaintBkgd = TRUE;
+
+    ReleaseDC(hwnd, hdc);
+    return 0L;
+}
+
+/*********************************************************************
+ *  WM_VSCROLL
+ */
+static void EDIT_WM_VScroll(HWND hwnd, WORD wParam, LONG lParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (IsMultiLine(hwnd))
+    {
+	HideCaret(hwnd);
+
+	switch (wParam)
+	{
+	case SB_LINEUP:
+	case SB_LINEDOWN:
+	    EDIT_VScrollLine(hwnd, wParam);
+	    break;
+
+	case SB_PAGEUP:
+	case SB_PAGEDOWN:
+	    EDIT_VScrollPage(hwnd, wParam);
+	    break;
+	}
+    }
+    
+    SetCaretPos(es->WndCol, es->WndRow);
+    ShowCaret(hwnd);
+}
+
+/*********************************************************************
+ *  WM_HSCROLL
+ */
+static void EDIT_WM_HScroll(HWND hwnd, WORD wParam, LONG lParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    switch (wParam)
+    {
+    case SB_LINEUP:
+    case SB_LINEDOWN:
+	HideCaret(hwnd);
+
+	SetCaretPos(es->WndCol, es->WndRow * es->txtht);
+	ShowCaret(hwnd);
+	break;
+    }
+}
+
+/*********************************************************************
+ *  WM_SIZE
+ */
+static void EDIT_WM_Size(HWND hwnd, WORD wParam, LONG lParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+  
+    EDIT_RecalcSize(hwnd,es);
+    if (wParam != SIZE_MAXIMIZED && wParam != SIZE_RESTORED) return;
+    InvalidateRect(hwnd, NULL, TRUE);
+    es->PaintBkgd = TRUE;
+    UpdateWindow(hwnd);
+}
+
+/*********************************************************************
+ *  WM_LBUTTONDOWN
+ */
+static void EDIT_WM_LButtonDown(HWND hwnd, WORD wParam, LONG lParam)
+{
+    char *cp;
+    int len;
+    BOOL end = FALSE;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (SelMarked(es))
+	EDIT_ClearSel(hwnd);
+
+    es->WndRow = HIWORD(lParam) / es->txtht;
+    dprintf_edit( stddeb, "EDIT_LButtonDown: %04x %08lx, WndRow %d\n", wParam,
+		  lParam, es->WndRow );
+    if (!IsMultiLine(hwnd)) es->WndRow = 0;
+    else if (es->WndRow > es->wlines - es->wtop - 1)
+    {
+        es->WndRow = es->wlines - es->wtop - 1;
+	end = TRUE;
+    }
+    es->CurrLine = es->wtop + es->WndRow;
+
+    cp = EDIT_TextLine(hwnd, es->CurrLine);
+    len = EDIT_LineLength(hwnd, es->CurrLine);
+    es->WndCol = LOWORD(lParam) + es->wleft;
+    if (end || es->WndCol > EDIT_StrWidth(hwnd, cp, len, 0))
+        es->WndCol = EDIT_StrWidth(hwnd, cp, len, 0);
+    dprintf_edit( stddeb, "EDIT_LButtonDown: CurrLine %d wtop %d wndcol %d\n",
+		  es->CurrLine, es->wtop, es->WndCol);
+    es->CurrCol = EDIT_PixelToChar(hwnd, es->CurrLine, &(es->WndCol));
+    es->WndCol -= es->wleft;
+
+    ButtonDown = TRUE;
+    ButtonRow = es->CurrLine;
+    ButtonCol = es->CurrCol;
+}
+
+/*********************************************************************
+ *  WM_MOUSEMOVE
+ */
+static void EDIT_WM_MouseMove(HWND hwnd, WORD wParam, LONG lParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    if (wParam != MK_LBUTTON)
+	return;
+
+    HideCaret(hwnd);
+    if (ButtonDown)
+    {
+	EDIT_SetAnchor(hwnd, ButtonRow, ButtonCol);
+	TextMarking = TRUE;
+	ButtonDown = FALSE;
+    }
+
+    if (TextMarking)
+    {
+	EDIT_ExtendSel(hwnd, LOWORD(lParam), HIWORD(lParam));
+        SetCaretPos(es->WndCol, es->WndRow * es->txtht);
+    }
+    ShowCaret(hwnd);
+}
+
+/*********************************************************************
+ *  WM_CHAR
+ */
+static void EDIT_WM_Char(HWND hwnd, WORD wParam)
+{
+    dprintf_edit(stddeb,"EDIT_WM_Char: wParam=%c\n", (char)wParam);
+
+    switch (wParam)
+    {
+    case '\r':
+    case '\n':
+	if (!IsMultiLine(hwnd))
+	    break;
+	wParam = '\n';
+	EDIT_KeyTyped(hwnd, wParam);
+	break;
+
+    case VK_TAB:
+	if (!IsMultiLine(hwnd))
+	    break;
+	EDIT_KeyTyped(hwnd, wParam);
+	break;
+
+    default:
+	if (wParam >= 20 && wParam <= 254 && wParam != 127 )
+	    EDIT_KeyTyped(hwnd, wParam);
+	break;
+    }
+}
+
+/*********************************************************************
+ *  WM_KEYDOWN
+ */
+static void EDIT_WM_KeyDown(HWND hwnd, WORD wParam)
+{
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    dprintf_edit(stddeb,"EDIT_WM_KeyDown: key=%x\n", wParam);
+
+    HideCaret(hwnd);
+    switch (wParam)
+    {
+    case VK_UP:
+	if (SelMarked(es))
+	    EDIT_ClearSel(hwnd);
+	if (IsMultiLine(hwnd))
+	    EDIT_Upward(hwnd);
+	else
+	    EDIT_Backward(hwnd);
+	break;
+
+    case VK_DOWN:
+	if (SelMarked(es))
+	    EDIT_ClearSel(hwnd);
+	if (IsMultiLine(hwnd))
+	    EDIT_Downward(hwnd);
+	else
+	    EDIT_Forward(hwnd);
+	break;
+
+    case VK_RIGHT:
+	if (SelMarked(es))
+	    EDIT_ClearSel(hwnd);
+	EDIT_Forward(hwnd);
+	break;
+
+    case VK_LEFT:
+	if (SelMarked(es))
+	    EDIT_ClearSel(hwnd);
+	EDIT_Backward(hwnd);
+	break;
+
+    case VK_HOME:
+	if (SelMarked(es))
+	    EDIT_ClearSel(hwnd);
+	EDIT_Home(hwnd);
+	break;
+
+    case VK_END:
+	if (SelMarked(es))
+	    EDIT_ClearSel(hwnd);
+	EDIT_End(hwnd);
+	break;
+
+    case VK_PRIOR:
+	if (IsMultiLine(hwnd))
+	{
+	    if (SelMarked(es))
+		EDIT_ClearSel(hwnd);
+	    EDIT_KeyVScrollPage(hwnd, SB_PAGEUP);
+	}
+	break;
+
+    case VK_NEXT:
+	if (IsMultiLine(hwnd))
+	{
+	    if (SelMarked(es))
+		EDIT_ClearSel(hwnd);
+	    EDIT_KeyVScrollPage(hwnd, SB_PAGEDOWN);
+	}
+	break;
+
+    case VK_BACK:
+	if (SelMarked(es))
+	    EDIT_DeleteSel(hwnd);
+	else
+	{
+	    if (es->CurrCol == 0 && es->CurrLine == 0)
+		break;
+	    EDIT_Backward(hwnd);
+	    EDIT_DelKey(hwnd);
+	}
+	break;
+
+    case VK_DELETE:
+	if (SelMarked(es))
+	    EDIT_DeleteSel(hwnd);
+	else
+	    EDIT_DelKey(hwnd);
+	break;
+    }
+
+    SetCaretPos(es->WndCol, es->WndRow * es->txtht);
+    ShowCaret(hwnd);
+}
+
+/*********************************************************************
+ *  WM_SETTEXT
+ */
+static LONG EDIT_WM_SetText(HWND hwnd, LONG lParam)
+{
+    int len;
+    char *text,*settext;
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
+
+    settext = PTR_SEG_TO_LIN( lParam );
+    dprintf_edit( stddeb,"WM_SetText, length %d\n",strlen(settext) );
+    if (strlen(settext) <= es->MaxTextLen)
+    {
+	len = settext != NULL ? strlen(settext) : 0;
+	EDIT_ClearText(hwnd);
+	es->textlen = len;
+	dprintf_edit( stddeb, "EDIT_WM_SetText: realloc\n" );
+	es->hText = EDIT_HeapReAlloc(hwnd, es->hText, len + 3);
+	text = EDIT_HeapLock(hwnd, es->hText);
+	if (lParam)
+	    strcpy(text, (char *)PTR_SEG_TO_LIN(lParam));
+	text[len]     = '\0';
+	text[len + 1] = '\0';
+	text[len + 2] = '\0';
+	EDIT_BuildTextPointers(hwnd);
+	InvalidateRect(hwnd, NULL, TRUE);
+	es->PaintBkgd = TRUE;
+	es->TextChanged = TRUE;
+	return 0;
+    }
+    else
+	return EN_ERRSPACE;
+}
+
+/*********************************************************************
+ * EditWndProc()
+ */
 LONG EditWndProc(HWND hwnd, WORD uMsg, WORD wParam, LONG lParam)
 {
-    LONG lResult = 0L;
+    LONG lResult = 0;
     char *textPtr;
     int len;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
+    EDITSTATE *es = EDIT_GetEditState(hwnd);
 
     switch (uMsg) {
     case EM_CANUNDO:
@@ -211,14 +2636,14 @@
 	break;
 
     case EM_GETLINE:
-	if (IsMultiLine())
+	if (IsMultiLine(hwnd))
 	    lResult = EDIT_GetLineMsg(hwnd, wParam, lParam);
 	else
 	    lResult = 0L;
 	break;
 
     case EM_GETLINECOUNT:
-	if (IsMultiLine())
+	if (IsMultiLine(hwnd))
 	    lResult = es->wlines;
 	else
 	    lResult = 0L;
@@ -247,7 +2672,7 @@
     case EM_LIMITTEXT:
 	if (wParam)
 	    es->MaxTextLen = wParam;
-	else if (IsMultiLine())
+	else if (IsMultiLine(hwnd))
 	    es->MaxTextLen = 65535;
 	else
 	    es->MaxTextLen = 32767;
@@ -258,7 +2683,7 @@
 	break;
 
     case EM_LINEINDEX:
-	if (IsMultiLine())
+	if (IsMultiLine(hwnd))
 	    lResult = EDIT_LineIndexMsg(hwnd, wParam);
 	else
 	    lResult = 0L;
@@ -329,7 +2754,7 @@
         return DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
 
     case WM_CHAR:
-	EDIT_CharMsg(hwnd, wParam);
+	EDIT_WM_Char(hwnd, wParam);
 	break;
 
     case WM_COPY:
@@ -338,7 +2763,7 @@
 	break;
 
     case WM_CREATE:
-	lResult = EDIT_CreateMsg(hwnd, lParam);
+	lResult = EDIT_WM_Create(hwnd, lParam);
 	break;
 
     case WM_CUT:
@@ -347,10 +2772,12 @@
 	break;
 
     case WM_DESTROY:
-	EDIT_HeapFree(hwnd, es->hTextPtrs);
-	EDIT_HeapFree(hwnd, es->hCharWidths);
+	free(es->textptrs);
+	free(es->CharWidths);
+	free(es->TabStops);
+	free(es->BlankLine);
 	EDIT_HeapFree(hwnd, es->hText);
-	EDIT_HeapFree(hwnd, (HANDLE)(*(wndPtr->wExtra)));
+	free( EDIT_GetEditState(hwnd) );
 	break;
 
     case WM_ENABLE:
@@ -358,27 +2785,30 @@
 	break;
 
     case WM_GETTEXT:
-	textPtr = EDIT_HeapAddr(hwnd, es->hText);
-	if ((int)wParam > (len = strlen(textPtr)))
+	textPtr = EDIT_HeapLock(hwnd, es->hText);
+	len = strlen( textPtr );
+	if ((int)wParam > len)
 	{
 	    strcpy((char *)PTR_SEG_TO_LIN(lParam), textPtr);
 	    lResult = (DWORD)len ;
 	}
 	else
 	    lResult = 0L;
+	EDIT_HeapUnlock(hwnd, es->hText);
 	break;
 
     case WM_GETTEXTLENGTH:
-	textPtr = EDIT_HeapAddr(hwnd, es->hText);
+	textPtr = EDIT_HeapLock(hwnd, es->hText);
 	lResult = (DWORD)strlen(textPtr);
+	EDIT_HeapUnlock(hwnd, es->hText);
 	break;
 
     case WM_HSCROLL:
-	EDIT_HScrollMsg(hwnd, wParam, lParam);
+	EDIT_WM_HScroll(hwnd, wParam, lParam);
 	break;
 
     case WM_KEYDOWN:
-	EDIT_KeyDownMsg(hwnd, wParam);
+	EDIT_WM_KeyDown(hwnd, wParam);
 	break;
 
     case WM_KILLFOCUS:
@@ -392,7 +2822,7 @@
 	HideCaret(hwnd);
 	SetFocus(hwnd);
 	SetCapture(hwnd);
-	EDIT_LButtonDownMsg(hwnd, wParam, lParam);
+	EDIT_WM_LButtonDown(hwnd, wParam, lParam);
 	SetCaretPos(es->WndCol, es->WndRow * es->txtht);
 	ShowCaret(hwnd);
 	break;
@@ -407,7 +2837,7 @@
 
     case WM_MOUSEMOVE:
 	if (es->HaveFocus)
-	    EDIT_MouseMoveMsg(hwnd, wParam, lParam);
+	    EDIT_WM_MouseMove(hwnd, wParam, lParam);
 	break;
 
     case WM_MOVE:
@@ -415,15 +2845,15 @@
 	break;
 
     case WM_NCCREATE:
-	lResult = EDIT_NCCreateMsg(hwnd, lParam);
+	lResult = EDIT_WM_NCCreate(hwnd, lParam);
 	break;
 	
     case WM_PAINT:
-	EDIT_PaintMsg(hwnd);
+	EDIT_WM_Paint(hwnd);
 	break;
 
     case WM_PASTE:
-	EDIT_PasteMsg(hwnd);
+	EDIT_WM_Paste(hwnd);
 	break;
 
     case WM_SETFOCUS:
@@ -436,7 +2866,7 @@
 
     case WM_SETFONT:
 	HideCaret(hwnd);
-	EDIT_SetFont(hwnd, wParam, lParam);
+	EDIT_WM_SetFont(hwnd, wParam, lParam);
 	SetCaretPos(es->WndCol, es->WndRow * es->txtht);
 	ShowCaret(hwnd);
 	break;
@@ -448,16 +2878,16 @@
 	break;
 #endif
     case WM_SETTEXT:
-	EDIT_SetTextMsg(hwnd, lParam);
+	EDIT_WM_SetText(hwnd, lParam);
 	break;
 
     case WM_SIZE:
-	EDIT_SizeMsg(hwnd, wParam, lParam);
+	EDIT_WM_Size(hwnd, wParam, lParam);
 	lResult = 0;
 	break;
 
     case WM_VSCROLL:
-	EDIT_VScrollMsg(hwnd, wParam, lParam);
+	EDIT_WM_VScroll(hwnd, wParam, lParam);
 	break;
 
     default:
@@ -468,2787 +2898,3 @@
     return lResult;
 }
 
-
-/*********************************************************************
- *  WM_NCCREATE message function
- */
-
-long EDIT_NCCreateMsg(HWND hwnd, LONG lParam)
-{
-    CREATESTRUCT *createStruct = (CREATESTRUCT *)PTR_SEG_TO_LIN(lParam);
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es;
-    unsigned int *textPtrs;
-    char *text;
-
-    /* store pointer to local or global heap in window structure so that */
-    /* EDITSTATE structure itself can be stored on local heap  */
-#if 0
-    if (HEAP_LocalFindHeap(createStruct->hInstance)!=NULL)
-      (MDESC **)*(LONG *)(wndPtr->wExtra + 2) = 
-	&HEAP_LocalFindHeap(createStruct->hInstance)->free_list;
-    else
-      {
-	(MDESC **)*(LONG *)(wndPtr->wExtra + 2) =
-	  GlobalLock(createStruct->hInstance);
-	/* GlobalUnlock(createStruct->hInstance); */
-      }
-#endif
-    /* allocate space for state variable structure */
-    (HANDLE)(*(wndPtr->wExtra)) = EDIT_HeapAlloc(hwnd, sizeof(EDITSTATE));
-    es = (EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    es->hTextPtrs = EDIT_HeapAlloc(hwnd, sizeof(int));
-    textPtrs = (unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-    es->hCharWidths = EDIT_HeapAlloc(hwnd, 256 * sizeof(short));
-
-    /* --- text buffer */
-    es->MaxTextLen = MAXTEXTLEN + 1;
-    if (!(createStruct->lpszName))
-    {
-	es->textlen = EditBufLen(wndPtr) + 1;
-	es->hText = EDIT_HeapAlloc(hwnd, EditBufLen(wndPtr) + 2);
-	text = EDIT_HeapAddr(hwnd, es->hText);
-	memset(text, 0, es->textlen + 2);
-        es->wlines = 0;
-        es->textwidth = 0;
-	EDIT_ClearTextPointers(hwnd);
-	if(IsMultiLine()) strcpy(text, "\r\n");
-	EDIT_BuildTextPointers(hwnd);
-    }
-    else
-    {
-        char *windowName = (char *)PTR_SEG_TO_LIN( createStruct->lpszName );
-	if (strlen(windowName) < EditBufLen(wndPtr))
-	{
-	    es->textlen = EditBufLen(wndPtr) + 1;
-	    es->hText = EDIT_HeapAlloc(hwnd, EditBufLen(wndPtr) + 2);
-	    text = EDIT_HeapAddr(hwnd, es->hText);
-	    strcpy(text, windowName);
-	    if(IsMultiLine()) strcat(text, "\r\n");
-	    es->textlen += 2;
-	    *(text + es->textlen) = '\0';
-	}
-	else
-	{
-	    es->hText = EDIT_HeapAlloc(hwnd, strlen(windowName) + 4);
-	    text = EDIT_HeapAddr(hwnd, es->hText);
-	    strcpy(text, windowName);
-	    if(IsMultiLine()) strcat(text, "\r\n");
-	    es->textlen = strlen(windowName) + 3;
-	    *(text + es->textlen) = '\0';
-	}
-	*(text + es->textlen + 1) = '\0';
-	EDIT_BuildTextPointers(hwnd);
-    }
-
-    /* ES_AUTOVSCROLL and ES_AUTOHSCROLL are automatically applied if */
-    /* the corresponding WS_* style is set                            */
-    if (createStruct->style & WS_VSCROLL)
-	wndPtr->dwStyle |= ES_AUTOVSCROLL;
-    if (createStruct->style & WS_HSCROLL)
-	wndPtr->dwStyle |= ES_AUTOHSCROLL;
-
-    /* remove the WS_CAPTION style if it has been set - this is really a  */
-    /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */
-    if (wndPtr->dwStyle & WS_BORDER && wndPtr->dwStyle & WS_DLGFRAME)
-	wndPtr->dwStyle ^= WS_DLGFRAME;
-
-    return 1;
-}
-
-
-/*********************************************************************
- *  WM_CREATE message function
- */
-
-long EDIT_CreateMsg(HWND hwnd, LONG lParam)
-{
-    HDC hdc;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    CLASS *classPtr;
-    short *charWidths;
-    TEXTMETRIC tm;
-    char *text;
-
-    /* initialize state variable structure */
-    hdc = GetDC(hwnd);
-
-    /* --- char width array                                        */
-    /*     only initialise chars <= 32 as X returns strange widths */
-    /*     for other chars                                         */
-    charWidths = (short *)EDIT_HeapAddr(hwnd, es->hCharWidths);
-    memset(charWidths, 0, 256 * sizeof(short));
-    GetCharWidth(hdc, 32, 254, &charWidths[32]);
-
-    /* --- other structure variables */
-    GetTextMetrics(hdc, &tm);
-    es->txtht = tm.tmHeight + tm.tmExternalLeading;
-    es->wtop = es->wleft = 0;
-    es->CurrCol = es->CurrLine = 0;
-    es->WndCol = es->WndRow = 0;
-    es->TextChanged = FALSE;
-    es->SelBegLine = es->SelBegCol = 0;
-    es->SelEndLine = es->SelEndCol = 0;
-    es->hFont = 0;
-    es->hDeletedText = 0;
-    es->DeletedLength = 0;
-    es->NumTabStops = 0;
-    es->hTabStops = EDIT_HeapAlloc(hwnd, sizeof(int));
-
-    /* allocate space for a line full of blanks to speed up */
-    /* line filling */
-    es->hBlankLine = EDIT_HeapAlloc(hwnd, (ClientWidth(wndPtr) / 
-				      charWidths[32]) + 2); 
-    text = EDIT_HeapAddr(hwnd, es->hBlankLine);
-    memset(text, ' ', (ClientWidth(wndPtr) / charWidths[32]) + 2);
-
-    /* set up text cursor for edit class */
-    CLASS_FindClassByName("EDIT", 0, &classPtr);
-    classPtr->wc.hCursor = LoadCursor(0, IDC_IBEAM);
-
-    /* paint background on first WM_PAINT */
-    es->PaintBkgd = TRUE;
-
-    ReleaseDC(hwnd, hdc);
-    return 0L;
-}
-
-
-/*********************************************************************
- *  EDIT_ClearTextPointers
- *
- *  Clear and initialize text line pointer array.
- */
-
-void EDIT_ClearTextPointers(HWND hwnd)
-{
-    unsigned int *textPtrs;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    
-    es->hTextPtrs = EDIT_HeapReAlloc(hwnd, es->hTextPtrs, sizeof(int));
-    textPtrs = (unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-    *textPtrs = 0;
-}
-
-
-/*********************************************************************
- *  EDIT_BuildTextPointers
- *
- *  Build array of pointers to text lines.
- */
-
-#define INITLINES 100
-
-void EDIT_BuildTextPointers(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    char *text, *cp;
-    int incrs = INITLINES;
-    unsigned int off, len;
-    EDITSTATE *es;
-    unsigned int *textPtrs;
-    short *charWidths;
-
-    es = (EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    text = EDIT_HeapAddr(hwnd, es->hText);
-    textPtrs = (unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-    charWidths = (short *)EDIT_HeapAddr(hwnd, es->hCharWidths);
-
-    es->textwidth = es->wlines = 0;
-    cp = text;
-
-    /* advance through text buffer */
-    while (*cp)
-    {
-	/* increase size of text pointer array */ 
-	if (incrs == INITLINES)
-	{
-	    incrs = 0;
-	    es->hTextPtrs = EDIT_HeapReAlloc(hwnd, es->hTextPtrs,
-			      (es->wlines + INITLINES) * sizeof(int));
-	    textPtrs = (unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-	}
-	off = (unsigned int)(cp - text);     /* offset of beginning of line */
-	*(textPtrs + es->wlines) = off;
-	es->wlines++;
-	incrs++;
-	len = 0;
-	
-	/* advance through current line */
-	while (*cp && *cp != '\n')
-	{
-	    len += EDIT_CharWidth(hwnd, (BYTE)*cp, len);
-	                                     /* width of line in pixels */
-	    cp++;
-	}
-	es->textwidth = max(es->textwidth, len);
-	if (*cp)
-	    cp++;                            /* skip '\n' */
-    }
-
-    off = (unsigned int)(cp - text);
-    *(textPtrs + es->wlines) = off;
-}
-
-
-/*********************************************************************
- *  EDIT_ModTextPointers
- *
- *  Modify text pointers from a specified position.
- */
-
-void EDIT_ModTextPointers(HWND hwnd, int lineno, int var)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    unsigned int *textPtrs = 
-	(unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-
-    while (lineno < es->wlines)
-	*(textPtrs + lineno++) += var;
-}
-
-
-/*********************************************************************
- *  WM_PAINT message function
- */
-
-void EDIT_PaintMsg(HWND hwnd)
-{
-    PAINTSTRUCT ps;
-    HDC hdc;
-    int y;
-    RECT rc;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    hdc = BeginPaint(hwnd, &ps);
-    rc = ps.rcPaint;
-
-    dprintf_edit(stddeb,"WM_PAINT: rc=(%d,%d), (%d,%d)\n", rc.left, rc.top, 
-	   rc.right, rc.bottom);
-
-    if (es->PaintBkgd)
-	FillWindow(GetParent(hwnd), hwnd, hdc, CTLCOLOR_EDIT);
-
-    for (y = (rc.top / es->txtht); y <= (rc.bottom / es->txtht); y++)
-    {
-	if (y < (IsMultiLine() ? es->wlines : 1) - es->wtop)
-	    EDIT_WriteTextLine(hwnd, &rc, y + es->wtop);
-    }
-
-    EndPaint(hwnd, &ps);
-}
-
-
-/*********************************************************************
- *  EDIT_GetTextLine
- *
- *  Get a copy of the text in the specified line.
- */
-
-HANDLE EDIT_GetTextLine(HWND hwnd, int selection)
-{
-    char *line;
-    HANDLE hLine;
-    int len = 0;
-    char *cp, *cp1;
-
-    dprintf_edit(stddeb,"GetTextLine %d\n", selection);
-    cp = cp1 = EDIT_TextLine(hwnd, selection);
-    /* advance through line */
-    while (*cp && *cp != '\r')
-    {
-	len++;
-	cp++;
-    }
-
-    /* store selected line and return handle */
-    hLine = EDIT_HeapAlloc(hwnd, len + 6);
-    line = (char *)EDIT_HeapAddr(hwnd, hLine);
-    memmove(line, cp1, len);
-    line[len] = '\0';
-    return hLine;
-}
-
-
-/*********************************************************************
- *  EDIT_TextLine
- *
- *  Return a pointer to the text in the specified line.
- */
-
-char *EDIT_TextLine(HWND hwnd, int sel)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    char *text = EDIT_HeapAddr(hwnd, es->hText);
-    unsigned int *textPtrs = 
-	(unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-
-    if(sel>es->wlines)return NULL;
-    return (text + *(textPtrs + sel));
-}
-    
-
-/*********************************************************************
- *  EDIT_StrLength
- *
- *  Return length of string _str_ of length _len_ characters in pixels.
- *  The current column offset in pixels _pcol_ is required to calculate 
- *  the width of a tab.
- */
-
-int EDIT_StrLength(HWND hwnd, unsigned char *str, int len, int pcol)
-{
-    int i, plen = 0;
-
-    for (i = 0; i < len; i++)
-	plen += EDIT_CharWidth(hwnd, (BYTE)(*(str + i)), pcol + plen);
-
-    dprintf_edit(stddeb,"EDIT_StrLength: returning %d\n", plen);
-    return plen;
-}
-
-
-/*********************************************************************
- *  EDIT_LineLength
- *
- *  Return length of line _num_ in characters.
- */
-
-int EDIT_LineLength(HWND hwnd, int num)
-{
-    char *cp = EDIT_TextLine(hwnd, num);
-    char *cp1;
-
-    if(!cp)return 0;
-    cp1 = strchr(cp, '\r');
-    return cp1 ? (int)(cp1 - cp) : strlen(cp);
-}
-
-
-/*********************************************************************
- *  EDIT_WriteTextLine
- *
- *  Write the line of text at offset _y_ in text buffer to a window.
- */
-
-void EDIT_WriteTextLine(HWND hwnd, RECT *rect, int y)
-{
-    int len = 0;
-    HANDLE hLine;
-    unsigned char *lp;
-    int lnlen, lnlen1;
-    int col, off = 0;
-    int sbl, sel, sbc, sec;
-    RECT rc;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    /* initialize rectangle if NULL, else copy */
-    if (rect)
-	CopyRect(&rc, rect);
-    else
-	GetClientRect(hwnd, &rc);
-
-    dprintf_edit(stddeb,"WriteTextLine %d\n", y);
-
-    /* make sure y is inside the window */
-    if (y < es->wtop || y > (es->wtop + ClientHeight(wndPtr, es)))
-    {
-	dprintf_edit(stddeb,"EDIT_WriteTextLine: y (%d) is not a displayed line\n", y);
-	return;
-    }
-
-    /* make sure rectangle is within window */
-    if (rc.left >= ClientWidth(wndPtr) - 1)
-    {
-	dprintf_edit(stddeb,"EDIT_WriteTextLine: rc.left (%d) is greater than right edge\n",
-	       rc.left);
-	return;
-    }
-    if (rc.right <= 0)
-    {
-	dprintf_edit(stddeb,"EDIT_WriteTextLine: rc.right (%d) is less than left edge\n",
-	       rc.right);
-	return;
-    }
-    if (y - es->wtop < (rc.top / es->txtht) || 
-	y - es->wtop > (rc.bottom / es->txtht))
-    {
-	dprintf_edit(stddeb,"EDIT_WriteTextLine: y (%d) is outside window\n", y);
-	return;
-    }
-
-    /* get the text and length of line */
-    if ((hLine = EDIT_GetTextLine(hwnd, y)) == 0)
-	return;
-    lp = (unsigned char *)EDIT_HeapAddr(hwnd, hLine);
-    lnlen = EDIT_StrLength(hwnd, lp, strlen(lp), 0);
-    lnlen1 = lnlen;
-
-    /* build the line to display */
-    if (lnlen < (es->wleft + rc.left))
-    {
-	lnlen = 0;
-        return;
-    }
-    else
-    {
-	off += es->wleft;
-	lnlen -= off;
-    }
-
-    if (lnlen > rc.left)
-    {
-	off += rc.left;
-	lnlen = lnlen1 - off;
-    }
-    len = min(lnlen, rc.right - rc.left);
-
-    if (SelMarked(es))
-    {
-	sbl = es->SelBegLine;
-	sel = es->SelEndLine;
-	sbc = es->SelBegCol;
-	sec = es->SelEndCol;
-
-	/* put lowest marker first */
-	if (sbl > sel)
-	{
-	    swap(&sbl, &sel);
-	    swap(&sbc, &sec);
-	}
-	if (sbl == sel && sbc > sec)
-	    swap(&sbc, &sec);
-
-	if (y < sbl || y > sel)
-	    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, rc.left, &rc,
-			   TRUE, FALSE);
-	else if (y > sbl && y < sel)
-	    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, rc.left, &rc,
-			   TRUE, TRUE);
-	else if (y == sbl)
-	{
-	    col = EDIT_StrLength(hwnd, lp, sbc, 0);
-	    if (col > (es->wleft + rc.left))
-	    {
-		len = min(col - off, rc.right - off);
-		EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, 
-			       rc.left, &rc, FALSE, FALSE);
-		off = col;
-	    }
-	    if (y == sel)
-	    {
-		col = EDIT_StrLength(hwnd, lp, sec, 0);
-		if (col < (es->wleft + rc.right))
-		{
-		    len = min(col - off, rc.right - off);
-		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
-				   off - es->wleft, &rc, FALSE, TRUE);
-		    off = col;
-		    len = min(lnlen - off, rc.right - off);
-		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
-				   off - es->wleft, &rc, TRUE, FALSE);
-		}
-		else
-		{
-		    len = min(lnlen - off, rc.right - off);
-		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
-				   off - es->wleft, &rc, TRUE, TRUE);
-		}
-	    }
-	    else
-	    {
-		len = min(lnlen - off, rc.right - off);
-		if (col < (es->wleft + rc.right))
-		    EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
-				   off - es->wleft, &rc, TRUE, TRUE);
-	    }
-	}
-	else if (y == sel)
-	{
-	    col = EDIT_StrLength(hwnd, lp, sec, 0);
-	    if (col < (es->wleft + rc.right))
-	    {
-		len = min(col - off, rc.right - off);
-		EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
-			       off - es->wleft, &rc, FALSE, TRUE);
-		off = col;
-		len = min(lnlen - off, rc.right - off);
-		EDIT_WriteText(hwnd, lp, off, len, y - es->wtop,
-			       off - es->wleft, &rc, TRUE, FALSE);
-	    }
-	}
-    }
-    else 
-	EDIT_WriteText(hwnd, lp, off, len, y - es->wtop, rc.left, &rc,
-		       TRUE, FALSE);
-
-    EDIT_HeapFree(hwnd, hLine);
-}
-
-
-/*********************************************************************
- *  EDIT_WriteText
- *
- *  Write text to a window
- *     lp  - text line
- *     off - offset in text line (in pixels)
- *     len - length from off (in pixels)
- *     row - line in window
- *     col - column in window
- *     rc  - rectangle in which to display line
- *     blank - blank remainder of line?
- *     reverse - reverse color of line?
- */
-
-void EDIT_WriteText(HWND hwnd, char *lp, int off, int len, int row, 
-		    int col, RECT *rc, BOOL blank, BOOL reverse)
-{
-    HDC hdc;
-    HANDLE hStr;
-    char *str, *cp, *cp1;
-    int diff=0, num_spaces, tabwidth, scol;
-    HRGN hrgnClip;
-    COLORREF oldTextColor, oldBkgdColor;
-    HFONT oldfont;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    short *charWidths = (short *)EDIT_HeapAddr(hwnd, es->hCharWidths);
-    char *blanks = (char *)EDIT_HeapAddr(hwnd, es->hBlankLine);
-
-    dprintf_edit(stddeb,"EDIT_WriteText lp=%s, off=%d, len=%d, row=%d, col=%d, reverse=%d\n", lp, off, len, row, col, reverse);
-
-    if( off < 0 ) {
-      len += off;
-      col -= off;
-      off = 0;
-    }
-	
-    hdc = GetDC(hwnd);
-    hStr = EDIT_GetStr(hwnd, lp, off, len, &diff);
-    str = (char *)EDIT_HeapAddr(hwnd, hStr);
-    hrgnClip = CreateRectRgnIndirect(rc);
-    SelectClipRgn(hdc, hrgnClip);
-
-    if (es->hFont)
-	oldfont = (HFONT)SelectObject(hdc, (HANDLE)es->hFont);
-
-    SendMessage(GetParent(hwnd), WM_CTLCOLOR, (WORD)hdc,
-		MAKELPARAM(hwnd, CTLCOLOR_EDIT));
-
-    if (reverse)
-    {
-	oldBkgdColor = GetBkColor(hdc);
-	oldTextColor = GetTextColor(hdc);
-	SetBkColor(hdc, oldTextColor);
-	SetTextColor(hdc, oldBkgdColor);
-    }
-
-    if (strlen(blanks) < (ClientWidth(wndPtr) / charWidths[32]) + 2)
-    {
-        es->hBlankLine = EDIT_HeapReAlloc(hwnd, es->hBlankLine,
-             (ClientWidth(wndPtr) / charWidths[32]) + 2);
-        blanks = EDIT_HeapAddr(hwnd, es->hBlankLine);
-        memset(blanks, ' ', (ClientWidth(wndPtr) / charWidths[32]) + 2);
-    }
-
-    if (!(cp = strchr(str, VK_TAB)))
-	TextOut(hdc, col - diff, row * es->txtht, str, strlen(str));
-    else
-    {
-	TextOut(hdc, col - diff, row * es->txtht, str, (int)(cp - str));
-	scol = EDIT_StrLength(hwnd, str, (int)(cp - str), 0);
-	tabwidth = EDIT_CharWidth(hwnd, VK_TAB, scol);
-	num_spaces = tabwidth / charWidths[32] + 1;
-	TextOut(hdc, scol, row * es->txtht, blanks, num_spaces);
-	cp++;
-	scol += tabwidth;
-
-	while ((cp1 = strchr(cp, VK_TAB)))
-	{
-	    TextOut(hdc, scol, row * es->txtht, cp, (int)(cp1 - cp));
-	    scol += EDIT_StrLength(hwnd, cp, (int)(cp1 - cp), scol);
-	    tabwidth = EDIT_CharWidth(hwnd, VK_TAB, scol);
-	    num_spaces = tabwidth / charWidths[32] + 1;
-	    TextOut(hdc, scol, row * es->txtht, blanks, num_spaces);
-	    cp = ++cp1;
-	    scol += tabwidth;
-	}
-
-	TextOut(hdc, scol, row * es->txtht, cp, strlen(cp));
-    }
-
-    if (reverse)
-    {
-	SetBkColor(hdc, oldBkgdColor);
-	SetTextColor(hdc, oldTextColor);
-    }
-
-    /* blank out remainder of line if appropriate */
-    if (blank)
-    {
-	if ((rc->right - col) > len)
-	{
-	    num_spaces = (rc->right - col - len) / charWidths[32];
-	    TextOut(hdc, col + len, row * es->txtht, blanks, num_spaces);
-	}
-    }
-
-    if (es->hFont)
-	SelectObject(hdc, (HANDLE)oldfont);
-
-    EDIT_HeapFree(hwnd, hStr);
-    ReleaseDC(hwnd, hdc);
-}
-
-
-/*********************************************************************
- *  EDIT_GetStr
- *
- *  Return sub-string starting at pixel _off_ of length _len_ pixels.
- *  If _off_ is part way through a character, the negative offset of
- *  the beginning of the character is returned in _diff_, else _diff_ 
- *  will be zero.
- */
-
-HANDLE EDIT_GetStr(HWND hwnd, char *lp, int off, int len, int *diff)
-{
-    HANDLE hStr;
-    char *str;
-    int ch = 0, i = 0, j, s_i=0;
-    int ch1;
-
-    dprintf_edit(stddeb,"EDIT_GetStr lp='%s'  off=%d  len=%d\n", lp, off, len);
-
-    if (off < 0) off = 0;
-    while (i < off)
-    {
-	s_i = i;
-	i += EDIT_CharWidth(hwnd, (BYTE)(*(lp + ch)), i);
-	ch++;
-    }
-    /* if stepped past _off_, go back a character */
-    if (i - off)
-    {
-	i = s_i;
-	ch--;
-    }
-    *diff = off - i;
-    ch1 = ch;
-    while (i < len + off)
-    {
-	if (*(lp + ch) == '\r' || *(lp + ch) == '\n')
-	    break;
-	i += EDIT_CharWidth(hwnd, (BYTE)(*(lp + ch)), i);
-	ch++;
-    }
-    
-    hStr = EDIT_HeapAlloc(hwnd, ch - ch1 + 3);
-    str = (char *)EDIT_HeapAddr(hwnd, hStr);
-    for (i = ch1, j = 0; i < ch; i++, j++)
-	str[j] = lp[i];
-    str[j] = '\0';
-    dprintf_edit(stddeb,"EDIT_GetStr: returning %s\n", str);
-    return hStr;
-}
-
-
-/*********************************************************************
- *  WM_CHAR message function
- */
-
-void EDIT_CharMsg(HWND hwnd, WORD wParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-
-    dprintf_edit(stddeb,"EDIT_CharMsg: wParam=%c\n", (char)wParam);
-
-    switch (wParam)
-    {
-    case '\r':
-    case '\n':
-	if (!IsMultiLine())
-	    break;
-	wParam = '\n';
-	EDIT_KeyTyped(hwnd, wParam);
-	break;
-
-    case VK_TAB:
-	if (!IsMultiLine())
-	    break;
-	EDIT_KeyTyped(hwnd, wParam);
-	break;
-
-    default:
-	if (wParam >= 20 && wParam <= 254 && wParam != 127 )
-	    EDIT_KeyTyped(hwnd, wParam);
-	break;
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_KeyTyped
- *
- *  Process keystrokes that produce displayable characters.
- */
-
-void EDIT_KeyTyped(HWND hwnd, short ch)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    char *text = EDIT_HeapAddr(hwnd, es->hText);
-    char *currchar;
-    RECT rc;
-    BOOL FullPaint = FALSE;
-
-    dprintf_edit(stddeb,"EDIT_KeyTyped: ch=%c\n", (char)ch);
-
-    /* delete selected text (if any) */
-    if (SelMarked(es))
-	EDIT_DeleteSel(hwnd);
-
-    /* currchar must be assigned after deleting the selection */
-    currchar = CurrChar;
-
-    /* test for typing at end of maximum buffer size */
-    if (currchar == text + es->MaxTextLen)
-    {
-	NOTIFY_PARENT(hwnd, EN_ERRSPACE);
-	return;
-    }
-
-    if (*currchar == '\0' && IsMultiLine())
-    {
-	/* insert a newline at end of text */
-	*currchar = '\r';
-	*(currchar + 1) = '\n';
-	*(currchar + 2) = '\0';
-	EDIT_BuildTextPointers(hwnd);
-    }
-
-    /* insert the typed character */
-    if (text[es->textlen - 1] != '\0')
-    {
-	/* current text buffer is full */
-	if (es->textlen == es->MaxTextLen)
-	{
-	    /* text buffer is at maximum size */
-	    NOTIFY_PARENT(hwnd, EN_ERRSPACE);
-	    return;
-	}
-
-	/* increase the text buffer size */
-	es->textlen += GROWLENGTH;
-	/* but not above maximum size */
-	if (es->textlen > es->MaxTextLen)
-	    es->textlen = es->MaxTextLen;
-	es->hText = EDIT_HeapReAlloc(hwnd, es->hText, es->textlen + 2);
-	if (!es->hText)
-	    NOTIFY_PARENT(hwnd, EN_ERRSPACE);
-	text = EDIT_HeapAddr(hwnd, es->hText);
-	text[es->textlen - 1] = '\0';
-	currchar = CurrChar;
-    }
-    /* make space for new character and put char in buffer */
-    if (ch == '\n')
-    {
-	memmove(currchar + 2, currchar, strlen(currchar) + 1);
-	*currchar = '\r';
-	*(currchar + 1) = '\n';
-	EDIT_ModTextPointers(hwnd, es->CurrLine + 1, 2);
-    }
-    else
-    {
-	memmove(currchar + 1, currchar, strlen(currchar) + 1);
-	*currchar = ch;
-	EDIT_ModTextPointers(hwnd, es->CurrLine + 1, 1);
-    }
-    es->TextChanged = TRUE;
-    NOTIFY_PARENT(hwnd, EN_UPDATE);
-
-    /* re-adjust textwidth, if necessary, and redraw line */
-    HideCaret(hwnd);
-    if (IsMultiLine() && es->wlines > 1)
-    {
-	es->textwidth = max(es->textwidth,
-		    EDIT_StrLength(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
-		    (int)(EDIT_TextLine(hwnd, es->CurrLine + 1) -
-			  EDIT_TextLine(hwnd, es->CurrLine)), 0));
-    }
-    else
-	es->textwidth = max(es->textwidth,
-			    EDIT_StrLength(hwnd, text, strlen(text), 0));
-
-    if (ch == '\n')
-    {
-	if (es->wleft > 0)
-	    FullPaint = TRUE;
-	es->wleft = 0;
-	EDIT_BuildTextPointers(hwnd);
-	EDIT_End(hwnd);
-	EDIT_Forward(hwnd);
-
-	/* invalidate rest of window */
-	GetClientRect(hwnd, &rc);
-	if (!FullPaint)
-	    rc.top = es->WndRow * es->txtht;
-	InvalidateRect(hwnd, &rc, FALSE);
-
-	SetCaretPos(es->WndCol, es->WndRow * es->txtht);
-	ShowCaret(hwnd);
-	UpdateWindow(hwnd);
-	NOTIFY_PARENT(hwnd, EN_CHANGE);
-	return;
-    }
-
-    /* test end of window */
-    if (es->WndCol >= ClientWidth(wndPtr) - 
-	                    EDIT_CharWidth(hwnd, (BYTE)ch, es->WndCol + es->wleft))
-    {
-	/* TODO:- Word wrap to be handled here */
-
-/*	if (!(currchar == text + es->MaxTextLen - 2)) */
-	    EDIT_KeyHScroll(hwnd, SB_LINEDOWN);
-    }
-    es->WndCol += EDIT_CharWidth(hwnd, (BYTE)ch, es->WndCol + es->wleft);
-    es->CurrCol++;
-    EDIT_WriteTextLine(hwnd, NULL, es->wtop + es->WndRow);
-    SetCaretPos(es->WndCol, es->WndRow * es->txtht);
-    ShowCaret(hwnd);
-    NOTIFY_PARENT(hwnd, EN_CHANGE);
-}
-
-
-/*********************************************************************
- *  EDIT_CharWidth
- *
- *  Return the width of the given character in pixels.
- *  The current column offset in pixels _pcol_ is required to calculate 
- *  the width of a tab.
- */
-
-int EDIT_CharWidth(HWND hwnd, short ch, int pcol)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    short *charWidths = (short *)EDIT_HeapAddr(hwnd, es->hCharWidths);
-
-    if (ch != VK_TAB)
-	return (charWidths[ch]);
-    else
-	return (EDIT_GetNextTabStop(hwnd, pcol) - pcol);
-}
-
-
-/*********************************************************************
- *  EDIT_GetNextTabStop
- *
- *  Return the next tab stop beyond _pcol_.
- */
-
-int EDIT_GetNextTabStop(HWND hwnd, int pcol)
-{
-    int i;
-    int baseUnitWidth = LOWORD(GetDialogBaseUnits());
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    unsigned short *tabstops = EDIT_HeapAddr(hwnd, es->hTabStops);
-
-    if (es->NumTabStops == 0)
-	return ROUNDUP(pcol, 8 * baseUnitWidth);
-    else if (es->NumTabStops == 1)
-	return ROUNDUP(pcol, *tabstops * baseUnitWidth / 4);
-    else
-    {
-	for (i = 0; i < es->NumTabStops; i++)
-	{
-	    if (*(tabstops + i) * baseUnitWidth / 4 >= pcol)
-		return (*(tabstops + i) * baseUnitWidth / 4);
-	}
-	return pcol;
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_Forward
- *
- *  Cursor right key: move right one character position.
- */
-
-void EDIT_Forward(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (*CurrChar == '\0')
-	return;
-
-    if (*CurrChar == '\r')
-    {
-        if (es->CurrLine < (es->wlines - 1))
-        {
-	    EDIT_Home(hwnd);
-	    EDIT_Downward(hwnd);
-        }
-    }
-    else
-    {
-	es->WndCol += EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), es->WndCol + es->wleft);
-	es->CurrCol++;
-	if (es->WndCol >= ClientWidth(wndPtr))
-	    EDIT_KeyHScroll(hwnd, SB_LINEDOWN);
-    }
-}
-
-
-
-/*********************************************************************
- *  EDIT_Downward
- *
- *  Cursor down key: move down one line.
- */
-
-void EDIT_Downward(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    dprintf_edit(stddeb,"EDIT_Downward: WndRow=%d, wtop=%d, wlines=%d\n", 
-	     es->WndRow, es->wtop, es->wlines);
-
-    if (IsMultiLine() && (es->WndRow + es->wtop + 1 < es->wlines))
-    {
-	es->CurrLine++;
-	if (es->WndRow == ClientHeight(wndPtr, es) - 1)
-	{
-	    es->WndRow++;
-	    EDIT_KeyVScrollLine(hwnd, SB_LINEDOWN);
-	}
-	else
-	    es->WndRow++;
-	EDIT_StickEnd(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_Upward
- *
- *  Cursor up key: move up one line.
- */
-
-void EDIT_Upward(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (IsMultiLine() && es->CurrLine != 0)
-    {
-	--es->CurrLine;
-	if (es->WndRow == 0)
-	{
-	    --es->WndRow;
-	    EDIT_KeyVScrollLine(hwnd, SB_LINEUP);
-	}
-	else
-	    --es->WndRow;
-	EDIT_StickEnd(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_Backward
- *
- *  Cursor left key: move left one character position.
- */
-
-void EDIT_Backward(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (es->CurrCol)
-    {
-	--es->CurrCol;
-	if (*CurrChar == VK_TAB)
-	    es->WndCol -= EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), 
-					 EDIT_StrLength(hwnd, 
-					 EDIT_TextLine(hwnd, es->CurrLine), 
-					 es->CurrCol, 0));
-	else
-	    es->WndCol -= EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), 0);
-	if (es->WndCol < 0)
-	    EDIT_KeyHScroll(hwnd, SB_LINEUP);
-    }
-    else if (IsMultiLine() && es->CurrLine != 0)
-    {
-	EDIT_Upward(hwnd);
-	EDIT_End(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_End
- *
- *  End key: move to end of line.
- */
-
-void EDIT_End(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    while (*CurrChar && *CurrChar != '\r')
-    {
-	es->WndCol += EDIT_CharWidth(hwnd, (BYTE)(*CurrChar), es->WndCol + es->wleft);
-	es->CurrCol++;
-    }
-
-    if (es->WndCol >= ClientWidth(wndPtr))
-    {
-	es->wleft = es->WndCol - ClientWidth(wndPtr) + HSCROLLDIM;
-	es->WndCol -= es->wleft;
-	InvalidateRect(hwnd, NULL, FALSE);
-	UpdateWindow(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_Home
- *
- *  Home key: move to beginning of line.
- */
-
-void EDIT_Home(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    es->CurrCol = es->WndCol = 0;
-    if (es->wleft != 0)
-    {
-	es->wleft = 0;
-	InvalidateRect(hwnd, NULL, FALSE);
-	UpdateWindow(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_StickEnd
- *
- *  Stick the cursor to the end of the line.
- */
-
-void EDIT_StickEnd(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    int len = EDIT_LineLength(hwnd, es->CurrLine);
-    char *cp = EDIT_TextLine(hwnd, es->CurrLine);
-    int currpel;
-
-    es->CurrCol = min(len, es->CurrCol);
-    es->WndCol = min(EDIT_StrLength(hwnd, cp, len, 0) - es->wleft, es->WndCol);
-    currpel = EDIT_StrLength(hwnd, cp, es->CurrCol, 0);
-
-    if (es->wleft > currpel)
-    {
-	es->wleft = max(0, currpel - 20);
-	es->WndCol = currpel - es->wleft;
-	UpdateWindow(hwnd);
-    }
-    else if (currpel - es->wleft >= ClientWidth(wndPtr))
-    {
-	es->wleft = currpel - (ClientWidth(wndPtr) - 5);
-	es->WndCol = currpel - es->wleft;
-	UpdateWindow(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  WM_KEYDOWN message function
- */
-
-void EDIT_KeyDownMsg(HWND hwnd, WORD wParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    dprintf_edit(stddeb,"EDIT_KeyDownMsg: key=%x\n", wParam);
-
-    HideCaret(hwnd);
-    switch (wParam)
-    {
-    case VK_UP:
-	if (SelMarked(es))
-	    EDIT_ClearSel(hwnd);
-	if (IsMultiLine())
-	    EDIT_Upward(hwnd);
-	else
-	    EDIT_Backward(hwnd);
-	break;
-
-    case VK_DOWN:
-	if (SelMarked(es))
-	    EDIT_ClearSel(hwnd);
-	if (IsMultiLine())
-	    EDIT_Downward(hwnd);
-	else
-	    EDIT_Forward(hwnd);
-	break;
-
-    case VK_RIGHT:
-	if (SelMarked(es))
-	    EDIT_ClearSel(hwnd);
-	EDIT_Forward(hwnd);
-	break;
-
-    case VK_LEFT:
-	if (SelMarked(es))
-	    EDIT_ClearSel(hwnd);
-	EDIT_Backward(hwnd);
-	break;
-
-    case VK_HOME:
-	if (SelMarked(es))
-	    EDIT_ClearSel(hwnd);
-	EDIT_Home(hwnd);
-	break;
-
-    case VK_END:
-	if (SelMarked(es))
-	    EDIT_ClearSel(hwnd);
-	EDIT_End(hwnd);
-	break;
-
-    case VK_PRIOR:
-	if (IsMultiLine())
-	{
-	    if (SelMarked(es))
-		EDIT_ClearSel(hwnd);
-	    EDIT_KeyVScrollPage(hwnd, SB_PAGEUP);
-	}
-	break;
-
-    case VK_NEXT:
-	if (IsMultiLine())
-	{
-	    if (SelMarked(es))
-		EDIT_ClearSel(hwnd);
-	    EDIT_KeyVScrollPage(hwnd, SB_PAGEDOWN);
-	}
-	break;
-
-    case VK_BACK:
-	if (SelMarked(es))
-	    EDIT_DeleteSel(hwnd);
-	else
-	{
-	    if (es->CurrCol == 0 && es->CurrLine == 0)
-		break;
-	    EDIT_Backward(hwnd);
-	    EDIT_DelKey(hwnd);
-	}
-	break;
-
-    case VK_DELETE:
-	if (SelMarked(es))
-	    EDIT_DeleteSel(hwnd);
-	else
-	    EDIT_DelKey(hwnd);
-	break;
-    }
-
-    SetCaretPos(es->WndCol, es->WndRow * es->txtht);
-    ShowCaret(hwnd);
-}
-
-
-/*********************************************************************
- *  EDIT_KeyHScroll
- *
- *  Scroll text horizontally using cursor keys.
- */
-
-void EDIT_KeyHScroll(HWND hwnd, WORD opt)
-{
-    int hscrollpos;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (opt == SB_LINEDOWN)
-    {
-	es->wleft += HSCROLLDIM;
-	es->WndCol -= HSCROLLDIM;
-    }
-    else
-    {
-	if (es->wleft == 0)
-	    return;
-	if (es->wleft - HSCROLLDIM < 0)
-	{
-	    es->WndCol += es->wleft;
-	    es->wleft = 0;
-	}	    
-	else
-	{
-	    es->wleft -= HSCROLLDIM;
-	    es->WndCol += HSCROLLDIM;
-	}
-    }
-
-    InvalidateRect(hwnd, NULL, FALSE);
-    UpdateWindow(hwnd);
-
-    if (IsHScrollBar())
-    {
-	hscrollpos = EDIT_ComputeHScrollPos(hwnd);
-	SetScrollPos(hwnd, SB_HORZ, hscrollpos, TRUE);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_KeyVScrollLine
- *
- *  Scroll text vertically by one line using keyboard.
- */
-
-void EDIT_KeyVScrollLine(HWND hwnd, WORD opt)
-{
-    RECT rc;
-    int y, vscrollpos;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (!IsMultiLine())
-	return;
-
-    if (opt == SB_LINEDOWN)
-    {
-	/* move down one line */
-	if (es->wtop + ClientHeight(wndPtr, es) >= es->wlines)
-	    return;
-	es->wtop++;
-    }
-    else
-    {
-	/* move up one line */
-	if (es->wtop == 0)
-	    return;
-	--es->wtop;
-    }
-
-    if (IsWindowVisible(hwnd))
-    {
-	/* adjust client bottom to nearest whole line */
-	GetClientRect(hwnd, &rc);
-	rc.bottom = (rc.bottom / es->txtht) * es->txtht;
-
-	if (opt == SB_LINEUP)
-	{
-	    /* move up one line (scroll window down) */
-	    ScrollWindow(hwnd, 0, es->txtht, &rc, &rc);
-	    /* write top line */
-	    EDIT_WriteTextLine(hwnd, NULL, es->wtop);
-	    es->WndRow++;
-	}
-	else
-	{
-	    /* move down one line (scroll window up) */
-	    ScrollWindow(hwnd, 0, -(es->txtht), &rc, &rc);
-	    /* write bottom line */
-	    y = (((rc.bottom - rc.top) / es->txtht) - 1);
-	    EDIT_WriteTextLine(hwnd, NULL, es->wtop + y);
-	    --es->WndRow;
-	}
-    }
-
-    /* reset the vertical scroll bar */
-    if (IsVScrollBar())
-    {
-	vscrollpos = EDIT_ComputeVScrollPos(hwnd);
-	SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_KeyVScrollPage
- *
- *  Scroll text vertically by one page using keyboard.
- */
-
-void EDIT_KeyVScrollPage(HWND hwnd, WORD opt)
-{
-    int vscrollpos;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (IsMultiLine())
-    {
-	if (opt == SB_PAGEUP)
-	{
-	    if (es->wtop)
-		es->wtop -= ClientHeight(wndPtr, es);
-	}
-	else
-	{
-	    if (es->wtop + ClientHeight(wndPtr, es) < es->wlines)
-	    {
-		es->wtop += ClientHeight(wndPtr, es);
-		if (es->wtop > es->wlines - ClientHeight(wndPtr, es))
-		    es->wtop = es->wlines - ClientHeight(wndPtr, es);
-	    }
-	}
-	if (es->wtop < 0)
-	    es->wtop = 0;
-
-	es->CurrLine = es->wtop + es->WndRow;
-	EDIT_StickEnd(hwnd);
-	InvalidateRect(hwnd, NULL, TRUE);
-	UpdateWindow(hwnd);
-
-	/* reset the vertical scroll bar */
-	if (IsVScrollBar())
-	{
-	    vscrollpos = EDIT_ComputeVScrollPos(hwnd);
-	    SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
-	}
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_KeyVScrollDoc
- *
- *  Scroll text to top and bottom of document using keyboard.
- */
-
-void EDIT_KeyVScrollDoc(HWND hwnd, WORD opt)
-{
-    int vscrollpos;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (!IsMultiLine())
-	return;
-
-    if (opt == SB_TOP)
-	es->wtop = es->wleft = 0;
-    else if (es->wtop + ClientHeight(wndPtr, es) < es->wlines)
-    {
-	es->wtop = es->wlines - ClientHeight(wndPtr, es);
-	es->wleft = 0;
-    }
-
-    es->CurrLine = es->wlines;
-    es->WndRow = es->wlines - es->wtop;
-    EDIT_End(hwnd);
-    InvalidateRect(hwnd, NULL, TRUE);
-    UpdateWindow(hwnd);
-
-    /* reset the vertical scroll bar */
-    if (IsVScrollBar())
-    {
-	vscrollpos = EDIT_ComputeVScrollPos(hwnd);
-	SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_ComputeVScrollPos
- *
- *  Compute the vertical scroll bar position from the window
- *  position and text width.
- */
-
-int EDIT_ComputeVScrollPos(HWND hwnd)
-{
-    int vscrollpos;
-    short minpos, maxpos;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    GetScrollRange(hwnd, SB_VERT, &minpos, &maxpos);
-
-    if (es->wlines > ClientHeight(wndPtr, es))
-	vscrollpos = (double)(es->wtop) / (double)(es->wlines - 
-		     ClientHeight(wndPtr, es)) * (maxpos - minpos);
-    else
-	vscrollpos = minpos;
-
-    return vscrollpos;
-}
-    
-
-/*********************************************************************
- *  EDIT_ComputeHScrollPos
- *
- *  Compute the horizontal scroll bar position from the window
- *  position and text width.
- */
-
-int EDIT_ComputeHScrollPos(HWND hwnd)
-{
-    int hscrollpos;
-    short minpos, maxpos;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    GetScrollRange(hwnd, SB_HORZ, &minpos, &maxpos);
-
-    if (es->textwidth > ClientWidth(wndPtr))
-	hscrollpos = (double)(es->wleft) / (double)(es->textwidth - 
-		     ClientWidth(wndPtr)) * (maxpos - minpos);
-    else
-	hscrollpos = minpos;
-
-    return hscrollpos;
-}
-
-
-/*********************************************************************
- *  EDIT_DelKey
- *
- *  Delete character to right of cursor.
- */
-
-void EDIT_DelKey(HWND hwnd)
-{
-    RECT rc;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    char *currchar = CurrChar;
-    BOOL repaint = *currchar == '\n';
-
-    if (IsMultiLine() && *currchar == '\n' && *(currchar + 1) == '\0')
-	return;
-    strcpy(currchar, currchar + 1);
-    NOTIFY_PARENT(hwnd, EN_UPDATE);
-    
-    if (repaint)
-    {
-	EDIT_BuildTextPointers(hwnd);
-	GetClientRect(hwnd, &rc);
-	rc.top = es->WndRow * es->txtht;
-	InvalidateRect(hwnd, &rc, FALSE);
-	UpdateWindow(hwnd);
-    }
-    else
-    {
-	EDIT_ModTextPointers(hwnd, es->CurrLine + 1, -1);
-	EDIT_WriteTextLine(hwnd, NULL, es->WndRow + es->wtop);
-    }
-
-    es->TextChanged = TRUE;
-    NOTIFY_PARENT(hwnd, EN_CHANGE);
-}
-
-/*********************************************************************
- *  WM_VSCROLL message function
- */
-
-void EDIT_VScrollMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (IsMultiLine())
-    {
-	HideCaret(hwnd);
-
-	switch (wParam)
-	{
-	case SB_LINEUP:
-	case SB_LINEDOWN:
-	    EDIT_VScrollLine(hwnd, wParam);
-	    break;
-
-	case SB_PAGEUP:
-	case SB_PAGEDOWN:
-	    EDIT_VScrollPage(hwnd, wParam);
-	    break;
-	}
-    }
-    
-    SetCaretPos(es->WndCol, es->WndRow);
-    ShowCaret(hwnd);
-}
-
-
-/*********************************************************************
- *  EDIT_VScrollLine
- *
- *  Scroll text vertically by one line using scrollbars.
- */
-
-void EDIT_VScrollLine(HWND hwnd, WORD opt)
-{
-    RECT rc;
-    int y;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    dprintf_edit(stddeb,"EDIT_VScrollLine: direction=%d\n", opt);
-
-    if (opt == SB_LINEDOWN)
-    {
-	/* move down one line */
-	if (es->wtop + ClientHeight(wndPtr, es) >= es->wlines)
-	    return;
-	es->wtop++;
-    }
-    else
-    {
-	/* move up one line */
-	if (es->wtop == 0)
-	    return;
-	--es->wtop;
-    }
-
-    if (IsWindowVisible(hwnd))
-    {
-	/* adjust client bottom to nearest whole line */
-	GetClientRect(hwnd, &rc);
-	rc.bottom = (rc.bottom / es->txtht) * es->txtht;
-
-	if (opt == SB_LINEUP)
-	{
-	    /* move up one line (scroll window down) */
-	    ScrollWindow(hwnd, 0, es->txtht, &rc, &rc);
-	    /* write top line */
-	    EDIT_WriteTextLine(hwnd, NULL, es->wtop);
-	    es->WndRow++;
-	}
-	else
-	{
-	    /* move down one line (scroll window up) */
-	    ScrollWindow(hwnd, 0, -(es->txtht), &rc, &rc);
-	    /* write bottom line */
-	    y = ((rc.bottom - rc.top / es->txtht) - 1);
-	    EDIT_WriteTextLine(hwnd, NULL, es->wtop + y);
-	    --es->WndRow;
-	}
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_VScrollPage
- *
- *  Scroll text vertically by one page using keyboard.
- */
-
-void EDIT_VScrollPage(HWND hwnd, WORD opt)
-{
-    int vscrollpos;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (opt == SB_PAGEUP)
-    {
-	if (es->wtop)
-	    es->wtop -= ClientHeight(wndPtr, es);
-    }
-    else
-    {
-	if (es->wtop + ClientHeight(wndPtr, es) < es->wlines)
-	{
-	    es->wtop += ClientHeight(wndPtr, es);
-	    if (es->wtop > es->wlines - ClientHeight(wndPtr, es))
-		es->wtop = es->wlines - ClientHeight(wndPtr, es);
-	}
-    }
-    if (es->wtop < 0)
-	es->wtop = 0;
-    
-    InvalidateRect(hwnd, NULL, TRUE);
-    UpdateWindow(hwnd);
-
-    /* reset the vertical scroll bar */
-    if (IsVScrollBar())
-    {
-	vscrollpos = EDIT_ComputeVScrollPos(hwnd);
-	SetScrollPos(hwnd, SB_VERT, vscrollpos, TRUE);
-    }
-}
-
-
-/*********************************************************************
- *  WM_HSCROLL message function
- */
-
-void EDIT_HScrollMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    switch (wParam)
-    {
-    case SB_LINEUP:
-    case SB_LINEDOWN:
-	HideCaret(hwnd);
-
-	SetCaretPos(es->WndCol, es->WndRow * es->txtht);
-	ShowCaret(hwnd);
-	break;
-    }
-}
-
-
-/*********************************************************************
- *  WM_SIZE message function
- */
-
-void EDIT_SizeMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (wParam != SIZE_MAXIMIZED && wParam != SIZE_RESTORED) return;
-
-    InvalidateRect(hwnd, NULL, TRUE);
-    es->PaintBkgd = TRUE;
-    UpdateWindow(hwnd);
-}
-
-
-/*********************************************************************
- *  WM_LBUTTONDOWN message function
- */
-
-void EDIT_LButtonDownMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    char *cp;
-    int len;
-    BOOL end = FALSE;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (SelMarked(es))
-	EDIT_ClearSel(hwnd);
-
-    es->WndRow = HIWORD(lParam) / es->txtht;
-    if (!IsMultiLine())
-        es->WndRow = 0;
-    else if (es->WndRow > es->wlines - es->wtop - 1)
-    {
-        es->WndRow = es->wlines - es->wtop - 1;
-	end = TRUE;
-    }
-    es->CurrLine = es->wtop + es->WndRow;
-
-    cp = EDIT_TextLine(hwnd, es->CurrLine);
-    len = EDIT_LineLength(hwnd, es->CurrLine);
-    es->WndCol = LOWORD(lParam) + es->wleft;
-    if (es->WndCol > EDIT_StrLength(hwnd, cp, len, 0) || end)
-	es->WndCol = EDIT_StrLength(hwnd, cp, len, 0);
-    es->CurrCol = EDIT_PixelToChar(hwnd, es->CurrLine, &(es->WndCol));
-    es->WndCol -= es->wleft;
-
-    ButtonDown = TRUE;
-    ButtonRow = es->CurrLine;
-    ButtonCol = es->CurrCol;
-}
-
-
-/*********************************************************************
- *  WM_MOUSEMOVE message function
- */
-
-void EDIT_MouseMoveMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (wParam != MK_LBUTTON)
-	return;
-
-    HideCaret(hwnd);
-    if (ButtonDown)
-    {
-	EDIT_SetAnchor(hwnd, ButtonRow, ButtonCol);
-	TextMarking = TRUE;
-	ButtonDown = FALSE;
-    }
-
-    if (TextMarking)
-    {
-	EDIT_ExtendSel(hwnd, LOWORD(lParam), HIWORD(lParam));
-        SetCaretPos(es->WndCol, es->WndRow * es->txtht);
-    }
-    ShowCaret(hwnd);
-}
-
-
-/*********************************************************************
- *  EDIT_PixelToChar
- *
- *  Convert a pixel offset in the given row to a character offset,
- *  adjusting the pixel offset to the nearest whole character if
- *  necessary.
- */
-
-int EDIT_PixelToChar(HWND hwnd, int row, int *pixel)
-{
-    int ch = 0, i = 0, s_i = 0;
-    char *text;
-
-    dprintf_edit(stddeb,"EDIT_PixelToChar: row=%d, pixel=%d\n", row, *pixel);
-
-    text = EDIT_TextLine(hwnd, row);
-    while (i < *pixel)
-    {
-	s_i = i;
-	i += EDIT_CharWidth(hwnd, (BYTE)(*(text + ch)), i);
-	ch++;
-    }
-
-    /* if stepped past _pixel_, go back a character */
-    if (i - *pixel)
-    {
-	i = s_i;
-	--ch;
-    }
-    *pixel = i;
-    return ch;
-}
-
-
-/*********************************************************************
- *  WM_SETTEXT message function
- */
-
-LONG EDIT_SetTextMsg(HWND hwnd, LONG lParam)
-{
-    int len;
-    char *text;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (strlen((char *)PTR_SEG_TO_LIN(lParam)) <= es->MaxTextLen)
-    {
-	len = ( lParam? strlen((char *)PTR_SEG_TO_LIN(lParam)) : 0 );
-	EDIT_ClearText(hwnd);
-	es->textlen = len;
-	es->hText = EDIT_HeapReAlloc(hwnd, es->hText, len + 3);
-	text = EDIT_HeapAddr(hwnd, es->hText);
-	if (lParam)
-	    strcpy(text, (char *)PTR_SEG_TO_LIN(lParam));
-	text[len]     = '\0';
-	text[len + 1] = '\0';
-	text[len + 2] = '\0';
-	EDIT_BuildTextPointers(hwnd);
-	InvalidateRect(hwnd, NULL, TRUE);
-	es->PaintBkgd = TRUE;
-	es->TextChanged = TRUE;
-	return 0L;
-    }
-    else
-	return EN_ERRSPACE;
-}
-
-
-/*********************************************************************
- *  EDIT_ClearText
- *
- *  Clear text from text buffer.
- */
-
-void EDIT_ClearText(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    unsigned int blen = EditBufLen(wndPtr) + 2;
-    char *text;
-
-    es->hText = EDIT_HeapReAlloc(hwnd, es->hText, blen);
-    text = EDIT_HeapAddr(hwnd, es->hText);
-    memset(text, 0, blen);
-    es->textlen = 0;
-    es->wlines = 0;
-    es->CurrLine = es->CurrCol = 0;
-    es->WndRow = es->WndCol = 0;
-    es->wleft = es->wtop = 0;
-    es->textwidth = 0;
-    es->TextChanged = FALSE;
-    EDIT_ClearTextPointers(hwnd);
-}
-
-
-/*********************************************************************
- *  EM_SETSEL message function
- */
-
-void EDIT_SetSelMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    INT so, eo;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    so = LOWORD(lParam);
-    eo = HIWORD(lParam);
-
-    if (so == -1)       /* if so == -1, clear selection */
-    {
-	EDIT_ClearSel(hwnd);
-	return;
-    }
-
-    if (so == eo)       /* if so == eo, set caret only */
-    {
-	EDIT_GetLineCol(hwnd, (int) so, &(es->CurrLine), &(es->CurrCol));
-	es->WndRow = es->CurrLine - es->wtop;
-
-	if (!wParam)
-	{
-	    if (es->WndRow < 0 || es->WndRow > ClientHeight(wndPtr, es))
-	    {
-		es->wtop = es->CurrLine;
-		es->WndRow = 0;
-	    }
-	    es->WndCol = EDIT_StrLength(hwnd, 
-					EDIT_TextLine(hwnd, es->CurrLine), 
-					es->CurrCol, 0) - es->wleft;
-	    if (es->WndCol > ClientWidth(wndPtr))
-	    {
-		es->wleft = es->WndCol;
-		es->WndCol = 0;
-	    }
-	    else if (es->WndCol < 0)
-	    {
-		es->wleft += es->WndCol;
-		es->WndCol = 0;
-	    }
-	}
-    }
-    else                /* otherwise set selection */
-    {
-	if (eo >= 0 && so > eo)	  /* eo == -1 flag to extend to end of text */
-        {
-            INT tmp;
-            tmp = so;
-            so = eo;
-            eo = tmp;
-        }
-
-	EDIT_GetLineCol(hwnd, (int) so, &(es->SelBegLine), &(es->SelBegCol));
-	EDIT_GetLineCol(hwnd, (int) eo, &(es->SelEndLine), &(es->SelEndCol));
-	es->CurrLine = es->SelEndLine;
-	es->CurrCol = es->SelEndCol;
-	es->WndRow = es->SelEndLine - es->wtop;
-
-	if (!wParam)          /* don't suppress scrolling of text */
-	{
-	    if (es->WndRow < 0)
-	    {
-		es->wtop = es->SelEndLine;
-		es->WndRow = 0;
-	    }
-	    else if (es->WndRow > ClientHeight(wndPtr, es))
-	    {
-		es->wtop += es->WndRow - ClientHeight(wndPtr, es);
-		es->WndRow = ClientHeight(wndPtr, es);
-	    }
-	    es->WndCol = EDIT_StrLength(hwnd, 
-					EDIT_TextLine(hwnd, es->SelEndLine), 
-					es->SelEndCol, 0) - es->wleft;
-	    if (es->WndCol > ClientWidth(wndPtr))
-	    {
-		es->wleft += es->WndCol - ClientWidth(wndPtr);
-		es->WndCol = ClientWidth(wndPtr);
-	    }
-	    else if (es->WndCol < 0)
-	    {
-		es->wleft += es->WndCol;
-		es->WndCol = 0;
-	    }
-	}
-
-	InvalidateRect(hwnd, NULL, TRUE);
-	UpdateWindow(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_GetLineCol
- *
- *  Return line and column in text buffer from character offset.
- */
-
-void EDIT_GetLineCol(HWND hwnd, int off, int *line, int *col)
-{
-    int lineno;
-    char *cp, *cp1;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    char *text = EDIT_HeapAddr(hwnd, es->hText);
-    unsigned int *textPtrs = 
-	(unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-
-    /* check for (0,0) */
-    if (!off || !es->wlines)
-    {
-	*line = 0;
-	*col = 0;
-	return;
-    }
-
-    if (off < 0 || off > strlen(text)) off = strlen(text);
-    cp1 = text;
-    for (lineno = 0; lineno < es->wlines; lineno++)
-    {
-	cp = text + *(textPtrs + lineno);
-	if (off == (int)(cp - text))
-	{
-	    *line = lineno;
-	    *col = 0;
-	    return;
-	}
-	if (off < (int)(cp - text))
-	    break;
-	cp1 = cp;
-    }
-    *line = lineno - 1;
-    *col = off - (int)(cp1 - text);
-#if 0
-    if (*(text + *col) == '\0')
-	(*col)--;
-#endif
-}
-
-
-/*********************************************************************
- *  EDIT_DeleteSel
- *
- *  Delete the current selected text (if any)
- */
-
-void EDIT_DeleteSel(HWND hwnd)
-{
-    char *bbl, *bel;
-    int len;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (SelMarked(es))
-    {
-	bbl = EDIT_TextLine(hwnd, es->SelBegLine) + es->SelBegCol;
-	bel = EDIT_TextLine(hwnd, es->SelEndLine) + es->SelEndCol;
-	len = (int)(bel - bbl);
-	EDIT_SaveDeletedText(hwnd, bbl, len, es->SelBegLine, es->SelBegCol);
-	es->TextChanged = TRUE;
-	strcpy(bbl, bel);
-
-	es->CurrLine = es->SelBegLine;
-	es->CurrCol = es->SelBegCol;
-	es->WndRow = es->SelBegLine - es->wtop;
-	if (es->WndRow < 0)
-	{
-	    es->wtop = es->SelBegLine;
-	    es->WndRow = 0;
-	}
-	es->WndCol = EDIT_StrLength(hwnd, bbl - es->SelBegCol, 
-				     es->SelBegCol, 0) - es->wleft;
-
-	EDIT_BuildTextPointers(hwnd);
-	es->PaintBkgd = TRUE;
-	EDIT_ClearSel(hwnd);
-    }
-}
-    
-
-/*********************************************************************
- *  EDIT_ClearSel
- *
- *  Clear the current selection.
- */
-
-void EDIT_ClearSel(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    es->SelBegLine = es->SelBegCol = 0;
-    es->SelEndLine = es->SelEndCol = 0;
-
-    InvalidateRect(hwnd, NULL, TRUE);
-    UpdateWindow(hwnd);
-}
-
-
-/*********************************************************************
- *  EDIT_TextLineNumber
- *
- *  Return the line number in the text buffer of the supplied
- *  character pointer.
- */
-
-int EDIT_TextLineNumber(HWND hwnd, char *lp)
-{
-    int lineno;
-    char *cp;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    char *text = EDIT_HeapAddr(hwnd, es->hText);
-    unsigned int *textPtrs = 
-	(unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-
-    for (lineno = 0; lineno < es->wlines; lineno++)
-    {
-	cp = text + *(textPtrs + lineno);
-	if (cp == lp)
-	    return lineno;
-	if (cp > lp)
-	    break;
-    }
-    return lineno - 1;
-}
-
-
-/*********************************************************************
- *  EDIT_SetAnchor
- *
- *  Set down anchor for text marking.
- */
-
-void EDIT_SetAnchor(HWND hwnd, int row, int col)
-{
-    BOOL sel = FALSE;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (SelMarked(es))
-    {
-	sel = TRUE;
-        EDIT_ClearSel(hwnd);
-    }
-    es->SelBegLine = es->SelEndLine = row;
-    es->SelBegCol = es->SelEndCol = col;
-    if (sel)
-    {
-	InvalidateRect(hwnd, NULL, FALSE);
-	UpdateWindow(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_ExtendSel
- *
- *  Extend selection to the given screen co-ordinates.
- */
-
-void EDIT_ExtendSel(HWND hwnd, INT x, INT y)
-{
-    int bbl, bel, bbc, bec;
-    char *cp;
-    int len, line;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    dprintf_edit(stddeb,"EDIT_ExtendSel: x=%d, y=%d\n", x, y);
-
-    bbl = es->SelEndLine;
-    bbc = es->SelEndCol;
-    y = max(y,0);
-    if (IsMultiLine())
-    {
-        if ((line = es->wtop + y / es->txtht) >= es->wlines)
-	    line = es->wlines - 1;
-    }
-    else
-        line = 0;
-        
-    cp = EDIT_TextLine(hwnd, line);
-    len = EDIT_LineLength(hwnd, line);
-
-    es->WndRow = y / es->txtht;
-    if (!IsMultiLine())
-	    es->WndRow = 0;
-    else if (es->WndRow > es->wlines - es->wtop - 1)
-	    es->WndRow = es->wlines - es->wtop - 1;
-    es->CurrLine = es->wtop + es->WndRow;
-    es->SelEndLine = es->CurrLine;
-
-    es->WndCol = es->wleft + max(x,0);
-    if (es->WndCol > EDIT_StrLength(hwnd, cp, len, 0))
-	es->WndCol = EDIT_StrLength(hwnd, cp, len, 0);
-    es->CurrCol = EDIT_PixelToChar(hwnd, es->CurrLine, &(es->WndCol));
-    es->WndCol -= es->wleft;
-    es->SelEndCol = es->CurrCol;
-
-    bel = es->SelEndLine;
-    bec = es->SelEndCol;
-
-    /* return if no new characters to mark */
-    if (bbl == bel && bbc == bec)
-	return;
-
-    /* put lowest marker first */
-    if (bbl > bel)
-    {
-	swap(&bbl, &bel);
-	swap(&bbc, &bec);
-    }
-    if (bbl == bel && bbc > bec)
-	swap(&bbc, &bec);
-
-    for (y = bbl; y <= bel; y++)
-    {
-	if (y == bbl && y == bel)
-	    EDIT_WriteSel(hwnd, y, bbc, bec);
-	else if (y == bbl)
-	    EDIT_WriteSel(hwnd, y, bbc, -1);
-	else if (y == bel)
-	    EDIT_WriteSel(hwnd, y, 0, bec);
-	else
-	    EDIT_WriteSel(hwnd, y, 0, -1);
-    }
-}
-
-
-/*********************************************************************
- *  EDIT_WriteSel
- *
- *  Display selection by reversing pixels in selected text.
- *  If end == -1, selection applies to end of line.
- */
-
-void EDIT_WriteSel(HWND hwnd, int y, int start, int end)
-{
-    RECT rc, rcInvert;
-    int scol, ecol;
-    char *cp;
-    HDC hdc;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    dprintf_edit(stddeb,"EDIT_WriteSel: y=%d start=%d end=%d\n", y, start,end);
-    GetClientRect(hwnd, &rc);
-
-    /* make sure y is within the window */
-    if (y < es->wtop || y > (es->wtop + ClientHeight(wndPtr, es)))
-	return;
-
-    /* get pointer to text */
-    cp = EDIT_TextLine(hwnd, y);
-
-    /* get length of line if end == -1 */
-    if (end == -1)
-	end = EDIT_LineLength(hwnd, y);
-
-    /* For some reason Rectangle, when called with R2_XORPEN filling,
-     * appears to leave a 2 pixel gap between characters and between
-     * lines.  I have kludged this by adding on two pixels to ecol and
-     * to the line height in the call to Rectangle.
-     */
-    scol = EDIT_StrLength(hwnd, cp, start, 0) - es->wleft;
-    if (scol > rc.right) return;
-    if (scol < rc.left) scol = rc.left;
-    ecol = EDIT_StrLength(hwnd, cp, end, 0) - es->wleft;
-    if (ecol < rc.left) return;
-    if (ecol > rc.right) ecol = rc.right;
-
-    hdc = GetDC(hwnd);
-    rcInvert.left = scol;
-    rcInvert.top = y * es->txtht;
-    rcInvert.right = ecol;
-    rcInvert.bottom = (y + 1) * es->txtht;
-    InvertRect(hdc, (LPRECT) &rcInvert);
-    ReleaseDC(hwnd, hdc);
-}
-
-
-/*********************************************************************
- *  EDIT_StopMarking
- *
- *  Stop text marking (selection).
- */
-
-void EDIT_StopMarking(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    TextMarking = FALSE;
-    if (es->SelBegLine > es->SelEndLine)
-    {
-	swap(&(es->SelBegLine), &(es->SelEndLine));
-	swap(&(es->SelBegCol), &(es->SelEndCol));
-    }
-    if (es->SelBegLine == es->SelEndLine && es->SelBegCol > es->SelEndCol)
-	swap(&(es->SelBegCol), &(es->SelEndCol));
-}
-
-
-/*********************************************************************
- *  EM_GETLINE message function
- */
-
-LONG EDIT_GetLineMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    char *cp, *cp1;
-    int len;
-    char *buffer = (char *)lParam;
-
-    cp = EDIT_TextLine(hwnd, wParam);
-    cp1 = EDIT_TextLine(hwnd, wParam + 1);
-    len = min((int)(cp1 - cp), (WORD)(*buffer));
-    strncpy(buffer, cp, len);
-
-    return (LONG)len;
-}
-
-
-/*********************************************************************
- *  EM_GETSEL message function
- */
-
-LONG EDIT_GetSelMsg(HWND hwnd)
-{
-    int so, eo;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    unsigned int *textPtrs = 
-	(unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-
-    so = *(textPtrs + es->SelBegLine) + es->SelBegCol;
-    eo = *(textPtrs + es->SelEndLine) + es->SelEndCol;
-
-    return MAKELONG(so, eo);
-}
-
-
-/*********************************************************************
- *  EM_REPLACESEL message function
- */
-
-void EDIT_ReplaceSel(HWND hwnd, LONG lParam)
-{
-    EDIT_DeleteSel(hwnd);
-    EDIT_InsertText(hwnd, (char *)PTR_SEG_TO_LIN(lParam),
-                    strlen((char *)PTR_SEG_TO_LIN(lParam)));
-    InvalidateRect(hwnd, NULL, TRUE);
-    UpdateWindow(hwnd);
-}
-
-
-/*********************************************************************
- *  EDIT_InsertText
- *
- *  Insert text at current line and column.
- */
-
-void EDIT_InsertText(HWND hwnd, char *str, int len)
-{
-    int plen;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    char *text = EDIT_HeapAddr(hwnd, es->hText);
-    
-    plen = strlen(text) + len;
-    if (plen + 1 > es->textlen)
-    {
-	es->hText = EDIT_HeapReAlloc(hwnd, es->hText, es->textlen + len);
-	es->textlen = plen + 1;
-    }
-    memmove(CurrChar + len, CurrChar, strlen(CurrChar) + 1);
-    memcpy(CurrChar, str, len);
-
-    EDIT_BuildTextPointers(hwnd);
-    es->PaintBkgd = TRUE;
-    es->TextChanged = TRUE;
-
-    EDIT_GetLineCol(hwnd, (int)((CurrChar + len) - text), &(es->CurrLine),
-		                                    &(es->CurrCol));
-    es->WndRow = es->CurrLine - es->wtop;
-    es->WndCol = EDIT_StrLength(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
-				 es->CurrCol, 0) - es->wleft;
-}
-
-
-/*********************************************************************
- *  EM_LINEFROMCHAR message function
- */
-
-LONG EDIT_LineFromCharMsg(HWND hwnd, WORD wParam)
-{
-    int row, col;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (wParam == (WORD)-1)
-	return (LONG)(es->SelBegLine);
-    else
-	EDIT_GetLineCol(hwnd, wParam, &row, &col);
-
-    return (LONG)row;
-}
-
-
-/*********************************************************************
- *  EM_LINEINDEX message function
- */
-
-LONG EDIT_LineIndexMsg(HWND hwnd, WORD wParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    unsigned int *textPtrs = 
-	(unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-
-    if (wParam == (WORD)-1)
-	wParam = es->CurrLine;
-
-    return (LONG)(*(textPtrs + wParam));
-}
-
-
-/*********************************************************************
- *  EM_LINELENGTH message function
- */
-
-LONG EDIT_LineLengthMsg(HWND hwnd, WORD wParam)
-{
-    int row, col, len;
-    int sbl, sbc, sel, sec;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    unsigned int *textPtrs = 
-	(unsigned int *)EDIT_HeapAddr(hwnd, es->hTextPtrs);
-
-    if (wParam == (WORD)-1)
-    {
-	if (SelMarked(es))
-	{
-	    sbl = es->SelBegLine;
-	    sbc = es->SelBegCol;
-	    sel = es->SelEndLine;
-	    sec = es->SelEndCol;
-
-	    if (sbl > sel)
-	    {
-		swap(&sbl, &sel);
-		swap(&sbc, &sec);
-	    }
-	    if (sbl == sel && sbc > sec)
-		swap(&sbc, &sec);
-
-	    if (sbc == sel)
-	    {
-		len = *(textPtrs + sbl + 1) - *(textPtrs + sbl) - 1;
-		return len - sec - sbc;
-	    }
-
-	    len = *(textPtrs + sel + 1) - *(textPtrs + sel) - sec - 1;
-	    return len + sbc;
-	}
-	else    /* no selection marked */
-	{
-	    len = *(textPtrs + es->CurrLine + 1) - 
-		  *(textPtrs + es->CurrLine) - 1;
-	    return len;
-	}
-    }
-    else    /* line number specified */
-    {
-	EDIT_GetLineCol(hwnd, wParam, &row, &col);
-	len = *(textPtrs + row + 1) - *(textPtrs + row);
-	return len;
-    }
-}
-
-
-/*********************************************************************
- *  WM_SETFONT message function
- */
-
-void EDIT_SetFont(HWND hwnd, WORD wParam, LONG lParam)
-{
-    HDC hdc;
-    TEXTMETRIC tm;
-    HFONT oldfont;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    short *charWidths = (short *)EDIT_HeapAddr(hwnd, es->hCharWidths);
-
-    es->hFont = wParam;
-    hdc = GetDC(hwnd);
-    oldfont = (HFONT)SelectObject(hdc, (HANDLE)es->hFont);
-    GetCharWidth(hdc, 0, 255, charWidths);
-    GetTextMetrics(hdc, &tm);
-    es->txtht = tm.tmHeight + tm.tmExternalLeading;
-    SelectObject(hdc, (HANDLE)oldfont);
-    ReleaseDC(hwnd, hdc);
-
-    es->WndRow = (es->CurrLine - es->wtop) / es->txtht;
-    es->WndCol = EDIT_StrLength(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
-				 es->CurrCol, 0) - es->wleft;
-
-    InvalidateRect(hwnd, NULL, TRUE);
-    es->PaintBkgd = TRUE;
-    if (lParam) UpdateWindow(hwnd);
-}
-
-
-/*********************************************************************
- *  EDIT_SaveDeletedText
- *
- *  Save deleted text in deleted text buffer.
- */
-
-void EDIT_SaveDeletedText(HWND hwnd, char *deltext, int len,
-			                  int line, int col)
-{
-    char *text;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (!es->hDeletedText)
-        es->hDeletedText = GlobalAlloc( GMEM_MOVEABLE, len );
-    else 
-        es->hDeletedText = GlobalReAlloc(es->hDeletedText, len, GMEM_MOVEABLE);
-    if (!es->hDeletedText) return;
-    text = (char *)GlobalLock(es->hDeletedText);
-    memcpy(text, deltext, len);
-    GlobalUnlock(es->hDeletedText);
-    es->DeletedLength = len;
-    es->DeletedCurrLine = line;
-    es->DeletedCurrCol = col;
-}
-
-
-/*********************************************************************
- *  EDIT_ClearDeletedText
- *
- *  Clear deleted text buffer.
- */
-
-void EDIT_ClearDeletedText(HWND hwnd)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    GlobalFree(es->hDeletedText);
-    es->hDeletedText = 0;
-    es->DeletedLength = 0;
-}
-
-
-/*********************************************************************
- *  EM_UNDO message function
- */
-
-LONG EDIT_UndoMsg(HWND hwnd)
-{
-    char *text;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-    
-    if (es->hDeletedText)
-    {
-	text = (char *)GlobalLock(es->hDeletedText);
-	es->CurrLine = es->DeletedCurrLine;
-	es->CurrCol = es->DeletedCurrCol;
-	EDIT_InsertText(hwnd, text, es->DeletedLength);
-	GlobalUnlock(es->hDeletedText);
-	EDIT_ClearDeletedText(hwnd);
-
-	es->SelBegLine = es->CurrLine;
-	es->SelBegCol = es->CurrCol;
-	EDIT_GetLineCol(hwnd, (int)((CurrChar + es->DeletedLength) - text), 
-			&(es->CurrLine), &(es->CurrCol));
-	es->WndRow = es->CurrLine - es->wtop;
-	es->WndCol = EDIT_StrLength(hwnd, EDIT_TextLine(hwnd, es->CurrLine),
-				     es->CurrCol, 0) - es->wleft;
-	es->SelEndLine = es->CurrLine;
-	es->SelEndCol = es->CurrCol;
-
-	InvalidateRect(hwnd, NULL, TRUE);
-	UpdateWindow(hwnd);
-	return 1;
-    }
-    else
-	return 0;
-}
-
-
-/*********************************************************************
- *  EDIT_HeapAlloc
- *
- *  Allocate the specified number of bytes on the specified local heap.
- */
-
-unsigned int EDIT_HeapAlloc(HWND hwnd, int bytes)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    unsigned int ret;
-
-    ret = LOCAL_Alloc( wndPtr->hInstance, LMEM_FIXED, bytes );
-    if (ret == 0)
-      printf("EDIT_HeapAlloc: Out of heap-memory\n");
-    return ret;
-}
-
-
-/*********************************************************************
- *  EDIT_HeapAddr
- *
- *  Return the address of the memory pointed to by the handle.
- */
-
-void *EDIT_HeapAddr(HWND hwnd, unsigned int handle)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    return handle ? PTR_SEG_OFF_TO_LIN( wndPtr->hInstance, handle ) : 0;
-}
-
-
-/*********************************************************************
- *  EDIT_HeapReAlloc
- *
- *  Reallocate the memory pointed to by the handle.
- */
-
-unsigned int EDIT_HeapReAlloc(HWND hwnd, unsigned int handle, int bytes)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-
-    return LOCAL_ReAlloc( wndPtr->hInstance, handle, bytes, LMEM_FIXED );
-}
-
-
-/*********************************************************************
- *  EDIT_HeapFree
- *
- *  Frees the memory pointed to by the handle.
- */
-
-void EDIT_HeapFree(HWND hwnd, unsigned int handle)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-
-    LOCAL_Free( wndPtr->hInstance, handle );
-}
-
-
-/*********************************************************************
- *  EDIT_HeapSize
- *
- *  Return the size of the given object on the local heap.
- */
-
-unsigned int EDIT_HeapSize(HWND hwnd, unsigned int handle)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-
-#if 0
-    return HEAP_LocalSize((MDESC **)*(LONG *)(wndPtr->wExtra + 2), handle);
-#endif
-    return LOCAL_Size( wndPtr->hInstance, handle );
-}
-
-
-/*********************************************************************
- *  EM_SETHANDLE message function
- */
-
-void EDIT_SetHandleMsg(HWND hwnd, WORD wParam)
-{
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    if (IsMultiLine())
-    {
-	es->hText = wParam;
-	es->textlen = EDIT_HeapSize(hwnd, es->hText);
-	es->wlines = 0;
-	es->wtop = es->wleft = 0;
-	es->CurrLine = es->CurrCol = 0;
-	es->WndRow = es->WndCol = 0;
-	es->TextChanged = FALSE;
-	es->textwidth = 0;
-	es->SelBegLine = es->SelBegCol = 0;
-	es->SelEndLine = es->SelEndCol = 0;
-	dprintf_edit(stddeb, "EDIT_SetHandleMsg: textlen=%d\n",
-                                                es->textlen);
-
-	EDIT_BuildTextPointers(hwnd);
-	es->PaintBkgd = TRUE;
-	InvalidateRect(hwnd, NULL, TRUE);
-	UpdateWindow(hwnd);
-    }
-}
-
-
-/*********************************************************************
- *  EM_SETTABSTOPS message function
- */
-
-LONG EDIT_SetTabStopsMsg(HWND hwnd, WORD wParam, LONG lParam)
-{
-    unsigned short *tabstops;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    es->NumTabStops = wParam;
-    if (wParam == 0)
-	es->hTabStops = EDIT_HeapReAlloc(hwnd, es->hTabStops, 1);
-    else if (wParam == 1)
-    {
-	es->hTabStops = EDIT_HeapReAlloc(hwnd, es->hTabStops, 1);
-	tabstops = (unsigned short *)EDIT_HeapAddr(hwnd, es->hTabStops);
-	*tabstops = (unsigned short)lParam;
-    }
-    else
-    {
-	es->hTabStops = EDIT_HeapReAlloc(hwnd, es->hTabStops, wParam);
-	tabstops = (unsigned short *)EDIT_HeapAddr(hwnd, es->hTabStops);
-	memcpy(tabstops, (unsigned short *)lParam, wParam);
-    }
-    return 0L;
-}
-
-
-/*********************************************************************
- *  EDIT_CopyToClipboard
- *
- *  Copy the specified text to the clipboard.
- */
-
-void EDIT_CopyToClipboard(HWND hwnd)
-{
-    HANDLE hMem;
-    char *lpMem;
-    int i, len;
-    char *bbl, *bel;
-    WND *wndPtr = WIN_FindWndPtr(hwnd);
-    EDITSTATE *es = 
-	(EDITSTATE *)EDIT_HeapAddr(hwnd, (HANDLE)(*(wndPtr->wExtra)));
-
-    bbl = EDIT_TextLine(hwnd, es->SelBegLine) + es->SelBegCol;
-    bel = EDIT_TextLine(hwnd, es->SelEndLine) + es->SelEndCol;
-    len = (int)(bel - bbl);
-
-    hMem = GlobalAlloc(GHND, (DWORD)(len + 1));
-    lpMem = GlobalLock(hMem);
-
-    for (i = 0; i < len; i++)
-	*lpMem++ = *bbl++;
-
-    GlobalUnlock(hMem);
-    OpenClipboard(hwnd);
-    EmptyClipboard();
-    SetClipboardData(CF_TEXT, hMem);
-    CloseClipboard();
-}
-
-
-/*********************************************************************
- *  WM_PASTE message function
- */
-
-void EDIT_PasteMsg(HWND hwnd)
-{
-    HANDLE hClipMem;
-    char *lpClipMem;
-
-    OpenClipboard(hwnd);
-    if (!(hClipMem = GetClipboardData(CF_TEXT)))
-    {
-	/* no text in clipboard */
-	CloseClipboard();
-	return;
-    }
-    lpClipMem = GlobalLock(hClipMem);
-    EDIT_InsertText(hwnd, lpClipMem, strlen(lpClipMem));
-    GlobalUnlock(hClipMem);
-    CloseClipboard();
-    InvalidateRect(hwnd, NULL, TRUE);
-    UpdateWindow(hwnd);
-}
-
-
-/*********************************************************************
- *  Utility functions
- */
-
-void swap(int *a, int *b)
-{
-    int x;
-
-    x = *a;
-    *a = *b;
-    *b = x;
-}
-
diff --git a/controls/listbox.c b/controls/listbox.c
index 75b1a37..a2518b6 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -386,8 +386,7 @@
  
   *lpmeasure = lpls->mis;
   lpmeasure->itemHeight = lphl->StdItemHeight;
-  SendMessage(lphl->hParent, WM_MEASUREITEM,
-	      0, USER_HEAP_SEG_ADDR(hTemp));
+  SendMessage(lphl->hParent, WM_MEASUREITEM, 0, USER_HEAP_SEG_ADDR(hTemp));
 
   if (lphl->dwStyle & LBS_OWNERDRAWFIXED) {
     lphl->StdItemHeight = lpmeasure->itemHeight;
@@ -419,7 +418,7 @@
 
 int ListBoxInsertString(LPHEADLIST lphl, UINT uIndex, LPSTR newstr)
 {
-  LPLISTSTRUCT *lppls, lplsnew;
+  LPLISTSTRUCT *lppls, lplsnew, lpls;
   HANDLE       hStr;
   LPSTR	str;
   UINT	Count;
@@ -448,20 +447,25 @@
   
   hStr = 0;
   if (HasStrings(lphl)) {
-    hStr = LIST_HEAP_ALLOC(lphl, GMEM_MOVEABLE, strlen(newstr) + 1);
+    hStr = LIST_HEAP_ALLOC(lphl, LMEM_MOVEABLE, strlen(newstr) + 1);
     str = (LPSTR)LIST_HEAP_ADDR(lphl, hStr);
     if (str == NULL) return LB_ERRSPACE;
     strcpy(str, newstr);
     lplsnew->itemText = str;
     /* I'm not so sure about the next one */
-    lplsnew->mis.itemData = LIST_HEAP_SEG_ADDR(lphl,hStr); 
+    lplsnew->mis.itemData = 0;
   } else {
     lplsnew->itemText = NULL;
     lplsnew->mis.itemData = (DWORD)newstr;
   }
 
-  lplsnew->mis.itemID = lphl->ItemsCount;
+  lplsnew->mis.itemID = uIndex;
   lplsnew->hData = hStr;
+  
+  /* adjust the itemID field of the following entries */
+  for(lpls = lplsnew->lpNext; lpls != NULL; lpls = lpls->lpNext) {
+      lpls->mis.itemID++;
+  }
  
   if (lphl->needMeasure) {
     ListBoxAskMeasure(lphl, lplsnew);
@@ -530,7 +534,7 @@
 
 int ListBoxDeleteString(LPHEADLIST lphl, UINT uIndex)
 {
-  LPLISTSTRUCT lpls;
+  LPLISTSTRUCT lpls, lpls2;
   UINT	Count;
 
   if (uIndex >= lphl->ItemsCount) return LB_ERR;
@@ -548,9 +552,14 @@
       lpls2 = lpls;
       lpls = (LPLISTSTRUCT)lpls->lpNext;
     }
-    lpls2->lpNext = (LPLISTSTRUCT)lpls->lpNext;
+    lpls2->lpNext = lpls->lpNext;
   }
 
+  /* adjust the itemID field of the following entries */
+  for(lpls2 = lpls->lpNext; lpls2 != NULL; lpls2 = lpls2->lpNext) {
+      lpls2->mis.itemID--;
+  }
+ 
   lphl->ItemsCount--;
 
   if (lpls->hData != 0) LIST_HEAP_FREE(lphl, lpls->hData);
diff --git a/debugger/break.c b/debugger/break.c
index b3945ee..711c495 100644
--- a/debugger/break.c
+++ b/debugger/break.c
@@ -141,7 +141,7 @@
    unsigned int addr;
    addr=wbp[num].addr;
    if(wbp[num].next_addr == 0)
-	wbp[num].next_addr = db_disasm( addr, 0, (dbg_mode == 16) );
+	wbp[num].next_addr = db_disasm( 0, addr, (dbg_mode == 16) );
    wbp[num].addr=wbp[num].next_addr;
    wbp[num].next_addr=addr;
 }
diff --git a/debugger/db_disasm.c b/debugger/db_disasm.c
index fe64594..5d7d176 100644
--- a/debugger/db_disasm.c
+++ b/debugger/db_disasm.c
@@ -74,7 +74,7 @@
 #include "db_disasm.h"
 #include "ldt.h"
 
-extern void print_address(unsigned int addr, FILE * outfile, int addrlen);
+extern void print_address( unsigned int seg, unsigned int addr, int addrlen );
 
 /*
  * Switch to disassemble 16-bit code.
@@ -891,10 +891,11 @@
 	10,	/* EXTR */
 };
 
-static unsigned int db_get_task_value(unsigned int loc, int size, int is_signed)
+static unsigned int db_get_task_value( unsigned int segment, unsigned int loc,
+                                       int size, int is_signed)
 {
   unsigned int result;
-  if (db_disasm_16) loc = (unsigned int)PTR_SEG_TO_LIN(loc);
+  if (segment) loc = (unsigned int)PTR_SEG_OFF_TO_LIN( segment, loc );
   switch(size)
     {
     case 4:
@@ -923,8 +924,8 @@
   return result;
 }
 
-#define	get_value_inc(result, loc, size, is_signed) \
-	result = db_get_task_value((loc), (size), (is_signed)); \
+#define	get_value_inc(result, segment, loc, size, is_signed) \
+	result = db_get_task_value((segment), (loc), (size), (is_signed)); \
         if (!db_disasm_16) (loc) += (size); \
         else (loc) = ((loc) & 0xffff0000) | (((loc) + (size)) & 0xffff);
 
@@ -932,7 +933,8 @@
  * Read address at location and return updated location.
  */
 db_addr_t
-db_read_address(loc, short_addr, regmodrm, addrp)
+db_read_address(segment, loc, short_addr, regmodrm, addrp)
+        unsigned int segment;
 	db_addr_t	loc;
 	int		short_addr;
 	int		regmodrm;
@@ -957,7 +959,7 @@
 	    switch (mod) {
 		case 0:
 		    if (rm == 6) {
-			get_value_inc(disp, loc, 2, TRUE);
+			get_value_inc(disp, segment, loc, 2, TRUE);
 			addrp->disp = disp;
 			addrp->base = 0;
 		    }
@@ -967,12 +969,12 @@
 		    }
 		    break;
 		case 1:
-		    get_value_inc(disp, loc, 1, TRUE);
+		    get_value_inc(disp, segment, loc, 1, TRUE);
 		    addrp->disp = disp;
 		    addrp->base = db_index_reg_16[rm];
 		    break;
 		case 2:
-		    get_value_inc(disp, loc, 2, TRUE);
+		    get_value_inc(disp, segment, loc, 2, TRUE);
 		    addrp->disp = disp;
 		    addrp->base = db_index_reg_16[rm];
 		    break;
@@ -980,7 +982,7 @@
 	}
 	else {
 	    if (mod != 3 && rm == 4) {
-		get_value_inc(sib, loc, 1, FALSE);
+		get_value_inc(sib, segment, loc, 1, FALSE);
 		rm = sib_base(sib);
 		index = sib_index(sib);
 		if (index != 4)
@@ -991,7 +993,7 @@
 	    switch (mod) {
 		case 0:
 		    if (rm == 5) {
-			get_value_inc(addrp->disp, loc, 4, FALSE);
+			get_value_inc(addrp->disp, segment, loc, 4, FALSE);
 			addrp->base = 0;
 		    }
 		    else {
@@ -1001,13 +1003,13 @@
 		    break;
 
 		case 1:
-		    get_value_inc(disp, loc, 1, TRUE);
+		    get_value_inc(disp, segment, loc, 1, TRUE);
 		    addrp->disp = disp;
 		    addrp->base = db_reg[LONG][rm];
 		    break;
 
 		case 2:
-		    get_value_inc(disp, loc, 4, FALSE);
+		    get_value_inc(disp, segment, loc, 4, FALSE);
 		    addrp->disp = disp;
 		    addrp->base = db_reg[LONG][rm];
 		    break;
@@ -1027,7 +1029,7 @@
         fprintf(stderr, "0x%4.4x", addr & 0xffff );
         break;
     case LONG:
-        print_address(addr, stderr, db_disasm_16 ? 16 : 32);
+        print_address(0, addr, db_disasm_16 ? 16 : 32);
         break;
     }
 }
@@ -1064,7 +1066,8 @@
  * and return updated location.
  */
 db_addr_t
-db_disasm_esc(loc, inst, short_addr, size, seg)
+db_disasm_esc(segment, loc, inst, short_addr, size, seg)
+        unsigned int segment;
 	db_addr_t	loc;
 	int		inst;
 	int		short_addr;
@@ -1077,14 +1080,14 @@
 	struct i_addr	address;
 	char *		name;
 
-	get_value_inc(regmodrm, loc, 1, FALSE);
+	get_value_inc(regmodrm, segment, loc, 1, FALSE);
 	fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
 	mod = f_mod(regmodrm);
 	if (mod != 3) {
 	    /*
 	     * Normal address modes.
 	     */
-	    loc = db_read_address(loc, short_addr, regmodrm, &address);
+	    loc = db_read_address(segment,loc, short_addr, regmodrm, &address);
 	    fprintf(stderr,fp->f_name);
 	    switch(fp->f_size) {
 		case SNGL:
@@ -1145,14 +1148,13 @@
 }
 
 /*
- * Disassemble instruction at 'loc'.  'altfmt' specifies an
- * (optional) alternate format.  Return address of start of
+ * Disassemble instruction at 'loc'.  Return address of start of
  * next instruction.
  */
 db_addr_t
-db_disasm(loc, altfmt, flag16)
+db_disasm(segment, loc, flag16)
+        unsigned int segment;
 	db_addr_t	loc;
-	boolean_t	altfmt;
         boolean_t       flag16;
 {
 	int	inst;
@@ -1163,7 +1165,7 @@
 	char *	i_name;
 	int	i_size;
 	int	i_mode;
-	int	regmodrm;
+	int	regmodrm = 0;
 	boolean_t	first;
 	int	displ;
 	int	prefix;
@@ -1174,7 +1176,7 @@
 
 	db_disasm_16 = flag16;
 
-	get_value_inc(inst, loc, 1, FALSE);
+	get_value_inc(inst, segment, loc, 1, FALSE);
 
 	if (db_disasm_16) {
 	    short_addr = TRUE;
@@ -1233,7 +1235,7 @@
 		    break;
 	    }
 	    if (prefix) {
-		get_value_inc(inst, loc, 1, FALSE);
+		get_value_inc(inst, segment, loc, 1, FALSE);
 	    }
 	} while (prefix);
 
@@ -1244,7 +1246,7 @@
 	}
 
 	if (inst == 0x0f) {
-	    get_value_inc(inst, loc, 1, FALSE);
+	    get_value_inc(inst, segment, loc, 1, FALSE);
 	    ip = db_inst_0f[inst>>4];
 	    if (ip == 0) {
 		ip = &db_bad_inst;
@@ -1257,8 +1259,8 @@
 	    ip = &db_inst_table[inst];
 
 	if (ip->i_has_modrm) {
-	    get_value_inc(regmodrm, loc, 1, FALSE);
-	    loc = db_read_address(loc, short_addr, regmodrm, &address);
+	    get_value_inc(regmodrm, segment, loc, 1, FALSE);
+	    loc = db_read_address(segment,loc, short_addr, regmodrm, &address);
 	}
 
 	i_name = ip->i_name;
@@ -1399,42 +1401,42 @@
 
 		case I:
 		    len = db_lengths[size];
-		    get_value_inc(imm, loc, len, FALSE);/* unsigned */
+		    get_value_inc(imm, segment, loc, len, FALSE);/* unsigned */
 		    fprintf(stderr,"$0x%x", imm);
 		    break;
 
 		case Is:
 		    len = db_lengths[size];
-		    get_value_inc(imm, loc, len, TRUE);	/* signed */
+		    get_value_inc(imm, segment, loc, len, TRUE); /* signed */
 		    fprintf(stderr,"$%d", imm);
 		    break;
 
 		case Ib:
-		    get_value_inc(imm, loc, 1, FALSE);	/* unsigned */
+		    get_value_inc(imm, segment, loc, 1, FALSE); /* unsigned */
 		    fprintf(stderr,"$0x%x", imm);
 		    break;
 
 		case Ibs:
-		    get_value_inc(imm, loc, 1, TRUE);	/* signed */
+		    get_value_inc(imm, segment, loc, 1, TRUE); /* signed */
 		    fprintf(stderr,"$%d", imm);
 		    break;
 
 		case Iw:
-		    get_value_inc(imm, loc, 2, FALSE);	/* unsigned */
+		    get_value_inc(imm, segment, loc, 2, FALSE); /* unsigned */
 		    fprintf(stderr,"$0x%x", imm);
 		    break;
 
 		case Il:
-		    get_value_inc(imm, loc, 4, FALSE);
+		    get_value_inc(imm, segment, loc, 4, FALSE);
 		    fprintf(stderr,"$0x%x", imm);
 		    break;
 
 		case O:
 		    if (short_addr) {
-			get_value_inc(displ, loc, 2, TRUE);
+			get_value_inc(displ, segment, loc, 2, TRUE);
 		    }
 		    else {
-			get_value_inc(displ, loc, 4, TRUE);
+			get_value_inc(displ, segment, loc, 4, TRUE);
 		    }
 		    if (seg)
 			fprintf(stderr,"%s:%d",seg, displ);
@@ -1444,7 +1446,7 @@
 		    break;
 
 		case Db:
-		    get_value_inc(displ, loc, 1, TRUE);
+		    get_value_inc(displ, segment, loc, 1, TRUE);
 		    if (short_addr) {
 			/* offset only affects low 16 bits */
 		        displ = (loc & 0xffff0000)
@@ -1458,13 +1460,13 @@
 
 		case Dl:
 		    if (short_addr) {
-			get_value_inc(displ, loc, 2, TRUE);
+			get_value_inc(displ, segment, loc, 2, TRUE);
 			/* offset only affects low 16 bits */
 		        displ = (loc & 0xffff0000)
 			      | ((loc + displ) & 0xffff);
 		    }
 		    else {
-			get_value_inc(displ, loc, 4, TRUE);
+			get_value_inc(displ, segment, loc, 4, TRUE);
 			displ = displ + loc;
 		    }
 		    db_task_printsym((db_addr_t)displ,
@@ -1481,30 +1483,17 @@
 
 		case OS:
 		    if (short_addr) {
-			get_value_inc(imm, loc, 2, FALSE); /* offset */
+			get_value_inc(imm, segment, loc, 2, FALSE);/* offset */
 		    }
 		    else {
-			get_value_inc(imm, loc, 4, FALSE); /* offset */
+			get_value_inc(imm, segment, loc, 4, FALSE);/* offset */
 		    }
-		    get_value_inc(imm2, loc, 2, FALSE);	/* segment */
-                    if (short_addr)
-                        print_address( (imm2 << 16) | imm, stderr, 16 );
-                    else
-                        fprintf(stderr,"$0x%x,0x%08x", imm2, imm);
+		    get_value_inc(imm2, segment, loc, 2, FALSE); /* segment */
+                    print_address( imm2, imm, short_addr ? 16 : 32 );
 		    break;
 	    }
 	}
 
-	if (altfmt == 0 && !db_disasm_16) {
-	    if (inst == 0xe9 || inst == 0xeb) {
-		/*
-		 * GAS pads to longword boundary after unconditional jumps.
-		 */
-#if 0
-		loc = (loc + (4-1)) & ~(4-1);
-#endif
-	    }
-	}
 	return (loc);
 }
 
diff --git a/debugger/db_disasm.h b/debugger/db_disasm.h
index 8192e0d..73992d7 100644
--- a/debugger/db_disasm.h
+++ b/debugger/db_disasm.h
@@ -4,4 +4,5 @@
 typedef unsigned char boolean_t;
 typedef unsigned long db_addr_t;
 
-extern db_addr_t db_disasm(db_addr_t loc, boolean_t altfmt, boolean_t flag16);
+extern db_addr_t db_disasm(unsigned int segment, db_addr_t loc,
+                           boolean_t flag16);
diff --git a/debugger/dbg.y b/debugger/dbg.y
index cf7a3d2..fd8748d 100644
--- a/debugger/dbg.y
+++ b/debugger/dbg.y
@@ -43,7 +43,6 @@
 %token SET
 %token MODE
 %token PRINT
-%token FILE_IDENTIFIER
 %token IDENTIFIER
 %token NO_SYMBOL
 %token SYMBOLFILE
@@ -64,7 +63,7 @@
 	| CONT '\n'        { return 0; }
 	| 'c' '\n'         { return 0; }
 	| ABORT '\n'       { kill(getpid(), SIGABRT); }
- 	| SYMBOLFILE FILE_IDENTIFIER '\n' { read_symboltable($2); }
+ 	| SYMBOLFILE IDENTIFIER '\n' { read_symboltable($2); }
 	| DEFINE IDENTIFIER expr '\n'  { add_hash($2, 0, $3); }
 	| MODE NUM	   { mode_command($2); }
 	| ENABLE NUM	   { enable_break($2); }
@@ -82,18 +81,17 @@
 
 
 x_command:
-	  'x' expr  '\n' { examine_memory($2, 1, 'x'); }
-	| 'x' '/' fmt expr  '\n' { examine_memory($4, 1, $3); }
-	| 'x' '/' NUM fmt expr  '\n' { examine_memory($5, $3, $4); }
+	  'x' expr  '\n' { examine_memory( 0xffffffff, $2, 1, 'x'); }
+	| 'x' '/' fmt expr  '\n' { examine_memory( 0xffffffff, $4, 1, $3); }
+	| 'x' '/' NUM fmt expr  '\n' { examine_memory( 0xffffffff, $5, $3, $4); }
 
 print:
 	  'p'
 	| PRINT
 	
  print_command:
-	  print expr '\n' { examine_memory(((unsigned int) &$2 ), 1, 'x'); }
-	| print '/' fmt expr '\n' { examine_memory((unsigned int) &$4, 1, $3); }
-	| print '/' NUM fmt expr '\n' { examine_memory((unsigned int) &$5, $3, $4); }
+	  print expr '\n' { examine_memory( 0, ((unsigned int) &$2 ), 1, 'x'); }
+	| print '/' fmt expr '\n' { examine_memory( 0, (unsigned int) &$4, 1, $3); }
 
  fmt:  'x'     { $$ = 'x'; }
 	| 'd'  { $$ = 'd'; }
@@ -162,15 +160,10 @@
 	yyin = stdin;
 	regval = regs ? regs : dummy_regs;
 
-	if (SC_CS == WINE_CODE_SELECTOR)
-        {
-		dbg_mask = 0xffffffff;
-		dbg_mode = 32;
-	} else
-        {
-		dbg_mask = 0xffff;
-		dbg_mode = 16;
-	}
+	if (SC_CS == WINE_CODE_SELECTOR) dbg_mode = 32;
+        else dbg_mode = (GET_SEL_FLAGS(SC_CS) & LDT_FLAGS_32BIT) ? 32 : 16;
+        dbg_mask = (dbg_mode == 32) ? 0xffffffff : 0xffff;
+
 	fprintf(stderr,"In %d bit mode.\n", dbg_mode);
 
 	if(dbg_mode == 32 && !loaded_symbols)
@@ -190,8 +183,7 @@
 	    unsigned int addr;
 	    int bpnum;
 	    addr = SC_EIP(dbg_mask);
-	    if((addr & 0xffff0000) == 0 && dbg_mode == 16)
-	      addr = PTR_SEG_OFF_TO_LIN( SC_CS, addr );
+	    if (dbg_mode == 16) addr = PTR_SEG_OFF_TO_LIN( SC_CS, addr );
 	    if(should_continue(bpnum=get_bpnum(addr))){
 		insert_break(1);
 		return;
@@ -201,7 +193,7 @@
 
 	/* Show where we crashed */
 	if(regs)
-	  examine_memory(SC_EIP(dbg_mask), 1, 'i');
+	  examine_memory(0xffffffff, SC_EIP(dbg_mask), 1, 'i');
 
 	issue_prompt();
 
diff --git a/debugger/debug.l b/debugger/debug.l
index 6e9817e..68975b7 100644
--- a/debugger/debug.l
+++ b/debugger/debug.l
@@ -29,7 +29,6 @@
 HEXDIGIT [0-9a-fA-F]
 
 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
-FILE_IDENTIFIER [_a-zA-Z\.~/][_a-zA-Z\.~/]*
 
 %%
 
@@ -120,10 +119,6 @@
 	          return IDENTIFIER;
 	         }
 
-{FILE_IDENTIFIER} {yylval = (int) make_symbol(yytext); 
-	          return FILE_IDENTIFIER;
-	         }
-
 [ \t]+        /* Eat up whitespace */
 
 .		{ if(syntax_error == 0) {
diff --git a/debugger/hash.c b/debugger/hash.c
index 4dd93ad..5136c1c 100644
--- a/debugger/hash.c
+++ b/debugger/hash.c
@@ -16,8 +16,8 @@
 
 struct  name_hash{
 	struct name_hash * next;
-        unsigned short segment;
-	unsigned int * address;
+        unsigned int segment;
+	unsigned int address;
 	char * name;
 };
 
@@ -37,7 +37,7 @@
 }
 
 
-void add_hash(char * name, unsigned short segment, unsigned int * address)
+void add_hash(char * name, unsigned int segment, unsigned int address)
 {
 	struct name_hash  * new;
 	int hash;
@@ -54,7 +54,7 @@
 	name_hash_table[hash] = new;
 }
 
-unsigned int * find_hash(char * name)
+unsigned int find_hash(char * name)
 {
 	char buffer[256];
 	struct name_hash  * nh;
@@ -70,32 +70,39 @@
 	};
 
 
-	return (unsigned int *) 0xffffffff;
+	return 0xffffffff;
 }
 
 
 static char name_buffer[256];
 
-char * find_nearest_symbol(unsigned int segment, unsigned int * address)
+char * find_nearest_symbol(unsigned int segment, unsigned int address)
 {
 	struct name_hash * nearest;
-	struct name_hash start;
 	struct name_hash  * nh;
+        unsigned int nearest_address;
 	int i;
 	
-	nearest = &start;
-	start.address = (unsigned int *) 0;
+	nearest = NULL;
+        nearest_address = 0;
 	
 	for(i=0; i<NR_NAME_HASH; i++) {
 		for(nh = name_hash_table[i]; nh; nh = nh->next)
 			if (nh->segment == segment &&
                             nh->address <= address &&
-                            nh->address > nearest->address) nearest = nh;
-	};
-	if((unsigned int) nearest->address == 0) return NULL;
+                            nh->address >= nearest_address)
+                        {
+                            nearest_address = nh->address;
+                            nearest = nh;
+                        }
+	}
+        if (!nearest) return NULL;
 
-	sprintf(name_buffer, "%s+0x%x", nearest->name, ((unsigned int) address) - 
-		((unsigned int) nearest->address));
+        if (address == nearest->address)
+            sprintf( name_buffer, "%s", nearest->name );
+	else
+            sprintf( name_buffer, "%s+0x%x", nearest->name,
+                     address - nearest->address );
 	return name_buffer;
 }
 
@@ -142,7 +149,7 @@
 		};
 		
 		nargs = sscanf(buffer, "%x %c %s", &addr, &type, name);
-		add_hash(name, 0, (unsigned int *) addr);
+		add_hash(name, 0, addr);
       };
       fclose(symbolfile);
 }
@@ -172,8 +179,7 @@
         sprintf( buffer, "%*.*s.%*.*s", *name, *name, name + 1,
                  *cpnt, *cpnt, cpnt + 1 );
         address = MODULE_GetEntryPoint( hModule, *(WORD *)(cpnt + *cpnt + 1) );
-        if (address)
-            add_hash(buffer, address >> 16, (unsigned int*)(address & 0xffff));
+        if (address) add_hash( buffer, HIWORD(address), LOWORD(address) );
     }
 
       /* Now search the non-resident names table */
@@ -186,7 +192,6 @@
         sprintf( buffer, "%*.*s.%*.*s", *name, *name, name + 1,
                  *cpnt, *cpnt, cpnt + 1 );
         address = MODULE_GetEntryPoint( hModule, *(WORD *)(cpnt + *cpnt + 1) );
-        if (address)
-            add_hash(buffer, address >> 16, (unsigned int*)(address & 0xffff));
+        if (address) add_hash( buffer, HIWORD(address), LOWORD(address) );
     }
 }
diff --git a/debugger/info.c b/debugger/info.c
index 938150a..3f99349 100644
--- a/debugger/info.c
+++ b/debugger/info.c
@@ -10,6 +10,8 @@
 #include "db_disasm.h"
 #include "regpos.h"
 
+extern char * find_nearest_symbol( unsigned int seg, unsigned int addr );
+
 extern int * regval;
 extern unsigned int dbg_mask;
 extern unsigned int dbg_mode;
@@ -19,29 +21,14 @@
   fprintf(stderr,"Application not running\n");
 }
 
-void print_address(unsigned int addr, FILE * outfile, int addrlen)
+void print_address( unsigned int segment, unsigned int addr, int addrlen )
 {
-    extern char * find_nearest_symbol(unsigned short, unsigned int *);
-    char *name;
+    char *name = find_nearest_symbol( segment, addr );
 
-    if (addrlen == 16)
-    {
-        name = find_nearest_symbol( addr >> 16,
-                                    (unsigned int *)(addr & 0xffff) );
-        if (name)
-            fprintf( outfile, "0x%4.4x:0x%4.4x (%s)",
-                     addr >> 16, addr & 0xffff, name );
-        else
-            fprintf( outfile, "0x%4.4x:0x%4.4x", addr >> 16, addr & 0xffff );
-    }
-    else
-    {
-        name = find_nearest_symbol(0, (unsigned int *) addr);
-	if(name)
-		fprintf(outfile,"0x%8.8x(%s)", addr, name);
-	else
-		fprintf(outfile,"0x%8.8x", addr);
-    }
+    if (segment) fprintf( stderr, "0x%04x:", segment );
+    if (addrlen == 16) fprintf( stderr, "0x%04x", addr );
+    else fprintf( stderr, "0x%08x", addr );
+    if (name) fprintf( stderr, " (%s)", name );
 }
 
 
@@ -82,7 +69,7 @@
 	}
 
 	fprintf(stderr,"Stack dump:\n");
-	dump = (int*) SC_EIP(dbg_mask);
+	dump = (int*) SC_ESP(dbg_mask);
 	for(i=0; i<22; i++) 
 	{
 	    fprintf(stderr," %8.8x", *dump++);
@@ -93,24 +80,28 @@
 }
 
 
-void examine_memory(int addr, int count, char format){
-	char * pnt;
-	unsigned int * dump;
-	unsigned short int * wdump;
-	int i;
+void examine_memory( unsigned int segment, unsigned int addr,
+                     int count, char format )
+{
+    char * pnt;
+    unsigned int * dump;
+    unsigned short int * wdump;
+    int i;
 
-	if((addr & 0xffff0000) == 0 && dbg_mode == 16)
-            addr |= (format == 'i' ? SC_CS : SC_DS) << 16;
+    if (segment == 0xffffffff)
+        segment = (dbg_mode == 32) ? 0 : (format == 'i' ? SC_CS : SC_DS);
+    
+    if (format != 'i' && count > 1)
+    {
+        print_address( segment, addr, dbg_mode );
+        fprintf(stderr,":  ");
+    }
 
-	if(format != 'i' && count > 1) {
-		print_address(addr, stderr, dbg_mode);
-		fprintf(stderr,":  ");
-	};
+    pnt = segment ? (char *)PTR_SEG_OFF_TO_LIN(segment,addr) : (char *)addr;
 
-	switch(format){
+    switch(format)
+    {
 	case 's':
-		pnt = dbg_mode == 16 ? (char *)PTR_SEG_TO_LIN(addr)
-                                     : (char *)addr;
 		if (count == 1) count = 256;
 	        while(*pnt && count) {
 			fputc( *pnt++, stderr);
@@ -121,22 +112,21 @@
 
 	case 'i':
 		for(i=0; i<count; i++) {
-			print_address(addr, stderr, dbg_mode);
+			print_address( segment, addr, dbg_mode );
 			fprintf(stderr,":  ");
-			addr = db_disasm( addr, 0, (dbg_mode == 16) );
+			addr = db_disasm( segment, addr, (dbg_mode == 16) );
 			fprintf(stderr,"\n");
 		};
 		return;
 	case 'x':
-		dump = dbg_mode == 16 ? (unsigned int *)PTR_SEG_TO_LIN(addr)
-                                      : (unsigned int *)addr;
+		dump = (unsigned int *)pnt;
 		for(i=0; i<count; i++) 
 		{
 			fprintf(stderr," %8.8x", *dump++);
                         addr += 4;
 			if ((i % 8) == 7) {
 				fprintf(stderr,"\n");
-				print_address(addr, stderr, dbg_mode);
+				print_address( segment, addr, dbg_mode );
 				fprintf(stderr,":  ");
 			};
 		}
@@ -144,15 +134,14 @@
 		return;
 	
 	case 'd':
-		dump = dbg_mode == 16 ? (unsigned int *)PTR_SEG_TO_LIN(addr)
-                                      : (unsigned int *)addr;
+		dump = (unsigned int *)pnt;
 		for(i=0; i<count; i++) 
 		{
 			fprintf(stderr," %d", *dump++);
                         addr += 4;
 			if ((i % 8) == 7) {
 				fprintf(stderr,"\n");
-				print_address(addr, stderr, dbg_mode);
+				print_address( segment, addr, dbg_mode );
 				fprintf(stderr,":  ");
 			};
 		}
@@ -160,15 +149,14 @@
 		return;
 	
 	case 'w':
-		wdump = dbg_mode == 16 ? (unsigned short *)PTR_SEG_TO_LIN(addr)
-                                       : (unsigned short *)addr;
+		wdump = (unsigned short *)pnt;
 		for(i=0; i<count; i++) 
 		{
 			fprintf(stderr," %x", *wdump++);
                         addr += 2;
 			if ((i % 10) == 7) {
 				fprintf(stderr,"\n");
-				print_address(addr, stderr, dbg_mode);
+				print_address( segment, addr, dbg_mode );
 				fprintf(stderr,":  ");
 			};
 		}
@@ -176,8 +164,6 @@
 		return;
 	
 	case 'c':
-		pnt = dbg_mode == 16 ? (char *)PTR_SEG_TO_LIN(addr)
-                                     : (char *)addr;
 		for(i=0; i<count; i++) 
 		{
 			if(*pnt < 0x20) {
@@ -188,7 +174,7 @@
                         addr++;
 			if ((i % 32) == 7) {
 				fprintf(stderr,"\n");
-				print_address(addr, stderr, dbg_mode);
+				print_address( segment, addr, dbg_mode );
 				fprintf(stderr,":  ");
 			};
 		}
@@ -196,15 +182,13 @@
 		return;
 	
 	case 'b':
-		pnt = dbg_mode == 16 ? (char *)PTR_SEG_TO_LIN(addr)
-                                     : (char *)addr;
 		for(i=0; i<count; i++) 
 		{
 			fprintf(stderr," %02x", (*pnt++) & 0xff);
                         addr++;
 			if ((i % 32) == 7) {
 				fprintf(stderr,"\n");
-				print_address(addr, stderr, dbg_mode);
+				print_address( segment, addr, dbg_mode );
 				fprintf(stderr,":  ");
 			};
 		}
@@ -285,7 +269,7 @@
     /* See if in 32 bit mode or not.  Assume GDT means 32 bit. */
     if ((cs & 7) != 7) {
       fprintf(stderr,"%d ",frameno++);
-      print_address(frame->u.win32.saved_ip,stderr,32);
+      print_address( 0, frame->u.win32.saved_ip, 32 );
       fprintf( stderr, "\n" );
       if (!frame->u.win32.saved_ip) break;
       frame = (struct frame *) frame->u.win32.saved_bp;
diff --git a/debugger/readline/Make.os9 b/debugger/readline/Make.os9
deleted file mode 100644
index c632847..0000000
--- a/debugger/readline/Make.os9
+++ /dev/null
@@ -1,19 +0,0 @@
-##  $Revision: 1.2 $
-##
-##  OS-9 makefile for editline library.
-##
-
-.SUFFIXES:
-
-RFILES	= editline.r complete.r sysos9.r
-
-%.r:		%.c
-	cc68 -r -Dstrchr=index -Dstrrchr=rindex -DNEED_STRDUP -DSYS_OS9 $*.c
-
-testit:		testit.r editline.lib
-	cc68 -f=testit testit.r -l=editline.lib
-
-$(RFILES):	$(RFILES:%.r=%.c)
-
-editline.lib:	$(RFILES)
-	cat $(RFILES) >$@
diff --git a/debugger/readline/os9.h b/debugger/readline/os9.h
deleted file mode 100644
index 7bb7cf3..0000000
--- a/debugger/readline/os9.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*  $Revision: 1.1 $
-**
-**  Editline system header file for OS-9 (on 68k).
-*/
-
-#define CRLF		"\r\l"
-#define FORWARD		extern
-
-#include <dir.h>
-typedef struct direct	DIRENTRY;
diff --git a/debugger/readline/sysos9.c b/debugger/readline/sysos9.c
deleted file mode 100644
index fd23aa4..0000000
--- a/debugger/readline/sysos9.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*  $Revision: 1.1 $
-**
-**  OS-9 system-dependant routines for editline library.
-*/
-#include "editline.h"
-#include <sgstat.h>
-#include <modes.h>
-
-
-void
-rl_ttyset(Reset)
-    int			Reset;
-{
-    static struct sgbuf	old;
-    struct sgbuf	new;
-
-
-    if (Reset == 0) {
-        _gs_opt(0, &old);
-        _gs_opt(0, &new);
-        new.sg_backsp = 0;	new.sg_delete = 0;	new.sg_echo = 0;
-        new.sg_alf = 0;		new.sg_nulls = 0;	new.sg_pause = 0;
-        new.sg_page = 0;	new.sg_bspch = 0;	new.sg_dlnch = 0;
-        new.sg_eorch = 0;	new.sg_eofch = 0;	new.sg_rlnch = 0;
-        new.sg_dulnch = 0;	new.sg_psch = 0;	new.sg_kbich = 0;
-        new.sg_kbach = 0;	new.sg_bsech = 0;	new.sg_bellch = 0;
-        new.sg_xon = 0;		new.sg_xoff = 0;	new.sg_tabcr = 0;
-        new.sg_tabsiz = 0;
-        _ss_opt(0, &new);
-        rl_erase = old.sg_bspch;
-        rl_kill = old.sg_dlnch;
-        rl_eof = old.sg_eofch;
-        rl_intr = old.sg_kbich;
-        rl_quit = -1;
-    }
-    else
-        _ss_opt(0, &old);
-}
-
-void
-rl_add_slash(path, p)
-    char	*path;
-    char	*p;
-{
-    (void)strcat(p, access(path, S_IREAD | S_IFDIR) ? " " : "/");
-}
diff --git a/debugger/readline/version.c b/debugger/readline/version.c
deleted file mode 100644
index 7b1b242..0000000
--- a/debugger/readline/version.c
+++ /dev/null
@@ -1,6 +0,0 @@
-const char version_string[] = "1.234";
-
-
-static char foobar[]="foobar";
-
-const char * foo_string = foobar;
diff --git a/if1632/compobj.spec b/if1632/compobj.spec
index 248eecf..765ad30 100644
--- a/if1632/compobj.spec
+++ b/if1632/compobj.spec
@@ -1,9 +1,9 @@
 name	compobj
 id	22
 
-1 stub COBUILDVERSION
-2 stub COINITIALIZE
-3 stub COUNINITIALIZE
+1 pascal CoBuildVersion() CoBuildVersion
+2 pascal CoInitialize(ptr) CoInitialize
+3 pascal CoUninitialize() CoUnitialize
 4 stub COGETMALLOC
 5 stub COREGISTERCLASSOBJECT
 6 stub COREVOKECLASSOBJECT
diff --git a/if1632/gdi.spec b/if1632/gdi.spec
index 81584db..99b769b 100644
--- a/if1632/gdi.spec
+++ b/if1632/gdi.spec
@@ -20,7 +20,7 @@
 17  pascal OffsetViewportOrg(word s_word s_word) OffsetViewportOrg
 18  pascal ScaleViewportExt(word s_word s_word s_word s_word) ScaleViewportExt
 19  pascal16 LineTo(word s_word s_word) LineTo
-20  pascal MoveTo(word s_word s_word) MoveTo
+20  pascal   MoveTo(word s_word s_word) MoveTo
 21  pascal16 ExcludeClipRect(word s_word s_word s_word s_word) ExcludeClipRect
 22  pascal16 IntersectClipRect(word s_word s_word s_word s_word)
              IntersectClipRect
@@ -35,7 +35,7 @@
              RoundRect
 29  pascal16 PatBlt(word s_word s_word s_word s_word long) PatBlt
 30  pascal16 SaveDC(word) SaveDC
-31  pascal SetPixel(word s_word s_word long) SetPixel
+31  pascal   SetPixel(word s_word s_word long) SetPixel
 32  pascal16 OffsetClipRgn(word s_word s_word) OffsetClipRgn
 33  pascal16 TextOut(word s_word s_word ptr word) TextOut
 34  pascal16 BitBlt( word s_word s_word s_word s_word word s_word s_word long)
@@ -123,7 +123,7 @@
 125 pascal16 CreateMetaFile(ptr) CreateMetaFile
 126 pascal16 CloseMetaFile(word) CloseMetaFile
 127 pascal16 DeleteMetaFile(word) DeleteMetaFile
-128 pascal MulDiv(s_word s_word s_word) MulDiv
+128 pascal16 MulDiv(s_word s_word s_word) MulDiv
 129 pascal16 SaveVisRgn(word) SaveVisRgn
 130 pascal16 RestoreVisRgn(word) RestoreVisRgn
 131 pascal16 InquireVisRgn(word) InquireVisRgn
@@ -212,7 +212,7 @@
 313 pascal16 GetRasterizerCaps(ptr word) GetRasterizerCaps
 314 stub EngineExtTextOut
 330 pascal16 EnumFontFamilies(word ptr segptr long) EnumFontFamilies
-332 stub GetKerningPairs
+332 pascal16 GetKerningPairs(word word ptr) GetKerningPairs
 345 pascal16 GetTextAlign(word) GetTextAlign
 346 pascal16 SetTextAlign(word word) SetTextAlign
 348 pascal16 Chord(word s_word s_word s_word s_word s_word s_word
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index 1fbeb4e..e546d1d 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -211,7 +211,7 @@
 #327 K327
 328 stub _DebugOutput
 #329 K329
-332 stub THHOOK
+#332 stub THHOOK
 334 pascal16 IsBadReadPtr(segptr word) IsBadReadPtr
 335 pascal16 IsBadWritePtr(segptr word) IsBadWritePtr
 336 pascal16 IsBadCodePtr(segptr) IsBadCodePtr
diff --git a/if1632/ole2.spec b/if1632/ole2.spec
index 8b47478..fe82b71 100644
--- a/if1632/ole2.spec
+++ b/if1632/ole2.spec
@@ -1,9 +1,9 @@
 name	OLE2
 id	15
 
-1 stub OLEBUILDVERSION
-2 stub OLEINITIALIZE
-3 stub OLEUNINITIALIZE
+1 stub OleBuildVersion
+2 pascal OleInitialize(ptr) OleInitialize
+3 pascal OleUninitialize() OleUninitialize
 4 stub DLLGETCLASSOBJECT
 #5 WEP
 6 stub OLEQUERYLINKFROMDATA
diff --git a/if1632/ole2disp.spec b/if1632/ole2disp.spec
index 86475f6..7f09aec 100644
--- a/if1632/ole2disp.spec
+++ b/if1632/ole2disp.spec
@@ -109,5 +109,30 @@
 106 stub VARBOOLFROMDISP
 107 stub DOINVOKEMETHOD
 108 stub VARIANTCHANGETYPEEX
-#109 WEP
-#110 ___EXPORTEDSTUB
+109 stub SAFEARRAYPTROFINDEX
+110 stub SETERRORINFO
+111 stub GETERRORINFO
+112 stub CREATEERRORINFO
+113 stub _IID_IERRORINFO
+114 stub _IID_ICREATEERRORINFO
+115 stub _IID_ISUPPORTERRORINFO
+116 stub VARUI1FROMI2
+117 stub VARUI1FROMI4
+118 stub VARUI1FROMR4
+119 stub VARUI1FROMR8
+120 stub VARUI1FROMCY
+121 stub VARUI1FROMDATE
+122 stub VARUI1FROMSTR
+123 stub VARUI1FROMDISP
+124 stub VARUI1FROMBOOL
+125 stub VARI2FROMUI1
+126 stub VARI4FROMUI1
+127 stub VARR4FROMUI1
+128 stub VARR8FROMUI1
+129 stub VARDATEFROMUI1
+130 stub VARCYFROMUI1
+131 stub VARBSTRFROMUI1
+132 stub VARBOOLFROMUI1
+133 stub DLLCANUNLOADNOW
+#134 stub WEP
+#135 stub ___EXPORTEDSTUB
diff --git a/if1632/ole2nls.spec b/if1632/ole2nls.spec
index f975990..bafbc4f 100644
--- a/if1632/ole2nls.spec
+++ b/if1632/ole2nls.spec
@@ -5,7 +5,7 @@
 2 pascal GetSystemDefaultLCID()    GetSystemDefaultLCID
 3 pascal GetUserDefaultLangID()    GetUserDefaultLangID
 4 pascal GetSystemDefaultLangID()  GetSystemDefaultLangID
-5 stub GETLOCALEINFOA
+5 pascal GetLocaleInfoA(long long ptr word) GetLocaleInfoA
 6 stub LCMAPSTRINGA
 7 stub GETSTRINGTYPEA
 8 stub COMPARESTRINGA
diff --git a/if1632/olecli.spec b/if1632/olecli.spec
index a476791..03ef5ca 100644
--- a/if1632/olecli.spec
+++ b/if1632/olecli.spec
@@ -56,7 +56,7 @@
 57 stub OLEEXECUTE
 58 stub OLECREATEINVISIBLE
 59 stub OLEQUERYCLIENTVERSION
-60 stub OLEISDCMETA
+60 pascal16 OleIsDcMeta(word) OleIsDcMeta
 100 stub DOCWNDPROC
 101 stub SRVRWNDPROC
 102 stub MFCALLBACKFUNC
diff --git a/if1632/relay.c b/if1632/relay.c
index c628457..1524517 100644
--- a/if1632/relay.c
+++ b/if1632/relay.c
@@ -21,6 +21,9 @@
 #define DLL_ENTRY(name) \
   { #name, name##_Code_Start, name##_Data_Start, \
     name##_Module_Start, name##_Module_End, TRUE, 0 }
+#define DLL_ENTRY_NOTUSED(name) \
+  { #name, name##_Code_Start, name##_Data_Start, \
+    name##_Module_Start, name##_Module_End, FALSE, 0 }
 
 struct dll_table_s dll_builtin_table[N_BUILTINS] =
 {
@@ -38,17 +41,17 @@
     DLL_ENTRY(TOOLHELP),
     DLL_ENTRY(MOUSE),
     DLL_ENTRY(COMMDLG),
-    DLL_ENTRY(OLE2),
-    DLL_ENTRY(OLE2CONV),
-    DLL_ENTRY(OLE2DISP),
-    DLL_ENTRY(OLE2NLS),
-    DLL_ENTRY(OLE2PROX),
-    DLL_ENTRY(OLECLI),
-    DLL_ENTRY(OLESVR),
-    DLL_ENTRY(COMPOBJ),
-    DLL_ENTRY(STORAGE),
+    DLL_ENTRY_NOTUSED(OLE2),
+    DLL_ENTRY_NOTUSED(OLE2CONV),
+    DLL_ENTRY_NOTUSED(OLE2DISP),
+    DLL_ENTRY_NOTUSED(OLE2NLS),
+    DLL_ENTRY_NOTUSED(OLE2PROX),
+    DLL_ENTRY_NOTUSED(OLECLI),
+    DLL_ENTRY_NOTUSED(OLESVR),
+    DLL_ENTRY_NOTUSED(COMPOBJ),
+    DLL_ENTRY_NOTUSED(STORAGE),
     DLL_ENTRY(WINPROCS),
-    DLL_ENTRY(DDEML)
+    DLL_ENTRY_NOTUSED(DDEML)
 };
 
 /* don't forget to increase N_BUILTINS in dlls.h if you add a dll */
@@ -153,7 +156,7 @@
 /***********************************************************************
  *           RELAY_DebugReturn
  */
-void RELAY_DebugReturn( int short_ret, int ret_val )
+void RELAY_DebugReturn( int func_type, int ret_val )
 {
     STACK16FRAME *frame;
     struct dll_table_s *table;
@@ -166,8 +169,18 @@
     name  = MODULE_GetEntryPointName( table->hModule, frame->ordinal_number );
     printf( "Ret  %s.%d: %*.*s() ",
             table->name, frame->ordinal_number, *name, *name, name + 1 );
-    if (short_ret) printf( "retval=0x%04x\n", ret_val & 0xffff );
-    else printf( "retval=0x%08x\n", ret_val );
+    switch(func_type)
+    {
+    case 0: /* long */
+        printf( "retval=0x%08x ds=%04x\n", ret_val, frame->ds );
+        break;
+    case 1: /* word */
+        printf( "retval=0x%04x ds=%04x\n", ret_val & 0xffff, frame->ds );
+        break;
+    case 2: /* regs */
+        printf( "retval=none ds=%04x\n", frame->ds );
+        break;
+    }
 }
 
 
diff --git a/if1632/shell.spec b/if1632/shell.spec
index ad04c35..da6e571 100644
--- a/if1632/shell.spec
+++ b/if1632/shell.spec
@@ -6,27 +6,28 @@
 # 			proper parameters. It's just to have stub for PROGMAN.EXE ...
 #
 
-  1 pascal RegOpenKey(word ptr ptr) RegOpenKey
-  2 pascal RegCreateKey(word ptr ptr) RegCreateKey
-  3 pascal RegCloseKey(word) RegCloseKey
-  4 pascal RegDeleteKey(word ptr) RegDeleteKey
-  5 pascal RegSetValue(word ptr long ptr long) RegSetValue
-  6 pascal RegQueryValue(word ptr ptr ptr) RegQueryValue
-  7 pascal RegEnumKey(word long ptr long) RegEnumKey
-  9 pascal DragAcceptFiles(word word) DragAcceptFiles
- 11 pascal DragQueryFile(word s_word ptr s_word) DragQueryFile
- 12 pascal DragFinish(word) DragFinish
- 13 pascal DragQueryPoint(word ptr) DragQueryPoint
- 20 pascal ShellExecute(word ptr ptr ptr ptr s_word) ShellExecute 
- 21 pascal FindExecutable(ptr ptr ptr) FindExecutable
- 22 pascal ShellAbout(word ptr ptr word) ShellAbout
- 33 pascal AboutDlgProc(word word word long) AboutDlgProc
- 34 pascal ExtractIcon(word ptr s_word) ExtractIcon
- 36 pascal ExtractAssociatedIcon(word ptr ptr) ExtractAssociatedIcon
- 37 pascal DoEnvironmentSubst(ptr word) DoEnvironmentSubst
+  1 pascal   RegOpenKey(word ptr ptr) RegOpenKey
+  2 pascal   RegCreateKey(word ptr ptr) RegCreateKey
+  3 pascal   RegCloseKey(word) RegCloseKey
+  4 pascal   RegDeleteKey(word ptr) RegDeleteKey
+  5 pascal   RegSetValue(word ptr long ptr long) RegSetValue
+  6 pascal   RegQueryValue(word ptr ptr ptr) RegQueryValue
+  7 pascal   RegEnumKey(word long ptr long) RegEnumKey
+  9 pascal16 DragAcceptFiles(word word) DragAcceptFiles
+ 11 pascal16 DragQueryFile(word s_word ptr s_word) DragQueryFile
+ 12 pascal16 DragFinish(word) DragFinish
+ 13 pascal16 DragQueryPoint(word ptr) DragQueryPoint
+ 20 pascal16 ShellExecute(word ptr ptr ptr ptr s_word) ShellExecute 
+ 21 pascal16 FindExecutable(ptr ptr ptr) FindExecutable
+ 22 pascal16 ShellAbout(word ptr ptr word) ShellAbout
+ 33 pascal16 AboutDlgProc(word word word long) AboutDlgProc
+ 34 pascal16 ExtractIcon(word ptr s_word) ExtractIcon
+ 36 pascal16 ExtractAssociatedIcon(word ptr ptr) ExtractAssociatedIcon
+ 37 pascal   DoEnvironmentSubst(ptr word) DoEnvironmentSubst
+ 38 stub FindEnvironmentString
  39 stub InternalExtractIcon
-102 pascal RegisterShellHook(ptr) RegisterShellHook
-103 pascal ShellHookProc() ShellHookProc
+102 pascal16 RegisterShellHook(ptr) RegisterShellHook
+103 pascal16 ShellHookProc() ShellHookProc
 
 #  8   7  0000  WEP exported, shared data
 #100   4  0550  HERETHARBETYGARS exported, shared data
diff --git a/if1632/sound.spec b/if1632/sound.spec
index 7447932..2191fdd 100644
--- a/if1632/sound.spec
+++ b/if1632/sound.spec
@@ -1,21 +1,20 @@
 name	sound
 id	6
 
-1    pascal  OPENSOUND() OpenSound
-2    pascal  CLOSESOUND() CloseSound
-3    pascal  SETVOICEQUEUESIZE(word word) SetVoiceQueueSize
-4    pascal  SETVOICENOTE(word word word word) SetVoiceNote
-5    pascal  SETVOICEACCENT(word word word word word) 
-		       SetVoiceAccent
-6    pascal  SETVOICEENVELOPE(word word word) SetVoiceEnvelope
-7    pascal  SETSOUNDNOISE(word word) SetSoundNoise
-8    pascal  SETVOICESOUND(word long word) SetVoiceSound
-9    pascal  STARTSOUND() StartSound
-10   pascal  STOPSOUND() StopSound
-11   pascal  WAITSOUNDSTATE(word) WaitSoundState
-12   pascal  SYNCALLVOICES() SyncAllVoices
-13   pascal  COUNTVOICENOTES(word) CountVoiceNotes
-14   pascal  GETTHRESHOLDEVENT() GetThresholdEvent
-15   pascal  GETTHRESHOLDSTATUS() GetThresholdStatus
-16   pascal  SETVOICETHRESHOLD(word word) SetVoiceThreshold
-17   pascal  DOBEEP() DoBeep
+1  pascal16 OpenSound() OpenSound
+2  pascal16 CloseSound() CloseSound
+3  pascal16 SetVoiceQueueSize(word word) SetVoiceQueueSize
+4  pascal16 SetVoiceNote(word word word word) SetVoiceNote
+5  pascal16 SetVoiceAccent(word word word word word) SetVoiceAccent
+6  pascal16 SetVoiceEnvelope(word word word) SetVoiceEnvelope
+7  pascal16 SetSoundNoise(word word) SetSoundNoise
+8  pascal16 SetVoiceSound(word long word) SetVoiceSound
+9  pascal16 StartSound() StartSound
+10 pascal16 StopSound() StopSound
+11 pascal16 WaitSoundState(word) WaitSoundState
+12 pascal16 SyncAllVoices() SyncAllVoices
+13 pascal16 CountVoiceNotes(word) CountVoiceNotes
+14 pascal   GetThresholdEvent() GetThresholdEvent
+15 pascal16 GetThresholdStatus() GetThresholdStatus
+16 pascal16 SetVoiceThreshold(word word) SetVoiceThreshold
+17 pascal16 DoBeep() DoBeep
diff --git a/if1632/system.spec b/if1632/system.spec
index 4edc485..de7816e 100644
--- a/if1632/system.spec
+++ b/if1632/system.spec
@@ -7,7 +7,7 @@
 4 stub EnableSystemTimers
 5 stub DisableSystemTimers
 6 pascal GetSystemmsecCount() GetTickCount
-7 stub Get80x87SaveSize
+7 return Get80x87SaveSize 0 94
 8 stub Save80x87State
 9 stub Restore80x87State
 #20 stub A20_Proc
diff --git a/if1632/toolhelp.spec b/if1632/toolhelp.spec
index 7db2d70..1d6c2f0 100644
--- a/if1632/toolhelp.spec
+++ b/if1632/toolhelp.spec
@@ -29,8 +29,8 @@
 75 stub INTERRUPTREGISTER
 76 stub INTERRUPTUNREGISTER
 77 stub TERMINATEAPP
-78 pascal MemoryRead(word long ptr long) MemoryRead
-79 pascal MemoryWrite(word long ptr long) MemoryWrite
+78 pascal   MemoryRead(word long ptr long) MemoryRead
+79 pascal   MemoryWrite(word long ptr long) MemoryWrite
 80 stub TIMERCOUNT
 81 stub TASKSETCSIP
 82 stub TASKGETCSIP
diff --git a/if1632/user.spec b/if1632/user.spec
index f4156d4..b5512b3 100644
--- a/if1632/user.spec
+++ b/if1632/user.spec
@@ -1,424 +1,426 @@
 name	user
 id	2
 
-1   pascal MessageBox(word ptr ptr word) MessageBox
+1   pascal16 MessageBox(word ptr ptr word) MessageBox
 2   stub OldExitWindows
 3   stub EnableOEMLayer
 4   stub DisableOEMLayer
-5   pascal InitApp(word) USER_InitApp
-6   pascal PostQuitMessage(word) PostQuitMessage
-7   pascal ExitWindows(long word) ExitWindows
-10  pascal SetTimer(word word word segptr) SetTimer
-11  pascal SetSystemTimer(word word word segptr) SetSystemTimer
-12  pascal KillTimer(word word) KillTimer
-13  pascal GetTickCount() GetTickCount
-14  pascal GetTimerResolution() GetTimerResolution
-15  pascal GetCurrentTime() GetTickCount
-16  pascal ClipCursor(ptr) ClipCursor
-17  pascal GetCursorPos(ptr) GetCursorPos
-18  pascal SetCapture(word) SetCapture
-19  pascal ReleaseCapture() ReleaseCapture
-20  pascal SetDoubleClickTime(word) SetDoubleClickTime
-21  pascal GetDoubleClickTime() GetDoubleClickTime
-22  pascal SetFocus(word) SetFocus
-23  pascal GetFocus() GetFocus
+5   pascal16 InitApp(word) USER_InitApp
+6   pascal16 PostQuitMessage(word) PostQuitMessage
+7   pascal16 ExitWindows(long word) ExitWindows
+10  pascal16 SetTimer(word word word segptr) SetTimer
+11  pascal16 SetSystemTimer(word word word segptr) SetSystemTimer
+12  pascal16 KillTimer(word word) KillTimer
+13  pascal   GetTickCount() GetTickCount
+14  pascal   GetTimerResolution() GetTimerResolution
+15  pascal   GetCurrentTime() GetTickCount
+16  pascal16 ClipCursor(ptr) ClipCursor
+17  pascal16 GetCursorPos(ptr) GetCursorPos
+18  pascal16 SetCapture(word) SetCapture
+19  pascal16 ReleaseCapture() ReleaseCapture
+20  pascal16 SetDoubleClickTime(word) SetDoubleClickTime
+21  pascal16 GetDoubleClickTime() GetDoubleClickTime
+22  pascal16 SetFocus(word) SetFocus
+23  pascal16 GetFocus() GetFocus
 24  pascal16 RemoveProp(word segptr) RemoveProp
 25  pascal16 GetProp(word segptr) GetProp
 26  pascal16 SetProp(word segptr word) SetProp
 27  pascal16 EnumProps(word segptr) EnumProps
-28  pascal ClientToScreen(word ptr) ClientToScreen
-29  pascal ScreenToClient(word ptr) ScreenToClient
-30  pascal WindowFromPoint(long) WindowFromPoint
-31  pascal IsIconic(word) IsIconic
-32  pascal GetWindowRect(word ptr) GetWindowRect
-33  pascal GetClientRect(word ptr) GetClientRect
-34  pascal EnableWindow(word word) EnableWindow
-35  pascal IsWindowEnabled(word) IsWindowEnabled
-36  pascal GetWindowText(word segptr word) WIN16_GetWindowText
-37  pascal SetWindowText(word segptr) WIN16_SetWindowText
-38  pascal GetWindowTextLength(word) GetWindowTextLength
-39  pascal BeginPaint(word ptr) BeginPaint
-40  pascal EndPaint(word ptr) EndPaint
-41  pascal CreateWindow(ptr ptr long s_word s_word s_word s_word
-	                word word word segptr) CreateWindow
-42  pascal ShowWindow(word word) ShowWindow
-43  pascal CloseWindow(word) CloseWindow
-44  pascal OpenIcon(word) OpenIcon
-45  pascal BringWindowToTop(word) BringWindowToTop
-46  pascal GetParent(word) GetParent
-47  pascal IsWindow(word) IsWindow
-48  pascal IsChild(word word) IsChild
-49  pascal IsWindowVisible(word) IsWindowVisible
-50  pascal FindWindow(ptr ptr) FindWindow
+28  pascal16 ClientToScreen(word ptr) ClientToScreen
+29  pascal16 ScreenToClient(word ptr) ScreenToClient
+30  pascal16 WindowFromPoint(long) WindowFromPoint
+31  pascal16 IsIconic(word) IsIconic
+32  pascal16 GetWindowRect(word ptr) GetWindowRect
+33  pascal16 GetClientRect(word ptr) GetClientRect
+34  pascal16 EnableWindow(word word) EnableWindow
+35  pascal16 IsWindowEnabled(word) IsWindowEnabled
+36  pascal16 GetWindowText(word segptr word) WIN16_GetWindowText
+37  pascal16 SetWindowText(word segptr) WIN16_SetWindowText
+38  pascal16 GetWindowTextLength(word) GetWindowTextLength
+39  pascal16 BeginPaint(word ptr) BeginPaint
+40  pascal16 EndPaint(word ptr) EndPaint
+41  pascal16 CreateWindow(ptr ptr long s_word s_word s_word s_word
+	                  word word word segptr) CreateWindow
+42  pascal16 ShowWindow(word word) ShowWindow
+43  pascal16 CloseWindow(word) CloseWindow
+44  pascal16 OpenIcon(word) OpenIcon
+45  pascal16 BringWindowToTop(word) BringWindowToTop
+46  pascal16 GetParent(word) GetParent
+47  pascal16 IsWindow(word) IsWindow
+48  pascal16 IsChild(word word) IsChild
+49  pascal16 IsWindowVisible(word) IsWindowVisible
+50  pascal16 FindWindow(ptr ptr) FindWindow
 #51 BEAR51
-52  pascal AnyPopup() AnyPopup
-53  pascal DestroyWindow(word) DestroyWindow
-54  pascal EnumWindows(segptr long) EnumWindows
-55  pascal EnumChildWindows(word segptr long) EnumChildWindows
-56  pascal MoveWindow(word word word word word word) MoveWindow
-57  pascal RegisterClass(ptr) RegisterClass
-58  pascal GetClassName(word ptr word) GetClassName
-59  pascal SetActiveWindow(word) SetActiveWindow
-60  pascal GetActiveWindow() GetActiveWindow
-61  pascal ScrollWindow(word s_word s_word ptr ptr) ScrollWindow
-62  pascal SetScrollPos(word word s_word word) SetScrollPos
-63  pascal GetScrollPos(word word) GetScrollPos
-64  pascal SetScrollRange(word word s_word s_word word) SetScrollRange
-65  pascal GetScrollRange(word word ptr ptr) GetScrollRange
-66  pascal GetDC(word) GetDC
-67  pascal GetWindowDC(word) GetWindowDC
-68  pascal ReleaseDC(word word) ReleaseDC
-69  pascal SetCursor(word) SetCursor
-70  pascal SetCursorPos(word word) SetCursorPos
-71  pascal ShowCursor(word) ShowCursor
-72  pascal SetRect(ptr s_word s_word s_word s_word) SetRect
-73  pascal SetRectEmpty(ptr) SetRectEmpty
-74  pascal CopyRect(ptr ptr) CopyRect
-75  pascal IsRectEmpty(ptr) IsRectEmpty
-76  pascal PtInRect(ptr long) PtInRect
-77  pascal OffsetRect(ptr s_word s_word) OffsetRect
-78  pascal InflateRect(ptr s_word s_word) InflateRect
-79  pascal IntersectRect(ptr ptr ptr) IntersectRect
-80  pascal UnionRect(ptr ptr ptr) UnionRect
-81  pascal FillRect(word ptr word) FillRect
-82  pascal InvertRect(word ptr) InvertRect
-83  pascal FrameRect(word ptr word) FrameRect
-84  pascal DrawIcon(word s_word s_word word) DrawIcon
-85  pascal DrawText(word ptr s_word ptr word) DrawText
+52  pascal16 AnyPopup() AnyPopup
+53  pascal16 DestroyWindow(word) DestroyWindow
+54  pascal16 EnumWindows(segptr long) EnumWindows
+55  pascal16 EnumChildWindows(word segptr long) EnumChildWindows
+56  pascal16 MoveWindow(word word word word word word) MoveWindow
+57  pascal16 RegisterClass(ptr) RegisterClass
+58  pascal16 GetClassName(word ptr word) GetClassName
+59  pascal16 SetActiveWindow(word) SetActiveWindow
+60  pascal16 GetActiveWindow() GetActiveWindow
+61  pascal16 ScrollWindow(word s_word s_word ptr ptr) ScrollWindow
+62  pascal16 SetScrollPos(word word s_word word) SetScrollPos
+63  pascal16 GetScrollPos(word word) GetScrollPos
+64  pascal16 SetScrollRange(word word s_word s_word word) SetScrollRange
+65  pascal16 GetScrollRange(word word ptr ptr) GetScrollRange
+66  pascal16 GetDC(word) GetDC
+67  pascal16 GetWindowDC(word) GetWindowDC
+68  pascal16 ReleaseDC(word word) ReleaseDC
+69  pascal16 SetCursor(word) SetCursor
+70  pascal16 SetCursorPos(word word) SetCursorPos
+71  pascal16 ShowCursor(word) ShowCursor
+72  pascal16 SetRect(ptr s_word s_word s_word s_word) SetRect
+73  pascal16 SetRectEmpty(ptr) SetRectEmpty
+74  pascal16 CopyRect(ptr ptr) CopyRect
+75  pascal16 IsRectEmpty(ptr) IsRectEmpty
+76  pascal16 PtInRect(ptr long) PtInRect
+77  pascal16 OffsetRect(ptr s_word s_word) OffsetRect
+78  pascal16 InflateRect(ptr s_word s_word) InflateRect
+79  pascal16 IntersectRect(ptr ptr ptr) IntersectRect
+80  pascal16 UnionRect(ptr ptr ptr) UnionRect
+81  pascal16 FillRect(word ptr word) FillRect
+82  pascal16 InvertRect(word ptr) InvertRect
+83  pascal16 FrameRect(word ptr word) FrameRect
+84  pascal16 DrawIcon(word s_word s_word word) DrawIcon
+85  pascal16 DrawText(word ptr s_word ptr word) DrawText
 87  pascal16 DialogBox(word segptr word segptr) DialogBox
-88  pascal EndDialog(word s_word) EndDialog
+88  pascal16 EndDialog(word s_word) EndDialog
 89  pascal16 CreateDialog(word segptr word segptr) CreateDialog
-90  pascal IsDialogMessage(word ptr) IsDialogMessage
-91  pascal GetDlgItem(word word) GetDlgItem
-92  pascal SetDlgItemText(word word segptr) SetDlgItemText
-93  pascal GetDlgItemText(word word segptr word) GetDlgItemText
-94  pascal SetDlgItemInt(word word word word) SetDlgItemInt
-95  pascal GetDlgItemInt(word word ptr word) GetDlgItemInt
-96  pascal CheckRadioButton(word word word word) CheckRadioButton
-97  pascal CheckDlgButton(word word word) CheckDlgButton
-98  pascal IsDlgButtonChecked(word word) IsDlgButtonChecked
-99  pascal DlgDirSelect(word ptr word) DlgDirSelect
-100 pascal DlgDirList(word ptr word word word) DlgDirList
-101 pascal SendDlgItemMessage(word word word word long) SendDlgItemMessage
-102 pascal AdjustWindowRect(ptr long word) AdjustWindowRect
-103 pascal MapDialogRect(word ptr) MapDialogRect
-104 pascal MessageBeep(word) MessageBeep
-105 pascal FlashWindow(word word) FlashWindow
-106 pascal GetKeyState(word) GetKeyState
-107 pascal DefWindowProc(word word word long) DefWindowProc
-108 pascal GetMessage(segptr word word word) GetMessage
-109 pascal PeekMessage(ptr word word word word) PeekMessage
-110 pascal PostMessage(word word word long) PostMessage
-111 pascal SendMessage(word word word long) SendMessage
-112 pascal WaitMessage() WaitMessage
-113 pascal TranslateMessage(ptr) TranslateMessage
-114 pascal DispatchMessage(ptr) DispatchMessage
+90  pascal16 IsDialogMessage(word ptr) IsDialogMessage
+91  pascal16 GetDlgItem(word word) GetDlgItem
+92  pascal16 SetDlgItemText(word word segptr) SetDlgItemText
+93  pascal16 GetDlgItemText(word word segptr word) GetDlgItemText
+94  pascal16 SetDlgItemInt(word word word word) SetDlgItemInt
+95  pascal16 GetDlgItemInt(word word ptr word) GetDlgItemInt
+96  pascal16 CheckRadioButton(word word word word) CheckRadioButton
+97  pascal16 CheckDlgButton(word word word) CheckDlgButton
+98  pascal16 IsDlgButtonChecked(word word) IsDlgButtonChecked
+99  pascal16 DlgDirSelect(word ptr word) DlgDirSelect
+100 pascal16 DlgDirList(word ptr word word word) DlgDirList
+101 pascal   SendDlgItemMessage(word word word word long) SendDlgItemMessage
+102 pascal16 AdjustWindowRect(ptr long word) AdjustWindowRect
+103 pascal16 MapDialogRect(word ptr) MapDialogRect
+104 pascal16 MessageBeep(word) MessageBeep
+105 pascal16 FlashWindow(word word) FlashWindow
+106 pascal16 GetKeyState(word) GetKeyState
+107 pascal   DefWindowProc(word word word long) DefWindowProc
+108 pascal16 GetMessage(segptr word word word) GetMessage
+109 pascal16 PeekMessage(ptr word word word word) PeekMessage
+110 pascal16 PostMessage(word word word long) PostMessage
+111 pascal   SendMessage(word word word long) SendMessage
+112 pascal16 WaitMessage() WaitMessage
+113 pascal16 TranslateMessage(ptr) TranslateMessage
+114 pascal   DispatchMessage(ptr) DispatchMessage
 115 stub ReplyMessage
-116 pascal PostAppMessage(word word word long) PostAppMessage
-118 pascal RegisterWindowMessage(ptr) RegisterWindowMessage
-119 pascal GetMessagePos() GetMessagePos
-120 pascal GetMessageTime() GetMessageTime
-121 pascal SetWindowsHook(s_word segptr) SetWindowsHook
-122 pascal CallWindowProc(segptr word word word long) CallWindowProc
-123 pascal CallMsgFilter(segptr s_word) CallMsgFilter
-124 pascal UpdateWindow(word) UpdateWindow
-125 pascal InvalidateRect(word ptr word) InvalidateRect
-126 pascal InvalidateRgn(word word word) InvalidateRgn
-127 pascal ValidateRect(word ptr) ValidateRect
-128 pascal ValidateRgn(word word) ValidateRgn
-129 pascal GetClassWord(word s_word) GetClassWord
-130 pascal SetClassWord(word s_word word) SetClassWord
-131 pascal GetClassLong(word s_word) GetClassLong
-132 pascal SetClassLong(word s_word long) SetClassLong
-133 pascal GetWindowWord(word s_word) GetWindowWord
-134 pascal SetWindowWord(word s_word word) SetWindowWord
-135 pascal GetWindowLong(word s_word) GetWindowLong
-136 pascal SetWindowLong(word s_word long) SetWindowLong
-137 pascal OpenClipboard(word) OpenClipboard
-138 pascal CloseClipboard() CloseClipboard
-139 pascal EmptyClipboard() EmptyClipboard
-140 pascal GetClipboardOwner() GetClipboardOwner
-141 pascal SetClipboardData(word word) SetClipboardData
-142 pascal GetClipboardData(word) GetClipboardData
-143 pascal CountClipboardFormats() CountClipboardFormats
-144 pascal EnumClipboardFormats(word) EnumClipboardFormats
-145 pascal RegisterClipboardFormat(ptr) RegisterClipboardFormat
-146 pascal GetClipboardFormatName(word ptr s_word) GetClipboardFormatName
-147 pascal SetClipboardViewer(word) SetClipboardViewer
-148 pascal GetClipboardViewer() GetClipboardViewer
-149 pascal ChangeClipboardChain(word ptr) ChangeClipboardChain
-150 pascal LoadMenu(word segptr) LoadMenu
-151 pascal CreateMenu() CreateMenu
-152 pascal DestroyMenu(word) DestroyMenu
-153 pascal ChangeMenu(word word ptr word word) ChangeMenu
-154 pascal CheckMenuItem(word word word) CheckMenuItem
-155 pascal EnableMenuItem(word word word) EnableMenuItem
-156 pascal GetSystemMenu(word word) GetSystemMenu
-157 pascal GetMenu(word) GetMenu
-158 pascal SetMenu(word word) SetMenu
-159 pascal GetSubMenu(word word) GetSubMenu
-160 pascal DrawMenuBar(word) DrawMenuBar
-161 pascal GetMenuString(word word ptr s_word word) GetMenuString
-162 pascal HiliteMenuItem(word word word word) HiliteMenuItem
-163 pascal CreateCaret(word word word word) CreateCaret
-164 pascal DestroyCaret() DestroyCaret
-165 pascal SetCaretPos(word word) SetCaretPos
-166 pascal HideCaret(word) HideCaret
-167 pascal ShowCaret(word) ShowCaret
-168 pascal SetCaretBlinkTime(word) SetCaretBlinkTime
-169 pascal GetCaretBlinkTime() GetCaretBlinkTime
-170 pascal ArrangeIconicWindows(word) ArrangeIconicWindows
-171 pascal WinHelp(word ptr word long) WinHelp
+116 pascal16 PostAppMessage(word word word long) PostAppMessage
+118 pascal16 RegisterWindowMessage(ptr) RegisterWindowMessage
+119 pascal   GetMessagePos() GetMessagePos
+120 pascal   GetMessageTime() GetMessageTime
+121 pascal   SetWindowsHook(s_word segptr) SetWindowsHook
+122 pascal   CallWindowProc(segptr word word word long) CallWindowProc
+123 pascal16 CallMsgFilter(segptr s_word) CallMsgFilter
+124 pascal16 UpdateWindow(word) UpdateWindow
+125 pascal16 InvalidateRect(word ptr word) InvalidateRect
+126 pascal16 InvalidateRgn(word word word) InvalidateRgn
+127 pascal16 ValidateRect(word ptr) ValidateRect
+128 pascal16 ValidateRgn(word word) ValidateRgn
+129 pascal16 GetClassWord(word s_word) GetClassWord
+130 pascal16 SetClassWord(word s_word word) SetClassWord
+131 pascal   GetClassLong(word s_word) GetClassLong
+132 pascal   SetClassLong(word s_word long) SetClassLong
+133 pascal16 GetWindowWord(word s_word) GetWindowWord
+134 pascal16 SetWindowWord(word s_word word) SetWindowWord
+135 pascal   GetWindowLong(word s_word) GetWindowLong
+136 pascal   SetWindowLong(word s_word long) SetWindowLong
+137 pascal16 OpenClipboard(word) OpenClipboard
+138 pascal16 CloseClipboard() CloseClipboard
+139 pascal16 EmptyClipboard() EmptyClipboard
+140 pascal16 GetClipboardOwner() GetClipboardOwner
+141 pascal16 SetClipboardData(word word) SetClipboardData
+142 pascal16 GetClipboardData(word) GetClipboardData
+143 pascal16 CountClipboardFormats() CountClipboardFormats
+144 pascal16 EnumClipboardFormats(word) EnumClipboardFormats
+145 pascal16 RegisterClipboardFormat(ptr) RegisterClipboardFormat
+146 pascal16 GetClipboardFormatName(word ptr s_word) GetClipboardFormatName
+147 pascal16 SetClipboardViewer(word) SetClipboardViewer
+148 pascal16 GetClipboardViewer() GetClipboardViewer
+149 pascal16 ChangeClipboardChain(word ptr) ChangeClipboardChain
+150 pascal16 LoadMenu(word segptr) LoadMenu
+151 pascal16 CreateMenu() CreateMenu
+152 pascal16 DestroyMenu(word) DestroyMenu
+153 pascal16 ChangeMenu(word word ptr word word) ChangeMenu
+154 pascal16 CheckMenuItem(word word word) CheckMenuItem
+155 pascal16 EnableMenuItem(word word word) EnableMenuItem
+156 pascal16 GetSystemMenu(word word) GetSystemMenu
+157 pascal16 GetMenu(word) GetMenu
+158 pascal16 SetMenu(word word) SetMenu
+159 pascal16 GetSubMenu(word word) GetSubMenu
+160 pascal16 DrawMenuBar(word) DrawMenuBar
+161 pascal16 GetMenuString(word word ptr s_word word) GetMenuString
+162 pascal16 HiliteMenuItem(word word word word) HiliteMenuItem
+163 pascal16 CreateCaret(word word word word) CreateCaret
+164 pascal16 DestroyCaret() DestroyCaret
+165 pascal16 SetCaretPos(word word) SetCaretPos
+166 pascal16 HideCaret(word) HideCaret
+167 pascal16 ShowCaret(word) ShowCaret
+168 pascal16 SetCaretBlinkTime(word) SetCaretBlinkTime
+169 pascal16 GetCaretBlinkTime() GetCaretBlinkTime
+170 pascal16 ArrangeIconicWindows(word) ArrangeIconicWindows
+171 pascal16 WinHelp(word ptr word long) WinHelp
 172 stub SwitchToThisWindow
 173 pascal16 LoadCursor(word segptr) LoadCursor
 174 pascal16 LoadIcon(word segptr) LoadIcon
 175 pascal16 LoadBitmap(word segptr) LoadBitmap
 176 pascal16 LoadString(word word ptr s_word) LoadString
 177 pascal16 LoadAccelerators(word segptr) LoadAccelerators
-178 pascal TranslateAccelerator(word word ptr) TranslateAccelerator
-179 pascal GetSystemMetrics(word) GetSystemMetrics
-180 pascal GetSysColor(word) GetSysColor
-181 pascal SetSysColors(word ptr ptr) SetSysColors
-182 pascal KillSystemTimer(word word) KillSystemTimer
-183 pascal GetCaretPos(ptr) GetCaretPos
+178 pascal16 TranslateAccelerator(word word ptr) TranslateAccelerator
+179 pascal16 GetSystemMetrics(word) GetSystemMetrics
+180 pascal   GetSysColor(word) GetSysColor
+181 pascal16 SetSysColors(word ptr ptr) SetSysColors
+182 pascal16 KillSystemTimer(word word) KillSystemTimer
+183 pascal16 GetCaretPos(ptr) GetCaretPos
 184 stub QuerySendMessage
-185 pascal GrayString(word word ptr ptr word word word word word) GrayString
-186 pascal SwapMouseButton(word) SwapMouseButton
-187 pascal EndMenu() EndMenu
-188 pascal SetSysModalWindow(word) SetSysModalWindow
-189 pascal GetSysModalWindow() GetSysModalWindow
-190 pascal GetUpdateRect(word ptr word) GetUpdateRect
-191 pascal ChildWindowFromPoint(word long) ChildWindowFromPoint
+185 pascal16 GrayString(word word ptr ptr word word word word word) GrayString
+186 pascal16 SwapMouseButton(word) SwapMouseButton
+187 pascal16 EndMenu() EndMenu
+188 pascal16 SetSysModalWindow(word) SetSysModalWindow
+189 pascal16 GetSysModalWindow() GetSysModalWindow
+190 pascal16 GetUpdateRect(word ptr word) GetUpdateRect
+191 pascal16 ChildWindowFromPoint(word long) ChildWindowFromPoint
 192 pascal16 InSendMessage() InSendMessage
-193 pascal IsClipboardFormatAvailable(word) IsClipboardFormatAvailable
-194 pascal DlgDirSelectComboBox(word ptr word) DlgDirSelectComboBox
-195 pascal DlgDirListComboBox(word segptr word word word) DlgDirListComboBox
-196 pascal TabbedTextOut(word s_word s_word ptr s_word s_word ptr s_word)
-           TabbedTextOut
-197 pascal GetTabbedTextExtent(word ptr word word ptr) GetTabbedTextExtent
-198 pascal CascadeChildWindows(word word) CascadeChildWindows
-199 pascal TileChildWindows(word word) TileChildWindows
-200 pascal OpenComm(ptr word word) OpenComm
-201 pascal SetCommState(ptr) SetCommState
-202 pascal GetCommState(word ptr) GetCommState
-203 pascal GetCommError(word ptr) GetCommError
-204 pascal ReadComm(word ptr word) ReadComm
-205 pascal WriteComm(word ptr word) WriteComm
-206 pascal TransmitCommChar(word byte) TransmitCommChar 
-207 pascal CloseComm(word) CloseComm
-208 pascal SetCommEventMask(word word) SetCommEventMask
-209 pascal GetCommEventMask(word word) GetCommEventMask
-210 pascal SetCommBreak(word) SetCommBreak
-211 pascal ClearCommBreak(word) ClearCommBreak
-212 pascal UngetCommChar(word byte) UngetCommChar
-213 pascal BuildCommDCB(ptr ptr) BuildCommDCB
-214 pascal EscapeCommFunction(word word) EscapeCommFunction
-215 pascal FlushComm(word word) FlushComm
+193 pascal16 IsClipboardFormatAvailable(word) IsClipboardFormatAvailable
+194 pascal16 DlgDirSelectComboBox(word ptr word) DlgDirSelectComboBox
+195 pascal16 DlgDirListComboBox(word segptr word word word) DlgDirListComboBox
+196 pascal   TabbedTextOut(word s_word s_word ptr s_word s_word ptr s_word)
+             TabbedTextOut
+197 pascal   GetTabbedTextExtent(word ptr word word ptr) GetTabbedTextExtent
+198 pascal16 CascadeChildWindows(word word) CascadeChildWindows
+199 pascal16 TileChildWindows(word word) TileChildWindows
+200 pascal16 OpenComm(ptr word word) OpenComm
+201 pascal16 SetCommState(ptr) SetCommState
+202 pascal16 GetCommState(word ptr) GetCommState
+203 pascal16 GetCommError(word ptr) GetCommError
+204 pascal16 ReadComm(word ptr word) ReadComm
+205 pascal16 WriteComm(word ptr word) WriteComm
+206 pascal16 TransmitCommChar(word byte) TransmitCommChar 
+207 pascal16 CloseComm(word) CloseComm
+208 pascal   SetCommEventMask(word word) SetCommEventMask
+209 pascal16 GetCommEventMask(word word) GetCommEventMask
+210 pascal16 SetCommBreak(word) SetCommBreak
+211 pascal16 ClearCommBreak(word) ClearCommBreak
+212 pascal16 UngetCommChar(word byte) UngetCommChar
+213 pascal16 BuildCommDCB(ptr ptr) BuildCommDCB
+214 pascal   EscapeCommFunction(word word) EscapeCommFunction
+215 pascal16 FlushComm(word word) FlushComm
 #216 USERSEEUSERDO
-217 pascal LookupMenuHandle(word s_word) LookupMenuHandle
+217 pascal16 LookupMenuHandle(word s_word) LookupMenuHandle
 218 pascal16 DialogBoxIndirect(word word word segptr) DialogBoxIndirect
 219 pascal16 CreateDialogIndirect(word ptr word segptr) CreateDialogIndirect
-220 pascal LoadMenuIndirect(ptr) LoadMenuIndirect
-221 pascal ScrollDC(word s_word s_word ptr ptr word ptr) ScrollDC
+220 pascal16 LoadMenuIndirect(ptr) LoadMenuIndirect
+221 pascal16 ScrollDC(word s_word s_word ptr ptr word ptr) ScrollDC
 222 pascal16 GetKeyboardState(ptr) GetKeyboardState
 223 pascal16 SetKeyboardState(ptr) SetKeyboardState
 224 pascal16 GetWindowTask(word) GetWindowTask
-225 pascal EnumTaskWindows(word segptr long) EnumTaskWindows
+225 pascal16 EnumTaskWindows(word segptr long) EnumTaskWindows
 226 stub LockInput
-227 pascal GetNextDlgGroupItem(word word word) GetNextDlgGroupItem
-228 pascal GetNextDlgTabItem(word word word) GetNextDlgTabItem
-229 pascal GetTopWindow(word) GetTopWindow
-230 pascal GetNextWindow(word word) GetNextWindow
+227 pascal16 GetNextDlgGroupItem(word word word) GetNextDlgGroupItem
+228 pascal16 GetNextDlgTabItem(word word word) GetNextDlgTabItem
+229 pascal16 GetTopWindow(word) GetTopWindow
+230 pascal16 GetNextWindow(word word) GetNextWindow
 231 stub GetSystemDebugState
-232 pascal SetWindowPos(word word word word word word word) SetWindowPos
-233 pascal SetParent(word word) SetParent
-234 pascal UnhookWindowsHook(s_word segptr) UnhookWindowsHook
-235 pascal DefHookProc(s_word word long ptr) DefHookProc
-236 pascal GetCapture() GetCapture
-237 pascal GetUpdateRgn(word word word) GetUpdateRgn
-238 pascal ExcludeUpdateRgn(word word) ExcludeUpdateRgn
+232 pascal16 SetWindowPos(word word word word word word word) SetWindowPos
+233 pascal16 SetParent(word word) SetParent
+234 pascal16 UnhookWindowsHook(s_word segptr) UnhookWindowsHook
+235 pascal   DefHookProc(s_word word long ptr) DefHookProc
+236 pascal16 GetCapture() GetCapture
+237 pascal16 GetUpdateRgn(word word word) GetUpdateRgn
+238 pascal16 ExcludeUpdateRgn(word word) ExcludeUpdateRgn
 239 pascal16 DialogBoxParam(word segptr word segptr long) DialogBoxParam
 240 pascal16 DialogBoxIndirectParam(word word word segptr long)
              DialogBoxIndirectParam
 241 pascal16 CreateDialogParam(word segptr word segptr long) CreateDialogParam
 242 pascal16 CreateDialogIndirectParam(word ptr word segptr long)
              CreateDialogIndirectParam
-243 pascal GetDialogBaseUnits() GetDialogBaseUnits
-244 pascal EqualRect(ptr ptr) EqualRect
+243 pascal   GetDialogBaseUnits() GetDialogBaseUnits
+244 pascal16 EqualRect(ptr ptr) EqualRect
 245 stub EnableCommNotification
 246 stub ExitWindowsExec
-247 pascal GetCursor() GetCursor
-248 pascal GetOpenClipboardWindow() GetOpenClipboardWindow
-249 pascal GetAsyncKeyState(word) GetAsyncKeyState
-250 pascal GetMenuState(word word word) GetMenuState
-251 pascal SendDriverMessage(word word long long) SendDriverMessage
-252 pascal OpenDriver(ptr ptr long) OpenDriver
-253 pascal CloseDriver(word word long) CloseDriver
-254 pascal GetDriverModuleHandle(word) GetDriverModuleHandle
-255 pascal DefDriverProc(long word word long long) DefDriverProc
-256 pascal GetDriverInfo(word ptr) GetDriverInfo
-257 pascal GetNextDriver(word long) GetNextDriver
-258 pascal MapWindowPoints(word word ptr word) MapWindowPoints
+247 pascal16 GetCursor() GetCursor
+248 pascal16 GetOpenClipboardWindow() GetOpenClipboardWindow
+249 pascal16 GetAsyncKeyState(word) GetAsyncKeyState
+250 pascal16 GetMenuState(word word word) GetMenuState
+251 pascal   SendDriverMessage(word word long long) SendDriverMessage
+252 pascal16 OpenDriver(ptr ptr long) OpenDriver
+253 pascal   CloseDriver(word word long) CloseDriver
+254 pascal16 GetDriverModuleHandle(word) GetDriverModuleHandle
+255 pascal   DefDriverProc(long word word long long) DefDriverProc
+256 pascal16 GetDriverInfo(word ptr) GetDriverInfo
+257 pascal16 GetNextDriver(word long) GetNextDriver
+258 pascal16 MapWindowPoints(word word ptr word) MapWindowPoints
 259 pascal16 BeginDeferWindowPos(s_word) BeginDeferWindowPos
 260 pascal16 DeferWindowPos(word word word s_word s_word s_word s_word word)
              DeferWindowPos
 261 pascal16 EndDeferWindowPos(word) EndDeferWindowPos
-262 pascal GetWindow(word word) GetWindow
-263 pascal GetMenuItemCount(word) GetMenuItemCount
-264 pascal GetMenuItemID(word word) GetMenuItemID
+262 pascal16 GetWindow(word word) GetWindow
+263 pascal16 GetMenuItemCount(word) GetMenuItemCount
+264 pascal16 GetMenuItemID(word word) GetMenuItemID
 265 stub ShowOwnedPopups
-266 pascal SetMessageQueue(word) SetMessageQueue
-267 pascal ShowScrollBar(word word word) ShowScrollBar
-268 pascal GlobalAddAtom(ptr) GlobalAddAtom
-269 pascal GlobalDeleteAtom(word) GlobalDeleteAtom
-270 pascal GlobalFindAtom(ptr) GlobalFindAtom
-271 pascal GlobalGetAtomName(word ptr s_word) GlobalGetAtomName
-272 pascal IsZoomed(word) IsZoomed
+266 pascal16 SetMessageQueue(word) SetMessageQueue
+267 pascal16 ShowScrollBar(word word word) ShowScrollBar
+268 pascal16 GlobalAddAtom(ptr) GlobalAddAtom
+269 pascal16 GlobalDeleteAtom(word) GlobalDeleteAtom
+270 pascal16 GlobalFindAtom(ptr) GlobalFindAtom
+271 pascal16 GlobalGetAtomName(word ptr s_word) GlobalGetAtomName
+272 pascal16 IsZoomed(word) IsZoomed
 273 stub ControlPanelInfo
 274 stub GetNextQueueWindow
 275 stub RepaintScreen
 276 stub LockMyTask
-277 pascal GetDlgCtrlID(word) GetDlgCtrlID
-278 pascal GetDeskTopHwnd() GetDesktopWindow
+277 pascal16 GetDlgCtrlID(word) GetDlgCtrlID
+278 pascal16 GetDeskTopHwnd() GetDesktopWindow
 279 stub OldSetDeskPattern
 280 stub SetSystemMenu
-281 pascal GetSysColorBrush(word) GetSysColorBrush
-282 pascal SelectPalette(word word word) SelectPalette
-283 pascal RealizePalette(word) RealizePalette
+281 pascal16 GetSysColorBrush(word) GetSysColorBrush
+282 pascal16 SelectPalette(word word word) SelectPalette
+283 pascal16 RealizePalette(word) RealizePalette
 284 pascal16 GetFreeSystemResources(word) GetFreeSystemResources
 #285 BEAR285
-286 pascal GetDesktopWindow() GetDesktopWindow
-287 pascal GetLastActivePopup(word) GetLastActivePopup
-288 pascal GetMessageExtraInfo() GetMessageExtraInfo
+286 pascal16 GetDesktopWindow() GetDesktopWindow
+287 pascal16 GetLastActivePopup(word) GetLastActivePopup
+288 pascal   GetMessageExtraInfo() GetMessageExtraInfo
 #289 KEYB_EVENT
-290 pascal RedrawWindow(word ptr word word) RedrawWindow
-291 pascal SetWindowsHookEx(s_word segptr word word) SetWindowsHookEx
-292 pascal UnhookWindowsHookEx(segptr) UnhookWindowsHookEx
-293 pascal CallNextHookEx(segptr s_word word long) CallNextHookEx
+290 pascal16 RedrawWindow(word ptr word word) RedrawWindow
+291 pascal   SetWindowsHookEx(s_word segptr word word) SetWindowsHookEx
+292 pascal16 UnhookWindowsHookEx(segptr) UnhookWindowsHookEx
+293 pascal   CallNextHookEx(segptr s_word word long) CallNextHookEx
 294 stub LockWindowUpdate
 #299 MOUSE_EVENT
 #301 BOZOSLIVEHERE :-))
 #306 BEAR306
-308 pascal DefDlgProc(word word word long) DefDlgProc
+308 pascal   DefDlgProc(word word word long) DefDlgProc
+309 pascal16 GetClipCursor(ptr) GetClipCursor
 314 stub SignalProc
-319 pascal ScrollWindowEx(word s_word s_word ptr ptr word ptr word)
-           ScrollWindowEx
+319 pascal16 ScrollWindowEx(word s_word s_word ptr ptr word ptr word)
+             ScrollWindowEx
 320 stub SysErrorBox
 321 stub SetEventHook
 322 stub WinOldAppHackOMatic
 323 stub GetMessage2
-324 pascal FillWindow(word word word word) FillWindow
-325 pascal PaintRect(word word word word ptr) PaintRect
+324 pascal16 FillWindow(word word word word) FillWindow
+325 pascal16 PaintRect(word word word word ptr) PaintRect
 326 pascal16 GetControlBrush(word word word) GetControlBrush
-331 pascal EnableHardwareInput(word) EnableHardwareInput
+331 pascal16 EnableHardwareInput(word) EnableHardwareInput
 332 return UserYield 0 0
 333 stub IsUserIdle
-334 pascal GetQueueStatus(word) GetQueueStatus
-335 pascal GetInputState() GetInputState
+334 pascal   GetQueueStatus(word) GetQueueStatus
+335 pascal16 GetInputState() GetInputState
 336 stub LoadCursorIconHandler
 337 stub GetMouseEventProc
 #341 _FFFE_FARFRAME
 343 stub GetFilePortName
 356 stub LoadDIBCursorHandler
 357 stub LoadDIBIconHandler
-358 pascal IsMenu(word) IsMenu
-359 pascal GetDCEx(word word long) GetDCEx
+358 pascal16 IsMenu(word) IsMenu
+359 pascal16 GetDCEx(word word long) GetDCEx
 362 stub DCHook
 368 stub CopyIcon
 369 stub CopyCursor
-370 pascal GetWindowPlacement(word ptr) GetWindowPlacement
-371 pascal SetWindowPlacement(word ptr) SetWindowPlacement
+370 pascal16 GetWindowPlacement(word ptr) GetWindowPlacement
+371 pascal16 SetWindowPlacement(word ptr) SetWindowPlacement
 372 stub GetInternalIconHeader
-373 pascal SubtractRect(ptr ptr ptr) SubtractRect
+373 pascal16 SubtractRect(ptr ptr ptr) SubtractRect
 400 stub FinalUserInit
-402 pascal GetPriorityClipboardFormat(word ptr s_word)
-           GetPriorityClipboardFormat
-403 pascal UnregisterClass(ptr word) UnregisterClass
-404 pascal GetClassInfo(word segptr ptr) GetClassInfo
-406 pascal CreateCursor(word word word word word ptr ptr) CreateCursor
-407 pascal CreateIcon(word word word byte byte ptr ptr) CreateIcon
-408 stub CreateCursorIconIndirect
-410 pascal InsertMenu(word word word word ptr) InsertMenu
-411 pascal AppendMenu(word word word ptr) AppendMenu
-412 pascal RemoveMenu(word word word) RemoveMenu
-413 pascal DeleteMenu(word word word) DeleteMenu
-414 pascal ModifyMenu(word word word word ptr) ModifyMenu
-415 pascal CreatePopupMenu() CreatePopupMenu
-416 pascal TrackPopupMenu(word word word word word word ptr) TrackPopupMenu
-417 pascal GetMenuCheckMarkDimensions() GetMenuCheckMarkDimensions
-418 pascal SetMenuItemBitmaps(word word word word word) SetMenuItemBitmaps
-420 pascal wsprintf() windows_wsprintf
+402 pascal16 GetPriorityClipboardFormat(word ptr s_word)
+             GetPriorityClipboardFormat
+403 pascal16 UnregisterClass(ptr word) UnregisterClass
+404 pascal16 GetClassInfo(word segptr ptr) GetClassInfo
+406 pascal16 CreateCursor(word word word word word ptr ptr) CreateCursor
+407 pascal16 CreateIcon(word word word byte byte ptr ptr) CreateIcon
+408 pascal16 CreateCursorIconIndirect(word ptr ptr ptr)
+	     CreateCursorIconIndirect
+410 pascal16 InsertMenu(word word word word ptr) InsertMenu
+411 pascal16 AppendMenu(word word word ptr) AppendMenu
+412 pascal16 RemoveMenu(word word word) RemoveMenu
+413 pascal16 DeleteMenu(word word word) DeleteMenu
+414 pascal16 ModifyMenu(word word word word ptr) ModifyMenu
+415 pascal16 CreatePopupMenu() CreatePopupMenu
+416 pascal16 TrackPopupMenu(word word word word word word ptr) TrackPopupMenu
+417 pascal   GetMenuCheckMarkDimensions() GetMenuCheckMarkDimensions
+418 pascal16 SetMenuItemBitmaps(word word word word word) SetMenuItemBitmaps
+420 pascal16 wsprintf() windows_wsprintf
 # windows_wsprintf() handles arguments itself, as libc can't handle an
 # 16-bit stack. DLLRelay() will pass 16-bit stack pointer as 1st arg.
-421 pascal wvsprintf(ptr ptr ptr) wvsprintf
+421 pascal16 wvsprintf(ptr ptr ptr) wvsprintf
 422 stub DlgDirSelectEx
 423 stub DlgDirSelectComboBoxEx
 430 pascal16 lstrcmp(ptr ptr) lstrcmp
-431 pascal AnsiUpper(segptr) WIN16_AnsiUpper
-432 pascal AnsiLower(segptr) WIN16_AnsiLower
+431 pascal   AnsiUpper(segptr) WIN16_AnsiUpper
+432 pascal   AnsiLower(segptr) WIN16_AnsiLower
 433 pascal16 IsCharAlpha(byte) IsCharAlpha
 434 pascal16 IsCharAlphanumeric(byte) IsCharAlphanumeric
 435 pascal16 IsCharUpper(byte) IsCharUpper
 436 pascal16 IsCharLower(byte) IsCharLower
 437 pascal16 AnsiUpperBuff(ptr word) AnsiUpperBuff
 438 pascal16 AnsiLowerBuff(ptr word) AnsiLowerBuff
-445 pascal DefFrameProc(word word word word long) DefFrameProc
-447 pascal DefMDIChildProc(word word word long) DefMDIChildProc
-451 pascal TranslateMDISysAccel(word ptr) TranslateMDISysAccel
-452 pascal CreateWindowEx(long ptr ptr long s_word s_word s_word s_word
-                          word word word segptr) CreateWindowEx
-454 pascal AdjustWindowRectEx(ptr long word long) AdjustWindowRectEx
+445 pascal   DefFrameProc(word word word word long) DefFrameProc
+447 pascal   DefMDIChildProc(word word word long) DefMDIChildProc
+451 pascal16 TranslateMDISysAccel(word ptr) TranslateMDISysAccel
+452 pascal16 CreateWindowEx(long ptr ptr long s_word s_word s_word s_word
+                            word word word segptr) CreateWindowEx
+454 pascal16 AdjustWindowRectEx(ptr long word long) AdjustWindowRectEx
 455 stub GetIconId
 456 stub LoadIconHandler
-457 pascal DestroyIcon(word) DestroyIcon
-458 pascal DestroyCursor(word) DestroyCursor
-459 pascal DumpIcon(ptr ptr ptr ptr) DumpIcon
-460 pascal GetInternalWindowPos(word ptr ptr) GetInternalWindowPos
-461 pascal SetInternalWindowPos(word word ptr ptr) SetInternalWindowPos
-462 stub CalcChildScroll
+457 pascal16 DestroyIcon(word) DestroyIcon
+458 pascal16 DestroyCursor(word) DestroyCursor
+459 pascal   DumpIcon(ptr ptr ptr ptr) DumpIcon
+460 pascal16 GetInternalWindowPos(word ptr ptr) GetInternalWindowPos
+461 pascal16 SetInternalWindowPos(word word ptr ptr) SetInternalWindowPos
+462 pascal16 CalcChildScroll(word word) CalcChildScroll
 463 stub ScrollChildren
 464 stub DragObject
 465 stub DragDetect
-466 pascal DrawFocusRect(word ptr) DrawFocusRect
+466 pascal16 DrawFocusRect(word ptr) DrawFocusRect
 470 stub StringFunc
 471 pascal16 lstrcmpi(ptr ptr) lstrcmpi
-472 pascal AnsiNext(segptr) AnsiNext
-473 pascal AnsiPrev(segptr segptr) AnsiPrev
+472 pascal   AnsiNext(segptr) AnsiNext
+473 pascal   AnsiPrev(segptr segptr) AnsiPrev
 480 stub GetUserLocalObjType
 #481 HARDWARE_EVENT
 482 pascal16 EnableScrollBar(word word word) EnableScrollBar
-483 pascal SystemParametersInfo(word word ptr word) SystemParametersInfo
+483 pascal16 SystemParametersInfo(word word ptr word) SystemParametersInfo
 #484 __GP
-499 pascal WNetErrorText(word ptr word) WNetErrorText
-501 pascal WNetOpenJob(ptr ptr word ptr)  WNetOpenJob
-502 pascal WNetCloseJob(word ptr ptr) WNetCloseJob
-503 pascal WNetAbortJob(ptr word) WNetAbortJob
-504 pascal WNetHoldJob(ptr word) WNetHoldJob
-505 pascal WNetReleaseJob(ptr word) WNetReleaseJob
-506 pascal WNetCancelJob(ptr word) WNetCancelJob
-507 pascal WNetSetJobCopies(ptr word word) WNetSetJobCopies
-508 pascal WNetWatchQueue(word ptr ptr word) WNetWatchQueue
-509 pascal WNetUnwatchQueue(word ptr ptr word) WNetUnwatchQueue
-510 pascal WNetLockQueueData(ptr ptr ptr) WNetLockQueueData
-511 pascal WNetUnlockQueueData(ptr) WNetUnlockQueueData
+499 pascal16 WNetErrorText(word ptr word) WNetErrorText
+501 pascal16 WNetOpenJob(ptr ptr word ptr)  WNetOpenJob
+502 pascal16 WNetCloseJob(word ptr ptr) WNetCloseJob
+503 pascal16 WNetAbortJob(ptr word) WNetAbortJob
+504 pascal16 WNetHoldJob(ptr word) WNetHoldJob
+505 pascal16 WNetReleaseJob(ptr word) WNetReleaseJob
+506 pascal16 WNetCancelJob(ptr word) WNetCancelJob
+507 pascal16 WNetSetJobCopies(ptr word word) WNetSetJobCopies
+508 pascal16 WNetWatchQueue(word ptr ptr word) WNetWatchQueue
+509 pascal16 WNetUnwatchQueue(word ptr ptr word) WNetUnwatchQueue
+510 pascal16 WNetLockQueueData(ptr ptr ptr) WNetLockQueueData
+511 pascal16 WNetUnlockQueueData(ptr) WNetUnlockQueueData
 512 pascal16 WNetGetConnection(ptr ptr ptr) WNetGetConnection
-513 pascal WNetGetCaps(word) WNetGetCaps
-514 pascal WNetDeviceMode(word) WNetDeviceMode
-515 pascal WNetBrowseDialog(word word ptr) WNetBrowseDialog
-516 pascal WNetGetUser(ptr ptr ptr) WNetGetUser
+513 pascal16 WNetGetCaps(word) WNetGetCaps
+514 pascal16 WNetDeviceMode(word) WNetDeviceMode
+515 pascal16 WNetBrowseDialog(word word ptr) WNetBrowseDialog
+516 pascal16 WNetGetUser(ptr ptr ptr) WNetGetUser
 517 pascal16 WNetAddConnection(ptr ptr ptr) WNetAddConnection
 518 pascal16 WNetCancelConnection(ptr word) WNetCancelConnection
-519 pascal WNetGetError(ptr) WNetGetError
-520 pascal WNetGetErrorText(word ptr ptr) WNetGetErrorText
+519 pascal16 WNetGetError(ptr) WNetGetError
+520 pascal16 WNetGetErrorText(word ptr ptr) WNetGetErrorText
 521 stub WNetEnable
 522 stub WNetDisable
-523 pascal WNetRestoreConnection(word ptr) WNetRestoreConnection
-524 pascal WNetWriteJob(word ptr ptr) WNetWriteJob
-525 pascal WnetConnectDialog(word word) WNetConnectDialog
-526 pascal WNetDisconnectDialog(word word) WNetDisconnectDialog
-527 pascal WNetConnectionDialog(word word) WNetConnectionDialog
-528 pascal WNetViewQueueDialog(word ptr) WNetViewQueueDialog
-529 pascal WNetPropertyDialog(word word ptr word) WNetPropertyDialog
-530 pascal WNetGetDirectoryType(ptr ptr) WNetGetDirectoryType
-531 pascal WNetDirectoryNotify(word ptr word) WNetDirectoryNotify
-532 pascal WNetGetPropertyText(word word word ptr word) WNetGetPropertyText
+523 pascal16 WNetRestoreConnection(word ptr) WNetRestoreConnection
+524 pascal16 WNetWriteJob(word ptr ptr) WNetWriteJob
+525 pascal16 WnetConnectDialog(word word) WNetConnectDialog
+526 pascal16 WNetDisconnectDialog(word word) WNetDisconnectDialog
+527 pascal16 WNetConnectionDialog(word word) WNetConnectionDialog
+528 pascal16 WNetViewQueueDialog(word ptr) WNetViewQueueDialog
+529 pascal16 WNetPropertyDialog(word word ptr word) WNetPropertyDialog
+530 pascal16 WNetGetDirectoryType(ptr ptr) WNetGetDirectoryType
+531 pascal16 WNetDirectoryNotify(word ptr word) WNetDirectoryNotify
+532 pascal16 WNetGetPropertyText(word word word ptr word) WNetGetPropertyText
diff --git a/if1632/win87em.spec b/if1632/win87em.spec
index fa50432..71759fa 100644
--- a/if1632/win87em.spec
+++ b/if1632/win87em.spec
@@ -2,6 +2,6 @@
 id	4
 
 1 register _fpMath() WIN87_fpmath
-3 pascal __WinEm87Info(ptr word) WIN87_WinEm87Info
-4 pascal __WinEm87Restore(ptr word) WIN87_WinEm87Restore
-5 pascal __WinEm87Save(ptr word) WIN87_WinEm87Save
+3 pascal16 __WinEm87Info(ptr word) WIN87_WinEm87Info
+4 pascal16 __WinEm87Restore(ptr word) WIN87_WinEm87Restore
+5 pascal16 __WinEm87Save(ptr word) WIN87_WinEm87Save
diff --git a/include/cursor.h b/include/cursor.h
index a65f965..21bd322 100644
--- a/include/cursor.h
+++ b/include/cursor.h
@@ -7,6 +7,16 @@
 #ifndef __WINE_CURSOR_H
 #define __WINE_CURSOR_H
 
+
+typedef struct {
+        POINT           pntHotSpot;     /* cursor hot spot */
+        WORD            nWidth;         /* width of bitmap in pixels */
+        WORD            nHeight;
+        WORD            nWidthBytes;
+        BYTE            byPlanes;       /* number of bit planes */
+        BYTE            byBitsPix;      /* bits per pixel */
+        } CURSORICONINFO, FAR *LPCURSORICONINFO;
+
 typedef struct {
 	BYTE	Width;
 	BYTE	Reserved1;
diff --git a/include/debug.h b/include/debug.h
index 24c4730..d728531 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -3,13 +3,22 @@
 #define stddeb stdout
 #define stdnimp stdout
 
+#ifdef DEBUG_RUNTIME
+#define api_assert(name,test) if (test) ; else \
+    { \
+        fprintf(stddeb,"API assertion failed for %s: %s\n", name, #test); \
+        abort(); \
+    }
+#else
+#define api_assert(name,test) ;
+#endif
+
 /* Do not remove this line or change anything below this line */
 
 #ifdef DEBUG_NONE_EXT
 #undef DEBUG_ACCEL
 #undef DEBUG_BITBLT
 #undef DEBUG_BITMAP
-#undef DEBUG_CALLBACK
 #undef DEBUG_CARET
 #undef DEBUG_CATCH
 #undef DEBUG_CDAUDIO
@@ -34,7 +43,6 @@
 #undef DEBUG_GDI
 #undef DEBUG_GLOBAL
 #undef DEBUG_GRAPHICS
-#undef DEBUG_HEAP
 #undef DEBUG_ICON
 #undef DEBUG_INT
 #undef DEBUG_KEY
@@ -53,10 +61,10 @@
 #undef DEBUG_METAFILE
 #undef DEBUG_MIDI
 #undef DEBUG_MMIO
+#undef DEBUG_MMSYS
 #undef DEBUG_MMTIME
 #undef DEBUG_MODULE
 #undef DEBUG_MSG
-#undef DEBUG_MSGBOX
 #undef DEBUG_NONCLIENT
 #undef DEBUG_OLE
 #undef DEBUG_PALETTE
@@ -84,7 +92,6 @@
 #define DEBUG_ACCEL
 #define DEBUG_BITBLT
 #define DEBUG_BITMAP
-#define DEBUG_CALLBACK
 #define DEBUG_CARET
 #define DEBUG_CATCH
 #define DEBUG_CDAUDIO
@@ -109,7 +116,6 @@
 #define DEBUG_GDI
 #define DEBUG_GLOBAL
 #define DEBUG_GRAPHICS
-#define DEBUG_HEAP
 #define DEBUG_ICON
 #define DEBUG_INT
 #define DEBUG_KEY
@@ -128,10 +134,10 @@
 #define DEBUG_METAFILE
 #define DEBUG_MIDI
 #define DEBUG_MMIO
+#define DEBUG_MMSYS
 #define DEBUG_MMTIME
 #define DEBUG_MODULE
 #define DEBUG_MSG
-#define DEBUG_MSGBOX
 #define DEBUG_NONCLIENT
 #define DEBUG_OLE
 #define DEBUG_PALETTE
@@ -173,11 +179,6 @@
 #else
     0,
 #endif
-#ifdef DEBUG_CALLBACK
-    1,
-#else
-    0,
-#endif
 #ifdef DEBUG_CARET
     1,
 #else
@@ -298,11 +299,6 @@
 #else
     0,
 #endif
-#ifdef DEBUG_HEAP
-    1,
-#else
-    0,
-#endif
 #ifdef DEBUG_ICON
     1,
 #else
@@ -393,6 +389,11 @@
 #else
     0,
 #endif
+#ifdef DEBUG_MMSYS
+    1,
+#else
+    0,
+#endif
 #ifdef DEBUG_MMTIME
     1,
 #else
@@ -408,11 +409,6 @@
 #else
     0,
 #endif
-#ifdef DEBUG_MSGBOX
-    1,
-#else
-    0,
-#endif
 #ifdef DEBUG_NONCLIENT
     1,
 #else
@@ -565,21 +561,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_callback if(!debug_msg_enabled[3]) ; else fprintf
-#define debugging_callback debug_msg_enabled[3]
-#else
-#ifdef DEBUG_CALLBACK
-#define dprintf_callback fprintf
-#define debugging_callback 1
-#else
-#define dprintf_callback while(0) fprintf
-#define debugging_callback 0
-#endif
-#endif
-
-#ifdef DEBUG_RUNTIME
-#define dprintf_caret if(!debug_msg_enabled[4]) ; else fprintf
-#define debugging_caret debug_msg_enabled[4]
+#define dprintf_caret if(!debug_msg_enabled[3]) ; else fprintf
+#define debugging_caret debug_msg_enabled[3]
 #else
 #ifdef DEBUG_CARET
 #define dprintf_caret fprintf
@@ -591,8 +574,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_catch if(!debug_msg_enabled[5]) ; else fprintf
-#define debugging_catch debug_msg_enabled[5]
+#define dprintf_catch if(!debug_msg_enabled[4]) ; else fprintf
+#define debugging_catch debug_msg_enabled[4]
 #else
 #ifdef DEBUG_CATCH
 #define dprintf_catch fprintf
@@ -604,8 +587,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_cdaudio if(!debug_msg_enabled[6]) ; else fprintf
-#define debugging_cdaudio debug_msg_enabled[6]
+#define dprintf_cdaudio if(!debug_msg_enabled[5]) ; else fprintf
+#define debugging_cdaudio debug_msg_enabled[5]
 #else
 #ifdef DEBUG_CDAUDIO
 #define dprintf_cdaudio fprintf
@@ -617,8 +600,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_class if(!debug_msg_enabled[7]) ; else fprintf
-#define debugging_class debug_msg_enabled[7]
+#define dprintf_class if(!debug_msg_enabled[6]) ; else fprintf
+#define debugging_class debug_msg_enabled[6]
 #else
 #ifdef DEBUG_CLASS
 #define dprintf_class fprintf
@@ -630,8 +613,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_clipboard if(!debug_msg_enabled[8]) ; else fprintf
-#define debugging_clipboard debug_msg_enabled[8]
+#define dprintf_clipboard if(!debug_msg_enabled[7]) ; else fprintf
+#define debugging_clipboard debug_msg_enabled[7]
 #else
 #ifdef DEBUG_CLIPBOARD
 #define dprintf_clipboard fprintf
@@ -643,8 +626,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_clipping if(!debug_msg_enabled[9]) ; else fprintf
-#define debugging_clipping debug_msg_enabled[9]
+#define dprintf_clipping if(!debug_msg_enabled[8]) ; else fprintf
+#define debugging_clipping debug_msg_enabled[8]
 #else
 #ifdef DEBUG_CLIPPING
 #define dprintf_clipping fprintf
@@ -656,8 +639,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_combo if(!debug_msg_enabled[10]) ; else fprintf
-#define debugging_combo debug_msg_enabled[10]
+#define dprintf_combo if(!debug_msg_enabled[9]) ; else fprintf
+#define debugging_combo debug_msg_enabled[9]
 #else
 #ifdef DEBUG_COMBO
 #define dprintf_combo fprintf
@@ -669,8 +652,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_comm if(!debug_msg_enabled[11]) ; else fprintf
-#define debugging_comm debug_msg_enabled[11]
+#define dprintf_comm if(!debug_msg_enabled[10]) ; else fprintf
+#define debugging_comm debug_msg_enabled[10]
 #else
 #ifdef DEBUG_COMM
 #define dprintf_comm fprintf
@@ -682,8 +665,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_cursor if(!debug_msg_enabled[12]) ; else fprintf
-#define debugging_cursor debug_msg_enabled[12]
+#define dprintf_cursor if(!debug_msg_enabled[11]) ; else fprintf
+#define debugging_cursor debug_msg_enabled[11]
 #else
 #ifdef DEBUG_CURSOR
 #define dprintf_cursor fprintf
@@ -695,8 +678,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dc if(!debug_msg_enabled[13]) ; else fprintf
-#define debugging_dc debug_msg_enabled[13]
+#define dprintf_dc if(!debug_msg_enabled[12]) ; else fprintf
+#define debugging_dc debug_msg_enabled[12]
 #else
 #ifdef DEBUG_DC
 #define dprintf_dc fprintf
@@ -708,8 +691,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dialog if(!debug_msg_enabled[14]) ; else fprintf
-#define debugging_dialog debug_msg_enabled[14]
+#define dprintf_dialog if(!debug_msg_enabled[13]) ; else fprintf
+#define debugging_dialog debug_msg_enabled[13]
 #else
 #ifdef DEBUG_DIALOG
 #define dprintf_dialog fprintf
@@ -721,8 +704,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dll if(!debug_msg_enabled[15]) ; else fprintf
-#define debugging_dll debug_msg_enabled[15]
+#define dprintf_dll if(!debug_msg_enabled[14]) ; else fprintf
+#define debugging_dll debug_msg_enabled[14]
 #else
 #ifdef DEBUG_DLL
 #define dprintf_dll fprintf
@@ -734,8 +717,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dosfs if(!debug_msg_enabled[16]) ; else fprintf
-#define debugging_dosfs debug_msg_enabled[16]
+#define dprintf_dosfs if(!debug_msg_enabled[15]) ; else fprintf
+#define debugging_dosfs debug_msg_enabled[15]
 #else
 #ifdef DEBUG_DOSFS
 #define dprintf_dosfs fprintf
@@ -747,8 +730,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_driver if(!debug_msg_enabled[17]) ; else fprintf
-#define debugging_driver debug_msg_enabled[17]
+#define dprintf_driver if(!debug_msg_enabled[16]) ; else fprintf
+#define debugging_driver debug_msg_enabled[16]
 #else
 #ifdef DEBUG_DRIVER
 #define dprintf_driver fprintf
@@ -760,8 +743,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_edit if(!debug_msg_enabled[18]) ; else fprintf
-#define debugging_edit debug_msg_enabled[18]
+#define dprintf_edit if(!debug_msg_enabled[17]) ; else fprintf
+#define debugging_edit debug_msg_enabled[17]
 #else
 #ifdef DEBUG_EDIT
 #define dprintf_edit fprintf
@@ -773,8 +756,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_enum if(!debug_msg_enabled[19]) ; else fprintf
-#define debugging_enum debug_msg_enabled[19]
+#define dprintf_enum if(!debug_msg_enabled[18]) ; else fprintf
+#define debugging_enum debug_msg_enabled[18]
 #else
 #ifdef DEBUG_ENUM
 #define dprintf_enum fprintf
@@ -786,8 +769,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_event if(!debug_msg_enabled[20]) ; else fprintf
-#define debugging_event debug_msg_enabled[20]
+#define dprintf_event if(!debug_msg_enabled[19]) ; else fprintf
+#define debugging_event debug_msg_enabled[19]
 #else
 #ifdef DEBUG_EVENT
 #define dprintf_event fprintf
@@ -799,8 +782,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_exec if(!debug_msg_enabled[21]) ; else fprintf
-#define debugging_exec debug_msg_enabled[21]
+#define dprintf_exec if(!debug_msg_enabled[20]) ; else fprintf
+#define debugging_exec debug_msg_enabled[20]
 #else
 #ifdef DEBUG_EXEC
 #define dprintf_exec fprintf
@@ -812,8 +795,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_file if(!debug_msg_enabled[22]) ; else fprintf
-#define debugging_file debug_msg_enabled[22]
+#define dprintf_file if(!debug_msg_enabled[21]) ; else fprintf
+#define debugging_file debug_msg_enabled[21]
 #else
 #ifdef DEBUG_FILE
 #define dprintf_file fprintf
@@ -825,8 +808,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_fixup if(!debug_msg_enabled[23]) ; else fprintf
-#define debugging_fixup debug_msg_enabled[23]
+#define dprintf_fixup if(!debug_msg_enabled[22]) ; else fprintf
+#define debugging_fixup debug_msg_enabled[22]
 #else
 #ifdef DEBUG_FIXUP
 #define dprintf_fixup fprintf
@@ -838,8 +821,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_font if(!debug_msg_enabled[24]) ; else fprintf
-#define debugging_font debug_msg_enabled[24]
+#define dprintf_font if(!debug_msg_enabled[23]) ; else fprintf
+#define debugging_font debug_msg_enabled[23]
 #else
 #ifdef DEBUG_FONT
 #define dprintf_font fprintf
@@ -851,8 +834,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_gdi if(!debug_msg_enabled[25]) ; else fprintf
-#define debugging_gdi debug_msg_enabled[25]
+#define dprintf_gdi if(!debug_msg_enabled[24]) ; else fprintf
+#define debugging_gdi debug_msg_enabled[24]
 #else
 #ifdef DEBUG_GDI
 #define dprintf_gdi fprintf
@@ -864,8 +847,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_global if(!debug_msg_enabled[26]) ; else fprintf
-#define debugging_global debug_msg_enabled[26]
+#define dprintf_global if(!debug_msg_enabled[25]) ; else fprintf
+#define debugging_global debug_msg_enabled[25]
 #else
 #ifdef DEBUG_GLOBAL
 #define dprintf_global fprintf
@@ -877,8 +860,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_graphics if(!debug_msg_enabled[27]) ; else fprintf
-#define debugging_graphics debug_msg_enabled[27]
+#define dprintf_graphics if(!debug_msg_enabled[26]) ; else fprintf
+#define debugging_graphics debug_msg_enabled[26]
 #else
 #ifdef DEBUG_GRAPHICS
 #define dprintf_graphics fprintf
@@ -890,21 +873,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_heap if(!debug_msg_enabled[28]) ; else fprintf
-#define debugging_heap debug_msg_enabled[28]
-#else
-#ifdef DEBUG_HEAP
-#define dprintf_heap fprintf
-#define debugging_heap 1
-#else
-#define dprintf_heap while(0) fprintf
-#define debugging_heap 0
-#endif
-#endif
-
-#ifdef DEBUG_RUNTIME
-#define dprintf_icon if(!debug_msg_enabled[29]) ; else fprintf
-#define debugging_icon debug_msg_enabled[29]
+#define dprintf_icon if(!debug_msg_enabled[27]) ; else fprintf
+#define debugging_icon debug_msg_enabled[27]
 #else
 #ifdef DEBUG_ICON
 #define dprintf_icon fprintf
@@ -916,8 +886,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_int if(!debug_msg_enabled[30]) ; else fprintf
-#define debugging_int debug_msg_enabled[30]
+#define dprintf_int if(!debug_msg_enabled[28]) ; else fprintf
+#define debugging_int debug_msg_enabled[28]
 #else
 #ifdef DEBUG_INT
 #define dprintf_int fprintf
@@ -929,8 +899,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_key if(!debug_msg_enabled[31]) ; else fprintf
-#define debugging_key debug_msg_enabled[31]
+#define dprintf_key if(!debug_msg_enabled[29]) ; else fprintf
+#define debugging_key debug_msg_enabled[29]
 #else
 #ifdef DEBUG_KEY
 #define dprintf_key fprintf
@@ -942,8 +912,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_keyboard if(!debug_msg_enabled[32]) ; else fprintf
-#define debugging_keyboard debug_msg_enabled[32]
+#define dprintf_keyboard if(!debug_msg_enabled[30]) ; else fprintf
+#define debugging_keyboard debug_msg_enabled[30]
 #else
 #ifdef DEBUG_KEYBOARD
 #define dprintf_keyboard fprintf
@@ -955,8 +925,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ldt if(!debug_msg_enabled[33]) ; else fprintf
-#define debugging_ldt debug_msg_enabled[33]
+#define dprintf_ldt if(!debug_msg_enabled[31]) ; else fprintf
+#define debugging_ldt debug_msg_enabled[31]
 #else
 #ifdef DEBUG_LDT
 #define dprintf_ldt fprintf
@@ -968,8 +938,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_listbox if(!debug_msg_enabled[34]) ; else fprintf
-#define debugging_listbox debug_msg_enabled[34]
+#define dprintf_listbox if(!debug_msg_enabled[32]) ; else fprintf
+#define debugging_listbox debug_msg_enabled[32]
 #else
 #ifdef DEBUG_LISTBOX
 #define dprintf_listbox fprintf
@@ -981,8 +951,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_local if(!debug_msg_enabled[35]) ; else fprintf
-#define debugging_local debug_msg_enabled[35]
+#define dprintf_local if(!debug_msg_enabled[33]) ; else fprintf
+#define debugging_local debug_msg_enabled[33]
 #else
 #ifdef DEBUG_LOCAL
 #define dprintf_local fprintf
@@ -994,8 +964,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_malloc if(!debug_msg_enabled[36]) ; else fprintf
-#define debugging_malloc debug_msg_enabled[36]
+#define dprintf_malloc if(!debug_msg_enabled[34]) ; else fprintf
+#define debugging_malloc debug_msg_enabled[34]
 #else
 #ifdef DEBUG_MALLOC
 #define dprintf_malloc fprintf
@@ -1007,8 +977,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mci if(!debug_msg_enabled[37]) ; else fprintf
-#define debugging_mci debug_msg_enabled[37]
+#define dprintf_mci if(!debug_msg_enabled[35]) ; else fprintf
+#define debugging_mci debug_msg_enabled[35]
 #else
 #ifdef DEBUG_MCI
 #define dprintf_mci fprintf
@@ -1020,8 +990,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mcianim if(!debug_msg_enabled[38]) ; else fprintf
-#define debugging_mcianim debug_msg_enabled[38]
+#define dprintf_mcianim if(!debug_msg_enabled[36]) ; else fprintf
+#define debugging_mcianim debug_msg_enabled[36]
 #else
 #ifdef DEBUG_MCIANIM
 #define dprintf_mcianim fprintf
@@ -1033,8 +1003,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mciwave if(!debug_msg_enabled[39]) ; else fprintf
-#define debugging_mciwave debug_msg_enabled[39]
+#define dprintf_mciwave if(!debug_msg_enabled[37]) ; else fprintf
+#define debugging_mciwave debug_msg_enabled[37]
 #else
 #ifdef DEBUG_MCIWAVE
 #define dprintf_mciwave fprintf
@@ -1046,8 +1016,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mdi if(!debug_msg_enabled[40]) ; else fprintf
-#define debugging_mdi debug_msg_enabled[40]
+#define dprintf_mdi if(!debug_msg_enabled[38]) ; else fprintf
+#define debugging_mdi debug_msg_enabled[38]
 #else
 #ifdef DEBUG_MDI
 #define dprintf_mdi fprintf
@@ -1059,8 +1029,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_menu if(!debug_msg_enabled[41]) ; else fprintf
-#define debugging_menu debug_msg_enabled[41]
+#define dprintf_menu if(!debug_msg_enabled[39]) ; else fprintf
+#define debugging_menu debug_msg_enabled[39]
 #else
 #ifdef DEBUG_MENU
 #define dprintf_menu fprintf
@@ -1072,8 +1042,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_menucalc if(!debug_msg_enabled[42]) ; else fprintf
-#define debugging_menucalc debug_msg_enabled[42]
+#define dprintf_menucalc if(!debug_msg_enabled[40]) ; else fprintf
+#define debugging_menucalc debug_msg_enabled[40]
 #else
 #ifdef DEBUG_MENUCALC
 #define dprintf_menucalc fprintf
@@ -1085,8 +1055,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_message if(!debug_msg_enabled[43]) ; else fprintf
-#define debugging_message debug_msg_enabled[43]
+#define dprintf_message if(!debug_msg_enabled[41]) ; else fprintf
+#define debugging_message debug_msg_enabled[41]
 #else
 #ifdef DEBUG_MESSAGE
 #define dprintf_message fprintf
@@ -1098,8 +1068,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_metafile if(!debug_msg_enabled[44]) ; else fprintf
-#define debugging_metafile debug_msg_enabled[44]
+#define dprintf_metafile if(!debug_msg_enabled[42]) ; else fprintf
+#define debugging_metafile debug_msg_enabled[42]
 #else
 #ifdef DEBUG_METAFILE
 #define dprintf_metafile fprintf
@@ -1111,8 +1081,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_midi if(!debug_msg_enabled[45]) ; else fprintf
-#define debugging_midi debug_msg_enabled[45]
+#define dprintf_midi if(!debug_msg_enabled[43]) ; else fprintf
+#define debugging_midi debug_msg_enabled[43]
 #else
 #ifdef DEBUG_MIDI
 #define dprintf_midi fprintf
@@ -1124,8 +1094,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmio if(!debug_msg_enabled[46]) ; else fprintf
-#define debugging_mmio debug_msg_enabled[46]
+#define dprintf_mmio if(!debug_msg_enabled[44]) ; else fprintf
+#define debugging_mmio debug_msg_enabled[44]
 #else
 #ifdef DEBUG_MMIO
 #define dprintf_mmio fprintf
@@ -1137,8 +1107,21 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmtime if(!debug_msg_enabled[47]) ; else fprintf
-#define debugging_mmtime debug_msg_enabled[47]
+#define dprintf_mmsys if(!debug_msg_enabled[45]) ; else fprintf
+#define debugging_mmsys debug_msg_enabled[45]
+#else
+#ifdef DEBUG_MMSYS
+#define dprintf_mmsys fprintf
+#define debugging_mmsys 1
+#else
+#define dprintf_mmsys while(0) fprintf
+#define debugging_mmsys 0
+#endif
+#endif
+
+#ifdef DEBUG_RUNTIME
+#define dprintf_mmtime if(!debug_msg_enabled[46]) ; else fprintf
+#define debugging_mmtime debug_msg_enabled[46]
 #else
 #ifdef DEBUG_MMTIME
 #define dprintf_mmtime fprintf
@@ -1150,8 +1133,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_module if(!debug_msg_enabled[48]) ; else fprintf
-#define debugging_module debug_msg_enabled[48]
+#define dprintf_module if(!debug_msg_enabled[47]) ; else fprintf
+#define debugging_module debug_msg_enabled[47]
 #else
 #ifdef DEBUG_MODULE
 #define dprintf_module fprintf
@@ -1163,8 +1146,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_msg if(!debug_msg_enabled[49]) ; else fprintf
-#define debugging_msg debug_msg_enabled[49]
+#define dprintf_msg if(!debug_msg_enabled[48]) ; else fprintf
+#define debugging_msg debug_msg_enabled[48]
 #else
 #ifdef DEBUG_MSG
 #define dprintf_msg fprintf
@@ -1176,21 +1159,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_msgbox if(!debug_msg_enabled[50]) ; else fprintf
-#define debugging_msgbox debug_msg_enabled[50]
-#else
-#ifdef DEBUG_MSGBOX
-#define dprintf_msgbox fprintf
-#define debugging_msgbox 1
-#else
-#define dprintf_msgbox while(0) fprintf
-#define debugging_msgbox 0
-#endif
-#endif
-
-#ifdef DEBUG_RUNTIME
-#define dprintf_nonclient if(!debug_msg_enabled[51]) ; else fprintf
-#define debugging_nonclient debug_msg_enabled[51]
+#define dprintf_nonclient if(!debug_msg_enabled[49]) ; else fprintf
+#define debugging_nonclient debug_msg_enabled[49]
 #else
 #ifdef DEBUG_NONCLIENT
 #define dprintf_nonclient fprintf
@@ -1202,8 +1172,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ole if(!debug_msg_enabled[52]) ; else fprintf
-#define debugging_ole debug_msg_enabled[52]
+#define dprintf_ole if(!debug_msg_enabled[50]) ; else fprintf
+#define debugging_ole debug_msg_enabled[50]
 #else
 #ifdef DEBUG_OLE
 #define dprintf_ole fprintf
@@ -1215,8 +1185,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_palette if(!debug_msg_enabled[53]) ; else fprintf
-#define debugging_palette debug_msg_enabled[53]
+#define dprintf_palette if(!debug_msg_enabled[51]) ; else fprintf
+#define debugging_palette debug_msg_enabled[51]
 #else
 #ifdef DEBUG_PALETTE
 #define dprintf_palette fprintf
@@ -1228,8 +1198,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_profile if(!debug_msg_enabled[54]) ; else fprintf
-#define debugging_profile debug_msg_enabled[54]
+#define dprintf_profile if(!debug_msg_enabled[52]) ; else fprintf
+#define debugging_profile debug_msg_enabled[52]
 #else
 #ifdef DEBUG_PROFILE
 #define dprintf_profile fprintf
@@ -1241,8 +1211,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_prop if(!debug_msg_enabled[55]) ; else fprintf
-#define debugging_prop debug_msg_enabled[55]
+#define dprintf_prop if(!debug_msg_enabled[53]) ; else fprintf
+#define debugging_prop debug_msg_enabled[53]
 #else
 #ifdef DEBUG_PROP
 #define dprintf_prop fprintf
@@ -1254,8 +1224,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_reg if(!debug_msg_enabled[56]) ; else fprintf
-#define debugging_reg debug_msg_enabled[56]
+#define dprintf_reg if(!debug_msg_enabled[54]) ; else fprintf
+#define debugging_reg debug_msg_enabled[54]
 #else
 #ifdef DEBUG_REG
 #define dprintf_reg fprintf
@@ -1267,8 +1237,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_region if(!debug_msg_enabled[57]) ; else fprintf
-#define debugging_region debug_msg_enabled[57]
+#define dprintf_region if(!debug_msg_enabled[55]) ; else fprintf
+#define debugging_region debug_msg_enabled[55]
 #else
 #ifdef DEBUG_REGION
 #define dprintf_region fprintf
@@ -1280,8 +1250,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_relay if(!debug_msg_enabled[58]) ; else fprintf
-#define debugging_relay debug_msg_enabled[58]
+#define dprintf_relay if(!debug_msg_enabled[56]) ; else fprintf
+#define debugging_relay debug_msg_enabled[56]
 #else
 #ifdef DEBUG_RELAY
 #define dprintf_relay fprintf
@@ -1293,8 +1263,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_resource if(!debug_msg_enabled[59]) ; else fprintf
-#define debugging_resource debug_msg_enabled[59]
+#define dprintf_resource if(!debug_msg_enabled[57]) ; else fprintf
+#define debugging_resource debug_msg_enabled[57]
 #else
 #ifdef DEBUG_RESOURCE
 #define dprintf_resource fprintf
@@ -1306,8 +1276,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_scroll if(!debug_msg_enabled[60]) ; else fprintf
-#define debugging_scroll debug_msg_enabled[60]
+#define dprintf_scroll if(!debug_msg_enabled[58]) ; else fprintf
+#define debugging_scroll debug_msg_enabled[58]
 #else
 #ifdef DEBUG_SCROLL
 #define dprintf_scroll fprintf
@@ -1319,8 +1289,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_selector if(!debug_msg_enabled[61]) ; else fprintf
-#define debugging_selector debug_msg_enabled[61]
+#define dprintf_selector if(!debug_msg_enabled[59]) ; else fprintf
+#define debugging_selector debug_msg_enabled[59]
 #else
 #ifdef DEBUG_SELECTOR
 #define dprintf_selector fprintf
@@ -1332,8 +1302,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_selectors if(!debug_msg_enabled[62]) ; else fprintf
-#define debugging_selectors debug_msg_enabled[62]
+#define dprintf_selectors if(!debug_msg_enabled[60]) ; else fprintf
+#define debugging_selectors debug_msg_enabled[60]
 #else
 #ifdef DEBUG_SELECTORS
 #define dprintf_selectors fprintf
@@ -1345,8 +1315,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_stress if(!debug_msg_enabled[63]) ; else fprintf
-#define debugging_stress debug_msg_enabled[63]
+#define dprintf_stress if(!debug_msg_enabled[61]) ; else fprintf
+#define debugging_stress debug_msg_enabled[61]
 #else
 #ifdef DEBUG_STRESS
 #define dprintf_stress fprintf
@@ -1358,8 +1328,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_syscolor if(!debug_msg_enabled[64]) ; else fprintf
-#define debugging_syscolor debug_msg_enabled[64]
+#define dprintf_syscolor if(!debug_msg_enabled[62]) ; else fprintf
+#define debugging_syscolor debug_msg_enabled[62]
 #else
 #ifdef DEBUG_SYSCOLOR
 #define dprintf_syscolor fprintf
@@ -1371,8 +1341,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_task if(!debug_msg_enabled[65]) ; else fprintf
-#define debugging_task debug_msg_enabled[65]
+#define dprintf_task if(!debug_msg_enabled[63]) ; else fprintf
+#define debugging_task debug_msg_enabled[63]
 #else
 #ifdef DEBUG_TASK
 #define dprintf_task fprintf
@@ -1384,8 +1354,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_text if(!debug_msg_enabled[66]) ; else fprintf
-#define debugging_text debug_msg_enabled[66]
+#define dprintf_text if(!debug_msg_enabled[64]) ; else fprintf
+#define debugging_text debug_msg_enabled[64]
 #else
 #ifdef DEBUG_TEXT
 #define dprintf_text fprintf
@@ -1397,8 +1367,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_timer if(!debug_msg_enabled[67]) ; else fprintf
-#define debugging_timer debug_msg_enabled[67]
+#define dprintf_timer if(!debug_msg_enabled[65]) ; else fprintf
+#define debugging_timer debug_msg_enabled[65]
 #else
 #ifdef DEBUG_TIMER
 #define dprintf_timer fprintf
@@ -1410,8 +1380,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_toolhelp if(!debug_msg_enabled[68]) ; else fprintf
-#define debugging_toolhelp debug_msg_enabled[68]
+#define dprintf_toolhelp if(!debug_msg_enabled[66]) ; else fprintf
+#define debugging_toolhelp debug_msg_enabled[66]
 #else
 #ifdef DEBUG_TOOLHELP
 #define dprintf_toolhelp fprintf
@@ -1423,8 +1393,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_utility if(!debug_msg_enabled[69]) ; else fprintf
-#define debugging_utility debug_msg_enabled[69]
+#define dprintf_utility if(!debug_msg_enabled[67]) ; else fprintf
+#define debugging_utility debug_msg_enabled[67]
 #else
 #ifdef DEBUG_UTILITY
 #define dprintf_utility fprintf
@@ -1436,8 +1406,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win if(!debug_msg_enabled[70]) ; else fprintf
-#define debugging_win debug_msg_enabled[70]
+#define dprintf_win if(!debug_msg_enabled[68]) ; else fprintf
+#define debugging_win debug_msg_enabled[68]
 #else
 #ifdef DEBUG_WIN
 #define dprintf_win fprintf
@@ -1449,8 +1419,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_winsock if(!debug_msg_enabled[71]) ; else fprintf
-#define debugging_winsock debug_msg_enabled[71]
+#define dprintf_winsock if(!debug_msg_enabled[69]) ; else fprintf
+#define debugging_winsock debug_msg_enabled[69]
 #else
 #ifdef DEBUG_WINSOCK
 #define dprintf_winsock fprintf
@@ -1468,7 +1438,6 @@
     "accel",
     "bitblt",
     "bitmap",
-    "callback",
     "caret",
     "catch",
     "cdaudio",
@@ -1493,7 +1462,6 @@
     "gdi",
     "global",
     "graphics",
-    "heap",
     "icon",
     "int",
     "key",
@@ -1512,10 +1480,10 @@
     "metafile",
     "midi",
     "mmio",
+    "mmsys",
     "mmtime",
     "module",
     "msg",
-    "msgbox",
     "nonclient",
     "ole",
     "palette",
diff --git a/include/driver.h b/include/driver.h
index efc1f0b..be62981 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -46,7 +46,7 @@
 	} DRIVERINFOSTRUCT;
 typedef DRIVERINFOSTRUCT FAR* LPDRIVERINFOSTRUCT;
 
-typedef LRESULT (CALLBACK* DRIVERPROC)(DWORD, HDRVR, UINT, LPARAM, LPARAM);
+typedef LONG (CALLBACK* DRIVERPROC)(DWORD, HDRVR, UINT, LPARAM, LPARAM);
 
 typedef struct {
 	DRIVERINFOSTRUCT dis;
@@ -59,12 +59,12 @@
 
 LRESULT DefDriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2);
-HDRVR   WINAPI OpenDriver(LPSTR szDriverName, LPSTR szSectionName, LPARAM lParam2);
-LRESULT WINAPI CloseDriver(HDRVR hDriver, LPARAM lParam1, LPARAM lParam2);
-LRESULT WINAPI SendDriverMessage(HDRVR hDriver, WORD message, LPARAM lParam1, LPARAM lParam2);
-HINSTANCE WINAPI GetDriverModuleHandle(HDRVR hDriver);
-HDRVR   WINAPI GetNextDriver(HDRVR, DWORD);
-BOOL    WINAPI GetDriverInfo(HDRVR, DRIVERINFOSTRUCT FAR*);
+HDRVR   OpenDriver(LPSTR szDriverName, LPSTR szSectionName, LPARAM lParam2);
+LRESULT CloseDriver(HDRVR hDriver, LPARAM lParam1, LPARAM lParam2);
+LRESULT SendDriverMessage(HDRVR hDriver, WORD message, LPARAM lParam1, LPARAM lParam2);
+HINSTANCE GetDriverModuleHandle(HDRVR hDriver);
+HDRVR   GetNextDriver(HDRVR, DWORD);
+BOOL    GetDriverInfo(HDRVR, DRIVERINFOSTRUCT FAR*);
 
 
 
diff --git a/include/ldt.h b/include/ldt.h
index db9d37f..5ee3fb9 100644
--- a/include/ldt.h
+++ b/include/ldt.h
@@ -26,8 +26,10 @@
     enum seg_type type;            /* segment type */
 } ldt_entry;
 
+extern void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content);
+extern void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content);
 extern int LDT_GetEntry( int entry, ldt_entry *content );
-extern int LDT_SetEntry( int entry, ldt_entry *content );
+extern int LDT_SetEntry( int entry, const ldt_entry *content );
 extern void LDT_Print();
 
 
@@ -57,6 +59,17 @@
            ((void*)(GET_SEL_BASE((int)(ptr) >> 16) + ((int)(ptr) & 0xffff)))
 
 #define PTR_SEG_OFF_TO_LIN(seg,off) \
-           ((void*)(GET_SEL_BASE(seg) + ((int)(off) & 0xffff)))
+           ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
+
+
+extern unsigned char ldt_flags_copy[LDT_SIZE];
+
+#define LDT_FLAGS_TYPE      0x03  /* Mask for segment type */
+#define LDT_FLAGS_READONLY  0x04  /* Segment is read-only (data) */
+#define LDT_FLAGS_EXECONLY  0x04  /* Segment is execute-only (code) */
+#define LDT_FLAGS_32BIT     0x08  /* Segment is 32-bit (code or stack) */
+#define LDT_FLAGS_BIG       0x10  /* Segment is big (limit is in pages) */
+
+#define GET_SEL_FLAGS(sel)   (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
 
 #endif  /* _WINE_LDT_H */
diff --git a/include/local.h b/include/local.h
index a676a13..de58d4f 100644
--- a/include/local.h
+++ b/include/local.h
@@ -20,5 +20,7 @@
 extern WORD LOCAL_Size( WORD ds, HLOCAL handle );
 extern WORD LOCAL_Flags( WORD ds, HLOCAL handle );
 extern WORD LOCAL_HeapSize( WORD ds );
+extern WORD LOCAL_Lock( WORD ds, HLOCAL handle );
+extern BOOL LOCAL_Unlock( WORD ds, HLOCAL handle );
 
 #endif  /* __WINE_LOCAL_H */
diff --git a/include/mdi.h b/include/mdi.h
index 73ebb4d..6891c3d 100644
--- a/include/mdi.h
+++ b/include/mdi.h
@@ -15,24 +15,24 @@
 			     WORD wParam, LONG lParam); /* mdi.c */
 
 
-typedef struct mdi_child_info_s
+typedef struct
 {
-    struct mdi_child_info_s *next, *prev;
+    HLOCAL next, prev;
     HWND hwnd;
 } MDICHILDINFO;
 
 typedef struct 
 {
-    HMENU         hWindowMenu;
-    MDICHILDINFO *infoActiveChildren;
-    WORD          nActiveChildren;
-    WORD          idFirstChild;
-    HWND          hwndActiveChild;
-    HWND	  hwndHitTest;
-    BOOL          flagMenuAltered;
-    BOOL          flagChildMaximized;
-    RECT          rectMaximize;
-    RECT          rectRestore;
+    HMENU  hWindowMenu;
+    HLOCAL infoActiveChildren;
+    WORD   nActiveChildren;
+    WORD   idFirstChild;
+    HWND   hwndActiveChild;
+    HWND   hwndHitTest;
+    BOOL   flagMenuAltered;
+    BOOL   flagChildMaximized;
+    RECT   rectMaximize;
+    RECT   rectRestore;
 } MDICLIENTINFO;
 
 #endif /* MDI_H */
diff --git a/include/miscemu.h b/include/miscemu.h
index 4f8b378..e979ff1 100644
--- a/include/miscemu.h
+++ b/include/miscemu.h
@@ -4,6 +4,8 @@
 #include "wintypes.h"
 #include "wine.h"
 
+extern BOOL INSTR_HandleInstruction( struct sigcontext_struct *context );
+
 extern int do_int10(struct sigcontext_struct *);
 extern int do_int13(struct sigcontext_struct *);
 extern int do_int15(struct sigcontext_struct *);
@@ -17,14 +19,14 @@
 extern int do_int31(struct sigcontext_struct *);
 extern int do_int5c(struct sigcontext_struct *);
 
-extern void inportb(struct sigcontext_struct *context);
-extern void inport(struct sigcontext_struct *context);
-extern void outportb(struct sigcontext_struct *context);
-extern void outport(struct sigcontext_struct *context);
-extern void inportb_abs(struct sigcontext_struct *context);
-extern void inport_abs(struct sigcontext_struct *context);
-extern void outportb_abs(struct sigcontext_struct *context);
-extern void outport_abs(struct sigcontext_struct *context);
+extern void inportb( struct sigcontext_struct *context );
+extern void inport( struct sigcontext_struct *context, int long_op );
+extern void outportb( struct sigcontext_struct *context );
+extern void outport( struct sigcontext_struct *context, int long_op );
+extern void inportb_abs( struct sigcontext_struct *context);
+extern void inport_abs( struct sigcontext_struct *context, int long_op );
+extern void outportb_abs( struct sigcontext_struct *context );
+extern void outport_abs( struct sigcontext_struct *context, int long_op );
 
 extern void IntBarf(int i, struct sigcontext_struct *context);
 
diff --git a/include/mmsystem.h b/include/mmsystem.h
index 3607e5c..0357103 100644
--- a/include/mmsystem.h
+++ b/include/mmsystem.h
@@ -132,10 +132,10 @@
 #define MM_PC_JOYSTICK          12      /* Joystick adapter */
 
 
-WORD WINAPI mmsystemGetVersion(void);
-void WINAPI OutputDebugStr(LPCSTR);
+WORD mmsystemGetVersion(void);
+void OutputDebugStr(LPCSTR);
 
-BOOL WINAPI sndPlaySound(LPCSTR lpszSoundName, UINT uFlags);
+BOOL sndPlaySound(LPCSTR lpszSoundName, UINT uFlags);
 
 #define SND_SYNC            0x0000  /* play synchronously (default) */
 #define SND_ASYNC           0x0001  /* play asynchronously */
@@ -248,57 +248,57 @@
 } PCMWAVEFORMAT;
 typedef PCMWAVEFORMAT FAR  *LPPCMWAVEFORMAT;
 
-UINT WINAPI waveOutGetNumDevs(void);
-UINT WINAPI waveOutGetDevCaps(UINT uDeviceID, WAVEOUTCAPS FAR* lpCaps,
+UINT waveOutGetNumDevs(void);
+UINT waveOutGetDevCaps(UINT uDeviceID, WAVEOUTCAPS FAR* lpCaps,
     UINT uSize);
-UINT WINAPI waveOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume);
-UINT WINAPI waveOutSetVolume(UINT uDeviceID, DWORD dwVolume);
-UINT WINAPI waveOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT WINAPI waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT WINAPI waveOutOpen(HWAVEOUT FAR* lphWaveOut, UINT uDeviceID,
+UINT waveOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume);
+UINT waveOutSetVolume(UINT uDeviceID, DWORD dwVolume);
+UINT waveOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+UINT waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+UINT waveOutOpen(HWAVEOUT FAR* lphWaveOut, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT WINAPI waveOutClose(HWAVEOUT hWaveOut);
-UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutClose(HWAVEOUT hWaveOut);
+UINT waveOutPrepareHeader(HWAVEOUT hWaveOut,
      WAVEHDR FAR* lpWaveOutHdr, UINT uSize);
-UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutUnprepareHeader(HWAVEOUT hWaveOut,
     WAVEHDR FAR* lpWaveOutHdr, UINT uSize);
-UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR FAR* lpWaveOutHdr,
+UINT waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR FAR* lpWaveOutHdr,
     UINT uSize);
-UINT WINAPI waveOutPause(HWAVEOUT hWaveOut);
-UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut);
-UINT WINAPI waveOutReset(HWAVEOUT hWaveOut);
-UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut);
-UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, MMTIME FAR* lpInfo,
+UINT waveOutPause(HWAVEOUT hWaveOut);
+UINT waveOutRestart(HWAVEOUT hWaveOut);
+UINT waveOutReset(HWAVEOUT hWaveOut);
+UINT waveOutBreakLoop(HWAVEOUT hWaveOut);
+UINT waveOutGetPosition(HWAVEOUT hWaveOut, MMTIME FAR* lpInfo,
     UINT uSize);
-UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, DWORD FAR* lpdwPitch);
-UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dwPitch);
-UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, DWORD FAR* lpdwRate);
-UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dwRate);
-UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT FAR* lpuDeviceID);
+UINT waveOutGetPitch(HWAVEOUT hWaveOut, DWORD FAR* lpdwPitch);
+UINT waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dwPitch);
+UINT waveOutGetPlaybackRate(HWAVEOUT hWaveOut, DWORD FAR* lpdwRate);
+UINT waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dwRate);
+UINT waveOutGetID(HWAVEOUT hWaveOut, UINT FAR* lpuDeviceID);
 
-DWORD WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, DWORD dw1, DWORD dw2);
 
-UINT WINAPI waveInGetNumDevs(void);
-UINT WINAPI waveInGetDevCaps(UINT uDeviceID, WAVEINCAPS FAR* lpCaps,
+UINT waveInGetNumDevs(void);
+UINT waveInGetDevCaps(UINT uDeviceID, WAVEINCAPS FAR* lpCaps,
     UINT uSize);
-UINT WINAPI waveInGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT WINAPI waveInOpen(HWAVEIN FAR* lphWaveIn, UINT uDeviceID,
+UINT waveInGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+UINT waveInOpen(HWAVEIN FAR* lphWaveIn, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT WINAPI waveInClose(HWAVEIN hWaveIn);
-UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn,
+UINT waveInClose(HWAVEIN hWaveIn);
+UINT waveInPrepareHeader(HWAVEIN hWaveIn,
     WAVEHDR FAR* lpWaveInHdr, UINT uSize);
-UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn,
+UINT waveInUnprepareHeader(HWAVEIN hWaveIn,
     WAVEHDR FAR* lpWaveInHdr, UINT uSize);
-UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
+UINT waveInAddBuffer(HWAVEIN hWaveIn,
     WAVEHDR FAR* lpWaveInHdr, UINT uSize);
-UINT WINAPI waveInStart(HWAVEIN hWaveIn);
-UINT WINAPI waveInStop(HWAVEIN hWaveIn);
-UINT WINAPI waveInReset(HWAVEIN hWaveIn);
-UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, MMTIME FAR* lpInfo,
+UINT waveInStart(HWAVEIN hWaveIn);
+UINT waveInStop(HWAVEIN hWaveIn);
+UINT waveInReset(HWAVEIN hWaveIn);
+UINT waveInGetPosition(HWAVEIN hWaveIn, MMTIME FAR* lpInfo,
     UINT uSize);
-UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT FAR* lpuDeviceID);
+UINT waveInGetID(HWAVEIN hWaveIn, UINT FAR* lpuDeviceID);
 
-DWORD WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD waveInMessage(HWAVEIN hWaveIn, UINT uMessage, DWORD dw1, DWORD dw2);
 
 #define MIDIERR_UNPREPARED    (MIDIERR_BASE + 0)   /* header not prepared */
 #define MIDIERR_STILLPLAYING  (MIDIERR_BASE + 1)   /* still something playing */
@@ -388,51 +388,51 @@
 #define MHDR_PREPARED   0x00000002       /* set if header prepared */
 #define MHDR_INQUEUE    0x00000004       /* reserved for driver */
 
-UINT WINAPI midiOutGetNumDevs(void);
-UINT WINAPI midiOutGetDevCaps(UINT uDeviceID,
+UINT midiOutGetNumDevs(void);
+UINT midiOutGetDevCaps(UINT uDeviceID,
     MIDIOUTCAPS FAR* lpCaps, UINT uSize);
-UINT WINAPI midiOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume);
-UINT WINAPI midiOutSetVolume(UINT uDeviceID, DWORD dwVolume);
-UINT WINAPI midiOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT WINAPI midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT WINAPI midiOutOpen(HMIDIOUT FAR* lphMidiOut, UINT uDeviceID,
+UINT midiOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume);
+UINT midiOutSetVolume(UINT uDeviceID, DWORD dwVolume);
+UINT midiOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+UINT midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+UINT midiOutOpen(HMIDIOUT FAR* lphMidiOut, UINT uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT WINAPI midiOutClose(HMIDIOUT hMidiOut);
-UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutClose(HMIDIOUT hMidiOut);
+UINT midiOutPrepareHeader(HMIDIOUT hMidiOut,
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize);
-UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutUnprepareHeader(HMIDIOUT hMidiOut,
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize);
-UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg);
-UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
+UINT midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg);
+UINT midiOutLongMsg(HMIDIOUT hMidiOut,
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize);
-UINT WINAPI midiOutReset(HMIDIOUT hMidiOut);
-UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut,
+UINT midiOutReset(HMIDIOUT hMidiOut);
+UINT midiOutCachePatches(HMIDIOUT hMidiOut,
     UINT uBank, WORD FAR* lpwPatchArray, UINT uFlags);
-UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut,
+UINT midiOutCacheDrumPatches(HMIDIOUT hMidiOut,
     UINT uPatch, WORD FAR* lpwKeyArray, UINT uFlags);
-UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT FAR* lpuDeviceID);
+UINT midiOutGetID(HMIDIOUT hMidiOut, UINT FAR* lpuDeviceID);
 
-DWORD WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage, DWORD dw1, DWORD dw2);
 
-UINT WINAPI midiInGetNumDevs(void);
-UINT WINAPI midiInGetDevCaps(UINT uDeviceID,
+UINT midiInGetNumDevs(void);
+UINT midiInGetDevCaps(UINT uDeviceID,
     LPMIDIINCAPS lpCaps, UINT uSize);
-UINT WINAPI midiInGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT WINAPI midiInOpen(HMIDIIN FAR* lphMidiIn, UINT uDeviceID,
+UINT midiInGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+UINT midiInOpen(HMIDIIN FAR* lphMidiIn, UINT uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT WINAPI midiInClose(HMIDIIN hMidiIn);
-UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
+UINT midiInClose(HMIDIIN hMidiIn);
+UINT midiInPrepareHeader(HMIDIIN hMidiIn,
     MIDIHDR FAR* lpMidiInHdr, UINT uSize);
-UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
+UINT midiInUnprepareHeader(HMIDIIN hMidiIn,
     MIDIHDR FAR* lpMidiInHdr, UINT uSize);
-UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
+UINT midiInAddBuffer(HMIDIIN hMidiIn,
     MIDIHDR FAR* lpMidiInHdr, UINT uSize);
-UINT WINAPI midiInStart(HMIDIIN hMidiIn);
-UINT WINAPI midiInStop(HMIDIIN hMidiIn);
-UINT WINAPI midiInReset(HMIDIIN hMidiIn);
-UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT FAR* lpuDeviceID);
+UINT midiInStart(HMIDIIN hMidiIn);
+UINT midiInStop(HMIDIIN hMidiIn);
+UINT midiInReset(HMIDIIN hMidiIn);
+UINT midiInGetID(HMIDIIN hMidiIn, UINT FAR* lpuDeviceID);
 
-DWORD WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD midiInMessage(HMIDIIN hMidiIn, UINT uMessage, DWORD dw1, DWORD dw2);
 
 #define AUX_MAPPER     (-1)
 
@@ -452,12 +452,12 @@
 #define AUXCAPS_VOLUME          0x0001  /* supports volume control */
 #define AUXCAPS_LRVOLUME        0x0002  /* separate left-right volume control */
 
-UINT WINAPI auxGetNumDevs(void);
-UINT WINAPI auxGetDevCaps(UINT uDeviceID, AUXCAPS FAR* lpCaps, UINT uSize);
-UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume);
-UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume);
+UINT auxGetNumDevs(void);
+UINT auxGetDevCaps(UINT uDeviceID, AUXCAPS FAR* lpCaps, UINT uSize);
+UINT auxSetVolume(UINT uDeviceID, DWORD dwVolume);
+UINT auxGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume);
 
-DWORD WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD dw1, DWORD dw2);
 
 #define TIMERR_NOERROR        (0)                  /* no error */
 #define TIMERR_NOCANDO        (TIMERR_BASE+1)      /* request not completed */
@@ -476,14 +476,14 @@
     } TIMECAPS;
 typedef TIMECAPS FAR  *LPTIMECAPS;
 
-UINT WINAPI timeGetSystemTime(MMTIME FAR* lpTime, UINT uSize);
-DWORD WINAPI timeGetTime(void);
-UINT WINAPI timeSetEvent(UINT uDelay, UINT uResolution,
+UINT timeGetSystemTime(MMTIME FAR* lpTime, UINT uSize);
+DWORD timeGetTime(void);
+UINT timeSetEvent(UINT uDelay, UINT uResolution,
     LPTIMECALLBACK lpFunction, DWORD dwUser, UINT uFlags);
-UINT WINAPI timeKillEvent(UINT uTimerID);
-UINT WINAPI timeGetDevCaps(TIMECAPS FAR* lpTimeCaps, UINT uSize);
-UINT WINAPI timeBeginPeriod(UINT uPeriod);
-UINT WINAPI timeEndPeriod(UINT uPeriod);
+UINT timeKillEvent(UINT uTimerID);
+UINT timeGetDevCaps(TIMECAPS FAR* lpTimeCaps, UINT uSize);
+UINT timeBeginPeriod(UINT uPeriod);
+UINT timeEndPeriod(UINT uPeriod);
 
 #define JOYERR_NOERROR        (0)                  /* no error */
 #define JOYERR_PARMS          (JOYERR_BASE+5)      /* bad parameters */
@@ -526,14 +526,14 @@
     } JOYINFO;
 typedef JOYINFO FAR  *LPJOYINFO;
 
-UINT WINAPI joyGetDevCaps(UINT uJoyID, JOYCAPS FAR* lpCaps, UINT uSize);
-UINT WINAPI joyGetNumDevs(void);
-UINT WINAPI joyGetPos(UINT uJoyID, JOYINFO FAR* lpInfo);
-UINT WINAPI joyGetThreshold(UINT uJoyID, UINT FAR* lpuThreshold);
-UINT WINAPI joyReleaseCapture(UINT uJoyID);
-UINT WINAPI joySetCapture(HWND hwnd, UINT uJoyID, UINT uPeriod,
+UINT joyGetDevCaps(UINT uJoyID, JOYCAPS FAR* lpCaps, UINT uSize);
+UINT joyGetNumDevs(void);
+UINT joyGetPos(UINT uJoyID, JOYINFO FAR* lpInfo);
+UINT joyGetThreshold(UINT uJoyID, UINT FAR* lpuThreshold);
+UINT joyReleaseCapture(UINT uJoyID);
+UINT joySetCapture(HWND hwnd, UINT uJoyID, UINT uPeriod,
     BOOL bChanged);
-UINT WINAPI joySetThreshold(UINT uJoyID, UINT uThreshold);
+UINT joySetThreshold(UINT uJoyID, UINT uThreshold);
 
 #define MMIOERR_BASE            256
 #define MMIOERR_FILENOTFOUND    (MMIOERR_BASE + 1)  /* file not found */
@@ -551,7 +551,7 @@
 
 typedef DWORD           FOURCC;         /* a four character code */
 DECLARE_HANDLE(HMMIO);                  /* a handle to an open file */
-typedef LRESULT (CALLBACK MMIOPROC)(LPSTR lpmmioinfo, UINT uMessage,
+typedef LONG (CALLBACK MMIOPROC)(LPSTR lpmmioinfo, UINT uMessage,
             LPARAM lParam1, LPARAM lParam2);
 typedef MMIOPROC FAR *LPMMIOPROC;
 
@@ -650,48 +650,48 @@
                 ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |    \
                 ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
 
-FOURCC WINAPI mmioStringToFOURCC(LPCSTR sz, UINT uFlags);
-LPMMIOPROC WINAPI mmioInstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
+FOURCC mmioStringToFOURCC(LPCSTR sz, UINT uFlags);
+LPMMIOPROC mmioInstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
     DWORD dwFlags);
-HMMIO WINAPI mmioOpen(LPSTR szFileName, MMIOINFO FAR* lpmmioinfo,
+HMMIO mmioOpen(LPSTR szFileName, MMIOINFO FAR* lpmmioinfo,
     DWORD dwOpenFlags);
 
-UINT WINAPI mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
+UINT mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
      MMIOINFO FAR* lpmmioinfo, DWORD dwRenameFlags);
 
-UINT WINAPI mmioClose(HMMIO hmmio, UINT uFlags);
-LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch);
-LONG WINAPI mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch);
-LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, int iOrigin);
-UINT WINAPI mmioGetInfo(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags);
-UINT WINAPI mmioSetInfo(HMMIO hmmio, const MMIOINFO FAR* lpmmioinfo, UINT uFlags);
-UINT WINAPI mmioSetBuffer(HMMIO hmmio, LPSTR pchBuffer, LONG cchBuffer,
+UINT mmioClose(HMMIO hmmio, UINT uFlags);
+LONG mmioRead(HMMIO hmmio, HPSTR pch, LONG cch);
+LONG mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch);
+LONG mmioSeek(HMMIO hmmio, LONG lOffset, int iOrigin);
+UINT mmioGetInfo(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags);
+UINT mmioSetInfo(HMMIO hmmio, const MMIOINFO FAR* lpmmioinfo, UINT uFlags);
+UINT mmioSetBuffer(HMMIO hmmio, LPSTR pchBuffer, LONG cchBuffer,
     UINT uFlags);
-UINT WINAPI mmioFlush(HMMIO hmmio, UINT uFlags);
-UINT WINAPI mmioAdvance(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags);
-LRESULT WINAPI mmioSendMessage(HMMIO hmmio, UINT uMessage,
+UINT mmioFlush(HMMIO hmmio, UINT uFlags);
+UINT mmioAdvance(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags);
+LONG mmioSendMessage(HMMIO hmmio, UINT uMessage,
     LPARAM lParam1, LPARAM lParam2);
-UINT WINAPI mmioDescend(HMMIO hmmio, MMCKINFO FAR* lpck,
+UINT mmioDescend(HMMIO hmmio, MMCKINFO FAR* lpck,
     const MMCKINFO FAR* lpckParent, UINT uFlags);
-UINT WINAPI mmioAscend(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags);
-UINT WINAPI mmioCreateChunk(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags);
+UINT mmioAscend(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags);
+UINT mmioCreateChunk(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags);
 
 typedef UINT (CALLBACK *YIELDPROC) (UINT uDeviceID, DWORD dwYieldData);
 
-DWORD WINAPI mciSendCommand (UINT uDeviceID, UINT uMessage,
+DWORD mciSendCommand (UINT uDeviceID, UINT uMessage,
     DWORD dwParam1, DWORD dwParam2);
-DWORD WINAPI mciSendString (LPCSTR lpstrCommand,
+DWORD mciSendString (LPCSTR lpstrCommand,
     LPSTR lpstrReturnString, UINT uReturnLength, HWND hwndCallback);
-UINT WINAPI mciGetDeviceID (LPCSTR lpstrName);
-UINT WINAPI mciGetDeviceIDFromElementID (DWORD dwElementID,
+UINT mciGetDeviceID (LPCSTR lpstrName);
+UINT mciGetDeviceIDFromElementID (DWORD dwElementID,
     LPCSTR lpstrType);
-BOOL WINAPI mciGetErrorString (DWORD wError, LPSTR lpstrBuffer,
+BOOL mciGetErrorString (DWORD wError, LPSTR lpstrBuffer,
     UINT uLength);
-BOOL WINAPI mciSetYieldProc (UINT uDeviceID, YIELDPROC fpYieldProc,
+BOOL mciSetYieldProc (UINT uDeviceID, YIELDPROC fpYieldProc,
     DWORD dwYieldData);
 
-HTASK WINAPI mciGetCreatorTask(UINT uDeviceID);
-YIELDPROC WINAPI mciGetYieldProc (UINT uDeviceID, DWORD FAR* lpdwYieldData);
+HTASK mciGetCreatorTask(UINT uDeviceID);
+YIELDPROC mciGetYieldProc (UINT uDeviceID, DWORD FAR* lpdwYieldData);
 
 #define MCIERR_INVALID_DEVICE_ID        (MCIERR_BASE + 1)
 #define MCIERR_UNRECOGNIZED_KEYWORD     (MCIERR_BASE + 3)
@@ -1562,14 +1562,14 @@
 	} MCI_OPEN_DRIVER_PARMS;
 typedef MCI_OPEN_DRIVER_PARMS FAR * LPMCI_OPEN_DRIVER_PARMS;
 
-DWORD WINAPI mciGetDriverData(UINT uDeviceID);
-BOOL  WINAPI mciSetDriverData(UINT uDeviceID, DWORD dwData);
-UINT  WINAPI mciDriverYield(UINT uDeviceID);
-BOOL  WINAPI mciDriverNotify(HWND hwndCallback, UINT uDeviceID,
+DWORD mciGetDriverData(UINT uDeviceID);
+BOOL  mciSetDriverData(UINT uDeviceID, DWORD dwData);
+UINT  mciDriverYield(UINT uDeviceID);
+BOOL  mciDriverNotify(HWND hwndCallback, UINT uDeviceID,
     UINT uStatus);
-UINT  WINAPI mciLoadCommandResource(HINSTANCE hInstance,
+UINT  mciLoadCommandResource(HINSTANCE hInstance,
     LPCSTR lpResName, UINT uType);
-BOOL  WINAPI mciFreeCommandResource(UINT uTable);
+BOOL  mciFreeCommandResource(UINT uTable);
 
 #define DCB_NULL		0x0000
 #define DCB_WINDOW		0x0001			/* dwCallback is a HWND */
diff --git a/include/msdos.h b/include/msdos.h
index 7b2bda7..c5392aa 100644
--- a/include/msdos.h
+++ b/include/msdos.h
@@ -10,7 +10,7 @@
 	DIR *ds;
 	char unixpath[256];
 	char filename[256];
-	char filemask[12];
+	char filemask[13];
 	char attribute;
 	char search_attribute;
 	long filesize;
@@ -30,7 +30,9 @@
 	BYTE dummy2[9];
 };
 
-#define DOSVERSION 0x0005;      /* Major version in low byte: DOS 5.00 */
+#define DOSVERSION 0x0005      /* Major version in low byte: DOS 5.00 */
+#define WINVERSION 0x0a03      /* Windows version 3.10 */
+
 #define MAX_DOS_DRIVES	26
 
 extern WORD ExtendedError;
diff --git a/include/ole2.h b/include/ole2.h
new file mode 100644
index 0000000..10a16e9
--- /dev/null
+++ b/include/ole2.h
@@ -0,0 +1,12 @@
+/*
+ *	ole2.h - Declarations for OLE2
+ */
+
+typedef LONG HRESULT;
+
+#define S_OK	0
+#define S_FALSE	1
+
+/* OLE version */
+#define rmm             23
+#define rup            639
diff --git a/include/registers.h b/include/registers.h
index 0298c23..ed323f9 100644
--- a/include/registers.h
+++ b/include/registers.h
@@ -7,39 +7,45 @@
 
 #include "wine.h"
 
-#define EAX context->sc_eax
-#define EBX context->sc_ebx
-#define ECX context->sc_ecx
-#define EDX context->sc_edx
+#define EAX (context->sc_eax)
+#define EBX (context->sc_ebx)
+#define ECX (context->sc_ecx)
+#define EDX (context->sc_edx)
+#define ESI (context->sc_esi)
+#define EDI (context->sc_edi)
 
-#define AX *(WORD*)&context->sc_eax
-#define BX *(WORD*)&context->sc_ebx
-#define CX *(WORD*)&context->sc_ecx
-#define DX *(WORD*)&context->sc_edx
+#define AX (*(WORD*)&context->sc_eax)
+#define BX (*(WORD*)&context->sc_ebx)
+#define CX (*(WORD*)&context->sc_ecx)
+#define DX (*(WORD*)&context->sc_edx)
+#define SI (*(WORD*)&context->sc_esi)
+#define DI (*(WORD*)&context->sc_edi)
 
-#define AL *(BYTE*)&context->sc_eax
-#define AH *(((BYTE*)&context->sc_eax)+1)
-#define BL *(BYTE*)&context->sc_ebx
-#define BH *(((BYTE*)&context->sc_ebx)+1)
-#define CL *(BYTE*)&context->sc_ecx
-#define CH *(((BYTE*)&context->sc_ecx)+1)
-#define DL *(BYTE*)&context->sc_edx
-#define DH *(((BYTE*)&context->sc_edx)+1)
+#define AL (*(BYTE*)&context->sc_eax)
+#define AH (*(((BYTE*)&context->sc_eax)+1))
+#define BL (*(BYTE*)&context->sc_ebx)
+#define BH (*(((BYTE*)&context->sc_ebx)+1))
+#define CL (*(BYTE*)&context->sc_ecx)
+#define CH (*(((BYTE*)&context->sc_ecx)+1))
+#define DL (*(BYTE*)&context->sc_edx)
+#define DH (*(((BYTE*)&context->sc_edx)+1))
 
-#define CS context->sc_cs
-#define DS context->sc_ds
-#define ES context->sc_es
-#define SS context->sc_ss
+#define CS (context->sc_cs)
+#define DS (context->sc_ds)
+#define ES (context->sc_es)
+#define SS (context->sc_ss)
 
-#define DI ((WORD)context->sc_edi)
-#define SI ((WORD)context->sc_esi)
-#define SP context->sc_esp
 #ifndef __FreeBSD__
-#define EFL context->sc_eflags
+#define EFL (context->sc_eflags)
 #else
-#define EFL context->sc_efl
+#define EFL (context->sc_efl)
 #endif
-#define EIP context->sc_eip
+
+#define EIP (context->sc_eip)
+#define ESP (context->sc_esp)
+
+#define IP  (*(WORD*)&context->sc_eip)
+#define SP  (*(WORD*)&context->sc_esp)
 
 #define SetCflag	(EFL |= 0x00000001)
 #define ResetCflag	(EFL &= 0xfffffffe)
diff --git a/include/stddebug.h b/include/stddebug.h
index 2b4114e..b568098 100644
--- a/include/stddebug.h
+++ b/include/stddebug.h
@@ -79,7 +79,6 @@
 #undef DEBUG_ACCEL
 #undef DEBUG_BITBLT
 #undef DEBUG_BITMAP
-#undef DEBUG_CALLBACK
 #undef DEBUG_CARET
 #undef DEBUG_CATCH
 #undef DEBUG_CDAUDIO
@@ -104,7 +103,6 @@
 #undef DEBUG_GDI
 #undef DEBUG_GLOBAL
 #undef DEBUG_GRAPHICS
-#undef DEBUG_HEAP
 #undef DEBUG_ICON
 #undef DEBUG_INT
 #undef DEBUG_KEY
@@ -123,10 +121,10 @@
 #undef DEBUG_METAFILE
 #undef DEBUG_MIDI
 #undef DEBUG_MMIO
+#undef DEBUG_MMSYS
 #undef DEBUG_MMTIME
 #undef DEBUG_MODULE
 #undef DEBUG_MSG
-#undef DEBUG_MSGBOX
 #undef DEBUG_NONCLIENT
 #undef DEBUG_OLE
 #undef DEBUG_PALETTE
@@ -154,7 +152,6 @@
 #define DEBUG_ACCEL
 #define DEBUG_BITBLT
 #define DEBUG_BITMAP
-#define DEBUG_CALLBACK
 #define DEBUG_CARET
 #define DEBUG_CATCH
 #define DEBUG_CDAUDIO
@@ -179,7 +176,6 @@
 #define DEBUG_GDI
 #define DEBUG_GLOBAL
 #define DEBUG_GRAPHICS
-#define DEBUG_HEAP
 #define DEBUG_ICON
 #define DEBUG_INT
 #define DEBUG_KEY
@@ -198,10 +194,10 @@
 #define DEBUG_METAFILE
 #define DEBUG_MIDI
 #define DEBUG_MMIO
+#define DEBUG_MMSYS
 #define DEBUG_MMTIME
 #define DEBUG_MODULE
 #define DEBUG_MSG
-#define DEBUG_MSGBOX
 #define DEBUG_NONCLIENT
 #define DEBUG_OLE
 #define DEBUG_PALETTE
diff --git a/include/windows.h b/include/windows.h
index 7230f39..0389728 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -2125,6 +2125,8 @@
   
 #define LMEM_FIXED          0   
 #define LMEM_MOVEABLE       0x0002
+#define LMEM_NOCOMPACT      0x0010
+#define LMEM_NODISCARD      0x0020
 #define LMEM_ZEROINIT       0x0040
 #define LMEM_MODIFY         0x0080
 #define LMEM_DISCARDABLE    0x0F00
@@ -2815,9 +2817,9 @@
 Fc(INT,GetTextFace,HDC,a,INT,b,LPSTR,c)
 Fc(INT,OpenFile,LPSTR,a,LPOFSTRUCT,b,WORD,c)
 Fc(INT,_lread,INT,a,LPSTR,b,WORD,c)
-Fc(INT,_lwrite,INT,a,LPSTR,b,WORD,c)
+Fc(INT,_lwrite,INT,a,LPCSTR,b,WORD,c)
 Fc(LONG,_hread,INT,a,LPSTR,b,LONG,c)
-Fc(LONG,_hwrite,INT,a,LPSTR,b,LONG,c)
+Fc(LONG,_hwrite,INT,a,LPCSTR,b,LONG,c)
 Fc(LONG,GetBitmapBits,HBITMAP,a,LONG,b,LPSTR,c)
 Fc(LONG,SetBitmapBits,HBITMAP,a,LONG,b,LPSTR,c)
 Fc(LONG,SetClassLong,HWND,a,short,b,LONG,c)
diff --git a/include/winnls.h b/include/winnls.h
new file mode 100644
index 0000000..2e5c652
--- /dev/null
+++ b/include/winnls.h
@@ -0,0 +1,100 @@
+#define LOCALE_ILANGUAGE            0x00000001   
+#define LOCALE_SLANGUAGE            0x00000002   
+#define LOCALE_SENGLANGUAGE         0x00001001   
+#define LOCALE_SABBREVLANGNAME      0x00000003   
+#define LOCALE_SNATIVELANGNAME      0x00000004   
+#define LOCALE_ICOUNTRY             0x00000005   
+#define LOCALE_SCOUNTRY             0x00000006   
+#define LOCALE_SENGCOUNTRY          0x00001002   
+#define LOCALE_SABBREVCTRYNAME      0x00000007   
+#define LOCALE_SNATIVECTRYNAME      0x00000008   
+#define LOCALE_IDEFAULTLANGUAGE     0x00000009   
+#define LOCALE_IDEFAULTCOUNTRY      0x0000000A   
+#define LOCALE_IDEFAULTCODEPAGE     0x0000000B   
+#define LOCALE_IDEFAULTANSICODEPAGE 0x00001004   
+#define LOCALE_SLIST                0x0000000C   
+#define LOCALE_IMEASURE             0x0000000D   
+#define LOCALE_SDECIMAL             0x0000000E   
+#define LOCALE_STHOUSAND            0x0000000F   
+#define LOCALE_SGROUPING            0x00000010   
+#define LOCALE_IDIGITS              0x00000011   
+#define LOCALE_ILZERO               0x00000012   
+#define LOCALE_INEGNUMBER           0x00001010   
+#define LOCALE_SNATIVEDIGITS        0x00000013   
+#define LOCALE_SCURRENCY            0x00000014   
+#define LOCALE_SINTLSYMBOL          0x00000015   
+#define LOCALE_SMONDECIMALSEP       0x00000016   
+#define LOCALE_SMONTHOUSANDSEP      0x00000017   
+#define LOCALE_SMONGROUPING         0x00000018   
+#define LOCALE_ICURRDIGITS          0x00000019   
+#define LOCALE_IINTLCURRDIGITS      0x0000001A   
+#define LOCALE_ICURRENCY            0x0000001B   
+#define LOCALE_INEGCURR             0x0000001C   
+#define LOCALE_SDATE                0x0000001D   
+#define LOCALE_STIME                0x0000001E   
+#define LOCALE_SSHORTDATE           0x0000001F   
+#define LOCALE_SLONGDATE            0x00000020   
+#define LOCALE_STIMEFORMAT          0x00001003   
+#define LOCALE_IDATE                0x00000021   
+#define LOCALE_ILDATE               0x00000022   
+#define LOCALE_ITIME                0x00000023   
+#define LOCALE_ITIMEMARKPOSN        0x00001005   
+#define LOCALE_ICENTURY             0x00000024   
+#define LOCALE_ITLZERO              0x00000025   
+#define LOCALE_IDAYLZERO            0x00000026   
+#define LOCALE_IMONLZERO            0x00000027   
+#define LOCALE_S1159                0x00000028   
+#define LOCALE_S2359                0x00000029   
+#define LOCALE_ICALENDARTYPE        0x00001009   
+#define LOCALE_IOPTIONALCALENDAR    0x0000100B   
+#define LOCALE_IFIRSTDAYOFWEEK      0x0000100C   
+#define LOCALE_IFIRSTWEEKOFYEAR     0x0000100D   
+#define LOCALE_SDAYNAME1            0x0000002A   
+#define LOCALE_SDAYNAME2            0x0000002B   
+#define LOCALE_SDAYNAME3            0x0000002C   
+#define LOCALE_SDAYNAME4            0x0000002D   
+#define LOCALE_SDAYNAME5            0x0000002E   
+#define LOCALE_SDAYNAME6            0x0000002F   
+#define LOCALE_SDAYNAME7            0x00000030   
+#define LOCALE_SABBREVDAYNAME1      0x00000031   
+#define LOCALE_SABBREVDAYNAME2      0x00000032   
+#define LOCALE_SABBREVDAYNAME3      0x00000033   
+#define LOCALE_SABBREVDAYNAME4      0x00000034   
+#define LOCALE_SABBREVDAYNAME5      0x00000035   
+#define LOCALE_SABBREVDAYNAME6      0x00000036   
+#define LOCALE_SABBREVDAYNAME7      0x00000037   
+#define LOCALE_SMONTHNAME1          0x00000038   
+#define LOCALE_SMONTHNAME2          0x00000039   
+#define LOCALE_SMONTHNAME3          0x0000003A   
+#define LOCALE_SMONTHNAME4          0x0000003B   
+#define LOCALE_SMONTHNAME5          0x0000003C   
+#define LOCALE_SMONTHNAME6          0x0000003D   
+#define LOCALE_SMONTHNAME7          0x0000003E   
+#define LOCALE_SMONTHNAME8          0x0000003F   
+#define LOCALE_SMONTHNAME9          0x00000040   
+#define LOCALE_SMONTHNAME10         0x00000041   
+#define LOCALE_SMONTHNAME11         0x00000042   
+#define LOCALE_SMONTHNAME12         0x00000043   
+#define LOCALE_SMONTHNAME13         0x0000100E   
+#define LOCALE_SABBREVMONTHNAME1    0x00000044   
+#define LOCALE_SABBREVMONTHNAME2    0x00000045   
+#define LOCALE_SABBREVMONTHNAME3    0x00000046   
+#define LOCALE_SABBREVMONTHNAME4    0x00000047   
+#define LOCALE_SABBREVMONTHNAME5    0x00000048   
+#define LOCALE_SABBREVMONTHNAME6    0x00000049   
+#define LOCALE_SABBREVMONTHNAME7    0x0000004A   
+#define LOCALE_SABBREVMONTHNAME8    0x0000004B   
+#define LOCALE_SABBREVMONTHNAME9    0x0000004C   
+#define LOCALE_SABBREVMONTHNAME10   0x0000004D   
+#define LOCALE_SABBREVMONTHNAME11   0x0000004E   
+#define LOCALE_SABBREVMONTHNAME12   0x0000004F   
+#define LOCALE_SABBREVMONTHNAME13   0x0000100F   
+#define LOCALE_SPOSITIVESIGN        0x00000050   
+#define LOCALE_SNEGATIVESIGN        0x00000051   
+#define LOCALE_IPOSSIGNPOSN         0x00000052   
+#define LOCALE_INEGSIGNPOSN         0x00000053   
+#define LOCALE_IPOSSYMPRECEDES      0x00000054   
+#define LOCALE_IPOSSEPBYSPACE       0x00000055   
+#define LOCALE_INEGSYMPRECEDES      0x00000056   
+#define LOCALE_INEGSEPBYSPACE       0x00000057   
+
diff --git a/include/wintypes.h b/include/wintypes.h
index e63f97a..74e3feb 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -31,8 +31,8 @@
 typedef SEGPTR WNDPROC;
 #endif
 typedef FARPROC DLGPROC;
-typedef int CATCHBUF[9];
-typedef int *LPCATCHBUF;
+typedef WORD CATCHBUF[9];
+typedef WORD *LPCATCHBUF;
 typedef FARPROC HOOKPROC;
 
 #define DECLARE_HANDLE(a) typedef HANDLE a;
diff --git a/loader/module.c b/loader/module.c
index aa397d8..01d2678 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -26,6 +26,7 @@
 
 
 static HMODULE hFirstModule = 0;
+static HMODULE hCachedModule = 0;  /* Module cached by MODULE_OpenFile */
 
 
 /***********************************************************************
@@ -271,7 +272,6 @@
     NE_MODULE *pModule;
     char *name;
 
-    static HMODULE hCachedModule = 0;
     static int cachedfd = -1;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
@@ -306,8 +306,10 @@
         if (i == pModule->ss) minsize += pModule->stack_size;
         if (i == pModule->dgroup)
         {
+#if 0
             /* FIXME: this is needed because heap growing is not implemented */
             pModule->heap_size = 0x10000 - minsize;
+#endif
             /* The DGROUP is allocated by MODULE_CreateInstance */
             continue;
         }
@@ -865,6 +867,10 @@
     if (pModule->nrname_handle) GlobalFree( pModule->nrname_handle );
     if (pModule->dlls_to_init) GlobalFree( pModule->dlls_to_init );
     GlobalFree( hModule );
+
+      /* Remove module from cache */
+
+    if (hCachedModule == hModule) hCachedModule = 0;
 }
 
 
@@ -997,6 +1003,8 @@
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return FALSE;
 
+    dprintf_module( stddeb, "FreeModule: %s count %d\n", 
+		    MODULE_GetModuleName(hModule), pModule->count );
     if (--pModule->count == 0) MODULE_FreeModule( hModule );
     return TRUE;
 }
@@ -1052,8 +1060,10 @@
     HANDLE handle;
 
     dprintf_module( stddeb, "LoadLibrary: (%08x) %s\n", (int)libname, libname);
+    /* This does not increment the module reference count, and will
+     * therefore cause crashes on FreeLibrary calls.
     if ((handle = MODULE_FindModule( libname )) != 0) return handle;
-
+     */
     handle = LoadModule( libname, (LPVOID)-1 );
     if (handle == 2)  /* file not found */
     {
diff --git a/loader/ne_image.c b/loader/ne_image.c
index 4529f62..98ec822 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -48,6 +48,7 @@
     pSegTable = NE_SEG_TABLE( pModule );
     pSeg = pSegTable + segnum - 1;
     pModuleTable = NE_MODULE_TABLE( pModule );
+
     if (!pSeg->filepos) return TRUE;  /* No file image, just return */
 
     fd = MODULE_OpenFile( hModule );
@@ -56,14 +57,6 @@
     lseek( fd, pSeg->filepos << pModule->alignment, SEEK_SET );
     read( fd, GlobalLock( pSeg->selector ), pSeg->size ? pSeg->size : 0x10000);
 
-    if ( pModule->heap_size && pModule->dgroup == segnum )
-    {
-        /* Initialize the local heap */
-        WORD heapstart = pSeg->minsize;
-        if (pModule->ss == pModule->dgroup) heapstart += pModule->stack_size;
-        LocalInit( pSeg->selector, heapstart, heapstart + pModule->heap_size );
-    }    
-
     if (!(pSeg->flags & NE_SEGFLAGS_RELOC_DATA))
         return TRUE;  /* No relocation data, we are done */
 
@@ -316,36 +309,51 @@
         p += 2;
         while (count-- > 0)
         {
-            dprintf_module( stddeb,"Flags: %04x ", *p );
-            /* FIXME: Does anyone know the exact meaning of these flags? */
-            /* 0x0001 seems to mean: Fix up the function prolog          */
+            dprintf_module( stddeb,"Flags: %04x, sel %02x ", *p, sel);
+            /* According to the output generated by TDUMP, the flags mean:
+             * 0x0001 function is exported
+	     * 0x0002 Single data (seems to occur only in DLLs)
+	     */
+	    if (sel == 0xff) { /* moveable */
+		dprintf_module( stddeb, "(%02x) o %04x ", p[3], *(WORD *)(p+4) );
+		fixup_ptr = (char *)GET_SEL_BASE(pSegTable[p[3]-1].selector) + *(WORD *)(p + 4);
+	    } else { /* fixed */
+		dprintf_module( stddeb, "offset %04x ", *(WORD *)(p+1) );
+		fixup_ptr = (char *)GET_SEL_BASE(pSegTable[sel-1].selector) + *(WORD *)(p + 1);
+	    }
+	    dprintf_module( stddeb, "Signature: %02x %02x %02x,ff %x\n",
+			   fixup_ptr[0], fixup_ptr[1], fixup_ptr[2],
+			   pModule->flags );
             if (*p & 0x0001)
             {
-                if (sel == 0xff)  /* moveable */
-                    fixup_ptr = (char *)GET_SEL_BASE(pSegTable[p[3]-1].selector) + *(WORD *)(p + 4);
-                else  /* fixed */
-                    fixup_ptr = (char *)GET_SEL_BASE(pSegTable[sel-1].selector) + *(WORD *)(p + 1);
-                dprintf_module( stddeb, "Signature: %02x %02x %02x,ff %x\n",
-                                fixup_ptr[0], fixup_ptr[1], fixup_ptr[2],
-                                pModule->flags );
                 /* Verify the signature */
                 if (((fixup_ptr[0] == 0x1e && fixup_ptr[1] == 0x58)
                      || (fixup_ptr[0] == 0x8c && fixup_ptr[1] == 0xd8))
                     && fixup_ptr[2] == 0x90)
                 {
-                    if (pModule->flags & NE_FFLAGS_SINGLEDATA)
+                    if (*p & 0x0002)
                     {
+			if (pModule->flags & NE_FFLAGS_MULTIPLEDATA) {
+			    /* can this happen? */
+			    fprintf( stderr, "FixupPrologs got confused\n" );
+			}
                         *fixup_ptr = 0xb8;	/* MOV AX, */
                         *(WORD *)(fixup_ptr+1) = dgroup;
                     }
                     else
                     {
-                        fixup_ptr[0] = 0x90; /* non-library: NOPs */	
-                        fixup_ptr[1] = 0x90;
-                        fixup_ptr[2] = 0x90;
+			if (pModule->flags & NE_FFLAGS_MULTIPLEDATA) {
+			    fixup_ptr[0] = 0x90; /* non-library: NOPs */
+			    fixup_ptr[1] = 0x90;
+			    fixup_ptr[2] = 0x90;
+			}
                     }
-                } 
+                } else {
+		    dprintf_fixup( stddeb, "Unknown signature\n" );
+		}
             }
+	    else
+	      dprintf_module( stddeb,"\n");
             p += (sel == 0xff) ? 6 : 3;  
         }
     }
@@ -423,13 +431,14 @@
     pModule = (NE_MODULE *)GlobalLock( hModule );
     if (pModule->dlls_to_init)
     {
-        for (pDLL = (WORD *)GlobalLock( pModule->dlls_to_init ); *pDLL; pDLL++)
+	HANDLE to_init = pModule->dlls_to_init;
+	pModule->dlls_to_init = 0;
+        for (pDLL = (WORD *)GlobalLock( to_init ); *pDLL; pDLL++)
         {
-            NE_InitDLL( *pDLL );
             NE_InitializeDLLs( *pDLL );
+            NE_InitDLL( *pDLL );
         }
-        GlobalFree( pModule->dlls_to_init );
-        pModule->dlls_to_init = 0;
+        GlobalFree( to_init );
     }
     NE_InitDLL( hModule );
 }
diff --git a/loader/ne_resource.c b/loader/ne_resource.c
index 76f30b8..ab9b089 100644
--- a/loader/ne_resource.c
+++ b/loader/ne_resource.c
@@ -248,7 +248,7 @@
     pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
 
     name = ((LOADEDFILEINFO*)((char*)pModule + pModule->fileinfo))->filename;
-    fd = open( name, O_RDONLY );
+    fd = open( DOS_GetUnixFileName(name), O_RDONLY );
     sizeShift = *(WORD *)((char *)pModule + pModule->res_table);
     lseek( fd, (int)pNameInfo->offset << sizeShift, SEEK_SET );
     return fd;
diff --git a/loader/resource.c b/loader/resource.c
index 0970786..2a008ab 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -372,6 +372,7 @@
     if (bih->biSize != sizeof(BITMAPINFOHEADER)) return 0;
     lpico->hBitmap = CreateDIBitmap( hdc, &pInfo->bmiHeader, CBM_INIT,
                                     (char*)bmi + size, pInfo, DIB_RGB_COLORS );
+
     if (bih->biSizeImage == 0)
     {
 	if (bih->biCompression != BI_RGB)
@@ -381,20 +382,18 @@
 	    ReleaseDC( 0, hdc); 
 	    return 0;
         }
-	bih->biSizeImage = DIB_GetImageWidthBytes(bih->biWidth,bih->biBitCount)
-                             * bih->biHeight;
+	bih->biSizeImage = (DIB_GetImageWidthBytes(bih->biWidth,bih->biBitCount) +
+                     DIB_GetImageWidthBytes(bih->biWidth,1)) * bih->biHeight/2;
     }
     bits = (char *)bmi + size +
              bih->biSizeImage * bih->biBitCount / (bih->biBitCount+1);
     bih->biBitCount = 1;
     bih->biClrUsed = bih->biClrImportant = 2;
-    rgbq = &bmi->bmiColors[0];
+    rgbq = &pInfo->bmiColors[0];
     rgbq[0].rgbBlue = rgbq[0].rgbGreen = rgbq[0].rgbRed = 0x00;
     rgbq[1].rgbBlue = rgbq[1].rgbGreen = rgbq[1].rgbRed = 0xff;
     rgbq[0].rgbReserved = rgbq[1].rgbReserved = 0;
     lpico->hBitMask = CreateDIBitmap(hdc, &pInfo->bmiHeader, CBM_INIT,
-/*  	(LPSTR)bmi + bih->biSizeImage - sizeof(BITMAPINFOHEADER) / 2 - 4,
-   (LPSTR)lp + bih->biSizeImage + bih->biSize + 4*lpicodesc->ColorCount, */
                                      bits, pInfo, DIB_RGB_COLORS );
     FreeResource( rsc_mem );
     ReleaseDC( 0, hdc);
@@ -612,19 +611,20 @@
     for (i = 0; i < string_num; i++)
 	p += *p + 1;
     
+    dprintf_resource( stddeb, "strlen = %d\n", (int)*p );
+    
     i = min(buflen - 1, *p);
-	if (i > 0) {
-		memcpy(buffer, p + 1, i);
-		buffer[i] = '\0';
-		}
-	else {
-		if (buflen > 1) {
-			buffer[0] = '\0';
-			return 0;
-			}
-		fprintf(stderr,"LoadString // I dont know why , but caller give buflen=%d *p=%d !\n", buflen, *p);
-		fprintf(stderr,"LoadString // and try to obtain string '%s'\n", p + 1);
-		}
+    if (i > 0) {
+	memcpy(buffer, p + 1, i);
+	buffer[i] = '\0';
+    } else {
+	if (buflen > 1) {
+	    buffer[0] = '\0';
+	    return 0;
+	}
+	fprintf(stderr,"LoadString // I dont know why , but caller give buflen=%d *p=%d !\n", buflen, *p);
+	fprintf(stderr,"LoadString // and try to obtain string '%s'\n", p + 1);
+    }
     FreeResource( hmem );
 
     dprintf_resource(stddeb,"LoadString // '%s' copied !\n", buffer);
diff --git a/loader/signal.c b/loader/signal.c
index 6ac04ad..37109ecba 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -15,7 +15,6 @@
 #endif
 
 #include "wine.h"
-#include "dos_fs.h"
 #include "prototypes.h"
 #include "miscemu.h"
 #include "registers.h"
@@ -45,46 +44,6 @@
 }
 #endif
 
-int do_int(int intnum, struct sigcontext_struct *context)
-{
-	switch(intnum)
-	{
-	      case 0x10: return do_int10(context);
-
-	      case 0x11:  
-		AX = DOS_GetEquipment();
-		return 1;
-
-	      case 0x12:               
-		AX = 640;
-		return 1;	/* get base mem size */                
-
-              case 0x13: return do_int13(context);
-	      case 0x15: return do_int15(context);
-	      case 0x16: return do_int16(context);
-	      case 0x1a: return do_int1a(context);
-	      case 0x21: return do_int21(context);
-
-	      case 0x22:
-		AX = 0x1234;
-		BX = 0x5678;
-		CX = 0x9abc;
-		DX = 0xdef0;
-		return 1;
-
-              case 0x25: return do_int25(context);
-              case 0x26: return do_int26(context);
-              case 0x2a: return do_int2a(context);
-	      case 0x2f: return do_int2f(context);
-	      case 0x31: return do_int31(context);
-	      case 0x5c: return do_int5c(context);
-
-              default:
-                fprintf(stderr,"int%02x: Unimplemented!\n", intnum);
-                break;
-	}
-	return 0;
-}
 
 #ifdef linux
 static void win_fault(int signal, struct sigcontext_struct context_struct)
@@ -94,131 +53,19 @@
 static void win_fault(int signal, int code, struct sigcontext *context)
 {
 #endif
-    unsigned char * instr;
-    WORD *stack;
+
 #if !(defined (linux) || defined (__NetBSD__))
     int i, *dump;
 #endif
 
-	/* First take care of a few preliminaries */
-#ifdef linux
-    if(signal != SIGSEGV 
-       && signal != SIGILL 
-       && signal != SIGFPE 
-#ifdef SIGBUS
-       && signal != SIGBUS 
-#endif
-       && signal != SIGTRAP) 
+    if(signal == SIGTRAP) EIP--;   /* Back up over the int3 instruction. */
+    else if (CS == WINE_CODE_SELECTOR)
     {
-	exit(1);
+	fprintf(stderr, "Segmentation fault in Wine program (%x:%lx)."
+		        "  Please debug\n", CS, EIP );
     }
+    else if (INSTR_EmulateInstruction( context )) return;
 
-    /* And back up over the int3 instruction. */
-    if(signal == SIGTRAP) {
-      EIP--;
-      goto oops;
-    }
-#endif
-#ifdef __NetBSD__
-/*         set_es(0x1f); set_ds(0x1f); */
-    if(signal != SIGBUS && signal != SIGSEGV && signal != SIGTRAP) 
-	exit(1);
-#endif
-#ifdef __FreeBSD__
-/*         set_es(0x27); set_ds(0x27); */
-    if(signal != SIGBUS && signal != SIGSEGV && signal != SIGTRAP) 
-	exit(1);
-#endif
-    if (CS == WINE_CODE_SELECTOR)
-    {
-	fprintf(stderr,
-		"Segmentation fault in Wine program (%x:%lx)."
-		"  Please debug\n", CS, EIP );
-	goto oops;
-    }
-
-    /*  Now take a look at the actual instruction where the program
-	bombed */
-    instr = (unsigned char *) PTR_SEG_OFF_TO_LIN( CS, EIP );
-
-    switch(*instr)
-    {
-      case 0xcd: /* int <XX> */
-            instr++;
-	    if (!do_int(*instr, context)) {
-		fprintf(stderr,"Unexpected Windows interrupt %x\n", *instr);
-		goto oops;
-	    }
-	    EIP += 2;  /* Bypass the int instruction */
-            break;
-
-      case 0xcf: /* iret */
-            stack = (WORD *)PTR_SEG_OFF_TO_LIN( SS, SP );
-            EIP = *stack++;
-            CS  = *stack++;
-            EFL = *stack;
-            SP += 6;  /* Pop the return address and flags */
-            break;
-
-      case 0xe4: /* inb al,XX */
-            inportb_abs(context);
-	    EIP += 2;
-            break;
-
-      case 0xe5: /* in ax,XX */
-            inport_abs(context);
-	    EIP += 2;
-            break;
-
-      case 0xe6: /* outb XX,al */
-            outportb_abs(context);
-	    EIP += 2;
-            break;
-
-      case 0xe7: /* out XX,ax */
-            outport_abs(context);
-	    EIP += 2;
-            break;
-
-      case 0xec: /* inb al,dx */
-            inportb(context);
-	    EIP++;
-            break;
-
-      case 0xed: /* in ax,dx */
-            inport(context);
-	    EIP++;  
-            break;
-
-      case 0xee: /* outb dx,al */
-            outportb(context);
-	    EIP++;
-            break;
-      
-      case 0xef: /* out dx,ax */
-            outport(context);
-	    EIP++;
-            break;
-
-      case 0xfa: /* cli, ignored */
-	    EIP++;
-            break;
-
-      case 0xfb: /* sti, ignored */
-	    EIP++;
-            break;
-
-      default:
-		fprintf(stderr, "Unexpected Windows program segfault"
-			" - opcode = %x\n", *instr);
-		goto oops;
-    }
-    
-    /* OK, done handling the interrupt */
-
-    return;
-
-  oops:
     XUngrabPointer(display, CurrentTime);
     XUngrabServer(display);
     XFlush(display);
diff --git a/loader/task.c b/loader/task.c
index 5663419..9e39700 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -529,6 +529,9 @@
     static int firstTask = 1;
     TDB *pTask;
     NE_MODULE *pModule;
+    SEGTABLEENTRY *pSegTable;
+    INSTANCEDATA *pinstance;
+    LONG stacklow, stackhi;
 
     context.sc_eax = 0;
     if (!(pTask = (TDB *)GlobalLock( hCurrentTask ))) return;
@@ -567,6 +570,23 @@
     context.sc_esi = pTask->hPrevInstance;
     context.sc_edi = pTask->hInstance;
     context.sc_es  = pTask->hPDB;
+
+    /* Initialize the local heap */
+    if ( pModule->heap_size )
+    {
+        LocalInit( pTask->hInstance, 0, pModule->heap_size );
+    }    
+
+
+    /* Initialize the INSTANCEDATA structure */
+    pSegTable = NE_SEG_TABLE( pModule );
+    stacklow = pSegTable[pModule->ss - 1].minsize;
+    stackhi  = stacklow + pModule->stack_size;
+    if (stackhi > 0xffff) stackhi = 0xffff;
+    pinstance = (INSTANCEDATA *)PTR_SEG_OFF_TO_LIN(CURRENT_DS, 0);
+    pinstance->stackbottom = stackhi; /* yup, that's right. Confused me too. */
+    pinstance->stacktop    = stacklow; 
+    pinstance->stackmin    = IF1632_Saved16_sp;
 }
 
 
@@ -585,8 +605,8 @@
         return FALSE;
     }
     TASK_SCHEDULE();
-    /* When we get back here, we have an event */
-    pTask->nEvents--;
+    /* When we get back here, we have an event (or the task is the only one) */
+    if (pTask->nEvents > 0) pTask->nEvents--;
     return TRUE;
 }
 
diff --git a/memory/global.c b/memory/global.c
index d7fd15b..4a51b5e 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -307,7 +307,6 @@
  */
 LPSTR GlobalLock( HGLOBAL handle )
 {
-    dprintf_global( stddeb, "GlobalLock: %04x\n", handle );
     if (!handle) return 0;
     return (LPSTR)GET_ARENA_PTR(handle)->base;
 }
@@ -452,7 +451,7 @@
  */
 LONG SetSwapAreaSize( WORD size )
 {
-    dprintf_heap(stdnimp, "STUB: SetSwapAreaSize(%d)\n", size );
+    dprintf_global(stdnimp, "STUB: SetSwapAreaSize(%d)\n", size );
     return MAKELONG( size, 0xffff );
 }
 
diff --git a/memory/ldt.c b/memory/ldt.c
index 73e1260..f80b2cc 100644
--- a/memory/ldt.c
+++ b/memory/ldt.c
@@ -32,13 +32,17 @@
 
 #endif  /* ifndef WINELIB */
 
+
+ldt_copy_entry ldt_copy[LDT_SIZE] = { {0,0}, };
+unsigned char ldt_flags_copy[LDT_SIZE] = { 0, };
+
         
 /***********************************************************************
  *           LDT_BytesToEntry
  *
  * Convert the raw bytes of the descriptor to an ldt_entry structure.
  */
-static void LDT_BytesToEntry( unsigned long *buffer, ldt_entry *content )
+void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content )
 {
     content->base  = (*buffer >> 16) & 0x0000ffff;
     content->limit = *buffer & 0x0000ffff;
@@ -53,6 +57,26 @@
 
 
 /***********************************************************************
+ *           LDT_EntryToBytes
+ *
+ * Convert an ldt_entry structure to the raw bytes of the descriptor.
+ */
+void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content )
+{
+    *buffer++ = ((content->base & 0x0000ffff) << 16) |
+                 (content->limit & 0x0ffff);
+    *buffer = (content->base & 0xff000000) |
+              ((content->base & 0x00ff0000)>>16) |
+              (content->limit & 0xf0000) |
+              (content->type << 10) |
+              ((content->read_only == 0) << 9) |
+              ((content->seg_32bit != 0) << 22) |
+              ((content->limit_in_pages != 0) << 23) |
+              0xf000;
+}
+
+
+/***********************************************************************
  *           LDT_GetEntry
  *
  * Retrieve an LDT entry.
@@ -61,31 +85,12 @@
 {
     int ret = 0;
 
-#ifdef WINELIB
     content->base           = ldt_copy[entry].base;
     content->limit          = ldt_copy[entry].limit;
-    content->type           = SEGMENT_DATA;
-    content->seg_32bit      = 0;
-    content->read_only      = 0;
-    content->limit_in_pages = 0;
-#else  /* WINELIB */
-
-#ifdef linux
-    int size = (entry + 1) * 2 * sizeof(long);
-    long *buffer = (long *) malloc( size );
-    ret = modify_ldt( 0, buffer, size );
-    LDT_BytesToEntry( &buffer[entry*2], content );
-    free( buffer );
-#endif  /* linux */
-
-#if defined(__NetBSD__) || defined(__FreeBSD__)
-    long buffer[2];
-    ret = i386_get_ldt( entry, (union descriptor *)buffer, 1 );
-    LDT_BytesToEntry( buffer, content );
-#endif  /* __NetBSD__ || __FreeBSD__ */
-
-#endif  /* WINELIB */
-
+    content->type           = (ldt_flags_copy[entry] & LDT_FLAGS_TYPE);
+    content->seg_32bit      = (ldt_flags_copy[entry] & LDT_FLAGS_32BIT) != 0;
+    content->read_only      = (ldt_flags_copy[entry] & LDT_FLAGS_READONLY) !=0;
+    content->limit_in_pages = (ldt_flags_copy[entry] & LDT_FLAGS_BIG) !=0;
     return ret;
 }
 
@@ -95,7 +100,7 @@
  *
  * Set an LDT entry.
  */
-int LDT_SetEntry( int entry, ldt_entry *content )
+int LDT_SetEntry( int entry, const ldt_entry *content )
 {
     int ret = 0;
 
@@ -108,6 +113,9 @@
           content->read_only || (content->type & SEGMENT_CODE) ? '-' : 'w',
           (content->type & SEGMENT_CODE) ? 'x' : '-' );
 
+    /* Entry 0 must not be modified; its base and limit are always 0 */
+    if (!entry) return 0;
+
 #ifndef WINELIB
 #ifdef linux
     {
@@ -129,16 +137,7 @@
     {
         long d[2];
 
-        d[0] = ((content->base & 0x0000ffff) << 16) |
-                (content->limit & 0x0ffff);
-        d[1] = (content->base & 0xff000000) |
-               ((content->base & 0x00ff0000)>>16) |
-               (content->limit & 0xf0000) |
-               (content->type << 10) |
-               ((content->read_only == 0) << 9) |
-               ((content->seg_32bit != 0) << 22) |
-               ((content->limit_in_pages != 0) << 23) |
-               0xf000;
+        LDT_EntryToBytes( d, content );
         ret = i386_set_ldt(entry, (union descriptor *)d, 1);
         if (ret < 0)
         {
@@ -155,6 +154,10 @@
     ldt_copy[entry].base = content->base;
     if (!content->limit_in_pages) ldt_copy[entry].limit = content->limit;
     else ldt_copy[entry].limit = (content->limit << 12) | 0x0fff;
+    ldt_flags_copy[entry] = (content->type & LDT_FLAGS_TYPE) |
+                            (content->read_only ? LDT_FLAGS_READONLY : 0) |
+                            (content->seg_32bit ? LDT_FLAGS_32BIT : 0) |
+                            (content->limit_in_pages ? LDT_FLAGS_BIG : 0);
     return ret;
 }
 
@@ -167,40 +170,28 @@
 void LDT_Print()
 {
     int i;
+    char flags[3];
 
-#ifdef WINELIB
     for (i = 0; i < LDT_SIZE; i++)
     {
-        if (ldt_copy[i].base || ldt_copy[i].limit)
+        if (!ldt_copy[i].base && !ldt_copy[i].limit) continue; /* Free entry */
+        if ((ldt_flags_copy[i] & LDT_FLAGS_TYPE) == SEGMENT_CODE)
         {
-            fprintf( stderr, "%04x: sel=%04x base=%08x limit=%05x\n",
-                     i, ENTRY_TO_SELECTOR(i),
-                     ldt_copy[i].base, ldt_copy[i].limit );
+            flags[0] = (ldt_flags_copy[i] & LDT_FLAGS_EXECONLY) ? '-' : 'r';
+            flags[1] = '-';
+            flags[2] = 'x';
         }
-    }
-#else  /* WINELIB */
-
-    long buffer[2*LDT_SIZE];
-    ldt_entry content;
-    int n;
-
-#ifdef linux
-    n = modify_ldt( 0, buffer, sizeof(buffer) ) / 8;
-#endif  /* linux */
-#if defined(__NetBSD__) || defined(__FreeBSD__)
-    n = i386_get_ldt( 0, (union descriptor *)buffer, LDT_SIZE );
-#endif  /* __NetBSD__ || __FreeBSD__ */
-    for (i = 0; i < n; i++)
-    {
-        LDT_BytesToEntry( &buffer[2*i], &content );
-        if (content.base || content.limit)
+        else
         {
-            fprintf( stderr, "%04x: sel=%04x base=%08lx limit=%05lx %s type=%d\n",
-                    i, ENTRY_TO_SELECTOR(i),
-                    content.base, content.limit,
-                    content.limit_in_pages ? "(pages)" : "(bytes)",
-                    content.type );
+            flags[0] = 'r';
+            flags[1] = (ldt_flags_copy[i] & LDT_FLAGS_READONLY) ? '-' : 'w';
+            flags[2] = '-';
         }
+        printf("%04x: sel=%04x base=%08lx limit=%05lx %s %d-bit %c%c%c\n",
+                i, ENTRY_TO_SELECTOR(i),
+                ldt_copy[i].base, ldt_copy[i].limit,
+                ldt_flags_copy[i] & LDT_FLAGS_BIG ? "(pages)" : "(bytes)",
+                ldt_flags_copy[i] & LDT_FLAGS_32BIT ? 32 : 16,
+                flags[0], flags[1], flags[2] );
     }
-#endif  /* WINELIB */
 }
diff --git a/memory/local.c b/memory/local.c
index 1cd4a58..f42b8d3 100644
--- a/memory/local.c
+++ b/memory/local.c
@@ -47,9 +47,6 @@
 #define LOCAL_ARENA_FIXED      1
 #define LOCAL_ARENA_MOVEABLE   3
 
-#define LMEM_NOCOMPACT 0x0010
-#define LMEM_NODISCARD 0x0020
-
 typedef struct
 {
     WORD addr;                /* Address of the MOVEABLE block */
@@ -109,7 +106,7 @@
 {
     LOCALHEAPINFO *pInfo;
     INSTANCEDATA *ptr = (INSTANCEDATA *)PTR_SEG_OFF_TO_LIN( ds, 0 );
-    dprintf_local( stddeb, "Heap at %04x\n", ptr->heap );
+    dprintf_local( stddeb, "Heap at %p, %04x\n", ptr, ptr->heap );
     if (!ptr->heap) return 0;
     pInfo = (LOCALHEAPINFO*)((char*)ptr + ptr->heap);
     if (pInfo->magic != LOCAL_HEAP_MAGIC) return NULL;
@@ -304,26 +301,30 @@
 
     dprintf_local(stddeb, "LocalInit: %04x %04x-%04x\n", selector, start, end);
     if (!selector) selector = CURRENT_DS;
-    ptr = PTR_SEG_OFF_TO_LIN( selector, 0 );
     pHeapInfo = LOCAL_GetHeap(selector);
-      /* If there's already a local heap in this segment, */
-      /* we simply return TRUE. This helps some programs. */
+
     if (pHeapInfo)  {
-      dprintf_local(stddeb,"LocalInit: Heap %04x initialized twice.\n",selector);
+      fprintf( stderr, "LocalInit: Heap %04x initialized twice.\n", selector);
       if (debugging_local) LOCAL_PrintHeap(selector);
-      return TRUE;
     }
 
-#if 0
+#if 1
+    if (start == 0) {
       /* Check if the segment is the DGROUP of a module */
 
-    if ((pModule = (NE_MODULE *)GlobalLock( GetExePtr( selector ) )))
-    {
-        SEGTABLEENTRY *pSeg = NE_SEG_TABLE( pModule ) + pModule->dgroup - 1;
-        if (pModule->dgroup && (pSeg->selector == selector))
-            start = max( start, pSeg->minsize );
+	if ((pModule = (NE_MODULE *)GlobalLock( GetExePtr( selector ) )))
+	{
+	    SEGTABLEENTRY *pSeg = NE_SEG_TABLE( pModule ) + pModule->dgroup - 1;
+	    if (pModule->dgroup && (pSeg->selector == selector)) {
+		start = GlobalSize( GlobalHandle( selector ) );
+		start -= end;
+		end += start;
+		dprintf_local( stddeb," new start %04x, minstart: %04x\n", start, pSeg->minsize + pModule->stack_size);
+	    }
+	}
     }
 #endif
+    ptr = PTR_SEG_OFF_TO_LIN( selector, 0 );
 
     start = LALIGN( max( start, sizeof(INSTANCEDATA) ) );
     heapInfoArena = LALIGN(start + sizeof(LOCALARENA) );
@@ -389,13 +390,85 @@
 }
 
 /***********************************************************************
+ *           LOCAL_GrowHeap
+ */
+static void LOCAL_GrowHeap( WORD ds )
+{
+    HANDLE hseg = GlobalHandle( ds );
+    LONG oldsize = GlobalSize( hseg );
+    LONG end;
+    LOCALHEAPINFO *pHeapInfo;
+    WORD freeArena, lastArena;
+    LOCALARENA *pArena, *pLastArena;
+    char *ptr;
+    
+    /* if nothing can be gained, return */
+    if (oldsize > 0xfff0) return;
+    hseg = GlobalReAlloc( hseg, 0x10000, GMEM_FIXED );
+    ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+    pHeapInfo = LOCAL_GetHeap( ds );
+    if (pHeapInfo == NULL) {
+	fprintf( stderr, "Local_GrowHeap: heap not found\n" );
+	return;
+    }
+    end = GlobalSize( hseg );
+    lastArena = (end - sizeof(LOCALARENA)) & ~3;
+
+      /* Update the HeapInfo */
+    pHeapInfo->items++;
+    freeArena = pHeapInfo->last;
+    pHeapInfo->last = lastArena;
+    pHeapInfo->minsize += end - oldsize;
+    
+      /* grow the old last block */
+      /* FIXME: merge two adjacent free blocks */
+    pArena = ARENA_PTR( ptr, freeArena );
+    pArena->size      = lastArena - freeArena;
+    pArena->next      = lastArena;
+    pArena->free_next = lastArena;
+    
+      /* Initialise the new last block */
+
+    pLastArena = ARENA_PTR( ptr, lastArena );
+    pLastArena->prev      = freeArena | LOCAL_ARENA_FREE;
+    pLastArena->next      = lastArena;  /* this one */
+    pLastArena->size      = LALIGN(sizeof(LOCALARENA));
+    pLastArena->free_prev = freeArena;
+    pLastArena->free_next = lastArena;  /* this one */
+    
+    dprintf_local( stddeb, "Heap expanded\n" );
+    LOCAL_PrintHeap( ds );
+}
+
+/***********************************************************************
  *           LOCAL_Compact
  */
 static WORD LOCAL_Compact( WORD ds, WORD minfree, WORD flags )
 {
-    if (flags & LMEM_NOCOMPACT) return 0;
+    char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+    LOCALHEAPINFO *pInfo;
+    LOCALARENA *pArena;
+    WORD arena;
+    WORD freespace = 0;
     
-    return 0;
+    if (!(pInfo = LOCAL_GetHeap( ds ))) {
+	dprintf_local( stddeb, "Local_FindFreeBlock: Local heap not found\n" );
+	LOCAL_PrintHeap(ds);
+	return 0;
+    }
+
+    arena = pInfo->first;
+    pArena = ARENA_PTR( ptr, arena );
+    while (arena != pArena->free_next) {
+        arena = pArena->free_next;
+        pArena = ARENA_PTR( ptr, arena );
+        if (pArena->size >= freespace) freespace = pArena->size;
+    }
+    
+    if (flags & LMEM_NOCOMPACT) return freespace;
+    
+    if (flags & LMEM_NODISCARD) return freespace;
+    return freespace;
 }
 
 /***********************************************************************
@@ -428,6 +501,8 @@
 
 /***********************************************************************
  *           LOCAL_GetBlock
+ * The segment may get moved around in this function, so all callers
+ * should reset their pointer variables.
  */
 static HLOCAL LOCAL_GetBlock( WORD ds, WORD size, WORD flags )
 {
@@ -448,11 +523,20 @@
       /* Find a suitable free block */
     arena = LOCAL_FindFreeBlock( ds, size );
     if (arena == 0) {
+	/* no space: try to make some */
 	LOCAL_Compact( ds, size, flags );
 	arena = LOCAL_FindFreeBlock( ds, size );
     }
     if (arena == 0) {
+	/* still no space: try to grow the segment */
+	LOCAL_GrowHeap( ds );
+	ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+	pInfo = LOCAL_GetHeap( ds );
+	arena = LOCAL_FindFreeBlock( ds, size );
+    }
+    if (arena == 0) {
 	fprintf( stderr, "Local_GetBlock: not enough space!\n" );
+	return 0;
     }
 
     dprintf_local( stddeb, "LOCAL_GetBlock size = %04x\n", size );
@@ -466,6 +550,10 @@
     }
     LOCAL_RemoveFreeBlock( ptr, arena );
 
+    if (flags & LMEM_ZEROINIT) {
+	memset( (char *)pArena + ARENA_HEADER_SIZE, 0, size - ARENA_HEADER_SIZE );
+    }
+
     dprintf_local( stddeb, "Local_GetBlock: arena at %04x\n", arena );
     return arena + ARENA_HEADER_SIZE;
 }
@@ -487,6 +575,8 @@
     }
 
     handle = LOCAL_GetBlock( ds, pInfo->hdelta*4 + 2, LMEM_FIXED );
+    ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+    pInfo = LOCAL_GetHeap( ds );
     if (handle == 0) return FALSE;
     *(WORD *)(ptr + handle) = 0; /* no handles in this block yet */
     pInfo->htable = handle;
@@ -508,10 +598,16 @@
 	return 0;
     }
     /* Check if we need a new handle table */
-    if (pInfo->htable == 0) 
+    if (pInfo->htable == 0)  {
         if (!LOCAL_NewHTable( ds )) return 0;
-    if (*(WORD *)(ptr + pInfo->htable) == pInfo->hdelta) 
+	ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+	pInfo = LOCAL_GetHeap( ds );
+    }
+    if (*(WORD *)(ptr + pInfo->htable) == pInfo->hdelta) {
         if (!LOCAL_NewHTable( ds )) return 0;
+	ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+	pInfo = LOCAL_GetHeap( ds );
+    }
 
     /* increase count */
     count = (*(WORD *)(ptr + pInfo->htable))++;
@@ -598,7 +694,7 @@
  */
 HLOCAL LOCAL_Alloc( WORD ds, WORD flags, WORD size )
 {
-    char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+    char *ptr;
     HLOCAL handle;
     
     dprintf_local( stddeb, "LocalAlloc: %04x %d ds=%04x\n", flags, size, ds );
@@ -615,6 +711,7 @@
 	    LOCAL_FreeArena( ds, ARENA_HEADER(hmem) );
 	    return 0;
 	}
+	ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
 	*(WORD *)(ptr + hmem) = handle;
 	plhe = (LOCALHANDLEENTRY *)(ptr + handle);
 	plhe->addr = hmem + 2;
@@ -636,7 +733,8 @@
     char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
     LOCALHEAPINFO *pInfo;
     LOCALARENA *pArena, *pNext;
-    WORD arena, newhandle, blockhandle, nextarena;
+    WORD arena, newhandle, blockhandle;
+    LONG nextarena;
 
     dprintf_local( stddeb, "LocalReAlloc: %04x %d %04x ds=%04x\n",
                    handle, size, flags, ds );
@@ -701,6 +799,7 @@
 
     newhandle = LOCAL_GetBlock( ds, size, flags );
     if (newhandle == 0) return 0;
+    ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
     memcpy( ptr + newhandle, ptr + (arena + ARENA_HEADER_SIZE), size );
     LOCAL_FreeArena( ds, arena );
     if (HANDLE_MOVEABLE( handle )) {
@@ -715,13 +814,49 @@
 
 
 /***********************************************************************
+ *           LOCAL_Lock
+ */
+WORD LOCAL_Lock( WORD ds, HLOCAL handle )
+{
+    char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
+
+    dprintf_local( stddeb, "LocalLock: %04x ", handle );
+    if (HANDLE_MOVEABLE(handle)) {
+	handle = *(WORD *)(ptr + handle);
+    }
+    dprintf_local( stddeb, "returning %04x\n", handle );
+    return handle;
+}
+
+
+/***********************************************************************
+ *           LOCAL_Unlock
+ */
+BOOL LOCAL_Unlock( WORD ds, HLOCAL handle )
+{
+    return TRUE;
+}
+
+
+/***********************************************************************
  *           LOCAL_Size
  *
  * Implementation of LocalSize().
  */
 WORD LOCAL_Size( WORD ds, HLOCAL handle )
 {
-    LOCALARENA *pArena = PTR_SEG_OFF_TO_LIN( ds, handle - ARENA_HEADER_SIZE );
+    char *ptr = PTR_SEG_OFF_TO_LIN( CURRENT_DS, 0 );
+    LOCALARENA *pArena;
+    WORD arena;
+
+    dprintf_local( stddeb, "LocalSize: %04x ds=%04x\n", handle, ds );
+    
+    if (HANDLE_FIXED( handle )) {
+	arena = ARENA_HEADER( handle );
+    } else {
+	arena = ARENA_HEADER( handle = *(WORD *)(ptr + handle) );
+    }
+    pArena = ARENA_PTR( ptr, arena );
     return pArena->next - handle;
 }
 
@@ -771,12 +906,7 @@
  */
 WORD LocalLock( HLOCAL handle )
 {
-    char *ptr = PTR_SEG_OFF_TO_LIN( CURRENT_DS, 0 );
-
-    if (HANDLE_MOVEABLE(handle)) {
-	handle = *(WORD *)(ptr + handle);
-    }
-    return handle;
+    return LOCAL_Lock( CURRENT_DS, handle );
 }
 
 
@@ -785,7 +915,7 @@
  */
 BOOL LocalUnlock( HLOCAL handle )
 {
-    return TRUE;
+    return LOCAL_Unlock( CURRENT_DS, handle );
 }
 
 
@@ -829,7 +959,7 @@
 WORD LocalCompact( WORD minfree )
 {
     dprintf_local( stddeb, "LocalCompact: %04x\n", minfree );
-    return 0;
+    return LOCAL_Compact( CURRENT_DS, minfree, 0 );
 }
 
 
diff --git a/memory/selector.c b/memory/selector.c
index 367aae2..57afc7f 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -11,7 +11,6 @@
 #include "stddebug.h"
 #include "debug.h"
 
-ldt_copy_entry ldt_copy[LDT_SIZE] = { {0,0}, };
 
 #define FIRST_LDT_ENTRY_TO_ALLOC  6
 
@@ -323,12 +322,12 @@
     ldt_entry entry;
 
     sel = SELECTOROF(lpfn);
-    if (!sel) return FALSE;
-    if (IS_SELECTOR_FREE(sel)) return FALSE;
+    if (!sel) return TRUE;
+    if (IS_SELECTOR_FREE(sel)) return TRUE;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
-    if (entry.type != SEGMENT_CODE) return FALSE;
-    if (OFFSETOF(lpfn) > entry.limit) return FALSE;
-    return TRUE;
+    if (entry.type != SEGMENT_CODE) return TRUE;
+    if (OFFSETOF(lpfn) > entry.limit) return TRUE;
+    return FALSE;
 }
 
 
@@ -341,13 +340,13 @@
     ldt_entry entry;
 
     sel = SELECTOROF(ptr);
-    if (!sel) return FALSE;
-    if (IS_SELECTOR_FREE(sel)) return FALSE;
+    if (!sel) return TRUE;
+    if (IS_SELECTOR_FREE(sel)) return TRUE;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
-    if ((entry.type == SEGMENT_CODE) && entry.read_only) return FALSE;
+    if ((entry.type == SEGMENT_CODE) && entry.read_only) return TRUE;
     if (strlen(PTR_SEG_TO_LIN(ptr)) < size) size = strlen(PTR_SEG_TO_LIN(ptr));
-    if (OFFSETOF(ptr) + size > entry.limit) return FALSE;
-    return TRUE;
+    if (OFFSETOF(ptr) + size > entry.limit) return TRUE;
+    return FALSE;
 }
 
 
@@ -360,12 +359,12 @@
     ldt_entry entry;
 
     sel = SELECTOROF(ptr);
-    if (!sel) return FALSE;
-    if (IS_SELECTOR_FREE(sel)) return FALSE;
+    if (!sel) return TRUE;
+    if (IS_SELECTOR_FREE(sel)) return TRUE;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
-    if ((entry.type == SEGMENT_CODE) && entry.read_only) return FALSE;
-    if (OFFSETOF(ptr) + size > entry.limit) return FALSE;
-    return TRUE;
+    if ((entry.type == SEGMENT_CODE) && entry.read_only) return TRUE;
+    if (OFFSETOF(ptr) + size > entry.limit) return TRUE;
+    return FALSE;
 }
 
 
@@ -378,12 +377,12 @@
     ldt_entry entry;
 
     sel = SELECTOROF(ptr);
-    if (!sel) return FALSE;
-    if (IS_SELECTOR_FREE(sel)) return FALSE;
+    if (!sel) return TRUE;
+    if (IS_SELECTOR_FREE(sel)) return TRUE;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
-    if ((entry.type == SEGMENT_CODE) || entry.read_only) return FALSE;
-    if (OFFSETOF(ptr) + size > entry.limit) return FALSE;
-    return TRUE;
+    if ((entry.type == SEGMENT_CODE) || entry.read_only) return TRUE;
+    if (OFFSETOF(ptr) + size > entry.limit) return TRUE;
+    return FALSE;
 }
 
 /***********************************************************************
diff --git a/misc/Imakefile b/misc/Imakefile
index 36b097a..bbf9b32 100644
--- a/misc/Imakefile
+++ b/misc/Imakefile
@@ -17,6 +17,7 @@
 	kernel32.c \
 	lstr.c \
 	main.c \
+	ole2.c \
 	ole2nls.c \
 	olecli.c \
 	olesvr.c \
diff --git a/misc/commdlg.c b/misc/commdlg.c
index 47d08ed..2383229 100644
--- a/misc/commdlg.c
+++ b/misc/commdlg.c
@@ -210,23 +210,23 @@
 static LONG FILEDLG_WMDrawItem(HWND hWnd, WORD wParam, LONG lParam)
 {
     LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
-    LPSTR str;
+    char str[512];
     HBRUSH hBrush;
     HBITMAP hBitmap, hPrevBitmap;
     BITMAP bm;
     HDC hMemDC;
-    
+
+    strcpy(str, "");
     if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
 	hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
 	SelectObject(lpdis->hDC, hBrush);
 	FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
-	str = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
-	if (str != NULL)  {
-	    TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
-		    str, strlen(str));
-	    if (lpdis->itemState != 0) {
-		InvertRect(lpdis->hDC, &lpdis->rcItem);
-	    }
+	SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID, 
+		    MAKE_SEGPTR(str));
+	TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
+		str, strlen(str));
+	if (lpdis->itemState != 0) {
+	    InvertRect(lpdis->hDC, &lpdis->rcItem);
 	}
 	return TRUE;
     }
@@ -235,21 +235,21 @@
 	hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
 	SelectObject(lpdis->hDC, hBrush);
 	FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
-	str = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
-	if (str != NULL)  {
-	    hBitmap = hFolder;
-	    GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
-	    TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth, 
-		    lpdis->rcItem.top, str, strlen(str));
-	    hMemDC = CreateCompatibleDC(lpdis->hDC);
-	    hPrevBitmap = SelectObject(hMemDC, hBitmap);
-	    BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
-		   bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-	    SelectObject(hMemDC, hPrevBitmap);
-	    DeleteDC(hMemDC);
-	    if (lpdis->itemState != 0) {
-		InvertRect(lpdis->hDC, &lpdis->rcItem);
-	    }
+	SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID, 
+		    MAKE_SEGPTR(str));
+
+	hBitmap = hFolder;
+	GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
+	TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth, 
+		lpdis->rcItem.top, str, strlen(str));
+	hMemDC = CreateCompatibleDC(lpdis->hDC);
+	hPrevBitmap = SelectObject(hMemDC, hBitmap);
+	BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
+	       bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
+	SelectObject(hMemDC, hPrevBitmap);
+	DeleteDC(hMemDC);
+	if (lpdis->itemState != 0) {
+	    InvertRect(lpdis->hDC, &lpdis->rcItem);
 	}
 	return TRUE;
     }
@@ -257,28 +257,27 @@
 	hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
 	SelectObject(lpdis->hDC, hBrush);
 	FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
-	str = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
-	if (str != NULL) {
-	    switch(str[2]) {
-	     case 'a': case 'b':
-		hBitmap = hFloppy;
-		break;
-	     default:
-		hBitmap = hHDisk;
-		break;
-	    }
-	    GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
-	    TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth, 
-		    lpdis->rcItem.top, str, strlen(str));
-	    hMemDC = CreateCompatibleDC(lpdis->hDC);
-	    hPrevBitmap = SelectObject(hMemDC, hBitmap);
-	    BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
-		   bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-	    SelectObject(hMemDC, hPrevBitmap);
-	    DeleteDC(hMemDC);
-	    if (lpdis->itemState != 0) {
-		InvertRect(lpdis->hDC, &lpdis->rcItem);
-	    }
+	SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID, 
+		    MAKE_SEGPTR(str));
+	switch(str[2]) {
+	 case 'a': case 'b':
+	    hBitmap = hFloppy;
+	    break;
+	 default:
+	    hBitmap = hHDisk;
+	    break;
+	}
+	GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
+	TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth, 
+		lpdis->rcItem.top, str, strlen(str));
+	hMemDC = CreateCompatibleDC(lpdis->hDC);
+	hPrevBitmap = SelectObject(hMemDC, hBitmap);
+	BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
+	       bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
+	SelectObject(hMemDC, hPrevBitmap);
+	DeleteDC(hMemDC);
+	if (lpdis->itemState != 0) {
+	    InvertRect(lpdis->hDC, &lpdis->rcItem);
 	}
 	return TRUE;
     }
diff --git a/misc/compobj.c b/misc/compobj.c
index 690cfa4..b4a0f9f 100644
--- a/misc/compobj.c
+++ b/misc/compobj.c
@@ -10,10 +10,37 @@
 #include "windows.h"
 #include "compobj.h"
 #include "ole.h"
+#include "ole2.h"
 #include "stddebug.h"
 #include "debug.h"
 
 /***********************************************************************
+ *           CoBuildVersion [COMPOBJ.1]
+ */
+DWORD WINAPI CoBuildVersion()
+{
+	dprintf_ole(stddeb,"CoBuildVersion()\n");
+	return (rmm<<16)+rup;
+}
+
+/***********************************************************************
+ *           CoInitialize	[COMPOBJ.2]
+ */
+HRESULT WINAPI CoInitialize(LPVOID lpReserved)
+{
+	dprintf_ole(stdnimp,"CoInitialize\n");
+	return S_OK;
+}
+
+/***********************************************************************
+ *           CoUnitialize   [COMPOBJ.3]
+ */
+void CoUnitialize()
+{
+	dprintf_ole(stdnimp,"CoUnitialize()\n");
+}
+
+/***********************************************************************
  *           CoDisconnectObject
  */
 OLESTATUS WINAPI CoDisconnectObject(
diff --git a/misc/dos_fs.c b/misc/dos_fs.c
index c26f69ba..c9864c8 100644
--- a/misc/dos_fs.c
+++ b/misc/dos_fs.c
@@ -301,7 +301,7 @@
 
         dprintf_dosfs(stddeb,"ValidDrive %c (%d) -- ",'A'+drive,drive);
 
-	if (drive >= MAX_DOS_DRIVES)
+	if (drive < 0 || drive >= MAX_DOS_DRIVES)
 		valid = 0;
 	if (DosDrives[drive].rootdir == NULL)
 		valid = 0;
@@ -446,12 +446,14 @@
 char *DOS_GetUnixFileName(char *dosfilename)
 { 
 	/*   a:\windows\system.ini  =>  /dos/windows/system.ini */
-	
+
+        /* FIXME: should handle devices here (like LPT: or NUL:) */
+
 	static char temp[256];
 	static char dostemp[256];
 	int drive;
 
-	if (dosfilename[1] == ':') 
+	if (dosfilename[0] && (dosfilename[1] == ':'))
 	{
 		drive = (islower(*dosfilename) ? toupper(*dosfilename) : *dosfilename) - 'A';
 		
@@ -463,7 +465,8 @@
 		drive = CurrentDrive;
 
 	/* Consider dosfilename const */
-	strcpy(dostemp,dosfilename);
+	strncpy( dostemp, dosfilename, 255 );
+        dostemp[255] = '\0';
 
         /* Expand the filename to it's full path if it doesn't
          * start from the root.
@@ -675,7 +678,7 @@
     char *workingpath, *dirname, *rootname, **e;
     DIR *d;
     struct dirent *f;
-    int rootnamelen, found = 0;
+    int rootnamelen;
     struct stat filestat;
 
     if (strchr(filename, '\\') != NULL)
@@ -713,41 +716,35 @@
 	if (d != NULL)
 	{
 	    while ((f = readdir(d)) != NULL)
-	    {
-		if (strncasecmp(rootname, f->d_name, rootnamelen) == 0)
-		{
-		    if (extensions == NULL || 
-			strcasecmp(rootname, f->d_name) == 0)
-				found = 1;
-		    else 
-		    if (f->d_name[rootnamelen] == '.')
-			for (e = extensions; *e != NULL; e++)
-			    if (strcasecmp(*e, f->d_name + rootnamelen + 1) 
-				== 0)
-			    {
-				found = 1;
-				break;
-			    }
+	    {		
+		if (strcasecmp(rootname, f->d_name) != 0) {
+		    if (strncasecmp(rootname, f->d_name, rootnamelen) != 0
+		      || extensions == NULL 
+		      || f->d_name[rootnamelen] != '.')
+		        continue;
 
-		    if (found)
-		    {
-			if (strchr(dirname, '\\') != NULL)
-				strncpy(buffer, DOS_GetUnixFileName(dirname), buflen);
-			else
-				strncpy(buffer, dirname, buflen);
-
-			strncat(buffer, "/", buflen - strlen(buffer));
-			strncat(buffer, f->d_name, buflen - strlen(buffer));
-
-			stat(buffer, &filestat);
-			if (S_ISREG(filestat.st_mode)) {
-				closedir(d);
-				free(rootname);
-				return buffer;
-		    	} else 
-		    		found = 0; 
+		    for (e = extensions; *e != NULL; e++) {
+			if (strcasecmp(*e, f->d_name + rootnamelen + 1) == 0)
+			    break;
 		    }
+		    if (*e == NULL) continue;
 		}
+
+		if (strchr(dirname, '\\') != NULL) {
+		    strncpy(buffer, DOS_GetUnixFileName(dirname), buflen);
+		} else {
+		    strncpy(buffer, dirname, buflen);
+		}
+
+		strncat(buffer, "/", buflen - strlen(buffer));
+		strncat(buffer, f->d_name, buflen - strlen(buffer));
+		
+		stat(buffer, &filestat);
+		if (S_ISREG(filestat.st_mode)) {
+		    closedir(d);
+		    free(rootname);
+		    return buffer;
+		} 
 	    }
 	    closedir(d);
 	}
@@ -897,7 +894,8 @@
 	  if (strcmp(DosDirs[x].unixpath,temp) == 0) break;
 	}
         
-        strcpy(DosDirs[x].filemask, unixdirname);
+        strncpy(DosDirs[x].filemask, unixdirname, 12);
+        DosDirs[x].filemask[12] = 0;
         ToDos(DosDirs[x].filemask);
     	dprintf_dosfs(stddeb,"DOS_opendir: %s / %s\n", unixdirname, temp);
 
diff --git a/misc/exec.c b/misc/exec.c
index ad55c1c..635f4bd 100644
--- a/misc/exec.c
+++ b/misc/exec.c
@@ -34,12 +34,15 @@
 /**********************************************************************
  *				ExitWindows		[USER.7]
  */
-BOOL ExitWindows(DWORD dwReserved, WORD wRetCode)
+BOOL ExitWindows(DWORD dwReturnCode, WORD wReserved)
 {
-    dprintf_exec(stdnimp,"EMPTY STUB !!! ExitWindows(%08lX, %04X) !\n", 
-		dwReserved, wRetCode);
+    api_assert("ExitWindows", wReserved == 0);
+    api_assert("ExitWindows", HIWORD(dwReturnCode) == 0);
 
-   exit(wRetCode);
+    dprintf_exec( stdnimp,"PARTIAL STUB ExitWindows(%08lX, %04X)\n", 
+                  dwReturnCode, wReserved);
+
+    exit( LOWORD(dwReturnCode) );
 }
 
 
diff --git a/misc/file.c b/misc/file.c
index 31c2cfc..5c5eee4 100644
--- a/misc/file.c
+++ b/misc/file.c
@@ -86,19 +86,19 @@
 /****************************************************************************
  _lwrite
 ****************************************************************************/
-INT _lwrite (INT hFile, LPSTR lpBuffer, WORD wBytes)
+INT _lwrite (INT hFile, LPCSTR lpBuffer, WORD wBytes)
 {
-	int result;
+    int result;
 
-  dprintf_file(stddeb, "_lwrite: handle %d, buffer = %ld, length = %d\n",
-	  		hFile, (long) lpBuffer, wBytes);
+    dprintf_file(stddeb, "_lwrite: handle %d, buffer = %ld, length = %d\n",
+		 hFile, (long) lpBuffer, wBytes);
 
     result = write (hFile, lpBuffer, wBytes);
 
-	if (result == -1)
-  		return HFILE_ERROR;
-  	else
-  		return result;
+    if (result == -1)
+        return HFILE_ERROR;
+    else
+        return result;
 }
 
 /***************************************************************************
@@ -106,11 +106,16 @@
  ***************************************************************************/
 INT _lclose (INT hFile)
 {
-    	dprintf_file(stddeb, "_lclose: handle %d\n", hFile);
-	if (close (hFile))
-  		return HFILE_ERROR;
-  	else
-  		return 0;
+    dprintf_file(stddeb, "_lclose: handle %d\n", hFile);
+    
+    if (hFile == 1 || hFile == 2) {
+	fprintf( stderr, "Program attempted to close stdout or stderr!\n" );
+	return 0;
+    }
+    if (close (hFile))
+        return HFILE_ERROR;
+    else
+        return 0;
 }
 
 /**************************************************************************
@@ -123,7 +128,7 @@
     struct stat  s;
     struct tm   *now;
     int          res, handle;
-    int          verify_time;
+    int          verify_time = 0;
   
     dprintf_file(stddeb,"Openfile(%s,<struct>,%d)\n",lpFileName,wStyle);
   
@@ -162,64 +167,62 @@
     /* If path isn't given, try to find the file. */
 
     if (!(action & OF_REOPEN))
-      {
-	if( !( index(lpFileName,'\\') || index(lpFileName,'/') || 
-	      index(lpFileName,':')))
-	while(1)
+    {
+	char temp[MAX_PATH + 1];
+	
+	if(index(lpFileName,'\\') || index(lpFileName,'/') || 
+	   index(lpFileName,':')) 
 	{
-          char temp[MAX_PATH+1];
-          /* Try current directory */
-	  strcpy (filename, lpFileName);
-	  if ( (!stat(DOS_GetUnixFileName(filename), &s)) && (S_ISREG(s.st_mode)) )
-	    break;
-
-          /* Try Windows directory */
-
-	  GetWindowsDirectory (filename,MAX_PATH);
-	  if ((!filename[0])||(filename[strlen(filename)-1]!='\\'))
-            strcat(filename, "\\");
-	  strcat (filename, lpFileName);
-	  if ( (!stat(DOS_GetUnixFileName(filename), &s)) && (S_ISREG(s.st_mode)) )
-	    break;
-
-          /* Try Windows system directory */
-
-	  GetSystemDirectory (filename,MAX_PATH);
-	  if ((!filename[0])||(filename[strlen(filename)-1]!='\\'))
- 	    strcat(filename, "\\");
-	  strcat (filename, lpFileName);
-	  if ( (!stat(DOS_GetUnixFileName(filename), &s)) && (S_ISREG(s.st_mode)) )
-	    break;
-
-          /* Try the path of the current executable */
-
-          if (GetCurrentTask())
-          {
-              char *p;
-              GetModuleFileName( GetCurrentTask(), filename, MAX_PATH );
-              if ((p = strrchr( filename, '\\' )))
-              {
-                  p[1] = '\0';
-                  strcat( filename, lpFileName );
-                  if ((!stat(DOS_GetUnixFileName(filename), &s)) &&
-                      (S_ISREG(s.st_mode)) )
-                      break;
-              }
-          }
-
-          /* Try all directories in path */
-
-	  if (DOS_FindFile(temp,MAX_PATH,lpFileName,NULL,WindowsPath))
-          {
-	      strcpy(filename, DOS_GetDosFileName(temp));
-	      break;
-          }
-	  strcpy (filename, lpFileName);
-	  break;
+	    strcpy (filename,lpFileName);
+	    goto found;
 	}
-	else
-	  strcpy (filename,lpFileName);
+	/* Try current directory */
+	if (DOS_FindFile(temp, MAX_PATH, lpFileName, NULL, ".")) {
+	    strcpy(filename, DOS_GetDosFileName(temp));
+	    goto found;
+	}
 
+	/* Try Windows directory */
+	GetWindowsDirectory(filename, MAX_PATH);
+	if (DOS_FindFile(temp, MAX_PATH, lpFileName, NULL, filename)) {
+	    strcpy(filename, DOS_GetDosFileName(temp));
+	    goto found;
+	}
+	
+	/* Try Windows system directory */
+	GetSystemDirectory(filename, MAX_PATH);
+	if (DOS_FindFile(temp, MAX_PATH, lpFileName, NULL, filename)) {
+	    strcpy(filename, DOS_GetDosFileName(temp));
+	    goto found;
+	}
+
+	/* Try the path of the current executable */
+	if (GetCurrentTask())
+	{
+	    char *p;
+	    GetModuleFileName( GetCurrentTask(), filename, MAX_PATH );
+	    if ((p = strrchr( filename, '\\' )))
+	    {
+		p[1] = '\0';
+		if (DOS_FindFile(temp, MAX_PATH, lpFileName, NULL, filename)) {
+		    strcpy(filename, DOS_GetDosFileName(temp));
+		    goto found;
+		}
+	    }
+	}
+
+	/* Try all directories in path */
+
+	if (DOS_FindFile(temp,MAX_PATH,lpFileName,NULL,WindowsPath))
+	{
+	    strcpy(filename, DOS_GetDosFileName(temp));
+	    goto found;
+	}
+	/* ??? shouldn't we give an error here? */
+	strcpy (filename, lpFileName);
+	
+	found:
+	
 	ofs->cBytes = sizeof(OFSTRUCT);
 	ofs->fFixedDisk = FALSE;
 	strcpy(ofs->szPathName, filename);
@@ -305,9 +308,9 @@
 			break;
 		default: origin = SEEK_SET;
 			break;
-		}
+	}
 
-	return ( lseek(hFile, lOffset, origin) );
+	return lseek(hFile, lOffset, origin);
 }
 
 /***************************************************************************
@@ -413,7 +416,7 @@
 		lpszPrefixString,uUnique,lpszTempFileName);
 	if ((handle = _lcreat (lpszTempFileName, 0x0000)) == -1) {
 		fprintf(stderr,"GetTempFilename: can't create temp file '%s' !\n", lpszTempFileName);
-		}
+	}
 	else
 		close(handle);
 
@@ -440,7 +443,7 @@
 /***************************************************************************
  _hwrite
  ***************************************************************************/
-LONG _hwrite(INT hf, const LPSTR hpvBuffer, LONG cbBuffer)
+LONG _hwrite(INT hf, LPCSTR hpvBuffer, LONG cbBuffer)
 {
 	return write(hf, hpvBuffer, cbBuffer);
 }
diff --git a/misc/main.c b/misc/main.c
index c174132..5af55c2 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -550,7 +550,7 @@
  */
 LONG GetVersion(void)
 {
-	return( 0x03300a03 ); /*  dos 3.30 & win 3.10 */
+    return MAKELONG( WINVERSION, DOSVERSION );
 }
 
 /***********************************************************************
diff --git a/misc/ole2.c b/misc/ole2.c
new file mode 100644
index 0000000..e5ae3c7
--- /dev/null
+++ b/misc/ole2.c
@@ -0,0 +1,39 @@
+/*
+ *	OLE2 library
+ *
+ *	Copyright 1995	Martin von Loewis
+ */
+
+/*	At the moment, these are only empty stubs.
+ */
+
+#include "windows.h"
+#include "ole2.h"
+#include "stddebug.h"
+#include "debug.h"
+
+/***********************************************************************
+ *           OleBuildVersion     [OLE.1]
+ */
+DWORD OleBuildVersion()
+{
+	dprintf_ole(stddeb,"OleBuildVersion()\n");
+	return (rmm<<16)+rup;
+}
+
+/***********************************************************************
+ *           OleInitialize       [OLE2.2]
+ */
+HRESULT WINAPI OleInitialize(LPVOID reserved)
+{
+    dprintf_ole(stdnimp,"OleInitialize\n");
+	return S_OK;
+}
+
+/***********************************************************************
+ *           OleUnitialize       [OLE2.3]
+ */
+void WINAPI OleUninitialize()
+{
+	dprintf_ole(stdnimp,"OleUninitialize()\n");
+}
diff --git a/misc/ole2nls.c b/misc/ole2nls.c
index 68cbaa4..de78508 100644
--- a/misc/ole2nls.c
+++ b/misc/ole2nls.c
@@ -7,8 +7,10 @@
 /*	At the moment, these are only empty stubs.
  */
 
+#include <string.h>
 #include "windows.h"
 #include "ole.h"
+#include "winnls.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -53,3 +55,277 @@
 {
 	return GetUserDefaultLangID();
 }
+
+/***********************************************************************
+ *         GetLocaleInfoA             (OLE2NLS.5)
+ * Is the last parameter really WORD for Win16?
+ */
+int WINAPI GetLocaleInfoA(DWORD lcid,DWORD LCType,LPSTR buf,WORD len)
+{
+	char *retString;
+    int retLen;
+    dprintf_ole(stddeb,"GetLocaleInfoA(%8lX,%8lX,%p,%4X)\n",
+			lcid,LCType,buf,len);
+	/* Wine is supporting only the default locale */
+	if(lcid!=GetUserDefaultLCID())
+	{
+		dprintf_ole(stdnimp,"GetLocaleInfoA: Unknown locale\n");
+		return 0;
+	}
+	/* As an option, we could obtain the value from win.ini.
+	   This would not match the Wine compile-time option.
+	   Also, not all identifiers are available from win.ini */
+	retString=0;
+	retLen=0;
+	/* If we are through all of this, retLen should not be zero anymore.
+	   If it is, the value is not supported */
+#define LOCVAL(type,value)	if(type==LCType)			\
+								{retLen=strlen(value)+1;\
+								 retString=value;       \
+								}
+#define UNSUPPORTED(type)   if(type==lcid)retString=#type;
+
+/* I really wish I would know a better way to do this */
+UNSUPPORTED(LOCALE_ILANGUAGE)
+UNSUPPORTED(LOCALE_SLANGUAGE)
+UNSUPPORTED(LOCALE_SENGLANGUAGE)
+UNSUPPORTED(LOCALE_SABBREVLANGNAME)
+UNSUPPORTED(LOCALE_SNATIVELANGNAME)
+UNSUPPORTED(LOCALE_ICOUNTRY)
+UNSUPPORTED(LOCALE_SCOUNTRY)
+UNSUPPORTED(LOCALE_SENGCOUNTRY)
+UNSUPPORTED(LOCALE_SABBREVCTRYNAME)
+UNSUPPORTED(LOCALE_SNATIVECTRYNAME)
+UNSUPPORTED(LOCALE_IDEFAULTLANGUAGE)
+UNSUPPORTED(LOCALE_IDEFAULTCOUNTRY)
+UNSUPPORTED(LOCALE_IDEFAULTCODEPAGE)
+UNSUPPORTED(LOCALE_IDEFAULTANSICODEPAGE)
+UNSUPPORTED(LOCALE_SLIST)
+UNSUPPORTED(LOCALE_IMEASURE)
+UNSUPPORTED(LOCALE_SDECIMAL)
+UNSUPPORTED(LOCALE_STHOUSAND)
+UNSUPPORTED(LOCALE_SGROUPING)
+UNSUPPORTED(LOCALE_IDIGITS)
+UNSUPPORTED(LOCALE_ILZERO)
+UNSUPPORTED(LOCALE_INEGNUMBER)
+UNSUPPORTED(LOCALE_SNATIVEDIGITS)
+UNSUPPORTED(LOCALE_SCURRENCY)
+UNSUPPORTED(LOCALE_SINTLSYMBOL)
+UNSUPPORTED(LOCALE_SMONDECIMALSEP)
+UNSUPPORTED(LOCALE_SMONTHOUSANDSEP)
+UNSUPPORTED(LOCALE_SMONGROUPING)
+UNSUPPORTED(LOCALE_ICURRDIGITS)
+UNSUPPORTED(LOCALE_IINTLCURRDIGITS)
+UNSUPPORTED(LOCALE_ICURRENCY)
+UNSUPPORTED(LOCALE_INEGCURR)
+UNSUPPORTED(LOCALE_SDATE)
+UNSUPPORTED(LOCALE_STIME)
+UNSUPPORTED(LOCALE_SSHORTDATE)
+UNSUPPORTED(LOCALE_SLONGDATE)
+UNSUPPORTED(LOCALE_STIMEFORMAT)
+UNSUPPORTED(LOCALE_IDATE)
+UNSUPPORTED(LOCALE_ILDATE)
+UNSUPPORTED(LOCALE_ITIME)
+UNSUPPORTED(LOCALE_ITIMEMARKPOSN)
+UNSUPPORTED(LOCALE_ICENTURY)
+UNSUPPORTED(LOCALE_ITLZERO)
+UNSUPPORTED(LOCALE_IDAYLZERO)
+UNSUPPORTED(LOCALE_IMONLZERO)
+UNSUPPORTED(LOCALE_S1159)
+UNSUPPORTED(LOCALE_S2359)
+UNSUPPORTED(LOCALE_ICALENDARTYPE)
+UNSUPPORTED(LOCALE_IOPTIONALCALENDAR)
+UNSUPPORTED(LOCALE_IFIRSTDAYOFWEEK)
+UNSUPPORTED(LOCALE_IFIRSTWEEKOFYEAR)
+UNSUPPORTED(LOCALE_SDAYNAME1)
+UNSUPPORTED(LOCALE_SDAYNAME2)
+UNSUPPORTED(LOCALE_SDAYNAME3)
+UNSUPPORTED(LOCALE_SDAYNAME4)
+UNSUPPORTED(LOCALE_SDAYNAME5)
+UNSUPPORTED(LOCALE_SDAYNAME6)
+UNSUPPORTED(LOCALE_SDAYNAME7)
+UNSUPPORTED(LOCALE_SABBREVDAYNAME1)
+UNSUPPORTED(LOCALE_SABBREVDAYNAME2)
+UNSUPPORTED(LOCALE_SABBREVDAYNAME3)
+UNSUPPORTED(LOCALE_SABBREVDAYNAME4)
+UNSUPPORTED(LOCALE_SABBREVDAYNAME5)
+UNSUPPORTED(LOCALE_SABBREVDAYNAME6)
+UNSUPPORTED(LOCALE_SABBREVDAYNAME7)
+UNSUPPORTED(LOCALE_SMONTHNAME1)
+UNSUPPORTED(LOCALE_SMONTHNAME2)
+UNSUPPORTED(LOCALE_SMONTHNAME3)
+UNSUPPORTED(LOCALE_SMONTHNAME4)
+UNSUPPORTED(LOCALE_SMONTHNAME5)
+UNSUPPORTED(LOCALE_SMONTHNAME6)
+UNSUPPORTED(LOCALE_SMONTHNAME7)
+UNSUPPORTED(LOCALE_SMONTHNAME8)
+UNSUPPORTED(LOCALE_SMONTHNAME9)
+UNSUPPORTED(LOCALE_SMONTHNAME10)
+UNSUPPORTED(LOCALE_SMONTHNAME11)
+UNSUPPORTED(LOCALE_SMONTHNAME12)
+UNSUPPORTED(LOCALE_SMONTHNAME13)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME1)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME2)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME3)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME4)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME5)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME6)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME7)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME8)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME9)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME10)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME11)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME12)
+UNSUPPORTED(LOCALE_SABBREVMONTHNAME13)
+UNSUPPORTED(LOCALE_SPOSITIVESIGN)
+UNSUPPORTED(LOCALE_SNEGATIVESIGN)
+UNSUPPORTED(LOCALE_IPOSSIGNPOSN)
+UNSUPPORTED(LOCALE_INEGSIGNPOSN)
+UNSUPPORTED(LOCALE_IPOSSYMPRECEDES)
+UNSUPPORTED(LOCALE_IPOSSEPBYSPACE)
+UNSUPPORTED(LOCALE_INEGSYMPRECEDES)
+UNSUPPORTED(LOCALE_INEGSEPBYSPACE)
+
+/* Now, the language specific definitions. They don't have to be
+   complete */
+#if #LANG(De)
+/* This definitions apply to Germany only. Users in Austria 
+   or Switzerland might want to modify them */
+LOCVAL(LOCALE_ILANGUAGE,"9")
+LOCVAL(LOCALE_SLANGUAGE,"Deutsch")
+LOCVAL(LOCALE_SENGLANGUAGE,"German")
+LOCVAL(LOCALE_SABBREVLANGNAME,"deu")
+LOCVAL(LOCALE_SNATIVELANGNAME,"Deutsch")
+LOCVAL(LOCALE_ICOUNTRY,"49")
+LOCVAL(LOCALE_SCOUNTRY,"Deutschland")
+LOCVAL(LOCALE_SENGCOUNTRY,"Deutschland")
+LOCVAL(LOCALE_SABBREVCTRYNAME,"De")
+LOCVAL(LOCALE_SNATIVECTRYNAME,"Deutschland")
+LOCVAL(LOCALE_IDEFAULTLANGUAGE,"9")
+LOCVAL(LOCALE_IDEFAULTCOUNTRY,"49")
+/* Dunno
+LOCVAL(LOCALE_IDEFAULTCODEPAGE)
+LOCVAL(LOCALE_IDEFAULTANSICODEPAGE)
+*/
+LOCVAL(LOCALE_SLIST,";")
+LOCVAL(LOCALE_IMEASURE,"0")
+LOCVAL(LOCALE_SDECIMAL,",")
+LOCVAL(LOCALE_STHOUSAND,".")
+/*
+LOCVAL(LOCALE_SGROUPING)
+*/
+LOCVAL(LOCALE_IDIGITS,"2")
+LOCVAL(LOCALE_ILZERO,"1")
+/*
+LOCVAL(LOCALE_INEGNUMBER)
+Is this "0123456789" ??
+LOCVAL(LOCALE_SNATIVEDIGITS)
+*/
+LOCVAL(LOCALE_SCURRENCY,"DM")
+/*
+LOCVAL(LOCALE_SINTLSYMBOL)
+LOCVAL(LOCALE_SMONDECIMALSEP)
+LOCVAL(LOCALE_SMONTHOUSANDSEP)
+LOCVAL(LOCALE_SMONGROUPING)
+*/
+LOCVAL(LOCALE_ICURRDIGITS,"2")
+/*
+LOCVAL(LOCALE_IINTLCURRDIGITS)
+*/
+LOCVAL(LOCALE_ICURRENCY,"3")
+LOCVAL(LOCALE_INEGCURR,"8")
+LOCVAL(LOCALE_SDATE,".")
+LOCVAL(LOCALE_STIME,":")
+LOCVAL(LOCALE_SSHORTDATE,"dd.MM.yyyy")
+LOCVAL(LOCALE_SLONGDATEi,"ddd, d. MMMM yyyy")
+/*
+LOCVAL(LOCALE_STIMEFORMAT)
+*/
+LOCVAL(LOCALE_IDATE,"1")
+/*
+LOCVAL(LOCALE_ILDATE)
+*/
+LOCVAL(LOCALE_ITIME,"1")
+/*
+LOCVAL(LOCALE_ITIMEMARKPOSN)
+LOCVAL(LOCALE_ICENTURY)
+*/
+LOCVAL(LOCALE_ITLZERO,"1")
+/*
+LOCVAL(LOCALE_IDAYLZERO)
+LOCVAL(LOCALE_IMONLZERO)
+LOCVAL(LOCALE_S1159)
+LOCVAL(LOCALE_S2359)
+LOCVAL(LOCALE_ICALENDARTYPE)
+LOCVAL(LOCALE_IOPTIONALCALENDAR)
+LOCVAL(LOCALE_IFIRSTDAYOFWEEK)
+LOCVAL(LOCALE_IFIRSTWEEKOFYEAR)
+*/
+LOCVAL(LOCALE_SDAYNAME1,"Montag")
+LOCVAL(LOCALE_SDAYNAME2,"Dienstag")
+LOCVAL(LOCALE_SDAYNAME3,"Mittwoch")
+LOCVAL(LOCALE_SDAYNAME4,"Donnerstag")
+LOCVAL(LOCALE_SDAYNAME5,"Freitag")
+LOCVAL(LOCALE_SDAYNAME6,"Sonnabend")
+LOCVAL(LOCALE_SDAYNAME7,"Sonntag")
+LOCVAL(LOCALE_SABBREVDAYNAME1,"Mo")
+LOCVAL(LOCALE_SABBREVDAYNAME2,"Di")
+LOCVAL(LOCALE_SABBREVDAYNAME3,"Mi")
+LOCVAL(LOCALE_SABBREVDAYNAME4,"Do")
+LOCVAL(LOCALE_SABBREVDAYNAME5,"Fr")
+LOCVAL(LOCALE_SABBREVDAYNAME6,"Sa")
+LOCVAL(LOCALE_SABBREVDAYNAME7,"So")
+LOCVAL(LOCALE_SMONTHNAME1,"Januar")
+LOCVAL(LOCALE_SMONTHNAME2,"Februar")
+LOCVAL(LOCALE_SMONTHNAME3,"März")
+LOCVAL(LOCALE_SMONTHNAME4,"April")
+LOCVAL(LOCALE_SMONTHNAME5,"Mai")
+LOCVAL(LOCALE_SMONTHNAME6,"Juni")
+LOCVAL(LOCALE_SMONTHNAME7,"Juli")
+LOCVAL(LOCALE_SMONTHNAME8,"August")
+LOCVAL(LOCALE_SMONTHNAME9,"September")
+LOCVAL(LOCALE_SMONTHNAME10,"Oktober")
+LOCVAL(LOCALE_SMONTHNAME11,"November")
+LOCVAL(LOCALE_SMONTHNAME12,"Dezember")
+LOCVAL(LOCALE_SMONTHNAME13,"")
+LOCVAL(LOCALE_SABBREVMONTHNAME1,"Jan")
+LOCVAL(LOCALE_SABBREVMONTHNAME2,"Feb")
+LOCVAL(LOCALE_SABBREVMONTHNAME3,"Mär")
+LOCVAL(LOCALE_SABBREVMONTHNAME4,"Apr")
+LOCVAL(LOCALE_SABBREVMONTHNAME5,"Mai")
+LOCVAL(LOCALE_SABBREVMONTHNAME6,"Jun")
+LOCVAL(LOCALE_SABBREVMONTHNAME7,"Jul")
+LOCVAL(LOCALE_SABBREVMONTHNAME8,"Aug")
+LOCVAL(LOCALE_SABBREVMONTHNAME9,"Sep")
+LOCVAL(LOCALE_SABBREVMONTHNAME10,"Okt")
+LOCVAL(LOCALE_SABBREVMONTHNAME11,"Nov")
+LOCVAL(LOCALE_SABBREVMONTHNAME12,"Dez")
+LOCVAL(LOCALE_SABBREVMONTHNAME13,"")
+/*
+LOCVAL(LOCALE_SPOSITIVESIGN)
+LOCVAL(LOCALE_SNEGATIVESIGN)
+LOCVAL(LOCALE_IPOSSIGNPOSN)
+LOCVAL(LOCALE_INEGSIGNPOSN)
+LOCVAL(LOCALE_IPOSSYMPRECEDES)
+LOCVAL(LOCALE_IPOSSEPBYSPACE)
+LOCVAL(LOCALE_INEGSYMPRECEDES)
+LOCVAL(LOCALE_INEGSEPBYSPACE)
+*/
+#endif /* LANG(De) */
+
+/*Insert other languages here*/
+
+
+
+	if(!retLen)
+	{
+		if(!retString)fprintf(stderr,"Unkown LC type %lX\n",LCType);
+		else fprintf(stderr,"'%s' not supported for your language.\n",
+			retString);
+		return 0;
+	}
+
+	if(retLen>len)retLen=len;
+	strncpy(buf,retString,len);
+	return retLen;
+}
diff --git a/misc/olecli.c b/misc/olecli.c
index 8be7034..0dadd1a 100644
--- a/misc/olecli.c
+++ b/misc/olecli.c
@@ -9,6 +9,7 @@
 
 #include "windows.h"
 #include "ole.h"
+#include "gdi.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -45,3 +46,12 @@
     dprintf_ole(stdnimp,"OleRevokeClientDoc:%ld\n",hServerDoc);
     return OLE_OK;
 }
+
+/***********************************************************************
+ *           OleIsDcMeta
+ */
+BOOL WINAPI OleIsDcMeta(HDC hdc)
+{
+	dprintf_ole(stddeb,"OleIsDCMeta(%04X)\n",hdc);
+	return GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ) != 0;
+}
diff --git a/misc/profile.c b/misc/profile.c
index a1bce12..9cf4c52 100644
--- a/misc/profile.c
+++ b/misc/profile.c
@@ -24,6 +24,8 @@
 #include "wine.h"
 #include "windows.h"
 #include "dos_fs.h"
+#include "module.h"
+#include "toolhelp.h"
 #include "stddebug.h"
 /* #define DEBUG_PROFILE */
 #include "debug.h"
@@ -48,6 +50,7 @@
     
 typedef struct TProfile {
     char *FileName;
+    char *FullName;
     TSecHeader *Section;
     struct TProfile *link;
     int changed;
@@ -70,7 +73,7 @@
     return 0;
 }
 
-static char *GetIniFileName(char *name)
+static char *GetIniFileName(char *name, char *dir)
 {
 	char temp[256];
 
@@ -79,15 +82,15 @@
 
 	if (strchr(name, '\\'))
 		return DOS_GetUnixFileName(name);
-		
-	GetWindowsDirectory(temp, sizeof(temp) );
-	strcat(temp, "\\");
+
+        strcpy(temp, dir);
+        strcat(temp, "\\");
 	strcat(temp, name);
 	
 	return DOS_GetUnixFileName(temp);
 }
 
-static TSecHeader *load (char *filename)
+static TSecHeader *load (char *filename, char **pfullname)
 {
     FILE *f;
     int state;
@@ -95,13 +98,37 @@
     char CharBuffer [STRSIZE];
     char *next, *file;
     char c;
+    char path[MAX_PATH+1];
 
-    file = GetIniFileName(filename);
+    /* Try the Windows directory */
+
+    GetWindowsDirectory(path, sizeof(path));
+    file = GetIniFileName(filename, path);
 
     dprintf_profile(stddeb,"Load %s\n", file);
-    if ((f = fopen (file, "r"))==NULL)
+    f = fopen(file, "r");
+    
+    if (f == NULL) {
+	/* Try the path of the current executable */
+    
+	if (GetCurrentTask())
+	{
+	    char *p;
+	    GetModuleFileName( GetCurrentTask(), path, MAX_PATH );
+	    if ((p = strrchr( path, '\\' )))
+	    {
+		p[1] = '\0';
+		file = GetIniFileName(filename, path);
+		f = fopen(file, "r");
+	    }
+	}
+    }
+    if (f == NULL) {
+	fprintf(stderr, "profile.c: load() can't find file %s\n", filename);
 	return NULL;
-
+    }
+    
+    *pfullname = strdup(file);
     dprintf_profile(stddeb,"Loading %s\n", file);
 
 
@@ -220,7 +247,7 @@
 	New = (TProfile *) xmalloc (sizeof (TProfile));
 	New->link = Base;
 	New->FileName = strdup (FileName);
-	New->Section = load (FileName);
+	New->Section = load (FileName, &New->FullName);
 	New->changed = FALSE;
 	Base = New;
 	section = New->Section;
@@ -242,7 +269,7 @@
 		if (left < 1) {
 			dprintf_profile(stddeb,"GetSetProfile // No more storage for enum !\n");
 			return (Size - 2);
-			}
+		}
 		slen = min(strlen(key->KeyName) + 1, left);
 		dprintf_profile(stddeb,"GetSetProfile // strncpy(%p, %p, %d);\n", 
 				ReturnedString, key->Value, slen);
@@ -376,7 +403,7 @@
     dump_profile (p->link);
     if(!p->changed)
 	return;
-    if ((profile = fopen (GetIniFileName(p->FileName), "w")) != NULL){
+    if ((profile = fopen (p->FullName, "w")) != NULL){
 	dump_sections (profile, p->Section);
 	fclose (profile);
     }
diff --git a/misc/shell.c b/misc/shell.c
index f300710..5ef692c 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -351,15 +351,32 @@
  */
 HINSTANCE ShellExecute(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int iShowCmd)
 {
-        fprintf(stdnimp, "ShellExecute: empty stub\n");
+    char cmd[400];
+    dprintf_exec(stddeb, "ShellExecute(%4X,'%s','%s','%s','%s',%x)\n",
+		hWnd, lpOperation ? lpOperation:"<null>", lpFile ? lpFile:"<null>",
+		lpParameters ? lpParameters : "<null>", 
+		lpDirectory ? lpDirectory : "<null>", iShowCmd);
+    if(lpOperation && !strcasecmp(lpOperation,"print"))
+    {
+        fprintf(stderr, "Shell print %s: not supported\n", lpFile);
+    	return 2; /* file not found */
+    }
+    if(lpOperation && !strcasecmp(lpOperation,"open"))
+    {
+        fprintf(stderr, "ShellExecute: Unknown operation %s\n",lpOperation);
         return 2;
-	fprintf(stdnimp, "ShellExecute // hWnd=%04X\n", hWnd);  
-	fprintf(stdnimp, "ShellExecute // lpOperation='%s'\n", lpOperation);
-	fprintf(stdnimp, "ShellExecute // lpFile='%s'\n", lpFile);
-	fprintf(stdnimp, "ShellExecute // lpParameters='%s'\n", lpParameters);
-	fprintf(stdnimp, "ShellExecute // lpDirectory='%s'\n", lpDirectory);
-	fprintf(stdnimp, "ShellExecute // iShowCmd=%04X\n", iShowCmd);
-	return 2; /* file not found */
+    }
+    /* OK. We are supposed to lookup the program associated with lpFile,
+       then to execute it using that program. If lpFile is a program,
+       we have to pass the parameters. If an instance is already running,
+       we might have to send DDE commands.
+       This implementation does none of that. It assumes lpFile is a program.
+       Plain WinExec will do what we need */
+    if(lpParameters)
+        sprintf(cmd,"%s %s",lpFile,lpParameters);
+    else
+        strcpy(cmd,lpFile);
+    return WinExec(cmd,iShowCmd);
 }
 
 
@@ -430,8 +447,9 @@
 	HINSTANCE hInst2 = hInst;
 	dprintf_reg(stddeb, "ExtractIcon(%04X, '%s', %d\n", 
 			hInst, lpszExeFileName, nIconIndex);
+        return 0;
 	if (lpszExeFileName != NULL) {
-		hInst2 = LoadLibrary(lpszExeFileName);
+		hInst2 = LoadModule(lpszExeFileName,(LPVOID)-1);
 	}
 	if (hInst2 != 0 && nIconIndex == (UINT)-1) {
 #if 0
diff --git a/misc/spy.c b/misc/spy.c
index 524392c..7c82b10 100644
--- a/misc/spy.c
+++ b/misc/spy.c
@@ -288,6 +288,7 @@
  */
 void SpyInit(void)
 {
+#ifndef NOSPY
     char filename[100];
 
     if (SpyFp != NULL)
@@ -322,4 +323,5 @@
     if (*SpyFilters != 0) {
       strcat(SpyFilters, ";");
     }
+#endif
 }
diff --git a/miscemu/Imakefile b/miscemu/Imakefile
index 70a5b6a..a73da1c 100644
--- a/miscemu/Imakefile
+++ b/miscemu/Imakefile
@@ -3,7 +3,9 @@
 MODULE = miscemu
 
 SRCS = \
+	dpmi.c \
 	emulate.c \
+	instr.c \
 	int10.c \
 	int13.c \
 	int15.c \
@@ -14,7 +16,6 @@
 	int26.c \
 	int2a.c \
 	int2f.c \
-	int31.c \
 	int5c.c \
 	interrupts.c \
 	ioports.c
diff --git a/miscemu/dpmi.c b/miscemu/dpmi.c
new file mode 100644
index 0000000..c44a6af
--- /dev/null
+++ b/miscemu/dpmi.c
@@ -0,0 +1,173 @@
+/*
+ * DPMI 0.9 emulation
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "windows.h"
+#include "ldt.h"
+#include "registers.h"
+#include "wine.h"
+#include "miscemu.h"
+#include "stddebug.h"
+/* #define DEBUG_INT */
+#include "debug.h"
+
+
+/**********************************************************************
+ *	    do_int31
+ *
+ * Handle the DPMI interrupt (int 31h).
+ */
+int do_int31( struct sigcontext_struct *context )
+{
+    DWORD dw;
+    BYTE *ptr;
+
+    dprintf_int( stddeb, "int31 (DPMI): AX %04x, BX %04x, CX %04x, DX %04x, "
+                 "SI %04x, DI %04x, DS %04x, ES %04x\n",
+                 AX, BX, CX, DX, SI, DI, DS, ES );
+
+    ResetCflag;
+    switch(AX)
+    {
+    case 0x0000:  /* Allocate LDT descriptors */
+        if (!(AX = AllocSelectorArray( CX )))
+        {
+            AX = 0x8011;  /* descriptor unavailable */
+            SetCflag;
+        }
+        break;
+
+    case 0x0001:  /* Free LDT descriptor */
+        if (FreeSelector( BX ))
+        {
+            AX = 0x8022;  /* invalid selector */
+            SetCflag;
+        }
+        break;
+
+    case 0x0003:  /* Get next selector increment */
+        AX = __AHINCR;
+        break;
+
+    case 0x0004:  /* Lock selector (not supported) */
+        AX = 0;  /* FIXME: is this a correct return value? */
+        break;
+
+    case 0x0005:  /* Unlock selector (not supported) */
+        AX = 0;  /* FIXME: is this a correct return value? */
+        break;
+
+    case 0x0006:  /* Get selector base address */
+        if (!(dw = GetSelectorBase( BX )))
+        {
+            AX = 0x8022;  /* invalid selector */
+            SetCflag;
+        }
+        else
+        {
+            CX = HIWORD(dw);
+            DX = LOWORD(dw);
+        }
+        break;
+
+    case 0x0007:  /* Set selector base address */
+        SetSelectorBase( BX, MAKELONG( DX, CX ) );
+        break;
+
+    case 0x0008:  /* Set selector limit */
+        SetSelectorLimit( BX, MAKELONG( DX, CX ) );
+        break;
+
+    case 0x0009:  /* Set selector access rights */
+        SelectorAccessRights( BX, 1, CX );
+
+    case 0x000a:  /* Allocate selector alias */
+        if (!(AX = AllocCStoDSAlias( BX )))
+        {
+            AX = 0x8011;  /* descriptor unavailable */
+            SetCflag;
+        }
+        break;
+
+    case 0x000b:  /* Get descriptor */
+        {
+            ldt_entry entry;
+            LDT_GetEntry( SELECTOR_TO_ENTRY(BX), &entry );
+            /* FIXME: should use ES:EDI for 32-bit clients */
+            LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES, DI ), &entry );
+        }
+        break;
+
+    case 0x000c:  /* Set descriptor */
+        {
+            ldt_entry entry;
+            LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES, DI ), &entry );
+            LDT_GetEntry( SELECTOR_TO_ENTRY(BX), &entry );
+        }
+        break;
+
+    case 0x000d:  /* Allocate specific LDT descriptor */
+        AX = 0x8011; /* descriptor unavailable */
+        SetCflag;
+        break;
+
+    case 0x0400:  /* Get DPMI version */
+        AX = 0x0009;  /* DPMI version 0.9 */
+        BX = 0x0005;  /* Flags: 32-bit, virtual memory */
+        CL = 4;       /* CPU type: 486 */
+        DX = 0x0102;  /* Master and slave interrupt controller base */
+        break;
+
+    case 0x0500:  /* Get free memory information */
+        memset( PTR_SEG_OFF_TO_LIN( ES, DI ),
+                0xff, 0x30 );  /* No information supported */
+        break;
+
+    case 0x0501:  /* Allocate memory block */
+        if (!(ptr = (BYTE *)malloc( MAKELONG( CX, BX ) )))
+        {
+            AX = 0x8012;  /* linear memory not available */
+            SetCflag;
+        }
+        else
+        {
+            BX = SI = HIWORD(ptr);
+            CX = DI = LOWORD(ptr);
+        }
+        break;
+
+    case 0x0502:  /* Free memory block */
+        free( (void *)MAKELONG( DI, SI ) );
+        break;
+
+    case 0x0503:  /* Resize memory block */
+        if (!(ptr = (BYTE *)realloc( (void *)MAKELONG(DI,SI),MAKELONG(CX,BX))))
+        {
+            AX = 0x8012;  /* linear memory not available */
+            SetCflag;
+        }
+        else
+        {
+            BX = SI = HIWORD(ptr);
+            CX = DI = LOWORD(ptr);
+        }
+        break;
+
+    case 0x0600:  /* Lock linear region */
+        break;  /* Just ignore it */
+
+    case 0x0601:  /* Unlock linear region */
+        break;  /* Just ignore it */
+
+    default:
+        AX = 0x8001;  /* unsupported function */
+        SetCflag;
+        break;
+    }
+    return 1;
+}
diff --git a/miscemu/emulate.c b/miscemu/emulate.c
index 70d8153..03de983 100644
--- a/miscemu/emulate.c
+++ b/miscemu/emulate.c
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include "wine.h"
+#include "registers.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
 #include "debug.h"
@@ -15,18 +16,20 @@
 };
 
 void
-WIN87_fpmath( struct sigcontext_struct context )
+WIN87_fpmath( struct sigcontext_struct sigcontext )
 {
-  dprintf_int(stddeb, "_fpmath: (%x:%lx %x %x)\n",context.sc_cs, 
-              context.sc_eip, context.sc_es, (int)context.sc_ebx & 0xffff );
+    /* Declare a context pointer so that registers macros work */
+    struct sigcontext_struct *context = &sigcontext;
 
-  switch(context.sc_ebx & 0xffff)
+    dprintf_int(stddeb, "_fpmath: (%x:%lx %x %x)\n", CS, EIP, ES, BX );
+
+    switch(BX)
     {
     case 11:
-        context.sc_eax = 1;
+        AX = 1;
         break;
     default:
-        context.sc_eax = 0;
+        AX = 0;
         break;
     }
 }
diff --git a/miscemu/instr.c b/miscemu/instr.c
new file mode 100644
index 0000000..b2ef67b
--- /dev/null
+++ b/miscemu/instr.c
@@ -0,0 +1,201 @@
+/*
+ * Emulation of priviledged instructions
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+
+#include <stdio.h>
+#include "windows.h"
+#include "dos_fs.h"
+#include "ldt.h"
+#include "miscemu.h"
+#include "registers.h"
+
+
+static int do_int(int intnum, struct sigcontext_struct *context)
+{
+	switch(intnum)
+	{
+	      case 0x10: return do_int10(context);
+
+	      case 0x11:  
+		AX = DOS_GetEquipment();
+		return 1;
+
+	      case 0x12:               
+		AX = 640;
+		return 1;	/* get base mem size */                
+
+              case 0x13: return do_int13(context);
+	      case 0x15: return do_int15(context);
+	      case 0x16: return do_int16(context);
+	      case 0x1a: return do_int1a(context);
+	      case 0x21: return do_int21(context);
+
+	      case 0x22:
+		AX = 0x1234;
+		BX = 0x5678;
+		CX = 0x9abc;
+		DX = 0xdef0;
+		return 1;
+
+              case 0x25: return do_int25(context);
+              case 0x26: return do_int26(context);
+              case 0x2a: return do_int2a(context);
+	      case 0x2f: return do_int2f(context);
+	      case 0x31: return do_int31(context);
+              case 0x3d: return 1;
+	      case 0x5c: return do_int5c(context);
+
+              default:
+                fprintf(stderr,"int%02x: Unimplemented!\n", intnum);
+                break;
+	}
+	return 0;
+}
+
+
+/***********************************************************************
+ *           INSTR_EmulateInstruction
+ *
+ * Emulate a priviledged instruction. Returns TRUE if emulation successful.
+ */
+BOOL INSTR_EmulateInstruction( struct sigcontext_struct *context )
+{
+    int prefix, segprefix, long_op, long_addr;
+    BYTE *instr = (BYTE *) PTR_SEG_OFF_TO_LIN( CS, IP );
+
+    /* First handle any possible prefix */
+
+    long_op = long_addr = (GET_SEL_FLAGS(CS) & LDT_FLAGS_32BIT) != 0;
+    segprefix = 0;  /* no prefix */
+    prefix = 1;
+    while(prefix)
+    {
+        switch(*instr)
+        {
+        case 0x2e:
+            segprefix = 1;  /* CS */
+            break;
+        case 0x36:
+            segprefix = 2;  /* SS */
+            break;
+        case 0x3e:
+            segprefix = 3;  /* DS */
+            break;
+        case 0x26:
+            segprefix = 4;  /* ES */
+            break;
+        case 0x64:
+            segprefix = 5;  /* FS */
+            break;
+        case 0x65:
+            segprefix = 6;  /* GS */
+            break;
+        case 0x66:
+            long_op = !long_op;  /* opcode size prefix */
+            break;
+        case 0x67:
+            long_addr = !long_addr;  /* addr size prefix */
+            break;
+        default:
+            prefix = 0;  /* no more prefixes */
+            break;
+        }
+        if (prefix)
+        {
+            instr++;
+            EIP++;
+        }
+    }
+
+    /* Now look at the actual instruction */
+
+    switch(*instr)
+    {
+      case 0xcd: /* int <XX> */
+            instr++;
+	    if (!do_int(*instr, context))
+            {
+		fprintf(stderr,"Unexpected Windows interrupt %x\n", *instr);
+                return FALSE;
+	    }
+	    EIP += 2;  /* Bypass the int instruction */
+            break;
+
+      case 0xcf: /* iret */
+            if (long_op)
+            {
+                /* FIXME: should check the stack 'big' bit */
+                DWORD *stack = (WORD *)PTR_SEG_OFF_TO_LIN( SS, SP );
+                EIP = *stack++;
+                CS  = *stack++;
+                EFL = *stack;
+                SP += 3*sizeof(DWORD);  /* Pop the return address and flags */
+            }
+            else
+            {
+                /* FIXME: should check the stack 'big' bit */
+                WORD *stack = (WORD *)PTR_SEG_OFF_TO_LIN( SS, SP );
+                EIP = *stack++;
+                CS  = *stack++;
+                EFL = (EFL & 0xffff0000) | *stack;
+                SP += 3*sizeof(WORD);  /* Pop the return address and flags */
+            }
+            break;
+
+      case 0xe4: /* inb al,XX */
+            inportb_abs(context);
+	    EIP += 2;
+            break;
+
+      case 0xe5: /* in ax,XX */
+            inport_abs( context, long_op );
+	    EIP += 2;
+            break;
+
+      case 0xe6: /* outb XX,al */
+            outportb_abs(context);
+	    EIP += 2;
+            break;
+
+      case 0xe7: /* out XX,ax */
+            outport_abs( context, long_op );
+	    EIP += 2;
+            break;
+
+      case 0xec: /* inb al,dx */
+            inportb(context);
+	    EIP++;
+            break;
+
+      case 0xed: /* in ax,dx */
+            inport( context, long_op );
+	    EIP++;  
+            break;
+
+      case 0xee: /* outb dx,al */
+            outportb(context);
+	    EIP++;
+            break;
+      
+      case 0xef: /* out dx,ax */
+            outport( context, long_op );
+	    EIP++;
+            break;
+
+      case 0xfa: /* cli, ignored */
+	    EIP++;
+            break;
+
+      case 0xfb: /* sti, ignored */
+	    EIP++;
+            break;
+
+      default:
+            fprintf(stderr, "Unexpected Windows program segfault"
+                            " - opcode = %x\n", *instr);
+            return FALSE;  /* Unable to emulate it */
+    }
+    return TRUE;
+}
diff --git a/miscemu/int21.c b/miscemu/int21.c
index f0af67b..10226b8 100644
--- a/miscemu/int21.c
+++ b/miscemu/int21.c
@@ -222,9 +222,9 @@
 		return;
 	}
 	
-	EAX = 4;
-	ECX = 512;
-	EDX = (size / (CX * AX));
+	AX = 4;
+	CX = 512;
+	DX = (size / (CX * AX));
 
 	heap->mediaID = 0xf0;
 
@@ -312,7 +312,7 @@
 			BX, CX, size);
 		if (size == -1) {
 			errno_to_doserr();
-			AL = ExtendedError;
+			AX = ExtendedError;
 			SetCflag;
 			return;
 		}		
@@ -343,19 +343,19 @@
 		fflush(stddeb);
 
 		Error (0,0,0);
-		AL = CX;
+		AX = CX;
 		ResetCflag;
 	} else {
 		size = write(BX, ptr , CX);
 		if (size == 0) {
 			Error (WriteFault, EC_Unknown, EL_Unknown);
-			AL = ExtendedError;
+			AX = ExtendedError;
 			return;
 		}
 
 		if (size == -1) {
 			errno_to_doserr();
-			AL = ExtendedError;
+			AX = ExtendedError;
 			SetCflag;
 			return;
 		}		
@@ -385,13 +385,13 @@
 
 	if (status == -1) {
 		errno_to_doserr();
-		AL = ExtendedError;			SetCflag;
+		AX = ExtendedError;
+                SetCflag;
 		return;
 	}		
 	Error (0,0,0);
-	AX = (status & 0xffff);
-	DX = ((status >> 16) & 0xffff);
-
+	AX = LOWORD(status);
+	DX = HIWORD(status);
 	ResetCflag;
 }
 
@@ -404,7 +404,7 @@
 		case 0:
 		case 1:
 		case 2:
-			DX = 0x80d0 + (1 << BX);
+			DX = 0x80d0 | (1 << (BX != 0));
                         ResetCflag;
 			break;
 
@@ -415,7 +415,6 @@
 		    if (fstat(BX, &sbuf) < 0)
 		    {
 			IntBarf(0x21, context);
-			DX = 0x50;
 			SetCflag;
 			return;
 		    }
@@ -481,7 +480,7 @@
 	ltime = time(NULL);
 	now = localtime(&ltime);
 
-	CX = now->tm_year + 1900 - 1980;
+	CX = now->tm_year + 1900;
 	DX = ((now->tm_mon + 1) << 8) | now->tm_mday;
 	AX = now->tm_wday;
 }
@@ -501,7 +500,7 @@
 
 static void GetExtendedErrorInfo(struct sigcontext_struct *context)
 {
-	AL = ExtendedError;
+	AX = ExtendedError;
 	BX = (ErrorClass << 8) | Action;
 	CH = ErrorLocus << 8;
 }
@@ -513,12 +512,12 @@
 	if ((handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)), 
            O_CREAT | O_TRUNC | O_RDWR )) == -1) {
 		errno_to_doserr();
-		AL = ExtendedError;
+		AX = ExtendedError;
 		SetCflag;
 		return;
 		}			
 	Error (0,0,0);
-	EAX = (EAX & 0xffff0000) | handle;
+        AX = handle;
 	ResetCflag;
 }
 
@@ -554,7 +553,7 @@
 		dprintf_int (stddeb, "int21: open (%s, %d) = -1\n",
 			DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS,DX)), mode);
                 errno_to_doserr();
-                AL = ExtendedError;
+                AX = ExtendedError;
                 SetCflag;
                 return;
             }
@@ -606,7 +605,7 @@
 	  if(result)  
 	  {
 	    errno_to_doserr();
-	    EAX = (EAX & 0xffffff00) | ExtendedError;
+	    AX = ExtendedError;
 	    close(handle);
 	    SetCflag;
 	    return;
@@ -615,7 +614,7 @@
         }
 
 	Error (0,0,0);
-	EAX = (EAX & 0xffff0000) | handle;
+	AX = handle;
 	ResetCflag;
 }
 
@@ -625,12 +624,12 @@
 
 	if (close(BX) == -1) {
 		errno_to_doserr();
-		AL = ExtendedError;
+		AX = ExtendedError;
 		SetCflag;
 		return;
 	}
 	Error (0,0,0);
-	AL = NoError;
+	AX = NoError;
 	ResetCflag;
 }
 
@@ -638,6 +637,7 @@
 {
 	char *newname, *oldname;
 
+        /* FIXME: should not rename over an existing file */
 	dprintf_int(stddeb,"int21: renaming %s to %s\n",
 			(char *)PTR_SEG_OFF_TO_LIN(DS,DX), (char *)PTR_SEG_OFF_TO_LIN(ES,DI) );
 	
@@ -656,13 +656,13 @@
 	dprintf_int(stddeb,"int21: makedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS,DX) );
 	
 	if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ))== NULL) {
-		AL = CanNotMakeDir;
+		AX = CanNotMakeDir;
 		SetCflag;
 		return;
 	}
 
 	if (mkdir(dirname,0) == -1) {
-		AL = CanNotMakeDir;
+		AX = CanNotMakeDir;
 		SetCflag;
 		return;
 	}
@@ -693,7 +693,7 @@
 	dprintf_int(stddeb,"int21: removedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS,DX) );
 
 	if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ))== NULL) {
-		AL = CanNotMakeDir;
+		AX = PathNotFound;
 		SetCflag;
 		return;
 	}
@@ -705,17 +705,13 @@
 	}
 */	
 	if (rmdir(dirname) == -1) {
-		AL = CanNotMakeDir; 
+		AX = AccessDenied;
 		SetCflag;
+                return;
 	} 
 	ResetCflag;
 }
 
-static void ExecProgram(struct sigcontext_struct *context)
-{
-	execl("wine", DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)) );
-}
-
 static void FindNext(struct sigcontext_struct *context)
 {
 	struct dosdirent *dp;
@@ -727,7 +723,7 @@
 	do {
 		if ((dp = DOS_readdir(dp)) == NULL) {
 			Error(NoMoreFiles, EC_MediaError , EL_Disk);
-			AL = NoMoreFiles;
+			AX = NoMoreFiles;
 			SetCflag;
 			return;
 		}
@@ -745,7 +741,7 @@
 	setdword(&dta[0x1a], dp->filesize);
 	strncpy(dta + 0x1e, dp->filename, 13);
 
-	AL = 0;
+	AX = 0;
 	ResetCflag;
 
         dprintf_int(stddeb, "int21: FindNext -- (%s) index=%d size=%ld\n", dp->filename, dp->entnum, dp->filesize);
@@ -766,7 +762,7 @@
 
 		if (!DOS_ValidDrive(drive)) {
 			Error(InvalidDrive, EC_MediaError , EL_Disk);
-			AL = InvalidDrive;
+			AX = InvalidDrive;
 			SetCflag;
 			return;
 		}
@@ -783,14 +779,14 @@
 		if (DOS_GetVolumeLabel(drive) != NULL) 
 			strncpy(dta + 0x1e, DOS_GetVolumeLabel(drive), 8);
 
-		AL = 0;
+		AX = 0;
 		ResetCflag;
 		return;
 	}
 
 	if ((dp = DOS_opendir(path)) == NULL) {
 		Error(PathNotFound, EC_MediaError, EL_Disk);
-		AL = FileNotFound;
+		AX = FileNotFound;
 		SetCflag;
 		return;
 	}
@@ -809,7 +805,8 @@
 	now = localtime (&filestat.st_mtime);
 	
 	CX = ((now->tm_hour * 0x2000) + (now->tm_min * 0x20) + now->tm_sec/2);
-	DX = ((now->tm_year * 0x200) + (now->tm_mon * 0x20) + now->tm_mday);
+	DX = (((now->tm_year + 1900 - 1980) * 0x200) +
+              (now->tm_mon * 0x20) + now->tm_mday);
 
 	ResetCflag;
 }
@@ -842,7 +839,7 @@
 	handle = open(DOS_GetUnixFileName(temp), O_CREAT | O_TRUNC | O_RDWR);
 
 	if (handle == -1) {
-		AL = WriteProtected;
+		AX = WriteProtected;
 		SetCflag;
 		return;
 	}
@@ -858,7 +855,7 @@
 	int handle;
 	
 	if ((handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ), O_CREAT | O_EXCL | O_RDWR)) == -1) {
-		AL = WriteProtected;
+		AX = WriteProtected;
 		SetCflag;
 		return;
 	}
@@ -877,7 +874,7 @@
 		drive = DL - 1;
 
 	if (!DOS_ValidDrive(drive)) {
-		AL = InvalidDrive;
+		AX = InvalidDrive;
 		SetCflag;
 		return;
 	}
@@ -898,7 +895,7 @@
 		drive = BL - 1;
 
 	if (!DOS_ValidDrive(drive)) {
-		AL =InvalidDrive;
+		AX =InvalidDrive;
 		SetCflag;
 		return;
 	}
@@ -910,7 +907,7 @@
 	strncpy(dataptr + 6, DOS_GetVolumeLabel(drive), 8);
 	strncpy(dataptr + 0x11, "FAT16   ", 8);
 	
-	AL = 0;
+	AX = 0;
 	ResetCflag;
 }
 
@@ -926,7 +923,7 @@
 		drive = BL - 1;
 
 	if (!DOS_ValidDrive(drive)) {
-		AL = InvalidDrive;
+		AX = InvalidDrive;
 		SetCflag;
 		return;
 	}
@@ -935,7 +932,7 @@
 			(dataptr[4] << 24);
 
 	DOS_SetSerialNumber(drive, serialnumber);
-	AL = 1L;
+	AX = 1;
 	ResetCflag;
 }
 
@@ -985,7 +982,7 @@
 	    if (!DOS_ValidDrive(drive))
 	      {
 		Error (InvalidDrive, EC_MediaError, EL_Disk);
-		AL = 0xff;
+		AX = 0xff;
 		return;
 	      }
 	  }
@@ -1003,7 +1000,7 @@
 		if (DOS_GetVolumeLabel(drive) != NULL) 
 		  {
 		    strncpy(output_fcb->name, DOS_GetVolumeLabel(drive), 11);
-		    AL = 0x00;
+		    AX = 0x00;
 		    return;
 		  }
 	      }
@@ -1017,7 +1014,7 @@
 	if ((output_fcb->directory = DOS_opendir(path))==NULL)
 	  {
 	    Error (PathNotFound, EC_MediaError, EL_Disk);
-	    AL = 0xff;
+	    AX = 0xff;
 	    return;
 	  }
 	
@@ -1047,7 +1044,7 @@
 
 	if ((dp = DOS_opendir(temp)) == NULL) {
 		Error(InvalidDrive, EC_MediaError , EL_Disk);
-		AL = 0xffL;
+		AX = 0xff;
 		return;
 	}
 
@@ -1063,7 +1060,7 @@
 		/* unlink(DOS_GetUnixFileName(temp)); */
 	}
 	DOS_closedir(dp);
-	AL = 0;
+	AX = 0;
 }
 
 static void RenameFileFCB(struct sigcontext_struct *context)
@@ -1089,7 +1086,7 @@
 
 	if ((dp = DOS_opendir(temp)) == NULL) {
 		Error(InvalidDrive, EC_MediaError , EL_Disk);
-		AL = 0xffL;
+		AX = 0xff;
 		return;
 	}
 
@@ -1109,7 +1106,7 @@
 			oldname, newname);
 	}
 	DOS_closedir(dp);
-	AL = 0;
+	AX = 0;
 }
 
 
@@ -1135,7 +1132,7 @@
 	  break;
 
 	default:
-	  EAX = (EAX & 0xffff0000) | 0x0001;
+	  AX = 0x0001;
 	  SetCflag;
 	  return;
      }
@@ -1156,7 +1153,7 @@
       if(result)  
       {
          errno_to_doserr();
-         EAX = (EAX & 0xffffff00) | ExtendedError;
+         AX = ExtendedError;
          SetCflag;
          return;
       }
@@ -1170,27 +1167,26 @@
 {
   char *filename = PTR_SEG_OFF_TO_LIN (DS,DX);
   struct stat s;
-  int res,cx; 
+  int res;
 
   res = stat(DOS_GetUnixFileName(filename), &s);
   if (res==-1)
   {
     errno_to_doserr();
-    EAX = (EAX & 0xffffff00) | ExtendedError;
+    AX = ExtendedError;
     SetCflag;
     return;
   }
   
-  cx = 0;
+  CX = 0;
   if (S_ISDIR(s.st_mode))
-    cx|=0x10;
+    CX |= 0x10;
   if ((S_IWRITE & s.st_mode) != S_IWRITE)
-    cx|=0x01;
+    CX |= 0x01;
 
   dprintf_int (stddeb, "int21: GetFileAttributes (%s) = 0x%x\n",
-		filename, cx);
+		filename, CX );
 
-  ECX = (ECX & 0xffff0000) | cx;
   ResetCflag;
   Error (0,0,0); 
 }
@@ -1252,19 +1248,21 @@
 	    IntBarf(0x21, context);
 	    break;
 
-	  case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
-	  case 0x1d:
-	  case 0x1e:
-	  case 0x20:
 	  case 0x2b: /* SET SYSTEM DATE */
 	  case 0x2d: /* SET SYSTEM TIME */
 	  case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
 			"SWITCHAR" - SET SWITCH CHARACTER
 			"AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
 	  case 0x54: /* GET VERIFY FLAG */
-	  case 0x6b: /* NULL FUNCTION */
             IntBarf(0x21, context);
-	    EAX &= 0xff00;
+	    break;
+
+	  case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
+	  case 0x1d:
+	  case 0x1e:
+	  case 0x20:
+	  case 0x6b: /* NULL FUNCTION */
+            AL = 0;
 	    break;
 	
 	  case 0x5c: /* "FLOCK" - RECORD LOCKING */
@@ -1278,6 +1276,7 @@
 	  case 0x0e: /* SELECT DEFAULT DRIVE */
 		if (!DOS_ValidDrive(DL)) {
 			Error (InvalidDrive, EC_MediaError, EL_Disk);
+			AX = MAX_DOS_DRIVES; 
 			break;
 		} else {
 			DOS_SetDefaultDrive(DL);
@@ -1360,8 +1359,7 @@
 	  case 0x33: /* MULTIPLEXED */
 	    switch (AL) {
 	      case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
-		if (!(AL)) 
-		    EDX &= 0xff00L;
+                DL = 0;
 		break;
 
 	      case 0x01: /* SET EXTENDED BREAK STATE */
@@ -1377,8 +1375,8 @@
 		break;
 				
 	      case 0x06: /* GET TRUE VERSION NUMBER */
-		EBX = DOSVERSION;
-		EDX = 0x00;
+		BX = DOSVERSION;
+		DX = 0x00;
 		break;
 
 	      default:
@@ -1444,7 +1442,7 @@
 	  case 0x41: /* "UNLINK" - DELETE FILE */
 		if (unlink( DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)) ) == -1) {
 			errno_to_doserr();
-			AL = ExtendedError;
+			AX = ExtendedError;
 			SetCflag;
 			break;
 		}		
@@ -1484,10 +1482,10 @@
                 }
                 else
                 {
-                    if(drive > 1)
-                        EAX = (EAX & 0xFFFF0000) | 0x0001;   /* not removable */
+                    if (drive > 1)
+                        AX = 1;   /* not removable */
                     else
-                        EAX = (EAX & 0xFFFF0000);       /* removable */
+                        AX = 0;      /* removable */
                     ResetCflag;
                 }
                 break;
@@ -1501,7 +1499,7 @@
                 }
                 else
                 {
-		    EDX = (EDX & 0xffff0000) | (1<<9) | (1<<12) | (1<<15);
+		    DX = (1<<9) | (1<<12) | (1<<15);
 		    ResetCflag;
                 }
 		break;
@@ -1509,7 +1507,7 @@
 	      case 0x0b:   /* SET SHARING RETRY COUNT */
 		if (!CX)
 		{ 
-		  EAX = (EAX & 0xffff0000) | 0x0001;
+		  AX = 1;
 		  SetCflag;
 		  break;
 		}
@@ -1526,7 +1524,7 @@
               case 0x0F:   /* Set logical drive mapping */
                 /* FIXME: Not implemented at the moment, always returns error
                  */
-                EAX = (EAX & 0xFFFF0000) | 0x0001; /* invalid function */
+                AX = 0x0001; /* invalid function */
                 SetCflag;
                 break;
                 
@@ -1537,11 +1535,25 @@
 	    break;
 
 	  case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
-	  case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
-		AX = dup(BX);
-		ResetCflag;
+            if ((AX = dup(BX)) == 0xffff)
+            {
+                errno_to_doserr();
+                AX = ExtendedError;
+                SetCflag;
+            }
+            else ResetCflag;
 	    break;
 
+	  case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
+            if (dup2( BX, CX ) == -1)
+            {
+                errno_to_doserr();
+                AX = ExtendedError;
+                SetCflag;
+            }
+            else ResetCflag;
+            break;
+
 	  case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
 	    GetCurrentDirectory(context);
 	    AX = 0x0100; 
@@ -1555,7 +1567,7 @@
 	    break;
 	
 	  case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
-	    ExecProgram(context);
+            WinExec( PTR_SEG_OFF_TO_LIN(DS,DX), SW_NORMAL );
 	    break;		
 	
 	  case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
@@ -1563,7 +1575,7 @@
 	    break;
 
 	  case 0x4d: /* GET RETURN CODE */
-	    AL = NoError; /* normal exit */
+	    AX = NoError; /* normal exit */
 	    break;
 
 	  case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
@@ -1600,10 +1612,10 @@
 	    switch (AL) 
 	    {
 	      case 0x00:
-		AL = 0x01L;
+		AX = 1;
 		break;
 	      case 0x02:
-		EAX &= 0xff00L;
+		AX = 0;
 		break;
 	      case 0x01:
 	      case 0x03:
@@ -1623,7 +1635,7 @@
 	  case 0x5d: /* NETWORK */
 	  case 0x5e:
 	    /* network software not installed */
-	    AL = NoNetwork;
+	    AX = NoNetwork;
 	    SetCflag;
 	    break;
 	
@@ -1634,7 +1646,7 @@
 		if (!DOS_EnableDrive(DL)) 
 		{
 		    Error(InvalidDrive, EC_MediaError , EL_Disk);
-		    AL = InvalidDrive;
+		    AX = InvalidDrive;
 		    SetCflag;
 		    break;
 		}
@@ -1647,7 +1659,7 @@
 		if (!DOS_DisableDrive(DL)) 
 		{
 		    Error(InvalidDrive, EC_MediaError , EL_Disk);
-		    AL = InvalidDrive;
+		    AX = InvalidDrive;
 		    SetCflag;
 		    break;
 		} 
@@ -1658,7 +1670,7 @@
 		}
 	      default:
 		/* network software not installed */
-		AL = NoNetwork; 
+		AX = NoNetwork; 
 		SetCflag;
 		break;
 	    }
@@ -1696,6 +1708,8 @@
 	    break;
 
 	  case 0x68: /* "FFLUSH" - COMMIT FILE */
+	  case 0x6a: /* COMMIT FILE */
+            fsync( BX );
 	    ResetCflag;
 	    break;		
 	
@@ -1711,10 +1725,6 @@
 	    }
 	    break;
 
-	  case 0x6a: /* COMMIT FILE */
-	    ResetCflag;
-	    break;		
-
 	  case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
 	    break;
 
diff --git a/miscemu/int25.c b/miscemu/int25.c
index 3fb25a7..6ebc32e 100644
--- a/miscemu/int25.c
+++ b/miscemu/int25.c
@@ -37,7 +37,7 @@
 		length = CX;
 	}
 	dprintf_int(stdnimp, "int25: abs diskread, drive %d, sector %ld, "
-	"count %ld, buffer %d\n", (int)EAX & 0xff, begin, length, (int) dataptr);
+	"count %ld, buffer %d\n", AL, begin, length, (int) dataptr);
 
 	memset(dataptr, 0, length * 512);
 
diff --git a/miscemu/int26.c b/miscemu/int26.c
index de0aecf..97bf02d 100644
--- a/miscemu/int26.c
+++ b/miscemu/int26.c
@@ -37,7 +37,7 @@
 	}
 		
 	dprintf_int(stdnimp,"int26: abs diskwrite, drive %d, sector %ld, "
-	"count %ld, buffer %d\n", (int)EAX & 0xff, begin, length, (int) dataptr);
+	"count %ld, buffer %d\n", AL, begin, length, (int) dataptr);
 
 	ResetCflag;
 
diff --git a/miscemu/int2f.c b/miscemu/int2f.c
index 106d110..ad797d1 100644
--- a/miscemu/int2f.c
+++ b/miscemu/int2f.c
@@ -2,7 +2,9 @@
 #include <stdlib.h>
 #include "registers.h"
 #include "wine.h"
+#include "msdos.h"
 #include "miscemu.h"
+#include "options.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
 #include "debug.h"
@@ -15,10 +17,10 @@
                "SI %04x, DI %04x, DS %04x, ES %04x\n",
                AX, BX, CX, DX, SI, DI, DS, ES);
 
-	switch((context->sc_eax >> 8) & 0xff)
+	switch(AH)
 	{
-	case 0x10: /* share is installed */
-	        EAX = (EAX & 0xffffff00) | 0xff;
+	case 0x10:
+                AL = 0xff; /* share is installed */
 		break;
 
 	case 0x15: /* mscdex */
@@ -37,30 +39,36 @@
 
 int do_int2f_16(struct sigcontext_struct *context)
 {
-	switch(context->sc_eax & 0xff) {
-		case 0x00: 
-			/* return 'major/minor' for MSWin 3.1 */
-			dprintf_int(stddeb,"do_int2f_16 // return 'major/minor' for MSWin 3.1 !\n");
-			context->sc_eax = 0x0310;
-			return 1;
-		case 0x86:
-			/* operating in protected mode under DPMI */
-			dprintf_int(stddeb,"do_int2f_16 // operating in protected mode under DPMI !\n");
-			context->sc_eax = 0x0000;
-			return 1;
-		case 0x87:
-			dprintf_int(stddeb,"do_int2f_16 // return DPMI flags !\n");
-			context->sc_eax = 0x0000;		/* DPMI Installed */
-			context->sc_ebx = 0x0001;		/* 32bits available */
-			context->sc_ecx = 0x04;			/* processor 486 */
-			context->sc_edx = 0x0100;		/* DPMI major/minor */
-			context->sc_esi = 0;			/* # of para. of DOS */
-											/* extended private data */
-			return 1;
-		default:
-			IntBarf(0x2f, context);
-		}
-	return 1;
+    switch(AL)
+    {
+    case 0x00:  /* Windows enhanced mode installation check */
+        AX = Options.enhanced ? WINVERSION : 0;
+        break;
+
+    case 0x0a:  /* Get Windows version and type */
+        AX = 0;
+        BX = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+        CX = Options.enhanced ? 3 : 2;
+        break;
+
+    case 0x86:  /* DPMI detect mode */
+        AX = 0;  /* Running under DPMI */
+        break;
+
+    case 0x87:  /* DPMI installation check */
+        AX = 0x0000;  /* DPMI Installed */
+        BX = 0x0001;  /* 32bits available */
+        CX = 0x04;    /* processor 486 */
+        DX = 0x0009;  /* DPMI major/minor 0.9 */
+        SI = 0;       /* # of para. of DOS extended private data */
+        ES = 0;       /* ES:DI is DPMI switch entry point */
+        DI = 0;
+        break;
+
+    default:
+        IntBarf(0x2f, context);
+    }
+    return 1;
 }
 
 
diff --git a/miscemu/int31.c b/miscemu/int31.c
deleted file mode 100644
index 7aa7dfd..0000000
--- a/miscemu/int31.c
+++ /dev/null
@@ -1,108 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "registers.h"
-#include "wine.h"
-#include "miscemu.h"
-#include "stddebug.h"
-/* #define DEBUG_INT */
-#include "debug.h"
-
-typedef struct {
-	WORD	accessed    : 1;
-	WORD	read_write  : 1;
-	WORD	conf_exp    : 1;
-	WORD	code        : 1;
-	WORD	xsystem     : 1;
-	WORD	dpl         : 2;
-	WORD	present     : 1;
-	WORD	dummy	    : 8;
-	} ACCESS;
-typedef ACCESS *LPACCESS;
-
-typedef struct {
-	WORD	Limit;
-	WORD	addr_lo;
-	BYTE	addr_hi;
-	ACCESS	access; 
-	WORD	reserved;
-	} DESCRIPTOR;
-typedef DESCRIPTOR *LPDESCRIPTOR;
-
-HANDLE DPMI_GetNewSelector(WORD selcount);
-BOOL DPMI_FreeSelector(HANDLE pmSel);
-BOOL DPMI_SetDescriptor(HANDLE pmSel, LPDESCRIPTOR lpDesc);
-
-/*************************************************************************/
-
-int do_int31(struct sigcontext_struct *context)
-{
-	LPDESCRIPTOR lpDesc;
-	dprintf_int(stddeb,"do_int31 // context->sc_eax=%08lX\n",
-		context->sc_eax);
-	switch(context->sc_eax)
-	{
-	case 0x0000:
-		context->sc_eax = DPMI_GetNewSelector(context->sc_ecx);
-		break;
-	case 0x0001:
-		context->sc_eax = DPMI_FreeSelector(context->sc_ebx);
-		break;
-	case 0x000C:
-		lpDesc = (LPDESCRIPTOR) MAKELONG(context->sc_edi,
-                                                 context->sc_es);
-		context->sc_eax = DPMI_SetDescriptor(context->sc_ebx, lpDesc);
-		break;
-	default:
-		IntBarf(0x31, context);
-	};
-	return 1;
-}
-
-
-/*************************************************************************/
-
-
-HANDLE DPMI_GetNewSelector(WORD selcount)
-{
-	LPSTR	ptr;
-	HANDLE 	pmSel;
-	dprintf_int(stddeb,"DPMI_GetNewSelector(%d); !\n", selcount);
-	pmSel = GlobalAlloc(GMEM_FIXED, 4096);
-	ptr = GlobalLock(pmSel);
-	dprintf_int(stddeb,"DPMI_GetNewSelector() return %04X !\n", pmSel);
-	return pmSel;
-}
-
-
-BOOL DPMI_FreeSelector(HANDLE pmSel)
-{
-	dprintf_int(stddeb,"DPMI_FreeSelector(%04X); !\n", pmSel);
-	GlobalFree(pmSel);
-	return 0;
-}
-
-BOOL DPMI_SetDescriptor(HANDLE pmSel, LPDESCRIPTOR lpDesc)
-{
-	dprintf_int(stdnimp,"DPMI_SetDescriptor(%04X, %p); !\n", 
-		pmSel, lpDesc);
-	dprintf_int(stdnimp,"DPMI lpDesc->Limit=%u \n", lpDesc->Limit);
-	dprintf_int(stdnimp,"DPMI lpDesc->addr_lo=%04X \n", lpDesc->addr_lo);
-	dprintf_int(stdnimp,"DPMI lpDesc->addr_hi=%02X \n", lpDesc->addr_hi);
-	dprintf_int(stdnimp,"DPMI lpDesc->access.accessed=%u \n", 
-		lpDesc->access.accessed);
-	dprintf_int(stdnimp,"DPMI lpDesc->access.read_write=%u \n", 
-		lpDesc->access.read_write);
-	dprintf_int(stdnimp,"DPMI lpDesc->access.conf_exp=%u \n", 
-		lpDesc->access.conf_exp);
-	dprintf_int(stdnimp,"DPMI lpDesc->access.code=%u \n", 
-		lpDesc->access.code);
-	dprintf_int(stdnimp,"DPMI lpDesc->access.xsystem=%u \n", 
-		lpDesc->access.xsystem);
-	dprintf_int(stdnimp,"DPMI lpDesc->access.dpl=%u \n", 
-		lpDesc->access.dpl);
-	dprintf_int(stdnimp,"DPMI lpDesc->access.present=%u \n", 
-		lpDesc->access.present);
-	dprintf_int(stdnimp,"DPMI lpDesc->reserved=%04X \n", lpDesc->reserved);
-	return FALSE;
-}
-
diff --git a/miscemu/ioports.c b/miscemu/ioports.c
index fe86fc1..161ca06 100644
--- a/miscemu/ioports.c
+++ b/miscemu/ioports.c
@@ -34,11 +34,11 @@
 	}
 }
 
-void inport(struct sigcontext_struct *context)
+void inport( struct sigcontext_struct *context, int long_op )
 {
-	dprintf_int(stdnimp, "IO: in (%x)\n", DX);
-
-	AX = 0xffff;
+    dprintf_int(stdnimp, "IO: in (%x)\n", DX);
+    if (long_op) EAX = 0xffffffff;
+    else AX = 0xffff;
 }
 
 void inportb_abs(struct sigcontext_struct *context)
@@ -47,10 +47,11 @@
 	AL = 0xff;
 }
 
-void inport_abs(struct sigcontext_struct *context)
+void inport_abs( struct sigcontext_struct *context, int long_op )
 {
-	dprintf_int(stdnimp, "IO: in (%x)\n", *(BYTE *)(EIP+1));
-	AX = 0xffff;
+    dprintf_int(stdnimp, "IO: in (%x)\n", *(BYTE *)(EIP+1));
+    if (long_op) EAX = 0xffffffff;
+    else AX = 0xffff;
 }
 
 void outportb(struct sigcontext_struct *context)
@@ -69,9 +70,9 @@
 	}
 }
 
-void outport(struct sigcontext_struct *context)
+void outport( struct sigcontext_struct *context, int long_op )
 {
-	dprintf_int(stdnimp, "IO: out (%x), %x\n", DX, AX);
+    dprintf_int(stdnimp, "IO: out (%x), %lx\n", DX, long_op ? EAX : AX);
 }
 
 void outportb_abs(struct sigcontext_struct *context)
@@ -79,7 +80,8 @@
     dprintf_int(stdnimp, "IO: out (%x), %x\n", *(BYTE *)(EIP+1), AL);
 }
 
-void outport_abs(struct sigcontext_struct *context)
+void outport_abs( struct sigcontext_struct *context, int long_op )
 {
-    dprintf_int(stdnimp, "IO: out (%x), %x\n", *(BYTE *)(EIP+1), AX);
+    dprintf_int(stdnimp, "IO: out (%x), %lx\n", *(BYTE *)(EIP+1),
+                long_op ? EAX : AX);
 }
diff --git a/multimedia/audio.c b/multimedia/audio.c
index 2a5faa4..5ce2271 100644
--- a/multimedia/audio.c
+++ b/multimedia/audio.c
@@ -2,9 +2,8 @@
  * Sample Wine Driver for Linux
  *
  * Copyright 1994 Martin Ayotte
- *
-static char Copyright[] = "Copyright  Martin Ayotte, 1994";
-*/
+ */
+
 #ifndef WINELIB
 #define BUILTIN_MMSYSTEM
 #endif 
@@ -81,118 +80,29 @@
 static LINUX_WAVEOUT	WOutDev[MAX_WAVOUTDRV];
 static LINUX_WAVEIN	WInDev[MAX_WAVOUTDRV];
 static LINUX_MCIWAVE	MCIWavDev[MAX_MCIWAVDRV];
-#endif
-
-DWORD WAVE_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_WAVE_OPEN_PARMS lpParms);
-DWORD WAVE_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms);
-DWORD WAVE_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms);
-DWORD WAVE_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms);
-DWORD WAVE_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
-DWORD WAVE_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
-DWORD WAVE_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
-DWORD WAVE_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms);
-DWORD WAVE_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms);
-DWORD WAVE_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms);
-DWORD WAVE_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms);
-
-DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPS lpCaps, DWORD dwSize);
-DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags);
-DWORD wodClose(WORD wDevID);
-DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize);
-DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize);
-DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize);
 
 
 /**************************************************************************
 * 				WAVE_NotifyClient			[internal]
 */
-DWORD WAVE_NotifyClient(UINT wDevID, WORD wMsg, 
+static DWORD WAVE_NotifyClient(UINT wDevID, WORD wMsg, 
 				DWORD dwParam1, DWORD dwParam2)
 {
-#ifdef linux
 	if (WInDev[wDevID].wFlags != DCB_NULL && !DriverCallback(
 		WInDev[wDevID].waveDesc.dwCallBack, WInDev[wDevID].wFlags, 
 		WInDev[wDevID].waveDesc.hWave, wMsg, 
 		WInDev[wDevID].waveDesc.dwInstance, dwParam1, dwParam2)) {
-		fprintf(stderr,"WAVE_NotifyClient // can't notify client !\n");
+		dprintf_mciwave(stddeb,"WAVE_NotifyClient // can't notify client !\n");
 		return MMSYSERR_NOERROR;
 		}
         return 0;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 
 /**************************************************************************
-* 				AUDIO_DriverProc		[sample driver]
-*/
-LRESULT WAVE_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
-						DWORD dwParam1, DWORD dwParam2)
-{
-#ifdef linux
-	dprintf_mciwave(stddeb,"WAVE_DriverProc(%08lX, %04X, %04X, %08lX, %08lX)\n", 
-		dwDevID, hDriv, wMsg, dwParam1, dwParam2);
-	switch(wMsg) {
-		case DRV_LOAD:
-			return (LRESULT)1L;
-		case DRV_FREE:
-			return (LRESULT)1L;
-		case DRV_OPEN:
-			return (LRESULT)1L;
-		case DRV_CLOSE:
-			return (LRESULT)1L;
-		case DRV_ENABLE:
-			return (LRESULT)1L;
-		case DRV_DISABLE:
-			return (LRESULT)1L;
-		case DRV_QUERYCONFIGURE:
-			return (LRESULT)1L;
-		case DRV_CONFIGURE:
-			MessageBox((HWND)NULL, "Sample MultiMedia Linux Driver !", 
-								"MMLinux Driver", MB_OK);
-			return (LRESULT)1L;
-		case DRV_INSTALL:
-			return (LRESULT)DRVCNF_RESTART;
-		case DRV_REMOVE:
-			return (LRESULT)DRVCNF_RESTART;
-		case MCI_OPEN_DRIVER:
-		case MCI_OPEN:
-			return WAVE_mciOpen(dwDevID, dwParam1, (LPMCI_WAVE_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_CLOSE_DRIVER:
-		case MCI_CLOSE:
-			return WAVE_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_PLAY:
-			return WAVE_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_RECORD:
-			return WAVE_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_STOP:
-			return WAVE_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_SET:
-			return WAVE_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_PAUSE:
-			return WAVE_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_RESUME:
-			return WAVE_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_STATUS:
-			return WAVE_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_GETDEVCAPS:
-			return WAVE_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_INFO:
-			return WAVE_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		default:
-			return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
-		}
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
-}
-
-/**************************************************************************
 * 				WAVE_mciOpen	*/
-DWORD WAVE_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_WAVE_OPEN_PARMS lpParms)
+static DWORD WAVE_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_WAVE_OPEN_PARMS lpParms)
 {
-#ifdef linux
 	HANDLE		hFormat;
 	LPPCMWAVEFORMAT	lpWaveFormat;
 	HANDLE		hDesc;
@@ -235,7 +145,7 @@
 			MCIWavDev[wDevID].hFile = mmioOpen(str, NULL, 
 				MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_EXCLUSIVE);
 			if (MCIWavDev[wDevID].hFile == 0) {
-				fprintf(stderr,"WAVE_mciOpen // can't find file='%s' !\n", str);
+				dprintf_mciwave(stddeb,"WAVE_mciOpen // can't find file='%s' !\n", str);
 				return MCIERR_FILE_NOT_FOUND;
 				}
 			}
@@ -307,17 +217,13 @@
 	USER_HEAP_FREE(hFormat);
 	USER_HEAP_FREE(hDesc);
 	return 0;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				WAVE_mciClose		[internal]
 */
-DWORD WAVE_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
+static DWORD WAVE_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
 	DWORD		dwRet;
 	dprintf_mciwave(stddeb,
 		"WAVE_mciClose(%u, %08lX, %p);\n", wDevID, dwParam, lpParms);
@@ -333,18 +239,14 @@
 		if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL;
 		}
 	return 0;
-#else
-	return 0;
-#endif
 }
 
 
 /**************************************************************************
 * 				WAVE_mciPlay		[internal]
 */
-DWORD WAVE_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
+static DWORD WAVE_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
 {
-#ifdef linux
 	int				start, end;
 	LONG			bufsize, count;
 	HANDLE			hData;
@@ -355,7 +257,7 @@
 	dprintf_mciwave(stddeb,
 		 "WAVE_mciPlay(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (MCIWavDev[wDevID].hFile == 0) {
-        fprintf(stderr,"WAVE_mciPlay // can't find file='%s' !\n",
+        dprintf_mciwave(stddeb,"WAVE_mciPlay // can't find file='%s' !\n",
 				MCIWavDev[wDevID].openParms.lpstrElementName);
 		return MCIERR_FILE_NOT_FOUND;
 		}
@@ -369,13 +271,13 @@
 		end = lpParms->dwTo;
 		dprintf_mciwave(stddeb,"WAVE_mciPlay // MCI_TO=%d \n", end);
 		}
-/**/
+#if 0
 	if (dwFlags & MCI_NOTIFY) {
         dprintf_mciwave(stddeb,
 	        "WAVE_mciPlay // MCI_NOTIFY %08lX !\n", lpParms->dwCallback);
 		switch(fork()) {
 			case -1:
-				fprintf(stderr,
+				dprintf_mciwave(stddeb,
 				  "WAVE_mciPlay // Can't 'fork' process !\n");
 				break;
 			case 0:
@@ -385,7 +287,7 @@
 				return 0;
 			}
 		}
-/**/
+#endif
 	bufsize = 64000;
 	lpWaveHdr = &MCIWavDev[wDevID].WaveHdr;
 	hData = GlobalAlloc(GMEM_MOVEABLE, bufsize);
@@ -423,18 +325,14 @@
 		exit(0);
 		}
 	return 0;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 
 /**************************************************************************
 * 				WAVE_mciRecord			[internal]
 */
-DWORD WAVE_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
+static DWORD WAVE_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
 {
-#ifdef linux
 	int				start, end;
 	LONG			bufsize;
 	HANDLE			hData;
@@ -446,7 +344,7 @@
 	dprintf_mciwave(stddeb,
 		"WAVE_mciRecord(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (MCIWavDev[wDevID].hFile == 0) {
-		fprintf(stderr,"WAVE_mciRecord // can't find file='%s' !\n", 
+		dprintf_mciwave(stddeb,"WAVE_mciRecord // can't find file='%s' !\n", 
 				MCIWavDev[wDevID].openParms.lpstrElementName);
 		return MCIERR_FILE_NOT_FOUND;
 		}
@@ -497,66 +395,50 @@
 			MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		}
 	return 0;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 
 /**************************************************************************
 * 				WAVE_mciStop			[internal]
 */
-DWORD WAVE_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD WAVE_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"WAVE_mciStop(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
 }
 
 
 /**************************************************************************
 * 				WAVE_mciPause			[internal]
 */
-DWORD WAVE_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD WAVE_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"WAVE_mciPause(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
 }
 
 
 /**************************************************************************
 * 				WAVE_mciResume			[internal]
 */
-DWORD WAVE_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD WAVE_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"WAVE_mciResume(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
 }
 
 
 /**************************************************************************
 * 				WAVE_mciSet			[internal]
 */
-DWORD WAVE_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
+static DWORD WAVE_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"WAVE_mciSet(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -576,7 +458,7 @@
 				dprintf_mciwave(stddeb,	"WAVE_mciSet // MCI_FORMAT_SAMPLES !\n");
 				break;
 			default:
-				fprintf(stderr,	"WAVE_mciSet // bad time format !\n");
+				dprintf_mciwave(stddeb,	"WAVE_mciSet // bad time format !\n");
 				return MCIERR_BAD_TIME_FORMAT;
 			}
 		}
@@ -618,18 +500,14 @@
 	  dprintf_mciwave(stddeb,
 			  "WAVE_mciSet // MCI_WAVE_SET_SAMPLESPERSEC !\n");
  	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
 }
 
 
 /**************************************************************************
 * 				WAVE_mciStatus		[internal]
 */
-DWORD WAVE_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
+static DWORD WAVE_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"WAVE_mciStatus(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -710,7 +588,7 @@
 				lpParms->dwReturn = 22050;
 				break;
 			default:
-				fprintf(stderr,"WAVE_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
+				dprintf_mciwave(stddeb,"WAVE_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
 				return MCIERR_UNRECOGNIZED_COMMAND;
 			}
 		}
@@ -720,18 +598,14 @@
 			MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		}
  	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
 }
 
 /**************************************************************************
 * 				WAVE_mciGetDevCaps		[internal]
 */
-DWORD WAVE_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
+static DWORD WAVE_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
 					LPMCI_GETDEVCAPS_PARMS lpParms)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"WAVE_mciGetDevCaps(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -775,17 +649,13 @@
 			}
 		}
  	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
 }
 
 /**************************************************************************
 * 				WAVE_mciInfo			[internal]
 */
-DWORD WAVE_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
+static DWORD WAVE_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"WAVE_mciInfo(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -812,9 +682,6 @@
 	else
 		lpParms->dwRetSize = 0;
  	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
 }
 
 
@@ -824,9 +691,8 @@
 /**************************************************************************
 * 				wodGetDevCaps				[internal]
 */
-DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPS lpCaps, DWORD dwSize)
+static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPS lpCaps, DWORD dwSize)
 {
-#ifdef linux
 	int 	audio;
 	int		smplrate;
 	int		samplesize = 16;
@@ -882,18 +748,14 @@
 	dprintf_mciwave(stddeb,
 		"wodGetDevCaps // dwFormats = %08lX\n", lpCaps->dwFormats);
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 
 /**************************************************************************
 * 				wodOpen				[internal]
 */
-DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
+static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
 {
-#ifdef linux
 	int 		audio;
 	int			abuf_size;
 	int			smplrate;
@@ -904,25 +766,25 @@
 	dprintf_mciwave(stddeb,
 		"wodOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
-		fprintf(stderr,"Linux 'wodOpen' // Invalid Parameter !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	if (wDevID >= MAX_WAVOUTDRV) {
-		fprintf(stderr,"Linux 'wodOpen' // MAX_WAVOUTDRV reached !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodOpen' // MAX_WAVOUTDRV reached !\n");
 		return MMSYSERR_ALLOCATED;
 		}
 	WOutDev[wDevID].unixdev = 0;
 	audio = open (SOUND_DEV, O_WRONLY, 0);
 	if (audio == -1) {
-		fprintf(stderr,"Linux 'wodOpen' // can't open !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodOpen' // can't open !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size);
 	if (abuf_size < 4096 || abuf_size > 65536) {
 		if (abuf_size == -1)
-			fprintf(stderr,"Linux 'wodOpen' // IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
+			dprintf_mciwave(stddeb,"Linux 'wodOpen' // IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
 		else
-			fprintf(stderr,"Linux 'wodOpen' // SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n");
+			dprintf_mciwave(stddeb,"Linux 'wodOpen' // SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	WOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
@@ -948,11 +810,11 @@
 /*	lpFormat = (LPWAVEFORMAT) PTR_SEG_TO_LIN(lpDesc->lpFormat); */
 	lpFormat = lpDesc->lpFormat;
 	if (lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
-		fprintf(stderr,"Linux 'wodOpen' // Bad format %04X !\n",
+		dprintf_mciwave(stddeb,"Linux 'wodOpen' // Bad format %04X !\n",
 				lpFormat->wFormatTag);
-		fprintf(stderr,"Linux 'wodOpen' // Bad nChannels %d !\n",
+		dprintf_mciwave(stddeb,"Linux 'wodOpen' // Bad nChannels %d !\n",
 				lpFormat->nChannels);
-		fprintf(stderr,"Linux 'wodOpen' // Bad nSamplesPerSec %ld !\n",
+		dprintf_mciwave(stddeb,"Linux 'wodOpen' // Bad nSamplesPerSec %ld !\n",
 				lpFormat->nSamplesPerSec);
 		return WAVERR_BADFORMAT;
 		}
@@ -982,50 +844,42 @@
 	dprintf_mciwave(stddeb,"Linux 'wodOpen' // nChannels=%u !\n",
 				WOutDev[wDevID].Format.wf.nChannels);
 	if (WAVE_NotifyClient(wDevID, WOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'wodOpen' // can't notify client !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodOpen' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				wodClose			[internal]
 */
-DWORD wodClose(WORD wDevID)
+static DWORD wodClose(WORD wDevID)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,"wodClose(%u);\n", wDevID);
 	if (WOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'wodClose' // can't close !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodClose' // can't close !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	close(WOutDev[wDevID].unixdev);
 	WOutDev[wDevID].unixdev = 0;
 	WOutDev[wDevID].bufsize = 0;
 	if (WAVE_NotifyClient(wDevID, WOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'wodClose' // can't notify client !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodClose' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				wodWrite			[internal]
 */
-DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
 {
-#ifdef linux
 	int		count;
 	LPSTR	lpData;
 	dprintf_mciwave(stddeb,"wodWrite(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WOutDev[wDevID].unixdev == 0) {
-        fprintf(stderr,"Linux 'wodWrite' // can't play !\n");
+        dprintf_mciwave(stddeb,"Linux 'wodWrite' // can't play !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (lpWaveHdr->lpData == NULL) return WAVERR_UNPREPARED;
@@ -1042,36 +896,32 @@
 	dprintf_mciwave(stddeb,
 		"wodWrite() // write returned count %u !\n", count);
 	if (count != lpWaveHdr->dwBufferLength) {
-		fprintf(stderr,"Linux 'wodWrite' // error writting !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodWrite' // error writting !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	WOutDev[wDevID].dwTotalPlayed += count;
 	lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
 	lpWaveHdr->dwFlags |= WHDR_DONE;
 	if (WAVE_NotifyClient(wDevID, WOM_DONE, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'wodWrite' // can't notify client !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodWrite' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				wodPrepare			[internal]
 */
-DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"wodPrepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'wodPrepare' // can't prepare !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodPrepare' // can't prepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (WOutDev[wDevID].lpQueueHdr != NULL) {
-		fprintf(stderr,"Linux 'wodPrepare' // already prepare !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodPrepare' // already prepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	WOutDev[wDevID].dwTotalPlayed = 0;
@@ -1080,78 +930,61 @@
 	lpWaveHdr->dwFlags |= WHDR_PREPARED;
 	lpWaveHdr->dwFlags &= ~WHDR_DONE;
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				wodUnprepare			[internal]
 */
-DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"wodUnprepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'wodUnprepare' // can't unprepare !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodUnprepare' // can't unprepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				wodRestart				[internal]
 */
-DWORD wodRestart(WORD wDevID)
+static DWORD wodRestart(WORD wDevID)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,"wodRestart(%u);\n", wDevID);
 	if (WOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'wodRestart' // can't restart !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodRestart' // can't restart !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				wodReset				[internal]
 */
-DWORD wodReset(WORD wDevID)
+static DWORD wodReset(WORD wDevID)
 {
-#ifdef linux
     dprintf_mciwave(stddeb,"wodReset(%u);\n", wDevID);
 	if (WOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'wodReset' // can't reset !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodReset' // can't reset !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 
 /**************************************************************************
 * 				wodGetPosition			[internal]
 */
-DWORD wodGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
+static DWORD wodGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
 {
-#ifdef linux
 	int		time;
 	dprintf_mciwave(stddeb,"wodGetPosition(%u, %p, %lu);\n", wDevID, lpTime, uSize);
 	if (WOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'wodGetPosition' // can't get pos !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodGetPosition' // can't get pos !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (lpTime == NULL)	return MMSYSERR_INVALPARAM;
-TryAGAIN:
 	switch(lpTime->wType) {
 		case TIME_BYTES:
 			lpTime->u.cb = WOutDev[wDevID].dwTotalPlayed;
@@ -1166,11 +999,6 @@
 						WOutDev[wDevID].Format.wBitsPerSample;
 			dprintf_mciwave(stddeb,"wodGetPosition // TIME_SAMPLES=%lu\n", lpTime->u.sample);
 			break;
-		case TIME_MS:
-			lpTime->u.ms = WOutDev[wDevID].dwTotalPlayed /
-					(WOutDev[wDevID].Format.wf.nAvgBytesPerSec / 1000);
-			dprintf_mciwave(stddeb,"wodGetPosition // TIME_MS=%lu\n", lpTime->u.ms);
-			break;
 		case TIME_SMPTE:
 			time = WOutDev[wDevID].dwTotalPlayed /
 				(WOutDev[wDevID].Format.wf.nAvgBytesPerSec / 1000);
@@ -1188,32 +1016,32 @@
 			  lpTime->u.smpte.sec, lpTime->u.smpte.frame);
 			break;
 		default:
-			fprintf(stderr,"wodGetPosition() format not supported ! use TIME_MS !\n");
+			dprintf_mciwave(stddeb,"wodGetPosition() format not supported ! use TIME_MS !\n");
 			lpTime->wType = TIME_MS;
-			goto TryAGAIN;
+		case TIME_MS:
+			lpTime->u.ms = WOutDev[wDevID].dwTotalPlayed /
+					(WOutDev[wDevID].Format.wf.nAvgBytesPerSec / 1000);
+			dprintf_mciwave(stddeb,"wodGetPosition // TIME_MS=%lu\n", lpTime->u.ms);
+			break;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				wodGetVolume			[internal]
 */
-DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol)
+static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol)
 {
-#ifdef linux
 	int 	mixer;
 	int		volume, left, right;
 	dprintf_mciwave(stddeb,"wodGetVolume(%u, %p);\n", wDevID, lpdwVol);
 	if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
 	if ((mixer = open("/dev/mixer", O_RDONLY)) < 0) {
-		fprintf(stderr, "Linux 'wodGetVolume' // mixer device not available !\n");
+		dprintf_mciwave(stddeb, "Linux 'wodGetVolume' // mixer device not available !\n");
 		return MMSYSERR_NOTENABLED;
 		}
     if (ioctl(mixer, SOUND_MIXER_READ_PCM, &volume) == -1) {
-		fprintf(stderr,"Linux 'wodGetVolume' // unable read mixer !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodGetVolume' // unable read mixer !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	close(mixer);
@@ -1222,38 +1050,32 @@
 	printf("Linux 'AUX_GetVolume' // left=%d right=%d !\n", left, right);
 	*lpdwVol = MAKELONG(left << 9, right << 9);
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 
 /**************************************************************************
 * 				wodSetVolume			[internal]
 */
-DWORD wodSetVolume(WORD wDevID, DWORD dwParam)
+static DWORD wodSetVolume(WORD wDevID, DWORD dwParam)
 {
-#ifdef linux
 	int 	mixer;
 	int		volume;
 	dprintf_mciwave(stddeb,"wodSetVolume(%u, %08lX);\n", wDevID, dwParam);
 	volume = (LOWORD(dwParam) >> 9 & 0x7F) + 
 		((HIWORD(dwParam) >> 9  & 0x7F) << 8);
 	if ((mixer = open("/dev/mixer", O_WRONLY)) < 0) {
-		fprintf(stderr,	"Linux 'wodSetVolume' // mixer device not available !\n");
+		dprintf_mciwave(stddeb,	"Linux 'wodSetVolume' // mixer device not available !\n");
 		return MMSYSERR_NOTENABLED;
 		}
     if (ioctl(mixer, SOUND_MIXER_WRITE_PCM, &volume) == -1) {
-		fprintf(stderr,"Linux 'wodSetVolume' // unable set mixer !\n");
+		dprintf_mciwave(stddeb,"Linux 'wodSetVolume' // unable set mixer !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	close(mixer);
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
+#endif /* linux */
 
 /**************************************************************************
 * 				wodMessage			[sample driver]
@@ -1263,7 +1085,8 @@
 {
 	dprintf_mciwave(stddeb,"wodMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
-	switch(wMsg) {
+#ifdef linux
+        switch(wMsg) {
 		case WODM_OPEN:
 			return wodOpen(wDevID, (LPWAVEOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
 		case WODM_CLOSE:
@@ -1301,20 +1124,24 @@
 		case WODM_RESET:
 			return wodReset(wDevID);
 		default:
-			fprintf(stderr,"wodMessage // unknown message !\n");
+			dprintf_mciwave(stddeb,"wodMessage // unknown message !\n");
 		}
 	return MMSYSERR_NOTSUPPORTED;
+#else
+	return MMSYSERR_NOTENABLED;
+#endif
 }
 
 
 /*-----------------------------------------------------------------------*/
 
+#ifdef linux
+
 /**************************************************************************
 * 				widGetDevCaps				[internal]
 */
-DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPS lpCaps, DWORD dwSize)
+static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPS lpCaps, DWORD dwSize)
 {
-#ifdef linux
 	int 	audio;
 	int		smplrate;
 	int		samplesize = 16;
@@ -1368,18 +1195,14 @@
 	dprintf_mciwave(stddeb,
 		"widGetDevCaps // dwFormats = %08lX\n", lpCaps->dwFormats);
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 
 /**************************************************************************
 * 				widOpen				[internal]
 */
-DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
+static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
 {
-#ifdef linux
 	int 		audio;
 	int			abuf_size;
 	int			smplrate;
@@ -1388,25 +1211,25 @@
 	LPWAVEFORMAT  lpFormat;
 	dprintf_mciwave(stddeb, "widOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
-		fprintf(stderr,"Linux 'widOpen' // Invalid Parameter !\n");
+		dprintf_mciwave(stddeb,"Linux 'widOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	if (wDevID >= MAX_WAVINDRV) {
-		fprintf(stderr,"Linux 'widOpen' // MAX_WAVINDRV reached !\n");
+		dprintf_mciwave(stddeb,"Linux 'widOpen' // MAX_WAVINDRV reached !\n");
 		return MMSYSERR_ALLOCATED;
 		}
 	WInDev[wDevID].unixdev = 0;
 	audio = open (SOUND_DEV, O_RDONLY, 0);
 	if (audio == -1) {
-		fprintf(stderr,"Linux 'widOpen' // can't open !\n");
+		dprintf_mciwave(stddeb,"Linux 'widOpen' // can't open !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size);
 	if (abuf_size < 4096 || abuf_size > 65536) {
 		if (abuf_size == -1)
-			fprintf(stderr,"Linux 'widOpen' // IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
+			dprintf_mciwave(stddeb,"Linux 'widOpen' // IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
 		else
-			fprintf(stderr,"Linux 'widOpen' // SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n");
+			dprintf_mciwave(stddeb,"Linux 'widOpen' // SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	WInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
@@ -1431,7 +1254,7 @@
 	memcpy(&WInDev[wDevID].waveDesc, lpDesc, sizeof(WAVEOPENDESC));
         lpFormat = lpDesc->lpFormat;
 	if (lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
-		fprintf(stderr,"Linux 'widOpen' // Bad format %04X !\n",
+		dprintf_mciwave(stddeb,"Linux 'widOpen' // Bad format %04X !\n",
 					lpFormat->wFormatTag);
 		return WAVERR_BADFORMAT;
 		}
@@ -1460,59 +1283,51 @@
 	dprintf_mciwave(stddeb,"Linux 'widOpen' // nAvgBytesPerSec=%lu\n",
 			WInDev[wDevID].Format.wf.nAvgBytesPerSec); 
 	if (WAVE_NotifyClient(wDevID, WIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'widOpen' // can't notify client !\n");
+		dprintf_mciwave(stddeb,"Linux 'widOpen' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widClose			[internal]
 */
-DWORD widClose(WORD wDevID)
+static DWORD widClose(WORD wDevID)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,"widClose(%u);\n", wDevID);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'widClose' // can't close !\n");
+		dprintf_mciwave(stddeb,"Linux 'widClose' // can't close !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	close(WInDev[wDevID].unixdev);
 	WInDev[wDevID].unixdev = 0;
 	WInDev[wDevID].bufsize = 0;
 	if (WAVE_NotifyClient(wDevID, WIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'widClose' // can't notify client !\n");
+		dprintf_mciwave(stddeb,"Linux 'widClose' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widAddBuffer		[internal]
 */
-DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
 {
-#ifdef linux
 	int			count	= 1;
 	LPWAVEHDR 	lpWIHdr;
 	dprintf_mciwave(stddeb,
 		"widAddBuffer(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'widAddBuffer' // can't do it !\n");
+		dprintf_mciwave(stddeb,"Linux 'widAddBuffer' // can't do it !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) {
-		fprintf(stderr,	"Linux 'widAddBuffer' // never been prepared !\n");
+		dprintf_mciwave(stddeb,	"Linux 'widAddBuffer' // never been prepared !\n");
 		return WAVERR_UNPREPARED;
 		}
 	if (lpWaveHdr->dwFlags & WHDR_INQUEUE) {
-		fprintf(stderr,	"Linux 'widAddBuffer' // header already in use !\n");
+		dprintf_mciwave(stddeb,	"Linux 'widAddBuffer' // header already in use !\n");
 		return WAVERR_STILLPLAYING;
 		}
 	lpWaveHdr->dwFlags |= WHDR_PREPARED;
@@ -1537,25 +1352,21 @@
 	dprintf_mciwave(stddeb,
 		"widAddBuffer // buffer added ! (now %u in queue)\n", count);
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widPrepare			[internal]
 */
-DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+static DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"widPrepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'widPrepare' // can't prepare !\n");
+		dprintf_mciwave(stddeb,"Linux 'widPrepare' // can't prepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (WInDev[wDevID].lpQueueHdr != NULL) {
-		fprintf(stderr,"Linux 'widPrepare' // already prepare !\n");
+		dprintf_mciwave(stddeb,"Linux 'widPrepare' // already prepare !\n");
 		return WAVERR_BADFORMAT;
 		}
 	if (lpWaveHdr->dwFlags & WHDR_INQUEUE) return WAVERR_STILLPLAYING;
@@ -1565,21 +1376,17 @@
 	lpWaveHdr->dwBytesRecorded = 0;
 	dprintf_mciwave(stddeb,"Linux 'widPrepare' // header prepared !\n");
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widUnprepare			[internal]
 */
-DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
+static DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,
 		"widUnprepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'widUnprepare' // can't unprepare !\n");
+		dprintf_mciwave(stddeb,"Linux 'widUnprepare' // can't unprepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
@@ -1589,27 +1396,23 @@
 	dprintf_mciwave(stddeb,
 		"Linux 'widUnprepare' // all headers unprepared !\n");
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widStart				[internal]
 */
-DWORD widStart(WORD wDevID)
+static DWORD widStart(WORD wDevID)
 {
-#ifdef linux
 	int			count	= 1;
 	LPWAVEHDR 	lpWIHdr;
 	dprintf_mciwave(stddeb,"widStart(%u);\n", wDevID);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,	"Linux 'widStart' // can't start recording !\n");
+		dprintf_mciwave(stddeb,	"Linux 'widStart' // can't start recording !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (WInDev[wDevID].lpQueueHdr == NULL || 
 		WInDev[wDevID].lpQueueHdr->lpData == NULL) {
-		fprintf(stderr,"Linux 'widStart' // never been prepared !\n");
+		dprintf_mciwave(stddeb,"Linux 'widStart' // never been prepared !\n");
 		return WAVERR_UNPREPARED;
 		}
 	lpWIHdr = WInDev[wDevID].lpQueueHdr;
@@ -1628,7 +1431,7 @@
 		lpWIHdr->dwFlags |= WHDR_DONE;
 		if (WAVE_NotifyClient(wDevID, WIM_DATA, (DWORD)lpWIHdr, 0L) != 
 			MMSYSERR_NOERROR) {
-			fprintf(stderr,	"Linux 'widStart' // can't notify client !\n");
+			dprintf_mciwave(stddeb,	"Linux 'widStart' // can't notify client !\n");
 			return MMSYSERR_INVALPARAM;
 			}
 		lpWIHdr = lpWIHdr->lpNext;
@@ -1637,60 +1440,48 @@
 	dprintf_mciwave(stddeb,"widStart // end of recording !\n");
 	fflush(stdout);
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widStop					[internal]
 */
-DWORD widStop(WORD wDevID)
+static DWORD widStop(WORD wDevID)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,"widStop(%u);\n", wDevID);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'widStop' // can't stop !\n");
+		dprintf_mciwave(stddeb,"Linux 'widStop' // can't stop !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widReset				[internal]
 */
-DWORD widReset(WORD wDevID)
+static DWORD widReset(WORD wDevID)
 {
-#ifdef linux
 	dprintf_mciwave(stddeb,"widReset(%u);\n", wDevID);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'widReset' // can't reset !\n");
+		dprintf_mciwave(stddeb,"Linux 'widReset' // can't reset !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
 /**************************************************************************
 * 				widGetPosition			[internal]
 */
-DWORD widGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
+static DWORD widGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
 {
-#ifdef linux
 	int		time;
+    
 	dprintf_mciwave(stddeb,
 		"widGetPosition(%u, %p, %lu);\n", wDevID, lpTime, uSize);
 	if (WInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'widGetPosition' // can't get pos !\n");
+		dprintf_mciwave(stddeb,"Linux 'widGetPosition' // can't get pos !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (lpTime == NULL)	return MMSYSERR_INVALPARAM;
-TryAGAIN:
 	dprintf_mciwave(stddeb,"widGetPosition // wType=%04X !\n", 
 			lpTime->wType);
 	dprintf_mciwave(stddeb,"widGetPosition // wBitsPerSample=%u\n",
@@ -1715,12 +1506,6 @@
 					"widGetPosition // TIME_SAMPLES=%lu\n", 
 					lpTime->u.sample);
 			break;
-		case TIME_MS:
-			lpTime->u.ms = WInDev[wDevID].dwTotalRecorded /
-					(WInDev[wDevID].Format.wf.nAvgBytesPerSec / 1000);
-			dprintf_mciwave(stddeb,
-			      "widGetPosition // TIME_MS=%lu\n", lpTime->u.ms);
-			break;
 		case TIME_SMPTE:
 			time = WInDev[wDevID].dwTotalRecorded /
 				(WInDev[wDevID].Format.wf.nAvgBytesPerSec / 1000);
@@ -1737,16 +1522,20 @@
 					lpTime->u.smpte.sec, lpTime->u.smpte.frame);
 			break;
 		default:
-			fprintf(stderr,"widGetPosition() format not supported ! use TIME_MS !\n");
+			dprintf_mciwave(stddeb,"widGetPosition() format not supported ! use TIME_MS !\n");
 			lpTime->wType = TIME_MS;
-			goto TryAGAIN;
+		case TIME_MS:
+			lpTime->u.ms = WInDev[wDevID].dwTotalRecorded /
+					(WInDev[wDevID].Format.wf.nAvgBytesPerSec / 1000);
+			dprintf_mciwave(stddeb,
+			      "widGetPosition // TIME_MS=%lu\n", lpTime->u.ms);
+			break;
 		}
 	return MMSYSERR_NOERROR;
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
 }
 
+#endif /* linux */
+
 /**************************************************************************
 * 				widMessage			[sample driver]
 */
@@ -1755,6 +1544,7 @@
 {
 	dprintf_mciwave(stddeb,"widMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
+#ifdef linux
 	switch(wMsg) {
 		case WIDM_OPEN:
 			return widOpen(wDevID, (LPWAVEOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
@@ -1769,7 +1559,7 @@
 		case WIDM_GETDEVCAPS:
 			return widGetDevCaps(wDevID, (LPWAVEINCAPS)PTR_SEG_TO_LIN(dwParam1), dwParam2);
 		case WIDM_GETNUMDEVS:
-			return 1L;
+			return 1;
 		case WIDM_GETPOS:
 			return widGetPosition(wDevID, (LPMMTIME)PTR_SEG_TO_LIN(dwParam1), dwParam2);
 		case WIDM_RESET:
@@ -1779,9 +1569,77 @@
 		case WIDM_STOP:
 			return widStop(wDevID);
 		default:
-			fprintf(stderr,"widMessage // unknown message !\n");
+			dprintf_mciwave(stddeb,"widMessage // unknown message !\n");
 		}
 	return MMSYSERR_NOTSUPPORTED;
+#else
+	return MMSYSERR_NOTENABLED;
+#endif
+}
+
+
+/**************************************************************************
+* 				AUDIO_DriverProc		[sample driver]
+*/
+LONG WAVE_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+						DWORD dwParam1, DWORD dwParam2)
+{
+#ifdef linux
+	dprintf_mciwave(stddeb,"WAVE_DriverProc(%08lX, %04X, %04X, %08lX, %08lX)\n", 
+		dwDevID, hDriv, wMsg, dwParam1, dwParam2);
+	switch(wMsg) {
+		case DRV_LOAD:
+			return 1;
+		case DRV_FREE:
+			return 1;
+		case DRV_OPEN:
+			return 1;
+		case DRV_CLOSE:
+			return 1;
+		case DRV_ENABLE:
+			return 1;
+		case DRV_DISABLE:
+			return 1;
+		case DRV_QUERYCONFIGURE:
+			return 1;
+		case DRV_CONFIGURE:
+			MessageBox((HWND)NULL, "Sample MultiMedia Linux Driver !", 
+								"MMLinux Driver", MB_OK);
+			return 1;
+		case DRV_INSTALL:
+			return DRVCNF_RESTART;
+		case DRV_REMOVE:
+			return DRVCNF_RESTART;
+		case MCI_OPEN_DRIVER:
+		case MCI_OPEN:
+			return WAVE_mciOpen(dwDevID, dwParam1, (LPMCI_WAVE_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_CLOSE_DRIVER:
+		case MCI_CLOSE:
+			return WAVE_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_PLAY:
+			return WAVE_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_RECORD:
+			return WAVE_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_STOP:
+			return WAVE_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_SET:
+			return WAVE_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_PAUSE:
+			return WAVE_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_RESUME:
+			return WAVE_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_STATUS:
+			return WAVE_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_GETDEVCAPS:
+			return WAVE_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_INFO:
+			return WAVE_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		default:
+			return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
+		}
+#else
+	return MMSYSERR_NOTENABLED;
+#endif
 }
 
 
diff --git a/multimedia/mcianim.c b/multimedia/mcianim.c
index ebe1bbc..895042c 100644
--- a/multimedia/mcianim.c
+++ b/multimedia/mcianim.c
@@ -2,9 +2,8 @@
  * Sample MCI ANIMATION Wine Driver for Linux
  *
  * Copyright 1994 Martin Ayotte
- *
-static char Copyright[] = "Copyright  Martin Ayotte, 1994";
-*/
+ */
+
 #ifndef WINELIB
 #define BUILTIN_MMSYSTEM
 #endif 
@@ -22,8 +21,6 @@
 #include "driver.h"
 #include "mmsystem.h"
 #include "stddebug.h"
-/* #define DEBUG_MCIANIM */
-#define DEBUG_MCIANIM
 #include "debug.h"
 
 #define MAX_ANIMDRV 		2
@@ -53,16 +50,12 @@
 #endif
 
 
-DWORD ANIM_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame);
-DWORD ANIM_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime);
-
-
 /*-----------------------------------------------------------------------*/
 
 /**************************************************************************
 * 				ANIM_mciOpen			[internal]
 */
-DWORD ANIM_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
+static DWORD ANIM_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
 {
 #ifdef linux
 	LPSTR		lpstrElementName;
@@ -120,7 +113,7 @@
 /**************************************************************************
 * 				ANIM_mciClose		[internal]
 */
-DWORD ANIM_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
+static DWORD ANIM_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
 	dprintf_mcianim(stddeb,"ANIM_mciClose(%u, %08lX, %p);\n", 
@@ -134,7 +127,7 @@
 /**************************************************************************
 * 				ANIM_mciGetDevCaps	[internal]
 */
-DWORD ANIM_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
+static DWORD ANIM_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
 						LPMCI_GETDEVCAPS_PARMS lpParms)
 {
 #ifdef linux
@@ -186,10 +179,114 @@
 #endif
 }
 
+
+/**************************************************************************
+* 				ANIM_CalcTime			[internal]
+*/
+static DWORD ANIM_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
+{
+	DWORD	dwTime = 0;
+#ifdef linux
+	UINT	wTrack;
+	UINT	wMinutes;
+	UINT	wSeconds;
+	UINT	wFrames;
+	dprintf_mcianim(stddeb,"ANIM_CalcTime(%u, %08lX, %lu);\n", 
+			wDevID, dwFormatType, dwFrame);
+    
+	switch (dwFormatType) {
+		case MCI_FORMAT_MILLISECONDS:
+			dwTime = dwFrame / ANIMFRAMES_PERSEC * 1000;
+			dprintf_mcianim(stddeb,
+				"ANIM_CalcTime // MILLISECONDS %lu\n", dwTime);
+			break;
+		case MCI_FORMAT_MSF:
+			wMinutes = dwFrame / ANIMFRAMES_PERMIN;
+			wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC;
+			wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - 
+								ANIMFRAMES_PERSEC * wSeconds;
+			dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
+			dprintf_mcianim(stddeb,"ANIM_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
+								wMinutes, wSeconds, wFrames, dwTime);
+			break;
+		default:
+			/* unknown format ! force TMSF ! ... */
+			dwFormatType = MCI_FORMAT_TMSF;
+		case MCI_FORMAT_TMSF:
+			for (wTrack = 0; wTrack < AnimDev[wDevID].nTracks; wTrack++) {
+/*				dwTime += AnimDev[wDevID].lpdwTrackLen[wTrack - 1];
+				printf("Adding trk#%u curpos=%u \n", dwTime);
+				if (dwTime >= dwFrame) break; */
+				if (AnimDev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
+				}
+			wMinutes = dwFrame / ANIMFRAMES_PERMIN;
+			wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC;
+			wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - 
+								ANIMFRAMES_PERSEC * wSeconds;
+			dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
+			dprintf_mcianim(stddeb,
+				"ANIM_CalcTime // %02u-%02u:%02u:%02u\n",
+				wTrack, wMinutes, wSeconds, wFrames);
+			break;
+		}
+#endif
+	return dwTime;
+}
+
+
+/**************************************************************************
+* 				ANIM_CalcFrame			[internal]
+*/
+static DWORD ANIM_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
+{
+	DWORD	dwFrame = 0;
+#ifdef linux
+	UINT	wTrack;
+	dprintf_mcianim(stddeb,"ANIM_CalcFrame(%u, %08lX, %lu);\n", 
+			wDevID, dwFormatType, dwTime);
+
+        switch (dwFormatType) {
+		case MCI_FORMAT_MILLISECONDS:
+			dwFrame = dwTime * ANIMFRAMES_PERSEC / 1000;
+			dprintf_mcianim(stddeb,
+				"ANIM_CalcFrame // MILLISECONDS %lu\n", dwFrame);
+			break;
+		case MCI_FORMAT_MSF:
+			dprintf_mcianim(stddeb,
+				"ANIM_CalcFrame // MSF %02u:%02u:%02u\n",
+				MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), 
+				MCI_MSF_FRAME(dwTime));
+			dwFrame += ANIMFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
+			dwFrame += ANIMFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
+			dwFrame += MCI_MSF_FRAME(dwTime);
+			break;
+		default:
+			/* unknown format ! force TMSF ! ... */
+			dwFormatType = MCI_FORMAT_TMSF;
+		case MCI_FORMAT_TMSF:
+			wTrack = MCI_TMSF_TRACK(dwTime);
+			dprintf_mcianim(stddeb,
+				"ANIM_CalcFrame // TMSF %02u-%02u:%02u:%02u\n",
+				MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), 
+				MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
+			dprintf_mcianim(stddeb,
+				"ANIM_CalcFrame // TMSF trackpos[%u]=%lu\n",
+				wTrack, AnimDev[wDevID].lpdwTrackPos[wTrack - 1]);
+			dwFrame = AnimDev[wDevID].lpdwTrackPos[wTrack - 1];
+			dwFrame += ANIMFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime);
+			dwFrame += ANIMFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime);
+			dwFrame += MCI_TMSF_FRAME(dwTime);
+			break;
+		}
+#endif
+	return dwFrame;
+}
+
+
 /**************************************************************************
 * 				ANIM_mciInfo			[internal]
 */
-DWORD ANIM_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
+static DWORD ANIM_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
 #ifdef linux
 	dprintf_mcianim(stddeb,"ANIM_mciInfo(%u, %08lX, %p);\n", 
@@ -223,7 +320,7 @@
 /**************************************************************************
 * 				ANIM_mciStatus		[internal]
 */
-DWORD ANIM_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
+static DWORD ANIM_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
 #ifdef linux
 	dprintf_mcianim(stddeb,"ANIM_mciStatus(%u, %08lX, %p);\n", 
@@ -310,115 +407,9 @@
 
 
 /**************************************************************************
-* 				ANIM_CalcTime			[internal]
-*/
-DWORD ANIM_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
-{
-	DWORD	dwTime = 0;
-#ifdef linux
-	UINT	wTrack;
-	UINT	wMinutes;
-	UINT	wSeconds;
-	UINT	wFrames;
-	dprintf_mcianim(stddeb,"ANIM_CalcTime(%u, %08lX, %lu);\n", 
-			wDevID, dwFormatType, dwFrame);
-TryAGAIN:
-	switch (dwFormatType) {
-		case MCI_FORMAT_MILLISECONDS:
-			dwTime = dwFrame / ANIMFRAMES_PERSEC * 1000;
-			dprintf_mcianim(stddeb,
-				"ANIM_CalcTime // MILLISECONDS %lu\n", dwTime);
-			break;
-		case MCI_FORMAT_MSF:
-			wMinutes = dwFrame / ANIMFRAMES_PERMIN;
-			wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC;
-			wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - 
-								ANIMFRAMES_PERSEC * wSeconds;
-			dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
-			dprintf_mcianim(stddeb,"ANIM_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
-								wMinutes, wSeconds, wFrames, dwTime);
-			break;
-		case MCI_FORMAT_TMSF:
-			for (wTrack = 0; wTrack < AnimDev[wDevID].nTracks; wTrack++) {
-/*				dwTime += AnimDev[wDevID].lpdwTrackLen[wTrack - 1];
-				printf("Adding trk#%u curpos=%u \n", dwTime);
-				if (dwTime >= dwFrame) break; */
-				if (AnimDev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
-				}
-			wMinutes = dwFrame / ANIMFRAMES_PERMIN;
-			wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC;
-			wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - 
-								ANIMFRAMES_PERSEC * wSeconds;
-			dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
-			dprintf_mcianim(stddeb,
-				"ANIM_CalcTime // %02u-%02u:%02u:%02u\n",
-				wTrack, wMinutes, wSeconds, wFrames);
-			break;
-		default:
-			/* unknown format ! force TMSF ! ... */
-			dwFormatType = MCI_FORMAT_TMSF;
-			goto TryAGAIN;
-		}
-#endif
-	return dwTime;
-}
-
-
-/**************************************************************************
-* 				ANIM_CalcFrame			[internal]
-*/
-DWORD ANIM_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
-{
-	DWORD	dwFrame = 0;
-#ifdef linux
-	UINT	wTrack;
-	dprintf_mcianim(stddeb,"ANIM_CalcFrame(%u, %08lX, %lu);\n", 
-			wDevID, dwFormatType, dwTime);
-TryAGAIN:
-	switch (dwFormatType) {
-		case MCI_FORMAT_MILLISECONDS:
-			dwFrame = dwTime * ANIMFRAMES_PERSEC / 1000;
-			dprintf_mcianim(stddeb,
-				"ANIM_CalcFrame // MILLISECONDS %lu\n", dwFrame);
-			break;
-		case MCI_FORMAT_MSF:
-			dprintf_mcianim(stddeb,
-				"ANIM_CalcFrame // MSF %02u:%02u:%02u\n",
-				MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), 
-				MCI_MSF_FRAME(dwTime));
-			dwFrame += ANIMFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
-			dwFrame += ANIMFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
-			dwFrame += MCI_MSF_FRAME(dwTime);
-			break;
-		case MCI_FORMAT_TMSF:
-			wTrack = MCI_TMSF_TRACK(dwTime);
-			dprintf_mcianim(stddeb,
-				"ANIM_CalcFrame // TMSF %02u-%02u:%02u:%02u\n",
-				MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), 
-				MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
-			dprintf_mcianim(stddeb,
-				"ANIM_CalcFrame // TMSF trackpos[%u]=%lu\n",
-				wTrack, AnimDev[wDevID].lpdwTrackPos[wTrack - 1]);
-			dwFrame = AnimDev[wDevID].lpdwTrackPos[wTrack - 1];
-			dwFrame += ANIMFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime);
-			dwFrame += ANIMFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime);
-			dwFrame += MCI_TMSF_FRAME(dwTime);
-			break;
-		default:
-			/* unknown format ! force TMSF ! ... */
-			dwFormatType = MCI_FORMAT_TMSF;
-			goto TryAGAIN;
-		}
-#endif
-	return dwFrame;
-}
-
-
-
-/**************************************************************************
 * 				ANIM_mciPlay			[internal]
 */
-DWORD ANIM_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
+static DWORD ANIM_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
 {
 #ifdef linux
 	int 	start, end;
@@ -457,7 +448,7 @@
 /**************************************************************************
 * 				ANIM_mciStop			[internal]
 */
-DWORD ANIM_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD ANIM_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
 	dprintf_mcianim(stddeb,"ANIM_mciStop(%u, %08lX, %p);\n", 
@@ -480,7 +471,7 @@
 /**************************************************************************
 * 				ANIM_mciPause		[internal]
 */
-DWORD ANIM_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD ANIM_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
 	dprintf_mcianim(stddeb,"ANIM_mciPause(%u, %08lX, %p);\n", 
@@ -503,7 +494,7 @@
 /**************************************************************************
 * 				ANIM_mciResume		[internal]
 */
-DWORD ANIM_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD ANIM_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
 	dprintf_mcianim(stddeb,"ANIM_mciResume(%u, %08lX, %p);\n", 
@@ -526,7 +517,7 @@
 /**************************************************************************
 * 				ANIM_mciSeek			[internal]
 */
-DWORD ANIM_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
+static DWORD ANIM_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
 {
 #ifdef linux
 	DWORD	dwRet;
@@ -566,7 +557,7 @@
 /**************************************************************************
 * 				ANIM_mciSet			[internal]
 */
-DWORD ANIM_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
+static DWORD ANIM_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
 #ifdef linux
 	dprintf_mcianim(stddeb,"ANIM_mciSet(%u, %08lX, %p);\n", 
@@ -614,15 +605,15 @@
 /**************************************************************************
 * 				ANIM_DriverProc		[sample driver]
 */
-LRESULT ANIM_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG ANIM_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 #ifdef linux
 	switch(wMsg) {
 		case DRV_LOAD:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_FREE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_OPEN:
 		case MCI_OPEN_DRIVER:
 		case MCI_OPEN:
@@ -634,19 +625,19 @@
 			return ANIM_mciClose(dwDevID, dwParam1, 
 					(LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
 		case DRV_ENABLE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_DISABLE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_QUERYCONFIGURE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_CONFIGURE:
 			MessageBox((HWND)NULL, "Sample MultiMedia Linux Driver !", 
 								"MMLinux Driver", MB_OK);
-			return (LRESULT)1L;
+			return 1;
 		case DRV_INSTALL:
-			return (LRESULT)DRVCNF_RESTART;
+			return DRVCNF_RESTART;
 		case DRV_REMOVE:
-			return (LRESULT)DRVCNF_RESTART;
+			return DRVCNF_RESTART;
 		case MCI_GETDEVCAPS:
 			return ANIM_mciGetDevCaps(dwDevID, dwParam1, 
 					(LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
diff --git a/multimedia/mcicda.c b/multimedia/mcicda.c
index 6e00345..f1e125c 100644
--- a/multimedia/mcicda.c
+++ b/multimedia/mcicda.c
@@ -2,9 +2,8 @@
  * Sample MCI CDAUDIO Wine Driver for Linux
  *
  * Copyright 1994 Martin Ayotte
- *
-static char Copyright[] = "Copyright  Martin Ayotte, 1994";
-*/
+ */
+
 #ifndef WINELIB
 #define BUILTIN_MMSYSTEM
 #endif 
@@ -22,7 +21,6 @@
 #include "driver.h"
 #include "mmsystem.h"
 #include "stddebug.h"
-/* #define DEBUG_CDAUDIO */
 #include "debug.h"
 
 #ifdef linux
@@ -69,19 +67,114 @@
 static LINUX_CDAUDIO	CDADev[MAX_CDAUDIODRV];
 #endif
 
-UINT CDAUDIO_GetNumberOfTracks(UINT wDevID);
-BOOL CDAUDIO_GetTracksInfo(UINT wDevID);
-BOOL CDAUDIO_GetCDStatus(UINT wDevID);
-DWORD CDAUDIO_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame);
-
 
 /*-----------------------------------------------------------------------*/
 
 
 /**************************************************************************
+* 				CDAUDIO_GetNumberOfTracks		[internal]
+*/
+static UINT CDAUDIO_GetNumberOfTracks(UINT wDevID)
+{
+#ifdef linux
+	struct cdrom_tochdr	hdr;
+	if (CDADev[wDevID].nTracks == 0) {
+		if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCHDR, &hdr)) {
+            		dprintf_cdaudio(stddeb,
+				"GetNumberOfTracks(%u) // Error occured !\n", 
+				wDevID);
+			return (WORD)-1;
+			}
+		CDADev[wDevID].nTracks = hdr.cdth_trk1;
+		}
+	return CDADev[wDevID].nTracks;
+#else
+	return (WORD)-1;
+#endif
+}
+
+
+/**************************************************************************
+* 				CDAUDIO_GetTracksInfo			[internal]
+*/
+static BOOL CDAUDIO_GetTracksInfo(UINT wDevID)
+{
+#ifdef linux
+	int		i, length;
+	int		start, last_start = 0;
+	int		total_length = 0;
+	struct cdrom_tocentry	entry;
+	if (CDADev[wDevID].nTracks == 0) {
+		if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE;
+		}
+    	dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // nTracks=%u\n", 
+		CDADev[wDevID].nTracks);
+	if (CDADev[wDevID].lpdwTrackLen != NULL) 
+		free(CDADev[wDevID].lpdwTrackLen);
+	CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc(
+		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
+	if (CDADev[wDevID].lpdwTrackPos != NULL) 
+		free(CDADev[wDevID].lpdwTrackPos);
+	CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc(
+		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
+	if (CDADev[wDevID].lpdwTrackLen == NULL ||
+		CDADev[wDevID].lpdwTrackPos == NULL) {
+        		dprintf_cdaudio(stddeb,
+				"CDAUDIO_GetTracksInfo // error allocating track table !\n");
+		return FALSE;
+		}
+	memset(CDADev[wDevID].lpdwTrackLen, 0, 
+		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
+	memset(CDADev[wDevID].lpdwTrackPos, 0, 
+		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
+	for (i = 0; i <= CDADev[wDevID].nTracks; i++) {
+		if (i == CDADev[wDevID].nTracks)
+			entry.cdte_track = CDROM_LEADOUT;
+		else
+			entry.cdte_track = i + 1;
+		entry.cdte_format = CDROM_MSF;
+		if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCENTRY, &entry)) {
+            		dprintf_cdaudio(stddeb,
+				"CDAUDIO_GetTracksInfo // error read entry\n");
+			return FALSE;
+			}
+		start = CDFRAMES_PERSEC * (SECONDS_PERMIN * 
+			entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) + 
+			entry.cdte_addr.msf.frame;
+		if (i == 0) {
+			last_start = start;
+			CDADev[wDevID].dwFirstOffset = start;
+            		dprintf_cdaudio(stddeb,
+				"CDAUDIO_GetTracksInfo // dwFirstOffset=%u\n", 
+				start);
+			}
+		else {
+			length = start - last_start;
+			last_start = start;
+			start = last_start - length;
+			total_length += length;
+			CDADev[wDevID].lpdwTrackLen[i - 1] = length;
+			CDADev[wDevID].lpdwTrackPos[i - 1] = start;
+            		dprintf_cdaudio(stddeb,
+			"CDAUDIO_GetTracksInfo // track #%u start=%u len=%u\n",
+				i, start, length);
+			}
+		}
+	CDADev[wDevID].dwTotalLen = total_length;
+    	dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // total_len=%u\n", 
+		total_length);
+	fflush(stdout);
+	return TRUE;
+#else
+	return FALSE;
+#endif
+}
+
+
+/**************************************************************************
 * 				CDAUDIO_mciOpen			[internal]
 */
-DWORD CDAUDIO_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
+static DWORD CDAUDIO_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen(%04X, %08lX, %p);\n", 
@@ -109,7 +202,7 @@
 	CDADev[wDevID].wNotifyDeviceID = lpParms->wDeviceID;
 	CDADev[wDevID].unixdev = open (CDAUDIO_DEV, O_RDONLY, 0);
 	if (CDADev[wDevID].unixdev == -1) {
-		fprintf(stderr,"CDAUDIO_mciOpen // can't open '%s' !\n", CDAUDIO_DEV);
+		dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // can't open '%s' !\n", CDAUDIO_DEV);
 		return MCIERR_HARDWARE;
 		}
 	CDADev[wDevID].mode = 0;
@@ -121,7 +214,7 @@
 	CDADev[wDevID].lpdwTrackLen = NULL;
 	CDADev[wDevID].lpdwTrackPos = NULL;
 	if (!CDAUDIO_GetTracksInfo(wDevID)) {
-		fprintf(stderr,"CDAUDIO_mciOpen // error reading TracksInfo !\n");
+		dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // error reading TracksInfo !\n");
 /*		return MCIERR_INTERNAL; */
 		}
 	if (dwFlags & MCI_NOTIFY) {
@@ -140,7 +233,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciClose		[internal]
 */
-DWORD CDAUDIO_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
+static DWORD CDAUDIO_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciClose(%u, %08lX, %p);\n", 
@@ -155,7 +248,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciGetDevCaps	[internal]
 */
-DWORD CDAUDIO_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
+static DWORD CDAUDIO_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
 						LPMCI_GETDEVCAPS_PARMS lpParms)
 {
 #ifdef linux
@@ -210,7 +303,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciInfo			[internal]
 */
-DWORD CDAUDIO_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
+static DWORD CDAUDIO_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciInfo(%u, %08lX, %p);\n", 
@@ -234,10 +327,173 @@
 #endif
 }
 
+
+/**************************************************************************
+* 				CDAUDIO_CalcFrame			[internal]
+*/
+static DWORD CDAUDIO_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
+{
+	DWORD	dwFrame = 0;
+#ifdef linux
+	UINT	wTrack;
+    
+    	dprintf_cdaudio(stddeb,"CDAUDIO_CalcFrame(%u, %08lX, %lu);\n", 
+		wDevID, dwFormatType, dwTime);
+    
+	switch (dwFormatType) {
+		case MCI_FORMAT_MILLISECONDS:
+			dwFrame = dwTime * CDFRAMES_PERSEC / 1000;
+            		dprintf_cdaudio(stddeb,
+				"CDAUDIO_CalcFrame // MILLISECONDS %lu\n", 
+				dwFrame);
+			break;
+		case MCI_FORMAT_MSF:
+            		dprintf_cdaudio(stddeb,
+				"CDAUDIO_CalcFrame // MSF %02u:%02u:%02u\n",
+				MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), 
+				MCI_MSF_FRAME(dwTime));
+			dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
+			dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
+			dwFrame += MCI_MSF_FRAME(dwTime);
+			break;
+		default:
+			/* unknown format ! force TMSF ! ... */
+			dwFormatType = MCI_FORMAT_TMSF;
+		case MCI_FORMAT_TMSF:
+			wTrack = MCI_TMSF_TRACK(dwTime);
+            		dprintf_cdaudio(stddeb,
+			"CDAUDIO_CalcFrame // TMSF %02u-%02u:%02u:%02u\n",
+					MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), 
+					MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
+            		dprintf_cdaudio(stddeb,
+				"CDAUDIO_CalcFrame // TMSF trackpos[%u]=%lu\n",
+				wTrack, CDADev[wDevID].lpdwTrackPos[wTrack - 1]);
+			dwFrame = CDADev[wDevID].lpdwTrackPos[wTrack - 1];
+			dwFrame += CDFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime);
+			dwFrame += CDFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime);
+			dwFrame += MCI_TMSF_FRAME(dwTime);
+			break;
+		}
+#endif
+	return dwFrame;
+}
+
+
+/**************************************************************************
+* 				CDAUDIO_GetCDStatus				[internal]
+*/
+static BOOL CDAUDIO_GetCDStatus(UINT wDevID)
+{
+#ifdef linux
+	int		oldmode = CDADev[wDevID].mode;
+	CDADev[wDevID].sc.cdsc_format = CDROM_MSF;
+	if (ioctl(CDADev[wDevID].unixdev, CDROMSUBCHNL, &CDADev[wDevID].sc)) {
+        	dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // opened or no_media !\n");
+		CDADev[wDevID].mode = MCI_MODE_NOT_READY;
+		return TRUE;
+		}
+	switch (CDADev[wDevID].sc.cdsc_audiostatus) {
+		case CDROM_AUDIO_INVALID:
+            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // device doesn't support status !\n");
+			return FALSE;
+		case CDROM_AUDIO_NO_STATUS: 
+			CDADev[wDevID].mode = MCI_MODE_STOP;
+            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
+			break;
+		case CDROM_AUDIO_PLAY: 
+			CDADev[wDevID].mode = MCI_MODE_PLAY;
+            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
+			break;
+		case CDROM_AUDIO_PAUSED:
+			CDADev[wDevID].mode = MCI_MODE_PAUSE;
+            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
+			break;
+		default:
+            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // status=%02X !\n",
+					CDADev[wDevID].sc.cdsc_audiostatus);
+		}
+	CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk;
+	CDADev[wDevID].dwCurFrame = 
+		CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute +
+		CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second +
+		CDADev[wDevID].sc.cdsc_absaddr.msf.frame;
+    	dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // %02u-%02u:%02u:%02u \n",
+		CDADev[wDevID].sc.cdsc_trk,
+		CDADev[wDevID].sc.cdsc_absaddr.msf.minute,
+		CDADev[wDevID].sc.cdsc_absaddr.msf.second,
+		CDADev[wDevID].sc.cdsc_absaddr.msf.frame);
+	if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) {
+		if (!CDAUDIO_GetTracksInfo(wDevID)) {
+            dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // error updating TracksInfo !\n");
+			return MCIERR_INTERNAL;
+			}
+		}
+	return TRUE;
+#else
+	return FALSE;
+#endif
+}
+
+
+/**************************************************************************
+* 				CDAUDIO_CalcTime			[internal]
+*/
+static DWORD CDAUDIO_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
+{
+	DWORD	dwTime = 0;
+#ifdef linux
+	UINT	wTrack;
+	UINT	wMinutes;
+	UINT	wSeconds;
+	UINT	wFrames;
+    	dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime(%u, %08lX, %lu);\n", 
+		wDevID, dwFormatType, dwFrame);
+
+	switch (dwFormatType) {
+		case MCI_FORMAT_MILLISECONDS:
+			dwTime = dwFrame / CDFRAMES_PERSEC * 1000;
+            		dprintf_cdaudio(stddeb,
+				"CDAUDIO_CalcTime // MILLISECONDS %lu\n", 
+				dwTime);
+			break;
+		case MCI_FORMAT_MSF:
+			wMinutes = dwFrame / CDFRAMES_PERMIN;
+			wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
+			wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - 
+								CDFRAMES_PERSEC * wSeconds;
+			dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
+            		dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
+								wMinutes, wSeconds, wFrames, dwTime);
+			break;
+		default:
+			/* unknown format ! force TMSF ! ... */
+			dwFormatType = MCI_FORMAT_TMSF;
+		case MCI_FORMAT_TMSF:
+			for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) {
+/*				dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
+				printf("Adding trk#%u curpos=%u \n", dwTime);
+				if (dwTime >= dwFrame) break; */
+				if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
+				}
+			wMinutes = dwFrame / CDFRAMES_PERMIN;
+			wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
+			wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - 
+								CDFRAMES_PERSEC * wSeconds;
+			dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
+            		dprintf_cdaudio(stddeb,
+				"CDAUDIO_CalcTime // %02u-%02u:%02u:%02u\n",
+					wTrack, wMinutes, wSeconds, wFrames);
+			break;
+		}
+#endif
+	return dwTime;
+}
+
+
 /**************************************************************************
 * 				CDAUDIO_mciStatus		[internal]
 */
-DWORD CDAUDIO_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
+static DWORD CDAUDIO_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus(%u, %08lX, %p);\n", 
@@ -261,7 +517,7 @@
 			case MCI_STATUS_LENGTH:
 				if (CDADev[wDevID].nTracks == 0) {
 					if (!CDAUDIO_GetTracksInfo(wDevID)) {
-                        			fprintf(stderr,"CDAUDIO_mciStatus // error reading TracksInfo !\n");
+                        			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // error reading TracksInfo !\n");
 						return MCIERR_INTERNAL;
 						}
 					}
@@ -287,7 +543,7 @@
 			case MCI_STATUS_MEDIA_PRESENT:
 				lpParms->dwReturn = (CDADev[wDevID].nTracks > 0) ? TRUE : FALSE;
 				if (lpParms->dwReturn == FALSE)
-                    			fprintf(stderr,"CDAUDIO_mciStatus // MEDIA_NOT_PRESENT !\n");
+                    			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MEDIA_NOT_PRESENT !\n");
 				else
                     			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
 			 	return 0;
@@ -324,11 +580,11 @@
 				lpParms->dwReturn = MCI_FORMAT_MILLISECONDS;
 			 	return 0;
 			default:
-                		fprintf(stderr,"CDAUDIO_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
+                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
 				return MCIERR_UNRECOGNIZED_COMMAND;
 			}
 		}
-    fprintf(stderr,"CDAUDIO_mciStatus // not MCI_STATUS_ITEM !\n");
+    dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // not MCI_STATUS_ITEM !\n");
  	return 0;
 #else
 	return MMSYSERR_NOTENABLED;
@@ -337,270 +593,9 @@
 
 
 /**************************************************************************
-* 				CDAUDIO_CalcTime			[internal]
-*/
-DWORD CDAUDIO_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
-{
-	DWORD	dwTime = 0;
-#ifdef linux
-	UINT	wTrack;
-	UINT	wMinutes;
-	UINT	wSeconds;
-	UINT	wFrames;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime(%u, %08lX, %lu);\n", 
-		wDevID, dwFormatType, dwFrame);
-TryAGAIN:
-	switch (dwFormatType) {
-		case MCI_FORMAT_MILLISECONDS:
-			dwTime = dwFrame / CDFRAMES_PERSEC * 1000;
-            		dprintf_cdaudio(stddeb,
-				"CDAUDIO_CalcTime // MILLISECONDS %lu\n", 
-				dwTime);
-			break;
-		case MCI_FORMAT_MSF:
-			wMinutes = dwFrame / CDFRAMES_PERMIN;
-			wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
-			wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - 
-								CDFRAMES_PERSEC * wSeconds;
-			dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
-            		dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
-								wMinutes, wSeconds, wFrames, dwTime);
-			break;
-		case MCI_FORMAT_TMSF:
-			for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) {
-/*				dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
-				printf("Adding trk#%u curpos=%u \n", dwTime);
-				if (dwTime >= dwFrame) break; */
-				if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
-				}
-			wMinutes = dwFrame / CDFRAMES_PERMIN;
-			wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
-			wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - 
-								CDFRAMES_PERSEC * wSeconds;
-			dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
-            		dprintf_cdaudio(stddeb,
-				"CDAUDIO_CalcTime // %02u-%02u:%02u:%02u\n",
-					wTrack, wMinutes, wSeconds, wFrames);
-			break;
-		default:
-			/* unknown format ! force TMSF ! ... */
-			dwFormatType = MCI_FORMAT_TMSF;
-			goto TryAGAIN;
-		}
-#endif
-	return dwTime;
-}
-
-
-/**************************************************************************
-* 				CDAUDIO_CalcFrame			[internal]
-*/
-DWORD CDAUDIO_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
-{
-	DWORD	dwFrame = 0;
-#ifdef linux
-	UINT	wTrack;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_CalcFrame(%u, %08lX, %lu);\n", 
-		wDevID, dwFormatType, dwTime);
-TryAGAIN:
-	switch (dwFormatType) {
-		case MCI_FORMAT_MILLISECONDS:
-			dwFrame = dwTime * CDFRAMES_PERSEC / 1000;
-            		dprintf_cdaudio(stddeb,
-				"CDAUDIO_CalcFrame // MILLISECONDS %lu\n", 
-				dwFrame);
-			break;
-		case MCI_FORMAT_MSF:
-            		dprintf_cdaudio(stddeb,
-				"CDAUDIO_CalcFrame // MSF %02u:%02u:%02u\n",
-				MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), 
-				MCI_MSF_FRAME(dwTime));
-			dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
-			dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
-			dwFrame += MCI_MSF_FRAME(dwTime);
-			break;
-		case MCI_FORMAT_TMSF:
-			wTrack = MCI_TMSF_TRACK(dwTime);
-            		dprintf_cdaudio(stddeb,
-			"CDAUDIO_CalcFrame // TMSF %02u-%02u:%02u:%02u\n",
-					MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), 
-					MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
-            		dprintf_cdaudio(stddeb,
-				"CDAUDIO_CalcFrame // TMSF trackpos[%u]=%lu\n",
-				wTrack, CDADev[wDevID].lpdwTrackPos[wTrack - 1]);
-			dwFrame = CDADev[wDevID].lpdwTrackPos[wTrack - 1];
-			dwFrame += CDFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime);
-			dwFrame += CDFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime);
-			dwFrame += MCI_TMSF_FRAME(dwTime);
-			break;
-		default:
-			/* unknown format ! force TMSF ! ... */
-			dwFormatType = MCI_FORMAT_TMSF;
-			goto TryAGAIN;
-		}
-#endif
-	return dwFrame;
-}
-
-
-/**************************************************************************
-* 				CDAUDIO_GetNumberOfTracks		[internal]
-*/
-UINT CDAUDIO_GetNumberOfTracks(UINT wDevID)
-{
-#ifdef linux
-	struct cdrom_tochdr	hdr;
-	if (CDADev[wDevID].nTracks == 0) {
-		if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCHDR, &hdr)) {
-            		fprintf(stderr,
-				"GetNumberOfTracks(%u) // Error occured !\n", 
-				wDevID);
-			return (WORD)-1;
-			}
-		CDADev[wDevID].nTracks = hdr.cdth_trk1;
-		}
-	return CDADev[wDevID].nTracks;
-#else
-	return (WORD)-1;
-#endif
-}
-
-/**************************************************************************
-* 				CDAUDIO_GetTracksInfo			[internal]
-*/
-BOOL CDAUDIO_GetTracksInfo(UINT wDevID)
-{
-#ifdef linux
-	int		i, length;
-	int		start, last_start;
-	int		total_length = 0;
-	struct cdrom_tocentry	entry;
-	if (CDADev[wDevID].nTracks == 0) {
-		if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE;
-		}
-    	dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // nTracks=%u\n", 
-		CDADev[wDevID].nTracks);
-	if (CDADev[wDevID].lpdwTrackLen != NULL) 
-		free(CDADev[wDevID].lpdwTrackLen);
-	CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc(
-		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
-	if (CDADev[wDevID].lpdwTrackPos != NULL) 
-		free(CDADev[wDevID].lpdwTrackPos);
-	CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc(
-		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
-	if (CDADev[wDevID].lpdwTrackLen == NULL ||
-		CDADev[wDevID].lpdwTrackPos == NULL) {
-        		fprintf(stderr,
-				"CDAUDIO_GetTracksInfo // error allocating track table !\n");
-		return FALSE;
-		}
-	memset(CDADev[wDevID].lpdwTrackLen, 0, 
-		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
-	memset(CDADev[wDevID].lpdwTrackPos, 0, 
-		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
-	for (i = 0; i <= CDADev[wDevID].nTracks; i++) {
-		if (i == CDADev[wDevID].nTracks)
-			entry.cdte_track = CDROM_LEADOUT;
-		else
-			entry.cdte_track = i + 1;
-		entry.cdte_format = CDROM_MSF;
-		if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCENTRY, &entry)) {
-            		fprintf(stderr,
-				"CDAUDIO_GetTracksInfo // error read entry\n");
-			return FALSE;
-			}
-		start = CDFRAMES_PERSEC * (SECONDS_PERMIN * 
-			entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) + 
-			entry.cdte_addr.msf.frame;
-		if (i == 0) {
-			last_start = start;
-			CDADev[wDevID].dwFirstOffset = start;
-            		dprintf_cdaudio(stddeb,
-				"CDAUDIO_GetTracksInfo // dwFirstOffset=%u\n", 
-				start);
-			}
-		else {
-			length = start - last_start;
-			last_start = start;
-			start = last_start - length;
-			total_length += length;
-			CDADev[wDevID].lpdwTrackLen[i - 1] = length;
-			CDADev[wDevID].lpdwTrackPos[i - 1] = start;
-            		dprintf_cdaudio(stddeb,
-			"CDAUDIO_GetTracksInfo // track #%u start=%u len=%u\n",
-				i, start, length);
-			}
-		}
-	CDADev[wDevID].dwTotalLen = total_length;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // total_len=%u\n", 
-		total_length);
-	fflush(stdout);
-	return TRUE;
-#else
-	return FALSE;
-#endif
-}
-
-
-/**************************************************************************
-* 				CDAUDIO_GetCDStatus				[internal]
-*/
-BOOL CDAUDIO_GetCDStatus(UINT wDevID)
-{
-#ifdef linux
-	int		oldmode = CDADev[wDevID].mode;
-	CDADev[wDevID].sc.cdsc_format = CDROM_MSF;
-	if (ioctl(CDADev[wDevID].unixdev, CDROMSUBCHNL, &CDADev[wDevID].sc)) {
-        	fprintf(stderr,"CDAUDIO_GetCDStatus // opened or no_media !\n");
-		CDADev[wDevID].mode = MCI_MODE_NOT_READY;
-		return TRUE;
-		}
-	switch (CDADev[wDevID].sc.cdsc_audiostatus) {
-		case CDROM_AUDIO_INVALID:
-            		fprintf(stderr,"CDAUDIO_GetCDStatus // device doesn't support status !\n");
-			return FALSE;
-		case CDROM_AUDIO_NO_STATUS: 
-			CDADev[wDevID].mode = MCI_MODE_STOP;
-            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
-			break;
-		case CDROM_AUDIO_PLAY: 
-			CDADev[wDevID].mode = MCI_MODE_PLAY;
-            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
-			break;
-		case CDROM_AUDIO_PAUSED:
-			CDADev[wDevID].mode = MCI_MODE_PAUSE;
-            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
-			break;
-		default:
-            		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // status=%02X !\n",
-					CDADev[wDevID].sc.cdsc_audiostatus);
-		}
-	CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk;
-	CDADev[wDevID].dwCurFrame = 
-		CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute +
-		CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second +
-		CDADev[wDevID].sc.cdsc_absaddr.msf.frame;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // %02u-%02u:%02u:%02u \n",
-		CDADev[wDevID].sc.cdsc_trk,
-		CDADev[wDevID].sc.cdsc_absaddr.msf.minute,
-		CDADev[wDevID].sc.cdsc_absaddr.msf.second,
-		CDADev[wDevID].sc.cdsc_absaddr.msf.frame);
-	if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) {
-		if (!CDAUDIO_GetTracksInfo(wDevID)) {
-            fprintf(stderr,"CDAUDIO_GetCDStatus // error updating TracksInfo !\n");
-			return MCIERR_INTERNAL;
-			}
-		}
-	return TRUE;
-#else
-	return FALSE;
-#endif
-}
-
-/**************************************************************************
 * 				CDAUDIO_mciPlay			[internal]
 */
-DWORD CDAUDIO_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
+static DWORD CDAUDIO_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
 {
 #ifdef linux
 	int 	start, end;
@@ -633,11 +628,11 @@
 	msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
 	msf.cdmsf_frame1 = end % CDFRAMES_PERSEC;
 	if (ioctl(CDADev[wDevID].unixdev, CDROMSTART)) {
-        	fprintf(stderr,"CDAUDIO_mciPlay // motor doesn't start !\n");
+        	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // motor doesn't start !\n");
 		return MCIERR_HARDWARE;
 		}
 	if (ioctl(CDADev[wDevID].unixdev, CDROMPLAYMSF, &msf)) {
-        	fprintf(stderr,"CDAUDIO_mciPlay // device doesn't play !\n");
+        	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // device doesn't play !\n");
 		return MCIERR_HARDWARE;
 		}
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // msf = %d:%d:%d %d:%d:%d\n",
@@ -662,7 +657,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciStop			[internal]
 */
-DWORD CDAUDIO_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD CDAUDIO_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciStop(%u, %08lX, %p);\n", 
@@ -686,7 +681,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciPause		[internal]
 */
-DWORD CDAUDIO_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD CDAUDIO_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciPause(%u, %08lX, %p);\n", 
@@ -710,7 +705,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciResume		[internal]
 */
-DWORD CDAUDIO_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD CDAUDIO_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciResume(%u, %08lX, %p);\n", 
@@ -734,7 +729,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciSeek			[internal]
 */
-DWORD CDAUDIO_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
+static DWORD CDAUDIO_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
 {
 #ifdef linux
 	DWORD	dwRet;
@@ -775,7 +770,7 @@
 /**************************************************************************
 * 				CDAUDIO_mciSet			[internal]
 */
-DWORD CDAUDIO_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
+static DWORD CDAUDIO_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
 #ifdef linux
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciSet(%u, %08lX, %p);\n", 
@@ -798,7 +793,7 @@
                 		dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // MCI_FORMAT_TMSF !\n");
 				break;
 			default:
-                		fprintf(stderr,"CDAUDIO_mciSet // bad time format !\n");
+                		dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // bad time format !\n");
 				return MCIERR_BAD_TIME_FORMAT;
 			}
 		CDADev[wDevID].dwTimeFormat = lpParms->dwTimeFormat;
@@ -835,15 +830,15 @@
 /**************************************************************************
 * 				CDAUDIO_DriverProc		[sample driver]
 */
-LRESULT CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 #ifdef linux
 	switch(wMsg) {
 		case DRV_LOAD:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_FREE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_OPEN:
 		case MCI_OPEN_DRIVER:
 		case MCI_OPEN:
@@ -854,19 +849,19 @@
 			return CDAUDIO_mciClose(dwDevID, dwParam1, 
 					(LPMCI_GENERIC_PARMS)dwParam2);
 		case DRV_ENABLE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_DISABLE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_QUERYCONFIGURE:
-			return (LRESULT)1L;
+			return 1;
 		case DRV_CONFIGURE:
 			MessageBox((HWND)NULL, "Sample MultiMedia Linux Driver !", 
 								"MMLinux Driver", MB_OK);
-			return (LRESULT)1L;
+			return 1;
 		case DRV_INSTALL:
-			return (LRESULT)DRVCNF_RESTART;
+			return DRVCNF_RESTART;
 		case DRV_REMOVE:
-			return (LRESULT)DRVCNF_RESTART;
+			return DRVCNF_RESTART;
 		case MCI_GETDEVCAPS:
 			return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1, 
 				(LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
diff --git a/multimedia/midi.c b/multimedia/midi.c
index be27086..0a61f36 100644
--- a/multimedia/midi.c
+++ b/multimedia/midi.c
@@ -2,9 +2,8 @@
  * Sample MIDI Wine Driver for Linux
  *
  * Copyright 1994 Martin Ayotte
- *
-static char Copyright[] = "Copyright  Martin Ayotte, 1994";
-*/
+ */
+
 #ifndef WINELIB
 #define BUILTIN_MMSYSTEM
 #endif 
@@ -22,7 +21,6 @@
 #include "mmsystem.h"
 
 #include "stddebug.h"
-/* #define DEBUG_MIDI */
 #include "debug.h"
 
 #ifdef linux
@@ -83,34 +81,11 @@
 static LINUX_MCIMIDI	MCIMidiDev[MAX_MCIMIDIDRV];
 #endif
 
-DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms);
-DWORD MIDI_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms);
-DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms);
-DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms);
-DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
-DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
-DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
-DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms);
-DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms);
-DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms);
-DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms);
-
-DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags);
-DWORD modClose(WORD wDevID);
-DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPS lpCaps, DWORD dwSize);
-DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize);
-DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize);
-DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize);
-DWORD modData(WORD wDevID, DWORD dwParam);
-
-DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags);
-DWORD midClose(WORD wDevID);
-DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPS lpCaps, DWORD dwSize);
 
 /**************************************************************************
 * 				MIDI_NotifyClient			[internal]
 */
-DWORD MIDI_NotifyClient(UINT wDevID, WORD wMsg, 
+static DWORD MIDI_NotifyClient(UINT wDevID, WORD wMsg, 
 				DWORD dwParam1, DWORD dwParam2)
 {
 #ifdef linux
@@ -118,7 +93,7 @@
 		MidiInDev[wDevID].midiDesc.dwCallback, MidiInDev[wDevID].wFlags, 
 		MidiInDev[wDevID].midiDesc.hMidi, wMsg, 
 		MidiInDev[wDevID].midiDesc.dwInstance, dwParam1, dwParam2)) {
-		printf("MIDI_NotifyClient // can't notify client !\n");
+		dprintf_midi(stddeb, "MIDI_NotifyClient // can't notify client !\n");
 		return MMSYSERR_NOERROR;
 		}
         return 0;
@@ -129,72 +104,9 @@
 
 
 /**************************************************************************
-* 				AUDIO_DriverProc		[sample driver]
-*/
-LRESULT MIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
-						DWORD dwParam1, DWORD dwParam2)
-{
-#ifdef linux
-	switch(wMsg) {
-		case DRV_LOAD:
-			return (LRESULT)1L;
-		case DRV_FREE:
-			return (LRESULT)1L;
-		case DRV_OPEN:
-			return (LRESULT)1L;
-		case DRV_CLOSE:
-			return (LRESULT)1L;
-		case DRV_ENABLE:
-			return (LRESULT)1L;
-		case DRV_DISABLE:
-			return (LRESULT)1L;
-		case DRV_QUERYCONFIGURE:
-			return (LRESULT)1L;
-		case DRV_CONFIGURE:
-			MessageBox((HWND)NULL, "Sample Midi Linux Driver !", 
-								"MMLinux Driver", MB_OK);
-			return (LRESULT)1L;
-		case DRV_INSTALL:
-			return (LRESULT)DRVCNF_RESTART;
-		case DRV_REMOVE:
-			return (LRESULT)DRVCNF_RESTART;
-		case MCI_OPEN_DRIVER:
-		case MCI_OPEN:
-			return MIDI_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_CLOSE_DRIVER:
-		case MCI_CLOSE:
-			return MIDI_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_PLAY:
-			return MIDI_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_RECORD:
-			return MIDI_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_STOP:
-			return MIDI_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_SET:
-			return MIDI_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_PAUSE:
-			return MIDI_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_RESUME:
-			return MIDI_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_STATUS:
-			return MIDI_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_GETDEVCAPS:
-			return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		case MCI_INFO:
-			return MIDI_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
-		default:
-			return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
-		}
-#else
-	return MMSYSERR_NOTENABLED;
-#endif
-}
-
-
-/**************************************************************************
 * 				MIDI_ReadByte			[internal]	
 */
-DWORD MIDI_ReadByte(UINT wDevID, BYTE FAR *lpbyt)
+static DWORD MIDI_ReadByte(UINT wDevID, BYTE FAR *lpbyt)
 {
 #ifdef linux
 	if (lpbyt != NULL) {
@@ -203,7 +115,7 @@
 			return 0;
 			}
 		}
-	printf("MIDI_ReadByte // error reading wDevID=%d \n", wDevID);
+	dprintf_midi(stddeb, "MIDI_ReadByte // error reading wDevID=%d \n", wDevID);
 	return MCIERR_INTERNAL;
 
 #else
@@ -215,7 +127,7 @@
 /**************************************************************************
 * 				MIDI_ReadWord			[internal]	
 */
-DWORD MIDI_ReadWord(UINT wDevID, LPWORD lpw)
+static DWORD MIDI_ReadWord(UINT wDevID, LPWORD lpw)
 {
 	BYTE	hibyte, lobyte;
 	if (lpw != NULL) {
@@ -226,7 +138,7 @@
 				}
 			}
 		}
-	printf("MIDI_ReadWord // error reading wDevID=%d \n", wDevID);
+	dprintf_midi(stddeb, "MIDI_ReadWord // error reading wDevID=%d \n", wDevID);
 	return MCIERR_INTERNAL;
 }
 
@@ -234,7 +146,7 @@
 /**************************************************************************
 * 				MIDI_ReadLong			[internal]	
 */
-DWORD MIDI_ReadLong(UINT wDevID, LPDWORD lpdw)
+static DWORD MIDI_ReadLong(UINT wDevID, LPDWORD lpdw)
 {
 	WORD	hiword, loword;
 	if (lpdw != NULL) {
@@ -245,7 +157,7 @@
 				}
 			}
 		}
-	printf("MIDI_ReadLong // error reading wDevID=%d \n", wDevID);
+	dprintf_midi(stddeb, "MIDI_ReadLong // error reading wDevID=%d \n", wDevID);
 	return MCIERR_INTERNAL;
 }
 
@@ -253,26 +165,26 @@
 /**************************************************************************
 * 				MIDI_ReadVaryLen		[internal]	
 */
-DWORD MIDI_ReadVaryLen(UINT wDevID, LPDWORD lpdw)
+static DWORD MIDI_ReadVaryLen(UINT wDevID, LPDWORD lpdw)
 {
 	BYTE	byte;
 	DWORD	value;
 	if (lpdw == NULL) return MCIERR_INTERNAL;
 	if (MIDI_ReadByte(wDevID, &byte) != 0) {
-		printf("MIDI_ReadVaryLen // error reading wDevID=%d \n", wDevID);
+		dprintf_midi(stddeb, "MIDI_ReadVaryLen // error reading wDevID=%d \n", wDevID);
 		return MCIERR_INTERNAL;
 		}
 	value = (DWORD)(byte & 0x7F);
 	while (byte & 0x80) {
 		if (MIDI_ReadByte(wDevID, &byte) != 0) {
-			printf("MIDI_ReadVaryLen // error reading wDevID=%d \n", wDevID);
+			dprintf_midi(stddeb, "MIDI_ReadVaryLen // error reading wDevID=%d \n", wDevID);
 			return MCIERR_INTERNAL;
 			}
 		value = (value << 7) + (byte & 0x7F);
 		}
 	*lpdw = value;
 /*
-	printf("MIDI_ReadVaryLen // val=%08lX \n", value);
+	dprintf_midi(stddeb, "MIDI_ReadVaryLen // val=%08lX \n", value);
 */
 	return 0;
 }
@@ -281,14 +193,14 @@
 /**************************************************************************
 * 				MIDI_ReadMThd			[internal]	
 */
-DWORD MIDI_ReadMThd(UINT wDevID, DWORD dwOffset)
+static DWORD MIDI_ReadMThd(UINT wDevID, DWORD dwOffset)
 {
 #ifdef linux
 	DWORD	toberead;
 	FOURCC	fourcc;
 	dprintf_midi(stddeb, "MIDI_ReadMThd(%04X, %08lX);\n", wDevID, dwOffset);
 	if (mmioSeek(MCIMidiDev[wDevID].hFile, dwOffset, SEEK_SET) != dwOffset) {
-		printf("MIDI_ReadMThd // can't seek at %08lX begin of 'MThd' \n", dwOffset);
+		dprintf_midi(stddeb, "MIDI_ReadMThd // can't seek at %08lX begin of 'MThd' \n", dwOffset);
 		return MCIERR_INTERNAL;
 		}
 	if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc,
@@ -307,7 +219,7 @@
 	if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].nTempo) != 0) {
 		return MCIERR_INTERNAL;
 		}
-	printf("MIDI_ReadMThd // toberead=%08lX, wFormat=%04X nTracks=%04X nTempo=%04X\n",
+	dprintf_midi(stddeb, "MIDI_ReadMThd // toberead=%08lX, wFormat=%04X nTracks=%04X nTempo=%04X\n",
 		toberead, MCIMidiDev[wDevID].wFormat,
 		MCIMidiDev[wDevID].nTracks,
 		MCIMidiDev[wDevID].nTempo);
@@ -324,13 +236,13 @@
 }
 
 
-DWORD MIDI_ReadMTrk(UINT wDevID, DWORD dwOffset)
+static DWORD MIDI_ReadMTrk(UINT wDevID, DWORD dwOffset)
 {
 #ifdef linux
 	DWORD	toberead;
 	FOURCC	fourcc;
 	if (mmioSeek(MCIMidiDev[wDevID].hFile, dwOffset, SEEK_SET) != dwOffset) {
-		printf("MIDI_ReadMTrk // can't seek at %08lX begin of 'MThd' \n", dwOffset);
+		dprintf_midi(stddeb, "MIDI_ReadMTrk // can't seek at %08lX begin of 'MThd' \n", dwOffset);
 		}
 	if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc,
 		(long) sizeof(FOURCC)) != (long) sizeof(FOURCC)) {
@@ -339,7 +251,7 @@
 	if (MIDI_ReadLong(wDevID, &toberead) != 0) {
 		return MCIERR_INTERNAL;
 		}
-	printf("MIDI_ReadMTrk // toberead=%08lX\n", toberead);
+	dprintf_midi(stddeb, "MIDI_ReadMTrk // toberead=%08lX\n", toberead);
 	toberead -= 3 * sizeof(WORD);
 	MCIMidiDev[wDevID].dwTotalLen = toberead;
 	return 0;
@@ -352,7 +264,7 @@
 /**************************************************************************
 * 				MIDI_mciOpen			[internal]	
 */
-DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
+static DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
 {
 #ifdef linux
 	MIDIOPENDESC 	MidiDesc;
@@ -361,7 +273,7 @@
 	LPSTR		lpstrElementName;
 	char		str[128];
 
-	dprintf_midi( stddeb, "MIDI_mciOpen(%08lX, %p)\n", dwFlags, lpParms);
+	dprintf_midi(stddeb, "MIDI_mciOpen(%08lX, %p)\n", dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (MCIMidiDev[wDevID].nUseCount > 0) {
 		/* The driver already open on this channel */
@@ -376,28 +288,28 @@
 		MCIMidiDev[wDevID].nUseCount = 1;
 		MCIMidiDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE;
 		}
-	dprintf_midi(stddeb,"MIDI_mciOpen // wDevID=%04X\n", wDevID);
+	dprintf_midi(stddeb, "MIDI_mciOpen // wDevID=%04X\n", wDevID);
 	lpParms->wDeviceID = wDevID;
-	dprintf_midi(stddeb,"MIDI_mciOpen // lpParms->wDevID=%04X\n", lpParms->wDeviceID);
-	dprintf_midi(stddeb,"MIDI_mciOpen // before OPEN_ELEMENT\n");
+	dprintf_midi(stddeb, "MIDI_mciOpen // lpParms->wDevID=%04X\n", lpParms->wDeviceID);
+	dprintf_midi(stddeb, "MIDI_mciOpen // before OPEN_ELEMENT\n");
     if (dwFlags & MCI_OPEN_ELEMENT) {
 		lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(lpParms->lpstrElementName);
-		dprintf_midi( stddeb, "MIDI_mciOpen // MCI_OPEN_ELEMENT '%s' !\n", lpstrElementName);
-/*		printf("MIDI_mciOpen // cdw='%s'\n", DOS_GetCurrentDir(DOS_GetDefaultDrive())); */
+		dprintf_midi(stddeb, "MIDI_mciOpen // MCI_OPEN_ELEMENT '%s' !\n", lpstrElementName);
+/*		dprintf_midi(stddeb, "MIDI_mciOpen // cdw='%s'\n", DOS_GetCurrentDir(DOS_GetDefaultDrive())); */
 		if (strlen(lpstrElementName) > 0) {
 			strcpy(str, lpstrElementName);
 			AnsiUpper(str);
 			MCIMidiDev[wDevID].hFile = mmioOpen(str, NULL, 
 				MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_EXCLUSIVE);
 			if (MCIMidiDev[wDevID].hFile == 0) {
-				printf("MIDI_mciOpen // can't find file='%s' !\n", str);
+				dprintf_midi(stddeb, "MIDI_mciOpen // can't find file='%s' !\n", str);
 				return MCIERR_FILE_NOT_FOUND;
 				}
 			}
 		else 
 			MCIMidiDev[wDevID].hFile = 0;
 		}
-	printf("MIDI_mciOpen // hFile=%u\n", MCIMidiDev[wDevID].hFile);
+	dprintf_midi(stddeb, "MIDI_mciOpen // hFile=%u\n", MCIMidiDev[wDevID].hFile);
 	memcpy(&MCIMidiDev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS));
 	MCIMidiDev[wDevID].wNotifyDeviceID = lpParms->wDeviceID;
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
@@ -414,25 +326,25 @@
 				ckMainRIFF.cksize);
 		dwOffset = 0;
 		if (ckMainRIFF.ckid == mmioFOURCC('R', 'M', 'I', 'D')) {
-			printf("MIDI_mciOpen // is a 'RMID' file \n");
+			dprintf_midi(stddeb, "MIDI_mciOpen // is a 'RMID' file \n");
 			dwOffset = ckMainRIFF.dwDataOffset;
 			}
 		if (ckMainRIFF.ckid != mmioFOURCC('M', 'T', 'h', 'd')) {
-			printf("MIDI_mciOpen // unknown format !\n");
+			dprintf_midi(stddeb, "MIDI_mciOpen // unknown format !\n");
 			return MCIERR_INTERNAL;
 			}
 		if (MIDI_ReadMThd(wDevID, dwOffset) != 0) {
-			printf("MIDI_mciOpen // can't read 'MThd' header \n");
+			dprintf_midi(stddeb, "MIDI_mciOpen // can't read 'MThd' header \n");
 			return MCIERR_INTERNAL;
 			}
 		dwOffset = mmioSeek(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR);
 		if (MIDI_ReadMTrk(wDevID, dwOffset) != 0) {
-			printf("MIDI_mciOpen // can't read 'MTrk' header \n");
+			dprintf_midi(stddeb, "MIDI_mciOpen // can't read 'MTrk' header \n");
 			return MCIERR_INTERNAL;
 			}
 		dwOffset = mmioSeek(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR);
 		MCIMidiDev[wDevID].dwBeginData = dwOffset;
-		dprintf_midi(stddeb,"MIDI_mciOpen // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
+		dprintf_midi(stddeb, "MIDI_mciOpen // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
 				(LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType,
 				ckMainRIFF.cksize);
 		}
@@ -446,15 +358,31 @@
 
 
 /**************************************************************************
+* 				MIDI_mciStop			[internal]
+*/
+static DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+{
+#ifdef linux
+	dprintf_midi(stddeb, "MIDI_mciStop(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
+	if (lpParms == NULL) return MCIERR_INTERNAL;
+	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
+	dprintf_midi(stddeb, "MIDI_mciStop // MCIMidiDev[wDevID].dwStatus=%p %d\n",
+			&MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
+	return 0;
+#else
+	return MCIERR_INTERNAL;
+#endif
+}
+
+
+/**************************************************************************
 * 				MIDI_mciClose		[internal]
 */
-DWORD MIDI_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
+static DWORD MIDI_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
 	DWORD		dwRet;
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciClose(%u, %08lX, %p);\n", wDevID, dwParam, lpParms);
-#endif
+	dprintf_midi(stddeb, "MIDI_mciClose(%u, %08lX, %p);\n", wDevID, dwParam, lpParms);
 	if (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
 		MIDI_mciStop(wDevID, MCI_WAIT, lpParms);
 		}
@@ -464,7 +392,7 @@
 		if (MCIMidiDev[wDevID].hFile != 0) {
 			mmioClose(MCIMidiDev[wDevID].hFile, 0);
 			MCIMidiDev[wDevID].hFile = 0;
-			printf("MIDI_mciClose // hFile closed !\n");
+			dprintf_midi(stddeb, "MIDI_mciClose // hFile closed !\n");
 			}
 		dwRet = modMessage(0, MODM_CLOSE, 0, 0L, 0L);
 		if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL;
@@ -481,7 +409,7 @@
 /**************************************************************************
 * 				MIDI_mciPlay		[internal]
 */
-DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
+static DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
 {
 #ifdef linux
 	int			count;
@@ -490,39 +418,37 @@
 	DWORD		dwData;
 	LPWORD		ptr;
 	DWORD		dwRet;
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciPlay(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
-#endif
+	dprintf_midi(stddeb, "MIDI_mciPlay(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (MCIMidiDev[wDevID].hFile == 0) {
-		printf("MIDI_mciPlay // can't find file='%s' !\n", 
+		dprintf_midi(stddeb, "MIDI_mciPlay // can't find file='%s' !\n", 
 				MCIMidiDev[wDevID].openParms.lpstrElementName);
 		return MCIERR_FILE_NOT_FOUND;
 		}
 	start = 1; 		end = 99999;
 	if (dwFlags & MCI_FROM) {
 		start = lpParms->dwFrom; 
-		printf("MIDI_mciPlay // MCI_FROM=%d \n", start);
+		dprintf_midi(stddeb, "MIDI_mciPlay // MCI_FROM=%d \n", start);
 		}
 	if (dwFlags & MCI_TO) {
 		end = lpParms->dwTo;
-		printf("MIDI_mciPlay // MCI_TO=%d \n", end);
+		dprintf_midi(stddeb, "MIDI_mciPlay // MCI_TO=%d \n", end);
 		}
-/**/
+#if 0
 	if (dwFlags & MCI_NOTIFY) {
-		printf("MIDI_mciPlay // MCI_NOTIFY %08lX !\n", lpParms->dwCallback);
+		dprintf_midi(stddeb, "MIDI_mciPlay // MCI_NOTIFY %08lX !\n", lpParms->dwCallback);
 		switch(fork()) {
 			case -1:
-				printf("MIDI_mciPlay // Can't 'fork' process !\n");
+				dprintf_midi(stddeb, "MIDI_mciPlay // Can't 'fork' process !\n");
 				break;
 			case 0:
-				printf("MIDI_mciPlay // process started ! play in background ...\n");
+				dprintf_midi(stddeb, "MIDI_mciPlay // process started ! play in background ...\n");
 				break;
 			default:
-				printf("MIDI_mciPlay // process started ! return to caller...\n");
+				dprintf_midi(stddeb, "MIDI_mciPlay // process started ! return to caller...\n");
 				return 0;
 			}
 		}
-/**/
+#endif
 	lpMidiHdr = &MCIMidiDev[wDevID].MidiHdr;
 	lpMidiHdr->lpData = (LPSTR) malloc(1200);
 	if (lpMidiHdr->lpData == NULL) return MCIERR_INTERNAL;
@@ -530,10 +456,10 @@
 	lpMidiHdr->dwUser = 0L;
 	lpMidiHdr->dwFlags = 0L;
 	dwRet = modMessage(0, MODM_PREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
-/*	printf("MIDI_mciPlay // after MODM_PREPARE \n"); */
+/*	dprintf_midi(stddeb, "MIDI_mciPlay // after MODM_PREPARE \n"); */
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_PLAY;
 	while(MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
-		printf("MIDI_mciPlay // MCIMidiDev[wDevID].dwStatus=%p %d\n",
+		dprintf_midi(stddeb, "MIDI_mciPlay // MCIMidiDev[wDevID].dwStatus=%p %d\n",
 			&MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
 		ptr = (LPWORD)lpMidiHdr->lpData;
 		for (count = 0; count < lpMidiHdr->dwBufferLength; count++) {
@@ -545,10 +471,8 @@
 */
 		if (count < 1) break;
 		lpMidiHdr->dwBytesRecorded = count;
-#ifdef DEBUG_MIDI
-		printf("MIDI_mciPlay // before MODM_LONGDATA lpMidiHdr=%p dwBytesRecorded=%lu\n",
+		dprintf_midi(stddeb, "MIDI_mciPlay // before MODM_LONGDATA lpMidiHdr=%p dwBytesRecorded=%lu\n",
 					lpMidiHdr, lpMidiHdr->dwBytesRecorded);
-#endif
 		dwRet = modMessage(0, MODM_LONGDATA, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
 		}
 	dwRet = modMessage(0, MODM_UNPREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
@@ -558,9 +482,7 @@
 		}
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
-#ifdef DEBUG_MIDI
-		printf("MIDI_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
-#endif
+		dprintf_midi(stddeb, "MIDI_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		exit(1);
@@ -575,27 +497,27 @@
 /**************************************************************************
 * 				MIDI_mciRecord			[internal]
 */
-DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
+static DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
 {
 #ifdef linux
 	int			start, end;
 	LPMIDIHDR	lpMidiHdr;
 	DWORD		dwRet;
 
-	dprintf_midi( stddeb, "MIDI_mciRecord(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
+	dprintf_midi(stddeb, "MIDI_mciRecord(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (MCIMidiDev[wDevID].hFile == 0) {
-		printf("MIDI_mciRecord // can't find file='%s' !\n", 
+		dprintf_midi(stddeb, "MIDI_mciRecord // can't find file='%s' !\n", 
 				MCIMidiDev[wDevID].openParms.lpstrElementName);
 		return MCIERR_FILE_NOT_FOUND;
 		}
 	start = 1; 		end = 99999;
 	if (dwFlags & MCI_FROM) {
 		start = lpParms->dwFrom; 
-		printf("MIDI_mciRecord // MCI_FROM=%d \n", start);
+		dprintf_midi(stddeb, "MIDI_mciRecord // MCI_FROM=%d \n", start);
 		}
 	if (dwFlags & MCI_TO) {
 		end = lpParms->dwTo;
-		printf("MIDI_mciRecord // MCI_TO=%d \n", end);
+		dprintf_midi(stddeb, "MIDI_mciRecord // MCI_TO=%d \n", end);
 		}
 	lpMidiHdr = &MCIMidiDev[wDevID].MidiHdr;
 	lpMidiHdr->lpData = (LPSTR) malloc(1200);
@@ -603,29 +525,27 @@
 	lpMidiHdr->dwUser = 0L;
 	lpMidiHdr->dwFlags = 0L;
 	dwRet = midMessage(0, MIDM_PREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
-	printf("MIDI_mciRecord // after MIDM_PREPARE \n");
+	dprintf_midi(stddeb, "MIDI_mciRecord // after MIDM_PREPARE \n");
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_RECORD;
 	while(MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
-		printf("MIDI_mciRecord // MCIMidiDev[wDevID].dwStatus=%p %d\n",
+		dprintf_midi(stddeb, "MIDI_mciRecord // MCIMidiDev[wDevID].dwStatus=%p %d\n",
 			&MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
 		lpMidiHdr->dwBytesRecorded = 0;
 		dwRet = midMessage(0, MIDM_START, 0, 0L, 0L);
-		printf("MIDI_mciRecord // after MIDM_START lpMidiHdr=%p dwBytesRecorded=%lu\n",
+		dprintf_midi(stddeb, "MIDI_mciRecord // after MIDM_START lpMidiHdr=%p dwBytesRecorded=%lu\n",
 					lpMidiHdr, lpMidiHdr->dwBytesRecorded);
 		if (lpMidiHdr->dwBytesRecorded == 0) break;
 		}
-	printf("MIDI_mciRecord // before MIDM_UNPREPARE \n");
+	dprintf_midi(stddeb, "MIDI_mciRecord // before MIDM_UNPREPARE \n");
 	dwRet = midMessage(0, MIDM_UNPREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
-	printf("MIDI_mciRecord // after MIDM_UNPREPARE \n");
+	dprintf_midi(stddeb, "MIDI_mciRecord // after MIDM_UNPREPARE \n");
 	if (lpMidiHdr->lpData != NULL) {
 		free(lpMidiHdr->lpData);
 		lpMidiHdr->lpData = NULL;
 		}
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
-#ifdef DEBUG_MIDI
-		printf("MIDI_mciRecord // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
-#endif
+		dprintf_midi(stddeb, "MIDI_mciRecord // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		}
@@ -637,34 +557,12 @@
 
 
 /**************************************************************************
-* 				MIDI_mciStop			[internal]
-*/
-DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
-{
-#ifdef linux
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciStop(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
-#endif
-	if (lpParms == NULL) return MCIERR_INTERNAL;
-	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
-	printf("MIDI_mciStop // MCIMidiDev[wDevID].dwStatus=%p %d\n",
-			&MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
-	return 0;
-#else
-	return MCIERR_INTERNAL;
-#endif
-}
-
-
-/**************************************************************************
 * 				MIDI_mciPause			[internal]
 */
-DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciPause(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
-#endif
+	dprintf_midi(stddeb, "MIDI_mciPause(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
 #else
@@ -676,12 +574,10 @@
 /**************************************************************************
 * 				MIDI_mciResume			[internal]
 */
-DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
+static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciResume(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
-#endif
+	dprintf_midi(stddeb, "MIDI_mciResume(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
 #else
@@ -693,30 +589,26 @@
 /**************************************************************************
 * 				MIDI_mciSet			[internal]
 */
-DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
+static DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
 #ifdef linux
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciSet(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
-#endif
+	dprintf_midi(stddeb, "MIDI_mciSet(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
-	printf("MIDI_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
-#endif
+	dprintf_midi(stddeb, "MIDI_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
+	dprintf_midi(stddeb, "MIDI_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
 	if (dwFlags & MCI_SET_TIME_FORMAT) {
 		switch (lpParms->dwTimeFormat) {
 			case MCI_FORMAT_MILLISECONDS:
-				printf("MIDI_mciSet // MCI_FORMAT_MILLISECONDS !\n");
+				dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_MILLISECONDS !\n");
 				break;
 			case MCI_FORMAT_BYTES:
-				printf("MIDI_mciSet // MCI_FORMAT_BYTES !\n");
+				dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_BYTES !\n");
 				break;
 			case MCI_FORMAT_SAMPLES:
-				printf("MIDI_mciSet // MCI_FORMAT_SAMPLES !\n");
+				dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_SAMPLES !\n");
 				break;
 			default:
-				printf("MIDI_mciSet // bad time format !\n");
+				dprintf_midi(stddeb, "MIDI_mciSet // bad time format !\n");
 				return MCIERR_BAD_TIME_FORMAT;
 			}
 		}
@@ -724,34 +616,34 @@
 	if (dwFlags & MCI_SET_DOOR_OPEN) return MCIERR_UNSUPPORTED_FUNCTION;
 	if (dwFlags & MCI_SET_DOOR_CLOSED) return MCIERR_UNSUPPORTED_FUNCTION;
 	if (dwFlags & MCI_SET_AUDIO) {
-		printf("MIDI_mciSet // MCI_SET_AUDIO !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_AUDIO !\n");
 		}
 	if (dwFlags && MCI_SET_ON) {
-		printf("MIDI_mciSet // MCI_SET_ON !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_ON !\n");
 		if (dwFlags && MCI_SET_AUDIO_LEFT) {
-			printf("MIDI_mciSet // MCI_SET_AUDIO_LEFT !\n");
+			dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_AUDIO_LEFT !\n");
 			}
 		if (dwFlags && MCI_SET_AUDIO_RIGHT) {
-			printf("MIDI_mciSet // MCI_SET_AUDIO_RIGHT !\n");
+			dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_AUDIO_RIGHT !\n");
 			}
 		}
 	if (dwFlags & MCI_SET_OFF) {
-		printf("MIDI_mciSet // MCI_SET_OFF !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_OFF !\n");
 		}
 	if (dwFlags & MCI_SEQ_SET_MASTER) {
-		printf("MIDI_mciSet // MCI_SEQ_SET_MASTER !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_MASTER !\n");
 		}
 	if (dwFlags & MCI_SEQ_SET_SLAVE) {
-		printf("MIDI_mciSet // MCI_SEQ_SET_SLAVE !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_SLAVE !\n");
 		}
 	if (dwFlags & MCI_SEQ_SET_OFFSET) {
-		printf("MIDI_mciSet // MCI_SEQ_SET_OFFSET !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_OFFSET !\n");
 		}
 	if (dwFlags & MCI_SEQ_SET_PORT) {
-		printf("MIDI_mciSet // MCI_SEQ_SET_PORT !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_PORT !\n");
 		}
 	if (dwFlags & MCI_SEQ_SET_TEMPO) {
-		printf("MIDI_mciSet // MCI_SEQ_SET_TEMPO !\n");
+		dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_TEMPO !\n");
 		}
  	return 0;
 #else
@@ -763,12 +655,10 @@
 /**************************************************************************
 * 				MIDI_mciStatus		[internal]
 */
-DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
+static DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
 #ifdef linux
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciStatus(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
-#endif
+	dprintf_midi(stddeb, "MIDI_mciStatus(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_STATUS_ITEM) {
 		switch(lpParms->dwItem) {
@@ -786,7 +676,7 @@
 				lpParms->dwReturn = MCI_MODE_STOP;
 				break;
 			case MCI_STATUS_MEDIA_PRESENT:
-				printf("MIDI_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
 				lpParms->dwReturn = TRUE;
 				break;
 			case MCI_STATUS_NUMBER_OF_TRACKS:
@@ -803,44 +693,44 @@
 					}
 				break;
 			case MCI_STATUS_READY:
-				printf("MIDI_mciStatus // MCI_STATUS_READY !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_READY !\n");
 				lpParms->dwReturn = TRUE;
 				break;
 			case MCI_STATUS_TIME_FORMAT:
-				printf("MIDI_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
 				lpParms->dwReturn = MCI_FORMAT_MILLISECONDS;
 				break;
 			case MCI_SEQ_STATUS_DIVTYPE:
-				printf("MIDI_mciStatus // MCI_SEQ_STATUS_DIVTYPE !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_DIVTYPE !\n");
 				lpParms->dwReturn = 0;
 				break;
 			case MCI_SEQ_STATUS_MASTER:
-				printf("MIDI_mciStatus // MCI_SEQ_STATUS_MASTER !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_MASTER !\n");
 				lpParms->dwReturn = 0;
 				break;
 			case MCI_SEQ_STATUS_SLAVE:
-				printf("MIDI_mciStatus // MCI_SEQ_STATUS_SLAVE !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_SLAVE !\n");
 				lpParms->dwReturn = 0;
 				break;
 			case MCI_SEQ_STATUS_OFFSET:
-				printf("MIDI_mciStatus // MCI_SEQ_STATUS_OFFSET !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_OFFSET !\n");
 				lpParms->dwReturn = 0;
 				break;
 			case MCI_SEQ_STATUS_PORT:
-				printf("MIDI_mciStatus // MCI_SEQ_STATUS_PORT !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_PORT !\n");
 				lpParms->dwReturn = 0;
 				break;
 			case MCI_SEQ_STATUS_TEMPO:
-				printf("MIDI_mciStatus // MCI_SEQ_STATUS_TEMPO !\n");
+				dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_TEMPO !\n");
 				lpParms->dwReturn = 0;
 				break;
 			default:
-				printf("MIDI_mciStatus // unknowm command %08lX !\n", lpParms->dwItem);
+				dprintf_midi(stddeb, "MIDI_mciStatus // unknowm command %08lX !\n", lpParms->dwItem);
 				return MCIERR_UNRECOGNIZED_COMMAND;
 			}
 		}
 	if (dwFlags & MCI_NOTIFY) {
-		printf("MIDI_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
+		dprintf_midi(stddeb, "MIDI_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		}
@@ -853,11 +743,11 @@
 /**************************************************************************
 * 				MIDI_mciGetDevCaps		[internal]
 */
-DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
+static DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
 					LPMCI_GETDEVCAPS_PARMS lpParms)
 {
 #ifdef linux
-	printf("MIDI_mciGetDevCaps(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
+	dprintf_midi(stddeb, "MIDI_mciGetDevCaps(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_GETDEVCAPS_ITEM) {
 		switch(lpParms->dwItem) {
@@ -901,10 +791,10 @@
 /**************************************************************************
 * 				MIDI_mciInfo			[internal]
 */
-DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
+static DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
 #ifdef linux
-	printf("MIDI_mciInfo(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
+	dprintf_midi(stddeb, "MIDI_mciInfo(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	lpParms->lpstrReturn = NULL;
 	switch(dwFlags) {
@@ -934,39 +824,39 @@
 /**************************************************************************
 * 				midGetDevCaps			[internal]
 */
-DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPS lpCaps, DWORD dwSize)
+static DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPS lpCaps, DWORD dwSize)
 {
-	printf("midGetDevCaps(%u, %p, %08lX);\n", wDevID, lpCaps, dwSize);
+	dprintf_midi(stddeb, "midGetDevCaps(%u, %p, %08lX);\n", wDevID, lpCaps, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
 /**************************************************************************
 * 				midOpen					[internal]
 */
-DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
+static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
 {
 #ifdef linux
 	int		midi;
 	dprintf_midi(stddeb,
 		"midOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
-		fprintf(stderr,"Linux 'midOpen' // Invalid Parameter !\n");
+		dprintf_midi(stddeb,"Linux 'midOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	if (wDevID >= MAX_MIDIINDRV) {
-		fprintf(stderr,"Linux 'midOpen' // MAX_MIDIINDRV reached !\n");
+		dprintf_midi(stddeb,"Linux 'midOpen' // MAX_MIDIINDRV reached !\n");
 		return MMSYSERR_ALLOCATED;
 		}
 	MidiInDev[wDevID].unixdev = 0;
 	midi = open (MIDI_DEV, O_RDONLY, 0);
 	if (midi == -1) {
-		fprintf(stderr,"Linux 'midOpen' // can't open !\n");
+		dprintf_midi(stddeb,"Linux 'midOpen' // can't open !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
 	switch(MidiInDev[wDevID].wFlags) {
 		case DCB_NULL:
-			fprintf(stderr,"Linux 'midOpen' // CALLBACK_NULL !\n");
+			dprintf_midi(stddeb,"Linux 'midOpen' // CALLBACK_NULL !\n");
 			break;
 		case DCB_WINDOW:
 			dprintf_midi(stddeb,
@@ -986,7 +876,7 @@
 	MidiInDev[wDevID].dwTotalPlayed = 0;
 	MidiInDev[wDevID].bufsize = 0x3FFF;
 	if (MIDI_NotifyClient(wDevID, MIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'midOpen' // can't notify client !\n");
+		dprintf_midi(stddeb,"Linux 'midOpen' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
@@ -998,19 +888,19 @@
 /**************************************************************************
 * 				midClose				[internal]
 */
-DWORD midClose(WORD wDevID)
+static DWORD midClose(WORD wDevID)
 {
 #ifdef linux
-	dprintf_midi(stddeb,"midClose(%u);\n", wDevID);
+	dprintf_midi(stddeb, "midClose(%u);\n", wDevID);
 	if (MidiInDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'midClose' // can't close !\n");
+		dprintf_midi(stddeb,"Linux 'midClose' // can't close !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	close(MidiInDev[wDevID].unixdev);
 	MidiInDev[wDevID].unixdev = 0;
 	MidiInDev[wDevID].bufsize = 0;
 	if (MIDI_NotifyClient(wDevID, MIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'midClose' // can't notify client !\n");
+		dprintf_midi(stddeb,"Linux 'midClose' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
@@ -1022,36 +912,36 @@
 /**************************************************************************
 * 				midAddBuffer		[internal]
 */
-DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
+static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-	printf("midAddBuffer(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
+	dprintf_midi(stddeb, "midAddBuffer(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
 /**************************************************************************
 * 				midPrepare			[internal]
 */
-DWORD midPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
+static DWORD midPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-	printf("midPrepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
+	dprintf_midi(stddeb, "midPrepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
 /**************************************************************************
 * 				midUnprepare			[internal]
 */
-DWORD midUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
+static DWORD midUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-	printf("midUnprepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
+	dprintf_midi(stddeb, "midUnprepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
 /**************************************************************************
 * 				midReset				[internal]
 */
-DWORD midReset(WORD wDevID)
+static DWORD midReset(WORD wDevID)
 {
-	printf("midReset(%u);\n", wDevID);
+	dprintf_midi(stddeb, "midReset(%u);\n", wDevID);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1059,9 +949,9 @@
 /**************************************************************************
 * 				midStart				[internal]
 */
-DWORD midStart(WORD wDevID)
+static DWORD midStart(WORD wDevID)
 {
-	printf("midStart(%u);\n", wDevID);
+	dprintf_midi(stddeb, "midStart(%u);\n", wDevID);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1069,9 +959,9 @@
 /**************************************************************************
 * 				midStop					[internal]
 */
-DWORD midStop(WORD wDevID)
+static DWORD midStop(WORD wDevID)
 {
-	printf("midStop(%u);\n", wDevID);
+	dprintf_midi(stddeb, "midStop(%u);\n", wDevID);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1082,7 +972,7 @@
 DWORD midMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2)
 {
-	printf("midMessage(%u, %04X, %08lX, %08lX, %08lX);\n", 
+	dprintf_midi(stddeb, "midMessage(%u, %04X, %08lX, %08lX, %08lX);\n", 
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
 	switch(wMsg) {
 		case MIDM_OPEN:
@@ -1098,7 +988,7 @@
 		case MIDM_GETDEVCAPS:
 			return midGetDevCaps(wDevID, (LPMIDIINCAPS)PTR_SEG_TO_LIN(dwParam1), dwParam2);
 		case MIDM_GETNUMDEVS:
-			return 0L;
+			return 0;
 		case MIDM_RESET:
 			return midReset(wDevID);
 		case MIDM_START:
@@ -1117,9 +1007,9 @@
 /**************************************************************************
 * 				modGetDevCaps			[internal]
 */
-DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPS lpCaps, DWORD dwSize)
+static DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPS lpCaps, DWORD dwSize)
 {
-	printf("modGetDevCaps(%u, %p, %08lX);\n", wDevID, lpCaps, dwSize);
+	dprintf_midi(stddeb, "modGetDevCaps(%u, %p, %08lX);\n", wDevID, lpCaps, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1127,30 +1017,30 @@
 /**************************************************************************
 * 				modOpen					[internal]
 */
-DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
+static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
 {								 
 #ifdef linux
 	int		midi;
 	dprintf_midi(stddeb,
 		"modOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
-		fprintf(stderr,"Linux 'modOpen' // Invalid Parameter !\n");
+		dprintf_midi(stddeb,"Linux 'modOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	if (wDevID >= MAX_MIDIOUTDRV) {
-		fprintf(stderr,"Linux 'modOpen' // MAX_MIDIOUTDRV reached !\n");
+		dprintf_midi(stddeb,"Linux 'modOpen' // MAX_MIDIOUTDRV reached !\n");
 		return MMSYSERR_ALLOCATED;
 		}
 	MidiOutDev[wDevID].unixdev = 0;
 	midi = open (MIDI_DEV, O_WRONLY, 0);
 	if (midi == -1) {
-		fprintf(stderr,"Linux 'modOpen' // can't open !\n");
+		dprintf_midi(stddeb,"Linux 'modOpen' // can't open !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	MidiOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
 	switch(MidiOutDev[wDevID].wFlags) {
 		case DCB_NULL:
-			fprintf(stderr,"Linux 'modOpen' // CALLBACK_NULL !\n");
+			dprintf_midi(stddeb,"Linux 'modOpen' // CALLBACK_NULL !\n");
 			break;
 		case DCB_WINDOW:
 			dprintf_midi(stddeb,
@@ -1170,7 +1060,7 @@
 	MidiOutDev[wDevID].dwTotalPlayed = 0;
 	MidiOutDev[wDevID].bufsize = 0x3FFF;
 	if (MIDI_NotifyClient(wDevID, MOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'modOpen' // can't notify client !\n");
+		dprintf_midi(stddeb,"Linux 'modOpen' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	dprintf_midi(stddeb,
@@ -1185,19 +1075,19 @@
 /**************************************************************************
 * 				modClose				[internal]
 */
-DWORD modClose(WORD wDevID)
+static DWORD modClose(WORD wDevID)
 {
 #ifdef linux
-	dprintf_midi(stddeb,"modClose(%u);\n", wDevID);
+	dprintf_midi(stddeb, "modClose(%u);\n", wDevID);
 	if (MidiOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'modClose' // can't close !\n");
+		dprintf_midi(stddeb,"Linux 'modClose' // can't close !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	close(MidiOutDev[wDevID].unixdev);
 	MidiOutDev[wDevID].unixdev = 0;
 	MidiOutDev[wDevID].bufsize = 0;
 	if (MIDI_NotifyClient(wDevID, MOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'modClose' // can't notify client !\n");
+		dprintf_midi(stddeb,"Linux 'modClose' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
@@ -1209,14 +1099,14 @@
 /**************************************************************************
 * 				modData					[internal]
 */
-DWORD modData(WORD wDevID, DWORD dwParam)
+static DWORD modData(WORD wDevID, DWORD dwParam)
 {
 #ifdef linux
 	WORD	event;
 	dprintf_midi(stddeb,	
 		"modData(%u, %08lX);\n", wDevID, dwParam);
 	if (MidiOutDev[wDevID].unixdev == 0) {
-        fprintf(stderr,"Linux 'modData' // can't play !\n");
+        dprintf_midi(stddeb,"Linux 'modData' // can't play !\n");
 		return MIDIERR_NODEVICE;
 		}
 	event = LOWORD(dwParam);
@@ -1234,16 +1124,16 @@
 /**************************************************************************
 * 				modLongData					[internal]
 */
-DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
+static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
 #ifdef linux
 	int		count;
 	LPWORD	ptr;
 	dprintf_midi(stddeb,	
 		"modLongData(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
-	printf("modLongData(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
+	dprintf_midi(stddeb, "modLongData(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
-        fprintf(stderr,"Linux 'modLongData' // can't play !\n");
+        dprintf_midi(stddeb,"Linux 'modLongData' // can't play !\n");
 		return MIDIERR_NODEVICE;
 		}
 	if (lpMidiHdr->lpData == NULL) return MIDIERR_UNPREPARED;
@@ -1272,7 +1162,7 @@
 	lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
 	lpMidiHdr->dwFlags |= MHDR_DONE;
 	if (MIDI_NotifyClient(wDevID, MOM_DONE, 0L, 0L) != MMSYSERR_NOERROR) {
-		fprintf(stderr,"Linux 'modLongData' // can't notify client !\n");
+		dprintf_midi(stddeb,"Linux 'modLongData' // can't notify client !\n");
 		return MMSYSERR_INVALPARAM;
 		}
 	return MMSYSERR_NOERROR;
@@ -1284,17 +1174,17 @@
 /**************************************************************************
 * 				modPrepare				[internal]
 */
-DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
+static DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
 #ifdef linux
 	dprintf_midi(stddeb,
 		  "modPrepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'modPrepare' // can't prepare !\n");
+		dprintf_midi(stddeb,"Linux 'modPrepare' // can't prepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	if (MidiOutDev[wDevID].lpQueueHdr != NULL) {
-		fprintf(stderr,"Linux 'modPrepare' // already prepare !\n");
+		dprintf_midi(stddeb,"Linux 'modPrepare' // already prepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	MidiOutDev[wDevID].dwTotalPlayed = 0;
@@ -1311,13 +1201,13 @@
 /**************************************************************************
 * 				modUnprepare			[internal]
 */
-DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
+static DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
 #ifdef linux
 	dprintf_midi(stddeb,
 		"modUnprepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
-		fprintf(stderr,"Linux 'modUnprepare' // can't unprepare !\n");
+		dprintf_midi(stddeb,"Linux 'modUnprepare' // can't unprepare !\n");
 		return MMSYSERR_NOTENABLED;
 		}
 	return MMSYSERR_NOERROR;
@@ -1329,9 +1219,9 @@
 /**************************************************************************
 * 				modReset				[internal]
 */
-DWORD modReset(WORD wDevID)
+static DWORD modReset(WORD wDevID)
 {
-	printf("modReset(%u);\n", wDevID);
+	dprintf_midi(stddeb, "modReset(%u);\n", wDevID);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1339,9 +1229,9 @@
 /**************************************************************************
 * 				modGetPosition			[internal]
 */
-DWORD modGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
+static DWORD modGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
 {
-	printf("modGetposition(%u, %p, %08lX);\n", wDevID, lpTime, uSize);
+	dprintf_midi(stddeb, "modGetposition(%u, %p, %08lX);\n", wDevID, lpTime, uSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1352,7 +1242,7 @@
 DWORD modMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2)
 {
-	printf("modMessage(%u, %04X, %08lX, %08lX, %08lX);\n", 
+	dprintf_midi(stddeb, "modMessage(%u, %04X, %08lX, %08lX, %08lX);\n", 
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
 	switch(wMsg) {
 		case MODM_OPEN:
@@ -1370,11 +1260,11 @@
 		case MODM_GETDEVCAPS:
 			return modGetDevCaps(wDevID, (LPMIDIOUTCAPS)PTR_SEG_TO_LIN(dwParam1), dwParam2);
 		case MODM_GETNUMDEVS:
-			return 1L;
+			return 1;
 		case MODM_GETVOLUME:
-			return 0L;
+			return 0;
 		case MODM_SETVOLUME:
-			return 0L;
+			return 0;
 		case MODM_RESET:
 			return modReset(wDevID);
 		}
@@ -1382,6 +1272,69 @@
 }
 
 
+/**************************************************************************
+* 				MIDI_DriverProc		[sample driver]
+*/
+LONG MIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+						DWORD dwParam1, DWORD dwParam2)
+{
+#ifdef linux
+	switch(wMsg) {
+		case DRV_LOAD:
+			return 1;
+		case DRV_FREE:
+			return 1;
+		case DRV_OPEN:
+			return 1;
+		case DRV_CLOSE:
+			return 1;
+		case DRV_ENABLE:
+			return 1;
+		case DRV_DISABLE:
+			return 1;
+		case DRV_QUERYCONFIGURE:
+			return 1;
+		case DRV_CONFIGURE:
+			MessageBox(0, "Sample Midi Linux Driver !", 
+								"MMLinux Driver", MB_OK);
+			return 1;
+		case DRV_INSTALL:
+			return DRVCNF_RESTART;
+		case DRV_REMOVE:
+			return DRVCNF_RESTART;
+		case MCI_OPEN_DRIVER:
+		case MCI_OPEN:
+			return MIDI_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_CLOSE_DRIVER:
+		case MCI_CLOSE:
+			return MIDI_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_PLAY:
+			return MIDI_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_RECORD:
+			return MIDI_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_STOP:
+			return MIDI_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_SET:
+			return MIDI_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_PAUSE:
+			return MIDI_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_RESUME:
+			return MIDI_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_STATUS:
+			return MIDI_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_GETDEVCAPS:
+			return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		case MCI_INFO:
+			return MIDI_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
+		default:
+			return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
+		}
+#else
+	return MMSYSERR_NOTENABLED;
+#endif
+}
+
+
 /*-----------------------------------------------------------------------*/
 
 #endif /* #ifdef BUILTIN_MMSYSTEM */
diff --git a/multimedia/mmaux.c b/multimedia/mmaux.c
index 05a1a0b..e325fd1 100644
--- a/multimedia/mmaux.c
+++ b/multimedia/mmaux.c
@@ -2,9 +2,8 @@
  * Sample AUXILARY Wine Driver for Linux
  *
  * Copyright 1994 Martin Ayotte
- *
-static char Copyright[] = "Copyright  Martin Ayotte, 1994";
-*/
+ */
+
 #ifndef WINELIB
 #define BUILTIN_MMSYSTEM
 #endif 
@@ -45,7 +44,7 @@
 /**************************************************************************
 * 				AUX_GetDevCaps			[internal]
 */
-DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPS lpCaps, DWORD dwSize)
+static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPS lpCaps, DWORD dwSize)
 {
 #ifdef linux
 	int 	mixer;
@@ -116,7 +115,7 @@
 /**************************************************************************
 * 				AUX_GetVolume			[internal]
 */
-DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
+static DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
 {
 #ifdef linux
 	int 	mixer;
@@ -175,7 +174,7 @@
 /**************************************************************************
 * 				AUX_SetVolume			[internal]
 */
-DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
+static DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
 {
 #ifdef linux
 	int 	mixer;
diff --git a/multimedia/mmsystem.c b/multimedia/mmsystem.c
index ce8642f..2a01641 100644
--- a/multimedia/mmsystem.c
+++ b/multimedia/mmsystem.c
@@ -2,9 +2,8 @@
  * MMSYTEM functions
  *
  * Copyright 1993 Martin Ayotte
- *
-static char Copyright[] = "Copyright  Martin Ayotte, 1993";
-*/
+ */
+
 #ifndef WINELIB
 
 #include <unistd.h>
@@ -20,12 +19,6 @@
 #include "driver.h"
 #include "mmsystem.h"
 #include "stddebug.h"
-/* #define DEBUG_MCI    */
-/* #undef  DEBUG_MCI    */
-/* #define DEBUG_MMTIME */
-/* #undef  DEBUG_MMTIME */
-/* #define DEBUG_MMIO   */
-/* #undef  DEBUG_MMIO   */
 #include "debug.h"
 
 static int	InstalledCount;
@@ -53,18 +46,18 @@
 
 static MCI_OPEN_DRIVER_PARMS	mciDrv[MAXMCIDRIVERS];
 
-UINT WINAPI midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT WINAPI waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-LRESULT DrvDefDriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+UINT midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+UINT waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
+LONG DrvDefDriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2);
 
-LRESULT WAVE_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG WAVE_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2);
-LRESULT MIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG MIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2);
-LRESULT CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2);
-LRESULT ANIM_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG ANIM_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2);
 
 /**************************************************************************
@@ -80,7 +73,7 @@
 /**************************************************************************
 * 				sndPlaySound		[MMSYSTEM.2]
 */
-BOOL WINAPI sndPlaySound(LPCSTR lpszSoundName, UINT uFlags)
+BOOL sndPlaySound(LPCSTR lpszSoundName, UINT uFlags)
 {
 	HMMIO			hmmio;
 	MMCKINFO		mmckInfo;
@@ -98,22 +91,22 @@
 	DWORD			dwRet;
 	char			str[128];
 	LPSTR			ptr;
-	printf("sndPlaySound // SoundName='%s' uFlags=%04X !\n", 
+	dprintf_mmsys(stddeb, "sndPlaySound // SoundName='%s' uFlags=%04X !\n", 
 									lpszSoundName, uFlags);
 	if (lpszSoundName == NULL) {
-		printf("sndPlaySound // Stop !\n");
+		dprintf_mmsys(stddeb, "sndPlaySound // Stop !\n");
 		return FALSE;
 		}
 	hmmio = mmioOpen((LPSTR)lpszSoundName, NULL, 
 		MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
 	if (hmmio == 0) {
-		printf("sndPlaySound // searching in SystemSound List !\n");
+		dprintf_mmsys(stddeb, "sndPlaySound // searching in SystemSound List !\n");
 		GetProfileString("Sounds", (LPSTR)lpszSoundName, "", str, sizeof(str));
 		if (strlen(str) == 0) return FALSE;
 		if ( (ptr = (LPSTR)strchr(str, ',')) != NULL) *ptr = '\0';
 		hmmio = mmioOpen(str, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
 		if (hmmio == 0) {
-			printf("sndPlaySound // can't find SystemSound='%s' !\n", str);
+			dprintf_mmsys(stddeb, "sndPlaySound // can't find SystemSound='%s' !\n", str);
 			return FALSE;
 			}
 		}
@@ -121,29 +114,29 @@
 ErrSND:	if (hmmio != 0)   mmioClose(hmmio, 0);
 		return FALSE;
 		}
-	printf("sndPlaySound // ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
+	dprintf_mmsys(stddeb, "sndPlaySound // ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
 				(LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType,
 				ckMainRIFF.cksize);
 	if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
 	    (ckMainRIFF.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) goto ErrSND;
 	mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' ');
 	if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) != 0) goto ErrSND;
-	printf("sndPlaySound // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
+	dprintf_mmsys(stddeb, "sndPlaySound // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
 			(LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType,
 			mmckInfo.cksize);
 	if (mmioRead(hmmio, (HPSTR) &pcmWaveFormat,
 		(long) sizeof(PCMWAVEFORMAT)) != (long) sizeof(PCMWAVEFORMAT)) goto ErrSND;
 
-	printf("sndPlaySound // wFormatTag=%04X !\n", pcmWaveFormat.wf.wFormatTag);
-	printf("sndPlaySound // nChannels=%d \n", pcmWaveFormat.wf.nChannels);
-	printf("sndPlaySound // nSamplesPerSec=%ld\n", pcmWaveFormat.wf.nSamplesPerSec);
-	printf("sndPlaySound // nAvgBytesPerSec=%ld\n", pcmWaveFormat.wf.nAvgBytesPerSec);
-	printf("sndPlaySound // nBlockAlign=%d \n", pcmWaveFormat.wf.nBlockAlign);
-	printf("sndPlaySound // wBitsPerSample=%u !\n", pcmWaveFormat.wBitsPerSample);
+	dprintf_mmsys(stddeb, "sndPlaySound // wFormatTag=%04X !\n", pcmWaveFormat.wf.wFormatTag);
+	dprintf_mmsys(stddeb, "sndPlaySound // nChannels=%d \n", pcmWaveFormat.wf.nChannels);
+	dprintf_mmsys(stddeb, "sndPlaySound // nSamplesPerSec=%ld\n", pcmWaveFormat.wf.nSamplesPerSec);
+	dprintf_mmsys(stddeb, "sndPlaySound // nAvgBytesPerSec=%ld\n", pcmWaveFormat.wf.nAvgBytesPerSec);
+	dprintf_mmsys(stddeb, "sndPlaySound // nBlockAlign=%d \n", pcmWaveFormat.wf.nBlockAlign);
+	dprintf_mmsys(stddeb, "sndPlaySound // wBitsPerSample=%u !\n", pcmWaveFormat.wBitsPerSample);
 
 	mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
 	if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) != 0) goto ErrSND;
-	printf("sndPlaySound // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
+	dprintf_mmsys(stddeb, "sndPlaySound // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
 			(LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType,
 			mmckInfo.cksize);
 	hDesc = USER_HEAP_ALLOC(sizeof(WAVEOPENDESC));
@@ -157,7 +150,7 @@
 	lpWaveDesc = (LPWAVEOPENDESC) USER_HEAP_SEG_ADDR(hDesc);
 	dwRet = wodMessage(0, WODM_OPEN, 0, (DWORD)lpWaveDesc, CALLBACK_NULL);
 	if (dwRet != MMSYSERR_NOERROR) {
-		printf("sndPlaySound // can't open WaveOut device !\n");
+		dprintf_mmsys(stddeb, "sndPlaySound // can't open WaveOut device !\n");
 		goto ErrSND;
 		}
 	USER_HEAP_FREE(hFormat);
@@ -173,7 +166,7 @@
 	lpWaveHdr->dwLoops = 0L;
 	dwRet = wodMessage(0, WODM_PREPARE, 0, (DWORD)lp16WaveHdr, sizeof(WAVEHDR));
 	if (dwRet != MMSYSERR_NOERROR) {
-		printf("sndPlaySound // can't prepare WaveOut device !\n");
+		dprintf_mmsys(stddeb, "sndPlaySound // can't prepare WaveOut device !\n");
 		GlobalUnlock(hData);
 		GlobalFree(hData);
 		USER_HEAP_FREE(hDesc);
@@ -200,10 +193,10 @@
 /**************************************************************************
 * 				mmsystemGetVersion	[MMSYSTEM.5]
 */
-WORD WINAPI mmsystemGetVersion()
+WORD mmsystemGetVersion()
 {
-	printf("mmsystemGetVersion // 0.4.0 ...?... :-) !\n");
-	return(0x0040);
+	dprintf_mmsys(stddeb, "mmsystemGetVersion // 0.4.0 ...?... :-) !\n");
+	return 0x0040;
 }
 
 /**************************************************************************
@@ -218,9 +211,9 @@
 /**************************************************************************
 * 				OutputDebugStr		[MMSYSTEM.30]
 */
-void WINAPI OutputDebugStr(LPCSTR str)
+void OutputDebugStr(LPCSTR str)
 {
-	printf("EMPTY STUB !!! OutputDebugStr('%s');\n", str);
+	fprintf(stdnimp, "EMPTY STUB !!! OutputDebugStr('%s');\n", str);
 }
 
 /**************************************************************************
@@ -229,20 +222,20 @@
 BOOL DriverCallback(DWORD dwCallBack, UINT uFlags, HANDLE hDev, 
 		WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2)
 {
-	printf("DriverCallback(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n",
+	dprintf_mmsys(stddeb, "DriverCallback(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n",
 		dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
 	switch(uFlags & DCB_TYPEMASK) {
 		case DCB_NULL:
-			printf("DriverCallback() // CALLBACK_NULL !\n");
+			dprintf_mmsys(stddeb, "DriverCallback() // CALLBACK_NULL !\n");
 			break;
 		case DCB_WINDOW:
-			printf("DriverCallback() // CALLBACK_WINDOW !\n");
+			dprintf_mmsys(stddeb, "DriverCallback() // CALLBACK_WINDOW !\n");
 			break;
 		case DCB_TASK:
-			printf("DriverCallback() // CALLBACK_TASK !\n");
+			dprintf_mmsys(stddeb, "DriverCallback() // CALLBACK_TASK !\n");
 			break;
 		case DCB_FUNCTION:
-			printf("DriverCallback() // CALLBACK_FUNCTION !\n");
+			dprintf_mmsys(stddeb, "DriverCallback() // CALLBACK_FUNCTION !\n");
 			break;
 		}
 	return TRUE;
@@ -253,7 +246,7 @@
 */
 WORD JoyGetNumDevs()
 {
-	printf("EMPTY STUB !!! JoyGetNumDevs();\n");
+	fprintf(stdnimp, "EMPTY STUB !!! JoyGetNumDevs();\n");
 	return 0;
 }
 
@@ -262,7 +255,7 @@
 */
 WORD JoyGetDevCaps(WORD wID, LPJOYCAPS lpCaps, WORD wSize)
 {
-	printf("EMPTY STUB !!! JoyGetDevCaps(%04X, %p, %d);\n", 
+	fprintf(stdnimp, "EMPTY STUB !!! JoyGetDevCaps(%04X, %p, %d);\n", 
 										wID, lpCaps, wSize);
 	return MMSYSERR_NODRIVER;
 }
@@ -272,7 +265,7 @@
 */
 WORD JoyGetPos(WORD wID, LPJOYINFO lpInfo)
 {
-	printf("EMPTY STUB !!! JoyGetPos(%04X, %p);\n", wID, lpInfo);
+	fprintf(stdnimp, "EMPTY STUB !!! JoyGetPos(%04X, %p);\n", wID, lpInfo);
 	return MMSYSERR_NODRIVER;
 }
 
@@ -281,7 +274,7 @@
 */
 WORD JoyGetThreshold(WORD wID, LPWORD lpThreshold)
 {
-	printf("EMPTY STUB !!! JoyGetThreshold(%04X, %p);\n", wID, lpThreshold);
+	fprintf(stdnimp, "EMPTY STUB !!! JoyGetThreshold(%04X, %p);\n", wID, lpThreshold);
 	return MMSYSERR_NODRIVER;
 }
 
@@ -290,7 +283,7 @@
 */
 WORD JoyReleaseCapture(WORD wID)
 {
-	printf("EMPTY STUB !!! JoyReleaseCapture(%04X);\n", wID);
+	fprintf(stdnimp, "EMPTY STUB !!! JoyReleaseCapture(%04X);\n", wID);
 	return MMSYSERR_NODRIVER;
 }
 
@@ -299,7 +292,7 @@
 */
 WORD JoySetCapture(HWND hWnd, WORD wID, WORD wPeriod, BOOL bChanged)
 {
-	printf("EMPTY STUB !!! JoySetCapture(%04X, %04X, %d, %d);\n", 
+	fprintf(stdnimp, "EMPTY STUB !!! JoySetCapture(%04X, %04X, %d, %d);\n", 
 							hWnd, wID, wPeriod, bChanged);
 	return MMSYSERR_NODRIVER;
 }
@@ -309,7 +302,7 @@
 */
 WORD JoySetThreshold(WORD wID, WORD wThreshold)
 {
-	printf("EMPTY STUB !!! JoySetThreshold(%04X, %d);\n", wID, wThreshold);
+	fprintf(stdnimp, "EMPTY STUB !!! JoySetThreshold(%04X, %d);\n", wID, wThreshold);
 	return MMSYSERR_NODRIVER;
 }
 
@@ -318,7 +311,7 @@
 */
 WORD JoySetCalibration(WORD wID)
 {
-	printf("EMPTY STUB !!! JoySetCalibration(%04X);\n", wID);
+	fprintf(stdnimp, "EMPTY STUB !!! JoySetCalibration(%04X);\n", wID);
 	return MMSYSERR_NODRIVER;
 }
 
@@ -326,21 +319,21 @@
 /**************************************************************************
 * 				auxGetNumDevs		[MMSYSTEM.350]
 */
-UINT WINAPI auxGetNumDevs()
+UINT auxGetNumDevs()
 {
 	UINT	count = 0;
-	printf("auxGetNumDevs !\n");
+	dprintf_mmsys(stddeb, "auxGetNumDevs !\n");
 	count += auxMessage(0, AUXDM_GETNUMDEVS, 0L, 0L, 0L);
-	printf("auxGetNumDevs return %u \n", count);
+	dprintf_mmsys(stddeb, "auxGetNumDevs return %u \n", count);
 	return count;
 }
 
 /**************************************************************************
 * 				auxGetDevCaps		[MMSYSTEM.351]
 */
-UINT WINAPI auxGetDevCaps(UINT uDeviceID, AUXCAPS FAR* lpCaps, UINT uSize)
+UINT auxGetDevCaps(UINT uDeviceID, AUXCAPS FAR* lpCaps, UINT uSize)
 {
-	printf("auxGetDevCaps(%04X, %p, %d) !\n", 
+	dprintf_mmsys(stddeb, "auxGetDevCaps(%04X, %p, %d) !\n", 
 					uDeviceID, lpCaps, uSize);
 	return auxMessage(uDeviceID, AUXDM_GETDEVCAPS, 
 				0L, (DWORD)lpCaps, (DWORD)uSize);
@@ -349,27 +342,27 @@
 /**************************************************************************
 * 				auxGetVolume		[MMSYSTEM.352]
 */
-UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume)
+UINT auxGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume)
 {
-	printf("auxGetVolume(%04X, %p) !\n", uDeviceID, lpdwVolume);
+	dprintf_mmsys(stddeb, "auxGetVolume(%04X, %p) !\n", uDeviceID, lpdwVolume);
 	return auxMessage(uDeviceID, AUXDM_GETVOLUME, 0L, (DWORD)lpdwVolume, 0L);
 }
 
 /**************************************************************************
 * 				auxSetVolume		[MMSYSTEM.353]
 */
-UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
+UINT auxSetVolume(UINT uDeviceID, DWORD dwVolume)
 {
-	printf("auxSetVolume(%04X, %08lX) !\n", uDeviceID, dwVolume);
+	dprintf_mmsys(stddeb, "auxSetVolume(%04X, %08lX) !\n", uDeviceID, dwVolume);
 	return auxMessage(uDeviceID, AUXDM_SETVOLUME, 0L, dwVolume, 0L);
 }
 
 /**************************************************************************
 * 				auxOutMessage		[MMSYSTEM.354]
 */
-DWORD WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD dw1, DWORD dw2)
+DWORD auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD dw1, DWORD dw2)
 {
-	printf("auxOutMessage(%04X, %04X, %08lX, %08lX)\n", 
+	dprintf_mmsys(stddeb, "auxOutMessage(%04X, %04X, %08lX, %08lX)\n", 
 				uDeviceID, uMessage, dw1, dw2);
 	return auxMessage(uDeviceID, uMessage, 0L, dw1, dw2);
 }
@@ -381,7 +374,7 @@
 {
 	LPSTR	msgptr;
 	int		maxbuf;
-	printf("mciGetErrorString(%08lX, %p, %d);\n", wError, lpstrBuffer, uLength);
+	dprintf_mmsys(stddeb, "mciGetErrorString(%08lX, %p, %d);\n", wError, lpstrBuffer, uLength);
 	if ((lpstrBuffer == NULL) || (uLength < 1)) return(FALSE);
 	lpstrBuffer[0] = '\0';
 	switch(wError) {
@@ -640,11 +633,11 @@
 /**************************************************************************
 * 				mciDriverNotify			[MMSYSTEM.711]
 */
-BOOL WINAPI mciDriverNotify(HWND hWndCallBack, UINT wDevID, UINT wStatus)
+BOOL mciDriverNotify(HWND hWndCallBack, UINT wDevID, UINT wStatus)
 {
-	printf("mciDriverNotify(%04X, %u, %04X)\n", hWndCallBack, wDevID, wStatus);
+	dprintf_mmsys(stddeb, "mciDriverNotify(%04X, %u, %04X)\n", hWndCallBack, wDevID, wStatus);
 	if (!IsWindow(hWndCallBack)) return FALSE;
-	printf("mciDriverNotify // before PostMessage\n");
+	dprintf_mmsys(stddeb, "mciDriverNotify // before PostMessage\n");
 	PostMessage(hWndCallBack, MM_MCINOTIFY, wStatus, 
 			MAKELONG(mciDrv[wDevID].wDeviceID, 0));
 	return TRUE;
@@ -660,28 +653,28 @@
 	UINT	uDevTyp = 0;
 	UINT	wDevID = 0;
 	lpParms = PTR_SEG_TO_LIN(lp16Parms);
-	printf("mciOpen(%08lX, %p (%p))\n", dwParam, lp16Parms, lpParms);
+	dprintf_mmsys(stddeb, "mciOpen(%08lX, %p (%p))\n", dwParam, lp16Parms, lpParms);
 	if (lp16Parms == NULL) return MCIERR_INTERNAL;
 	while(mciDrv[wDevID].wType != 0) {
 		if (++wDevID >= MAXMCIDRIVERS) {
-			printf("MCI_OPEN // MAXMCIDRIVERS reached !\n");
+			dprintf_mmsys(stddeb, "MCI_OPEN // MAXMCIDRIVERS reached !\n");
 			return MCIERR_INTERNAL;
 			}
 		}
-	printf("mciOpen // wDevID=%d \n", wDevID);
+	dprintf_mmsys(stddeb, "mciOpen // wDevID=%d \n", wDevID);
 	if (dwParam & MCI_OPEN_ALIAS) {
-		printf("MCI_OPEN // Alias='%s' !\n",
+		dprintf_mmsys(stddeb, "MCI_OPEN // Alias='%s' !\n",
 			(char*)PTR_SEG_TO_LIN(lpParms->lpstrAlias));
 		uDevTyp = MCI_DEVTYPE_WAVEFORM_AUDIO;
  		}
 	if (dwParam & MCI_OPEN_TYPE) {
 		if (dwParam & MCI_OPEN_TYPE_ID) {
-			printf("MCI_OPEN // Dev=%p !\n", lpParms->lpstrDeviceType);
+			dprintf_mmsys(stddeb, "MCI_OPEN // Dev=%p !\n", lpParms->lpstrDeviceType);
 			uDevTyp = LOWORD((DWORD)lpParms->lpstrDeviceType);
 			}
 		else {
 			if (lpParms->lpstrDeviceType == NULL) return MCIERR_INTERNAL;
-			printf("MCI_OPEN // Dev='%s' !\n",
+			dprintf_mmsys(stddeb, "MCI_OPEN // Dev='%s' !\n",
                               (char*)PTR_SEG_TO_LIN(lpParms->lpstrDeviceType));
 			strcpy(str, PTR_SEG_TO_LIN(lpParms->lpstrDeviceType));
 			AnsiUpper(str);
@@ -709,7 +702,7 @@
 	mciDrv[wDevID].wType = uDevTyp;
 	mciDrv[wDevID].wDeviceID = wDevID;
 	lpParms->wDeviceID = wDevID;
-	printf("MCI_OPEN // mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n", 
+	dprintf_mmsys(stddeb, "MCI_OPEN // mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n", 
 				wDevID, uDevTyp, lpParms->wDeviceID);
 	switch(uDevTyp) {
 		case MCI_DEVTYPE_CD_AUDIO:
@@ -729,10 +722,10 @@
 			return ANIM_DriverProc(0, 0, MCI_OPEN_DRIVER, 
 								dwParam, (DWORD)lp16Parms);
 		case MCI_DEVTYPE_DIGITAL_VIDEO:
-			printf("MCI_OPEN // No DIGITAL_VIDEO yet !\n");
+			dprintf_mmsys(stddeb, "MCI_OPEN // No DIGITAL_VIDEO yet !\n");
 			return MCIERR_DEVICE_NOT_INSTALLED;
 		default:
-			printf("MCI_OPEN // Invalid Device Name '%p' !\n", lpParms->lpstrDeviceType);
+			dprintf_mmsys(stddeb, "MCI_OPEN // Invalid Device Name '%p' !\n", lpParms->lpstrDeviceType);
 			return MCIERR_INVALID_DEVICE_NAME;
 		}
 	return MCIERR_INTERNAL;
@@ -745,7 +738,7 @@
 DWORD mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
 	DWORD	dwRet = MCIERR_INTERNAL;
-	printf("mciClose(%u, %08lX, %p)\n", wDevID, dwParam, lpParms);
+	dprintf_mmsys(stddeb, "mciClose(%u, %08lX, %p)\n", wDevID, dwParam, lpParms);
 	switch(mciDrv[wDevID].wType) {
 		case MCI_DEVTYPE_CD_AUDIO:
 #ifndef WINELIB
@@ -766,7 +759,7 @@
 						MCI_CLOSE, dwParam, (DWORD)lpParms);
 			break;
 		default:
-			printf("mciClose() // unknown device type=%04X !\n", mciDrv[wDevID].wType);
+			dprintf_mmsys(stddeb, "mciClose() // unknown device type=%04X !\n", mciDrv[wDevID].wType);
 		}
 	mciDrv[wDevID].wType = 0;
 	return dwRet;
@@ -799,7 +792,7 @@
 				ptr = lpInstallNames = malloc(2048);
 				GetPrivateProfileString("mci", NULL, "", lpInstallNames, 2000, SysFile);
 				while(strlen(ptr) > 0) {
-					printf("---> '%s' \n", ptr);
+					dprintf_mci(stddeb, "---> '%s' \n", ptr);
 					len = strlen(ptr) + 1;
 					ptr += len;
 					InstalledListLen += len;
@@ -830,7 +823,7 @@
 {
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwParam & MCI_SOUND_NAME)
-		printf("MCI_SOUND // file='%s' !\n", lpParms->lpstrSoundName);
+		dprintf_mci(stddeb, "MCI_SOUND // file='%s' !\n", lpParms->lpstrSoundName);
 	return MCIERR_INVALID_DEVICE_ID;
 }
 
@@ -869,7 +862,7 @@
 					return ANIM_DriverProc(mciDrv[wDevID].wDeviceID, hDrv, 
 											wMsg, dwParam1, dwParam2);
 				default:
-					printf("mciSendCommand() // unknown device type=%04X !\n", 
+					dprintf_mci(stddeb, "mciSendCommand() // unknown device type=%04X !\n", 
 											mciDrv[wDevID].wType);
 				}
 		}
@@ -882,7 +875,7 @@
 UINT mciGetDeviceID (LPCSTR lpstrName)
 {
 	char	str[128];
-	printf("mciGetDeviceID(%s)\n", lpstrName);
+	dprintf_mci(stddeb, "mciGetDeviceID(%s)\n", lpstrName);
 	if (lpstrName != NULL) {
 		strcpy(str, lpstrName);
 		AnsiUpper(str);
@@ -894,10 +887,10 @@
 /**************************************************************************
 * 				mciSendString			[MMSYSTEM.702]
 */
-DWORD WINAPI mciSendString (LPCSTR lpstrCommand,
+DWORD mciSendString (LPCSTR lpstrCommand,
     LPSTR lpstrReturnString, UINT uReturnLength, HWND hwndCallback)
 {
-	printf("mciSendString('%s', %p, %u, %X)\n", 
+	dprintf_mci(stddeb, "mciSendString('%s', %p, %u, %X)\n", 
 			lpstrCommand, lpstrReturnString, 
 			uReturnLength, hwndCallback);
 	return MCIERR_MISSING_COMMAND_STRING;
@@ -906,7 +899,7 @@
 /**************************************************************************
 * 				mciSetYieldProc		[MMSYSTEM.714]
 */
-BOOL WINAPI mciSetYieldProc (UINT uDeviceID, 
+BOOL mciSetYieldProc (UINT uDeviceID, 
 		YIELDPROC fpYieldProc, DWORD dwYieldData)
 {
     return FALSE;
@@ -915,7 +908,7 @@
 /**************************************************************************
 * 				mciGetDeviceIDFromElementID	[MMSYSTEM.715]
 */
-UINT WINAPI mciGetDeviceIDFromElementID(DWORD dwElementID, LPCSTR lpstrType)
+UINT mciGetDeviceIDFromElementID(DWORD dwElementID, LPCSTR lpstrType)
 {
     return 0;
 }
@@ -923,7 +916,7 @@
 /**************************************************************************
 * 				mciGetYieldProc		[MMSYSTEM.716]
 */
-YIELDPROC WINAPI mciGetYieldProc(UINT uDeviceID, DWORD FAR* lpdwYieldData)
+YIELDPROC mciGetYieldProc(UINT uDeviceID, DWORD FAR* lpdwYieldData)
 {
     return NULL;
 }
@@ -931,7 +924,7 @@
 /**************************************************************************
 * 				mciGetCreatorTask	[MMSYSTEM.717]
 */
-HTASK WINAPI mciGetCreatorTask(UINT uDeviceID)
+HTASK mciGetCreatorTask(UINT uDeviceID)
 {
     return 0;
 }
@@ -939,39 +932,38 @@
 /**************************************************************************
 * 				midiOutGetNumDevs	[MMSYSTEM.201]
 */
-UINT WINAPI midiOutGetNumDevs(void)
+UINT midiOutGetNumDevs(void)
 {
 	UINT	count = 0;
-	printf("midiOutGetNumDevs\n");
+	dprintf_mmsys(stddeb, "midiOutGetNumDevs\n");
 	count += modMessage(0, MODM_GETNUMDEVS, 0L, 0L, 0L);
-	printf("midiOutGetNumDevs return %u \n", count);
+	dprintf_mmsys(stddeb, "midiOutGetNumDevs return %u \n", count);
 	return count;
 }
 
 /**************************************************************************
 * 				midiOutGetDevCaps	[MMSYSTEM.202]
 */
-UINT WINAPI midiOutGetDevCaps(UINT uDeviceID,
-    MIDIOUTCAPS FAR* lpCaps, UINT uSize)
+UINT midiOutGetDevCaps(UINT uDeviceID, MIDIOUTCAPS FAR* lpCaps, UINT uSize)
 {
-	printf("midiOutGetDevCaps\n");
+	dprintf_mmsys(stddeb, "midiOutGetDevCaps\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiOutGetErrorText 	[MMSYSTEM.203]
 */
-UINT WINAPI midiOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
+UINT midiOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
 {
-	printf("midiOutGetErrorText\n");
-	return(midiGetErrorText(uError, lpText, uSize));
+	dprintf_mmsys(stddeb, "midiOutGetErrorText\n");
+	return midiGetErrorText(uError, lpText, uSize);
 }
 
 
 /**************************************************************************
 * 				midiGetErrorText 		[internal]
 */
-UINT WINAPI midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
+UINT midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
 {
 	LPSTR	msgptr;
 	int		maxbuf;
@@ -1019,7 +1011,7 @@
 /**************************************************************************
 * 				midiOutOpen			[MMSYSTEM.204]
 */
-UINT WINAPI midiOutOpen(HMIDIOUT FAR* lphMidiOut, UINT uDeviceID,
+UINT midiOutOpen(HMIDIOUT FAR* lphMidiOut, UINT uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
 	HMIDI	hMidiOut;
@@ -1028,10 +1020,10 @@
 	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
 	if (lphMidiOut != NULL) *lphMidiOut = 0;
-	printf("midiOutOpen(%p, %d, %08lX, %08lX, %08lX);\n", 
+	dprintf_mmsys(stddeb, "midiOutOpen(%p, %d, %08lX, %08lX, %08lX);\n", 
 		lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
 	if (uDeviceID == (UINT)MIDI_MAPPER) {
-		printf("midiOutOpen	// MIDI_MAPPER mode requested !\n");
+		dprintf_mmsys(stddeb, "midiOutOpen	// MIDI_MAPPER mode requested !\n");
 		bMapperFlg = TRUE;
 		uDeviceID = 0;
 		}
@@ -1049,7 +1041,7 @@
 		if (dwRet == MMSYSERR_NOERROR) break;
 		if (!bMapperFlg) break;
 		uDeviceID++;
-		printf("midiOutOpen	// MIDI_MAPPER mode ! try next driver...\n");
+		dprintf_mmsys(stddeb, "midiOutOpen	// MIDI_MAPPER mode ! try next driver...\n");
 		}
 	return dwRet;
 }
@@ -1057,10 +1049,10 @@
 /**************************************************************************
 * 				midiOutClose		[MMSYSTEM.205]
 */
-UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
+UINT midiOutClose(HMIDIOUT hMidiOut)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutClose(%04X)\n", hMidiOut);
+	dprintf_mmsys(stddeb, "midiOutClose(%04X)\n", hMidiOut);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return modMessage(0, MODM_CLOSE, lpDesc->dwInstance, 0L, 0L);
@@ -1069,11 +1061,11 @@
 /**************************************************************************
 * 				midiOutPrepareHeader	[MMSYSTEM.206]
 */
-UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutPrepareHeader(HMIDIOUT hMidiOut,
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutPrepareHeader(%04X, %p, %d)\n", 
+	dprintf_mmsys(stddeb, "midiOutPrepareHeader(%04X, %p, %d)\n", 
 					hMidiOut, lpMidiOutHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1084,11 +1076,11 @@
 /**************************************************************************
 * 				midiOutUnprepareHeader	[MMSYSTEM.207]
 */
-UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutUnprepareHeader(HMIDIOUT hMidiOut,
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutUnprepareHeader(%04X, %p, %d)\n", 
+	dprintf_mmsys(stddeb, "midiOutUnprepareHeader(%04X, %p, %d)\n", 
 					hMidiOut, lpMidiOutHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1099,10 +1091,10 @@
 /**************************************************************************
 * 				midiOutShortMsg		[MMSYSTEM.208]
 */
-UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
+UINT midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutShortMsg(%04X, %08lX)\n", hMidiOut, dwMsg);
+	dprintf_mmsys(stddeb, "midiOutShortMsg(%04X, %08lX)\n", hMidiOut, dwMsg);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return modMessage(0, MODM_DATA, lpDesc->dwInstance, dwMsg, 0L);
@@ -1111,11 +1103,11 @@
 /**************************************************************************
 * 				midiOutLongMsg		[MMSYSTEM.209]
 */
-UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
+UINT midiOutLongMsg(HMIDIOUT hMidiOut,
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutLongMsg(%04X, %p, %d)\n", 
+	dprintf_mmsys(stddeb, "midiOutLongMsg(%04X, %p, %d)\n", 
 				hMidiOut, lpMidiOutHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1126,10 +1118,10 @@
 /**************************************************************************
 * 				midiOutReset		[MMSYSTEM.210]
 */
-UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
+UINT midiOutReset(HMIDIOUT hMidiOut)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutReset(%04X)\n", hMidiOut);
+	dprintf_mmsys(stddeb, "midiOutReset(%04X)\n", hMidiOut);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return modMessage(0, MODM_RESET, lpDesc->dwInstance, 0L, 0L);
@@ -1138,9 +1130,9 @@
 /**************************************************************************
 * 				midiOutGetVolume	[MMSYSTEM.211]
 */
-UINT WINAPI midiOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume)
+UINT midiOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume)
 {
-	printf("midiOutGetVolume(%04X, %p);\n", uDeviceID, lpdwVolume);
+	dprintf_mmsys(stddeb, "midiOutGetVolume(%04X, %p);\n", uDeviceID, lpdwVolume);
 	return modMessage(uDeviceID, MODM_GETVOLUME, 0L, (DWORD)lpdwVolume, 0L);
 	return 0;
 }
@@ -1148,9 +1140,9 @@
 /**************************************************************************
 * 				midiOutSetVolume	[MMSYSTEM.212]
 */
-UINT WINAPI midiOutSetVolume(UINT uDeviceID, DWORD dwVolume)
+UINT midiOutSetVolume(UINT uDeviceID, DWORD dwVolume)
 {
-	printf("midiOutSetVolume(%04X, %08lX);\n", uDeviceID, dwVolume);
+	dprintf_mmsys(stddeb, "midiOutSetVolume(%04X, %08lX);\n", uDeviceID, dwVolume);
 	return modMessage(uDeviceID, MODM_SETVOLUME, 0L, dwVolume, 0L);
 	return 0;
 }
@@ -1158,40 +1150,40 @@
 /**************************************************************************
 * 				midiOutCachePatches		[MMSYSTEM.213]
 */
-UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut,
+UINT midiOutCachePatches(HMIDIOUT hMidiOut,
     UINT uBank, WORD FAR* lpwPatchArray, UINT uFlags)
 {
-	printf("midiOutCachePatches\n");
+	dprintf_mmsys(stddeb, "midiOutCachePatches\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiOutCacheDrumPatches	[MMSYSTEM.214]
 */
-UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut,
+UINT midiOutCacheDrumPatches(HMIDIOUT hMidiOut,
     UINT uPatch, WORD FAR* lpwKeyArray, UINT uFlags)
 {
-	printf("midiOutCacheDrumPatches\n");
+	dprintf_mmsys(stddeb, "midiOutCacheDrumPatches\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiOutGetID		[MMSYSTEM.215]
 */
-UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT FAR* lpuDeviceID)
+UINT midiOutGetID(HMIDIOUT hMidiOut, UINT FAR* lpuDeviceID)
 {
-	printf("midiOutGetID\n");
+	dprintf_mmsys(stddeb, "midiOutGetID\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiOutMessage		[MMSYSTEM.216]
 */
-DWORD WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage, 
+DWORD midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage, 
 						DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutMessage(%04X, %04X, %08lX, %08lX)\n", 
+	dprintf_mmsys(stddeb, "midiOutMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hMidiOut, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1202,38 +1194,38 @@
 /**************************************************************************
 * 				midiInGetNumDevs	[MMSYSTEM.301]
 */
-UINT WINAPI midiInGetNumDevs(void)
+UINT midiInGetNumDevs(void)
 {
 	UINT	count = 0;
-	printf("midiInGetNumDevs\n");
+	dprintf_mmsys(stddeb, "midiInGetNumDevs\n");
 	count += midMessage(0, MIDM_GETNUMDEVS, 0L, 0L, 0L);
-	printf("midiInGetNumDevs return %u \n", count);
+	dprintf_mmsys(stddeb, "midiInGetNumDevs return %u \n", count);
 	return count;
 }
 
 /**************************************************************************
 * 				midiInGetDevCaps	[MMSYSTEM.302]
 */
-UINT WINAPI midiInGetDevCaps(UINT uDeviceID,
+UINT midiInGetDevCaps(UINT uDeviceID,
     LPMIDIINCAPS lpCaps, UINT uSize)
 {
-	printf("midiInGetDevCaps\n");
+	dprintf_mmsys(stddeb, "midiInGetDevCaps\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiInGetErrorText 		[MMSYSTEM.303]
 */
-UINT WINAPI midiInGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
+UINT midiInGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
 {
-	printf("midiInGetErrorText\n");
+	dprintf_mmsys(stddeb, "midiInGetErrorText\n");
 	return (midiGetErrorText(uError, lpText, uSize));
 }
 
 /**************************************************************************
 * 				midiInOpen		[MMSYSTEM.304]
 */
-UINT WINAPI midiInOpen(HMIDIIN FAR* lphMidiIn, UINT uDeviceID,
+UINT midiInOpen(HMIDIIN FAR* lphMidiIn, UINT uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
 	HMIDI	hMidiIn;
@@ -1242,10 +1234,10 @@
 	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
 	if (lphMidiIn != NULL) *lphMidiIn = 0;
-	printf("midiInOpen(%p, %d, %08lX, %08lX, %08lX);\n", 
+	dprintf_mmsys(stddeb, "midiInOpen(%p, %d, %08lX, %08lX, %08lX);\n", 
 		lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
 	if (uDeviceID == (UINT)MIDI_MAPPER) {
-		printf("midiInOpen	// MIDI_MAPPER mode requested !\n");
+		dprintf_mmsys(stddeb, "midiInOpen	// MIDI_MAPPER mode requested !\n");
 		bMapperFlg = TRUE;
 		uDeviceID = 0;
 		}
@@ -1263,7 +1255,7 @@
 		if (dwRet == MMSYSERR_NOERROR) break;
 		if (!bMapperFlg) break;
 		uDeviceID++;
-		printf("midiInOpen	// MIDI_MAPPER mode ! try next driver...\n");
+		dprintf_mmsys(stddeb, "midiInOpen	// MIDI_MAPPER mode ! try next driver...\n");
 		}
 	return dwRet;
 }
@@ -1271,10 +1263,10 @@
 /**************************************************************************
 * 				midiInClose		[MMSYSTEM.305]
 */
-UINT WINAPI midiInClose(HMIDIIN hMidiIn)
+UINT midiInClose(HMIDIIN hMidiIn)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiInClose(%04X)\n", hMidiIn);
+	dprintf_mmsys(stddeb, "midiInClose(%04X)\n", hMidiIn);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return midMessage(0, MIDM_CLOSE, lpDesc->dwInstance, 0L, 0L);
@@ -1283,11 +1275,11 @@
 /**************************************************************************
 * 				midiInPrepareHeader	[MMSYSTEM.306]
 */
-UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
+UINT midiInPrepareHeader(HMIDIIN hMidiIn,
     MIDIHDR FAR* lpMidiInHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiInPrepareHeader(%04X, %p, %d)\n", 
+	dprintf_mmsys(stddeb, "midiInPrepareHeader(%04X, %p, %d)\n", 
 					hMidiIn, lpMidiInHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1298,11 +1290,11 @@
 /**************************************************************************
 * 				midiInUnprepareHeader	[MMSYSTEM.307]
 */
-UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
+UINT midiInUnprepareHeader(HMIDIIN hMidiIn,
     MIDIHDR FAR* lpMidiInHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiInUnprepareHeader(%04X, %p, %d)\n", 
+	dprintf_mmsys(stddeb, "midiInUnprepareHeader(%04X, %p, %d)\n", 
 					hMidiIn, lpMidiInHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1313,57 +1305,57 @@
 /**************************************************************************
 * 				midiInAddBuffer		[MMSYSTEM.308]
 */
-UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
+UINT midiInAddBuffer(HMIDIIN hMidiIn,
     MIDIHDR FAR* lpMidiInHdr, UINT uSize)
 {
-	printf("midiInAddBuffer\n");
+	dprintf_mmsys(stddeb, "midiInAddBuffer\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiInStart			[MMSYSTEM.309]
 */
-UINT WINAPI midiInStart(HMIDIIN hMidiIn)
+UINT midiInStart(HMIDIIN hMidiIn)
 {
-	printf("midiInStart\n");
+	dprintf_mmsys(stddeb, "midiInStart\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiInStop			[MMSYSTEM.310]
 */
-UINT WINAPI midiInStop(HMIDIIN hMidiIn)
+UINT midiInStop(HMIDIIN hMidiIn)
 {
-	printf("midiInStop\n");
+	dprintf_mmsys(stddeb, "midiInStop\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiInReset			[MMSYSTEM.311]
 */
-UINT WINAPI midiInReset(HMIDIIN hMidiIn)
+UINT midiInReset(HMIDIIN hMidiIn)
 {
-	printf("midiInReset\n");
+	dprintf_mmsys(stddeb, "midiInReset\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiInGetID			[MMSYSTEM.312]
 */
-UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT FAR* lpuDeviceID)
+UINT midiInGetID(HMIDIIN hMidiIn, UINT FAR* lpuDeviceID)
 {
-	printf("midiInGetID\n");
+	dprintf_mmsys(stddeb, "midiInGetID\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				midiInMessage		[MMSYSTEM.313]
 */
-DWORD WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage, 
+DWORD midiInMessage(HMIDIIN hMidiIn, UINT uMessage, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiInMessage(%04X, %04X, %08lX, %08lX)\n", 
+	dprintf_mmsys(stddeb, "midiInMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hMidiIn, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPMIDIOPENDESC) USER_HEAP_LIN_ADDR(hMidiIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1374,30 +1366,30 @@
 /**************************************************************************
 * 				waveOutGetNumDevs		[MMSYSTEM.401]
 */
-UINT WINAPI waveOutGetNumDevs()
+UINT waveOutGetNumDevs()
 {
 	UINT	count = 0;
-	printf("waveOutGetNumDevs\n");
+	dprintf_mmsys(stddeb, "waveOutGetNumDevs\n");
 	count += wodMessage(0, WODM_GETNUMDEVS, 0L, 0L, 0L);
-	printf("waveOutGetNumDevs return %u \n", count);
+	dprintf_mmsys(stddeb, "waveOutGetNumDevs return %u \n", count);
 	return count;
 }
 
 /**************************************************************************
 * 				waveOutGetDevCaps		[MMSYSTEM.402]
 */
-UINT WINAPI waveOutGetDevCaps(UINT uDeviceID, WAVEOUTCAPS FAR* lpCaps, UINT uSize)
+UINT waveOutGetDevCaps(UINT uDeviceID, WAVEOUTCAPS FAR* lpCaps, UINT uSize)
 {
-	printf("waveOutGetDevCaps\n");
+	dprintf_mmsys(stddeb, "waveOutGetDevCaps\n");
 	return wodMessage(uDeviceID, WODM_GETDEVCAPS, 0L, (DWORD)lpCaps, uSize);
 }
 
 /**************************************************************************
 * 				waveOutGetErrorText 	[MMSYSTEM.403]
 */
-UINT WINAPI waveOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
+UINT waveOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
 {
-   printf("waveOutGetErrorText\n");
+   dprintf_mmsys(stddeb, "waveOutGetErrorText\n");
    return(waveGetErrorText(uError, lpText, uSize));
 }
 
@@ -1405,11 +1397,11 @@
 /**************************************************************************
 * 				waveGetErrorText 		[internal]
 */
-UINT WINAPI waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
+UINT waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
 {
 	LPSTR	msgptr;
 	int		maxbuf;
-	printf("waveGetErrorText(%04X, %p, %d);\n", uError, lpText, uSize);
+	dprintf_mmsys(stddeb, "waveGetErrorText(%04X, %p, %d);\n", uError, lpText, uSize);
 	if ((lpText == NULL) || (uSize < 1)) return(FALSE);
 	lpText[0] = '\0';
 	switch(uError) {
@@ -1474,7 +1466,7 @@
 /**************************************************************************
 * 				waveOutOpen			[MMSYSTEM.404]
 */
-UINT WINAPI waveOutOpen(HWAVEOUT FAR* lphWaveOut, UINT uDeviceID,
+UINT waveOutOpen(HWAVEOUT FAR* lphWaveOut, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
 	HWAVE	hWaveOut;
@@ -1482,13 +1474,13 @@
 	LPWAVEOPENDESC	lp16Desc;
 	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
-	printf("waveOutOpen(%p, %d, %p, %08lX, %08lX, %08lX);\n", 
+	dprintf_mmsys(stddeb, "waveOutOpen(%p, %d, %p, %08lX, %08lX, %08lX);\n", 
 		lphWaveOut, uDeviceID, lpFormat, dwCallback, dwInstance, dwFlags);
 	if (dwFlags & WAVE_FORMAT_QUERY) {
-		printf("waveOutOpen	// WAVE_FORMAT_QUERY requested !\n");
+		dprintf_mmsys(stddeb, "waveOutOpen	// WAVE_FORMAT_QUERY requested !\n");
 		}
 	if (uDeviceID == (UINT)WAVE_MAPPER) {
-		printf("waveOutOpen	// WAVE_MAPPER mode requested !\n");
+		dprintf_mmsys(stddeb, "waveOutOpen	// WAVE_MAPPER mode requested !\n");
 		bMapperFlg = TRUE;
 		uDeviceID = 0;
 		}
@@ -1508,10 +1500,10 @@
 		if (dwRet == MMSYSERR_NOERROR) break;
 		if (!bMapperFlg) break;
 		uDeviceID++;
-		printf("waveOutOpen	// WAVE_MAPPER mode ! try next driver...\n");
+		dprintf_mmsys(stddeb, "waveOutOpen	// WAVE_MAPPER mode ! try next driver...\n");
 		}
 	if (dwFlags & WAVE_FORMAT_QUERY) {
-		printf("waveOutOpen	// End of WAVE_FORMAT_QUERY !\n");
+		dprintf_mmsys(stddeb, "waveOutOpen	// End of WAVE_FORMAT_QUERY !\n");
 		waveOutClose(hWaveOut);
 		}
 	return dwRet;
@@ -1520,10 +1512,10 @@
 /**************************************************************************
 * 				waveOutClose		[MMSYSTEM.405]
 */
-UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
+UINT waveOutClose(HWAVEOUT hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutClose(%04X)\n", hWaveOut);
+	dprintf_mmsys(stddeb, "waveOutClose(%04X)\n", hWaveOut);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_CLOSE, lpDesc->dwInstance, 0L, 0L);
@@ -1532,11 +1524,11 @@
 /**************************************************************************
 * 				waveOutPrepareHeader	[MMSYSTEM.406]
 */
-UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutPrepareHeader(HWAVEOUT hWaveOut,
      WAVEHDR FAR* lpWaveOutHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutPrepareHeader(%04X, %p, %u);\n", 
+	dprintf_mmsys(stddeb, "waveOutPrepareHeader(%04X, %p, %u);\n", 
 					hWaveOut, lpWaveOutHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1547,11 +1539,11 @@
 /**************************************************************************
 * 				waveOutUnprepareHeader	[MMSYSTEM.407]
 */
-UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutUnprepareHeader(HWAVEOUT hWaveOut,
     WAVEHDR FAR* lpWaveOutHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutUnprepareHeader(%04X, %p, %u);\n", 
+	dprintf_mmsys(stddeb, "waveOutUnprepareHeader(%04X, %p, %u);\n", 
 						hWaveOut, lpWaveOutHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1562,10 +1554,10 @@
 /**************************************************************************
 * 				waveOutWrite		[MMSYSTEM.408]
 */
-UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR FAR* lpWaveOutHdr,  UINT uSize)
+UINT waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR FAR* lpWaveOutHdr,  UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutWrite(%04X, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
+	dprintf_mmsys(stddeb, "waveOutWrite(%04X, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_WRITE, lpDesc->dwInstance, 
@@ -1575,10 +1567,10 @@
 /**************************************************************************
 * 				waveOutPause		[MMSYSTEM.409]
 */
-UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
+UINT waveOutPause(HWAVEOUT hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutPause(%04X)\n", hWaveOut);
+	dprintf_mmsys(stddeb, "waveOutPause(%04X)\n", hWaveOut);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_PAUSE, lpDesc->dwInstance, 0L, 0L);
@@ -1587,10 +1579,10 @@
 /**************************************************************************
 * 				waveOutRestart		[MMSYSTEM.410]
 */
-UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
+UINT waveOutRestart(HWAVEOUT hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutRestart(%04X)\n", hWaveOut);
+	dprintf_mmsys(stddeb, "waveOutRestart(%04X)\n", hWaveOut);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_RESTART, lpDesc->dwInstance, 0L, 0L);
@@ -1599,10 +1591,10 @@
 /**************************************************************************
 * 				waveOutReset		[MMSYSTEM.411]
 */
-UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
+UINT waveOutReset(HWAVEOUT hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutReset(%04X)\n", hWaveOut);
+	dprintf_mmsys(stddeb, "waveOutReset(%04X)\n", hWaveOut);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_RESET, lpDesc->dwInstance, 0L, 0L);
@@ -1611,10 +1603,10 @@
 /**************************************************************************
 * 				waveOutGetPosition	[MMSYSTEM.412]
 */
-UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, MMTIME FAR* lpTime, UINT uSize)
+UINT waveOutGetPosition(HWAVEOUT hWaveOut, MMTIME FAR* lpTime, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutGetPosition(%04X, %p, %u);\n", hWaveOut, lpTime, uSize);
+	dprintf_mmsys(stddeb, "waveOutGetPosition(%04X, %p, %u);\n", hWaveOut, lpTime, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_GETPOS, lpDesc->dwInstance, 
@@ -1624,10 +1616,10 @@
 /**************************************************************************
 * 				waveOutGetPitch		[MMSYSTEM.413]
 */
-UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, DWORD FAR* lpdwPitch)
+UINT waveOutGetPitch(HWAVEOUT hWaveOut, DWORD FAR* lpdwPitch)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutGetPitch(%04X, %p);\n", hWaveOut, lpdwPitch);
+	dprintf_mmsys(stddeb, "waveOutGetPitch(%04X, %p);\n", hWaveOut, lpdwPitch);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_GETPITCH, lpDesc->dwInstance, 
@@ -1637,10 +1629,10 @@
 /**************************************************************************
 * 				waveOutSetPitch		[MMSYSTEM.414]
 */
-UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dwPitch)
+UINT waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dwPitch)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutSetPitch(%04X, %08lX);\n", hWaveOut, dwPitch);
+	dprintf_mmsys(stddeb, "waveOutSetPitch(%04X, %08lX);\n", hWaveOut, dwPitch);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_SETPITCH, lpDesc->dwInstance, (DWORD)dwPitch, 0L);
@@ -1649,28 +1641,28 @@
 /**************************************************************************
 * 				waveOutGetVolume	[MMSYSTEM.415]
 */
-UINT WINAPI waveOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume)
+UINT waveOutGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume)
 {
-	printf("waveOutGetVolume(%04X, %p);\n", uDeviceID, lpdwVolume);
+	dprintf_mmsys(stddeb, "waveOutGetVolume(%04X, %p);\n", uDeviceID, lpdwVolume);
 	return wodMessage(uDeviceID, WODM_GETVOLUME, 0L, (DWORD)lpdwVolume, 0L);
 }
 
 /**************************************************************************
 * 				waveOutSetVolume	[MMSYSTEM.416]
 */
-UINT WINAPI waveOutSetVolume(UINT uDeviceID, DWORD dwVolume)
+UINT waveOutSetVolume(UINT uDeviceID, DWORD dwVolume)
 {
-	printf("waveOutSetVolume(%04X, %08lX);\n", uDeviceID, dwVolume);
+	dprintf_mmsys(stddeb, "waveOutSetVolume(%04X, %08lX);\n", uDeviceID, dwVolume);
 	return wodMessage(uDeviceID, WODM_SETVOLUME, 0L, dwVolume, 0L);
 }
 
 /**************************************************************************
 * 				waveOutGetPlaybackRate	[MMSYSTEM.417]
 */
-UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, DWORD FAR* lpdwRate)
+UINT waveOutGetPlaybackRate(HWAVEOUT hWaveOut, DWORD FAR* lpdwRate)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutGetPlaybackRate(%04X, %p);\n", hWaveOut, lpdwRate);
+	dprintf_mmsys(stddeb, "waveOutGetPlaybackRate(%04X, %p);\n", hWaveOut, lpdwRate);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_GETPLAYBACKRATE, lpDesc->dwInstance, 
@@ -1680,10 +1672,10 @@
 /**************************************************************************
 * 				waveOutSetPlaybackRate	[MMSYSTEM.418]
 */
-UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dwRate)
+UINT waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dwRate)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutSetPlaybackRate(%04X, %08lX);\n", hWaveOut, dwRate);
+	dprintf_mmsys(stddeb, "waveOutSetPlaybackRate(%04X, %08lX);\n", hWaveOut, dwRate);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_SETPLAYBACKRATE, 
@@ -1693,19 +1685,19 @@
 /**************************************************************************
 * 				waveOutBreakLoop 	[MMSYSTEM.419]
 */
-UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
+UINT waveOutBreakLoop(HWAVEOUT hWaveOut)
 {
-	printf("waveOutBreakLoop(%04X)\n", hWaveOut);
+	dprintf_mmsys(stddeb, "waveOutBreakLoop(%04X)\n", hWaveOut);
 	return MMSYSERR_INVALHANDLE;
 }
 
 /**************************************************************************
 * 				waveOutGetID	 	[MMSYSTEM.420]
 */
-UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT FAR* lpuDeviceID)
+UINT waveOutGetID(HWAVEOUT hWaveOut, UINT FAR* lpuDeviceID)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutGetID(%04X, %p);\n", hWaveOut, lpuDeviceID);
+	dprintf_mmsys(stddeb, "waveOutGetID(%04X, %p);\n", hWaveOut, lpuDeviceID);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
@@ -1718,11 +1710,11 @@
 /**************************************************************************
 * 				waveOutMessage 		[MMSYSTEM.421]
 */
-DWORD WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, 
+DWORD waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutMessage(%04X, %04X, %08lX, %08lX)\n", 
+	dprintf_mmsys(stddeb, "waveOutMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hWaveOut, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1732,12 +1724,12 @@
 /**************************************************************************
 * 				waveInGetNumDevs 		[MMSYSTEM.501]
 */
-UINT WINAPI waveInGetNumDevs()
+UINT waveInGetNumDevs()
 {
 	UINT	count = 0;
-	printf("waveInGetNumDevs\n");
+	dprintf_mmsys(stddeb, "waveInGetNumDevs\n");
 	count += widMessage(0, WIDM_GETNUMDEVS, 0L, 0L, 0L);
-	printf("waveInGetNumDevs return %u \n", count);
+	dprintf_mmsys(stddeb, "waveInGetNumDevs return %u \n", count);
 	return count;
 }
 
@@ -1745,9 +1737,9 @@
 /**************************************************************************
 * 				waveInGetDevCaps 		[MMSYSTEM.502]
 */
-UINT WINAPI waveInGetDevCaps(UINT uDeviceID, WAVEINCAPS FAR* lpCaps, UINT uSize)
+UINT waveInGetDevCaps(UINT uDeviceID, WAVEINCAPS FAR* lpCaps, UINT uSize)
 {
-	printf("waveInGetDevCaps\n");
+	dprintf_mmsys(stddeb, "waveInGetDevCaps\n");
 	return widMessage(uDeviceID, WIDM_GETDEVCAPS, 0L, (DWORD)lpCaps, uSize);
 }
 
@@ -1755,9 +1747,9 @@
 /**************************************************************************
 * 				waveInGetErrorText 	[MMSYSTEM.503]
 */
-UINT WINAPI waveInGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
+UINT waveInGetErrorText(UINT uError, LPSTR lpText, UINT uSize)
 {
-   printf("waveInGetErrorText\n");
+   dprintf_mmsys(stddeb, "waveInGetErrorText\n");
    return(waveGetErrorText(uError, lpText, uSize));
 }
 
@@ -1765,7 +1757,7 @@
 /**************************************************************************
 * 				waveInOpen			[MMSYSTEM.504]
 */
-UINT WINAPI waveInOpen(HWAVEIN FAR* lphWaveIn, UINT uDeviceID,
+UINT waveInOpen(HWAVEIN FAR* lphWaveIn, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
 	HWAVE	hWaveIn;
@@ -1773,13 +1765,13 @@
 	LPWAVEOPENDESC	lp16Desc;
 	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
-	printf("waveInOpen(%p, %d, %p, %08lX, %08lX, %08lX);\n", 
+	dprintf_mmsys(stddeb, "waveInOpen(%p, %d, %p, %08lX, %08lX, %08lX);\n", 
 		lphWaveIn, uDeviceID, lpFormat, dwCallback, dwInstance, dwFlags);
 	if (dwFlags & WAVE_FORMAT_QUERY) {
-		printf("waveInOpen // WAVE_FORMAT_QUERY requested !\n");
+		dprintf_mmsys(stddeb, "waveInOpen // WAVE_FORMAT_QUERY requested !\n");
 		}
 	if (uDeviceID == (UINT)WAVE_MAPPER) {
-		printf("waveInOpen	// WAVE_MAPPER mode requested !\n");
+		dprintf_mmsys(stddeb, "waveInOpen	// WAVE_MAPPER mode requested !\n");
 		bMapperFlg = TRUE;
 		uDeviceID = 0;
 		}
@@ -1799,10 +1791,10 @@
 		if (dwRet == MMSYSERR_NOERROR) break;
 		if (!bMapperFlg) break;
 		uDeviceID++;
-		printf("waveInOpen	// WAVE_MAPPER mode ! try next driver...\n");
+		dprintf_mmsys(stddeb, "waveInOpen	// WAVE_MAPPER mode ! try next driver...\n");
 		}
 	if (dwFlags & WAVE_FORMAT_QUERY) {
-		printf("waveInOpen	// End of WAVE_FORMAT_QUERY !\n");
+		dprintf_mmsys(stddeb, "waveInOpen	// End of WAVE_FORMAT_QUERY !\n");
 		waveInClose(hWaveIn);
 		}
 	return dwRet;
@@ -1812,10 +1804,10 @@
 /**************************************************************************
 * 				waveInClose			[MMSYSTEM.505]
 */
-UINT WINAPI waveInClose(HWAVEIN hWaveIn)
+UINT waveInClose(HWAVEIN hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInClose(%04X)\n", hWaveIn);
+	dprintf_mmsys(stddeb, "waveInClose(%04X)\n", hWaveIn);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return widMessage(0, WIDM_CLOSE, lpDesc->dwInstance, 0L, 0L);
@@ -1825,12 +1817,12 @@
 /**************************************************************************
 * 				waveInPrepareHeader		[MMSYSTEM.506]
 */
-UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn,
+UINT waveInPrepareHeader(HWAVEIN hWaveIn,
     WAVEHDR FAR* lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEHDR 		lp32WaveInHdr;
-	printf("waveInPrepareHeader(%04X, %p, %u);\n", 
+	dprintf_mmsys(stddeb, "waveInPrepareHeader(%04X, %p, %u);\n", 
 					hWaveIn, lpWaveInHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1838,7 +1830,7 @@
 	lp32WaveInHdr = PTR_SEG_TO_LIN(lpWaveInHdr);
 	lp32WaveInHdr->lpNext = NULL;
     lp32WaveInHdr->dwBytesRecorded = 0;
-	printf("waveInPrepareHeader // lpData=%p size=%lu \n", 
+	dprintf_mmsys(stddeb, "waveInPrepareHeader // lpData=%p size=%lu \n", 
 		lp32WaveInHdr->lpData, lp32WaveInHdr->dwBufferLength);
 	return widMessage(0, WIDM_PREPARE, lpDesc->dwInstance, 
 							(DWORD)lpWaveInHdr, uSize);
@@ -1848,12 +1840,12 @@
 /**************************************************************************
 * 				waveInUnprepareHeader	[MMSYSTEM.507]
 */
-UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn,
+UINT waveInUnprepareHeader(HWAVEIN hWaveIn,
     WAVEHDR FAR* lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEHDR 		lp32WaveInHdr;
-	printf("waveInUnprepareHeader(%04X, %p, %u);\n", 
+	dprintf_mmsys(stddeb, "waveInUnprepareHeader(%04X, %p, %u);\n", 
 						hWaveIn, lpWaveInHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1870,19 +1862,19 @@
 /**************************************************************************
 * 				waveInAddBuffer		[MMSYSTEM.508]
 */
-UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
+UINT waveInAddBuffer(HWAVEIN hWaveIn,
     WAVEHDR FAR* lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEHDR 		lp32WaveInHdr;
-	printf("waveInAddBuffer(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
+	dprintf_mmsys(stddeb, "waveInAddBuffer(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
 	lp32WaveInHdr = PTR_SEG_TO_LIN(lpWaveInHdr);
 	lp32WaveInHdr->lpNext = NULL;
     lp32WaveInHdr->dwBytesRecorded = 0;
-	printf("waveInAddBuffer // lpData=%p size=%lu \n", 
+	dprintf_mmsys(stddeb, "waveInAddBuffer // lpData=%p size=%lu \n", 
 		lp32WaveInHdr->lpData, lp32WaveInHdr->dwBufferLength);
 	return widMessage(0, WIDM_ADDBUFFER, lpDesc->dwInstance,
 								(DWORD)lpWaveInHdr, uSize);
@@ -1892,10 +1884,10 @@
 /**************************************************************************
 * 				waveInStart			[MMSYSTEM.509]
 */
-UINT WINAPI waveInStart(HWAVEIN hWaveIn)
+UINT waveInStart(HWAVEIN hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInStart(%04X)\n", hWaveIn);
+	dprintf_mmsys(stddeb, "waveInStart(%04X)\n", hWaveIn);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return widMessage(0, WIDM_START, lpDesc->dwInstance, 0L, 0L);
@@ -1905,10 +1897,10 @@
 /**************************************************************************
 * 				waveInStop			[MMSYSTEM.510]
 */
-UINT WINAPI waveInStop(HWAVEIN hWaveIn)
+UINT waveInStop(HWAVEIN hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInStop(%04X)\n", hWaveIn);
+	dprintf_mmsys(stddeb, "waveInStop(%04X)\n", hWaveIn);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return widMessage(0, WIDM_STOP, lpDesc->dwInstance, 0L, 0L);
@@ -1918,10 +1910,10 @@
 /**************************************************************************
 * 				waveInReset			[MMSYSTEM.511]
 */
-UINT WINAPI waveInReset(HWAVEIN hWaveIn)
+UINT waveInReset(HWAVEIN hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInReset(%04X)\n", hWaveIn);
+	dprintf_mmsys(stddeb, "waveInReset(%04X)\n", hWaveIn);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return widMessage(0, WIDM_RESET, lpDesc->dwInstance, 0L, 0L);
@@ -1931,10 +1923,10 @@
 /**************************************************************************
 * 				waveInGetPosition	[MMSYSTEM.512]
 */
-UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, MMTIME FAR* lpTime, UINT uSize)
+UINT waveInGetPosition(HWAVEIN hWaveIn, MMTIME FAR* lpTime, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInGetPosition(%04X, %p, %u);\n", hWaveIn, lpTime, uSize);
+	dprintf_mmsys(stddeb, "waveInGetPosition(%04X, %p, %u);\n", hWaveIn, lpTime, uSize);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return widMessage(0, WIDM_GETPOS, lpDesc->dwInstance,
@@ -1945,9 +1937,9 @@
 /**************************************************************************
 * 				waveInGetID			[MMSYSTEM.513]
 */
-UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT FAR* lpuDeviceID)
+UINT waveInGetID(HWAVEIN hWaveIn, UINT FAR* lpuDeviceID)
 {
-	printf("waveInGetID\n");
+	dprintf_mmsys(stddeb, "waveInGetID\n");
 	if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
 	return 0;
 }
@@ -1956,11 +1948,11 @@
 /**************************************************************************
 * 				waveInMessage 		[MMSYSTEM.514]
 */
-DWORD WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
+DWORD waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInMessage(%04X, %04X, %08lX, %08lX)\n", 
+	dprintf_mmsys(stddeb, "waveInMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hWaveIn, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPWAVEOPENDESC) USER_HEAP_LIN_ADDR(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -2021,7 +2013,7 @@
 */
 WORD timeGetSystemTime(LPMMTIME lpTime, WORD wSize)
 {
-	printf("timeGetSystemTime(%p, %u);\n", lpTime, wSize);
+	dprintf_mmsys(stddeb, "timeGetSystemTime(%p, %u);\n", lpTime, wSize);
 	if (!mmTimeStarted) StartMMTime();
 	return 0;
 }
@@ -2036,7 +2028,7 @@
 	WORD			wNewID = 0;
 	LPTIMERENTRY	lpNewTimer;
 	LPTIMERENTRY	lpTimer = lpTimerList;
-	printf("timeSetEvent(%u, %u, %p, %08lX, %04X);\n",
+	dprintf_mmsys(stddeb, "timeSetEvent(%u, %u, %p, %08lX, %04X);\n",
 			wDelay, wResol, lpFunc, dwUser, wFlags);
 	if (!mmTimeStarted) StartMMTime();
 	lpNewTimer = (LPTIMERENTRY) malloc(sizeof(TIMERENTRY));
@@ -2088,7 +2080,7 @@
 */
 WORD timeGetDevCaps(LPTIMECAPS lpCaps, WORD wSize)
 {
-	printf("timeGetDevCaps(%p, %u) !\n", lpCaps, wSize);
+	dprintf_mmsys(stddeb, "timeGetDevCaps(%p, %u) !\n", lpCaps, wSize);
 	return 0;
 }
 
@@ -2097,7 +2089,7 @@
 */
 WORD timeBeginPeriod(WORD wPeriod)
 {
-	printf("timeBeginPeriod(%u) !\n", wPeriod);
+	dprintf_mmsys(stddeb, "timeBeginPeriod(%u) !\n", wPeriod);
 	if (!mmTimeStarted) StartMMTime();
 	return 0;
 }
@@ -2107,7 +2099,7 @@
 */
 WORD timeEndPeriod(WORD wPeriod)
 {
-	printf("timeEndPeriod(%u) !\n", wPeriod);
+	dprintf_mmsys(stddeb, "timeEndPeriod(%u) !\n", wPeriod);
 	return 0;
 }
 
@@ -2116,7 +2108,7 @@
 */
 DWORD timeGetTime()
 {
-	printf("timeGetTime(); !\n");
+	dprintf_mmsys(stddeb, "timeGetTime(); !\n");
 	if (!mmTimeStarted) StartMMTime();
 	return 0;
 }
@@ -2125,13 +2117,13 @@
 /**************************************************************************
 * 				mmioOpen			[MMSYSTEM.1210]
 */
-HMMIO WINAPI mmioOpen(LPSTR szFileName, MMIOINFO FAR* lpmmioinfo, DWORD dwOpenFlags)
+HMMIO mmioOpen(LPSTR szFileName, MMIOINFO FAR* lpmmioinfo, DWORD dwOpenFlags)
 {
 	int		hFile;
 	HANDLE		hmmio;
 	OFSTRUCT	ofs;
 	LPMMIOINFO	lpmminfo;
-	printf("mmioOpen('%s', %p, %08lX);\n", szFileName, lpmmioinfo, dwOpenFlags);
+	dprintf_mmsys(stddeb, "mmioOpen('%s', %p, %08lX);\n", szFileName, lpmmioinfo, dwOpenFlags);
 	hFile = OpenFile(szFileName, &ofs, dwOpenFlags);
 	if (hFile == -1) return 0;
 	hmmio = GlobalAlloc(GMEM_MOVEABLE, sizeof(MMIOINFO));
@@ -2141,7 +2133,7 @@
 	lpmminfo->hmmio = hmmio;
 	lpmminfo->dwReserved2 = MAKELONG(hFile, 0);
 	GlobalUnlock(hmmio);
-	printf("mmioOpen // return hmmio=%04X\n", hmmio);
+	dprintf_mmsys(stddeb, "mmioOpen // return hmmio=%04X\n", hmmio);
 	return (HMMIO)hmmio;
 }
 
@@ -2150,10 +2142,10 @@
 /**************************************************************************
 * 				mmioClose			[MMSYSTEM.1211]
 */
-UINT WINAPI mmioClose(HMMIO hmmio, UINT uFlags)
+UINT mmioClose(HMMIO hmmio, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
-	printf("mmioClose(%04X, %04X);\n", hmmio, uFlags);
+	dprintf_mmsys(stddeb, "mmioClose(%04X, %04X);\n", hmmio, uFlags);
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) return 0;
 	_lclose(LOWORD(lpmminfo->dwReserved2));
@@ -2167,7 +2159,7 @@
 /**************************************************************************
 * 				mmioRead			[MMSYSTEM.1212]
 */
-LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
+LONG mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
 {
 	LONG		count;
 	LPMMIOINFO	lpmminfo;
@@ -2185,11 +2177,11 @@
 /**************************************************************************
 * 				mmioWrite			[MMSYSTEM.1213]
 */
-LONG WINAPI mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch)
+LONG mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch)
 {
 	LONG		count;
 	LPMMIOINFO	lpmminfo;
-	printf("mmioWrite(%04X, %p, %ld);\n", hmmio, pch, cch);
+	dprintf_mmsys(stddeb, "mmioWrite(%04X, %p, %ld);\n", hmmio, pch, cch);
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) return 0;
 	count = _lwrite(LOWORD(lpmminfo->dwReserved2), (LPSTR)pch, cch);
@@ -2200,14 +2192,14 @@
 /**************************************************************************
 * 				mmioSeek			[MMSYSTEM.1214]
 */
-LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, int iOrigin)
+LONG mmioSeek(HMMIO hmmio, LONG lOffset, int iOrigin)
 {
 	int		count;
 	LPMMIOINFO	lpmminfo;
-	printf("mmioSeek(%04X, %08lX, %d);\n", hmmio, lOffset, iOrigin);
+	dprintf_mmsys(stddeb, "mmioSeek(%04X, %08lX, %d);\n", hmmio, lOffset, iOrigin);
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) {
-		printf("mmioSeek // can't lock hmmio=%04X !\n", hmmio);
+		dprintf_mmsys(stddeb, "mmioSeek // can't lock hmmio=%04X !\n", hmmio);
 		return 0;
 		}
 	count = _llseek(LOWORD(lpmminfo->dwReserved2), lOffset, iOrigin);
@@ -2218,10 +2210,10 @@
 /**************************************************************************
 * 				mmioGetInfo			[MMSYSTEM.1215]
 */
-UINT WINAPI mmioGetInfo(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags)
+UINT mmioGetInfo(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
-	printf("mmioGetInfo\n");
+	dprintf_mmsys(stddeb, "mmioGetInfo\n");
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) return 0;
 	memcpy(lpmmioinfo, lpmminfo, sizeof(MMIOINFO));
@@ -2232,10 +2224,10 @@
 /**************************************************************************
 * 				mmioSetInfo			[MMSYSTEM.1216]
 */
-UINT WINAPI mmioSetInfo(HMMIO hmmio, const MMIOINFO FAR* lpmmioinfo, UINT uFlags)
+UINT mmioSetInfo(HMMIO hmmio, const MMIOINFO FAR* lpmmioinfo, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
-	printf("mmioSetInfo\n");
+	dprintf_mmsys(stddeb, "mmioSetInfo\n");
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) return 0;
 	GlobalUnlock(hmmio);
@@ -2245,20 +2237,20 @@
 /**************************************************************************
 * 				mmioSetBuffer		[MMSYSTEM.1217]
 */
-UINT WINAPI mmioSetBuffer(HMMIO hmmio, LPSTR pchBuffer, 
+UINT mmioSetBuffer(HMMIO hmmio, LPSTR pchBuffer, 
 						LONG cchBuffer, UINT uFlags)
 {
-	printf("mmioSetBuffer // empty stub \n");
+	dprintf_mmsys(stddeb, "mmioSetBuffer // empty stub \n");
 	return 0;
 }
 
 /**************************************************************************
 * 				mmioFlush			[MMSYSTEM.1218]
 */
-UINT WINAPI mmioFlush(HMMIO hmmio, UINT uFlags)
+UINT mmioFlush(HMMIO hmmio, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
-	printf("mmioFlush(%04X, %04X)\n", hmmio, uFlags);
+	dprintf_mmsys(stddeb, "mmioFlush(%04X, %04X)\n", hmmio, uFlags);
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) return 0;
 	GlobalUnlock(hmmio);
@@ -2268,11 +2260,11 @@
 /**************************************************************************
 * 				mmioAdvance			[MMSYSTEM.1219]
 */
-UINT WINAPI mmioAdvance(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags)
+UINT mmioAdvance(HMMIO hmmio, MMIOINFO FAR* lpmmioinfo, UINT uFlags)
 {
 	int		count = 0;
 	LPMMIOINFO	lpmminfo;
-	printf("mmioAdvance\n");
+	dprintf_mmsys(stddeb, "mmioAdvance\n");
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) return 0;
 	if (uFlags == MMIO_READ) {
@@ -2292,36 +2284,36 @@
 /**************************************************************************
 * 				mmioStringToFOURCC	[MMSYSTEM.1220]
 */
-FOURCC WINAPI mmioStringToFOURCC(LPCSTR sz, UINT uFlags)
+FOURCC mmioStringToFOURCC(LPCSTR sz, UINT uFlags)
 {
-	printf("mmioStringToFOURCC // empty stub \n");
+	dprintf_mmsys(stddeb, "mmioStringToFOURCC // empty stub \n");
 	return 0;
 }
 
 /**************************************************************************
 * 				mmioInstallIOProc	[MMSYSTEM.1221]
 */
-LPMMIOPROC WINAPI mmioInstallIOProc(FOURCC fccIOProc, 
+LPMMIOPROC mmioInstallIOProc(FOURCC fccIOProc, 
 				LPMMIOPROC pIOProc, DWORD dwFlags)
 {
-	printf("mmioInstallIOProc // empty stub \n");
+	dprintf_mmsys(stddeb, "mmioInstallIOProc // empty stub \n");
 	return 0;
 }
 
 /**************************************************************************
 * 				mmioSendMessage		[MMSYSTEM.1222]
 */
-LRESULT WINAPI mmioSendMessage(HMMIO hmmio, UINT uMessage,
+LRESULT mmioSendMessage(HMMIO hmmio, UINT uMessage,
 					    LPARAM lParam1, LPARAM lParam2)
 {
-	printf("mmioSendMessage // empty stub \n");
+	dprintf_mmsys(stddeb, "mmioSendMessage // empty stub \n");
 	return 0;
 }
 
 /**************************************************************************
 * 				mmioDescend			[MMSYSTEM.1223]
 */
-UINT WINAPI mmioDescend(HMMIO hmmio, MMCKINFO FAR* lpck,
+UINT mmioDescend(HMMIO hmmio, MMCKINFO FAR* lpck,
 		    const MMCKINFO FAR* lpckParent, UINT uFlags)
 {
 	DWORD	dwfcc, dwOldPos;
@@ -2375,25 +2367,25 @@
 	GlobalUnlock(hmmio);
 	dprintf_mmio(stddeb, "mmioDescend // lpck->ckid=%08lX lpck->cksize=%ld !\n", 
 								lpck->ckid, lpck->cksize);
-	printf("mmioDescend // lpck->fccType=%08lX !\n", lpck->fccType);
+	dprintf_mmsys(stddeb, "mmioDescend // lpck->fccType=%08lX !\n", lpck->fccType);
 	return 0;
 }
 
 /**************************************************************************
 * 				mmioAscend			[MMSYSTEM.1224]
 */
-UINT WINAPI mmioAscend(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags)
+UINT mmioAscend(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags)
 {
-	printf("mmioAscend // empty stub !\n");
+	dprintf_mmsys(stddeb, "mmioAscend // empty stub !\n");
 	return 0;
 }
 
 /**************************************************************************
 * 				mmioCreateChunk		[MMSYSTEM.1225]
 */
-UINT WINAPI mmioCreateChunk(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags)
+UINT mmioCreateChunk(HMMIO hmmio, MMCKINFO FAR* lpck, UINT uFlags)
 {
-	printf("mmioCreateChunk // empty stub \n");
+	dprintf_mmsys(stddeb, "mmioCreateChunk // empty stub \n");
 	return 0;
 }
 
@@ -2401,10 +2393,10 @@
 /**************************************************************************
 * 				mmioRename			[MMSYSTEM.1226]
 */
-UINT WINAPI mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
+UINT mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
      MMIOINFO FAR* lpmmioinfo, DWORD dwRenameFlags)
 {
-	printf("mmioRename('%s', '%s', %p, %08lX); // empty stub \n",
+	dprintf_mmsys(stddeb, "mmioRename('%s', '%s', %p, %08lX); // empty stub \n",
 			szFileName, szNewFileName, lpmmioinfo, dwRenameFlags);
 	return 0;
 }
@@ -2414,7 +2406,7 @@
 */
 HDRVR DrvOpen(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
 {
-	printf("DrvOpen('%s', '%s', %08lX);\n",
+	dprintf_mmsys(stddeb, "DrvOpen('%s', '%s', %08lX);\n",
 		lpDriverName, lpSectionName, lParam);
 	return OpenDriver(lpDriverName, lpSectionName, lParam);
 }
@@ -2425,7 +2417,7 @@
 */
 LRESULT DrvClose(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
 {
-	printf("DrvClose(%04X, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
+	dprintf_mmsys(stddeb, "DrvClose(%04X, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
 	return CloseDriver(hDrvr, lParam1, lParam2);
 }
 
@@ -2433,10 +2425,10 @@
 /**************************************************************************
 * 				DrvSendMessage		[MMSYSTEM.1102]
 */
-LRESULT WINAPI DrvSendMessage(HDRVR hDriver, WORD msg, LPARAM lParam1, LPARAM lParam2)
+LRESULT DrvSendMessage(HDRVR hDriver, WORD msg, LPARAM lParam1, LPARAM lParam2)
 {
 	DWORD 	dwDevID = 0;
-	printf("DrvSendMessage(%04X, %04X, %08lX, %08lX);\n",
+	dprintf_mmsys(stddeb, "DrvSendMessage(%04X, %04X, %08lX, %08lX);\n",
 					hDriver, msg, lParam1, lParam2);
 #ifndef WINELIB
 	return CDAUDIO_DriverProc(dwDevID, hDriver, msg, lParam1, lParam2);
@@ -2448,7 +2440,7 @@
 */
 HANDLE DrvGetModuleHandle(HDRVR hDrvr)
 {
-	printf("DrvGetModuleHandle(%04X);\n", hDrvr);
+	dprintf_mmsys(stddeb, "DrvGetModuleHandle(%04X);\n", hDrvr);
         return 0;
 }
 
diff --git a/objects/bitblt.c b/objects/bitblt.c
index f5037b0..12f8167 100644
--- a/objects/bitblt.c
+++ b/objects/bitblt.c
@@ -1240,8 +1240,12 @@
                 "BitBlt: %04x %d,%d %d bpp -> %04x %d,%d %dx%dx%d rop=%06lx\n",
                 hdcSrc, xSrc, ySrc, dcSrc ? dcSrc->w.bitsPerPixel : 0,
                 hdcDst, xDst, yDst, width, height, dcDst->w.bitsPerPixel, rop);
-    dprintf_bitblt(stddeb,"        src org=%d,%d  dst org=%d,%d\n",
-                dcSrc->w.DCOrgX, dcSrc->w.DCOrgY, dcDst->w.DCOrgX, dcDst->w.DCOrgY );
+    if (dcSrc != NULL) {
+	dprintf_bitblt(stddeb,"        src org=%d,%d",
+		       dcSrc->w.DCOrgX, dcSrc->w.DCOrgY);
+    }
+    dprintf_bitblt(stddeb,"  dst org=%d,%d\n", dcDst->w.DCOrgX, 
+		   dcDst->w.DCOrgY);
     return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
                                 dcDst, xDst, yDst, width, height,
                                 dcSrc, xSrc, ySrc, width, height, rop );
diff --git a/objects/dc.c b/objects/dc.c
index 92bf252..5a74ad2 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -334,6 +334,7 @@
 
     dprintf_dc(stddeb, "GetDCState(%d): returning %d\n", hdc, handle );
 
+    memset( &newdc->u.x, 0, sizeof(newdc->u.x) );
     memcpy( &newdc->w, &dc->w, sizeof(dc->w) );
     memcpy( &newdc->u.x.pen, &dc->u.x.pen, sizeof(dc->u.x.pen) );
     newdc->saveLevel = 0;
diff --git a/objects/dcvalues.c b/objects/dcvalues.c
index 8180c44..5bd7729 100644
--- a/objects/dcvalues.c
+++ b/objects/dcvalues.c
@@ -22,7 +22,7 @@
 { \
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); \
     if (!dc) return 0; \
-    return MAKELONG( dc->w.ret_x, dc->w.ret_y << 16 ); \
+    return MAKELONG( dc->w.ret_x, dc->w.ret_y ); \
 }
 
 #define DC_GET_VAL_EX( func_name, ret_x, ret_y ) \
diff --git a/objects/dib.c b/objects/dib.c
index f55c44f..34a202f 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -473,8 +473,8 @@
 	if (coloruse == DIB_RGB_COLORS)
 	{
 	    RGBQUAD * rgbPtr = info->bmiColors;
-	    for (i = 0; i < colors; i++, rgbPtr++)
-		colorMapping[i] = COLOR_ToPhysical( dc, RGB(rgbPtr->rgbRed,
+            for (i = 0; i < colors; i++, rgbPtr++)
+                colorMapping[i] = COLOR_ToPhysical( dc, RGB(rgbPtr->rgbRed,
 							    rgbPtr->rgbGreen,
 							    rgbPtr->rgbBlue) );
 	}
@@ -677,6 +677,9 @@
     HBITMAP handle;
     
     handle = CreateCompatibleBitmap( hdc, header->biWidth, header->biHeight );
+/*    handle = CreateBitmap( header->biWidth, header->biHeight,
+                           1, header->biBitCount, NULL );
+*/
     if (!handle) return 0;
     if (init == CBM_INIT) SetDIBits( hdc, handle, 0, header->biHeight,
 				    bits, data, coloruse );
diff --git a/objects/font.c b/objects/font.c
index b6bcaaa..57079f0 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -15,7 +15,6 @@
 #include "wine.h"
 #include "callback.h"
 #include "stddebug.h"
-/* #define DEBUG_FONT */
 #include "debug.h"
 
 #define MAX_FONTS	256
@@ -122,7 +121,7 @@
     const char *family, *weight, *charset;
     char **names;
     char slant, spacing;
-    int width, height, count;
+    int width, height, oldheight, count;
     XFontStruct * fontStruct;
     
     weight = (font->lfWeight > 550) ? "bold" : "medium";
@@ -138,6 +137,11 @@
     }
     else height *= 10;
     width  = 10 * (font->lfWidth * dc->w.VportExtY / dc->w.WndExtY);
+    if (width < 0) {
+	dprintf_font( stddeb, "FONT_MatchFont: negative width %d(%d)\n",
+		      width, font->lfWidth );
+	width = -width;
+    }
     spacing = (font->lfPitchAndFamily & FIXED_PITCH) ? 'm' :
 	      (font->lfPitchAndFamily & VARIABLE_PITCH) ? 'p' : '*';
     charset = (font->lfCharSet == ANSI_CHARSET) ? "iso8859-1" : "*-*";
@@ -164,6 +168,7 @@
       break;
     }
     
+    oldheight = height;
     while (TRUE) {
 	    /* Width==0 seems not to be a valid wildcard on SGI's, using * instead */
 	    if ( width == 0 )
@@ -178,11 +183,20 @@
             height -= 10;		
             if (height < 10) {
                 dprintf_font(stddeb,"*** No match for %s\n", pattern );
-				if(slant == 'i')
-					/* try oblique if no italic font */
-					slant = 'o';
-				else
-                	return NULL;
+		if(slant == 'i') {
+		    /* try oblique if no italic font */
+		    slant = 'o';
+		    height = oldheight;
+		    continue;
+		}
+		if (spacing == 'm') {
+		    /* If a fixed spacing font could not be found, ignore
+		     * the family */
+		    family = "*-*";
+		    height = oldheight;
+		    continue;
+		}
+		return NULL;
             }
     }
     dprintf_font(stddeb,"        Found '%s'\n", *names );
@@ -630,7 +644,7 @@
   names = XListFonts( display, pattern, MAX_FONTS, &count );
   dprintf_font(stddeb,"InitFontsList // count=%d \n", count);
   for (i = 0; i < count; i++) {
-    lpNewFont = malloc(sizeof(LOGFONT));
+    lpNewFont = malloc(sizeof(LOGFONT) + LF_FACESIZE);
     if (lpNewFont == NULL) {
       dprintf_font(stddeb, "InitFontsList // Error alloc new font structure !\n");
       break;
@@ -731,6 +745,7 @@
       if (strcmp(FaceName, lpLogFontList[i]->lfFaceName) != 0) continue;
     }
     dprintf_font(stddeb,"EnumFonts // enum '%s' !\n", lpLogFontList[i]->lfFaceName);
+    dprintf_font(stddeb,"EnumFonts // %p !\n", lpLogFontList[i]);
     memcpy(lpLogFont, lpLogFontList[i], sizeof(LOGFONT) + LF_FACESIZE);
     hFont = CreateFontIndirect(lpLogFont);
     hOldFont = SelectObject(hDC, hFont);
@@ -836,3 +851,13 @@
   rs.nLanguageID = 0;
   return True;
 }
+
+/*************************************************************************
+ *             GetKerningPairs      [GDI.332]
+ *  FIXME: The last parameter is actually LPKERNINGPAIR
+ */
+int GetKerningPairs(WORD hDC,int cBufLen,LPVOID lpKerningPairs)
+{
+	/* Wine fonts are ugly and don't support kerning :) */
+	return 0;
+}
diff --git a/objects/text.c b/objects/text.c
index 52673fe..09a58e4 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -262,7 +262,7 @@
 	y += lh;
 	if (strPtr)
 	{
-	    if (!(flags & DT_NOCLIP))
+	    if (!(flags & DT_NOCLIP) && !(flags & DT_CALCRECT))
 	    {
 		if (y > rect->bottom - lh)
 		    break;
diff --git a/rc/parser.l b/rc/parser.l
index 3add2b5..945ff82 100644
--- a/rc/parser.l
+++ b/rc/parser.l
@@ -4,7 +4,6 @@
  * Copyright  Martin von Loewis, 1994
  *
  */
-static char Copyright[] = "Copyright Martin von Loewis, 1994";
 
 #include <string.h>
 #include <stdio.h>
diff --git a/rc/parser.y b/rc/parser.y
index 9ba6969..d8d7004 100644
--- a/rc/parser.y
+++ b/rc/parser.y
@@ -4,8 +4,6 @@
  * Copyright  Martin von Loewis, 1994
  */
 
-static char Copyright[] = "Copyright Martin von Loewis, 1994";
-
 #include <stdio.h>
 #include "parser.h"
 #include "windows.h"
diff --git a/rc/sysres.rc b/rc/sysres.rc
index 44e217f..bc15c8c 100644
--- a/rc/sysres.rc
+++ b/rc/sysres.rc
@@ -85,50 +85,6 @@
 }
 
 
-11 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Open"
-FONT 8, "Helv"
-{
- LTEXT "File &Name:", 1090, 6, 6, 76, 9
- LTEXT "", 1152, 6, 16, 90, 12
- LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "&Directories:", -1, 110, 6, 92, 9
- LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
- LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "List Files of &Type:", 1089, 6, 104, 90, 9
- COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- LTEXT "Dri&ves:", 1091, 110, 104, 92, 9
- COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- DEFPUSHBUTTON "Open", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
- PUSHBUTTON "Cancel", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
- PUSHBUTTON "&Help", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
- CHECKBOX "&Read Only", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
-}
-
-
-12 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Save As ..."
-FONT 8, "Helv"
-{
- LTEXT "File &Name:", 1090, 6, 6, 76, 9
- LTEXT "", 1152, 6, 16, 90, 12
- LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "&Directories:", -1, 110, 6, 92, 9
- LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
- LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "List Files of &Type:", 1089, 6, 104, 90, 9
- COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- LTEXT "Dri&ves:", 1091, 110, 104, 92, 9
- COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- DEFPUSHBUTTON "Save As", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
- PUSHBUTTON "Cancel", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
- PUSHBUTTON "&Help", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
- CHECKBOX "&Read Only", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
-}
-
-
 5 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Print"
diff --git a/rc/sysres_De.rc b/rc/sysres_De.rc
index 4f74ac2..ee38aae 100644
--- a/rc/sysres_De.rc
+++ b/rc/sysres_De.rc
@@ -83,50 +83,6 @@
 }
 
 
-11 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Öffnen"
-FONT 8, "Helv"
-{
- LTEXT "Datei&name:", 1090, 6, 6, 76, 9
- LTEXT "", 1152, 6, 16, 90, 12
- LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "&Verzeichnisse:", -1, 110, 6, 92, 9
- LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
- LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "Liste der Datei&typen:", 1089, 6, 104, 90, 9
- COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- LTEXT "&Laufwerke:", 1091, 110, 104, 92, 9
- COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- DEFPUSHBUTTON "Öffnen", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
- PUSHBUTTON "Abbrechen", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
- PUSHBUTTON "&Hilfe", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
- CHECKBOX "&Schreibgeschützt", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
-}
-
-
-12 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Speichern als ..."
-FONT 8, "Helv"
-{
- LTEXT "Datei&name:", 1090, 6, 6, 76, 9
- LTEXT "", 1152, 6, 16, 90, 12
- LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "&Verzeichnisse:", -1, 110, 6, 92, 9
- LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
- LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "Liste der Datei&typen:", 1089, 6, 104, 90, 9
- COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- LTEXT "&Laufwerke:", 1091, 110, 104, 92, 9
- COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- DEFPUSHBUTTON "Speichern als", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
- PUSHBUTTON "Abbrechen", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
- PUSHBUTTON "&Hilfe", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
- CHECKBOX "&Schreibgeschützt", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
-}
-
-
 5 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Drucken"
diff --git a/rc/sysres_No.rc b/rc/sysres_No.rc
index 2a86058..ec29dd6 100644
--- a/rc/sysres_No.rc
+++ b/rc/sysres_No.rc
@@ -83,50 +83,6 @@
 }
 
 
-11 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Åpne"
-FONT 8, "Helv"
-{
- LTEXT "&Filnavn:", 1090, 6, 6, 76, 9
- LTEXT "", 1152, 6, 16, 90, 12
- LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "&Kataloger:", -1, 110, 6, 92, 9
- LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
- LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "Liste over filer av &type:", 1089, 6, 104, 90, 9
- COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- LTEXT "&Kataloger:", 1091, 110, 104, 92, 9
- COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- DEFPUSHBUTTON "Åpne", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
- PUSHBUTTON "Avbryt", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
- PUSHBUTTON "&Hjelp", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
- CHECKBOX "&Skrivebeskyttet", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
-}
-
-
-12 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Lagre som ..."
-FONT 8, "Helv"
-{
- LTEXT "&Filnavn:", 1090, 6, 6, 76, 9
- LTEXT "", 1152, 6, 16, 90, 12
- LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "&Kataloger:", -1, 110, 6, 92, 9
- LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
- LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
- LTEXT "Liste over filer av &type:", 1089, 6, 104, 90, 9
- COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- LTEXT "&Kataloger:", 1091, 110, 104, 92, 9
- COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
- DEFPUSHBUTTON "Lagre som", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
- PUSHBUTTON "Avbryt", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
- PUSHBUTTON "&Hjelp", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
- CHECKBOX "&Skrivebeskyttet", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
-}
-
-
 5 DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Skriv"
diff --git a/rc/winerc.c b/rc/winerc.c
index b2c9d31..45fde21 100644
--- a/rc/winerc.c
+++ b/rc/winerc.c
@@ -3,7 +3,6 @@
  * Copyright  Martin von Loewis, 1994
  *
  */
-static char Copyright[] = "Copyright Martin von Loewis, 1994";
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/tools/build.c b/tools/build.c
index 045de3c..eee4aac 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -974,27 +974,32 @@
     printf( "\tpushl %%ebp\n" );
     printf( "\tmovl %%esp,%%ebp\n" );
 
+    /* Retrieve the original 32-bit stack pointer */
+
+    printf( "\tmovl " PREFIX "IF1632_Original32_esp, %%eax\n" );
+    printf( "\torl %%eax,%%eax\n" );
+    printf( "\tje 0f\n" );
+
     /* Save registers */
 
     printf( "\tpushl %%ecx\n" );
     printf( "\tpushl %%esi\n" );
     printf( "\tpushl %%edi\n" );
 
-    /* Switch to the new stack (if any) */
+    /* Switch to the new stack */
 
-    printf( "\tleal 16(%%ebp),%%esi\n" );
-    printf( "\tmovl " PREFIX "IF1632_Original32_esp, %%ecx\n" );
-    printf( "\tjcxz 0f\n" );
-    printf( "\tmovl %%ecx,%%esp\n" );
+    printf( "\tmovl %%eax,%%esp\n" );
 
     /* Transfer the arguments */
 
+    printf( "\tleal 16(%%ebp),%%esi\n" );
     printf( "\tmovl 12(%%ebp),%%ecx\n" );
-    printf( "\tjcxz 1f\n" );
-    printf( "\tshl $2,%%ecx\n" );
+    printf( "\torl %%ecx,%%ecx\n" );
+    printf( "\tje 1f\n" );
+    printf( "\tshll $2,%%ecx\n" );
     printf( "\tsubl %%ecx,%%esp\n" );
     printf( "\tmovl %%esp,%%edi\n" );
-    printf( "\tshr $2,%%ecx\n" );
+    printf( "\tshrl $2,%%ecx\n" );
     printf( "\trep; movsl\n" );
     printf( "1:\n" );
 
@@ -1020,12 +1025,6 @@
 
     printf( "0:\n" );
 
-    /* Restore the registers */
-
-    printf( "\tpopl %%edi\n" );
-    printf( "\tpopl %%esi\n" );
-    printf( "\tpopl %%ecx\n" );
-
     /* Move the return address up the stack */
 
     printf( "\tmovl 4(%%ebp),%%eax\n" );
@@ -1267,6 +1266,11 @@
 
     printf( "\tmovl -8(%%ebp),%%eax\n" );
 
+    /* If necessary, save %edx over the API function address */
+
+    if (!reg_func && short_ret)
+        printf( "\tmovl %%edx,-8(%%ebp)\n" );
+
     /* Setup es */
 
     printf( "\tpushw %%ds\n" );
@@ -1284,7 +1288,7 @@
 
     printf( "\taddl $24,%%ebp\n" );
 
-    /* Call the entry point */
+    /* Print the debug information before the call */
 
     if (debugging)
     {
@@ -1295,22 +1299,21 @@
         printf( "\tpopl %%eax\n" );
     }
 
+    /* Call the entry point */
+
     printf( "\tcall %%eax\n" );
 
+    /* Print the debug information after the call */
+
     if (debugging)
     {
         printf( "\tpushl %%eax\n" );
-        printf( "\tpushl $%d\n", short_ret );
+        printf( "\tpushl $%d\n", reg_func ? 2 : (short_ret ? 1 : 0) );
         printf( "\tcall " PREFIX "RELAY_DebugReturn\n" );
         printf( "\tpopl %%eax\n" );
         printf( "\tpopl %%eax\n" );
     }
 
-    if (reg_func)
-        printf( "\taddl $%d,%%esp\n", sizeof(struct sigcontext_struct) );
-    else if (*args)
-        printf( "\taddl $%d,%%esp\n", 4 * strlen(args) );
-
     /* Restore the 16-bit stack */
 
     printf( "\tmovw " PREFIX "IF1632_Saved16_ss,%%ss\n" );
@@ -1342,21 +1345,40 @@
             args++;
         }
     }
-    else  /* Store the return value in dx:ax if needed */
-    {
-        if (!short_ret)
-        {
-            printf( "\tpushl %%eax\n" );
-            printf( "\tpopw %%dx\n" );
-            printf( "\tpopw %%dx\n" );
-        }
-    }
 
-    /* Restore ds and bp */
+    /* Restore ds */
 
     printf( "\tpopw %%ds\n" );
-    printf( "\tpopl %%ebp\n" );  /* Remove entry point address */
-    printf( "\tpopl %%ebp\n" );  /* Remove DLL id and ordinal */
+
+    /* Get the return value into dx:ax and clean up the stack */
+
+    if (!reg_func)
+    {
+        if (short_ret)
+        {
+            printf( "\tpopl %%edx\n" );     /* Restore %edx */
+            printf( "\taddl $4,%%esp\n" );  /* Remove DLL id and ordinal */
+        }
+        else
+        {
+            printf( "\tpushl %%eax\n" );
+            printf( "\tpopw %%ax\n" );
+            printf( "\tpopw %%dx\n" );
+            /* Remove API entry point, DLL id and ordinal from the stack */
+            printf( "\taddl $8,%%esp\n" );
+        }
+    }
+    else
+    {
+        /* Remove API entry point, DLL id and ordinal from the stack, */
+        /* but take care not to change the value of the carry flag.   */
+
+        printf( "\tpopl %%ebp\n" );
+        printf( "\tpopl %%ebp\n" );
+    }
+
+    /* Restore bp */
+
     printf( "\tpopw %%bp\n" );
 
     /* Remove the arguments and return */
@@ -1451,7 +1473,7 @@
         /* Push the address of the first argument */
         printf( "\tmovl %%ebx,%%eax\n" );
         printf( "\taddl $12,%%eax\n" );
-        printf( "\tpushl $%d\n", reg_func ? 7 : strlen(args) );
+        printf( "\tpushl $%d\n", reg_func ? 8 : strlen(args) );
         printf( "\tpushl %%eax\n" );
         printf( "\tcall " PREFIX "RELAY_DebugCall16\n" );
         printf( "\tpopl %%eax\n" );
@@ -1512,18 +1534,17 @@
     /* Get the 16-bit ds */
     /* FIXME: this shouldn't be necessary if function prologs fixup worked. */
 
-    printf( "\tpushw 16(%%ebx)\n" );
-    printf( "\tpopw %%ds\n" );
-
     if (reg_func)
     {
-        /* Retrieve ebx from the 32-bit stack */
-        printf( "\tmovl %%fs:28(%%ebx),%%ebx\n" );
+        printf( "\tpushw 16(%%ebx)\n" );
+        printf( "\tmovl 32(%%ebx),%%ebx\n" ); /*Get ebx from the 32-bit stack*/
+        printf( "\tpopw %%ds\n" );
     }
     else
     {
         /* Set ax equal to ds for window procedures */
-        printf( "\tmovw %%ds,%%ax\n" );
+        printf( "\tmovw 16(%%ebx),%%ax\n" );
+/*        printf( "\tmovw %%ax,%%ds\n" ); */
     }
 
     /* Jump to the called routine */
diff --git a/windows/class.c b/windows/class.c
index a589ae2..050d4e7 100644
--- a/windows/class.c
+++ b/windows/class.c
@@ -2,9 +2,7 @@
  * Window classes functions
  *
  * Copyright 1993 Alexandre Julliard
- *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
+ */
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -55,12 +53,7 @@
     for (class = firstClass; (class); class = classPtr->hNext)
     {
         classPtr = (CLASS *) USER_HEAP_LIN_ADDR(class);
-#if 0
-      /* This breaks Borland's Resource Workshop: A DLL creates a class,
-       * and the main program tries to use it, but passes a different
-       * hInstance */
-      if (!(classPtr->wc.style & CS_GLOBALCLASS)) continue;
-#endif
+        if (!(classPtr->wc.style & CS_GLOBALCLASS)) continue;
         if (classPtr->atomName == atom)
         {
             if (ptr) *ptr = classPtr;
@@ -98,11 +91,14 @@
     int classExtra;
     char *name = PTR_SEG_TO_LIN( class->lpszClassName );
 
-    dprintf_class(stddeb, "RegisterClass: wndproc=%08lx hinst=%d name='%s' background %04x\n",
+    dprintf_class(stddeb, "RegisterClass: wndproc=%08lx hinst=%04x name='%s' background %04x\n",
 	    (DWORD)class->lpfnWndProc, class->hInstance, name, class->hbrBackground );
     dprintf_class(stddeb, "               style %04x\n",class->style);
+    
+      /* Window classes are owned by modules, not instances */
+    class->hInstance = GetExePtr( class->hInstance );
+    
       /* Check if a class with this name already exists */
-
     prevClass = CLASS_FindClassByName( name, class->hInstance, &prevClassPtr );
     if (prevClass)
     {
@@ -155,15 +151,16 @@
 /***********************************************************************
  *           UnregisterClass    (USER.403)
  */
-BOOL UnregisterClass( LPSTR className, HANDLE instance )
+BOOL UnregisterClass( LPSTR className, HANDLE hinstance )
 {
     HANDLE class, prevClass;
     CLASS * classPtr, * prevClassPtr;
     
+    hinstance = GetExePtr( hinstance );
       /* Check if we can remove this class */
-    class = CLASS_FindClassByName( className, instance, &classPtr );
+    class = CLASS_FindClassByName( className, hinstance, &classPtr );
     if (!class) return FALSE;
-    if ((classPtr->wc.hInstance != instance) || (classPtr->cWindows > 0))
+    if ((classPtr->wc.hInstance != hinstance) || (classPtr->cWindows > 0))
 	return FALSE;
     
       /* Remove the class from the linked list */
@@ -289,7 +286,8 @@
     dprintf_class(stddeb, "GetClassInfo   hInstance=%04x  lpClassName=%s\n",
 		  hInstance, lpClassName);
 
-
+    hInstance = GetExePtr(hInstance);
+    
     /* if (!(CLASS_FindClassByName(lpClassName, &classPtr))) return FALSE; */
     if (!(CLASS_FindClassByName(lpClassName, hInstance, &classPtr)))
     {
diff --git a/windows/cursor.c b/windows/cursor.c
index f9e976e..810dcf2 100644
--- a/windows/cursor.c
+++ b/windows/cursor.c
@@ -230,6 +230,23 @@
 
 
 
+/***********************************************************************
+ *           CreateCursorIconIndirect           (USER.408)
+ *
+ * Returns handle to either an icon or a cursor. Used by CreateCursor
+ * and CreateIcon in  Windoze, but will use same in this version.
+ */
+HANDLE CreateCursorIconIndirect(HANDLE hInstance, LPCURSORICONINFO lpInfo,
+                                LPSTR lpANDBits, /* bitmap data */
+                                LPSTR lpXORBits /* masking data */)
+{
+        return CreateIcon(hInstance,
+                lpInfo->nWidth, lpInfo->nHeight,
+                lpInfo->byPlanes, lpInfo->byBitsPix,
+                lpANDBits, lpXORBits);
+}
+
+
 /**********************************************************************
  *			CreateCursor [USER.406]
  */
diff --git a/windows/defwnd.c b/windows/defwnd.c
index b1c95e6..e5811fb 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -31,6 +31,7 @@
     LPSTR textPtr;
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
+    if (!text) text = "";
     if (wndPtr->hText) USER_HEAP_FREE( wndPtr->hText );
     wndPtr->hText = USER_HEAP_ALLOC( strlen(text) + 1 );
     textPtr = (LPSTR) USER_HEAP_LIN_ADDR( wndPtr->hText );
diff --git a/windows/dialog.c b/windows/dialog.c
index d7c7926..b5b78a4 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -398,7 +398,7 @@
 	SendMessage( hwnd, WM_SETFONT, dlgInfo->hUserFont, 0 );
     if (SendMessage( hwnd, WM_INITDIALOG, dlgInfo->hwndFocus, param ))
 	SetFocus( dlgInfo->hwndFocus );
-    ShowWindow(hwnd, SW_SHOW);
+    if (template.header->style & WS_VISIBLE) ShowWindow(hwnd, SW_SHOW);
     return hwnd;
 }
 
diff --git a/windows/hook.c b/windows/hook.c
index 2110dd9..257b754 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -11,6 +11,8 @@
 
 #include "hook.h"
 #include "user.h"
+#include "stddebug.h"
+#include "debug.h"
 
 HHOOK systemHooks[LAST_HOOK-FIRST_HOOK+1] = { 0, };
 
@@ -97,6 +99,9 @@
     HHOOK *prevHook;
 
     if ((id < FIRST_HOOK) || (id > LAST_HOOK)) return 0;
+    if (id != WH_GETMESSAGE && id != WH_CALLWNDPROC) {
+	fprintf( stdnimp, "Unimplemented hook set: %d!\n", id );
+    }
     if (htask)  /* Task-specific hook */
     {
 	if ((id == WH_JOURNALRECORD) || (id == WH_JOURNALPLAYBACK) ||
diff --git a/windows/mdi.c b/windows/mdi.c
index 53d35f4..85b49b5 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -21,10 +21,10 @@
 /**********************************************************************
  *					MDIRecreateMenuList
  */
-void
-MDIRecreateMenuList(MDICLIENTINFO *ci)
+void MDIRecreateMenuList(MDICLIENTINFO *ci)
 {
-    MDICHILDINFO *chi;
+    HLOCAL hinfo;
+    
     char buffer[128];
     int id, n, index;
 
@@ -46,15 +46,18 @@
     
     id = ci->idFirstChild;
     index = 1;
-    for (chi = ci->infoActiveChildren; chi != NULL; chi = chi->next)
+    for (hinfo = ci->infoActiveChildren; hinfo != 0;)
     {
+	MDICHILDINFO *chi = USER_HEAP_LIN_ADDR(hinfo);
+	
 	n = sprintf(buffer, "%d ", index++);
 	GetWindowText(chi->hwnd, buffer + n, sizeof(buffer) - n - 1);
 
-	dprintf_mdi(stddeb, "MDIRecreateMenuList: id %04x, '%s'\n", 
+	dprintf_mdi(stddeb, "MDIRecreateMenuList: id %04x, '%s'\n",
 		id, buffer);
 
 	AppendMenu(ci->hWindowMenu, MF_STRING, id++, buffer);
+	hinfo = chi->next;
     }
 }
 
@@ -62,8 +65,7 @@
 /**********************************************************************
  *					MDIIconArrange
  */
-WORD
-MDIIconArrange(HWND parent)
+WORD MDIIconArrange(HWND parent)
 {
   return ArrangeIconicWindows(parent);		/* Any reason why the    */
 						/* existing icon arrange */
@@ -74,8 +76,7 @@
 /**********************************************************************
  *					MDICreateChild
  */
-HWND 
-MDICreateChild(WND *w, MDICLIENTINFO *ci, HWND parent, LPARAM lParam )
+HWND MDICreateChild(WND *w, MDICLIENTINFO *ci, HWND parent, LPARAM lParam )
 {
     MDICREATESTRUCT *cs = (MDICREATESTRUCT *)PTR_SEG_TO_LIN(lParam);
     HWND hwnd;
@@ -104,6 +105,7 @@
     {
 	HANDLE h = USER_HEAP_ALLOC( sizeof(MDICHILDINFO) );
 	MDICHILDINFO *child_info = USER_HEAP_LIN_ADDR(h);
+	
 	if (!h)
 	{
 	    DestroyWindow(hwnd);
@@ -111,15 +113,17 @@
 	}
 
 	ci->nActiveChildren++;
-	
+
 	child_info->next = ci->infoActiveChildren;
-	child_info->prev = NULL;
+	child_info->prev = 0;
 	child_info->hwnd = hwnd;
 
-	if (ci->infoActiveChildren)
-	    ci->infoActiveChildren->prev = child_info;
+	if (ci->infoActiveChildren) {
+	    MDICHILDINFO *nextinfo = USER_HEAP_LIN_ADDR(ci->infoActiveChildren);
+	    nextinfo->prev = h;
+	}
 
-	ci->infoActiveChildren = child_info;
+	ci->infoActiveChildren = h;
 
 	SendMessage(parent, WM_CHILDACTIVATE, 0, 0);
     }
@@ -130,23 +134,26 @@
 /**********************************************************************
  *					MDIDestroyChild
  */
-HWND 
-MDIDestroyChild(WND *w_parent, MDICLIENTINFO *ci, HWND parent, HWND child,
-		 BOOL flagDestroy)
+HWND MDIDestroyChild(WND *w_parent, MDICLIENTINFO *ci, HWND parent,
+		     HWND child, BOOL flagDestroy)
 {
     MDICHILDINFO  *chi;
+    HLOCAL hinfo;
     
-    chi = ci->infoActiveChildren;
-    while (chi && chi->hwnd != child)
-	chi = chi->next;
-
-    if (chi)
+    hinfo = ci->infoActiveChildren;
+    while (hinfo != 0) {
+	chi = (MDICHILDINFO *)USER_HEAP_LIN_ADDR(hinfo);
+	if (chi->hwnd == child) break;
+	hinfo = chi->next;
+    }
+    
+    if (hinfo != 0)
     {
 	if (chi->prev)
-	    chi->prev->next = chi->next;
+	    ((MDICHILDINFO *)USER_HEAP_LIN_ADDR(chi->prev))->next = chi->next;
 	if (chi->next)
-	    chi->next->prev = chi->prev;
-	if (ci->infoActiveChildren == chi)
+	    ((MDICHILDINFO *)USER_HEAP_LIN_ADDR(chi->next))->prev = chi->prev;
+	if (ci->infoActiveChildren == hinfo)
 	    ci->infoActiveChildren = chi->next;
 
 	ci->nActiveChildren--;
@@ -154,7 +161,7 @@
 	if (chi->hwnd == ci->hwndActiveChild)
 	    SendMessage(parent, WM_CHILDACTIVATE, 0, 0);
 
-	USER_HEAP_FREE((HANDLE) (LONG) chi);
+	USER_HEAP_FREE(hinfo);
 	
 	if (flagDestroy)
 	    DestroyWindow(child);
@@ -168,6 +175,7 @@
  */
 void MDIBringChildToTop(HWND parent, WORD id, WORD by_id, BOOL send_to_bottom)
 {
+    HLOCAL hinfo;
     MDICHILDINFO  *chi;
     MDICLIENTINFO *ci;
     WND           *w;
@@ -182,24 +190,28 @@
 	id -= ci->idFirstChild;
     if (!by_id || id < ci->nActiveChildren)
     {
-	chi = ci->infoActiveChildren;
+	hinfo = ci->infoActiveChildren;
 
 	if (by_id)
 	{
 	    for (i = 0; i < id; i++)
-		chi = chi->next;
+		hinfo = ((MDICHILDINFO *)USER_HEAP_LIN_ADDR(hinfo))->next;
+	    chi = USER_HEAP_LIN_ADDR(hinfo);
 	}
 	else
 	{
-	    while (chi && chi->hwnd != id)
-		chi = chi->next;
+	    while (hinfo != 0) {
+		chi = (MDICHILDINFO *)USER_HEAP_LIN_ADDR(hinfo);
+		if (chi->hwnd == id) break;
+	        hinfo = chi->next;
+	    }
 	}
 
-	if (!chi)
+	if (hinfo == 0)
 	    return;
 
 	dprintf_mdi(stddeb, "MDIBringToTop: child %04x\n", chi->hwnd);
-	if (chi != ci->infoActiveChildren)
+	if (hinfo != ci->infoActiveChildren)
 	{
 	    if (ci->flagChildMaximized)
 	    {
@@ -220,7 +232,7 @@
 			       (w->rectWindow.right - w->rectClient.right));
 		w->dwStyle |= WS_MAXIMIZE;
 		SetWindowPos(chi->hwnd, HWND_TOP, rect.left, rect.top, 
-			     rect.right - rect.left + 1, 
+			     rect.right - rect.left + 1,
 			     rect.bottom - rect.top + 1, 0);
 		SendMessage(chi->hwnd, WM_SIZE, SIZE_MAXIMIZED,
 			    MAKELONG(w->rectClient.right-w->rectClient.left,
@@ -247,15 +259,15 @@
 	    }
 		
 	    if (chi->next)
-		chi->next->prev    = chi->prev;
+		((MDICHILDINFO *)USER_HEAP_LIN_ADDR(chi->next))->prev = chi->prev;
 
 	    if (chi->prev)
-		chi->prev->next    = chi->next;
+		((MDICHILDINFO *)USER_HEAP_LIN_ADDR(chi->prev))->next = chi->next;
 	    
-	    chi->prev              = NULL;
+	    chi->prev              = 0;
 	    chi->next              = ci->infoActiveChildren;
-	    chi->next->prev        = chi;
-	    ci->infoActiveChildren = chi;
+	    ((MDICHILDINFO *)USER_HEAP_LIN_ADDR(chi->next))->prev = hinfo;
+	    ci->infoActiveChildren = hinfo;
 
 	    SendMessage(parent, WM_CHILDACTIVATE, 0, 0);
 	}
@@ -323,6 +335,7 @@
  */
 LONG MDIChildActivated(WND *w, MDICLIENTINFO *ci, HWND parent)
 {
+    HLOCAL hinfo;
     MDICHILDINFO *chi;
     HWND          deact_hwnd;
     HWND          act_hwnd;
@@ -330,9 +343,10 @@
 
     dprintf_mdi(stddeb, "MDIChildActivate: top %04x\n", w->hwndChild);
 
-    chi = ci->infoActiveChildren;
-    if (chi)
+    hinfo = ci->infoActiveChildren;
+    if (hinfo)
     {
+	chi = (MDICHILDINFO *)USER_HEAP_LIN_ADDR(hinfo);
 	deact_hwnd = ci->hwndActiveChild;
 	act_hwnd   = chi->hwnd;
 	lParam     = ((LONG) deact_hwnd << 16) | act_hwnd;
@@ -353,7 +367,7 @@
 	SendMessage(act_hwnd, WM_MDIACTIVATE, TRUE, lParam);
     }
 
-    if (chi || ci->nActiveChildren == 0)
+    if (hinfo || ci->nActiveChildren == 0)
     {
 	MDIRecreateMenuList(ci);
 	SendMessage(GetParent(parent), WM_NCPAINT, 0, 0);
@@ -367,6 +381,7 @@
  */
 LONG MDICascade(HWND parent, MDICLIENTINFO *ci)
 {
+    HLOCAL hinfo;
     MDICHILDINFO *chi;
     RECT          rect;
     int           spacing, xsize, ysize;
@@ -389,21 +404,29 @@
 	    "MDICascade: Client wnd at (%d,%d) - (%d,%d), spacing %d\n", 
 	    rect.left, rect.top, rect.right, rect.bottom, spacing);
     dprintf_mdi(stddeb, "MDICascade: searching for last child\n");
-    for (chi = ci->infoActiveChildren; chi->next != NULL; chi = chi->next)
-	;
+    hinfo = ci->infoActiveChildren;
+    while(1) {
+	chi = USER_HEAP_LIN_ADDR(hinfo);
+	if (chi->next == 0) break;
+	hinfo = chi->next;
+    }
     
     dprintf_mdi(stddeb, "MDICascade: last child is %04x\n", chi->hwnd);
     x = 0;
     y = 0;
-    for ( ; chi != NULL; chi = chi->prev)
+    while (hinfo != 0)
     {
+	chi = USER_HEAP_LIN_ADDR(hinfo);
 	dprintf_mdi(stddeb, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n", 
 		chi->hwnd, x, y, xsize, ysize);
+        if (IsIconic(chi->hwnd)) continue;
 	SetWindowPos(chi->hwnd, 0, x, y, xsize, ysize, 
 		     SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
 
 	x += spacing;
 	y += spacing;
+	
+	hinfo = chi->prev;
     }
 
     return 0;
@@ -414,6 +437,7 @@
  */
 LONG MDITile(HWND parent, MDICLIENTINFO *ci)
 {
+    HLOCAL hinfo;
     MDICHILDINFO *chi;
     RECT          rect;
     int           xsize, ysize;
@@ -436,7 +460,7 @@
     ysize   = rect.bottom / rows;
     xsize   = rect.right  / columns;
     
-    chi     = ci->infoActiveChildren;
+    hinfo   = ci->infoActiveChildren;
     x       = 0;
     i       = 0;
     for (c = 1; c <= columns; c++)
@@ -448,12 +472,14 @@
 	}
 
 	y = 0;
-	for (r = 1; r <= rows; r++, i++, chi = chi->next)
+	for (r = 1; r <= rows; r++, i++)
 	{
+	    chi = (MDICHILDINFO *)USER_HEAP_LIN_ADDR(hinfo);
 	    SetWindowPos(chi->hwnd, 0, x, y, xsize, ysize, 
 			 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
 
 	    y += ysize;
+	    hinfo = chi->next;
 	}
 
 	x += xsize;
@@ -510,22 +536,20 @@
     
     MDICLIENTINFO *ci;
     WND           *w;
-    HDC            hdc, hdcMem;
-    RECT           rect;
+    HDC           hdc, hdcMem;
+    RECT          rect;
     WND           *wndPtr = WIN_FindWndPtr(hwndFrame);
 
     w  = WIN_FindWndPtr(hwndClient);
     ci = (MDICLIENTINFO *) w->wExtra;
 
-    dprintf_mdi(stddeb, 
-		"MDIPaintMaximized: frame %04x,  client %04x"
-		",  max flag %d,  menu %04x\n", 
-		hwndFrame, hwndClient, 
+    dprintf_mdi(stddeb, "MDIPaintMaximized: frame %04x,  client %04x"
+		",  max flag %d,  menu %04x\n", hwndFrame, hwndClient, 
 		ci->flagChildMaximized, wndPtr ? wndPtr->wIDmenu : 0);
 
     if (ci->flagChildMaximized && wndPtr && wndPtr->wIDmenu != 0)
     {
-	NC_DoNCPaint( hwndFrame, wParam, TRUE);
+	NC_DoNCPaint(hwndFrame, wParam, TRUE);
 
 	hdc = GetDCEx(hwndFrame, 0, DCX_CACHE | DCX_WINDOW);
 	if (!hdc) return 0;
@@ -539,21 +563,19 @@
 	}
 
 	dprintf_mdi(stddeb, 
-		"MDIPaintMaximized: hdcMem %04x, close bitmap %04x, "
-		"maximized bitmap %04x\n",
-		hdcMem, hbitmapClose, hbitmapMaximized);
+		    "MDIPaintMaximized: hdcMem %04x, close bitmap %04x, "
+		    "maximized bitmap %04x\n",
+		    hdcMem, hbitmapClose, hbitmapMaximized);
 
 	NC_GetInsideRect(hwndFrame, &rect);
-	rect.top   += ((wndPtr->dwStyle & WS_CAPTION) ? 
-		       SYSMETRICS_CYSIZE + 1 :  0);
+	rect.top += (wndPtr->dwStyle & WS_CAPTION) ? SYSMETRICS_CYSIZE + 1 : 0;
 	SelectObject(hdcMem, hbitmapClose);
 	BitBlt(hdc, rect.left, rect.top + 1, 
 	       SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
 	       hdcMem, 1, 1, SRCCOPY);
 	
 	NC_GetInsideRect(hwndFrame, &rect);
-	rect.top   += ((wndPtr->dwStyle & WS_CAPTION) ? 
-		       SYSMETRICS_CYSIZE + 1 :  0);
+	rect.top += (wndPtr->dwStyle & WS_CAPTION) ? SYSMETRICS_CYSIZE + 1 : 0;
 	rect.left   = rect.right - SYSMETRICS_CXSIZE;
 	SelectObject(hdcMem, hbitmapMaximized);
 	BitBlt(hdc, rect.left, rect.top + 1, 
@@ -561,9 +583,8 @@
 	       hdcMem, 1, 1, SRCCOPY);
 	
 	NC_GetInsideRect(hwndFrame, &rect);
-	rect.top   += ((wndPtr->dwStyle & WS_CAPTION) ? 
-		       SYSMETRICS_CYSIZE + 1 :  0);
-	rect.left  += SYSMETRICS_CXSIZE;
+	rect.top += (wndPtr->dwStyle & WS_CAPTION) ? SYSMETRICS_CYSIZE + 1 : 0;
+	rect.left += SYSMETRICS_CXSIZE;
 	rect.right -= SYSMETRICS_CXSIZE;
 	rect.bottom = rect.top + SYSMETRICS_CYMENU;
 
@@ -573,7 +594,7 @@
 	ReleaseDC(hwndFrame, hdc);
     }
     else
-	DefWindowProc(hwndFrame, message, wParam, lParam);
+	return DefWindowProc(hwndFrame, message, wParam, lParam);
 
     return 0;
 }
@@ -583,8 +604,7 @@
  *
  * This function is the handler for all MDI requests.
  */
-LONG 
-MDIClientWndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+LONG MDIClientWndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
 {
     LPCREATESTRUCT       cs;
     LPCLIENTCREATESTRUCT ccs;
@@ -604,7 +624,7 @@
 	ccs                     = (LPCLIENTCREATESTRUCT) PTR_SEG_TO_LIN(cs->lpCreateParams);
 	ci->hWindowMenu         = ccs->hWindowMenu;
 	ci->idFirstChild        = ccs->idFirstChild;
-	ci->infoActiveChildren  = NULL;
+	ci->infoActiveChildren  = 0;
 	ci->flagMenuAltered     = FALSE;
 	ci->flagChildMaximized  = FALSE;
 	w->dwStyle             |= WS_CLIPCHILDREN;
@@ -676,9 +696,8 @@
  *					DefFrameProc (USER.445)
  *
  */
-LONG 
-DefFrameProc(HWND hwnd, HWND hwndMDIClient, WORD message, 
-	     WORD wParam, LONG lParam)
+LONG DefFrameProc(HWND hwnd, HWND hwndMDIClient, WORD message, 
+		  WORD wParam, LONG lParam)
 {
     if (hwndMDIClient)
     {
@@ -720,8 +739,7 @@
  *					DefMDIChildProc (USER.447)
  *
  */
-LONG 
-DefMDIChildProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+LONG DefMDIChildProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
 {
     MDICLIENTINFO       *ci;
     WND                 *w;
@@ -763,3 +781,37 @@
 {
     return 0;
 }
+
+
+/***********************************************************************
+ *           CalcChildScroll   (USER.462)
+ */
+void CalcChildScroll( HWND hwnd, WORD scroll )
+{
+    RECT childRect, clientRect;
+    HWND hwndChild;
+
+    GetClientRect( hwnd, &clientRect );
+    SetRectEmpty( &childRect );
+    hwndChild = GetWindow( hwnd, GW_CHILD );
+    while (hwndChild)
+    {
+        WND *wndPtr = WIN_FindWndPtr( hwndChild );
+        UnionRect( &childRect, &wndPtr->rectWindow, &childRect );
+        hwndChild = wndPtr->hwndNext;
+    }
+    UnionRect( &childRect, &clientRect, &childRect );
+
+    if ((scroll == SB_HORZ) || (scroll == SB_BOTH))
+    {
+        SetScrollRange( hwnd, SB_HORZ, childRect.left,
+                        childRect.right - clientRect.right, FALSE );
+        SetScrollPos( hwnd, SB_HORZ, clientRect.left - childRect.left, TRUE );
+    }
+    if ((scroll == SB_VERT) || (scroll == SB_BOTH))
+    {
+        SetScrollRange( hwnd, SB_VERT, childRect.top,
+                        childRect.bottom - clientRect.bottom, FALSE );
+        SetScrollPos( hwnd, SB_HORZ, clientRect.top - childRect.top, TRUE );
+    }
+}
diff --git a/windows/message.c b/windows/message.c
index c219424..8135724 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -1003,7 +1003,7 @@
     if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
     {
 	if (msg->lParam)
-	    return CallWindowProc( (WNDPROC)msg->lParam, msg->hwnd,
+	    return CallWndProc( (WNDPROC)msg->lParam, CURRENT_DS, msg->hwnd,
 				   msg->message, msg->wParam, GetTickCount() );
     }
 
diff --git a/windows/msgbox.c b/windows/msgbox.c
index 8e4aec4..c064f6d 100644
--- a/windows/msgbox.c
+++ b/windows/msgbox.c
@@ -75,6 +75,7 @@
       SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_ASTERISK), 0);
       break;
      case MB_ICONHAND:
+     default:
       SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_HAND), 0);
       break;
     }
diff --git a/windows/utility.c b/windows/utility.c
index 6bc0ef4..61df0cb 100644
--- a/windows/utility.c
+++ b/windows/utility.c
@@ -16,7 +16,6 @@
 #include "ldt.h"
 #include "stackframe.h"
 #include "stddebug.h"
-/* #define DEBUG_UTILITY */
 #include "debug.h"
 
 
@@ -33,7 +32,11 @@
 
 int MulDiv(int foo, int bar, int baz)
 {
-	return (long)(((int)foo*bar)/baz);
+    int ret;
+    if (!baz) return -32768;
+    ret = (foo * bar) / baz;
+    if ((ret > 32767) || (ret < -32767)) return -32768;
+    return ret;
 };
 
 /*	UTILITY_strip015() removes \015 (^M, CR) from a string;
@@ -210,62 +213,84 @@
 
 char *UTILITY_convertArgs(char *format, char *winarg)
 {
-	char *result = (char *)malloc(UTILITY_argsize(format, 0));
-	char *rptr = result;
-
-	while(*format) {
-		while((*format) && (*format != '%')) format++;	/* skip ahead */
-		if(*format) {
-			char modifier = ' ';
-			dprintf_utility(stddeb, "found:\t\"%%");
-			format++;		/* skip past '%' */
-			/* First skip the flags, field width, etc. */
-			/* First the flags */
-			if ((*format == '#') || (*format == '-') || (*format == '+')
-				|| (*format == ' ')) format++;
-			/* Now the field width, etc. */
-			while(isdigit(*format)) format++;
-			if(*format == '.') format++;
-			while(isdigit(*format)) format++;
-			/* Now we handle the rest */
-			if((*format == 'h') || (*format == 'l') || (*format == 'L'))
-				modifier = *(format++);
-			/* Handle the actual type. */
-			dprintf_utility(stddeb, "%c\"\n", *format);
-			switch(*format) {
-				case 'd':
-				case 'i':
-					*(((int *)rptr)++) = (modifier=='l') ? *(((int *)winarg)++) : *(((short *)winarg)++);
-					break;
-				case 'o':
-				case 'x':
-				case 'X':
-				case 'u':
-				case 'c':
-					*(((unsigned int *)rptr)++) = (modifier=='l') ? *(((unsigned int *)winarg)++) 
-						: *(((unsigned short *)winarg)++);
-					break;
-				case 's':
-				case 'p':
-				case 'n':	/* A pointer, is a pointer, is a pointer... */
-					*(((char **)rptr)++) = (char *)PTR_SEG_TO_LIN(*(((char **)winarg)++));
-					break;
-				case 'e':
-				case 'E':
-				case 'f':
-				case 'g':
-				case 'G':
-					/* It doesn't look as if Windows' wvsprintf()
-					   supports floating-point arguments. However,
-					   I'll leave this code here just in case. */
-					if(modifier=='L')
-						*(((long double *)rptr)++) = *(((long double *)winarg)++);
-					else *(((double *)rptr)++) = *(((double *)winarg)++);
-					break;
-			}
+    char *result = (char *)malloc(UTILITY_argsize(format, 0));
+    char *rptr = result;
+    short *wptr = (short *)winarg;
+    long *dptr = (long *)result;
+    
+    while(*format) {
+	while((*format) && (*format != '%')) format++;	/* skip ahead */
+	if(*format) {
+	    char modifier = ' ';
+	    dprintf_utility(stddeb, "found:\t\"%%");
+	    format++;		/* skip past '%' */
+	    
+	    /* First skip the flags, field width, etc. */
+	    /* First the flags */
+	    if (*format == '#' || *format == '-' || *format == '+'
+		|| *format == ' ') format++;
+	    
+	    /* Now the field width, etc. */
+	    while (isdigit(*format)) format++;
+	    if (*format == '.') format++;
+	    while (isdigit(*format)) format++;
+	    
+	    /* Now we handle the rest */
+	    if(*format == 'h' || *format == 'l' || *format == 'L')
+	        modifier = *format++;
+	    
+	    /* Handle the actual type. */
+	    dprintf_utility(stddeb, "%c\"\n", *format);
+	    
+	    switch(*format) {
+	     case 'd':
+	     case 'i':
+		if (modifier == 'l') {
+		    *((int *)rptr)++ = *((int *)winarg)++;
+		} else {
+		    *((int *)rptr)++ = *((short *)winarg)++;
 		}
+		break;
+	     case 'o':
+	     case 'x':
+	     case 'X':
+	     case 'u':
+	     case 'c':
+		if (modifier == 'l')  {
+		    *((unsigned int *)rptr)++ =  *((unsigned int *)winarg)++;
+		} else {
+		    *((unsigned int *)rptr)++ = *((unsigned short *)winarg)++;
+		}
+		break;
+	     case 's':
+	     case 'p':
+	     case 'n':	/* A pointer, is a pointer, is a pointer... */
+		*((char **)rptr)++ = (char *)PTR_SEG_TO_LIN(*(SEGPTR *)winarg);
+		((SEGPTR *)winarg)++;
+		break;
+	     case 'e':
+	     case 'E':
+	     case 'f':
+	     case 'g':
+	     case 'G':
+		/* It doesn't look as if Windows' wvsprintf()
+		 supports floating-point arguments. However,
+		 I'll leave this code here just in case. */
+		if(modifier=='L')
+		    *((long double *)rptr)++ = *((long double *)winarg)++;
+		else
+		    *((double *)rptr)++ = *((double *)winarg)++;
+		break;
+	    }
 	}
-	return result;
+    }
+    for(; (char *)dptr < rptr; dptr ++)
+        dprintf_utility( stddeb, "%08lx ", *dptr );
+    dprintf_utility( stddeb, "\n" );
+    for(; (char *)wptr < winarg; wptr ++)
+        dprintf_utility( stddeb, "%04x ", *wptr );
+    dprintf_utility( stddeb, "\n" );
+    return result;
 };
 
 #ifndef WINELIB
diff --git a/windows/win.c b/windows/win.c
index be12941..6add88a 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -138,6 +138,8 @@
     for ( ; hwnd != 0; hwnd = wndPtr->hwndNext )
     {
 	if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
+	dprintf_win( stddeb, "WIN_FindWinToRepaint: %04x, style %08lx\n",
+		     hwnd, wndPtr->dwStyle );
         if (!(wndPtr->dwStyle & WS_VISIBLE) || (wndPtr->flags & WIN_NO_REDRAW))
             continue;
         if ((wndPtr->dwStyle & WS_MINIMIZE) && (WIN_CLASS_INFO(wndPtr).hIcon))
@@ -295,44 +297,50 @@
     int wmcreate;
     XSetWindowAttributes win_attr;
 
-    dprintf_win(stddeb, "CreateWindowEx: %08lX '%s' '%s' %08lX %d,%d %dx%d %04X %04X %04X %08lx\n",
-				exStyle, className, windowName, style, x, y, width, height, 
-				parent, menu, instance, data);
-	/* 'soundrec.exe' has negative position ! 
-	Why ? For now, here a patch : */
-        if (!strcmp(className, "SoundRec"))
-	{
-	    if (x < 0) x = 0;
-	    if (y < 0) y = 0;
-	}
+    if (windowName != NULL && HIWORD(windowName) == 0) {
+	dprintf_win(stddeb,"CreateWindowEx: %04x ", LOWORD(windowName));
+    } else {
+	dprintf_win(stddeb,"CreateWindowEx: '%s' ", windowName);
+    }
+    dprintf_win(stddeb, "%08lX '%s' %08lX %d,%d %dx%d %04X %04X %04X %08lx\n",
+		exStyle, className, style, x, y, width, height,
+		parent, menu, instance, data);
+    /* 'soundrec.exe' has negative position ! 
+       Why ? For now, here a patch : */
+    if (!strcmp(className, "SoundRec"))
+    {
+	if (x < 0) x = 0;
+	if (y < 0) y = 0;
+    }
     if (x == CW_USEDEFAULT) x = y = 0;
     if (width == CW_USEDEFAULT)
     {
 	width = 600;
 	height = 400;
     }
-    if (width == 0) width = 1;
-    if (height == 0) height = 1;
 
       /* Find the parent and class */
 
     if (parent)
     {
-	  /* Make sure parent is valid */
+	/* Make sure parent is valid */
         if (!IsWindow( parent )) {
-			dprintf_win(stddeb,"CreateWindowEx: Parent %x is not a windows\n", parent);
-			return 0;
-		}
-    }
-    else if (style & WS_CHILD) {
-		dprintf_win(stddeb,"CreateWindowEx: no parent\n");
-		return 0;  /* WS_CHILD needs a parent */
+	    dprintf_win(stddeb,"CreateWindowEx: Parent %x is not a windows\n", parent);
+	    return 0;
 	}
+    }
+    else 
+    {
+	if (style & WS_CHILD) {
+	    dprintf_win(stddeb,"CreateWindowEx: no parent\n");
+	    return 0;  /* WS_CHILD needs a parent */
+	}
+    }
 
-    if (!(class = CLASS_FindClassByName( className, instance, &classPtr ))) {
+    if (!(class = CLASS_FindClassByName( className, GetExePtr( instance ), &classPtr ))) {
 	fprintf(stderr,"CreateWindow BAD CLASSNAME '%s' !\n", className);
 	return 0;
-	}    
+    }
 
       /* Correct the window style */
 
@@ -344,45 +352,39 @@
 
     hwnd = USER_HEAP_ALLOC( sizeof(WND)+classPtr->wc.cbWndExtra );
     if (!hwnd) {
-		dprintf_win(stddeb,"CreateWindowEx: Out of memory\n");
-		return 0;
-	}
+	dprintf_win(stddeb,"CreateWindowEx: Out of memory\n");
+	return 0;
+    }
 
       /* Fill the structure */
 
     wndPtr = (WND *) USER_HEAP_LIN_ADDR( hwnd );
-    wndPtr->hwndNext   = 0;
-    wndPtr->hwndChild  = 0;
-    wndPtr->window     = 0;
-    wndPtr->dwMagic    = WND_MAGIC;
-    wndPtr->hwndParent = (style & WS_CHILD) ? parent : hwndDesktop;
-    wndPtr->hwndOwner  = (style & WS_CHILD) ? 0 : parent;
-    wndPtr->hClass     = class;
-    wndPtr->hInstance  = instance;
-    wndPtr->rectWindow.left   = x;
-    wndPtr->rectWindow.top    = y;
-    wndPtr->rectWindow.right  = x + width;
-    wndPtr->rectWindow.bottom = y + height;
-    wndPtr->rectClient        = wndPtr->rectWindow;
-    wndPtr->rectNormal        = wndPtr->rectWindow;
-    wndPtr->ptIconPos.x       = -1;
-    wndPtr->ptIconPos.y       = -1;
-    wndPtr->ptMaxPos.x        = -1;
-    wndPtr->ptMaxPos.y        = -1;
-    wndPtr->hmemTaskQ         = GetTaskQueue(0);
-    wndPtr->hrgnUpdate        = 0;
-    wndPtr->hwndPrevActive    = 0;
-    wndPtr->hwndLastActive    = hwnd;
-    wndPtr->lpfnWndProc       = classPtr->wc.lpfnWndProc;
-    wndPtr->dwStyle           = style;
-    wndPtr->dwExStyle         = exStyle;
-    wndPtr->wIDmenu           = 0;
-    wndPtr->hText             = 0;
-    wndPtr->flags             = 0;
-    wndPtr->hVScroll          = 0;
-    wndPtr->hHScroll          = 0;
-    wndPtr->hSysMenu          = 0;
-    wndPtr->hProp             = 0;
+    wndPtr->hwndNext       = 0;
+    wndPtr->hwndChild      = 0;
+    wndPtr->window         = 0;
+    wndPtr->dwMagic        = WND_MAGIC;
+    wndPtr->hwndParent     = (style & WS_CHILD) ? parent : hwndDesktop;
+    wndPtr->hwndOwner      = (style & WS_CHILD) ? 0 : parent;
+    wndPtr->hClass         = class;
+    wndPtr->hInstance      = instance;
+    wndPtr->ptIconPos.x    = -1;
+    wndPtr->ptIconPos.y    = -1;
+    wndPtr->ptMaxPos.x     = -1;
+    wndPtr->ptMaxPos.y     = -1;
+    wndPtr->hmemTaskQ      = GetTaskQueue(0);
+    wndPtr->hrgnUpdate     = 0;
+    wndPtr->hwndPrevActive = 0;
+    wndPtr->hwndLastActive = hwnd;
+    wndPtr->lpfnWndProc    = classPtr->wc.lpfnWndProc;
+    wndPtr->dwStyle        = style;
+    wndPtr->dwExStyle      = exStyle;
+    wndPtr->wIDmenu        = 0;
+    wndPtr->hText          = 0;
+    wndPtr->flags          = 0;
+    wndPtr->hVScroll       = 0;
+    wndPtr->hHScroll       = 0;
+    wndPtr->hSysMenu       = 0;
+    wndPtr->hProp          = 0;
 
     if (classPtr->wc.cbWndExtra)
 	memset( wndPtr->wExtra, 0, classPtr->wc.cbWndExtra );
@@ -410,16 +412,17 @@
 
     NC_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack );
 
-    if ( maxSize.x < width)
-      {
-	width = maxSize.x;
-	wndPtr->rectWindow.right = x + width;
-      }
-    if ( maxSize.y < height)
-      {
-	height = maxSize.y;
-	wndPtr->rectWindow.bottom = y + height;
-      }
+    if (maxSize.x < width) width = maxSize.x;
+    if (maxSize.y < height) height = maxSize.y;
+    if (width <= 0) width = 1;
+    if (height <= 0) height = 1;
+
+    wndPtr->rectWindow.left   = x;
+    wndPtr->rectWindow.top    = y;
+    wndPtr->rectWindow.right  = x + width;
+    wndPtr->rectWindow.bottom = y + height;
+    wndPtr->rectClient        = wndPtr->rectWindow;
+    wndPtr->rectNormal        = wndPtr->rectWindow;
 
       /* Create the X window (only for top-level windows, and then only */
       /* when there's no desktop window) */
@@ -475,9 +478,15 @@
     createStruct.dwExStyle      = 0;
     if (windowName)
     {
-        hwinName = USER_HEAP_ALLOC( strlen(windowName)+1 );
-        strcpy( USER_HEAP_LIN_ADDR(hwinName), windowName );
-        createStruct.lpszName = (LPSTR)USER_HEAP_SEG_ADDR(hwinName);
+	if (HIWORD(windowName) == 0) {
+	    /* Hack for SS_ICON controls */
+	    createStruct.lpszName = windowName;
+	    hwinName = 0;
+	} else  {
+	    hwinName = USER_HEAP_ALLOC( strlen(windowName)+1 );
+	    strcpy( USER_HEAP_LIN_ADDR(hwinName), windowName );
+	    createStruct.lpszName = (LPSTR)USER_HEAP_SEG_ADDR(hwinName);
+	}
     }
     else
     {
@@ -487,9 +496,9 @@
 
     wmcreate = SendMessage( hwnd, WM_NCCREATE, 0, MAKE_SEGPTR(&createStruct) );
     if (!wmcreate) {
-		dprintf_win(stddeb,"CreateWindowEx: WM_NCCREATE return 0\n");
-		wmcreate = -1;
-	}
+	dprintf_win(stddeb,"CreateWindowEx: WM_NCCREATE return 0\n");
+	wmcreate = -1;
+    }
     else
     {
 	WINPOS_SendNCCalcSize( hwnd, FALSE, &wndPtr->rectWindow,
@@ -503,7 +512,7 @@
     if (wmcreate == -1)
     {
 	  /* Abort window creation */
-	  dprintf_win(stddeb,"CreateWindowEx: wmcreate==-1, aborting\n");
+	dprintf_win(stddeb,"CreateWindowEx: wmcreate==-1, aborting\n");
         WIN_DestroyWindow( hwnd );
 	return 0;
     }
@@ -851,11 +860,15 @@
 
     temp = wndPtr->hwndParent;
 
+    WIN_UnlinkWindow(hwndChild);
     if (hwndNewParent)
       wndPtr->hwndParent = hwndNewParent;
     else
       wndPtr->hwndParent = GetDesktopWindow();
-
+    WIN_LinkWindow(hwndChild, HWND_BOTTOM);
+    
+    if (IsWindowVisible(hwndChild)) UpdateWindow(hwndChild);
+    
     return temp;
 }