Release 950109

Thu Jan  5 13:37:42 1995  Cameron Heide  (heide@ee.ualberta.ca)

	* [memory/global.c]
	GlobalCompact should now return the correct value when the
	largest run of free blocks includes the last block.

	* [windows/mdi.c]
	Tiling and cascading windows without any MDI children should
	no longer crash (assuming no-op is the correct thing to do).

Sun Jan  1 23:30:25 1995  Fons Botman  <botman@rabo.nl>

	* [objects/font.c]
	GetTextExtentPoint: fixed debug output, str is counted string, not
        zero terminated.

	* [if1632/relay.c]
	DLLRelay: when debugging_stack got segv, added upper bound for
        stack dump.
diff --git a/ANNOUNCE b/ANNOUNCE
index 7212bee..b2255e5 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,12 +1,13 @@
-This is release 941227 of Wine the MS Windows emulator.  This is still a
+This is release 950109 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 try to make a new release every Sunday.
 
-WHAT'S NEW with Wine-941227: (see ChangeLog for details)
-	- Better BitBlt()
+WHAT'S NEW with Wine-950109: (see ChangeLog for details)
+	- Compiling with -Wall. Don't panic if you get many warnings...
+	- Better StretchBlt()
 	- Lots of bug fixes
 
 See the README file in the distribution for installation instructions.
@@ -15,11 +16,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-941227.tar.gz
-	aris.com:/pub/linux/ALPHA/Wine/development/Wine-941227.tar.gz
-	tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-941227.tar.gz
-	ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-941227.tar.gz
-	ftp.wonderland.org:/Wine/Wine-941227.tar.gz
+	sunsite.unc.edu:/pub/Linux/ALPHA/wine/Wine-950109.tar.gz
+	aris.com:/pub/linux/ALPHA/Wine/development/Wine-950109.tar.gz
+	tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-950109.tar.gz
+	ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-950109.tar.gz
+	ftp.wonderland.org:/Wine/Wine-950109.tar.gz
 
 If you submitted a patch, please check to make sure it has been
 included in the new release.
diff --git a/ChangeLog b/ChangeLog
index a2a0da4..2ebc86d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Thu Jan  5 13:37:42 1995  Cameron Heide  (heide@ee.ualberta.ca)
+
+	* [memory/global.c]
+	GlobalCompact should now return the correct value when the
+	largest run of free blocks includes the last block.
+
+	* [windows/mdi.c]
+	Tiling and cascading windows without any MDI children should
+	no longer crash (assuming no-op is the correct thing to do).
+
+Sun Jan  1 23:30:25 1995  Fons Botman  <botman@rabo.nl>
+
+	* objects/font.c (GetTextExtentPoint): 
+	Fixed debug output, str is counted string, not zero terminated.
+
+	* if1632/relay.c (DLLRelay): 
+	When debugging_stack got segv, added upper bound for stack dump.
+
+----------------------------------------------------------------------
 Tue Dec 27 13:35:16 1994  Alexandre Julliard  (julliard@lamisun.epfl.ch)
 
 	* [*/Imakefile]
diff --git a/Imakefile b/Imakefile
index ea60138..f5e2fad 100644
--- a/Imakefile
+++ b/Imakefile
@@ -7,6 +7,7 @@
 #endif
 
 DEFINES = AutoDefines -DUSE_READLINE -DWINESTAT
+CDEBUGFLAGS = -O2 -Wall
 
 /*
  * This is the second try at using Imakefiles. There are probably many
diff --git a/controls/button.c b/controls/button.c
index 54c5df0..32b8fed 100644
--- a/controls/button.c
+++ b/controls/button.c
@@ -367,7 +367,7 @@
         ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
     else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
     GRAPH_DrawBitmap( hDC, hbitmapCheckBoxes, rc.left, rc.top + delta,
-                      x, y, checkBoxWidth, checkBoxHeight, SRCCOPY );
+                      x, y, checkBoxWidth, checkBoxHeight );
     rc.left += checkBoxWidth + tm.tmAveCharWidth / 2;
 
     if (action == ODA_DRAWENTIRE)
diff --git a/controls/combo.c b/controls/combo.c
index b5c9186..34cece2 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -16,7 +16,6 @@
 #include "user.h"
 #include "heap.h"
 #include "win.h"
-#include "prototypes.h"
 #include "stddebug.h"
 /* #define DEBUG_COMBO */
 #include "debug.h"
@@ -271,8 +270,7 @@
 			GetObject(hComboBit, sizeof(BITMAP), (LPSTR)&bm);
                         GRAPH_DrawBitmap( hDC, hComboBit,
                                           rect.right - bm.bmWidth, 0,
-                                          0, 0, bm.bmWidth, bm.bmHeight,
-                                          SRCCOPY );
+                                          0, 0, bm.bmWidth, bm.bmHeight );
 			}
 		EndPaint(hwnd, &paintstruct);
 		lphc = ComboGetStorageHeader(hwnd);
diff --git a/controls/desktop.c b/controls/desktop.c
index e075bee..7a7d545 100644
--- a/controls/desktop.c
+++ b/controls/desktop.c
@@ -95,7 +95,7 @@
 		    GRAPH_DrawBitmap( hdc, infoPtr->hbitmapWallPaper,
 				      x, y, 0, 0, 
 				      infoPtr->bitmapSize.cx,
-				      infoPtr->bitmapSize.cy, SRCCOPY );
+				      infoPtr->bitmapSize.cy );
 	}
 	else
 	{
@@ -104,8 +104,7 @@
 	    if (x < 0) x = 0;
 	    if (y < 0) y = 0;
 	    GRAPH_DrawBitmap( hdc, infoPtr->hbitmapWallPaper, x, y, 0, 0, 
-			      infoPtr->bitmapSize.cx, infoPtr->bitmapSize.cy,
-			      SRCCOPY );
+                              infoPtr->bitmapSize.cx, infoPtr->bitmapSize.cy );
 	}
     }
 
diff --git a/controls/listbox.c b/controls/listbox.c
index 86c3940..96a194f 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -1091,7 +1091,7 @@
 int ListBoxDirectory(HWND hwnd, UINT attrib, LPSTR filespec)
 {
 	struct dosdirent *dp;
-	int	x, wRet;
+	int	x, wRet = LB_OKAY;
 	BOOL    OldFlag;
 	char 	temp[256];
     LPHEADLIST 	lphl;
diff --git a/controls/menu.c b/controls/menu.c
index 3ac8946..0647eaf 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -1,9 +1,9 @@
 /*
- *        Menus functions
-static char RCSId[] = "$Id$";
-static char Copyright[] = "Copyright  Martin Ayotte, 1993";
-static char Copyright2[] = "Copyright  Alexandre Julliard, 1994";
-*/
+ * Menu functions
+ *
+ * Copyright 1993 Martin Ayotte
+ * Copyright 1994 Alexandre Julliard
+ */
 
 /*
  * Note: the style MF_MOUSESELECT is used to mark popup items that
@@ -18,7 +18,6 @@
 #include "windows.h"
 #include "syscolor.h"
 #include "sysmetrics.h"
-#include "prototypes.h"
 #include "menu.h"
 #include "user.h"
 #include "win.h"
@@ -482,15 +481,13 @@
 	    GRAPH_DrawBitmap(hdc, lpitem->hCheckBit ? lpitem->hCheckBit :
 			     hStdCheck, rect.left,
 			     (rect.top+rect.bottom-check_bitmap_height) / 2,
-			     0, 0, check_bitmap_width, check_bitmap_height,
-			     SRCCOPY);
+			     0, 0, check_bitmap_width, check_bitmap_height );
 	}
 	else if (lpitem->hUnCheckBit != 0)  /* Not checked */
 	{
 	    GRAPH_DrawBitmap(hdc, lpitem->hUnCheckBit, rect.left,
 			     (rect.top+rect.bottom-check_bitmap_height) / 2,
-			     0, 0, check_bitmap_width, check_bitmap_height,
-			     SRCCOPY);
+			     0, 0, check_bitmap_width, check_bitmap_height );
 	}
 
 	  /* Draw the popup-menu arrow */
@@ -500,8 +497,7 @@
 	    GRAPH_DrawBitmap( hdc, hStdMnArrow,
 			      rect.right-arrow_bitmap_width-1,
 			      (rect.top+rect.bottom-arrow_bitmap_height) / 2,
-			      0, 0, arrow_bitmap_width, arrow_bitmap_height,
-			      SRCCOPY );
+                              0, 0, arrow_bitmap_width, arrow_bitmap_height );
 	}
 
 	rect.left += check_bitmap_width;
@@ -513,8 +509,7 @@
     if (lpitem->item_flags & MF_BITMAP)
     {
 	GRAPH_DrawBitmap( hdc, (HBITMAP)lpitem->hText, rect.left, rect.top,
-			  0, 0, rect.right-rect.left, rect.bottom-rect.top,
-			  SRCCOPY );
+                          0, 0, rect.right-rect.left, rect.bottom-rect.top );
 	return;
     }
     /* No bitmap - process text if present */
@@ -1018,7 +1013,7 @@
 {
     POPUPMENU *menu;
     MENUITEM *item;
-    HMENU hsubmenu;
+    HMENU hsubmenu = 0;
     WORD id;
 
     if (!hmenu) return FALSE;  /* Outside all menus */
diff --git a/controls/scroll.c b/controls/scroll.c
index e28347a..03de3c8 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -163,6 +163,9 @@
 	GetClientRect( hwnd, lprect );
         vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
 	break;
+
+    default:
+        return FALSE;
     }
 
     if (vertical) pixels = lprect->bottom - lprect->top;
@@ -267,6 +270,7 @@
     HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
                                     TOP_ARROW(infoPtr->flags, top_pressed)
                                     : LEFT_ARROW(infoPtr->flags, top_pressed));
+    SetStretchBltMode( hdc, STRETCH_DELETESCANS );
     StretchBlt( hdc, rect->left, rect->top,
                 vertical ? rect->right-rect->left : arrowSize+1,
                 vertical ? arrowSize+1 : rect->bottom-rect->top,
@@ -385,7 +389,7 @@
     if (!thumbPos)  /* No thumb to draw */
     {
         PatBlt( hdc, r.left+1, r.top+1, r.right - r.left - 2,
-                r.bottom - r.top - 2, SRCCOPY );
+                r.bottom - r.top - 2, PATCOPY );
         return;
     }
 
@@ -394,12 +398,12 @@
         PatBlt( hdc, r.left + 1, r.top + 1,
                 r.right - r.left - 2,
                 thumbPos - arrowSize,
-                top_selected ? NOTSRCCOPY : SRCCOPY );
+                top_selected ? 0x0f0000 : PATCOPY );
         r.top += thumbPos - arrowSize;
         PatBlt( hdc, r.left + 1, r.top + SYSMETRICS_CYHSCROLL + 1,
                 r.right - r.left - 2,
                 r.bottom - r.top - SYSMETRICS_CYHSCROLL - 2,
-                bottom_selected ? NOTSRCCOPY : SRCCOPY );
+                bottom_selected ? 0x0f0000 : PATCOPY );
         r.bottom = r.top + SYSMETRICS_CYHSCROLL + 1;
     }
     else  /* horizontal */
@@ -407,12 +411,12 @@
         PatBlt( hdc, r.left + 1, r.top + 1,
                 thumbPos - arrowSize,
                 r.bottom - r.top - 2,
-                top_selected ? NOTSRCCOPY : SRCCOPY );
+                top_selected ? 0x0f0000 : PATCOPY );
         r.left += thumbPos - arrowSize;
         PatBlt( hdc, r.left + SYSMETRICS_CYHSCROLL + 1, r.top + 1,
                 r.right - r.left - SYSMETRICS_CYHSCROLL - 2,
                 r.bottom - r.top - 2,
-                bottom_selected ? NOTSRCCOPY : SRCCOPY );
+                bottom_selected ? 0x0f0000 : PATCOPY );
         r.right = r.left + SYSMETRICS_CXVSCROLL + 1;
     }
 
diff --git a/controls/static.c b/controls/static.c
index 9089095..85345d8 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -211,6 +211,9 @@
     case SS_LEFTNOWORDWRAP:
 	wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER;
 	break;
+
+    default:
+        return;
     }
 
     if (style & SS_NOPREFIX)
@@ -247,6 +250,9 @@
     case SS_WHITERECT:
 	hBrush = CreateSolidBrush(color_window);
 	break;
+
+    default:
+        return;
     }
     FillRect( hdc, &rc, hBrush );
 }
@@ -274,6 +280,9 @@
     case SS_WHITEFRAME:
 	hPen = CreatePen(PS_SOLID, 1, color_window);
 	break;
+
+    default:
+        return;
     }
 
     hBrush = CreateSolidBrush(color_window);
diff --git a/debugger/hash.c b/debugger/hash.c
index 600cf34..cba6ce2 100644
--- a/debugger/hash.c
+++ b/debugger/hash.c
@@ -11,7 +11,6 @@
 #include <sys/types.h>
 #include <neexe.h>
 #include <segmem.h>
-#include <prototypes.h>
 #include "selectors.h"
 #include <wine.h>
 #include <dlls.h>
diff --git a/debugger/readline/editline.c b/debugger/readline/editline.c
index 31a846e..cd20bbb 100644
--- a/debugger/readline/editline.c
+++ b/debugger/readline/editline.c
@@ -555,7 +555,7 @@
     if ((c = *pat) == '\0')
         return *text == '\0';
     for ( ; *text; text++)
-        if (*text == c && strncmp(text, pat, len) == 0)
+        if ((CHAR)*text == c && strncmp(text, pat, len) == 0)
             return 0;
     return 1;
 }
diff --git a/if1632/callback.c b/if1632/callback.c
index aef1d53..a38d13b 100644
--- a/if1632/callback.c
+++ b/if1632/callback.c
@@ -195,7 +195,7 @@
     }
     else if (IS_16_BIT_ADDRESS(func))
     {	
-	dprintf_callback(stddeb, "CallWindowProc // 16bit func=%p !\n", 
+	dprintf_callback(stddeb, "CallWindowProc // 16bit func=%08x !\n", 
 		(unsigned int) func);
 	PushOn16( CALLBACK_SIZE_WORD, hwnd );
 	PushOn16( CALLBACK_SIZE_WORD, message );
diff --git a/if1632/relay.c b/if1632/relay.c
index 5a5b6cb..e286bb8 100644
--- a/if1632/relay.c
+++ b/if1632/relay.c
@@ -23,8 +23,8 @@
 #include "dlls.h"
 #include "options.h"
 #include "stddebug.h"
-/* #define DEBUG_RELAY /* */
-/* #define DEBUG_STACK /* */
+/* #define DEBUG_RELAY */
+/* #define DEBUG_STACK */
 #include "debug.h"
 
 #if 0
@@ -129,7 +129,9 @@
 	if(debugging_stack)
         {
             unsigned short *stack_p = (unsigned short *) seg_off;
-            for (i = 0; i < 24; i++, stack_p++)
+	    /* FIXME: Is there an end-of-stack-pointer somewhere ? */
+	    int n = min(24, (0x10000 - (seg_off & 0xffff)) / sizeof(*stack_p));
+            for (i = 0; i < n; i++, stack_p++)
             {
                 printf("%04x ", *stack_p);
                 if ((i & 7) == 7)
diff --git a/include/bitmap.h b/include/bitmap.h
index 7d730b7..9bac249 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -4,19 +4,19 @@
  * Copyright 1993, 1994  Alexandre Julliard
  */
 
-#ifndef BITMAP_H
-#define BITMAP_H
+#ifndef __WINE_BITMAP_H
+#define __WINE_BITMAP_H
 
-#include <stdlib.h>
-#include <X11/Xlib.h>
-#include "windows.h"
+#include "gdi.h"
 
-  /* objects/bitmap.c */
-extern BOOL BITMAP_Init(void);
-
-  /* objects/dib.c */
-extern int DIB_GetImageWidthBytes( int width, int depth );
-extern int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse );
+  /* GDI logical bitmap object */
+typedef struct
+{
+    GDIOBJHDR   header;
+    BITMAP      bitmap;
+    Pixmap      pixmap;
+    SIZE        size;   /* For SetBitmapDimension() */
+} BITMAPOBJ;
 
   /* GCs used for B&W and color bitmap operations */
 extern GC BITMAP_monoGC, BITMAP_colorGC;
@@ -32,4 +32,15 @@
                            (width), (height), 32, width_bytes ); \
 }
 
-#endif  /* BITMAP_H */
+  /* objects/bitmap.c */
+extern BOOL BITMAP_Init(void);
+extern int BITMAP_GetObject( BITMAPOBJ * bmp, int count, LPSTR buffer );
+extern BOOL BITMAP_DeleteObject( HBITMAP hbitmap, BITMAPOBJ * bitmap );
+extern HBITMAP BITMAP_SelectObject( HDC hdc, DC * dc, HBITMAP hbitmap,
+                                    BITMAPOBJ * bmp );
+
+  /* objects/dib.c */
+extern int DIB_GetImageWidthBytes( int width, int depth );
+extern int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse );
+
+#endif  /* __WINE_BITMAP_H */
diff --git a/include/brush.h b/include/brush.h
new file mode 100644
index 0000000..3f41e59
--- /dev/null
+++ b/include/brush.h
@@ -0,0 +1,29 @@
+/*
+ * GDI brush definitions
+ *
+ * Copyright 1994 Alexandre Julliard
+ */
+
+#ifndef __WINE_BRUSH_H
+#define __WINE_BRUSH_H
+
+#include "gdi.h"
+
+#pragma pack(1)
+
+  /* GDI logical brush object */
+typedef struct
+{
+    GDIOBJHDR   header;
+    LOGBRUSH    logbrush WINE_PACKED;
+} BRUSHOBJ;
+
+#pragma pack(4)
+
+extern BOOL BRUSH_Init(void);
+extern int BRUSH_GetObject( BRUSHOBJ * brush, int count, LPSTR buffer );
+extern BOOL BRUSH_DeleteObject( HBRUSH hbrush, BRUSHOBJ * brush );
+extern HBRUSH BRUSH_SelectObject( HDC hdc, DC * dc, HBRUSH hbrush,
+                                  BRUSHOBJ * brush );
+
+#endif  /* __WINE_BRUSH_H */
diff --git a/include/dc.h b/include/dc.h
index 5723fa8..7e3874a 100644
--- a/include/dc.h
+++ b/include/dc.h
@@ -1,12 +1,20 @@
+/*
+ * GDI Device Context function prototypes
+ *
+ * Copyright 1994 Alexandre Julliard
+ *
+ */
+
 #ifndef __WINE_DC_H
 #define __WINE_DC_H
 
 #include "gdi.h"
 
 extern void DC_InitDC( HDC hdc );
-extern int DC_SetupGCForBrush( DC * dc );
-extern int DC_SetupGCForPen( DC * dc );
-extern int DC_SetupGCForText( DC * dc );
+extern BOOL DC_SetupGCForPatBlt( DC * dc, GC gc, BOOL fMapColors );
+extern BOOL DC_SetupGCForBrush( DC * dc );
+extern BOOL DC_SetupGCForPen( DC * dc );
+extern BOOL DC_SetupGCForText( DC * dc );
 
 extern const int DC_XROPfunction[];
 
diff --git a/include/debug.h b/include/debug.h
index 61713ce..03bf4a2 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -7,6 +7,7 @@
 
 #ifdef DEBUG_NONE_EXT
 #undef DEBUG_ACCEL
+#undef DEBUG_BITBLT
 #undef DEBUG_BITMAP
 #undef DEBUG_CALLBACK
 #undef DEBUG_CARET
@@ -76,6 +77,7 @@
 
 #ifdef DEBUG_ALL_EXT
 #define DEBUG_ACCEL
+#define DEBUG_BITBLT
 #define DEBUG_BITMAP
 #define DEBUG_CALLBACK
 #define DEBUG_CARET
@@ -151,6 +153,11 @@
 #else
     0,
 #endif
+#ifdef DEBUG_BITBLT
+    1,
+#else
+    0,
+#endif
 #ifdef DEBUG_BITMAP
     1,
 #else
@@ -497,8 +504,21 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_bitmap if(debug_msg_enabled[1]) fprintf
-#define debugging_bitmap debug_msg_enabled[1]
+#define dprintf_bitblt if(debug_msg_enabled[1]) fprintf
+#define debugging_bitblt debug_msg_enabled[1]
+#else
+#ifdef DEBUG_BITBLT
+#define dprintf_bitblt fprintf
+#define debugging_bitblt 1
+#else
+#define dprintf_bitblt
+#define debugging_bitblt 0
+#endif
+#endif
+
+#ifdef DEBUG_RUNTIME
+#define dprintf_bitmap if(debug_msg_enabled[2]) fprintf
+#define debugging_bitmap debug_msg_enabled[2]
 #else
 #ifdef DEBUG_BITMAP
 #define dprintf_bitmap fprintf
@@ -510,8 +530,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_callback if(debug_msg_enabled[2]) fprintf
-#define debugging_callback debug_msg_enabled[2]
+#define dprintf_callback if(debug_msg_enabled[3]) fprintf
+#define debugging_callback debug_msg_enabled[3]
 #else
 #ifdef DEBUG_CALLBACK
 #define dprintf_callback fprintf
@@ -523,8 +543,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_caret if(debug_msg_enabled[3]) fprintf
-#define debugging_caret debug_msg_enabled[3]
+#define dprintf_caret if(debug_msg_enabled[4]) fprintf
+#define debugging_caret debug_msg_enabled[4]
 #else
 #ifdef DEBUG_CARET
 #define dprintf_caret fprintf
@@ -536,8 +556,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_catch if(debug_msg_enabled[4]) fprintf
-#define debugging_catch debug_msg_enabled[4]
+#define dprintf_catch if(debug_msg_enabled[5]) fprintf
+#define debugging_catch debug_msg_enabled[5]
 #else
 #ifdef DEBUG_CATCH
 #define dprintf_catch fprintf
@@ -549,8 +569,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_cdaudio if(debug_msg_enabled[5]) fprintf
-#define debugging_cdaudio debug_msg_enabled[5]
+#define dprintf_cdaudio if(debug_msg_enabled[6]) fprintf
+#define debugging_cdaudio debug_msg_enabled[6]
 #else
 #ifdef DEBUG_CDAUDIO
 #define dprintf_cdaudio fprintf
@@ -562,8 +582,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_class if(debug_msg_enabled[6]) fprintf
-#define debugging_class debug_msg_enabled[6]
+#define dprintf_class if(debug_msg_enabled[7]) fprintf
+#define debugging_class debug_msg_enabled[7]
 #else
 #ifdef DEBUG_CLASS
 #define dprintf_class fprintf
@@ -575,8 +595,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_clipboard if(debug_msg_enabled[7]) fprintf
-#define debugging_clipboard debug_msg_enabled[7]
+#define dprintf_clipboard if(debug_msg_enabled[8]) fprintf
+#define debugging_clipboard debug_msg_enabled[8]
 #else
 #ifdef DEBUG_CLIPBOARD
 #define dprintf_clipboard fprintf
@@ -588,8 +608,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_clipping if(debug_msg_enabled[8]) fprintf
-#define debugging_clipping debug_msg_enabled[8]
+#define dprintf_clipping if(debug_msg_enabled[9]) fprintf
+#define debugging_clipping debug_msg_enabled[9]
 #else
 #ifdef DEBUG_CLIPPING
 #define dprintf_clipping fprintf
@@ -601,8 +621,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_combo if(debug_msg_enabled[9]) fprintf
-#define debugging_combo debug_msg_enabled[9]
+#define dprintf_combo if(debug_msg_enabled[10]) fprintf
+#define debugging_combo debug_msg_enabled[10]
 #else
 #ifdef DEBUG_COMBO
 #define dprintf_combo fprintf
@@ -614,8 +634,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_comm if(debug_msg_enabled[10]) fprintf
-#define debugging_comm debug_msg_enabled[10]
+#define dprintf_comm if(debug_msg_enabled[11]) fprintf
+#define debugging_comm debug_msg_enabled[11]
 #else
 #ifdef DEBUG_COMM
 #define dprintf_comm fprintf
@@ -627,8 +647,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_cursor if(debug_msg_enabled[11]) fprintf
-#define debugging_cursor debug_msg_enabled[11]
+#define dprintf_cursor if(debug_msg_enabled[12]) fprintf
+#define debugging_cursor debug_msg_enabled[12]
 #else
 #ifdef DEBUG_CURSOR
 #define dprintf_cursor fprintf
@@ -640,8 +660,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dc if(debug_msg_enabled[12]) fprintf
-#define debugging_dc debug_msg_enabled[12]
+#define dprintf_dc if(debug_msg_enabled[13]) fprintf
+#define debugging_dc debug_msg_enabled[13]
 #else
 #ifdef DEBUG_DC
 #define dprintf_dc fprintf
@@ -653,8 +673,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dialog if(debug_msg_enabled[13]) fprintf
-#define debugging_dialog debug_msg_enabled[13]
+#define dprintf_dialog if(debug_msg_enabled[14]) fprintf
+#define debugging_dialog debug_msg_enabled[14]
 #else
 #ifdef DEBUG_DIALOG
 #define dprintf_dialog fprintf
@@ -666,8 +686,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dll if(debug_msg_enabled[14]) fprintf
-#define debugging_dll debug_msg_enabled[14]
+#define dprintf_dll if(debug_msg_enabled[15]) fprintf
+#define debugging_dll debug_msg_enabled[15]
 #else
 #ifdef DEBUG_DLL
 #define dprintf_dll fprintf
@@ -679,8 +699,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dosfs if(debug_msg_enabled[15]) fprintf
-#define debugging_dosfs debug_msg_enabled[15]
+#define dprintf_dosfs if(debug_msg_enabled[16]) fprintf
+#define debugging_dosfs debug_msg_enabled[16]
 #else
 #ifdef DEBUG_DOSFS
 #define dprintf_dosfs fprintf
@@ -692,8 +712,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_driver if(debug_msg_enabled[16]) fprintf
-#define debugging_driver debug_msg_enabled[16]
+#define dprintf_driver if(debug_msg_enabled[17]) fprintf
+#define debugging_driver debug_msg_enabled[17]
 #else
 #ifdef DEBUG_DRIVER
 #define dprintf_driver fprintf
@@ -705,8 +725,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_edit if(debug_msg_enabled[17]) fprintf
-#define debugging_edit debug_msg_enabled[17]
+#define dprintf_edit if(debug_msg_enabled[18]) fprintf
+#define debugging_edit debug_msg_enabled[18]
 #else
 #ifdef DEBUG_EDIT
 #define dprintf_edit fprintf
@@ -718,8 +738,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_enum if(debug_msg_enabled[18]) fprintf
-#define debugging_enum debug_msg_enabled[18]
+#define dprintf_enum if(debug_msg_enabled[19]) fprintf
+#define debugging_enum debug_msg_enabled[19]
 #else
 #ifdef DEBUG_ENUM
 #define dprintf_enum fprintf
@@ -731,8 +751,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_event if(debug_msg_enabled[19]) fprintf
-#define debugging_event debug_msg_enabled[19]
+#define dprintf_event if(debug_msg_enabled[20]) fprintf
+#define debugging_event debug_msg_enabled[20]
 #else
 #ifdef DEBUG_EVENT
 #define dprintf_event fprintf
@@ -744,8 +764,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_exec if(debug_msg_enabled[20]) fprintf
-#define debugging_exec debug_msg_enabled[20]
+#define dprintf_exec if(debug_msg_enabled[21]) fprintf
+#define debugging_exec debug_msg_enabled[21]
 #else
 #ifdef DEBUG_EXEC
 #define dprintf_exec fprintf
@@ -757,8 +777,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_file if(debug_msg_enabled[21]) fprintf
-#define debugging_file debug_msg_enabled[21]
+#define dprintf_file if(debug_msg_enabled[22]) fprintf
+#define debugging_file debug_msg_enabled[22]
 #else
 #ifdef DEBUG_FILE
 #define dprintf_file fprintf
@@ -770,8 +790,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_fixup if(debug_msg_enabled[22]) fprintf
-#define debugging_fixup debug_msg_enabled[22]
+#define dprintf_fixup if(debug_msg_enabled[23]) fprintf
+#define debugging_fixup debug_msg_enabled[23]
 #else
 #ifdef DEBUG_FIXUP
 #define dprintf_fixup fprintf
@@ -783,8 +803,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_font if(debug_msg_enabled[23]) fprintf
-#define debugging_font debug_msg_enabled[23]
+#define dprintf_font if(debug_msg_enabled[24]) fprintf
+#define debugging_font debug_msg_enabled[24]
 #else
 #ifdef DEBUG_FONT
 #define dprintf_font fprintf
@@ -796,8 +816,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_gdi if(debug_msg_enabled[24]) fprintf
-#define debugging_gdi debug_msg_enabled[24]
+#define dprintf_gdi if(debug_msg_enabled[25]) fprintf
+#define debugging_gdi debug_msg_enabled[25]
 #else
 #ifdef DEBUG_GDI
 #define dprintf_gdi fprintf
@@ -809,8 +829,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_graphics if(debug_msg_enabled[25]) fprintf
-#define debugging_graphics debug_msg_enabled[25]
+#define dprintf_graphics if(debug_msg_enabled[26]) fprintf
+#define debugging_graphics debug_msg_enabled[26]
 #else
 #ifdef DEBUG_GRAPHICS
 #define dprintf_graphics fprintf
@@ -822,8 +842,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_heap if(debug_msg_enabled[26]) fprintf
-#define debugging_heap debug_msg_enabled[26]
+#define dprintf_heap if(debug_msg_enabled[27]) fprintf
+#define debugging_heap debug_msg_enabled[27]
 #else
 #ifdef DEBUG_HEAP
 #define dprintf_heap fprintf
@@ -835,8 +855,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_icon if(debug_msg_enabled[27]) fprintf
-#define debugging_icon debug_msg_enabled[27]
+#define dprintf_icon if(debug_msg_enabled[28]) fprintf
+#define debugging_icon debug_msg_enabled[28]
 #else
 #ifdef DEBUG_ICON
 #define dprintf_icon fprintf
@@ -848,8 +868,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_int if(debug_msg_enabled[28]) fprintf
-#define debugging_int debug_msg_enabled[28]
+#define dprintf_int if(debug_msg_enabled[29]) fprintf
+#define debugging_int debug_msg_enabled[29]
 #else
 #ifdef DEBUG_INT
 #define dprintf_int fprintf
@@ -861,8 +881,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_key if(debug_msg_enabled[29]) fprintf
-#define debugging_key debug_msg_enabled[29]
+#define dprintf_key if(debug_msg_enabled[30]) fprintf
+#define debugging_key debug_msg_enabled[30]
 #else
 #ifdef DEBUG_KEY
 #define dprintf_key fprintf
@@ -874,8 +894,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_keyboard if(debug_msg_enabled[30]) fprintf
-#define debugging_keyboard debug_msg_enabled[30]
+#define dprintf_keyboard if(debug_msg_enabled[31]) fprintf
+#define debugging_keyboard debug_msg_enabled[31]
 #else
 #ifdef DEBUG_KEYBOARD
 #define dprintf_keyboard fprintf
@@ -887,8 +907,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ldt if(debug_msg_enabled[31]) fprintf
-#define debugging_ldt debug_msg_enabled[31]
+#define dprintf_ldt if(debug_msg_enabled[32]) fprintf
+#define debugging_ldt debug_msg_enabled[32]
 #else
 #ifdef DEBUG_LDT
 #define dprintf_ldt fprintf
@@ -900,8 +920,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_listbox if(debug_msg_enabled[32]) fprintf
-#define debugging_listbox debug_msg_enabled[32]
+#define dprintf_listbox if(debug_msg_enabled[33]) fprintf
+#define debugging_listbox debug_msg_enabled[33]
 #else
 #ifdef DEBUG_LISTBOX
 #define dprintf_listbox fprintf
@@ -913,8 +933,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mci if(debug_msg_enabled[33]) fprintf
-#define debugging_mci debug_msg_enabled[33]
+#define dprintf_mci if(debug_msg_enabled[34]) fprintf
+#define debugging_mci debug_msg_enabled[34]
 #else
 #ifdef DEBUG_MCI
 #define dprintf_mci fprintf
@@ -926,8 +946,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mcianim if(debug_msg_enabled[34]) fprintf
-#define debugging_mcianim debug_msg_enabled[34]
+#define dprintf_mcianim if(debug_msg_enabled[35]) fprintf
+#define debugging_mcianim debug_msg_enabled[35]
 #else
 #ifdef DEBUG_MCIANIM
 #define dprintf_mcianim fprintf
@@ -939,8 +959,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mciwave if(debug_msg_enabled[35]) fprintf
-#define debugging_mciwave debug_msg_enabled[35]
+#define dprintf_mciwave if(debug_msg_enabled[36]) fprintf
+#define debugging_mciwave debug_msg_enabled[36]
 #else
 #ifdef DEBUG_MCIWAVE
 #define dprintf_mciwave fprintf
@@ -952,8 +972,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mdi if(debug_msg_enabled[36]) fprintf
-#define debugging_mdi debug_msg_enabled[36]
+#define dprintf_mdi if(debug_msg_enabled[37]) fprintf
+#define debugging_mdi debug_msg_enabled[37]
 #else
 #ifdef DEBUG_MDI
 #define dprintf_mdi fprintf
@@ -965,8 +985,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_menu if(debug_msg_enabled[37]) fprintf
-#define debugging_menu debug_msg_enabled[37]
+#define dprintf_menu if(debug_msg_enabled[38]) fprintf
+#define debugging_menu debug_msg_enabled[38]
 #else
 #ifdef DEBUG_MENU
 #define dprintf_menu fprintf
@@ -978,8 +998,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_menucalc if(debug_msg_enabled[38]) fprintf
-#define debugging_menucalc debug_msg_enabled[38]
+#define dprintf_menucalc if(debug_msg_enabled[39]) fprintf
+#define debugging_menucalc debug_msg_enabled[39]
 #else
 #ifdef DEBUG_MENUCALC
 #define dprintf_menucalc fprintf
@@ -991,8 +1011,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_message if(debug_msg_enabled[39]) fprintf
-#define debugging_message debug_msg_enabled[39]
+#define dprintf_message if(debug_msg_enabled[40]) fprintf
+#define debugging_message debug_msg_enabled[40]
 #else
 #ifdef DEBUG_MESSAGE
 #define dprintf_message fprintf
@@ -1004,8 +1024,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_metafile if(debug_msg_enabled[40]) fprintf
-#define debugging_metafile debug_msg_enabled[40]
+#define dprintf_metafile if(debug_msg_enabled[41]) fprintf
+#define debugging_metafile debug_msg_enabled[41]
 #else
 #ifdef DEBUG_METAFILE
 #define dprintf_metafile fprintf
@@ -1017,8 +1037,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_midi if(debug_msg_enabled[41]) fprintf
-#define debugging_midi debug_msg_enabled[41]
+#define dprintf_midi if(debug_msg_enabled[42]) fprintf
+#define debugging_midi debug_msg_enabled[42]
 #else
 #ifdef DEBUG_MIDI
 #define dprintf_midi fprintf
@@ -1030,8 +1050,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmio if(debug_msg_enabled[42]) fprintf
-#define debugging_mmio debug_msg_enabled[42]
+#define dprintf_mmio if(debug_msg_enabled[43]) fprintf
+#define debugging_mmio debug_msg_enabled[43]
 #else
 #ifdef DEBUG_MMIO
 #define dprintf_mmio fprintf
@@ -1043,8 +1063,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmtime if(debug_msg_enabled[43]) fprintf
-#define debugging_mmtime debug_msg_enabled[43]
+#define dprintf_mmtime if(debug_msg_enabled[44]) fprintf
+#define debugging_mmtime debug_msg_enabled[44]
 #else
 #ifdef DEBUG_MMTIME
 #define dprintf_mmtime fprintf
@@ -1056,8 +1076,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_module if(debug_msg_enabled[44]) fprintf
-#define debugging_module debug_msg_enabled[44]
+#define dprintf_module if(debug_msg_enabled[45]) fprintf
+#define debugging_module debug_msg_enabled[45]
 #else
 #ifdef DEBUG_MODULE
 #define dprintf_module fprintf
@@ -1069,8 +1089,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_msg if(debug_msg_enabled[45]) fprintf
-#define debugging_msg debug_msg_enabled[45]
+#define dprintf_msg if(debug_msg_enabled[46]) fprintf
+#define debugging_msg debug_msg_enabled[46]
 #else
 #ifdef DEBUG_MSG
 #define dprintf_msg fprintf
@@ -1082,8 +1102,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_msgbox if(debug_msg_enabled[46]) fprintf
-#define debugging_msgbox debug_msg_enabled[46]
+#define dprintf_msgbox if(debug_msg_enabled[47]) fprintf
+#define debugging_msgbox debug_msg_enabled[47]
 #else
 #ifdef DEBUG_MSGBOX
 #define dprintf_msgbox fprintf
@@ -1095,8 +1115,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_nonclient if(debug_msg_enabled[47]) fprintf
-#define debugging_nonclient debug_msg_enabled[47]
+#define dprintf_nonclient if(debug_msg_enabled[48]) fprintf
+#define debugging_nonclient debug_msg_enabled[48]
 #else
 #ifdef DEBUG_NONCLIENT
 #define dprintf_nonclient fprintf
@@ -1108,8 +1128,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_palette if(debug_msg_enabled[48]) fprintf
-#define debugging_palette debug_msg_enabled[48]
+#define dprintf_palette if(debug_msg_enabled[49]) fprintf
+#define debugging_palette debug_msg_enabled[49]
 #else
 #ifdef DEBUG_PALETTE
 #define dprintf_palette fprintf
@@ -1121,8 +1141,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_profile if(debug_msg_enabled[49]) fprintf
-#define debugging_profile debug_msg_enabled[49]
+#define dprintf_profile if(debug_msg_enabled[50]) fprintf
+#define debugging_profile debug_msg_enabled[50]
 #else
 #ifdef DEBUG_PROFILE
 #define dprintf_profile fprintf
@@ -1134,8 +1154,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_prop if(debug_msg_enabled[50]) fprintf
-#define debugging_prop debug_msg_enabled[50]
+#define dprintf_prop if(debug_msg_enabled[51]) fprintf
+#define debugging_prop debug_msg_enabled[51]
 #else
 #ifdef DEBUG_PROP
 #define dprintf_prop fprintf
@@ -1147,8 +1167,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_reg if(debug_msg_enabled[51]) fprintf
-#define debugging_reg debug_msg_enabled[51]
+#define dprintf_reg if(debug_msg_enabled[52]) fprintf
+#define debugging_reg debug_msg_enabled[52]
 #else
 #ifdef DEBUG_REG
 #define dprintf_reg fprintf
@@ -1160,8 +1180,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_region if(debug_msg_enabled[52]) fprintf
-#define debugging_region debug_msg_enabled[52]
+#define dprintf_region if(debug_msg_enabled[53]) fprintf
+#define debugging_region debug_msg_enabled[53]
 #else
 #ifdef DEBUG_REGION
 #define dprintf_region fprintf
@@ -1173,8 +1193,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_relay if(debug_msg_enabled[53]) fprintf
-#define debugging_relay debug_msg_enabled[53]
+#define dprintf_relay if(debug_msg_enabled[54]) fprintf
+#define debugging_relay debug_msg_enabled[54]
 #else
 #ifdef DEBUG_RELAY
 #define dprintf_relay fprintf
@@ -1186,8 +1206,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_resource if(debug_msg_enabled[54]) fprintf
-#define debugging_resource debug_msg_enabled[54]
+#define dprintf_resource if(debug_msg_enabled[55]) fprintf
+#define debugging_resource debug_msg_enabled[55]
 #else
 #ifdef DEBUG_RESOURCE
 #define dprintf_resource fprintf
@@ -1199,8 +1219,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_scroll if(debug_msg_enabled[55]) fprintf
-#define debugging_scroll debug_msg_enabled[55]
+#define dprintf_scroll if(debug_msg_enabled[56]) fprintf
+#define debugging_scroll debug_msg_enabled[56]
 #else
 #ifdef DEBUG_SCROLL
 #define dprintf_scroll fprintf
@@ -1212,8 +1232,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_selectors if(debug_msg_enabled[56]) fprintf
-#define debugging_selectors debug_msg_enabled[56]
+#define dprintf_selectors if(debug_msg_enabled[57]) fprintf
+#define debugging_selectors debug_msg_enabled[57]
 #else
 #ifdef DEBUG_SELECTORS
 #define dprintf_selectors fprintf
@@ -1225,8 +1245,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_stack if(debug_msg_enabled[57]) fprintf
-#define debugging_stack debug_msg_enabled[57]
+#define dprintf_stack if(debug_msg_enabled[58]) fprintf
+#define debugging_stack debug_msg_enabled[58]
 #else
 #ifdef DEBUG_STACK
 #define dprintf_stack fprintf
@@ -1238,8 +1258,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_stress if(debug_msg_enabled[58]) fprintf
-#define debugging_stress debug_msg_enabled[58]
+#define dprintf_stress if(debug_msg_enabled[59]) fprintf
+#define debugging_stress debug_msg_enabled[59]
 #else
 #ifdef DEBUG_STRESS
 #define dprintf_stress fprintf
@@ -1251,8 +1271,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_syscolor if(debug_msg_enabled[59]) fprintf
-#define debugging_syscolor debug_msg_enabled[59]
+#define dprintf_syscolor if(debug_msg_enabled[60]) fprintf
+#define debugging_syscolor debug_msg_enabled[60]
 #else
 #ifdef DEBUG_SYSCOLOR
 #define dprintf_syscolor fprintf
@@ -1264,8 +1284,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_task if(debug_msg_enabled[60]) fprintf
-#define debugging_task debug_msg_enabled[60]
+#define dprintf_task if(debug_msg_enabled[61]) fprintf
+#define debugging_task debug_msg_enabled[61]
 #else
 #ifdef DEBUG_TASK
 #define dprintf_task fprintf
@@ -1277,8 +1297,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_text if(debug_msg_enabled[61]) fprintf
-#define debugging_text debug_msg_enabled[61]
+#define dprintf_text if(debug_msg_enabled[62]) fprintf
+#define debugging_text debug_msg_enabled[62]
 #else
 #ifdef DEBUG_TEXT
 #define dprintf_text fprintf
@@ -1290,8 +1310,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_timer if(debug_msg_enabled[62]) fprintf
-#define debugging_timer debug_msg_enabled[62]
+#define dprintf_timer if(debug_msg_enabled[63]) fprintf
+#define debugging_timer debug_msg_enabled[63]
 #else
 #ifdef DEBUG_TIMER
 #define dprintf_timer fprintf
@@ -1303,8 +1323,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_utility if(debug_msg_enabled[63]) fprintf
-#define debugging_utility debug_msg_enabled[63]
+#define dprintf_utility if(debug_msg_enabled[64]) fprintf
+#define debugging_utility debug_msg_enabled[64]
 #else
 #ifdef DEBUG_UTILITY
 #define dprintf_utility fprintf
@@ -1316,8 +1336,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win if(debug_msg_enabled[64]) fprintf
-#define debugging_win debug_msg_enabled[64]
+#define dprintf_win if(debug_msg_enabled[65]) fprintf
+#define debugging_win debug_msg_enabled[65]
 #else
 #ifdef DEBUG_WIN
 #define dprintf_win fprintf
@@ -1329,8 +1349,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_winsock if(debug_msg_enabled[65]) fprintf
-#define debugging_winsock debug_msg_enabled[65]
+#define dprintf_winsock if(debug_msg_enabled[66]) fprintf
+#define debugging_winsock debug_msg_enabled[66]
 #else
 #ifdef DEBUG_WINSOCK
 #define dprintf_winsock fprintf
@@ -1346,6 +1366,7 @@
 #ifdef DEBUG_DEFINE_VARIABLES
 static char *debug_msg_name[] = {
     "accel",
+    "bitblt",
     "bitmap",
     "callback",
     "caret",
diff --git a/include/font.h b/include/font.h
index 40c24d6..b26a260 100644
--- a/include/font.h
+++ b/include/font.h
@@ -1,7 +1,26 @@
+/*
+ * GDI font definitions
+ *
+ * Copyright 1994 Alexandre Julliard
+ */
+
 #ifndef __WINE_FONT_H
 #define __WINE_FONT_H
 
-extern void Font_Init( void );
+#include "gdi.h"
+
+#pragma pack(1)
+
+  /* GDI logical font object */
+typedef struct
+{
+    GDIOBJHDR   header;
+    LOGFONT     logfont WINE_PACKED;
+} FONTOBJ;
+
+#pragma pack(4)
+
+extern BOOL FONT_Init( void );
 extern int FONT_GetObject( FONTOBJ * font, int count, LPSTR buffer );
 extern HFONT FONT_SelectObject( DC * dc, HFONT hfont, FONTOBJ * font );
 
diff --git a/include/gdi.h b/include/gdi.h
index b176d42..07bde36 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -29,14 +29,6 @@
 
 #pragma pack(1)
 
-typedef struct tagREGION
-{
-    WORD        type;
-    RECT        box;
-    Pixmap      pixmap;
-    Region      xrgn;
-} REGION;
-
 typedef struct tagGDIOBJHDR
 {
     HANDLE      hNext;
@@ -45,45 +37,6 @@
     WORD        wMetaList;
 } GDIOBJHDR;
 
-typedef struct tagBRUSHOBJ
-{
-    GDIOBJHDR   header;
-    LOGBRUSH    logbrush WINE_PACKED;
-} BRUSHOBJ;
-
-typedef struct tagPENOBJ
-{
-    GDIOBJHDR   header;
-    LOGPEN      logpen WINE_PACKED;
-} PENOBJ;
-
-typedef struct tagPALETTEOBJ
-{
-    GDIOBJHDR   header;
-    LOGPALETTE  logpalette WINE_PACKED;
-} PALETTEOBJ;
-
-typedef struct tagFONTOBJ
-{
-    GDIOBJHDR   header;
-    LOGFONT     logfont WINE_PACKED;
-} FONTOBJ;
-
-typedef struct tagBITMAPOBJ
-{
-    GDIOBJHDR   header;
-    BITMAP      bitmap;
-    Pixmap      pixmap;
-    SIZE        size;   /* For SetBitmapDimension() */
-} BITMAPOBJ;
-
-typedef struct tagRGNOBJ
-{
-    GDIOBJHDR   header;
-    REGION      region;
-} RGNOBJ;
-
-#pragma pack(4)
 
 typedef struct
 {
@@ -119,6 +72,8 @@
     WORD   colorRes;      /* 108: color resolution */    
 } DeviceCaps;
 
+#pragma pack(4)
+
 
   /* Device independent DC information */
 typedef struct
@@ -134,6 +89,7 @@
     HBRUSH        hBrush;
     HFONT         hFont;
     HBITMAP       hBitmap;
+    HBITMAP       hFirstBitmap; /* Bitmap selected at creation of the DC */
     HANDLE        hDevice;
     HPALETTE      hPalette;
 
diff --git a/include/graphics.h b/include/graphics.h
index a9580f5..2fba422 100644
--- a/include/graphics.h
+++ b/include/graphics.h
@@ -1,9 +1,16 @@
+/*
+ * Internal graphics functions prototypes
+ *
+ * Copyright 1994 Alexandre Julliard
+ *
+ */
+
 #ifndef __WINE_GRAPHICS_H
 #define __WINE_GRAPHICS_H
 
 extern void GRAPH_DrawReliefRect( HDC hdc, RECT *rect, int highlight_size,
                                   int shadow_size, BOOL pressed );
 extern BOOL GRAPH_DrawBitmap( HDC hdc, HBITMAP hbitmap, int xdest, int ydest,
-                          int xsrc, int ysrc, int width, int height, int rop );
+                              int xsrc, int ysrc, int width, int height );
 
-#endif /* __WINE_GRAPHICS */
+#endif /* __WINE_GRAPHICS_H */
diff --git a/include/message.h b/include/message.h
index 66d7926..b634227 100644
--- a/include/message.h
+++ b/include/message.h
@@ -49,6 +49,7 @@
 extern void MSG_IncTimerCount( HANDLE hQueue );
 extern void MSG_DecTimerCount( HANDLE hQueue );
 extern void MSG_Synchronize();
+extern BOOL MSG_WaitXEvent( LONG maxWait );
 extern BOOL MSG_CreateSysMsgQueue( int size );
 extern void hardware_event( WORD message, WORD wParam, LONG lParam,
 			    int xPos, int yPos, DWORD time, DWORD extraInfo );
diff --git a/include/miscemu.h b/include/miscemu.h
index a24bfae..1cc6fcc 100644
--- a/include/miscemu.h
+++ b/include/miscemu.h
@@ -17,6 +17,10 @@
 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 IntBarf(int i, struct sigcontext_struct *context);
 
diff --git a/include/palette.h b/include/palette.h
new file mode 100644
index 0000000..ddb76e0
--- /dev/null
+++ b/include/palette.h
@@ -0,0 +1,25 @@
+/*
+ * GDI palette definitions
+ *
+ * Copyright 1994 Alexandre Julliard
+ */
+
+#ifndef __WINE_PALETTE_H
+#define __WINE_PALETTE_H
+
+#include "gdi.h"
+
+#pragma pack(1)
+
+  /* GDI logical palette object */
+typedef struct
+{
+    GDIOBJHDR   header;
+    LOGPALETTE  logpalette WINE_PACKED;
+} PALETTEOBJ;
+
+#pragma pack(4)
+
+extern int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer );
+     
+#endif /* __WINE_FONT_H */
diff --git a/include/pen.h b/include/pen.h
new file mode 100644
index 0000000..2e2b512
--- /dev/null
+++ b/include/pen.h
@@ -0,0 +1,26 @@
+/*
+ * GDI pen definitions
+ *
+ * Copyright 1994 Alexandre Julliard
+ */
+
+#ifndef __WINE_PEN_H
+#define __WINE_PEN_H
+
+#include "gdi.h"
+
+#pragma pack(1)
+
+  /* GDI logical pen object */
+typedef struct
+{
+    GDIOBJHDR   header;
+    LOGPEN      logpen WINE_PACKED;
+} PENOBJ;
+
+#pragma pack(4)
+
+extern int PEN_GetObject( PENOBJ * pen, int count, LPSTR buffer );
+extern HPEN PEN_SelectObject( DC * dc, HPEN hpen, PENOBJ * pen );
+
+#endif  /* __WINE_PEN_H */
diff --git a/include/prototypes.h b/include/prototypes.h
index 5ba1e4f..d50a2db 100644
--- a/include/prototypes.h
+++ b/include/prototypes.h
@@ -32,7 +32,7 @@
 
 /* loader/signal.c */
 
-extern int init_wine_signals(void);
+extern void init_wine_signals(void);
 extern void wine_debug(int signal, int * regs);
 
 /* loader/wine.c */
@@ -57,18 +57,6 @@
 
 extern BOOL WIDGETS_Init(void);
 
-/* objects/palette.c */
-
-extern BOOL PALETTE_Init(void);
-
-/* objects/region.c */
-
-extern BOOL REGION_Init(void);
-
-/* windows/graphic.c */
-
-extern void DrawReliefRect(HDC hdc, RECT rect, int thickness, BOOL pressed);
-
 /* windows/dce.c */
 
 extern void DCE_Init(void);
diff --git a/include/region.h b/include/region.h
new file mode 100644
index 0000000..a6fef59
--- /dev/null
+++ b/include/region.h
@@ -0,0 +1,31 @@
+/*
+ * GDI region definitions
+ *
+ * Copyright 1994 Alexandre Julliard
+ */
+
+#ifndef __WINE_REGION_H
+#define __WINE_REGION_H
+
+#include "gdi.h"
+
+typedef struct
+{
+    WORD        type;
+    RECT        box;
+    Pixmap      pixmap;
+    Region      xrgn;
+} REGION;
+
+  /* GDI logical region object */
+typedef struct
+{
+    GDIOBJHDR   header;
+    REGION      region;
+} RGNOBJ;
+
+
+extern BOOL REGION_Init(void);
+extern BOOL REGION_DeleteObject( HRGN hrgn, RGNOBJ * obj );
+
+#endif  /* __WINE_REGION_H */
diff --git a/include/selectors.h b/include/selectors.h
index aac6fa9..921e65b 100644
--- a/include/selectors.h
+++ b/include/selectors.h
@@ -2,6 +2,8 @@
 #define __WINE_SELECTORS_H
 
 #include "dlls.h"
+#include "segmem.h"
+#include "windows.h"
 
 extern int FindUnusedSelectors(int n_selectors);
 extern int IPCCopySelector(int i_old, unsigned long new, int swap_type);
diff --git a/include/stddebug.h b/include/stddebug.h
index 48348c4..087790e 100644
--- a/include/stddebug.h
+++ b/include/stddebug.h
@@ -77,6 +77,7 @@
 
 #ifdef DEBUG_NONE
 #undef DEBUG_ACCEL
+#undef DEBUG_BITBLT
 #undef DEBUG_BITMAP
 #undef DEBUG_CALLBACK
 #undef DEBUG_CARET
@@ -146,6 +147,7 @@
 
 #ifdef DEBUG_ALL
 #define DEBUG_ACCEL
+#define DEBUG_BITBLT
 #define DEBUG_BITMAP
 #define DEBUG_CALLBACK
 #define DEBUG_CARET
diff --git a/include/syscolor.h b/include/syscolor.h
index 0144953..e5441ce 100644
--- a/include/syscolor.h
+++ b/include/syscolor.h
@@ -7,7 +7,7 @@
 #ifndef SYSCOLOR_H
 #define SYSCOLOR_H
 
-#include "gdi.h"
+#include "windows.h"
 
 struct SysColorObjects
 {
diff --git a/include/win.h b/include/win.h
index d47cb2c..9bb1087 100644
--- a/include/win.h
+++ b/include/win.h
@@ -67,14 +67,13 @@
 #define WIN_CLASS_STYLE(wndPtr)  (WIN_CLASS_INFO(wndPtr).style)
 
   /* Window functions */
-WND *WIN_FindWndPtr( HWND hwnd );
-Window WIN_GetXWindow( HWND hwnd );
-BOOL WIN_UnlinkWindow( HWND hwnd );
-BOOL WIN_LinkWindow( HWND hwnd, HWND hwndInsertAfter );
-HWND WIN_FindWinToRepaint( HWND hwnd );
-BOOL WIN_CreateDesktopWindow(void);
-BOOL WINPOS_IsAnActiveWindow( HWND hwnd );
-void WINPOS_ActivateChild( HWND hwnd );
+extern WND *WIN_FindWndPtr( HWND hwnd );
+extern Window WIN_GetXWindow( HWND hwnd );
+extern BOOL WIN_UnlinkWindow( HWND hwnd );
+extern BOOL WIN_LinkWindow( HWND hwnd, HWND hwndInsertAfter );
+extern HWND WIN_FindWinToRepaint( HWND hwnd );
+extern void WIN_SendParentNotify( HWND hwnd, WORD event, LONG lParam );
+extern BOOL WIN_CreateDesktopWindow(void);
 
 extern Display * display;
 extern Screen * screen;
diff --git a/include/winpos.h b/include/winpos.h
index 0d58c53..1df7d57 100644
--- a/include/winpos.h
+++ b/include/winpos.h
@@ -9,15 +9,6 @@
 
 #define DWP_MAGIC  0x5057  /* 'WP' */
 
-extern HWND WINPOS_ChangeActiveWindow( HWND hwnd, BOOL mouseMsg ); /*winpos.c*/
-extern void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
-			    POINT *minTrack, POINT *maxTrack );  /* winpos.c */
-extern LONG WINPOS_SendNCCalcSize( HWND hwnd, BOOL calcValidRect,
-				   RECT *newWindowRect, RECT *oldWindowRect,
-				   RECT *oldClientRect, WINDOWPOS *winpos,
-				   RECT *newClientRect );  /* winpos.c */
-extern LONG WINPOS_HandleWindowPosChanging( WINDOWPOS *winpos ); /* winpos.c */
-
 typedef struct
 {
     WORD        actualCount;
@@ -28,4 +19,15 @@
     WINDOWPOS   winPos[1];
 } DWP;
 
+
+extern HWND WINPOS_NextWindowFromPoint( HWND hwnd, POINT pt );
+extern HWND WINPOS_ChangeActiveWindow( HWND hwnd, BOOL mouseMsg );
+extern void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
+			    POINT *minTrack, POINT *maxTrack );
+extern LONG WINPOS_SendNCCalcSize( HWND hwnd, BOOL calcValidRect,
+				   RECT *newWindowRect, RECT *oldWindowRect,
+				   RECT *oldClientRect, WINDOWPOS *winpos,
+				   RECT *newClientRect );
+extern LONG WINPOS_HandleWindowPosChanging( WINDOWPOS *winpos );
+
 #endif  /* WINPOS_H */
diff --git a/loader/resource.c b/loader/resource.c
index adee0cf..e09927b 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -12,6 +12,7 @@
 #include "arch.h"
 #include "windows.h"
 #include "gdi.h"
+#include "bitmap.h"
 #include "neexe.h"
 #include "icon.h"
 #include "menu.h"
@@ -742,7 +743,7 @@
 	}
 	if(!it->value)return 0;
 	dprintf_resource(stddeb,"Found %s\n",it->name);
-	lp=it->value;
+	lp=(long *)it->value;
 	rsc_mem=(HANDLE)NULL;
     } else { /* Load from file - indent this code properly later */
 
diff --git a/loader/signal.c b/loader/signal.c
index 3cc7461..51fa430 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -214,7 +214,7 @@
 	XFlush(display);
     fprintf(stderr,"In win_fault %x:%lx\n", scp->sc_cs, scp->sc_eip);
 #if defined(linux) || defined(__NetBSD__) || defined(__FreeBSD__)
-    wine_debug(signal, scp);  /* Enter our debugger */
+    wine_debug(signal, (int *)scp);  /* Enter our debugger */
 #else
     fprintf(stderr,"Stack: %x:%x\n", scp->sc_ss, scp->sc_esp);
     dump = (int*) scp;
@@ -229,7 +229,7 @@
 #endif
 }
 
-int init_wine_signals(void)
+void init_wine_signals(void)
 {
 #ifdef linux
 	segv_act.sa_handler = (__sighandler_t) win_fault;
diff --git a/memory/global.c b/memory/global.c
index e6b0f00..7d5d469 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -167,15 +167,6 @@
 }
 
 /**********************************************************************
- *					WIN16_GlobalAlloc
- */
-HANDLE
-WIN16_GlobalAlloc(unsigned int flags, unsigned long size)
-{
-    return GlobalAlloc(flags & ~GLOBAL_FLAGS_MOVEABLE, size);
-}
-
-/**********************************************************************
  *					GlobalAlloc
  */
 HANDLE
@@ -289,6 +280,15 @@
 	return g->handle;
     }
 }
+
+/**********************************************************************
+ *					WIN16_GlobalAlloc
+ */
+HANDLE
+WIN16_GlobalAlloc(unsigned int flags, unsigned long size)
+{
+    return GlobalAlloc(flags & ~GLOBAL_FLAGS_MOVEABLE, size);
+}
 
 /**********************************************************************
  *					GlobalFree
@@ -549,6 +549,13 @@
 	    current_free = 0;
 	}
     }
+
+    /* One final check just in case the last block was also marked free, in
+     * which case the above test against max_free doesn't occur for the
+     * last run of free blocks.
+     */
+    if (current_free > max_free)
+        max_free = current_free;
     
     return max_free << 16;
 }
diff --git a/memory/heap.c b/memory/heap.c
index 56474e7..939eb83 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -26,11 +26,11 @@
     for (m = *free_list; m != NULL; m = m->next)
     {
 	if (((int) m & 0xffff0000) != ((int) *free_list & 0xffff0000))
-	{   dprintf_heap(stddeb,"Invalid block %08x\n",m);
+	{   dprintf_heap(stddeb,"Invalid block %p\n",m);
 	    *(char *)0 = 0;
 	}
 	if (m->prev && (((int) m->prev & 0xffff0000) != ((int) *free_list & 0xffff0000)))
-	{   dprintf_heap(stddeb,"Invalid prev %08x from %08x\n", m->prev, m);
+	{   dprintf_heap(stddeb,"Invalid prev %p from %p\n", m->prev, m);
 	    *(char *)0 = 0;
 	}
     }
@@ -164,7 +164,7 @@
     if (m->prev != m || m->next != m || 
 	((int) m & 0xffff0000) != ((int) *free_list & 0xffff0000))
     {
-	fprintf(stderr,"Attempt to resize bad pointer, m = %08x, *free_list = %08x\n",
+	fprintf(stderr,"Attempt to resize bad pointer, m = %p, *free_list = %p\n",
 	       m, free_list);
 	HEAP_CheckHeap(free_list);
 	return NULL;
@@ -235,7 +235,7 @@
     MDESC *m;
     MDESC *m_prev;
 
-    dprintf_heap(stddeb,"HeapFree: free_list %08x, block %08x\n", 
+    dprintf_heap(stddeb,"HeapFree: free_list %p, block %p\n", 
 	   free_list, block);
     if(debugging_heap)HEAP_CheckHeap(free_list);
 
@@ -246,7 +246,7 @@
     if (m_free->prev != m_free || m_free->next != m_free)
     {
 	fprintf(stderr,"Attempt to free bad pointer,"
-	       "m_free = %08x, *free_list = %08x\n",
+	       "m_free = %p, *free_list = %p\n",
 	       m_free, free_list);
 	return -1;
     }
@@ -261,7 +261,7 @@
     else if (((int) m_free & 0xffff0000) != ((int) *free_list & 0xffff0000))
     {
 	fprintf(stderr,"Attempt to free bad pointer,"
-	       "m_free = %08x, *free_list = %08x\n",
+	       "m_free = %p, *free_list = %p\n",
 	       m_free, free_list);
 	return -1;
     }
@@ -276,7 +276,7 @@
     if (m_prev != NULL && (int) m_prev + m_prev->length > (int) m_free)
     {
 	fprintf(stderr,"Attempt to free bad pointer,"
-	       "m_free = %08x, m_prev = %08x (length %x)\n",
+	       "m_free = %p, m_prev = %p (length %x)\n",
 	       m_free, m_prev, m_prev->length);
 	return -1;
     }
@@ -285,7 +285,7 @@
 	(int) m_free + m_free->length > ((int) m_free | 0xffff))
     {
 	fprintf(stderr,"Attempt to free bad pointer,"
-	       "m_free = %08x (length %x), m = %08x\n",
+	       "m_free = %p (length %x), m = %p\n",
 	       m_free, m_free->length, m);
 	return -1;
     }
@@ -347,7 +347,7 @@
     LHEAP *lh;
     dprintf_heap(stddeb,"CheckLocalHeaps called from %s %d\n",file,line);
     for(lh=LocalHeaps; lh!=NULL; lh = lh->next)
-    {	dprintf_heap(stddeb,"Checking heap %08x, free_list %08x\n",
+    {	dprintf_heap(stddeb,"Checking heap %p, free_list %p\n",
 		lh,lh->free_list);
 	HEAP_CheckHeap(&lh->free_list);
     }
@@ -361,7 +361,6 @@
 HEAP_LocalFindHeap(unsigned short owner)
 {
     LHEAP *lh;
-    extern struct w_files *current_exe;
     
     dprintf_heap(stddeb,"HEAP_LocalFindHeap: owner %04x\n", owner);
 
@@ -383,7 +382,7 @@
 {
     LHEAP *lh;
 
-    dprintf_heap(stddeb,"HEAP_LocalInit: owner %04x, start %08x, length %04x\n"
+    dprintf_heap(stddeb,"HEAP_LocalInit: owner %04x, start %p, length %04x\n"
 	   ,owner, start, length);
 
     if (length < 2 * sizeof(MDESC))
@@ -398,7 +397,7 @@
     lh->local_table = NULL;
     lh->delta       = 0x20;
     HEAP_Init(&lh->free_list, start, length);
-    dprintf_heap(stddeb,"HEAP_LocalInit: free_list %08x, length %04x, prev %08x, next %08x\n",&lh->free_list,lh->free_list->length, lh->free_list->prev,lh->free_list->next);
+    dprintf_heap(stddeb,"HEAP_LocalInit: free_list %p, length %04x, prev %p, next %p\n",&lh->free_list,lh->free_list->length, lh->free_list->prev,lh->free_list->next);
     LocalHeaps = lh;
 }
 
@@ -553,9 +552,9 @@
     void *m;
     dprintf_heap(stddeb,"WIN16_LocalReAlloc(%04X, %d, %04X); !\n",	
 		 handle, bytes, flags);
-    dprintf_heap(stddeb,"WIN16_LocalReAlloc // LOCALHEAP()=%08X !\n", 
+    dprintf_heap(stddeb,"WIN16_LocalReAlloc // LOCALHEAP()=%p !\n", 
 		 LOCALHEAP());
-    dprintf_heap(stddeb,"WIN16_LocalReAlloc // *LOCALHEAP()=%08X !\n", 
+    dprintf_heap(stddeb,"WIN16_LocalReAlloc // *LOCALHEAP()=%p !\n", 
 		 *LOCALHEAP());
     m = HEAP_ReAlloc(LOCALHEAP(), (void *)
 		     (((int) *LOCALHEAP() & 0xffff0000) | (handle & 0xffff)),
diff --git a/misc/clipboard.c b/misc/clipboard.c
index e8a0cf9..51fefde 100644
--- a/misc/clipboard.c
+++ b/misc/clipboard.c
@@ -14,9 +14,9 @@
 #include <unistd.h>
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
-#include "prototypes.h"
 #include "heap.h"
 #include "win.h"
+#include "message.h"
 #include "clipboard.h"
 #include "stddebug.h"
 #include "debug.h"
diff --git a/misc/commdlg.c b/misc/commdlg.c
index f9a6298..abf119f 100644
--- a/misc/commdlg.c
+++ b/misc/commdlg.c
@@ -61,14 +61,14 @@
 	HINSTANCE	hInst;
 	WND 		*wndPtr;
 	BOOL		bRet;
-	printf("GetOpenFileName(%08X); !\n", lpofn);
+	printf("GetOpenFileName(%p); !\n", lpofn);
 	if (lpofn == NULL) return FALSE;
-	printf("GetOpenFileName // Flags=%08X !\n", lpofn->Flags);
-	printf("GetOpenFileName // nMaxFile=%d lpstrFile='%s' !\n", 
+	printf("GetOpenFileName // Flags=%08lX !\n", lpofn->Flags);
+	printf("GetOpenFileName // nMaxFile=%ld lpstrFile='%s' !\n", 
 						lpofn->nMaxFile, lpofn->lpstrFile);
 	printf("GetOpenFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
-	printf("GetOpenFileName // lpstrFilter=%08X !\n", lpofn->lpstrFilter);
-	printf("GetOpenFileName // nFilterIndex=%d !\n", lpofn->nFilterIndex);
+	printf("GetOpenFileName // lpstrFilter=%p !\n", lpofn->lpstrFilter);
+	printf("GetOpenFileName // nFilterIndex=%ld !\n", lpofn->nFilterIndex);
 	if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
 		hDlgTmpl = lpofn->hInstance;
 		}
@@ -123,13 +123,13 @@
 	HINSTANCE	hInst;
     WND 		*wndPtr;
 	BOOL		bRet;
-	printf("GetSaveFileName(%08X); !\n", lpofn);
+	printf("GetSaveFileName(%p); !\n", lpofn);
 	if (lpofn == NULL) return FALSE;
-	printf("GetSaveFileName // Flags=%08X !\n", lpofn->Flags);
-	printf("GetSaveFileName // nMaxFile=%d lpstrFile='%s' !\n", 
+	printf("GetSaveFileName // Flags=%08lX !\n", lpofn->Flags);
+	printf("GetSaveFileName // nMaxFile=%ld lpstrFile='%s' !\n", 
 						lpofn->nMaxFile, lpofn->lpstrFile);
 	printf("GetSaveFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
-	printf("GetSaveFileName // lpstrFilter=%08X !\n", lpofn->lpstrFilter);
+	printf("GetSaveFileName // lpstrFilter=%p !\n", lpofn->lpstrFilter);
 	if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
 		hDlgTmpl = lpofn->hInstance;
 		}
@@ -197,7 +197,6 @@
 	HDC 	hMemDC;
 	HBITMAP	hBitmap;
 	BITMAP	bm;
-    WND 	*wndPtr;
 	LPMEASUREITEMSTRUCT lpmeasure;
 	LPDRAWITEMSTRUCT lpdis;
 	static	int		nDrive;
@@ -209,7 +208,7 @@
 #ifdef DEBUG_OPENDLG
 			printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
 #endif
-			printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
+			printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
 			if (!FileDlg_Init(hWnd, lParam)) return TRUE;
 			SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0L);
 			lpofn = (LPOPENFILENAME)lParam;
@@ -632,8 +631,6 @@
 	LPMEASUREITEMSTRUCT lpmeasure;
 	LPDRAWITEMSTRUCT lpdis;
 	static	int		nDrive;
-	static	int		OldDrive;
-	static 	char	OldPath[512];
 	static 	char	CurPath[512];
 	static LPOPENFILENAME lpofn;
 
@@ -874,7 +871,7 @@
 {
 	switch (wMsg) {
 		case WM_INITDIALOG:
-			printf("ColorDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
+			printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
 			ShowWindow(hWnd, SW_SHOWNORMAL);
 			return (TRUE);
 
@@ -952,7 +949,7 @@
 {
 	switch (wMsg) {
 		case WM_INITDIALOG:
-			printf("FindTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
+			printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
 			ShowWindow(hWnd, SW_SHOWNORMAL);
 			return (TRUE);
 
@@ -978,7 +975,7 @@
 {
 	switch (wMsg) {
 		case WM_INITDIALOG:
-			printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
+			printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
 			ShowWindow(hWnd, SW_SHOWNORMAL);
 			return (TRUE);
 
@@ -1006,7 +1003,7 @@
 	HANDLE	hResInfo;
     WND 	*wndPtr;
 	BOOL	bRet;
-	printf("PrintDlg(%08X) // Flags=%08X\n", lpPrint->Flags);
+	printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags);
 	if (lpPrint->Flags & PD_PRINTSETUP)
 		hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(PRINTSETUPDLG), RT_DIALOG);
 	else
@@ -1038,7 +1035,7 @@
 {
 	switch (wMsg) {
 		case WM_INITDIALOG:
-			printf("PrintDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
+			printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
 			ShowWindow(hWnd, SW_SHOWNORMAL);
 			return (TRUE);
 
@@ -1064,7 +1061,7 @@
 {
 	switch (wMsg) {
 		case WM_INITDIALOG:
-			printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
+			printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
 			ShowWindow(hWnd, SW_SHOWNORMAL);
 			return (TRUE);
 
@@ -1098,7 +1095,7 @@
 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
 {
 	int		i, len;
-	printf("GetFileTitle(%08X %08X %d); \n", lpFile, lpTitle, cbBuf);
+	printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
 	if (lpFile == NULL || lpTitle == NULL) return -1;
 	len = strlen(lpFile);
 	if (len == 0) return -1;
diff --git a/misc/dos_fs.c b/misc/dos_fs.c
index 54bf564..235205d 100644
--- a/misc/dos_fs.c
+++ b/misc/dos_fs.c
@@ -89,6 +89,43 @@
 		path[strlen(path)-1] = '\0';
 }
 
+void ToUnix(char *s)
+{
+	/*  \WINDOWS\\SYSTEM   =>   /windows/system */
+
+	char *p;
+
+	for (p = s; *p; p++) 
+	{
+		if (*p != '\\')
+			*s++ = tolower(*p);
+		else {
+			*s++ = '/';
+			if (*(p+1) == '/' || *(p+1) == '\\')
+				p++;
+		}
+	}
+	*s = '\0';
+}
+
+void ToDos(char *s)
+{
+	/* /windows//system   =>   \WINDOWS\SYSTEM */
+
+	char *p;
+	for (p = s; *p; p++) 
+	{
+		if (*p != '/')
+			*s++ = toupper(*p);
+		else {
+			*s++ = '\\';
+			if (*(p+1) == '/' || *(p+1) == '\\') 
+			    p++;
+		}
+	}
+	*s = '\0';
+}
+
 void DOS_InitFS(void)
 {
 	int x;
@@ -279,43 +316,6 @@
 		CurrentDrive = drive;
 }
 
-void ToUnix(char *s)
-{
-	/*  \WINDOWS\\SYSTEM   =>   /windows/system */
-
-	char *p;
-
-	for (p = s; *p; p++) 
-	{
-		if (*p != '\\')
-			*s++ = tolower(*p);
-		else {
-			*s++ = '/';
-			if (*(p+1) == '/' || *(p+1) == '\\')
-				p++;
-		}
-	}
-	*s = '\0';
-}
-
-void ToDos(char *s)
-{
-	/* /windows//system   =>   \WINDOWS\SYSTEM */
-
-	char *p;
-	for (p = s; *p; p++) 
-	{
-		if (*p != '/')
-			*s++ = toupper(*p);
-		else {
-			*s++ = '\\';
-			if (*(p+1) == '/' || *(p+1) == '\\') 
-			    p++;
-		}
-	}
-	*s = '\0';
-}
-
 int DOS_DisableDrive(int drive)
 {
 	if (drive >= MAX_DOS_DRIVES)
diff --git a/misc/driver.c b/misc/driver.c
index c39c3e7..e9f5f40 100644
--- a/misc/driver.c
+++ b/misc/driver.c
@@ -46,6 +46,7 @@
 {
 	dprintf_driver(stdnimp,"SendDriverMessage(%04X, %04X, %08lX, %08lX);\n",
 						hDriver, msg, lParam1, lParam2);
+        return 0;
 }
 
 /**************************************************************************
diff --git a/misc/keyboard.c b/misc/keyboard.c
index 9a07198..ce2c0ec 100644
--- a/misc/keyboard.c
+++ b/misc/keyboard.c
@@ -6,7 +6,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "prototypes.h"
 #include "windows.h"
 #include "keyboard.h"
 #include "stddebug.h"
diff --git a/misc/lstr.c b/misc/lstr.c
index aaf47f3..f188dad 100644
--- a/misc/lstr.c
+++ b/misc/lstr.c
@@ -9,7 +9,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "prototypes.h"
 #include "regfunc.h"
 #include "windows.h"
 
diff --git a/misc/main.c b/misc/main.c
index 9aa9111..03c7584 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -491,7 +491,6 @@
     MAIN_SaveSetup();
     DOS_InitFS();
     Comm_Init();
-    Font_Init();
 #ifndef WINELIB
     INT21_Init();
 #endif
@@ -553,7 +552,7 @@
 				}
 			free(lpEnv->Value);
 			lpEnv->Value = malloc(nCount);
-			if (lpNewEnv->Value == NULL) {
+			if (lpEnv->Value == NULL) {
 				printf("SetEnvironment() // Error allocating entry value !\n");
 				return 0;
 			}
diff --git a/misc/message.c b/misc/message.c
index 2134464..0b02f24 100644
--- a/misc/message.c
+++ b/misc/message.c
@@ -15,7 +15,6 @@
 #include <ctype.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include "prototypes.h"
 #include "heap.h"
 #include "library.h"
 #include "win.h"
diff --git a/misc/network.c b/misc/network.c
index 779d6aa..7ccc901 100644
--- a/misc/network.c
+++ b/misc/network.c
@@ -37,7 +37,7 @@
 int WNetGetConnection(LPSTR lpLocalName, 
 	LPSTR lpRemoteName, UINT FAR *cbRemoteName)
 {
-	printf("EMPTY STUB !!! WNetGetConnection('%s', %08X, %08X);\n", 
+	printf("EMPTY STUB !!! WNetGetConnection('%s', %p, %p);\n", 
 		lpLocalName, lpRemoteName, cbRemoteName);
 	return	WN_NET_ERROR;
 }
@@ -55,7 +55,7 @@
  */
 UINT WNetGetUser(LPSTR lpLocalName, LPSTR lpUserName, DWORD *lpSize)
 {
-	printf("EMPTY STUB !!! WNetGetUser('%s', %08X, %08X);\n", 
+	printf("EMPTY STUB !!! WNetGetUser('%s', %p, %p);\n", 
 							lpLocalName, lpUserName, lpSize);
 	return WN_NET_ERROR;
 }
@@ -65,7 +65,7 @@
  */
 UINT WNetAddConnection(LPSTR lpNetPath, LPSTR lpPassWord, LPSTR lpLocalName)
 {
-	printf("EMPTY STUB !!! WNetAddConnection('%s', %08X, '%s');\n",
+	printf("EMPTY STUB !!! WNetAddConnection('%s', %p, '%s');\n",
 							lpNetPath, lpPassWord, lpLocalName);
 	return WN_NET_ERROR;
 }
@@ -87,7 +87,7 @@
 UINT WNetAddConnection2(LPSTR lpNetPath, LPSTR lpPassWord, 
 		LPSTR lpLocalName, LPSTR lpUserName)
 {
-	printf("EMPTY STUB !!! WNetAddConnection2('%s', %08X, '%s', '%s');\n",
+	printf("EMPTY STUB !!! WNetAddConnection2('%s', %p, '%s', '%s');\n",
 					lpNetPath, lpPassWord, lpLocalName, lpUserName);
 	return WN_NET_ERROR;
 }
@@ -107,7 +107,7 @@
 UINT WNetEnumResource(HANDLE hEnum, DWORD cRequ, 
 				DWORD *lpCount, LPVOID lpBuf)
 {
-	printf("EMPTY STUB !!! WNetEnumResource(%04X, %08X, %08X, %08X);\n", 
+	printf("EMPTY STUB !!! WNetEnumResource(%04X, %08lX, %p, %p);\n", 
 							hEnum, cRequ, lpCount, lpBuf);
 	return WN_NET_ERROR;
 }
@@ -118,7 +118,7 @@
 UINT WNetOpenEnum(DWORD dwScope, DWORD dwType, 
 	LPNETRESOURCE lpNet, HANDLE FAR *lphEnum)
 {
-	printf("EMPTY STUB !!! WNetOpenEnum(%08X, %08X, %08X, %08X);\n",
+	printf("EMPTY STUB !!! WNetOpenEnum(%08lX, %08lX, %p, %p);\n",
 							dwScope, dwType, lpNet, lphEnum);
 	return WN_NET_ERROR;
 }
diff --git a/misc/profile.c b/misc/profile.c
index d30774f..7fd305d 100644
--- a/misc/profile.c
+++ b/misc/profile.c
@@ -24,7 +24,6 @@
 #include "wine.h"
 #include "windows.h"
 #include "dos_fs.h"
-#include "prototypes.h"
 #include "stddebug.h"
 /* #define DEBUG_PROFILE */
 #include "debug.h"
diff --git a/misc/shell.c b/misc/shell.c
index 0c6091e..97a9653 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -5,10 +5,10 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
-#include "prototypes.h"
 #include "windows.h"
 #include "library.h"
 #include "shell.h"
+#include "neexe.h"
 #include "../rc/sysres.h"
 #include "stddebug.h"
 /* #define DEBUG_REG */
@@ -25,13 +25,13 @@
 	LPSTR		ptr;
 	char		str[128];
 
-	dprintf_reg(stddeb, "RegOpenKey(%04X, %08X='%s', %08X)\n",
+	dprintf_reg(stddeb, "RegOpenKey(%08lX, %p='%s', %p)\n",
 						hKey, lpSubKey, lpSubKey, lphKey);
 	if (lpKey == NULL) return ERROR_BADKEY;
 	if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
 	if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
 	if (hKey != HKEY_CLASSES_ROOT) {
-		dprintf_reg(stddeb,"RegOpenKey // specific key = %04X !\n", hKey);
+		dprintf_reg(stddeb,"RegOpenKey // specific key = %08lX !\n", hKey);
 		lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
 		}
 	while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
@@ -67,7 +67,7 @@
 		lpKey = lpKey->lpNextKey;
 		}
 	*lphKey = lpKey->hKey;
-	dprintf_reg(stddeb,"RegOpenKey // return hKey=%04X !\n", lpKey->hKey);
+	dprintf_reg(stddeb,"RegOpenKey // return hKey=%08lX !\n", lpKey->hKey);
 	return ERROR_SUCCESS;
 }
 
@@ -84,11 +84,11 @@
 	LONG		dwRet;
 	LPSTR		ptr;
 	char		str[128];
-	dprintf_reg(stddeb, "RegCreateKey(%04X, '%s', %08X)\n",	hKey, lpSubKey, lphKey);
+	dprintf_reg(stddeb, "RegCreateKey(%08lX, '%s', %p)\n",	hKey, lpSubKey, lphKey);
 	if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
 	if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
 	if (hKey != HKEY_CLASSES_ROOT) {
-		dprintf_reg(stddeb,"RegCreateKey // specific key = %04X !\n", hKey);
+		dprintf_reg(stddeb,"RegCreateKey // specific key = %08lX !\n", hKey);
 		lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
 		}
 	while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
@@ -158,7 +158,7 @@
 	lpNewKey->lpNextKey = NULL;
 	lpNewKey->lpSubLvl = NULL;
 	*lphKey = hNewKey;
-	dprintf_reg(stddeb,"RegCreateKey // successful '%s' key=%04X !\n", lpSubKey, hNewKey);
+	dprintf_reg(stddeb,"RegCreateKey // successful '%s' key=%08lX !\n", lpSubKey, hNewKey);
 	return ERROR_SUCCESS;
 }
 
@@ -168,7 +168,7 @@
  */
 LONG RegCloseKey(HKEY hKey)
 {
-	dprintf_reg(stdnimp, "EMPTY STUB !!! RegCloseKey(%04X);\n", hKey);
+	dprintf_reg(stdnimp, "EMPTY STUB !!! RegCloseKey(%08lX);\n", hKey);
 	return ERROR_INVALID_PARAMETER;
 }
 
@@ -178,7 +178,7 @@
  */
 LONG RegDeleteKey(HKEY hKey, LPCSTR lpSubKey)
 {
-	dprintf_reg(stdnimp, "EMPTY STUB !!! RegDeleteKey(%04X, '%s');\n", 
+	dprintf_reg(stdnimp, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n", 
 												hKey, lpSubKey);
 	return ERROR_INVALID_PARAMETER;
 }
@@ -193,14 +193,14 @@
 	HKEY		hRetKey;
 	LPKEYSTRUCT	lpKey;
 	LONG		dwRet;
-	dprintf_reg(stddeb, "RegSetValue(%04X, '%s', %08X, '%s', %08X);\n",
+	dprintf_reg(stddeb, "RegSetValue(%08lX, '%s', %08lX, '%s', %08lX);\n",
 						hKey, lpSubKey, dwType, lpVal, dwIgnored);
 	if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
 	if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
 	if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
 		dprintf_reg(stddeb, "RegSetValue // key not found ... so create it !\n");
 		if ((dwRet = RegCreateKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
-			fprintf(stderr, "RegSetValue // key creation error %04X !\n", dwRet);
+			fprintf(stderr, "RegSetValue // key creation error %08lX !\n", dwRet);
 			return dwRet;
 			}
 		}
@@ -223,7 +223,7 @@
 	LPKEYSTRUCT	lpKey;
 	LONG		dwRet;
 	int			size;
-	dprintf_reg(stddeb, "RegQueryValue(%04X, '%s', %08X, %08X);\n",
+	dprintf_reg(stddeb, "RegQueryValue(%08lX, '%s', %p, %p);\n",
 							hKey, lpSubKey, lpVal, lpcb);
 	if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
 	if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
@@ -317,7 +317,7 @@
 HINSTANCE FindExecutable(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
 {
 	dprintf_reg(stdnimp, "FindExecutable : Empty Stub !!!\n");
-
+        return 0;
 }
 
 char AppName[256], AppMisc[256];
@@ -399,6 +399,7 @@
 HICON ExtractAssociatedIcon(HINSTANCE hInst,LPSTR lpIconPath, LPWORD lpiIcon)
 {
 	dprintf_reg(stdnimp, "ExtractAssociatedIcon : Empty Stub !!!\n");
+        return 0;
 }
 
 /*************************************************************************
@@ -417,4 +418,5 @@
 int ShellHookProc(void) 
 {
 	dprintf_reg(stdnimp, "ShellHookProc : Empty Stub !!!\n");
+        return 0;
 }
diff --git a/misc/sound.c b/misc/sound.c
index 6d1b321..8b8696d 100644
--- a/misc/sound.c
+++ b/misc/sound.c
@@ -5,7 +5,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include "prototypes.h"
+#include "windows.h"
 
 int OpenSound(void)
 {
@@ -51,7 +51,7 @@
 
 int SetVoiceSound(int nVoice, long lFrequency, int nDuration)
 {
-  printf("SetVoiceSound(%d, %d, %d)\n",nVoice,lFrequency, nDuration);
+  printf("SetVoiceSound(%d, %ld, %d)\n",nVoice,lFrequency, nDuration);
   return 0;
 }
 
@@ -68,31 +68,37 @@
 int WaitSoundState(int x)
 {
 	fprintf(stderr, "WaitSoundState(%d)\n", x);
+        return 0;
 }
 
 int SyncAllVoices(void)
 {
 	fprintf(stderr, "SyncAllVoices()\n");
+        return 0;
 }
 
 int CountVoiceNotes(int x)
 {
 	fprintf(stderr, "CountVoiceNotes(%d)\n", x);
+        return 0;
 }
 
 LPINT GetThresholdEvent(void)
 {
 	fprintf(stderr, "GetThresholdEvent()\n");
+        return NULL;
 }
 
 int GetThresholdStatus(void)
 {
 	fprintf(stderr, "GetThresholdStatus()\n");
+        return 0;
 }
 
 int SetVoiceThreshold(int a, int b)
 {
 	fprintf(stderr, "SetVoiceThreshold(%d,%d)\n", a, b);
+        return 0;
 }
 
 void DoBeep(void)
diff --git a/miscemu/emulate.c b/miscemu/emulate.c
index c014887..31c9634 100644
--- a/miscemu/emulate.c
+++ b/miscemu/emulate.c
@@ -1,6 +1,5 @@
 #include <stdlib.h>
 #include <stdio.h>
-#include "prototypes.h"
 #include "regfunc.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
@@ -18,8 +17,8 @@
 int
 WIN87_fpmath()
 {
-  dprintf_int(stddeb, "_fpmath: (%x:%lx %lx %x)\n",_CONTEXT->sc_cs, 
-	 _CONTEXT->sc_eip, _CONTEXT->sc_es, _BX & 0xffff);
+  dprintf_int(stddeb, "_fpmath: (%x:%lx %x %x)\n",_CONTEXT->sc_cs, 
+	 _CONTEXT->sc_eip, _CONTEXT->sc_es, (unsigned int)_BX & 0xffff);
 
   switch(_BX & 0xffff)
     {
diff --git a/miscemu/int1a.c b/miscemu/int1a.c
index a8739f0..9cb0db0 100644
--- a/miscemu/int1a.c
+++ b/miscemu/int1a.c
@@ -9,17 +9,12 @@
 /* #define DEBUG_INT */
 #include "debug.h"
 
-#ifdef linux
-#define inline __inline__  /* So we can compile with -ansi */
-#include <linux/sched.h> /* needed for HZ */
-#undef inline
-#endif
-
 #define	BCD_TO_BIN(x) ((x&15) + (x>>4)*10)
 #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4))
 
 int do_int1a(struct sigcontext_struct * context){
-	time_t ltime, ticks;
+	time_t ltime;
+        DWORD ticks;
 	struct tm *bdtime;
 
     if (debugging_relay) {
@@ -30,8 +25,7 @@
 
 	switch(AH) {
 	case 0:
-		ltime = time(NULL);
-		ticks = (int) (ltime * HZ);
+                ticks = GetTickCount();
 		CX = ticks >> 16;
 		DX = ticks & 0x0000FFFF;
 		AX = 0;  /* No midnight rollover */
diff --git a/miscemu/int21.c b/miscemu/int21.c
index 5ab5c11..62330ff 100644
--- a/miscemu/int21.c
+++ b/miscemu/int21.c
@@ -22,7 +22,6 @@
 #include "msdos.h"
 #include "registers.h"
 #include "options.h"
-#include "prototypes.h"
 #include "miscemu.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
@@ -485,7 +484,7 @@
 	  case 0x30:    /* DENYREAD */
 	    dprintf_int(stdnimp,
 	      "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
-	      SAFEMAKEPTR(DS,DX));
+	      (char *)SAFEMAKEPTR(DS,DX));
 	  case 0x10:    /* DENYALL */  
 	    lock = LOCK_EX;
 	    break;
@@ -549,7 +548,7 @@
 	char *newname, *oldname;
 
 	dprintf_int(stddeb,"int21: renaming %s to %s\n",
-			SAFEMAKEPTR(DS,DX), SAFEMAKEPTR(ES,DI) );
+			(char *)SAFEMAKEPTR(DS,DX), (char *)SAFEMAKEPTR(ES,DI) );
 	
 	oldname = DOS_GetUnixFileName( SAFEMAKEPTR(DS,DX) );
 	newname = DOS_GetUnixFileName( SAFEMAKEPTR(ES,DI) );
@@ -563,7 +562,7 @@
 {
 	char *dirname;
 
-	dprintf_int(stddeb,"int21: makedir %s\n", SAFEMAKEPTR(DS,DX) );
+	dprintf_int(stddeb,"int21: makedir %s\n", (char *)SAFEMAKEPTR(DS,DX) );
 	
 	if ((dirname = DOS_GetUnixFileName( SAFEMAKEPTR(DS,DX) ))== NULL) {
 		AL = CanNotMakeDir;
@@ -600,7 +599,7 @@
 {
 	char *dirname;
 
-	dprintf_int(stddeb,"int21: removedir %s\n", SAFEMAKEPTR(DS,DX) );
+	dprintf_int(stddeb,"int21: removedir %s\n", (char *)SAFEMAKEPTR(DS,DX) );
 
 	if ((dirname = DOS_GetUnixFileName( SAFEMAKEPTR(DS,DX) ))== NULL) {
 		AL = CanNotMakeDir;
@@ -1601,7 +1600,10 @@
 	MDESC *DosHeapDesc;
 
 	if ((handle = GlobalAlloc(GMEM_FIXED,sizeof(struct DosHeap))) == 0)
-		myerror("out of memory");
+        {
+            fprintf( stderr, "INT21_Init: Out of memory\n");
+            exit(1);
+        }
 
 	heap = (struct DosHeap *) GlobalLock(handle);
 	HEAP_Init(&DosHeapDesc, heap, sizeof(struct DosHeap));
diff --git a/miscemu/int25.c b/miscemu/int25.c
index 54cdbc6..38c306d 100644
--- a/miscemu/int25.c
+++ b/miscemu/int25.c
@@ -25,7 +25,7 @@
 		length = CX;
 	}
 	dprintf_int(stdnimp, "int25: abs diskread, drive %d, sector %ld, "
-	"count %ld, buffer %d\n", EAX & 0xff, begin, length, (int) dataptr);
+	"count %ld, buffer %d\n", (int)EAX & 0xff, begin, length, (int) dataptr);
 
 	memset(dataptr, 0, length * 512);
 
diff --git a/miscemu/int26.c b/miscemu/int26.c
index e6a7da8..c642f4c 100644
--- a/miscemu/int26.c
+++ b/miscemu/int26.c
@@ -25,7 +25,7 @@
 	}
 		
 	dprintf_int(stdnimp,"int26: abs diskwrite, drive %d, sector %ld, "
-	"count %ld, buffer %d\n", EAX & 0xff, begin, length, (int) dataptr);
+	"count %ld, buffer %d\n", (int)EAX & 0xff, begin, length, (int) dataptr);
 
 	ResetCflag;
 
diff --git a/multimedia/audio.c b/multimedia/audio.c
index e005b86..e595c11 100644
--- a/multimedia/audio.c
+++ b/multimedia/audio.c
@@ -115,6 +115,7 @@
 		fprintf(stderr,"WAVE_NotifyClient // can't notify client !\n");
 		return MMSYSERR_NOERROR;
 		}
+        return 0;
 #else
 	return MMSYSERR_NOTENABLED;
 #endif
@@ -194,7 +195,7 @@
 	DWORD		dwRet;
 	char		str[128];
 
-	dprintf_mciwave(stddeb,"WAVE_mciOpen(%08X, %08X)\n", dwFlags, lpParms);
+	dprintf_mciwave(stddeb,"WAVE_mciOpen(%08lX, %p)\n", dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	wDevID = lpParms->wDeviceID;
 	if (MCIWavDev[wDevID].nUseCount > 0) {
@@ -274,7 +275,7 @@
 				(LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType,
 				mmckInfo.cksize);
 		dprintf_mciwave(stddeb,
-			"WAVE_mciOpen // nChannels=%d nSamplesPerSec=%d\n",
+			"WAVE_mciOpen // nChannels=%d nSamplesPerSec=%ld\n",
 			lpWaveFormat->wf.nChannels, lpWaveFormat->wf.nSamplesPerSec);
 		lpWaveFormat->wBitsPerSample = 0;
 		}
@@ -296,7 +297,7 @@
 #ifdef linux
 	DWORD		dwRet;
 	dprintf_mciwave(stddeb,
-		"WAVE_mciClose(%u, %08X, %08X);\n", wDevID, dwParam, lpParms);
+		"WAVE_mciClose(%u, %08lX, %p);\n", wDevID, dwParam, lpParms);
 	MCIWavDev[wDevID].nUseCount--;
 	if (MCIWavDev[wDevID].nUseCount == 0) {
 		if (MCIWavDev[wDevID].hFile != 0) {
@@ -326,7 +327,7 @@
 	LPWAVEHDR		lpWaveHdr;
 	DWORD		dwRet;
 	dprintf_mciwave(stddeb,
-		 "WAVE_mciPlay(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		 "WAVE_mciPlay(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (MCIWavDev[wDevID].hFile == 0) {
         fprintf(stderr,"WAVE_mciPlay // can't find file='%s' !\n",
 				MCIWavDev[wDevID].openParms.lpstrElementName);
@@ -345,7 +346,7 @@
 /**/
 	if (dwFlags & MCI_NOTIFY) {
         dprintf_mciwave(stddeb,
-	        "WAVE_mciPlay // MCI_NOTIFY %08X !\n", lpParms->dwCallback);
+	        "WAVE_mciPlay // MCI_NOTIFY %08lX !\n", lpParms->dwCallback);
 		switch(fork()) {
 			case -1:
 				fprintf(stderr,
@@ -371,7 +372,7 @@
 		count = mmioRead(MCIWavDev[wDevID].hFile, lpWaveHdr->lpData, lpWaveHdr->dwBufferLength);
 		if (count < 1) break;
 		lpWaveHdr->dwBytesRecorded = count;
-		dprintf_mciwave(stddeb,"WAVE_mciPlay // before WODM_WRITE lpWaveHdr=%08X dwBytesRecorded=%u\n",
+		dprintf_mciwave(stddeb,"WAVE_mciPlay // before WODM_WRITE lpWaveHdr=%p dwBytesRecorded=%lu\n",
 					lpWaveHdr, lpWaveHdr->dwBytesRecorded);
 		dwRet = wodMessage(0, WODM_WRITE, 0, (DWORD)lpWaveHdr, sizeof(WAVEHDR));
 		}
@@ -381,7 +382,7 @@
 		lpWaveHdr->lpData = NULL;
 		}
 	if (dwFlags & MCI_NOTIFY) {
-	  dprintf_mciwave(stddeb,"WAVE_mciPlay // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms->dwCallback);
+	  dprintf_mciwave(stddeb,"WAVE_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		exit(0);
@@ -399,13 +400,12 @@
 DWORD WAVE_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
 {
 #ifdef linux
-	int			count;
 	int			start, end;
 	LPWAVEHDR		lpWaveHdr;
 	DWORD			dwRet;
 
 	dprintf_mciwave(stddeb,
-		"WAVE_mciRecord(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		"WAVE_mciRecord(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (MCIWavDev[wDevID].hFile == 0) {
 		fprintf(stderr,"WAVE_mciRecord // can't find file='%s' !\n", 
 				MCIWavDev[wDevID].openParms.lpstrElementName);
@@ -433,7 +433,7 @@
 		lpWaveHdr->dwBytesRecorded = 0;
 		dwRet = widMessage(0, WIDM_START, 0, 0L, 0L);
 		dprintf_mciwave(stddeb,
-                    "WAVE_mciRecord // after WIDM_START lpWaveHdr=%08X dwBytesRecorded=%u\n",
+                    "WAVE_mciRecord // after WIDM_START lpWaveHdr=%p dwBytesRecorded=%lu\n",
 					lpWaveHdr, lpWaveHdr->dwBytesRecorded);
 		if (lpWaveHdr->dwBytesRecorded == 0) break;
 		}
@@ -445,7 +445,7 @@
 		lpWaveHdr->lpData = NULL;
 		}
 	if (dwFlags & MCI_NOTIFY) {
-	  dprintf_mciwave(stddeb,"WAVE_mciRecord // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms->dwCallback);
+	  dprintf_mciwave(stddeb,"WAVE_mciRecord // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		}
@@ -463,7 +463,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		 "WAVE_mciStop(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		 "WAVE_mciStop(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
 #else
@@ -479,7 +479,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		"WAVE_mciPause(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		"WAVE_mciPause(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
 #else
@@ -495,7 +495,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		"WAVE_mciResume(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		"WAVE_mciResume(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
 #else
@@ -511,12 +511,12 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		  "WAVE_mciSet(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		  "WAVE_mciSet(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	dprintf_mciwave(stddeb,
-		 "WAVE_mciSet // dwTimeFormat=%08X\n", lpParms->dwTimeFormat);
+		 "WAVE_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
 	dprintf_mciwave(stddeb,
-		 "WAVE_mciSet // dwAudio=%08X\n", lpParms->dwAudio);
+		 "WAVE_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
 	if (dwFlags & MCI_SET_TIME_FORMAT) {
 		switch (lpParms->dwTimeFormat) {
 			case MCI_FORMAT_MILLISECONDS:
@@ -588,7 +588,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		"WAVE_mciStatus(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		"WAVE_mciStatus(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_STATUS_ITEM) {
 		switch(lpParms->dwItem) {
@@ -667,12 +667,12 @@
 				lpParms->dwReturn = 22050;
 				break;
 			default:
-				fprintf(stderr,"WAVE_mciStatus // unknown command %04X !\n", lpParms->dwItem);
+				fprintf(stderr,"WAVE_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
 				return MCIERR_UNRECOGNIZED_COMMAND;
 			}
 		}
 	if (dwFlags & MCI_NOTIFY) {
-  	        dprintf_mciwave(stddeb,"WAVE_mciStatus // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms->dwCallback);
+  	        dprintf_mciwave(stddeb,"WAVE_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		}
@@ -690,7 +690,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-	    "WAVE_mciGetDevCaps(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	    "WAVE_mciGetDevCaps(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_GETDEVCAPS_ITEM) {
 		switch(lpParms->dwItem) {
@@ -744,7 +744,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		"WAVE_mciInfo(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+		"WAVE_mciInfo(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	lpParms->lpstrReturn = NULL;
 	switch(dwFlags) {
@@ -790,7 +790,7 @@
 	int		dsp_stereo = 1;
 	int		bytespersmpl;
 	dprintf_mciwave(stddeb,
-		   "wodGetDevCaps(%u, %08X, %u);\n", wDevID, lpCaps, dwSize);
+		   "wodGetDevCaps(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
 	if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
 	audio = open (SOUND_DEV, O_WRONLY, 0);
 	if (audio == -1) return MMSYSERR_NOTENABLED;
@@ -837,7 +837,7 @@
 		}
 	close(audio);
 	dprintf_mciwave(stddeb,
-		"wodGetDevCaps // dwFormats = %08X\n", lpCaps->dwFormats);
+		"wodGetDevCaps // dwFormats = %08lX\n", lpCaps->dwFormats);
 	return MMSYSERR_NOERROR;
 #else
 	return MMSYSERR_NOTENABLED;
@@ -857,7 +857,7 @@
 	int			samplesize;
 	int			dsp_stereo;
 	dprintf_mciwave(stddeb,
-		     "wodOpen(%u, %08X, %08X);\n", wDevID, lpDesc, dwFlags);
+		     "wodOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
 	        fprintf(stderr,"Linux 'wodOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
@@ -925,7 +925,7 @@
 	IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo);
 	dprintf_mciwave(stddeb,"Linux 'wodOpen' // wBitsPerSample=%u !\n",
 				WOutDev[wDevID].Format.wBitsPerSample);
-	dprintf_mciwave(stddeb,"Linux 'wodOpen' // nSamplesPerSec=%u !\n",
+	dprintf_mciwave(stddeb,"Linux 'wodOpen' // nSamplesPerSec=%lu !\n",
 				WOutDev[wDevID].Format.wf.nSamplesPerSec);
 	dprintf_mciwave(stddeb,"Linux 'wodOpen' // nChannels=%u !\n",
 				WOutDev[wDevID].Format.wf.nChannels);
@@ -969,7 +969,7 @@
 DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
 {
 #ifdef linux
-        dprintf_mciwave(stddeb,"wodWrite(%u, %08X, %08X);\n", wDevID, lpWaveHdr, dwSize);
+        dprintf_mciwave(stddeb,"wodWrite(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WOutDev[wDevID].unixdev == 0) {
         fprintf(stderr,"Linux 'wodWrite' // can't play !\n");
 		return MMSYSERR_NOTENABLED;
@@ -980,7 +980,7 @@
 	lpWaveHdr->dwFlags &= ~WHDR_DONE;
 	lpWaveHdr->dwFlags |= WHDR_INQUEUE;
         dprintf_mciwave(stddeb,
-	   "wodWrite() // dwBytesRecorded %u !\n", lpWaveHdr->dwBytesRecorded);
+	   "wodWrite() // dwBytesRecorded %lu !\n", lpWaveHdr->dwBytesRecorded);
 	if (write (WOutDev[wDevID].unixdev, lpWaveHdr->lpData, 
 		lpWaveHdr->dwBytesRecorded) != lpWaveHdr->dwBytesRecorded) {
 		return MMSYSERR_NOTENABLED;
@@ -1004,7 +1004,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		  "wodPrepare(%u, %08X, %08X);\n", wDevID, lpWaveHdr, dwSize);
+		  "wodPrepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WOutDev[wDevID].unixdev == 0) {
                 fprintf(stderr,"Linux 'wodPrepare' // can't prepare !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1031,7 +1031,7 @@
 {
 #ifdef linux
         dprintf_mciwave(stddeb,
-		"wodUnprepare(%u, %08X, %08X);\n", wDevID, lpWaveHdr, dwSize);
+		"wodUnprepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WOutDev[wDevID].unixdev == 0) {
         fprintf(stderr,"Linux 'wodUnprepare' // can't unprepare !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1084,7 +1084,7 @@
 {
 #ifdef linux
 	int		time;
-	dprintf_mciwave(stddeb,"wodGetPosition(%u, %08X, %u);\n", wDevID, lpTime, uSize);
+	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");
 		return MMSYSERR_NOTENABLED;
@@ -1094,17 +1094,17 @@
 	switch(lpTime->wType) {
 		case TIME_BYTES:
 			lpTime->u.cb = WOutDev[wDevID].dwTotalPlayed;
-			dprintf_mciwave(stddeb,"wodGetPosition // TIME_BYTES=%u\n", lpTime->u.cb);
+			dprintf_mciwave(stddeb,"wodGetPosition // TIME_BYTES=%lu\n", lpTime->u.cb);
 			break;
 		case TIME_SAMPLES:
 			lpTime->u.sample = WOutDev[wDevID].dwTotalPlayed * 8 /
 						WOutDev[wDevID].Format.wBitsPerSample;
-			dprintf_mciwave(stddeb,"wodGetPosition // TIME_SAMPLES=%u\n", lpTime->u.sample);
+			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=%u\n", lpTime->u.ms);
+			dprintf_mciwave(stddeb,"wodGetPosition // TIME_MS=%lu\n", lpTime->u.ms);
 			break;
 		case TIME_SMPTE:
 			time = WOutDev[wDevID].dwTotalPlayed /
@@ -1141,7 +1141,7 @@
 #ifdef linux
 	int 	mixer;
 	int		volume;
-	dprintf_mciwave(stddeb,"wodGetVolume(%u, %08X);\n", wDevID, lpdwVol);
+	dprintf_mciwave(stddeb,"wodGetVolume(%u, %p);\n", wDevID, lpdwVol);
 	if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
 	if (WOutDev[wDevID].unixdev == 0) {
 		fprintf(stderr,"Linux 'wodGetVolume' // can't read volume !\n");
@@ -1172,7 +1172,7 @@
 #ifdef linux
 	int 	mixer;
 	int		volume;
-	dprintf_mciwave(stddeb,"wodSetVolume(%u, %08X);\n", wDevID, dwParam);
+	dprintf_mciwave(stddeb,"wodSetVolume(%u, %08lX);\n", wDevID, dwParam);
 	volume = LOWORD(dwParam);
 	if (WOutDev[wDevID].unixdev == 0) {
 		fprintf(stderr,"Linux 'wodSetVolume' // can't set volume !\n");
@@ -1200,7 +1200,7 @@
 DWORD wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2)
 {
-        dprintf_mciwave(stddeb,"wodMessage(%u, %04X, %08X, %08X, %08X);\n",
+        dprintf_mciwave(stddeb,"wodMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
 	switch(wMsg) {
 		case WODM_OPEN:
@@ -1258,7 +1258,7 @@
 	int		dsp_stereo = 1;
 	int		bytespersmpl;
 	dprintf_mciwave(stddeb,
-		  "widGetDevCaps(%u, %08X, %u);\n", wDevID, lpCaps, dwSize);
+		  "widGetDevCaps(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
 	if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
 	audio = open (SOUND_DEV, O_RDONLY, 0);
 	if (audio == -1) return MMSYSERR_NOTENABLED;
@@ -1303,7 +1303,7 @@
 		}
 	close(audio);
 	dprintf_mciwave(stddeb,
-		 "widGetDevCaps // dwFormats = %08X\n", lpCaps->dwFormats);
+		 "widGetDevCaps // dwFormats = %08lX\n", lpCaps->dwFormats);
 	return MMSYSERR_NOERROR;
 #else
 	return MMSYSERR_NOTENABLED;
@@ -1323,7 +1323,7 @@
 	int			samplesize;
 	int			dsp_stereo;
 	dprintf_mciwave(stddeb,
-		 "widOpen(%u, %08X, %08X);\n", wDevID, lpDesc, dwFlags);
+		 "widOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
                 fprintf(stderr,"Linux 'widOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
@@ -1393,11 +1393,11 @@
 	IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo);
 	dprintf_mciwave(stddeb,"Linux 'widOpen' // wBitsPerSample=%u !\n",
 				WInDev[wDevID].Format.wBitsPerSample);
-	dprintf_mciwave(stddeb,"Linux 'widOpen' // nSamplesPerSec=%u !\n",
+	dprintf_mciwave(stddeb,"Linux 'widOpen' // nSamplesPerSec=%lu !\n",
 				WInDev[wDevID].Format.wf.nSamplesPerSec);
 	dprintf_mciwave(stddeb,"Linux 'widOpen' // nChannels=%u !\n",
 				WInDev[wDevID].Format.wf.nChannels);
-	dprintf_mciwave(stddeb,"Linux 'widOpen' // nAvgBytesPerSec=%u\n",
+	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");
@@ -1442,7 +1442,7 @@
 	int			count	= 1;
 	LPWAVEHDR 	lpWIHdr;
 	dprintf_mciwave(stddeb,
-	       "widAddBuffer(%u, %08X, %08X);\n", wDevID, lpWaveHdr, dwSize);
+	       "widAddBuffer(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WInDev[wDevID].unixdev == 0) {
 	        fprintf(stderr,"Linux 'widAddBuffer' // can't do it !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1489,7 +1489,7 @@
 {
 #ifdef linux
 	dprintf_mciwave(stddeb,
-		"widPrepare(%u, %08X, %08X);\n", wDevID, lpWaveHdr, dwSize);
+		"widPrepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WInDev[wDevID].unixdev == 0) {
 	        fprintf(stderr,"Linux 'widPrepare' // can't prepare !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1519,7 +1519,7 @@
 {
 #ifdef linux
 	dprintf_mciwave(stddeb,
-		"widUnprepare(%u, %08X, %08X);\n", wDevID, lpWaveHdr, dwSize);
+		"widUnprepare(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
 	if (WInDev[wDevID].unixdev == 0) {
                 fprintf(stderr,"Linux 'widUnprepare' // can't unprepare !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1559,7 +1559,7 @@
 	while(lpWIHdr != NULL) {
 		lpWIHdr->dwBufferLength &= 0xFFFF;
                 dprintf_mciwave(stddeb,
-		        "widStart // recording buf#%u=%08X size=%u \n",
+		        "widStart // recording buf#%u=%p size=%lu \n",
 			count, lpWIHdr->lpData, lpWIHdr->dwBufferLength);
 		fflush(stddeb);
 		read (WInDev[wDevID].unixdev, lpWIHdr->lpData,
@@ -1627,7 +1627,7 @@
 #ifdef linux
 	int		time;
         dprintf_mciwave(stddeb,
-		"widGetPosition(%u, %08X, %u);\n", wDevID, lpTime, uSize);
+		"widGetPosition(%u, %p, %lu);\n", wDevID, lpTime, uSize);
 	if (WInDev[wDevID].unixdev == 0) {
                 fprintf(stderr,"Linux 'widGetPosition' // can't get pos !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1638,31 +1638,31 @@
 			lpTime->wType);
 	dprintf_mciwave(stddeb,"widGetPosition // wBitsPerSample=%u\n",
 			WInDev[wDevID].Format.wBitsPerSample); 
-	dprintf_mciwave(stddeb,"widGetPosition // nSamplesPerSec=%u\n",
+	dprintf_mciwave(stddeb,"widGetPosition // nSamplesPerSec=%lu\n",
 			WInDev[wDevID].Format.wf.nSamplesPerSec); 
 	dprintf_mciwave(stddeb,"widGetPosition // nChannels=%u\n",
 			WInDev[wDevID].Format.wf.nChannels); 
-	dprintf_mciwave(stddeb,"widGetPosition // nAvgBytesPerSec=%u\n",
+	dprintf_mciwave(stddeb,"widGetPosition // nAvgBytesPerSec=%lu\n",
 			WInDev[wDevID].Format.wf.nAvgBytesPerSec); 
 	fflush(stddeb);
 	switch(lpTime->wType) {
 		case TIME_BYTES:
 			lpTime->u.cb = WInDev[wDevID].dwTotalRecorded;
 			dprintf_mciwave(stddeb,
-			    "widGetPosition // TIME_BYTES=%u\n", lpTime->u.cb);
+			    "widGetPosition // TIME_BYTES=%lu\n", lpTime->u.cb);
 			break;
 		case TIME_SAMPLES:
 			lpTime->u.sample = WInDev[wDevID].dwTotalRecorded * 8 /
 					  WInDev[wDevID].Format.wBitsPerSample;
 			dprintf_mciwave(stddeb,
-					"widGetPosition // TIME_SAMPLES=%u\n", 
+					"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=%u\n", lpTime->u.ms);
+			      "widGetPosition // TIME_MS=%lu\n", lpTime->u.ms);
 			break;
 		case TIME_SMPTE:
 			time = WInDev[wDevID].dwTotalRecorded /
@@ -1696,7 +1696,7 @@
 DWORD widMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2)
 {
-        dprintf_mciwave(stddeb,"widMessage(%u, %04X, %08X, %08X, %08X);\n",
+        dprintf_mciwave(stddeb,"widMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
 	switch(wMsg) {
 		case WIDM_OPEN:
diff --git a/multimedia/mcianim.c b/multimedia/mcianim.c
index ce2ddc2..331ea52 100644
--- a/multimedia/mcianim.c
+++ b/multimedia/mcianim.c
@@ -66,10 +66,7 @@
 {
 #ifdef linux
 	UINT	wDevID;
-	int		cdrom;
-	dprintf_mcianim(stddeb,"ANIM_mciOpen(%08X, %08X);\n", 
-						dwFlags, lpParms);
-	printf("ANIM_mciOpen(%08X, %08X);\n", dwFlags, lpParms);
+	dprintf_mcianim(stddeb,"ANIM_mciOpen(%08lX, %p);\n", dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	wDevID = lpParms->wDeviceID;
 	if (AnimDev[wDevID].nUseCount > 0) {
@@ -101,7 +98,7 @@
 	AnimDev[wDevID].lpdwTrackPos = NULL;
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciOpen // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciOpen // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -118,11 +115,12 @@
 DWORD ANIM_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciClose(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciClose(%u, %08lX, %p);\n", 
 				wDevID, dwParam, lpParms);
 	if (AnimDev[wDevID].lpdwTrackLen != NULL) free(AnimDev[wDevID].lpdwTrackLen);
 	if (AnimDev[wDevID].lpdwTrackPos != NULL) free(AnimDev[wDevID].lpdwTrackPos);
 #endif
+        return 0;
 }
 
 /**************************************************************************
@@ -132,12 +130,12 @@
 						LPMCI_GETDEVCAPS_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciGetDevCaps(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciGetDevCaps(%u, %08lX, %p);\n", 
 				wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_GETDEVCAPS_ITEM) {
         	dprintf_mcianim(stddeb,
-		"ANIM_mciGetDevCaps // MCI_GETDEVCAPS_ITEM dwItem=%08X;\n",
+		"ANIM_mciGetDevCaps // MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n",
 				lpParms->dwItem);
 		switch(lpParms->dwItem) {
 			case MCI_GETDEVCAPS_CAN_RECORD:
@@ -172,7 +170,7 @@
 			}
 		}
 	dprintf_mcianim(stddeb,
-		"ANIM_mciGetDevCaps // lpParms->dwReturn=%08X;\n", 
+		"ANIM_mciGetDevCaps // lpParms->dwReturn=%08lX;\n", 
 		lpParms->dwReturn);
  	return 0;
 #else
@@ -186,7 +184,7 @@
 DWORD ANIM_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciInfo(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciInfo(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	lpParms->lpstrReturn = NULL;
@@ -220,12 +218,12 @@
 DWORD ANIM_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciStatus(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciStatus(%u, %08lX, %p);\n", 
 			wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciStatus // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -234,11 +232,11 @@
 		switch(lpParms->dwItem) {
 			case MCI_STATUS_CURRENT_TRACK:
 				lpParms->dwReturn = AnimDev[wDevID].nCurTrack;
-				dprintf_mcianim(stddeb,"ANIM_mciStatus // CURRENT_TRACK=%u!\n", lpParms->dwReturn);
+				dprintf_mcianim(stddeb,"ANIM_mciStatus // CURRENT_TRACK=%lu!\n", lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_LENGTH:
 				if (dwFlags & MCI_TRACK) {
-					dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_TRACK #%u LENGTH=??? !\n",
+					dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_TRACK #%lu LENGTH=??? !\n",
 														lpParms->dwTrack);
 					if (lpParms->dwTrack > AnimDev[wDevID].nTracks)
 						return MCIERR_OUTOFRANGE;
@@ -248,11 +246,11 @@
 					lpParms->dwReturn = AnimDev[wDevID].dwTotalLen;
 				lpParms->dwReturn = ANIM_CalcTime(wDevID, 
 					AnimDev[wDevID].dwTimeFormat, lpParms->dwReturn);
-                		dprintf_mcianim(stddeb,"ANIM_mciStatus // LENGTH=%u !\n", lpParms->dwReturn);
+                		dprintf_mcianim(stddeb,"ANIM_mciStatus // LENGTH=%lu !\n", lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_MODE:
 				lpParms->dwReturn = AnimDev[wDevID].mode;
-				dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_STATUS_MODE=%08X !\n",
+				dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_STATUS_MODE=%08lX !\n",
 												lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_MEDIA_PRESENT:
@@ -261,7 +259,7 @@
 			 	return 0;
 			case MCI_STATUS_NUMBER_OF_TRACKS:
 				lpParms->dwReturn = 1;
-				dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %u !\n",
+				dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n",
 											lpParms->dwReturn);
 				if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL;
 			 	return 0;
@@ -275,11 +273,11 @@
 					if (lpParms->dwTrack > AnimDev[wDevID].nTracks)
 						return MCIERR_OUTOFRANGE;
 					lpParms->dwReturn = AnimDev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1];
-					dprintf_mcianim(stddeb,"ANIM_mciStatus // get MCI_TRACK #%u !\n", lpParms->dwTrack);
+					dprintf_mcianim(stddeb,"ANIM_mciStatus // get MCI_TRACK #%lu !\n", lpParms->dwTrack);
 					}
 				lpParms->dwReturn = ANIM_CalcTime(wDevID, 
 					AnimDev[wDevID].dwTimeFormat, lpParms->dwReturn);
-					dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_STATUS_POSITION=%08X !\n",
+					dprintf_mcianim(stddeb,"ANIM_mciStatus // MCI_STATUS_POSITION=%08lX !\n",
 														lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_READY:
@@ -291,7 +289,7 @@
 				lpParms->dwReturn = MCI_FORMAT_MILLISECONDS;
 			 	return 0;
 			default:
-				fprintf(stderr,"ANIM_mciStatus // unknown command %04X !\n", lpParms->dwItem);
+				fprintf(stderr,"ANIM_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
 				return MCIERR_UNRECOGNIZED_COMMAND;
 			}
 		}
@@ -314,14 +312,14 @@
 	UINT	wMinutes;
 	UINT	wSeconds;
 	UINT	wFrames;
-	dprintf_mcianim(stddeb,"ANIM_CalcTime(%u, %08X, %lu);\n", 
+	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 %u\n", dwTime);
+				"ANIM_CalcTime // MILLISECONDS %lu\n", dwTime);
 			break;
 		case MCI_FORMAT_MSF:
 			wMinutes = dwFrame / ANIMFRAMES_PERMIN;
@@ -329,7 +327,7 @@
 			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=%u\n",
+			dprintf_mcianim(stddeb,"ANIM_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
 								wMinutes, wSeconds, wFrames, dwTime);
 			break;
 		case MCI_FORMAT_TMSF:
@@ -366,14 +364,14 @@
 	DWORD	dwFrame = 0;
 #ifdef linux
 	UINT	wTrack;
-	dprintf_mcianim(stddeb,"ANIM_CalcFrame(%u, %08X, %lu);\n", 
+	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 %u\n", dwFrame);
+				"ANIM_CalcFrame // MILLISECONDS %lu\n", dwFrame);
 			break;
 		case MCI_FORMAT_MSF:
 			dprintf_mcianim(stddeb,
@@ -391,7 +389,7 @@
 				MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), 
 				MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
 			dprintf_mcianim(stddeb,
-				"ANIM_CalcFrame // TMSF trackpos[%u]=%u\n",
+				"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);
@@ -416,29 +414,28 @@
 {
 #ifdef linux
 	int 	start, end;
-	dprintf_mcianim(stddeb,"ANIM_mciPlay(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciPlay(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
-	printf("ANIM_mciPlay(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	start = 0; 		end = AnimDev[wDevID].dwTotalLen;
 	AnimDev[wDevID].nCurTrack = 1;
 	if (dwFlags & MCI_FROM) {
 		start = ANIM_CalcFrame(wDevID, 
 			AnimDev[wDevID].dwTimeFormat, lpParms->dwFrom); 
-        dprintf_mcianim(stddeb,"ANIM_mciPlay // MCI_FROM=%08X -> %u \n",
+        dprintf_mcianim(stddeb,"ANIM_mciPlay // MCI_FROM=%08lX -> %u \n",
 				lpParms->dwFrom, start);
 		}
 	if (dwFlags & MCI_TO) {
 		end = ANIM_CalcFrame(wDevID, 
 			AnimDev[wDevID].dwTimeFormat, lpParms->dwTo);
         	dprintf_mcianim(stddeb,
-			"ANIM_mciPlay // MCI_TO=%08X -> %u \n",
+			"ANIM_mciPlay // MCI_TO=%08lX -> %u \n",
 			lpParms->dwTo, end);
 		}
 	AnimDev[wDevID].mode = MCI_MODE_PLAY;
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciPlay // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -455,13 +452,13 @@
 DWORD ANIM_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciStop(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciStop(%u, %08lX, %p);\n", 
 			wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	AnimDev[wDevID].mode = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciStop // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciStop // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -478,13 +475,13 @@
 DWORD ANIM_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciPause(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciPause(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	AnimDev[wDevID].mode = MCI_MODE_PAUSE;
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciPause // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciPause // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -501,13 +498,13 @@
 DWORD ANIM_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciResume(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciResume(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	AnimDev[wDevID].mode = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciResume // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciResume // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -526,7 +523,7 @@
 #ifdef linux
 	DWORD	dwRet;
 	MCI_PLAY_PARMS PlayParms;
-	dprintf_mcianim(stddeb,"ANIM_mciSeek(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciSeek(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	AnimDev[wDevID].mode = MCI_MODE_SEEK;
@@ -546,7 +543,7 @@
 	dwRet = ANIM_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms);
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciSeek // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciSeek // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -564,12 +561,12 @@
 DWORD ANIM_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
 #ifdef linux
-	dprintf_mcianim(stddeb,"ANIM_mciSet(%u, %08X, %08X);\n", 
+	dprintf_mcianim(stddeb,"ANIM_mciSet(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 /*
-	printf("ANIM_mciSet // dwTimeFormat=%08X\n", lpParms->dwTimeFormat);
-	printf("ANIM_mciSet // dwAudio=%08X\n", lpParms->dwAudio);
+	printf("ANIM_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
+	printf("ANIM_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
 */
 	if (dwFlags & MCI_SET_TIME_FORMAT) {
 		switch (lpParms->dwTimeFormat) {
@@ -594,7 +591,7 @@
 	if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION;
 	if (dwFlags & MCI_NOTIFY) {
 		dprintf_mcianim(stddeb,
-			"ANIM_mciSet // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"ANIM_mciSet // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
diff --git a/multimedia/mcicda.c b/multimedia/mcicda.c
index 6775335..1339f1d 100644
--- a/multimedia/mcicda.c
+++ b/multimedia/mcicda.c
@@ -85,8 +85,7 @@
 {
 #ifdef linux
 	UINT	wDevID;
-	int		cdrom;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen(%08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen(%08lX, %p);\n", 
 		dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	wDevID = lpParms->wDeviceID;
@@ -128,7 +127,7 @@
 		}
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciOpen // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"CDAUDIO_mciOpen // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -145,12 +144,13 @@
 DWORD CDAUDIO_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciClose(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciClose(%u, %08lX, %p);\n", 
 		wDevID, dwParam, lpParms);
 	if (CDADev[wDevID].lpdwTrackLen != NULL) free(CDADev[wDevID].lpdwTrackLen);
 	if (CDADev[wDevID].lpdwTrackPos != NULL) free(CDADev[wDevID].lpdwTrackPos);
 	close(CDADev[wDevID].unixdev);
 #endif
+        return 0;
 }
 
 /**************************************************************************
@@ -160,12 +160,12 @@
 						LPMCI_GETDEVCAPS_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciGetDevCaps(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciGetDevCaps(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_GETDEVCAPS_ITEM) {
         	dprintf_cdaudio(stddeb,
-		"CDAUDIO_mciGetDevCaps // MCI_GETDEVCAPS_ITEM dwItem=%08X;\n",
+		"CDAUDIO_mciGetDevCaps // MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n",
 				lpParms->dwItem);
 		switch(lpParms->dwItem) {
 			case MCI_GETDEVCAPS_CAN_RECORD:
@@ -200,7 +200,7 @@
 			}
 		}
     	dprintf_cdaudio(stddeb,
-		"CDAUDIO_mciGetDevCaps // lpParms->dwReturn=%08X;\n", 
+		"CDAUDIO_mciGetDevCaps // lpParms->dwReturn=%08lX;\n", 
 		lpParms->dwReturn);
  	return 0;
 #else
@@ -214,7 +214,7 @@
 DWORD CDAUDIO_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciInfo(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciInfo(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	lpParms->lpstrReturn = NULL;
@@ -241,13 +241,13 @@
 DWORD CDAUDIO_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciStatus // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"CDAUDIO_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -257,7 +257,7 @@
 			case MCI_STATUS_CURRENT_TRACK:
 				if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
 				lpParms->dwReturn = CDADev[wDevID].nCurTrack;
-                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // CURRENT_TRACK=%u!\n", lpParms->dwReturn);
+                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // CURRENT_TRACK=%lu!\n", lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_LENGTH:
 				if (CDADev[wDevID].nTracks == 0) {
@@ -267,7 +267,7 @@
 						}
 					}
 				if (dwFlags & MCI_TRACK) {
-                    			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_TRACK #%u LENGTH=??? !\n",
+                    			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_TRACK #%lu LENGTH=??? !\n",
 														lpParms->dwTrack);
 					if (lpParms->dwTrack > CDADev[wDevID].nTracks)
 						return MCIERR_OUTOFRANGE;
@@ -277,12 +277,12 @@
 					lpParms->dwReturn = CDADev[wDevID].dwTotalLen;
 				lpParms->dwReturn = CDAUDIO_CalcTime(wDevID, 
 					CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
-                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // LENGTH=%u !\n", lpParms->dwReturn);
+                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // LENGTH=%lu !\n", lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_MODE:
 				if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
 				lpParms->dwReturn = CDADev[wDevID].mode;
-                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MODE=%08X !\n",
+                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MODE=%08lX !\n",
 												lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_MEDIA_PRESENT:
@@ -294,7 +294,7 @@
 			 	return 0;
 			case MCI_STATUS_NUMBER_OF_TRACKS:
 				lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(wDevID);
-                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %u !\n",
+                		dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n",
 													lpParms->dwReturn);
 				if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL;
 			 	return 0;
@@ -309,11 +309,11 @@
 					if (lpParms->dwTrack > CDADev[wDevID].nTracks)
 						return MCIERR_OUTOFRANGE;
 					lpParms->dwReturn = CDADev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1];
-                    			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_TRACK #%u !\n", lpParms->dwTrack);
+                    			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_TRACK #%lu !\n", lpParms->dwTrack);
 					}
 				lpParms->dwReturn = CDAUDIO_CalcTime(wDevID, 
 					CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
-                			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_POSITION=%08X !\n",
+                			dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_POSITION=%08lX !\n",
 														lpParms->dwReturn);
 			 	return 0;
 			case MCI_STATUS_READY:
@@ -325,7 +325,7 @@
 				lpParms->dwReturn = MCI_FORMAT_MILLISECONDS;
 			 	return 0;
 			default:
-                		fprintf(stderr,"CDAUDIO_mciStatus // unknown command %04X !\n", lpParms->dwItem);
+                		fprintf(stderr,"CDAUDIO_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
 				return MCIERR_UNRECOGNIZED_COMMAND;
 			}
 		}
@@ -348,14 +348,14 @@
 	UINT	wMinutes;
 	UINT	wSeconds;
 	UINT	wFrames;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime(%u, %08X, %lu);\n", 
+    	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 %u\n", 
+				"CDAUDIO_CalcTime // MILLISECONDS %lu\n", 
 				dwTime);
 			break;
 		case MCI_FORMAT_MSF:
@@ -364,7 +364,7 @@
 			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=%u\n",
+            		dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
 								wMinutes, wSeconds, wFrames, dwTime);
 			break;
 		case MCI_FORMAT_TMSF:
@@ -401,14 +401,14 @@
 	DWORD	dwFrame = 0;
 #ifdef linux
 	UINT	wTrack;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_CalcFrame(%u, %08X, %lu);\n", 
+    	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 %u\n", 
+				"CDAUDIO_CalcFrame // MILLISECONDS %lu\n", 
 				dwFrame);
 			break;
 		case MCI_FORMAT_MSF:
@@ -427,7 +427,7 @@
 					MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), 
 					MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
             		dprintf_cdaudio(stddeb,
-				"CDAUDIO_CalcFrame // TMSF trackpos[%u]=%u\n",
+				"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);
@@ -605,7 +605,7 @@
 #ifdef linux
 	int 	start, end;
 	struct 	cdrom_msf	msf;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
@@ -614,14 +614,14 @@
 	if (dwFlags & MCI_FROM) {
 		start = CDAUDIO_CalcFrame(wDevID, 
 			CDADev[wDevID].dwTimeFormat, lpParms->dwFrom); 
-        dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // MCI_FROM=%08X -> %u \n",
+        dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // MCI_FROM=%08lX -> %u \n",
 				lpParms->dwFrom, start);
 		}
 	if (dwFlags & MCI_TO) {
 		end = CDAUDIO_CalcFrame(wDevID, 
 			CDADev[wDevID].dwTimeFormat, lpParms->dwTo);
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciPlay // MCI_TO=%08X -> %u \n",
+			"CDAUDIO_mciPlay // MCI_TO=%08lX -> %u \n",
 			lpParms->dwTo, end);
 		}
 	start += CDADev[wDevID].dwFirstOffset;	
@@ -646,7 +646,7 @@
 	CDADev[wDevID].mode = MCI_MODE_PLAY;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciPlay // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"CDAUDIO_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -663,14 +663,14 @@
 DWORD CDAUDIO_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciStop(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciStop(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (ioctl(CDADev[wDevID].unixdev, CDROMSTOP)) return MCIERR_HARDWARE;
 	CDADev[wDevID].mode = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciStop // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"CDAUDIO_mciStop // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -687,14 +687,14 @@
 DWORD CDAUDIO_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciPause(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciPause(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (ioctl(CDADev[wDevID].unixdev, CDROMPAUSE)) return MCIERR_HARDWARE;
 	CDADev[wDevID].mode = MCI_MODE_PAUSE;
 	if (dwFlags & MCI_NOTIFY) {
         dprintf_cdaudio(stddeb,
-		"CDAUDIO_mciPause // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+		"CDAUDIO_mciPause // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 		lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -711,14 +711,14 @@
 DWORD CDAUDIO_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciResume(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciResume(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (ioctl(CDADev[wDevID].unixdev, CDROMRESUME)) return MCIERR_HARDWARE;
 	CDADev[wDevID].mode = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciResume // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"CDAUDIO_mciResume // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -737,7 +737,7 @@
 #ifdef linux
 	DWORD	dwRet;
 	MCI_PLAY_PARMS PlayParms;
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciSeek(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciSeek(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (ioctl(CDADev[wDevID].unixdev, CDROMRESUME)) return MCIERR_HARDWARE;
@@ -758,7 +758,7 @@
 	dwRet = CDAUDIO_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms);
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciSeek // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"CDAUDIO_mciSeek // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -776,12 +776,12 @@
 DWORD CDAUDIO_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
 #ifdef linux
-    	dprintf_cdaudio(stddeb,"CDAUDIO_mciSet(%u, %08X, %08X);\n", 
+    	dprintf_cdaudio(stddeb,"CDAUDIO_mciSet(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 /*
-	printf("CDAUDIO_mciSet // dwTimeFormat=%08X\n", lpParms->dwTimeFormat);
-	printf("CDAUDIO_mciSet // dwAudio=%08X\n", lpParms->dwAudio);
+	printf("CDAUDIO_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
+	printf("CDAUDIO_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
 */
 	if (dwFlags & MCI_SET_TIME_FORMAT) {
 		switch (lpParms->dwTimeFormat) {
@@ -818,7 +818,7 @@
 	if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
-			"CDAUDIO_mciSet // MCI_NOTIFY_SUCCESSFUL %08X !\n", 
+			"CDAUDIO_mciSet // MCI_NOTIFY_SUCCESSFUL %08lX !\n", 
 			lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
diff --git a/multimedia/midi.c b/multimedia/midi.c
index df24045..05f271b 100644
--- a/multimedia/midi.c
+++ b/multimedia/midi.c
@@ -12,20 +12,19 @@
 #ifdef BUILTIN_MMSYSTEM
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
 #include "win.h"
 #include "user.h"
 #include "driver.h"
 #include "mmsystem.h"
-#include <fcntl.h>
-#include <sys/ioctl.h>
 
 #include "stddebug.h"
 /* #define DEBUG_MIDI */
-
-#define DEBUG_MIDI
 #include "debug.h"
 
-
 #ifdef linux
 #include <linux/soundcard.h>
 #endif
@@ -122,6 +121,7 @@
 		printf("MIDI_NotifyClient // can't notify client !\n");
 		return MMSYSERR_NOERROR;
 		}
+        return 0;
 #else
 	return MMSYSERR_NOTENABLED;
 #endif
@@ -196,6 +196,7 @@
 */
 DWORD MIDI_ReadByte(UINT wDevID, BYTE FAR *lpbyt)
 {
+#ifdef linux
 	if (lpbyt != NULL) {
 		if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)lpbyt,
 			(long) sizeof(BYTE)) == (long) sizeof(BYTE)) {
@@ -204,6 +205,10 @@
 		}
 	printf("MIDI_ReadByte // error reading wDevID=%d \n", wDevID);
 	return MCIERR_INTERNAL;
+
+#else
+        return MMSYSERR_NOTENABLED;
+#endif
 }
 
 
@@ -232,7 +237,6 @@
 DWORD MIDI_ReadLong(UINT wDevID, LPDWORD lpdw)
 {
 	WORD	hiword, loword;
-	BYTE	hibyte, lobyte;
 	if (lpdw != NULL) {
 		if (MIDI_ReadWord(wDevID, &hiword) == 0) {
 			if (MIDI_ReadWord(wDevID, &loword) == 0) {
@@ -279,11 +283,12 @@
 */
 DWORD MIDI_ReadMThd(UINT wDevID, DWORD dwOffset)
 {
+#ifdef linux
 	DWORD	toberead;
 	FOURCC	fourcc;
-	dprintf_midi(stddeb, "MIDI_ReadMThd(%04X, %08X);\n", wDevID, dwOffset);
+	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 %08X begin of 'MThd' \n", dwOffset);
+		printf("MIDI_ReadMThd // can't seek at %08lX begin of 'MThd' \n", dwOffset);
 		return MCIERR_INTERNAL;
 		}
 	if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc,
@@ -302,7 +307,7 @@
 	if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].nTempo) != 0) {
 		return MCIERR_INTERNAL;
 		}
-	printf("MIDI_ReadMThd // toberead=%08X, wFormat=%04X nTracks=%04X nTempo=%04X\n",
+	printf("MIDI_ReadMThd // toberead=%08lX, wFormat=%04X nTracks=%04X nTempo=%04X\n",
 		toberead, MCIMidiDev[wDevID].wFormat,
 		MCIMidiDev[wDevID].nTracks,
 		MCIMidiDev[wDevID].nTempo);
@@ -312,15 +317,20 @@
 		Mf_division = division = read16bit ();
 */
 	return 0;
+
+#else
+         return MMSYSERR_NOTENABLED;
+#endif
 }
 
 
 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 %08X begin of 'MThd' \n", dwOffset);
+		printf("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)) {
@@ -329,10 +339,13 @@
 	if (MIDI_ReadLong(wDevID, &toberead) != 0) {
 		return MCIERR_INTERNAL;
 		}
-	printf("MIDI_ReadMTrk // toberead=%08X\n", toberead);
+	printf("MIDI_ReadMTrk // toberead=%08lX\n", toberead);
 	toberead -= 3 * sizeof(WORD);
 	MCIMidiDev[wDevID].dwTotalLen = toberead;
 	return 0;
+#else
+         return MMSYSERR_NOTENABLED;
+#endif
 }
 
 
@@ -342,18 +355,13 @@
 DWORD MIDI_mciOpen(DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
 {
 #ifdef linux
-	int			hFile;
 	UINT 		wDevID;
-	OFSTRUCT	OFstruct;
 	MIDIOPENDESC 	MidiDesc;
 	DWORD		dwRet;
 	DWORD		dwOffset;
 	char		str[128];
-	LPSTR		ptr;
-	DWORD		toberead;
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciOpen(%08X, %08X)\n", dwFlags, lpParms);
-#endif
+
+	dprintf_midi( stddeb, "MIDI_mciOpen(%08lX, %p)\n", dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	wDevID = lpParms->wDeviceID;
 	if (MCIMidiDev[wDevID].nUseCount > 0) {
@@ -394,16 +402,13 @@
 	MCIMidiDev[wDevID].dwTotalLen = 0;
 	MidiDesc.hMidi = 0;
 	if (MCIMidiDev[wDevID].hFile != 0) {
-		MMCKINFO	mmckInfo;
 		MMCKINFO	ckMainRIFF;
 		if (mmioDescend(MCIMidiDev[wDevID].hFile, &ckMainRIFF, NULL, 0) != 0) {
 			return MCIERR_INTERNAL;
 			}
-#ifdef DEBUG_MIDI
-		printf("MIDI_mciOpen // ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
+		dprintf_midi(stddeb,"MIDI_mciOpen // ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
 				(LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType,
 				ckMainRIFF.cksize);
-#endif
 		dwOffset = 0;
 		if (ckMainRIFF.ckid == mmioFOURCC('R', 'M', 'I', 'D')) {
 			printf("MIDI_mciOpen // is a 'RMID' file \n");
@@ -424,11 +429,9 @@
 			}
 		dwOffset = mmioSeek(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR);
 		MCIMidiDev[wDevID].dwBeginData = dwOffset;
-#ifdef DEBUG_MIDI
-		printf("MIDI_mciOpen // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
-				(LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType,
-				mmckInfo.cksize);
-#endif
+		dprintf_midi(stddeb,"MIDI_mciOpen // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
+				(LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType,
+				ckMainRIFF.cksize);
 		}
 	dwRet = modMessage(0, MODM_OPEN, 0, (DWORD)&MidiDesc, CALLBACK_NULL);
 	dwRet = midMessage(0, MIDM_OPEN, 0, (DWORD)&MidiDesc, CALLBACK_NULL);
@@ -447,7 +450,7 @@
 #ifdef linux
 	DWORD		dwRet;
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciClose(%u, %08X, %08X);\n", wDevID, dwParam, lpParms);
+	printf("MIDI_mciClose(%u, %08lX, %p);\n", wDevID, dwParam, lpParms);
 #endif
 	if (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
 		MIDI_mciStop(wDevID, MCI_WAIT, lpParms);
@@ -485,7 +488,7 @@
 	LPWORD		ptr;
 	DWORD		dwRet;
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciPlay(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciPlay(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 #endif
 	if (MCIMidiDev[wDevID].hFile == 0) {
 		printf("MIDI_mciPlay // can't find file='%s' !\n", 
@@ -503,7 +506,7 @@
 		}
 /**/
 	if (dwFlags & MCI_NOTIFY) {
-		printf("MIDI_mciPlay // MCI_NOTIFY %08X !\n", lpParms->dwCallback);
+		printf("MIDI_mciPlay // MCI_NOTIFY %08lX !\n", lpParms->dwCallback);
 		switch(fork()) {
 			case -1:
 				printf("MIDI_mciPlay // Can't 'fork' process !\n");
@@ -540,7 +543,7 @@
 		if (count < 1) break;
 		lpMidiHdr->dwBytesRecorded = count;
 #ifdef DEBUG_MIDI
-		printf("MIDI_mciPlay // before MODM_LONGDATA lpMidiHdr=%08X dwBytesRecorded=%u\n",
+		printf("MIDI_mciPlay // before MODM_LONGDATA lpMidiHdr=%p dwBytesRecorded=%lu\n",
 					lpMidiHdr, lpMidiHdr->dwBytesRecorded);
 #endif
 		dwRet = modMessage(0, MODM_LONGDATA, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
@@ -553,7 +556,7 @@
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
 #ifdef DEBUG_MIDI
-		printf("MIDI_mciPlay // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms->dwCallback);
+		printf("MIDI_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 #endif
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -572,13 +575,11 @@
 DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
 {
 #ifdef linux
-	int			count;
 	int			start, end;
 	LPMIDIHDR	lpMidiHdr;
 	DWORD		dwRet;
-#ifdef DEBUG_MIDI
-	printf("MIDI_mciRecord(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
-#endif
+
+	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", 
 				MCIMidiDev[wDevID].openParms.lpstrElementName);
@@ -606,7 +607,7 @@
 			&MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
 		lpMidiHdr->dwBytesRecorded = 0;
 		dwRet = midMessage(0, MIDM_START, 0, 0L, 0L);
-		printf("MIDI_mciRecord // after MIDM_START lpMidiHdr=%08X dwBytesRecorded=%u\n",
+		printf("MIDI_mciRecord // after MIDM_START lpMidiHdr=%p dwBytesRecorded=%lu\n",
 					lpMidiHdr, lpMidiHdr->dwBytesRecorded);
 		if (lpMidiHdr->dwBytesRecorded == 0) break;
 		}
@@ -620,7 +621,7 @@
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
 #ifdef DEBUG_MIDI
-		printf("MIDI_mciRecord // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms->dwCallback);
+		printf("MIDI_mciRecord // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 #endif
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
@@ -639,7 +640,7 @@
 {
 #ifdef linux
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciStop(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciStop(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 #endif
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
@@ -659,7 +660,7 @@
 {
 #ifdef linux
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciPause(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciPause(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 #endif
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
@@ -676,7 +677,7 @@
 {
 #ifdef linux
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciResume(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciResume(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 #endif
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
@@ -693,12 +694,12 @@
 {
 #ifdef linux
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciSet(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciSet(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 #endif
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciSet // dwTimeFormat=%08X\n", lpParms->dwTimeFormat);
-	printf("MIDI_mciSet // dwAudio=%08X\n", lpParms->dwAudio);
+	printf("MIDI_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
+	printf("MIDI_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
 #endif
 	if (dwFlags & MCI_SET_TIME_FORMAT) {
 		switch (lpParms->dwTimeFormat) {
@@ -763,7 +764,7 @@
 {
 #ifdef linux
 #ifdef DEBUG_MIDI
-	printf("MIDI_mciStatus(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciStatus(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 #endif
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_STATUS_ITEM) {
@@ -831,12 +832,12 @@
 				lpParms->dwReturn = 0;
 				break;
 			default:
-				printf("MIDI_mciStatus // unknowm command %04X !\n", lpParms->dwItem);
+				printf("MIDI_mciStatus // unknowm command %08lX !\n", lpParms->dwItem);
 				return MCIERR_UNRECOGNIZED_COMMAND;
 			}
 		}
 	if (dwFlags & MCI_NOTIFY) {
-		printf("MIDI_mciStatus // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms->dwCallback);
+		printf("MIDI_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
 		mciDriverNotify((HWND)LOWORD(lpParms->dwCallback), 
 			MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
 		}
@@ -853,7 +854,7 @@
 					LPMCI_GETDEVCAPS_PARMS lpParms)
 {
 #ifdef linux
-	printf("MIDI_mciGetDevCaps(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciGetDevCaps(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_GETDEVCAPS_ITEM) {
 		switch(lpParms->dwItem) {
@@ -900,7 +901,7 @@
 DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
 #ifdef linux
-	printf("MIDI_mciInfo(%u, %08X, %08X);\n", wDevID, dwFlags, lpParms);
+	printf("MIDI_mciInfo(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	lpParms->lpstrReturn = NULL;
 	switch(dwFlags) {
@@ -932,7 +933,7 @@
 */
 DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPS lpCaps, DWORD dwSize)
 {
-	printf("midGetDevCaps(%u, %08X, %08X);\n", wDevID, lpCaps, dwSize);
+	printf("midGetDevCaps(%u, %p, %08lX);\n", wDevID, lpCaps, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -944,7 +945,7 @@
 #ifdef linux
 	int		midi;
 	dprintf_midi(stddeb,
-		"midOpen(%u, %08X, %08X);\n", wDevID, lpDesc, dwFlags);
+		"midOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
 		fprintf(stderr,"Linux 'midOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
@@ -1020,7 +1021,7 @@
 */
 DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-	printf("midAddBuffer(%u, %08X, %08X);\n", wDevID, lpMidiHdr, dwSize);
+	printf("midAddBuffer(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1029,7 +1030,7 @@
 */
 DWORD midPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-	printf("midPrepare(%u, %08X, %08X);\n", wDevID, lpMidiHdr, dwSize);
+	printf("midPrepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1038,7 +1039,7 @@
 */
 DWORD midUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-	printf("midUnprepare(%u, %08X, %08X);\n", wDevID, lpMidiHdr, dwSize);
+	printf("midUnprepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1078,7 +1079,7 @@
 DWORD midMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2)
 {
-	printf("midMessage(%u, %04X, %08X, %08X, %08X);\n", 
+	printf("midMessage(%u, %04X, %08lX, %08lX, %08lX);\n", 
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
 	switch(wMsg) {
 		case MIDM_OPEN:
@@ -1115,7 +1116,7 @@
 */
 DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPS lpCaps, DWORD dwSize)
 {
-	printf("modGetDevCaps(%u, %08X, %08X);\n", wDevID, lpCaps, dwSize);
+	printf("modGetDevCaps(%u, %p, %08lX);\n", wDevID, lpCaps, dwSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1128,7 +1129,7 @@
 #ifdef linux
 	int		midi;
 	dprintf_midi(stddeb,
-		"modOpen(%u, %08X, %08X);\n", wDevID, lpDesc, dwFlags);
+		"modOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
 	if (lpDesc == NULL) {
 		fprintf(stderr,"Linux 'modOpen' // Invalid Parameter !\n");
 		return MMSYSERR_INVALPARAM;
@@ -1207,9 +1208,10 @@
 */
 DWORD modData(WORD wDevID, DWORD dwParam)
 {
+#ifdef linux
 	WORD	event;
 	dprintf_midi(stddeb,	
-		"modData(%u, %08X);\n", wDevID, dwParam);
+		"modData(%u, %08lX);\n", wDevID, dwParam);
 	if (MidiOutDev[wDevID].unixdev == 0) {
         fprintf(stderr,"Linux 'modData' // can't play !\n");
 		return MIDIERR_NODEVICE;
@@ -1221,6 +1223,9 @@
 			"modData() // error writting unixdev !\n");
 		}
 	return MMSYSERR_NOTENABLED;
+#else
+        return MMSYSERR_NOTENABLED;
+#endif
 }
 
 /**************************************************************************
@@ -1232,8 +1237,8 @@
 	int		count;
 	LPWORD	ptr;
 	dprintf_midi(stddeb,	
-		"modLongData(%u, %08X, %08X);\n", wDevID, lpMidiHdr, dwSize);
-	printf("modLongData(%u, %08X, %08X);\n", wDevID, lpMidiHdr, dwSize);
+		"modLongData(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
+	printf("modLongData(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
         fprintf(stderr,"Linux 'modLongData' // can't play !\n");
 		return MIDIERR_NODEVICE;
@@ -1244,7 +1249,7 @@
 	lpMidiHdr->dwFlags &= ~MHDR_DONE;
 	lpMidiHdr->dwFlags |= MHDR_INQUEUE;
 	dprintf_midi(stddeb,
-		"modLongData() // dwBytesRecorded %u !\n", lpMidiHdr->dwBytesRecorded);
+		"modLongData() // dwBytesRecorded %lu !\n", lpMidiHdr->dwBytesRecorded);
 /*
 	count = write (MidiOutDev[wDevID].unixdev, 
 		lpMidiHdr->lpData, lpMidiHdr->dwBytesRecorded);
@@ -1257,7 +1262,7 @@
 		}
 	if (count != lpMidiHdr->dwBytesRecorded) {
 		dprintf_midi(stddeb,
-			"modLongData() // error writting unixdev #%d ! (%d != %d)\n",
+			"modLongData() // error writting unixdev #%d ! (%d != %ld)\n",
 			MidiOutDev[wDevID].unixdev, count, lpMidiHdr->dwBytesRecorded);
 		return MMSYSERR_NOTENABLED;
 		}
@@ -1280,7 +1285,7 @@
 {
 #ifdef linux
 	dprintf_midi(stddeb,
-		  "modPrepare(%u, %08X, %08X);\n", wDevID, lpMidiHdr, dwSize);
+		  "modPrepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
 		fprintf(stderr,"Linux 'modPrepare' // can't prepare !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1307,7 +1312,7 @@
 {
 #ifdef linux
 	dprintf_midi(stddeb,
-		"modUnprepare(%u, %08X, %08X);\n", wDevID, lpMidiHdr, dwSize);
+		"modUnprepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
 		fprintf(stderr,"Linux 'modUnprepare' // can't unprepare !\n");
 		return MMSYSERR_NOTENABLED;
@@ -1333,7 +1338,7 @@
 */
 DWORD modGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
 {
-	printf("modGetposition(%u, %08X, %08X);\n", wDevID, lpTime, uSize);
+	printf("modGetposition(%u, %p, %08lX);\n", wDevID, lpTime, uSize);
 	return MMSYSERR_NOTENABLED;
 }
 
@@ -1344,7 +1349,7 @@
 DWORD modMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2)
 {
-	printf("modMessage(%u, %04X, %08X, %08X, %08X);\n", 
+	printf("modMessage(%u, %04X, %08lX, %08lX, %08lX);\n", 
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
 	switch(wMsg) {
 		case MODM_OPEN:
@@ -1376,5 +1381,4 @@
 
 /*-----------------------------------------------------------------------*/
 
-
 #endif /* #ifdef BUILTIN_MMSYSTEM */
diff --git a/multimedia/mmaux.c b/multimedia/mmaux.c
index a3ab0a8..ea19e54 100644
--- a/multimedia/mmaux.c
+++ b/multimedia/mmaux.c
@@ -48,7 +48,7 @@
 #ifdef linux
 	int 	mixer;
 	int		volume;
-	printf("AUX_GetDevCaps(%u, %08X, %u);\n", wDevID, lpCaps, dwSize);
+	printf("AUX_GetDevCaps(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
 	if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
 	if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
 		printf("AUX_GetDevCaps // mixer device not available !\n");
@@ -120,7 +120,7 @@
 	int 	mixer;
 	int		volume;
 	int		cmd;
-	printf("AUX_GetVolume(%u, %08X);\n", wDevID, lpdwVol);
+	printf("AUX_GetVolume(%u, %p);\n", wDevID, lpdwVol);
 	if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
 	if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
 		printf("Linux 'AUX_GetVolume' // mixer device not available !\n");
@@ -174,7 +174,7 @@
 	int 	mixer;
 	int		volume;
 	int		cmd;
-	printf("AUX_SetVolume(%u, %08X);\n", wDevID, dwParam);
+	printf("AUX_SetVolume(%u, %08lX);\n", wDevID, dwParam);
 	volume = LOWORD(dwParam);
 	if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
 		printf("Linux 'AUX_SetVolume' // mixer device not available !\n");
@@ -225,7 +225,7 @@
 DWORD auxMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2)
 {
-	printf("auxMessage(%u, %04X, %08X, %08X, %08X);\n", 
+	printf("auxMessage(%u, %04X, %08lX, %08lX, %08lX);\n", 
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
 	switch(wMsg) {
 		case AUXDM_GETDEVCAPS:
diff --git a/multimedia/mmsystem.c b/multimedia/mmsystem.c
index 28f67cb..bb25771 100644
--- a/multimedia/mmsystem.c
+++ b/multimedia/mmsystem.c
@@ -12,7 +12,8 @@
 #include <string.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include "win.h"
+#include "windows.h"
+#include "callback.h"
 #include "user.h"
 #include "driver.h"
 #include "mmsystem.h"
@@ -26,7 +27,6 @@
 #include "debug.h"
 
 
-static WORD		mciActiveDev = 0;
 static BOOL		mmTimeStarted = FALSE;
 static MMTIME	mmSysTimeMS;
 static MMTIME	mmSysTimeSMPTE;
@@ -197,7 +197,7 @@
 BOOL DriverCallback(DWORD dwCallBack, UINT uFlags, HANDLE hDev, 
 		WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2)
 {
-	printf("DriverCallback(%08X, %04X, %04X, %04X, %08X, %08X, %08X); !\n",
+	printf("DriverCallback(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n",
 		dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
 	switch(uFlags & DCB_TYPEMASK) {
 		case DCB_NULL:
@@ -230,7 +230,7 @@
 */
 WORD JoyGetDevCaps(WORD wID, LPJOYCAPS lpCaps, WORD wSize)
 {
-	printf("EMPTY STUB !!! JoyGetDevCaps(%04X, %08X, %d);\n", 
+	printf("EMPTY STUB !!! JoyGetDevCaps(%04X, %p, %d);\n", 
 										wID, lpCaps, wSize);
 	return MMSYSERR_NODRIVER;
 }
@@ -240,7 +240,7 @@
 */
 WORD JoyGetPos(WORD wID, LPJOYINFO lpInfo)
 {
-	printf("EMPTY STUB !!! JoyGetPos(%04X, %08X);\n", wID, lpInfo);
+	printf("EMPTY STUB !!! JoyGetPos(%04X, %p);\n", wID, lpInfo);
 	return MMSYSERR_NODRIVER;
 }
 
@@ -249,7 +249,7 @@
 */
 WORD JoyGetThreshold(WORD wID, LPWORD lpThreshold)
 {
-	printf("EMPTY STUB !!! JoyGetThreshold(%04X, %08X);\n", wID, lpThreshold);
+	printf("EMPTY STUB !!! JoyGetThreshold(%04X, %p);\n", wID, lpThreshold);
 	return MMSYSERR_NODRIVER;
 }
 
@@ -308,7 +308,7 @@
 */
 UINT WINAPI auxGetDevCaps(UINT uDeviceID, AUXCAPS FAR* lpCaps, UINT uSize)
 {
-	printf("auxGetDevCaps(%04X, %08X, %d) !\n", 
+	printf("auxGetDevCaps(%04X, %p, %d) !\n", 
 					uDeviceID, lpCaps, uSize);
 	return auxMessage(uDeviceID, AUXDM_GETDEVCAPS, 
 				0L, (DWORD)lpCaps, (DWORD)uSize);
@@ -319,7 +319,7 @@
 */
 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD FAR* lpdwVolume)
 {
-	printf("auxGetVolume(%04X, %08X) !\n", uDeviceID, lpdwVolume);
+	printf("auxGetVolume(%04X, %p) !\n", uDeviceID, lpdwVolume);
 	return auxMessage(uDeviceID, AUXDM_GETVOLUME, 0L, (DWORD)lpdwVolume, 0L);
 }
 
@@ -328,7 +328,7 @@
 */
 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
 {
-	printf("auxSetVolume(%04X, %08X) !\n", uDeviceID, dwVolume);
+	printf("auxSetVolume(%04X, %08lX) !\n", uDeviceID, dwVolume);
 	return auxMessage(uDeviceID, AUXDM_SETVOLUME, 0L, dwVolume, 0L);
 }
 
@@ -337,8 +337,7 @@
 */
 DWORD WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD dw1, DWORD dw2)
 {
-	LPMIDIOPENDESC	lpDesc;
-	printf("auxOutMessage(%04X, %04X, %08X, %08X)\n", 
+	printf("auxOutMessage(%04X, %04X, %08lX, %08lX)\n", 
 				uDeviceID, uMessage, dw1, dw2);
 	return auxMessage(uDeviceID, uMessage, 0L, dw1, dw2);
 }
@@ -350,7 +349,7 @@
 {
 	LPSTR	msgptr;
 	int		maxbuf;
-	printf("mciGetErrorString(%04X, %08X, %d);\n", wError, lpstrBuffer, uLength);
+	printf("mciGetErrorString(%08lX, %p, %d);\n", wError, lpstrBuffer, uLength);
 	if ((lpstrBuffer == NULL) || (uLength < 1)) return(FALSE);
 	lpstrBuffer[0] = '\0';
 	switch(wError) {
@@ -626,7 +625,7 @@
 	char	str[128];
 	DWORD	dwDevTyp = 0;
 	UINT	wDevID = 1;
-	printf("mciOpen(%08X, %08X)\n", dwParam, lpParms);
+	printf("mciOpen(%08lX, %p)\n", dwParam, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	while(mciDrv[wDevID].wType != 0) {
 		if (++wDevID >= MAXMCIDRIVERS) {
@@ -637,7 +636,7 @@
 	if (dwParam & MCI_OPEN_TYPE) {
 		if (lpParms->lpstrDeviceType == NULL) return MCIERR_INTERNAL;
 		if (dwParam & MCI_OPEN_TYPE_ID) {
-			printf("MCI_OPEN // Dev=%08X !\n", lpParms->lpstrDeviceType);
+			printf("MCI_OPEN // Dev=%p !\n", lpParms->lpstrDeviceType);
 			dwDevTyp = (DWORD)lpParms->lpstrDeviceType;
 			}
 		else {
@@ -686,7 +685,7 @@
 				printf("MCI_OPEN // No DIGITAL_VIDEO yet !\n");
 				return MCIERR_DEVICE_NOT_INSTALLED;
 			default:
-				printf("MCI_OPEN // Invalid Device Name '%08X' !\n", lpParms->lpstrDeviceType);
+				printf("MCI_OPEN // Invalid Device Name '%p' !\n", lpParms->lpstrDeviceType);
 				return MCIERR_INVALID_DEVICE_NAME;
 			}
 		}
@@ -700,7 +699,7 @@
 DWORD mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
 	DWORD	dwRet = MCIERR_INTERNAL;
-	printf("mciClose(%u, %08X, %08X)\n", wDevID, dwParam, lpParms);
+	printf("mciClose(%u, %08lX, %p)\n", wDevID, dwParam, lpParms);
 	switch(mciDrv[wDevID].wType) {
 		case MCI_DEVTYPE_CD_AUDIO:
 #ifndef WINELIB
@@ -747,7 +746,7 @@
 DWORD mciSendCommand(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2)
 {
 	HDRVR	hDrv = 0;
-	dprintf_mci(stddeb, "mciSendCommand(%04X, %04X, %08X, %08X)\n", 
+	dprintf_mci(stddeb, "mciSendCommand(%04X, %04X, %08lX, %08lX)\n", 
 					wDevID, wMsg, dwParam1, dwParam2);
 	switch(wMsg) {
 		case MCI_OPEN:
@@ -800,7 +799,7 @@
 DWORD WINAPI mciSendString (LPCSTR lpstrCommand,
     LPSTR lpstrReturnString, UINT uReturnLength, HWND hwndCallback)
 {
-	printf("mciSendString('%s', %lX, %u, %X)\n", 
+	printf("mciSendString('%s', %p, %u, %X)\n", 
 			lpstrCommand, lpstrReturnString, 
 			uReturnLength, hwndCallback);
 	return MCIERR_MISSING_COMMAND_STRING;
@@ -812,6 +811,7 @@
 BOOL WINAPI mciSetYieldProc (UINT uDeviceID, 
 		YIELDPROC fpYieldProc, DWORD dwYieldData)
 {
+    return FALSE;
 }
 
 /**************************************************************************
@@ -819,6 +819,7 @@
 */
 UINT WINAPI mciGetDeviceIDFromElementID(DWORD dwElementID, LPCSTR lpstrType)
 {
+    return 0;
 }
 
 /**************************************************************************
@@ -826,6 +827,7 @@
 */
 YIELDPROC WINAPI mciGetYieldProc(UINT uDeviceID, DWORD FAR* lpdwYieldData)
 {
+    return NULL;
 }
 
 /**************************************************************************
@@ -833,6 +835,7 @@
 */
 HTASK WINAPI mciGetCreatorTask(UINT uDeviceID)
 {
+    return 0;
 }
 
 /**************************************************************************
@@ -923,10 +926,10 @@
 {
 	HMIDI	hMidiOut;
 	LPMIDIOPENDESC	lpDesc;
-	DWORD	dwRet;
+	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
 	if (lphMidiOut != NULL) *lphMidiOut = 0;
-	printf("midiOutOpen(%08X, %d, %08X, %08X, %08X);\n", 
+	printf("midiOutOpen(%p, %d, %08lX, %08lX, %08lX);\n", 
 		lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
 	if (uDeviceID == (UINT)MIDI_MAPPER) {
 		printf("midiOutOpen	// MIDI_MAPPER mode requested !\n");
@@ -970,7 +973,7 @@
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutPrepareHeader(%04X, %08X, %d)\n", 
+	printf("midiOutPrepareHeader(%04X, %p, %d)\n", 
 					hMidiOut, lpMidiOutHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -985,7 +988,7 @@
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutUnprepareHeader(%04X, %08X, %d)\n", 
+	printf("midiOutUnprepareHeader(%04X, %p, %d)\n", 
 					hMidiOut, lpMidiOutHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -999,7 +1002,7 @@
 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutShortMsg(%04X, %08X)\n", hMidiOut, dwMsg);
+	printf("midiOutShortMsg(%04X, %08lX)\n", hMidiOut, dwMsg);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return modMessage(0, MODM_DATA, lpDesc->dwInstance, dwMsg, 0L);
@@ -1012,7 +1015,7 @@
     MIDIHDR FAR* lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutLongMsg(%04X, %08X, %d)\n", 
+	printf("midiOutLongMsg(%04X, %p, %d)\n", 
 				hMidiOut, lpMidiOutHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1083,7 +1086,7 @@
 						DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiOutMessage(%04X, %04X, %08X, %08X)\n", 
+	printf("midiOutMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hMidiOut, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1127,10 +1130,10 @@
 {
 	HMIDI	hMidiIn;
 	LPMIDIOPENDESC	lpDesc;
-	DWORD	dwRet;
+	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
 	if (lphMidiIn != NULL) *lphMidiIn = 0;
-	printf("midiInOpen(%08X, %d, %08X, %08X, %08X);\n", 
+	printf("midiInOpen(%p, %d, %08lX, %08lX, %08lX);\n", 
 		lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
 	if (uDeviceID == (UINT)MIDI_MAPPER) {
 		printf("midiInOpen	// MIDI_MAPPER mode requested !\n");
@@ -1174,7 +1177,7 @@
     MIDIHDR FAR* lpMidiInHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiInPrepareHeader(%04X, %08X, %d)\n", 
+	printf("midiInPrepareHeader(%04X, %p, %d)\n", 
 					hMidiIn, lpMidiInHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1189,7 +1192,7 @@
     MIDIHDR FAR* lpMidiInHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiInUnprepareHeader(%04X, %08X, %d)\n", 
+	printf("midiInUnprepareHeader(%04X, %p, %d)\n", 
 					hMidiIn, lpMidiInHdr, uSize);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1250,7 +1253,7 @@
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
-	printf("midiInMessage(%04X, %04X, %08X, %08X)\n", 
+	printf("midiInMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hMidiIn, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPMIDIOPENDESC) GlobalLock(hMidiIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1296,7 +1299,7 @@
 {
 	LPSTR	msgptr;
 	int		maxbuf;
-	printf("waveGetErrorText(%04X, %08X, %d);\n", uError, lpText, uSize);
+	printf("waveGetErrorText(%04X, %p, %d);\n", uError, lpText, uSize);
 	if ((lpText == NULL) || (uSize < 1)) return(FALSE);
 	lpText[0] = '\0';
 	switch(uError) {
@@ -1366,9 +1369,9 @@
 {
 	HWAVE	hWaveOut;
 	LPWAVEOPENDESC	lpDesc;
-	DWORD	dwRet;
+	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
-	printf("waveOutOpen(%08X, %d, %08X, %08X, %08X, %08X);\n", 
+	printf("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");
@@ -1421,7 +1424,7 @@
      WAVEHDR FAR* lpWaveOutHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutPrepareHeader(%04X, %08X, %u);\n", 
+	printf("waveOutPrepareHeader(%04X, %p, %u);\n", 
 					hWaveOut, lpWaveOutHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1436,7 +1439,7 @@
     WAVEHDR FAR* lpWaveOutHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutUnprepareHeader(%04X, %08X, %u);\n", 
+	printf("waveOutUnprepareHeader(%04X, %p, %u);\n", 
 						hWaveOut, lpWaveOutHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1450,7 +1453,7 @@
 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR FAR* lpWaveOutHdr,  UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutWrite(%04X, %08X, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
+	printf("waveOutWrite(%04X, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_WRITE, lpDesc->dwInstance, 
@@ -1490,7 +1493,7 @@
 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, MMTIME FAR* lpTime, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutGetPosition(%04X, %08X, %u);\n", hWaveOut, lpTime, uSize);
+	printf("waveOutGetPosition(%04X, %p, %u);\n", hWaveOut, lpTime, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return wodMessage(0, WODM_GETPOS, lpDesc->dwInstance, 
@@ -1576,7 +1579,7 @@
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveOutMessage(%04X, %04X, %08X, %08X)\n", 
+	printf("waveOutMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hWaveOut, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveOut);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1624,9 +1627,9 @@
 {
 	HWAVE	hWaveIn;
 	LPWAVEOPENDESC	lpDesc;
-	DWORD	dwRet;
+	DWORD	dwRet = 0;
 	BOOL	bMapperFlg = FALSE;
-	printf("waveInOpen(%08X, %d, %08X, %08X, %08X, %08X);\n", 
+	printf("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");
@@ -1681,14 +1684,14 @@
     WAVEHDR FAR* lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInPrepareHeader(%04X, %08X, %u);\n", 
+	printf("waveInPrepareHeader(%04X, %p, %u);\n", 
 					hWaveIn, lpWaveInHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
 	lpWaveInHdr->lpNext = NULL;
     lpWaveInHdr->dwBytesRecorded = 0;
-	printf("waveInPrepareHeader // lpData=%08X size=%u \n", 
+	printf("waveInPrepareHeader // lpData=%p size=%lu \n", 
 		lpWaveInHdr->lpData, lpWaveInHdr->dwBufferLength);
 	return widMessage(0, WIDM_PREPARE, lpDesc->dwInstance, 
 							(DWORD)lpWaveInHdr, uSize);
@@ -1702,7 +1705,7 @@
     WAVEHDR FAR* lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInUnprepareHeader(%04X, %08X, %u);\n", 
+	printf("waveInUnprepareHeader(%04X, %p, %u);\n", 
 						hWaveIn, lpWaveInHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1722,13 +1725,13 @@
     WAVEHDR FAR* lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInAddBuffer(%04X, %08X, %u);\n", hWaveIn, lpWaveInHdr, uSize);
+	printf("waveInAddBuffer(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
 	lpWaveInHdr->lpNext = NULL;
     lpWaveInHdr->dwBytesRecorded = 0;
-	printf("waveInAddBuffer // lpData=%08X size=%u \n", 
+	printf("waveInAddBuffer // lpData=%p size=%lu \n", 
 		lpWaveInHdr->lpData, lpWaveInHdr->dwBufferLength);
 	return widMessage(0, WIDM_ADDBUFFER, lpDesc->dwInstance,
 								(DWORD)lpWaveInHdr, uSize);
@@ -1780,7 +1783,7 @@
 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, MMTIME FAR* lpTime, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInGetPosition(%04X, %08X, %u);\n", hWaveIn, lpTime, uSize);
+	printf("waveInGetPosition(%04X, %p, %u);\n", hWaveIn, lpTime, uSize);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
 	return widMessage(0, WIDM_GETPOS, lpDesc->dwInstance,
@@ -1806,7 +1809,7 @@
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
-	printf("waveInMessage(%04X, %04X, %08X, %08X)\n", 
+	printf("waveInMessage(%04X, %04X, %08lX, %08lX)\n", 
 			hWaveIn, uMessage, dwParam1, dwParam2);
 	lpDesc = (LPWAVEOPENDESC) GlobalLock(hWaveIn);
 	if (lpDesc == NULL) return MMSYSERR_INVALHANDLE;
@@ -1872,7 +1875,7 @@
 */
 WORD timeGetSystemTime(LPMMTIME lpTime, WORD wSize)
 {
-	printf("timeGetSystemTime(%08X, %u);\n", lpTime, wSize);
+	printf("timeGetSystemTime(%p, %u);\n", lpTime, wSize);
 	if (!mmTimeStarted) StartMMTime();
 	return 0;
 }
@@ -1887,7 +1890,7 @@
 	WORD			wNewID = 0;
 	LPTIMERENTRY	lpNewTimer;
 	LPTIMERENTRY	lpTimer = lpTimerList;
-	printf("timeSetEvent(%u, %u, %08X, %08X, %04X);\n",
+	printf("timeSetEvent(%u, %u, %p, %08lX, %04X);\n",
 			wDelay, wResol, lpFunc, dwUser, wFlags);
 	if (!mmTimeStarted) StartMMTime();
 	lpNewTimer = (LPTIMERENTRY) malloc(sizeof(TIMERENTRY));
@@ -1899,11 +1902,11 @@
 		}
 	if (lpTimerList == NULL) {
 		lpTimerList = lpNewTimer;
-		lpNewTimer->Prev == NULL;
+		lpNewTimer->Prev = NULL;
 		}
 	else {
-		lpTimer->Next == lpNewTimer;
-		lpNewTimer->Prev == lpTimer;
+		lpTimer->Next = lpNewTimer;
+		lpNewTimer->Prev = lpTimer;
 		}
 	lpNewTimer->Next = NULL;
 	lpNewTimer->wTimerID = wNewID + 1;
@@ -1939,7 +1942,7 @@
 */
 WORD timeGetDevCaps(LPTIMECAPS lpCaps, WORD wSize)
 {
-	printf("timeGetDevCaps(%08X, %u) !\n", lpCaps, wSize);
+	printf("timeGetDevCaps(%p, %u) !\n", lpCaps, wSize);
 	return 0;
 }
 
@@ -1982,7 +1985,7 @@
 	HANDLE	hmmio;
 	OFSTRUCT	ofs;
 	LPMMIOINFO	lpmminfo;
-	printf("mmioOpen('%s', %08X, %08X);\n", szFileName, lpmmioinfo, dwOpenFlags);
+	printf("mmioOpen('%s', %p, %08lX);\n", szFileName, lpmmioinfo, dwOpenFlags);
 	hFile = OpenFile(szFileName, &ofs, dwOpenFlags);
 	if (hFile == -1) return 0;
 	hmmio = GlobalAlloc(GMEM_MOVEABLE, sizeof(MMIOINFO));
@@ -2021,7 +2024,7 @@
 {
 	int		count;
 	LPMMIOINFO	lpmminfo;
-	dprintf_mmio(stddeb, "mmioRead(%04X, %08X, %ld);\n", hmmio, pch, cch);
+	dprintf_mmio(stddeb, "mmioRead(%04X, %p, %ld);\n", hmmio, pch, cch);
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) return 0;
 	count = _lread(LOWORD(lpmminfo->dwReserved2), pch, cch);
@@ -2038,7 +2041,7 @@
 {
 	int		count;
 	LPMMIOINFO	lpmminfo;
-	printf("mmioWrite(%04X, %08X, %ld);\n", hmmio, pch, cch);
+	printf("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);
@@ -2053,7 +2056,7 @@
 {
 	int		count;
 	LPMMIOINFO	lpmminfo;
-	printf("mmioSeek(%04X, %08X, %d);\n", hmmio, lOffset, iOrigin);
+	printf("mmioSeek(%04X, %08lX, %d);\n", hmmio, lOffset, iOrigin);
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
 	if (lpmminfo == NULL) {
 		printf("mmioSeek // can't lock hmmio=%04X !\n", hmmio);
@@ -2175,7 +2178,7 @@
 {
 	DWORD	dwfcc, dwOldPos;
 	LPMMIOINFO	lpmminfo;
-	dprintf_mmio(stddeb, "mmioDescend(%04X, %08X, %08X, %04X);\n", 
+	dprintf_mmio(stddeb, "mmioDescend(%04X, %p, %p, %04X);\n", 
 				hmmio, lpck, lpckParent, uFlags);
 	if (lpck == NULL) return 0;
 	lpmminfo = (LPMMIOINFO)GlobalLock(hmmio);
@@ -2189,7 +2192,7 @@
 		}
 	if ((uFlags & MMIO_FINDCHUNK) || (uFlags & MMIO_FINDRIFF) || 
 		(uFlags & MMIO_FINDLIST)) {
-		dprintf_mmio(stddeb, "mmioDescend // MMIO_FINDxxxx dwfcc=%08X !\n", dwfcc);
+		dprintf_mmio(stddeb, "mmioDescend // MMIO_FINDxxxx dwfcc=%08lX !\n", dwfcc);
 		while (TRUE) {
 			if (_lread(LOWORD(lpmminfo->dwReserved2), (LPSTR)lpck, 
 					sizeof(MMCKINFO)) < sizeof(MMCKINFO)) {
@@ -2197,7 +2200,7 @@
 				GlobalUnlock(hmmio);
 				return MMIOERR_CHUNKNOTFOUND;
 				}
-			dprintf_mmio(stddeb, "mmioDescend // dwfcc=%08X ckid=%08X cksize=%08X !\n", 
+			dprintf_mmio(stddeb, "mmioDescend // dwfcc=%08lX ckid=%08lX cksize=%08lX !\n", 
 									dwfcc, lpck->ckid, lpck->cksize);
 			if (dwfcc == lpck->ckid) break;
 			dwOldPos += lpck->cksize + 2 * sizeof(DWORD);
@@ -2220,9 +2223,9 @@
 		lpck->dwDataOffset += sizeof(DWORD);
 	lpmminfo->lDiskOffset = _llseek(LOWORD(lpmminfo->dwReserved2), 
 									lpck->dwDataOffset, SEEK_SET);
-	dprintf_mmio(stddeb, "mmioDescend // lpck->ckid=%08X lpck->cksize=%ld !\n", 
+	dprintf_mmio(stddeb, "mmioDescend // lpck->ckid=%08lX lpck->cksize=%ld !\n", 
 								lpck->ckid, lpck->cksize);
-	printf("mmioDescend // lpck->fccType=%08X !\n", lpck->fccType);
+	printf("mmioDescend // lpck->fccType=%08lX !\n", lpck->fccType);
 	return 0;
 }
 
@@ -2251,7 +2254,7 @@
 UINT WINAPI mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
      MMIOINFO FAR* lpmmioinfo, DWORD dwRenameFlags)
 {
-	printf("mmioRename('%s', '%s', %08X, %08X);\n",
+	printf("mmioRename('%s', '%s', %p, %08lX);\n",
 			szFileName, szNewFileName, lpmmioinfo, dwRenameFlags);
 	return 0;
 }
@@ -2261,7 +2264,7 @@
 */
 HDRVR DrvOpen(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
 {
-	printf("DrvOpen('%s', '%s', %08X);\n",
+	printf("DrvOpen('%s', '%s', %08lX);\n",
 		lpDriverName, lpSectionName, lParam);
 	return OpenDriver(lpDriverName, lpSectionName, lParam);
 }
@@ -2272,7 +2275,7 @@
 */
 LRESULT DrvClose(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
 {
-	printf("DrvClose(%04X, %08X, %08X);\n", hDrvr, lParam1, lParam2);
+	printf("DrvClose(%04X, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
 	return CloseDriver(hDrvr, lParam1, lParam2);
 }
 
@@ -2283,7 +2286,7 @@
 LRESULT WINAPI DrvSendMessage(HDRVR hDriver, WORD msg, LPARAM lParam1, LPARAM lParam2)
 {
 	DWORD 	dwDevID = 0;
-	printf("DrvSendMessage(%04X, %04X, %08X, %08X);\n",
+	printf("DrvSendMessage(%04X, %04X, %08lX, %08lX);\n",
 					hDriver, msg, lParam1, lParam2);
 #ifndef WINELIB
 	return CDAUDIO_DriverProc(dwDevID, hDriver, msg, lParam1, lParam2);
@@ -2296,6 +2299,7 @@
 HANDLE DrvGetModuleHandle(HDRVR hDrvr)
 {
 	printf("DrvGetModuleHandle(%04X);\n", hDrvr);
+        return 0;
 }
 
 
diff --git a/objects/Imakefile b/objects/Imakefile
index 60afdec..6ba4f82 100644
--- a/objects/Imakefile
+++ b/objects/Imakefile
@@ -11,7 +11,6 @@
 	dc.c \
 	dcvalues.c \
 	dib.c \
-	dither.c \
 	font.c \
 	gdiobj.c \
 	linedda.c \
diff --git a/objects/bitblt.c b/objects/bitblt.c
index 142c9a9..a7b3270 100644
--- a/objects/bitblt.c
+++ b/objects/bitblt.c
@@ -8,30 +8,30 @@
 #include <stdlib.h>
 #include <X11/Xlib.h>
 #include <X11/Intrinsic.h>
-#include "windows.h"
-#include "dc.h"
-#include "gdi.h"
-#include "color.h"
-#include "metafile.h"
 #include "bitmap.h"
+#include "color.h"
+#include "dc.h"
+#include "metafile.h"
 #include "options.h"
 #include "stddebug.h"
-/* #define DEBUG_GDI */
+/* #define DEBUG_BITBLT */
 #include "debug.h"
 
 
-#define TMP 0   /* Temporary drawable */
-#define DST 1   /* Destination drawable */
-#define SRC 2   /* Source drawable */
+#define DST 0   /* Destination drawable */
+#define SRC 1   /* Source drawable */
+#define TMP 2   /* Temporary drawable */
 #define PAT 3   /* Pattern (brush) in destination DC */
 
-  /* Build the ROP arguments */
+#define OP(src,dst,rop)   (OP_ARGS(src,dst) << 4 | (rop))
 #define OP_ARGS(src,dst)  (((src) << 2) | (dst))
 
-  /* Build the ROP code */
-#define OP(src,dst,rop)   (OP_ARGS(src,dst) << 4 | (rop))
+#define OP_SRC(opcode)    ((opcode) >> 6)
+#define OP_DST(opcode)    (((opcode) >> 4) & 3) 
+#define OP_SRCDST(opcode) ((opcode) >> 4)
+#define OP_ROP(opcode)    ((opcode) & 0x0f)
 
-#define MAX_OP_LEN 6
+#define MAX_OP_LEN  6  /* Longest opcode + 1 for the terminating 0 */
 
 static const unsigned char BITBLT_Opcodes[256][MAX_OP_LEN] =
 {
@@ -512,192 +512,670 @@
 
 
 /***********************************************************************
- *           BITBLT_GetImage
+ *           BITBLT_StretchRow
+ *
+ * Stretch a row of pixels. Helper function for BITBLT_StretchImage.
  */
-static XImage *BITBLT_GetImage( HDC hdc, int x, int y, int width, int height )
+static void BITBLT_StretchRow( int *rowSrc, int *rowDst,
+                               short startDst, short widthDst,
+                               int xinc, WORD mode )
 {
-    XImage *image;
-    RECT rect, tmpRect, clipRect;
-    DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
-
-    GetClipBox( hdc, &clipRect );
-    OffsetRect( &clipRect, dc->w.DCOrgX, dc->w.DCOrgY );
-    SetRect( &tmpRect, x, y, x+width, y+height );
-    IntersectRect( &rect, &tmpRect, &clipRect );
-    if (EqualRect(&rect,&tmpRect))
+    register int xsrc = xinc * startDst;
+    rowDst += startDst;
+    switch(mode)
     {
-        image = XGetImage( display, dc->u.x.drawable, x, y, width, height,
-                           AllPlanes, ZPixmap );
+    case STRETCH_ANDSCANS:
+        for(; widthDst > 0; widthDst--, xsrc += xinc)
+            *rowDst++ &= rowSrc[xsrc >> 16];
+        break;
+    case STRETCH_ORSCANS:
+        for(; widthDst > 0; widthDst--, xsrc += xinc)
+            *rowDst++ |= rowSrc[xsrc >> 16];
+        break;
+    case STRETCH_DELETESCANS:
+        for(; widthDst > 0; widthDst--, xsrc += xinc)
+            *rowDst++ = rowSrc[xsrc >> 16];
+        break;
     }
-    else  /* Get only the visible sub-image */
-    {
-        XCREATEIMAGE( image, width, height, dc->w.bitsPerPixel );
-        if (image && !IsRectEmpty(&rect))
-        {
-            XGetSubImage( display, dc->u.x.drawable, rect.left, rect.top,
-                          rect.right-rect.left, rect.bottom-rect.top,
-                          AllPlanes, ZPixmap, image, rect.left-x, rect.top-y );
-        }
-    }
-    return image;
 }
 
 
 /***********************************************************************
- *           BITBLT_GetArea
+ *           BITBLT_ShrinkRow
  *
- * Retrieve an area of the source DC. If necessary, the area is
- * mapped to colormap-independent colors.
+ * Shrink a row of pixels. Helper function for BITBLT_StretchImage.
  */
-static void BITBLT_GetArea( HDC hdcSrc, HDC hdcDst, Pixmap pixmap, GC gc,
-                            int x, int y, int width, int height )
+static void BITBLT_ShrinkRow( int *rowSrc, int *rowDst,
+                              short startSrc, short widthSrc,
+                              short xinc, WORD mode )
 {
-    XImage *srcImage, *dstImage;
-    DC * dcSrc = (DC *) GDI_GetObjPtr( hdcSrc, DC_MAGIC );
-    DC * dcDst = (DC *) GDI_GetObjPtr( hdcDst, DC_MAGIC );
-
-    if ((dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel) &&
-        (!COLOR_PixelToPalette || (dcDst->w.bitsPerPixel == 1)))
+    register int xdst = xinc * startSrc;
+    rowSrc += startSrc;
+    switch(mode)
     {
-        XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
-                   x, y, width, height, 0, 0 );
-        return;
+    case STRETCH_ORSCANS:
+        for(; widthSrc > 0; widthSrc--, xdst += xinc)
+            rowDst[xdst >> 16] |= *rowSrc++;
+        break;
+    case STRETCH_ANDSCANS:
+        for(; widthSrc > 0; widthSrc--, xdst += xinc)
+            rowDst[xdst >> 16] &= *rowSrc++;
+        break;
+    case STRETCH_DELETESCANS:
+        for(; widthSrc > 0; widthSrc--, xdst += xinc)
+            rowDst[xdst >> 16] = *rowSrc++;
+        break;
     }
-    if ((dcSrc->w.bitsPerPixel == 1) && (dcDst->w.bitsPerPixel != 1))
-    {
-        XSetBackground( display, gc, COLOR_PixelToPalette ?
-                        COLOR_PixelToPalette[dcDst->w.textPixel] :
-                        dcDst->w.textPixel );
-        XSetForeground( display, gc, COLOR_PixelToPalette ?
-                        COLOR_PixelToPalette[dcDst->w.backgroundPixel] :
-                        dcDst->w.backgroundPixel );
-        XCopyPlane( display, dcSrc->u.x.drawable, pixmap, gc,
-                    x, y, width, height, 0, 0, 1);
-        return;
-    }
+}
 
-    srcImage = BITBLT_GetImage( hdcSrc, x, y, width, height );
-    if (dcSrc->w.bitsPerPixel != dcDst->w.bitsPerPixel)
+
+/***********************************************************************
+ *           BITBLT_GetRow
+ *
+ * Retrieve a row from an image. Helper function for BITBLT_StretchImage.
+ */
+static void BITBLT_GetRow( XImage *image, int *pdata, short row,
+                           short start, short width, short depthDst,
+                           int fg, int bg, BOOL swap)
+{
+    register short i;
+
+    pdata += swap ? start+width-1 : start;
+    if (image->depth == depthDst)
     {
-        XCREATEIMAGE( dstImage, width, height, dcDst->w.bitsPerPixel );
-        for (y = 0; y < height; y++)
-            for (x = 0; x < width; x++)
-            {
-                XPutPixel( dstImage, x, y, (XGetPixel( srcImage, x, y ) ==
-                                            dcSrc->w.backgroundPixel) );
-            }
-        XDestroyImage( srcImage );
+        if (COLOR_PixelToPalette && (depthDst != 1))
+            if (swap) for (i = 0; i < width; i++)
+                *pdata-- = COLOR_PixelToPalette[XGetPixel( image, i, row )];
+            else for (i = 0; i < width; i++)
+                *pdata++ = COLOR_PixelToPalette[XGetPixel( image, i, row )];
+        else
+            if (swap) for (i = 0; i < width; i++)
+                *pdata-- = XGetPixel( image, i, row );
+            else for (i = 0; i < width; i++)
+                *pdata++ = XGetPixel( image, i, row );
     }
     else
     {
-        for (y = 0; y < height; y++)
-            for (x = 0; x < width; x++)
-            {
-                XPutPixel( srcImage, x, y,
-                          COLOR_PixelToPalette[XGetPixel( srcImage, x, y)] );
-            }
-        dstImage = srcImage;
+        if (image->depth == 1)
+            if (swap) for (i = 0; i < width; i++)
+                *pdata-- = XGetPixel( image, i, row ) ? bg : fg;
+            else for (i = 0; i < width; i++)
+                *pdata++ = XGetPixel( image, i, row ) ? bg : fg;
+        else
+            if (swap) for (i = 0; i < width; i++)
+                *pdata-- = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
+            else for (i = 0; i < width; i++)
+                *pdata++ = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
     }
-    XPutImage( display, pixmap, gc, dstImage, 0, 0, 0, 0, width, height );
-    XDestroyImage( dstImage );
 }
 
 
 /***********************************************************************
- *           BITBLT_PutArea
+ *           BITBLT_StretchImage
  *
- * Put an area back into an hdc, possibly applying a mapping
- * to every pixel in the process.
+ * Stretch an X image.
  */
-static void BITBLT_PutArea( HDC hdc, Pixmap pixmap, GC gc,
-                            int x, int y, int width, int height )
+static void BITBLT_StretchImage( XImage *srcImage, XImage *dstImage,
+                                 short widthSrc, short heightSrc,
+                                 short widthDst, short heightDst,
+                                 RECT *visRectSrc, RECT *visRectDst,
+                                 int foreground, int background, WORD mode )
 {
-    XImage *image;
-    int x1, y1;
-    DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
+    int *rowSrc, *rowDst, *pixel;
+    int xinc, yinc, ysrc, ydst;
+    register short x, y;
+    BOOL hstretch, vstretch, hswap, vswap;
+
+    hswap = ((int)widthSrc * widthDst) < 0;
+    vswap = ((int)heightSrc * heightDst) < 0;
+    widthSrc  = abs(widthSrc);
+    heightSrc = abs(heightSrc);
+    widthDst  = abs(widthDst);
+    heightDst = abs(heightDst);
+    
+    dprintf_bitblt( stddeb, "BITBLT_StretchImage: %dx%d -> %dx%d (mode=%d,h=%d,v=%d)\n",
+                widthSrc, heightSrc, widthDst, heightDst, mode, hswap, vswap );
+
+    if (!(rowSrc = (int *)malloc( (widthSrc+widthDst)*sizeof(int) ))) return;
+    rowDst = rowSrc + widthSrc;
+
+      /* When stretching, all modes are the same, and DELETESCANS is faster */
+    if ((widthSrc < widthDst) && (heightSrc < heightDst))
+        mode = STRETCH_DELETESCANS;
+
+    hstretch = ((widthSrc < widthDst) || (mode == STRETCH_DELETESCANS));
+    vstretch = ((heightSrc < heightDst) || (mode == STRETCH_DELETESCANS));
+    xinc = hstretch ? ((int)widthSrc << 16) / widthDst :
+                      ((int)widthDst << 16) / widthSrc;
+
+    if (vstretch)
+    {
+        yinc = ((int)heightSrc << 16) / heightDst;
+        ydst = visRectDst->top;
+        ysrc = yinc * ydst;
+    }
+    else
+    {
+        yinc = ((int)heightDst << 16) / heightSrc;
+        ysrc = visRectSrc->top;
+        ydst = yinc * ysrc;
+    }
+
+    while(vstretch ? (ydst < visRectDst->bottom) : (ysrc < visRectSrc->bottom))
+    {
+          /* Retrieve a source row */
+        BITBLT_GetRow( srcImage, rowSrc, vstretch ? ysrc >> 16 : ysrc,
+                       visRectSrc->left, visRectSrc->right - visRectSrc->left,
+                       dstImage->depth, foreground, background, hswap );
+
+          /* Stretch or shrink it */
+        if (hstretch)
+            BITBLT_StretchRow( rowSrc, rowDst, visRectDst->left,
+                               visRectDst->right-visRectDst->left, xinc, mode);
+        else BITBLT_ShrinkRow( rowSrc, rowDst, visRectSrc->left,
+                               visRectSrc->right-visRectSrc->left, xinc, mode);
+
+          /* When shrinking, merge several source rows into the destination */
+        if (!vstretch)
+        {
+            if (mode == STRETCH_DELETESCANS)
+            {
+                  /* Simply skip the overlapping rows */
+                while (((ydst + yinc) >> 16 == ydst >> 16) &&
+                       (ysrc < visRectSrc->bottom-1))
+                {
+                    ydst += yinc;
+                    ysrc++;
+                }
+            }
+            else if (((ydst + yinc) >> 16 == ydst >> 16) &&
+                     (ysrc < visRectSrc->bottom-1))
+            {
+                ydst += yinc;
+                ysrc++;
+                continue;  /* Restart loop for next overlapping row */
+            }
+        }
+        
+          /* Store the destination row */
+
+        pixel = rowDst + visRectDst->right - 1;
+        if (vswap)
+            y = visRectDst->bottom - (vstretch ? ydst : ydst >> 16);
+        else
+            y = (vstretch ? ydst : ydst >> 16) - visRectDst->top;
+        for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
+            XPutPixel( dstImage, x, y, *pixel-- );
+        if (mode != STRETCH_DELETESCANS)
+            memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
+                    widthDst*sizeof(int) );
+
+          /* If stretching, make copies of the destination row */
+
+        if (vstretch)
+        {
+            char *pdata = dstImage->data + dstImage->bytes_per_line * y;
+            while (((ysrc + yinc) >> 16 == ysrc >> 16) &&
+                   (ydst < visRectDst->bottom-1))
+            {
+                if (vswap)
+                {
+                    memcpy( pdata - dstImage->bytes_per_line, pdata,
+                            dstImage->bytes_per_line );
+                    pdata -= dstImage->bytes_per_line;
+                }
+                else
+                {
+                    memcpy( pdata + dstImage->bytes_per_line, pdata,
+                            dstImage->bytes_per_line );
+                    pdata += dstImage->bytes_per_line;
+                }
+                ysrc += yinc;
+                ydst++;
+            }
+            ysrc += yinc;
+            ydst++;
+        }
+        else
+        {
+            ydst += yinc;
+            ysrc++;
+        }
+    }        
+
+    free( rowSrc );
+}
+
+
+/***********************************************************************
+ *           BITBLT_GetSrcAreaStretch
+ *
+ * Retrieve an area from the source DC, stretching and mapping all the
+ * pixels to Windows colors.
+ */
+static void BITBLT_GetSrcAreaStretch( DC *dcSrc, DC *dcDst,
+                                      Pixmap pixmap, GC gc,
+                                      short xSrc, short ySrc,
+                                      short widthSrc, short heightSrc,
+                                      short xDst, short yDst,
+                                      short widthDst, short heightDst,
+                                      RECT *visRectSrc, RECT *visRectDst )
+{
+    XImage *imageSrc, *imageDst;
+
+    RECT rectSrc = *visRectSrc;
+    RECT rectDst = *visRectDst;
+    OffsetRect( &rectSrc, -xSrc, -ySrc );
+    OffsetRect( &rectDst, -xDst, -yDst );
+    imageSrc = XGetImage( display, dcSrc->u.x.drawable,
+                          visRectSrc->left, visRectSrc->top,
+                          visRectSrc->right - visRectSrc->left,
+                          visRectSrc->bottom - visRectSrc->top,
+                          AllPlanes, ZPixmap );
+    XCREATEIMAGE( imageDst, rectDst.right - rectDst.left,
+                  rectDst.bottom - rectDst.top, dcDst->w.bitsPerPixel );
+    BITBLT_StretchImage( imageSrc, imageDst, widthSrc, heightSrc,
+                         widthDst, heightDst, &rectSrc, &rectDst,
+                         dcDst->w.textPixel, dcDst->w.bitsPerPixel != 1 ?
+                           dcDst->w.backgroundPixel : dcSrc->w.backgroundPixel,
+                         dcDst->w.stretchBltMode );
+    XPutImage( display, pixmap, gc, imageDst, 0, 0, 0, 0,
+               rectDst.right - rectDst.left, rectDst.bottom - rectDst.top );
+    XDestroyImage( imageSrc );
+    XDestroyImage( imageDst );
+}
+
+
+/***********************************************************************
+ *           BITBLT_GetSrcArea
+ *
+ * Retrieve an area from the source DC, mapping all the
+ * pixels to Windows colors.
+ */
+static void BITBLT_GetSrcArea( DC *dcSrc, DC *dcDst, Pixmap pixmap, GC gc,
+                               short xSrc, short ySrc,
+                               RECT *visRectSrc )
+{
+    XImage *imageSrc, *imageDst;
+    register short x, y;
+    short width  = visRectSrc->right - visRectSrc->left;
+    short height = visRectSrc->bottom - visRectSrc->top;
+
+    if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
+    {
+        if (!COLOR_PixelToPalette ||
+            (dcDst->w.bitsPerPixel == 1))  /* monochrome -> monochrome */
+        {
+            XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
+                       visRectSrc->left, visRectSrc->top, width, height, 0, 0);
+        }
+        else  /* color -> color */
+        {
+            imageSrc = XGetImage( display, dcSrc->u.x.drawable,
+                                  visRectSrc->left, visRectSrc->top,
+                                  width, height, AllPlanes, ZPixmap );
+            for (y = 0; y < height; y++)
+                for (x = 0; x < width; x++)
+                    XPutPixel(imageSrc, x, y,
+                              COLOR_PixelToPalette[XGetPixel(imageSrc, x, y)]);
+            XPutImage( display, pixmap, gc, imageSrc,
+                       0, 0, 0, 0, width, height );
+            XDestroyImage( imageSrc );
+        }
+    }
+    else
+    {
+        if (dcSrc->w.bitsPerPixel == 1)  /* monochrome -> color */
+        {
+            if (COLOR_PixelToPalette)
+            {
+                XSetBackground( display, gc, 
+                               COLOR_PixelToPalette[dcDst->w.textPixel] );
+                XSetForeground( display, gc,
+                               COLOR_PixelToPalette[dcDst->w.backgroundPixel]);
+            }
+            else
+            {
+                XSetBackground( display, gc, dcDst->w.textPixel );
+                XSetForeground( display, gc, dcDst->w.backgroundPixel );
+            }
+            XCopyPlane( display, dcSrc->u.x.drawable, pixmap, gc,
+                        visRectSrc->left, visRectSrc->top,
+                        width, height, 0, 0, 1 );
+        }
+        else  /* color -> monochrome */
+        {
+            imageSrc = XGetImage( display, dcSrc->u.x.drawable,
+                                  visRectSrc->left, visRectSrc->top,
+                                  width, height, AllPlanes, ZPixmap );
+            XCREATEIMAGE( imageDst, width, height, dcDst->w.bitsPerPixel );
+            for (y = 0; y < height; y++)
+                for (x = 0; x < width; x++)
+                    XPutPixel(imageDst, x, y, (XGetPixel(imageSrc,x,y) ==
+                                               dcSrc->w.backgroundPixel) );
+            XPutImage( display, pixmap, gc, imageDst,
+                       0, 0, 0, 0, width, height );
+            XDestroyImage( imageSrc );
+            XDestroyImage( imageDst );
+        }
+    }
+}
+
+
+/***********************************************************************
+ *           BITBLT_GetDstArea
+ *
+ * Retrieve an area from the destination DC, mapping all the
+ * pixels to Windows colors.
+ */
+static void BITBLT_GetDstArea( DC *dc, Pixmap pixmap, GC gc, RECT *visRectDst )
+{
+    short width  = visRectDst->right - visRectDst->left;
+    short height = visRectDst->bottom - visRectDst->top;
+
+    if (!COLOR_PixelToPalette || (dc->w.bitsPerPixel == 1))
+    {
+        XCopyArea( display, dc->u.x.drawable, pixmap, gc,
+                   visRectDst->left, visRectDst->top, width, height, 0, 0 );
+    }
+    else
+    {
+        register short x, y;
+        XImage *image = XGetImage( display, dc->u.x.drawable,
+                                   visRectDst->left, visRectDst->top,
+                                   width, height, AllPlanes, ZPixmap );
+        for (y = 0; y < height; y++)
+            for (x = 0; x < width; x++)
+                XPutPixel( image, x, y,
+                           COLOR_PixelToPalette[XGetPixel( image, x, y )]);
+        XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, width, height );
+    }
+}
+
+
+/***********************************************************************
+ *           BITBLT_PutDstArea
+ *
+ * Put an area back into the destination DC, mapping the pixel
+ * colors to X pixels.
+ */
+static void BITBLT_PutDstArea( DC *dc, Pixmap pixmap, GC gc, RECT *visRectDst )
+{
+    short width  = visRectDst->right - visRectDst->left;
+    short height = visRectDst->bottom - visRectDst->top;
 
     if (!COLOR_PaletteToPixel)
     {
-        XCopyArea( display, pixmap, dc->u.x.drawable, gc,
-                  0, 0, width, height, x, y );
+        XCopyArea( display, pixmap, dc->u.x.drawable, gc, 0, 0,
+                   width, height, visRectDst->left, visRectDst->top );
     }
     else
     {
-        image = XGetImage( display, pixmap, 0, 0, width, height,
-                           AllPlanes, ZPixmap );
-        for (y1 = 0; y1 < height; y1++)
-            for (x1 = 0; x1 < width; x1++)
+        register short x, y;
+        XImage *image = XGetImage( display, pixmap, 0, 0, width, height,
+                                   AllPlanes, ZPixmap );
+        for (y = 0; y < height; y++)
+            for (x = 0; x < width; x++)
             {
-                XPutPixel( image, x1, y1,
-                           COLOR_PaletteToPixel[XGetPixel( image, x1, y1)] );
+                XPutPixel( image, x, y,
+                           COLOR_PaletteToPixel[XGetPixel( image, x, y )]);
             }
-        XPutImage( display, dc->u.x.drawable, gc, image,
-                   0, 0, x, y, width, height );
+        XPutImage( display, dc->u.x.drawable, gc, image, 0, 0,
+                   visRectDst->left, visRectDst->top, width, height );
         XDestroyImage( image );
     }
 }
 
 
 /***********************************************************************
- *           BITBLT_SelectBrush
+ *           BITBLT_GetVisRectangles
  *
- * Select the brush into a GC.
+ * Get the source and destination visible rectangles for StretchBlt().
+ * Return FALSE if one of the rectangles is empty.
  */
-static BOOL BITBLT_SelectBrush( DC * dc, GC gc )
+static BOOL BITBLT_GetVisRectangles( DC *dcDst, short xDst, short yDst,
+                                     short widthDst, short heightDst,
+                                     DC *dcSrc, short xSrc, short ySrc,
+                                     short widthSrc, short heightSrc,
+                                     RECT *visRectSrc, RECT *visRectDst )
 {
-    XGCValues val;
-    XImage *image;
-    Pixmap pixmap = 0;
-    int x, y, mask = 0;
-    
-    if (dc->u.x.brush.style == BS_NULL) return FALSE;
-    if (dc->u.x.brush.pixel == -1)
+    RECT tmpRect, clipRect;
+
+    if (widthSrc < 0)  { widthSrc = -widthSrc; xSrc -= widthSrc; }
+    if (widthDst < 0)  { widthDst = -widthDst; xDst -= widthDst; }
+    if (heightSrc < 0) { heightSrc = -heightSrc; ySrc -= heightSrc; }
+    if (heightDst < 0) { heightDst = -heightDst; yDst -= heightDst; }
+
+      /* Get the destination visible rectangle */
+
+    SetRect( &tmpRect, xDst, yDst, xDst + widthDst, yDst + heightDst );
+    GetRgnBox( dcDst->w.hGCClipRgn, &clipRect );
+    OffsetRect( &clipRect, dcDst->w.DCOrgX, dcDst->w.DCOrgY );
+    if (!IntersectRect( visRectDst, &tmpRect, &clipRect )) return FALSE;
+
+      /* Get the source visible rectangle */
+
+    if (!dcSrc) return TRUE;
+    SetRect( &tmpRect, xSrc, ySrc, xSrc + widthSrc, ySrc + heightSrc );
+    GetRgnBox( dcSrc->w.hGCClipRgn, &clipRect );
+    OffsetRect( &clipRect, dcSrc->w.DCOrgX, dcSrc->w.DCOrgY );
+    if (!IntersectRect( visRectSrc, &tmpRect, &clipRect )) return FALSE;
+
+      /* Intersect the rectangles */
+
+    if ((widthSrc == widthDst) && (heightSrc == heightDst)) /* no stretching */
     {
-        val.foreground = dc->w.backgroundPixel;
-        val.background = dc->w.textPixel;
+        OffsetRect( visRectSrc, xDst - xSrc, yDst - ySrc );
+        if (!IntersectRect( &tmpRect, visRectSrc, visRectDst )) return FALSE;
+        *visRectSrc = *visRectDst = tmpRect;
+        OffsetRect( visRectSrc, xSrc - xDst, ySrc - yDst );
+    }
+    else  /* stretching */
+    {
+        visRectSrc->left = xDst + (visRectSrc->left-xSrc)*widthDst/widthSrc;
+        visRectSrc->top = yDst + (visRectSrc->top-ySrc)*heightDst/heightSrc;
+        visRectSrc->right = xDst +
+             ((visRectSrc->right-xSrc) * widthDst + widthSrc-1) / widthSrc;
+        visRectSrc->bottom = yDst +
+             ((visRectSrc->bottom-ySrc) * heightDst + heightSrc-1) / heightSrc;
+        if (!IntersectRect( &tmpRect, visRectSrc, visRectDst )) return FALSE;
+        *visRectSrc = *visRectDst = tmpRect;
+        visRectSrc->left = xSrc + (visRectSrc->left-xDst)*widthSrc/widthDst;
+        visRectSrc->top = ySrc + (visRectSrc->top-yDst)*heightSrc/heightDst;
+        visRectSrc->right = xSrc +
+             ((visRectSrc->right-xDst) * widthSrc + widthDst-1) / widthDst;
+        visRectSrc->bottom = ySrc +
+             ((visRectSrc->bottom-yDst) * heightSrc + heightDst-1) / heightDst;
+        if (IsRectEmpty( visRectSrc )) return FALSE;
+    }
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           BITBLT_InternalStretchBlt
+ *
+ * Implementation of PatBlt(), BitBlt() and StretchBlt().
+ */
+BOOL BITBLT_InternalStretchBlt( DC *dcDst, short xDst, short yDst,
+                                short widthDst, short heightDst,
+                                DC *dcSrc, short xSrc, short ySrc,
+                                short widthSrc, short heightSrc, DWORD rop )
+{
+    BOOL usePat, useSrc, useDst, destUsed, fStretch, fNullBrush;
+    RECT visRectDst, visRectSrc;
+    short width, height;
+    const BYTE *opcode;
+    Pixmap pixmaps[3] = { 0, 0, 0 };  /* pixmaps for DST, SRC, TMP */
+    GC tmpGC = 0;
+
+    usePat = (((rop >> 4) & 0x0f0000) != (rop & 0x0f0000));
+    useSrc = (((rop >> 2) & 0x330000) != (rop & 0x330000));
+    useDst = (((rop >> 1) & 0x550000) != (rop & 0x550000));
+    if (!dcSrc && useSrc) return FALSE;
+
+      /* Map the coordinates to device coords */
+
+    xDst      = dcDst->w.DCOrgX + XLPTODP( dcDst, xDst );
+    yDst      = dcDst->w.DCOrgY + YLPTODP( dcDst, yDst );
+    widthDst  = widthDst * dcDst->w.VportExtX / dcDst->w.WndExtX;
+    heightDst = heightDst * dcDst->w.VportExtY / dcDst->w.WndExtY;
+    if (useSrc)
+    {
+        xSrc      = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc );
+        ySrc      = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc );
+        widthSrc  = widthSrc * dcSrc->w.VportExtX / dcSrc->w.WndExtX;
+        heightSrc = heightSrc * dcSrc->w.VportExtY / dcSrc->w.WndExtY;
+        fStretch  = (widthSrc != widthDst) || (heightSrc != heightDst);
+        if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
+                                      dcSrc, xSrc, ySrc, widthSrc, heightSrc,
+                                      &visRectSrc, &visRectDst ))
+            return TRUE;
     }
     else
     {
-        val.foreground = dc->u.x.brush.pixel;
-        val.background = dc->w.backgroundPixel;
+        fStretch = FALSE;
+        if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
+                                      NULL, 0, 0, 0, 0, NULL, &visRectDst ))
+            return TRUE;
     }
-    if (COLOR_PixelToPalette)
+
+    width  = visRectDst.right - visRectDst.left;
+    height = visRectDst.bottom - visRectDst.top;
+
+    if (!fStretch) switch(rop)  /* A few optimisations */
     {
-        val.foreground = COLOR_PixelToPalette[val.foreground];
-        val.background = COLOR_PixelToPalette[val.background];
-    }
-    val.fill_style = dc->u.x.brush.fillStyle;
-    if ((val.fill_style==FillStippled) || (val.fill_style==FillOpaqueStippled))
-    {
-        if (dc->w.backgroundMode==OPAQUE) val.fill_style = FillOpaqueStippled;
-        val.stipple = dc->u.x.brush.pixmap;
-        mask = GCStipple;
-    }
-    else if (val.fill_style == FillTiled)
-    {
-        if (COLOR_PixelToPalette)
+    case BLACKNESS:  /* 0x00 */
+        if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
+            XSetFunction( display, dcDst->u.x.gc, GXclear );
+        else
         {
-            pixmap = XCreatePixmap( display, rootWindow, 8, 8, screenDepth );
-            image = XGetImage( display, dc->u.x.brush.pixmap, 0, 0, 8, 8,
-                               AllPlanes, ZPixmap );
-            for (y = 0; y < 8; y++)
-                for (x = 0; x < 8; x++)
-                    XPutPixel( image, x, y,
-                               COLOR_PixelToPalette[XGetPixel( image, x, y)] );
-            XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
-            XDestroyImage( image );
-            val.tile = pixmap;
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+            XSetForeground( display, dcDst->u.x.gc, COLOR_PaletteToPixel[0] );
+            XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
         }
-        else val.tile = dc->u.x.brush.pixmap;
-        mask = GCTile;
+        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+                        visRectDst.left, visRectDst.top, width, height );
+        return TRUE;
+
+    case PATINVERT:  /* 0x5a */
+          /* FIXME: This is not really correct, but for now PATINVERT is */
+          /* used to draw the window moving frame, so it has to be fast. */
+        if (!DC_SetupGCForBrush( dcDst )) return TRUE;
+        XSetFunction( display, dcDst->u.x.gc, GXxor );
+        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+                        visRectDst.left, visRectDst.top, width, height );
+        return TRUE;
+        
+    case SRCCOPY:  /* 0xcc */
+        if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
+        {
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+	    XCopyArea( display, dcSrc->u.x.drawable,
+                       dcDst->u.x.drawable, dcDst->u.x.gc,
+                       visRectSrc.left, visRectSrc.top,
+                       width, height, visRectDst.left, visRectDst.top );
+            return TRUE;
+        }
+        if (dcSrc->w.bitsPerPixel == 1)
+        {
+            XSetBackground( display, dcDst->u.x.gc, dcDst->w.textPixel );
+            XSetForeground( display, dcDst->u.x.gc, dcDst->w.backgroundPixel );
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+	    XCopyPlane( display, dcSrc->u.x.drawable,
+                        dcDst->u.x.drawable, dcDst->u.x.gc,
+                        visRectSrc.left, visRectSrc.top,
+                        width, height, visRectDst.left, visRectDst.top, 1 );
+            return TRUE;
+        }
+        break;
+
+    case PATCOPY:  /* 0xf0 */
+        if (!DC_SetupGCForBrush( dcDst )) return TRUE;
+        XSetFunction( display, dcDst->u.x.gc, GXcopy );
+        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+                        visRectDst.left, visRectDst.top, width, height );
+        return TRUE;
+
+    case WHITENESS:  /* 0xff */
+        if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
+            XSetFunction( display, dcDst->u.x.gc, GXset );
+        else
+        {
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+            XSetForeground( display, dcDst->u.x.gc,
+                            COLOR_PaletteToPixel[COLOR_ColormapSize-1] );
+            XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
+        }
+        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+                        visRectDst.left, visRectDst.top, width, height );
+        return TRUE;
     }
-    val.ts_x_origin = dc->w.DCOrgX + dc->w.brushOrgX;
-    val.ts_y_origin = dc->w.DCOrgY + dc->w.brushOrgY;
-    XChangeGC( display, gc,
-              GCForeground | GCBackground | GCFillStyle |
-              GCTileStipXOrigin | GCTileStipYOrigin | mask,
-              &val );
-    if (pixmap) XFreePixmap( display, pixmap );
+
+    tmpGC = XCreateGC( display, dcDst->u.x.drawable, 0, NULL );
+    pixmaps[DST] = XCreatePixmap( display, rootWindow, width, height,
+                                  dcDst->w.bitsPerPixel );
+    if (useSrc)
+    {
+        pixmaps[SRC] = XCreatePixmap( display, rootWindow, width, height,
+                                      dcDst->w.bitsPerPixel );
+        if (fStretch)
+            BITBLT_GetSrcAreaStretch( dcSrc, dcDst, pixmaps[SRC], tmpGC,
+                                      xSrc, ySrc, widthSrc, heightSrc,
+                                      xDst, yDst, widthDst, heightDst,
+                                      &visRectSrc, &visRectDst );
+        else
+            BITBLT_GetSrcArea( dcSrc, dcDst, pixmaps[SRC], tmpGC,
+                               xSrc, ySrc, &visRectSrc );
+    }
+    if (useDst) BITBLT_GetDstArea( dcDst, pixmaps[DST], tmpGC, &visRectDst );
+    if (usePat) fNullBrush = !DC_SetupGCForPatBlt( dcDst, tmpGC, TRUE );
+    else fNullBrush = FALSE;
+    destUsed = FALSE;
+
+    for (opcode = BITBLT_Opcodes[(rop >> 16) & 0xff]; *opcode; opcode++)
+    {
+        if (OP_DST(*opcode) == DST) destUsed = TRUE;
+        XSetFunction( display, tmpGC, OP_ROP(*opcode) );
+        switch(OP_SRCDST(*opcode))
+        {
+        case OP_ARGS(DST,TMP):
+        case OP_ARGS(SRC,TMP):
+            if (!pixmaps[TMP])
+                pixmaps[TMP] = XCreatePixmap( display, rootWindow,
+                                              width, height,
+                                              dcDst->w.bitsPerPixel );
+            /* fall through */
+        case OP_ARGS(DST,SRC):
+        case OP_ARGS(SRC,DST):
+        case OP_ARGS(TMP,SRC):
+        case OP_ARGS(TMP,DST):
+            XCopyArea( display, pixmaps[OP_SRC(*opcode)],
+                       pixmaps[OP_DST(*opcode)], tmpGC,
+                       0, 0, width, height, 0, 0 );
+            break;
+
+        case OP_ARGS(PAT,TMP):
+            if (!pixmaps[TMP] && !fNullBrush)
+                pixmaps[TMP] = XCreatePixmap( display, rootWindow,
+                                              width, height,
+                                              dcDst->w.bitsPerPixel );
+            /* fall through */
+        case OP_ARGS(PAT,DST):
+        case OP_ARGS(PAT,SRC):
+            if (!fNullBrush)
+                XFillRectangle( display, pixmaps[OP_DST(*opcode)],
+                                tmpGC, 0, 0, width, height );
+            break;
+        }
+    }
+    XSetFunction( display, dcDst->u.x.gc, GXcopy );
+    BITBLT_PutDstArea( dcDst, pixmaps[destUsed ? DST : SRC],
+                       dcDst->u.x.gc, &visRectDst );
+    XFreePixmap( display, pixmaps[DST] );
+    if (pixmaps[SRC]) XFreePixmap( display, pixmaps[SRC] );
+    if (pixmaps[TMP]) XFreePixmap( display, pixmaps[TMP] );
+    XFreeGC( display, tmpGC );
     return TRUE;
 }
 
@@ -718,43 +1196,11 @@
 	return TRUE;
     }
 
-    dprintf_gdi(stddeb, "PatBlt: %d %d,%d %dx%d %06lx\n",
+    dprintf_bitblt(stddeb, "PatBlt: %d %d,%d %dx%d %06lx\n",
 	    hdc, left, top, width, height, rop );
 
-      /* Convert ROP3 code to ROP2 code */
-    rop >>= 16;
-    if (!DC_SetupGCForBrush( dc )) rop &= 0x0f;
-    else rop = (rop & 0x03) | ((rop >> 4) & 0x0c);
-
-      /* Special case for BLACKNESS and WHITENESS */
-    if (!Options.usePrivateMap && ((rop == R2_BLACK-1) || (rop == R2_WHITE-1)))
-    {
-        XSetForeground( display, dc->u.x.gc, (rop == R2_BLACK-1) ?
-                      BlackPixelOfScreen(screen) : WhitePixelOfScreen(screen));
-        XSetFillStyle( display, dc->u.x.gc, FillSolid );
-        rop = R2_COPYPEN;
-    }
-
-    XSetFunction( display, dc->u.x.gc, DC_XROPfunction[rop] );
-
-    left = dc->w.DCOrgX + XLPTODP( dc, left );
-    top  = dc->w.DCOrgY + YLPTODP( dc, top );
-
-      /* Convert dimensions to device coords */
-    if ((width = (width * dc->w.VportExtX) / dc->w.WndExtX) < 0)
-    {
-        width = -width;
-        left -= width;
-    }
-    if ((height = (height * dc->w.VportExtY) / dc->w.WndExtY) < 0)
-    {
-        height = -height;
-        top -= height;
-    }
-
-    XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
-                    left, top, width, height );
-    return TRUE;
+    return BITBLT_InternalStretchBlt( dc, left, top, width, height,
+                                      NULL, 0, 0, 0, 0, rop );
 }
 
 
@@ -765,605 +1211,52 @@
 	     HDC hdcSrc, short xSrc, short ySrc, DWORD rop )
 {
     DC *dcDst, *dcSrc;
-    BOOL usePat, useSrc, useDst, destUsed;
-    RECT dstRect, tmpRect, clipRect;
-    const BYTE *opcode;
-    Pixmap srcPixmap = 0, dstPixmap = 0, tmpPixmap = 0;
-    GC tmpGC = 0;
 
-    usePat = (((rop >> 4) & 0x0f0000) != (rop & 0x0f0000));
-    useSrc = (((rop >> 2) & 0x330000) != (rop & 0x330000));
-    useDst = (((rop >> 1) & 0x550000) != (rop & 0x550000));
-
-    dprintf_gdi(stddeb, "BitBlt: %04x %d,%d %dx%d %04x %d,%d %06lx\n",
-                hdcDst, xDst, yDst, width, height, hdcSrc, xSrc, ySrc, rop);
-
-    if (!useSrc)
-	return PatBlt( hdcDst, xDst, yDst, width, height, rop );
-
-    dcDst = (DC *) GDI_GetObjPtr( hdcDst, DC_MAGIC );
-    if (!dcDst) 
+    if (!(dcDst = (DC *)GDI_GetObjPtr( hdcDst, DC_MAGIC )))
     {
-	dcDst = (DC *)GDI_GetObjPtr(hdcDst, METAFILE_DC_MAGIC);
-	if (!dcDst) return FALSE;
-	MF_BitBlt(dcDst, xDst, yDst, width, height,
-		  hdcSrc, xSrc, ySrc, rop);
-	return TRUE;
+        dcDst = (DC *)GDI_GetObjPtr( hdcDst, METAFILE_DC_MAGIC );
+        if (!dcDst) return FALSE;
+        return MF_BitBlt( dcDst, xDst, yDst, width, height,
+                          hdcSrc, xSrc, ySrc, rop );
     }
     dcSrc = (DC *) GDI_GetObjPtr( hdcSrc, DC_MAGIC );
-    if (!dcSrc) return FALSE;
 
-    if ((width * dcSrc->w.VportExtX / dcSrc->w.WndExtX !=
-         width * dcDst->w.VportExtX / dcDst->w.WndExtX) ||
-        (height * dcSrc->w.VportExtY / dcSrc->w.WndExtY !=
-         height * dcDst->w.VportExtY / dcDst->w.WndExtY))
-	return StretchBlt( hdcDst, xDst, yDst, width, height,
-                           hdcSrc, xSrc, ySrc, width, height, rop );
+    dprintf_bitblt(stddeb,
+                "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);
 
-    xSrc = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc );
-    ySrc = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc );
-    xDst = dcDst->w.DCOrgX + XLPTODP( dcDst, xDst );
-    yDst = dcDst->w.DCOrgY + YLPTODP( dcDst, yDst );
-    width  = width * dcDst->w.VportExtX / dcDst->w.WndExtX;
-    height = height * dcDst->w.VportExtY / dcDst->w.WndExtY;
-
-    tmpRect.left   = min( xDst, xDst + width );
-    tmpRect.top    = min( yDst, yDst + height );
-    tmpRect.right  = max( xDst, xDst + width );
-    tmpRect.bottom = max( yDst, yDst + height );
-
-    GetClipBox( hdcDst, &clipRect );
-    OffsetRect( &clipRect, dcDst->w.DCOrgX, dcDst->w.DCOrgY );
-    if (!IntersectRect( &dstRect, &tmpRect, &clipRect )) return TRUE;
-
-    xSrc  += dstRect.left - xDst;
-    ySrc  += dstRect.top - yDst;
-    xDst   = dstRect.left;
-    yDst   = dstRect.top;
-    width  = dstRect.right - dstRect.left;
-    height = dstRect.bottom - dstRect.top;
-
-    if (rop == SRCCOPY)  /* Optimisation for SRCCOPY */
-    {
-        DC_SetupGCForText( dcDst );
-        if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
-        {
-	    XCopyArea( display, dcSrc->u.x.drawable, dcDst->u.x.drawable,
-                       dcDst->u.x.gc, xSrc, ySrc, width, height, xDst, yDst );
-            return TRUE;
-        }
-        if (dcSrc->w.bitsPerPixel == 1)
-        {
-	    XCopyPlane( display, dcSrc->u.x.drawable,
-                        dcDst->u.x.drawable, dcDst->u.x.gc,
-                        xSrc, ySrc, width, height, xDst, yDst, 1);
-            return TRUE;
-        }
-    }
-
-    rop >>= 16;
-
-    /* printf( "BitBlt: applying rop %lx\n", rop ); */
-    tmpGC = XCreateGC( display, rootWindow, 0, NULL );
-    srcPixmap = XCreatePixmap( display, rootWindow, width, height,
-                               dcDst->w.bitsPerPixel );
-    dstPixmap = XCreatePixmap( display, rootWindow, width, height,
-                               dcDst->w.bitsPerPixel );
-    if (useSrc)
-        BITBLT_GetArea( hdcSrc, hdcDst, srcPixmap, tmpGC,
-                        xSrc, ySrc, width, height );
-    if (useDst)
-        BITBLT_GetArea( hdcDst, hdcDst, dstPixmap, tmpGC,
-                        xDst, yDst, width, height );
-    if (usePat)
-        BITBLT_SelectBrush( dcDst, tmpGC );
-    destUsed = FALSE;
-
-    for (opcode = BITBLT_Opcodes[rop & 0xff]; *opcode; opcode++)
-    {
-        switch(*opcode >> 4)
-        {
-        case OP_ARGS(DST,TMP):
-            if (!tmpPixmap) tmpPixmap = XCreatePixmap( display, rootWindow,
-                                                       width, height,
-                                                       dcDst->w.bitsPerPixel );
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XCopyArea( display, dstPixmap, tmpPixmap, tmpGC,
-                       0, 0, width, height, 0, 0 );
-            break;
-
-        case OP_ARGS(DST,SRC):
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XCopyArea( display, dstPixmap, srcPixmap, tmpGC,
-                       0, 0, width, height, 0, 0 );
-            break;
-
-        case OP_ARGS(SRC,TMP):
-            if (!tmpPixmap) tmpPixmap = XCreatePixmap( display, rootWindow,
-                                                       width, height,
-                                                       dcDst->w.bitsPerPixel );
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XCopyArea( display, srcPixmap, tmpPixmap, tmpGC,
-                       0, 0, width, height, 0, 0 );
-            break;
-
-        case OP_ARGS(SRC,DST):
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XCopyArea( display, srcPixmap, dstPixmap, tmpGC,
-                       0, 0, width, height, 0, 0 );
-            destUsed = TRUE;
-            break;
-
-        case OP_ARGS(PAT,TMP):
-            if (!tmpPixmap) tmpPixmap = XCreatePixmap( display, rootWindow,
-                                                       width, height,
-                                                       dcDst->w.bitsPerPixel );
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XFillRectangle( display, tmpPixmap, tmpGC, 0, 0, width, height );
-            break;
-
-        case OP_ARGS(PAT,DST):
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XFillRectangle( display, dstPixmap, tmpGC, 0, 0, width, height );
-            destUsed = TRUE;
-            break;
-
-        case OP_ARGS(PAT,SRC):
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XFillRectangle( display, srcPixmap, tmpGC, 0, 0, width, height );
-            break;
-
-        case OP_ARGS(TMP,SRC):
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XCopyArea( display, tmpPixmap, srcPixmap, tmpGC,
-                       0, 0, width, height, 0, 0 );
-            break;
-
-        case OP_ARGS(TMP,DST):
-            XSetFunction( display, tmpGC, *opcode & 0x0f );
-            XCopyArea( display, tmpPixmap, dstPixmap, tmpGC,
-                       0, 0, width, height, 0, 0 );
-            destUsed = TRUE;
-            break;
-        }
-    }
-    XSetFunction( display, dcDst->u.x.gc, GXcopy );
-    BITBLT_PutArea( hdcDst, destUsed ? dstPixmap : srcPixmap,
-                    dcDst->u.x.gc, xDst, yDst, width, height );
-    XFreePixmap( display, dstPixmap );
-    XFreePixmap( display, srcPixmap );
-    if (tmpPixmap) XFreePixmap( display, tmpPixmap );
-    XFreeGC( display, tmpGC );
-    return TRUE;
-#if 0
-    if (((rop & 0x0f) == (rop >> 4))&&(rop!=0xbb))
-	/* FIXME: Test, whether more than just 0xbb has to be excluded */
-      {
-        XSetFunction( display, dcDst->u.x.gc, DC_XROPfunction[rop & 0x0f] );
-        if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
-        {
-	    XCopyArea( display, dcSrc->u.x.drawable,
-	    	       dcDst->u.x.drawable, dcDst->u.x.gc,
-		       min(xs1,xs2), min(ys1,ys2), abs(xs2-xs1), abs(ys2-ys1),
-		       min(xd1,xd2), min(yd1,yd2) );
-        }
-        else
-        {
-	   if (dcSrc->w.bitsPerPixel != 1) return FALSE;
-	    XCopyPlane( display, dcSrc->u.x.drawable,
-	  	        dcDest->u.x.drawable, dcDest->u.x.gc,
-		        min(xs1,xs2), min(ys1,ys2), abs(xs2-xs1), abs(ys2-ys1),
-		        min(xd1,xd2), min(yd1,yd2), 1 );
-        }
-      }  
-    else
-      {
-        XImage *sxi, *dxi, *bxi;
-	int x,y,s,d,p,res,ofs,i,cp,cs,cd,cres;
-	XColor sentry,dentry,pentry,entry;
-	long colors[256];
-
-	/* HDC hdcBrush = CreateCompatibleDC(hdcDest);
-	DC *dcBrush;*/
-	RECT r = {min(xDest,xDest+width), min(yDest,yDest+height), 
-		  max(xDest,xDest+width), max(yDest,yDest+height)};
-	HBRUSH cur_brush=SelectObject(hdcDest, GetStockObject(BLACK_BRUSH));
-	SelectObject(hdcDest, cur_brush);
-        /* FillRect(hdcBrush, &r, cur_brush);*/
-        sxi = BITBLT_GetImage( hdcSrc, min(xs1,xs2), min(ys1,ys2),
-                               abs(xs2-xs1), abs(ys2-ys1) );
-        dxi = BITBLT_GetImage( hdcDest, min(xd1,xd2), min(yd1,yd2),
-                               abs(xs2-xs1), abs(ys2-ys1) );
-        /* dcBrush = (DC *) GDI_GetObjPtr( hdcBrush, DC_MAGIC );*/
-        /* bxi=XGetImage(display, dcBrush->u.x.drawable, min(xd1,xd2),min(yd1,yd2),
-             abs(xs2-xs1), abs(ys2-ys1), AllPlanes, ZPixmap);*/
-	/* FIXME: It's really not necessary to do this on the visible screen */
-        FillRect(hdcDest, &r, cur_brush);
-        bxi = BITBLT_GetImage( hdcDest, min(xd1,xd2), min(yd1,yd2),
-                               abs(xs2-xs1), abs(ys2-ys1) );
-        for (i=0; i<min(256,1<<(dcDest->w.bitsPerPixel)); i++)
-	{
-	  entry.pixel = i;
-	  XQueryColor ( display, COLOR_WinColormap, &entry);
-	  colors[i] = (int) RGB( entry.red>>8, entry.green>>8, entry.blue>>8 );
-	}
-	if (dcSrc->w.bitsPerPixel == dcDest->w.bitsPerPixel)
-        {
- 	  for(x=0; x<abs(xs2-xs1); x++)
-	  {
-	    for(y=0; y<abs(ys2-ys1); y++)
-	    {
-	      s = XGetPixel(sxi, x, y);
-	      d = XGetPixel(dxi, x, y);
-	      p = XGetPixel(bxi, x, y);
-	      if (s<256)
-		cs=colors[s];
-	      else
-	      {
-	        sentry.pixel = s;
-		XQueryColor ( display, COLOR_WinColormap, &sentry);
-		cs = (int) RGB( sentry.red>>8,sentry.green>>8, sentry.blue>>8 );
-	      }
-	      if (d<256)
-		cd=colors[d];
-	      else
-	      {
-       		dentry.pixel = d;
-		XQueryColor ( display, COLOR_WinColormap, &dentry);
-		cd = (int) RGB( dentry.red>>8, dentry.green>>8,dentry.blue>>8 );
-	      }
-	      if (p<256)
-		cp=colors[p];
-	      else
-    	      {	      
-	        pentry.pixel = p;
-	        XQueryColor ( display, COLOR_WinColormap, &pentry);
-	        cp = (int) RGB( pentry.red>>8, pentry.green>>8,pentry.blue>>8 );
-	      }
-	      cres = 0;
-	      for(i=0; i<24; i++)
- 	      {
-		ofs=1<<(((cp>>i)&1)*4+((cs>>i)&1)*2+((cd>>i)&1));
-		if (rop & ofs)
-		  cres |= (1<<i);
-	      }
-	      if (cres==cs)
-		res=s;
-	      else if (cres==cd)
-		res=d;
-	      else if (cres==cp)
-		res=p;
-	      else
-	      {
-		res = -1;
-	        for (i=0; i<min(256,1<<(dcDest->w.bitsPerPixel)); i++)
-		  if (colors[i]==cres)
-		  {
-		    res = i;
-		    break;
-	          }
-		if (res == -1)
-	          res = GetNearestPaletteIndex(dcDest->w.hPalette, res);
-	      } 	
-	      XPutPixel(dxi, x, y, res);
-	    }
-	  }
-        }
-	else
-	    fprintf(stderr,"BitBlt // depths different!\n");
-	XPutImage(display, dcDest->u.x.drawable, dcDest->u.x.gc,
-            dxi, 0, 0, min(xd1,xd2), min(yd1,yd2), abs(xs2-xs1), abs(ys2-ys1)+38);
-	XDestroyImage(sxi);
-        XDestroyImage(dxi);
-	XDestroyImage(bxi);
-	/*DeleteDC(hdcBrush);*/
-      }
-#endif
-    return TRUE;
+    return BITBLT_InternalStretchBlt( dcDst, xDst, yDst, width, height,
+                                      dcSrc, xSrc, ySrc, width, height, rop );
 }
 
 
-
-/***********************************************************************
- *           black on white stretch -- favors color pixels over white
- * 
- */
-static void bonw_stretch(XImage *sxi, XImage *dxi, 
-	short widthSrc, short heightSrc, short widthDest, short heightDest)
-{
-    float deltax, deltay, sourcex, sourcey, oldsourcex, oldsourcey;
-    register int x, y;
-    Pixel whitep;
-    int totalx, totaly, xavgwhite, yavgwhite;
-    register int i;
-    int endx, endy;
-    
-    deltax = (float)widthSrc/widthDest;
-    deltay = (float)heightSrc/heightDest;
-    whitep  = WhitePixel(display, DefaultScreen(display));
-
-    oldsourcex = 0;
-    for (x=0, sourcex=0.0; x<widthDest; 
-			x++, oldsourcex=sourcex, sourcex+=deltax) {
-        xavgwhite = 0;
-	if (deltax > 1.0) {
-            totalx = 0;
-	    endx = (int)sourcex;
-	    for (i=(int)oldsourcex; i<=endx; i++)
-	        if (XGetPixel(sxi, i, (int)sourcey) == whitep)
-	            totalx++;
-  	    xavgwhite = (totalx > (int)(deltax / 2.0));
-	} else {
-	    xavgwhite = 0;
-	}
-
-        oldsourcey = 0;
-        for (y=0, sourcey=0.0; y<heightDest; 
-				y++, oldsourcey=sourcey, sourcey+=deltay) {
-	    yavgwhite = 0;
-	    if (deltay > 1.0) {
-	        totaly = 0;
-	        endy = (int)sourcey;
-	        for (i=(int)oldsourcey; i<=endy; i++) 
-	            if (XGetPixel(sxi, (int)sourcex, i) == whitep)
-		        totaly++;
-	        yavgwhite = (totaly > ((int)deltay / 2));
-	    } else {
-		yavgwhite = 0;
-	    }
-	    if (xavgwhite && yavgwhite)
-	        XPutPixel(dxi, x, y, whitep);
-	    else
-	        XPutPixel(dxi, x, y, XGetPixel(sxi, (int)sourcex, (int)sourcey));
-
-	} /* for all y in dest */
-    } /* for all x in dest */
-
-}
-
-/***********************************************************************
- *           white on black stretch -- favors color pixels over black
- * 
- */
-static void wonb_stretch(XImage *sxi, XImage *dxi, 
-	short widthSrc, short heightSrc, short widthDest, short heightDest)
-{
-    float deltax, deltay, sourcex, sourcey, oldsourcex, oldsourcey;
-    register int x, y;
-    Pixel blackp;
-    int totalx, totaly, xavgblack, yavgblack;
-    register int i;
-    int endx, endy;
-    
-    deltax = (float)widthSrc/widthDest;
-    deltay = (float)heightSrc/heightDest;
-    blackp  = WhitePixel(display, DefaultScreen(display));
-
-    oldsourcex = 0;
-    for (x=0, sourcex=0.0; x<widthDest; 
-			x++, oldsourcex=sourcex, sourcex+=deltax) {
-        xavgblack = 0;
-	if (deltax > 1.0) {
-            totalx = 0;
-	    endx = (int)sourcex;
-	    for (i=(int)oldsourcex; i<=endx; i++)
-	        if (XGetPixel(sxi, i, (int)sourcey) == blackp)
-	            totalx++;
-  	    xavgblack = (totalx > (int)(deltax / 2.0));
-	} else {
-	    xavgblack = 0;
-	}
-
-        oldsourcey = 0;
-        for (y=0, sourcey=0.0; y<heightDest; 
-				y++, oldsourcey=sourcey, sourcey+=deltay) {
-	    yavgblack = 0;
-	    if (deltay > 1.0) {
-	        totaly = 0;
-	        endy = (int)sourcey;
-	        for (i=(int)oldsourcey; i<=endy; i++) 
-	            if (XGetPixel(sxi, (int)sourcex, i) == blackp)
-		        totaly++;
-	        yavgblack = (totaly > ((int)deltay / 2));
-	    } else {
-		yavgblack = 0;
-	    }
-	    if (xavgblack && yavgblack)
-	        XPutPixel(dxi, x, y, blackp);
-	    else
-	        XPutPixel(dxi, x, y, XGetPixel(sxi, (int)sourcex, (int)sourcey));
-
-	} /* for all y in dest */
-    } /* for all x in dest */
-}
-
-/* We use the 32-bit to 64-bit multiply and 64-bit to 32-bit divide of the */
-/* 386 (which gcc doesn't know well enough) to efficiently perform integer */
-/* scaling without having to worry about overflows. */
-
-/* ##### muldiv64() borrowed from svgalib 1.03 ##### */
-static __inline__ int muldiv64( int m1, int m2, int d ) 
-{
-	/* int32 * int32 -> int64 / int32 -> int32 */
-#ifdef i386	
-	int result;
-	__asm__(
-		"imull %%edx\n\t"
-		"idivl %3\n\t"
-		: "=&a" (result)		/* out */
-		: "0" (m1), "d" (m2), "g" (d)	/* in */
-		: "%edx"			/* mod */
-	);
-	return result;
-#else
-	return m1 * m2 / d;
-#endif
-}
-
-/***********************************************************************
- *          color stretch -- deletes unused pixels
- * 
- */
-static void color_stretch(XImage *sxi, XImage *dxi, 
-	short widthSrc, short heightSrc, short widthDest, short heightDest)
-{
-	register int x, y, sx, sy, xfactor, yfactor;
-
-	xfactor = muldiv64(widthSrc, 65536, widthDest);
-	yfactor = muldiv64(heightSrc, 65536, heightDest);
-
-	sy = 0;
-
-	for (y = 0; y < heightDest;) 
-	{
-		int sourcey = sy >> 16;
-		sx = 0;
-		for (x = 0; x < widthDest; x++) {
-            		XPutPixel(dxi, x, y, XGetPixel(sxi, sx >> 16, sourcey));
-			sx += xfactor;
-		}
-		y++;
-		while (y < heightDest) {
-			int py;
-
-			sourcey = sy >> 16;
-			sy += yfactor;
-
-			if ((sy >> 16) != sourcey)
-				break;
-
-			/* vertical stretch => copy previous line */
-			
-			py = y - 1;
-
-			for (x = 0; x < widthDest; x++)
-	            		XPutPixel(dxi, x, y, XGetPixel(dxi, x, py));
-        	    	y++;
-		}
-	}
-}
-
 /***********************************************************************
  *           StretchBlt    (GDI.35)
- * 
- * 	o StretchBlt is CPU intensive so we only call it if we have
- *        to.  Checks are made to see if we can call BitBlt instead.
- *
- * 	o the stretching is slowish, some integer interpolation would
- *        speed it up.
- *
- *      o only black on white and color copy have been tested
  */
-BOOL StretchBlt( HDC hdcDest, short xDest, short yDest, short widthDest, short heightDest,
-               HDC hdcSrc, short xSrc, short ySrc, short widthSrc, short heightSrc, DWORD rop )
+BOOL StretchBlt( HDC hdcDst, short xDst, short yDst,
+                 short widthDst, short heightDst,
+                 HDC hdcSrc, short xSrc, short ySrc,
+                 short widthSrc, short heightSrc, DWORD rop )
 {
-    int xs1, xs2, ys1, ys2;
-    int xd1, xd2, yd1, yd2;
-    DC *dcDest, *dcSrc;
-    XImage *sxi, *dxi;
-    DWORD saverop = rop;
-    WORD stretchmode;
+    DC *dcDst, *dcSrc;
 
-    dprintf_gdi(stddeb, "StretchBlt: %d %d,%d %dx%d %d %d,%d %dx%d %06lx\n",
-           hdcDest, xDest, yDest, widthDest, heightDest, hdcSrc, xSrc, 
-           ySrc, widthSrc, heightSrc, rop );
-    dprintf_gdi(stddeb, "StretchMode is %x\n", 
-           ((DC *)GDI_GetObjPtr(hdcDest, DC_MAGIC))->w.stretchBltMode);	
-
-	if (widthDest == 0 || heightDest == 0) return FALSE;
-	if (widthSrc == 0 || heightSrc == 0) return FALSE;
-    if ((rop & 0xcc0000) == ((rop & 0x330000) << 2))
-        return PatBlt( hdcDest, xDest, yDest, widthDest, heightDest, rop );
-
-    /* don't stretch the bitmap unless we have to; if we don't,
-     * call BitBlt for a performance boost
-     */
-
-    if (widthSrc == widthDest && heightSrc == heightDest) {
-	return BitBlt(hdcDest, xDest, yDest, widthSrc, heightSrc,
-               hdcSrc, xSrc, ySrc, rop);
-    }
-
-    rop >>= 16;
-    if ((rop & 0x0f) != (rop >> 4))
+    if (!(dcDst = (DC *) GDI_GetObjPtr( hdcDst, DC_MAGIC )))
     {
-        fprintf(stdnimp, "StretchBlt: Unimplemented ROP %02lx\n", rop );
-        return FALSE;
+	if (!(dcDst = (DC *)GDI_GetObjPtr( hdcDst, METAFILE_DC_MAGIC )))
+            return FALSE;
+        return MF_StretchBlt( dcDst, xDst, yDst, widthDst, heightDst,
+                              hdcSrc, xSrc, ySrc, widthSrc, heightSrc, rop );
     }
 
     dcSrc = (DC *) GDI_GetObjPtr( hdcSrc, DC_MAGIC );
-    if (!dcSrc) return FALSE;
-    dcDest = (DC *) GDI_GetObjPtr( hdcDest, DC_MAGIC );
-    if (!dcDest) 
-    {
-	dcDest = (DC *)GDI_GetObjPtr(hdcDest, METAFILE_DC_MAGIC);
-	if (!dcDest) return FALSE;
-	MF_StretchBlt(dcDest, xDest, yDest, widthDest, heightDest,
-		  hdcSrc, xSrc, ySrc, widthSrc, heightSrc, saverop);
-	return TRUE;
-    }
+    dprintf_bitblt(stddeb,
+          "StretchBlt: %04x %d,%d %dx%dx%d -> %04x %d,%d %dx%dx%d rop=%06lx\n",
+                   hdcSrc, xSrc, ySrc, widthSrc, heightSrc,
+                   dcSrc ? dcSrc->w.bitsPerPixel : 0, hdcDst, xDst, yDst,
+                   widthDst, heightDst, dcDst->w.bitsPerPixel, rop );
 
-    xs1 = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc );
-    xs2 = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc + widthSrc );
-    ys1 = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc );
-    ys2 = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc + heightSrc );
-    xd1 = dcDest->w.DCOrgX + XLPTODP( dcDest, xDest );
-    xd2 = dcDest->w.DCOrgX + XLPTODP( dcDest, xDest + widthDest );
-    yd1 = dcDest->w.DCOrgY + YLPTODP( dcDest, yDest );
-    yd2 = dcDest->w.DCOrgY + YLPTODP( dcDest, yDest + heightDest );
-
-
-    /* get a source and destination image so we can manipulate
-     * the pixels
-     */
-
-    sxi = BITBLT_GetImage( hdcSrc, xs1, ys1, widthSrc, heightSrc );
-    dxi = XCreateImage(display, DefaultVisualOfScreen(screen),
-	  		    screenDepth, ZPixmap,
-			    0, NULL, widthDest, heightDest,
-			    32, 0);
-    dxi->data = malloc(dxi->bytes_per_line * heightDest);
-
-    stretchmode = ((DC *)GDI_GetObjPtr(hdcDest, DC_MAGIC))->w.stretchBltMode;
-
-     /* the actual stretching is done here, we'll try to use
-      * some interolation to get some speed out of it in
-      * the future
-      */
-
-    switch (stretchmode) {
-	case BLACKONWHITE:
-		color_stretch(sxi, dxi, widthSrc, heightSrc, 
-				widthDest, heightDest);
-/*		bonw_stretch(sxi, dxi, widthSrc, heightSrc,
-				widthDest, heightDest);
-*/		break;
-	case WHITEONBLACK:
-		color_stretch(sxi, dxi, widthSrc, heightSrc, 
-				widthDest, heightDest);
-/*		wonb_stretch(sxi, dxi, widthSrc, heightSrc, 
-				widthDest, heightDest);
-*/		break;
-	case COLORONCOLOR:
-		color_stretch(sxi, dxi, widthSrc, heightSrc, 
-				widthDest, heightDest);
-		break;
-	default:
-		fprintf(stderr, "StretchBlt: unknown stretchmode '%d'\n",
-			stretchmode);
-		break;
-    }
-
-    DC_SetupGCForText(dcDest);
-    XSetFunction(display, dcDest->u.x.gc, DC_XROPfunction[rop & 0x0f]);
-    XPutImage(display, dcDest->u.x.drawable, dcDest->u.x.gc,
-	 	dxi, 0, 0, min(xd1,xd2), min(yd1,yd2), 
-		widthDest, heightDest);
-
-    /* now free the images we created */
-
-    XDestroyImage(sxi);
-    XDestroyImage(dxi);
-
-    return TRUE;
+    return BITBLT_InternalStretchBlt( dcDst, xDst, yDst, widthDst, heightDst,
+                                      dcSrc, xSrc, ySrc, widthSrc, heightSrc,
+                                      rop );
 }
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 86c6e3b..8191585 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -204,9 +204,9 @@
 
 
 /***********************************************************************
- *           BMP_DeleteObject
+ *           BITMAP_DeleteObject
  */
-BOOL BMP_DeleteObject( HBITMAP hbitmap, BITMAPOBJ * bitmap )
+BOOL BITMAP_DeleteObject( HBITMAP hbitmap, BITMAPOBJ * bitmap )
 {
     XFreePixmap( display, bitmap->pixmap );
     return GDI_FreeObject( hbitmap );
@@ -214,9 +214,9 @@
 
 	
 /***********************************************************************
- *           BMP_GetObject
+ *           BITMAP_GetObject
  */
-int BMP_GetObject( BITMAPOBJ * bmp, int count, LPSTR buffer )
+int BITMAP_GetObject( BITMAPOBJ * bmp, int count, LPSTR buffer )
 {
     if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
     memcpy( buffer, &bmp->bitmap, count );
diff --git a/objects/brush.c b/objects/brush.c
index 1bfed42..9d185af 100644
--- a/objects/brush.c
+++ b/objects/brush.c
@@ -1,21 +1,20 @@
 /*
  * GDI brush objects
  *
- * Copyright 1993 Alexandre Julliard
- *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
+ * Copyright 1993, 1994  Alexandre Julliard
+ */
 
-#include "gdi.h"
+#include <stdlib.h>
+#include "brush.h"
 #include "bitmap.h"
 #include "metafile.h"
-#include "stddebug.h"
 #include "color.h"
+#include "stddebug.h"
 #include "debug.h"
 
 #define NB_HATCH_STYLES  6
 
-static char HatchBrushes[NB_HATCH_STYLES][8] =
+static const char HatchBrushes[NB_HATCH_STYLES][8] =
 {
     { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HS_HORIZONTAL */
     { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HS_VERTICAL   */
@@ -25,6 +24,118 @@
     { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }  /* HS_DIAGCROSS  */
 };
 
+  /* Levels of each primary for dithering */
+#define PRIMARY_LEVELS  3  
+#define TOTAL_LEVELS    (PRIMARY_LEVELS*PRIMARY_LEVELS*PRIMARY_LEVELS)
+
+ /* Dithering matrix size  */
+#define MATRIX_SIZE     8
+#define MATRIX_SIZE_2   (MATRIX_SIZE*MATRIX_SIZE)
+
+  /* Total number of possible levels for a dithered primary color */
+#define DITHER_LEVELS   (MATRIX_SIZE_2 * (PRIMARY_LEVELS-1) + 1)
+
+  /* Dithering matrix */
+static const int dither_matrix[MATRIX_SIZE_2] =
+{
+     0, 32,  8, 40,  2, 34, 10, 42,
+    48, 16, 56, 24, 50, 18, 58, 26,
+    12, 44,  4, 36, 14, 46,  6, 38,
+    60, 28, 52, 20, 62, 30, 54, 22,
+     3, 35, 11, 43,  1, 33,  9, 41,
+    51, 19, 59, 27, 49, 17, 57, 25,
+    15, 47,  7, 39, 13, 45,  5, 37,
+    63, 31, 55, 23, 61, 29, 53, 21
+};
+
+  /* Mapping between (R,G,B) triples and EGA colors */
+static const int EGAmapping[TOTAL_LEVELS] =
+{
+    0,  /* 000000 -> 000000 */
+    4,  /* 00007f -> 000080 */
+    12, /* 0000ff -> 0000ff */
+    2,  /* 007f00 -> 008000 */
+    6,  /* 007f7f -> 008080 */
+    6,  /* 007fff -> 008080 */
+    10, /* 00ff00 -> 00ff00 */
+    6,  /* 00ff7f -> 008080 */
+    14, /* 00ffff -> 00ffff */
+    1,  /* 7f0000 -> 800000 */
+    5,  /* 7f007f -> 800080 */
+    5,  /* 7f00ff -> 800080 */
+    3,  /* 7f7f00 -> 808000 */
+    8,  /* 7f7f7f -> 808080 */
+    7,  /* 7f7fff -> c0c0c0 */
+    3,  /* 7fff00 -> 808000 */
+    7,  /* 7fff7f -> c0c0c0 */
+    7,  /* 7fffff -> c0c0c0 */
+    9,  /* ff0000 -> ff0000 */
+    5,  /* ff007f -> 800080 */
+    13, /* ff00ff -> ff00ff */
+    3,  /* ff7f00 -> 808000 */
+    7,  /* ff7f7f -> c0c0c0 */
+    7,  /* ff7fff -> c0c0c0 */
+    11, /* ffff00 -> ffff00 */
+    7,  /* ffff7f -> c0c0c0 */
+    15  /* ffffff -> ffffff */
+};
+
+#define PIXEL_VALUE(r,g,b) \
+    COLOR_mapEGAPixel[EGAmapping[((r)*PRIMARY_LEVELS+(g))*PRIMARY_LEVELS+(b)]]
+
+  /* X image for building dithered pixmap */
+static XImage *ditherImage = NULL;
+
+
+/***********************************************************************
+ *           BRUSH_Init
+ *
+ * Create the X image used for dithering.
+ */
+BOOL BRUSH_Init(void)
+{
+    XCREATEIMAGE( ditherImage, MATRIX_SIZE, MATRIX_SIZE, screenDepth );
+    return (ditherImage != NULL);
+}
+
+
+/***********************************************************************
+ *           BRUSH_DitherColor
+ */
+Pixmap BRUSH_DitherColor( DC *dc, COLORREF color )
+{
+    static COLORREF prevColor = 0xffffffff;
+    unsigned int x, y;
+    Pixmap pixmap;
+
+    if (color != prevColor)
+    {
+	int r = GetRValue( color ) * DITHER_LEVELS;
+	int g = GetGValue( color ) * DITHER_LEVELS;
+	int b = GetBValue( color ) * DITHER_LEVELS;
+	const int *pmatrix = dither_matrix;
+
+	for (y = 0; y < MATRIX_SIZE; y++)
+	{
+	    for (x = 0; x < MATRIX_SIZE; x++)
+	    {
+		int d  = *pmatrix++ * 256;
+		int dr = ((r + d) / MATRIX_SIZE_2) / 256;
+		int dg = ((g + d) / MATRIX_SIZE_2) / 256;
+		int db = ((b + d) / MATRIX_SIZE_2) / 256;
+		XPutPixel( ditherImage, x, y, PIXEL_VALUE(dr,dg,db) );
+	    }
+	}
+	prevColor = color;
+    }
+    
+    pixmap = XCreatePixmap( display, rootWindow,
+			    MATRIX_SIZE, MATRIX_SIZE, screenDepth );
+    XPutImage( display, pixmap, BITMAP_colorGC, ditherImage, 0, 0,
+	       0, 0, MATRIX_SIZE, MATRIX_SIZE );
+    return pixmap;
+}
+
 
 /***********************************************************************
  *           CreateBrushIndirect    (GDI.50)
@@ -172,14 +283,14 @@
 
 
 /***********************************************************************
- *           BRUSH_MakeSolidBrush
+ *           BRUSH_SelectSolidBrush
  */
 static void BRUSH_SelectSolidBrush( DC *dc, COLORREF color )
 {
     if ((dc->w.bitsPerPixel > 1) && (screenDepth <= 8) && !COLOR_IsSolid( color ))
     {
 	  /* Dithered brush */
-	dc->u.x.brush.pixmap = DITHER_DitherColor( dc, color );
+	dc->u.x.brush.pixmap = BRUSH_DitherColor( dc, color );
 	dc->u.x.brush.fillStyle = FillTiled;
 	dc->u.x.brush.pixel = 0;
     }
diff --git a/objects/clipping.c b/objects/clipping.c
index 48717e6..c633613 100644
--- a/objects/clipping.c
+++ b/objects/clipping.c
@@ -5,7 +5,7 @@
  */
 
 #include <stdio.h>
-#include "gdi.h"
+#include "region.h"
 #include "metafile.h"
 #include "stddebug.h"
 /* #define DEBUG_CLIPPING */
diff --git a/objects/color.c b/objects/color.c
index 3523880..68b029e 100644
--- a/objects/color.c
+++ b/objects/color.c
@@ -114,7 +114,7 @@
     colorTranslation = (WORD *) GDI_HEAP_ADDR( hSysColorTranslation );
     revTranslation   = (WORD *) GDI_HEAP_ADDR( hRevSysColorTranslation );
 
-    if (COLOR_WinColormap == DefaultColormapOfScreen(screen))
+    if ((COLOR_WinColormap == DefaultColormapOfScreen(screen)) && (screenDepth <= 8))
     {
         COLOR_PaletteToPixel = (int *)malloc( sizeof(int) * size );
         COLOR_PixelToPalette = (int *)malloc( sizeof(int) * size );
@@ -151,7 +151,7 @@
                 fprintf(stderr, "Warning: Not enough free colors. Try using the -privatemap option.\n" );
                 color.pixel = color.red = color.green = color.blue = 0;
             }
-            else
+            else if (COLOR_PaletteToPixel)
             {
                 COLOR_PaletteToPixel[pixel] = color.pixel;
                 COLOR_PixelToPalette[color.pixel] = pixel;
@@ -254,6 +254,14 @@
     WORD *mapping;
 
     if (screenDepth > 8) return color;
+    if (dc && (dc->w.bitsPerPixel == 1) && ((color >> 24) == 0))
+    {
+        if (((color >> 16) & 0xff) +
+            ((color >> 8) & 0xff) + (color & 0xff) > 255*3/2)
+            return 1;  /* white */
+        else return 0;  /* black */
+    }
+    
     switch(color >> 24)
     {
     case 0:  /* RGB */
diff --git a/objects/dc.c b/objects/dc.c
index df8e413..312f87f 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -3,8 +3,8 @@
  *
  * Copyright 1993 Alexandre Julliard
  *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
+ */
+
 #include <stdlib.h>
 #include <string.h>
 #include "gdi.h"
@@ -17,9 +17,57 @@
 
 static DeviceCaps * displayDevCaps = NULL;
 
-extern const WIN_DC_INFO DCVAL_defaultValues;
 extern void CLIPPING_UpdateGCRegion( DC * dc );     /* objects/clipping.c */
 
+  /* Default DC values */
+static const WIN_DC_INFO DC_defaultValues =
+{
+    0,                      /* flags */
+    NULL,                   /* devCaps */
+    0,                      /* hMetaFile */
+    0,                      /* hClipRgn */
+    0,                      /* hVisRgn */
+    0,                      /* hGCClipRgn */
+    STOCK_BLACK_PEN,        /* hPen */
+    STOCK_WHITE_BRUSH,      /* hBrush */
+    STOCK_SYSTEM_FONT,      /* hFont */
+    0,                      /* hBitmap */
+    0,                      /* hFirstBitmap */
+    0,                      /* hDevice */
+    STOCK_DEFAULT_PALETTE,  /* hPalette */
+    R2_COPYPEN,             /* ROPmode */
+    ALTERNATE,              /* polyFillMode */
+    BLACKONWHITE,           /* stretchBltMode */
+    ABSOLUTE,               /* relAbsMode */
+    OPAQUE,                 /* backgroundMode */
+    RGB( 255, 255, 255 ),   /* backgroundColor */
+    RGB( 0, 0, 0 ),         /* textColor */
+    0,                      /* backgroundPixel */
+    0,                      /* textPixel */
+    0,                      /* brushOrgX */
+    0,                      /* brushOrgY */
+    TA_LEFT | TA_TOP | TA_NOUPDATECP,  /* textAlign */
+    0,                      /* charExtra */
+    0,                      /* breakTotalExtra */
+    0,                      /* breakCount */
+    0,                      /* breakExtra */
+    0,                      /* breakRem */
+    1,                      /* bitsPerPixel */
+    MM_TEXT,                /* MapMode */
+    0,                      /* DCOrgX */
+    0,                      /* DCOrgY */
+    0,                      /* CursPosX */
+    0,                      /* CursPosY */
+    0,                      /* WndOrgX */
+    0,                      /* WndOrgY */
+    1,                      /* WndExtX */
+    1,                      /* WndExtY */
+    0,                      /* VportOrgX */
+    0,                      /* VportOrgY */
+    1,                      /* VportExtX */
+    1                       /* VportExtY */
+};
+
   /* ROP code to GC function conversion */
 const int DC_XROPfunction[16] =
 {
@@ -109,17 +157,19 @@
 
 
 /***********************************************************************
- *           DC_SetupDCForBrush
+ *           DC_SetupDCForPatBlt
  *
- * Setup dc->u.x.gc for drawing operations using current brush.
- * Return 0 if brush is BS_NULL, 1 otherwise.
+ * Setup the GC for a PatBlt operation using current brush.
+ * If fMapColors is TRUE, X pixels are mapped to Windows colors.
+ * Return FALSE if brush is BS_NULL, TRUE otherwise.
  */
-int DC_SetupGCForBrush( DC * dc )
+BOOL DC_SetupGCForPatBlt( DC * dc, GC gc, BOOL fMapColors )
 {
     XGCValues val;
-    unsigned long mask = 0;
+    unsigned long mask;
+    Pixmap pixmap = 0;
 
-    if (dc->u.x.brush.style == BS_NULL) return 0;
+    if (dc->u.x.brush.style == BS_NULL) return FALSE;
     if (dc->u.x.brush.pixel == -1)
     {
 	/* Special case used for monochrome pattern brushes.
@@ -134,27 +184,68 @@
 	val.foreground = dc->u.x.brush.pixel;
 	val.background = dc->w.backgroundPixel;
     }
+    if (fMapColors && COLOR_PixelToPalette)
+    {
+        val.foreground = COLOR_PixelToPalette[val.foreground];
+        val.background = COLOR_PixelToPalette[val.background];
+    }
+
     val.function = DC_XROPfunction[dc->w.ROPmode-1];
     val.fill_style = dc->u.x.brush.fillStyle;
-    if ((val.fill_style==FillStippled) || (val.fill_style==FillOpaqueStippled))
+    switch(val.fill_style)
     {
+    case FillStippled:
+    case FillOpaqueStippled:
 	if (dc->w.backgroundMode==OPAQUE) val.fill_style = FillOpaqueStippled;
 	val.stipple = dc->u.x.brush.pixmap;
 	mask = GCStipple;
-    }
-    else if (val.fill_style == FillTiled)
-    {
-	val.tile = dc->u.x.brush.pixmap;
+        break;
+
+    case FillTiled:
+        if (fMapColors && COLOR_PixelToPalette)
+        {
+            register int x, y;
+            XImage *image;
+            pixmap = XCreatePixmap( display, rootWindow, 8, 8, screenDepth );
+            image = XGetImage( display, dc->u.x.brush.pixmap, 0, 0, 8, 8,
+                               AllPlanes, ZPixmap );
+            for (y = 0; y < 8; y++)
+                for (x = 0; x < 8; x++)
+                    XPutPixel( image, x, y,
+                               COLOR_PixelToPalette[XGetPixel( image, x, y)] );
+            XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
+            XDestroyImage( image );
+            val.tile = pixmap;
+        }
+        else val.tile = dc->u.x.brush.pixmap;
 	mask = GCTile;
+        break;
+
+    default:
+        mask = 0;
+        break;
     }
     val.ts_x_origin = dc->w.DCOrgX + dc->w.brushOrgX;
     val.ts_y_origin = dc->w.DCOrgY + dc->w.brushOrgY;
     val.fill_rule = (dc->w.polyFillMode==WINDING) ? WindingRule : EvenOddRule;
-    XChangeGC( display, dc->u.x.gc, 
+    XChangeGC( display, gc, 
 	       GCFunction | GCForeground | GCBackground | GCFillStyle |
 	       GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
 	       &val );
-    return 1;
+    if (pixmap) XFreePixmap( display, pixmap );
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           DC_SetupDCForBrush
+ *
+ * Setup dc->u.x.gc for drawing operations using current brush.
+ * Return FALSE if brush is BS_NULL, TRUE otherwise.
+ */
+BOOL DC_SetupGCForBrush( DC * dc )
+{
+    return DC_SetupGCForPatBlt( dc, dc->u.x.gc, FALSE );
 }
 
 
@@ -162,13 +253,13 @@
  *           DC_SetupDCForPen
  *
  * Setup dc->u.x.gc for drawing operations using current pen.
- * Return 0 if pen is PS_NULL, 1 otherwise.
+ * Return FALSE if pen is PS_NULL, TRUE otherwise.
  */
-int DC_SetupGCForPen( DC * dc )
+BOOL DC_SetupGCForPen( DC * dc )
 {
     XGCValues val;
 
-    if (dc->u.x.pen.style == PS_NULL) return 0;
+    if (dc->u.x.pen.style == PS_NULL) return FALSE;
     val.function   = DC_XROPfunction[dc->w.ROPmode-1];
     val.foreground = dc->u.x.pen.pixel;
     val.background = dc->w.backgroundPixel;
@@ -187,7 +278,7 @@
     XChangeGC( display, dc->u.x.gc, 
 	       GCFunction | GCForeground | GCBackground | GCLineWidth |
 	       GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
-    return 1;    
+    return TRUE;
 }
 
 
@@ -195,15 +286,16 @@
  *           DC_SetupGCForText
  *
  * Setup dc->u.x.gc for text drawing operations.
- * Return 0 if the font is null, 1 otherwise.
+ * Return FALSE if the font is null, TRUE otherwise.
  */
-int DC_SetupGCForText( DC * dc )
+BOOL DC_SetupGCForText( DC * dc )
 {
     XGCValues val;
 
     if (!dc->u.x.font.fstruct)
     {
-	FONT_SelectObject(dc, STOCK_SYSTEM_FONT, NULL);
+        fprintf( stderr, "DC_SetupGCForText: fstruct is NULL. Please report this\n" );
+        return FALSE;
     }
     val.function   = GXcopy;  /* Text is always GXcopy */
     val.foreground = dc->w.textPixel;
@@ -213,7 +305,7 @@
     XChangeGC( display, dc->u.x.gc, 
 	       GCFunction | GCForeground | GCBackground | GCFillStyle |
 	       GCFont, &val );
-    return 1;
+    return TRUE;
 }
 
 
@@ -364,7 +456,7 @@
     }
 
     dc->saveLevel = 0;
-    memcpy( &dc->w, &DCVAL_defaultValues, sizeof(DCVAL_defaultValues) );
+    memcpy( &dc->w, &DC_defaultValues, sizeof(DC_defaultValues) );
     memset( &dc->u.x, 0, sizeof(dc->u.x) );
 
     dc->u.x.drawable   = rootWindow;
@@ -421,7 +513,7 @@
     bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
     
     dc->saveLevel = 0;
-    memcpy( &dc->w, &DCVAL_defaultValues, sizeof(DCVAL_defaultValues) );
+    memcpy( &dc->w, &DC_defaultValues, sizeof(DC_defaultValues) );
     memset( &dc->u.x, 0, sizeof(dc->u.x) );
 
     dc->u.x.drawable   = bmp->pixmap;
@@ -430,6 +522,7 @@
     dc->w.bitsPerPixel = 1;
     dc->w.devCaps      = displayDevCaps;
     dc->w.hBitmap      = hbitmap;
+    dc->w.hFirstBitmap = hbitmap;
     dc->w.hVisRgn      = CreateRectRgn( 0, 0, 1, 1 );
 
     if (!dc->w.hVisRgn)
@@ -473,8 +566,7 @@
 	XFreeGC( display, dc->u.x.gc );
     }
 
-    if (dc->w.flags & DC_MEMORY) DeleteObject( dc->w.hBitmap );
-
+    if (dc->w.flags & DC_MEMORY) DeleteObject( dc->w.hFirstBitmap );
     if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
     if (dc->w.hVisRgn) DeleteObject( dc->w.hVisRgn );
     if (dc->w.hGCClipRgn) DeleteObject( dc->w.hGCClipRgn );
diff --git a/objects/dcvalues.c b/objects/dcvalues.c
index 801b6df..8180c44 100644
--- a/objects/dcvalues.c
+++ b/objects/dcvalues.c
@@ -8,54 +8,6 @@
 #include "gdi.h"
 #include "metafile.h"
 
-  /* Default DC values */
-const WIN_DC_INFO DCVAL_defaultValues =
-{
-    0,                      /* flags */
-    NULL,                   /* devCaps */
-    0,                      /* hMetaFile */
-    0,                      /* hClipRgn */
-    0,                      /* hVisRgn */
-    0,                      /* hGCClipRgn */
-    STOCK_BLACK_PEN,        /* hPen */
-    STOCK_WHITE_BRUSH,      /* hBrush */
-    STOCK_SYSTEM_FONT,      /* hFont */
-    0,                      /* hBitmap */
-    0,                      /* hDevice */
-    STOCK_DEFAULT_PALETTE,  /* hPalette */
-    R2_COPYPEN,             /* ROPmode */
-    ALTERNATE,              /* polyFillMode */
-    BLACKONWHITE,           /* stretchBltMode */
-    ABSOLUTE,               /* relAbsMode */
-    OPAQUE,                 /* backgroundMode */
-    RGB( 255, 255, 255 ),   /* backgroundColor */
-    RGB( 0, 0, 0 ),         /* textColor */
-    0,                      /* backgroundPixel */
-    0,                      /* textPixel */
-    0,                      /* brushOrgX */
-    0,                      /* brushOrgY */
-    TA_LEFT | TA_TOP | TA_NOUPDATECP,  /* textAlign */
-    0,                      /* charExtra */
-    0,                      /* breakTotalExtra */
-    0,                      /* breakCount */
-    0,                      /* breakExtra */
-    0,                      /* breakRem */
-    1,                      /* bitsPerPixel */
-    MM_TEXT,                /* MapMode */
-    0,                      /* DCOrgX */
-    0,                      /* DCOrgY */
-    0,                      /* CursPosX */
-    0,                      /* CursPosY */
-    0,                      /* WndOrgX */
-    0,                      /* WndOrgY */
-    1,                      /* WndExtX */
-    1,                      /* WndExtY */
-    0,                      /* VportOrgX */
-    0,                      /* VportOrgY */
-    1,                      /* VportExtX */
-    1                       /* VportExtY */
-};
-
 
 #define DC_GET_VAL( func_type, func_name, dc_field ) \
 func_type func_name( HDC hdc ) \
diff --git a/objects/dib.c b/objects/dib.c
index fe2ae9d..40039af 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -9,8 +9,8 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include "dc.h"
-#include "gdi.h"
 #include "bitmap.h"
+#include "palette.h"
 #include "icon.h"
 #include "stddebug.h"
 #include "color.h"
@@ -395,7 +395,7 @@
 			   * bytes are always read in pairs.  [JAY]
 			   */
 			  if (escape_code & 1) 
-			    (*pIn++); /* Get and throw away the pad byte. */
+			    pIn++; /* Throw away the pad byte. */
 			  break;
 		      }
 		  } /* switch (escape_code) : Escape sequence */
diff --git a/objects/dither.c b/objects/dither.c
deleted file mode 100644
index 79a1dcd..0000000
--- a/objects/dither.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Dithering functions
- *
- * Copyright 1994 Alexandre Julliard
- *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1994";
-*/
-
-#include <stdlib.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include "color.h"
-#include "gdi.h"
-#include "bitmap.h"
-
-
-  /* Levels of each primary */
-#define PRIMARY_LEVELS  3  
-#define TOTAL_LEVELS    (PRIMARY_LEVELS*PRIMARY_LEVELS*PRIMARY_LEVELS)
-
- /* Dithering matrix size  */
-#define MATRIX_SIZE     8
-#define MATRIX_SIZE_2   (MATRIX_SIZE*MATRIX_SIZE)
-
-  /* Total number of possible levels for a dithered primary color */
-#define DITHER_LEVELS   (MATRIX_SIZE_2 * (PRIMARY_LEVELS-1) + 1)
-
-  /* Dithering matrix */
-static const int dither_matrix[MATRIX_SIZE_2] =
-{
-     0, 32,  8, 40,  2, 34, 10, 42,
-    48, 16, 56, 24, 50, 18, 58, 26,
-    12, 44,  4, 36, 14, 46,  6, 38,
-    60, 28, 52, 20, 62, 30, 54, 22,
-     3, 35, 11, 43,  1, 33,  9, 41,
-    51, 19, 59, 27, 49, 17, 57, 25,
-    15, 47,  7, 39, 13, 45,  5, 37,
-    63, 31, 55, 23, 61, 29, 53, 21
-};
-
-  /* Mapping between (R,G,B) triples and EGA colors */
-static const int EGAmapping[TOTAL_LEVELS] =
-{
-    0,  /* 000000 -> 000000 */
-    4,  /* 00007f -> 000080 */
-    12, /* 0000ff -> 0000ff */
-    2,  /* 007f00 -> 008000 */
-    6,  /* 007f7f -> 008080 */
-    6,  /* 007fff -> 008080 */
-    10, /* 00ff00 -> 00ff00 */
-    6,  /* 00ff7f -> 008080 */
-    14, /* 00ffff -> 00ffff */
-    1,  /* 7f0000 -> 800000 */
-    5,  /* 7f007f -> 800080 */
-    5,  /* 7f00ff -> 800080 */
-    3,  /* 7f7f00 -> 808000 */
-    8,  /* 7f7f7f -> 808080 */
-    7,  /* 7f7fff -> c0c0c0 */
-    3,  /* 7fff00 -> 808000 */
-    7,  /* 7fff7f -> c0c0c0 */
-    7,  /* 7fffff -> c0c0c0 */
-    9,  /* ff0000 -> ff0000 */
-    5,  /* ff007f -> 800080 */
-    13, /* ff00ff -> ff00ff */
-    3,  /* ff7f00 -> 808000 */
-    7,  /* ff7f7f -> c0c0c0 */
-    7,  /* ff7fff -> c0c0c0 */
-    11, /* ffff00 -> ffff00 */
-    7,  /* ffff7f -> c0c0c0 */
-    15  /* ffffff -> ffffff */
-};
-
-#define PIXEL_VALUE(r,g,b) \
-    COLOR_mapEGAPixel[EGAmapping[((r)*PRIMARY_LEVELS+(g))*PRIMARY_LEVELS+(b)]]
-
-  /* X image for building dithered pixmap */
-static XImage *ditherImage = NULL;
-static char *imageData = NULL;
-
-
-/***********************************************************************
- *           DITHER_Init
- *
- * Create the X image used for dithering.
- */
-BOOL DITHER_Init(void)
-{
-    XCREATEIMAGE( ditherImage, MATRIX_SIZE, MATRIX_SIZE, screenDepth );
-    return (ditherImage != NULL);
-}
-
-
-/***********************************************************************
- *           DITHER_DitherColor
- */
-Pixmap DITHER_DitherColor( DC *dc, COLORREF color )
-{
-    static COLORREF prevColor = 0xffffffff;
-    unsigned int x, y;
-    Pixmap pixmap;
-
-    if (color != prevColor)
-    {
-	int r = GetRValue( color ) * DITHER_LEVELS;
-	int g = GetGValue( color ) * DITHER_LEVELS;
-	int b = GetBValue( color ) * DITHER_LEVELS;
-	const int *pmatrix = dither_matrix;
-
-	for (y = 0; y < MATRIX_SIZE; y++)
-	{
-	    for (x = 0; x < MATRIX_SIZE; x++)
-	    {
-		int d  = *pmatrix++ * 256;
-		int dr = ((r + d) / MATRIX_SIZE_2) / 256;
-		int dg = ((g + d) / MATRIX_SIZE_2) / 256;
-		int db = ((b + d) / MATRIX_SIZE_2) / 256;
-		XPutPixel( ditherImage, x, y, PIXEL_VALUE(dr,dg,db) );
-	    }
-	}
-	prevColor = color;
-    }
-    
-    pixmap = XCreatePixmap( display, rootWindow,
-			    MATRIX_SIZE, MATRIX_SIZE, screenDepth );
-    XPutImage( display, pixmap, BITMAP_colorGC, ditherImage, 0, 0,
-	       0, 0, MATRIX_SIZE, MATRIX_SIZE );
-    return pixmap;
-}
diff --git a/objects/font.c b/objects/font.c
index f03962f..36d0ce4 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -10,8 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <X11/Xatom.h>
-#include "user.h"
-#include "gdi.h"
+#include "font.h"
 #include "metafile.h"
 #include "callback.h"
 #include "stddebug.h"
@@ -55,11 +54,11 @@
 } FontNames[32];
 int FontSize;
 
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
- *           Font_Init
- */
 
-void Font_Init( void )
+/***********************************************************************
+ *           FONT_Init
+ */
+BOOL FONT_Init( void )
 {
   char  temp[1024];
   LPSTR ptr;
@@ -88,8 +87,10 @@
     FontNames[6].window = "roman"; FontNames[6].x11 = "*-times";
     FontSize = 7;
   }
+  return TRUE;
 }
 
+
 /***********************************************************************
  *           FONT_TranslateName
  *
@@ -212,11 +213,13 @@
     metrics->tmLastChar         = xfont->max_char_or_byte2;
     metrics->tmDefaultChar      = xfont->default_char;
     metrics->tmBreakChar        = ' ';
-    metrics->tmPitchAndFamily   = logfont->lfPitchAndFamily;
     metrics->tmCharSet          = logfont->lfCharSet;
     metrics->tmOverhang         = 0;
     metrics->tmDigitizedAspectX = 1;
     metrics->tmDigitizedAspectY = 1;
+    metrics->tmPitchAndFamily   = (logfont->lfPitchAndFamily&0xf0)|TMPF_DEVICE;
+    if (logfont->lfPitchAndFamily & FIXED_PITCH) 
+        metrics->tmPitchAndFamily |= TMPF_FIXED_PITCH;
 
     if (!xfont->per_char) average = metrics->tmMaxCharWidth;
     else
@@ -313,16 +316,29 @@
     
     if (!stockPtr || !stockPtr->fstruct)
     {
-	fontStruct = FONT_MatchFont( &font->logfont, dc );
+	if (!(fontStruct = FONT_MatchFont( &font->logfont, dc )))
+        {
+              /* If it is not a stock font, we can simply return 0 */
+            if (!stockPtr) return 0;
+              /* Otherwise we must try to find a substitute */
+            dprintf_font(stddeb,"Loading font 'fixed' for %x\n", hfont );
+            font->logfont.lfPitchAndFamily &= ~VARIABLE_PITCH;
+            font->logfont.lfPitchAndFamily |= FIXED_PITCH;
+            fontStruct = XLoadQueryFont( display, "fixed" );
+            if (!fontStruct)
+            {
+                fprintf( stderr, "No system font could be found. Please check your font path.\n" );
+                exit( 1 );
+            }
+        }
     }
     else
     {
 	fontStruct = stockPtr->fstruct;
-	dprintf_font(stddeb, 
-		     "FONT_SelectObject: Loaded font from cache %x %p\n",
+	dprintf_font(stddeb,
+                     "FONT_SelectObject: Loaded font from cache %x %p\n",
 		     hfont, fontStruct );
     }	
-    if (!fontStruct) return 0;
 
       /* Free previous font */
 
@@ -451,8 +467,8 @@
     size->cy = abs((dc->u.x.font.fstruct->ascent+dc->u.x.font.fstruct->descent)
 		    * dc->w.WndExtY / dc->w.VportExtY);
 
-    dprintf_font(stddeb,"GetTextExtentPoint(%d '%s' %d %p): returning %d,%d\n",
-	    hdc, str, count, size, size->cx, size->cy );
+    dprintf_font(stddeb,"GetTextExtentPoint(%d '%*.*s' %d %p): returning %d,%d\n",
+	    hdc, count, count, str, count, size, size->cx, size->cy );
     return TRUE;
 }
 
@@ -669,19 +685,19 @@
 	int				nRet;
 	int				j, i = 0;
 
-	dprintf_font(stddeb,"EnumFonts(%04X, %08X='%s', %08X, %08X)\n", 
+	dprintf_font(stddeb,"EnumFonts(%04X, %p='%s', %p, %p)\n", 
 		hDC, lpFaceName, lpFaceName, lpEnumFunc, lpData);
 	if (lpEnumFunc == NULL) return 0;
-	hLog = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGFONT) + LF_FACESIZE);
-	lpLogFont = (LPLOGFONT) USER_HEAP_ADDR(hLog);
+	hLog = GDI_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGFONT) + LF_FACESIZE);
+	lpLogFont = (LPLOGFONT) GDI_HEAP_ADDR(hLog);
 	if (lpLogFont == NULL) {
 		dprintf_font(stddeb,"EnumFonts // can't alloc LOGFONT struct !\n");
 		return 0;
 		}
-	hMet = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(TEXTMETRIC));
-	lptm = (LPTEXTMETRIC) USER_HEAP_ADDR(hMet);
+	hMet = GDI_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(TEXTMETRIC));
+	lptm = (LPTEXTMETRIC) GDI_HEAP_ADDR(hMet);
 	if (lptm == NULL) {
-		USER_HEAP_FREE(hLog);
+		GDI_HEAP_FREE(hLog);
 		dprintf_font(stddeb, "EnumFonts // can't alloc TEXTMETRIC struct !\n");
 		return 0;
 		}
@@ -718,7 +734,7 @@
 		GetTextMetrics(hDC, lptm);
 		SelectObject(hDC, hOldFont);
 		DeleteObject(hFont);
-		dprintf_font(stddeb,"EnumFonts // i=%d lpLogFont=%08X lptm=%08X\n", i, lpLogFont, lptm);
+		dprintf_font(stddeb,"EnumFonts // i=%d lpLogFont=%p lptm=%p\n", i, lpLogFont, lptm);
 
 #ifdef WINELIB
 		nRet = (*lpEnumFunc)(lpLogFont, lptm, 0, lpData);
@@ -731,8 +747,8 @@
 			break;
 			}
 		}
-	USER_HEAP_FREE(hMet);
-	USER_HEAP_FREE(hLog);
+	GDI_HEAP_FREE(hMet);
+	GDI_HEAP_FREE(hLog);
 	return 0;
 }
 
@@ -753,19 +769,19 @@
 	int				nRet;
 	int				j, i = 0;
 
-	dprintf_font(stddeb,"EnumFontFamilies(%04X, %08X, %08X, %08X)\n", 
+	dprintf_font(stddeb,"EnumFontFamilies(%04X, %p, %p, %p)\n", 
 					hDC, lpszFamily, lpEnumFunc, lpData);
 	if (lpEnumFunc == NULL) return 0;
-	hLog = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGFONT) + LF_FACESIZE);
-	lpLogFont = (LPLOGFONT) USER_HEAP_ADDR(hLog);
+	hLog = GDI_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGFONT) + LF_FACESIZE);
+	lpLogFont = (LPLOGFONT) GDI_HEAP_ADDR(hLog);
 	if (lpLogFont == NULL) {
 		dprintf_font(stddeb,"EnumFontFamilies // can't alloc LOGFONT struct !\n");
 		return 0;
 		}
-	hMet = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(TEXTMETRIC));
-	lptm = (LPTEXTMETRIC) USER_HEAP_ADDR(hMet);
+	hMet = GDI_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(TEXTMETRIC));
+	lptm = (LPTEXTMETRIC) GDI_HEAP_ADDR(hMet);
 	if (lptm == NULL) {
-		USER_HEAP_FREE(hLog);
+		GDI_HEAP_FREE(hLog);
 		dprintf_font(stddeb,"EnumFontFamilies // can't alloc TEXTMETRIC struct !\n");
 		return 0;
 		}
@@ -803,7 +819,7 @@
 		GetTextMetrics(hDC, lptm);
 		SelectObject(hDC, hOldFont);
 		DeleteObject(hFont);
-		dprintf_font(stddeb, "EnumFontFamilies // i=%d lpLogFont=%08X lptm=%08X\n", i, lpLogFont, lptm);
+		dprintf_font(stddeb, "EnumFontFamilies // i=%d lpLogFont=%p lptm=%p\n", i, lpLogFont, lptm);
 
 #ifdef WINELIB
 		nRet = (*lpEnumFunc)(lpLogFont, lptm, 0, lpData);
@@ -816,8 +832,8 @@
 			break;
 			}
 		}
-	USER_HEAP_FREE(hMet);
-	USER_HEAP_FREE(hLog);
+	GDI_HEAP_FREE(hMet);
+	GDI_HEAP_FREE(hLog);
 	return 0;
 }
 
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index c418ec1..3d591d6 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -8,13 +8,16 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include "user.h"
+#include "selectors.h"
 #include "gdi.h"
 #include "color.h"
-#include "prototypes.h"
-#include "stddebug.h"
 #include "bitmap.h"
+#include "brush.h"
 #include "font.h"
+#include "palette.h"
+#include "pen.h"
+#include "region.h"
+#include "stddebug.h"
 /* #define DEBUG_GDI */
 #include "debug.h"
 
@@ -27,6 +30,7 @@
 #define MAX_OBJ 			1024
 HANDLE *lpPenBrushList = NULL;
 
+
 /***********************************************************************
  *          GDI stock objects 
  */
@@ -181,9 +185,13 @@
 
     if (!REGION_Init()) return FALSE;
     
-      /* Initialise dithering */
+      /* Initialise brush dithering */
 
-    if (!DITHER_Init()) return FALSE;
+    if (!BRUSH_Init()) return FALSE;
+
+      /* Initialise fonts */
+
+    if (!FONT_Init()) return FALSE;
 
     return TRUE;
 }
@@ -312,11 +320,11 @@
     switch(header->wMagic)
     {
       case PEN_MAGIC:     return GDI_FreeObject( obj );
-      case BRUSH_MAGIC:   return BRUSH_DeleteObject( obj, header );
+      case BRUSH_MAGIC:   return BRUSH_DeleteObject( obj, (BRUSHOBJ*)header );
       case FONT_MAGIC:    return GDI_FreeObject( obj );
       case PALETTE_MAGIC: return GDI_FreeObject( obj );
-      case BITMAP_MAGIC:  return BMP_DeleteObject( obj, header );
-      case REGION_MAGIC:  return REGION_DeleteObject( obj, header );
+      case BITMAP_MAGIC:  return BITMAP_DeleteObject( obj, (BITMAPOBJ*)header);
+      case REGION_MAGIC:  return REGION_DeleteObject( obj, (RGNOBJ*)header );
     }
     return FALSE;
 }
@@ -359,7 +367,7 @@
       case BRUSH_MAGIC: 
 	  return BRUSH_GetObject( (BRUSHOBJ *)ptr, count, buffer );
       case BITMAP_MAGIC: 
-	  return BMP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
+	  return BITMAP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
       case FONT_MAGIC:
 	  return FONT_GetObject( (FONTOBJ *)ptr, count, buffer );
       case PALETTE_MAGIC:
@@ -440,10 +448,10 @@
 	switch (nObjType) {
 		case OBJ_PEN:
 			wMagic = PEN_MAGIC;
-			dprintf_gdi(stddeb,"EnumObjects(%04X, OBJ_PEN, %08X, %08X);\n", 
+			dprintf_gdi(stddeb,"EnumObjects(%04X, OBJ_PEN, %p, %p);\n", 
 									hDC, lpEnumFunc, lpData);
-			hLog = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGPEN));
-			lpLog = (LPSTR) USER_HEAP_ADDR(hLog);
+			hLog = GDI_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGPEN));
+			lpLog = (LPSTR) GDI_HEAP_ADDR(hLog);
 			if (lpLog == NULL) {
 				fprintf(stderr,"EnumObjects // Unable to alloc LOGPEN struct !\n");
 				return 0;
@@ -451,17 +459,17 @@
 			break;
 		case OBJ_BRUSH:
 			wMagic = BRUSH_MAGIC;
-			dprintf_gdi(stddeb,"EnumObjects(%04X, OBJ_BRUSH, %08X, %08X);\n", 
+			dprintf_gdi(stddeb,"EnumObjects(%04X, OBJ_BRUSH, %p, %p);\n", 
 									hDC, lpEnumFunc, lpData);
-			hLog = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGBRUSH));
-			lpLog = (LPSTR) USER_HEAP_ADDR(hLog);
+			hLog = GDI_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LOGBRUSH));
+			lpLog = (LPSTR) GDI_HEAP_ADDR(hLog);
 			if (lpLog == NULL) {
 				fprintf(stderr,"EnumObjects // Unable to alloc LOGBRUSH struct !\n");
 				return 0;
 				}
 			break;
 		default:
-			fprintf(stderr,"EnumObjects(%04X, %04X, %08X, %08X); // Unknown OBJ type !\n", 
+			fprintf(stderr,"EnumObjects(%04X, %04X, %p, %p); // Unknown OBJ type !\n", 
 						hDC, nObjType, lpEnumFunc, lpData);
 			return 0;
 		}
@@ -469,18 +477,18 @@
 	for (i = 0; i < NB_STOCK_OBJECTS; i++) {
 		header = StockObjects[i];
 		if (header->wMagic == wMagic) {
-			PEN_GetObject( (PENOBJ *)header, sizeof(LOGPEN), (LPLOGPEN)lpLog);
-			BRUSH_GetObject( (BRUSHOBJ *)header, sizeof(LOGBRUSH), (LPLOGBRUSH)lpLog);
-			dprintf_gdi(stddeb,"EnumObjects // StockObj lpLog=%08X lpData=%08X\n", lpLog, lpData);
+			PEN_GetObject( (PENOBJ *)header, sizeof(LOGPEN), lpLog);
+			BRUSH_GetObject( (BRUSHOBJ *)header, sizeof(LOGBRUSH),lpLog);
+			dprintf_gdi(stddeb,"EnumObjects // StockObj lpLog=%p lpData=%p\n", lpLog, lpData);
 			if (header->wMagic == BRUSH_MAGIC) {
 				dprintf_gdi(stddeb,"EnumObjects // StockBrush lbStyle=%04X\n", ((LPLOGBRUSH)lpLog)->lbStyle);
-				dprintf_gdi(stddeb,"EnumObjects // StockBrush lbColor=%08X\n", ((LPLOGBRUSH)lpLog)->lbColor);
+				dprintf_gdi(stddeb,"EnumObjects // StockBrush lbColor=%08lX\n", ((LPLOGBRUSH)lpLog)->lbColor);
 				dprintf_gdi(stddeb,"EnumObjects // StockBrush lbHatch=%04X\n", ((LPLOGBRUSH)lpLog)->lbHatch);
 				}
 			if (header->wMagic == PEN_MAGIC) {
 				dprintf_gdi(stddeb,"EnumObjects // StockPen lopnStyle=%04X\n", ((LPLOGPEN)lpLog)->lopnStyle);
-				dprintf_gdi(stddeb,"EnumObjects // StockPen lopnWidth=%08X\n", ((LPLOGPEN)lpLog)->lopnWidth);
-				dprintf_gdi(stddeb,"EnumObjects // StockPen lopnColor=%08X\n", ((LPLOGPEN)lpLog)->lopnColor);
+				dprintf_gdi(stddeb,"EnumObjects // StockPen lopnWidth=%d\n", ((LPLOGPEN)lpLog)->lopnWidth.x);
+				dprintf_gdi(stddeb,"EnumObjects // StockPen lopnColor=%08lX\n", ((LPLOGPEN)lpLog)->lopnColor);
 				}
 			nRet = 1;
 /*
@@ -492,30 +500,30 @@
 */
 			dprintf_gdi(stddeb,"EnumObjects // after CallBack16 !\n");
 			if (nRet == 0) {
-				USER_HEAP_FREE(hLog);
+				GDI_HEAP_FREE(hLog);
 				dprintf_gdi(stddeb,"EnumObjects // EnumEnd requested by application !\n");
 				return 0;
 				}
 			}
 		}
 	if (lpPenBrushList == NULL) return 0;
-	dprintf_gdi(stddeb,"EnumObjects // Now DC owned objects %08X !\n", header);
+	dprintf_gdi(stddeb,"EnumObjects // Now DC owned objects %p !\n", header);
 	for (lphObj = lpPenBrushList; *lphObj != 0; ) {
 		dprintf_gdi(stddeb,"EnumObjects // *lphObj=%04X\n", *lphObj);
 		header = (GDIOBJHDR *) GDI_HEAP_ADDR(*lphObj++);
 		if (header->wMagic == wMagic) {
-			dprintf_gdi(stddeb,"EnumObjects // DC_Obj lpLog=%08X lpData=%08X\n", lpLog, lpData);
+			dprintf_gdi(stddeb,"EnumObjects // DC_Obj lpLog=%p lpData=%p\n", lpLog, lpData);
 			if (header->wMagic == BRUSH_MAGIC) {
-				BRUSH_GetObject( (BRUSHOBJ *)header, sizeof(LOGBRUSH), (LPLOGBRUSH)lpLog);
+				BRUSH_GetObject( (BRUSHOBJ *)header, sizeof(LOGBRUSH), lpLog);
 				dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbStyle=%04X\n", ((LPLOGBRUSH)lpLog)->lbStyle);
-				dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbColor=%08X\n", ((LPLOGBRUSH)lpLog)->lbColor);
+				dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbColor=%08lX\n", ((LPLOGBRUSH)lpLog)->lbColor);
 				dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbHatch=%04X\n", ((LPLOGBRUSH)lpLog)->lbHatch);
 				}
 			if (header->wMagic == PEN_MAGIC) {
-				PEN_GetObject( (PENOBJ *)header, sizeof(LOGPEN), (LPLOGPEN)lpLog);
+				PEN_GetObject( (PENOBJ *)header, sizeof(LOGPEN), lpLog);
 				dprintf_gdi(stddeb,"EnumObjects // DC_Pen lopnStyle=%04X\n", ((LPLOGPEN)lpLog)->lopnStyle);
-				dprintf_gdi(stddeb,"EnumObjects // DC_Pen lopnWidth=%08X\n", ((LPLOGPEN)lpLog)->lopnWidth);
-				dprintf_gdi(stddeb,"EnumObjects // DC_Pen lopnColor=%08X\n", ((LPLOGPEN)lpLog)->lopnColor);
+				dprintf_gdi(stddeb,"EnumObjects // DC_Pen lopnWidth=%d\n", ((LPLOGPEN)lpLog)->lopnWidth.x);
+				dprintf_gdi(stddeb,"EnumObjects // DC_Pen lopnColor=%08lX\n", ((LPLOGPEN)lpLog)->lopnColor);
 				}
 /*
 #ifdef WINELIB
@@ -527,13 +535,13 @@
 			nRet = 1;
 			dprintf_gdi(stddeb,"EnumObjects // after CallBack16 !\n");
 			if (nRet == 0) {
-				USER_HEAP_FREE(hLog);
+				GDI_HEAP_FREE(hLog);
 				dprintf_gdi(stddeb,"EnumObjects // EnumEnd requested by application !\n");
 				return 0;
 				}
 			}
 		}
-	USER_HEAP_FREE(hLog);
+	GDI_HEAP_FREE(hLog);
 	dprintf_gdi(stddeb,"EnumObjects // End of enumeration !\n");
 	return 0;
 }
diff --git a/objects/metafile.c b/objects/metafile.c
index debdf23..1ad135e 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -7,10 +7,9 @@
 */
 
 #include <string.h>
-#include "windows.h"
 #include "gdi.h"
+#include "bitmap.h"
 #include "metafile.h"
-#include "prototypes.h"
 #include "stddebug.h"
 /* #define DEBUG_METAFILE */
 #include "debug.h"
@@ -25,8 +24,6 @@
  */
 HMETAFILE GetMetaFile(LPSTR lpFilename)
 {
-
-  DC *dc;
   HMETAFILE hmf;
   METAFILE *mf;
   METAHEADER *mh;
@@ -143,7 +140,6 @@
     METAFILE *mf;
     METAHEADER *mh;
     HMETAFILE hmf;
-    char buffer[15];
 /*    METARECORD *mr = (METARECORD *)&buffer;*/
 
     dprintf_metafile(stddeb,"CloseMetaFile\n");
@@ -804,6 +800,8 @@
 	*(mr->rdParam + 1) = LOWORD(logbrush->lbColor);
 	memcpy(mr->rdParam + 2, info, biSize + bmSize);
 	break;
+    default:
+        return FALSE;
     }
     if (!MF_WriteRecord(dc->w.hMetaFile, mr, len))
     {
@@ -961,6 +959,7 @@
 	       short height, HDC hdcSrc, short xSrc, short ySrc, DWORD rop)
 {
     fprintf(stdnimp,"MF_BitBlt: not implemented yet\n");
+    return FALSE;
 }
 
 
@@ -972,4 +971,5 @@
 		   short widthSrc, short heightSrc, DWORD rop)
 {
     fprintf(stdnimp,"MF_StretchBlt: not implemented yet\n");
+    return FALSE;
 }
diff --git a/objects/oembitmap.c b/objects/oembitmap.c
index 883d092..9598653 100644
--- a/objects/oembitmap.c
+++ b/objects/oembitmap.c
@@ -246,7 +246,7 @@
         {
             fprintf( stderr, "Error %d creating pixmap %d\n",
                      err, OBM_FIRST+id );
-            pixmap = 0;
+            pixmap = width = height = 0;
         }
         else
         {
diff --git a/objects/palette.c b/objects/palette.c
index 5ae0188..050f7a2 100644
--- a/objects/palette.c
+++ b/objects/palette.c
@@ -15,8 +15,8 @@
 #endif
 
 #include <X11/Xlib.h>
-#include "gdi.h"
 #include "color.h"
+#include "palette.h"
 #include "stddebug.h"
 /* #define DEBUG_PALETTE */
 #include "debug.h"
diff --git a/objects/pen.c b/objects/pen.c
index 2293182..0896fda 100644
--- a/objects/pen.c
+++ b/objects/pen.c
@@ -2,10 +2,9 @@
  * GDI pen objects
  *
  * Copyright 1993 Alexandre Julliard
- *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
-#include "gdi.h"
+ */
+
+#include "pen.h"
 #include "metafile.h"
 #include "stddebug.h"
 #include "color.h"
diff --git a/objects/region.c b/objects/region.c
index f22183c..c83a2c1 100644
--- a/objects/region.c
+++ b/objects/region.c
@@ -8,7 +8,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "gdi.h"
+#include "region.h"
 #include "stddebug.h"
 /* #define DEBUG_REGION */
 #include "debug.h"
@@ -341,6 +341,7 @@
     }
     rgnObj = (RGNOBJ *) GDI_HEAP_ADDR( hrgn );
     rgnObj->region.type   = SIMPLEREGION;
+    rgnObj->region.xrgn   = 0;
     rgnObj->region.pixmap = 0;
 
       /* Create X region */
@@ -354,7 +355,13 @@
 	}
 	xrgn = XPolygonRegion( xpoints, *count,
 			       (mode == WINDING) ? WindingRule : EvenOddRule );
-	if (!xrgn) break;
+	if (!xrgn)
+        {
+            if (rgnObj->region.xrgn) XDestroyRegion( rgnObj->region.xrgn );
+            free( xpoints );
+            GDI_FreeObject( hrgn );
+            return 0;
+        }
 	if (i > 0)
 	{
 	    Region tmprgn = XCreateRegion();
@@ -367,11 +374,6 @@
     }
 
     free( xpoints );
-    if (!xrgn)
-    {
-	GDI_FreeObject( hrgn );
-	return 0;
-    }
     XClipBox( rgnObj->region.xrgn, &rect );
     SetRect( &rgnObj->region.box, rect.x, rect.y,
 	     rect.x + rect.width, rect.y + rect.height);
diff --git a/objects/text.c b/objects/text.c
index c28f3b0..186b729 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -52,7 +52,7 @@
     int numspaces;
     SIZE size;
     int lasttab = 0;
-    int wb_i = 0, wb_j = 0, wb_count;
+    int wb_i = 0, wb_j = 0, wb_count = 0;
 
     while (*count)
     {
@@ -301,8 +301,8 @@
     if (!DC_SetupGCForText( dc )) return TRUE;
     font = dc->u.x.font.fstruct;
 
-    dprintf_text(stddeb,"ExtTextOut: %d,%d '%s', %d  flags=%d rect=%d,%d,%d,%d\n",
-            x, y, str, count, flags,
+    dprintf_text(stddeb,"ExtTextOut: %d,%d '%*.*s', %d  flags=%d rect=%d,%d,%d,%d\n",
+            x, y, count, count, str, count, flags,
             lprect->left, lprect->top, lprect->right, lprect->bottom );
 
       /* Setup coordinates */
@@ -424,7 +424,7 @@
                 continue;  /* First iteration -> no delta */
             }
             pitem->delta = dc->w.charExtra;
-            if (str[i] == dc->u.x.font.metrics.tmBreakChar)
+            if (str[i] == (char)dc->u.x.font.metrics.tmBreakChar)
                 pitem->delta += dc->w.breakExtra;
             if (lpDx)
             {
@@ -565,8 +565,8 @@
 LONG TabbedTextOut( HDC hdc, short x, short y, LPSTR lpstr, short count, 
                     short cTabStops, LPINT lpTabPos, short nTabOrg )
 {
-    dprintf_text( stddeb, "TabbedTextOut: %x %d,%d '%s' %d\n",
-                  hdc, x, y, lpstr, count );
+    dprintf_text( stddeb, "TabbedTextOut: %x %d,%d '%*.*s' %d\n",
+                  hdc, x, y, count, count, lpstr, count );
     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
                                lpTabPos, nTabOrg, TRUE );
 }
@@ -578,8 +578,8 @@
 DWORD GetTabbedTextExtent( HDC hdc, LPSTR lpstr, int count, 
                           int cTabStops, LPINT lpTabPos )
 {
-    dprintf_text( stddeb, "GetTabbedTextExtent: %x '%s' %d\n",
-                  hdc, lpstr, count );
+    dprintf_text( stddeb, "GetTabbedTextExtent: %x '%*.*s' %d\n",
+                  hdc, count, count, lpstr, count );
     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
                                lpTabPos, 0, FALSE );
 }
diff --git a/rc/sysres.h b/rc/sysres.h
deleted file mode 100644
index 72c0af8..0000000
--- a/rc/sysres.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*		sysres.h
- * This File is automatically generated. Do not edit
- */
-#include "resource.h"
-extern unsigned char sysres_MENU_SYSMENU[];
-extern unsigned char sysres_DIALOG_2[];
-extern unsigned char sysres_DIALOG_STOP_MSGBOX[];
-extern unsigned char sysres_DIALOG_QUESTION_MSGBOX[];
-extern unsigned char sysres_DIALOG_EXCLAMATION_MSGBOX[];
-extern unsigned char sysres_DIALOG_SHELL_ABOUT_MSGBOX[];
-extern unsigned char sysres_DIALOG_3[];
-extern unsigned char sysres_DIALOG_4[];
-extern unsigned char sysres_DIALOG_11[];
-extern unsigned char sysres_DIALOG_12[];
-extern unsigned char sysres_DIALOG_5[];
-extern unsigned char sysres_DIALOG_6[];
-extern unsigned char sysres_DIALOG_7[];
-extern unsigned char sysres_DIALOG_8[];
-extern unsigned char sysres_DIALOG_9[];
-extern unsigned char sysres_DIALOG_10[];
-extern struct ResourceTable sysresTable[];
diff --git a/rc/sysresbm.h b/rc/sysresbm.h
deleted file mode 100644
index 98dc1e2..0000000
--- a/rc/sysresbm.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*		sysresbm.h
- * This File is automatically generated. Do not edit
- */
-#include "resource.h"
-extern unsigned char sysresbm_CURSOR_32514[];
-extern unsigned char sysresbm_CURSOR_32648[];
-extern unsigned char sysresbm_ICON_32516[];
-extern unsigned char sysresbm_ICON_32515[];
-extern unsigned char sysresbm_ICON_32513[];
-extern unsigned char sysresbm_ICON_32514[];
-extern unsigned char sysresbm_ICON_SYSIDI_STOPICON[];
-extern unsigned char sysresbm_ICON_32512[];
-extern unsigned char sysresbm_ICON_SYSIDI_HANDHAND[];
-extern unsigned char sysresbm_ICON_WINEICON[];
-extern unsigned char sysresbm_ICON_PORTRAIT[];
-extern unsigned char sysresbm_ICON_LANDSCAP[];
-extern unsigned char sysresbm_BITMAP_32754[];
-extern unsigned char sysresbm_BITMAP_32753[];
-extern unsigned char sysresbm_BITMAP_32752[];
-extern unsigned char sysresbm_BITMAP_32751[];
-extern unsigned char sysresbm_BITMAP_32750[];
-extern unsigned char sysresbm_BITMAP_32749[];
-extern unsigned char sysresbm_BITMAP_32748[];
-extern unsigned char sysresbm_BITMAP_32747[];
-extern unsigned char sysresbm_BITMAP_32746[];
-extern unsigned char sysresbm_BITMAP_32745[];
-extern unsigned char sysresbm_BITMAP_32744[];
-extern unsigned char sysresbm_BITMAP_32743[];
-extern unsigned char sysresbm_BITMAP_32742[];
-extern unsigned char sysresbm_BITMAP_32741[];
-extern unsigned char sysresbm_BITMAP_32740[];
-extern unsigned char sysresbm_BITMAP_32739[];
-extern unsigned char sysresbm_BITMAP_32738[];
-extern unsigned char sysresbm_BITMAP_32737[];
-extern unsigned char sysresbm_BITMAP_32736[];
-extern unsigned char sysresbm_BITMAP_32735[];
-extern unsigned char sysresbm_BITMAP_32734[];
-extern unsigned char sysresbm_BITMAP_32767[];
-extern unsigned char sysresbm_BITMAP_32766[];
-extern unsigned char sysresbm_BITMAP_32765[];
-extern unsigned char sysresbm_BITMAP_32764[];
-extern unsigned char sysresbm_BITMAP_32763[];
-extern unsigned char sysresbm_BITMAP_32762[];
-extern unsigned char sysresbm_BITMAP_32761[];
-extern unsigned char sysresbm_BITMAP_32760[];
-extern unsigned char sysresbm_BITMAP_32759[];
-extern unsigned char sysresbm_BITMAP_32758[];
-extern unsigned char sysresbm_BITMAP_32757[];
-extern unsigned char sysresbm_BITMAP_32756[];
-extern unsigned char sysresbm_BITMAP_32755[];
-extern unsigned char sysresbm_BITMAP_32520[];
-extern unsigned char sysresbm_BITMAP_32521[];
-extern unsigned char sysresbm_BITMAP_32522[];
-extern unsigned char sysresbm_BITMAP_32523[];
-extern unsigned char sysresbm_BITMAP_32524[];
-extern unsigned char sysresbm_BITMAP_SMILE[];
-extern unsigned char sysresbm_BITMAP_WINELOGO[];
-extern unsigned char sysresbm_BITMAP_OBMCLOSE[];
-extern struct ResourceTable sysresbmTable[];
diff --git a/tools/build.c b/tools/build.c
index 958995d..9f87253 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -1,5 +1,4 @@
-static char RCSId[] = "$Id: build.c,v 1.3 1993/07/04 04:04:21 root Exp root $";
-static char Copyright[] = "Copyright  Robert J. Amstadt, 1993";
+/* static char Copyright[] = "Copyright  Robert J. Amstadt, 1993"; */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -679,8 +678,6 @@
     ORDVARDEF *vdp;
     int i;
 
-    fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
-
     vdp = odp->additional_data;
     for (i = 0; i < vdp->n_values; i++)
     {
@@ -697,7 +694,7 @@
     fprintf(fp, "\n");
 }
 
-main(int argc, char **argv)
+int main(int argc, char **argv)
 {
     ORDDEF *odp;
     ORDFUNCDEF *fdp;
@@ -796,14 +793,17 @@
 		break;
 
 	      case VARTYPE_BYTE:
+                fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
 		OutputVariableCode(fp, ".byte", odp);
 		break;
 
 	      case VARTYPE_WORD:
+                fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
 		OutputVariableCode(fp, ".word", odp);
 		break;
 
 	      case VARTYPE_LONG:
+                fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
 		OutputVariableCode(fp, ".long", odp);
 		break;
 
diff --git a/windows/Imakefile b/windows/Imakefile
index e0306dc..6d5ca0d 100644
--- a/windows/Imakefile
+++ b/windows/Imakefile
@@ -14,7 +14,6 @@
 	focus.c \
 	graphics.c \
 	hook.c \
-	icon.c \
 	keyboard.c \
 	mapping.c \
 	mdi.c \
diff --git a/windows/cursor.c b/windows/cursor.c
index 4d3628a..5ba75a7 100644
--- a/windows/cursor.c
+++ b/windows/cursor.c
@@ -12,11 +12,11 @@
 #include <unistd.h>
 #include <X11/cursorfont.h>
 #include <X11/Xlib.h>
-#include "prototypes.h"
 #include "windows.h"
 #include "win.h"
 #include "gdi.h"
 #include "library.h"
+#include "neexe.h"
 #include "wine.h"
 #include "cursor.h"
 #include "stddebug.h"
@@ -69,11 +69,10 @@
 	for (i = 0; i < NB_SYS_CURSORS; i++)
 	    if (system_cursor[i].name == cursor_name)
 	    {
-		hCursor = system_cursor[i].cursor;
-		break;
+		if (system_cursor[i].cursor) return system_cursor[i].cursor;
+                else break;
 	    }
 	if (i == NB_SYS_CURSORS) return 0;
-	if (hCursor) return hCursor;
     }
     hCursor = GlobalAlloc(GMEM_MOVEABLE, sizeof(CURSORALLOC) + 1024L); 
     if (hCursor == (HCURSOR)NULL) return 0;
diff --git a/windows/defwnd.c b/windows/defwnd.c
index b02a371..a8c5319 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -100,7 +100,7 @@
 	}
 
     case WM_SETREDRAW:
-        if (wParam)
+        if (!wParam)
         {
             ValidateRect( hwnd, NULL );
             wndPtr->flags |= WIN_NO_REDRAW;
diff --git a/windows/dialog.c b/windows/dialog.c
index bd05034..ead08ba 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -35,12 +35,18 @@
     
       /* Calculate the dialog base units */
 
-    if (!(hdc = GetDC(GetDesktopWindow()))) return FALSE;
+    if (!(hdc = GetDC( 0 ))) return FALSE;
     GetTextMetrics( hdc, &tm );
     ReleaseDC( 0, hdc );
     xBaseUnit = tm.tmAveCharWidth;
     yBaseUnit = tm.tmHeight;
-    dprintf_dialog(stddeb, "DIALOG_Init: base units = %d,%d\n", xBaseUnit, yBaseUnit );
+
+      /* Dialog units are based on a proportional system font */
+      /* so we adjust them a bit for a fixed font. */
+    if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) xBaseUnit = xBaseUnit * 5 / 4;
+
+    dprintf_dialog( stddeb, "DIALOG_Init: base units = %d,%d\n",
+                    xBaseUnit, yBaseUnit );
     return TRUE;
 }
 
@@ -152,7 +158,7 @@
 {
     dprintf_dialog(stddeb, "DIALOG %d, %d, %d, %d\n", result->header->x, result->header->y,
 	    result->header->cx, result->header->cy );
-    dprintf_dialog(stddeb, " STYLE %08x\n", result->header->style );
+    dprintf_dialog(stddeb, " STYLE %08lx\n", result->header->style );
     dprintf_dialog(stddeb, " CAPTION '%s'\n", result->caption );
     dprintf_dialog(stddeb, " CLASS '%s'\n", result->className );
     if (result->menuName[0] == 0xff)
@@ -271,6 +277,8 @@
 	    ReleaseDC( 0, hdc );
 	    xUnit = tm.tmAveCharWidth;
 	    yUnit = tm.tmHeight;
+            if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
+                xBaseUnit = xBaseUnit * 5 / 4;  /* See DIALOG_Init() */
 	}
     }
     
@@ -464,16 +472,6 @@
     return DialogBoxIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
 }
 
-/***********************************************************************
- *           DialogBoxIndirectPtr
- *  like DialogBoxIndirect, but expects pointer to template
- */
-int DialogBoxIndirectPtr( HINSTANCE hInst, LPCSTR dlgTemplate,
-                          HWND owner, WNDPROC dlgProc)
-{
-    return DialogBoxIndirectParamPtr(hInst, dlgTemplate, owner, dlgProc, 0);
-}
-
 
 /***********************************************************************
  *           DialogBoxIndirectParam   (USER.240)
@@ -491,6 +489,7 @@
     return -1;
 }
 
+
 /***********************************************************************
  *           DialogBoxIndirectParamPtr
  *  like DialogBoxIndirectParam, but expects pointer to template
@@ -504,6 +503,15 @@
     return -1;
 }
 
+/***********************************************************************
+ *           DialogBoxIndirectPtr
+ *  like DialogBoxIndirect, but expects pointer to template
+ */
+int DialogBoxIndirectPtr( HINSTANCE hInst, LPCSTR dlgTemplate,
+                          HWND owner, WNDPROC dlgProc)
+{
+    return DialogBoxIndirectParamPtr(hInst, dlgTemplate, owner, dlgProc, 0);
+}
 
 /***********************************************************************
  *           EndDialog   (USER.88)
@@ -530,16 +538,16 @@
     if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
 
       /* Only the key messages get special processing */
-    if ((msg->message == WM_KEYDOWN) ||
-        (msg->message == WM_SYSCHAR) ||
-	(msg->message == WM_CHAR))
+    if ((msg->message != WM_KEYDOWN) &&
+        (msg->message != WM_SYSCHAR) &&
+	(msg->message != WM_CHAR))
+        return FALSE;
+
+    dlgCode = SendMessage( msg->hwnd, WM_GETDLGCODE, 0, 0 );
+    if (dlgCode & DLGC_WANTMESSAGE)
     {
-	dlgCode = SendMessage( msg->hwnd, WM_GETDLGCODE, 0, 0 );
-        if (dlgCode & DLGC_WANTMESSAGE)
-        {
-            DispatchMessage( msg );
-            return TRUE;
-        }
+        DispatchMessage( msg );
+        return TRUE;
     }
 
     switch(msg->message)
diff --git a/windows/graphics.c b/windows/graphics.c
index 4213282..cd8013b 100644
--- a/windows/graphics.c
+++ b/windows/graphics.c
@@ -4,8 +4,6 @@
  * Copyright 1993, 1994 Alexandre Julliard
  */
 
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993, 1994";
-
 #include <math.h>
 #include <stdlib.h>
 #include <X11/Xlib.h>
@@ -15,7 +13,7 @@
 #define PI M_PI
 #endif
 #include "dc.h"
-#include "gdi.h"
+#include "bitmap.h"
 #include "metafile.h"
 #include "syscolor.h"
 #include "stddebug.h"
@@ -250,6 +248,16 @@
     if (bottom < top)
     	swap_int(&bottom, &top);
     
+    if ((dc->u.x.pen.style == PS_INSIDEFRAME) &&
+        (dc->u.x.pen.width < right-left-1) &&
+        (dc->u.x.pen.width < bottom-top-1))
+    {
+        left   += dc->u.x.pen.width / 2;
+        right  -= (dc->u.x.pen.width + 1) / 2;
+        top    += dc->u.x.pen.width / 2;
+        bottom -= (dc->u.x.pen.width + 1) / 2;
+    }
+
     if (DC_SetupGCForBrush( dc ))
 	XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
 		  dc->w.DCOrgX + left, dc->w.DCOrgY + top,
@@ -286,7 +294,8 @@
     if (bottom < top)
     	swap_int(&bottom, &top);
 
-    if ((left == right) || (top == bottom)) {
+    if ((left == right) || (top == bottom))
+    {
 	if (DC_SetupGCForPen( dc ))
 	    XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, 
 		  dc->w.DCOrgX + left,
@@ -296,6 +305,16 @@
 	return TRUE;
     }
     
+    if ((dc->u.x.pen.style == PS_INSIDEFRAME) &&
+        (dc->u.x.pen.width < right-left) &&
+        (dc->u.x.pen.width < bottom-top))
+    {
+        left   += dc->u.x.pen.width / 2;
+        right  -= (dc->u.x.pen.width + 1) / 2;
+        top    += dc->u.x.pen.width / 2;
+        bottom -= (dc->u.x.pen.width + 1) / 2;
+    }
+
     if (DC_SetupGCForBrush( dc ))
 	XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
 		        dc->w.DCOrgX + left, dc->w.DCOrgY + top,
@@ -330,7 +349,8 @@
     y1 = YLPTODP(dc, top);
     x2 = XLPTODP(dc, right - ell_width);
     y2 = YLPTODP(dc, bottom - ell_height);
-    if (DC_SetupGCForBrush(dc)) {
+    if (DC_SetupGCForBrush( dc ))
+    {
 	XFillArc(display, dc->u.x.drawable, dc->u.x.gc,
 		        dc->w.DCOrgX + x1, dc->w.DCOrgY + y1,
 		        ell_width, ell_height, 90 * 64, 90 * 64);
@@ -428,7 +448,8 @@
     right  = XLPTODP( dc, rect->right );
     bottom = YLPTODP( dc, rect->bottom );
     
-    if (DC_SetupGCForBrush( dc )) {
+    if (DC_SetupGCForBrush( dc ))
+    {
    	PatBlt( hdc, rect->left, rect->top, 1,
 	    rect->bottom - rect->top, PATCOPY );
 	PatBlt( hdc, rect->right - 1, rect->top, 1,
@@ -498,19 +519,6 @@
 
     x = dc->w.DCOrgX + XLPTODP( dc, x );
     y = dc->w.DCOrgY + YLPTODP( dc, y );
-#if 0
-    if ((x < 0) || (y < 0)) return 0;
-    
-    if (!(dc->w.flags & DC_MEMORY))
-    {
-	XWindowAttributes win_attr;
-	
-	if (!XGetWindowAttributes( display, dc->u.x.drawable, &win_attr ))
-	    return 0;
-	if (win_attr.map_state != IsViewable) return 0;
-	if ((x >= win_attr.width) || (y >= win_attr.height)) return 0;
-    }
-#endif
     image = XGetImage( display, dc->u.x.drawable, x, y,
 		       1, 1, AllPlanes, ZPixmap );
     pixel = XGetPixel( image, 0, 0 );
@@ -534,6 +542,8 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
 
+      /* FIXME: the region is supposed to be in logical coordinates */
+
       /* Modify visible region */
 
     if (!(prevVisRgn = SaveVisRgn( hdc ))) return FALSE;
@@ -627,7 +637,7 @@
  * Faster than CreateCompatibleDC() + SelectBitmap() + BitBlt() + DeleteDC().
  */
 BOOL GRAPH_DrawBitmap( HDC hdc, HBITMAP hbitmap, int xdest, int ydest,
-		       int xsrc, int ysrc, int width, int height, int rop )
+		       int xsrc, int ysrc, int width, int height )
 {
     XGCValues val;
     BITMAPOBJ *bmp;
@@ -636,7 +646,7 @@
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
     if (!(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
 	return FALSE;
-    val.function   = DC_XROPfunction[(rop >> 16) & 0x0f];
+    val.function   = GXcopy;
     val.foreground = dc->w.textPixel;
     val.background = dc->w.backgroundPixel;
     XChangeGC(display, dc->u.x.gc, GCFunction|GCForeground|GCBackground, &val);
@@ -777,7 +787,7 @@
 	/* MF_MetaPoly(dc, META_POLYGON, pt, count); */
 	return TRUE;
     }
-      /* The points should be converted to device coords before */
+      /* FIXME: The points should be converted to device coords before */
       /* creating the region. But as CreatePolyPolygonRgn is not */
       /* really correct either, it doesn't matter much... */
       /* At least the outline will be correct :-) */
diff --git a/windows/hook.c b/windows/hook.c
index 20184bc..0f15595 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -4,8 +4,6 @@
  * Copyright 1994 Alexandre Julliard
  */
 
-static char Copyright[] = "Copyright  Alexandre Julliard, 1994";
-
 /* Warning!
  * HHOOK is not a real handle, but a 32-bit pointer to a HOOKDATA structure.
  * This is for compatibility with Windows 3.0 where HHOOK was a HOOKPROC.
diff --git a/windows/icon.c b/windows/icon.c
deleted file mode 100644
index 8b13789..0000000
--- a/windows/icon.c
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/windows/mapping.c b/windows/mapping.c
index b3f96d1..93a6f37 100644
--- a/windows/mapping.c
+++ b/windows/mapping.c
@@ -4,8 +4,6 @@
  * Copyright 1993 Alexandre Julliard
  */
 
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-
 #include "gdi.h"
 #include "metafile.h"
 #include "stddebug.h"
diff --git a/windows/mdi.c b/windows/mdi.c
index ed6ca96..43abdf4 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -361,6 +361,11 @@
     if (ci->flagChildMaximized)
 	MDIRestoreChild(parent, ci);
 
+    /* If there aren't any children, don't even bother.
+     */
+    if (ci->nActiveChildren == 0)
+        return 0;
+
     GetClientRect(parent, &rect);
     spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);
     ysize   = rect.bottom - 8 * spacing;
@@ -406,6 +411,11 @@
     if (ci->flagChildMaximized)
 	MDIRestoreChild(parent, ci);
 
+    /* If there aren't any children, don't even bother.
+     */
+    if (ci->nActiveChildren == 0)
+        return 0;
+
     GetClientRect(parent, &rect);
     rows    = (int) sqrt((double) ci->nActiveChildren);
     columns = ci->nActiveChildren / rows;
diff --git a/windows/message.c b/windows/message.c
index b4d6458..072635e 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -9,8 +9,6 @@
  * one message queue).
  */
 
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993, 1994";
-
 #include <stdlib.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -844,7 +842,7 @@
 	    while (hwnd) {
 	        if (!(wndPtr = WIN_FindWndPtr(hwnd))) break;
 			if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION) {
-				dprintf_msg(stddeb,"BROADCAST Message to hWnd=%04X m=%04X w=%04X l=%08X !\n", 
+				dprintf_msg(stddeb,"BROADCAST Message to hWnd=%04X m=%04X w=%04X l=%08lX !\n", 
 							hwnd, message, wParam, lParam);
 				PostMessage(hwnd, message, wParam, lParam);
 				}
diff --git a/windows/nonclient.c b/windows/nonclient.c
index f91eb12..bab7953 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -3,8 +3,7 @@
  *
  * Copyright 1994 Alexandre Julliard
  *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1994";
-*/
+ */
 
 #include "win.h"
 #include "class.h"
@@ -38,8 +37,8 @@
 
   /* Some useful macros */
 #define HAS_DLGFRAME(style,exStyle) \
-    (((style) & WS_DLGFRAME) && \
-     (((exStyle) & WS_EX_DLGMODALFRAME) || !((style) & WS_BORDER)))
+    (((exStyle) & WS_EX_DLGMODALFRAME) || \
+     (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
 
 #define HAS_THICKFRAME(style) \
     (((style) & WS_THICKFRAME) && \
@@ -316,13 +315,18 @@
 void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
 {
     RECT rect;
+    HDC hdcMem;
+    HBITMAP hbitmap;
     WND *wndPtr = WIN_FindWndPtr( hwnd );
+
     NC_GetInsideRect( hwnd, &rect );
-    GRAPH_DrawBitmap( hdc, hbitmapClose,
-		      rect.left, rect.top,
-                      (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
-                      SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
-		      down ? NOTSRCCOPY : SRCCOPY );
+    hdcMem = CreateCompatibleDC( hdc );
+    hbitmap = SelectObject( hdcMem, hbitmapClose );
+    BitBlt( hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
+            hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
+            down ? NOTSRCCOPY : SRCCOPY );
+    SelectObject( hdcMem, hbitmap );
+    DeleteDC( hdcMem );
 }
 
 
@@ -337,7 +341,7 @@
 			    (down ? hbitmapRestoreD : hbitmapRestore) :
 			    (down ? hbitmapMaximizeD : hbitmapMaximize)),
 		     rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
-		     0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE, SRCCOPY );
+		     0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
 }
 
 
@@ -352,7 +356,7 @@
     if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE + 1;
     GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
 		     rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
-		     0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE, SRCCOPY );
+		     0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
 }
 
 
@@ -544,9 +548,9 @@
 
     dprintf_nonclient(stddeb, "NC_DoNCPaint: %d %d\n", hwnd, hrgn );
     if (!wndPtr || !hrgn) return;
-    if ((!(wndPtr->dwStyle & (WS_BORDER | WS_DLGFRAME | WS_THICKFRAME))) ||
-	(!(wndPtr->dwStyle & WS_VISIBLE)))
-	return;  /* Nothing to do! */
+    if (!(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
+    if (!(wndPtr->dwStyle & (WS_BORDER | WS_DLGFRAME | WS_THICKFRAME)) &&
+        !(wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)) return; /* Nothing to do */
 
     if (hrgn == 1) hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
     else
@@ -594,7 +598,8 @@
 
     SelectObject( hdc, sysColorObjects.hpenWindowFrame );
 
-    if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME))
+    if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
+        (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
     {
 	MoveTo( hdc, 0, 0 );
 	LineTo( hdc, rect.right-1, 0 );
diff --git a/windows/painting.c b/windows/painting.c
index 16251ca..fe45db7 100644
--- a/windows/painting.c
+++ b/windows/painting.c
@@ -4,8 +4,6 @@
  * Copyright 1993 Alexandre Julliard
  */
 
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-
 #include <stdio.h>
 #include <X11/Xlib.h>
 
diff --git a/windows/scroll.c b/windows/scroll.c
index 2710c30..4a1a51f 100644
--- a/windows/scroll.c
+++ b/windows/scroll.c
@@ -5,8 +5,6 @@
  *
  */
 
-static char Copyright[] = "Copyright  David W. Metcalfe, 1993";
-
 #include <stdlib.h>
 #include "windows.h"
 #include "gdi.h"
diff --git a/windows/syscolor.c b/windows/syscolor.c
index bcf5397..066eb24 100644
--- a/windows/syscolor.c
+++ b/windows/syscolor.c
@@ -6,12 +6,9 @@
  *
  */
 
-static char Copyright[] = "Copyright  David W. Metcalfe, 1993";
-static char Copyright2[] = "Copyright  Alexandre Julliard, 1994";
-
 #include <stdio.h>
 #include <stdlib.h>
-#include "windows.h"
+#include "gdi.h"
 #include "syscolor.h"
 #include "stddebug.h"
 /* #define DEBUG_SYSCOLOR */
diff --git a/windows/timer.c b/windows/timer.c
index 9c54240..0d1b0af 100644
--- a/windows/timer.c
+++ b/windows/timer.c
@@ -4,8 +4,6 @@
  * Copyright 1993 Alexandre Julliard
  */
 
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-
 #include "windows.h"
 #include "message.h"
 #include "stddebug.h"
diff --git a/windows/utility.c b/windows/utility.c
index 75b779d..ec69566 100644
--- a/windows/utility.c
+++ b/windows/utility.c
@@ -18,7 +18,7 @@
 #include "debug.h"
 
 
-static char Copyright[] = "Copyright Andrew C. Bulhak, 1993";
+/* static char Copyright[] = "Copyright Andrew C. Bulhak, 1993"; */
 
 
 /*	MulDiv is a simple function that may as well have been
@@ -72,6 +72,7 @@
 	DebugPrintString(foo);
 };
 
+#if 0
 /*	UTILITY_qualify(source, dest) takes the format string source and
  *	changes all the parameters to correspond to Linux integer sizes
  *	rather than Windows sizes. For example, it converts %i to %hi
@@ -109,6 +110,7 @@
 	};
 	*dest = '\0';
 };
+#endif
 
 /*	UTILITY_argsize() evaluates the size of the argument list that
  *	accompanies a vsprintf() or wvsprintf() call.
diff --git a/windows/win.c b/windows/win.c
index 28131ec..779fbf7 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -20,6 +20,7 @@
 #include "icon.h"
 #include "cursor.h"
 #include "event.h"
+#include "message.h"
 #include "winpos.h"
 #include "color.h"
 #include "stddebug.h"
@@ -297,7 +298,7 @@
     int wmcreate;
     XSetWindowAttributes win_attr;
 
-    dprintf_win(stddeb, "CreateWindowEx: %04X '%s' '%s' %04X %d,%d %dx%d %04X %04X %04X %08X\n",
+    dprintf_win(stddeb, "CreateWindowEx: %08lX '%s' '%s' %08lX %d,%d %dx%d %04X %04X %04X %p\n",
 				exStyle, className, windowName, style, x, y, width, height, 
 				parent, menu, instance, data);
 	/* 'soundrec.exe' has negative position ! 
@@ -444,7 +445,7 @@
         GlobalUnlock( hCursor );
     }
     
-    dprintf_menu(stddeb,"CreateWindowEx // menu=%04X instance=%04X classmenu=%08X !\n", 
+    dprintf_menu(stddeb,"CreateWindowEx // menu=%04X instance=%04X classmenu=%p !\n", 
     	menu, instance, classPtr->wc.lpszMenuName);
 
 	if ((style & WS_CAPTION) && (style & WS_CHILD) == 0) {
diff --git a/windows/winpos.c b/windows/winpos.c
index 8a1ebd1..659211e 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -4,8 +4,6 @@
  * Copyright 1993, 1994 Alexandre Julliard
  */
 
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993, 1994";
-
 #include "sysmetrics.h"
 #include "user.h"
 #include "win.h"