Index: trunk/src/ddraw/new/OS2CLIPPER.CPP
===================================================================
--- trunk/src/ddraw/new/OS2CLIPPER.CPP	(revision 3345)
+++ trunk/src/ddraw/new/OS2CLIPPER.CPP	(revision 3345)
@@ -0,0 +1,174 @@
+/* $Id: OS2CLIPPER.CPP,v 1.1 2000-04-07 18:21:03 mike Exp $ */
+
+/*
+ * DX clipper class routines
+ *
+ * Copyright 1998 Sander van Leeuwen
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <memory.h>
+
+#define INITGUID
+#include "os2ddraw.h"
+#include "os2clipper.h"
+#define _OS2WIN_H
+#define FAR
+#include <misc.h>
+#include <winerror.h>
+
+//******************************************************************************
+//******************************************************************************
+OS2IDirectDrawClipper::OS2IDirectDrawClipper(OS2IDirectDraw *lpDirectDraw) :
+                 Referenced(0), lastError(DD_OK),
+                 clipWindow(0)
+{
+  lpVtbl                  = &Vtbl;
+  Vtbl.AddRef             = ClipAddRef;
+  Vtbl.Release            = ClipRelease;
+  Vtbl.QueryInterface     = ClipQueryInterface;
+  Vtbl.GetClipList        = ClipGetClipList;
+  Vtbl.GetHWnd            = ClipGetHWnd;
+  Vtbl.Initialize         = ClipInitialize;
+  Vtbl.IsClipListChanged  = ClipIsClipListChanged;
+  Vtbl.SetClipList        = ClipSetClipList;
+  Vtbl.SetHWnd            = ClipSetHWnd;
+
+  lpDraw                  = lpDirectDraw;
+  lpDraw->Vtbl.AddRef(lpDraw);
+  hDive                   = lpDirectDraw->GetDiveInstance();
+}
+//******************************************************************************
+//******************************************************************************
+OS2IDirectDrawClipper::~OS2IDirectDrawClipper()
+{
+  lpDraw->Vtbl.Release(lpDraw);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall ClipQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: ClipQueryInterface\n"));
+  #endif
+
+  *ppvObj = NULL;
+
+  if(!IsEqualGUID(riid, IID_IDirectDrawClipper) &&
+     !IsEqualGUID(riid, CLSID_DirectDrawClipper))
+//&& !IsEqualGUID(riid, IID_IUnknown))
+  return E_NOINTERFACE;
+
+  *ppvObj = This;
+
+  ClipAddRef(This);
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG   __stdcall ClipAddRef(THIS This)
+{
+ OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawClipper::AddRef %d\n", me->Referenced+1));
+  #endif
+
+  return ++me->Referenced;
+}
+//******************************************************************************
+//******************************************************************************
+ULONG   __stdcall ClipRelease(THIS This)
+{
+ OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawClipper::Release %d\n", me->Referenced-1));
+  #endif
+
+  if(me->Referenced)
+  {
+    me->Referenced--;
+    if(me->Referenced == 0)
+    {
+      delete( me);
+      return(0);
+    }
+    else
+      return me->Referenced;
+  }
+  else
+   return(0);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall ClipGetClipList(THIS, LPRECT, LPRGNDATA, LPDWORD)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: ClipGetClipList\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall ClipGetHWnd(THIS This, HWND FAR *pHwnd)
+{
+ OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: ClipGetHWnd\n"));
+  #endif
+
+  *pHwnd = me->clipWindow;
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall ClipInitialize(THIS, LPDIRECTDRAW, DWORD)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: ClipInitialize\n"));
+  #endif
+
+  return(DDERR_ALREADYINITIALIZED); // Init is done during creation see M$ Doc
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall ClipIsClipListChanged(THIS, BOOL FAR *)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: ClipIsClipListChanged\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall ClipSetClipList(THIS, LPRGNDATA,DWORD)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: ClipSetClipList\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//DWORD param not used in DirectX 3
+//******************************************************************************
+HRESULT __stdcall ClipSetHWnd(THIS This, DWORD reserved, HWND hwnd)
+{
+ OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: ClipSetHWnd\n"));
+  #endif
+
+  me->clipWindow = hwnd;
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/ddraw/new/OS2CLIPPER.H
===================================================================
--- trunk/src/ddraw/new/OS2CLIPPER.H	(revision 3345)
+++ trunk/src/ddraw/new/OS2CLIPPER.H	(revision 3345)
@@ -0,0 +1,63 @@
+/* $Id: OS2CLIPPER.H,v 1.1 2000-04-07 18:21:03 mike Exp $ */
+
+/*
+ * DX clipper class definition
+ *
+ * Copyright 1998 Sander va Leeuwen
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __OS2CLIPPER_H__
+#define __OS2CLIPPER_H__
+
+#include "divewrap.h"
+#define FAR
+#undef THIS
+#define THIS IDirectDrawClipper*
+class OS2IDirectDrawClipper
+{
+ public:
+  //this one has to go first!
+  IDirectDrawClipperVtbl *lpVtbl;
+  IDirectDrawClipperVtbl  Vtbl;
+
+  OS2IDirectDrawClipper(OS2IDirectDraw *lpDirectDraw);
+       ~OS2IDirectDrawClipper();
+
+        int             Referenced;
+        inline  HRESULT       GetLastError() { return lastError; };
+ private:
+
+ protected:
+              HRESULT                lastError;
+        OS2IDirectDraw        *lpDraw;
+        HDIVE                  hDive;
+        HWND         clipWindow;
+
+                              // Linked list management
+              OS2IDirectDrawClipper* next;                   // Next OS2IDirectDraw
+    static    OS2IDirectDrawClipper* ddraw;                  // List of OS2IDirectDraw
+
+    friend    HRESULT __stdcall ClipQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj);
+    friend    ULONG   __stdcall ClipAddRef(THIS);
+    friend    ULONG   __stdcall ClipRelease(THIS);
+    friend    HRESULT __stdcall ClipGetClipList(THIS, LPRECT, LPRGNDATA, LPDWORD);
+    friend    HRESULT __stdcall ClipGetHWnd(THIS, HWND FAR *);
+    friend    HRESULT __stdcall ClipInitialize(THIS, LPDIRECTDRAW, DWORD);
+    friend    HRESULT __stdcall ClipIsClipListChanged(THIS, BOOL FAR *);
+    friend    HRESULT __stdcall ClipSetClipList(THIS, LPRGNDATA,DWORD);
+    friend    HRESULT __stdcall ClipSetHWnd(THIS, DWORD, HWND );
+};
+
+HRESULT __stdcall ClipQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj);
+ULONG   __stdcall ClipAddRef(THIS);
+ULONG   __stdcall ClipRelease(THIS);
+HRESULT __stdcall ClipGetClipList(THIS, LPRECT, LPRGNDATA, LPDWORD);
+HRESULT __stdcall ClipGetHWnd(THIS, HWND FAR *);
+HRESULT __stdcall ClipInitialize(THIS, LPDIRECTDRAW, DWORD);
+HRESULT __stdcall ClipIsClipListChanged(THIS, BOOL FAR *);
+HRESULT __stdcall ClipSetClipList(THIS, LPRGNDATA,DWORD);
+HRESULT __stdcall ClipSetHWnd(THIS, DWORD, HWND );
+
+#endif
Index: trunk/src/ddraw/new/OS2D3D.CPP
===================================================================
--- trunk/src/ddraw/new/OS2D3D.CPP	(revision 3345)
+++ trunk/src/ddraw/new/OS2D3D.CPP	(revision 3345)
@@ -0,0 +1,116 @@
+/* $Id: OS2D3D.CPP,v 1.1 2000-04-07 18:21:04 mike Exp $ */
+
+/*
+ * DX clipper class routines
+ *
+ * Copyright 1998 Sander van Leeuwen
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <memory.h>
+
+#define INITGUID
+#include "os2ddraw.h"
+#include "os2clipper.h"
+#include "os2palette.h"
+#include "os2surface.h"
+#define _OS2WIN_H
+#define FAR
+#include <misc.h>
+#include <winerror.h>
+#include <builtin.h>
+#undef THIS
+#define THIS VOID*
+
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall D3DQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
+{
+  dprintf(("DDRAW: D3DQueryInterface\n"));
+  *ppvObj = NULL;
+
+  if(IID_IDirect3D != (GUID &)&riid)
+    return E_NOINTERFACE;
+
+  *ppvObj = This;
+
+  D3DAddRef(This);
+  return(D3D_OK);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall D3DAddRef(THIS This)
+{
+ OS2IDirectDraw *me = (OS2IDirectDraw *)This;
+
+  dprintf(("DDRAW: OS2IDirectDraw::AddRef %d\n", me->Referenced+1));
+  return ++me->Referenced;
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall D3DRelease(THIS This)
+{
+ OS2IDirectDraw *me = (OS2IDirectDraw *)This;
+
+  dprintf(("DDRAW: OS2IDirectDraw::Release %d\n", me->Referenced-1));
+  dprintf(("DDRAW: OS2IDirectDraw::%X \n", me));
+  if(me->Referenced)
+  {
+    me->Referenced--;
+    if(me->Referenced == 0)
+    {
+      delete(me);
+      return(0);
+    }
+    else
+      return me->Referenced;
+  }
+  else
+    return(0);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall D3DInitialize(THIS This, REFIID)
+{
+  dprintf(("DDRAW: D3DInitialize\n"));
+  return(D3D_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall D3DEnumDevices(THIS This, LPD3DENUMDEVICESCALLBACK, LPVOID)
+{
+  dprintf(("DDRAW: D3DEnumDevices\n"));
+  return(D3D_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall D3DCreateLight(THIS This, LPDIRECT3DLIGHT*, IUnknown*)
+{
+  dprintf(("DDRAW: D3DCreateLight\n"));
+  return(D3D_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall D3DCreateMaterial(THIS This, LPDIRECT3DMATERIAL*, IUnknown*)
+{
+  dprintf(("DDRAW: D3DCreateMaterial\n"));
+  return(D3D_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall D3DCreateViewport(THIS This, LPDIRECT3DVIEWPORT*, IUnknown*)
+{
+  dprintf(("DDRAW: D3DCreateViewport\n"));
+  return(D3D_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall D3DFindDevice(THIS This, LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT)
+{
+  dprintf(("DDRAW: D3DCreateFindDevice\n"));
+  return(D3D_OK);
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/ddraw/new/OS2DDRAW.CPP
===================================================================
--- trunk/src/ddraw/new/OS2DDRAW.CPP	(revision 3345)
+++ trunk/src/ddraw/new/OS2DDRAW.CPP	(revision 3345)
@@ -0,0 +1,1849 @@
+/* $Id: OS2DDRAW.CPP,v 1.1 2000-04-07 18:21:04 mike Exp $ */
+
+/*
+ * DX Draw base class implementation
+ *
+ * Copyright 1998 Sander van Leeuwen
+ * Copyright 1999 Markus Montkowski
+ * Copyright 2000 Michal Necasek
+ * Copyright 2000 Przemyslaw Dobrowolski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+
+#define INITGUID
+#include "os2ddraw.h"
+#include "os2clipper.h"
+#include "os2palette.h"
+#include "os2surface.h"
+#define _OS2WIN_H
+#define FAR
+#include <misc.h>
+#include <string.h>
+#include <winreg.h>
+#include <winuser.h>
+#include <winerror.h>
+#include <builtin.h>
+#include "cio2.h"
+#include "os2util.h"
+#include "os2fsdd.h"
+// include with the videomodes we support
+// better would be to get these modes from the card
+// But for now we use standard VESA 2.0 modes with 70Hz
+#include "os2ddrawmodes.h"
+#include "os2DDWindow.h"
+#include "os2palset.h"
+#include "os2fsdd.h"
+
+#define KEY_DIRECT2 "\\Software\\Win32OS2\\Direct2"
+#define KEY_DIRECT2DRAW "\\Software\\Win32OS2\\Direct2\\Draw"
+
+FOURCC  SupportedFourCCs[] = {FOURCC_SCRN,FOURCC_LUT8,FOURCC_R565,FOURCC_RGB3,FOURCC_RGB4};
+//******************************************************************************
+//******************************************************************************
+OS2IDirectDraw::OS2IDirectDraw(GUID *lpGUID) :
+     Referenced(0), lastError(DD_OK),
+     pFrameBuffer(NULL), hwndClient(0), screenwidth(640),
+     screenheight(480), screenbpp(16),PrimaryExists(FALSE),pPrimSurf(NULL)
+
+{
+  HKEY  hkDirectDraw2;
+  DWORD dwVSize, dwVType;
+  ULONG rc;
+  FOURCC fccModes[100];
+
+  // Setup table for 3d devices
+  Vtbl3D.AddRef         = D3DAddRef;
+  Vtbl3D.Release        = D3DRelease;
+  Vtbl3D.QueryInterface = D3DQueryInterface;
+  Vtbl3D.Initialize     = D3DInitialize;
+  Vtbl3D.EnumDevices    = D3DEnumDevices;
+  Vtbl3D.CreateLight    = D3DCreateLight;
+  Vtbl3D.CreateMaterial = D3DCreateMaterial;
+  Vtbl3D.CreateViewport = D3DCreateViewport;
+  Vtbl3D.FindDevice     = D3DFindDevice;
+
+  // old V2 Interface
+  Vtbl.AddRef                 = DrawAddRef;
+  Vtbl.Release                = DrawRelease;
+  Vtbl.QueryInterface         = DrawQueryInterface;
+  Vtbl.Compact                = DrawCompact;
+  Vtbl.CreateClipper          = DrawCreateClipper;
+  Vtbl.CreatePalette          = DrawCreatePalette;
+  Vtbl.CreateSurface          = DrawCreateSurface;
+  Vtbl.DuplicateSurface       = DrawDuplicateSurface;
+  Vtbl.EnumDisplayModes       = DrawEnumDisplayModes;
+  Vtbl.EnumSurfaces           = DrawEnumSurfaces;
+  Vtbl.FlipToGDISurface       = DrawFlipToGDISurface;
+  Vtbl.GetCaps                = DrawGetCaps;
+  Vtbl.GetDisplayMode         = DrawGetDisplayMode;
+  Vtbl.GetFourCCCodes         = DrawGetFourCCCodes;
+  Vtbl.GetGDISurface          = DrawGetGDISurface;
+  Vtbl.GetMonitorFrequency    = DrawGetMonitorFrequency;
+  Vtbl.GetScanLine            = DrawGetScanLine;
+  Vtbl.GetVerticalBlankStatus = DrawGetVerticalBlankStatus;
+  Vtbl.Initialize             = DrawInitialize;
+  Vtbl.RestoreDisplayMode     = DrawRestoreDisplayMode;
+  Vtbl.SetCooperativeLevel    = DrawSetCooperativeLevel;
+  if(lpGUID && *lpGUID == IID_IDirectDraw2)
+    *(ULONG *)&Vtbl.SetDisplayMode = (ULONG)DrawSetDisplayMode2;
+  else
+    *(ULONG *)&Vtbl.SetDisplayMode = (ULONG)DrawSetDisplayMode;
+  Vtbl.WaitForVerticalBlank   = DrawWaitForVerticalBlank;
+  Vtbl.GetAvailableVidMem     = DrawGetAvailableVidMem;
+
+  // New V4 interface
+  Vtbl4.AddRef                 = DrawAddRef;   // todo change to a DrawAddRef4 as handling this has changed
+  Vtbl4.Release                = DrawRelease;  // see above
+  Vtbl4.QueryInterface         = DrawQueryInterface;
+  Vtbl4.Compact                = DrawCompact;
+  Vtbl4.CreateClipper          = DrawCreateClipper;
+  Vtbl4.CreateSurface          = DrawCreateSurface4;//
+  Vtbl4.DuplicateSurface       = DrawDuplicateSurface4;//
+  Vtbl4.EnumDisplayModes       = DrawEnumDisplayModes4;//
+  Vtbl4.EnumSurfaces           = DrawEnumSurfaces4; //
+  Vtbl4.FlipToGDISurface       = DrawFlipToGDISurface;
+  Vtbl4.GetCaps                = DrawGetCaps;
+  Vtbl4.GetDisplayMode         = DrawGetDisplayMode4;//
+  Vtbl4.GetFourCCCodes         = DrawGetFourCCCodes;
+  Vtbl4.GetGDISurface          = DrawGetGDISurface4;//
+  Vtbl4.GetMonitorFrequency    = DrawGetMonitorFrequency;
+  Vtbl4.GetScanLine            = DrawGetScanLine;
+  Vtbl4.GetVerticalBlankStatus = DrawGetVerticalBlankStatus;
+  Vtbl4.Initialize             = DrawInitialize;
+  Vtbl4.RestoreDisplayMode     = DrawRestoreDisplayMode;
+  Vtbl4.SetCooperativeLevel    = DrawSetCooperativeLevel;
+  Vtbl4.SetDisplayMode         = DrawSetDisplayMode2;
+  Vtbl4.WaitForVerticalBlank   = DrawWaitForVerticalBlank;
+  Vtbl4.GetAvailableVidMem     = DrawGetAvailableVidMem4;
+  Vtbl4.GetSurfaceFromDC       = DrawGetSurfaceFromDC;
+  Vtbl4.RestoreAllSurfaces     = DrawRestoreAllSurfaces;
+  Vtbl4.TestCooperativeLevel   = DrawTestCooperativeLevel;
+  Vtbl4.GetDeviceIdentifier    = DrawGetDeviceIdentifier;
+
+  if(lpGUID && *lpGUID == IID_IDirect3D)
+  {
+    dprintf(("DDRAW: D3D Interface\n"));
+
+    lpVtbl = (IDirectDraw4Vtbl *)&Vtbl3D;
+  }
+  else
+  {
+    if(lpGUID && *lpGUID == IID_IDirectDraw4)
+    {
+      dprintf(("DDRAW: V4 Interface\n"));
+      lpVtbl = &Vtbl4;
+    }
+    else
+    {
+      dprintf(("DDRAW: <V4 Interface\n"));
+      lpVtbl = (IDirectDraw4Vtbl *) &Vtbl;
+    }
+  }
+
+  lpVtbl2 = lpVtbl;
+
+  pdwUnknownData = (DWORD*) malloc (255*sizeof(DWORD));
+  for(int i= 0 ;i<255;i++)
+    pdwUnknownData[i] = 0;
+
+  rc = DiveOpen( &hDive,
+                 FALSE,
+                 &pFrameBuffer);
+  if(rc)
+  {
+    dprintf(("DDRAW: ERROR: DiveOpen returned %d\n", rc));
+    lastError = DDERR_GENERIC;
+    hDive     = NULL;
+  }
+  else
+  {
+    dprintf(("DDRAW: DiveOpen OK Framebuufer at 0x%08X\n",pFrameBuffer));
+  }
+  memset( &dCaps,
+          0,
+          sizeof(DIVE_CAPS) );
+  dCaps.ulStructLen = sizeof(DIVE_CAPS);
+  dCaps.ulFormatLength = 100;
+  dCaps.pFormatData = &fccModes[0];
+
+  rc = DiveQueryCaps( &dCaps,
+                      DIVE_BUFFER_SCREEN);
+
+  dprintf(("DDRAW: DiveQueryCaps rc=0x%08X\n",rc));
+
+  pdwUnknownData[235] = dCaps.ulHorizontalResolution;
+  pdwUnknownData[236] = dCaps.ulVerticalResolution;
+  pdwUnknownData[241] = dCaps.ulDepth;
+
+  // Shall we run in FS mode ?
+  if(ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,KEY_DIRECT2DRAW,&hkDirectDraw2))
+  {
+    dwVSize = 4;
+    dwVType = REG_DWORD;
+    if(ERROR_SUCCESS!=RegQueryValueExA(hkDirectDraw2,"Fullscreen",NULL,&dwVType,(LPBYTE)&bScale,&dwVSize))
+      bScale = FALSE;
+  }
+  else
+    bScale = FALSE;
+
+  rc = InitIO();
+
+  if(rc)  // try to get IOPL for the thread
+  {
+    dprintf(("DDRAW: No IOPL\n"));
+  }
+  else
+  {
+    dprintf(("DDRAW: IOPL 3!\n"));
+  }
+
+  rc = LoadPMIService();
+
+  dprintf(("DDRAW: LoadPMIService() rc=0x%08X\n",rc));
+
+  if (!rc)
+    bPMILoaded=TRUE;
+  else
+    bPMILoaded=FALSE;
+
+  SetUpModeTable();
+}
+//******************************************************************************
+//******************************************************************************
+OS2IDirectDraw::~OS2IDirectDraw()
+{
+  dprintf(("DDRAW: OS2IDirectDraw::~OS2IDirectDraw()\n"));
+
+  if(hDive) DiveClose(hDive);
+
+  // Safty call in case the program did set the pal to all black
+  // so if the destructor gets called we might be able change this back
+  OS2ResetPhysPalette();
+
+  // we need this in Full Screen, but don't create any effect in windowed
+  // session.
+  if (bPMILoaded)
+  {
+    RestorePM();
+    FreeModeTable();
+  }
+}
+//******************************************************************************
+//******************************************************************************
+FOURCC OS2IDirectDraw::GetScreenFourCC()
+{
+  return SupportedFourCCs[screenbpp>>3];
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
+{
+ OS2IDirectDraw *me = (OS2IDirectDraw *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDraw::QueryInterface\n"));
+  #endif
+
+  *ppvObj = NULL;
+
+  if(!IsEqualGUID(riid, CLSID_DirectDraw) &&
+     !IsEqualGUID(riid, IID_IDirectDraw) &&
+     !IsEqualGUID(riid, IID_IDirectDraw2) &&
+     !IsEqualGUID(riid, IID_IDirectDraw4))
+//&& !IsEqualGUID(riid, IID_IUnknown))
+  return E_NOINTERFACE;
+
+  // ToDo Better way of returning differnent intterfaces for same class
+
+  if(IsEqualGUID(riid, IID_IDirectDraw4))
+  {
+    dprintf(("DDRAW: IID_IDirectDraw4 Interface\n"));
+    me->lpVtbl = &me->Vtbl4;
+  }
+  else
+  {
+    dprintf(("DDRAW: No IID_IDirectDraw4 Interface\n"));
+    me->lpVtbl = (IDirectDraw4Vtbl *) &me->Vtbl;
+  }
+  *ppvObj = This;
+  DrawAddRef(This);
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall DrawAddRef(THIS This)
+{
+ OS2IDirectDraw *me = (OS2IDirectDraw *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDraw::AddRef %d\n", me->Referenced+1));
+  #endif
+
+  return ++me->Referenced;
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall DrawRelease(THIS This)
+{
+ OS2IDirectDraw *me = (OS2IDirectDraw *)This;
+ ULONG rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDraw::Release %d\n", me->Referenced-1));
+    dprintf(("DDRAW: OS2IDirectDraw::%X \n", me));
+  #endif
+
+  if(me->Referenced)
+  {
+
+    me->Referenced--;
+    if(me->Referenced == 0)
+    {
+      delete(me);
+      rc = 0;
+    }
+    else
+      rc = me->Referenced;
+  }
+  else
+    rc = 0;
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawCompact(THIS)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: Compact\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawCreateClipper(THIS This, DWORD, LPDIRECTDRAWCLIPPER FAR *lplpDD, IUnknown FAR * )
+{
+ OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+ OS2IDirectDrawClipper *newclip;
+ HRESULT                rc;
+
+  newclip = new OS2IDirectDrawClipper(me);
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: CreateClipper\n"));
+  #endif
+
+  if(newclip == NULL)
+  {
+    rc = DDERR_OUTOFMEMORY;
+  }
+  else
+  {
+    newclip->Vtbl.AddRef((IDirectDrawClipper *)newclip);
+    rc = newclip->GetLastError();
+    if(rc != DD_OK)
+    {
+      *lplpDD = NULL;
+      delete newclip;
+    }
+    else
+      *lplpDD = (IDirectDrawClipper *)newclip;
+  }
+
+  return(rc);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawCreatePalette(THIS This, DWORD dwFlags,
+            LPPALETTEENTRY lpColorTable,
+            LPDIRECTDRAWPALETTE FAR *lplpDD,
+            IUnknown FAR *pUnkOuter)
+{
+  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+  OS2IDirectDrawPalette *newpal;
+  HRESULT                rc = DD_OK;
+  int                    palsize = 0;
+
+  if(dwFlags & DDPCAPS_8BITENTRIES)
+  {
+    // We Don't support Indexed palettes...
+
+    rc = DDERR_INVALIDPARAMS;
+  }
+
+  if(dwFlags & DDPCAPS_2BIT)
+    palsize = 4;
+  if(dwFlags & DDPCAPS_4BIT)
+    palsize = 16;
+  if(dwFlags & DDPCAPS_8BIT)
+    palsize = 256;
+  if(dwFlags & DDPCAPS_ALLOW256)
+    palsize = 256;
+
+  if(palsize == 0)
+    rc = DDERR_INVALIDPARAMS;
+
+  if(DD_OK == rc)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: CreatePalette with %d colors\n", palsize));
+    #endif
+
+    newpal = new OS2IDirectDrawPalette((VOID*)me, palsize, lpColorTable, dwFlags);
+
+    if(newpal == NULL)
+    {
+      rc = DDERR_OUTOFMEMORY;
+    }
+    else
+    {
+      newpal->Vtbl.AddRef((IDirectDrawPalette *)newpal);
+      rc = newpal->GetLastError();
+
+      if(DD_OK != rc)
+      {
+        *lplpDD = NULL;
+        delete newpal;
+      }
+      else
+        *lplpDD = (IDirectDrawPalette *)newpal;
+    }
+  }
+
+  return(rc);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawCreateSurface(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc,
+            LPDIRECTDRAWSURFACE FAR *lplpDD,
+            IUnknown FAR *pUnkOuter)
+{
+ OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+ OS2IDirectDrawSurface *newsurf;
+ HRESULT                rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: CreateSurface\n"));
+    dprintf(("DDRAW: dwSize %d\n", lpDDSurfaceDesc->dwSize));
+    dprintf(("DDRAW: dwFlags %X\n", lpDDSurfaceDesc->dwFlags));
+    dprintf(("DDRAW: dwHeight %d\n", lpDDSurfaceDesc->dwHeight));
+    dprintf(("DDRAW: dwWidth %d\n", lpDDSurfaceDesc->dwWidth));
+    dprintf(("DDRAW: lPitch %d\n", lpDDSurfaceDesc->lPitch));
+    dprintf(("DDRAW: dwBackBufferCount %d\n", lpDDSurfaceDesc->dwBackBufferCount));
+    dprintf(("DDRAW: dwMipMapCount %d\n", lpDDSurfaceDesc->dwMipMapCount));
+    dprintf(("DDRAW: dwAlphaBitDepth %d\n", lpDDSurfaceDesc->dwAlphaBitDepth));
+    dprintf(("DDRAW: ddsCaps.dwCaps %X\n", lpDDSurfaceDesc->ddsCaps.dwCaps));
+  #endif
+
+  newsurf = new OS2IDirectDrawSurface(me, (LPDDSURFACEDESC2)lpDDSurfaceDesc);
+  if(newsurf == NULL)
+  {
+    rc = DDERR_OUTOFMEMORY;
+  }
+  else
+  {
+    newsurf->Vtbl.AddRef((IDirectDrawSurface *)newsurf);
+    rc = newsurf->GetLastError();
+    if(rc != DD_OK)
+    {
+      dprintf(("DDRAW: Error createing Surface\n\n"));
+      *lplpDD = NULL;
+      delete newsurf;
+    }
+    else
+      *lplpDD = (IDirectDrawSurface *)newsurf;
+
+    dprintf(("DDRAW: New Surface created at %08X\n\n", newsurf));
+  }
+
+  return(rc);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawCreateSurface4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
+            LPDIRECTDRAWSURFACE4 FAR *lplpDD,
+            IUnknown FAR *pUnkOuter)
+{
+ OS2IDirectDraw         *me = (OS2IDirectDraw *)This;
+ OS2IDirectDrawSurface *newsurf;
+ HRESULT                rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: CreateSurface4\n"));
+    dprintf(("DDRAW: dwSize %d\n", lpDDSurfaceDesc2->dwSize));
+    dprintf(("DDRAW: dwHeight %d\n", lpDDSurfaceDesc2->dwHeight));
+    dprintf(("DDRAW: dwWidth %d\n", lpDDSurfaceDesc2->dwWidth));
+    dprintf(("DDRAW: lPitch %d\n", lpDDSurfaceDesc2->lPitch));
+    dprintf(("DDRAW: dwBackBufferCount %d\n", lpDDSurfaceDesc2->dwBackBufferCount));
+    dprintf(("DDRAW: dwMipMapCount %d\n", lpDDSurfaceDesc2->dwMipMapCount));
+    dprintf(("DDRAW: dwAlphaBitDepth %d\n", lpDDSurfaceDesc2->dwAlphaBitDepth));
+    dprintf(("DDRAW: ddsCaps.dwCaps %X\n", lpDDSurfaceDesc2->ddsCaps.dwCaps));
+  #endif
+
+  newsurf = new OS2IDirectDrawSurface(me, lpDDSurfaceDesc2);
+
+  if(newsurf == NULL)
+  {
+    rc = DDERR_OUTOFMEMORY;
+  }
+  else
+  {
+    newsurf->Vtbl.AddRef((IDirectDrawSurface *)newsurf);
+    rc = newsurf->GetLastError();
+    if(rc != DD_OK)
+    {
+      dprintf(("DDRAW: Error createing Surface\n\n"));
+      *lplpDD = NULL;
+
+      delete newsurf;
+    }
+    else
+      *lplpDD = (IDirectDrawSurface4 *)newsurf;
+
+    dprintf(("DDRAW: New Surface created at %08X\n\n", newsurf));
+  }
+
+  return(rc);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * )
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: DuplicateSurface NIY\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4 FAR * )
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: DuplicateSurface4 NIY\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawEnumDisplayModes( THIS This,
+                                        DWORD dwFlags,
+                                        LPDDSURFACEDESC lpDDSurfaceDesc,
+                                        LPVOID lpContext,
+                                        LPDDENUMMODESCALLBACK lpDDEnumModesCallback)
+{
+  int iMode = 0;
+  DDSURFACEDESC DDSurfAct;
+  BOOL fCallAgain;
+  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: EnumDisplayModes\n"));
+  #endif
+
+  // Check for Pointer to callback function
+  if (NULL == lpDDEnumModesCallback)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: EnumDisplayModes : Error NO EnumFunction passed in\n"));
+    #endif
+
+    return(DDERR_GENERIC);
+  }
+
+
+  // Setting up the surface
+  // During enum we report resolution and bitdepth, maybe we should
+  // also report back : Caps and Pitch
+  memset(&DDSurfAct,0,sizeof(DDSURFACEDESC));
+  DDSurfAct.dwSize = sizeof(DDSURFACEDESC);
+  DDSurfAct.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT ;
+  // Only report the bitdepth hope this is ok this way, we must set the BitMask fields
+
+  DDSurfAct.ddpfPixelFormat.dwSize  = sizeof (DDPIXELFORMAT);
+  DDSurfAct.ddpfPixelFormat.dwFlags = DDPF_RGB;
+  // Check if we use DIVE or Voodoo
+  if(me->lpVtbl != (IDirectDraw4Vtbl *) &(me->Vtbl3D))
+  {
+    // DIVE modes
+
+    #ifdef DEBUG
+      dprintf(("DDRAW: EnumDisplayModes : DIVE modes\n"));
+    #endif
+
+    // Enumerate all modes ?
+    if (NULL==lpDDSurfaceDesc)
+    {
+      // Check if we shall report 320x200 mode
+
+      #ifdef DEBUG
+        dprintf(("DDRAW: EnumDisplayModes : ALL modes\n"));
+      #endif
+
+      if(dwFlags && DDEDM_STANDARDVGAMODES)
+      {
+        #ifdef DEBUG
+          dprintf(("DDRAW: EnumDisplayModes : STANDARDVGAMODES\n"));
+        #endif
+        DDSurfAct.dwHeight = ModesDive[0].iYRes;
+        DDSurfAct.dwWidth  = ModesDive[0].iXRes;
+        DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[0].iBits;
+        DDSurfAct.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8 ;
+        if(!lpDDEnumModesCallback(&DDSurfAct,lpContext))
+        {
+          #ifdef DEBUG
+            dprintf(("DDRAW: EnumDisplayModes : Enum done\n"));
+          #endif
+          return (DD_OK);
+        }
+      }
+      // Don't know the flag for Mode X so we skip reporting it
+
+      // Now report all our modes
+      iMode = 2;
+      fCallAgain = TRUE;
+      do
+      {
+        // if the mode fits in the current resolution report it
+        // Change this if we support Fullscreen later !!!
+
+        if(ModesDive[iMode].iXRes < me->dCaps.ulHorizontalResolution)
+        {
+          DDSurfAct.dwHeight = ModesDive[iMode].iYRes;
+          DDSurfAct.dwWidth  = ModesDive[iMode].iXRes;
+          DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[iMode].iBits;
+          switch(ModesDive[iMode].iBits)
+          {
+            case 8:
+              DDSurfAct.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
+              break;
+            case 16:
+              // VESA uses 565 encoding in 16 bit modes
+              DDSurfAct.ddpfPixelFormat.dwFlags &= ~DDPF_PALETTEINDEXED8;
+              DDSurfAct.ddpfPixelFormat.dwRBitMask = 0x0000F800;
+              DDSurfAct.ddpfPixelFormat.dwGBitMask = 0x000007E0;
+              DDSurfAct.ddpfPixelFormat.dwBBitMask = 0x0000001F;
+              break;
+            case 24:
+              // VESA uses per default RGB4
+              DDSurfAct.ddpfPixelFormat.dwFlags &= ~DDPF_PALETTEINDEXED8;
+              DDSurfAct.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+              DDSurfAct.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+              DDSurfAct.ddpfPixelFormat.dwBBitMask = 0x000000FF;
+              break;
+            default:
+              break;
+          }
+          #ifdef DEBUG
+            dprintf( ("EnumDisplayModes : Enum Mode %dx%d @ %d\n",
+                      DDSurfAct.dwHeight,
+                      DDSurfAct.dwWidth,
+                      DDSurfAct.ddpfPixelFormat.dwRGBBitCount));
+          #endif
+          fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
+          #ifdef DEBUG
+            dprintf( ("EnumDisplayModes : Callback returned with %d\n",
+                      fCallAgain));
+          #endif
+        }
+        iMode++;
+      }
+      while( (iMode < NUM_MODES_DIVE) &&
+             (ModesDive[iMode].iBits <= me->dCaps.ulDepth) &&
+             (TRUE==fCallAgain) );
+    }
+    else
+    {
+      // No, so filter modes with lpDDSurfaceDesc
+
+      // Return Error if the program want to use other than the 3 supported values
+      // for filtering
+
+      if (lpDDSurfaceDesc->dwFlags & !(DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT))
+        return(DDERR_INVALIDPARAMS);
+
+      iMode = 0;
+      if( (dwFlags && DDEDM_STANDARDVGAMODES) &&
+         (
+          (((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)&&
+            (ModesDive[iMode].iXRes==lpDDSurfaceDesc->dwWidth)
+           )||(!(lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)))&&
+          (((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)&&
+            (ModesDive[iMode].iYRes==lpDDSurfaceDesc->dwHeight))||
+           (!(lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)))&&
+          (((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) &&
+            (ModesDive[iMode].iBits==lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount))||
+           (!(lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)))
+         )
+        )
+      {
+        DDSurfAct.dwHeight = ModesDive[0].iYRes;
+        DDSurfAct.dwWidth  = ModesDive[0].iXRes;
+        DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[0].iBits;
+        DDSurfAct.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
+        if(!lpDDEnumModesCallback(&DDSurfAct,lpContext))
+        {
+          return (DD_OK);
+        }
+      }
+      // Don't know the flag for Mode X so we skip reporting it
+
+      // Now report all our modes
+      iMode = 2;
+      fCallAgain = TRUE;
+      do
+      {
+        // if the mode fits in the current resolution and the filter applies report it
+        // Change this if we support Fullscreen later !!!
+        if( (ModesDive[iMode].iXRes < me->dCaps.ulHorizontalResolution)&&
+           (
+            (((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)&&
+              (ModesDive[iMode].iXRes==lpDDSurfaceDesc->dwWidth))||
+             (!(lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)))&&
+            (((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)&&
+              (ModesDive[iMode].iYRes==lpDDSurfaceDesc->dwHeight))||
+             (!(lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)))&&
+            (((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) &&
+              (ModesDive[iMode].iBits==lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount))||
+             (!(lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)))
+           )
+          )
+        {
+          DDSurfAct.dwHeight = ModesDive[iMode].iYRes;
+          DDSurfAct.dwWidth  = ModesDive[iMode].iXRes;
+          DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[iMode].iBits;
+          switch(ModesDive[iMode].iBits)
+          {
+            case 8:
+              DDSurfAct.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
+              break;
+            case 16:
+              // VESA uses 565 encoding in 16 bit modes
+              DDSurfAct.ddpfPixelFormat.dwFlags &= ~DDPF_PALETTEINDEXED8;
+              DDSurfAct.ddpfPixelFormat.dwRBitMask = 0x0000F800;
+              DDSurfAct.ddpfPixelFormat.dwGBitMask = 0x000007E0;
+              DDSurfAct.ddpfPixelFormat.dwBBitMask = 0x0000001F;
+              break;
+            case 24:
+              // VESA uses per default RGB4
+              DDSurfAct.ddpfPixelFormat.dwFlags &= ~DDPF_PALETTEINDEXED8;
+              DDSurfAct.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+              DDSurfAct.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+              DDSurfAct.ddpfPixelFormat.dwBBitMask = 0x000000FF;
+              break;
+            default:
+              break;
+          }
+
+          fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
+        }
+        iMode++;
+      }
+      while((ModesDive[iMode].iBits <= me->dCaps.ulDepth) &&
+            (iMode < NUM_MODES_DIVE) && (TRUE==fCallAgain));
+
+    }
+  }
+  else
+  {
+
+    // VOODOO modes
+
+    // Enumerate all modes ?
+    if (NULL==lpDDSurfaceDesc)
+    {
+
+      // report all our modes
+      iMode = 0;
+      fCallAgain = TRUE;
+      do
+      {
+        DDSurfAct.dwHeight = ModesVoodoo[iMode].iYRes;
+        DDSurfAct.dwWidth  = ModesVoodoo[iMode].iXRes;
+        DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesVoodoo[iMode].iBits;
+
+        fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
+        iMode++;
+      }
+      while((iMode < NUM_MODES_VOODOO) && (TRUE==fCallAgain));
+    }
+    else
+    {
+      // No, so filter modes with lpDDSurfaceDesc
+
+      // Return Error if the program want to use other than the 3 supported values
+      // for filtering
+
+      if (lpDDSurfaceDesc->dwFlags & !(DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT))
+      {
+        return(DDERR_INVALIDPARAMS);
+      }
+
+      iMode = 2;
+      fCallAgain = TRUE;
+      // All reported mode are 16bit
+      DDSurfAct.ddpfPixelFormat.dwRBitMask = 0x0000F800;
+      DDSurfAct.ddpfPixelFormat.dwGBitMask = 0x000007E0;
+      DDSurfAct.ddpfPixelFormat.dwBBitMask = 0x0000001F;
+      do
+      {
+        // if the mode fits the filter applies report it
+        if(
+            (((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)&&
+              (ModesVoodoo[iMode].iXRes==lpDDSurfaceDesc->dwWidth))||
+             (!(lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)))&&
+            (((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)&&
+              (ModesVoodoo[iMode].iYRes==lpDDSurfaceDesc->dwHeight))||
+             (!(lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)))&&
+            (((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) &&
+              (ModesVoodoo[iMode].iBits==lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount))||
+             (!(lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)))
+          )
+        {
+          DDSurfAct.dwHeight = ModesVoodoo[iMode].iYRes;
+          DDSurfAct.dwWidth  = ModesVoodoo[iMode].iXRes;
+          DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesVoodoo[iMode].iBits;
+
+          fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
+        }
+        iMode++;
+      }
+      while((iMode < NUM_MODES_VOODOO) && (TRUE==fCallAgain));
+
+    }
+
+  }
+
+
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawEnumDisplayModes4(THIS This, DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
+                                       LPVOID lpContext, LPDDENUMMODESCALLBACK2 lpDDEnumModesCallback2)
+{
+  int iMode = 0;
+  DDSURFACEDESC DDSurfAct;
+  BOOL fCallAgain;
+  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: EnumDisplayModes4 NIY\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK )
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: EnumSurfaces NIY\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 )
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: EnumSurfaces4 NIY\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawFlipToGDISurface(THIS)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: FlipToGDISurface NIY\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetCaps(THIS, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps)
+{
+  DWORD dwSize;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: DDGetCaps of "));
+  #endif
+
+  if( (NULL==lpDDDriverCaps) && (NULL==lpDDHELCaps) )
+    return(DDERR_INVALIDPARAMS);
+
+  if(NULL!=lpDDDriverCaps)
+  {
+    // Caller want Driver Caps
+
+    dprintf(("DDRAW: Driver\n"));
+
+    if( (sizeof(DDCAPS)!=lpDDDriverCaps->dwSize)     &&
+        (sizeof(DDCAPS_DX5)!=lpDDDriverCaps->dwSize) &&
+        (sizeof(DDCAPS_DX3)!=lpDDDriverCaps->dwSize) )
+    {
+      dprintf( ("Size %d Not supported ",
+                lpDDDriverCaps->dwSize));
+      return(DDERR_INVALIDPARAMS);
+    }
+    // Clear structure so we only have to set the supported flags
+
+    dwSize = lpDDDriverCaps->dwSize;
+    memset( lpDDDriverCaps,
+            0,
+            lpDDDriverCaps->dwSize);
+
+
+    // Reset the size
+    lpDDDriverCaps->dwSize = dwSize;
+
+    // Now report the CAPs back which we support
+    lpDDDriverCaps->dwCaps = DDCAPS_BLT |              // We do blitting
+                             DDCAPS_BLTCOLORFILL |     // We do colorfills
+                             DDCAPS_COLORKEY |         // We support Colorkeying
+                             DDCAPS_COLORKEYHWASSIST | // But we (may) use the CPU
+                             DDCAPS_GDI |              // Maybe check if we are on Voodoo ?
+                             DDCAPS_PALETTEVSYNC;      // Got VSync
+
+    lpDDDriverCaps->dwCaps2 = DDCAPS2_CERTIFIED |         // Who cares so say yes
+                              //DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
+                              DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
+                              DDCAPS2_NONLOCALVIDMEM |    // All surfaces are in memory
+                              DDCAPS2_WIDESURFACES;       // Any size you want!
+
+    lpDDDriverCaps->dwCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+
+//    lpDDDriverCaps->dwFXCaps = DDFXCAPS_BLTMIRRORUPDOWN; // DIVE supports this, do we also ?
+                                                         // Maybe later add stretching support?
+
+    lpDDDriverCaps->dwPalCaps = DDPCAPS_8BIT |          // Only 8 Bits pals
+                                DDPCAPS_ALLOW256 |      // But all 256 colors
+                                DDPCAPS_VSYNC  |        // Vsync yet
+                                DDPCAPS_PRIMARYSURFACE; //
+    lpDDDriverCaps->dwVidMemTotal = 4096*1024;          // total video memory
+    lpDDDriverCaps->dwVidMemFree  = 4096*1024;          // total free video memory
+    lpDDDriverCaps->dwNumFourCCCodes;        // number of supported FOURCC codes
+/*
+    ToDo: must finde out ow the array is used for this
+    lpDDDriverCaps->dwRops[DD_ROP_SPACE] = SRCCOPY |
+                                           BLACKNESS |
+                                           WHITENESS;  // Raster OPs implemented
+*/
+    lpDDDriverCaps->dwSVBCaps = DDCAPS_BLT |              // We do blitting
+                                DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                DDCAPS_COLORKEY |         // We support Colorkeying
+                                DDCAPS_COLORKEYHWASSIST;
+    lpDDDriverCaps->dwSVBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+    lpDDDriverCaps->dwSVBFXCaps = DDCAPS_BLT |              // We do blitting
+                                  DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                  DDCAPS_COLORKEY |         // We support Colorkeying
+                                  DDCAPS_COLORKEYHWASSIST;
+/*
+    ToDo: must finde out ow the array is used for this
+    lpDDDriverCaps->dwSVBRops[DD_ROP_SPACE] = SRCCOPY |
+                                              BLACKNESS |
+                                              WHITENESS;  // Raster OPs implemented
+*/
+    lpDDDriverCaps->dwVSBCaps = DDCAPS_BLT |              // We do blitting
+                                DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                DDCAPS_COLORKEY |         // We support Colorkeying
+                                DDCAPS_COLORKEYHWASSIST;
+    lpDDDriverCaps->dwVSBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+    lpDDDriverCaps->dwVSBFXCaps = DDCAPS_BLT |              // We do blitting
+                                  DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                  DDCAPS_COLORKEY |         // We support Colorkeying
+                                  DDCAPS_COLORKEYHWASSIST;
+/*
+    ToDo: must finde out ow the array is used for this
+    lpDDDriverCaps->dwVSBRops[DD_ROP_SPACE] = SRCCOPY |
+                                              BLACKNESS |
+                                              WHITENESS;  // Raster OPs implemented
+*/
+    lpDDDriverCaps->dwSSBCaps = DDCAPS_BLT |              // We do blitting
+                                DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                DDCAPS_COLORKEY |         // We support Colorkeying
+                                DDCAPS_COLORKEYHWASSIST;
+    lpDDDriverCaps->dwSSBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+    lpDDDriverCaps->dwSSBFXCaps = DDCAPS_BLT |              // We do blitting
+                                  DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                  DDCAPS_COLORKEY |         // We support Colorkeying
+                                  DDCAPS_COLORKEYHWASSIST;
+/*
+    ToDo: must finde out ow the array is used for this
+    lpDDDriverCaps->dwSSBRops[SRCCOPY]   = 1;
+    lpDDDriverCaps->dwSSBRops[BLACKNESS] = 1;
+    lpDDDriverCaps->dwSSBRops[WHITENESS] = 1;  // Raster OPs implemented
+*/
+    // These are ony in >DX5
+    if(dwSize>sizeof(DDCAPS_DX3))
+    {
+      lpDDDriverCaps->dwSVBCaps2 = //DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
+                                   DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
+                                   DDCAPS2_WIDESURFACES;       // Any size you want!
+      lpDDDriverCaps->dwNLVBCaps = DDCAPS_BLT |              // We do blitting
+                                   DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                   DDCAPS_COLORKEY |         // We support Colorkeying
+                                   DDCAPS_COLORKEYHWASSIST;
+      lpDDDriverCaps->dwNLVBCaps2 = //DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
+                                    DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
+                                    DDCAPS2_WIDESURFACES;       // Any size you want!
+      lpDDDriverCaps->dwNLVBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+      lpDDDriverCaps->dwNLVBFXCaps = DDCAPS_BLT |              // We do blitting
+                                     DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                     DDCAPS_COLORKEY |         // We support Colorkeying
+                                     DDCAPS_COLORKEYHWASSIST;
+      lpDDDriverCaps->dwNLVBRops[DD_ROP_SPACE];//  ToDo: Again the array ...
+
+      // General Surface caps only in DX6
+      if(dwSize>sizeof(DDCAPS_DX5))
+      {
+        lpDDDriverCaps->ddsCaps.dwCaps = DDSCAPS_ALPHA | DDSCAPS_BACKBUFFER |
+                                         DDSCAPS_COMPLEX | DDSCAPS_FLIP |
+                                         DDSCAPS_FRONTBUFFER | DDSCAPS_LOCALVIDMEM |
+                                         DDSCAPS_NONLOCALVIDMEM | DDSCAPS_OFFSCREENPLAIN |
+                                         // DDSCAPS_OVERLAY |
+                                         DDSCAPS_PALETTE | DDSCAPS_PRIMARYSURFACE |
+                                         DDSCAPS_SYSTEMMEMORY |DDSCAPS_VIDEOMEMORY |
+                                         DDSCAPS_VISIBLE;
+
+      #ifdef USE_OPENGL
+        lpDDDriverCaps->dwCaps |= DDCAPS_3D | DDCAPS_ZBLTS;
+        // ToDO find and put the value for DDCAPS2_NO2DDURING3DSCENE in ddraw.h
+        // lpDDDriverCaps->dwCaps2 |=  DDCAPS2_NO2DDURING3DSCENE;
+        lpDDDriverCaps->ddsCaps.dwCaps |= DDSCAPS_3DDEVICE | DDSCAPS_MIPMAP |
+                                          DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;
+      #endif
+      }
+    }
+
+
+  }
+
+  if(NULL!=lpDDHELCaps)
+  {
+    // Caller wants HEL Caps
+    dprintf(("DDRAW:  HEL\n"));
+
+    if(sizeof(DDCAPS)!=lpDDHELCaps->dwSize)
+    {
+      dprintf(("DDRAW: Size Not Set\n"));
+      return(DDERR_INVALIDPARAMS);
+    }
+    // Clear structure so we only have to set the supported flags
+
+
+    memset(lpDDHELCaps,0,sizeof(DDCAPS));
+
+
+    // Reset the size
+    lpDDHELCaps->dwSize = sizeof(DDCAPS);
+
+    // Now report the CAPs back which we support
+    lpDDHELCaps->dwCaps = DDCAPS_BLT |              // We do blitting
+                             DDCAPS_BLTCOLORFILL |     // We do colorfills
+                             DDCAPS_COLORKEY |         // We support Colorkeying
+                             DDCAPS_COLORKEYHWASSIST | // But we (may) use the CPU
+                             DDCAPS_GDI |              // Maybe check if we are on Voodoo ?
+                             DDCAPS_PALETTEVSYNC;      // Got VSync
+
+    lpDDHELCaps->dwCaps2 = DDCAPS2_CERTIFIED |         // Who cares so say yes
+                              DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
+                              DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
+                              DDCAPS2_NONLOCALVIDMEM |    // All surfaces are in memory
+                              DDCAPS2_WIDESURFACES;       // Any size you want!
+
+    lpDDHELCaps->dwCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+
+//    lpDDDriverCaps->dwFXCaps = DDFXCAPS_BLTMIRRORUPDOWN; // DIVE supports this, do we also ?
+                                                         // Maybe later add stretching support?
+
+    lpDDHELCaps->dwPalCaps = DDPCAPS_8BIT |          // Only 8 Bits pals
+                                DDPCAPS_ALLOW256 |      // But all 256 colors
+                                DDPCAPS_VSYNC  |        // Vsync yet
+                                DDPCAPS_PRIMARYSURFACE; //
+    lpDDHELCaps->dwVidMemTotal = 2048*1024;           // total video memory
+    lpDDHELCaps->dwVidMemFree  = 2048*1024;            // total free video memory
+    lpDDHELCaps->dwNumFourCCCodes;        // number of supported FOURCC codes
+    lpDDHELCaps->dwRops[DD_ROP_SPACE];    // supported raster ops
+    lpDDHELCaps->dwSVBCaps = DDCAPS_BLT |              // We do blitting
+                                DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                DDCAPS_COLORKEY |         // We support Colorkeying
+                                DDCAPS_COLORKEYHWASSIST;
+    lpDDHELCaps->dwSVBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+    lpDDHELCaps->dwSVBFXCaps;             //  .
+    lpDDHELCaps->dwSVBRops[DD_ROP_SPACE]; //  .
+    lpDDHELCaps->dwVSBCaps = DDCAPS_BLT |              // We do blitting
+                                DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                DDCAPS_COLORKEY |         // We support Colorkeying
+                                DDCAPS_COLORKEYHWASSIST;
+    lpDDHELCaps->dwVSBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+    lpDDHELCaps->dwVSBFXCaps;             //  .
+    lpDDHELCaps->dwVSBRops[DD_ROP_SPACE]; //  .
+    lpDDHELCaps->dwSSBCaps = DDCAPS_BLT |              // We do blitting
+                                DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                DDCAPS_COLORKEY |         // We support Colorkeying
+                                DDCAPS_COLORKEYHWASSIST;
+    lpDDHELCaps->dwSSBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+    lpDDHELCaps->dwSSBFXCaps;            //  .
+    lpDDHELCaps->dwSSBRops[DD_ROP_SPACE]; //  .
+    lpDDHELCaps->dwSVBCaps2 = DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
+                                 DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
+                                 DDCAPS2_WIDESURFACES;       // Any size you want!
+    lpDDHELCaps->dwNLVBCaps = DDCAPS_BLT |              // We do blitting
+                                 DDCAPS_BLTCOLORFILL |     // We do colorfills
+                                 DDCAPS_COLORKEY |         // We support Colorkeying
+                                 DDCAPS_COLORKEYHWASSIST;
+    lpDDHELCaps->dwNLVBCaps2 = DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
+                                  DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
+                                  DDCAPS2_WIDESURFACES;       // Any size you want!
+    lpDDHELCaps->dwNLVBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
+    lpDDHELCaps->dwNLVBFXCaps;            //  .
+    lpDDHELCaps->dwNLVBRops[DD_ROP_SPACE];//  .
+
+  }
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetDisplayMode(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc)
+{
+  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetDisplayMode\n"));
+  #endif
+
+  // Check Parameter
+  if(NULL==lpDDSurfaceDesc)
+    return(DDERR_INVALIDPARAMS);
+
+  if(sizeof(DDSURFACEDESC)!=lpDDSurfaceDesc->dwSize)
+    return(DDERR_INVALIDPARAMS);
+
+  // We report back the DIVE caps. maybe we should set up a local DDSURFACEDESC
+  // for the object so we can change the values when we switch modes (or say so)
+  // as a program may use this function to check the values after a mode change
+  // An other reason to to so is Voodoo supports maybe more functions
+
+  // Tell what we report
+  lpDDSurfaceDesc->dwFlags  = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+  lpDDSurfaceDesc->dwHeight = me->dCaps.ulHorizontalResolution;
+  lpDDSurfaceDesc->dwWidth  = me->dCaps.ulVerticalResolution;
+  // Set the PixelFormat
+  lpDDSurfaceDesc->ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+
+  lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC = me->dCaps.fccColorEncoding;
+  lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = me->dCaps.ulDepth;
+  lpDDSurfaceDesc->ddpfPixelFormat.dwRGBAlphaBitMask = 0; // No Alpha support
+  switch(me->dCaps.ulDepth)
+  {
+    case 4:
+      // Assume that no one will run OS/2 PM with less then 16 colors and try
+      // to start a DirectX program ;)
+      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags =  DDPF_RGB | DDPF_PALETTEINDEXED4;
+      lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0;
+      lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0;
+      lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0;
+      break;
+    case 8:
+      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8 |
+                                                 DDPF_FOURCC;
+      lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0;
+      lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0;
+      lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0;
+      break;
+    case 15:
+    case 16:
+      lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = 16; // No sure about 15Bit modes
+      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
+      if (FOURCC_R555 == me->dCaps.fccColorEncoding)
+      {
+        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00007C00;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000003E0;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F;
+      }
+      else
+      {
+        if(FOURCC_R565 == me->dCaps.fccColorEncoding)
+        {
+          lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800;
+          lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000007E0;
+          lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F;
+        }
+        else
+        {
+          // R664
+          lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800;
+          lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000003F0;
+          lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000000F;
+        }
+      }
+      break;
+    case 24:
+      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
+      if(FOURCC_RGB3 == me->dCaps.fccColorEncoding)
+      {
+        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF;
+      }
+      else
+      {
+        // BGR3
+        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x000000FF;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
+      }
+      break;
+    case 32:
+      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
+      if(FOURCC_RGB4 == me->dCaps.fccColorEncoding)
+      {
+        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF;
+      }
+      else
+      {
+        // BGR4
+        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x000000FF;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
+      }
+      break;
+    default:
+      #ifdef DEBUG
+        dprintf(("DDRAW: Unsupported mode\n"));
+      #endif
+      return(DDERR_UNSUPPORTEDMODE);
+  }
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetDisplayMode4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2)
+{
+  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetDisplayMode\n"));
+  #endif
+
+  // Check Parameter
+  if(NULL==lpDDSurfaceDesc2)
+    return(DDERR_INVALIDPARAMS);
+
+  if(sizeof(DDSURFACEDESC)!=lpDDSurfaceDesc2->dwSize)
+    return(DDERR_INVALIDPARAMS);
+
+  // We report back the DIVE caps. maybe we should set up a local DDSURFACEDESC
+  // for the object so we can change the values when we switch modes (or say so)
+  // as a program may use this function to check the values after a mode change
+  // An other reason to to so is Voodoo supports maybe more functions
+
+  // Tell what we report
+  lpDDSurfaceDesc2->dwFlags  = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+  lpDDSurfaceDesc2->dwHeight = me->dCaps.ulHorizontalResolution;
+  lpDDSurfaceDesc2->dwWidth  = me->dCaps.ulVerticalResolution;
+  // Set the PixelFormat
+  lpDDSurfaceDesc2->ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+
+  lpDDSurfaceDesc2->ddpfPixelFormat.dwFourCC = me->dCaps.fccColorEncoding;
+  lpDDSurfaceDesc2->ddpfPixelFormat.dwRGBBitCount = me->dCaps.ulDepth;
+  lpDDSurfaceDesc2->ddpfPixelFormat.dwRGBAlphaBitMask = 0; // No Alpha support
+  switch(me->dCaps.ulDepth)
+  {
+    case 4:
+      // Assume that no one will run OS/2 PM with less then 16 colors and try
+      // to start a DirectX program ;)
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags =  DDPF_RGB | DDPF_PALETTEINDEXED4;
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0;
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0;
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0;
+      break;
+    case 8:
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8 |
+                                                 DDPF_FOURCC;
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0;
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0;
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0;
+      break;
+    case 15:
+    case 16:
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwRGBBitCount = 16; // No sure about 15Bit modes
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
+      if (FOURCC_R555 == me->dCaps.ulDepth)
+      {
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x00007C00;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x000003E0;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x0000001F;
+      }
+      else
+      {
+        if(FOURCC_R565 == me->dCaps.fccColorEncoding)
+        {
+          lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x0000F800;
+          lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x000007E0;
+          lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x0000001F;
+        }
+        else
+        {
+          // R664
+          lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x0000F800;
+          lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x000003F0;
+          lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x0000000F;
+        }
+      }
+      break;
+    case 24:
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
+      if(FOURCC_RGB3 == me->dCaps.fccColorEncoding)
+      {
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x000000FF;
+      }
+      else
+      {
+        // BGR3
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x000000FF;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
+      }
+      break;
+    case 32:
+      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
+      if(FOURCC_RGB4 == me->dCaps.fccColorEncoding)
+      {
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x000000FF;
+      }
+      else
+      {
+        // BGR4
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x000000FF;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
+      }
+      break;
+    default:
+      #ifdef DEBUG
+        dprintf(("DDRAW: Unsupported mode\n"));
+      #endif
+      return(DDERR_UNSUPPORTEDMODE);
+  }
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetFourCCCodes(THIS, LPDWORD lpNumCodes, LPDWORD lpCodes)
+{
+  DWORD dwFCC[3] = {FOURCC_LUT8,FOURCC_R565,FOURCC_RGB3};
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetFourCCCodes\n"));
+  #endif
+
+  if(NULL==lpNumCodes)
+    return(DDERR_INVALIDPARAMS);
+
+  if(NULL==lpCodes)
+  {
+    *lpNumCodes = 3; // LUT8, R565, RGB3 are the FourCC we support for now
+  }
+  else
+  {
+    for(int i=0;(i<3)&&(i<*lpNumCodes);i++)
+    {
+      *lpCodes = dwFCC[i];
+      lpCodes +=4;
+    }
+    if(*lpNumCodes < 3)
+      *lpNumCodes = 3;
+  }
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE FAR *)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetGDISurface NYI\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4 FAR *)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetGDISurface NYI\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetMonitorFrequency(THIS This, LPDWORD lpdwFreq)
+{
+  ULONG ulTime1, ulTime2;
+  DWORD dwFlags = DDWAITVB_BLOCKBEGIN;
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetMonitorFrequency\n"));
+  #endif
+  if(NULL==lpdwFreq)
+    return(DDERR_INVALIDPARAMS);
+
+
+
+  if(DD_OK==DrawWaitForVerticalBlank(This, dwFlags, 0))
+  {
+    ulTime1 = GetTickCount();
+    // Timer has an accuracy of 4 ms so call it al least 4 times
+    DrawWaitForVerticalBlank(This, dwFlags, 0);
+    DrawWaitForVerticalBlank(This, dwFlags, 0);
+    DrawWaitForVerticalBlank(This, dwFlags, 0);
+    DrawWaitForVerticalBlank(This, dwFlags, 0);
+    ulTime2 = GetTickCount();
+    ulTime2 -= ulTime1;
+    if(ulTime2) // paranoid check to avoid DIV0
+      *lpdwFreq = 4000 / ulTime2;
+    else
+      *lpdwFreq = 70;
+  }
+  else
+  {
+    // Assume 70 Hz maybe better return DDERR_UNSUPPORTED if this function isn't mandatory
+    *lpdwFreq = 70;
+  }
+
+
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetScanLine(THIS, LPDWORD lpdwLine)
+{
+  BOOL bVertBlank;
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetScanLine\n"));
+  #endif
+  // ToDO find a way to get this position, so for now simply return DDERR_UNSUPPORTED
+  // as we indicated in DDCAPS we don't support this.
+
+  return(DDERR_UNSUPPORTED);
+
+  //the following code could be used if we implement this
+  /*
+  if(NULL==lpdwLine)
+    return(DDERR_INVALIDPARAMS);
+  DrawGetVertcalBlackStatus(This,&bVertBlank);
+  if(bVertBlank)
+    return (DDERR_VERTICALBLANKINPROGRESS);
+  *lpdwLine = GetLine(); // GetLine would be the function which gets us the line
+  return(DD_OK);
+  */
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetVerticalBlankStatus(THIS , LPBOOL lpbIsInVB)
+{
+  int rc;
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetVerticalBlankStatus\n"));
+  #endif
+  if(NULL==lpbIsInVB)
+    return(DDERR_INVALIDPARAMS);
+
+
+    rc = io_init1();
+
+
+  if(0==rc)  // try to get IOPL for the thread
+  {
+    *lpbIsInVB = (c_inb1(0x3da)&0x08)!=0;
+
+      io_exit1(); // reset IOPL
+
+    return(DD_OK);
+  }
+
+  return(DDERR_UNSUPPORTED);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawInitialize(THIS, GUID FAR *)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: Initialize\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawRestoreDisplayMode(THIS This)
+{
+  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+  ULONG ulModeInd;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: RestoreDisplayMode\n"));
+  #endif
+       /* restore previous screen mode */
+  if ((me->bPMILoaded) && (me->bInFullScreen))
+  {
+    SetSVGAMode(me->oldwidth, me->oldheight, me->oldbpp, 0xFF, &ulModeInd, NULL);
+    RestorePM();
+    /* restore DIVE caps entries */
+    me->dCaps.ulScanLineBytes        = me->oldscanlines;
+    me->dCaps.ulHorizontalResolution = me->oldwidth;
+    me->dCaps.ulVerticalResolution   = me->oldheight;
+    me->dCaps.ulDepth                = me->oldbpp;
+  }
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawSetCooperativeLevel(THIS This, HWND hwndClient, DWORD dwFlags)
+{
+ OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SetCooperativeLevel: hwnd %X, Flags %X\n", hwndClient, dwFlags));
+  #endif
+  me->dwCoopMode = dwFlags;
+  if(!(DDSCL_NORMAL & dwFlags))
+  {
+    // client window req. for all none DDSCL_NORMAL modes
+    if(NULL==hwndClient)
+      return(DDERR_INVALIDPARAMS);
+  }
+  me->hwndClient = hwndClient;
+  #if 0
+    OS2DDSubclassWindow(hwndClient);
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//Backwards compatibility, what's that??
+//******************************************************************************
+HRESULT __stdcall DrawSetDisplayMode2(THIS This, DWORD dwWidth, DWORD dwHeight,
+              DWORD dwBPP, DWORD dwRefreshRate,
+              DWORD dwFlags)
+{
+ ULONG rc;
+ OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+ SETUP_BLITTER sBlt;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SetDisplayMode2 to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP));
+  #endif
+
+  me->screenwidth  = dwWidth;
+  me->screenheight = dwHeight;
+  me->screenbpp    = dwBPP;
+
+  if(me->dwCoopMode & DDSCL_FULLSCREEN)
+  {
+    SetWindowPos(me->hwndClient, HWND_TOP, 0, 0, dwWidth, dwHeight, 0);
+  }
+
+  memset(&sBlt,0,sizeof(sBlt));
+  sBlt.ulStructLen = sizeof(sBlt);
+  sBlt.fccSrcColorFormat = FOURCC_SCRN;
+  sBlt.ulSrcWidth        = dwWidth;
+  sBlt.ulSrcHeight       = dwHeight;
+  sBlt.ulSrcPosX         = 0;
+  sBlt.ulSrcPosY         = 0;
+  sBlt.fccDstColorFormat = FOURCC_SCRN;
+  sBlt.ulDstWidth        = dwWidth;
+  sBlt.ulDstHeight       = dwHeight;
+  sBlt.lDstPosX          = 0;
+  sBlt.lDstPosY          = 0;
+  sBlt.lScreenPosX       = 0;
+  sBlt.lScreenPosY       = me->dCaps.ulVerticalResolution-dwHeight;
+  sBlt.ulNumDstRects     = DIVE_FULLY_VISIBLE;
+
+  rc = DiveSetupBlitter( me->hDive,
+                         &sBlt);
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawSetDisplayMode(THIS This, DWORD dwWidth, DWORD dwHeight,
+             DWORD dwBPP)
+{
+ ULONG rc;
+ ULONG ulModeInd;
+
+ OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
+ SETUP_BLITTER sBlt;
+
+#ifdef DEBUG
+  dprintf(("DDRAW: SetDisplayMode to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP));
+#endif
+  me->screenwidth  = dwWidth;
+  me->screenheight = dwHeight;
+  me->screenbpp    = dwBPP;
+
+  if(me->dwCoopMode & DDSCL_FULLSCREEN)
+  {
+      SetWindowPos(me->hwndClient, HWND_TOP,0,0,dwWidth,dwHeight,0);
+//    SetWindowPos(me->hwndClient, HWND_TOP, 0, 0, 1024, 768, 0);
+
+    if ((me->bPMILoaded) && (ModeInSVGAModeTable(dwWidth,dwHeight,dwBPP)))
+    {
+      KillPM();
+
+      rc=SetSVGAMode(dwWidth, dwHeight, dwBPP, 0xFF, &ulModeInd, NULL);
+
+      if (!rc) // When mode switched successfully
+      {
+        /* save old screen values */
+        me->bInFullScreen=TRUE;
+        me->oldwidth     = me->dCaps.ulHorizontalResolution;
+        me->oldheight    = me->dCaps.ulVerticalResolution;
+        me->oldscanlines = me->dCaps.ulScanLineBytes;
+        me->oldbpp       = me->dCaps.ulDepth;
+
+        /* now 'fix' some DIVE caps entries */
+        me->dCaps.ulScanLineBytes        = dwWidth * (dwBPP >> 3); /* FIX: use real value */
+        me->dCaps.ulHorizontalResolution = dwWidth;
+        me->dCaps.ulVerticalResolution   = dwHeight;
+        me->dCaps.ulDepth                = dwBPP;
+      }
+      else
+      // Display must be return to PM Session
+      RestorePM();
+    }
+  }
+  memset(&sBlt,0,sizeof(sBlt));
+  sBlt.ulStructLen = sizeof(sBlt);
+  sBlt.fccSrcColorFormat = FOURCC_SCRN;
+  sBlt.ulSrcWidth        = dwWidth;
+  sBlt.ulSrcHeight       = dwHeight;
+  sBlt.ulSrcPosX         = 0;
+  sBlt.ulSrcPosY         = 0;
+  sBlt.fccDstColorFormat = FOURCC_SCRN;
+  sBlt.ulDstWidth        = dwWidth;
+  sBlt.ulDstHeight       = dwHeight;
+  sBlt.lDstPosX          = 0;
+  sBlt.lDstPosY          = 0;
+  sBlt.lScreenPosX       = 0;
+  sBlt.lScreenPosY       = me->dCaps.ulVerticalResolution-dwHeight;
+  sBlt.ulNumDstRects     = DIVE_FULLY_VISIBLE;
+
+  rc = DiveSetupBlitter( me->hDive,
+                         &sBlt);
+
+  dprintf(("Mode set successful!\n"));
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawWaitForVerticalBlank(THIS, DWORD dwFlags, HANDLE hEvent)
+{
+  HRESULT rc;
+  int rci;
+  USHORT sel;
+  dprintf(("DDRAW: WaitForVerticalBlank\n"));
+
+  if(DDWAITVB_BLOCKBEGINEVENT == dwFlags) // This parameter isn't support in DX
+    return (DDERR_UNSUPPORTED);
+
+  return DD_OK;
+
+  rci = InitIO();
+
+  if(rci)  // try to get IOPL for the thread
+  {
+    dprintf(("DDRAW: No IOPL\n"));
+    return (DDERR_UNSUPPORTED);  // we failed so return error that we don't support this
+  }
+  // AT this point we should have IOPL so lets use it!
+  dprintf(("DDRAW: IOPL 3!\n"));
+
+  rc = DDERR_INVALIDPARAMS; // set returnvalue to fail
+
+  if(DDWAITVB_BLOCKBEGIN == dwFlags)
+  {
+    dprintf(("DDRAW: BLOCKBEGIN\n"));
+
+    while ((c_inb1(0x3da)&0x08)!=0); // Wait for end of vert. retrace if one is running
+    while ((c_inb1(0x3da)&0x08)==0); // Wait for new start of retrace
+    rc = DD_OK;
+  }
+
+  if(DDWAITVB_BLOCKEND == dwFlags)
+  {
+    dprintf(("DDRAW: BLOCKEND\n"));
+    rc = DD_OK;
+    if((c_inb1(0x3da)&0x08)!=0)        // Are we in a vert. retrace
+    {
+      while ((c_inb1(0x3da)&0x08)!=0); // Wait for end of retrace
+    }
+    else
+    {
+      while ((c_inb1(0x3da)&0x08)==0); // Wait for new start of retrace
+      while ((c_inb1(0x3da)&0x08)!=0); // Wait for end of vert. retrace
+    }
+
+  }
+
+
+  //  io_exit1();
+
+
+  return (rc);
+
+}
+//******************************************************************************
+//*** Added in the v2 interface ***
+//******************************************************************************
+HRESULT __stdcall DrawGetAvailableVidMem(THIS, LPDDSCAPS lpDDSCaps,
+                                         LPDWORD lpdwTotal, LPDWORD lpdwFree)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetAvailableVidMem\n"));
+  #endif
+
+  // Check parameters
+  if(NULL==lpDDSCaps)
+    return(DDERR_INVALIDPARAMS);
+
+  if((NULL==lpdwTotal)&&(NULL==lpdwFree))
+    return(DDERR_INVALIDPARAMS);
+
+  if(NULL!=lpdwTotal)
+    *lpdwTotal = 2048 *1024;
+
+  if(NULL!=lpdwFree)
+    *lpdwFree = 2048 *1024;
+
+  return(DD_OK);
+}
+//******************************************************************************
+//
+//******************************************************************************
+HRESULT __stdcall DrawGetAvailableVidMem4(THIS, LPDDSCAPS2 lpDDSCaps2,
+                                         LPDWORD lpdwTotal, LPDWORD lpdwFree)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetAvailableVidMem\n"));
+  #endif
+
+  // Check parameters
+  if(NULL==lpDDSCaps2)
+    return(DDERR_INVALIDPARAMS);
+
+  if((NULL==lpdwTotal)&&(NULL==lpdwFree))
+    return(DDERR_INVALIDPARAMS);
+
+  if(NULL!=lpdwTotal)
+    *lpdwTotal = 2048 *1024;
+
+  if(NULL!=lpdwFree)
+    *lpdwFree = 2048 *1024;
+
+  return(DD_OK);
+}
+//******************************************************************************
+//*** Added in the v4 interface ***
+//******************************************************************************
+HRESULT __stdcall DrawGetSurfaceFromDC(THIS, HDC hdc, LPDIRECTDRAWSURFACE4 *)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetSurfaceFromDC NYI\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawRestoreAllSurfaces(THIS)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: RestoreAllSurfaces\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawTestCooperativeLevel(THIS)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: TestCooperativeLevel\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall DrawGetDeviceIdentifier( THIS, LPDDDEVICEIDENTIFIER lpdddi,
+                                           DWORD dwFlags)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: GetDeviceIdentifier Flags = %d\n",dwFlags));
+  #endif
+  if(NULL==lpdddi)
+    return DDERR_INVALIDPARAMS;
+
+
+
+  memset( lpdddi,
+          0,
+          sizeof(DDDEVICEIDENTIFIER));
+  // ToDo: Cretae a GUID and put some better data inside
+  strcpy( lpdddi->szDriver,
+          "OS/2 DIVE Driver");
+  strcpy( lpdddi->szDescription,
+          "ODIN DD Emulation Driver");
+
+
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+VOID OS2IDirectDraw::SwitchDisplay(HWND hwnd)
+{
+  DWORD dwVType, dwVSize;
+  HKEY hkDirectDraw2;
+
+
+
+  if (bScale)
+  {
+    if (ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,KEY_DIRECT2DRAW,&hkDirectDraw2))
+    {
+      dwVSize = 4;
+      dwVType = REG_DWORD;
+      if (ERROR_SUCCESS!=RegQueryValueExA( hkDirectDraw2, "Fullscreen", NULL, &dwVType,
+                                         (LPBYTE)&bScale, &dwVSize))
+        bScale = FALSE;
+    }
+    else
+      bScale = FALSE;
+  }
+
+
+}
+//******************************************************************************
+//******************************************************************************
+
Index: trunk/src/ddraw/new/OS2DDRAW.H
===================================================================
--- trunk/src/ddraw/new/OS2DDRAW.H	(revision 3345)
+++ trunk/src/ddraw/new/OS2DDRAW.H	(revision 3345)
@@ -0,0 +1,196 @@
+/* $Id: OS2DDRAW.H,v 1.1 2000-04-07 18:21:04 mike Exp $ */
+
+/*
+ * DX Draw base class definition
+ *
+ * Copyright 1998 Sander va Leeuwen
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef __OS2DDRAW_HPP__
+  #define __OS2DDRAW_HPP__
+
+#include <ddraw.h>
+#include <d3d.h>
+#undef APIENTRY
+#define APIENTRY _System
+#include "divewrap.h"
+//#define DEBUG 1
+#define mmioFOURCC( ch0, ch1, ch2, ch3 )                         \
+                  ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |    \
+                  ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
+#include <fourcc.h>
+#undef THIS
+#define THIS VOID*
+class OS2IDirectDraw
+{
+  public:
+    //this one has to go first!
+    IDirectDraw4Vtbl *lpVtbl;
+    IDirectDraw4Vtbl *lpVtbl2;         // 2nd Vtable pointer An other MS assumtion see below
+    DWORD            *pdwUnknownData;  // MS DDCAPS (DX6 SDK bin\tools )program makes an assumtion that after the
+                                       // VTable comes a pointer to some data
+                                       // to avoid crashes we do it a favor and alloc a buffer
+                                       // with 255 DWORDS
+                                       // Known data in the buffer Height(offset 235),
+                                       // Height (236),  Bits (241)
+                                       // ToDO :
+                                       // debug into DirectDrawCreate and se what MS is doing !
+    IDirectDraw2Vtbl  Vtbl;
+    // MS did it again with direct/X 6 they changed the behavior of the directdraw component
+    // So we now need 2 Virt. Tables one for the old and one for the new so we return the
+    // right interface if one creates a DX6 directdraw object but wants a DX2,3,5 interface
+    IDirectDraw4Vtbl  Vtbl4;
+    IDirect3DVtbl     Vtbl3D;
+
+    OS2IDirectDraw(GUID *lpGUID);
+    ~OS2IDirectDraw();
+    // Simple management for Surfaces should be good enougth for now
+    inline  BOOL          HasPrimarySurface() { return PrimaryExists;}
+            void          SetPrimarySurface(BOOL NewStatus){PrimaryExists = NewStatus;}
+            int           Referenced;
+    inline  HRESULT       GetLastError()    { return lastError;    }
+    inline  HDIVE         GetDiveInstance() { return hDive;        }
+    inline  HDIVE         GetCCDiveInstance() { return hDiveColorConv;}
+    inline  char *        GetFrameBuffer()  { return pFrameBuffer; }
+    inline  int           GetScreenWidth()  { return screenwidth;  }
+    inline  int           GetScreenHeight() { return screenheight; }
+    inline  int           GetScreenBpp()    { return screenbpp;}
+    FOURCC        GetScreenFourCC();
+    // We should be able to use any mode with less or same bits and same or
+    // smaller size to be able to report all supported mode in the enum
+    // functions we need the physical screen size. Other information is later
+    // also needed so get all the info we can get
+    DIVE_CAPS dCaps;
+    VOID *pPrimSurf;
+
+  private:
+   VOID SwitchDisplay(HWND hwnd);
+
+
+  protected:
+
+    HRESULT lastError;
+    HDIVE   hDive;           // Handle to Screen DIVE instance
+    HDIVE   hDiveColorConv;  // Handle to Offscreen DIVE instance for Color conversion
+    char   *pFrameBuffer;
+    HWND    hwndClient;
+    DWORD   dwCoopMode;
+    int     screenwidth, screenheight, screenbpp;
+    int     oldwidth, oldheight, oldbpp, oldscanlines;
+    BOOL    PrimaryExists;
+    BOOL    bPMILoaded;
+    BOOL    bInFullScreen;
+    BOOL    bScale;
+
+   // Linked list management
+              OS2IDirectDraw* next;                   // Next OS2IDirectDraw
+    static    OS2IDirectDraw* ddraw;                  // List of OS2IDirectDraw
+
+    friend    HRESULT __stdcall DrawQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj);
+    friend    ULONG   __stdcall DrawAddRef(THIS);
+    friend    ULONG   __stdcall DrawRelease(THIS);
+    friend    HRESULT __stdcall DrawCompact(THIS);
+    friend    HRESULT __stdcall DrawCreateClipper(THIS, DWORD, LPDIRECTDRAWCLIPPER *, IUnknown  * );
+    friend    HRESULT __stdcall DrawCreatePalette(THIS, DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown  * );
+    friend    HRESULT __stdcall DrawCreateSurface(THIS, LPDDSURFACEDESC, LPDIRECTDRAWSURFACE  *, IUnknown  *);
+    friend    HRESULT __stdcall DrawCreateSurface4(THIS, LPDDSURFACEDESC2, LPDIRECTDRAWSURFACE4  *, IUnknown  *);
+    friend    HRESULT __stdcall DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE  * );
+    friend    HRESULT __stdcall DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4  * );
+    friend    HRESULT __stdcall DrawEnumDisplayModes(THIS, DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK );
+    friend    HRESULT __stdcall DrawEnumDisplayModes4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2 );
+    friend    HRESULT __stdcall DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK );
+    friend    HRESULT __stdcall DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 );
+    friend    HRESULT __stdcall DrawFlipToGDISurface(THIS);
+    friend    HRESULT __stdcall DrawGetCaps(THIS, LPDDCAPS, LPDDCAPS);
+    friend    HRESULT __stdcall DrawGetDisplayMode(THIS, LPDDSURFACEDESC);
+    friend    HRESULT __stdcall DrawGetFourCCCodes(THIS, LPDWORD, LPDWORD);
+    friend    HRESULT __stdcall DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE  *);
+    friend    HRESULT __stdcall DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4  *);
+    friend    HRESULT __stdcall DrawGetMonitorFrequency(THIS, LPDWORD);
+    friend    HRESULT __stdcall DrawGetScanLine(THIS, LPDWORD);
+    friend    HRESULT __stdcall DrawGetVerticalBlankStatus(THIS, LPBOOL);
+    friend    HRESULT __stdcall DrawInitialize(THIS, GUID  *);
+    friend    HRESULT __stdcall DrawRestoreDisplayMode(THIS);
+    friend    HRESULT __stdcall DrawSetCooperativeLevel(THIS, HWND, DWORD);
+    friend    HRESULT __stdcall DrawSetDisplayMode(THIS, DWORD, DWORD,DWORD);
+    friend    HRESULT __stdcall DrawSetDisplayMode2(THIS, DWORD, DWORD,DWORD, DWORD, DWORD);
+    friend    HRESULT __stdcall DrawWaitForVerticalBlank(THIS, DWORD, HANDLE);
+    // V2 Interface
+    friend    HRESULT __stdcall DrawGetAvailableVidMem(THIS, LPDDSCAPS, LPDWORD, LPDWORD);
+    friend    HRESULT __stdcall DrawGetAvailableVidMem4(THIS, LPDDSCAPS2, LPDWORD, LPDWORD);
+    // V4 Interface
+    friend    HRESULT __stdcall GetSurfaceFromDC(THIS, HDC, LPDIRECTDRAWSURFACE4 *);
+    friend    HRESULT __stdcall RestoreAllSurfaces(THIS) ;
+    friend    HRESULT __stdcall TestCooperativeLevel(THIS) ;
+    friend    HRESULT __stdcall GetDeviceIdentifier(THIS, LPDDDEVICEIDENTIFIER, DWORD );
+    /*** IDirect3D methods ***/
+    friend    HRESULT __stdcall D3DQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj);
+    friend    ULONG   __stdcall D3DAddRef(THIS);
+    friend    ULONG   __stdcall D3DRelease(THIS);
+    friend    HRESULT __stdcall D3DInitialize(THIS, REFIID);
+    friend    HRESULT __stdcall D3DEnumDevices(THIS, LPD3DENUMDEVICESCALLBACK, LPVOID);
+    friend    HRESULT __stdcall D3DCreateLight(THIS, LPDIRECT3DLIGHT*, IUnknown*);
+    friend    HRESULT __stdcall D3DCreateMaterial(THIS, LPDIRECT3DMATERIAL*, IUnknown*);
+    friend    HRESULT __stdcall D3DCreateViewport(THIS, LPDIRECT3DVIEWPORT*, IUnknown*);
+    friend    HRESULT __stdcall D3DFindDevice(THIS, LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT);
+
+};
+
+//******************************************************************************
+HRESULT __stdcall DrawQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj);
+ULONG   __stdcall DrawAddRef(THIS);
+ULONG   __stdcall DrawRelease(THIS);
+HRESULT __stdcall DrawCompact(THIS);
+HRESULT __stdcall DrawCreateClipper(THIS, DWORD, LPDIRECTDRAWCLIPPER *, IUnknown  * );
+HRESULT __stdcall DrawCreatePalette(THIS, DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown  * );
+HRESULT __stdcall DrawCreateSurface(THIS, LPDDSURFACEDESC, LPDIRECTDRAWSURFACE  *, IUnknown  *);
+HRESULT __stdcall DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE  * );
+HRESULT __stdcall DrawEnumDisplayModes(THIS, DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK );
+HRESULT __stdcall DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK );
+HRESULT __stdcall DrawFlipToGDISurface(THIS);
+HRESULT __stdcall DrawGetCaps(THIS, LPDDCAPS, LPDDCAPS);
+HRESULT __stdcall DrawGetDisplayMode(THIS, LPDDSURFACEDESC);
+HRESULT __stdcall DrawGetFourCCCodes(THIS, LPDWORD, LPDWORD);
+HRESULT __stdcall DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE  *);
+HRESULT __stdcall DrawGetMonitorFrequency(THIS, LPDWORD);
+HRESULT __stdcall DrawGetScanLine(THIS, LPDWORD);
+HRESULT __stdcall DrawGetVerticalBlankStatus(THIS, LPBOOL);
+HRESULT __stdcall DrawInitialize(THIS, GUID  *);
+HRESULT __stdcall DrawRestoreDisplayMode(THIS);
+HRESULT __stdcall DrawSetCooperativeLevel(THIS, HWND, DWORD);
+HRESULT __stdcall DrawSetDisplayMode(THIS, DWORD, DWORD,DWORD);
+HRESULT __stdcall DrawSetDisplayMode2(THIS, DWORD, DWORD,DWORD, DWORD, DWORD);
+HRESULT __stdcall DrawWaitForVerticalBlank(THIS, DWORD, HANDLE);
+// V2
+HRESULT __stdcall DrawGetAvailableVidMem(THIS, LPDDSCAPS, LPDWORD, LPDWORD);
+// V4
+HRESULT __stdcall DrawGetSurfaceFromDC(THIS, HDC, LPDIRECTDRAWSURFACE4 *);
+HRESULT __stdcall DrawRestoreAllSurfaces(THIS) ;
+HRESULT __stdcall DrawTestCooperativeLevel(THIS) ;
+HRESULT __stdcall DrawGetDeviceIdentifier(THIS, LPDDDEVICEIDENTIFIER, DWORD );
+// functions which ifaces are changed in DirectX6 after all MS uses COM where an programmer
+// isn't allowd to change a function iface after he published the iface (See MS COM docs!)
+HRESULT __stdcall DrawCreateSurface4(THIS, LPDDSURFACEDESC2, LPDIRECTDRAWSURFACE4  *, IUnknown  *);
+HRESULT __stdcall DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4  * );
+HRESULT __stdcall DrawEnumDisplayModes4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2 );
+HRESULT __stdcall DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 );
+HRESULT __stdcall DrawGetDisplayMode4(THIS, LPDDSURFACEDESC2);
+HRESULT __stdcall DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4  *);
+HRESULT __stdcall DrawGetAvailableVidMem4(THIS, LPDDSCAPS2, LPDWORD, LPDWORD);
+
+/*** IDirect3D methods ***/
+HRESULT __stdcall D3DQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj);
+ULONG   __stdcall D3DAddRef(THIS);
+ULONG   __stdcall D3DRelease(THIS);
+HRESULT __stdcall D3DInitialize(THIS, REFIID);
+HRESULT __stdcall D3DEnumDevices(THIS, LPD3DENUMDEVICESCALLBACK, LPVOID);
+HRESULT __stdcall D3DCreateLight(THIS, LPDIRECT3DLIGHT*, IUnknown*);
+HRESULT __stdcall D3DCreateMaterial(THIS, LPDIRECT3DMATERIAL*, IUnknown*);
+HRESULT __stdcall D3DCreateViewport(THIS, LPDIRECT3DVIEWPORT*, IUnknown*);
+HRESULT __stdcall D3DFindDevice(THIS, LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT);
+
+#endif
Index: trunk/src/ddraw/new/OS2PALETTE.CPP
===================================================================
--- trunk/src/ddraw/new/OS2PALETTE.CPP	(revision 3345)
+++ trunk/src/ddraw/new/OS2PALETTE.CPP	(revision 3345)
@@ -0,0 +1,283 @@
+/* $Id: OS2PALETTE.CPP,v 1.1 2000-04-07 18:21:04 mike Exp $ */
+
+/*
+ * DX palette class implementation
+ *
+ * Copyright 1998 Sander va Leeuwen
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#define INITGUID
+#include "os2ddraw.h"
+#include "os2clipper.h"
+#include "os2palette.h"
+#include "os2surface.h"
+#define _OS2WIN_H
+#define FAR
+#include <misc.h>
+#include "os2palset.h"
+#include "os2fsdd.h"
+#include <winerror.h>
+
+#undef THIS
+#define THIS IDirectDrawPalette*
+
+//******************************************************************************
+//******************************************************************************
+OS2IDirectDrawPalette::OS2IDirectDrawPalette( VOID *lpDirectDraw,
+                                              int palsize,
+                                              LPPALETTEENTRY lpColorTable,
+                                              DWORD dwPalFlags) :
+                                              Referenced(0), os2pal(NULL),
+                                              lastError(DD_OK), lpDraw(NULL)
+
+{
+  lpVtbl              = &Vtbl;
+  Vtbl.AddRef         = PalAddRef;
+  Vtbl.Release        = PalRelease;
+  Vtbl.QueryInterface = PalQueryInterface;
+  Vtbl.GetCaps        = PalGetCaps;
+  Vtbl.GetEntries     = PalGetEntries;
+  Vtbl.Initialize     = PalInitialize;
+  Vtbl.SetEntries     = PalSetEntries;
+
+  lpDraw                        = lpDirectDraw;
+  ((OS2IDirectDraw*)lpDraw)->Vtbl.AddRef(lpDraw);
+  hDive                         = ((OS2IDirectDraw*)lpDirectDraw)->GetDiveInstance();
+  dwCaps                        = dwPalFlags;
+  hDiveCC                       = ((OS2IDirectDraw*)lpDirectDraw)->GetCCDiveInstance();
+
+  dwSize = palsize;
+  if(256==dwSize)
+    dwCaps |= DDPCAPS_ALLOW256;
+  dwCaps &= ~DDPCAPS_VSYNC; // No sync change
+
+  os2pal = (LPPALETTEENTRY)malloc(palsize*sizeof(PALETTEENTRY));
+  memcpy((char *)os2pal, (char *)lpColorTable, palsize*sizeof(PALETTEENTRY));
+
+  dprintf(("DDRAW: Init CC PalTable"));
+  for(DWORD i=0;i<dwSize;i++)
+  {
+    aPal16[i] = (lpColorTable[i].peBlue>>3) +
+                ((lpColorTable[i].peGreen>>2) <<5) +
+                ((lpColorTable[i].peRed>>3) << 11);
+    dprintf(( " # %d : RGB=%02X/%02X/%02X => %04X\n",
+              i,
+              lpColorTable[i].peRed,
+              lpColorTable[i].peGreen,
+              lpColorTable[i].peBlue,
+              aPal16[i]));
+    aPal24[i] = (lpColorTable[i].peBlue <<8) +
+                (lpColorTable[i].peGreen<<16) +
+                (lpColorTable[i].peRed<<24);
+  }
+}
+//******************************************************************************
+//******************************************************************************
+OS2IDirectDrawPalette::~OS2IDirectDrawPalette()
+{
+  if(os2pal)
+    free(os2pal);
+  ((OS2IDirectDraw*)lpDraw)->Vtbl.Release((OS2IDirectDraw*)lpDraw);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall PalQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawPalette::PalQueryInterface\n"));
+  #endif
+
+  *ppvObj = NULL;
+
+  if(!IsEqualGUID(riid, IID_IDirectDrawPalette))
+//&& !IsEqualGUID(riid, IID_IUnknown))
+  return E_NOINTERFACE;
+
+  *ppvObj = This;
+
+  PalAddRef(This);
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall PalAddRef(THIS This)
+{
+  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawPalette::PalAddRef %d\n", me->Referenced+1));
+  #endif
+
+  return (++me->Referenced);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall PalRelease(THIS This)
+{
+  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawPalette::PalRelease %d\n", me->Referenced-1));
+  #endif
+
+  if(me->Referenced)
+  {
+    me->Referenced--;
+    if(me->Referenced == 0)
+    {
+      delete(me);
+      return(0);
+    }
+    else
+      return (me->Referenced);
+  }
+  else
+    return(0);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall PalGetCaps(THIS This, LPDWORD lpdwCaps)
+{
+  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawPalette::GetCaps\n"));
+  #endif
+
+  if(NULL== lpdwCaps)
+    return(DDERR_INVALIDPARAMS);
+
+  *lpdwCaps = me->dwCaps;
+
+  if(me->fAttachedToPrimary)
+    *lpdwCaps |= DDPCAPS_PRIMARYSURFACE;
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall PalGetEntries(THIS This, DWORD dwFlags,
+                                      DWORD dwBase,
+                                      DWORD dwNumEntries,
+                                      LPPALETTEENTRY lpEntries)
+{
+ OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawPalette::PalGetEntries\n"));
+  #endif
+
+  if( (NULL== lpEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
+    return(DDERR_INVALIDPARAMS);
+
+  memcpy( (char *)lpEntries,
+          (char *)(me->os2pal + dwBase),
+          dwNumEntries*sizeof(PALETTEENTRY));
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawPalette::PalInitialize\n"));
+  #endif
+  return(DDERR_ALREADYINITIALIZED);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall PalSetEntries(THIS This, DWORD dwFlags,
+                                      DWORD dwBase,
+                                      DWORD dwNumEntries,
+                                      LPPALETTEENTRY lpNewEntries)
+{
+ OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawPalette::PalSetEntries\n"));
+  #endif
+  if( (NULL== lpNewEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
+    return(DDERR_INVALIDPARAMS);
+
+  memcpy((char *)(me->os2pal + dwBase),
+         (char *)lpNewEntries,
+         dwNumEntries*sizeof(PALETTEENTRY));
+
+  dprintf(("DDRAW: Setting up CC Palentries:\n"));
+  for(DWORD i=0;i<dwNumEntries;i++)
+  {
+    me->aPal16[dwBase+i] = (lpNewEntries[i].peBlue>>3) +
+                           ((lpNewEntries[i].peGreen>>2) <<5) +
+                           ((lpNewEntries[i].peRed>>3) << 11);
+    dprintf(( " # %d : RGB=%02X/%02X/%02X => %04X\n",
+              dwBase+i,
+              lpNewEntries[i].peRed,
+              lpNewEntries[i].peGreen,
+              lpNewEntries[i].peBlue,
+              me->aPal16[dwBase+i]));
+    me->aPal24[dwBase+i] = (lpNewEntries[i].peBlue <<8) +
+                           (lpNewEntries[i].peGreen<<16) +
+                           (lpNewEntries[i].peRed<<24);
+  }
+
+  if(8==((OS2IDirectDraw*)me->lpDraw)->dCaps.ulDepth)
+  {
+    if(me->fAttachedToPrimary)
+      me->SetPhysPalette();
+  }
+  else
+  {
+    if(NULL!=((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)
+      ((OS2IDirectDrawSurface*)((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)->ColorConversion(NULL);
+  }
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+void OS2IDirectDrawPalette::SetPhysPalette()
+{
+#if 0
+  OS2SetPhysPalette(os2pal);
+#else
+  SetSVGAPalette(os2pal);
+#endif
+}
+//******************************************************************************
+//******************************************************************************
+void OS2IDirectDrawPalette::RestorePhysPalette()
+{
+  OS2ResetPhysPalette();
+}
+//******************************************************************************
+//******************************************************************************
+void OS2IDirectDrawPalette::SetIsPrimary(BOOL fNewVal)
+{
+  if(fNewVal==fAttachedToPrimary)
+    return;
+  fAttachedToPrimary = fNewVal;
+
+  /*
+  if(fAttachedToPrimary)
+  {
+    if(NULL!=hDiveCC)
+      DiveSetSourcePalette( hDiveCC,
+                            0,
+                            255,
+                            (PBYTE)os2pal);
+    else
+      SetPhysPalette();
+  }
+  */
+}
+//******************************************************************************
+//******************************************************************************
+
Index: trunk/src/ddraw/new/OS2PALETTE.H
===================================================================
--- trunk/src/ddraw/new/OS2PALETTE.H	(revision 3345)
+++ trunk/src/ddraw/new/OS2PALETTE.H	(revision 3345)
@@ -0,0 +1,83 @@
+/* $Id: OS2PALETTE.H,v 1.1 2000-04-07 18:21:05 mike Exp $ */
+
+/*
+ * DX palette class definition
+ *
+ * Copyright 1998 Sander va Leeuwen
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef __OS2PALETTE_H__
+#define __OS2PALETTE_H__
+
+#include "divewrap.h"
+#define FAR
+#undef THIS
+#define THIS IDirectDrawPalette*
+
+#pragma pack(1)          /* pack on wordboundary */
+
+typedef struct _RGB2         /* rgb2 */
+{
+  BYTE bBlue;              /* Blue component of the color definition */
+  BYTE bGreen;             /* Green component of the color definition*/
+  BYTE bRed;               /* Red component of the color definition  */
+  BYTE fcOptions;          /* Reserved, must be zero                 */
+} RGB2;
+typedef RGB2 *PRGB2;
+#pragma pack()
+
+class OS2IDirectDrawPalette
+{
+ public:
+  //this one has to go first!
+  IDirectDrawPaletteVtbl *lpVtbl;
+  IDirectDrawPaletteVtbl  Vtbl;
+
+  OS2IDirectDrawPalette( VOID *lpDirectDraw,
+                         int palsize,
+                         LPPALETTEENTRY lpColorTable,
+                         DWORD dwPalFlags);
+  ~OS2IDirectDrawPalette();
+
+  void          SetPhysPalette();
+  void          RestorePhysPalette();
+  void          SetIsPrimary(BOOL newValue);
+  int           Referenced;
+  inline  HRESULT       GetLastError() { return lastError; };
+  WORD           aPal16[256];
+  DWORD          aPal24[256];
+ private:
+
+ protected:
+  HDIVE          hDive;
+  HDIVE          hDiveCC;
+  HRESULT        lastError;
+  LPPALETTEENTRY os2pal;
+  VOID           *lpDraw;
+  DWORD          dwCaps;
+  DWORD          dwSize;
+  BOOL           fAttachedToPrimary;
+  friend    HRESULT __stdcall PalQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj);
+  friend    ULONG   __stdcall PalAddRef(THIS);
+  friend    ULONG   __stdcall PalRelease(THIS);
+  friend    HRESULT __stdcall PalGetCaps(THIS, LPDWORD);
+  friend    HRESULT __stdcall PalGetEntries(THIS, DWORD,DWORD,DWORD,LPPALETTEENTRY);
+  friend    HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY);
+  friend    HRESULT __stdcall PalSetEntries(THIS, DWORD,DWORD,DWORD,LPPALETTEENTRY);
+};
+
+
+HRESULT __stdcall PalQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj);
+ULONG   __stdcall PalAddRef(THIS);
+ULONG   __stdcall PalRelease(THIS);
+HRESULT __stdcall PalGetCaps(THIS, LPDWORD);
+HRESULT __stdcall PalGetEntries(THIS, DWORD,DWORD,DWORD,LPPALETTEENTRY);
+HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY);
+HRESULT __stdcall PalSetEntries(THIS, DWORD,DWORD,DWORD,LPPALETTEENTRY);
+
+
+#endif
Index: trunk/src/ddraw/new/OS2PALSET.CPP
===================================================================
--- trunk/src/ddraw/new/OS2PALSET.CPP	(revision 3345)
+++ trunk/src/ddraw/new/OS2PALSET.CPP	(revision 3345)
@@ -0,0 +1,93 @@
+/* $Id: OS2PALSET.CPP,v 1.1 2000-04-07 18:21:05 mike Exp $ */
+
+/*
+ * Functions used to Set the Physical Palette in OS/2 when in 8 Bit mode
+ *
+ * Copyright 1998 Sander va Leeuwen
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#define INCL_GREALL
+#define INCL_GPI
+#include <os2wrap.h>
+#include <pmddi.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "os2palset.h"
+
+//******************************************************************************
+//******************************************************************************
+void OS2SetPhysPalette(void *pal)
+{
+ PALETTEENTRY *pDirectXPal = (PALETTEENTRY *)pal;
+ HPS  hps;
+ HDC  hdc;
+ RGB2 os2rgb[256];
+ int  i;
+
+ USHORT sel = RestoreOS2FS();
+
+
+
+
+  hps = WinGetPS(HWND_DESKTOP);
+  hdc = GpiQueryDevice(hps);
+
+  for(i=0;i<256;i++)
+  {
+    os2rgb[i].bBlue     = pDirectXPal[i].peBlue;
+    os2rgb[i].bGreen    = pDirectXPal[i].peGreen;
+    os2rgb[i].bRed      = pDirectXPal[i].peRed;
+    os2rgb[i].fcOptions = 0;
+  }
+
+  GpiCreateLogColorTable( hps, LCOL_PURECOLOR | LCOL_REALIZABLE,
+                          LCOLF_CONSECRGB,
+                          0,
+                          256,
+                          (PLONG)&os2rgb);
+  Gre32Entry3( hdc,
+               0L,
+               0x000060C6L);
+
+  WinInvalidateRect( HWND_DESKTOP,
+                     (PRECTL)NULL,
+                     TRUE);
+  WinReleasePS(hps);
+
+  SetFS(sel);
+
+}
+
+//******************************************************************************
+//******************************************************************************
+void OS2ResetPhysPalette()
+{
+ HPS hps;
+ HDC hdc;
+
+ USHORT sel = RestoreOS2FS();
+
+
+
+  hps = WinGetPS( HWND_DESKTOP);
+
+  hdc = GpiQueryDevice( hps);
+
+  Gre32Entry3( hdc,
+               0L,
+               0x000060C7L);
+
+  WinInvalidateRect( HWND_DESKTOP,
+                    (PRECTL)NULL,
+                    TRUE);
+
+  WinReleasePS(hps);
+
+  SetFS(sel);
+
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/ddraw/new/OS2PALSET.H
===================================================================
--- trunk/src/ddraw/new/OS2PALSET.H	(revision 3345)
+++ trunk/src/ddraw/new/OS2PALSET.H	(revision 3345)
@@ -0,0 +1,28 @@
+/* $Id: OS2PALSET.H,v 1.1 2000-04-07 18:21:05 mike Exp $ */
+
+/*
+ * Defintions for OS/2 Palette functions
+ *
+ * Copyright 1998 Sander van Leeuwen
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __OS2PALSET_H__
+  #define __OS2PALSET_H__
+
+  #ifndef __OS2PALETTE_H__
+   typedef struct tagPALETTEENTRY
+   {
+      BYTE        peRed;
+      BYTE        peGreen;
+      BYTE        peBlue;
+      BYTE        peFlags;
+   } PALETTEENTRY;
+  #endif
+
+  //void OS2SetPhysPalette(PALETTEENTRY *pDirectXPal);
+  void OS2SetPhysPalette(void *pal);
+  void OS2ResetPhysPalette();
+
+#endif
Index: trunk/src/ddraw/new/OS2SURFACE.CPP
===================================================================
--- trunk/src/ddraw/new/OS2SURFACE.CPP	(revision 3345)
+++ trunk/src/ddraw/new/OS2SURFACE.CPP	(revision 3345)
@@ -0,0 +1,5982 @@
+/* $Id: OS2SURFACE.CPP,v 1.1 2000-04-07 18:21:05 mike Exp $ */
+
+/*
+ * Direct/X Surface class implementaion
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#define mmioFOURCC( ch0, ch1, ch2, ch3 )                         \
+                  ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |    \
+                  ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
+#include <fourcc.h>
+#define INITGUID
+#include "os2ddraw.h"
+#include "os2clipper.h"
+#include "os2palette.h"
+#include "os2surface.h"
+#include "os2util.h"
+#include "rectangle.h"
+#define _OS2WIN_H
+#define FAR
+#include <misc.h>
+#include "asmutil.h"
+#include "bltFunc.h"
+#include "colorconv.h"
+#include "fillfunc.h"
+#include <winerror.h>
+#include <os2win.h>
+#ifndef __WATCOMC__
+  #include <builtin.h>
+#endif
+
+extern FOURCC  SupportedFourCCs[];
+// ToDo: Move the following 2 defines in the right WINE headers.
+BYTE DefaultPalette[] = { 0x00,0x00,0x00,   // 0
+                          0x80,0x00,0x00,   // 1
+                          0x00,0x80,0x00,   // 2
+                          0x80,0x80,0x00,   // 3
+                          0x00,0x00,0x80,   // 4
+                          0x80,0x00,0x80,   // 5
+                          0x00,0x80,0x80,   // 6
+                          0xC0,0xC0,0xC0,   // 7
+                          0xC0,0xDC,0xC0,   // 8
+                          0xA6,0xCA,0xF0,   // 9
+                          0x04,0x04,0x04,   // 10
+                          0x08,0x08,0x08,   // 11
+                          0x0C,0x0C,0x0C,   // 12
+                          0x11,0x11,0x11,   // 13
+                          0x16,0x16,0x16,   // 14
+                          0x1C,0x1C,0x1C,   // 15
+                          0x22,0x22,0x22,   // 16
+                          0x29,0x29,0x29,   // 17
+                          0x55,0x55,0x55,   // 18
+                          0x4D,0x4D,0x4D,
+                          0x42,0x42,0x42,
+                          0x39,0x39,0x39,
+                          0x81,0x81,0x81,
+                          0x81,0x00,0x00,
+                          0x00,0x81,0x00,
+                          0x81,0x81,0x00,
+                          0x00,0x00,0x81,
+                          0x81,0x00,0x81,
+                          0x00,0x81,0x81,
+                          0x33,0x00,0x00,
+                          0x66,0x00,0x00,
+                          0x99,0x00,0x00,
+                          0xCC,0x00,0x00,
+                          0x00,0x33,0x00,
+                          0x33,0x33,0x00,
+                          0x66,0x33,0x00,
+                          0x99,0x33,0x00,
+                          0xCC,0x33,0x00,
+                          0xFF,0x33,0x00,
+                          0x00,0x66,0x00,
+                          0x33,0x66,0x00,
+                          0x66,0x66,0x00,
+                          0x99,0x66,0x00,
+                          0xCC,0x66,0x00,
+                          0xFF,0x66,0x00,
+                          0x00,0x99,0x00,
+                          0x33,0x99,0x00,
+                          0x66,0x99,0x00,
+                          0x99,0x99,0x00,
+                          0xCC,0x99,0x00,
+                          0xFF,0x99,0x00,
+                          0x00,0xCC,0x00,
+                          0x33,0xCC,0x00,
+                          0x66,0xCC,0x00,
+                          0x99,0xCC,0x00,
+                          0xCC,0xCC,0x00,
+                          0xFF,0xCC,0x00,
+                          0x66,0xFF,0x00,
+                          0x99,0xFF,0x00,
+                          0xCC,0xFF,0x00,
+                          0x00,0x00,0x33,
+                          0x33,0x00,0x33,
+                          0x66,0x00,0x33,
+                          0x99,0x00,0x33,
+                          0xCC,0x00,0x33,
+                          0xFF,0x00,0x33,
+                          0x00,0x33,0x33,
+                          0x33,0x33,0x33,
+                          0x66,0x33,0x33,
+                          0x99,0x33,0x33,
+                          0xCC,0x33,0x33,
+                          0xFF,0x33,0x33,
+                          0x00,0x66,0x33,
+                          0x33,0x66,0x33,
+                          0x66,0x66,0x33,
+                          0x99,0x66,0x33,
+                          0xCC,0x66,0x33,
+                          0xFF,0x66,0x33,
+                          0x00,0x99,0x33,
+                          0x33,0x99,0x33,
+                          0x66,0x99,0x33,
+                          0x99,0x99,0x33,
+                          0xCC,0x99,0x33,
+                          0xFF,0x99,0x33,
+                          0x00,0xCC,0x33,
+                          0x33,0xCC,0x33,
+                          0x66,0xCC,0x33,
+                          0x99,0xCC,0x33,
+                          0xCC,0xCC,0x33,
+                          0xFF,0xCC,0x33,
+                          0x33,0xFF,0x33,
+                          0x66,0xFF,0x33,
+                          0x99,0xFF,0x33,
+                          0xCC,0xFF,0x33,
+                          0xFF,0xFF,0x33,
+                          0x00,0x00,0x66,
+                          0x33,0x00,0x66,
+                          0x66,0x00,0x66,
+                          0x99,0x00,0x66,
+                          0xCC,0x00,0x66,
+                          0xFF,0x00,0x66,
+                          0x00,0x33,0x66,
+                          0x33,0x33,0x66,
+                          0x66,0x33,0x66,
+                          0x99,0x33,0x66,
+                          0xCC,0x33,0x66,
+                          0xFF,0x33,0x66,
+                          0x00,0x66,0x66,
+                          0x33,0x66,0x66,
+                          0x66,0x66,0x66,
+                          0x99,0x66,0x66,
+                          0xCC,0x66,0x66,
+                          0x00,0x99,0x66,
+                          0x33,0x99,0x66,
+                          0x66,0x99,0x66,
+                          0x99,0x99,0x66,
+                          0xCC,0x99,0x66,
+                          0xFF,0x99,0x66,
+                          0x00,0xCC,0x66,
+                          0x33,0xCC,0x66,
+                          0x99,0xCC,0x66,
+                          0xCC,0xCC,0x66,
+                          0xFF,0xCC,0x66,
+                          0x00,0xFF,0x66,
+                          0x33,0xFF,0x66,
+                          0x99,0xFF,0x66,
+                          0xCC,0xFF,0x66,
+                          0xFF,0x00,0xCC,
+                          0xCC,0x00,0xFF,
+                          0x00,0x99,0x99,
+                          0x99,0x33,0x99,
+                          0x99,0x00,0x99,
+                          0xCC,0x00,0x99,
+                          0x00,0x00,0x99,
+                          0x33,0x33,0x99,
+                          0x66,0x00,0x99,
+                          0xCC,0x33,0x99,
+                          0xFF,0x00,0x99,
+                          0x00,0x66,0x99,
+                          0x33,0x33,0x99,
+                          0x33,0x66,0x99,
+                          0x66,0x33,0x99,
+                          0x99,0x33,0x99,
+                          0xCC,0x66,0x99,
+                          0xFF,0x33,0x99,
+                          0x33,0x99,0x99,
+                          0x66,0x99,0x99,
+                          0x99,0x99,0x99,
+                          0xCC,0x99,0x99,
+                          0xFF,0x99,0x99,
+                          0x00,0xCC,0x99,
+                          0x33,0xCC,0x99,
+                          0x66,0xCC,0x66,
+                          0x99,0xCC,0x99,
+                          0xCC,0xCC,0x99,
+                          0xFF,0xCC,0x99,
+                          0x00,0xFF,0x99,
+                          0x33,0xFF,0x99,
+                          0x66,0xCC,0x99,
+                          0x99,0xFF,0x99,
+                          0xCC,0xFF,0x99,
+                          0xFF,0xFF,0x99,
+                          0x00,0x00,0xCC,
+                          0x33,0x00,0x99,
+                          0x66,0x00,0xCC,
+                          0x99,0x00,0xCC,
+                          0xCC,0x00,0xCC,
+                          0x00,0x33,0x99,
+                          0x33,0x33,0xCC,
+                          0x66,0x33,0xCC,
+                          0x99,0x33,0xCC,
+                          0xCC,0x33,0xCC,
+                          0xFF,0x33,0xCC,
+                          0x00,0x66,0xCC,
+                          0x33,0x66,0xCC,
+                          0x66,0x66,0x99,
+                          0x99,0x66,0xCC,
+                          0xCC,0x66,0xCC,
+                          0xFF,0x66,0x99,
+                          0x00,0x99,0xCC,
+                          0x33,0x99,0xCC,
+                          0x66,0x99,0xCC,
+                          0x99,0x99,0xCC,
+                          0xCC,0x99,0xCC,
+                          0xFF,0x99,0xCC,
+                          0x00,0xCC,0xCC,
+                          0x33,0xCC,0xCC,
+                          0x66,0xCC,0xCC,
+                          0x99,0xCC,0xCC,
+                          0xCC,0xCC,0xCC,
+                          0xFF,0xCC,0xCC,
+                          0x00,0xFF,0xCC,
+                          0x33,0xFF,0xCC,
+                          0x66,0xFF,0x99,
+                          0x99,0xFF,0xCC,
+                          0xCC,0xFF,0xCC,
+                          0xFF,0xFF,0xCC,
+                          0x33,0x00,0xCC,
+                          0x66,0x00,0xFF,
+                          0x99,0x00,0xFF,
+                          0x00,0x33,0xCC,
+                          0x33,0x33,0xFF,
+                          0x66,0x33,0xFF,
+                          0x99,0x33,0xFF,
+                          0xCC,0x33,0xFF,
+                          0xFF,0x33,0xFF,
+                          0x00,0x66,0xFF,
+                          0x33,0x66,0xFF,
+                          0x66,0x66,0xCC,
+                          0x99,0x66,0xFF,
+                          0xCC,0x66,0xFF,
+                          0xFF,0x66,0xCC,
+                          0x00,0x99,0xFF,
+                          0x33,0x99,0xFF,
+                          0x66,0x99,0xFF,
+                          0x99,0x99,0xFF,
+                          0xCC,0x99,0xFF,
+                          0xFF,0x99,0xFF,
+                          0x00,0xCC,0xFF,
+                          0x33,0xCC,0xFF,
+                          0x66,0xCC,0xFF,
+                          0x99,0xCC,0xFF,
+                          0xCC,0xCC,0xFF,
+                          0xFF,0xCC,0xFF,
+                          0x33,0xFF,0xFF,
+                          0x66,0xFF,0xCC,
+                          0x99,0xFF,0xFF,
+                          0xCC,0xFF,0xFF,
+                          0xFF,0x66,0x66,
+                          0x66,0xFF,0x66,
+                          0xFF,0xFF,0x66,
+                          0x66,0x66,0xFF,
+                          0xFF,0x66,0xFF,
+                          0x66,0xFF,0xFF,
+                          0xC1,0xC1,0xC1,
+                          0x5F,0x5F,0x5F,
+                          0x77,0x77,0x77,
+                          0x86,0x86,0x86,
+                          0x96,0x96,0x96,
+                          0xCB,0xCB,0xCB,
+                          0xB2,0xB2,0xB2,
+                          0xD7,0xD7,0xD7,
+                          0xDD,0xDD,0xDD,
+                          0xE3,0xE3,0xE3,
+                          0xEA,0xEA,0xEA,
+                          0xF1,0xF1,0xF1,
+                          0xF8,0xF8,0xF8,
+                          0xFF,0xFB,0xF0,
+                          0xA0,0xA0,0xA4,
+                          0x80,0x80,0x80,
+                          0xFF,0x00,0x00,
+                          0x00,0xFF,0x00,
+                          0xFF,0xFF,0x00,
+                          0x00,0x00,0xFF,
+                          0xFF,0x00,0xFF,
+//                          0x00,0xFF,0xFF,
+                          0xFF,0xFF,0xFF};
+
+WORD wDefaultPalete16[256];
+DWORD dwDefaultPalete24[256];
+BOOL fPalInit=FALSE;
+
+#define CBM_CREATEDIB   0x02L   /* create DIB bitmap */
+#ifdef DEBUG
+
+// ******************************************************************************
+// *    internal helper functions from WINE
+// *
+
+static void _dump_DDBLTFX(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+#define FE(x) { x, #x},
+    FE(DDBLTFX_ARITHSTRETCHY)
+    FE(DDBLTFX_MIRRORLEFTRIGHT)
+    FE(DDBLTFX_MIRRORUPDOWN)
+    FE(DDBLTFX_NOTEARING)
+    FE(DDBLTFX_ROTATE180)
+    FE(DDBLTFX_ROTATE270)
+    FE(DDBLTFX_ROTATE90)
+    FE(DDBLTFX_ZBUFFERRANGE)
+    FE(DDBLTFX_ZBUFFERBASEDEST)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+     if (flags[i].mask & flagmask) {
+        dprintf(("DDRAW: %s ",flags[i].name));
+     };
+  dprintf(("DDRAW: \n"));
+
+}
+
+static void _dump_DDBLTFAST(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+#define FE(x) { x, #x},
+    FE(DDBLTFAST_NOCOLORKEY)
+    FE(DDBLTFAST_SRCCOLORKEY)
+    FE(DDBLTFAST_DESTCOLORKEY)
+    FE(DDBLTFAST_WAIT)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+    if (flags[i].mask & flagmask)
+      dprintf(("DDRAW: %s ",flags[i].name));
+  dprintf(("DDRAW: \n"));
+}
+
+static void _dump_DDBLT(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+#define FE(x) { x, #x},
+    FE(DDBLT_ALPHADEST)
+    FE(DDBLT_ALPHADESTCONSTOVERRIDE)
+    FE(DDBLT_ALPHADESTNEG)
+    FE(DDBLT_ALPHADESTSURFACEOVERRIDE)
+    FE(DDBLT_ALPHAEDGEBLEND)
+    FE(DDBLT_ALPHASRC)
+    FE(DDBLT_ALPHASRCCONSTOVERRIDE)
+    FE(DDBLT_ALPHASRCNEG)
+    FE(DDBLT_ALPHASRCSURFACEOVERRIDE)
+    FE(DDBLT_ASYNC)
+    FE(DDBLT_COLORFILL)
+    FE(DDBLT_DDFX)
+    FE(DDBLT_DDROPS)
+    FE(DDBLT_KEYDEST)
+    FE(DDBLT_KEYDESTOVERRIDE)
+    FE(DDBLT_KEYSRC)
+    FE(DDBLT_KEYSRCOVERRIDE)
+    FE(DDBLT_ROP)
+    FE(DDBLT_ROTATIONANGLE)
+    FE(DDBLT_ZBUFFER)
+    FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE)
+    FE(DDBLT_ZBUFFERDESTOVERRIDE)
+    FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE)
+    FE(DDBLT_ZBUFFERSRCOVERRIDE)
+    FE(DDBLT_WAIT)
+    FE(DDBLT_DEPTHFILL)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+    if (flags[i].mask & flagmask)
+      dprintf(("DDRAW: %s ",flags[i].name));
+  dprintf(("DDRAW: \n"));
+}
+
+static void _dump_DDSCAPS(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+#define FE(x) { x, #x},
+    FE(DDSCAPS_RESERVED1)
+    FE(DDSCAPS_ALPHA)
+    FE(DDSCAPS_BACKBUFFER)
+    FE(DDSCAPS_COMPLEX)
+    FE(DDSCAPS_FLIP)
+    FE(DDSCAPS_FRONTBUFFER)
+    FE(DDSCAPS_OFFSCREENPLAIN)
+    FE(DDSCAPS_OVERLAY)
+    FE(DDSCAPS_PALETTE)
+    FE(DDSCAPS_PRIMARYSURFACE)
+    FE(DDSCAPS_PRIMARYSURFACELEFT)
+    FE(DDSCAPS_SYSTEMMEMORY)
+    FE(DDSCAPS_TEXTURE)
+    FE(DDSCAPS_3DDEVICE)
+    FE(DDSCAPS_VIDEOMEMORY)
+    FE(DDSCAPS_VISIBLE)
+    FE(DDSCAPS_WRITEONLY)
+    FE(DDSCAPS_ZBUFFER)
+    FE(DDSCAPS_OWNDC)
+    FE(DDSCAPS_LIVEVIDEO)
+    FE(DDSCAPS_HWCODEC)
+    FE(DDSCAPS_MODEX)
+    FE(DDSCAPS_MIPMAP)
+    FE(DDSCAPS_RESERVED2)
+    FE(DDSCAPS_ALLOCONLOAD)
+    FE(DDSCAPS_VIDEOPORT)
+    FE(DDSCAPS_LOCALVIDMEM)
+    FE(DDSCAPS_NONLOCALVIDMEM)
+    FE(DDSCAPS_STANDARDVGAMODE)
+    FE(DDSCAPS_OPTIMIZED)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+    if (flags[i].mask & flagmask)
+      dprintf(("DDRAW: %s ",flags[i].name));
+  dprintf(("DDRAW: \n"));
+}
+
+static void _dump_DDSCAPS2(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+#define FE(x) { x, #x},
+    FE(DDSCAPS2_HARDWAREDEINTERLACE)
+    FE(DDSCAPS2_HINTANTIALIASING)
+    FE(DDSCAPS2_HINTDYNAMIC)
+    FE(DDSCAPS2_HINTSTATIC)
+    FE(DDSCAPS2_OPAQUE)
+    FE(DDSCAPS2_TEXTUREMANAGE)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+    if (flags[i].mask & flagmask)
+      dprintf(("DDRAW: %s ",flags[i].name));
+  dprintf(("DDRAW: \n"));
+}
+
+
+static void _dump_DDSD(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+    FE(DDSD_CAPS)
+    FE(DDSD_HEIGHT)
+    FE(DDSD_WIDTH)
+    FE(DDSD_PITCH)
+    FE(DDSD_BACKBUFFERCOUNT)
+    FE(DDSD_ZBUFFERBITDEPTH)
+    FE(DDSD_ALPHABITDEPTH)
+    FE(DDSD_PIXELFORMAT)
+    FE(DDSD_CKDESTOVERLAY)
+    FE(DDSD_CKDESTBLT)
+    FE(DDSD_CKSRCOVERLAY)
+    FE(DDSD_CKSRCBLT)
+    FE(DDSD_MIPMAPCOUNT)
+    FE(DDSD_REFRESHRATE)
+    FE(DDSD_LINEARSIZE)
+    FE(DDSD_LPSURFACE)
+    FE(DDSD_TEXTURESTAGE)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+    if (flags[i].mask & flagmask)
+      dprintf(("DDRAW: %s ",flags[i].name));
+  dprintf(("DDRAW: \n"));
+}
+
+static void _dump_DDCOLORKEY(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+#define FE(x) { x, #x},
+          FE(DDCKEY_COLORSPACE)
+    FE(DDCKEY_DESTBLT)
+    FE(DDCKEY_DESTOVERLAY)
+    FE(DDCKEY_SRCBLT)
+    FE(DDCKEY_SRCOVERLAY)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+    if (flags[i].mask & flagmask)
+      dprintf(("DDRAW: %s ",flags[i].name));
+  dprintf(("DDRAW: \n"));
+}
+
+static void _dump_DDPIXELFORMAT(DWORD flagmask) {
+  int  i;
+  const struct {
+    DWORD  mask;
+    char  *name;
+  } flags[] = {
+#define FE(x) { x, #x},
+          FE(DDPF_ALPHAPIXELS)
+    FE(DDPF_ALPHA)
+    FE(DDPF_FOURCC)
+    FE(DDPF_PALETTEINDEXED4)
+    FE(DDPF_PALETTEINDEXEDTO8)
+    FE(DDPF_PALETTEINDEXED8)
+    FE(DDPF_RGB)
+    FE(DDPF_COMPRESSED)
+    FE(DDPF_RGBTOYUV)
+    FE(DDPF_YUV)
+    FE(DDPF_ZBUFFER)
+    FE(DDPF_PALETTEINDEXED1)
+    FE(DDPF_PALETTEINDEXED2)
+    FE(DDPF_ZPIXELS)
+  };
+  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+    if (flags[i].mask & flagmask)
+      dprintf(("DDRAW: %s ",flags[i].name));
+  dprintf(("DDRAW: \n"));
+}
+
+static void _dump_pixelformat(LPDDPIXELFORMAT pf) {
+  _dump_DDPIXELFORMAT(pf->dwFlags);
+  dprintf(("DDRAW: dwFourCC : %ld\n", pf->dwFourCC));
+  dprintf(("DDRAW: RBG bit cbout : %ld\n", pf->dwRGBBitCount));
+  dprintf(("DDRAW: Masks : R %08lx  G %08lx  B %08lx  A %08lx\n",
+       pf->dwRBitMask, pf->dwGBitMask, pf->dwBBitMask, pf->dwRGBAlphaBitMask));
+}
+
+// End of Internal Helpers
+#endif
+
+//******************************************************************************
+//******************************************************************************
+OS2IDirectDrawSurface::OS2IDirectDrawSurface(OS2IDirectDraw *lpDirectDraw,
+               LPDDSURFACEDESC2 lpDDSurfaceDesc, BOOL Implicit, BOOL Mainchain) :
+                  Referenced(0), lastError(DD_OK),
+                 diveBufNr(-1), lpClipper(NULL),
+                 lpPalette(NULL), lpDraw(NULL),
+                 fLocked(FALSE), hdcImage(NULL),
+                 hbmImage(NULL),
+                 pFrameBuffer(NULL),Updated(FALSE),
+                 fOverlayValid(FALSE),
+                 BackBuffer(NULL),FrontBuffer(NULL),
+                 pDBreal(NULL),pFBreal(NULL)
+
+{
+  ULONG rc;
+  DWORD i;
+  DIVE_CAPS dCaps;
+  DDSURFACEDESC2 ComplexSurfaceDesc;
+  OS2IDirectDrawSurface *AttachedSurface;
+  OS2IDirectDrawSurface *MipMapSurface;
+
+  lpVtbl                     = &Vtbl2;
+  lpVtbl2                    = &Vtbl2;
+  dwUnknownData              = 0xDEADDEAD;
+  Vtbl.AddRef                = SurfAddRef;
+  Vtbl.Release               = SurfRelease;
+  Vtbl.QueryInterface        = SurfQueryInterface;
+  Vtbl.AddAttachedSurface    = SurfAddAttachedSurface4;
+  Vtbl.AddOverlayDirtyRect   = SurfAddOverlayDirtyRect;
+  Vtbl.Blt                   = SurfBlt4;
+  Vtbl.BltBatch              = SurfBltBatch;
+  Vtbl.BltFast               = SurfBltFast4;
+  Vtbl.DeleteAttachedSurface = SurfDeleteAttachedSurface4;
+  Vtbl.EnumAttachedSurfaces  = SurfEnumAttachedSurfaces4;
+  Vtbl.EnumOverlayZOrders    = SurfEnumOverlayZOrders4;
+  Vtbl.Flip                  = SurfFlip4;
+  Vtbl.GetAttachedSurface    = SurfGetAttachedSurface4;
+  Vtbl.GetBltStatus          = SurfGetBltStatus;
+  Vtbl.GetCaps               = SurfGetCaps4;
+  Vtbl.GetClipper            = SurfGetClipper;
+  Vtbl.GetColorKey           = SurfGetColorKey;
+  Vtbl.GetDC                 = SurfGetDC;
+  Vtbl.GetFlipStatus         = SurfGetFlipStatus;
+  Vtbl.GetOverlayPosition    = SurfGetOverlayPosition;
+  Vtbl.GetPalette            = SurfGetPalette;
+  Vtbl.GetPixelFormat        = SurfGetPixelFormat;
+  Vtbl.GetSurfaceDesc        = SurfGetSurfaceDesc4;
+  Vtbl.Initialize            = SurfInitialize4;
+  Vtbl.IsLost                = SurfIsLost;
+  Vtbl.Lock                  = SurfLock4;
+  Vtbl.ReleaseDC             = SurfReleaseDC;
+  Vtbl.Restore               = SurfRestore;
+  Vtbl.SetClipper            = SurfSetClipper;
+  Vtbl.SetColorKey           = SurfSetColorKey;
+  Vtbl.SetOverlayPosition    = SurfSetOverlayPosition;
+  Vtbl.SetPalette            = SurfSetPalette;
+  Vtbl.Unlock                = SurfUnlock4;
+  Vtbl.UpdateOverlay         = SurfUpdateOverlay4;
+  Vtbl.UpdateOverlayDisplay  = SurfUpdateOverlayDisplay;
+  Vtbl.UpdateOverlayZOrder   = SurfUpdateOverlayZOrder4;
+  Vtbl.GetDDInterface        = SurfGetDDInterface;
+  Vtbl.PageLock              = SurfPageLock;
+  Vtbl.PageUnlock            = SurfPageUnlock;
+  Vtbl.SetSurfaceDesc        = SurfSetSurfaceDesc4;
+  Vtbl.SetPrivateData        = SurfSetPrivateData;
+  Vtbl.GetPrivateData        = SurfGetPrivateData;
+  Vtbl.FreePrivateData       = SurfFreePrivateData;
+  Vtbl.ChangeUniquenessValue = SurfChangeUniquenessValue;
+  Vtbl.GetUniquenessValue    = SurfGetUniquenessValue;
+
+  Vtbl3.AddRef                = SurfAddRef;
+  Vtbl3.Release               = SurfRelease;
+  Vtbl3.QueryInterface        = SurfQueryInterface;
+  Vtbl3.AddAttachedSurface    = SurfAddAttachedSurface3;
+  Vtbl3.AddOverlayDirtyRect   = SurfAddOverlayDirtyRect;
+  Vtbl3.Blt                   = SurfBlt3;
+  Vtbl3.BltBatch              = SurfBltBatch;
+  Vtbl3.BltFast               = SurfBltFast3;
+  Vtbl3.DeleteAttachedSurface = SurfDeleteAttachedSurface3;
+  Vtbl3.EnumAttachedSurfaces  = SurfEnumAttachedSurfaces;
+  Vtbl3.EnumOverlayZOrders    = SurfEnumOverlayZOrders;
+  Vtbl3.Flip                  = SurfFlip3;
+  Vtbl3.GetAttachedSurface    = SurfGetAttachedSurface3;
+  Vtbl3.GetBltStatus          = SurfGetBltStatus;
+  Vtbl3.GetCaps               = SurfGetCaps;
+  Vtbl3.GetClipper            = SurfGetClipper;
+  Vtbl3.GetColorKey           = SurfGetColorKey;
+  Vtbl3.GetDC                 = SurfGetDC;
+  Vtbl3.GetFlipStatus         = SurfGetFlipStatus;
+  Vtbl3.GetOverlayPosition    = SurfGetOverlayPosition;
+  Vtbl3.GetPalette            = SurfGetPalette;
+  Vtbl3.GetPixelFormat        = SurfGetPixelFormat;
+  Vtbl3.GetSurfaceDesc        = SurfGetSurfaceDesc;
+  Vtbl3.Initialize            = SurfInitialize;
+  Vtbl3.IsLost                = SurfIsLost;
+  Vtbl3.Lock                  = SurfLock;
+  Vtbl3.ReleaseDC             = SurfReleaseDC;
+  Vtbl3.Restore               = SurfRestore;
+  Vtbl3.SetClipper            = SurfSetClipper;
+  Vtbl3.SetColorKey           = SurfSetColorKey;
+  Vtbl3.SetOverlayPosition    = SurfSetOverlayPosition;
+  Vtbl3.SetPalette            = SurfSetPalette;
+  Vtbl3.Unlock                = SurfUnlock;
+  Vtbl3.UpdateOverlay         = SurfUpdateOverlay3;
+  Vtbl3.UpdateOverlayDisplay  = SurfUpdateOverlayDisplay;
+  Vtbl3.UpdateOverlayZOrder   = SurfUpdateOverlayZOrder3;
+  Vtbl3.GetDDInterface        = SurfGetDDInterface;
+  Vtbl3.PageLock              = SurfPageLock;
+  Vtbl3.PageUnlock            = SurfPageUnlock;
+  Vtbl3.SetSurfaceDesc        = SurfSetSurfaceDesc;
+
+  Vtbl2.AddRef                = SurfAddRef;
+  Vtbl2.Release               = SurfRelease;
+  Vtbl2.QueryInterface        = SurfQueryInterface;
+  Vtbl2.AddAttachedSurface    = SurfAddAttachedSurface;
+  Vtbl2.AddOverlayDirtyRect   = SurfAddOverlayDirtyRect;
+  Vtbl2.Blt                   = SurfBlt;
+  Vtbl2.BltBatch              = SurfBltBatch;
+  Vtbl2.BltFast               = SurfBltFast;
+  Vtbl2.DeleteAttachedSurface = SurfDeleteAttachedSurface;
+  Vtbl2.EnumAttachedSurfaces  = SurfEnumAttachedSurfaces;
+  Vtbl2.EnumOverlayZOrders    = SurfEnumOverlayZOrders;
+  Vtbl2.Flip                  = SurfFlip;
+  Vtbl2.GetAttachedSurface    = SurfGetAttachedSurface;
+  Vtbl2.GetBltStatus          = SurfGetBltStatus;
+  Vtbl2.GetCaps               = SurfGetCaps;
+  Vtbl2.GetClipper            = SurfGetClipper;
+  Vtbl2.GetColorKey           = SurfGetColorKey;
+  Vtbl2.GetDC                 = SurfGetDC;
+  Vtbl2.GetFlipStatus         = SurfGetFlipStatus;
+  Vtbl2.GetOverlayPosition    = SurfGetOverlayPosition;
+  Vtbl2.GetPalette            = SurfGetPalette;
+  Vtbl2.GetPixelFormat        = SurfGetPixelFormat;
+  Vtbl2.GetSurfaceDesc        = SurfGetSurfaceDesc;
+  Vtbl2.Initialize            = SurfInitialize;
+  Vtbl2.IsLost                = SurfIsLost;
+  Vtbl2.Lock                  = SurfLock;
+  Vtbl2.ReleaseDC             = SurfReleaseDC;
+  Vtbl2.Restore               = SurfRestore;
+  Vtbl2.SetClipper            = SurfSetClipper;
+  Vtbl2.SetColorKey           = SurfSetColorKey;
+  Vtbl2.SetOverlayPosition    = SurfSetOverlayPosition;
+  Vtbl2.SetPalette            = SurfSetPalette;
+  Vtbl2.Unlock                = SurfUnlock;
+  Vtbl2.UpdateOverlay         = SurfUpdateOverlay;
+  Vtbl2.UpdateOverlayDisplay  = SurfUpdateOverlayDisplay;
+  Vtbl2.UpdateOverlayZOrder   = SurfUpdateOverlayZOrder;
+  Vtbl2.GetDDInterface        = SurfGetDDInterface;
+  Vtbl2.PageLock              = SurfPageLock;
+  Vtbl2.PageUnlock            = SurfPageUnlock;
+
+  lpDraw                     = lpDirectDraw;
+  lpDraw->Vtbl.AddRef(lpDraw);
+
+  ImplicitSurface = Implicit;
+
+  hDive                      = lpDirectDraw->GetDiveInstance();
+  hDiveCC                    = lpDirectDraw->GetCCDiveInstance();
+  surfaceType                = DDSCAPS_OFFSCREENPLAIN;
+  memcpy((char *)&DDSurfaceDesc, (char *)lpDDSurfaceDesc, sizeof(DDSURFACEDESC2));
+
+  if(lpDraw->dCaps.ulDepth != 15)
+  {
+    if(lpDraw->dCaps.ulDepth >= 8)
+      dwBytesPPDive = lpDraw->dCaps.ulDepth >> 3;
+    else
+      dwBytesPPDive = 1; // not sure if this is the case
+  }
+  else
+    dwBytesPPDive = 2; // 2 bytes for 15Bit
+
+  // Setting up Cursors for handling attached Surfaces
+
+  DPA_SurfaceMipMaps = DPA_Create(8);
+  if(NULL==DPA_SurfaceMipMaps)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Internal : Error creating DPA for MipMaps\n"));
+    #endif
+    lastError = DDERR_OUTOFMEMORY ;
+    return;
+  }
+
+  DPA_SurfaceAttached = DPA_Create(8);
+  if(NULL==DPA_SurfaceAttached)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Internal : Error creating DPA for attached surfaces\n"));
+    #endif
+    lastError = DDERR_OUTOFMEMORY ;
+    return;
+  }
+
+  DPA_LockedRects = DPA_Create(8);
+  if(NULL==DPA_LockedRects)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Internal : Error creating DPA for Locked Rectangles\n"));
+    #endif
+    lastError = DDERR_OUTOFMEMORY ;
+    return;
+  }
+
+  DPA_SurfacePrivateData = DPA_Create(8);
+  if(NULL==DPA_SurfacePrivateData)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Internal : Error creating DPA for priva surface Data\n"));
+    #endif
+    lastError = DDERR_OUTOFMEMORY ;
+    return;
+  }
+
+  switch(lpDraw->GetScreenBpp())
+  {
+    case 8:
+      switch(lpDraw->dCaps.ulDepth)
+      {
+        case 8:
+          BltSolid  = &BltSolid8to8;
+          ColorConv = NULL;
+          ColorFill = &Fill8on8;
+          break;
+        case 16:
+          BltSolid  = &BltSolid8to16;
+          ColorConv = &Conv8to16;
+          ColorFill = &Fill8on16;
+          break;
+        case 24:
+          BltSolid  = &BltSolid8to24;
+          ColorConv = &Conv8to24;
+          ColorFill = &Fill8on24;
+          break;
+        case 32:
+          BltSolid  = &BltSolid8to32;
+          ColorConv = &Conv8to32;
+          ColorFill = &Fill8on32;
+          break;
+        default:
+          dprintf(("DDRAW: Unsupported System ColorDeapth %d",lpDraw->dCaps.ulDepth));
+          BltSolid  = NULL;
+          ColorConv = NULL;
+          ColorFill = NULL;
+          break;
+      }
+      break;
+    case 16:
+      switch(lpDraw->dCaps.ulDepth)
+      {
+        case 8:
+          BltSolid = &BltSolid16to8;
+          ColorConv = &Conv16to8;
+          ColorFill = &Fill16on8;
+          break;
+        case 16:
+          BltSolid  = &BltSolid16to16;
+          ColorConv = NULL;
+          ColorFill = &Fill16on16;
+          break;
+        case 24:
+          BltSolid  = &BltSolid16to24;
+          ColorConv = &Conv16to24;
+          ColorFill = &Fill16on24;
+          break;
+        case 32:
+          BltSolid  = &BltSolid16to32;
+          ColorConv = &Conv16to32;
+          ColorFill = &Fill16on32;
+          break;
+        default:
+          dprintf(("DDRAW: Unsupported System ColorDeapth %d",lpDraw->dCaps.ulDepth));
+          BltSolid  = NULL;
+          ColorConv = NULL;
+          ColorFill = NULL;
+          break;
+      }
+      break;
+    case 24:
+      switch(lpDraw->dCaps.ulDepth)
+      {
+        case 8:
+          BltSolid  = &BltSolid24to8;
+          ColorConv = &Conv24to8;
+          ColorFill = &Fill24on8;
+          break;
+        case 16:
+          BltSolid  = &BltSolid24to16;
+          ColorConv = &Conv24to16;
+          ColorFill = &Fill24on16;
+          break;
+        case 24:
+          BltSolid  = &BltSolid24to24;
+          ColorConv = NULL;
+          ColorFill = &Fill24on24;
+          break;
+        case 32:
+          BltSolid  = &BltSolid24to32;
+          ColorConv = &Conv24to32;
+          ColorFill = &Fill24on32;
+          break;
+        default:
+          dprintf(("DDRAW: Unsupported System ColorDeapth %d",lpDraw->dCaps.ulDepth));
+          BltSolid  = NULL;
+          ColorConv = NULL;
+          ColorFill = NULL;
+          break;
+      }
+      break;
+    case 32:
+      switch(lpDraw->dCaps.ulDepth)
+      {
+        case 8:
+          BltSolid  = &BltSolid32to8;
+          ColorConv = &Conv32to8;
+          ColorFill = &Fill32on8;
+          break;
+        case 16:
+          BltSolid  = &BltSolid32to16;
+          ColorConv = &Conv32to16;
+          ColorFill = &Fill32on16;
+          break;
+        case 24:
+          BltSolid  = &BltSolid32to24;
+          ColorConv = &Conv32to24;
+          ColorFill = &Fill32on24;
+          break;
+        case 32:
+          BltSolid  = &BltSolid32to32;
+          ColorConv = NULL;
+          ColorFill = &Fill32on32;
+          break;
+        default:
+          dprintf(("DDRAW: Unsupported System ColorDeapth %d",lpDraw->dCaps.ulDepth));
+          BltSolid  = NULL;
+          ColorConv = NULL;
+          ColorFill = NULL;
+          break;
+      }
+      break;
+    default:
+      dprintf(("DDRAW: Unsupported DX ColorDeapth %d",lpDraw->GetScreenBpp()));
+      BltSolid  = NULL;
+      ColorConv = NULL;
+      ColorFill = NULL;
+      break;
+  }
+  // hack set DDSD_CAPS if the value is other than 0
+  if( DDSurfaceDesc.ddsCaps.dwCaps)
+    DDSurfaceDesc.dwFlags |= DDSD_CAPS;
+
+  if( DDSurfaceDesc.dwFlags & DDSD_CAPS )
+  {
+    // First check if we want to create a primary surface while the ddraw object already has one
+    surfaceType = DDSurfaceDesc.ddsCaps.dwCaps;
+
+    if( surfaceType & DDSCAPS_PRIMARYSURFACE)
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: Primary surface!\n"));
+      #endif
+
+      if( lpDraw->HasPrimarySurface())
+      {
+        #ifdef DEBUG
+          dprintf(("DDRAW: Primary surface already exits!\n"));
+        #endif
+        lastError = DDERR_PRIMARYSURFACEALREADYEXISTS;
+        return;
+      }
+
+      if( (DDSurfaceDesc.dwFlags & DDSD_HEIGHT) ||
+          (DDSurfaceDesc.dwFlags & DDSD_WIDTH)  ||
+          (DDSurfaceDesc.dwFlags & DDSD_PIXELFORMAT)
+        )
+      {
+        // Dx doc says passing width,height etc. for primary surface in not permitted!!
+        dprintf(("DDRAW: Invalid parameters\n\n"));
+        lastError = DDERR_INVALIDPARAMS;
+        return;
+      }
+
+      // Check if OS/2 is running in the requested colormode
+
+      diveBufNr    = DIVE_BUFFER_SCREEN;
+      if( lpDraw->dCaps.ulDepth == lpDraw->GetScreenBpp() )
+      {
+        dprintf(("DDRAW: DirectScreenAccess possible\n"));
+
+        // Yes so direct access to framebuffer is possible
+
+        pFrameBuffer = lpDraw->GetFrameBuffer();
+        pDiveBuffer  = pFrameBuffer;
+        dwPitchDB    = lpDraw->dCaps.ulScanLineBytes;
+        dwPitchFB    = dwPitchDB;
+        DDSurfaceDesc.lPitch = dwPitchDB;
+      }
+      else
+      {
+        // No so we create a virtual framebuffer which the program can access
+        // and blit to the real framebuffer on Unlock to do color conversion
+
+        dprintf( ("Need Color conversation %d => %d Bit\n",
+                  lpDraw->GetScreenBpp(),
+                  lpDraw->dCaps.ulDepth
+                ));
+
+        dwPitchFB = (lpDraw->GetScreenWidth() * lpDraw->GetScreenBpp() +7) & ~7;
+        DDSurfaceDesc.lPitch = dwPitchFB;
+
+        // 24 byte more to enable alignment and speed up blitting
+
+        pFBreal = (char*)malloc( lpDraw->GetScreenHeight() * dwPitchFB + 24);
+        pFrameBuffer = (char*)(((int)pFBreal + 7) & ~7); // align to QWORD
+
+        // DiveBuffer points to real framebuffer
+        dwPitchDB    = lpDraw->dCaps.ulScanLineBytes;
+        pDiveBuffer = lpDraw->GetFrameBuffer();
+
+      }
+
+      // Update passed in and local Surface description
+
+      #ifdef DEBUG
+        dprintf(("DDRAW: Setting up Surface\n"));
+      #endif
+      DDSurfaceDesc.dwFlags     |= DDSD_WIDTH | DDSD_HEIGHT |
+                                   DDSD_PITCH | DDSD_LPSURFACE |
+                                   DDSD_PIXELFORMAT;
+      DDSurfaceDesc.dwHeight     = lpDraw->GetScreenHeight();
+      DDSurfaceDesc.dwWidth      = lpDraw->GetScreenWidth();
+      DDSurfaceDesc.lpSurface    = pFrameBuffer;
+      DDSurfaceDesc.ddsCaps.dwCaps    |= DDSCAPS_VISIBLE;
+      lpDraw->SetPrimarySurface(TRUE);
+      DDSurfaceDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+      DDSurfaceDesc.ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC();
+      DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount = lpDraw->GetScreenBpp();
+
+      switch(DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+      {
+        case 4:
+          DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB;
+          break;
+        case 8:
+          DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB;
+          break;
+        case 16:
+          DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB;
+          DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x0000F800;
+          DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x000007E0;
+          DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x0000001F;
+          break;
+        case 24:
+        case 32:
+          DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB;
+          DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+          DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+          DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x000000FF;
+          break;
+        default:
+          // Remove the Pixelformat flag
+          DDSurfaceDesc.dwFlags    &= ~DDSD_PIXELFORMAT;
+          dprintf(("DDRAW: Unexpected BitDepth : %d\n",lpDraw->GetScreenBpp()));
+          break;
+      } // end switch
+
+      dprintf(("DDRAW: Surface set up, checking other Caps\n"));
+
+      if( DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_COMPLEX)
+      {
+        dprintf(("DDRAW: Complex Surface\n"));
+
+        if(DDSurfaceDesc.dwFlags & DDSD_BACKBUFFERCOUNT)
+        {
+          dprintf(("DDRAW: Backbuffer # = %d\n",DDSurfaceDesc.dwBackBufferCount));
+          memset( &ComplexSurfaceDesc,
+                  0,
+                  sizeof(DDSURFACEDESC2));
+
+          ComplexSurfaceDesc.dwSize  = sizeof(DDSURFACEDESC2);
+          ComplexSurfaceDesc.dwFlags = DDSD_CAPS |
+                                       DDSD_WIDTH |
+                                       DDSD_HEIGHT |
+                                       DDSD_PIXELFORMAT;
+          ComplexSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_FLIP;
+          ComplexSurfaceDesc.dwHeight = DDSurfaceDesc.dwHeight;
+          ComplexSurfaceDesc.dwWidth = DDSurfaceDesc.dwWidth;
+          ComplexSurfaceDesc.ddpfPixelFormat.dwFlags = DDSurfaceDesc.ddpfPixelFormat.dwFlags;
+          ComplexSurfaceDesc.ddpfPixelFormat.dwRBitMask = DDSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+          ComplexSurfaceDesc.ddpfPixelFormat.dwGBitMask = DDSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+          ComplexSurfaceDesc.ddpfPixelFormat.dwBBitMask = DDSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+          ComplexSurfaceDesc.ddpfPixelFormat.dwRGBBitCount = DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount;
+
+          if(DDSurfaceDesc.dwBackBufferCount>1)
+          {
+            ComplexSurfaceDesc.dwFlags |=DDSD_BACKBUFFERCOUNT;
+            ComplexSurfaceDesc.dwBackBufferCount = DDSurfaceDesc.dwBackBufferCount -1;
+            ComplexSurfaceDesc.ddsCaps.dwCaps|= DDSCAPS_COMPLEX;
+          }
+
+          BackBuffer = new OS2IDirectDrawSurface(lpDraw, &ComplexSurfaceDesc, TRUE, TRUE);
+          BackBuffer->Vtbl.AddRef((IDirectDrawSurface *)BackBuffer);
+
+          if (BackBuffer->GetLastError()==DD_OK)
+          {
+            dprintf(("DDRAW: created backbuffer"));
+            // Our Primary Buffer is also the frontbuffer of a flipchain
+            DDSurfaceDesc.ddsCaps.dwCaps    |= DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP;
+            BackBuffer->SetFrontBuffer(this);
+          }
+          else
+          {
+            dprintf(("DDRAW: Error creating backbuffer"));
+          }
+        }
+        else
+        {
+          dprintf(("DDRAW: Unsupported Complex Surface\n"));
+          #ifdef DEBUG
+            _dump_DDSCAPS(DDSurfaceDesc.dwFlags);
+          #endif
+          lastError = DDERR_OUTOFMEMORY;
+          return;
+        } //endif Backbuffer
+      } // endif DDSCAPS_COMPLEX
+
+      width  = DDSurfaceDesc.dwWidth;
+      height = DDSurfaceDesc.dwHeight;
+
+      lpDraw->pPrimSurf = this;
+
+      lastError = DD_OK;
+      return;
+    } // endif  DDSCAPS_PRIMARYSURFACE
+
+    //
+    // ToDo : Do better calulation of Bitmap Size to support the compressed Bitmaps in Dx6
+    //
+
+    if( (DDSurfaceDesc.dwFlags & DDSD_HEIGHT) &&
+        (DDSurfaceDesc.dwFlags & DDSD_WIDTH)
+      )
+
+    {
+      DWORD dwBpp;
+      DWORD dwCaps;
+      dprintf(( " Requested Size %dx%d\n",
+                DDSurfaceDesc.dwWidth,
+                DDSurfaceDesc.dwHeight));
+
+      if(DDSurfaceDesc.dwFlags & DDSD_PIXELFORMAT)         // Pixelformat passed in ?
+      {
+        dprintf(("DDRAW:  Pixelformat requested :"));
+        // YES use it
+        if(DDSurfaceDesc.ddpfPixelFormat.dwFlags & DDPF_RGB)
+        {
+          dwBpp = DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount;
+        }
+        else
+        {
+          if(DDSurfaceDesc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
+            dwBpp = 8;
+          if(DDSurfaceDesc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4)
+            dwBpp = 4;
+        }
+      }
+      else
+      {
+        dprintf(("DDRAW:  Use Screen Format :"));
+        dwBpp = lpDraw->GetScreenBpp(); // No use Screenformat
+        DDSurfaceDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+        DDSurfaceDesc.ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC();
+        DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount = dwBpp;
+        switch(DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+        {
+          case 4:
+            DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB;
+            break;
+          case 8:
+            DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB;
+            break;
+          case 16:
+            DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB;
+            DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x0000F800;
+            DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x000007E0;
+            DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x0000001F;
+            break;
+          case 24:
+          case 32:
+            DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB;
+            DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+            DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+            DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x000000FF;
+            break;
+          default:
+            // Remove the Pixelformat flag
+            DDSurfaceDesc.dwFlags    &= ~DDSD_PIXELFORMAT;
+            dprintf(("DDRAW: Unexpected BitDepth : %d\n",lpDraw->GetScreenBpp()));
+            break;
+        } // end switch
+
+      }
+
+      dprintf(("DDRAW: %d Bits\n",dwBpp));
+
+      // three possible situaltions
+      // 1. User supplied pointer to surface -> use it
+      // 2. Delayed allocation of a texture -> don't alloc
+      // 3. Normal allocation
+      // After this check for complex flag.
+
+      dwCaps = DDSurfaceDesc.ddsCaps.dwCaps;
+
+      if(DDSurfaceDesc.dwFlags & DDSD_LPSURFACE)
+      {
+        // 1.
+
+        dprintf(("DDRAW:  Usersupplied Surface\n"));
+
+        if(NULL==DDSurfaceDesc.lpSurface)
+        {
+          // pointer is NULL! Stupid user ;)
+          lastError = DDERR_INVALIDPARAMS;
+          return;
+        }
+
+        // User allocated the Buffer for the surface so we don't have to
+
+        Updated = TRUE; // Set Flag to indicate User supplied buffer so we don't free it
+
+        // As we allready copied the surface description we are done if the # of colors
+        // of the surface is the same then the screen
+
+        pFrameBuffer = (char*)DDSurfaceDesc.lpSurface;
+        diveBufNr    = -1;
+        dwPitchFB    = DDSurfaceDesc.lPitch;
+
+        if( lpDraw->dCaps.ulDepth  == dwBpp )
+        {
+          // Yes No Colorconversion is needed so point to the same buffer
+          dwPitchDB    = dwPitchFB;
+          pDiveBuffer  = pFrameBuffer;
+        }
+        else
+        {
+          // No so we must create the Divebuffer to do the color conversion
+          // and blit to the real framebuffer on Unlock to do color conversion
+
+          dwPitchDB = (DDSurfaceDesc.dwWidth * dwBytesPPDive +7) & ~7;
+
+          // 24 byte more to enable alignment and speed up blitting
+
+          pDBreal = (char*)malloc( DDSurfaceDesc.dwHeight * dwPitchDB + 24);
+          pDiveBuffer = (char*)(((int)pDBreal + 7) & ~7); // align to QWORD
+
+          // Not sure if that is ok but we need this for translation
+          // I hope no game uses YUV or such a crap
+
+          DDSurfaceDesc.ddpfPixelFormat.dwFourCC = SupportedFourCCs[dwBpp>>3];
+        }
+
+      }
+      else
+      {
+
+        if(dwCaps & DDSCAPS_ALLOCONLOAD)
+        {
+          // 2.
+
+          dprintf(("DDRAW:  Alloc on Load Texture?!\n"));
+
+          dwCaps &= ~DDSCAPS_ALLOCONLOAD; // remove flag
+
+          // only allow this flag for textures
+          if(!dwCaps & DDSCAPS_TEXTURE)
+          {
+            lastError = DDERR_INVALIDPARAMS;
+            return;
+          }
+
+          dwCaps &= ~DDSCAPS_TEXTURE; // remove flag
+          pFrameBuffer = NULL;
+          pDiveBuffer  = NULL;
+
+          // This surface isn't allocated yet, but when the texture is loaded
+          dprintf(("DDRAW: Warning : Delayed memory allocation on request\n"));
+          DDSurfaceDesc.lpSurface = NULL;
+        }
+        else
+        {
+          // 3.
+
+          dprintf(("DDRAW:  Alloc now!\n"));
+
+          DDSurfaceDesc.dwFlags      = DDSurfaceDesc.dwFlags;
+
+          dwPitchFB = DDSurfaceDesc.dwWidth * (dwBpp<8?1:dwBpp/8);
+          dwPitchFB = (dwPitchFB +7) & ~7;  // Align on QWords
+          DDSurfaceDesc.lPitch = dwPitchFB;
+          #ifdef DEBUG
+            if(dwBpp<8)
+            {
+              dprintf(("DDRAW: 1 or 4 Bit Surface encountered may not work !"));
+            }
+          #endif
+
+
+          // 24 byte more to enable alignment and speed up blitting
+
+          pFBreal = (char*)malloc( DDSurfaceDesc.dwHeight * dwPitchFB + 24);
+
+          if(NULL==pFBreal)
+          {
+            lastError = DDERR_OUTOFMEMORY;
+            return;
+          }
+
+          pFrameBuffer = (char*)(((int)pFBreal + 7) & ~7); // align to QWORD
+
+          dprintf(("DDRAW:  Framebuffer @ %08X QWAligned @ %08X with a Pitch of %d\n",
+                    pFBreal, pFrameBuffer, dwPitchFB));
+
+          DDSurfaceDesc.lpSurface    = pFrameBuffer;
+
+          if( (lpDraw->dCaps.ulDepth ) == dwBpp )
+          {
+            dprintf(("DDRAW:  No CC_Buffer needed\n"));
+            // Yes => No Colorconversion is needed so point to the same buffer
+            pDiveBuffer  = pFrameBuffer;
+            dwPitchDB = dwPitchFB;
+          }
+          else
+          {
+            dwPitchDB = (DDSurfaceDesc.dwWidth * (lpDraw->dCaps.ulDepth/8) +7) & ~7;
+            dprintf( ("DDRAW:  Alloc CCBuf with malloc (%dx%d) Pitch %d ",
+                      DDSurfaceDesc.dwHeight,
+                      DDSurfaceDesc.dwWidth,
+                      dwPitchDB));
+            // No so we must create the Divebuffer to do the colortranslation
+            // and blit to the real framebuffer on Unlock to do color conversion
+            pDBreal = (char*)malloc( DDSurfaceDesc.dwHeight *
+                                     dwPitchDB + 24);
+            pDiveBuffer = (char*)(((int)pDBreal + 7) & ~7); // align to QWORD
+            dprintf(( " @ %08X\n", pDiveBuffer));
+
+          }
+
+          if(Mainchain)
+          {
+            diveBufNr = 0;
+            rc = DiveAllocImageBuffer( hDive,
+                                       &diveBufNr,
+                                       lpDraw->dCaps.fccColorEncoding,
+                                       DDSurfaceDesc.dwWidth,
+                                       DDSurfaceDesc.dwHeight,
+                                       dwPitchDB,
+                                       (PBYTE)pDiveBuffer);
+             dprintf(("DDRAW: rc = 0x%08X\n",rc));
+          }
+
+        }  // end of 3rd case
+      } // End of alloc surfaces
+
+      width  = DDSurfaceDesc.dwWidth;
+      height = DDSurfaceDesc.dwHeight;
+
+      if( dwCaps & DDSCAPS_COMPLEX)
+      {
+        // remove the flag
+        dwCaps &= ~DDSCAPS_COMPLEX;
+        dprintf(("DDRAW: Complex Surface\n"));
+
+        if(DDSurfaceDesc.dwFlags & DDSD_BACKBUFFERCOUNT)
+        {
+          dprintf(("DDRAW: Backbuffer # = %d\n",DDSurfaceDesc.dwBackBufferCount));
+
+          memcpy( &ComplexSurfaceDesc,
+                  &DDSurfaceDesc,
+                  sizeof(DDSURFACEDESC2));
+          ComplexSurfaceDesc.dwFlags        &= ~DDSD_BACKBUFFERCOUNT;
+          ComplexSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FLIP;        // set flip
+          ComplexSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_BACKBUFFER; // remove backbuffer
+
+          if(ComplexSurfaceDesc.dwBackBufferCount>1)
+          {
+            ComplexSurfaceDesc.dwBackBufferCount--;
+          }
+          else
+          {
+            ComplexSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
+            ComplexSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
+          }
+
+          BackBuffer = new OS2IDirectDrawSurface(lpDraw, &ComplexSurfaceDesc, TRUE, Mainchain);
+          BackBuffer->Vtbl.AddRef((IDirectDrawSurface *)BackBuffer);
+
+          if (BackBuffer->GetLastError()==DD_OK)
+          {
+            DDSurfaceDesc.dwFlags |= DDSCAPS_FLIP;
+            BackBuffer->SetFrontBuffer(this);
+          }
+
+        }
+
+        // MipMap Surfaces are handled here
+        if( (DDSurfaceDesc.dwFlags & DDSD_MIPMAPCOUNT) &&
+            (dwCaps & DDSCAPS_TEXTURE) &&
+            (dwCaps & DDSCAPS_MIPMAP) )
+        {
+          dwCaps &= ~ (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP);
+
+          dprintf(("DDRAW: Mipmpa # = %d\n",DDSurfaceDesc.dwMipMapCount));
+          memcpy( &ComplexSurfaceDesc,
+                  &DDSurfaceDesc,
+                  sizeof(DDSURFACEDESC2));
+          ComplexSurfaceDesc.dwMipMapCount = 0;
+          ComplexSurfaceDesc.dwFlags &= ~DDSD_MIPMAPCOUNT;
+
+          for(int i =0; i < DDSurfaceDesc.dwMipMapCount; i++)
+          {
+            dprintf(("DDRAW: Creating MipMap %d\n",i));
+            // Mpmaps shirnk by 2
+            ComplexSurfaceDesc.dwWidth  /= 2;
+            ComplexSurfaceDesc.dwHeight /= 2;
+
+            MipMapSurface = new OS2IDirectDrawSurface(lpDraw, &ComplexSurfaceDesc, TRUE);
+            MipMapSurface->Vtbl.AddRef((IDirectDrawSurface *)MipMapSurface);
+
+            DPA_InsertPtr( DPA_SurfaceMipMaps,
+                           DPA_GetPtrCount(DPA_SurfaceMipMaps),
+                           MipMapSurface);
+
+            if(MipMapSurface->GetLastError() != DD_OK)
+            {
+              lastError = MipMapSurface->GetLastError();
+              dprintf(("DDRAW: Attached surface creation returned error %d\n",lastError));
+              return;
+            } // Endif Errorcheck
+          } //End for(i =0; i < DDSurfaceDesc.dwMipMapCount; i++)
+        } // End of MipMaps
+
+        #if 0
+          if(DDSurfaceDesc.dwFlags)
+            dprintf(("DDRAW: Unsupported Complex Surface\n"));
+        #endif
+      } // Endif DDSCAPS_COMPLEX
+    }
+    else
+    {
+      lastError = DDERR_INVALIDPARAMS;
+    }
+  } // Endif DDCAPS is valid
+  else
+  {
+    dprintf(("DDRAW: CAPS not valid\n"));
+    lastError = DDERR_INVALIDPARAMS;
+  }
+  #ifdef DEBUG
+    dprintf(("DDRAW: Buf %X Screen Caps (%d,%d), bitcount %d\n\n", this, lpDraw->GetScreenHeight(), lpDraw->GetScreenWidth(),
+    lpDraw->dCaps.ulDepth));
+    if(DD_OK!=lastError)
+    {
+      dprintf(("DDRAW: Some Error Check Flags\n"));
+      _dump_DDSCAPS(DDSurfaceDesc.dwFlags);
+    }
+  #endif
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT OS2IDirectDrawSurface::DoColorFill(LPRECT lpDestRect,DWORD dwFillColor)
+{
+
+  int i, FillWidth, FillHeight, Top, Left;
+  DWORD *pPal24;
+  WORD  *pPal16;
+  #ifdef DEBUG
+    dprintf(("DDRAW: ColorFill with %08X\n", dwFillColor));
+  #endif
+
+  if(NULL!=lpDestRect)
+  {
+    dprintf(("DDRAW: Fill only Rect(%d,%d)(%d,%d)\n", lpDestRect->left, lpDestRect->top,
+             lpDestRect->right, lpDestRect->bottom));
+    FillWidth  = lpDestRect->right - lpDestRect->left;
+    FillHeight = lpDestRect->bottom - lpDestRect->top -1;
+    Top = lpDestRect->top;
+    Left = lpDestRect->left;
+  }
+  else
+  {
+    dprintf(("DDRAW: Fill all at addr "));
+    Top = 0;
+    Left = 0;
+    FillWidth  = width;
+    FillHeight = height -1;
+    //pLine = pDiveBuffer;
+  }
+  //dprintf(("DDRAW: 0x%08X (%d/%d) at\n", pLine,FillWidth,FillHeight));
+
+  // Better safe then sorry
+  if(FillHeight<=0)
+    return(DD_OK);
+
+  if(pDiveBuffer!=pFrameBuffer)
+  {
+    if( (NULL== lpDraw->pPrimSurf) ||
+        (NULL== ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette) )
+    {
+      if(!fPalInit)
+      {
+        for(DWORD i=0;i<256;i++)
+        {
+          wDefaultPalete16[i] = (DefaultPalette[i*3+2]>>3) +
+                                ((DefaultPalette[i*3+1]>>2) <<5) +
+                                ((DefaultPalette[i*3]>>3) << 11);
+          dwDefaultPalete24[i]= ((DefaultPalette[i*3+2]>>3) <<8)+
+                                ((DefaultPalette[i*3+1]>>2) <<16) +
+                                ((DefaultPalette[i*3]>>3) << 24);
+          dprintf(( " # %d : RGB=%02X/%02X/%02X => %04X\n",
+                    i,
+                    DefaultPalette[i*3],
+                    DefaultPalette[i*3+1],
+                    DefaultPalette[i*3+2],
+                    wDefaultPalete16[i]));
+         // aPal24[i] = (lpColorTable[i].peBlue <<8) +
+         //             (lpColorTable[i].peGreen<<16) +
+         //             (lpColorTable[i].peRed<<24);
+        }
+        fPalInit = TRUE;
+      }
+      pPal16 = &wDefaultPalete16[0];
+      pPal24 = &dwDefaultPalete24[0];
+    }
+    else
+    {
+      pPal16 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal16;
+      pPal24 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal24;
+    }
+  }
+
+  if(NULL!=ColorFill)
+    ColorFill( pDiveBuffer, pFrameBuffer, Top, Left,
+              FillWidth, FillHeight, dwPitchDB,dwPitchFB,
+              dwFillColor,(16==lpDraw->dCaps.ulDepth)?(VOID*)pPal16:(VOID*)pPal24);
+  else
+  {
+    dprintf(("DDRAW: ColorFill function is NULL!!"));
+  }
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+void OS2IDirectDrawSurface::ColorConversion(LPRECT lpRect)
+{
+  //char *pSrc,*pDst,*pSLine,*pDLine;
+  DWORD CCwidth,CCheight,x,y;
+  DWORD *pPal24;
+  WORD  *pPal16;
+
+  if( (NULL== lpDraw->pPrimSurf) ||
+      (NULL== ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette) )
+  {
+    if(!fPalInit)
+    {
+      for(DWORD i=0;i<256;i++)
+      {
+          wDefaultPalete16[i] = (DefaultPalette[i*3+2]>>3) +
+                                ((DefaultPalette[i*3+1]>>2) <<5) +
+                                ((DefaultPalette[i*3]>>3) << 11);
+          dwDefaultPalete24[i]= ((DefaultPalette[i*3+2]>>3) <<8)+
+                                ((DefaultPalette[i*3+1]>>2) <<16) +
+                                ((DefaultPalette[i*3]>>3) << 24);
+        dprintf(( " # %d : RGB=%02X/%02X/%02X => %04X\n",
+                  i,
+                  DefaultPalette[i*3],
+                  DefaultPalette[i*3+1],
+                  DefaultPalette[i*3+2],
+                  wDefaultPalete16[i]));
+       // aPal24[i] = (lpColorTable[i].peBlue <<8) +
+       //             (lpColorTable[i].peGreen<<16) +
+       //             (lpColorTable[i].peRed<<24);
+      }
+      fPalInit = TRUE;
+    }
+    pPal16 = &wDefaultPalete16[0];
+    pPal24 = &dwDefaultPalete24[0];
+  }
+  else
+  {
+    pPal16 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal16;
+    pPal24 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal24;
+  }
+
+  if(NULL==lpRect)
+  {
+    //pSrc = pFrameBuffer;
+    //pDst = pDiveBuffer;
+    CCwidth  = width;
+    CCheight = height;
+    x = 0;
+    y = 0;
+  }
+  else
+  {
+    // ToDo: Check why the top/bottom values come in swaped here
+    // for now simply reverse them with the following 3 lines
+    y = lpRect->top;
+    lpRect->top = lpRect->bottom;
+    lpRect->bottom = y;
+    // end of hack
+  #if 0
+    pSrc = pFrameBuffer +
+           (lpRect->top * dwPitchFB) +
+           (lpRect->left* (lpDraw->dCaps.ulDepth/8));
+    pDst = pDiveBuffer +
+           (lpRect->top * dwPitchDB) +
+           (lpRect->left* dwBytesPPDive);
+  #endif
+    y = lpRect->top;
+    x = lpRect->left;
+    CCwidth  = lpRect->right - lpRect->left;
+    CCheight = lpRect->bottom - lpRect->top;
+
+  }
+
+//  dprintf( ("H: %d W: %d\n SRC @ %08X\n DST @ %08X\n",
+//            CCheight, CCwidth, pSrc,pDst));
+  if(NULL!=ColorConv)
+    ColorConv( pDiveBuffer, pFrameBuffer, y, x,
+               CCwidth, CCheight, dwPitchDB,dwPitchFB,
+               16==lpDraw->dCaps.ulDepth?(VOID*)pPal16:(VOID*)pPal24);
+  else
+  {
+    dprintf(("DDRAW: ColorConv function is NULL!!"));
+  }
+
+/*
+  pSLine = pSrc;
+  pDLine = pDst;
+
+  switch(lpDraw->dCaps.ulDepth)
+  {
+    case 8:
+      dprintf(("DDRAW:  8Bit target CC not implemented\n"));
+      break;
+    case 15:
+      dprintf(("DDRAW:  15 Bit not implemented using 16bit might look ugly\n"));
+    case 16:
+      if(8==lpDraw->GetScreenBpp())
+      {
+        dprintf(("DDRAW: 8->16Bit CC\n"));
+        for(y=0;CCheight;CCheight--,y++)
+        {
+          for(x=0;x<width;x++)
+          {
+            *(((WORD*)pDLine)+x) = pPal16[pSLine[x]];
+
+          }
+          pSLine += dwPitchFB;
+          pDLine += dwPitchDB;
+        }
+      }
+      else
+      {
+        dprintf(("DDRAW: %d ->16Bit Not implemented",lpDraw->GetScreenBpp()));
+      }
+      break;
+    case 24:
+      if(8==lpDraw->GetScreenBpp())
+      {
+        dprintf(("DDRAW: 8->24Bit CC"));
+        for(y=0;CCheight;CCheight--,y++)
+        {
+          char *pIter;
+          for(x=0,pIter=pDLine;x<width;x++,pIter=pDLine)
+          {
+            *((DWORD*)pIter) = pPal24[pSLine[x]];
+            pIter+=3;
+          }
+          pSLine += dwPitchFB;
+          pDLine += dwPitchDB;
+        }
+      }
+      else
+      {
+        dprintf(("DDRAW: %d ->24Bit Not implemented",lpDraw->GetScreenBpp()));
+      }
+      break;
+    case 32:
+      if(8==lpDraw->GetScreenBpp())
+      {
+        dprintf(("DDRAW: 8->32Bit CC"));
+        for(y=0;CCheight;CCheight--,y++)
+        {
+          for(x=0;x<width;x++)
+          {
+            *(((DWORD*)pDLine)+x) = pPal24[pSLine[x]];
+
+          }
+          pSLine += dwPitchFB;
+          pDLine += dwPitchDB;
+        }
+      }
+      else
+      {
+        dprintf(("DDRAW: %d ->32Bit Not implemented",lpDraw->GetScreenBpp()));
+      }
+      break;
+    default:
+      #ifdef DEBUG
+        dprintf( ("Unexpected Screen Bitdepth %d\n",
+                  lpDraw->dCaps.ulDepth));
+      #endif
+      break;
+  }
+*/
+}
+//******************************************************************************
+//******************************************************************************
+// Internal callbacks uses by destructor
+INT CALLBACK DestroyRects(LPVOID lpItem, DWORD dwRes)
+{
+  DDRectangle *pItem = (DDRectangle*) lpItem;
+  delete(pItem);
+  return 1;
+}
+
+INT CALLBACK ReleaseSurfaces(LPVOID lpItem, DWORD dwRes)
+{
+  OS2IDirectDrawSurface *pSurf;
+  pSurf = (OS2IDirectDrawSurface *)lpItem;
+  pSurf->Vtbl.Release(pSurf);
+  return 1;
+}
+//******************************************************************************
+//******************************************************************************
+
+OS2IDirectDrawSurface::~OS2IDirectDrawSurface()
+{
+  OS2IDirectDrawSurface  *AttachedSurface;
+
+
+  if(DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
+  {
+    lpDraw->SetPrimarySurface(FALSE);
+    if(lpPalette)
+      lpPalette->RestorePhysPalette();
+
+  }
+  else
+  {
+    if( diveBufNr != -1)
+    {
+      if(fLocked)
+        DiveEndImageBufferAccess(hDive, diveBufNr);
+      DiveFreeImageBuffer(hDive, diveBufNr);
+
+    }
+
+    fLocked = FALSE;
+    diveBufNr = -1;
+  }
+  // Free Buffers if they have been allocated
+  // DIVE Buffer
+
+  if(NULL!=pDBreal)
+    free(pDBreal);
+
+  // FrameBuffer
+
+  if(NULL!=pFBreal)
+    free(pFBreal);
+
+  // Clear the list of locked rectangles
+  if (DPA_GetPtrCount(DPA_LockedRects)>0)
+  {
+    DPA_DestroyCallback( DPA_LockedRects,
+                         DestroyRects,
+                         0);
+  }
+
+  if(lpClipper)
+  {
+    lpClipper->Vtbl.Release((IDirectDrawClipper*)lpClipper);
+    lpClipper = NULL;
+  }
+
+  if(lpPalette)
+  {
+    lpPalette->Vtbl.Release((IDirectDrawPalette*)lpPalette);
+    lpPalette = NULL;
+  }
+
+  if(hbmImage)
+    DeleteObject(hbmImage);
+
+  if(hdcImage)
+    DeleteDC(hdcImage);
+
+  if (NULL!=BackBuffer)
+    BackBuffer->Vtbl.Release(BackBuffer);
+
+  if (DPA_GetPtrCount(DPA_SurfaceMipMaps)>0)
+  {
+    DPA_DestroyCallback( DPA_SurfaceMipMaps,
+                         ReleaseSurfaces,
+                         0);
+  }
+
+  if (DPA_GetPtrCount(DPA_SurfaceAttached)>0)
+  {
+    DPA_DestroyCallback( DPA_SurfaceAttached,
+                         ReleaseSurfaces,
+                         0);
+  }
+
+  lpDraw->Vtbl.Release(lpDraw);
+
+}
+//******************************************************************************
+//******************************************************************************
+inline  void OS2IDirectDrawSurface::SetFrontBuffer( OS2IDirectDrawSurface* NewFBuffer)
+{
+  FrontBuffer = NewFBuffer;
+  if (NULL==NewFBuffer)
+  {
+
+    dprintf(("DDRAW: Remove Frontbuffer\n"));
+
+    // The real Frontbuffer was removed check if I'm now the one
+    if(NULL!=BackBuffer)
+    {
+      dprintf(("DDRAW: We have the a backbuffer so we're the Frontbuffer\n"));
+      NextFlip = BackBuffer;
+      DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_BACKBUFFER;
+      DDSurfaceDesc.ddsCaps.dwCaps |=  DDSCAPS_FRONTBUFFER;
+      BackBuffer->SetFrontBuffer(this);
+    }
+    else
+    {
+      // Flipchain is destroyed
+      dprintf(("DDRAW: No longer part of a flipchain\n"));
+      DDSurfaceDesc.ddsCaps.dwCaps &= ~(DDSCAPS_BACKBUFFER | DDSCAPS_FLIP);
+    }
+  }
+  else
+  {
+    dprintf(("DDRAW: Set new Frontbuffer to 0x%08X\n",NewFBuffer));
+    if(NULL==NewFBuffer->GetFrontBuffer())
+    {
+      dprintf(("DDRAW: We're the 1st backbuffer\n"));
+      DDSurfaceDesc.ddsCaps.dwCaps |=  DDSCAPS_BACKBUFFER | DDSCAPS_FLIP;
+      FrontBuffer->NextFlip = this;
+    }
+    else
+    {
+      dprintf(("DDRAW: We are oe of many buffers\n"));
+      DDSurfaceDesc.ddsCaps.dwCaps &=  ~DDSCAPS_BACKBUFFER ;
+      DDSurfaceDesc.ddsCaps.dwCaps |=  DDSCAPS_FLIP;
+    }
+
+    if(NULL!=BackBuffer)
+      BackBuffer->SetFrontBuffer(this);
+
+    DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
+  }
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
+{
+  // ToDo: Add Interface handling for D3D Textures
+  HRESULT rc;
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  dprintf(("DDRAW: OS2IDirectDrawSurface::SurfQueryInterface\n"));
+
+  if(NULL==ppvObj)
+  {
+    rc = DDERR_INVALIDPARAMS;
+    goto RetFn;
+  }
+
+  rc = E_NOINTERFACE;
+  *ppvObj = NULL;
+
+  if(IsEqualGUID(riid, IID_IDirectDrawSurface))
+  {
+    *ppvObj = &me->Vtbl2;  // ToDo DO a real V1 table
+    rc = DD_OK;
+    goto RetFn;
+  }
+  if(IsEqualGUID(riid, IID_IDirectDrawSurface2))
+  {
+    *ppvObj = &me->Vtbl2;
+    rc = DD_OK;
+    goto RetFn;
+  }
+  if(IsEqualGUID(riid, IID_IDirectDrawSurface3))
+  {
+    *ppvObj = &me->Vtbl3;
+    rc = DD_OK;
+    goto RetFn;
+  }
+  if(IsEqualGUID(riid, IID_IDirectDrawSurface4))
+  {
+    *ppvObj = This;
+    rc =DD_OK;
+  }
+
+  //if(IsEqualGUID(riid, IID_IUnknown)) ...
+
+RetFn:
+
+  if(DD_OK==rc)
+    SurfAddRef(This);
+
+  return(rc);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall SurfAddRef(THIS This)
+{
+ OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawSurface::SurfAddRef %d\n", me->Referenced+1));
+  #endif
+
+  return ++me->Referenced;
+}
+//******************************************************************************
+//******************************************************************************
+ULONG __stdcall SurfRelease(THIS This)
+{
+ OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: OS2IDirectDrawSurface::SurfRelease %d\n", me->Referenced-1));
+    dprintf(("DDRAW: OS2IDirectDrawSurface::Surface %X\n", me));
+  #endif
+  if(me->Referenced)
+  {
+    me->Referenced--;
+    if(me->Referenced == 0)
+    {
+      delete( me);
+      #ifndef __WATCOMC__
+        //_interrupt(3);
+      #endif
+      return(0);
+    }
+    else
+      return me->Referenced;
+  }
+  else
+    return(0);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfAddAttachedSurface(THIS This, LPDIRECTDRAWSURFACE2 lpDDSurface)
+{
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfAddAttachedSurface\n"));
+  #endif
+  return SurfAddAttachedSurface4(This, (LPDIRECTDRAWSURFACE4)lpDDSurface);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfAddAttachedSurface3(THIS This, LPDIRECTDRAWSURFACE3 lpDDSurface)
+{
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfAddAttachedSurface\n"));
+  #endif
+  return SurfAddAttachedSurface4(This, (LPDIRECTDRAWSURFACE4)lpDDSurface);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfAddAttachedSurface4(THIS This, LPDIRECTDRAWSURFACE4 lpDDSurface)
+{
+  OS2IDirectDrawSurface *AttachedSurface;
+  OS2IDirectDrawSurface *BBCursor;
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfAddAttachedSurface4\n"));
+  #endif
+
+  if (NULL==lpDDSurface)
+    return DDERR_INVALIDPARAMS;
+
+  AttachedSurface = (OS2IDirectDrawSurface*) lpDDSurface;
+
+  if(AttachedSurface->IsImplicitSurface())
+  {
+    #ifdef DEBUG
+     dprintf(("DDRAW: Internal : Can't attach an implicit created surface to an other surface\n"));
+    #endif
+    return(DDERR_CANNOTATTACHSURFACE);
+  }
+
+  if(This == AttachedSurface)
+  {
+    #ifdef DEBUG
+     dprintf(("DDRAW: Can't attach an surface to itself\n"));
+    #endif
+    return(DDERR_CANNOTATTACHSURFACE);
+  }
+
+  if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_TEXTURE)
+  {
+    if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
+    {
+      if(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
+      {
+          rc = DPA_InsertPtr( me->DPA_SurfaceMipMaps,
+                              DPA_GetPtrCount(me->DPA_SurfaceMipMaps),
+                              AttachedSurface);
+
+        if( rc>=0)
+        {
+          me->DDSurfaceDesc.dwFlags |= DDSD_MIPMAPCOUNT;
+          me->DDSurfaceDesc.dwMipMapCount++;
+
+          AttachedSurface->Vtbl.AddRef(AttachedSurface);
+        }
+        else
+        {
+          #ifdef DEBUG
+            dprintf(("DDRAW: Internal : Error attaching to MipMap\n"));
+          #endif
+          return(DDERR_CANNOTATTACHSURFACE);
+        }
+      }
+      else
+      {
+        #ifdef DEBUG
+          dprintf(("DDRAW: Target Surface isn't a MipMap\n"));
+        #endif
+        return(DDERR_CANNOTATTACHSURFACE);
+      }
+    }
+    else
+    {
+        rc = DPA_InsertPtr( me->DPA_SurfaceAttached,
+                            DPA_GetPtrCount(me->DPA_SurfaceAttached),
+                            AttachedSurface);
+
+      if(rc>=0)
+      {
+        AttachedSurface->Vtbl.AddRef(AttachedSurface);
+      }
+      else
+      {
+        #ifdef DEBUG
+          dprintf(("DDRAW: Internal : Error attaching to general Set\n"));
+        #endif
+        return(DDERR_CANNOTATTACHSURFACE);
+      }
+    }
+  } // endif DDSCAPS_TEXTURE
+  else
+  {
+    if( (AttachedSurface->DDSurfaceDesc.dwWidth != me->DDSurfaceDesc.dwWidth)
+        || (AttachedSurface->DDSurfaceDesc.dwHeight != me->DDSurfaceDesc.dwHeight)
+    //    || (AttachedSurface->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount !=
+    //        me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+       )
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: Surfaces don't have same dimensions\n"));
+      #endif
+      return(DDERR_CANNOTATTACHSURFACE);
+    }
+    else
+    {
+      if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_BACKBUFFER)
+      {
+        if( (AttachedSurface->GetFrontBuffer()!=NULL) || (AttachedSurface->BackBuffer!= NULL))
+        {
+          #ifdef DEBUG
+            dprintf(("DDRAW: Surfaces already has a front/backbuffer\n"));
+          #endif
+          return(DDERR_SURFACEALREADYATTACHED);
+        }
+
+        if(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
+        {
+          if(NULL!=me->BackBuffer)
+          {
+            BBCursor = me->BackBuffer;
+            while(NULL!=BBCursor)
+            {
+              BBCursor->DDSurfaceDesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
+              BBCursor->DDSurfaceDesc.dwBackBufferCount++;
+              BBCursor->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
+              BBCursor = BBCursor->BackBuffer;
+            }
+            BBCursor->BackBuffer = AttachedSurface;
+            AttachedSurface->SetFrontBuffer(BBCursor);
+          }
+          else
+          {
+            me->BackBuffer = AttachedSurface;
+            AttachedSurface->SetFrontBuffer(me);
+          }
+          me->DDSurfaceDesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
+          me->DDSurfaceDesc.dwBackBufferCount++;
+          me->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
+
+          AttachedSurface->Vtbl.AddRef(AttachedSurface);
+          return (DD_OK);
+        }
+        else
+        {
+          #ifdef DEBUG
+            dprintf(("DDRAW: Can't attach backbuffer to anything but a frontbuffer\n"));
+          #endif
+         return(DDERR_CANNOTATTACHSURFACE);
+        }
+      }
+      else
+      {
+        if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
+        {
+          if(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
+          {
+            if( DPA_InsertPtr( me->DPA_SurfaceMipMaps,
+                               DPA_GetPtrCount(me->DPA_SurfaceMipMaps),
+                               AttachedSurface) >=0)
+            {
+              me->DDSurfaceDesc.dwFlags |= DDSD_MIPMAPCOUNT;
+              me->DDSurfaceDesc.dwMipMapCount++;
+              me->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER;
+
+              AttachedSurface->Vtbl.AddRef(AttachedSurface);
+            }
+            else
+            {
+              #ifdef DEBUG
+                dprintf(("DDRAW: Internal : Error attaching to MipMap\n"));
+              #endif
+              return(DDERR_CANNOTATTACHSURFACE);
+            }
+          }
+          else
+          {
+            #ifdef DEBUG
+              dprintf(("DDRAW: Tagget Surface isn't a MipMap\n"));
+            #endif
+           return(DDERR_CANNOTATTACHSURFACE);
+          }
+        }
+        else
+        {
+          if( DPA_InsertPtr( me->DPA_SurfaceAttached,
+                             DPA_GetPtrCount(me->DPA_SurfaceAttached),
+                             AttachedSurface) >=0)
+          {
+            AttachedSurface->Vtbl.AddRef(AttachedSurface);
+          }
+          else
+          {
+            #ifdef DEBUG
+              dprintf(("DDRAW: Internal : Error attaching to general Set\n"));
+            #endif
+            return(DDERR_CANNOTATTACHSURFACE);
+          }
+        }
+      }// End if not DDSCAPS_BACKBUFFER
+    }
+  }
+  dprintf(("DDRAW: Surface attached\n"));
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfAddOverlayDirtyRect(THIS, LPRECT)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfAddOverlayDirtyRect Not implemented by M$ in V 6.0! \n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfBlt(THIS This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE2 lpDDSrcSurface,
+        LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
+{
+ return SurfBlt4( This,
+                  lpDestRect,
+                  (LPDIRECTDRAWSURFACE4)lpDDSrcSurface,
+                  lpSrcRect,
+                  dwFlags,
+                  lpDDBltFx);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfBlt3(THIS This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE3 lpDDSrcSurface,
+        LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
+{
+ return SurfBlt4( This,
+                  lpDestRect,
+                  (LPDIRECTDRAWSURFACE4)lpDDSrcSurface,
+                  lpSrcRect,
+                  dwFlags,
+                  lpDDBltFx);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfBlt4(THIS This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE4 lpDDSrcSurface,
+        LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
+{
+   // We have determine between 3 different blit senarios.
+   // 1. Blitting between Divebuffers (Front/Backbuffer and primary surface)
+   // 2. Blitting between memory and Divebuffers (Front/Backbuffer and primary surface).
+   // 3. Blitting between memory buffers.
+   // 1 and 3 are easy. DiveBlitImage or memcpy will do the job for non transparent blits
+   // 2 is now also easy as we do colorconverion via Dive after each unlocking of a surface
+   // The advantage is that we don't have to call DiveSetupBlitter each time. The Blitter will be
+   // setup only when the screen resolution is changed by ddraw. I guess we should see a big performance
+   // increase by doing it this way, unless the software blits directly from memory to the primary surface)
+   // But even then this could be faster as the SetupBlitter call is timeconsumeing and DIVE does emulate
+   // the blit in SW anyway as there is no interface in the driver to blit with HW support from the sysmem.
+
+ OS2IDirectDrawSurface *dest = (OS2IDirectDrawSurface *)This;
+ OS2IDirectDrawSurface *src  = (OS2IDirectDrawSurface *)lpDDSrcSurface;
+
+ HRESULT                rc;
+ ULONG                  ulColor, *pColor;
+ RECTL                  cliprect;
+
+ int                    x, y, i, j, BlitWidth, BlitHeight;
+ PALETTEENTRY           SysPal[257];
+ PLOGPALETTE            pLogPal = (PLOGPALETTE) SysPal;
+ char                   *pBltPos, *pSrcPos;
+ DDSURFACEDESC2         DestSurfaceDesc, SrcSurfaceDesc;
+ DDRectangle             *pIRectDest,*pIRectSrc,*pIRectTest;
+ RECTL                  DestRect, SrcRect;
+ BOOL Found;
+ DWORD dwSrcColor, dwDestColor;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfBlt4 To Surf %08X, from Surf %08X\n",dest,src));
+    if ( (NULL!=lpDestRect)&& (NULL!=lpSrcRect))
+      dprintf(("DDRAW: SurfBlt4 to (%d,%d)(%d,%d) at %08X from (%d,%d)(%d,%d) at %08X\n", lpDestRect->left, lpDestRect->top,
+               lpDestRect->right, lpDestRect->bottom, dest, lpSrcRect->left, lpSrcRect->top,
+               lpSrcRect->right, lpSrcRect->bottom, src));
+
+    _dump_DDBLT(dwFlags);
+  #endif
+
+
+  if (NULL!=lpDestRect)
+  {
+    // HACK: RA does pss in negative values we might be better etrun an error,
+    //for now we clip
+#define RA_HACK 1
+
+#ifdef RA_HACK
+    int top,left,bottom,right;
+
+    top    = lpDestRect->top;
+    left   = lpDestRect->left;
+    bottom = lpDestRect->bottom;
+    right  = lpDestRect->right;
+
+    if(top<0)
+    {
+      bottom += top;
+      top = 0;
+    }
+
+    if(top > dest->height)
+      return DDERR_INVALIDPARAMS;
+
+    if(bottom<0)
+      return DDERR_INVALIDPARAMS;
+
+    if(bottom>dest->height)
+      bottom=dest->height;
+
+    if(left<0)
+    {
+      right += left;
+      left = 0;
+    }
+
+    if(left>dest->width)
+      return DDERR_INVALIDPARAMS;
+
+    if(right<0)
+      return DDERR_INVALIDPARAMS;
+
+    if(right>dest->width)
+       right = dest->width;
+#endif    // RA_HACK
+
+    pIRectDest = new DDRectangle( top,
+                                  left,
+                                  bottom,
+                                  right);
+#ifdef RA_HACK
+    DestRect.top    = top;
+    DestRect.left   = left;
+    DestRect.bottom = bottom;
+    DestRect.right  = right;
+#else
+    memcpy(&DestRect,lpDestRect,sizeof(RECTL) );
+#endif //RA_HACK
+  }
+  else
+  {
+    pIRectDest = new DDRectangle( 0, 0, dest->height, dest->width);
+    DestRect.top    = 0;
+    DestRect.left   = 0;
+    DestRect.bottom = dest->height;
+    DestRect.right  = dest->width;
+  }
+
+  if(dest->fLocked)
+  {
+    if (NULL==lpDestRect)
+    {
+      // If anything is locked we can't blit to the complete surface as
+      // a part is locked
+      Found = TRUE;
+    }
+    else
+    {
+      // If the dest Rectangle intersects with any of the locked rectangles
+      // we can't blit to it
+
+      Found = FALSE;
+      i=0;
+      while( (i<DPA_GetPtrCount(dest->DPA_LockedRects))  && !Found)
+      {
+        pIRectTest = (DDRectangle*) DPA_FastGetPtr(dest->DPA_LockedRects,i);
+        Found = pIRectDest->intersects(*pIRectTest);
+        i++;
+      }
+
+    }
+
+    if (Found)
+    {
+      delete pIRectDest;
+      dprintf(("DDRAW: Blt: Dest Surface partly locked\n"));
+      return(DDERR_SURFACEBUSY);
+    }
+  }
+
+  DestSurfaceDesc.dwSize = sizeof(DDSURFACEDESC2);
+  SrcSurfaceDesc.dwSize = sizeof(DDSURFACEDESC2);
+
+  // First check the simple first
+
+  dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC); // FIXME: can't handle right now
+
+  if(dwFlags & DDBLT_COLORFILL)
+  {
+    dprintf(("DDRAW: ColorFill\n"));
+    if((NULL==lpDDBltFx)||(lpDDBltFx->dwSize!=sizeof(DDBLTFX)) )
+      return DDERR_INVALIDPARAMS;
+
+    dest->DoColorFill(lpDestRect,lpDDBltFx->dwFillColor);
+
+    return(DD_OK); // according to the M$ DDK only one flag shall/can be set.
+  } // end of colorfill
+
+  if (dwFlags & DDBLT_DEPTHFILL)
+  {
+    dprintf(("DDRAW: DepthFill\n"));
+  #ifdef USE_OPENGL
+    GLboolean ztest;
+    // Todo support more than one Z-Buffer
+    // Clears the screen
+    dprintf(("DDRAW: Filling depth buffer with %ld\n", lpbltfx->b.dwFillDepth));
+    glClearDepth(lpDDBltFx->b.dwFillDepth / 65535.0); // We suppose a 16 bit Z Buffer
+    glGetBooleanv(GL_DEPTH_TEST, &ztest);
+    glDepthMask(GL_TRUE); // Enables Z writing to be sure to delete also the Z buffer
+    glClear(GL_DEPTH_BUFFER_BIT);
+    glDepthMask(ztest);
+
+    return (DD_OK);
+  #endif // USE_OPENGL
+  }
+
+  if(dwFlags & DDBLT_ROP)
+  {
+    // HEL and we only support the following ROPS
+    // SRC_COPY
+    // BLACKNESS
+    // WHITENESS
+    //
+    if(lpDDBltFx->dwROP & SRCCOPY)
+      dwFlags = 0;  // srccopy is a normal fast blt
+    else
+    {
+      if(lpDDBltFx->dwROP & BLACKNESS)
+      {
+        if(1==dest->dwBytesPPDive)
+        {
+          // ToDo: Realy implement code to get the correct index for black in 8 Bitmode
+          dest->DoColorFill(lpDestRect, 0 );
+        }
+        else
+          dest->DoColorFill(lpDestRect, 0);
+        return DD_OK;
+      }
+
+      if(lpDDBltFx->dwROP & WHITENESS)
+      {
+        if(1==dest->dwBytesPPDive)
+        {
+          // ToDo: Realy implement code to get the correct index for white in 8 Bitmode
+          dest->DoColorFill(lpDestRect, 0xFFFFFFFF );
+        }
+        else
+          dest->DoColorFill(lpDestRect, 0xFFFFFFFF);
+        return (DD_OK);
+      }
+
+      return DDERR_NORASTEROPHW;
+    }
+  }
+
+  if(NULL==src)
+  {
+    dprintf(("DDRAW: Unsupported sourceless FX operation. Flags = 0x%04X\n",dwFlags));
+
+    return DD_OK;
+  }
+
+  if (NULL!=lpSrcRect)
+  {
+#ifdef RA_HACK
+    // Same as for dest rectangle now for src
+
+    int top,left,bottom,right;
+
+    top    = lpSrcRect->top;
+    left   = lpSrcRect->left;
+    bottom = lpSrcRect->bottom;
+    right  = lpSrcRect->right;
+
+    if(top<0)
+    {
+      bottom += top;
+      top = 0;
+    }
+
+    if(top > src->height)
+      return DDERR_INVALIDPARAMS;
+
+    if(bottom<0)
+      return DDERR_INVALIDPARAMS;
+
+    if(bottom>src->height)
+      bottom=src->height;
+
+    if(left<0)
+    {
+      right += left;
+      left = 0;
+    }
+
+    if(left>src->width)
+      return DDERR_INVALIDPARAMS;
+
+    if(right<0)
+      return DDERR_INVALIDPARAMS;
+
+    if(right>src->width)
+       right = src->width;
+#endif    // RA_HACK
+
+    pIRectSrc = new DDRectangle( top,
+                                 left,
+                                 bottom,
+                                 right);
+#ifdef RA_HACK
+    SrcRect.top    = top;
+    SrcRect.left   = left;
+    SrcRect.bottom = bottom;
+    SrcRect.right  = right;
+#else
+    memcpy(&SrcRect,lpSrcRect,sizeof(RECTL) );
+#endif
+  }
+  else
+  {
+    pIRectSrc = new DDRectangle( 0, 0, src->height, src->width);
+    SrcRect.top    = 0;
+    SrcRect.left   = 0;
+    SrcRect.bottom = src->height;
+    SrcRect.right  = src->width;
+  }
+
+  if(src->fLocked)
+  {
+    if (NULL==lpSrcRect)
+    {
+      // If anything is locked we can't blit from the complete surface as
+      // a part is locked
+      Found = TRUE;
+    }
+    else
+    {
+      // If the src Rectangle intersects with any of the locked rectangles of the
+      // source surface we can't blit from it
+
+      Found = FALSE;
+      i=0;
+
+      while((i<DPA_GetPtrCount(src->DPA_LockedRects) ) && !Found)
+      {
+        pIRectTest = (DDRectangle*) DPA_FastGetPtr(src->DPA_LockedRects,i);
+        Found = pIRectDest->intersects(*pIRectTest);
+        i++;
+      }
+
+    }
+
+    if (Found)
+    {
+      delete pIRectSrc;
+      dprintf(("DDRAW: Blt: Src Surface partly locked\n"));
+
+      return(DDERR_SURFACEBUSY);
+    }
+  }
+/*
+  if( ( (NULL==lpDestRect) && (NULL!=lpSrcRect) ) ||
+      ( (NULL==lpSrcRect) && (NULL!=lpDestRect) ) )
+  {
+    dprintf(("DDRAW: Blitting with scaleing\n Not supported.\n"));
+
+    return DDERR_NOSTRETCHHW;
+  }
+
+  if( ( pIRectDest->width()  != pIRectSrc->width() ) ||
+      ( pIRectDest->height() != pIRectSrc->height() )
+    )
+  {
+    // Stretching not supported
+    dprintf(("DDRAW: No stretched blits\n"));
+
+    return DDERR_NOSTRETCHHW;
+  }
+*/
+  if (dest->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
+  {
+    dprintf(("DDRAW: Dest is Primary Surface\n"));
+    if(src->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
+    {
+      // special Type 1 : Bliting between parts of the screen
+
+      dprintf(("DDRAW: Src is Primary Surface\n"));
+
+      if( *pIRectDest == *pIRectSrc)
+        return DD_OK; // rects are the same => no blit needed
+
+      // Todo: might add transparent blits but I don't think they are used here, so later!
+
+      MoveRects( dest->pDiveBuffer,
+                 (LPRECT)&DestRect,
+                 (LPRECT)&SrcRect,
+                 dest->dwBytesPPDive,
+                 dest->dwPitchDB);
+      // MoveRects in framebuufer if we use colorconversion
+      if(dest->pFrameBuffer != dest->pDiveBuffer)
+      {
+        MoveRects( dest->pFrameBuffer,
+                   (LPRECT)&DestRect,
+                   (LPRECT)&SrcRect,
+                   dest->lpDraw->GetScreenBpp()>>3,
+                   dest->dwPitchFB);
+      }
+
+      // End of Special Type 1 blitting on the screen
+    }
+    else
+    {
+      if( src->diveBufNr>0)
+      {
+        dprintf(("DDRAW: DIVE Blit of all"));
+        if( (NULL==lpSrcRect)&&( NULL== lpDestRect))
+        {
+          // No Rectangles so use Dive to blit everything
+          // ToDo : Implement transparent blitting but that seams more
+          //        inportant for partial blits.
+          //        If we do this later we could skip this check and don't
+          //        use Dive .This keeps our simpler and smaler
+          //
+          DiveBlitImage(dest->hDive, src->diveBufNr, dest->diveBufNr);
+
+        }
+      }
+
+      // Everything else we do yourselfs
+      // Type 2 Sysmem to Primarysurface ca also be handled by this
+
+      if(!dwFlags)
+      {
+        dprintf(("DDRAW: Solid Blit\n"));
+
+        dest->BltSolid( dest->pDiveBuffer,
+                        dest->pFrameBuffer,
+                        DestRect.top,
+                        DestRect.left,
+                        dest->dwPitchDB,
+                        dest->dwPitchFB,
+                        src->pDiveBuffer,
+                        src->pFrameBuffer,
+                        SrcRect.top,
+                        SrcRect.left,
+                        pIRectDest->width(),
+                        pIRectDest->height(),
+                        src->dwPitchDB,
+                        src->dwPitchFB
+                        );
+
+      }
+      else
+      {
+        pBltPos = (char*) dest->pDiveBuffer + (DestRect.top * dest->dwPitchDB) +
+                  (DestRect.left * dest->dwBytesPPDive);
+
+        pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) +
+                  (SrcRect.left * src->dwBytesPPDive);
+
+        BlitHeight = pIRectDest->height();
+        BlitWidth = pIRectDest->width();
+        // Transparent Blit
+        if( (dwFlags &DDBLT_KEYSRC) || (dwFlags & DDBLT_KEYSRCOVERRIDE) )
+        {
+          dprintf(("DDRAW: Transparent src blit not done yet for primary!!"));
+        }
+        else
+        {
+          dprintf(("DDRAW: Unhandled Flags Destination colorkey ? 0x%04X",dwFlags));
+        }
+      }
+    } // end of handling blitting to primary
+  }  // end of target primary surface
+  else
+  {
+    if(0==src->diveBufNr)
+    {
+      // copy from the screen to a buffer
+
+      if( (NULL==lpDestRect) &&
+          (NULL==lpSrcRect) &&
+          (dest->diveBufNr>0) )
+      {
+        // Blitting everything from frontbuffer to a Divebuffer
+        // ToDo: Might should add checking for flags here
+        DiveBlitImage(dest->hDive, src->diveBufNr, dest->diveBufNr);
+      }
+      else
+      {
+        // DIVE => DIVE  or Mem => Dive
+        // or a rectangle from streen to a buffer can be handelt in the same way
+        pBltPos = (char*) dest->pDiveBuffer + (DestRect.top * dest->dwPitchDB) +
+                  (DestRect.left * dest->dwBytesPPDive);
+
+        pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) +
+                  (SrcRect.left * src->dwBytesPPDive);
+
+        BlitHeight = pIRectDest->height();
+        BlitWidth = pIRectDest->width();
+
+        // Check for transparent blit
+        if(!dwFlags)
+        {
+          dest->BltSolid( dest->pDiveBuffer,
+                          dest->pFrameBuffer,
+                          DestRect.top,
+                          DestRect.left,
+                          dest->dwPitchDB,
+                          dest->dwPitchFB,
+                          src->pDiveBuffer,
+                          src->pFrameBuffer,
+                          SrcRect.top,
+                          SrcRect.left,
+                          pIRectDest->width(),
+                          pIRectDest->height(),
+                          src->dwPitchDB,
+                          src->dwPitchFB
+                          );
+        }
+        else
+        {
+          dprintf(("DDRAW: Transblt not done yet"));
+          if(dwFlags & DDBLT_KEYSRC)
+          {
+            if(!(src->DDSurfaceDesc.dwFlags & DDCKEY_SRCBLT))
+            {
+            }
+          }
+          else
+          {
+            if(dwFlags & DDBLT_KEYSRCOVERRIDE)
+            {
+            }
+            else
+            {
+            }
+          }
+        }
+      }
+    } // end handling source screen
+    else
+    {
+      // DIVE => DIVE  or Mem => Dive can be handelt in the same way
+
+      if( (src->pDiveBuffer == dest->pDiveBuffer) &&
+          (pIRectDest->intersects(*pIRectSrc) ) )
+      {
+        // Overlapping rects  on the same surface ?
+
+        // ToDo : Maybe implement all the fancy blit flags here too ? ;)
+
+        MoveRects( dest->pDiveBuffer,
+                   (LPRECT)&DestRect,
+                   (LPRECT)&SrcRect,
+                   dest->dwBytesPPDive,
+                   dest->dwPitchDB);
+
+        // MoveRects in framebuufer if we use colorconversion
+        if(dest->pFrameBuffer != dest->pDiveBuffer)
+        {
+          MoveRects( dest->pFrameBuffer,
+                     (LPRECT)&DestRect,
+                     (LPRECT)&SrcRect,
+                     dest->lpDraw->GetScreenBpp()>>3,
+                     dest->dwPitchFB);
+        }
+        return DD_OK;
+      }
+
+      // Check for transparent blit
+      if(!dwFlags)
+      {
+        dest->BltSolid( dest->pDiveBuffer,
+                        dest->pFrameBuffer,
+                        DestRect.top,
+                        DestRect.left,
+                        dest->dwPitchDB,
+                        dest->dwPitchFB,
+                        src->pDiveBuffer,
+                        src->pFrameBuffer,
+                        SrcRect.top,
+                        SrcRect.left,
+                        pIRectDest->width(),
+                        pIRectDest->height(),
+                        src->dwPitchDB,
+                        src->dwPitchFB
+                        );
+      }
+      else
+      {
+        pBltPos = (char*) dest->pDiveBuffer + (DestRect.top * dest->dwPitchDB) +
+                  (DestRect.left * dest->dwBytesPPDive);
+
+        pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) +
+                  (SrcRect.left * src->dwBytesPPDive);
+
+        BlitHeight = pIRectDest->height();
+        BlitWidth = pIRectDest->width();
+        DWORD dwPitch = dest->dwPitchDB;
+
+        if(dwFlags &DDBLT_ROTATIONANGLE)
+        {
+          return DDERR_NOROTATIONHW;
+        }
+
+        if(dwFlags & DDBLT_DDFX)
+        {
+          DWORD dwFx;
+          DWORD dwSrcColor, dwDestColor;
+
+          dwFlags &= ~DDBLT_DDFX; // remove the handled flag
+
+          if( NULL==lpDDBltFx)
+            return DDERR_INVALIDPARAMS;
+
+          dwFx = lpDDBltFx->dwDDFX;
+
+          // Remove unsupported Flags
+          dwFx &= ~(DDBLTFX_ARITHSTRETCHY |    // Not streach support
+                    DDBLTFX_ZBUFFERBASEDEST |  // All ZBuffer flags are not
+                    DDBLTFX_ZBUFFERRANGE |     // implementet in M$ Dx 6
+                    DDBLTFX_NOTEARING );       // No sync with VRetrace yet
+
+          if(dwFx & DDBLTFX_ROTATE180)
+          {
+            // 180 degree turn is a mix of a flip up/down and one left/right
+            dwFx |= (DDBLTFX_MIRRORUPDOWN | DDBLTFX_MIRRORLEFTRIGHT);
+            dwFx &= ~DDBLTFX_ROTATE180; // remove handled flag
+          }
+          if(dwFx & DDBLTFX_MIRRORUPDOWN)
+          {
+            // switching the the direction can be integrated with other flags
+            dwPitch = -dwPitch;
+            pBltPos = (char*) dest->pDiveBuffer +
+                      ((DestRect.top +BlitHeight)* dest->dwPitchDB) +
+                      (DestRect.left * dest->dwBytesPPDive);
+
+            dwFx &= ~DDBLTFX_MIRRORUPDOWN;  // remove handled flag
+          }
+
+          if(dwFx & DDBLTFX_MIRRORLEFTRIGHT)
+          {
+            // 180 degree turn or a LR Mirroring
+            // don't support any other dwFlags like transparent at the moment
+
+            switch(dest->dwBytesPPDive)
+            {
+              case 1:
+                while(BlitHeight--)
+                {
+                  x = BlitWidth;
+                  while(x)
+                  {
+                    pBltPos[BlitWidth-x] = pSrcPos[x];
+                    x--;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              case 2:
+                while(BlitHeight--)
+                {
+                  x = BlitWidth;
+                  while(x)
+                  {
+                    ((USHORT*)pBltPos)[BlitWidth-x] = ((USHORT*)pSrcPos)[x];
+                    x--;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              case 3:
+                BlitWidth *= 3;
+                while(BlitHeight--)
+                {
+                  x = BlitWidth;
+                  while(x)
+                  {
+                    pBltPos[BlitWidth-x] = pSrcPos[x-2];
+                    x--;
+                    pBltPos[BlitWidth-x] = pSrcPos[x];
+                    x--;
+                    pBltPos[BlitWidth-x] = pSrcPos[x+2];
+                    x--;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              case 4:
+                while(BlitHeight--)
+                {
+                  x = BlitWidth;
+                  while(x)
+                  {
+                    ((DWORD*)pBltPos)[BlitWidth-x] = ((DWORD*)pSrcPos)[x];
+                    x--;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+            }  // end switch
+            //if(dest->lpVtbl == dest->Vtbl4)
+            //  dest->Vtbl4->ChangeUniquenessValue(dest);
+            return DD_OK;
+          }
+
+          #ifdef DEBUG
+            if(dwFx)
+              _dump_DDBLTFX(dwFx);
+          #endif
+          // We ignore unhandled flags at the moment
+        }
+
+        if( (dwFlags & DDBLT_KEYSRC) |
+            (dwFlags & DDBLT_KEYSRCOVERRIDE) )
+        {
+          if(dwFlags & DDBLT_KEYSRCOVERRIDE)
+          {
+
+            if( NULL==lpDDBltFx)
+              return DDERR_INVALIDPARAMS;
+
+            dwFlags &= ~DDBLT_KEYSRCOVERRIDE;
+
+            // We work like the HEL and test only the low value
+            dwSrcColor = lpDDBltFx->ddckSrcColorkey.dwColorSpaceLowValue;
+
+          }
+          else
+          {
+
+            dwFlags &= ~DDBLT_KEYSRC;
+
+            // Not sure if that is OK maybe check if one is set ?
+            // if(!(src->DDSurfaceDesc.dwFlags & DDCKEY_SRCBLT)) return DDERR_WRONGPARAM;?
+
+            dwSrcColor = src->DDSurfaceDesc.ddckCKSrcBlt.dwColorSpaceLowValue;
+          }
+
+          // ToDo : We currently indicate that we don't support
+          // DDBLT_KEYDEST but HEL does change that!
+          // also add this key in the get/setColorKey functions
+
+          if( (dwFlags & DDBLT_KEYDEST) |
+              (dwFlags & DDBLT_KEYDESTOVERRIDE) )
+          {
+            // Source and dest color keying SLOW!!!
+            if(dwFlags & DDBLT_KEYDESTOVERRIDE)
+            {
+              if( NULL==lpDDBltFx)
+                return DDERR_INVALIDPARAMS;
+
+              dwFlags &= ~DDBLT_KEYDESTOVERRIDE;
+
+              // We work like the HEL and test only the low value
+              dwDestColor = lpDDBltFx->ddckDestColorkey.dwColorSpaceLowValue;
+
+            }
+            else
+            {
+
+              dwFlags &= ~DDBLT_KEYDEST;
+
+              // Not sure if that is OK maybe check if one is set ?
+              // if(!(Dest->DDSurfaceDesc.dwFlags & DDCKEY_DESTBLT)) return DDERR_WRONGPARAM;?
+
+              dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue;
+            }
+
+            // This will be be slow maybe move to ASM ?
+            // using MMX should be much faster
+            switch(dest->dwBytesPPDive)
+            {
+              case 1:
+                while(BlitHeight--)
+                {
+                  x = 0;
+                  while(x<BlitWidth)
+                  {
+                    if(pSrcPos[x] != (char) dwSrcColor)
+                    {
+                      if(pBltPos[x] != (char) dwDestColor)
+                        pBltPos[x] = pSrcPos[x];
+                    }
+                    x++;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              case 2:
+                while(BlitHeight--)
+                {
+                  x = 0;
+                  while(x<BlitWidth)
+                  {
+                    if(((USHORT*)pSrcPos)[x] != (USHORT) dwSrcColor)
+                    {
+                      if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor)
+                        ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x];
+                    }
+                    x++;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              case 3:
+              {
+                char *pSC, *pDC;
+                pSC = (char*)&dwSrcColor;
+                pDC = (char*)&dwDestColor;
+                BlitWidth *=3;
+
+                while(BlitHeight--)
+                {
+                  x = 0;
+
+                  while(x<BlitWidth)
+                  {
+                    if( (pSrcPos[x]   != pSC[1]) &&
+                        (pSrcPos[x+1] != pSC[2]) &&
+                        (pSrcPos[x+2] != pSC[3])
+                      )
+                    {
+                      if( (pBltPos[x]   != pDC[1]) &&
+                          (pBltPos[x+1] != pDC[2]) &&
+                          (pBltPos[x+2] != pDC[3])
+                        )
+                        {
+                          pBltPos[x] = pSrcPos[x];
+                          pBltPos[x+1] = pSrcPos[x+2];
+                          pBltPos[x+1] = pSrcPos[x+2];
+                        }
+                    }
+                    x +=3;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              }
+              case 4:
+                while(BlitHeight--)
+                {
+                  x = 0;
+                  while(x<BlitWidth)
+                  {
+                    if(((DWORD*)pSrcPos)[x] != dwSrcColor)
+                    {
+                      if(((DWORD*)pBltPos)[x] != dwDestColor)
+                        ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x];
+                    }
+                    x++;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+            }  // End switch
+          }
+          else
+          {
+            // This will be be slow maybe move to ASM ?
+            // using MMX should be much faster
+            switch(dest->dwBytesPPDive)
+            {
+              case 1:
+                while(BlitHeight--)
+                {
+                  x = 0;
+                  while(x<BlitWidth)
+                  {
+                    if(pSrcPos[x] != (char) dwSrcColor)
+                    {
+                      pBltPos[x] = pSrcPos[x];
+                    }
+                    x++;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              case 2:
+                while(BlitHeight--)
+                {
+                  x = 0;
+                  while(x<BlitWidth)
+                  {
+                    if(((USHORT*)pSrcPos)[x] != (USHORT) dwSrcColor)
+                    {
+                      ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x];
+                    }
+                    x++;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              case 3:
+              {
+                char *pSC, *pDC;
+                pSC = (char*)&dwSrcColor;
+                pDC = (char*)&dwDestColor;
+                BlitWidth *=3;
+
+                while(BlitHeight--)
+                {
+                  x = 0;
+
+                  while(x<BlitWidth)
+                  {
+                    if( (pSrcPos[x]   != pSC[1]) &&
+                        (pSrcPos[x+1] != pSC[2]) &&
+                        (pSrcPos[x+2] != pSC[3])
+                      )
+                    {
+                       pBltPos[x] = pSrcPos[x];
+                       pBltPos[x+1] = pSrcPos[x+2];
+                       pBltPos[x+1] = pSrcPos[x+2];
+                    }
+                    x +=3;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+              }
+              case 4:
+                while(BlitHeight--)
+                {
+                  x = 0;
+                  while(x<BlitWidth)
+                  {
+                    if(((DWORD*)pSrcPos)[x] != dwSrcColor)
+                    {
+                      ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x];
+                    }
+                    x++;
+                  }
+                  pBltPos += dwPitch;
+                  pSrcPos += src->dwPitchDB;
+                }
+                break;
+            }  // End switch
+            // Only Source colorkey
+          }
+          // if(dest->lpVtbl == dest->Vtbl4)
+          //  dest->Vtbl4->ChangeUniquenessValue(dest);
+          return DD_OK;
+        }
+
+        if( (dwFlags & DDBLT_KEYDEST) |
+            (dwFlags & DDBLT_KEYDESTOVERRIDE) )
+        {
+          // Dest color keying SLOW!!!
+          if(dwFlags & DDBLT_KEYSRCOVERRIDE)
+          {
+            if( NULL==lpDDBltFx)
+              return DDERR_INVALIDPARAMS;
+
+            dwFlags &= ~DDBLT_KEYSRCOVERRIDE;
+
+            // We work like the HEL and test only the low value
+            dwDestColor = lpDDBltFx->ddckDestColorkey.dwColorSpaceLowValue;
+
+          }
+          else
+          {
+
+            dwFlags &= ~DDBLT_KEYDEST;
+
+            // Not sure if that is OK maybe check if one is set ?
+            // if(!(src->DDSurfaceDesc.dwFlags & DDCKEY_DESTBLT)) return DDERR_WRONGPARAM;?
+
+            dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue;
+          }
+
+          // This will be be slow maybe move to ASM ?
+          // using MMX should be much faster
+          switch(dest->dwBytesPPDive)
+          {
+            case 1:
+              while(BlitHeight--)
+              {
+                x = 0;
+                while(x<BlitWidth)
+                {
+                  if(pBltPos[x] != (char) dwDestColor)
+                    pBltPos[x] = pSrcPos[x];
+                  x++;
+                }
+                pBltPos += dwPitch;
+                pSrcPos += src->dwPitchDB;
+              }
+              break;
+            case 2:
+              while(BlitHeight--)
+              {
+                x = 0;
+                while(x<BlitWidth)
+                {
+                  if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor)
+                    ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x];
+                  x++;
+                }
+                pBltPos += dwPitch;
+                pSrcPos += src->dwPitchDB;
+              }
+              break;
+            case 3:
+            {
+              char *pSC, *pDC;
+              pSC = (char*)&dwSrcColor;
+              pDC = (char*)&dwDestColor;
+              BlitWidth *=3;
+
+              while(BlitHeight--)
+              {
+                x = 0;
+
+                while(x<BlitWidth)
+                {
+                  if( (pBltPos[x]   != pDC[1]) &&
+                      (pBltPos[x+1] != pDC[2]) &&
+                      (pBltPos[x+2] != pDC[3])
+                    )
+                  {
+                    pBltPos[x] = pSrcPos[x];
+                    pBltPos[x+1] = pSrcPos[x+2];
+                    pBltPos[x+1] = pSrcPos[x+2];
+                  }
+                  x +=3;
+                }
+                pBltPos += dwPitch;
+                pSrcPos += src->dwPitchDB;
+              }
+              break;
+            }
+            case 4:
+              while(BlitHeight--)
+              {
+                x = 0;
+                while(x<BlitWidth)
+                {
+                  if( ((DWORD*)pBltPos)[x] != dwDestColor)
+                    ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x];
+                  x++;
+                }
+                pBltPos += dwPitch;
+                pSrcPos += src->dwPitchDB;
+              }
+              break;
+          }  // End switch
+        } // End of Dest ColorKey
+
+
+      }// end  handling dwFlags
+    } // End handling source not Framebuffer
+
+  }// end handling destination not framebuffer
+
+  // if(dest->lpVtbl == dest->Vtbl4)
+  //   dest->Vtbl4->ChangeUniquenessValue(dest);
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfBltBatch(THIS, LPDDBLTBATCH, DWORD, DWORD )
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfBltBatch Not implemented by M$\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfBltFast( THIS This ,
+                               DWORD dwX,
+                               DWORD dwY,
+                               LPDIRECTDRAWSURFACE2 lpDDSrcSurface,
+                               LPRECT lpSrcRect,
+                               DWORD dwTrans)
+{
+  dprintf(("DDRAW: SurfBltFast=>"));
+  return SurfBltFast4( This,
+                       dwX,
+                       dwY,
+                       (LPDIRECTDRAWSURFACE4) lpDDSrcSurface,
+                       lpSrcRect,
+                       dwTrans);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfBltFast3(THIS This ,
+                               DWORD dwX,
+                               DWORD dwY,
+                               LPDIRECTDRAWSURFACE3 lpDDSrcSurface,
+                               LPRECT lpSrcRect,
+                               DWORD dwTrans)
+{
+  dprintf(("DDRAW: SurfBltFast3=>"));
+  return SurfBltFast4( This,
+                       dwX,
+                       dwY,
+                       (LPDIRECTDRAWSURFACE4) lpDDSrcSurface,
+                       lpSrcRect,
+                       dwTrans);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfBltFast4( THIS This,
+                                DWORD dwX,
+                                DWORD dwY,
+                                LPDIRECTDRAWSURFACE4 lpDDSrcSurface,
+                                LPRECT lpSrcRect,
+                                DWORD dwTrans)
+{
+  OS2IDirectDrawSurface *dest = (OS2IDirectDrawSurface *)This;
+  OS2IDirectDrawSurface *src  = (OS2IDirectDrawSurface *)lpDDSrcSurface;
+  RECTL SrcRect;
+  char *pBltPos, *pSrcPos;
+  DWORD dwDestColor, dwSrcColor, BlitWidth, BlitHeight,x,y;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfBltFast4 %08X at(%d/%d) onto %08X with flags %08X\n",src, dwX,dwY, dest, dwTrans));
+  #endif
+
+  if( (NULL==lpDDSrcSurface) ||
+      (dwX<0) || (dwY<0) ||
+      (dwX>dest->width) ||
+      (dwY>dest->height))
+  {
+    dprintf(("DDRAW: Invalid Parameters %08X, %d %d", lpDDSrcSurface ,dest->width , dest->height));
+    return DDERR_INVALIDPARAMS;
+  }
+
+  if (NULL!=lpSrcRect)
+  {
+    memcpy(&SrcRect,lpSrcRect,sizeof(RECTL) );
+  }
+  else
+  {
+    SrcRect.top    = 0;
+    SrcRect.left   = 0;
+    SrcRect.bottom = src->height;
+    SrcRect.right  = src->width;
+  }
+
+  // Todo: Test for locked src/dest
+
+  pBltPos = (char*) dest->pDiveBuffer + (dwY * dest->dwPitchDB) +
+            (dwX * dest->dwBytesPPDive);
+
+  pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) +
+            (SrcRect.left * src->dwBytesPPDive);
+
+  BlitHeight = SrcRect.bottom - SrcRect.top;
+  BlitWidth  = (SrcRect.right - SrcRect.left) * src->dwBytesPPDive;
+
+  // Remove unsupported wait flag
+  dwTrans &= ~DDBLTFAST_WAIT;
+
+  if(DDBLTFAST_NOCOLORKEY == dwTrans )
+  {
+    dprintf(( "Solid Blit, %d bits => %d bytes per line\n",
+              (SrcRect.right - SrcRect.left),
+              BlitWidth) );
+    #ifdef USE_ASM
+      BltRec(pBltPos, pSrcPos, BlitWidth, BlitHeight,
+             dest->dwPitchDB,
+             src->dwPitchDB);
+    #else
+      // Solid Blit
+      while(1)
+      {
+        memcpy(pBltPos,pSrcPos,BlitWidth);
+        pBltPos += dest->dwPitchDB;
+        pSrcPos += src->dwPitchDB;
+        if(! (--BlitHeight))
+          break;
+      }
+    #endif
+
+  }
+  else
+  {
+    dprintf(("DDRAW: TransBlit\n"));
+
+    if(dwTrans & DDBLTFAST_SRCCOLORKEY)
+    {
+      dprintf(("DDRAW: Trans SRC\n"));
+      // transparent source
+      dwSrcColor = src->DDSurfaceDesc.ddckCKSrcBlt.dwColorSpaceLowValue;
+      if(dwTrans & DDBLTFAST_DESTCOLORKEY)
+      {
+        dprintf(("DDRAW: And Dest Colorkey"));
+        dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue;
+        // Source and dest colorkeying
+        switch(dest->dwBytesPPDive)
+        {
+          case 1:
+            while(BlitHeight--)
+            {
+              x = 0;
+              while(x<BlitWidth)
+              {
+                if(pSrcPos[x] != (char) dwSrcColor)
+                {
+                  if(pBltPos[x] != (char) dwDestColor)
+                    pBltPos[x] = pSrcPos[x];
+                }
+                x++;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+          case 2:
+            while(BlitHeight--)
+            {
+              x = 0;
+              while(x<BlitWidth)
+              {
+                if(((USHORT*)pSrcPos)[x] != (USHORT) dwSrcColor)
+                {
+                  if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor)
+                    ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x];
+                }
+                x++;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+          case 3:
+          {
+            char *pSC, *pDC;
+            pSC = (char*)&dwSrcColor;
+            pDC = (char*)&dwDestColor;
+            BlitWidth *=3;
+
+            while(BlitHeight--)
+            {
+              x = 0;
+
+              while(x<BlitWidth)
+              {
+                if( (pSrcPos[x]   != pSC[1]) &&
+                    (pSrcPos[x+1] != pSC[2]) &&
+                    (pSrcPos[x+2] != pSC[3])
+                  )
+                {
+                  if( (pBltPos[x]   != pDC[1]) &&
+                      (pBltPos[x+1] != pDC[2]) &&
+                      (pBltPos[x+2] != pDC[3])
+                    )
+                    {
+                      pBltPos[x] = pSrcPos[x];
+                      pBltPos[x+1] = pSrcPos[x+2];
+                      pBltPos[x+1] = pSrcPos[x+2];
+                    }
+                }
+                x +=3;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+          }
+          case 4:
+            while(BlitHeight--)
+            {
+              x = 0;
+              while(x<BlitWidth)
+              {
+                if(((DWORD*)pSrcPos)[x] != dwSrcColor)
+                {
+                  if(((DWORD*)pBltPos)[x] != dwDestColor)
+                    ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x];
+                }
+                x++;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+        }  // End switch
+      }
+      else
+      {
+        // This MMX detection should be moved into OS2Draw
+        // and into the surface constructor a setup for blitting pointers
+        dprintf(("DDRAW: Only Src ColorKey"));
+        switch(dest->dwBytesPPDive)
+        {
+          case 1:
+            if(CPUHasMMX())
+              while(BlitHeight--)
+              {
+                BlitColorKey8MMX((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth);
+                pBltPos += dest->dwPitchDB;
+                pSrcPos += src->dwPitchDB;
+              }
+            else
+              while(BlitHeight--)
+              {
+                BlitColorKey8((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth);
+                pBltPos += dest->dwPitchDB;
+                pSrcPos += src->dwPitchDB;
+              }
+            break;
+          case 2:
+
+            if(CPUHasMMX())
+              while(BlitHeight--)
+              {
+                BlitColorKey16MMX((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth);
+                pBltPos += dest->dwPitchDB;
+                pSrcPos += src->dwPitchDB;
+              }
+            else
+              while(BlitHeight--)
+              {
+                BlitColorKey16((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth);
+                pBltPos += dest->dwPitchDB;
+                pSrcPos += src->dwPitchDB;
+              }
+            break;
+          case 3:
+            char *pSC;
+            pSC = (char*)&dwSrcColor;
+            BlitWidth *=3;
+
+            while(BlitHeight--)
+            {
+              x = 0;
+
+              while(x<BlitWidth)
+              {
+                if( (pSrcPos[x]   != pSC[1]) &&
+                    (pSrcPos[x+1] != pSC[2]) &&
+                    (pSrcPos[x+2] != pSC[3])
+                  )
+                {
+                  pBltPos[x] = pSrcPos[x];
+                  pBltPos[x+1] = pSrcPos[x+1];
+                  pBltPos[x+1] = pSrcPos[x+2];
+                }
+                x +=3;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+          case 4:
+            break;
+        }
+      }
+    }
+    else
+    {
+      if(dwTrans & DDBLTFAST_DESTCOLORKEY)
+      {
+        dprintf(("DDRAW: DestColorKey\n"));
+
+        dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue;
+        switch(dest->dwBytesPPDive)
+        {
+          case 1:
+            while(BlitHeight--)
+            {
+              x = 0;
+              while(x<BlitWidth)
+              {
+                if(pBltPos[x] != (char) dwDestColor)
+                  pBltPos[x] = pSrcPos[x];
+                x++;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+          case 2:
+            while(BlitHeight--)
+            {
+              x = 0;
+              while(x<BlitWidth)
+              {
+                if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor)
+                  ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x];
+                x++;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+          case 3:
+          {
+            char *pSC, *pDC;
+            pSC = (char*)&dwSrcColor;
+            pDC = (char*)&dwDestColor;
+            BlitWidth *=3;
+
+            while(BlitHeight--)
+            {
+              x = 0;
+
+              while(x<BlitWidth)
+              {
+                if( (pBltPos[x]   != pDC[1]) &&
+                    (pBltPos[x+1] != pDC[2]) &&
+                    (pBltPos[x+2] != pDC[3])
+                  )
+                {
+                  pBltPos[x] = pSrcPos[x];
+                  pBltPos[x+1] = pSrcPos[x+2];
+                  pBltPos[x+1] = pSrcPos[x+2];
+                }
+                x +=3;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+          }
+          case 4:
+            while(BlitHeight--)
+            {
+              x = 0;
+              while(x<BlitWidth)
+              {
+                if(((DWORD*)pBltPos)[x] != dwDestColor)
+                  ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x];
+                x++;
+              }
+              pBltPos += dest->dwPitchDB;
+              pSrcPos += src->dwPitchDB;
+            }
+            break;
+        }  // End switch
+      }
+      else
+      {
+        dprintf(("DDRAW: Unexpected Flags"));
+      }
+    }
+  }
+
+  // if(dest->lpVtbl == dest->Vtbl4)
+  //   dest->Vtbl4->ChangeUniquenessValue(dest);
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfDeleteAttachedSurface(THIS This, DWORD dwFlags, LPDIRECTDRAWSURFACE2 lpDDSurface)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfDeleteAttachedSurface\n"));
+  #endif
+
+  return(SurfDeleteAttachedSurface4(me, dwFlags, (LPDIRECTDRAWSURFACE4)lpDDSurface));
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfDeleteAttachedSurface3(THIS This, DWORD dwFlags, LPDIRECTDRAWSURFACE3 lpDDSurface)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfDeleteAttachedSurface\n"));
+  #endif
+
+  return(SurfDeleteAttachedSurface4(me, dwFlags, (LPDIRECTDRAWSURFACE4)lpDDSurface));
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfDeleteAttachedSurface4(THIS This, DWORD dwFlags , LPDIRECTDRAWSURFACE4 lpDDSurface)
+{
+
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  OS2IDirectDrawSurface *AttachedSurface;
+  OS2IDirectDrawSurface *SurfaceCursor;
+  int i;
+
+  BOOL Found = FALSE;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfDeleteAttachedSurface\n"));
+  #endif
+
+  if((0!=dwFlags)||(NULL==lpDDSurface))
+    return(DDERR_INVALIDPARAMS);
+
+  AttachedSurface = (OS2IDirectDrawSurface*) lpDDSurface;
+  if (AttachedSurface->IsImplicitSurface())
+    return (DDERR_CANNOTDETACHSURFACE);
+
+  if ( (AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & ( DDSCAPS_FLIP | DDSCAPS_BACKBUFFER)) &&
+       !(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
+  {
+    // Surface seams to be a backbuffer in a flipchain search it
+
+    // Goto top of list
+    if(me->FrontBuffer!=NULL)
+    {
+      SurfaceCursor = me->FrontBuffer;
+      while(SurfaceCursor->GetFrontBuffer()!=NULL)
+        SurfaceCursor = SurfaceCursor->GetFrontBuffer();
+    }
+    else
+      SurfaceCursor = me;
+
+    // now iterrate through the list skip first in list as we don't remove the frontbuffer
+
+    SurfaceCursor = SurfaceCursor->BackBuffer;
+    while((SurfaceCursor!= AttachedSurface)&&(SurfaceCursor!=NULL))
+      SurfaceCursor = SurfaceCursor->BackBuffer;
+
+    if(SurfaceCursor!=NULL)
+    {
+      Found = TRUE;
+      // remove the Surface from the list
+      SurfaceCursor->FrontBuffer->BackBuffer = SurfaceCursor->BackBuffer;
+      if(SurfaceCursor->BackBuffer!=NULL)
+      {
+        SurfaceCursor->BackBuffer->SetFrontBuffer(SurfaceCursor->FrontBuffer);
+
+      }
+      else
+      {
+        // we were the last buffer in the list have we been the only backbuffer?
+        if(SurfaceCursor->FrontBuffer->FrontBuffer == NULL)
+        {
+          // Yepp so "destroy" the flipchain
+          SurfaceCursor->FrontBuffer->DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
+          SurfaceCursor->FrontBuffer->DDSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
+        }
+      }
+      // decrement the backbuffer count of all buffers in the chain in front of us
+      while(SurfaceCursor->GetFrontBuffer()!=NULL)
+      {
+        SurfaceCursor = SurfaceCursor->GetFrontBuffer();
+        SurfaceCursor->DDSurfaceDesc.dwBackBufferCount-- ;
+      }
+
+      AttachedSurface->DDSurfaceDesc.dwBackBufferCount = 0;
+      AttachedSurface->DDSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
+      AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
+      AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER; // Set this flag as adding to the chain removed it
+      AttachedSurface->lpVtbl->Release(AttachedSurface);
+
+    }
+  } //endif delete back/frontbuffers
+
+  if ( (!Found) && (AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & ( DDSCAPS_FLIP & DDSCAPS_FRONTBUFFER)) )
+  {
+    // seams like someone wants a new frontbuffer
+
+    // Goto top of list
+
+    if(me->FrontBuffer!=NULL)
+    {
+      SurfaceCursor = me->FrontBuffer;
+      while(SurfaceCursor->GetFrontBuffer()!=NULL)
+        SurfaceCursor = SurfaceCursor->GetFrontBuffer();
+    }
+    else
+      SurfaceCursor = me;
+
+    if(SurfaceCursor == AttachedSurface)
+    {
+      Found = TRUE;
+      SurfaceCursor->BackBuffer->SetFrontBuffer(NULL);
+      AttachedSurface->DDSurfaceDesc.dwBackBufferCount = 0;
+      AttachedSurface->DDSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
+      AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
+      AttachedSurface->lpVtbl->Release(AttachedSurface);
+    }
+
+  }
+
+
+  if ( (!Found) && (AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps &  DDSCAPS_MIPMAP ) )
+  {
+    // Surface seams to be a mipmap
+    i = 0;
+    while((DPA_GetPtrCount(me->DPA_SurfaceMipMaps)>i ) && !Found)
+    {
+      if (DPA_FastGetPtr(me->DPA_SurfaceMipMaps,i) == AttachedSurface)
+      {
+        Found = TRUE;
+        DPA_DeletePtr(me->DPA_SurfaceMipMaps,i);
+        AttachedSurface->lpVtbl->Release(AttachedSurface);
+        // adjust our info
+        me->DDSurfaceDesc.dwMipMapCount-- ;
+        if (!me->DDSurfaceDesc.dwMipMapCount)
+        {
+          me->DDSurfaceDesc.dwFlags &= ~DDSD_MIPMAPCOUNT;
+        }
+      }
+      i++;
+    }
+  }
+
+  if(!Found)
+  {
+    // Surface seams to be an attached one
+    i = 0;
+    while((DPA_GetPtrCount(me->DPA_SurfaceAttached)>i ) && !Found)
+    {
+      if (DPA_FastGetPtr(me->DPA_SurfaceAttached,i) == AttachedSurface)
+      {
+        Found = TRUE;
+        DPA_DeletePtr(me->DPA_SurfaceAttached,i);
+        AttachedSurface->lpVtbl->Release(AttachedSurface);
+      }
+      i++;
+    }
+  }
+
+
+  return(Found?DD_OK:DDERR_SURFACENOTATTACHED);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfEnumAttachedSurfaces(THIS This, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpCallBack)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfEnumAttachedSurfaces\n"));
+  #endif
+
+  return(SurfEnumAttachedSurfaces4(me,lpContext, (LPDDENUMSURFACESCALLBACK2) lpCallBack));
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfEnumAttachedSurfaces4(THIS This, LPVOID lpContext ,LPDDENUMSURFACESCALLBACK2 lpCallBack)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  OS2IDirectDrawSurface *EnumSurface;
+  DDSURFACEDESC2         EnumDesc;
+  int i,count;
+  HRESULT rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfEnumAttachedSurfaces\n"));
+  #endif
+  if (NULL==lpCallBack)
+    return (DDERR_INVALIDPARAMS);
+
+  rc = DDENUMRET_OK;
+
+
+  if(me->BackBuffer != NULL)
+  {
+    memcpy(&EnumDesc,&(me->DDSurfaceDesc),sizeof(DDSURFACEDESC2));
+    rc = lpCallBack((LPDIRECTDRAWSURFACE4)me->BackBuffer,&EnumDesc,lpContext);
+  }
+
+  count = DPA_GetPtrCount(me->DPA_SurfaceMipMaps);
+
+  if(count>0)
+  {
+    i=0;
+    while( (DDENUMRET_OK == rc) && i<count )
+    {
+        EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceMipMaps,i);
+        memcpy( &EnumDesc,
+                &(EnumSurface->DDSurfaceDesc),
+                sizeof(DDSURFACEDESC2));
+      // Calling back into WIN32 app so we had to reset FS
+      rc = lpCallBack((LPDIRECTDRAWSURFACE4)EnumSurface,&EnumDesc,lpContext);
+      i++;
+    }
+  }
+
+  count = DPA_GetPtrCount(me->DPA_SurfaceAttached);
+
+  if(count>0)
+  {
+    i=0;
+    while( (DDENUMRET_OK == rc) && i<count )
+    {
+      EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceAttached,i);
+      memcpy( &EnumDesc,
+              &(EnumSurface->DDSurfaceDesc),
+              sizeof(DDSURFACEDESC2));
+      rc = lpCallBack((LPDIRECTDRAWSURFACE4)EnumSurface,&EnumDesc,lpContext);
+      i++;
+    }
+  }
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfEnumOverlayZOrders(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK)
+{
+  dprintf(("DDRAW: SurfEnumOverlayZOrders\n"));
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfEnumOverlayZOrders4(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK2)
+{
+  dprintf(("DDRAW: SurfEnumOverlayZOrders\n"));
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfFlip(THIS This, LPDIRECTDRAWSURFACE2 lpDDSurf, DWORD dwFlags)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  dprintf(("DDRAW: SurfFlip\n"));
+
+  return(SurfFlip4(me, (LPDIRECTDRAWSURFACE4) lpDDSurf, dwFlags));
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfFlip3(THIS This, LPDIRECTDRAWSURFACE3 lpDDSurf, DWORD dwFlags)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  dprintf(("DDRAW: SurfFlip\n"));
+
+  return(SurfFlip4(me, (LPDIRECTDRAWSURFACE4) lpDDSurf, dwFlags));
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfFlip4(THIS This, LPDIRECTDRAWSURFACE4 lpDDSurf, DWORD dwFlags)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  OS2IDirectDrawSurface *FlipSurface;
+  OS2IDirectDrawSurface *FlipCursor;
+  LPVOID Data;
+  char *pcrFB,*pcFB,*pcrDB,*pcDB;
+  ULONG rc;
+
+  dprintf(("DDRAW: SurfFlip4\n"));
+
+  if(!((me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) &&
+       (me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FLIP))
+    )
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Flip called on none Frontbuffer/Flip surface\n Flags:\n"));
+      _dump_DDSCAPS(me->DDSurfaceDesc.ddsCaps.dwCaps);
+      dprintf(("DDRAW: \n"));
+    #endif
+    return(DDERR_NOTFLIPPABLE);
+  }
+
+  if(NULL!=lpDDSurf)
+  {
+    dprintf(("DDRAW: Check if Surface is in Flipchain!\n"));
+
+    // We got an override surface check if it is in the flipchain
+    FlipSurface = (OS2IDirectDrawSurface*) lpDDSurf;
+    FlipCursor = me->BackBuffer;
+    while((NULL!=FlipCursor)&&(FlipCursor!=FlipSurface))
+    {
+      FlipCursor = FlipCursor->BackBuffer;
+    }
+
+    if(FlipCursor!=FlipSurface)
+    {
+      dprintf(("DDRAW: Surface not in Flipchain!\n"));
+
+      return (DDERR_INVALIDPARAMS); // Not sure if the returnvalue is right
+    }
+  }
+  else
+  {
+    FlipSurface = me->NextFlip; // Take the next Surface in the Flipchain
+    dprintf(("DDRAW: Next Surface @ 0x%08X\n",FlipSurface));
+  }
+
+  if((me->fLocked)||(FlipSurface->fLocked))
+  {
+    dprintf(("DDRAW: Locked surface(s) Dest %d Src %d\n",me->fLocked,FlipSurface->fLocked));
+
+    return(DDERR_SURFACEBUSY);
+  }
+
+  if(-1 != me->diveBufNr)
+  {
+    //dprintf(("DDRAW: DIVE Flipchain DiveBuffer #%d",FlipSurface->diveBufNr));
+
+    // we got some DIVE surfaces
+    // On Dive Buffers More then Double buffering won't get any perf. gain
+    // as we have to move all the data to the Frontbuffer and can't simply exchange the pointers
+    // Doulebuffering should work best.
+
+    //rc = DiveBlitImage(me->hDive, FlipSurface->diveBufNr, me->diveBufNr);
+    //dprintf(("DDRAW: DiveBlitImage rc = 0x%08X\n"));
+    SurfBltFast4( me,
+                  0,
+                  0,
+                  (LPDIRECTDRAWSURFACE4)FlipSurface,
+                  NULL,
+                  DDBLTFAST_NOCOLORKEY);
+
+    if(NULL==lpDDSurf)
+    {
+      // advance in the flipchain if no valid override surface was passed in
+      // if we reached the end of the flipchain The Frontbuffer is the next to flip to
+      me->NextFlip = FlipSurface->BackBuffer!=NULL?FlipSurface->BackBuffer:me->BackBuffer;
+    }
+  }
+  else
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Memory Flipchain"));
+    #endif
+    // Memory Flipchain
+    //
+    // ToDo : Check what happens to src/dest colorkeys etc do the move also ?
+    //
+    // We only change the memory pointer to the buffers no need to copy all the data
+    // So the NextFlip is here allways the Backbuffer so we won't advance this
+    //
+    // Sample  (triple buffering) :               Before Flip    After Flip
+    //                               Buffer:      FB  BB  TB     FB  BB  TB
+    //                               Memory:      11  22  33     22  33  11
+    //
+
+    Data  = me->DDSurfaceDesc.lpSurface;
+    pcrFB = me->pFBreal;
+    pcFB  = me->pFrameBuffer;
+    pcrDB = me->pDBreal;
+    pcDB  = me->pDiveBuffer;
+    me->DDSurfaceDesc.lpSurface = FlipSurface->DDSurfaceDesc.lpSurface;
+    me->pFBreal                 = FlipSurface->pFBreal;
+    me->pFrameBuffer            = FlipSurface->pFrameBuffer;
+    me->pDBreal                 = FlipSurface->pDBreal;
+    me->pDiveBuffer             = FlipSurface->pDiveBuffer;
+
+    if(NULL==lpDDSurf)
+    {
+      while(NULL!=FlipSurface->BackBuffer)
+      {
+        FlipSurface->DDSurfaceDesc.lpSurface = FlipSurface->BackBuffer->DDSurfaceDesc.lpSurface;
+        FlipSurface->pFBreal                 = FlipSurface->BackBuffer->pFBreal;
+        FlipSurface->pFrameBuffer            = FlipSurface->BackBuffer->pFrameBuffer;
+        FlipSurface->pDBreal                 = FlipSurface->BackBuffer->pDBreal;
+        FlipSurface->pDiveBuffer             = FlipSurface->BackBuffer->pDiveBuffer;
+        FlipSurface = FlipSurface->BackBuffer;
+      }
+    }
+    FlipSurface->DDSurfaceDesc.lpSurface = Data;
+    FlipSurface->pFBreal                 = pcrFB;
+    FlipSurface->pFrameBuffer            = pcFB;
+    FlipSurface->pDBreal                 = pcrDB;
+    FlipSurface->pDiveBuffer             = pcDB;
+  }
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetAttachedSurface(THIS This, LPDDSCAPS lpDDCaps,
+                                         LPDIRECTDRAWSURFACE2 FAR * lpDDSurf)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetAttachedSurface\n"));
+  #endif
+
+  return(SurfGetAttachedSurface4(me, (LPDDSCAPS2)lpDDCaps , (LPDIRECTDRAWSURFACE4*)lpDDSurf));
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetAttachedSurface3(THIS This, LPDDSCAPS lpDDCaps,
+                                         LPDIRECTDRAWSURFACE3 FAR * lpDDSurf)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetAttachedSurface3\n"));
+  #endif
+
+  return(SurfGetAttachedSurface4(me, (LPDDSCAPS2)lpDDCaps , (LPDIRECTDRAWSURFACE4*)lpDDSurf));
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetAttachedSurface4(THIS This, LPDDSCAPS2 lpDDCaps,
+                                          LPDIRECTDRAWSURFACE4 FAR * lpDDSurf)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  OS2IDirectDrawSurface *EnumSurface = NULL;
+  OS2IDirectDrawSurface *AttachedSurface = NULL;
+  HRESULT rc;
+  int i;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetAttachedSurface4\n>Requested Caps: "));
+    _dump_DDSCAPS(lpDDCaps->dwCaps);
+    dprintf(("DDRAW: \n"));
+  #endif
+
+  if( (NULL==lpDDCaps)||(NULL==lpDDSurf))
+  {
+    dprintf(("DDRAW: Invalid params\n\n"));
+    return (DDERR_INVALIDPARAMS);
+  }
+
+
+  rc = DD_OK;
+
+  if( (me->BackBuffer!=NULL) &&
+      (me->BackBuffer->DDSurfaceDesc.ddsCaps.dwCaps & lpDDCaps->dwCaps) )
+  {
+    dprintf(("DDRAW: Return Backbuffer\n"));
+    AttachedSurface = me->BackBuffer;
+  }
+
+  if(DPA_GetPtrCount(me->DPA_SurfaceMipMaps)>0)
+  {
+    i=0;
+    while( i<DPA_GetPtrCount(me->DPA_SurfaceMipMaps) )
+    {
+      EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceMipMaps,i);
+      if(EnumSurface->DDSurfaceDesc.ddsCaps.dwCaps == lpDDCaps->dwCaps)
+      {
+        if(NULL==AttachedSurface)
+          AttachedSurface = EnumSurface;
+        else
+          rc = DDERR_NOTFOUND; // Not sure if this is the right return value,
+                                  // but function must fail if more then one surface fits
+
+      }
+      i++;
+    }
+  }
+
+  if(DPA_GetPtrCount(me->DPA_SurfaceAttached)>0)
+  {
+    i=0;
+    while( i<DPA_GetPtrCount(me->DPA_SurfaceAttached) )
+    {
+      EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceAttached,i);
+      if(EnumSurface->DDSurfaceDesc.ddsCaps.dwCaps == lpDDCaps->dwCaps)
+      {
+        if(NULL==AttachedSurface)
+          AttachedSurface = EnumSurface;
+        else
+          rc = DDERR_NOTFOUND; // Not sure if this is the right return value,
+                                  // but function must fail if more then one surface fits
+
+      }
+      i++;
+    }
+  }
+
+  if( (DD_OK==rc) &&
+      (NULL!=AttachedSurface) )
+  {
+    *lpDDSurf = (IDirectDrawSurface4*)AttachedSurface;
+    // not sure but as we returned an reference rains usage count
+    AttachedSurface->lpVtbl->AddRef(AttachedSurface);
+  }
+  else
+  {
+    *lpDDSurf = NULL;
+    rc = DDERR_NOTFOUND;
+  }
+
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetBltStatus(THIS This, DWORD)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetBltStatus\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetCaps(THIS This, LPDDSCAPS lpDDCaps)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetCaps\n"));
+  #endif
+
+  if(NULL==lpDDCaps)
+    return(DDERR_INVALIDPARAMS);
+
+  lpDDCaps->dwCaps = me->DDSurfaceDesc.ddsCaps.dwCaps;
+  #ifdef DEBUG
+    _dump_DDSCAPS(lpDDCaps->dwCaps);
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetCaps4(THIS This, LPDDSCAPS2 lpDDCaps)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetCaps4\n"));
+  #endif
+
+  if(NULL==lpDDCaps)
+    return(DDERR_INVALIDPARAMS);
+
+  memcpy(lpDDCaps, &(me->DDSurfaceDesc.ddsCaps), sizeof(DDSCAPS2) );
+  #ifdef DEBUG
+    _dump_DDSCAPS(lpDDCaps->dwCaps);
+    _dump_DDSCAPS2(lpDDCaps->dwCaps2);
+
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetClipper(THIS This, LPDIRECTDRAWCLIPPER FAR *lplpClipper)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetClipper\n"));
+  #endif
+
+  if(me->lpClipper)
+  {
+    *lplpClipper = (LPDIRECTDRAWCLIPPER) me->lpClipper;
+    return(DD_OK);
+  }
+  else
+    return(DDERR_NOCLIPPERATTACHED);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetColorKey(THIS This, DWORD dwFlags, LPDDCOLORKEY lpDDColKey)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+#ifdef DEBUG
+  dprintf(("DDRAW: SurfGetColorKey\n"));
+#endif
+
+  if ((0==dwFlags) || (NULL==lpDDColKey))
+    return (DDERR_INVALIDPARAMS);
+
+  // as we report only src colorkey in the caps return error on all others flags
+  if( (DDCKEY_DESTBLT|DDCKEY_DESTOVERLAY|DDCKEY_SRCOVERLAY) & dwFlags)
+    return(DDERR_UNSUPPORTED);
+
+  if(me->DDSurfaceDesc.dwFlags & dwFlags)
+  {
+    if(DDCKEY_SRCBLT & dwFlags)
+    {
+      memcpy(lpDDColKey,&(me->DDSurfaceDesc.ddckCKSrcBlt),sizeof(DDCOLORKEY) );
+    }
+    else
+      return (DDERR_INVALIDPARAMS); // some other flags where set => error
+  }
+  else
+    return(DDERR_NOCOLORKEY); // surface doesn't have a color key set
+
+  return (DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetDC(THIS This, HDC FAR *hdc)
+{
+ OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+ DDSURFACEDESC2        LockedSurfaceDesc;
+ HRESULT rc;
+ BITMAP bmpSurface;
+ struct
+ {
+   BITMAPINFOHEADER  bmiHead;
+   RGBQUAD           bmiCols[256];
+ } BitmapInfo;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetDC\n"));
+  #endif
+
+  if (NULL==hdc)
+    return(DDERR_INVALIDPARAMS);
+
+  LockedSurfaceDesc.dwSize = sizeof(DDSURFACEDESC2);
+
+  if(DD_OK != me->Vtbl.Lock(me,NULL,&LockedSurfaceDesc,0,0))
+  {
+    return(DDERR_DCALREADYCREATED);
+  }
+
+  rc = DD_OK;
+
+  if(me->hdcImage == NULL)
+  {
+    // Create a Device context
+    me->hdcImage = CreateCompatibleDC(NULL);
+    if(me->hdcImage == NULL)
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: Can't create compatible DC!\n"));
+      #endif
+      me->Vtbl.Unlock(me,NULL);
+      rc = DDERR_GENERIC;
+    }
+    InverseDC(me->hdcImage, LockedSurfaceDesc.dwHeight);
+  }
+
+  if( (DD_OK==rc) &&
+      (me->hbmImage == NULL) )
+  {
+    dprintf( ("Trying to create Bitmap (%d/%d) at %d Bit\n",
+              LockedSurfaceDesc.lPitch/ (LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3),
+              LockedSurfaceDesc.dwHeight,
+              LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount
+            ));
+    #if 0
+    memset(&BitmapInfo, 0, sizeof(BitmapInfo));
+    BitmapInfo.bmiHead.biSize   = sizeof(BITMAPINFOHEADER);
+    BitmapInfo.bmiHead.biWidth  = LockedSurfaceDesc.lPitch/ (LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3);
+    BitmapInfo.bmiHead.biHeight = LockedSurfaceDesc.dwHeight;
+    BitmapInfo.bmiHead.biPlanes = 1;
+    BitmapInfo.bmiHead.biBitCount    = LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount;
+    #else
+    bmpSurface.bmType       = 0;
+    bmpSurface.bmWidth      = LockedSurfaceDesc.dwWidth;
+    bmpSurface.bmHeight     = LockedSurfaceDesc.dwHeight;
+    bmpSurface.bmWidthBytes = LockedSurfaceDesc.lPitch;
+    bmpSurface.bmPlanes     = 1;
+    bmpSurface.bmBits       = LockedSurfaceDesc.lpSurface;
+    #endif
+    switch(LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+    {
+      case 1:
+      case 4:
+        dprintf(("DDRAW: 1/4 Bit Not yet supported\n"));
+        break;
+      case 8:
+        #if 0
+        BitmapInfo.bmiHead.biCompression = BI_RGB;
+        GetSystemPaletteEntries(me->hdcImage,0,255,(PPALETTEENTRY)&BitmapInfo.bmiCols[0]);
+        me->hbmImage = CreateDIBitmap( me->hdcImage,
+                                       NULL,
+                                       CBM_CREATEDIB,
+                                       LockedSurfaceDesc.lpSurface,
+                                       (PBITMAPINFO)&BitmapInfo,
+                                       DIB_RGB_COLORS);
+        #else
+        bmpSurface.bmBitsPixel  = 8;
+        me->hbmImage = CreateBitmapIndirect( &bmpSurface);
+        #endif
+        break;
+      case 16:
+      case 32:
+        dprintf(("DDRAW: 16/32 Bit not supported by OS/2"));
+        break;
+      case 24:
+        #if 0
+        BitmapInfo.bmiHead.biCompression = BI_RGB;
+        me->hbmImage = CreateDIBitmap( me->hdcImage,
+                                       NULL,
+                                       CBM_CREATEDIB,
+                                       LockedSurfaceDesc.lpSurface,
+                                       (PBITMAPINFO)&BitmapInfo,
+                                       DIB_RGB_COLORS);
+        #else
+        bmpSurface.bmBitsPixel  = 24;
+        me->hbmImage = CreateBitmapIndirect( &bmpSurface);
+        #endif
+        break;
+      default:
+        #ifdef DEBUG
+          dprintf( ("Unexptected BitCount %d \n",
+                    LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount));
+        #endif
+        me->hbmImage=NULL;
+    } // end switch (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+
+    if(me->hbmImage == NULL)
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: Can't create bitmap!\n"));
+      #endif
+      DeleteDC(me->hdcImage);
+      me->hdcImage = NULL;
+      me->Vtbl.Unlock(me,NULL);
+      rc = DDERR_GENERIC;
+    }
+  }
+  else
+  {
+    if( (DD_OK==rc) &&
+        (me->dwLastDCUnique != me->dwUniqueValue) )
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: The Surface was locked/unlocked after the last DC was created =>Update Bitmap!\n"));
+      #endif
+
+      memset(&BitmapInfo,0, sizeof(BitmapInfo));
+      BitmapInfo.bmiHead.biSize     = sizeof(BITMAPINFOHEADER);
+      BitmapInfo.bmiHead.biWidth    = LockedSurfaceDesc.lPitch/ (LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3);
+      BitmapInfo.bmiHead.biHeight   = LockedSurfaceDesc.dwHeight;
+      BitmapInfo.bmiHead.biPlanes   = 1;
+      BitmapInfo.bmiHead.biBitCount = LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount;
+
+      switch(LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+      {
+        case 1:
+        case 4:
+        case 8:
+          BitmapInfo.bmiHead.biCompression = BI_RGB;
+          GetSystemPaletteEntries(me->hdcImage,0,255,(PPALETTEENTRY)&BitmapInfo.bmiCols[0]);
+          SetDIBits(me->hdcImage, me->hbmImage, 0, LockedSurfaceDesc.dwHeight,
+                    me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS);
+          break;
+        case 16:
+        case 32:
+          BitmapInfo.bmiHead.biCompression = BI_BITFIELDS;
+          BitmapInfo.bmiHead.biClrUsed     = 3;
+          *((DWORD *) &(BitmapInfo.bmiCols[0])) = me->DDSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+          *((DWORD *) &(BitmapInfo.bmiCols[1])) = me->DDSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+          *((DWORD *) &(BitmapInfo.bmiCols[2])) = me->DDSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+          SetDIBits(me->hdcImage, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight,
+                    me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS);
+          break;
+        case 24:
+          BitmapInfo.bmiHead.biCompression = BI_RGB;
+          SetDIBits(me->hdcImage, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight,
+                    me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS);
+          break;
+        default:
+          #ifdef DEBUG
+            dprintf(("DDRAW: Unexptected BitCount %d => Bitmap not updated!\n",LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount));
+          #endif
+          break;
+      } // end switch (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+
+    }
+  }
+
+  // Allways select the bitmap into the DC! No matter if the old or a new one
+
+  if(DD_OK==rc)
+  {
+    if((me->hgdiOld = SelectObject(me->hdcImage, me->hbmImage)) == NULL)
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: Can't select bitmap into dc!\n"));
+      #endif
+      DeleteDC(me->hdcImage);
+      me->hdcImage = NULL;
+      DeleteObject(me->hbmImage);
+      me->hbmImage = NULL;
+      me->Vtbl.Unlock(me,NULL);
+      rc = DDERR_GENERIC;
+    }
+    else
+    {
+      *hdc = me->hdcImage;
+    }
+  }
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetFlipStatus(THIS This, DWORD dwFlags)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetFlipStatus\n"));
+  #endif
+
+  if( (DDGFS_CANFLIP!=dwFlags) && (DDGFS_ISFLIPDONE!=dwFlags) )
+    return DDERR_INVALIDPARAMS;
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetOverlayPosition(THIS This, LPLONG lplX, LPLONG lplY)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetOverlayPosition\n"));
+  #endif
+
+  // Maybe simply return dderr_notsupported as we retun a max overlay value of 0 in the caps ?
+
+  if( (NULL==lplX) || (NULL==lplY))
+    return DDERR_INVALIDPARAMS;
+
+  if(!(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_OVERLAY))
+    return DDERR_NOTAOVERLAYSURFACE;
+
+  if(!(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_VISIBLE))
+    return DDERR_OVERLAYNOTVISIBLE;
+
+  if(!me->fOverlayValid)
+    return DDERR_NOOVERLAYDEST;
+
+  *lplX = me->lOverlayX;
+  *lplY = me->lOverlayY;
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetPalette(THIS This, LPDIRECTDRAWPALETTE FAR *lplpPalette)
+{
+ OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetPalette\n"));
+  #endif
+
+  if(me->lpPalette)
+  {
+    *lplpPalette = (LPDIRECTDRAWPALETTE)me->lpPalette;
+    return(DD_OK);
+  }
+  else
+    return(DDERR_NOPALETTEATTACHED);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetPixelFormat(THIS This, LPDDPIXELFORMAT lpPixelFormat)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetPixelFormat\n"));
+  #endif
+
+  if(NULL==lpPixelFormat)
+    return DDERR_INVALIDPARAMS;
+
+  memcpy( (char*)lpPixelFormat,
+          (char*)&(me->DDSurfaceDesc.ddpfPixelFormat),
+          sizeof(DDPIXELFORMAT));
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetSurfaceDesc(THIS This, LPDDSURFACEDESC lpSurface)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetSurfaceDesc\n"));
+  #endif
+
+  if((lpSurface == NULL)||(lpSurface->dwSize != sizeof(DDSURFACEDESC)) )
+    return(DDERR_INVALIDPARAMS);
+
+  memcpy( (char *)lpSurface,
+          (char *)&me->DDSurfaceDesc,
+          sizeof(DDSURFACEDESC));
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetSurfaceDesc4(THIS This, LPDDSURFACEDESC2 lpSurface)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetSurfaceDesc4\n"));
+  #endif
+
+  if((lpSurface == NULL)||(lpSurface->dwSize != sizeof(DDSURFACEDESC2)) )
+    return(DDERR_INVALIDPARAMS);
+
+  memcpy( (char *)lpSurface,
+          (char *)&me->DDSurfaceDesc,
+          sizeof(DDSURFACEDESC2));
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfInitialize(THIS, LPDIRECTDRAW, LPDDSURFACEDESC)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfInitialize\n"));
+  #endif
+
+  return(DDERR_ALREADYINITIALIZED); // Init is done during creation see M$ Doc
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfInitialize4(THIS, LPDIRECTDRAW, LPDDSURFACEDESC2)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfInitialize\n"));
+  #endif
+
+  return(DDERR_ALREADYINITIALIZED); // Init is done during creation see M$ Doc
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfIsLost(THIS)
+{
+  // We don't loose any surface ;)
+  // But we might shoud check for primary and/or Dive Buffers as I don't know
+  // if  they are preserved if switching to a FS DOS/OS2 session
+  //
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfIsLost\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfLock( THIS This,
+                            LPRECT lpRect,
+                            LPDDSURFACEDESC lpSurfaceDesc,
+                            DWORD dwFlags,
+                            HANDLE hEvent)
+{
+  DDSURFACEDESC2 SurfaceDesc4;
+  HRESULT rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfLock %d %08X %d %d\n", (int)lpRect, (int)lpSurfaceDesc, dwFlags, hEvent));
+  #endif
+
+  if((NULL==lpSurfaceDesc)||(NULL!=hEvent))
+    return DDERR_INVALIDPARAMS;
+
+  if(lpSurfaceDesc->dwSize != sizeof(DDSURFACEDESC))
+    return DDERR_INVALIDPARAMS;
+
+  SurfaceDesc4.dwSize = sizeof(DDSURFACEDESC2);
+
+  rc = SurfLock4( This,
+                  lpRect,
+                  &SurfaceDesc4,
+                  dwFlags,
+                  hEvent);
+  if (DD_OK==rc)
+  {
+    memcpy( (char*)lpSurfaceDesc,
+            (char*)&SurfaceDesc4,
+            sizeof(DDSURFACEDESC) );
+  }
+
+  return(rc);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfLock4( THIS This,
+                             LPRECT lpRect,
+                             LPDDSURFACEDESC2 lpSurfaceDesc,
+                             DWORD dwFlags,
+                             HANDLE hEvent)
+{
+
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int i;
+
+  BOOL Found;
+  ULONG  nrScanLines;
+  char *pBuffer;
+  DDRectangle *pIRectCurrent,*pIRectNew;
+  static int times = 0;
+  HRESULT rc;
+
+  #ifdef DEBUG
+    dprintf( ("SurfLock4 %08X %08X %08X %d %d\n",
+              me,
+              (int)lpRect,
+              (int)lpSurfaceDesc,
+              dwFlags,
+              hEvent) );
+  #endif
+
+  if( (NULL==lpSurfaceDesc) ||
+      (NULL!=hEvent)
+    )
+  {
+    dprintf(("DDERR_INVALIDPARAMS"));
+    return DDERR_INVALIDPARAMS;
+  }
+
+  if (NULL!=lpRect)
+    pIRectNew = new DDRectangle( lpRect->left, lpRect->top, lpRect->bottom, lpRect->right );
+  else
+    pIRectNew = new DDRectangle( 0, 0, me->height, me->width);
+
+  // ToDo : the lockchecking should be done in a critcal seq.
+  dprintf( ("Lock Rectangle (%d/%d) x (%d/%d)\n",
+            pIRectNew->Top(),
+            pIRectNew->Left(),
+            pIRectNew->Bottom(),
+            pIRectNew->Right() ));
+
+  rc = DD_OK;
+
+  if(me->fLocked)
+  {
+    if (NULL==lpRect)
+    {
+      // If anything is locked we can't locke the complete surface
+      dprintf(("DDRAW: Surface has locked Rectangles, and we want to complete lock it\n"));
+      Found = TRUE;
+    }
+    else
+    {
+      // If the new Rectangle intersects with any of the already locked rectangles it can't
+      // be locked so check for this
+
+      dprintf(("DDRAW: Surface has locked Rectangles, check if the overlap\n"));
+
+      i=0;
+      Found = FALSE;
+
+      while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found)
+      {
+        pIRectCurrent = (DDRectangle*) DPA_FastGetPtr(me->DPA_LockedRects,i);
+        dprintf( ("Test with Rectangle (%d/%d) x (%d/%d)\n",
+                  pIRectCurrent->Top(),
+                  pIRectCurrent->Left(),
+                  pIRectCurrent->Bottom(),
+                  pIRectCurrent->Right() ));
+        Found = pIRectCurrent->intersects(*pIRectNew);
+        i++;
+      }
+
+    }
+
+    if (Found)
+    {
+      delete pIRectNew;
+      #ifdef DEBUG
+        dprintf(("DDRAW: SurfLock4: Surface already locked\n\n"));
+      #endif
+      rc = DDERR_SURFACEBUSY;
+    }
+
+  }
+
+  if(DD_OK == rc)
+  {
+    memcpy((char *)lpSurfaceDesc, (char *)&me->DDSurfaceDesc, sizeof(DDSURFACEDESC2));
+
+    if(lpRect != NULL)
+    {
+      lpSurfaceDesc->lpSurface =  (LPVOID)((char*)me->pFrameBuffer +
+                                  (lpRect->top * me->dwPitchFB) +
+                                  (lpRect->left * (lpSurfaceDesc->ddpfPixelFormat.dwRGBBitCount>>3)));
+      #ifdef DEBUG
+        dprintf(("DDRAW: SurfLock4 %08X (x,y) = (%d,%d)\n\n", lpSurfaceDesc->lpSurface, lpRect->top, lpRect->left));
+      #endif
+    }
+    else
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: SurfLock4 %08X \n\n", lpSurfaceDesc->lpSurface));
+      #endif
+    }
+    // Add the rectangle to the list of locked rectangles
+
+    pIRectNew->SetMemPtr(lpSurfaceDesc->lpSurface);
+
+    DPA_InsertPtr( me->DPA_LockedRects,
+                   DPA_GetPtrCount(me->DPA_LockedRects),
+                   pIRectNew);
+
+    me->fLocked = TRUE;
+  }
+
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfReleaseDC(THIS This, HDC hdc)
+{
+ OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+ struct
+ {
+   BITMAPINFOHEADER  bmiHead;
+   RGBQUAD           bmiCols[256];
+ } BitmapInfo;
+ BITMAP bmpData;
+ char szError[256];
+ int i,rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfReleaseDC\n"));
+  #endif
+
+  if(hdc != me->hdcImage)
+    return(DDERR_INVALIDOBJECT);
+
+  #if 1
+  //unselect our bitmap
+  SelectObject(me->hdcImage, me->hgdiOld);
+  memset(&BitmapInfo,0, sizeof(BitmapInfo));
+  BitmapInfo.bmiHead.biSize     = sizeof(BITMAPINFOHEADER);
+  /*
+  BitmapInfo.bmiHead.biWidth    = me->DDSurfaceDesc.lPitch/ (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3);
+  BitmapInfo.bmiHead.biHeight   = me->DDSurfaceDesc.dwHeight;
+  BitmapInfo.bmiHead.biPlanes   = 1;
+  BitmapInfo.bmiHead.biBitCount = 0; // me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount;
+  */
+  switch(me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+  {
+    case 1:
+    case 4:
+    case 8:
+      BitmapInfo.bmiHead.biCompression = BI_RGB;
+      //GetSystemPaletteEntries(me->hdcImage,0,255,(PPALETTEENTRY)&BitmapInfo.bmiCols[0]);
+      rc = GetDIBits( hdc,
+                      me->hbmImage,
+                      0,
+                      me->DDSurfaceDesc.dwHeight,
+                      NULL,
+                      (PBITMAPINFO)&BitmapInfo,
+                      DIB_RGB_COLORS);
+      dprintf( ("GetDIBits rc=%d\n Size   :%d\n Width  :%d\n Height :%d\n"
+                " Planes :%d\n BitCount :%d\nLastEror = %d\nPixel[0,0] = 0x%02X\n",
+                rc,
+                BitmapInfo.bmiHead.biSize,
+                BitmapInfo.bmiHead.biWidth,
+                BitmapInfo.bmiHead.biHeight,
+                BitmapInfo.bmiHead.biPlanes,
+                BitmapInfo.bmiHead.biBitCount,
+                GetLastError(),
+                ((char*)me->DDSurfaceDesc.lpSurface)[0]));
+      rc = GetDIBits( hdc,
+                      me->hbmImage,
+                      0,
+                      me->DDSurfaceDesc.dwHeight,
+                      me->DDSurfaceDesc.lpSurface,
+                      (PBITMAPINFO)&BitmapInfo,
+                      DIB_RGB_COLORS);
+      dprintf( ("GetDIBits rc=%d\n LastEror = %d\nPixel[0,0] = 0x%02X\n",
+                rc,
+                GetLastError(),
+                ((char*)me->DDSurfaceDesc.lpSurface)[0]));
+      break;
+    case 16:
+    case 32:
+      BitmapInfo.bmiHead.biCompression = BI_BITFIELDS;
+      BitmapInfo.bmiHead.biClrUsed     = 3;
+      *((DWORD *) &(BitmapInfo.bmiCols[0])) = me->DDSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+      *((DWORD *) &(BitmapInfo.bmiCols[1])) = me->DDSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+      *((DWORD *) &(BitmapInfo.bmiCols[2])) = me->DDSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+      GetDIBits(hdc, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight,
+                me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS);
+      break;
+    case 24:
+      BitmapInfo.bmiHead.biCompression = BI_RGB;
+      GetDIBits(hdc, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight,
+                me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS);
+      break;
+    default:
+      #ifdef DEBUG
+        dprintf(("DDRAW: Unexptected BitCount %d => Surface unlocked but no data copied back\n",me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount));
+      #endif
+      // we might could keep the surface locked and return an error but this is more "safe"
+      break;
+  } // end switch (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+  #else
+
+  rc = GetObjectA( me->hbmImage,
+                  sizeof(BITMAP),
+                  &bmpData);
+  dprintf( ("GetObject returned rc=%d\n BitmapInfo:\n Size:(%dx%d)\n Pitch: %d\n Bits %d\n @mem %08X",
+            rc,
+            bmpData.bmWidth, bmpData.bmHeight,
+            bmpData.bmWidthBytes,
+            bmpData.bmBitsPixel,
+            bmpData.bmBits));
+  #endif
+  me->Vtbl.Unlock(me,NULL);
+  me->dwLastDCUnique = me->dwUniqueValue; // Store this to see if the surface was locked after we released the DC
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfRestore(THIS)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfRestore\n"));
+  #endif
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfSetClipper(THIS This, LPDIRECTDRAWCLIPPER lpClipper)
+{
+ OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfSetClipper\n"));
+  #endif
+
+  if(lpClipper == NULL)
+  {
+    //deattach surface
+    if(me->lpClipper)
+    {
+      me->lpClipper->Vtbl.Release((IDirectDrawClipper*)me->lpClipper);
+      me->lpClipper = NULL;
+      return(DD_OK);
+    }
+    else
+      return(DDERR_NOCLIPPERATTACHED);
+  }
+
+  if(lpClipper == (LPDIRECTDRAWCLIPPER)me->lpClipper)
+    return(DD_OK);  //already attached
+
+  if(me->lpClipper != NULL)
+  {
+    me->lpClipper->Vtbl.Release((IDirectDrawClipper*)me->lpClipper);  //attach other surface
+    return(DD_OK);
+  }
+
+  me->lpClipper = (OS2IDirectDrawClipper *)lpClipper;
+  me->lpClipper->Vtbl.AddRef((IDirectDrawClipper*)me->lpClipper);
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfSetColorKey(THIS  This, DWORD dwFlags, LPDDCOLORKEY lpDDColKey)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  HRESULT rc;
+
+  dprintf(("DDRAW: SurfSetColorKey %d %08X\n", dwFlags, lpDDColKey));
+
+  if (0==dwFlags)
+  {
+    return (DDERR_INVALIDPARAMS);
+  }
+
+  // as we report only src colorkey in the caps return error on all others flags
+  if( (DDCKEY_DESTBLT|DDCKEY_DESTOVERLAY|DDCKEY_SRCOVERLAY|DDCKEY_COLORSPACE) & dwFlags)
+  {
+    dprintf(("Unspported colorkey\n"));
+    return(DDERR_UNSUPPORTED);
+  }
+
+  if(DDCKEY_SRCBLT & dwFlags)
+  {
+
+    //(me->lpVtbl == me->Vtbl4)
+    //  me->Vtbl4->ChangeUniquenessValue(me); // we changed somethin so change this value
+    if(NULL!=lpDDColKey)
+    {
+      dprintf(("copy colorkey"));
+      memcpy(&(me->DDSurfaceDesc.ddckCKSrcBlt), lpDDColKey, sizeof(DDCOLORKEY) );
+      me->DDSurfaceDesc.dwFlags |= DDCKEY_SRCBLT;
+
+      // ToDo: Generate a maskbitmap for transparent blitting here
+    }
+    else
+    {
+      dprintf(("clear colorkey"));
+      memset(&(me->DDSurfaceDesc.ddckCKSrcBlt), 0, sizeof(DDCOLORKEY) );
+      me->DDSurfaceDesc.dwFlags &= ~DDCKEY_SRCBLT;
+    }
+    rc = DD_OK;
+  }
+  else
+  {
+    dprintf(("Unsupported flags"));
+    #ifdef DEBUG
+      _dump_DDCOLORKEY(dwFlags);
+    #endif
+    rc = DDERR_INVALIDPARAMS; // some other flags where set => error
+  }
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfSetOverlayPosition(THIS This, LONG lX, LONG lY)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfSetOverlayPosition\n"));
+  #endif
+
+  if( (me->DDSurfaceDesc.dwFlags & DDSD_CAPS) &&
+      (me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_OVERLAY) )
+  {
+    if(me->fOverlayValid)
+      return(DDERR_NOOVERLAYDEST);
+
+    if(!(me->DDSurfaceDesc.dwFlags & DDSCAPS_VISIBLE))
+      return(DDERR_OVERLAYNOTVISIBLE);
+
+    // ToDo: If we implement alignment restricions to the Overlay position
+    // check if the new values are OK otherwiese return DDERR_INVALIDPOSITION
+
+    me->lOverlayX = lX;
+    me->lOverlayY = lY;
+    return(DD_OK);
+  }
+
+  return(DDERR_NOTAOVERLAYSURFACE);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfSetPalette(THIS This, LPDIRECTDRAWPALETTE lpPalette)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfSetPalette\n"));
+  #endif
+
+  if(lpPalette == NULL)
+  {
+    //deattach palette
+    if(me->lpPalette)
+    {
+      // If removed from a primary surface notify
+      // palette that it is no longer attached to the
+      // primary surface => doesn't modify physical palette
+      if(me->surfaceType & DDSCAPS_PRIMARYSURFACE)
+      {
+        me->lpPalette->SetIsPrimary(FALSE);
+      }
+      me->lpPalette->Vtbl.Release((IDirectDrawPalette*)me->lpPalette);
+      me->lpPalette = NULL;
+      return(DD_OK);
+    }
+    else
+      return(DDERR_NOPALETTEATTACHED);
+  }
+
+  if(lpPalette == (LPDIRECTDRAWPALETTE)me->lpPalette)
+    return(DD_OK);  //already attached
+
+  if(me->lpPalette != NULL)
+  {
+    me->lpPalette->Vtbl.Release((IDirectDrawPalette*)me->lpPalette);  //attach other palette
+    //return(DD_OK);
+  }
+  me->lpPalette = (OS2IDirectDrawPalette *)lpPalette;
+  me->lpPalette->Vtbl.AddRef((IDirectDrawPalette*)me->lpPalette);
+
+  // If Attached to a primary surface notify
+  // palette that it is attached to the primary surface
+  //  => It does modify physical palette.
+  // This is important as an palette can be attached to
+  // multiple surfaces. If one is the primary surface
+  // changes done to it via any surface must result in
+  // changes in the phys pal.
+
+  if(me->surfaceType & DDSCAPS_PRIMARYSURFACE)
+  {
+    me->lpPalette->SetIsPrimary(TRUE);
+  }
+  // me->lpVtbl->ChangeUniquenessValue(me);
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUnlock(THIS This, LPVOID lpSurfaceData)
+{
+
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int i;
+  DDRectangle *pIRectUnlock, *pIRectEnum;
+  BOOL Found = FALSE;
+  OS2RECTL CCRect;
+  HRESULT rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUnlock at %08X\n",lpSurfaceData));
+  #endif
+
+  if(me->fLocked == FALSE)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Surface not locked!\n"));
+    #endif
+    return(DDERR_NOTLOCKED);
+  }
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: Start Emuneration of Locked Rects\n"));
+  #endif
+
+  i=0;
+  if(NULL!=lpSurfaceData)
+  {
+    dprintf(("DDRAW: Buffer Pointer Compare"));
+
+    // We got a pinter to the surface memory so we must search for
+    // this pointer in the locked rects DPA to unlock the right rect.
+
+    while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found)
+    {
+      pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i);
+      dprintf(( "Test with Rectangle %d (%d/%d) x (%d/%d) Mem at %08X\n",
+                i,
+                pIRectEnum->Top(),
+                pIRectEnum->Left(),
+                pIRectEnum->Bottom(),
+                pIRectEnum->Right(),
+                pIRectEnum->GetMemPtr() ));
+
+      Found = ( pIRectEnum->GetMemPtr() == lpSurfaceData);
+      if(!Found)
+      {
+        #ifdef DEBUG
+          dprintf(("DDRAW: Not Found, try Next rect\n"));
+        #endif
+        i++;
+      }
+      #ifdef DEBUG
+      else
+      {
+        dprintf(("DDRAW: Found Rect\n"));
+      }
+      #endif
+    }
+  }
+  else
+  {
+    // If a NULL pointer was passed in the SW tries to unlock the
+    // complete surface so we must compare the rects.
+    dprintf(("DDRAW: Rectangle compare"));
+
+    pIRectUnlock = new DDRectangle( 0, 0, me->height, me->width);
+
+    while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found)
+    {
+      pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i);
+      dprintf(( "Test with Rectangle %d (%d/%d) x (%d/%d) Mem at %08X\n",
+                i,
+                pIRectEnum->Top(),
+                pIRectEnum->Left(),
+                pIRectEnum->Bottom(),
+                pIRectEnum->Right(),
+                pIRectEnum->GetMemPtr() ));
+
+      Found = (*pIRectEnum == *pIRectUnlock);
+      if(!Found)
+      {
+        #ifdef DEBUG
+          dprintf(("DDRAW: Not Found, try Next rect\n"));
+        #endif
+        i++;
+      }
+      #ifdef DEBUG
+      else
+      {
+        dprintf(("DDRAW: Found Rect\n"));
+      }
+      #endif
+    }
+    delete pIRectUnlock;
+  }
+
+  if(!Found)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Rectangle not locked, wrong Rect!\n\n"));
+    #endif
+    rc = DDERR_INVALIDRECT;
+  }
+  else
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Remove Rect %d from Seq.\n",i));
+    #endif
+
+    DPA_DeletePtr(me->DPA_LockedRects,i);
+
+    #ifdef DEBUG
+      dprintf(("DDRAW: Test if locked Rects main\n"));
+    #endif
+
+    if(0==DPA_GetPtrCount(me->DPA_LockedRects))  // Do we have unlocked last rectangle
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: No Locked Rects left for surface\n"));
+      #endif
+      me->fLocked = FALSE;
+    }
+    #ifdef DEBUG
+    else
+      dprintf(( "%d Rects in Seq\n",
+                DPA_GetPtrCount(me->DPA_LockedRects)));
+    #endif
+
+    if(me->pFrameBuffer != me->pDiveBuffer)
+    {
+      #ifdef DEBUG
+        dprintf(( "ColorConversion Needed %08X != %08X\n",
+                  me->pFrameBuffer,
+                  me->pDiveBuffer));
+      #endif
+      if(NULL!=lpSurfaceData)
+      {
+        CCRect.yTop    = pIRectEnum->Top();
+        CCRect.xLeft   = pIRectEnum->Left();
+        CCRect.xRight  = pIRectEnum->Right();
+        CCRect.yBottom = pIRectEnum->Bottom();
+
+        me->ColorConversion( (LPRECT)&CCRect);
+      }
+      else
+      {
+        me->ColorConversion(NULL);
+      }
+    }
+    #ifdef DEBUG
+    else
+      dprintf( ("No ColorConversion Needed"));
+    #endif
+
+    // delete tne DDRectobject of the found rectangle
+    delete pIRectEnum;
+
+    // me->lpVtbl->ChangeUniquenessValue(me);
+
+    dprintf(("DDRAW: Unlock OK\n\n"));
+
+    rc = DD_OK;
+  }
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUnlock4(THIS This, LPRECT lpSurfaceRect)
+{
+  // MS changed the parameter from LPVOID to LPRECT with DX6
+  // as DX-6 allways returns a DDSurface4 on create surface this
+  // is a problem i not NULL is passed in.
+  // Solution We first test with the pointer ns assuming a rectangle
+  // if we don't find a rect Which is very likely if we get a pointer
+  // SurfaceMemory we call SurfUnlock and test for the pointer there.
+
+
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int i;
+  DDRectangle *pIRectUnlock, *pIRectEnum;
+  BOOL Found = FALSE;
+  HRESULT rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUnlock4\n"));
+  #endif
+
+  if(me->fLocked == FALSE)
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Surface not locked!\n"));
+    #endif
+    return(DDERR_NOTLOCKED);
+  }
+
+  if(NULL!=lpSurfaceRect)
+  {
+    dprintf(("DDRAW: Unlock rectangle\n"));
+    pIRectUnlock = new DDRectangle( lpSurfaceRect->top,
+                                    lpSurfaceRect->left,
+                                    lpSurfaceRect->bottom,
+                                    lpSurfaceRect->right);
+  }
+  else
+  {
+    dprintf(("DDRAW: Unlock complete surface\n"));
+    pIRectUnlock = new DDRectangle( 0, 0, me->height, me->width);
+  }
+
+  dprintf(( "Try to Unlock Rectangle (%d/%d) x (%d/%d)\n",
+            pIRectUnlock->Top(),
+            pIRectUnlock->Left(),
+            pIRectUnlock->Bottom(),
+            pIRectUnlock->Right() ));
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: Start Emuneration of Locked Rects\n"));
+  #endif
+
+  i=0;
+  while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found)
+  {
+    pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i);
+    dprintf(( "Test with Rectangle (%d/%d) x (%d/%d)\n",
+              pIRectEnum->Top(),
+              pIRectEnum->Left(),
+              pIRectEnum->Bottom(),
+              pIRectEnum->Right() ));
+
+    Found = (*pIRectEnum == *pIRectUnlock);
+    if(!Found)
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: Not Found, try Next rect\n"));
+      #endif
+      i++;
+    }
+    #ifdef DEBUG
+    else
+    {
+      dprintf(("DDRAW: Found Rect\n"));
+    }
+    #endif
+  }
+
+  if(!Found)
+  {
+
+    if(NULL==lpSurfaceRect)
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: Rectangle not locked, wrong Rect!\n\n"));
+      #endif
+      return(DDERR_INVALIDRECT);
+    }
+    else
+      rc = SurfUnlock(This, (LPVOID)lpSurfaceRect);
+  }
+  else
+  {
+    #ifdef DEBUG
+      dprintf(("DDRAW: Remove Rect from Seq.\n"));
+    #endif
+
+    DPA_DeletePtr(me->DPA_LockedRects,i);
+
+    if(0==DPA_GetPtrCount(me->DPA_LockedRects))  // Do we have unlocked last rectangle
+    {
+      #ifdef DEBUG
+        dprintf(("DDRAW: No Locked Rects left for surface\n"));
+      #endif
+      me->fLocked = FALSE;
+    }
+
+    if(me->pFrameBuffer != me->pDiveBuffer)
+    {
+      #ifdef DEBUG
+        dprintf(( "ColorConversion Needed %08X != %08X\n",
+                  me->pFrameBuffer,
+                  me->pDiveBuffer));
+      #endif
+      me->ColorConversion(lpSurfaceRect);
+    }
+
+    // me->lpVtbl->ChangeUniquenessValue(me);
+
+    dprintf(("DDRAW: Unlock OK\n\n"));
+    rc = DD_OK;
+  }
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUpdateOverlay(THIS This, LPRECT, LPDIRECTDRAWSURFACE2,LPRECT,DWORD, LPDDOVERLAYFX)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUpdateOverlay\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUpdateOverlay3(THIS This, LPRECT, LPDIRECTDRAWSURFACE3,LPRECT,DWORD, LPDDOVERLAYFX)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUpdateOverlay\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUpdateOverlay4(THIS, LPRECT, LPDIRECTDRAWSURFACE4,LPRECT,DWORD, LPDDOVERLAYFX)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUpdateOverlay\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUpdateOverlayDisplay(THIS, DWORD)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUpdateOverlayDisplay\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUpdateOverlayZOrder(THIS, DWORD, LPDIRECTDRAWSURFACE2)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUpdateOverlayZOrder\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUpdateOverlayZOrder3(THIS, DWORD, LPDIRECTDRAWSURFACE3)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUpdateOverlayZOrder\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfUpdateOverlayZOrder4(THIS, DWORD, LPDIRECTDRAWSURFACE4)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfUpdateOverlayZOrder4\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetDDInterface(THIS This, LPVOID FAR *lplpDirectDraw)
+{
+ OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetDDInterface\n"));
+  #endif
+  *lplpDirectDraw = (LPVOID FAR *)me->lpDraw;
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfPageLock(THIS, DWORD)
+{
+  // Only used for DMA memory access
+  // If we implement this for the None dive buffers with a pdd the we must change
+  // from malloc to DosAllocMem and use OBJ_TILE flag
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfPageLock\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfPageUnlock(THIS, DWORD)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfPageUnlock\n"));
+  #endif
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+// V3 Interface Functions
+
+HRESULT __stdcall SurfSetSurfaceDesc(THIS This, LPDDSURFACEDESC lpSurfDesc, DWORD dwFlags)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfSetSurfaceDesc\n"));
+  #endif
+
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  if ( (NULL==lpSurfDesc) || (dwFlags!=0) )
+    return DDERR_INVALIDPARAMS;
+
+  // Is this ok ? Not sure if Front/BackBuffer should be handled like the Primary one.
+  //  if ( ( DDSCAPS_PRIMARYSURFACE == me->DDSurfaceDesc.ddsCaps.dwCaps) ||
+  //       ( DDSCAPS_FRONTBUFFER == me->DDSurfaceDesc.ddsCaps.dwCaps) ||
+  //       ( DDSCAPS_BACKBUFFER  == me->DDSurfaceDesc.ddsCaps.dwCaps) )
+  if(-1==me->diveBufNr)
+    return DDERR_INVALIDSURFACETYPE; // only work for system alloced surfaces
+
+  if (!me->Updated)
+  {
+    me->Updated = TRUE;
+    // free our allocated Memory
+    if(me->DDSurfaceDesc.dwFlags & DDSD_LPSURFACE)
+    {
+      if(me->pFBreal)
+        free(me->pFBreal);
+      if(me->pDBreal)
+        free(me->pFBreal);
+    }
+  }
+  // me->lpVtbl->ChangeUniquenessValue(me);
+  memcpy( (char*)&(me->DDSurfaceDesc),
+          (char*)lpSurfDesc,
+          sizeof(DDSURFACEDESC));
+
+  me->dwPitchFB = me->DDSurfaceDesc.lPitch;
+
+  if( me->lpDraw->dCaps.ulDepth != me->lpDraw->GetScreenBpp() )
+  {
+    // create CC buffer ....
+    me->dwPitchDB = (me->DDSurfaceDesc.dwWidth * me->dwBytesPPDive +7) & ~7;
+    me->pDBreal = (char*)malloc( me->DDSurfaceDesc.dwHeight * me->dwPitchDB + 24);
+    me->pDiveBuffer = (char*)(((int)me->pDBreal + 7) & ~7); // align to QWORD
+  }
+  return DD_OK;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfSetSurfaceDesc4(THIS This, LPDDSURFACEDESC2 lpSurfDesc, DWORD dwFlags)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfSetSurfaceDesc4\n"));
+  #endif
+
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  if ( (NULL==lpSurfDesc) || (dwFlags!=0) )
+    return DDERR_INVALIDPARAMS;
+
+  // Is this ok ? Not sure if Front/BackBuffer should be handled like the Primary one.
+  //  if ( ( DDSCAPS_PRIMARYSURFACE == me->DDSurfaceDesc.ddsCaps.dwCaps) ||
+  //       ( DDSCAPS_FRONTBUFFER == me->DDSurfaceDesc.ddsCaps.dwCaps) ||
+  //       ( DDSCAPS_BACKBUFFER  == me->DDSurfaceDesc.ddsCaps.dwCaps) )
+  if(-1==me->diveBufNr)
+    return DDERR_INVALIDSURFACETYPE; // only work for system alloced surfaces
+
+  if (!me->Updated)
+  {
+    me->Updated = TRUE;
+    // free our allocated Memory
+    // free our allocated Memory
+    if(me->DDSurfaceDesc.dwFlags & DDSD_LPSURFACE)
+    {
+      if(me->pFBreal)
+        free(me->pFBreal);
+      if(me->pDBreal)
+        free(me->pFBreal);
+    }
+  }
+  // me->lpVtbl->ChangeUniquenessValue(me);
+  memcpy( (char *)&(me->DDSurfaceDesc),
+          (char*)lpSurfDesc,
+          sizeof(DDSURFACEDESC2));
+  me->dwPitchFB = me->DDSurfaceDesc.lPitch;
+
+  if( me->lpDraw->dCaps.ulDepth != me->lpDraw->GetScreenBpp() )
+  {
+    // create CC buffer ....
+    me->dwPitchDB = (me->DDSurfaceDesc.dwWidth * me->dwBytesPPDive +7) & ~7;
+    me->pDBreal = (char*)malloc( me->DDSurfaceDesc.dwHeight * me->dwPitchDB + 24);
+    me->pDiveBuffer = (char*)(((int)me->pDBreal + 7) & ~7); // align to QWORD
+  }
+
+  return DD_OK;
+}
+//******************************************************************************
+//******************************************************************************
+// V4 Interface Functions
+
+HRESULT __stdcall SurfSetPrivateData(THIS This, REFGUID refGUID, LPVOID lpData,
+                                     DWORD dwDataSize, DWORD dwFlags)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int i;
+  PSURFPRIVATEDATA pSData;
+  void *pBuffer;
+  BOOL bFound = FALSE;
+  HRESULT rc;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfSetPrivateData\n"));
+  #endif
+
+  if(NULL==me)
+    return(DDERR_INVALIDOBJECT);
+
+  if((NULL==lpData)||(0==dwDataSize)||
+     (dwFlags & ~(DDSPD_IUNKNOWNPOINTER|DDSPD_VOLATILE)))
+    return(DDERR_INVALIDPARAMS);
+
+  // first check if the refGUID is stored as then the content will be updated
+  if( DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0 )
+  {
+    i=0;
+    while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData) && !bFound)
+    {
+      pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i);
+
+      if (IsEqualGUID(pSData->guidTag,refGUID))
+        bFound = TRUE;
+
+      i++;
+    }
+  }
+
+  if(bFound)
+  {
+    // update Private Data
+
+    if (!pSData->isValid)
+    {
+      // Current data is invalid we need to update/allocate
+
+      if(dwFlags & DDSPD_IUNKNOWNPOINTER)
+      {
+        pSData->pData = lpData;
+        pSData->dwSize = 4;
+        pSData->dwFlags = dwFlags;
+        pSData->isValid = TRUE;
+        ((OS2IDirectDrawSurface *) lpData)->lpVtbl->AddRef(lpData);
+      }
+      else
+      {
+        pSData->pData = malloc(dwDataSize);
+        if(NULL!=pSData->pData)
+        {
+          memcpy(pSData->pData,lpData,dwDataSize);
+          pSData->dwSize  = dwDataSize;
+          pSData->dwFlags = dwFlags;
+          pSData->isValid = TRUE;
+        }
+        else
+        {
+          delete pSData;
+          rc = DDERR_OUTOFMEMORY;
+        }
+      }
+    }
+    else
+    {
+      if(pSData->dwFlags & DDSPD_IUNKNOWNPOINTER)
+      {
+        if(dwFlags & DDSPD_IUNKNOWNPOINTER)
+        {
+          if(pSData->pData != lpData)
+          {
+            // Change of IUNKOWNPOINTER => release old and add ref to new one
+            ((OS2IDirectDrawSurface *)pSData->pData)->lpVtbl->Release(pSData->pData);
+            ((OS2IDirectDrawSurface *)lpData)->lpVtbl->AddRef(lpData);
+            pSData->pData = lpData;
+          }
+          pSData->dwFlags = dwFlags; // Update the flags, size is the same
+        }
+        else
+        {
+          // Replace IUNKOWN through data
+          pBuffer = malloc(dwDataSize); // get new buffer first
+          if(NULL!=pBuffer)
+          {
+            // release old ref and copy data
+            ((OS2IDirectDrawSurface *)pSData->pData)->lpVtbl->Release(pSData->pData);
+            memcpy(pBuffer,lpData,dwDataSize);
+            pSData->pData = pBuffer;
+            pSData->dwSize = dwDataSize; // Update the size
+            pSData->dwFlags = dwFlags;   // Update the flags
+          }
+          else
+            rc = DDERR_OUTOFMEMORY;
+        }
+      }
+      else
+      {
+        if(dwFlags & DDSPD_IUNKNOWNPOINTER)
+        {
+          // Change of data to IUNKOWNPOINTER => free old memory and add ref to new one
+          free(pSData->pData);
+          ((OS2IDirectDrawSurface *)lpData)->lpVtbl->AddRef(lpData);
+          pSData->pData = lpData;
+          pSData->dwSize = dwDataSize; // Update the size
+          pSData->dwFlags = dwFlags;   // Update the flags
+        }
+        else
+        {
+          //  Update/Replace data
+          if(pSData->dwSize!=dwDataSize)
+            pBuffer = realloc(pSData->pData,dwDataSize); // update buffer to new size
+          else
+            pBuffer = pSData->pData;
+
+          if(NULL!=pBuffer)
+          {
+            // release old ref and copy data
+            memcpy(pBuffer,lpData,dwDataSize);
+            pSData->pData = pBuffer;
+            pSData->dwSize = dwDataSize; // Update the size
+            pSData->dwFlags = dwFlags;   // Update the flags
+          }
+          else
+            rc = DDERR_OUTOFMEMORY;
+        }
+      }
+    }
+  }
+  else
+  {
+    // New data
+
+    pSData = new(SURFPRIVATEDATA);
+    if (NULL!=pSData)
+    {
+      if(dwFlags & DDSPD_IUNKNOWNPOINTER)
+      {
+        memcpy(&(pSData->guidTag),&refGUID,sizeof(GUID));
+        pSData->pData = lpData;
+        pSData->dwSize = 4;
+        pSData->dwFlags = dwFlags;
+        pSData->isValid = TRUE;
+        ((OS2IDirectDrawSurface *)lpData)->lpVtbl->AddRef(lpData);
+      }
+      else
+      {
+        pSData->pData = malloc(dwDataSize);
+        if(NULL!=pSData->pData)
+        {
+          memcpy(&(pSData->guidTag),&refGUID,sizeof(GUID));
+          memcpy(pSData->pData,lpData,dwDataSize);
+          pSData->dwSize  = dwDataSize;
+          pSData->dwFlags = dwFlags;
+          pSData->isValid = TRUE;
+
+          if( DPA_InsertPtr( me->DPA_SurfacePrivateData,
+                             DPA_GetPtrCount(me->DPA_SurfacePrivateData),
+                             pSData) <0)
+          {
+            delete(pSData);
+            rc = DDERR_OUTOFMEMORY;
+          }
+        }
+        else
+        {
+          delete(pSData);
+          rc = DDERR_OUTOFMEMORY;
+        }
+      }
+
+    }
+    else
+      rc = DDERR_OUTOFMEMORY;
+  }
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetPrivateData(THIS This, REFGUID refGUID, LPVOID lpData, LPDWORD lpDataSize)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int i;
+  PSURFPRIVATEDATA pSData;
+  HRESULT rc;
+  BOOL bFound = FALSE;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetPrivateData\n"));
+  #endif
+
+  if(NULL==me)
+    return(DDERR_INVALIDOBJECT);
+
+  if((NULL==lpData)||(NULL==lpDataSize))
+    return(DDERR_INVALIDPARAMS);
+
+  if(DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0)
+  {
+    i=0;
+    while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData) && !bFound)
+    {
+      pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i);
+
+      if (IsEqualGUID(pSData->guidTag,refGUID))
+        bFound = TRUE;
+
+      i++;
+    }
+  }
+
+  if(bFound)
+  {
+    if(!pSData->isValid)
+    {
+      rc =DDERR_EXPIRED;
+    }
+    else
+    {
+      if(pSData->dwSize > *lpDataSize)
+      {
+        // Buffer to small return needed Size
+        *lpDataSize = pSData->dwSize;
+        rc = DDERR_MOREDATA;
+      }
+      else
+      {
+        memcpy(lpData,pSData->pData,pSData->dwSize);
+        rc = DD_OK;
+      }
+    }
+  }
+  else
+   rc = DDERR_NOTFOUND;
+
+
+  return rc;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfFreePrivateData(THIS This, REFGUID refGUID)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int i;
+  PSURFPRIVATEDATA pSData;
+  BOOL bFound = FALSE;
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfFreePrivateData\n"));
+  #endif
+
+  if(NULL==me)
+    return(DDERR_INVALIDOBJECT);
+
+  if(DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0)
+  {
+    i=0;
+    while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData) && !bFound)
+    {
+      pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i);
+
+      if (IsEqualGUID(pSData->guidTag,refGUID))
+      {
+        bFound = TRUE;
+
+        if(pSData->isValid)
+        {
+          // delete the data if valid
+          if (pSData->dwFlags & DDSPD_IUNKNOWNPOINTER)
+          {
+            // pointer to com stored so calll its release
+            ((OS2IDirectDrawSurface *) pSData->pData)->lpVtbl->Release(pSData->pData);
+          }
+          else
+          {
+            // Free allocated data
+            free( pSData->pData);
+          }
+        }
+        // Now remove the entry from the list
+        DPA_DeletePtr(me->DPA_SurfacePrivateData,i);
+      }
+      i++;
+    }
+  }
+
+  return (bFound?DD_OK:DDERR_NOTFOUND);
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfGetUniquenessValue(THIS This, LPDWORD lpValue)
+{
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfGetUniquenessValue\n"));
+  #endif
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  if (NULL==lpValue)
+    return DDERR_INVALIDPARAMS;
+
+  *lpValue = me->dwUniqueValue;
+  return DD_OK;
+}
+//******************************************************************************
+//******************************************************************************
+HRESULT __stdcall SurfChangeUniquenessValue(THIS This)
+{
+  OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This;
+  int i;
+  PSURFPRIVATEDATA pSData;
+
+
+  #ifdef DEBUG
+    dprintf(("DDRAW: SurfChangeUniquenessValue\n"));
+  #endif
+  me->dwUniqueValue++;
+
+  if(DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0)
+  {
+    i=0;
+    while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData))
+    {
+      pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i);
+      if (pSData->dwFlags & DDSPD_VOLATILE)
+      {
+        // Data becomes unvalid after a Surface change
+        if (pSData->dwFlags & DDSPD_IUNKNOWNPOINTER)
+        {
+          // pointer to com stored so call its release
+          ((OS2IDirectDrawSurface *) pSData->pData)->lpVtbl->Release(pSData->pData);
+        }
+        else
+        {
+          // Free allocated data
+          free( pSData->pData);
+        }
+        pSData->pData = NULL;
+        pSData->isValid = FALSE; // set flag to invalid
+      }
+      i++;
+    }
+  }
+
+  return (DD_OK);
+}
+
+
+
+//******************************************************************************
+//
+//  Purpose function copies one part of the bitmap inside the same bitmap
+//
+//******************************************************************************
+
+void __cdecl MoveRects(char* pBuffer, LPRECT lpDestRect, LPRECT lpSrcRect, int bpp, LONG lPitch)
+{
+
+  char *pBltPos, *pSrcPos;
+  int BlitWidth,BlitHeight;
+  static char Scanline[6400];  // sufficient for 1600 at 32 bit
+
+  // Bridge, we may got a problem ;)
+  // Check for Overlapping Rects
+
+  pBltPos = pBuffer;
+  pSrcPos = pBuffer;
+
+  if(lpDestRect->top <= lpSrcRect->top)
+  {
+    //  +-------+     +-------+      +-------+
+    //  |S      |     |S      |      |S      |  +---+---+---+
+    //  |   +---|---+ +-------+  +---|---+   |  |S/D|D/S|   |
+    //  |   | D |   | | D     |  | D |   |   |  |   |   |   |
+    //  +-------+   | +-------+  |   +-------+  |   |   |   |
+    //      |       | |       |  |       |      +---+---+---+
+    //      +-------+ +-------+  +-------+
+    //
+    // We got one of the above cases (or no overlapping) so copy from bottom up
+
+    pBltPos += (lpDestRect->left * bpp) + lPitch * lpDestRect->top;
+    pSrcPos += (lpSrcRect->left * bpp)  + lPitch * (lpSrcRect->bottom-1);
+    BlitHeight = lpDestRect->bottom - lpDestRect->top;
+    BlitWidth  = (lpDestRect->right - lpDestRect->left) * bpp;
+
+    while(1)
+    {
+      memcpy(Scanline,pSrcPos,BlitWidth);
+      memcpy(pBltPos,Scanline,BlitWidth);
+      pBltPos += lPitch;
+      pSrcPos -= lPitch;
+      if(! (--BlitHeight))
+        break;
+    }
+  }
+  else
+  {
+    //  +-------+     +-------+      +-------+
+    //  | D     |     | D     |      | D     |
+    //  |   +---|---+ +-------+  +---|---+   |
+    //  |   |S  |   | |S      |  |S  |   |   |
+    //  +-------+   | +-------+  |   +-------+
+    //      |       | |       |  |       |
+    //      +-------+ +-------+  +-------+
+    //
+    // We got one of the above cases so copy top down
+
+    pBltPos += (lpDestRect->left * bpp) + lPitch * lpDestRect->top;
+    pSrcPos += (lpSrcRect->left  * bpp) + lPitch * lpSrcRect->top;
+    BlitHeight = lpDestRect->bottom - lpDestRect->top;
+    BlitWidth  = (lpDestRect->right - lpDestRect->left) * bpp;
+
+    while(1)
+    {
+      memcpy(Scanline,pSrcPos,BlitWidth);
+      memcpy(pBltPos,Scanline,BlitWidth);
+      pBltPos += lPitch;
+      pSrcPos += lPitch;
+      if(! (--BlitHeight))
+        break;
+    }
+  }
+
+}
+
+//******************************************************************************
+//
+//  Purpose : Do a blit using the precalced Transbuffer
+//            That is the only way to do fast blits if a colorrange is used
+//            and we can find totally transparent lines and don't blit them
+//            and detect if the part of the line is transparent
+//
+//            Idea for a kind of mask buffer
+//            Format of Transparentbuffer (each line):
+//            the first DWORD contains 2 WORDS with Offset of First Non transparent
+//            pixel in the low word and the last non transparent pixel in a row in
+//            the high word. => 0 = line totally transparent!
+//            This limits the max supported width to 2^16 but I thing this is enougth
+//            The size per line is 1+((Width+31) & ~31) DWORDS => each Bit represents
+//            1 pixel
+//
+//            TransparentBufferCreate(lpDDSurfaceDesc->dwWidth, lpDDSurfaceDesc->dwHeight);
+//
+//          Layout of a DWORD:
+//             UUVVWWXX  dword is processed LS Byte FIRST ...
+//             Each bit in a byte stands for one pixel. MS Bit First
+//
+//          example: Bitmap (16x5) (X= opaque, . = Transparent)
+//                   ...XX...XX....XX
+//                   ..XXXX....XXXX..
+//                   ................
+//                   .........XXXXXX.
+//                   ...XX...X......X
+//
+//                   Transparent buffer (2DWORDS) per line
+//
+//         0x00100003, 0x0000C318
+//         0x000E0002, 0x00003C3C
+//         0x00000000, 0x00000000
+//         0x000F000A, 0x00007E00
+//         0x00100003, 0x00008118
+//******************************************************************************
+
+void __cdecl TransSRCBlit8(LPDDSURFACEDESC2 pDestDesc, LPDDSURFACEDESC2 pSrcDesc,  char *pAlpha, LPRECT lpSrcRect)
+{
+  DWORD *pdwTLine; // pointer to the transparent buffer
+  DWORD dwTLineLen;      // # of DWORDS in each tBuffer line
+  DWORD dwTLineStart;     // # DWORD in which the first transinfo is
+  DWORD dwTDWStart;       // byte in which the firs transinfo is
+  DWORD dwTrans;          // current transparentvalue
+  DWORD BlitWidth;
+  dwTLineLen = 1 + ((pSrcDesc->dwWidth + 31) & ~31);
+  pdwTLine = (DWORD*)pAlpha + (dwTLineLen* lpSrcRect->top);
+  dwTLineStart = 1+(lpSrcRect->left/32);
+  dwTDWStart   = (lpSrcRect->left+8)/8;
+}
+
+
Index: trunk/src/ddraw/new/OS2SURFACE.H
===================================================================
--- trunk/src/ddraw/new/OS2SURFACE.H	(revision 3345)
+++ trunk/src/ddraw/new/OS2SURFACE.H	(revision 3345)
@@ -0,0 +1,302 @@
+/* $Id: OS2SURFACE.H,v 1.1 2000-04-07 18:21:06 mike Exp $ */
+
+/*
+ * Direct/X Surface class
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef __OS2SURFACE_H__
+#define __OS2SURFACE_H__
+#define FAR
+#include "divewrap.h"
+#include <commctrl.h>
+
+#define FAR
+#undef THIS
+#define THIS VOID*
+
+typedef struct _OS2RECTL {
+   LONG     xLeft;    /*  X-coordinate of left-hand edge of rectangle. */
+   LONG     yBottom;  /*  Y-coordinate of bottom edge of rectangle. */
+   LONG     xRight;   /*  X-coordinate of right-hand edge of rectangle. */
+   LONG     yTop;     /*  Y-coordinate of top edge of rectangle. */
+ } OS2RECTL;
+
+typedef struct _SURFPRIVATEDATA
+{
+  GUID    guidTag;
+  void    *pData;
+  DWORD   dwFlags;
+  DWORD   dwSize;
+  BOOL    isValid;
+}SURFPRIVATEDATA , *PSURFPRIVATEDATA;
+
+class OS2IDirectDrawSurface
+{
+ public:
+  //this one has to go first!
+  IDirectDrawSurface2Vtbl *lpVtbl;
+  IDirectDrawSurface2Vtbl *lpVtbl2;         // 2nd Vtable pointer An other MS assumtion see below
+//  IDirectDrawSurface4Vtbl *lpVtbl;
+//  IDirectDrawSurface4Vtbl *lpVtbl2;         // 2nd Vtable pointer An other MS assumtion see below
+  DWORD                    dwUnknownData;   // Pointer to unknown data set to DEADDEAD to indicate that we can't handle this
+  IDirectDrawSurface2Vtbl  Vtbl2;
+  IDirectDrawSurface3Vtbl  Vtbl3;
+  IDirectDrawSurface4Vtbl  Vtbl; // With Dx6 CreateSurface creates per default one with Interface 4 !
+
+  OS2IDirectDrawSurface( OS2IDirectDraw *lpDirectDraw,
+                         LPDDSURFACEDESC2 lpDDSurfaceDesc,
+                         BOOL Implicit = FALSE,    // Indicates that this surface was created  as result of a complex surface
+                         BOOL Mainchain = FALSE);  // Indicates if an implicit surface belongs to the primary surface
+  ~OS2IDirectDrawSurface();
+          int           Referenced;
+  inline  HRESULT       GetLastError() { return lastError; };
+  inline  int           GetDiveBufNr() { return diveBufNr; };
+  inline  BOOL          IsImplicitSurface() {return ImplicitSurface; };
+  inline  OS2IDirectDrawSurface* GetFrontBuffer(){ return FrontBuffer;};
+  inline  void          SetFrontBuffer( OS2IDirectDrawSurface* NewFBuffer);
+          void          ColorConversion(LPRECT lpRect);
+
+ private:
+        HRESULT         DoColorFill(LPRECT, DWORD);
+        void (__cdecl *BltSolid)( char *pDBDst,
+                                char *pFBDst,
+                                DWORD dwDstTop,
+                                DWORD dwDstLeft,
+                                DWORD dwPitchDBDst,
+                                DWORD dwPitchFBDst,
+                                char *pDBSrc,
+                                char *pFBSrc,
+                                DWORD dwSrcTop,
+                                DWORD dwSrcLeft,
+                                DWORD dwWidth,
+                                DWORD dwHeight,
+                                DWORD dwPitchDBSrc,
+                                DWORD dwPitchFBSrc
+                               );
+        void (__cdecl *ColorConv)( char *pDB,
+                                   char *pFB,
+                                   DWORD dwTop,
+                                   DWORD dwLeft,
+                                   DWORD dwWidth,
+                                   DWORD dwHeight,
+                                   DWORD dwPitchDB,
+                                   DWORD dwPitchFB,
+                                   VOID  *pPalette
+                                   );
+        void (__cdecl *ColorFill)( char *pDBDst,
+                                   char *pFBDst,
+                                   DWORD dwDstTop,
+                                   DWORD dwDstLeft,
+                                   DWORD dwWidth,
+                                   DWORD dwHeight,
+                                   DWORD dwPitchDBDst,
+                                   DWORD dwPitchFBDst,
+                                   DWORD dwColor,
+                                   VOID  *pPalette
+                                 );
+ protected:
+        HRESULT                lastError;
+        HDIVE                  hDive;
+        HDIVE                  hDiveCC; // Color conversion DIVE Handle
+        ULONG                  height, width;
+        ULONG                  screenHeight, screenWidth;
+        ULONG                  surfaceType;
+        ULONG                  diveBufNr;
+        OS2IDirectDraw        *lpDraw;
+        OS2IDirectDrawClipper *lpClipper;
+        OS2IDirectDrawPalette *lpPalette;
+        DDSURFACEDESC2         DDSurfaceDesc;
+        BOOL                   fLocked;
+        HDC                    hdcImage;
+        HBITMAP                hbmImage;
+        HGDIOBJ                hgdiOld;
+        DWORD                  dwLastDCUnique;
+        // The real pointers hold the allocated memory (for the free)
+        // The other an pointer addjusted to QWORDs which we use and report
+        char                  *pFrameBuffer, *pFBreal;
+        char                  *pDiveBuffer, *pDBreal;
+        DWORD                 *pTransBufferSrc;
+        DWORD                 *pTransBufferDest;
+        DWORD                  dwPitchFB;
+        DWORD                  dwPitchDB;
+        DWORD                  dwBytesPPDive;
+        BOOL                   Updated;
+        BOOL                   ImplicitSurface;
+
+             // DDraw internal vars
+
+        DWORD                  dwUniqueValue;
+        HDPA DPA_SurfacePrivateData;
+
+        BOOL                   fOverlayValid;
+        LONG                   lOverlayX;
+        LONG                   lOverlayY;
+
+        // surface management
+
+        OS2IDirectDrawSurface*  BackBuffer;  // Backbuffer goes in here
+        OS2IDirectDrawSurface*  FrontBuffer; // NULL if the real frontbuffer of a Flipchain otherwise  the prev. Backbuffer
+        OS2IDirectDrawSurface*  NextFlip;    // Only valid in a frontbuffer
+
+        HDPA DPA_SurfaceMipMaps;
+        HDPA DPA_SurfaceAttached;
+        HDPA DPA_LockedRects;
+
+    friend    HRESULT __stdcall SurfQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj);
+    friend    ULONG   __stdcall SurfAddRef(THIS);
+    friend    ULONG   __stdcall SurfRelease(THIS);
+    friend    HRESULT __stdcall SurfAddAttachedSurface(THIS, LPDIRECTDRAWSURFACE2);
+    friend    HRESULT __stdcall SurfAddAttachedSurface3(THIS, LPDIRECTDRAWSURFACE3);
+    friend    HRESULT __stdcall SurfAddAttachedSurface4(THIS, LPDIRECTDRAWSURFACE4);
+    friend    HRESULT __stdcall SurfAddOverlayDirtyRect(THIS, LPRECT);
+    friend    HRESULT __stdcall SurfBlt(THIS, LPRECT,LPDIRECTDRAWSURFACE2, LPRECT,DWORD, LPDDBLTFX);
+    friend    HRESULT __stdcall SurfBlt3(THIS, LPRECT,LPDIRECTDRAWSURFACE3, LPRECT,DWORD, LPDDBLTFX);
+    friend    HRESULT __stdcall SurfBlt4(THIS, LPRECT,LPDIRECTDRAWSURFACE4, LPRECT,DWORD, LPDDBLTFX);
+    friend    HRESULT __stdcall SurfBltBatch(THIS, LPDDBLTBATCH, DWORD, DWORD );
+    friend    HRESULT __stdcall SurfBltFast(THIS, DWORD,DWORD,LPDIRECTDRAWSURFACE2, LPRECT,DWORD);
+    friend    HRESULT __stdcall SurfBltFast3(THIS, DWORD,DWORD,LPDIRECTDRAWSURFACE3, LPRECT,DWORD);
+    friend    HRESULT __stdcall SurfBltFast4(THIS, DWORD,DWORD,LPDIRECTDRAWSURFACE4, LPRECT,DWORD);
+    friend    HRESULT __stdcall SurfDeleteAttachedSurface(THIS, DWORD,LPDIRECTDRAWSURFACE2);
+    friend    HRESULT __stdcall SurfDeleteAttachedSurface3(THIS, DWORD,LPDIRECTDRAWSURFACE3);
+    friend    HRESULT __stdcall SurfDeleteAttachedSurface4(THIS, DWORD,LPDIRECTDRAWSURFACE4);
+    friend    HRESULT __stdcall SurfEnumAttachedSurfaces(THIS, LPVOID,LPDDENUMSURFACESCALLBACK);
+    friend    HRESULT __stdcall SurfEnumAttachedSurfaces4(THIS, LPVOID,LPDDENUMSURFACESCALLBACK2);
+    friend    HRESULT __stdcall SurfEnumOverlayZOrders(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK);
+    friend    HRESULT __stdcall SurfEnumOverlayZOrders4(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK2);
+    friend    HRESULT __stdcall SurfFlip(THIS, LPDIRECTDRAWSURFACE2 , DWORD);
+    friend    HRESULT __stdcall SurfFlip3(THIS, LPDIRECTDRAWSURFACE3 , DWORD);
+    friend    HRESULT __stdcall SurfFlip4(THIS, LPDIRECTDRAWSURFACE4 , DWORD);
+    friend    HRESULT __stdcall SurfGetAttachedSurface(THIS, LPDDSCAPS, LPDIRECTDRAWSURFACE2 FAR *);
+    friend    HRESULT __stdcall SurfGetAttachedSurface3(THIS, LPDDSCAPS, LPDIRECTDRAWSURFACE3 FAR *);
+    friend    HRESULT __stdcall SurfGetAttachedSurface4(THIS, LPDDSCAPS2, LPDIRECTDRAWSURFACE4 FAR *);
+    friend    HRESULT __stdcall SurfGetBltStatus(THIS, DWORD);
+    friend    HRESULT __stdcall SurfGetCaps(THIS, LPDDSCAPS);
+    friend    HRESULT __stdcall SurfGetCaps4(THIS, LPDDSCAPS2);
+    friend    HRESULT __stdcall SurfGetClipper(THIS, LPDIRECTDRAWCLIPPER FAR*);
+    friend    HRESULT __stdcall SurfGetColorKey(THIS, DWORD, LPDDCOLORKEY);
+    friend    HRESULT __stdcall SurfGetDC(THIS, HDC FAR *);
+    friend    HRESULT __stdcall SurfGetFlipStatus(THIS, DWORD);
+    friend    HRESULT __stdcall SurfGetOverlayPosition(THIS, LPLONG, LPLONG );
+    friend    HRESULT __stdcall SurfGetPalette(THIS, LPDIRECTDRAWPALETTE FAR*);
+    friend    HRESULT __stdcall SurfGetPixelFormat(THIS, LPDDPIXELFORMAT);
+    friend    HRESULT __stdcall SurfGetSurfaceDesc(THIS, LPDDSURFACEDESC);
+    friend    HRESULT __stdcall SurfGetSurfaceDesc4(THIS, LPDDSURFACEDESC2);
+    friend    HRESULT __stdcall SurfInitialize(THIS, LPDIRECTDRAW, LPDDSURFACEDESC);
+    friend    HRESULT __stdcall SurfInitialize4(THIS, LPDIRECTDRAW, LPDDSURFACEDESC2);
+    friend    HRESULT __stdcall SurfIsLost(THIS);
+    friend    HRESULT __stdcall SurfLock(THIS, LPRECT,LPDDSURFACEDESC,DWORD,HANDLE);
+    friend    HRESULT __stdcall SurfLock4(THIS, LPRECT,LPDDSURFACEDESC2,DWORD,HANDLE);
+    friend    HRESULT __stdcall SurfReleaseDC(THIS, HDC);
+    friend    HRESULT __stdcall SurfRestore(THIS);
+    friend    HRESULT __stdcall SurfSetClipper(THIS, LPDIRECTDRAWCLIPPER);
+    friend    HRESULT __stdcall SurfSetColorKey(THIS, DWORD, LPDDCOLORKEY);
+    friend    HRESULT __stdcall SurfSetOverlayPosition(THIS, LONG, LONG );
+    friend    HRESULT __stdcall SurfSetPalette(THIS, LPDIRECTDRAWPALETTE);
+    friend    HRESULT __stdcall SurfUnlock(THIS, LPVOID);
+    friend    HRESULT __stdcall SurfUnlock4(THIS, LPRECT);
+    friend    HRESULT __stdcall SurfUpdateOverlay(THIS, LPRECT, LPDIRECTDRAWSURFACE2,LPRECT,DWORD, LPDDOVERLAYFX);
+    friend    HRESULT __stdcall SurfUpdateOverlay3(THIS, LPRECT, LPDIRECTDRAWSURFACE3,LPRECT,DWORD, LPDDOVERLAYFX);
+    friend    HRESULT __stdcall SurfUpdateOverlay4(THIS, LPRECT, LPDIRECTDRAWSURFACE4,LPRECT,DWORD, LPDDOVERLAYFX);
+    friend    HRESULT __stdcall SurfUpdateOverlayDisplay(THIS, DWORD);
+    friend    HRESULT __stdcall SurfUpdateOverlayZOrder(THIS, DWORD, LPDIRECTDRAWSURFACE2);
+    friend    HRESULT __stdcall SurfUpdateOverlayZOrder3(THIS, DWORD, LPDIRECTDRAWSURFACE3);
+    friend    HRESULT __stdcall SurfUpdateOverlayZOrder4(THIS, DWORD, LPDIRECTDRAWSURFACE4);
+    // Added in V2 interface
+    friend    HRESULT __stdcall SurfGetDDInterface(THIS, LPVOID FAR *);
+    friend    HRESULT __stdcall SurfPageLock(THIS, DWORD);
+    friend    HRESULT __stdcall SurfPageUnlock(THIS, DWORD);
+    // Added in V3 interface
+    friend    HRESULT __stdcall SurfSetSurfaceDesc(THIS, LPDDSURFACEDESC, DWORD);
+    friend    HRESULT __stdcall SurfSetSurfaceDesc4(THIS, LPDDSURFACEDESC2, DWORD);
+    // Added in V4 interface
+    friend    HRESULT __stdcall SurfSetPrivateData(THIS, REFGUID, LPVOID, DWORD, DWORD);
+    friend    HRESULT __stdcall SurfGetPrivateData(THIS, REFGUID, LPVOID, LPDWORD);
+    friend    HRESULT __stdcall SurfFreePrivateData(THIS, REFGUID);
+    friend    HRESULT __stdcall SurfGetUniquenessValue(THIS, LPDWORD);
+    friend    HRESULT __stdcall SurfChangeUniquenessValue(THIS);
+};
+
+
+HRESULT __stdcall SurfQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj);
+ULONG   __stdcall SurfAddRef(THIS);
+ULONG   __stdcall SurfRelease(THIS);
+HRESULT __stdcall SurfAddAttachedSurface(THIS, LPDIRECTDRAWSURFACE2);
+HRESULT __stdcall SurfAddAttachedSurface3(THIS, LPDIRECTDRAWSURFACE3);
+HRESULT __stdcall SurfAddAttachedSurface4(THIS, LPDIRECTDRAWSURFACE4);
+HRESULT __stdcall SurfAddOverlayDirtyRect(THIS, LPRECT);
+HRESULT __stdcall SurfBlt(THIS, LPRECT,LPDIRECTDRAWSURFACE2, LPRECT,DWORD, LPDDBLTFX);
+HRESULT __stdcall SurfBlt3(THIS, LPRECT,LPDIRECTDRAWSURFACE3, LPRECT,DWORD, LPDDBLTFX);
+HRESULT __stdcall SurfBlt4(THIS, LPRECT,LPDIRECTDRAWSURFACE4, LPRECT,DWORD, LPDDBLTFX);
+HRESULT __stdcall SurfBltBatch(THIS, LPDDBLTBATCH, DWORD, DWORD );
+HRESULT __stdcall SurfBltFast(THIS, DWORD,DWORD,LPDIRECTDRAWSURFACE2, LPRECT,DWORD);
+HRESULT __stdcall SurfBltFast3(THIS, DWORD,DWORD,LPDIRECTDRAWSURFACE3, LPRECT,DWORD);
+HRESULT __stdcall SurfBltFast4(THIS, DWORD,DWORD,LPDIRECTDRAWSURFACE4, LPRECT,DWORD);
+HRESULT __stdcall SurfDeleteAttachedSurface(THIS, DWORD,LPDIRECTDRAWSURFACE2);
+HRESULT __stdcall SurfDeleteAttachedSurface3(THIS, DWORD,LPDIRECTDRAWSURFACE3);
+HRESULT __stdcall SurfDeleteAttachedSurface4(THIS, DWORD,LPDIRECTDRAWSURFACE4);
+HRESULT __stdcall SurfEnumAttachedSurfaces(THIS, LPVOID,LPDDENUMSURFACESCALLBACK);
+HRESULT __stdcall SurfEnumAttachedSurfaces4(THIS, LPVOID,LPDDENUMSURFACESCALLBACK2);
+HRESULT __stdcall SurfEnumOverlayZOrders(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK);
+HRESULT __stdcall SurfEnumOverlayZOrders4(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK2);
+HRESULT __stdcall SurfFlip(THIS, LPDIRECTDRAWSURFACE2 , DWORD);
+HRESULT __stdcall SurfFlip3(THIS, LPDIRECTDRAWSURFACE3 , DWORD);
+HRESULT __stdcall SurfFlip4(THIS, LPDIRECTDRAWSURFACE4 , DWORD);
+HRESULT __stdcall SurfGetAttachedSurface(THIS, LPDDSCAPS, LPDIRECTDRAWSURFACE2 FAR *);
+HRESULT __stdcall SurfGetAttachedSurface3(THIS, LPDDSCAPS, LPDIRECTDRAWSURFACE3 FAR *);
+HRESULT __stdcall SurfGetAttachedSurface4(THIS, LPDDSCAPS2, LPDIRECTDRAWSURFACE4 FAR *);
+HRESULT __stdcall SurfGetBltStatus(THIS, DWORD);
+HRESULT __stdcall SurfGetCaps4(THIS, LPDDSCAPS2);
+HRESULT __stdcall SurfGetCaps(THIS, LPDDSCAPS);
+HRESULT __stdcall SurfGetClipper(THIS, LPDIRECTDRAWCLIPPER FAR*);
+HRESULT __stdcall SurfGetColorKey(THIS, DWORD, LPDDCOLORKEY);
+HRESULT __stdcall SurfGetDC(THIS, HDC FAR *);
+HRESULT __stdcall SurfGetFlipStatus(THIS, DWORD);
+HRESULT __stdcall SurfGetOverlayPosition(THIS, LPLONG, LPLONG );
+HRESULT __stdcall SurfGetPalette(THIS, LPDIRECTDRAWPALETTE FAR*);
+HRESULT __stdcall SurfGetPixelFormat(THIS, LPDDPIXELFORMAT);
+HRESULT __stdcall SurfGetSurfaceDesc(THIS, LPDDSURFACEDESC);
+HRESULT __stdcall SurfGetSurfaceDesc4(THIS, LPDDSURFACEDESC2);
+HRESULT __stdcall SurfInitialize(THIS, LPDIRECTDRAW, LPDDSURFACEDESC);
+HRESULT __stdcall SurfInitialize4(THIS, LPDIRECTDRAW, LPDDSURFACEDESC2);
+HRESULT __stdcall SurfIsLost(THIS);
+HRESULT __stdcall SurfLock(THIS, LPRECT,LPDDSURFACEDESC,DWORD,HANDLE);
+HRESULT __stdcall SurfLock4(THIS, LPRECT,LPDDSURFACEDESC2,DWORD,HANDLE);
+HRESULT __stdcall SurfReleaseDC(THIS, HDC);
+HRESULT __stdcall SurfRestore(THIS);
+HRESULT __stdcall SurfSetClipper(THIS, LPDIRECTDRAWCLIPPER);
+HRESULT __stdcall SurfSetColorKey(THIS, DWORD, LPDDCOLORKEY);
+HRESULT __stdcall SurfSetOverlayPosition(THIS, LONG, LONG );
+HRESULT __stdcall SurfSetPalette(THIS, LPDIRECTDRAWPALETTE);
+HRESULT __stdcall SurfUnlock(THIS, LPVOID);
+HRESULT __stdcall SurfUnlock4(THIS, LPRECT);
+HRESULT __stdcall SurfUpdateOverlay(THIS, LPRECT, LPDIRECTDRAWSURFACE2,LPRECT,DWORD, LPDDOVERLAYFX);
+HRESULT __stdcall SurfUpdateOverlay3(THIS, LPRECT, LPDIRECTDRAWSURFACE3,LPRECT,DWORD, LPDDOVERLAYFX);
+HRESULT __stdcall SurfUpdateOverlay4(THIS, LPRECT, LPDIRECTDRAWSURFACE4,LPRECT,DWORD, LPDDOVERLAYFX);
+HRESULT __stdcall SurfUpdateOverlayDisplay(THIS, DWORD);
+HRESULT __stdcall SurfUpdateOverlayZOrder(THIS, DWORD, LPDIRECTDRAWSURFACE2);
+HRESULT __stdcall SurfUpdateOverlayZOrder3(THIS, DWORD, LPDIRECTDRAWSURFACE3);
+HRESULT __stdcall SurfUpdateOverlayZOrder4(THIS, DWORD, LPDIRECTDRAWSURFACE4);
+HRESULT __stdcall SurfGetDDInterface(THIS, LPVOID FAR *);
+HRESULT __stdcall SurfPageLock(THIS, DWORD);
+HRESULT __stdcall SurfPageUnlock(THIS, DWORD);
+HRESULT __stdcall SurfSetSurfaceDesc(THIS, LPDDSURFACEDESC, DWORD);
+HRESULT __stdcall SurfSetSurfaceDesc4(THIS, LPDDSURFACEDESC2, DWORD);
+HRESULT __stdcall SurfSetPrivateData(THIS, REFGUID, LPVOID, DWORD, DWORD);
+HRESULT __stdcall SurfGetPrivateData(THIS, REFGUID, LPVOID, LPDWORD);
+HRESULT __stdcall SurfFreePrivateData(THIS, REFGUID);
+HRESULT __stdcall SurfGetUniquenessValue(THIS, LPDWORD);
+HRESULT __stdcall SurfChangeUniquenessValue(THIS);
+
+void __cdecl MoveRects(char* pBuffer, LPRECT lpDestRect, LPRECT lpSrcRect, int bbp, LONG lPitch);
+void __cdecl TransSRCBlit8(LPDDSURFACEDESC2 pDestDesc, LPDDSURFACEDESC2 pSrcDesc,  char *pAlpha, LPRECT lpSrcRect);
+void __cdecl TransSRCBlit16(LPDDSURFACEDESC2 pDestDesc, LPDDSURFACEDESC2 pSrcDesc,  char *pAlpha, LPRECT lpSrcRect);
+void __cdecl TransSRCBlit24(LPDDSURFACEDESC2 pDestDesc, LPDDSURFACEDESC2 pSrcDesc,  char *pAlpha, LPRECT lpSrcRect);
+void __cdecl TransSRCBlit32(LPDDSURFACEDESC2 pDestDesc, LPDDSURFACEDESC2 pSrcDesc,  char *pAlpha, LPRECT lpSrcRect);
+
+
+#endif
Index: trunk/src/ddraw/new/OS2UTIL.CPP
===================================================================
--- trunk/src/ddraw/new/OS2UTIL.CPP	(revision 3345)
+++ trunk/src/ddraw/new/OS2UTIL.CPP	(revision 3345)
@@ -0,0 +1,95 @@
+/* $Id: OS2UTIL.CPP,v 1.1 2000-04-07 18:21:08 mike Exp $ */
+
+/*
+ * OS/2 Utility functions
+ *
+ * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#define INCL_DOSMEMMGR
+#define INCL_DOSDEVICES
+#include <os2wrap.h>
+#include <misc.h>
+#include "os2util.h"
+#include "cio2.h"
+
+//******************************************************************************
+//******************************************************************************
+char *OS2AllocMem(ULONG size)
+{
+ PVOID  lpMem;
+ APIRET rc;
+
+  rc = DosAllocMem(&lpMem, size, PAG_READ|PAG_WRITE|PAG_COMMIT);
+  if(rc) {
+    dprintf(("DDRAW: DosAllocMem returned %d", rc));
+    return(NULL);
+  }
+  return((char *)lpMem);
+}
+//******************************************************************************
+//******************************************************************************
+void OS2FreeMem(char *lpMem)
+{
+ APIRET rc;
+
+  rc = DosFreeMem(lpMem);
+  if(rc) {
+    dprintf(("DDRAW: DosFreeMem returned %d", rc));
+  }
+}//******************************************************************************
+//******************************************************************************
+void OS2MaximizeWindow(HWND hwndClient)
+{
+  WinSetWindowPos(hwndClient, HWND_TOP, 0, 0, 0, 0, SWP_MAXIMIZE);
+}
+//******************************************************************************
+//******************************************************************************
+
+HWND WIN32API WindowFromDC(HDC hdc);
+HWND Win32ToOS2Handle(HWND hwnd);
+BOOL    APIENTRY _GpiEnableYInversion (HPS hps, LONG lHeight);
+
+void InverseDC(HDC hdc, LONG lHeight)
+{
+ USHORT sel = RestoreOS2FS();
+
+ _GpiEnableYInversion( WinGetPS( Win32ToOS2Handle( WindowFromDC(hdc) ) ), lHeight);
+ SetFS(sel);
+
+}
+
+int InitIO()
+{
+  WORD  gdt;
+  HRESULT rc;
+  HFILE  device;
+  ULONG  ulAction;
+
+  return 1;
+
+  rc = DosOpen( "\\dev\\fastio$",
+                &device,
+                &ulAction,
+                0,0,1,
+                OPEN_ACCESS_READWRITE|OPEN_SHARE_DENYNONE,
+                0);
+  if(rc)
+    return rc;
+
+  rc = DosDevIOCtl( device, 118, 100, 0,0,0,&gdt,2,&ulAction);
+
+  DosClose(device);
+
+  if(rc)
+  {
+    return rc;
+  }
+
+  io_init2(gdt);
+
+  return 0;
+}
+
Index: trunk/src/ddraw/new/OS2UTIL.H
===================================================================
--- trunk/src/ddraw/new/OS2UTIL.H	(revision 3345)
+++ trunk/src/ddraw/new/OS2UTIL.H	(revision 3345)
@@ -0,0 +1,19 @@
+/* $Id: OS2UTIL.H,v 1.1 2000-04-07 18:21:08 mike Exp $ */
+
+/*
+ * OS/2 Utility functions
+ *
+ * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __OS2UTIL_H__
+#define __OS2UTIL_H__
+
+char *OS2AllocMem(ULONG size);
+void  OS2FreeMem(char *lpMem);
+void  OS2MaximizeWindow(HWND hwndClient);
+void InverseDC(HDC hdc, LONG lHeight);
+int InitIO();
+#endif
Index: trunk/src/ddraw/new/SVGADEFS.H
===================================================================
--- trunk/src/ddraw/new/SVGADEFS.H	(revision 3345)
+++ trunk/src/ddraw/new/SVGADEFS.H	(revision 3345)
@@ -0,0 +1,785 @@
+/*****************************************************************************
+ *
+ * SOURCE FILE NAME = SVGADEFS.H
+ *
+ * DESCRIPTIVE NAME =
+ *
+ * Copyright : COPYRIGHT IBM CORPORATION, 1991, 1992
+ *             Copyright Microsoft Corporation, 1990
+ *             LICENSED MATERIAL - PROGRAM PROPERTY OF IBM
+ *             REFER TO COPYRIGHT INSTRUCTION FORM#G120-2083
+ *             RESTRICTED MATERIALS OF IBM
+ *             IBM CONFIDENTIAL
+ *
+ * VERSION = V2.0
+ *
+ * DATE
+ *
+ * DESCRIPTION  Contains SVGA definitions.
+ *
+ * FUNCTIONS
+ *
+ * NOTES        When included into VVID sources, #ifdef SVGA
+ *              must be used before #include!
+ *
+ * STRUCTURES
+ *
+ * EXTERNAL REFERENCES
+ *
+ * EXTERNAL FUNCTIONS
+ *
+ * CHANGE ACTIVITY =
+ *   DATE      FLAG        APAR   CHANGE DESCRIPTION
+ *   --------  ----------  -----  --------------------------------------
+ *   mm/dd/yy  @Vr.mpppxx   xxxxx xxxxxxx
+ *   12/29/92  @V2.0SEN00         Created.
+ *   03/12/93  @V2.0SEN01         OEMINFO structure changed.
+ *   08/31/93  @V2.1YEE02         Recognize Cirrus Logic GD5428 chip
+ *   10/28/93  @V2.1MNH00         Recognize Additional Adapters
+ *   12/06/93  @V2.1YEE05 D 76476 Add ID for Chips & Technologies
+ *   12/15/93  @V2.1YEE06 D 76685 Add Artist Graphics manufacturer
+ *   02/21/94  @V2.1MNH01 D 79562 Recognize Additional Adapters/Chips
+ *   04/14/94  @V2.1MNH05 D 81883 WD90C24 allow more unlocks
+ *   04/26/94  @V2.1MNH08 D 82003 WD90C24 preserve locks for BIOS setmodes
+ *   05/12/94  @V2.1YEE08         Add more Cirrus chipsets
+ *   05/13/94  @V2.1MNH13 F 74819 ATI Mach8/32 check in files
+ *   05/18/94  @V2.1MNH14         WD90C33 Parse new style PMI
+ *   06/22/94  @V2.1JWK02 D 87347 Define Tseng Chip Names for consistant use
+ *   07/25/94  @V2.1JWK03 D 89911 Define Tseng W32xD Revisions
+ *   07/28/94  @V2.1YEE09 D 88172 Define a Chips and Technologies chiptype
+ *   08/02/94  @V2.1MNH25 D 91551 Fix various DAC programming problems
+ *   08/19/94  @V2.1MNH37 D 94209 Add more DAC detection
+ *   09/01/94  @V2.1YEE10 D 89853 Add support for S3864 with ICD2061 clock chip
+ *   09/10/94  @V2.2TSU00 D 86373 Weitek: PCI screen01 incorrect
+ *   09/15/94  @V2.1YEE11         Identify DAC as RGB (blue first) or BGR (red first)
+ *   09/17/94  @V2.2DAI01 D 92593 Adding monitor configuration enhancements.
+ *   09/26/94  @V2.2SEN05 D 97637 Changing Music DAC 4910 from BGR to RGB.
+ *   10/05/94  @V2.1MNH51 D101610 Increase size of CLEANDATA for MACH32
+ *   10/25/94  @V2.2JWK23 D103192 TSENG Rev D wont install
+ *   11/30/94  @V3.0YEE01 D105950 Support S3 964
+ *   01/20/95  @V3.0YEE02 D 99391 Support TBird-Enhanced (800x600 flat panel)
+ *   01/16/95  @V3.0YEE03 D114992 Add new chip manufacturers
+ *   01/24/95  @V3.0ITO01         ThinkPad 230 Support (IBM-J local)
+ *   04/19/95  @V3.0DAI01 D119247 Add DevEscape functions and structures for extra capability support
+ *   04/28/95  @V3.0YEE04 D120303 Treat ICS5342 unique from ICS5341
+ *   05/17/95  @V3.0JWK04 D113889 Add Toshiba manufacturer and models
+ *   05/30/95  @V3.0JWK11 D123835 allow displayless machines to init.  Requires
+ *                                /nodisplay on device driver statement in config.sys
+ *   07/25/95  @IBMJ-S3GEN   D386 More S3 chips support
+ *   07/27/95  @V3.0JWK18 D131213 fix AT&T 408/409/499 DAC programming
+ *   08/02/95  @V3.0JWK21 D131829 Identify and Support ATI MACH64 version 'CT'
+ *   09/11/95  @V3.2SEN01 D133791 Adding real mode software interrupt support to
+ *                                VIDEOPMI.
+ *   09/14/95  @V3.0JWK25 D126118 NEC C24 prevent 800x600x64k.  Add NEC Manufacturer and model
+ *   11/10/95  @V3.2JWK09 D143505 provide compatability with new VIDEO_ADAPTER structures
+ *   12/15/95  @V3.0TSU00         Make videopmi backward compatible
+ *   02/12/96  @V3.1MNH01 D148203 Merge DBCS-J source w/SBCS source
+ *   02/14/96  @V3.2TSU00 D148283 Merlin PBE, support linear aperture
+ *   02/16/96  @V3.0YEE06 D148329 APM support
+ *   05/14/96  @V3.1MNH10 D151513 S3 Trio Chips Identification
+ *****************************************************************************/
+
+/* NOINC */
+
+#include <svgapmi.h>
+
+/* INC */
+
+#define INCL_DOSERRORS
+#define MAX_LOCKUNLOCKCMD       40                              /*@V2.1MNH08*/
+#define MAX_CLEANDATA          200      /* Includes DACs */     /*@V3.0YEE01*/
+#define MAX_SETBANK_CMD         25                              /*@V2.1MNH14*/
+#define MAX_GETBANK_CMD         20                              /*@V2.1MNH14*/
+#define MAX_MODESET_CMD         84                              /*@V2.1MNH14*/
+
+
+#define DEFAULT_ADAPTER       (-1)
+#define UNKNOWN_ADAPTER         0
+#define VIDEO7_ADAPTER          1       /* bugbug line up with cleanups! */
+#define TRIDENT_ADAPTER         2
+#define TSENG_ADAPTER           3
+#define WESTERNDIG_ADAPTER      4
+#define ATI_ADAPTER             5
+#define IBM_ADAPTER             6
+#define CIRRUS_ADAPTER          7
+#define S3_ADAPTER              8
+#define CHIPS_ADAPTER           9                      /* @V2.1YEE05 */
+#define WEITEK_ADAPTER          10                     /* @V2.1MNH00 */
+#define NUMBER9_ADAPTER         11                     /* @V2.1YEE10 */
+#define GENERIC_PCISVGA_ADAPTER 12                      //@senja
+#define OAK_ADAPTER             13                     /* @V3.0YEE03 */
+#define MATROX_ADAPTER          14                     /* @V3.0YEE03 */
+#define BROOKTREE_ADAPTER       15                     /* @V3.0YEE03 */
+#define NVIDIA_ADAPTER          16                     /* @V3.0YEE03 */
+#define ALLIANCE_ADAPTER        17                     /* @V3.0YEE03 */
+#define AVANCE_ADAPTER          18                     /* @V3.0YEE03 */
+#define MEDIAVISION_ADAPTER     19                     /* @V3.0YEE03 */
+#define ARKLOGIC_ADAPTER        20                     /* @V3.0YEE03 */
+#define RADIUS_ADAPTER          21                     /* @V3.0YEE03 */
+#define THREE_D_LABS_ADAPTER    22                     /* @V3.0YEE03 */
+#define NCR_ADAPTER             23                     /* @V3.0YEE03 */
+#define IIT_ADAPTER             24                     /* @V3.0YEE03 */
+#define APPIAN_ADAPTER          25                     /* @V3.0YEE03 */
+#define SIERRA_ADAPTER          26                     /* @V3.0YEE03 */
+#define CORNERSTONE_ADAPTER     27                     /* @V3.0YEE03 */
+#define DIGITAL_ADAPTER         28                     /* @V3.0YEE03 */
+#define COMPAQ_ADAPTER          29                     /* @V3.0YEE03 */
+#define INFOTRONIC_ADAPTER      30                     /* @V3.0YEE03 */
+#define OPTI_ADAPTER            31                     /* @V3.0YEE03 */
+#define NULL_ADAPTER            32                     /* @V3.0JWK11 */
+ /* remember to update SVGA_LASTADAPTER when adding new adapter support */
+
+#define SVGA_FIRSTADAPTER       VIDEO7_ADAPTER         /* @V2.1YEE03 */
+#define SVGA_LASTADAPTER        NULL_ADAPTER           /* @V3.0JWK11 */
+
+/* @V2.1MNH13 start */
+#ifdef FAMILY2
+  #define ORCHID_MC_ADAPTER     2       /* @V2.0SEN06 */
+  #define ORCHID_MC_ID          0x86    /* @V2.0SEN06 */
+#endif
+
+/*
+** DAC types
+*/
+
+#define VGA_DAC           0                                     /*@V2.1MNH23*/
+#define DEFAULT_DAC       VGA_DAC                               /*@V2.1MNH23*/
+#define HICOLOR_DAC       1      /* Unidentified */             /*@V2.1MNH17*/
+#define WINBOND_DAC       HICOLOR_DAC                           /*@V2.1MNH23*/
+#define BT485_DAC         2      /* Brooktree 485 */            /*@V2.1MNH20*/
+#define Weitek_BT485DAC   3      /* BT485 used by Weitek      */
+#define SC15025_DAC       4      /* SC15025                   */
+#define SierraDAC         SC15025_DAC /* Use more specific name! */
+#define ATT490_DAC        5
+#define ATTDAC            ATT490_DAC /* Use more specific name! */
+#define MU9C1880_DAC      6      /* MU9C4870, MU9C1880, SS2410*/
+#define MU9C4870_DAC      MU9C1880_DAC                          /*@V2.1MNH23*/
+
+#define TRUECOLOR_DAC     7                                     /*@V2.1MNH17*/
+#define IMSG173_DAC       8      /*These DACS identified, but not programmed*/
+#define InmosDAC          IMSG173_DAC /* Use more specific name! */
+#define CH8398_DAC        9
+#define ChrontelDAC       CH8398_DAC /* Use more specific name! */
+#define CIRRUS_DAC       10
+#define ICS5341_DAC      11
+#define SGS1702_DAC      12
+#define SGSThomsonDAC16  SGS1702_DAC /* Use more specific name! */
+#define SGS1703_DAC      13                                     /*@V2.1MNH23*/
+#define MU9C4910_DAC     14      /* MU9C4910 (blue byte first) */
+                                 /*  note that the MU9C1880 is also true color, but */
+                                 /*       it does not need to be identified because */
+                                 /*       behaves like the others in its group      */
+#define MusicDAC16RGB    MU9C4910_DAC /* Use more specific name! */
+#define ATI68830_DAC     15      /* ATI 68830 & compatible  @V2.1MNH29  */
+#define S3SDAC_DAC       16      /* S3 SDAC                 @V2.1MNH29  */
+#define ATT498_DAC       17      /* AT&T 498 CLOCKDAC ID=$98 no programmable clocks      @V2.1MNH29  */
+#define SGS1700_DAC      18      /* SGS 1700 DAC            @V2.1MNH29  */
+#define TLC34075_DAC     19      /* Texas Instruments TLC34075*/
+#define ATI68875_DAC     TLC34075_DAC
+#define BT476_DAC        20      /* Brooktree 476/478       @V2.1MNH29  */
+#define BT478_DAC        BT476_DAC
+#define BT481_DAC        21      /* Brooktree 481/482       @V2.1MNH29  */
+#define BT482_DAC        BT481_DAC
+#define ATI68860_DAC     22      /* ATI 68860/68880         @V2.1MNH29  */
+#define MU9CBUG_DAC      23
+#define CH8391_DAC       24
+#define W82C490_DAC      25
+#define ATT491_DAC       26
+#define ATT492_DAC       27
+#define ATT493_DAC       28
+#define ATT497_DAC       29
+#define WD90C24_DAC      30
+#define MU9C9910_DAC     31      /* (blue byte first) */
+#define ATT409_DAC       32          //ID=$09 16 bit pixel I/O
+#define ATT499_DAC       33          //ID=$99 24 bit Pixel I/0  /*@V3.0YEE03*/
+#define TI3025_DAC       34      /* TI Viewpoint 3025 CLOCKDAC*//*@V3.0YEE01*/
+#define TI3020_DAC       35      /* TI Viewpoint 3020 CLOCKDAC*//*@V3.0YEE03*/
+#define ICS5342_DAC      36                                     /*@V3.0YEE04*/
+#define ATT408_DAC       ATT409_DAC  //ID=$09 HW pinouts diff   /*@V3.0JWK18*/
+#define NULL_DAC         37                                     /*@V3.0JWK11*/
+#define IMBEDDED_DAC     38      //ATI MACH64 'CT'              /*@V3.0JWK21*/
+#define S3TRIO_DAC       39      /* S3 TRIO DAC               *//*@V3.0YEE05*/
+#define MAX_DAC          40                                     /*@V3.0JWK21*/
+
+#define VGADAC_NAME     "VGA_RGB"                               /*@V2.1MNH23*/
+#define HICOLOR_NAME    "HICOLOR_RGB"                           /*@V2.1MNH17*/
+#define BT485_NAME      "BT485_RGB"                             /*@V2.1MNH20*/
+#define VIPER_NAME      "BT485_RGB"
+#define SC15025_NAME    "SC15025_RGB"
+#define ATT490_NAME     "ATT20C490_RGB"                         /*@V2.1MNH29*/
+#define MU9C1880_NAME   "MU9C1880_BGR"
+#define TRUECOLOR_NAME  "TRUECOLOR_RGB"                         /*@V2.1MNH17*/
+#define IMSG173_NAME    "IMSG173_RGB"
+#define CH8398_NAME     "CH8398_RGB"
+#define CIRRUS_NAME     "CIRRUS_RGB"
+#define ICS5341_NAME    "ICS5341_RGB"
+#define SGS1702_NAME    "SGS1702_RGB"
+#define SGS1703_NAME    "SGS1703_RGB"                           /*@V2.1MNH23*/
+#define MU9C4910_NAME   "MU9C4910_RGB"  /* was BGR */           /*@V2.2SEN05*/
+#define ATI68830_NAME   "ATI68830_RGB"                          /*@V2.1MNH20*/
+#define S3SDAC_NAME     "S3SDAC_RGB"                            /*@V2.1YEE02*/
+#define ATT498_NAME     "ATT20C498_RGB"                         /*@V2.1MNH29*/
+#define SGS1700_NAME    "SGS1700_RGB"                           /*@V2.1YEE02*/
+#define TLC34075_NAME   "TLC34075_RGB"                          /*@V2.1MNH20*/
+#define ATI68875_NAME   "ATI68875_RGB"                          /*@V2.1MNH20*/
+#define BT476_NAME      "BT476_RGB"                             /*@V2.1MNH20*/
+#define BT481_NAME      "BT481_RGB"                             /*@V2.1MNH20*/
+#define ATI68860_NAME   "ATI68860_RGB"                          /*@V2.1MNH20*/
+#define MU9CBUG_NAME    "MU9C1880BUG_BGR"                       /*@V2.1MNH29*/
+#define CH8391_NAME     "CH8391_RGB"                            /*@V2.1MNH29*/
+#define W82C490_NAME    "W82C490_RGB"                           /*@V2.1MNH29*/
+#define ATT491_NAME     "ATT20C491_RGB"                         /*@V2.1MNH29*/
+#define ATT492_NAME     "ATT20C492_RGB"                         /*@V2.1MNH29*/
+#define ATT493_NAME     "ATT20C493_RGB"                         /*@V2.1MNH29*/
+#define ATT497_NAME     "ATT20C497_RGB"                         /*@V2.1MNH29*/
+#define WD90C24_NAME    "WD90C24_RGB"                           /*@V2.1MNH35*/
+#define MU9C9910_NAME   "MU9C9910_RGB"                          /*@V2.1MNH37*/
+#define ATT499_NAME     "ATT20C499_RGB"                         /*@V3.0JWK18*/
+#define ATT498_NAME     "ATT20C498_RGB"                         /*@V3.0JWK18*/
+#define ATT409_NAME     "ATT20C409_RGB"                         /*@V2.1YEE10*/
+#define TI3025_NAME     "TVP3025_RGB" /* TI Viewpoint 3025 DAC*//*@V3.0YEE01*/
+#define TI3020_NAME     "TVP3020_RGB" /* TI Viewpoint 3020 DAC*//*@V3.0YEE03*/
+#define ICS5342_NAME    "ICS5342_RGB"                           /*@V3.0YEE04*/
+#define NULL_DAC_NAME   "NULLDAC_RGB"                           /*@V3.0JWK11*/
+#define IMBEDDED_NAME   "IMBEDDED_RGB"/*ATI MACH64CT internal *//*@V3.0JWK21*/
+#define S3TRIODAC_NAME  "S3_RGB"      /* S3 TRIO DAC          *//*@V3.0YEE05*/
+
+/* NOINC */
+typedef struct _DACINFO {       /* dac */
+  USHORT        DACFamily;
+  USHORT        DACType;
+} DACINFO;
+
+/* INC */
+
+#define WEITEK_P9000_INCREMENT  0x0040 //Spacing between potential bases.
+#define WEITEK_P9000_REGISTERS  0x0010 //Base address offset for registers.
+#define WEITEK_P9000_VRAM       0x0020 //Base address offset for VRAM.
+#define WEITEK_P9000_SYSCONFIG  0x0004 //Offset for config reg
+#define WEITEK_P9000_INTERRUPT  0x0008 //Offset for interrupt reg
+#define WEITEK_P9000_ENABLE     0x000c //Offset for interrupt enable reg
+#define WEITEK_P9000_MEMCONFIG  0x0184 //Offset for memory config reg
+#define WEITEK_P9000_REGLENGTH  0x2000 //Length for register addressability
+/* @V2.1MNH13 end   */
+
+#define UNKNOWN_CHIP            0
+
+#define VIDEO7_HT205_CHIP       1
+#define VIDEO7_HT208_CHIP       2
+#define VIDEO7_HT209_CHIP       3
+#define MAX_VIDEO7_CHIP         VIDEO7_HT209_CHIP               /*@V2.1MNH01*/
+
+#define VIDEO7_HT205_NAME       "HT205"                         /*@V2.1MNH20*/
+#define VIDEO7_HT208_NAME       "HT208"                         /*@V2.1MNH20*/
+#define VIDEO7_HT209_NAME       "HT209"                         /*@V2.1MNH20*/
+
+#define TRIDENT_8800_CHIP       1
+#define TRIDENT_8900_CHIP       2
+#define MAX_TRIDENT_CHIP        TRIDENT_8900_CHIP               /*@V2.1MNH01*/
+
+#define TRIDENT_8800_NAME       "TR8800"                        /*@V2.1MNH20*/
+#define TRIDENT_8900_NAME       "TR8900"                        /*@V2.1MNH20*/
+
+
+#define TSENG_ET3000_CHIP       1
+#define TSENG_ET4000_CHIP       2
+#define TSENG_ET4000W32_CHIP    3    /* w32                   @V2.1MNH01*/
+#define TSENG_ET4000W32I_CHIP   4    /* w32i (level a)        @V2.1JWK01*/
+#define TSENG_ET4000W32IB_CHIP  5    /* w32i level b          @V2.1JWK01*/
+#define TSENG_ET4000W32IC_CHIP  6    /* w32i level c          @V2.1JWK01*/
+#define TSENG_ET4000W32PA_CHIP  7    /* w32p level a          @V2.1JWK01*/
+#define TSENG_ET4000W32PB_CHIP  8    /* w32p level b          @V2.1JWK01*/
+#define TSENG_ET4000W32PC_CHIP  9    /* w32p level c          @V2.1JWK01*/
+#define TSENG_ET4000W32ID_CHIP 10    /* w32i level d          @V2.1JWK03*/
+#define TSENG_ET4000W32PD_CHIP 11    /* w32p level d          @V2.1JWK03*/
+#define TSENG_ET4000W32PX_CHIP 12    /* all others            @V2.1JWK23*/
+#define MAX_TSENG_CHIP         12
+
+#define TSENG_ET3000_NAME       "ET3000"                        /*@V2.1JWK02*/
+#define TSENG_ET4000_NAME       "ET4000"                        /*@V2.1JWK02*/
+#define TSENG_ET4000W32_NAME    "ET4000W32"                     /*@V2.1JWK02*/
+#define TSENG_ET4000W32I_NAME   "ET4000W32IREVA"                /*@V2.1JWK02*/
+#define TSENG_ET4000W32IB_NAME  "ET4000W32IREVB"                /*@V2.1JWK02*/
+#define TSENG_ET4000W32IC_NAME  "ET4000W32IREVC"                /*@V2.1JWK02*/
+#define TSENG_ET4000W32PA_NAME  "ET4000W32PREVA"                /*@V2.1JWK02*/
+#define TSENG_ET4000W32PB_NAME  "ET4000W32PREVB"                /*@V2.1JWK02*/
+#define TSENG_ET4000W32PC_NAME  "ET4000W32PREVC"                /*@V2.1JWK02*/
+#define TSENG_ET4000W32ID_NAME  "ET4000W32IREVD"                /*@V2.1JWK03*/
+#define TSENG_ET4000W32PD_NAME  "ET4000W32PREVD"                /*@V2.1JWK03*/
+#define TSENG_ET4000W32PX_NAME  "ET4000W32PREVC_COMPATABLE"     /*@V2.1JWK23*/
+
+#define WESTERNDIG_PVGA1A_CHIP  1
+#define WESTERNDIG_WD9000_CHIP  2 /* PVGA1B */
+#define WESTERNDIG_WD9011_CHIP  3 /* PVGA1C */
+#define WESTERNDIG_WD9030_CHIP  4 /* PVGA1D */
+#define WESTERNDIG_WD9026_CHIP  5 /* PVGA1F */                  /*@V2.1MNH01*/
+#define WESTERNDIG_WD9027_CHIP  6                               /*@V2.1MNH01*/
+#define WESTERNDIG_WD9031_CHIP  7 /* PVGA1DW */                 /*@V2.1MNH01*/
+#define WESTERNDIG_WD9024_CHIP  8                               /*@V2.1MNH01*/
+#define WESTERNDIG_WD9033_CHIP  9 /* PVGA2DW */                 /*@V2.1MNH01*/
+#define MAX_WESTERNDIG_CHIP     WESTERNDIG_WD9033_CHIP          /*@V2.1MNH01*/
+
+#define WESTERNDIG_PVGA1A_NAME  "PVGA1A"                        /*@V2.1MNH20*/
+#define WESTERNDIG_WD9000_NAME  "PVGA1B"                        /*@V2.1MNH20*/
+#define WESTERNDIG_WD9011_NAME  "PVGA1C"                        /*@V2.1MNH20*/
+#define WESTERNDIG_WD9030_NAME  "PVGA1D"                        /*@V2.1MNH20*/
+#define WESTERNDIG_WD9026_NAME  "WD90C26"                       /*@V2.1MNH20*/
+#define WESTERNDIG_WD9027_NAME  "WD90C27"                       /*@V2.1MNH20*/
+#define WESTERNDIG_WD9031_NAME  "WD90C31"                       /*@V2.1MNH20*/
+#define WESTERNDIG_WD9024_NAME  "WD90C24"                       /*@V2.1MNH20*/
+#define WESTERNDIG_WD9033_NAME  "WD90C33"                       /*@V2.1MNH20*/
+
+#define ATI_18800_CHIP          1 /*VGAWONDER*/
+#define ATI_28800_CHIP          2 /*VGAWONDER+/XL*/
+#define ATI_38800_CHIP          3 /*MACH8/GraphicsUltra*/       /*@V2.1MNH01*/
+#define ATI_68800_CHIP          4 /*MACH32/GraphicsUltraPro*/   /*@V2.1MNH01*/
+#define ATI_88800_CHIP          5 /*MACH64*/                    /*@V2.1MNH01*/
+#define ATI_88800CT_CHIP        6 /*MACH64CT*/                  /*@V3.0JWK21*/
+#define MAX_ATI_CHIP            ATI_88800CT_CHIP                /*@V3.0JWK21*/
+
+#define ATI_18800_NAME          "ATI18800"                      /*@V2.1MNH20*/
+#define ATI_28800_NAME          "ATI28800"                      /*@V2.1MNH20*/
+#define ATI_38800_NAME          "ATI38800MACH8"                 /*@V2.1MNH21*/
+#define ATI_68800_NAME          "ATI68800MACH32"                /*@V2.1MNH21*/
+#define ATI_88800_NAME          "ATI88800MACH64"                /*@V2.1MNH21*/
+#define ATI_88800CT_NAME        "ATI88800MACH64CT"              /*@V3.0JWK21*/
+
+#define IBM_SVGA_CHIP           1
+#define MAX_IBM_CHIP            IBM_SVGA_CHIP                   /*@V2.1MNH01*/
+
+#define IBM_SVGA_NAME           "IBMSVGA"                       /*@V2.1MNH20*/
+
+#define CIRRUS_5420_CHIP        1                               /*@V2.1YEE08*/
+#define CIRRUS_5422_CHIP        2
+#define CIRRUS_5424_CHIP        3
+#define CIRRUS_5426_CHIP        4
+#define CIRRUS_5428_CHIP        5                               /*@V2.1YEE02*/
+#define CIRRUS_5429_CHIP        6                               /*@V2.1YEE08*/
+#define CIRRUS_543X_CHIP        7                               /*@V2.1YEE08*/
+#define CIRRUS_5434_CHIP        8                               /*@V2.1YEE08*/
+#define CIRRUS_6235_CHIP        9                               /*@V3.0ITO01*/
+#define MAX_CIRRUS_CHIP         CIRRUS_6235_CHIP                /*@V3.0ITO01*/
+
+#define CIRRUS_5420_NAME        "GD5420"                        /*@V2.1MNH20*/
+#define CIRRUS_5422_NAME        "GD5422"                        /*@V2.1MNH20*/
+#define CIRRUS_5424_NAME        "GD5424"                        /*@V2.1MNH20*/
+#define CIRRUS_5426_NAME        "GD5426"                        /*@V2.1MNH20*/
+#define CIRRUS_5428_NAME        "GD5428"                        /*@V2.1MNH20*/
+#define CIRRUS_5429_NAME        "GD5429"                        /*@V2.1MNH20*/
+#define CIRRUS_543X_NAME        "GD543X"                        /*@V2.1MNH20*/
+#define CIRRUS_5434_NAME        "GD5434"                        /*@V2.1MNH20*/
+#define CIRRUS_6235_NAME        "GD6235"                        /*@V3.0ITO01*/
+
+#define S3_86C805_CHIP          1           /* 801 or 805 */
+#define S3_86C928_CHIP          2
+#define S3_86C911_CHIP          3           /* @V2.1YEE04 */
+#define S3_86C864_CHIP          4                               /*@V2.1MNH01*/
+//#define S3_DXP_CHIP              S3_86C864_CHIP               /*@IBMJ-S3GEN*/
+#define S3_86C964_CHIP          5                               /*@V2.1MNH01*/
+//#define S3_VXP_CHIP              S3_86C964_CHIP               /*@IBMJ-S3GEN*/
+
+/* These chip IDs added by S3 */                                /*@V3.1MNH10*/
+#define S3_86C868_CHIP          6                               /*@V3.1MNH10*/
+//#define S3_V868_CHIP             S3_86C868_CHIP               /*@V3.1MNH10*/
+#define S3_86C968_CHIP          7                               /*@V3.1MNH10*/
+//#define S3_V968_CHIP             S3_86C968_CHIP               /*@V3.1MNH10*/
+#define S3_86C732_CHIP          8                               /*@V3.1MNH10*/
+//#define S3_Trio32_CHIP           S3_86C732_CHIP               /*@V3.1MNH10*/
+#define S3_86C764_CHIP          9                               /*@V3.1MNH10*/
+//#define S3_Trio64_CHIP           S3_86C764_CHIP               /*@V3.1MNH10*/
+#define S3_86C765_CHIP         10                               /*@V3.1MNH10*/
+//#define S3_V765_CHIP             S3_86C765_CHIP               /*@V3.1MNH10*/
+#define S3_86CM65_CHIP         11 /* Aurora64V */               /*@V3.1MNH10*/
+#define S3_86C325_CHIP         12 /* ViRGE */                   /*@V3.1MNH10*/
+#define S3_86C988_CHIP         13 /* ViRGE/vX chip */           /*@V3.1MNH10*/
+#define S3_86C767_CHIP         14 /* Trio64UV+ */               /*@V3.1MNH10*/
+#define S3_86C765_FAMILY       15 /* Trio65V+ family compat */  /*@V3.1MNH10*/
+
+#define S3_86C924_CHIP         16                               /*@V3.1MNH10*/
+#define S3_86C866_CHIP         17                               /*@V3.1MNH10*/
+//#define S3_V866_CHIP             S3_86C866_CHIP               /*@V3.1MNH10*/
+#define S3_86C928PCI_CHIP      18                               /*@V3.1MNH10*/
+#define MAX_S3_CHIP              S3_86C928PCI_CHIP              /*@V3.1MNH10*/
+
+#define S3_86C805_NAME          "S386C80X"                      /*@V2.1MNH20*/
+#define S3_86C928_NAME          "S386C928"                      /*@V2.1MNH20*/
+#define S3_86C911_NAME          "S386C911"                      /*@V2.1MNH20*/
+#define S3_86C864_NAME          "VISION864"       /* S386C864 *//*@V3.1MNH10*/
+#define S3_86C964_NAME          "VISION964"       /* S386C964 *//*@V3.1MNH10*/
+
+#define S3_86C868_NAME          "VISION868"                     /*@V3.1MNH10*/
+//#define S3_V868_NAME            S3_86C868_NAME                /*@V3.1MNH10*/
+#define S3_86C968_NAME          "VISION968"                     /*@V3.1MNH10*/
+//#define S3_V968_NAME            S3_86C968_NAME                /*@V3.1MNH10*/
+#define S3_86C732_NAME          "S3TRIO32"                      /*@V3.1MNH10*/
+//#define S3_Trio32_NAME          S3_86C764_NAME                /*@V3.1MNH10*/
+#define S3_86C764_NAME          "S3TRIO64"                      /*@V3.1MNH10*/
+//#define S3_Trio64_NAME          S3_86C732_NAME                /*@V3.1MNH10*/
+#define S3_86C765_NAME          "S3TRIO64V+"                    /*@V3.1MNH10*/
+//#define S3_V765_NAME            S3_86C765_NAME                /*@V3.1MNH10*/
+#define S3_86CM65_NAME          "S3AURORA64V+"                  /*@V3.1MNH10*/
+#define S3_86C325_NAME          "S3VIRGE"                       /*@V3.1MNH10*/
+#define S3_86C988_NAME          "S3VIRGE/VX"                    /*@V3.1MNH10*/
+#define S3_86C767_NAME          "S3TRIO64UV+"                   /*@V3.1MNH10*/
+#define S3_86C765_FAMILY_NAME   "S3TRIO64V+COMPATIBLE"          /*@V3.1MNH10*/
+
+#define S3_86C924_NAME          "S386C924"                      /*@IBMJ-S3GEN*/
+#define S3_86C866_NAME          "S386C866"                      /*@V3.1MNH10*/
+//#define S3_V866_NAME            S3_86C866_NAME                /*@V3.1MNH10*/
+
+#define S3_86C928PCI_NAME       "S386C928PCI"                   /*@IBMJ-S3GEN*/
+
+#define CHIPS_FIRST_CHIP        1                /* bogus chip    @V2.1YEE09*/
+#define MAX_CHIPS_CHIP          1                               /*@V2.1YEE09*/
+
+#define WEITEK_P9000_CHIP       1                               /*@V2.1MNH01*/
+#define WEITEK_W5186_CHIP       2                               /*@V2.1MNH01*/
+#define WEITEK_W5286_CHIP       3                               /*@V2.1MNH01*/
+#define WEITEK_P9100_CHIP       4                               /*@V2.2TSU00*/
+#define MAX_WEITEK_CHIP         WEITEK_P9100_CHIP               /*@V2.2TSU00*/
+
+#define WEITEK_P9000_NAME       "P9000"                         /*@V2.1MNH20*/
+#define WEITEK_W5186_NAME       "W5186"                         /*@V2.1MNH20*/
+#define WEITEK_W5286_NAME       "W5286"                         /*@V2.1MNH20*/
+
+#define NULL_CHIP               1                               /*@V3.0JWK11*/
+#define MAX_NULL_CHIP           NULL_CHIP                       /*@V3.0JWK11*/
+                                                                /*@V3.0JWK11*/
+#define NULL_NAME               "NULL"                          /*@V3.0JWK11*/
+
+/*
+** OEM manufacturer defines.
+*/
+
+#define UNKNOWN_MANUFACTURER    0                               /*@V2.1MNH13*/
+#define DIAMOND_MANUFACTURER    1                               /*@V2.1YEE01*/
+#define ORCHID_MANUFACTURER     2                               /*@V2.1MNH01*/
+#define NUMBER9_MANUFACTURER    3                               /*@V2.1YEE04*/
+#define ARTIST_MANUFACTURER     4                               /*@V2.1YEE07*/
+#define LACUNA_MANUFACTURER     5                               /*@V2.1YEE07*/
+#define STB_MANUFACTURER        6                               /*@V2.2SEN02*/
+#define S3_MANUFACTURER         7                               /*@V2.1YEE10*/
+#define CIRRUS_MANUFACTURER     8
+#define MIROCRYSTAL_MANUFACTURER   9                            /*@V2.1YEE11*/
+#define VIDEOLOGIC_MANUFACTURER    10                           /*@V2.1YEE11*/
+#define THINKPAD_MANUFACTURER  11                               /*@V3.0YEE02*/
+#define TOSHIBA_MANUFACTURER   12                               /*@V3.0JWK04*/
+#define NEC_MANUFACTURER       13                               /*@V3.0JWK25*/
+#define IBM_VISION_MANUFACTURER    14                           /*@V3.1MNH01*/
+#define MANUFACTURER_MAX        IBM_VISION_MANUFACTURER         /*@V3.0MUT02*/
+#define DEFAULT_MANUFACTURER    UNKNOWN_MANUFACTURER            /*@V2.2SEN02*/
+
+/*
+** OEM manufacturer MODEL defines.
+*/
+
+#define UNKNOWN_MODEL           0                               /*@V3.0JWK04*/
+#define TOSHIBA_6600_MODEL      1                               /*@V3.0JWK04*/
+#define TOSHIBA_2100_MODEL      2                               /*@V3.0JWK04*/
+#define TOSHIBA_2100CS_MODEL    3                               /*@V3.0JWK04*/
+#define TOSHIBA_2100CT_MODEL    4                               /*@V3.0JWK04*/
+#define TOSHIBA_4700CS_MODEL    5                               /*@V3.0JWK04*/
+#define TOSHIBA_4700CT_MODEL    6                               /*@V3.0JWK04*/
+#define TOSHIBA_4800CT_MODEL    7                               /*@V3.0JWK04*/
+#define TOSHIBA_4850CT_MODEL    8                               /*@V3.0JWK04*/
+
+#define NEC_VERSA_MODEL         1                               /*@V3.0JWK25*/
+
+
+/* NOINC */
+typedef struct _ADAPTERS {      /* adp */
+  CHAR  *Name;
+  CHAR  *Manufacturer;
+  INT    ID;
+}ADAPTERS;
+
+typedef CHAR *CHIPNAMES;
+typedef CHIPNAMES *PCHIPNAMES;
+
+/*
+ * define CHIPS_INCL to include the following definitions.
+ */
+#ifdef CHIPS_INCL
+/*
+** This table contains adapter ID's as not to depend on the changes to
+** the ID's and their order. The ChipsetName table should be kept in sync
+** with the Adapters table.
+*/
+ADAPTERS Adapters [SVGA_LASTADAPTER + 0x01] =          /* @V2.2SENJA */
+{
+  {"UNKNOWN","Unknown",                         UNKNOWN_ADAPTER},
+  {"VIDEO7","Headland Technology, Inc.",        VIDEO7_ADAPTER},
+  {"TRIDENT","Trident Microsystems, Inc.",      TRIDENT_ADAPTER},
+  {"TSENG","Tseng Labs, Inc.",                  TSENG_ADAPTER},
+  {"WESTERNDIGITAL","Western Digital Corporation",WESTERNDIG_ADAPTER},
+  {"ATI","ATI Technologies Inc.",               ATI_ADAPTER},
+  {"IBM","IBM Corporation",                     IBM_ADAPTER},
+  {"CIRRUS","Cirrus Logic, Inc.",               CIRRUS_ADAPTER},
+  {"S3","S3 Incorporated",                      S3_ADAPTER},
+  {"CHIPS","Chips and Techologies",             CHIPS_ADAPTER},
+  {"WEITEK","WEITEK Corporation",               WEITEK_ADAPTER},
+  {"NUMBER9","Number Nine Corporation",         NUMBER9_ADAPTER},
+  {"GENERICPCI","Unknown",                      GENERIC_PCISVGA_ADAPTER},
+  {"OAK","Oak Technology, Inc",                 OAK_ADAPTER},         /* @V3.0YEE03 */
+  {"MATROX","Matrox",                           MATROX_ADAPTER},      /* @V3.0YEE03 */
+  {"BROOKTREE","Brooktree Corporation",         BROOKTREE_ADAPTER},   /* @V3.0YEE03 */
+  {"NVIDIA","nVIDIA",                           NVIDIA_ADAPTER},      /* @V3.0YEE03 */
+  {"ALLIANCE","Alliance Semiconductor Corporation", ALLIANCE_ADAPTER},/* @V3.0YEE03 */
+  {"AVANCE","Avance Logic",                     AVANCE_ADAPTER},      /* @V3.0YEE03 */
+  {"MEDIAVISION","Media Vision",                MEDIAVISION_ADAPTER}, /* @V3.0YEE03 */
+  {"ARKLOGIC","Ark Logic, Inc.",                ARKLOGIC_ADAPTER},    /* @V3.0YEE03 */
+  {"RADIUS","Radius",                           RADIUS_ADAPTER},      /* @V3.0YEE03 */
+  {"3DLABS","3D Labs Inc.",                     THREE_D_LABS_ADAPTER},/* @V3.0YEE03 */
+  {"NCR","NCR Corporation",                     NCR_ADAPTER},         /* @V3.0YEE03 */
+  {"IIT","IIT",                                 IIT_ADAPTER},         /* @V3.0YEE03 */
+  {"APPIAN","Appian Technology",                APPIAN_ADAPTER},      /* @V3.0YEE03 */
+  {"SIERRA","Sierra Semiconductor Inc.",        SIERRA_ADAPTER},      /* @V3.0YEE03 */
+  {"CORNERSTONE","Cornerstone Technology",      CORNERSTONE_ADAPTER}, /* @V3.0YEE03 */
+  {"DIGITAL","Digital Equipment Corporation",   DIGITAL_ADAPTER},     /* @V3.0YEE03 */
+  {"COMPAQ","Compaq Computer Corporation",      COMPAQ_ADAPTER},      /* @V3.0YEE03 */
+  {"INFOTRONIC","INFOTRONIC",                   INFOTRONIC_ADAPTER},  /* @V3.0YEE03 */
+  {"OPTI","OPTi, Inc.",                         OPTI_ADAPTER},        /* @V3.0YEE03 */
+  {"NULL","null",                               NULL_ADAPTER},        /* @V3.0JWK11 */
+};
+CHIPNAMES ppszUnknownChipNames [1] =
+  {
+    "UNKNOWN",
+  };
+CHIPNAMES ppszVideo7ChipNames [MAX_VIDEO7_CHIP] =               /*@V2.1MNH20*/
+  { /* Video 7==Headland Technology */                          /*@V2.1MNH01*/
+    VIDEO7_HT205_NAME,                                          /*@V2.1MNH20*/
+    VIDEO7_HT208_NAME,                                          /*@V2.1MNH20*/
+    VIDEO7_HT209_NAME,                                          /*@V2.1MNH20*/
+  };
+CHIPNAMES ppszTridentChipNames [MAX_TRIDENT_CHIP] =             /*@V2.1MNH20*/
+  { /* Trident */                                               /*@V2.1MNH01*/
+    TRIDENT_8800_NAME,                                          /*@V2.1MNH20*/
+    TRIDENT_8900_NAME,                                          /*@V2.1MNH20*/
+  };
+CHIPNAMES ppszTsengChipNames [MAX_TSENG_CHIP] =                 /*@V2.1MNH20*/
+  { /* Tseng */
+    TSENG_ET3000_NAME,                                          /*@V2.1MNH01*/
+    TSENG_ET4000_NAME,
+    TSENG_ET4000W32_NAME,
+    TSENG_ET4000W32I_NAME,
+    TSENG_ET4000W32IB_NAME,
+    TSENG_ET4000W32IC_NAME,                                     /*@V2.1JWK01*/
+    TSENG_ET4000W32PA_NAME,                                     /*@V2.1JWK01*/
+    TSENG_ET4000W32PB_NAME,                                     /*@V2.1JWK01*/
+    TSENG_ET4000W32PC_NAME,                                     /*@V2.2JWK03*/
+    TSENG_ET4000W32ID_NAME,                                     /*@V2.2JWK03*/
+    TSENG_ET4000W32PD_NAME,                                     /*@V2.2JWK03*/
+    TSENG_ET4000W32PX_NAME,                                     /*@V3.0JWK23*/
+  };
+CHIPNAMES ppszWDChipNames [MAX_WESTERNDIG_CHIP] =               /*@V2.1MNH20*/
+  { /* Western Digital */                                       /*@V2.1MNH01*/
+    WESTERNDIG_PVGA1A_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9000_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9011_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9030_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9026_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9027_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9031_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9024_NAME,                                     /*@V2.1MNH20*/
+    WESTERNDIG_WD9033_NAME,                                     /*@V2.1MNH20*/
+  };
+CHIPNAMES ppszATIChipNames [MAX_ATI_CHIP] =                     /*@V2.1MNH20*/
+  { /* ATI */                                                   /*@V2.1MNH01*/
+    ATI_18800_NAME,                                             /*@V2.1MNH20*/
+    ATI_28800_NAME,                                             /*@V2.1MNH20*/
+    ATI_38800_NAME,                                             /*@V2.1MNH20*/
+    ATI_68800_NAME,                                             /*@V2.1MNH20*/
+    ATI_88800_NAME,                                             /*@V2.1MNH20*/
+    ATI_88800CT_NAME,                                           /*@V3.0JWK21*/
+  };
+CHIPNAMES ppszIBMChipNames [MAX_IBM_CHIP] =                     /*@V2.1MNH20*/
+  { /* IBM */                                                   /*@V2.1MNH01*/
+    IBM_SVGA_NAME,                                              /*@V2.1MNH20*/
+  };
+CHIPNAMES ppszCirrusChipNames [MAX_CIRRUS_CHIP] =               /*@V2.1MNH20*/
+  { /* Cirrus Logic */                                          /*@V2.1MNH01*/
+    CIRRUS_5420_NAME,                                           /*@V2.1YEE31*/
+    CIRRUS_5422_NAME,
+    CIRRUS_5424_NAME,
+    CIRRUS_5426_NAME,
+    CIRRUS_5428_NAME,                                           /*@V2.1MNH01*/
+    CIRRUS_5429_NAME,                                           /*@V2.1YEE31*/
+    CIRRUS_543X_NAME,                                           /*@V2.1YEE31*/
+    CIRRUS_5434_NAME,
+    CIRRUS_6235_NAME,                                           /*@V3.0ITO01*/
+  };
+CHIPNAMES ppszS3ChipNames [MAX_S3_CHIP] =                       /*@V2.1MNH20*/
+  { /* S3 */                                                    /*@V2.1MNH01*/
+    S3_86C805_NAME,                                             /*@V2.1MNH20*/
+    S3_86C928_NAME,                                             /*@V2.1MNH20*/
+    S3_86C911_NAME,                                             /*@V2.1MNH20*/
+    S3_86C864_NAME,                                             /*@V2.1MNH20*/
+    S3_86C964_NAME,                                             /*@V2.1MNH20*/
+
+    S3_86C868_NAME,                                             /*@V3.1MNH10*/
+    S3_86C968_NAME,                                             /*@V3.1MNH10*/
+    S3_86C732_NAME,                                             /*@V3.1MNH10*/
+    S3_86C764_NAME,                                             /*@V3.1MNH10*/
+    S3_86C765_NAME,                                             /*@V3.1MNH10*/
+    S3_86CM65_NAME,                                             /*@V3.1MNH10*/
+    S3_86C325_NAME,                                             /*@V3.1MNH10*/
+    S3_86C988_NAME,                                             /*@V3.1MNH10*/
+    S3_86C767_NAME,                                             /*@V3.1MNH10*/
+    S3_86C765_FAMILY_NAME,                                      /*@V3.1MNH10*/
+
+    S3_86C924_NAME,                                             /*@IBMJ-S3GEN*/
+    S3_86C928PCI_NAME,                                          /*@IBMJ-S3GEN*/
+  };
+CHIPNAMES ppszWeitekChipNames [MAX_WEITEK_CHIP] =               /*@V2.1MNH20*/
+  { /* Weitek */                                                /*@V2.1MNH01*/
+    WEITEK_P9000_NAME,                                          /*@V2.1MNH20*/
+    WEITEK_W5186_NAME,                                          /*@V2.1MNH20*/
+    WEITEK_W5286_NAME,                                          /*@V2.1MNH20*/
+  };
+PCHIPNAMES ChipsetName [SVGA_LASTADAPTER + 0x01] =              /*@V2.1MNH20*/
+{
+  ppszUnknownChipNames,                                         /*@V2.1MNH20*/
+  ppszVideo7ChipNames,                                          /*@V2.1MNH20*/
+  ppszTridentChipNames,                                         /*@V2.1MNH20*/
+  ppszTsengChipNames,                                           /*@V2.1MNH20*/
+  ppszWDChipNames,                                              /*@V2.1MNH20*/
+  ppszATIChipNames,                                             /*@V2.1MNH20*/
+  ppszIBMChipNames,                                             /*@V2.1MNH20*/
+  ppszCirrusChipNames,                                          /*@V2.1MNH20*/
+  ppszS3ChipNames,                                              /*@V2.1MNH20*/
+  ppszUnknownChipNames,                                         /*@V2.1MNH20*/
+  ppszWeitekChipNames,                                          /*@V2.1MNH20*/
+};
+#endif
+/*
+** DIF subsystem defines
+*/
+typedef struct _MONMODEINFO { /* mmi */
+        USHORT            usXResolution;
+        USHORT            usYResolution;
+        BYTE              bVertRefresh;
+        BYTE              bHorizRefresh;
+        BYTE              bVPolarityPos;
+        BYTE              bHPolarityPos;
+} MONMODEINFO;
+#define MAX_PATH_NAME  256
+#define MAX_MONITOR_LEN   128   /* length of name string */
+#define MAX_MONITOR_MODES 10    /* up to 10 modes per monitor */
+typedef struct _MonInfo { /* mi */
+        CHAR             szMonitor[MAX_MONITOR_LEN];
+        MONMODEINFO      ModeInfo[MAX_MONITOR_MODES];
+} MONITORINFO, FAR *PMONITORINFO;
+
+#define DIF_SERVICE_DLL_NAME   "VIDEOCFG"
+#define VCFG_RESOURCE_DLL_NAME "VCFGMRI"
+
+#define SVGA_DATAFNAME         "svgadata.pmi"
+#define VIDEO_CFGFNAME         "video.cfg"
+#define MONITOR_FNAME          "monitor.dif"
+#define PRIVATE_MONITOR_FNAME  "private.dif"                    /*@V3.0DAI01*/
+
+/*
+**  DevEscape functions and structure for driver extra capabilities that need
+**  to be configured by VIDEOCFG.DLL
+*/
+
+#define  DEVESC_QUERYDRIVERCAPS      40010L                     /*@V3.0DAI01*/
+#define  DEVESC_QUERYDRIVERCAPSLIST  40011L                     /*@V3.0DAI01*/
+#define  DEVESC_SETDRIVERCAPSVALUE   40012L                     /*@V3.0DAI01*/
+                                                                /*@V3.0DAI01*/
+#define CAPSTYPE_BOOLEAN                 1L                     /*@V3.0DAI01*/
+#define CAPSTYPE_AGGREGATE_INT           2L                     /*@V3.0DAI01*/
+#define CAPSTYPE_AGGREGATE_STRING        3L                     /*@V3.0DAI01*/
+                                                                /*@V3.0DAI01*/
+typedef struct _DRIVERCAPS                                      /*@V3.0DAI01*/
+{                                                               /*@V3.0DAI01*/
+   ULONG  ulCb;                                                 /*@V3.0DAI01*/
+   CHAR   szCapsDesc[256];                                      /*@V3.0DAI01*/
+   CHAR   szHelpFileName[256];                                  /*@V3.0DAI01*/
+   ULONG  ulHelpId;                                             /*@V3.0DAI01*/
+   ULONG  ulCapsType;                                           /*@V3.0DAI01*/
+   ULONG  ulValueMemberSize;                                    /*@V3.0DAI01*/
+   ULONG  ulNumValueMember;                                     /*@V3.0DAI01*/
+   PVOID  pValueList;                                           /*@V3.0DAI01*/
+   PVOID  pCurrentValue;                                        /*@V3.0DAI01*/
+   PVOID  pDefaultValue;                                        /*@V3.0DAI01*/
+   BOOL   bDefaultValueSupported;                               /*@V3.0DAI01*/
+   BOOL   bStaticCaps;                                          /*@V3.0DAI01*/
+} DRIVERCAPS, *PDRIVERCAPS;                                     /*@V3.0DAI01*/
+
+/*
+** Functions exported by VIDEOCFG.DLL.
+*/
+
+/* Begin @V2.2DAI01                                                    */
+/* These functions are exported only to PM aware apps. Include PMWIN.H */
+#ifdef MRESULT
+BOOL EXPENTRY QueryScreenPageData(PHMODULE phmodResourceMRI,
+                                  PUSHORT  pusDlgId,
+                                  PSZ      pszName,
+                                  PUSHORT  pusHelpId,
+                                  PSZ      pszDlgProcName,
+                                  BOOL     bPaletteManagedDisplay);
+BOOL EXPENTRY QueryDisplayTypePageData(PHMODULE phmodResourceMRI,
+                                       PUSHORT  pusDlgId,
+                                       PSZ      pszName,
+                                       PUSHORT  pusHelpId,
+                                       PSZ      pszDlgProcName);
+MRESULT EXPENTRY ScreenDlgProc(HWND hwndDlg, USHORT msg, MPARAM mp1, MPARAM mp2);
+MRESULT EXPENTRY DIF_DisplayTypeDlgProc(HWND hwndDlg, USHORT msg, MPARAM mp1, MPARAM mp2);
+MRESULT EXPENTRY DMQS_DisplayTypeDlgProc(HWND hwndDlg, USHORT msg, MPARAM mp1, MPARAM mp2);
+#endif
+/* End @V2.2DAI01 */
+
+APIRET EXPENTRY QueryNumMonitors(ULONG *pulNumMonitors);
+APIRET EXPENTRY GetAllMonitors(MONITORINFO *pMonitors);
+APIRET EXPENTRY AddMonitorData(PSZ pszMonitorFileName, MONITORINFO *pNewMonitor);    /* @V3.0DAI01 */
+APIRET EXPENTRY GetCurrentCfg(ADAPTERINFO *pAdapter,MONITORINFO *pMonitor);
+APIRET EXPENTRY SetCurrentCfg(ADAPTERINFO *pAdapter,MONITORINFO *pMonitor);
+BOOL   EXPENTRY GetCurrentDesktopMode(PVIDEO_ADAPTER pVideoAdapter);                 /* @V3.0DAI01 */
+/*
+** 16 entry point into the VIDEOCFG.DLL
+*/
+APIRET VIDEOAPI VCFG16Request(PVOID pIn,ULONG function,PVOID pOut1,PVOID pOut2);
+typedef APIRET (VIDEOAPI  FNCFG16REQUEST)(PVOID, ULONG, PVOID, PVOID);
+typedef FNCFG16REQUEST *PFNCFG16REQUEST;
+/*
+** functions exported to 16 bit
+*/
+#define VCFG_GET_CURRENT_CONFIG 0       //pIn = NULL, pOut1 = pAdapter, pOut2 = pMonitor
+
+/* INC */
+
+
+/*
+** APM constants          @V3.0YEE06
+*/
+#define APM_RESUME              1
+#define APM_SUSPEND             2
+#define APM_DISABLED            4
+
+    /* this IOCTL is used internally between videopmi and screendd @V3.0YEE06 */
+#define SCREENDD_SVGA_APM               0x10    /* Wait for APM    @V3.0YEE06 */
+
+#ifndef INCL_DOSDEVIOCTL                //@senja: bsedev.h can't be used by vvid
+#ifndef BSEDEV_INCLUDED                 //don't define if bsedev already included
+#define SCREENDD_SVGA_ID                0x08    /* Get SVGA info IOCTL */
+#define SCREENDD_SVGA_OEM               0x09    /* Get OEM info IOCTL */
+/* #define SCREENDD_SVGA_APM            0x10       Wait for APM    @V3.0YEE06 */
+#define SCREENDD_CATEGORY               0x80
+#define SCREENDD_NAME                   "SCREEN$"
+                                           /* SCREENDD_SVGA_ID */
+typedef struct _OEMSVGAINFO { /* */
+        USHORT AdapterType;
+        USHORT ChipType;
+        ULONG  Memory;
+} OEMSVGAINFO;
+                                           /* SCREENDD_SVGA_OEM */
+typedef struct _OEMINFO {    /* */
+        ULONG  OEMLength;
+        USHORT Manufacturer;
+        ULONG  ManufacturerData;
+        USHORT ManufacturerModel;                               /*@V3.0JWK04*/
+} OEMINFO;
+#endif
+#endif
Index: trunk/src/ddraw/new/SVGAPMI.H
===================================================================
--- trunk/src/ddraw/new/SVGAPMI.H	(revision 3345)
+++ trunk/src/ddraw/new/SVGAPMI.H	(revision 3345)
@@ -0,0 +1,895 @@
+/*****************************************************************************
+ *
+ * SOURCE FILE NAME = SVGAPMI.H
+ *
+ * DESCRIPTIVE NAME =
+ *
+ * Copyright : COPYRIGHT IBM CORPORATION, 1991, 1992
+ *             Copyright Microsoft Corporation, 1990
+ *             LICENSED MATERIAL - PROGRAM PROPERTY OF IBM
+ *             REFER TO COPYRIGHT INSTRUCTION FORM#G120-2083
+ *             RESTRICTED MATERIALS OF IBM
+ *             IBM CONFIDENTIAL
+ *
+ * VERSION = V2.0
+ *
+ * DATE
+ *
+ * DESCRIPTION  Contains VIDEOPMI specific defintions
+ *
+ * FUNCTIONS
+ *
+ * NOTES
+ *
+ * STRUCTURES
+ *
+ * EXTERNAL REFERENCES
+ *
+ * EXTERNAL FUNCTIONS
+ *
+ * CHANGE ACTIVITY =
+ *   DATE      FLAG        APAR   CHANGE DESCRIPTION
+ *   --------  ----------  -----  --------------------------------------
+ *   mm/dd/yy  @Vr.mpppxx  xxxxx  xxxxxxx
+ *   02/14/96  @V3.2TSU00 148283  Merlin PBE, support linear aperture
+ *   04/18/96  @V3.2TSU01 150783  Add flags for _int10handler
+ *   07/15/96  @V3.2TSU02 160023  Use the old VIDEO_ADAPTER & VIDEOMDOEINFO
+ *
+ *****************************************************************************/
+
+
+/*
+ * This flag is used to set the linear aperture mode.
+ * the pIn passed in PMIREQUEST_SETMODE will be the pointer to
+ * (mode number | SET_LINEAR_BUFFER_MODE).
+ */
+#define SET_LINEAR_BUFFER_MODE  0x80000000
+
+/*
+ * definitions of bus type
+ */
+#define ISA_BUS    0
+#define VLB_BUS    1
+#define PCI_BUS    2
+#define EISA_BUS   3
+#define PCMCIA_BUS 4
+#define MCA_BUS    5
+
+/*
+* endian type
+*/
+#define LITTLE_ENDIAN  0
+#define BIG_ENDIAN     1
+
+
+/*
+** VIDEOPMI.DLL prototypes.
+*/
+/* NOINC */
+#define HVIDEO   PVOID
+typedef HVIDEO  *PHVIDEO;
+
+#ifndef APIENTRY
+#define APIENTRY /* nothing */
+#endif
+
+#ifndef APIRET
+#define APIRET ULONG
+#endif
+
+typedef ULONG       MODEID;
+typedef MODEID FAR *PMODEID;
+
+/*
+** PMIREQUEST_SOFTWAREINT structures @V3.2SEN01
+*/
+typedef struct {
+  ULONG ulFlags;           //VDM initialization type
+#define VDM_POSTLOAD    0x1  //adapter just loaded, used internally for initialization
+#define VDM_INITIALIZE  0x2  //force initialization of a permanently open VDM, even if previously initialized
+#define VDM_TERMINATE_POSTINITIALIZE   0x6  //start VDM with initialization, but close it afterwards (includes VDM_INITIALIZE)
+#define VDM_QUERY_CAPABILITY     0x10  // query the current int 10 capability
+#define VDM_FULL_VDM_CREATED     0x20  // a full VDM is created
+#define VDM_MINI_VDM_CREATED     0x40  // a mini VDM is created
+#define VDM_MINI_VDM_SUPPORTED   0x80  // mini VDM support is available
+  PCHAR szName;            //VDM initialization program
+  PCHAR szArgs;            //VDM initialization arguments
+}INITVDM;
+
+/*
+ * Don't change these structures without
+ * changing the kernel dos\dosinc\vdmint10.h !
+ */
+typedef struct {
+  BYTE bBufferType;        // input vs output buffer
+#define BUFFER_NONE     0
+#define INPUT_BUFFER    1
+#define OUTPUT_BUFFER   2
+  BYTE bReserved;
+  BYTE bSelCRF;           // CRF flag for the selector: ulong index into the CRF
+  BYTE bOffCRF;           // CRF flag for the offset: ulong index into the CRF
+  PVOID pAddress;         // linear address of the buffer
+  ULONG ulSize;
+}BUFFER, *PBUFFER;
+
+// CRF taken from kmode.h
+typedef struct vcrf_s {
+
+        ULONG reg_eax;
+        ULONG reg_ebx;
+        ULONG reg_ecx;
+        ULONG reg_edx;
+        ULONG reg_ebp;
+        ULONG reg_esi;
+        ULONG reg_edi;
+        ULONG reg_ds;
+        ULONG reg_es;
+        ULONG reg_fs;
+        ULONG reg_gs;
+        ULONG reg_cs;
+        ULONG reg_eip;
+        ULONG reg_eflag;
+        ULONG reg_ss;
+        ULONG reg_esp;
+}VCRF;
+
+
+typedef struct {
+  ULONG ulBIOSIntNo;      /* 0x10 for INT10 calls */
+  VCRF aCRF;
+  BUFFER pB[2];
+}INTCRF;
+#define VPRPMI "VPRPMI$"
+#define VPRSYSREQ_INT10HANDLER      1
+#define VPRSYSREQ_INT10WAITFORPDB   2
+#define VPRSYSREQ_MARKINT10VDM      3
+#define VPRSYSREQ_MAX               VPRSYSREQ_MARKINT10VDM
+/* @V3.2SEN01 end */
+/*
+** Structures passed as input and output parameters.
+*/
+
+typedef struct _VIDEOMODEINFO { /* vmi */
+        MODEID  miModeId;               /* used to make setmode request     */
+
+#define MODE_FLAG_NOT_MONO      0x0001  /* Mono-compatible                  */
+#define MODE_FLAG_GRAPHICS      0x0002  /* Text mode, Graphics              */
+#define MODE_FLAG_NO_CLR_BRST   0x0004  /* Disable Color burst              */
+#define MODE_FLAG_NATIVE        0x0008  /* Native (advanced function) mode  */
+#define IGNORE_CLR_BRST         0x0010  /* Disable color burst doesn't make */
+                                        /* sense for this mode              */
+#define NOT_PLASMA              0x0020  /* @V2.2TSU00 won't work on plasma  */
+                                        /* display                          */
+#define MODE_FLAG_VGA_ENTRY     0x0040  /* VGA mode, need clean up          */
+
+#define MODE_FLAG_LINEAR_BUFFER 0x0100  /* flat frame buffer is supported   */
+
+#define MODE_FLAG_DIRECT_RGB    0x1000  /* direct color RGB                 */
+#define MODE_FLAG_DIRECT_BGR    0x2000  /* direct color BGR                 */
+#define MODE_FLAG_YUV           0x4000  /* YUV color format                 */
+
+        USHORT  usType;                 /* mode type bits                   */
+        USHORT  usInt10ModeSet;         /* int 10 mode                      */
+        USHORT  usXResolution;          /* horizontal pels                  */
+        USHORT  usYResolution;          /* vertical scan lines              */
+        ULONG   ulBufferAddress;        /* physical address of VRAM         */
+        ULONG   ulApertureSize;         /* VRAM aperture                    */
+        BYTE    bBitsPerPixel;          /* no of colors                     */
+        BYTE    bBitPlanes;             /* number of planes                 */
+        BYTE    bXCharSize;             /* font width                       */
+        BYTE    bYCharSize;             /* font height                      */
+        USHORT  usBytesPerScanLine;     /* logical line length in bytes     */
+        USHORT  usTextRows;             /* text rows                        */
+        ULONG   ulPageLength;           /* no of bytes to save a plane      */
+        ULONG   ulSaveSize;             /* total bytes of VRAM to save      */
+        /*
+         * Monitor Info
+         */
+        BYTE    bVrtRefresh;
+        BYTE    bHrtRefresh;
+        BYTE    bVrtPolPos;
+        BYTE    bHrtPolPos;
+        /*
+         * Direct Color Fields. The same definitions as VESA 1.2 and up.
+         */
+        CHAR    bRedMaskSize;               // @V3.2TSU02
+        CHAR    bRedFieldPosition;          // @V3.2TSU02
+        CHAR    bGreenMaskSize;             // @V3.2TSU02
+        CHAR    bGreenFieldPosition;        // @V3.2TSU02
+        CHAR    bBlueMaskSize;              // @V3.2TSU02
+        CHAR    bBlueFieldPosition;         // @V3.2TSU02
+        CHAR    bRsvdMaskSize;              // @V3.2TSU02
+        CHAR    bRsvdFieldPosition;         // @V3.2TSU02
+
+        /*
+         * The number of colors can be derived from MaskSize fields.
+         */
+        ULONG   ulColors;             // @V3.2TSU02
+
+        ULONG   ulReserved[3];        // @V3.2TSU02
+
+//        USHORT  usScrnTop;           @V3.2TSU02
+//        USHORT  usScrnBottom;        @V3.2TSU02
+//        USHORT  usScrnLeft;          @V3.2TSU02
+//        USHORT  usScrnRight;         @V3.2TSU02
+
+//        CHAR    szColorFormat[8];    @V3.2TSU02
+//        CHAR    szColorWeight[8];    @V3.2TSU02
+#ifndef VIDEOPMI_30_LEVEL
+        /*
+        ** The assumption is that all of the base video components
+        ** are built together and shipped in unison.
+        ** In order to build a back-level 3.0 base video component
+        ** (VIDEOPMI, BVHSVGA, VIDEOCFG, IBMGPMI), define macro
+        ** VIDEOPMI_30_LEVEL.
+        */
+//        ULONG   ulColors;               /* @V3.2SEN01 @V3.2TSU02 */
+#endif
+
+} VIDEOMODEINFO;
+typedef VIDEOMODEINFO FAR *PVIDEOMODEINFO;
+
+typedef struct _SVGARGB { /* rgb */
+        BYTE    bR;
+        BYTE    bG;
+        BYTE    bB;
+        BYTE    bUnused;
+} SVGARGB;
+typedef SVGARGB FAR *PSVGARGB;
+
+#define EIGHT_BIT_DAC   0x00010000      /* over load ulRGBCount to tell     */
+                                        /* videopmi the dac values are for  */
+                                        /* 8 bit DAC.                       */
+
+typedef struct _CLUTDATA { /* clt */
+        ULONG   ulRGBCount;             /* No of aRGB entries that follow   */
+        ULONG   ulRGBStart;             /* Start index for RGB triplets     */
+        SVGARGB aRGB[1];                /* One defined, ulRGBCount entries  */
+} CLUTDATA;
+typedef CLUTDATA FAR *PCLUTDATA;
+
+typedef struct _PALETTEDATA { /* pal */
+        ULONG   ulPalCount;             /* No of bPal.. entries that follow */
+        ULONG   ulPalStart;             /* Start index for data             */
+        BYTE    bPaletteData[1];        /* One defined, ulPalCount entries  */
+} PALETTEDATA;
+typedef PALETTEDATA FAR *PPALETTEDATA;
+
+typedef struct _FONTDATA { /* font */
+        ULONG   ulCharCount;            /* No of chars in font              */
+        ULONG   ulFontHeight;           /* No of scanlines per character    */
+        ULONG   ulFontWidth;            /* No of columns per character      */
+        BYTE    bFontData[1];           /* ulCharCount*ulFontHeight entries */
+} FONTDATA;
+typedef FONTDATA FAR *PFONTDATA;
+
+typedef BYTE FAR *PVRAMDATA;
+
+typedef struct _CLEANDATA { /* clean */
+    USHORT  Command;
+    USHORT  IndexPort;
+    USHORT  DataPort;
+    USHORT  Index;
+    USHORT  ANDMask;
+    USHORT  ORMask;
+} CLEANDATA;
+
+typedef struct _BANKDATA { /* bank */
+        MODEID  miBank;                 /*                                  */
+        ULONG   ulBank;                 /*                                  */
+} BANKDATA;
+typedef BANKDATA FAR *PBANKDATA;
+
+#define MAX_OEM_STRING  128
+#define MAX_DAC_STRING  128
+#define MAX_VERSION     128
+
+typedef struct _ADAPTERINFO {   /* adi */
+        ULONG       ulAdapterID;
+        CHAR        szOEMString[MAX_OEM_STRING];    /* adapter info from Hardware section */
+        CHAR        szDACString[MAX_DAC_STRING];    /* DAC info from Hardware section */
+        CHAR        szRevision[MAX_VERSION];        /* whatever the revision  means   */
+        ULONG       ulTotalMemory;
+        ULONG       ulMMIOBaseAddress;
+        ULONG       ulPIOBaseAddress;
+        BYTE        bBusType;
+        BYTE        bEndian;
+        USHORT      usDeviceBusID;       /* has to be 2 bytes */
+        USHORT      usVendorBusID;       /* has to be 2 bytes */
+        USHORT      SlotID;              /* has to be 2 bytes */
+} ADAPTERINFO, FAR *PADAPTERINFO;
+
+/*
+ * Adapter Instance definition. The structure will be passed in every
+ * PMIREQUEST call.
+ */
+typedef struct _VIDEO_ADAPTER { /* va */
+     HVIDEO          hvideo;
+
+     /*
+     ** The assumption is that all of the base video components
+     ** are built together and shipped in unison (any driver including
+     ** svgadefs.h and using the VIDEOPMI interface as well).
+     **
+     ** @V3.0TSU00
+     ** All the callers to videopmi have to fill cbAdapterInfo and
+     ** and cbVideoModeInfo with sizeof (ADAPTERINFO) and
+     ** sizeof (VIDEOMODEINFO), respectively. It is for version control.
+     ** All the DLLs called by videopmi have to access the ModeInfo field
+     ** in VIDEO_ADAPTER by the offset of ModeInfo.
+     ** For example, instead of pAdapter->ModeInfo.bBitsPerPixel,
+     ** it should be
+     **    ((PVIDEOMODEINFO)&((PBYTE)&(pAdapter->Adapter) + pAdapter->AdapterInfo_cb))->
+     **                                              bBitsPerPixel.
+     */
+
+//
+//    Goes back to the old structure of OS/2 Warp 3.0.
+//
+//     USHORT      AdapterInfo_cb;       @V3.2TSU02
+//     USHORT      VideoModeInfo_cb;     @V3.2TSU02
+
+     ADAPTERINFO     Adapter;
+     VIDEOMODEINFO   ModeInfo;
+} VIDEO_ADAPTER, FAR *PVIDEO_ADAPTER;
+
+/*
+ * prototype for import functions in PMI file
+ */
+typedef ULONG   *PREGS;     //pointer to registers. Passed to imported PMI functions.
+typedef APIRET (EXPENTRY FNIMPORTPMI)(PVIDEO_ADAPTER, PREGS);
+typedef FNIMPORTPMI *PFNIMPORTPMI;
+
+#ifdef INCL_16
+   #define VIDEOAPI FAR     //this controls the calling convention.
+#else                           // 32-bit code
+   #define VIDEOAPI EXPENTRY       //C calling convention
+#endif
+
+/*
+** prototype for META PMI imports   @V3.2SEN01
+*/
+typedef APIRET (VIDEOAPI FNPMIREQ)(PVIDEO_ADAPTER, PVOID, PVOID);
+typedef FNPMIREQ *PFNPMIREQ;
+
+typedef struct _PMIREQUEST {
+        PFNPMIREQ       pfnPMIRequest;
+        ULONG           ulRing2Call;
+} PMIREQUEST;
+typedef PMIREQUEST *PPMIREQUEST;
+
+#define METAPMI_LOADADAPTER "LoadAdapter"
+
+typedef APIRET (EXPENTRY FNIMPORTLOADPMI)(CHAR *,PPMIREQUEST);
+typedef FNIMPORTLOADPMI *PFNIMPORTLOADPMI;
+
+/*
+** prototype for VIDEOPMI request functions
+*/
+typedef APIRET (VIDEOAPI FNVIDEOPMIREQUEST)(PVIDEO_ADAPTER, ULONG, PVOID, PVOID);
+
+typedef FNVIDEOPMIREQUEST     *PFNVIDEOPMIREQUEST;
+                                         /* used to exchange data with vvid */
+typedef struct _VDDDATA {    /* vdd */
+        PFNVIDEOPMIREQUEST       npfnEntryPointAddress;
+        HVIDEO                   hvideo;
+} VDDDATA;
+typedef VDDDATA *PVDDATA;
+/* INC */
+/*
+** Save Restore constants
+*/
+
+#define STATEFLAG_REGISTERS     0x0001  /*                                  */
+#define STATEFLAG_CLUT          0x0002  /*                                  */
+#define STATEFLAG_VRAM          0x0004  /*                                  */
+#define STATEFLAG_FONT          0x0008  /*                                  */
+
+/* NOINC */
+typedef struct _VIDEOSTATE { /* vst */
+        ULONG     fStateFlags;          /*                                  */
+        MODEID    miState;              /*                                  */
+        PVOID     pModeData;            /*                                  */
+        ULONG     ulVRAMSaveSize;       /* No of bytes/page to save         */
+        PVRAMDATA pVRAM;                /*                                  */
+        PCLUTDATA pCLUT;                /*                                  */
+        PFONTDATA pFont;                /*                                  */
+} VIDEOSTATE;
+typedef VIDEOSTATE FAR *PVIDEOSTATE;
+/* INC */
+
+/*
+** Function request parameters supported.
+*/
+
+#define PMIREQUEST_SETMODE                 0
+#define PMIREQUEST_LOCKREGISTERS           1
+#define PMIREQUEST_UNLOCKREGISTERS         2
+#define PMIREQUEST_CLEANUP                 3
+#define PMIREQUEST_SAVESTATE               4
+#define PMIREQUEST_RESTORESTATE            5
+#define PMIREQUEST_GETBANK                 6
+#define PMIREQUEST_SETBANK                 7
+#define PMIREQUEST_GETCLUT                 8
+#define PMIREQUEST_SETCLUT                 9
+#define PMIREQUEST_GETPALETTE             10
+#define PMIREQUEST_SETPALETTE             11
+#define PMIREQUEST_GETFONT                12
+#define PMIREQUEST_SETFONT                13
+#define PMIREQUEST_TUNEDISPLAY            14        /* @V2.2TSU00 */
+#define PMIREQUEST_QUERYMAXMODEENTRIES    15
+#define PMIREQUEST_QUERYMAXMODELISTSIZE   16
+#define PMIREQUEST_QUERYMODEINFODATA      17
+#define PMIREQUEST_QUERYMAXTRAPENTRIES    18
+#define PMIREQUEST_QUERYTRAPLISTDATA      19
+#define PMIREQUEST_QUERYMODEHRDWRLIST     20        /* @V2.2TSU00 */
+#define PMIREQUEST_LOADPMIFILE            21
+#define PMIREQUEST_IDENTIFYADAPTER        22
+#define PMIREQUEST_SOFTWAREINT            23             /* @V3.2SEN01 */
+#define PMIREQUEST_INT10         PMIREQUEST_SOFTWAREINT
+#define PMIREQUEST_UNLOADPMIFILE          24
+#define PMIREQUEST_SETMEMORYIOADDRESS     25            /* @V3.2TSU00 */
+
+#define PMIREQUEST_MAX (PMIREQUEST_SETMEMORYIOADDRESS + 1) /* last entry + 1 */
+
+/* NOINC */
+
+/*
+ * define PMIDEF_INCL to include the following definitions.
+ */
+#ifdef PMIDEF_INCL
+
+/* @V2.2TSU00
+** Possible flags in ModeAtrributes field in PMI file
+** the flags will be saved in ModeInfo.ulType
+*/
+#define  PMI_MODE_COLOUR          0x08        /* Bit 3 - 0 = mono, 1 = colour */
+#define  PMI_MODE_GRAPHICS        0x10      /* Bit 4 - 0 = text, 1 = graphics */
+#define  PMI_MODE_VGA_ENTRY       0x20/* vga entry, need clean up in set mode */
+#define  PMI_MODE_IGNORE_CLR_BRST 0x40 /* won't work on B/W mode              */
+#define  PMI_MODE_LINEAR_APERTURE 0x80 /* linear aperture mode */
+
+/*
+ * PMI commands
+ */
+#define PMICMD_NONE             0xFF            //reserved
+#define PMICMD_INB              0
+#define PMICMD_OUTB             1
+#define PMICMD_INW              2
+#define PMICMD_OUTW             3
+#define PMICMD_INDW             4
+#define PMICMD_OUTDW            5
+#define PMICMD_BINB             6
+#define PMICMD_BOUTB            7
+#define PMICMD_ABOUTW           8
+#define PMICMD_ABOUTDW          9
+#define PMICMD_RMWBN           10
+#define PMICMD_RMWBI           11
+#define PMICMD_RMWWN           12
+#define PMICMD_REGOP           13
+#define PMICMD_ASSIGN          14
+/***************** for backward compatibility ***************/
+#define PMICMD_WAIT            15
+#define PMI_WAIT_CLEAR          0       /* Wait for CLEAR condition         */
+/***************** for backward compatibility ***************/
+#define PMICMD_WAITB           16
+#define PMICMD_WAITW           17
+#define PMICMD_WAITDW          18
+#define PMICMD_READB           19               /* @V2.2TSU00          */
+#define PMICMD_READW           20               /* Don't rearrange the */
+#define PMICMD_READDW          21               /* order or put        */
+#define PMICMD_WRITEB          22               /* anything in between */
+#define PMICMD_WRITEW          23               /* for these MMIO      */
+#define PMICMD_WRITEDW         24               /* commands            */
+#define PMICMD_ROUTINE         25               /* @V2.2TSU01          */
+#define PMICMD_LABEL           26
+#define PMICMD_WHILE           27
+#define PMICMD_ENDWHILE        28
+#define PMICMD_IF              29
+#define PMICMD_GOTO            30
+#define PMICMD_STRCMP          31
+#define PMICMD_MEMCMP          32
+#define PMICMD_CALL            33
+#define PMICMD_MAX             PMICMD_CALL  /* equals last entry   */
+
+
+#define PMI_REGOP_ASSIGN          0     /* Rxxx  = <value>                  */
+#define PMI_REGOP_AND             1     /* Rxxx &= <value>                  */
+#define PMI_REGOP_OR              2     /* Rxxx |= <value>                  */
+#define PMI_REGOP_XOR             3     /* Rxxx ^= <value>                  */
+#define PMI_REGOP_PLUS            4     /* Rxxx += <value>                  */
+#define PMI_REGOP_MINUS           5     /* Rxxx -= <value>                  */
+#define PMI_REGOP_SHL             6     /* Rxxx <= <value>                  */
+#define PMI_REGOP_SHR             7     /* Rxxx >= <value>                  */
+#define PMI_REGOP_LESS            8     /* Rxx < Rxyy                       */
+#define PMI_REGOP_LESS_EQUALS     9     /* Rxx <= Ryy                       */
+#define PMI_REGOP_GREATER         10    /* Rxx > Rxyy                       */
+#define PMI_REGOP_GREATER_EQUALS  11    /* Rxx >= Ryy                       */
+#define PMI_REGOP_EQUALS          12    /* Rxx == Ryy                       */
+#define PMI_REGOP_NOT_EQUALS      13    /* Rxx != Ryy                       */
+#define PMI_REGOP_MAX  PMI_REGOP_NOT_EQUALS /* must equal last entry        */
+
+/*
+**      Type Definitions
+**
+**      Tokens are grouped, and must be kept that way.
+**      There are dummy tokens, place holders, TOK_??_BEGIN and TOK_??_END
+**      to make tests and expansion easier. Just be sure to keep token
+**      info for a given section, within these bounds.
+*/
+
+typedef enum _PMITOKEN {        /* pt */
+     TOK_SECT_BEGIN,
+/***************** for backward compatibility ***************/
+     TOK_ADAPTERTYPE,           /* Section Heading tokens */
+     TOK_CHIPSET,
+/***************** for backward compatibility ***************/
+     TOK_PMIVERSION,           /* Section Heading tokens */
+     TOK_COMMENT,
+     TOK_MODEINFO,
+     TOK_SETMODE,
+     TOK_MONITORMODEINFO,
+     TOK_TRAPREGS,
+     TOK_UNLOCK,
+     TOK_LOCK,
+     TOK_CLEANUP,
+     TOK_SETBANK,
+     TOK_GETBANK,
+     TOK_DECLARATIONS,
+     TOK_COPYVRAM,
+     TOK_TUNEDISPLAY,
+     TOK_SETMEMORYIOADDRESS,             // @V3.2TSU00
+     TOK_HARDWARE,
+     TOK_IDENTIFYADAPTER,
+     TOK_ISENGINEBUSY,
+     TOK_ENABLECONTROLLER,
+     TOK_DISABLECONTROLLER,
+     TOK_SETMONITORTIMINGS,
+     TOK_ROUTINE_DECLR,             /* @V2.2TSU01 */
+     TOK_INCLUDE,                   /* text include */
+     TOK_INCLUDECODE,               /* DLL include  */
+     TOK_SECT_END,
+
+     TOK_MI_BEGIN,
+     TOK_MODEATTRIBUTES,        /* ModeInfo Section tokens */
+     TOK_INT10MODESET,          /* @V2.2TSU00 int 10 mode */
+     TOK_BYTESPERSCANLINE,
+     TOK_TEXTROWS,              /* [ModeInfo] and [Hardware] tokens       */
+     TOK_XRESOLUTION,           /* are PMI keyvariables. Do remember      */
+     TOK_YRESOLUTION,           /* update the PMIKeyVarTable[] and        */
+     TOK_XCHARSIZE,             /* PMI Keyvariable defines in header file */
+     TOK_YCHARSIZE,
+     TOK_BITSPERPIXEL,
+     TOK_NUMBEROFPLANES,
+     TOK_PAGELENGTH,
+     TOK_SAVESIZE,
+     TOK_BUFFERADDRESS,
+     TOK_APERTURESIZE,
+     TOK_COLORFORMAT,
+     TOK_COLORWEIGHT,
+     TOK_VERTICALREFRESH,
+     TOK_HORIZONTALREFRESH,
+     TOK_VPOLARITYPOSITIVE,
+     TOK_HPOLARITYPOSITIVE,
+     TOK_SCREENLEFTEDGE,
+     TOK_SCREENRIGHTEDGE,
+     TOK_SCREENTOPEDGE,
+     TOK_SCREENBOTTOMEDGE,
+     TOK_COLORS,        /* @V3.2SEN01 number of colors field added */
+/***************** for backward compatibility ***************/
+     TOK_INTERLACEMODE,
+/***************** for backward compatibility ***************/
+     TOK_MI_END,
+
+     TOK_HARDWARE_BEGIN,      /* @V2.2TSU00 Hardware Section */
+     TOK_BUSTYPE,
+     TOK_OEMSTRING,
+     TOK_DACSTRING,
+     TOK_VERSION,
+     TOK_TOTALMEMORY,
+     TOK_MEMORYIOADDRESS,
+     TOK_PORTIOADDRESS,
+     TOK_ENDIAN,
+     TOK_INT10SETMODE,                   /* @V3.1TSU00  */
+     TOK_HARDWARE_END,
+
+     TOK_TRAP_BEGIN,
+     TOK_BYTE_IOPORT,             /* @V2.2TSU00, trap registers type */
+     TOK_WORD_IOPORT,
+     TOK_DWORD_IOPORT,
+     TOK_BYTE_MMIOPORT,
+     TOK_WORD_MMIOPORT,
+     TOK_DWORD_MMIOPORT,
+     TOK_RESET,
+     TOK_INDEX,
+     TOK_INDEXMASK,
+     TOK_DATAMASK,
+     TOK_ACCEL,
+     TOK_RO,
+     TOK_WO,
+     TOK_RW,
+     TOK_TRAP_END,
+
+     TOK_SM_BEGIN,
+     TOK_INB,                /* Command Section tokens */
+     TOK_OUTB,
+     TOK_INW,
+     TOK_INDW,
+     TOK_OUTW,
+     TOK_OUTDW,
+     TOK_BINB,
+     TOK_BOUTB,
+     TOK_RMWBI,
+     TOK_RMWBN,
+     TOK_RMWWN,
+     TOK_ABOUTW,
+     TOK_ABOUTDW,
+     TOK_IF,
+     TOK_GOTO,
+     TOK_VARIABLE,
+     TOK_WHILE,
+     TOK_ENDWHILE,
+     TOK_MEMCMP,
+     TOK_STRCMP,
+     TOK_READB,         /* @V2.2TSU00          */
+     TOK_READW,         /* Don't rearrange the */
+     TOK_READDW,        /* order or put        */
+     TOK_WRITEB,        /* anything in between */
+     TOK_WRITEW,        /* for these MMIO      */
+     TOK_WRITEDW,       /* commands            */
+     TOK_CALL,
+     TOK_ROUTINE,
+/***************** for backward compatibility ***************/
+     TOK_WAIT,
+/***************** for backward compatibility ***************/
+     TOK_WAITB,
+     TOK_WAITW,
+     TOK_WAITDW,
+     TOK_VALUE,
+     TOK_PMIREG,
+     TOK_LPAREN,
+     TOK_RPAREN,
+     TOK_LBRACE,
+     TOK_RBRACE,
+     TOK_EQUALS,
+     TOK_NOTEQUALS,
+     TOK_SEMICOLON,
+     TOK_COMMA,
+     TOK_COLON,
+     TOK_MINUS,
+     TOK_HYPHEN = TOK_MINUS,
+     TOK_NEGATE,         /* @V2.2TSU01 */
+     TOK_DOUBLEQUOTE,
+     TOK_PLUS,
+     TOK_REGOP_AND,
+     TOK_REGOP_OR,
+     TOK_REGOP_XOR,
+     TOK_REGOP_SHL,
+     TOK_LESS = TOK_REGOP_SHL,  /* @V2.2TSU01 */
+     TOK_REGOP_SHR,
+     TOK_SM_END,
+
+     TOK_EOF,
+     TOK_IOPORT,
+     TOK_MMIO,
+     TOK_PIO,
+     TOK_ISA,
+     TOK_VLB,
+     TOK_PCI,
+     TOK_EISA,
+     TOK_PCMCIA,
+     TOK_MCA,
+     TOK_BIG_ENDIAN,
+     TOK_LITTLE_ENDIAN,
+     TOK_QUOTEDSTRING,
+     TOK_MMIO_REG_NAME,
+     TOK_IOPORT_NAME,
+     TOK_PMI_KEYVAR,
+     TOK_SHADOWVRAM,
+     TOK_MINIVDM,                /* @V3.1TSU00  */
+     TOK_FULLVDM,                /* @V3.1TSU00  */
+     TOK_ERROR,                /* error */
+     TOK_PASS
+} PMITOKEN;
+
+typedef struct _TOK { /* tok */
+  CHAR *tok_txt;
+  PMITOKEN tok_val;
+} TOK;
+
+/*
+ * definitions of bus types.
+ */
+#define ISA_BUS    0           /* @V2.2SENJA */
+#define VLB_BUS    1
+#define PCI_BUS    2
+#define EISA_BUS   3
+#define PCMCIA_BUS 4
+#define MCA_BUS    5
+#define BUS_MAX MCA_BUS
+
+#endif /* PMIDEF_INCL */
+
+/*
+ * PMI token declarations
+ * PMI_TOKEN_ARRAY should be defined to include the following array.
+ * In this way, this array will not be allocated for every C file.
+ */
+#ifdef PMI_TOKEN_ARRAY
+
+TOK Tokens[] =
+{
+
+/***************** for backward compatibility ***************/
+  "[ADAPTERTYPE]",      TOK_ADAPTERTYPE,
+  "[CHIPSET]",          TOK_CHIPSET,
+/***************** for backward compatibility ***************/
+  "[PMIVERSION]",       TOK_PMIVERSION,
+  "[COMMENT]",          TOK_COMMENT,
+  "[MODEINFO]",         TOK_MODEINFO,
+  "[SETMODE]",          TOK_SETMODE,
+  "[MONITORMODEINFO]",  TOK_MONITORMODEINFO,
+  "[TRAPREGS]",         TOK_TRAPREGS,
+  "[UNLOCK]",           TOK_UNLOCK,
+  "[LOCK]",             TOK_LOCK,
+  "[CLEANUP]",          TOK_CLEANUP,
+  "[SETBANK]",          TOK_SETBANK,
+  "[GETBANK]",          TOK_GETBANK,
+  "[DECLARATIONS]",     TOK_DECLARATIONS,
+  "[COPYVRAM]",         TOK_COPYVRAM,
+  "[TUNEDISPLAY]",      TOK_TUNEDISPLAY,
+  "[SETMEMORYIOADDRESS]",TOK_SETMEMORYIOADDRESS,  // @V3.2TSU00
+  "[HARDWARE]",         TOK_HARDWARE,
+  "[IDENTIFYADAPTER]",  TOK_IDENTIFYADAPTER,
+  "[ISENGINEBUSY]",     TOK_ISENGINEBUSY,
+  "[ENABLECONTROLLER]", TOK_ENABLECONTROLLER,
+  "[DISABLECONTROLLER]",TOK_DISABLECONTROLLER,
+  "[SETMONITORTIMINGS]",TOK_SETMONITORTIMINGS,
+  "INCLUDE",            TOK_INCLUDE,                   /* text include */
+  "INCLUDECODE",        TOK_INCLUDECODE,               /* DLL include  */
+  /*
+   * Hardware Section
+   */
+  "BUSTYPE",            TOK_BUSTYPE,
+  "OEMSTRING",          TOK_OEMSTRING,
+  "DACSTRING",          TOK_DACSTRING,
+  "VERSION",            TOK_VERSION,
+  "TOTALMEMORY",        TOK_TOTALMEMORY,
+  "MEMORYIOADDRESS",    TOK_MEMORYIOADDRESS,
+  "PORTIOADDRESS",      TOK_PORTIOADDRESS,
+  "ENDIAN",             TOK_ENDIAN,
+  "INT10SETMODE",       TOK_INT10SETMODE,    /* @V3.1TSU00  */
+  /*
+   * TrapRegs Section
+   */
+  "BYTE_IOPORT",        TOK_BYTE_IOPORT,
+  "WORD_IOPORT",        TOK_WORD_IOPORT,
+  "DWORD_IOPORT",       TOK_DWORD_IOPORT,
+  "BYTE_MMIOPORT",      TOK_BYTE_MMIOPORT,
+  "WORD_MMIOPORT",      TOK_WORD_MMIOPORT,
+  "DWORD_MMIOPORT",     TOK_DWORD_MMIOPORT,
+  "RESET",              TOK_RESET,
+  "INDEX",              TOK_INDEX,
+  "INDEXMASK",          TOK_INDEXMASK,
+  "DATAMASK",           TOK_DATAMASK,
+  "ACCEL",              TOK_ACCEL,
+  "RO",                 TOK_RO,
+  "WO",                 TOK_WO,
+  "RW",                 TOK_RW,
+  /*
+   * ModeInfo Section
+   */
+  "INT10MODESET",       TOK_INT10MODESET,
+  "MODEATTRIBUTES",     TOK_MODEATTRIBUTES,
+  "BYTESPERSCANLINE",   TOK_BYTESPERSCANLINE,
+  "TEXTROWS",           TOK_TEXTROWS,
+  "XRESOLUTION",        TOK_XRESOLUTION,
+  "YRESOLUTION",        TOK_YRESOLUTION,
+  "XCHARSIZE",          TOK_XCHARSIZE,
+  "YCHARSIZE",          TOK_YCHARSIZE,
+  "BITSPERPIXEL",       TOK_BITSPERPIXEL,
+  "NUMBEROFPLANES",     TOK_NUMBEROFPLANES,
+  "PAGELENGTH",         TOK_PAGELENGTH,
+  "SAVESIZE",           TOK_SAVESIZE,
+  "BUFFERADDRESS",      TOK_BUFFERADDRESS,
+  "APERTURESIZE",       TOK_APERTURESIZE,
+  "COLORFORMAT",        TOK_COLORFORMAT,
+  "COLORWEIGHT",        TOK_COLORWEIGHT,
+/***************** for backward compatibility ***************/
+  "INTERLACEMODE",      TOK_INTERLACEMODE,
+/***************** for backward compatibility ***************/
+  "VERTICALREFRESH",    TOK_VERTICALREFRESH,
+  "HORIZONTALREFRESH",  TOK_HORIZONTALREFRESH,
+  "VPOLARITYPOSITIVE",  TOK_VPOLARITYPOSITIVE,
+  "HPOLARITYPOSITIVE",  TOK_HPOLARITYPOSITIVE,
+  "SCREENLEFTEDGE",     TOK_SCREENLEFTEDGE,
+  "SCREENRIGHTEDGE",    TOK_SCREENRIGHTEDGE,
+  "SCREENTOPEDGE",      TOK_SCREENTOPEDGE,
+  "SCREENBOTTOMEDGE",   TOK_SCREENBOTTOMEDGE,
+  "COLORS",             TOK_COLORS,    /* @V3.2SEN01 */
+  /*
+   * PMI Commands
+   */
+  "INB",                TOK_INB,
+  "OUTB",               TOK_OUTB,
+  "INW",                TOK_INW,
+  "OUTW",               TOK_OUTW,
+  "INDW",               TOK_INDW,
+  "OUTDW",              TOK_OUTDW,
+  "BINB",               TOK_BINB,
+  "BOUTB",              TOK_BOUTB,
+  "RMWBI",              TOK_RMWBI,
+  "RMWBN",              TOK_RMWBN,
+/***************** for backward compatibility ***************/
+  "RMWB",               TOK_RMWBI,
+  "RMWW",               TOK_RMWBN,
+/***************** for backward compatibility ***************/
+  "RMWWN",               TOK_RMWWN,
+  "ABOUTW",             TOK_ABOUTW,
+  "ABOUTDW",            TOK_ABOUTDW,
+  "IF",                 TOK_IF,
+  "GOTO",               TOK_GOTO,
+  "WHILE",              TOK_WHILE,
+  "ENDWHILE",           TOK_ENDWHILE,
+  "MEMCMP",             TOK_MEMCMP,
+  "STRCMP",             TOK_STRCMP,
+  "READB",              TOK_READB,      /* @V2.2TSU00          */
+  "READW",              TOK_READW,      /* Don't rearrange the */
+  "READDW",             TOK_READDW,     /* order or put        */
+  "WRITEB",             TOK_WRITEB,     /* anything in between */
+  "WRITEW",             TOK_WRITEW,     /* for these MMIO      */
+  "WRITEDW",            TOK_WRITEDW,    /* commands            */
+  "CALL",               TOK_CALL,
+/***************** for backward compatibility ***************/
+  "WAIT",               TOK_WAIT,
+/***************** for backward compatibility ***************/
+  "WAITB",              TOK_WAITB,
+  "WAITW",              TOK_WAITW,
+  "WAITDW",             TOK_WAITDW,
+  /*
+   * others
+   */
+  "MMIO",               TOK_MMIO,    /* used in [Declarations]  */
+/***************** for backward compatibility ***************/
+  "P",                  TOK_MMIO,    /* used in [Declarations]  */
+/***************** for backward compatibility ***************/
+  "PIO",                TOK_PIO,     /*                         */
+  "ISA",                TOK_ISA,
+  "VLB",                TOK_VLB,
+  "PCI",                TOK_PCI,
+  "EISA",               TOK_EISA,
+  "PCMCIA",             TOK_PCMCIA,
+  "MCA",                TOK_MCA,
+  "SHADOWVRAM",         TOK_SHADOWVRAM,
+  "BIG",                TOK_BIG_ENDIAN,
+  "LITTLE",             TOK_LITTLE_ENDIAN,
+  "MINIVDM",            TOK_MINIVDM,         /* @V3.1TSU00  */
+  "FULLVDM",            TOK_FULLVDM          /* @V3.1TSU00  */
+
+} ;
+
+extern TOK Tokens[];
+
+#endif  /* PMI_TOKEN_ARRAY */
+
+/*
+** PMI subsystem errors
+*/
+#define ERROR_ADAPTER_NOT_SUPPORTED          ERROR_USER_DEFINED_BASE+0x10
+#define ERROR_REFRESH_NOT_SUPPORTED          ERROR_USER_DEFINED_BASE+0x11
+#define ERROR_MODE_NOT_SUPPORTED             ERROR_USER_DEFINED_BASE+0x12
+#define ERROR_REQ_SECTION_UNDEFINED          ERROR_USER_DEFINED_BASE+0x13
+#define ERROR_PMI_FILE_SYNTAX                ERROR_USER_DEFINED_BASE+0x14
+#define ERROR_NO_MONITOR_SUPPORT             ERROR_USER_DEFINED_BASE+0x15
+#define ERROR_INVALID_CONFIGURATION          ERROR_USER_DEFINED_BASE+0x16
+/* @V3.2SEN01 start */
+#define ERROR_INADEQUATE_VDM_SUPPORT       ERROR_USER_DEFINED_BASE+0x17
+#define ERROR_VDM_CREATION_NOT_SHELLPROCESS    ERROR_USER_DEFINED_BASE+0x18
+#define ERROR_MINIVDM_PROCESSSUPPORTONLY   ERROR_USER_DEFINED_BASE+0x19
+#define ERROR_INVALID_ADAPTER_EXTENSION      ERROR_USER_DEFINED_BASE+0x20
+#define ERROR_ADAPTER_STILL_IN_USE           ERROR_USER_DEFINED_BASE+0x21
+#define ERROR_UPLEVEL_VIDEOPMI               ERROR_USER_DEFINED_BASE+0x22  //structure change for cb and ulcolors
+/* @V3.2SEN01 end */
+
+/* INC */
+
Index: trunk/src/ddraw/new/asmutil.asm
===================================================================
--- trunk/src/ddraw/new/asmutil.asm	(revision 3345)
+++ trunk/src/ddraw/new/asmutil.asm	(revision 3345)
@@ -0,0 +1,2105 @@
+; $Id: asmutil.asm,v 1.1 2000-04-07 18:21:09 mike Exp $
+
+;
+; asmutil.asm Color key bit blitting for DirectDraw
+;
+; Copyright 1998 Sander van Leeuwen
+;           1999 Markus Montkowski
+;
+; Project Odin Software License can be found in LICENSE.TXT
+;
+
+                NAME    asmutil
+.586p
+.MMX
+
+CODE32  SEGMENT DWORD USE32 PUBLIC 'CODE'
+CODE32  ENDS
+DATA32  SEGMENT DWORD USE32 PUBLIC 'DATA'
+DATA32  ENDS
+CONST32  SEGMENT DWORD USE32 PUBLIC 'CONST'
+CONST32  ENDS
+BSS32  SEGMENT DWORD USE32 PUBLIC 'BSS'
+BSS32  ENDS
+DGROUP  GROUP CONST32, BSS32, DATA32
+  ASSUME  CS:FLAT, DS:FLAT, SS:FLAT, ES:FLAT
+  DATA32  SEGMENT
+  DATA32  ENDS
+  BSS32  SEGMENT
+  BSS32  ENDS
+  CONST32  SEGMENT
+  CONST32  ENDS
+
+
+CODE32  SEGMENT
+
+    PUBLIC  _BlitColorKey8
+
+;      endpos = destbuf + blitlinesize;
+;      while(destbuf < endpos) {
+;        if(*srcbuf == colorkey) {
+;          destbuf++;
+;        }
+;        else  *destbuf++ = *srcbuf;
+;        srcbuf++;
+;      }
+;      destbuf += (destscanlinesize-blitlinesize);
+;      srcbuf  += (srcscanlinesize-blitlinesize);
+;void BlitColorKey8(char *dest, char *src, ULONG key, ULONG linesize)
+_BlitColorKey8   PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  eax
+  push  ebx
+  push  ecx
+  push  edx
+
+  mov  edi, dword ptr [ebp+8]    ;dest
+  mov  esi, dword ptr [ebp+12]    ;src
+  mov  ecx, dword ptr [ebp+20]    ;linesize
+  mov  edx, dword ptr [ebp+16]    ;colorkey
+
+  and  ecx, 3
+  mov  dh , dl
+  push ecx        ;do the remaining bytes afterwards
+  mov  eax, edx
+  shl  edx, 16
+  and  eax, 0000FFFFh
+  mov  ecx, dword ptr [ebp+20]    ;linesize
+  or   edx, eax      ; edx now contains the colorkey in each byte
+  shr  ecx, 2        ;linesize in dwords
+  jz  blitremain    ; less then 4 bytes
+  jmp blitStart
+blitloop:
+  add  esi, 4
+  add  edi, 4
+blitStart:
+  mov  ebx, dword ptr [esi]
+  mov  eax, dword ptr [edi]
+  cmp  ebx, edx  ; All 4 bytes transparent?
+  jz TTTT
+  cmp   bx, dx     ; lower 2 bytes transparent ?
+  jz XXTT
+  cmp   bl, dl    ; lower byte trans
+  jz XXOT
+  mov   al, bl
+  cmp   bh, dh    ; upper Byte transparent then skip copy
+  jz XXTT
+XXOT:
+  mov   ah, bh
+XXTT:   ; handle upper 2 pixel
+  ror  eax, 16
+  ror  ebx, 16
+  cmp   bx,dx
+  jz   skipbyte4
+  cmp   bl, dl
+  je  skipbyte3
+  mov   al, bl
+skipbyte3:
+  cmp  bh, dl
+  je  skipbyte4
+  mov  ah, bh
+skipbyte4:
+  ror  eax, 16
+  mov  dword ptr [edi], eax
+TTTT:
+  dec  ecx
+  jz   blitloop
+blitremain:
+  pop  ecx
+  cmp  ecx, 2
+  ja   blit3
+  jz   blit2
+  test ecx,ecx
+  jz endofblit
+  mov  eax, dword ptr[esi]
+  mov  ebx, dword ptr [edi]
+  rol  eax, 8
+  rol  ebx, 8
+  cmp  al,dl
+  jz  endofblit
+  mov  bl,al
+  ror  ebx, 8
+  mov  dword ptr[edi],ebx
+  jmp endofblit
+
+blit3:
+  mov  eax, dword ptr[esi]
+  mov  ebx, dword ptr [edi]
+  ror  eax, 16
+  ror  ebx, 16
+  cmp  ax, dx
+  jz TTX
+  cmp  ah,dh
+  jz TXX
+  mov bh,ah
+TXX:
+  cmp al,dl
+  jz TTX
+  mov bl,al
+TTX:
+  ror  eax, 16
+  ror  ebx, 16
+  cmp  ah,dh
+  jz Cpyback
+  mov  dh,ah
+Cpyback:
+  mov  dword ptr [edi], ebx
+  jmp endofblit
+
+blit2:
+  mov  eax, dword ptr[esi]
+  mov  ebx, dword ptr [edi]
+  ror  eax, 16
+  ror  ebx, 16
+  cmp  ax, dx  ; both bytes transparent ?
+  jz endofblit
+  cmp  ah,dh
+  jz TX
+  mov bh,ah
+TX:
+  cmp al,dl
+  jz OT
+  mov bl,al
+OT:
+  ror  ebx, 16
+  mov dword ptr[edi], ebx
+
+endofblit:
+  pop  edx
+  pop  ecx
+  pop  ebx
+  pop  eax
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+_BlitColorKey8  ENDP
+
+    PUBLIC  _BlitColorKey16
+
+;      endpos = destbuf + blitlinesize;
+;      while(destbuf < endpos) {
+;        if(*srcbuf == colorkey) {
+;          destbuf++;
+;        }
+;        else  *destbuf++ = *srcbuf;
+;        srcbuf++;
+;      }
+;      destbuf += (destscanlinesize-blitlinesize);
+;      srcbuf  += (srcscanlinesize-blitlinesize);
+;void BlitColorKey16(char *dest, char *src, ULONG key, ULONG linesize)
+_BlitColorKey16   PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  eax
+  push  ebx
+  push  ecx
+  push  edx
+
+  mov  edi, dword ptr [ebp+8]    ;dest
+  mov  esi, dword ptr [ebp+12]    ;src
+  mov  ecx, dword ptr [ebp+20]    ;linesize
+  mov  edx, dword ptr [ebp+16]    ;colorkey
+
+  mov  eax, edx
+  shl  edx, 16;
+  and  eax, 0000FFFFh
+  or   edx,eax       ; create dwColorKey
+  shr  ecx, 1        ; linesize in dwords
+  jz   OnePixel
+
+blitloop16:
+  mov  eax, dword ptr [esi]
+  mov  ebx, dword ptr [edi]
+  add esi , 4
+  cmp  eax, edx ; are both pixel transparent?
+  je  LoopUp    ; Yes, then Jump to loopend
+  cmp  ax,dx    ; Is lower pixel transparent
+  je  DrawOT    ; Yes So We got OT (OPAQUE/Transparent
+  mov  bx,ax    ; No so copy the lower pixel
+  ror  eax,16   ;
+  cmp  ax,dx    ; Is higher pixel transparent
+  je  CopyBack  ;
+DrawOT:
+  ror ebx,16
+  mov  bx,ax
+  ror ebx,16
+CopyBack:
+  mov dword ptr[edi], ebx ; copy back the result in ebx
+LoopUp:
+  mov ebx, dword ptr [ebp+20] ; V load this this in case we are done
+  add edi , 4                 ; U
+OnePixel:
+  dec  ecx
+  jnz blitloop16
+  test ebx, 1                 ; Do we have an odd linesize
+  jz endofblit16
+  mov  eax, dword ptr [esi]
+  mov  ebx, dword ptr [edi]
+  ror  eax,16
+  ror  ebx,16
+  cmp  ax, dx
+  je endofblit16              ; last pixel is transparent
+  mov  bx,ax    ; No so copy the lower pixel
+  ror ebx,16
+  mov dword ptr[edi], ebx ; copy back the result in ebx
+
+endofblit16:
+  pop  edx
+  pop  ecx
+  pop  ebx
+  pop  eax
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+_BlitColorKey16  ENDP
+
+
+    PUBLIC  _BlitColorKey8MMX
+; Now the same as BlitColorKey8 now with MMX
+;void BlitColorKey8MMX(char *dest, char *src, ULONG key, ULONG linesize)
+
+_BlitColorKey8MMX PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  eax
+  push  ebx
+  push  ecx
+  push  edx
+
+  mov  edx,  [ebp+16]    ;colorkey
+  mov  edi,  [ebp+8]    ;dest
+  mov  dh,dl
+  mov  esi,  [ebp+12]    ;src
+  mov  ax,dx
+  mov  ecx, dword ptr [ebp+20]    ;linesize
+  shr  edx,16
+  mov  dx,ax
+  movd mm4,edx
+  movd mm5,edx
+  psllq mm4,32
+  por  mm4,mm5
+  shr ecx,3
+  jz BltRemain8
+
+bltLoopMMX8:
+  movq mm0, [esi] ; get source qword
+  movq mm1, [edi] ; get dest   qword
+  movq mm2,mm0   ; copy source
+  PCMPEQB mm0,mm4 ; create mask
+  pand  mm1,mm0  ; mask dest
+  pandn mm2,mm0  ; mask source
+  por   mm1,mm2  ; or them
+  movq qword ptr [edi], mm1 ; write back result
+  add esi, 8
+  add edi, 8
+  dec ecx
+  jnz bltLoopMMX8
+BltRemain8:
+  mov  eax, dword ptr [ebp+20];
+  and  eax, 7
+  jmp  ds:JmpTable[eax*4]
+
+align 4
+
+JmpTable:
+  dd offset cs:bltEndMMX8
+  dd offset cs:blt1MMX8
+  dd offset cs:blt2MMX8
+  dd offset cs:blt3MMX8
+  dd offset cs:blt4MMX8
+  dd offset cs:blt5MMX8
+  dd offset cs:blt6MMX8
+  dd offset cs:blt7MMX8
+align 2
+;
+; Maybe it would be faster for 7-5 to load a qword into mm0/mm1
+; but we might cross a page and so I guess this is saver
+;
+blt7MMX8:
+  movd mm0, dword ptr[esi]
+  mov  ax,  word ptr[esi+4]
+  mov  bx,  word ptr[edi+4]
+  movd mm1, dword ptr[edi]
+  psllq mm0,32
+  shl  eax,8
+  shl  ebx,8
+  mov  al, byte ptr[esi+6]
+  mov  bl, byte ptr[edi+6]
+  movd mm0,eax
+  psllq mm1,32
+  movd mm1,ebx
+  movq mm2,mm0    ; copy source
+  PCMPEQB mm0,mm4 ; create mask
+  pand  mm1,mm0   ; mask dest
+  pandn mm2,mm0             ; mask source
+  por   mm1,mm2 ; or them
+  movd  eax, mm1
+  psrlq mm1,32
+  mov  byte ptr[edi+6], al
+  movd  dword ptr[edi], mm1
+  shr  eax,8
+  mov  word ptr[edi+4],ax
+  jmp bltEndMMX8
+
+blt6MMX8:
+  movd mm0, dword ptr[esi]
+  mov  ax,  word ptr[esi+4]
+  mov  bx,  word ptr[edi+4]
+  movd mm1, dword ptr[edi]
+  psllq mm0,32
+  psllq mm1,32
+  movd mm0,eax
+  movd mm1,ebx
+  movq mm2,mm0   ; copy source
+  pcmpeqb mm0,mm4 ; create mask
+  pand  mm1,mm0 ; mask dest
+  pandn mm2,mm0             ; mask source
+  por   mm1,mm2 ; or them
+  movd  eax, mm1
+  psrlq mm1,32
+  mov  word ptr[edi+4],ax
+  movd  dword ptr[edi], mm1
+  jmp bltEndMMX8
+
+blt5MMX8:
+  movd mm0, dword ptr[esi]
+  movd mm1, dword ptr[edi]
+  movq mm2,mm0   ; copy source
+  pcmpeqb mm0,mm4 ; create mask
+  pand  mm1,mm0 ; mask dest
+  add esi, 4;
+  pandn mm2,mm0 ; mask source
+  por   mm1,mm2 ; or them
+  movd  dword ptr[edi], mm1
+  add edi,4
+  jmp blt1MMX8
+
+blt4MMX8:
+  movd mm0, dword ptr[esi]
+  movd mm1, dword ptr[edi]
+  movq mm2,mm0   ; copy source
+  pcmpeqb mm0,mm4 ; create mask
+  pand  mm1,mm0 ; mask dest
+  pandn mm2,mm0             ; mask source
+  por   mm1,mm2 ; or them
+  movd dword ptr [edi], mm1 ; write back result
+  jmp bltEndMMX8
+;
+; loading a dword into mm0/mm1 might be faster for 3-2...
+;
+blt3MMX8:
+  mov  ax , word ptr [esi]
+  mov  bx , word ptr [edi]
+  shl  eax,8  ; 3 Pixel left to blit
+  shl  ebx,8  ; so shift the buffers
+  mov  al,byte ptr[esi+2]
+  mov  bl,byte ptr[edi+2]
+  movd mm0,eax
+  movd mm1,ebx
+  movq mm2,mm0
+  pcmpeqb mm0,mm4 ; create mask
+  pand  mm1,mm0 ; mask dest
+  pandn mm2,mm0 ; mask source
+  por   mm1,mm2 ; or them
+  movd eax, mm1 ; write back result
+  mov  byte ptr[edi+2],al
+  shr eax,8
+  mov  word ptr[edi],ax
+  jmp bltEndMMX8
+
+blt2MMX8:
+  mov  al, byte ptr [esi]
+  cmp al,dl
+  je  blt1aMMX8
+  mov  byte ptr [edi], al
+  mov  bl , byte ptr [esi+1]
+  cmp bl,dl
+  je  bltEndMMX8
+  mov  byte ptr [edi+1], bl
+  jmp bltEndMMX8
+blt1aMMX8:
+  add esi,1
+  add edi,1
+blt1MMX8:
+  mov  al, byte ptr [esi]
+  cmp al,dl
+  je  bltEndMMX8
+  mov  byte ptr [edi], al
+
+bltEndMMX8:
+  pop  edx
+  pop  ecx
+  pop  ebx
+  pop  eax
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+_BlitColorKey8MMX ENDP
+
+
+    PUBLIC  _BlitColorKey16MMX
+; Now the same as BlitColorKey16 now with MMX
+;void BlitColorKey16MMX(char *dest, char *src, ULONG key, ULONG linesize)
+_BlitColorKey16MMX PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  ecx
+  push  edx
+
+  mov  edx, dword ptr [ebp+16]    ; colorkey
+  mov  edi, dword ptr [ebp+8]     ; dest
+  mov  eax, dword ptr [ebp+16]    ; colorkey
+  shr  edx,16;
+  mov  ecx, dword ptr [ebp+20]    ; linesize in pixel!
+  mov  dx,ax                      ; extend colorkey to 32 Bit
+  mov  esi, dword ptr [ebp+12]    ; src
+  mov  eax, ecx                   ; copy of linesize
+  shr  ecx,2
+  movd mm4, edx
+  jz BltRemain16
+
+  movd mm5,edx                    ; Extend colorkey to 64 Bit
+  psllq mm4,32
+  por mm4,mm5
+
+bltLoopMMX16:
+  movq mm0,qword ptr [esi] ; get source dword
+  movq mm1,qword ptr [edi] ; get destination
+  movq mm2,mm0   ; copy source
+  pcmpeqw mm0,mm4 ; create mask
+  pand  mm1,mm0  ; mask dest
+  add esi, 8
+  pandn mm2,mm0  ; mask source
+  por   mm1,mm2  ; or them
+  movq qword ptr [edi], mm1 ; write back result
+  add edi, 8
+  dec ecx
+  jnz bltLoopMMX16
+
+BltRemain16:
+  and  eax,3
+  jmp  ds:JumpTable[eax*4]
+
+align 4
+
+JumpTable:
+  dd offset cs:bltEndMMX16
+  dd offset cs:blt1MMX16
+  dd offset cs:blt2MMX16
+  dd offset cs:blt3MMX16
+align 2
+
+blt3MMX16:
+  movd mm0, dword ptr[esi]
+  movd mm1, dword ptr[edi]
+  movq mm2,mm0   ; copy source
+  add esi,4
+  pcmpeqw mm0,mm4 ; create mask 16 bit
+  pand  mm1,mm0 ; mask dest
+  pandn mm2,mm0             ; mask source
+  add edi,4
+  por   mm1,mm2 ; or them
+  movd  dword ptr[edi-4], mm1
+  jmp blt1MMX16
+
+blt2MMX16:
+  movd mm0, dword ptr[esi]
+  movd mm1, dword ptr[edi]
+  movq mm2,mm0   ; copy source
+  pcmpeqw mm0,mm4 ; create mask 16 bit
+  pand  mm1,mm0 ; mask dest
+  pandn mm2,mm0             ; mask source
+  por   mm1,mm2 ; or them
+  movd dword ptr [edi], mm1 ; write back result
+  jmp bltEndMMX16
+
+blt1MMX16:
+  mov  ax, word ptr [esi] ; cmov ?
+  cmp ax,dx
+  je  bltEndMMX16
+  mov  word ptr [edi], ax
+
+
+bltEndMMX16:
+  pop  edx
+  pop  ecx
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+_BlitColorKey16MMX ENDP
+
+;
+; extern void __cdecl BltTransSrcRecMMX(PBYTE dest, PBYTE src, ULONG ulBltWidth,ULONG ulBltHeight
+;                                       ULONG ulDestPitch, ULONG ulSrcPitch, ULONG ulTransCol);
+
+    PUBLIC _BltTransSrcRecMMX
+_BltTransSrcRecMMX PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  eax
+  push  ebx
+  push  ecx
+  push  edx
+
+EndTSBlt:
+  pop  edx
+  pop  ecx
+  pop  ebx
+  pop  eax
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+
+_BltTransSrcRecMMX ENDP
+
+
+    PUBLIC _BltRec
+;
+; extern void __cdecl BltRec(PBYTE dest, PBYTE src, ULONG ulBltWidth,ULONG ulBltHeight
+;                           ULONG ulDestPitch, ULONG ulSrcPitch);
+_BltRec   PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  eax
+  push  ebx
+  push  ecx
+  push  edx
+
+  mov  ecx, dword ptr [ebp+16]    ; U ulBltWidth
+  mov  esi, dword ptr [ebp+12]    ; V src
+  mov  ebx, ecx                   ; U
+  mov  edx, dword ptr [ebp+20]    ; V ulBltHeight
+  and  ebx, 0Fh                   ; U ebx = # of bytes < 16
+  mov  edi, dword ptr [ebp+8]     ; V dest
+  cmp  edx, 0
+  jz BltRecEnd                    ; height is zero so done
+  shr  ecx, 4                     ; U
+  jz   SmallBlt                   ; Small (width < 16) rectangle done in special case
+  test ebx, ebx
+  jnz  ComplexBlt                 ; ulBltWidth mod 16  is not 0
+
+;
+; Blitwidth is an multiple of 16
+;
+  mov  ebx, dword ptr [ebp+24]    ; ulDestPitch
+  mov  eax, dword ptr [ebp+28]    ; ulSrcPitch
+  sub  ebx, dword ptr [ebp+16]    ; adjust both widths
+  sub  eax, dword ptr [ebp+16]
+  mov  dword ptr [ebp+28], eax    ; store adjusted SrcPitch
+  mov  eax, ecx
+LineLoop:
+  FLD QWORD PTR [ESI]
+  FLD QWORD PTR [ESI+8]
+  FXCH
+  FSTP QWORD PTR [EDI]
+  FSTP QWORD PTR [EDI+8]
+  ADD ESI,16
+  ADD EDI,16
+  dec eax
+  jz  LineLoop
+  dec edx
+  jz BltRecEnd
+  add ESI, dword ptr[ebp+28]
+  add EDI, ebx
+  mov  eax, ecx
+  jmp LineLoop
+
+SmallBlt:
+  mov  eax, dword ptr [ebp+28]    ; ulSrcPitch
+  mov  ecx, dword ptr [ebp+24]    ; ulDestPitch
+  jmp  ds:SmallJmpTable[ebx*4]
+SmallJmpTable:
+ dd cs:offset BltRecEnd ; BlitWidth is 0 done
+ dd cs:offset Rec1
+ dd cs:offset Rec2
+ dd cs:offset Rec3
+ dd cs:offset Rec4
+ dd cs:offset Rec5
+ dd cs:offset Rec6
+ dd cs:offset Rec7
+ dd cs:offset Rec8
+ dd cs:offset Rec9
+ dd cs:offset Rec10
+ dd cs:offset Rec11
+ dd cs:offset Rec12
+ dd cs:offset Rec13
+ dd cs:offset Rec14
+ dd cs:offset Rec15
+
+;One Pixel wide
+
+Rec1:
+ cmp edx,4
+ jb Rec1_0123
+ mov bl, byte ptr [esi]
+ add esi,eax
+ mov byte ptr [edi], bl
+ add edi,ecx
+ mov bl, byte ptr [esi]
+ add esi,eax
+ mov byte ptr [edi], bl
+ add edi,ecx
+ mov bl, byte ptr [esi]
+ add esi,eax
+ mov byte ptr [edi], bl
+ add edi,ecx
+ mov bl, byte ptr [esi]
+ add esi,eax
+ mov byte ptr [edi], bl
+ add edi,ecx
+ sub edx,4
+ jnz Rec1
+ jmp BltRecEnd
+Rec1_0123:
+ cmp edx,2
+ jz Rec1_2
+ jb Rec1_01
+; Must be 3 lines left
+ mov bl, byte ptr [esi]
+ add esi,eax
+ mov byte ptr [edi], bl
+ add edi,ecx
+ mov bl, byte ptr [esi]
+ add esi,eax
+ mov byte ptr [edi], bl
+ add edi,ecx
+ mov bl, byte ptr [esi]
+ mov byte ptr [edi], bl
+ jmp BltRecEnd
+Rec1_2:
+ mov bl, byte ptr [esi]
+ add esi,eax
+ mov byte ptr [edi], bl
+ add edi,ecx
+ mov bl, byte ptr [esi]
+ mov byte ptr [edi], bl
+ jmp BltRecEnd
+Rec1_01:
+ test edx,edx
+ jz BltRecEnd
+ mov bl, byte ptr [esi]
+ mov byte ptr [edi], bl
+ jmp BltRecEnd
+
+;2 Pixel Wide
+
+Rec2:
+ cmp edx,4
+ jb Rec2_0123
+ mov bx, word ptr [esi]
+ add esi,eax
+ mov word ptr [edi], bx
+ add edi,ecx
+ mov bx, word ptr [esi]
+ add esi,eax
+ mov word ptr [edi], bx
+ add edi,ecx
+ mov bx, word ptr [esi]
+ add esi,eax
+ mov word ptr [edi], bx
+ add edi,ecx
+ mov bx, word ptr [esi]
+ add esi,eax
+ mov word ptr [edi], bx
+ add edi,ecx
+ sub edx, 4
+ jnz Rec2
+ jmp BltRecEnd
+
+Rec2_0123:
+ cmp edx,2
+ jz Rec2_2
+ jb Rec2_01
+;3 lines left
+ mov bx, word ptr [esi]
+ add esi,eax
+ mov word ptr [edi], bx
+ add edi,ecx
+ mov bx, word ptr [esi]
+ add esi,eax
+ mov word ptr [edi], bx
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov word ptr [edi], bx
+ jmp BltRecEnd
+Rec2_2:
+ mov bx, word ptr [esi]
+ add esi,eax
+ mov word ptr [edi], bx
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov word ptr [edi], bx
+ jmp BltRecEnd
+Rec2_01:
+ test edx,edx
+ jz BltRecEnd
+ mov bx, word ptr [esi]
+ mov word ptr [edi], bx
+ jmp BltRecEnd
+
+; 3 Pixel Wide must check if it's better to read 4 bytes as
+; Intel might stall on reading 2 and 1 byte, but this takes more care as we
+; could create a pagefault on the last 3 pixel
+
+Rec3:
+ cmp edx,4
+ jb Rec3_0123
+ push edx
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ add esi,eax
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ add esi,eax
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ add esi,eax
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ add esi,eax
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ add edi,ecx
+ pop edx
+ sub edx,4
+ jnz Rec3
+ jmp BltRecEnd
+
+Rec3_0123:
+ cmp edx,2
+ jz Rec3_2
+ jb Rec3_01
+; Must be 3 lines left
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ add esi,eax
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ add esi,eax
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ jmp BltRecEnd
+Rec3_2:
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ add esi,eax
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ add edi,ecx
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ jmp BltRecEnd
+Rec3_01:
+ test edx,edx
+ jz BltRecEnd
+ mov bx, word ptr [esi]
+ mov dl, byte ptr [esi+2]
+ mov word ptr [edi], bx
+ mov byte ptr [edi+2], dl
+ jmp BltRecEnd
+
+; 4 Pixel Wide
+
+Rec4:
+ cmp edx,4
+ jb Rec4_0123
+ mov ebx, dword ptr [esi]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ add edi,ecx
+ sub edx ,4
+ jnz Rec4
+ jmp BltRecEnd
+
+Rec4_0123:
+ cmp edx,2
+ jz Rec2_2
+ jb Rec2_01
+;3 lines left
+ mov ebx, dword ptr [esi]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dword ptr [edi], ebx
+ jmp BltRecEnd
+Rec4_2:
+ mov ebx, dword ptr [esi]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dword ptr [edi], ebx
+ jmp BltRecEnd
+Rec4_01:
+ test edx,edx
+ jz BltRecEnd
+ mov ebx, dword ptr [esi]
+ mov dword ptr [edi], ebx
+ jmp BltRecEnd
+
+; 5 Pixel Wide
+
+Rec5:
+ cmp edx,4
+ jb Rec5_0123
+ push edx
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec5
+ jmp BltRecEnd
+Rec5_0123:
+ cmp edx,2
+ jz Rec5_2
+ jb Rec5_01
+; Must be 3 lines left
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ jmp BltRecEnd
+Rec5_2:
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ jmp BltRecEnd
+Rec5_01:
+ test edx,edx
+ jz BltRecEnd
+ mov ebx, dword ptr [esi]
+ mov dl, byte ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov byte ptr [edi+4], dl
+ jmp BltRecEnd
+
+; 6 Pixel Wide
+
+Rec6:
+ cmp edx,4
+ jb Rec6_0123
+ push edx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec6
+ jmp BltRecEnd
+Rec6_0123:
+ cmp edx,2
+ jz Rec6_2
+ jb Rec6_01
+; Must be 3 lines left
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ jmp BltRecEnd
+Rec6_2:
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ add esi,eax
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ jmp BltRecEnd
+Rec6_01:
+ test edx,edx
+ jz BltRecEnd
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ jmp BltRecEnd
+
+; 7 Pixel Wide
+
+Rec7:
+ cmp edx,4
+ jb Rec6_0123
+ push edx
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ add esi,eax
+ mov byte ptr[edi+6],bl
+ add edi,ecx
+ xor ebx,ebx ; clear ebx to avoid stalls
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ add esi,eax
+ mov byte ptr[edi+6],bl
+ add edi,ecx
+ xor ebx,ebx ; clear ebx to avoid stalls
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ add esi,eax
+ mov byte ptr[edi+6],bl
+ add edi,ecx
+ xor ebx,ebx ; clear ebx to avoid stalls
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ add esi,eax
+ mov byte ptr[edi+6],bl
+ add edi,ecx
+ xor ebx,ebx ; clear ebx to avoid stalls
+ pop edx
+ sub edx ,4
+ jnz Rec7
+ jmp BltRecEnd
+Rec7_0123:
+ cmp edx,2
+ jz Rec7_2
+ jb Rec7_01
+; Must be 3 lines left
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ add esi,eax
+ mov byte ptr[edi+6],bl
+ add edi,ecx
+ xor ebx,ebx ; clear ebx to avoid stalls
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ add esi,eax
+ mov byte ptr[edi+6],bl
+ add edi,ecx
+ xor ebx,ebx ; clear ebx to avoid stalls
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ mov byte ptr[edi+6],bl
+ jmp BltRecEnd
+Rec7_2:
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ add esi,eax
+ mov byte ptr[edi+6],bl
+ add edi,ecx
+ xor ebx,ebx ; clear ebx to avoid stalls
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ mov byte ptr[edi+6],bl
+ jmp BltRecEnd
+Rec7_01:
+ test edx,edx
+ jz BltRecEnd
+ mov ebx, dword ptr [esi]
+ mov dx, word ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov word ptr [edi+4], dx
+ mov bl, byte ptr[esi+6]
+ mov byte ptr[edi+6],bl
+ jmp BltRecEnd
+
+; 8 Pixel Wide
+
+Rec8:
+ cmp edx,4
+ jb Rec8_0123
+ push edx
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ add esi,eax
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ add esi,eax
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ add esi,eax
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ add esi,eax
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec8
+ jmp BltRecEnd
+
+Rec8_0123:
+ cmp edx,2
+ jz Rec8_2
+ jb Rec8_01
+;3 lines left
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ add esi,eax
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ add esi,eax
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ jmp BltRecEnd
+Rec8_2:
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ add esi,eax
+ add edi,ecx
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ jmp BltRecEnd
+Rec8_01:
+ test edx,edx
+ jz BltRecEnd
+ mov ebx, dword ptr [esi]
+ mov edx, dword ptr [esi+4]
+ mov dword ptr [edi], ebx
+ mov dword ptr [edi+4], edx
+ jmp BltRecEnd
+
+; 9 Pixel Wide
+
+Rec9:
+ cmp edx,4
+ jb Rec9_0123
+ push edx
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ add esi,eax
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec9
+ jmp BltRecEnd
+
+Rec9_0123:
+ cmp edx,2
+ jz Rec9_2
+ jb Rec9_01
+;3 lines left
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ jmp BltRecEnd
+Rec9_2:
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ jmp BltRecEnd
+Rec9_01:
+ test edx,edx
+ jz BltRecEnd
+ FLD QWORD PTR [ESI]
+ mov bl, byte ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov byte ptr [edi+8], bl
+ jmp BltRecEnd
+
+; 10 Pixel Wide
+
+Rec10:
+ cmp edx,4
+ jb Rec10_0123
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ add esi,eax
+ add edi,ecx
+ sub edx ,4
+ jnz Rec10
+ jmp BltRecEnd
+
+Rec10_0123:
+ cmp edx,2
+ jz Rec10_2
+ jb Rec10_01
+;3 lines left
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ jmp BltRecEnd
+Rec10_2:
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ jmp BltRecEnd
+Rec10_01:
+ test edx,edx
+ jz BltRecEnd
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ jmp BltRecEnd
+
+; 11 Pixel Wide
+
+Rec11:
+ cmp edx,4
+ jb Rec11_0123
+ push edx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ add esi,eax
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec10
+ jmp BltRecEnd
+
+Rec11_0123:
+ cmp edx,2
+ jz Rec11_2
+ jb Rec11_01
+;3 lines left
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ jmp BltRecEnd
+Rec11_2:
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ jmp BltRecEnd
+Rec11_01:
+ test edx,edx
+ jz BltRecEnd
+ FLD QWORD PTR [ESI]
+ mov bx, word ptr [esi+8]
+ mov dl, byte ptr [esi+10]
+ FSTP QWORD PTR [EDI]
+ mov word ptr [edi+8], bx
+ mov byte ptr [edi+10], dl
+ jmp BltRecEnd
+
+; 12 Pixel Wide
+
+Rec12:
+ cmp edx,4
+ jb Rec12_0123
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ add esi,eax
+ add edi,ecx
+ sub edx ,4
+ jnz Rec12
+ jmp BltRecEnd
+
+Rec12_0123:
+ cmp edx,2
+ jz Rec12_2
+ jb Rec12_01
+;3 lines left
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ jmp BltRecEnd
+Rec12_2:
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ jmp BltRecEnd
+Rec12_01:
+ test edx,edx
+ jz BltRecEnd
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ jmp BltRecEnd
+
+; 13 Pixel Wide
+
+Rec13:
+ cmp edx,4
+ jb Rec13_0123
+ push edx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ add esi,eax
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec13
+ jmp BltRecEnd
+
+Rec13_0123:
+ cmp edx,2
+ jz Rec13_2
+ jb Rec13_01
+;3 lines left
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ jmp BltRecEnd
+Rec13_2:
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ jmp BltRecEnd
+Rec13_01:
+ test edx,edx
+ jz BltRecEnd
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dl, byte ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov byte ptr [edi+12], dl
+ jmp BltRecEnd
+
+; 14 Pixel Wide
+
+Rec14:
+ cmp edx,4
+ jb Rec14_0123
+ push edx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ add esi,eax
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec14
+ jmp BltRecEnd
+
+Rec14_0123:
+ cmp edx,2
+ jz Rec14_2
+ jb Rec14_01
+;3 lines left
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ jmp BltRecEnd
+Rec14_2:
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ add esi,eax
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ jmp BltRecEnd
+Rec14_01:
+ test edx,edx
+ jz BltRecEnd
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov word ptr [edi+12], dx
+ jmp BltRecEnd
+
+; 15 Pixel Wide
+
+Rec15:
+ cmp edx,4
+ jb Rec15_0123
+ push edx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ add esi,eax
+ mov byte ptr[edi+14], bl
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ add esi,eax
+ mov byte ptr[edi+14], bl
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ add esi,eax
+ mov byte ptr[edi+14], bl
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ add esi,eax
+ mov byte ptr[edi+14], bl
+ add edi,ecx
+ pop edx
+ sub edx ,4
+ jnz Rec15
+ jmp BltRecEnd
+
+Rec15_0123:
+ cmp edx,2
+ jz Rec15_2
+ jb Rec15_01
+;3 lines left
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ add esi,eax
+ mov byte ptr[edi+14], bl
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ add esi,eax
+ mov byte ptr[edi+14], bl
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ mov byte ptr[edi+14], bl
+ jmp BltRecEnd
+Rec15_2:
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ add esi,eax
+ mov byte ptr[edi+14], bl
+ add edi,ecx
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ mov byte ptr[edi+14], bl
+ jmp BltRecEnd
+Rec15_01:
+ test edx,edx
+ jz BltRecEnd
+ FLD QWORD PTR [ESI]
+ mov ebx, dword ptr [esi+8]
+ mov dx, word ptr [esi+12]
+ FSTP QWORD PTR [EDI]
+ mov dword ptr [edi+8], ebx
+ mov bl, byte ptr[esi+14]
+ mov word ptr [edi+12], dx
+ mov byte ptr[edi+14], bl
+ jmp BltRecEnd
+
+
+ComplexBlt:
+ ; Blit first the even rect then the rest
+
+ push dword ptr [ebp+28]    ; ulSrcPitch
+ push dword ptr [ebp+24]    ; ulDestPitch
+ push edx
+ shl  ecx,4
+ push ecx
+ push esi
+ push edi
+ call _BltRec
+ sub  esp,24
+ add  esi,ecx
+ add  edi,ecx
+ push dword ptr [ebp+28]    ; ulSrcPitch
+ push dword ptr [ebp+24]    ; ulDestPitch
+ push edx
+ push ebx
+ push esi
+ push edi
+ call _BltRec
+ sub  esp,24
+
+BltRecEnd:
+  pop  edx
+  pop  ecx
+  pop  ebx
+  pop  eax
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+_BltRec   ENDP
+
+
+    PUBLIC _CPUHasMMX
+;
+; int __cdecl CPUHasMMX()
+; returns:
+;   0 = NoMMX
+;   1 = MMX
+;   2 = MMX+CMov instuction
+
+_CPUHasMMX PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  ebx
+  push  ecx
+  push  edx
+
+  pushfd
+  pop  eax
+  mov  ebx ,eax
+  xor  eax, 00200000h
+  push eax
+  popfd
+  pushfd
+  pop  eax
+  sub  eax,ebx
+  jz   Return  ; No CPUID => No MMX => return 0 in eax;
+  mov eax, 1
+  CPUID
+  test edx,00800000h ; MMX Bit Set ?
+  jz Return
+  mov eax, 1
+  test edx,00008000h ; Conditonal Mov Bit Set ?
+  jz Return
+  inc eax
+Return:
+  pop  edx
+  pop  ecx
+  pop  ebx
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+_CPUHasMMX   ENDP
+
+    PUBLIC _MemFlip
+
+;
+; memcpy via FLD / FSTP MMX might even be faster but
+; not present on every system
+; to maximize the speed we copy 64 bytes in each loop
+; and after the loop the rest left
+;
+;
+;void __cdecl MemFlip(PBYTE dest, PBYTE src, ULONG Size);
+
+_MemFlip PROC NEAR
+  push  ebp
+  mov   ebp, esp
+  push  edi
+  push  esi
+  push  eax
+  push  ebx
+  push  ecx
+
+  mov eax , dword ptr [ebp+16]    ; Size of Buffer
+  mov edi , dword ptr [ebp+8]     ; Destination
+  mov ebx , eax
+  mov esi , dword ptr [ebp+12]    ; SourcePointer
+
+  and ebx , 0000003Fh             ; Calc leftover bytes
+  shr eax , 5                     ; Calc Loops
+
+  jz COPYREMAIN                   ; Less then 64 to copy
+ALIGN 4
+
+Loop64:
+  FLD QWORD PTR [ESI]      ; 1
+  FLD QWORD PTR [ESI+8]    ; 2
+  FXCH                     ; Doesn't take any clocks
+  FSTP QWORD PTR [EDI]     ; 3,4 Clocks
+  FSTP QWORD PTR [EDI+8]   ; 5,6
+  ADD ESI,16               ; 7 U Integer instruction can be executed parallel
+  ADD EDI,16               ; 7 V Total clocks for copying 16 byte 7 clocks Rep Movs needs 20! for each 16 byte + 13 setup
+  FLD QWORD PTR [ESI]
+  FLD QWORD PTR [ESI+8]
+  FXCH
+  FSTP QWORD PTR [EDI]
+  FSTP QWORD PTR [EDI+8]
+  ADD ESI,16
+  ADD EDI,16
+  FLD QWORD PTR [ESI]
+  FLD QWORD PTR [ESI+8]
+  FXCH
+  FSTP QWORD PTR [EDI]
+  FSTP QWORD PTR [EDI+8]
+  ADD ESI,16
+  ADD EDI,16
+  FLD QWORD PTR [ESI]
+  FLD QWORD PTR [ESI+8]
+  FXCH
+  FSTP QWORD PTR [EDI]
+  FSTP QWORD PTR [EDI+8]
+  ADD ESI,16
+  ADD EDI,16
+  inc eax
+  jnz Loop64
+
+COPYREMAIN:
+  test ebx, ebx ; something left ?
+  jz EndOffFlip
+
+  test ebx, 00000020h; at least 32 bytes left ?
+  jz Test16
+
+  FLD QWORD PTR [ESI]
+  FLD QWORD PTR [ESI+8]
+  FXCH
+  FSTP QWORD PTR [EDI]
+  FSTP QWORD PTR [EDI+8]
+  ADD ESI,16
+  ADD EDI,16
+  FLD QWORD PTR [ESI]
+  FLD QWORD PTR [ESI+8]
+  FXCH
+  FSTP QWORD PTR [EDI]
+  FSTP QWORD PTR [EDI+8]
+  ADD ESI,16
+  ADD EDI,16
+  sub ebx, 00000020h
+  jz EndOffFlip
+
+Test16:
+
+  test ebx, 00000010h; at least 16 bytes left ?
+  jb Test8
+
+  FLD QWORD PTR [ESI]
+  FLD QWORD PTR [ESI+8]
+  FXCH
+  FSTP QWORD PTR [EDI]
+  FSTP QWORD PTR [EDI+8]
+  ADD ESI,16
+  ADD EDI,16
+  sub ebx, 00000010h
+  jz EndOffFlip
+Test8:
+
+  test ebx, 00000008h; at least 8 bytes left ?
+  jb Test4
+  mov eax,[esi]
+  mov ecx,[esi+4]
+  mov [edi],eax
+  mov [edi+4],ecx
+  add esi, 8
+  add edi, 8
+  sub ebx, 8
+  jz EndOffFlip
+
+Test4:
+  test ebx, 00000004h; at least 4 bytes left ?
+  jb Test2
+  mov eax,[esi]
+  sub ebx, 4
+  mov [edi],eax
+  add esi, 4
+  add edi, 4
+  test ebx, ebx ; something left ?
+  jz EndOffFlip
+
+Test2:
+  test ebx, 00000002h
+  jb Copy1
+  mov ax,[esi]
+  sub ebx,2
+  mov [edi],ax
+  add esi,2
+  add edi,2
+  test ebx,ebx
+  jz EndOffFlip
+
+Copy1:
+  mov al,[esi]
+  mov [edi],al
+
+EndOffFlip:
+  pop  ecx
+  pop  ebx
+  pop  eax
+  pop  esi
+  pop  edi
+  pop  ebp
+  ret
+_MemFlip   ENDP
+
+CODE32          ENDS
+
+                END
Index: trunk/src/ddraw/new/asmutil.h
===================================================================
--- trunk/src/ddraw/new/asmutil.h	(revision 3345)
+++ trunk/src/ddraw/new/asmutil.h	(revision 3345)
@@ -0,0 +1,34 @@
+/* $Id: asmutil.h,v 1.1 2000-04-07 18:21:09 mike Exp $ */
+
+/*
+ * asmutil.asm function definition
+ *
+ * Copyright 1998 Sander van Leeuwen
+ *           1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef __ASMUTIL_H__
+#define __ASMUTIL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void __cdecl BlitColorKey8(PBYTE dest, PBYTE src, ULONG key, ULONG linesize);
+extern void __cdecl BlitColorKey16(PBYTE dest, PBYTE src, ULONG key, ULONG linesize);
+extern void __cdecl BlitColorKey32(PBYTE dest, PBYTE src, ULONG key, ULONG linesize);
+extern void __cdecl BlitColorKey8MMX(PBYTE dest, PBYTE src, ULONG key, ULONG linesize);
+extern void __cdecl BlitColorKey16MMX(PBYTE dest, PBYTE src, ULONG key, ULONG linesize);
+extern void __cdecl BltRec(PBYTE dest, PBYTE src, ULONG ulBltWidth, ULONG ulBltHeight,
+                           ULONG ulDestPitch, ULONG ulSrcPitch);
+extern void __cdecl MemFlip(PBYTE dest, PBYTE src, ULONG Size);
+extern int __cdecl CPUHasMMX();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: trunk/src/ddraw/new/bltFunc.cpp
===================================================================
--- trunk/src/ddraw/new/bltFunc.cpp	(revision 3345)
+++ trunk/src/ddraw/new/bltFunc.cpp	(revision 3345)
@@ -0,0 +1,567 @@
+/* $Id: bltFunc.cpp,v 1.1 2000-04-07 18:21:10 mike Exp $ */
+
+/*
+ * Blitting functions
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <memory.h>
+#include <misc.h>
+#include "bltFunc.h"
+
+//
+// Blt Functions
+//
+
+#ifndef USE_ASM
+void __cdecl BltSolid8( char* pDst,
+                        char* pSrc,
+                        DWORD dwWidth,
+                        DWORD dwHeight,
+                        DWORD dwPitchDst,
+                        DWORD dwPitchSrc)
+{
+  dprintf(("DDRAW:BltSolid8\n"));
+  while(dwHeight)
+  {
+    memcpy(pDst,pSrc,dwWidth);
+    pDst += dwPitchDst;
+    pSrc += dwPitchSrc;
+    dwHeight--;
+  }
+}
+void __cdecl BltSolid16(char* pDst,
+                        char* pSrc,
+                        DWORD dwWidth,
+                        DWORD dwHeight,
+                        DWORD dwPitchDst,
+                        DWORD dwPitchSrc)
+{
+  dprintf(("DDRAW:BltSolid16\n"));
+  dwWidth *=2;
+  while(dwHeight)
+  {
+    memcpy(pDst,pSrc,dwWidth);
+    pDst += dwPitchDst;
+    pSrc += dwPitchSrc;
+    dwHeight--;
+  }
+}
+void __cdecl BltSolid24(char* pDst,
+                        char* pSrc,
+                        DWORD dwWidth,
+                        DWORD dwHeight,
+                        DWORD dwPitchDst,
+                        DWORD dwPitchSrc)
+{
+  dprintf(("DDRAW:BltSolid24\n"));
+  dwWidth *=3;
+  while(dwHeight)
+  {
+    memcpy(pDst,pSrc,dwWidth);
+    pDst += dwPitchDst;
+    pSrc += dwPitchSrc;
+    dwHeight--;
+  }
+}
+void __cdecl BltSolid32(char* pDst,
+                        char* pSrc,
+                        DWORD dwWidth,
+                        DWORD dwHeight,
+                        DWORD dwPitchDst,
+                        DWORD dwPitchSrc)
+{
+  dprintf(("DDRAW:BltSolid32\n"));
+  dwWidth *=4;
+  while(dwHeight)
+  {
+    memcpy(pDst,pSrc,dwWidth);
+    pDst += dwPitchDst;
+    pSrc += dwPitchSrc;
+    dwHeight--;
+  }
+}
+#else
+  #define BltSolid8  BltSolid8ASM
+  #define BltSolid16 BltSolid16ASM
+  #define BltSolid24 BltSolid24ASM
+  #define BltSolid32 BltSolid32ASM
+#endif
+
+// without ColorConversion
+void __cdecl BltSolid8to8( char *pDBDst,
+                           char *pFBDst,
+                           DWORD dwDstTop,
+                           DWORD dwDstLeft,
+                           DWORD dwPitchDBDst,
+                           DWORD dwPitchFBDst,
+                           char *pDBSrc,
+                           char *pFBSrc,
+                           DWORD dwSrcTop,
+                           DWORD dwSrcLeft,
+                           DWORD dwWidth,
+                           DWORD dwHeight,
+                           DWORD dwPitchDBSrc,
+                           DWORD dwPitchFBSrc
+                           )
+{
+  dprintf(("DDRAW:BltSolid8to8\n"));
+  BltSolid8( pDBDst + dwDstLeft + (dwDstTop*dwPitchDBDst),
+             pDBSrc + dwSrcLeft + (dwSrcTop*dwPitchDBSrc),
+             dwWidth,
+             dwHeight,
+             dwPitchDBDst,
+             dwPitchDBSrc);
+}
+void __cdecl BltSolid16to16( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             )
+{
+  dprintf(("DDRAW:BltSolid16to16\n"));
+  BltSolid16( pDBDst + (dwDstLeft*2) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*2) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+}
+void __cdecl BltSolid24to24( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             )
+{
+  dprintf(("DDRAW:BltSolid24to24\n"));
+  BltSolid24( pDBDst + (dwDstLeft*3) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*3) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+}
+void __cdecl BltSolid32to32( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             )
+{
+  dprintf(("DDRAW:BltSolid32to32\n"));
+  BltSolid32( pDBDst + (dwDstLeft*4) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*4) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+}
+
+// With ColorConversion
+
+// 8 to X bit
+void __cdecl BltSolid8to16( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid8to16\n"));
+
+  BltSolid8( pFBDst + dwDstLeft + (dwDstTop*dwPitchFBDst),
+             pFBSrc + dwSrcLeft + (dwSrcTop*dwPitchFBSrc),
+             dwWidth,
+             dwHeight,
+             dwPitchFBDst,
+             dwPitchFBSrc);
+  BltSolid16( pDBDst + (dwDstLeft*2) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*2) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+
+}
+
+void __cdecl BltSolid8to24( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid8to24\n"));
+  BltSolid8( pFBDst + dwDstLeft + (dwDstTop*dwPitchFBDst),
+             pFBSrc + dwSrcLeft + (dwSrcTop*dwPitchFBSrc),
+             dwWidth,
+             dwHeight,
+             dwPitchFBDst,
+             dwPitchFBSrc);
+  BltSolid24( pDBDst + (dwDstLeft*3) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*3) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+}
+void __cdecl BltSolid8to32( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid8to32\n"));
+  BltSolid8( pFBDst + dwDstLeft + (dwDstTop*dwPitchFBDst),
+             pFBSrc + dwSrcLeft + (dwSrcTop*dwPitchFBSrc),
+             dwWidth,
+             dwHeight,
+             dwPitchFBDst,
+             dwPitchFBSrc);
+  BltSolid32( pDBDst + (dwDstLeft*4) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*4) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+}
+
+// 16 to X bit
+void __cdecl BltSolid16to8( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid16to8\n"));
+  BltSolid8( pDBDst + dwDstLeft + (dwDstTop*dwPitchDBDst),
+             pDBSrc + dwSrcLeft + (dwSrcTop*dwPitchDBSrc),
+             dwWidth,
+             dwHeight,
+             dwPitchDBDst,
+             dwPitchDBSrc);
+  BltSolid16( pFBDst + (dwDstLeft*2) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*2) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+
+void __cdecl BltSolid16to24( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid16to24\n"));
+  BltSolid24( pDBDst + (dwDstLeft*3) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*3) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+  BltSolid16( pFBDst + (dwDstLeft*2) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*2) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+void __cdecl BltSolid16to32( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             )
+{
+  dprintf(("DDRAW:BltSolid16to32\n"));
+  BltSolid32( pDBDst + (dwDstLeft*4) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*4) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+  BltSolid16( pFBDst + (dwDstLeft*2) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*2) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+
+// 24 to X bit
+void __cdecl BltSolid24to8( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid24to8\n"));
+  BltSolid8( pDBDst + dwDstLeft + (dwDstTop*dwPitchDBDst),
+             pDBSrc + dwSrcLeft + (dwSrcTop*dwPitchDBSrc),
+             dwWidth,
+             dwHeight,
+             dwPitchDBDst,
+             dwPitchDBSrc);
+  BltSolid24( pFBDst + (dwDstLeft*3) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*3) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+void __cdecl BltSolid24to16( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid24to16\n"));
+  BltSolid16( pDBDst + (dwDstLeft*2) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*2) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+  BltSolid24( pFBDst + (dwDstLeft*3) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*3) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+void __cdecl BltSolid24to32( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             )
+{
+  dprintf(("DDRAW:BltSolid24to32\n"));
+  BltSolid32( pDBDst + (dwDstLeft*4) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*4) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+  BltSolid24( pFBDst + (dwDstLeft*3) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*3) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+
+// 32 to X bit
+void __cdecl BltSolid32to8( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid32to8\n"));
+  BltSolid8( pDBDst + dwDstLeft + (dwDstTop*dwPitchDBDst),
+             pDBSrc + dwSrcLeft + (dwSrcTop*dwPitchDBSrc),
+             dwWidth,
+             dwHeight,
+             dwPitchDBDst,
+             dwPitchDBSrc);
+  BltSolid32( pFBDst + (dwDstLeft*4) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*4) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+void __cdecl BltSolid32to16( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             )
+{
+  dprintf(("DDRAW:BltSolid32to16\n"));
+  BltSolid16( pDBDst + (dwDstLeft*2) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*2) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+  BltSolid32( pFBDst + (dwDstLeft*4) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*4) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+
+void __cdecl BltSolid32to24( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                            )
+{
+  dprintf(("DDRAW:BltSolid32to24\n"));
+  BltSolid24( pDBDst + (dwDstLeft*3) + (dwDstTop*dwPitchDBDst),
+              pDBSrc + (dwSrcLeft*3) + (dwSrcTop*dwPitchDBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchDBDst,
+              dwPitchDBSrc);
+  BltSolid32( pFBDst + (dwDstLeft*4) + (dwDstTop*dwPitchFBDst),
+              pFBSrc + (dwSrcLeft*4) + (dwSrcTop*dwPitchFBSrc),
+              dwWidth,
+              dwHeight,
+              dwPitchFBDst,
+              dwPitchFBSrc);
+}
+
Index: trunk/src/ddraw/new/bltFunc.h
===================================================================
--- trunk/src/ddraw/new/bltFunc.h	(revision 3345)
+++ trunk/src/ddraw/new/bltFunc.h	(revision 3345)
@@ -0,0 +1,266 @@
+/* $Id: bltFunc.h,v 1.1 2000-04-07 18:21:10 mike Exp $ */
+
+/*
+ * Blitting functions definitions
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+
+// without ColorConversion
+extern void __cdecl BltSolid8to8( char *pDBDst,
+                                 char *pFBDst,
+                                 DWORD dwDstTop,
+                                 DWORD dwDstLeft,
+                                 DWORD dwPitchDBDst,
+                                 DWORD dwPitchFBDst,
+                                 char *pDBSrc,
+                                 char *pFBSrc,
+                                 DWORD dwSrcTop,
+                                 DWORD dwSrcLeft,
+                                 DWORD dwWidth,
+                                 DWORD dwHeight,
+                                 DWORD dwPitchDBSrc,
+                                 DWORD dwPitchFBSrc
+                                 );
+extern void __cdecl BltSolid16to16( char *pDBDst,
+                                   char *pFBDst,
+                                   DWORD dwDstTop,
+                                   DWORD dwDstLeft,
+                                   DWORD dwPitchDBDst,
+                                   DWORD dwPitchFBDst,
+                                   char *pDBSrc,
+                                   char *pFBSrc,
+                                   DWORD dwSrcTop,
+                                   DWORD dwSrcLeft,
+                                   DWORD dwWidth,
+                                   DWORD dwHeight,
+                                   DWORD dwPitchDBSrc,
+                                   DWORD dwPitchFBSrc
+                                   );
+extern void __cdecl BltSolid24to24( char *pDBDst,
+                                   char *pFBDst,
+                                   DWORD dwDstTop,
+                                   DWORD dwDstLeft,
+                                   DWORD dwPitchDBDst,
+                                   DWORD dwPitchFBDst,
+                                   char *pDBSrc,
+                                   char *pFBSrc,
+                                   DWORD dwSrcTop,
+                                   DWORD dwSrcLeft,
+                                   DWORD dwWidth,
+                                   DWORD dwHeight,
+                                   DWORD dwPitchDBSrc,
+                                   DWORD dwPitchFBSrc
+                                   );
+extern void __cdecl BltSolid32to32( char *pDBDst,
+                                   char *pFBDst,
+                                   DWORD dwDstTop,
+                                   DWORD dwDstLeft,
+                                   DWORD dwPitchDBDst,
+                                   DWORD dwPitchFBDst,
+                                   char *pDBSrc,
+                                   char *pFBSrc,
+                                   DWORD dwSrcTop,
+                                   DWORD dwSrcLeft,
+                                   DWORD dwWidth,
+                                   DWORD dwHeight,
+                                   DWORD dwPitchDBSrc,
+                                   DWORD dwPitchFBSrc
+                                   );
+
+void __cdecl BltSolid8to16( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid8to24( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid8to32( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid16to8( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid16to24( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid16to32( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             );
+
+void __cdecl BltSolid24to8( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid24to16( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid24to32( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             );
+
+void __cdecl BltSolid32to8( char *pDBDst,
+                            char *pFBDst,
+                            DWORD dwDstTop,
+                            DWORD dwDstLeft,
+                            DWORD dwPitchDBDst,
+                            DWORD dwPitchFBDst,
+                            char *pDBSrc,
+                            char *pFBSrc,
+                            DWORD dwSrcTop,
+                            DWORD dwSrcLeft,
+                            DWORD dwWidth,
+                            DWORD dwHeight,
+                            DWORD dwPitchDBSrc,
+                            DWORD dwPitchFBSrc
+                            );
+
+void __cdecl BltSolid32to16( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                             );
+
+void __cdecl BltSolid32to24( char *pDBDst,
+                             char *pFBDst,
+                             DWORD dwDstTop,
+                             DWORD dwDstLeft,
+                             DWORD dwPitchDBDst,
+                             DWORD dwPitchFBDst,
+                             char *pDBSrc,
+                             char *pFBSrc,
+                             DWORD dwSrcTop,
+                             DWORD dwSrcLeft,
+                             DWORD dwWidth,
+                             DWORD dwHeight,
+                             DWORD dwPitchDBSrc,
+                             DWORD dwPitchFBSrc
+                            );
+
Index: trunk/src/ddraw/new/cio2.h
===================================================================
--- trunk/src/ddraw/new/cio2.h	(revision 3345)
+++ trunk/src/ddraw/new/cio2.h	(revision 3345)
@@ -0,0 +1,24 @@
+/* Copyright (C) 1995 by Holger Veit (Holger.Veit@gmd.de) */
+/* Use at your own risk! No Warranty! The author is not responsible for
+ * any damage or loss of data caused by proper or improper use of this
+ * device driver.
+ */
+
+#ifndef _CIO2_H_
+#define _CIO2_H_
+
+extern "C"
+{
+ int io_init1();
+ int io_init2(short);
+ int io_exit1();
+
+ char c_inb1(short);
+ short c_inw1(short);
+ long c_inl1(short);
+ void c_outb1(short,char);
+ void c_outw1(short,short);
+ void c_outl1(short,long);
+ int psw();
+}
+#endif
Index: trunk/src/ddraw/new/colorconv.cpp
===================================================================
--- trunk/src/ddraw/new/colorconv.cpp	(revision 3345)
+++ trunk/src/ddraw/new/colorconv.cpp	(revision 3345)
@@ -0,0 +1,350 @@
+/* $Id: colorconv.cpp,v 1.1 2000-04-07 18:21:10 mike Exp $ */
+
+/*
+ * ColorConversion routines
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <memory.h>
+#include <misc.h>
+#include "colorconv.h"
+
+ void __cdecl Conv8to16( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        )
+{
+  char *pSrcLine, *pDstLine;
+
+  dprintf(("DDRAW: Conv8to16(%d,%d ,%d,%d)\n",dwTop,dwLeft,dwWidth,dwHeight));
+
+  pSrcLine = pFB + (dwTop*dwPitchDB) + dwLeft;
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*2);
+
+  for(;dwHeight;dwHeight--)
+  {
+    for(int x=0;x<dwWidth;x++)
+    {
+      *(((WORD*)pDstLine)+x) = ((WORD*)pPalette)[pSrcLine[x]];
+
+    }
+    pSrcLine += dwPitchFB;
+    pDstLine += dwPitchDB;
+  }
+}
+
+ void __cdecl Conv8to24( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        )
+{
+  char *pSrcLine, *pDstLine;
+
+  dprintf(("DDRAW: Conv8to24\n"));
+
+  pSrcLine = pFB + (dwTop*dwPitchDB) + dwLeft;
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*3);
+
+  for(;dwHeight;dwHeight--)
+  {
+    char *pIter;
+    pIter=pDstLine;
+    for(int x=0;x<dwWidth;x++)
+    {
+      *((DWORD*)pIter) = ((DWORD*)pPalette)[pSrcLine[x]];
+      pIter+=3;
+    }
+    pSrcLine += dwPitchFB;
+    pDstLine += dwPitchDB;
+  }
+}
+ void __cdecl Conv8to32( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        )
+{
+  char *pSrcLine, *pDstLine;
+
+  dprintf(("DDRAW: Conv8to32\n"));
+
+  pSrcLine = pFB + (dwTop*dwPitchDB) + dwLeft;
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*4);
+
+  for(;dwHeight;dwHeight--)
+  {
+    for(int x=0;x<dwWidth;x++)
+    {
+      *(((DWORD*)pDstLine)+x) = ((DWORD*)pPalette)[pSrcLine[x]];
+
+    }
+    pSrcLine += dwPitchFB;
+    pDstLine += dwPitchDB;
+  }
+}
+
+ void __cdecl Conv16to8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        )
+{
+  dprintf(("DDRAW: Conv16to8 Not Implemented\n"));
+}
+
+ void __cdecl Conv16to24( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                        )
+{
+  WORD *pSrcLine;
+  char *pDstLine;
+
+  dprintf(("DDRAW: Conv16to24 (assuming R565) \n"));
+
+  pSrcLine = (WORD*)(pFB + (dwTop*dwPitchDB) + (dwLeft*2));
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*3);
+
+  for(;dwHeight;dwHeight--)
+  {
+    char *pIter;
+    pIter=pDstLine;
+    for(int x=0;x<dwWidth;x++)
+    {
+      *((DWORD*)pIter) = ((pSrcLine[x] & 0xF800)<< 16) +
+                         ((pSrcLine[x] & 0x07E0)<< 13) +
+                         ((pSrcLine[x] & 0x001F)<< 11);
+      pIter+=3;
+    }
+    pSrcLine = (WORD*)((char*)pSrcLine +dwPitchFB);
+    pDstLine += dwPitchDB;
+  }
+
+}
+ void __cdecl Conv16to32( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                         )
+{
+  WORD *pSrcLine;
+  char *pDstLine;
+
+  dprintf(("DDRAW: Conv16to32 (assuming R565) \n"));
+
+  pSrcLine = (WORD*)(pFB + (dwTop*dwPitchDB) + (dwLeft*2));
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*4);
+
+  for(;dwHeight;dwHeight--)
+  {
+
+    for(int x=0;x<dwWidth;x++)
+    {
+      *(((DWORD*)pDstLine)+x) = ((pSrcLine[x] & 0xF800)<< 16) +
+                                ((pSrcLine[x] & 0x07E0)<< 13) +
+                                ((pSrcLine[x] & 0x001F)<< 11);
+    }
+    pSrcLine = (WORD*)((char*)pSrcLine + dwPitchFB);
+    pDstLine += dwPitchDB;
+  }
+}
+
+ void __cdecl Conv24to8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        )
+{
+  dprintf(("DDRAW: Conv24to8 Not Implmented\n"));
+}
+ void __cdecl Conv24to16( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                        )
+{
+  char *pSrcLine;
+  char *pDstLine;
+
+  dprintf(("DDRAW: Conv24to16 (assuming R565) \n"));
+
+  pSrcLine = pFB + (dwTop*dwPitchDB) + (dwLeft*3);
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*2);
+
+  for(;dwHeight;dwHeight--)
+  {
+
+    for(int x=0;x<dwWidth;x++)
+    {
+      *((WORD*)pDstLine[x]) = ((pSrcLine[x*3] & 0x1F)<< 11) +
+                              ((pSrcLine[x*3+1] & 0x3F)<< 5) +
+                              ((pSrcLine[x*3+2] & 0x1F));
+    }
+    pSrcLine += dwPitchFB;
+    pDstLine += dwPitchDB;
+  }
+}
+
+ void __cdecl Conv24to32( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                         )
+{
+  char *pSrcLine;
+  char *pDstLine;
+
+
+  dprintf(("DDRAW: Conv24to32 Assuming RGBA \n"));
+
+  pSrcLine = pFB + (dwTop*dwPitchDB) + (dwLeft*3);;
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*4);
+
+  for(;dwHeight;dwHeight--)
+  {
+    char *pIter;
+    pIter=pDstLine;
+    for(int x=0;x<dwWidth;x++)
+    {
+      *((DWORD*)pDstLine[x]) = *((DWORD*)pIter) & 0xffffff00;
+      pIter +=3;
+    }
+    pSrcLine += dwPitchFB;
+    pDstLine += dwPitchDB;
+  }
+
+}
+
+ void __cdecl Conv32to8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        )
+{
+  dprintf(("DDRAW: Conv32to8 Not Implemented\n"));
+}
+ void __cdecl Conv32to16( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                        )
+{
+  DWORD *pSrcLine;
+  WORD  *pDstLine;
+
+  dprintf(("DDRAW: Conv32to16 (assuming R565) \n"));
+
+  pSrcLine = (DWORD*)(pFB + (dwTop*dwPitchDB) + (dwLeft*4));
+  pDstLine = (WORD*)(pDB + (dwTop*dwPitchFB) + (dwLeft*2));
+
+  for(;dwHeight;dwHeight--)
+  {
+
+    for(int x=0;x<dwWidth;x++)
+    {
+      pDstLine[x] = ((pSrcLine[x] & 0xF8000000) >> 16) +
+                    ((pSrcLine[x] & 0x00FE0000) >> 13) +
+                    ((pSrcLine[x] & 0x0000F800) >> 11);
+    }
+    pSrcLine = (DWORD*)((char*)pSrcLine + dwPitchFB);
+    pDstLine = (WORD*)((char*)pDstLine + dwPitchDB);
+  }
+}
+
+ void __cdecl Conv32to24( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                         )
+{
+  char *pSrcLine;
+  char *pDstLine;
+
+
+  dprintf(("DDRAW: Conv32to24 Assuming RGBA \n"));
+
+  pSrcLine = pFB + (dwTop*dwPitchDB) + (dwLeft*3);
+  pDstLine = pDB + (dwTop*dwPitchFB) + (dwLeft*4);
+
+  for(;dwHeight;dwHeight--)
+  {
+    char *pIter;
+    pIter=pDstLine;
+    for(int x=0;x<dwWidth;x++)
+    {
+      *((DWORD*)pIter[x]) = *((DWORD*)pSrcLine[x]);
+      pIter +=3;
+    }
+    pSrcLine += dwPitchFB;
+    pDstLine += dwPitchDB;
+  }
+
+}
+
Index: trunk/src/ddraw/new/colorconv.h
===================================================================
--- trunk/src/ddraw/new/colorconv.h	(revision 3345)
+++ trunk/src/ddraw/new/colorconv.h	(revision 3345)
@@ -0,0 +1,136 @@
+/* $Id: colorconv.h,v 1.1 2000-04-07 18:21:10 mike Exp $ */
+
+/*
+ * ColorConversion definitions
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+
+ extern void __cdecl Conv8to16( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        );
+
+ extern void __cdecl Conv8to24( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        );
+ extern void __cdecl Conv8to32( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        );
+
+ extern void __cdecl Conv16to8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        );
+
+ extern void __cdecl Conv16to24( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                        );
+ extern void __cdecl Conv16to32( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                         );
+ extern void __cdecl Conv24to8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        );
+ extern void __cdecl Conv24to16( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                        );
+ extern void __cdecl Conv24to32( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                         );
+ extern void __cdecl Conv32to8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         VOID  *pPalette
+                        );
+ extern void __cdecl Conv32to16( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                        );
+ extern void __cdecl Conv32to24( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          VOID  *pPalette
+                         );
+
Index: trunk/src/ddraw/new/ddraw.CPP
===================================================================
--- trunk/src/ddraw/new/ddraw.CPP	(revision 3345)
+++ trunk/src/ddraw/new/ddraw.CPP	(revision 3345)
@@ -0,0 +1,270 @@
+/* $Id: ddraw.CPP,v 1.1 2000-04-07 18:21:11 mike Exp $ */
+
+/*
+ * DXDraw DLL implementaion
+ *
+ * Copyright 1998 Sander va Leeuwen
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <memory.h>
+#include <stdio.h>
+#include <builtin.h>
+#define INITGUID
+#define ICOM_CINTERFACE 1
+#define CINTERFACE
+
+#include "os2ddraw.h"
+#include "winerror.h"
+// define the following as we include winnt.h
+#define _OS2WIN_H
+#define FAR
+
+#include <misc.h>
+
+//******************************************************************************
+//******************************************************************************
+HRESULT WIN32API OS2DirectDrawCreate( GUID FAR *lpGUID,
+                                      LPDIRECTDRAW FAR *lplpDD,
+                                      IUnknown FAR *pUnkOuter)
+{
+  OS2IDirectDraw *newdraw;
+  HRESULT         rc;
+
+  dprintf(("DDRAW: DirectDrawCreate %X %X %X\n", lpGUID, lplpDD, pUnkOuter));
+
+  newdraw = new OS2IDirectDraw(lpGUID);
+
+  if(newdraw == NULL)
+  {
+    rc = DDERR_NODIRECTDRAWHW;
+  }
+  else
+  {
+    newdraw->Vtbl.AddRef((IDirectDraw2 *)newdraw);
+    rc = newdraw->GetLastError();
+    if(rc != DD_OK)
+    {
+      *lplpDD = NULL;
+
+      delete newdraw;
+    }
+    else
+      *lplpDD = (LPDIRECTDRAW)newdraw;
+  }
+  return(rc);
+}
+//******************************************************************************
+typedef BOOL (FAR PASCAL * LPDDENUMCALLBACKA)(GUID FAR *, LPSTR, LPSTR, LPVOID);
+//******************************************************************************
+HRESULT WIN32API OS2DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback,
+               LPVOID lpContext)
+{
+  dprintf(("DDRAW: DirectDrawEnumerateA\n Callback for DIVE\n"));
+  //call it twice for the DirectDraw & Direct3D classes
+ if(lpCallback(NULL, "DIVE DirectDraw for OS/2",
+                "DirectDraw/2 v0.2", lpContext) == DDENUMRET_CANCEL)
+  {
+    dprintf(("DDRAW: Cancel Callback\n"));
+    return(DD_OK);
+  }
+  else //now for Direct3D
+  {
+    dprintf(("DDRAW: Callback for 3Dfx Voodoo"));
+    if(lpCallback((GUID *)&IID_IDirect3D, "3Dfx Voodoo Direct3D/2",
+      "Direct3D/2 v0.2", lpContext) == DDENUMRET_CANCEL)
+    {
+      dprintf(("DDRAW: Cancel Callback\n"));
+      return(DD_OK);
+    }
+  }
+  dprintf(("DDRAW: Done Enumeration\n\n"));
+
+  return(DD_OK);
+}
+
+//******************************************************************************
+typedef struct
+{
+  LPDDENUMCALLBACKEXA lpCallbackEx;
+  LPVOID lpContext;
+} ENUMDATA, *PENUMDATA;
+
+BOOL FAR PASCAL SimpleEnum ( GUID FAR *lpGUID,
+                             LPSTR  lpDriverDescription,
+                             LPSTR  lpDriverName,
+                             LPVOID lpContext)
+{
+  BOOL rc;
+  PENUMDATA pData;
+
+  dprintf(("DDRAW: SimpleEnum\n"));
+
+  pData = (PENUMDATA)lpContext;
+  rc = pData->lpCallbackEx( lpGUID,
+                            lpDriverDescription,
+                            lpDriverName,
+                            pData->lpContext,
+                            NULL);
+
+  dprintf(("DDRAW: Callback returned\n"));
+  return rc;
+}
+
+//******************************************************************************
+HRESULT WIN32API OS2DirectDrawEnumerateExA( LPDDENUMCALLBACKEXA lpCallbackEx,
+                                            LPVOID lpContext,
+                                            DWORD dwFlags)
+{
+  ENUMDATA data;
+
+  dprintf(("DDRAW: DirectDrawEnumerateExA\n"));
+
+  data.lpCallbackEx = lpCallbackEx;
+  data.lpContext    = lpContext;
+
+   OS2DirectDrawEnumerateA( SimpleEnum,
+                            &data);
+  return (DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+DWORD WIN32API DDHAL32_VidMemFree(DWORD address)
+{
+  dprintf(("DDRAW: DDHAL32_VidMemFree, not supported\n"));
+  return(0);
+}
+//******************************************************************************
+//******************************************************************************
+DWORD WIN32API DDHAL32_VidMemAlloc(DWORD size)
+{
+  dprintf(("DDRAW: DDHAL32_VidMemAlloc, not supported\n"));
+  return(0);
+}
+//******************************************************************************
+
+/*******************************************************************************
+ * DirectDraw ClassFactory
+ *
+ */
+
+typedef struct
+{
+    /* IUnknown fields */
+    ICOM_VTABLE(IClassFactory) *lpvtbl;
+    DWORD                       ref;
+} IClassFactoryImpl;
+
+static HRESULT WINAPI
+DDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+  char buf[80];
+
+  if (HIWORD(riid))
+    WINE_StringFromCLSID(riid,buf);
+  else
+    sprintf(buf,"<guid-0x%04x>",LOWORD(riid));
+  dprintf(("DDRAW:(%p)->(%s,%p),stub!\n",This,buf,ppobj));
+  return E_NOINTERFACE;
+}
+
+static ULONG WINAPI
+DDCF_AddRef(LPCLASSFACTORY iface)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+  return ++(This->ref);
+}
+
+static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+  /* static class, won't be  freed */
+  return --(This->ref);
+}
+
+static HRESULT WINAPI DDCF_CreateInstance( LPCLASSFACTORY iface,
+                                           LPUNKNOWN pOuter,
+                                           REFIID riid,
+                                           LPVOID *ppobj)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+  LPGUID lpGUID;
+  lpGUID = (LPGUID) riid;
+
+  dprintf(("DDRAW:DDCF_CreateInstance\n"));
+  if( lpGUID &&
+      ( (*lpGUID == IID_IDirectDraw ) ||
+        (*lpGUID == IID_IDirectDraw2) ||
+        (*lpGUID == IID_IDirectDraw4))
+    )
+  {
+    /* FIXME: reuse already created DirectDraw if present? */
+    return OS2DirectDrawCreate(lpGUID,(LPDIRECTDRAW*)ppobj,pOuter);
+  }
+  return E_NOINTERFACE;
+}
+
+static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+  dprintf(("DDRAW:(%p)->(%d),stub!\n",This,dolock));
+  return S_OK;
+}
+
+static ICOM_VTABLE(IClassFactory) DDCF_Vtbl =
+{
+  DDCF_QueryInterface,
+  DDCF_AddRef,
+  DDCF_Release,
+  DDCF_CreateInstance,
+  DDCF_LockServer
+};
+
+static IClassFactoryImpl DDRAW_CF = {&DDCF_Vtbl, 1 };
+
+
+HRESULT WINAPI DllGetClassObject( REFCLSID rclsid,
+                                  REFIID riid,
+                                  LPVOID *ppv)
+{
+  char buf[80],xbuf[80];
+
+  if (HIWORD(rclsid))
+    WINE_StringFromCLSID(rclsid,xbuf);
+  else
+    sprintf(xbuf,"<guid-0x%04x>",LOWORD(rclsid));
+  if (HIWORD(riid))
+    WINE_StringFromCLSID(riid,buf);
+  else
+    sprintf(buf,"<guid-0x%04x>",LOWORD(riid));
+  WINE_StringFromCLSID(riid,xbuf);
+
+  dprintf(("DDRAW:(%p,%p,%p)\n", xbuf, buf, ppv));
+  if (!memcmp(riid,&IID_IClassFactory,sizeof(IID_IClassFactory)))
+  {
+    *ppv = (LPVOID)&DDRAW_CF;
+    DDRAW_CF.lpvtbl->AddRef((IClassFactory*)&DDRAW_CF);
+    return S_OK;
+  }
+  dprintf(("DDRAW: (%p,%p,%p): no interface found.\n", xbuf, buf, ppv));
+  return E_NOINTERFACE;
+}
+
+
+/*******************************************************************************
+ * DllCanUnloadNow [DDRAW.12]  Determines whether the DLL is in use.
+ *
+ * RETURNS
+ *    Success: S_OK
+ *    Failure: S_FALSE
+ */
+HRESULT WINAPI DllCanUnloadNow(void)
+{
+  dprintf(("DllCanUnloadNow(void) stub\n"));
+  return S_FALSE;
+}//******************************************************************************
+
Index: trunk/src/ddraw/new/ddraw.DEF
===================================================================
--- trunk/src/ddraw/new/ddraw.DEF	(revision 3345)
+++ trunk/src/ddraw/new/ddraw.DEF	(revision 3345)
@@ -0,0 +1,51 @@
+; $Id: ddraw.DEF,v 1.1 2000-04-07 18:21:11 mike Exp $
+
+;
+; Based on Windows 98 DirectX7: DDRAW.DLL
+;
+LIBRARY DDRAW INITINSTANCE TERMINSTANCE
+PROTMODE
+DATA MULTIPLE NONSHARED READWRITE LOADONCALL
+CODE LOADONCALL
+
+IMPORTS
+    _GpiEnableYInversion       = PMGPI.723
+    _GpiQueryDCData            = PMGPI.665
+
+EXPORTS
+; AcquireDDThreadLock           @1
+; D3DParseUnknownCommand          @2
+; DDGetAttachedSurfaceLcl         @3
+ DDHAL32_VidMemFree = _DDHAL32_VidMemFree@4         @4
+ DDHAL32_VidMemAlloc    = _DDHAL32_VidMemAlloc@4        @5
+; DDInternalLock            @6
+; DDInternalUnlock            @7
+; DSoundHelp              @8
+ DirectDrawCreate       = _OS2DirectDrawCreate@12         @9
+; DirectDrawCreateClipper         @10
+; DirectDrawCreateEx            @11
+ DirectDrawEnumerateA   = _OS2DirectDrawEnumerateA@8      @12
+ DirectDrawEnumerateExA   = _OS2DirectDrawEnumerateExA@12     @13
+; DirectDrawEnumerateExW          @14
+; DirectDrawEnumerateW            @15
+DllCanUnloadNow   = _DllCanUnloadNow@0                      @16
+DllGetClassObject = _DllGetClassObject@12                    @17
+; GetAliasedVidMem            @18
+; GetDDSurfaceLocal           @19
+; GetNextMipMap             @20
+; GetOLEThunkData           @21
+; GetSurfaceFromDC            @22
+; HeapVidMemAllocAligned          @23
+; InternalLock              @24
+; InternalUnlock            @25
+; LateAllocateSurfaceMem          @26
+; RegisterSpecialCase           @27
+; ReleaseDDThreadLock           @28
+; VidMemAlloc             @29
+; VidMemAmountFree            @30
+; VidMemFini              @31
+; VidMemFree              @32
+; VidMemInit              @33
+; VidMemLargestFree           @34
+; thk1632_ThunkData32           @35
+; thk3216_ThunkData32           @36
Index: trunk/src/ddraw/new/ddrawrsrc.orc
===================================================================
--- trunk/src/ddraw/new/ddrawrsrc.orc	(revision 3345)
+++ trunk/src/ddraw/new/ddrawrsrc.orc	(revision 3345)
@@ -0,0 +1,41 @@
+/* $Id: ddrawrsrc.orc,v 1.1 2000-04-07 18:21:11 mike Exp $ */
+
+#include "winuser.h"
+#include "odinrsrc.h"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version (based on NT 4 SP3)
+//
+
+1 VERSIONINFO
+ FILEVERSION 4,07,00,0700
+ PRODUCTVERSION 4,07,00,0700
+ FILEFLAGSMASK 0x3fL
+ FILEFLAGS 0xaL
+ FILEOS 0x10001L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904E4"
+        BEGIN
+            VALUE "Comments", "Odin32 System Dll\0"
+            VALUE "CompanyName", "Odin Team\0"
+            VALUE "FileDescription", "DDRAW System dll\0"
+            VALUE "FileVersion", "4.07.00.0700\0"
+            VALUE "InternalName", "DDRAW\0"
+            VALUE "LegalCopyright", "Copyright (C) 1999-2000\0"
+            VALUE "LegalTrademarks", "\0"
+            VALUE "OriginalFilename", "DDRAW.DLL\0"
+            VALUE "ProductName", "Odin32 - DDRAW\0"
+            VALUE "ProductVersion", "4.07.00.0700\0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 0x04E4
+    END
+END
Index: trunk/src/ddraw/new/dive.h
===================================================================
--- trunk/src/ddraw/new/dive.h	(revision 3345)
+++ trunk/src/ddraw/new/dive.h	(revision 3345)
@@ -0,0 +1,384 @@
+/***************************************************************************\
+*
+* Module Name: DIVE.H
+*
+* OS/2 2.1 Multimedia Extensions Display Engine API data structures
+*
+* Copyright (c) International Business Machines Corporation 1993, 1994
+*                         All Rights Reserved
+*
+*
+\****************************************************************************/
+#ifdef __cplusplus
+   extern "C" {
+#endif
+
+#ifndef _DIVE_H_
+#define _DIVE_H_
+
+#define MAX_DIVE_INSTANCES    64
+
+#define FOURCC ULONG
+#define HDIVE ULONG
+
+#define DIVE_SUCCESS                                     0x00000000
+#define DIVE_ERR_INVALID_INSTANCE                        0x00001000
+#define DIVE_ERR_SOURCE_FORMAT                           0x00001001
+#define DIVE_ERR_DESTINATION_FORMAT                      0x00001002
+#define DIVE_ERR_BLITTER_NOT_SETUP                       0x00001003
+#define DIVE_ERR_INSUFFICIENT_LENGTH                     0x00001004
+#define DIVE_ERR_TOO_MANY_INSTANCES                      0x00001005
+#define DIVE_ERR_NO_DIRECT_ACCESS                        0x00001006
+#define DIVE_ERR_NOT_BANK_SWITCHED                       0x00001007
+#define DIVE_ERR_INVALID_BANK_NUMBER                     0x00001008
+#define DIVE_ERR_FB_NOT_ACQUIRED                         0x00001009
+#define DIVE_ERR_FB_ALREADY_ACQUIRED                     0x0000100a
+#define DIVE_ERR_ACQUIRE_FAILED                          0x0000100b
+#define DIVE_ERR_BANK_SWITCH_FAILED                      0x0000100c
+#define DIVE_ERR_DEACQUIRE_FAILED                        0x0000100d
+#define DIVE_ERR_INVALID_PALETTE                         0x0000100e
+#define DIVE_ERR_INVALID_DESTINATION_RECTL               0x0000100f
+#define DIVE_ERR_INVALID_BUFFER_NUMBER                   0x00001010
+#define DIVE_ERR_SSMDD_NOT_INSTALLED                     0x00001011
+#define DIVE_ERR_BUFFER_ALREADY_ACCESSED                 0x00001012
+#define DIVE_ERR_BUFFER_NOT_ACCESSED                     0x00001013
+#define DIVE_ERR_TOO_MANY_BUFFERS                        0x00001014
+#define DIVE_ERR_ALLOCATION_ERROR                        0x00001015
+#define DIVE_ERR_INVALID_LINESIZE                        0x00001016
+#define DIVE_ERR_FATAL_EXCEPTION                         0x00001017
+#define DIVE_ERR_INVALID_CONVERSION                      0x00001018
+#define DIVE_ERR_VSD_ERROR                               0x00001019
+#define DIVE_ERR_COLOR_SUPPORT                           0x0000101a
+#define DIVE_ERR_OUT_OF_RANGE                            0x0000101b
+#define DIVE_WARN_NO_SIZE                                0x00001100
+
+#define DIVE_BUFFER_SCREEN                               0x00000000
+#define DIVE_BUFFER_GRAPHICS_PLANE                       0x00000001
+#define DIVE_BUFFER_ALTERNATE_PLANE                      0x00000002
+
+#define DIVE_FULLY_VISIBLE                               0xffffffff
+
+
+/* Notes:
+      Associated/Allocated memory buffers start at:      0x00000010
+
+      Specifing DIVE_BUFFER_GRAPHICS_PLANE results in the image being
+            transferred to the graphics plane.
+      Specifing DIVE_BUFFER_ALTERNATE_PLANE results in the image being
+            transferred to the alternate (e.g. overlay) plane.  If your
+            hardware doesn't support such a plane, this is an error.
+      Specifing DIVE_BUFFER_SCREEN will result in the image being
+            transferred to either the graphics plane buffer or the alternate
+            plane buffer based on if an alternate buffer exists and based on
+            the suitability the overlay plane to accelerate the scaling of
+            the image.  If DIVE chooses to use the alternate buffer, it
+            will also paint the overlay "key" color on the graphics plane.
+            This automatic painting does not occur if the alternate plane
+            is explicitly specified.
+*/
+
+
+
+typedef struct _DIVE_CAPS {
+
+   ULONG  ulStructLen;            /* Set equal to sizeof(DIVE_CAPS)          */
+   ULONG  ulPlaneCount;           /* Number of defined planes.               */
+
+   /* Info returned in the following fields pertains to ulPlaneID.           */
+   BOOL   fScreenDirect;          /* TRUE if can get addressability to vram. */
+   BOOL   fBankSwitched;          /* TRUE if vram is bank-switched.          */
+   ULONG  ulDepth;                /* Number of bits per pixel.               */
+   ULONG  ulHorizontalResolution; /* Screen width in pixels.                 */
+   ULONG  ulVerticalResolution;   /* Screen height in pixels.                */
+   ULONG  ulScanLineBytes;        /* Screen scan line size in bytes.         */
+   FOURCC fccColorEncoding;       /* Colorspace encoding of the screen.      */
+   ULONG  ulApertureSize;         /* Size of vram aperture in bytes.         */
+
+   ULONG  ulInputFormats;         /* Number of input color formats.          */
+   ULONG  ulOutputFormats;        /* Number of output color formats.         */
+   ULONG  ulFormatLength;         /* Length of format buffer.                */
+   PVOID  pFormatData;            /* Pointer to color format buffer FOURCC's.*/
+
+   } DIVE_CAPS;
+typedef DIVE_CAPS *PDIVE_CAPS;
+
+
+
+
+typedef struct _SETUP_BLITTER {
+
+     /* Set the ulStructLen field equal to the amount of the structure used. */
+     /* allowable: blank lines below mark sizes of 8, 28, 32, 52, 60, or 68. */
+   ULONG  ulStructLen;
+     /* Set the ulInvert flags based on the following:                       */
+     /* b0001 = d01 = h01 = flip the image in the horizontal direction.      */
+     /* b0010 = d02 = h02 = flip the image in the vertical direction.        */
+     /* All other bits ignored.                                              */
+   ULONG  fInvert;
+
+     /* This is the color format of the source data.  See "FOURCC.H"         */
+   FOURCC fccSrcColorFormat;
+     /* This is the width of the source image in pixels.                     */
+   ULONG  ulSrcWidth;
+     /* This is the height of the source image in pixels.                    */
+   ULONG  ulSrcHeight;
+     /* This is the horizontal offset from which to start displaying for     */
+     /* use in displaying a sub-portion of the source image.                 */
+   ULONG  ulSrcPosX;
+     /* This is the vertical offset from which to start displaying.          */
+   ULONG  ulSrcPosY;
+
+     /* This is the dither type to use.  0 defines no dither and 1           */
+     /* defines 2x2 dither (all others ignored).  Note: dithering is only    */
+     /* supported in direct color to LUT8 conversions.                       */
+   ULONG  ulDitherType;
+
+     /* This is the color format of the destinaion data.  See "FOURCC.H"     */
+   FOURCC fccDstColorFormat;
+     /* This is the width of the destination image in pixels.                */
+   ULONG  ulDstWidth;
+     /* This is the height of the destination image in pixels.               */
+   ULONG  ulDstHeight;
+     /* This is the horizontal offset from which to start displaying for     */
+     /* use in displaying to sub-portion of the destination image.           */
+   LONG   lDstPosX;
+     /* This is the vertical offset from which to start displaying.          */
+   LONG   lDstPosY;
+
+     /* This is the world screen horizontal position, where 0 is left.       */
+     /* These are ignored if the destination is not the screen.              */
+   LONG   lScreenPosX;
+     /* This is the world screen vertical position, where 0 is bottom.       */
+   LONG   lScreenPosY;
+
+     /* This is the number of visible rectangular regions being passed in.   */
+     /* These are ignored if the destination is not the screen.              */
+     /* Also, if you application *KNOWS* that the region is fully visible    */
+     /* (like not going to the screen), the you can use DIVE_FULLY_VISIBLE   */
+     /* instead of making up a bogus visible region structure.               */
+   ULONG  ulNumDstRects;
+     /* This points to an array of visible regions which defines what        */
+     /* portions of the source image are to be displayed.                    */
+   PRECTL pVisDstRects;           /* Pointer to array of visible rectangles. */
+
+   } SETUP_BLITTER;
+typedef SETUP_BLITTER *PSETUP_BLITTER;
+
+
+
+ULONG APIENTRY DiveQueryCaps ( PDIVE_CAPS pDiveCaps,
+                               ULONG      ulPlaneBufNum );
+
+ULONG APIENTRY DiveOpen ( HDIVE *phDiveInst,
+                          BOOL   fNonScreenInstance,
+                          PVOID  ppFrameBuffer );
+
+ULONG APIENTRY DiveSetupBlitter ( HDIVE          hDiveInst,
+                                  PSETUP_BLITTER pSetupBlitter );
+
+ULONG APIENTRY DiveBlitImage ( HDIVE hDiveInst,
+                               ULONG ulSrcBufNumber,
+                               ULONG ulDstBufNumber );
+
+#ifdef INCL_MM_OS2
+/* Same as DiveBlitImage, except pbLineMask points to one byte per line      */
+/* in source image buffer such that 0: unchanged, 0xFF: changed              */
+ULONG APIENTRY DiveBlitImageLines ( HDIVE hDiveInst,
+                                    ULONG ulSrcBufNumber,
+                                    ULONG ulDstBufNumber,
+                                    PBYTE pbLineMask );
+#endif
+
+ULONG APIENTRY DiveClose ( HDIVE hDiveInst );
+
+ULONG APIENTRY DiveAcquireFrameBuffer ( HDIVE   hDiveInst,
+                                        PRECTL  prectlDst );
+
+ULONG APIENTRY DiveSwitchBank ( HDIVE hDiveInst,
+                                ULONG ulBankNumber );
+
+ULONG APIENTRY DiveDeacquireFrameBuffer ( HDIVE hDiveInst );
+
+ULONG APIENTRY DiveCalcFrameBufferAddress ( HDIVE  hDiveInst,
+                                            PRECTL prectlDest,
+                                            PBYTE *ppDestinationAddress,
+                                            PULONG pulBankNumber,
+                                            PULONG pulRemLinesInBank );
+
+/* Notes on DiveAllocImageBuffer:
+      If pbImageBuffer is not NULL, the buffer is associated rather than
+      allocated.  If pbImageBuffer is not NULL and the buffer number
+      pointed to by pulBufferNumber is non-zero, a new buffer pointer is
+      associated with the buffer number.  Even though no memory is
+      allocated by DiveAllocImageBuffer when user-allocated buffers are
+      associated, DiveFreeImageBuffer should be called to release the
+      buffer association to avoid using up available buffer indexes.
+      The specified line size will be used if a buffer is allocated in
+      system memory, or if a user buffer is associated.  If the
+      specified line size is zero, the allocated line size is rounded up
+      to the nearest DWORD boundry.
+*/
+
+ULONG APIENTRY DiveAllocImageBuffer ( HDIVE  hDiveInst,
+                                      PULONG pulBufferNumber,
+                                      FOURCC fccColorSpace,
+                                      ULONG  ulWidth,
+                                      ULONG  ulHeight,
+                                      ULONG  ulLineSizeBytes,
+                                      PBYTE  pbImageBuffer );
+
+ULONG APIENTRY DiveFreeImageBuffer ( HDIVE hDiveInst,
+                                     ULONG ulBufferNumber );
+
+ULONG APIENTRY DiveBeginImageBufferAccess ( HDIVE  hDiveInst,
+                                            ULONG  ulBufferNumber,
+                                            PBYTE *ppbImageBuffer,
+                                            PULONG pulBufferScanLineBytes,
+                                            PULONG pulBufferScanLines );
+
+ULONG APIENTRY DiveEndImageBufferAccess ( HDIVE hDiveInst,
+                                          ULONG ulBufferNumber );
+
+
+
+/* Notes on palettes:
+      Neither DiveSetSourcePalette nor DiveSetDestinationPalette API's will set
+      the physical palette.  If your application MUST set the PHYSICAL palette,
+      try using no more than 236 entries (the middle 236: 10-245, thus leaving
+      the top and bottom 10 entries for the Workplace Shell).  If your
+      application MUST use ALL 256 entries, it must do so as a full-screen
+      (i.e. maximized) application.  Remember, No WM_REALIZEPALETTE message
+      will be sent to other running applications, meaning they will not redraw
+      and their colors will be all wrong.  It is not recommended that a
+      developer use these commands:
+
+   To set physical palette, do the following:
+            hps = WinGetPS ( HWND_DESKTOP );
+            hdc = GpiQueryDevice ( hps );
+            GpiCreateLogColorTable ( hps, LCOL_PURECOLOR | LCOL_REALIZABLE,
+                           LCOLF_CONSECRGB, 0, 256, (PLONG)plRGB2Entries );
+            Gre32EntrY3 ( hdc, 0L, 0x000060C6L );
+            WinInvalidateRect ( HWND_DESKTOP, (PRECTL)NULL, TRUE );
+            WinReleasePS ( hps );
+
+   To reset physical palette, do the following:
+            hps = WinGetPS ( HWND_DESKTOP );
+            hdc = GpiQueryDevice ( hps );
+            Gre32EntrY3 ( hdc, 0L, 0x000060C7L );
+            WinInvalidateRect ( HWND_DESKTOP, (PRECTL)NULL, TRUE );
+            WinReleasePS ( hps );
+*/
+
+
+/* Use either of the two defines as the pRGB2Entries pointer to have DIVE    */
+/* query and set the physical or default palette as source or destination.   */
+
+#define DIVE_PALETTE_PHYSICAL                     (PBYTE)0x00000000
+#define DIVE_PALETTE_DEFAULT                      (PBYTE)0xffffffff
+
+ULONG APIENTRY DiveSetDestinationPalette ( HDIVE hDiveInst,
+                                           ULONG ulStartIndex,
+                                           ULONG ulNumEntries,
+                                           PBYTE pbRGB2Entries );
+
+ULONG APIENTRY DiveSetSourcePalette ( HDIVE hDiveInst,
+                                      ULONG ulStartIndex,
+                                      ULONG ulNumEntries,
+                                      PBYTE pbRGB2Entries );
+
+#ifdef INCL_MM_OS2
+ULONG APIENTRY DiveSetTransparentBlitMode ( HDIVE hDiveInst,
+                                            ULONG ulTransBlitMode,
+                                            ULONG ulValue1,
+                                            ULONG ulValue2 );
+
+/* The following transparent blitting modes are supported:                   */
+
+#define DIVE_TBM_NONE                              0x0
+/* No transparency, i.e. all pixels are transferred (default)                */
+
+#define DIVE_TBM_EXCLUDE_SOURCE_VALUE              0x01
+/* Source pixels with values that exactly match the value specified in       */
+/* ulValue1 are not transferred.                                             */
+
+#define DIVE_TBM_EXCLUDE_SOURCE_RGB_RANGE          0x02
+/* Source pixels with values that lie within the range specified in RGB      */
+/* color space specified by ulValue1 (minimum) and ulValue2 (maximum)        */
+/* are not transferred by DiveBlitImage.                                     */
+
+#define DIVE_TBM_INCLUDE_SOURCE_RGB_RANGE          0x03
+/* Source pixels with values that lie outside the range specified in RGB     */
+/* color space specified by ulValue1 (minimum) and ulValue2 (maximum)        */
+/* are not transferred by DiveBlitImage.                                     */
+
+#define DIVE_TBM_EXCLUDE_SOURCE_YUV_RANGE          0x04
+/* Source pixels with values that lie within the range specified in RGB      */
+/* color space specified by ulValue1 (minimum) and ulValue2 (maximum)        */
+/* are not transferred by DiveBlitImage.                                     */
+
+#define DIVE_TBM_INCLUDE_SOURCE_YUV_RANGE          0x05
+/* Source pixels with values that lie outside the range specified in RGB     */
+/* color space specified by ulValue1 (minimum) and ulValue2 (maximum)        */
+/* are not transferred by DiveBlitImage.                                     */
+
+/* Notes on transparent blitting:
+   Supported transparent blitting functions are all based on source pixel
+   values.  A pixel in the destination image buffer is not modified if the
+   corresponding pixel in the source buffer is "transparent".  The color
+   values or color value ranges specified in ulValue1 and ulValue2 are
+   dependent on the source image color format (fccSrcColorFormat) and the
+   color space in which the range comparison is taking place.
+
+   FOURCC_LUT8:
+      The color value is specified in the low 8 bits of parameter
+
+   FOURCC_Y888, FOURCC_Y2X2, FOURCC_Y4X4, FOURCC_YUV9, FOURCC_Y644, FOURCC_Y422:
+      23:8 - Y, 15:8 - U, 7:8 - V  (bits 31:8 ignored)
+
+   FOURCC_R565, FOURCC_R555, FOURCC_R664, FOURCC_RGB3, FOURCC_BGR3, FOURCC_RGB4,
+   FOURCC_BGR4:
+      23:8 - R, 15:8 - G, 7:8 - B  (bits 31:8 ignored)
+      R, G, and B components are specified with 8 bit significance, regardless
+      of significance in the source data.
+
+   Transparent blitting of other source image formats is not supported.
+
+   For range comparisons in RGB or YUV, the three components are compared
+   independently against the minimum and maximum values specified by the
+   ulValue1 and ulValue2 parameters respectively.  A value is considered to
+   within the specified range if all three components satisfy:
+   min <= value <= max.
+
+   For EXCLUDE_SOURCE_VALUE tranparent blitting, the specified value in
+   ulValue1 is assumed to be in the source color space as described above.
+   For range comparisons, the values specified in ulValue1 and ulValue2 are
+   assumed to be in the color space in which the range comparison is to be
+   performed, either YUV or RGB.
+
+   - For range comparisons in YUV where the source data format is a YUV
+     form, the values in ulValue1 and ulValue2 are in the source YUV
+     format.
+
+   - For range comparisons in YUV where the source data format is RGB,
+     conversion of source data format from RGB to YUV using standard
+     CCIR601 equations is assumed (refer to fourcc.h).
+
+   - For range comparisons in RGB where the source data format is an RGB
+     form, the values in ulValue1 and ulValue2 specify the RGB range with
+     5 bits significance in R, 6 bits in G, and 5 bits in B.
+
+   - For range comparisons in RGB where the source data format is YUV,
+     conversion of source data format from YUV to RGB using standard
+     CCIR601 equations is assumed (refer to fourcc.h).
+
+
+
+*/
+
+#endif
+
+#endif
+#ifdef __cplusplus
+}
+#endif
+
Index: trunk/src/ddraw/new/divewrap.h
===================================================================
--- trunk/src/ddraw/new/divewrap.h	(revision 3345)
+++ trunk/src/ddraw/new/divewrap.h	(revision 3345)
@@ -0,0 +1,278 @@
+/* $Id: divewrap.h,v 1.1 2000-04-07 18:21:12 mike Exp $ */
+
+/*
+ * Wrapper for DIVE functions calls
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+
+#ifndef __DIVEWRAP_H__
+  #define __DIVEWRAP_H__
+
+  #define INCL_MM_OS2
+  #include <os2sel.h>
+  #include <dive.h>
+
+  inline ULONG APIENTRY _DiveQueryCaps ( PDIVE_CAPS a,
+                                        ULONG      b )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveQueryCaps(a, b);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveQueryCaps
+  #define DiveQueryCaps _DiveQueryCaps
+
+  inline ULONG APIENTRY _DiveOpen ( HDIVE *a,
+                                   BOOL   b,
+                                   PVOID  c )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveOpen(a, b, c);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveOpen
+  #define DiveOpen _DiveOpen
+
+  inline ULONG APIENTRY _DiveSetupBlitter ( HDIVE          a,
+                                           PSETUP_BLITTER b )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveSetupBlitter(a, b);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveSetupBlitter
+  #define DiveSetupBlitter _DiveSetupBlitter
+
+  inline ULONG APIENTRY _DiveBlitImage ( HDIVE a,
+                                        ULONG b,
+                                        ULONG c )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveBlitImage(a, b, c);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveBlitImage
+  #define DiveBlitImage _DiveBlitImage
+
+  inline ULONG APIENTRY _DiveBlitImageLines ( HDIVE a,
+                                             ULONG b,
+                                             ULONG c,
+                                             PBYTE d )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveBlitImageLines(a, b, c, d);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveBlitImageLines
+  #define DiveBlitImageLines _DiveBlitImageLines
+
+  inline ULONG APIENTRY _DiveClose ( HDIVE a )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveClose(a);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveClose
+  #define DiveClose _DiveClose
+
+  inline ULONG APIENTRY _DiveAcquireFrameBuffer ( HDIVE   a,
+                                                 PRECTL  b )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveAcquireFrameBuffer(a, b);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveAcquireFrameBuffer
+  #define DiveAcquireFrameBuffer _DiveAcquireFrameBuffer
+
+  inline ULONG APIENTRY _DiveSwitchBank ( HDIVE a,
+                                         ULONG b )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveSwitchBank(a, b);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveSwitchBank
+  #define DiveSwitchBank _DiveSwitchBank
+
+  inline ULONG APIENTRY _DiveDeacquireFrameBuffer ( HDIVE a )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveDeacquireFrameBuffer(a);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveDeacquireFrameBuffer
+  #define DiveDeacquireFrameBuffer _DiveDeacquireFrameBuffer
+
+  inline ULONG APIENTRY _DiveCalcFrameBufferAddress ( HDIVE  a,
+                                                     PRECTL b,
+                                                     PBYTE *c,
+                                                     PULONG d,
+                                                     PULONG e )
+  {
+   ULONG yyrc;
+   USHORT sel = RestoreOS2FS();
+
+      yyrc = DiveCalcFrameBufferAddress(a, b, c, d, e);
+      SetFS(sel);
+
+      return yyrc;
+  }
+  #undef  DiveCalcFrameBufferAddress
+  #define DiveCalcFrameBufferAddress _DiveCalcFrameBufferAddress
+
+  inline ULONG APIENTRY _DiveAllocImageBuffer ( HDIVE  a,
+                                               PULONG b,
+                                               FOURCC c,
+                                               ULONG  d,
+                                               ULONG  e,
+                                               ULONG  f,
+                                               PBYTE  g )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveAllocImageBuffer(a, b, c, d, e, f, g);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveAllocImageBuffer
+  #define DiveAllocImageBuffer _DiveAllocImageBuffer
+
+  inline ULONG APIENTRY _DiveFreeImageBuffer ( HDIVE a,
+                                              ULONG b )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveFreeImageBuffer(a, b);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveFreeImageBuffer
+  #define DiveFreeImageBuffer _DiveFreeImageBuffer
+
+  inline ULONG APIENTRY _DiveBeginImageBufferAccess ( HDIVE  a,
+                                                     ULONG  b,
+                                                     PBYTE *c,
+                                                     PULONG d,
+                                                     PULONG e )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveBeginImageBufferAccess(a, b, c, d, e);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveBeginImageBufferAccess
+  #define DiveBeginImageBufferAccess _DiveBeginImageBufferAccess
+
+  inline ULONG APIENTRY _DiveEndImageBufferAccess ( HDIVE a,
+                                                   ULONG b )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveEndImageBufferAccess(a, b);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveEndImageBufferAccess
+  #define DiveEndImageBufferAccess _DiveEndImageBufferAccess
+
+  inline ULONG APIENTRY _DiveSetDestinationPalette ( HDIVE a,
+                                                    ULONG b,
+                                                    ULONG c,
+                                                    PBYTE d )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveSetDestinationPalette(a, b, c, d);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveSetDestinationPalette
+  #define DiveSetDestinationPalette _DiveSetDestinationPalette
+
+  inline ULONG APIENTRY _DiveSetSourcePalette ( HDIVE a,
+                                               ULONG b,
+                                               ULONG c,
+                                               PBYTE d )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveSetSourcePalette(a, b, c, d);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveSetSourcePalette
+  #define DiveSetSourcePalette _DiveSetSourcePalette
+
+  inline ULONG APIENTRY _DiveSetTransparentBlitMode ( HDIVE a,
+                                                     ULONG b,
+                                                     ULONG c,
+                                                     ULONG d )
+  {
+    ULONG yyrc;
+    USHORT sel = RestoreOS2FS();
+
+    yyrc = DiveSetTransparentBlitMode(a, b, c, d);
+    SetFS(sel);
+
+    return yyrc;
+  }
+  #undef  DiveSetTransparentBlitMode
+  #define DiveSetTransparentBlitMode _DiveSetTransparentBlitMode
+
+
+#endif
Index: trunk/src/ddraw/new/fillfunc.cpp
===================================================================
--- trunk/src/ddraw/new/fillfunc.cpp	(revision 3345)
+++ trunk/src/ddraw/new/fillfunc.cpp	(revision 3345)
@@ -0,0 +1,586 @@
+/* $Id: fillfunc.cpp,v 1.1 2000-04-07 18:21:12 mike Exp $ */
+
+/*
+ * ColorFill functions
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <memory.h>
+#include <misc.h>
+#include "fillfunc.h"
+
+//
+// Blt Functions
+//
+
+#ifndef USE_ASM
+void __cdecl Fill8( char* pDst,
+                    DWORD dwWidth,
+                    DWORD dwHeight,
+                    DWORD dwPitch,
+                    DWORD dwColor)
+{
+  DWORD *pColor;
+  char  *pFillPos;
+  int i;
+  dprintf(("DDRAW:Fill8 with %08X\n",dwColor));
+
+  // First Fill First row with the color
+
+  for( i=0,pColor = (DWORD*)pDst;i<(dwWidth/4);i++)
+    pColor[i] = dwColor;
+
+  if(dwWidth % 4)
+  {
+    pFillPos = (char*) (&pColor[i-1]);
+    for(i=0;i<dwWidth % 4;i++)
+      pFillPos[i] = (UCHAR) dwColor;
+  }
+
+  dwHeight--;
+
+  if(dwWidth == dwPitch)
+  {
+    // Width = Pitch => fill buffer so no need to take care of lines
+    memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
+  }
+  else
+  {
+    pFillPos = pDst+dwPitch;
+    while(dwHeight)
+    {
+      memcpy(pFillPos,pDst,dwWidth);
+      pFillPos += dwPitch;
+      dwHeight--;
+    }
+  }
+}
+void __cdecl Fill16( char* pDst,
+                     DWORD dwWidth,
+                     DWORD dwHeight,
+                     DWORD dwPitch,
+                     DWORD dwColor)
+{
+  DWORD *pColor;
+  char  *pFillPos;
+  int i;
+  dprintf(("DDRAW:Fill16 with %08X \n",dwColor));
+
+  // First Fill First row with the color
+
+  for( i=0,pColor = (DWORD*)pDst;i<(dwWidth/2);i++)
+    pColor[i] = dwColor;
+
+  if(dwWidth % 2)
+  {
+     pFillPos = (char*)(&pColor[i-1]);
+    *((USHORT*)pFillPos) = (USHORT)dwColor;
+  }
+
+  dwWidth *=2;
+  dwHeight--;
+
+  if(dwWidth == dwPitch)
+  {
+    // Width = Pitch => fill buffer so no need to take care of lines
+    memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
+  }
+  else
+  {
+    pFillPos = pDst+dwPitch;
+    while(dwHeight)
+    {
+      memcpy(pFillPos,pDst,dwWidth);
+      pFillPos += dwPitch;
+      dwHeight--;
+    }
+  }
+}
+void __cdecl Fill24( char* pDst,
+                     DWORD dwWidth,
+                     DWORD dwHeight,
+                     DWORD dwPitch,
+                     DWORD dwColor)
+{
+  DWORD *pColor;
+  char  *pFillPos;
+  int i;
+  dprintf(("DDRAW:Fill24 with %08X \n",dwColor));
+
+  // First Fill First row with the color
+
+  for(i=0 ; i<dwWidth ; i++)
+  {
+    pColor = (DWORD*)(pDst+(i*3));
+    *pColor = dwColor;
+  }
+  dwWidth *=3;
+  dwHeight--;
+
+  if(dwWidth == dwPitch)
+  {
+    // Width = Pitch => fill buffer so no need to take care of lines
+    memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
+  }
+  else
+  {
+    pFillPos = pDst+dwPitch;
+    while(dwHeight)
+    {
+      memcpy(pFillPos,pDst,dwWidth);
+      pFillPos += dwPitch;
+      dwHeight--;
+    }
+  }
+}
+
+void __cdecl Fill32( char* pDst,
+                     DWORD dwWidth,
+                     DWORD dwHeight,
+                     DWORD dwPitch,
+                     DWORD dwColor)
+{
+  DWORD *pColor;
+  char  *pFillPos;
+  int i;
+  dprintf(("DDRAW:Fill24 with %08X \n",dwColor));
+
+  // First Fill First row with the color
+
+  for(i=0 ; i<dwWidth ; i++)
+  {
+    pColor[i] = dwColor;
+  }
+  dwWidth *=4;
+  dwHeight--;
+
+  if(dwWidth == dwPitch)
+  {
+    // Width = Pitch => fill buffer so no need to take care of lines
+    memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
+  }
+  else
+  {
+    pFillPos = pDst+dwPitch;
+    while(dwHeight)
+    {
+      memcpy(pFillPos,pDst,dwWidth);
+      pFillPos += dwPitch;
+      dwHeight--;
+    }
+  }
+}
+#else
+  #define Fill8  Fill8ASM
+  #define Fill16 Fill16ASM
+  #define Fill24 Fill24ASM
+  #define Fill32 Fill32ASM
+#endif
+
+
+
+// without ColorConversion
+ void __cdecl Fill8on8( char *pDB,
+                        char *pFB,
+                        DWORD dwTop,
+                        DWORD dwLeft,
+                        DWORD dwWidth,
+                        DWORD dwHeight,
+                        DWORD dwPitchDB,
+                        DWORD dwPitchFB,
+                        DWORD dwColor,
+                        VOID  *pPalette
+                       )
+{
+  dprintf(("Fill8on8\n"));
+  dwColor = (dwColor&0xFF)+(dwColor&0xFF<<8);
+  dwColor += (dwColor<<16);
+
+  Fill8( pDB+(dwTop*dwPitchDB)+dwLeft,
+         dwWidth,
+         dwHeight,
+         dwPitchDB,
+         dwColor);
+}
+ void __cdecl Fill16on16( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                        )
+{
+  dprintf(("Fill16on16\n"));
+  dwColor = (dwColor&0xFFFF)+((dwColor&0xFFFF)<<16);
+
+  Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwColor);
+}
+ void __cdecl Fill24on24( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                         )
+{
+  dprintf(("Fill24on24\n"));
+  dwColor <<= 8;
+
+  Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwColor);
+
+}
+ void __cdecl Fill32on32( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                         )
+{
+  dprintf(("Fill32on32\n"));
+  Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwColor);
+}
+
+ void __cdecl Fill8on16( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         DWORD dwColor,
+                         VOID  *pPalette
+                        )
+{
+  DWORD dwCol;
+  dprintf(("Fill8on16\n"));
+  dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
+  dwCol += (dwCol<<16);
+
+  Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
+         dwWidth,
+         dwHeight,
+         dwPitchFB,
+         dwCol);
+
+  dwCol = ((WORD*)pPalette)[dwColor];
+  dwCol += (dwCol<<16);
+  Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwCol);
+}
+
+ void __cdecl Fill8on24( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         DWORD dwColor,
+                         VOID  *pPalette
+                        )
+{
+  DWORD dwCol;
+  dprintf(("Fill8on24\n"));
+  dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
+  dwCol += (dwCol<<16);
+
+  Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
+         dwWidth,
+         dwHeight,
+         dwPitchFB,
+         dwCol);
+
+  dwCol = ((DWORD*)pPalette)[dwColor];
+  //dwCol <<= 8;
+  Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwCol);
+}
+ void __cdecl Fill8on32( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         DWORD dwColor,
+                         VOID  *pPalette
+                        )
+{
+  DWORD dwCol;
+  dprintf(("Fill8on32\n"));
+  dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
+  dwCol += (dwCol<<16);
+
+  Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
+         dwWidth,
+         dwHeight,
+         dwPitchFB,
+         dwCol);
+
+  dwCol = ((DWORD*)pPalette)[dwColor];
+  Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwCol);
+}
+ void __cdecl Fill16on8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         DWORD dwColor,
+                         VOID  *pPalette
+                        )
+{
+  dprintf(("Fill16on8 NOT Implemented \n"));
+}
+ void __cdecl Fill16on24( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                        )
+{
+  DWORD dwCol;
+  dprintf(("Fill16on24\n"));
+  dwCol = dwColor + (dwColor<<16);
+
+  Fill16( pFB+(dwTop*dwPitchFB)+(dwLeft*2),
+          dwWidth,
+          dwHeight,
+          dwPitchFB,
+          dwCol);
+
+  dwCol = ((dwColor & 0xF800)<< 16) +
+          ((dwColor & 0x07E0)<< 13) +
+          ((dwColor & 0x001F)<< 11);
+  Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwCol);
+}
+ void __cdecl Fill16on32( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                         )
+{
+  DWORD dwCol;
+  dprintf(("Fill16on32\n"));
+  dwCol = dwColor + (dwColor<<16);
+
+  Fill16( pFB+(dwTop*dwPitchFB)+(dwLeft*2),
+          dwWidth,
+          dwHeight,
+          dwPitchFB,
+          dwCol);
+
+  dwCol = ((dwColor & 0xF800)<< 16) +
+          ((dwColor & 0x07E0)<< 13) +
+          ((dwColor & 0x001F)<< 11);
+  Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwCol);
+}
+
+ void __cdecl Fill24on8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         DWORD dwColor,
+                         VOID  *pPalette
+                        )
+{
+  dprintf(("Fill24on8 NOT implemented\n"));
+}
+ void __cdecl Fill24on16( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                        )
+{
+  DWORD dwCol;
+  dprintf(("Fill24on16\n"));
+  //dwColor <<=8;
+
+  Fill24( pFB+(dwTop*dwPitchFB)+(dwLeft*3),
+          dwWidth,
+          dwHeight,
+          dwPitchFB,
+          dwColor);
+
+  dwCol = ((dwColor & 0xF8000000) >>16) +
+          ((dwColor & 0x00FE0000)>> 13) +
+          ((dwColor & 0x0000F800)>> 11);
+
+  dwCol = dwCol + (dwCol<<16);
+  Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwCol);
+}
+ void __cdecl Fill24on32( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                         )
+{
+  dprintf(("Fill24on32\n"));
+  //dwColor <<=8;
+
+  Fill24( pFB+(dwTop*dwPitchFB)+(dwLeft*3),
+          dwWidth,
+          dwHeight,
+          dwPitchFB,
+          dwColor);
+  Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwColor);
+}
+ void __cdecl Fill32on8( char *pDB,
+                         char *pFB,
+                         DWORD dwTop,
+                         DWORD dwLeft,
+                         DWORD dwWidth,
+                         DWORD dwHeight,
+                         DWORD dwPitchDB,
+                         DWORD dwPitchFB,
+                         DWORD dwColor,
+                         VOID  *pPalette
+                        )
+{
+  dprintf(("Fill32on8 NOT implemented\n"));
+}
+ void __cdecl Fill32on16( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                        )
+{
+  DWORD dwCol;
+  dprintf(("Fill32on16\n"));
+
+  Fill32( pFB+(dwTop*dwPitchFB)+(dwLeft*4),
+          dwWidth,
+          dwHeight,
+          dwPitchFB,
+          dwColor);
+
+  dwCol = ((dwColor & 0xF8000000) >>16) +
+          ((dwColor & 0x00FE0000)>> 13) +
+          ((dwColor & 0x0000F800)>> 11);
+
+  dwCol = dwCol + (dwCol<<16);
+  Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwCol);
+}
+ void __cdecl Fill32on24( char *pDB,
+                          char *pFB,
+                          DWORD dwTop,
+                          DWORD dwLeft,
+                          DWORD dwWidth,
+                          DWORD dwHeight,
+                          DWORD dwPitchDB,
+                          DWORD dwPitchFB,
+                          DWORD dwColor,
+                          VOID  *pPalette
+                         )
+{
+  dprintf(("Fill32on24\n"));
+  Fill32( pFB+(dwTop*dwPitchFB)+(dwLeft*4),
+          dwWidth,
+          dwHeight,
+          dwPitchFB,
+          dwColor);
+
+  Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
+          dwWidth,
+          dwHeight,
+          dwPitchDB,
+          dwColor);
+}
+
Index: trunk/src/ddraw/new/fillfunc.h
===================================================================
--- trunk/src/ddraw/new/fillfunc.h	(revision 3345)
+++ trunk/src/ddraw/new/fillfunc.h	(revision 3345)
@@ -0,0 +1,203 @@
+/* $Id: fillfunc.h,v 1.1 2000-04-07 18:21:12 mike Exp $ */
+
+/*
+ * Colorfill function definitions
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+
+// without ColorConversion
+extern void __cdecl Fill8on8( char *pDBDst,
+                              char *pFBDst,
+                              DWORD dwDstTop,
+                              DWORD dwDstLeft,
+                              DWORD dwWidth,
+                              DWORD dwHeight,
+                              DWORD dwPitchDBDst,
+                              DWORD dwPitchFBDst,
+                              DWORD dwColor,
+                              VOID  *pPalette
+                             );
+
+extern void __cdecl Fill16on16( char *pDBDst,
+                                char *pFBDst,
+                                DWORD dwDstTop,
+                                DWORD dwDstLeft,
+                                DWORD dwWidth,
+                                DWORD dwHeight,
+                                DWORD dwPitchDBDst,
+                                DWORD dwPitchFBDst,
+                                DWORD dwColor,
+                                VOID  *pPalette
+                              );
+extern void __cdecl Fill24on24( char *pDBDst,
+                                char *pFBDst,
+                                DWORD dwDstTop,
+                                DWORD dwDstLeft,
+                                DWORD dwWidth,
+                                DWORD dwHeight,
+                                DWORD dwPitchDBDst,
+                                DWORD dwPitchFBDst,
+                                DWORD dwColor,
+                                VOID  *pPalette
+                               );
+extern void __cdecl Fill32on32( char *pDBDst,
+                                char *pFBDst,
+                                DWORD dwDstTop,
+                                DWORD dwDstLeft,
+                                DWORD dwWidth,
+                                DWORD dwHeight,
+                                DWORD dwPitchDBDst,
+                                DWORD dwPitchFBDst,
+                                DWORD dwColor,
+                                VOID  *pPalette
+                               );
+
+extern void __cdecl Fill8on16( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill8on24( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill8on32( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill16on8( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill16on24( char *pDBDst,
+                                char *pFBDst,
+                                DWORD dwDstTop,
+                                DWORD dwDstLeft,
+                                DWORD dwWidth,
+                                DWORD dwHeight,
+                                DWORD dwPitchDBDst,
+                                DWORD dwPitchFBDst,
+                                DWORD dwColor,
+                                VOID  *pPalette
+                              );
+
+extern void __cdecl Fill16on32( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill24on8( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill24on16( char *pDBDst,
+                                char *pFBDst,
+                                DWORD dwDstTop,
+                                DWORD dwDstLeft,
+                                DWORD dwWidth,
+                                DWORD dwHeight,
+                                DWORD dwPitchDBDst,
+                                DWORD dwPitchFBDst,
+                                DWORD dwColor,
+                                VOID  *pPalette
+                              );
+
+extern void __cdecl Fill24on32( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill32on8( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
+extern void __cdecl Fill32on16( char *pDBDst,
+                                char *pFBDst,
+                                DWORD dwDstTop,
+                                DWORD dwDstLeft,
+                                DWORD dwWidth,
+                                DWORD dwHeight,
+                                DWORD dwPitchDBDst,
+                                DWORD dwPitchFBDst,
+                                DWORD dwColor,
+                                VOID  *pPalette
+                              );
+
+extern void __cdecl Fill32on24( char *pDBDst,
+                               char *pFBDst,
+                               DWORD dwDstTop,
+                               DWORD dwDstLeft,
+                               DWORD dwWidth,
+                               DWORD dwHeight,
+                               DWORD dwPitchDBDst,
+                               DWORD dwPitchFBDst,
+                               DWORD dwColor,
+                               VOID  *pPalette
+                              );
+
Index: trunk/src/ddraw/new/iccio1.asm
===================================================================
--- trunk/src/ddraw/new/iccio1.asm	(revision 3345)
+++ trunk/src/ddraw/new/iccio1.asm	(revision 3345)
@@ -0,0 +1,297 @@
+; **********************************************************************
+; Copyright (C) 1995 by Holger Veit (Holger.Veit@gmd.de)
+; Use at your own risk! No Warranty! The author is not responsible for
+; any damage or loss of data caused by proper or improper use of this
+; device driver.
+; **********************************************************************
+;
+; compile with ALP
+;
+  TITLE  ICCIO.ASM
+  .386
+  .387
+CODE32  SEGMENT DWORD USE32 PUBLIC 'CODE'
+CODE32  ENDS
+DATA32  SEGMENT DWORD USE32 PUBLIC 'DATA'
+DATA32  ENDS
+CONST32  SEGMENT DWORD USE32 PUBLIC 'CONST'
+CONST32  ENDS
+BSS32  SEGMENT DWORD USE32 PUBLIC 'BSS'
+BSS32  ENDS
+DGROUP  GROUP CONST32, BSS32, DATA32
+  ASSUME  CS:FLAT, DS:FLAT, SS:FLAT, ES:FLAT
+DATA32  SEGMENT
+DATA32  ENDS
+BSS32  SEGMENT
+BSS32  ENDS
+CONST32  SEGMENT
+CONST32  ENDS
+
+DATA32  SEGMENT
+ioentry   DWORD  0
+gdt    WORD  0
+DATA32  ENDS
+
+CODE32  SEGMENT
+
+; performs fast output of a byte to an I/O port
+; this routine is intended to be called from gcc C code
+;
+; Calling convention:
+;  void c_outb1(short port,char data)
+;
+;
+  PUBLIC  c_outb1
+  ALIGN  04H
+c_outb1  PROC
+  MOV  EDX, [ESP+4]    ; get port
+  MOV  AL, [ESP+8]    ; get data
+  OUT  DX,AL
+  RET
+c_outb1  ENDP
+
+; performs fast output of a word to an I/O port
+; this routine is intended to be called from gcc C code
+;
+; Calling convention:
+;  void c_outw1(short port,short data)
+;
+;
+  PUBLIC  c_outw1
+  ALIGN  04H
+c_outw1  PROC
+  MOV  EDX, [ESP+4]    ; get port
+  MOV  AX, [ESP+8]    ; get data
+  OUT  DX,AX
+  RET
+c_outw1  ENDP
+
+; performs fast output of a longword to an I/O port
+; this routine is intended to be called from gcc C code
+;
+; Calling convention:
+;  void c_outl1(short port,long data)
+;
+;
+  PUBLIC  c_outl1
+  ALIGN  04H
+c_outl1  PROC
+  MOV  EDX, [ESP+4]    ; get port
+  MOV  EAX, [ESP+8]    ; get data
+  OUT  DX, EAX
+  RET
+c_outl1  ENDP
+
+; performs fast input of a byte from an I/O port
+; this routine is intended to be called from gcc C code
+;
+; Calling convention:
+;  char c_inb1(short port)
+;
+;
+  PUBLIC c_inb1
+  ALIGN  04H
+c_inb1  PROC
+  MOV  EDX, [ESP+4]    ; get port
+  IN  AL,DX
+  AND  EAX, 000000FFh
+  RET
+c_inb1  ENDP
+
+; performs fast input of a word from an I/O port
+; this routine is intended to be called from gcc C code
+;
+; Calling convention:
+;  short c_inw1(short port)
+;
+;
+  PUBLIC c_inw1
+  ALIGN  04H
+c_inw1  PROC
+  MOV  EDX, [ESP+4]    ; get port
+  IN  AX, DX
+  AND  EAX, 0000FFFFh    ; mask out word
+  RET
+c_inw1  ENDP
+
+; performs fast input of a longword from an I/O port
+; this routine is intended to be called from gcc C code
+;
+; Calling convention:
+;  lomg c_inl1(short port)
+;
+;
+  PUBLIC c_inl1
+  ALIGN  04H
+c_inl1  PROC
+  MOV  EDX, [ESP+4]    ; get port
+  IN  EAX, DX
+  RET
+c_inl1  ENDP
+
+CODE32  ENDS
+
+;------------------------------------------------------------------------------
+
+; Initialize I/O access via the driver.
+; You *must* call this routine once for each *thread* that wants to do
+; I/O.
+;
+; The routine is mainly equivalent to a C routine performing the
+; following (but no need to add another file):
+;  DosOpen("/dev/fastio$", read, nonexclusive)
+;  DosDevIOCtl(device, XFREE86IO, IOGETSEL32)
+;  selector -> ioentry+4
+;  DosClose(device)
+;
+; Calling convention:
+;  int io_init1(void)
+; Return:
+;  0 if successful
+;  standard APIRET RETurn code if error
+;
+
+CONST32  SEGMENT
+  ALIGN  04H
+devname:
+  DB  "/dev/fastio$",0
+CONST32  ENDS
+
+
+CODE32  SEGMENT
+  PUBLIC  io_init1
+  EXTRN  DosOpen:PROC
+  EXTRN  DosClose:PROC
+  EXTRN  DosDevIOCtl:PROC
+  ALIGN  04H
+io_init1  PROC
+  PUSH  EBP
+  MOV  EBP, ESP  ; standard stack frame
+  SUB  ESP, 16    ; reserve memory
+        ; -16 = len arg of DosDevIOCtl
+        ; -12 = action arg of DosOpen
+        ; -8 = fd arg of DosOpen
+        ; -2 = short GDT selector arg
+  PUSH  0    ; (PEAOP2)NULL
+  PUSH  66    ; OPENACCESSREADWRITE|OPENSHAREDENYNONE
+  PUSH  1    ; FILEOPEN
+  PUSH  0    ; FILENORMAL
+  PUSH  0    ; initial size
+  LEA  EAX, [EBP-12]  ; Adress of 'action' arg
+  PUSH  EAX
+  LEA  EAX, [EBP-8]  ; Address of 'fd' arg
+  PUSH  EAX
+  PUSH  OFFSET FLAT:devname
+  CALL  DosOpen    ; call DosOpen
+  ADD  ESP, 32    ; cleanup stack frame
+  CMP  EAX, 0    ; is return code zero?
+  JE  goon    ; yes, proceed
+  LEAVE      ; no RETurn error
+  RET
+  ALIGN  04H
+goon:
+  LEA  EAX, [EBP-16]  ; address of 'len' arg of DosDevIOCtl
+  PUSH  EAX
+  PUSH  2    ; sizeof(short)
+  LEA  EAX, [EBP-2]  ; address to return the GDT selector
+  PUSH  EAX
+  PUSH  0    ; no parameter len
+  PUSH  0    ; no parameter size
+  PUSH  0    ; no parameter address
+  PUSH  100    ; function code IOGETSEL32
+  PUSH  118    ; category code XFREE6IO
+  MOV  EAX,[EBP-8]  ; file handle
+  PUSH  EAX
+  CALL  DosDevIOCtl  ; perform ioctl
+  ADD  ESP, 36    ; cleanup stack
+  CMP  EAX, 0    ; is return code = 0?
+  JE  ok    ; yes, proceed
+  PUSH  EAX    ; was error, save error code
+  MOV  EAX, [EBP-8]  ; file handle
+  PUSH  EAX
+  CALL  DosClose  ; close device
+  ADD  ESP,4    ; clean stack
+  POP  EAX    ; get error code
+  LEAVE      ; return error
+  RET
+
+  ALIGN  04H
+ok:
+  MOV  EAX, [EBP-8]  ; file handle
+  PUSH  EAX    ; do normal close
+  CALL  DosClose
+  ADD  ESP,4    ; clean stack
+
+  MOV  AX, [EBP-2]  ; load gdt selector
+  MOV  gdt, AX    ; store in ioentry address selector part
+  XOR  EAX, EAX  ; EAX = 0
+  MOV  DWORD PTR [ioentry], EAX ; clear ioentry offset part
+        ; return code = 0 (in EAX)
+
+        ; now use this function to raise the IOPL
+  MOV  EBX,13    ; special function code
+  CALL  FWORD PTR [ioentry]  ; CALL intersegment indirect 16:32
+
+  ; thread should now be running at IOPL=3
+
+  XOR  EAX, EAX  ; return code = 0
+  LEAVE      ; clean stack frame
+  RET      ; exit
+io_init1 ENDP
+
+; void in_init(short)
+PUBLIC  io_init2
+  ALIGN  04H
+io_init2  PROC
+
+  MOV  gdt, AX    ; store in ioentry address selector part
+  XOR  EAX, EAX  ; EAX = 0
+  MOV  DWORD PTR [ioentry], EAX ; clear ioentry offset part
+        ; return code = 0 (in EAX)
+
+        ; now use this function to raise the IOPL
+  MOV  EBX,13    ; special function code
+  CALL  FWORD PTR [ioentry]  ; CALL intersegment indirect 16:32
+
+  XOR  EAX, EAX  ; return code = 0
+  ret
+io_init2  ENDP
+
+  PUBLIC  io_exit1
+  ALIGN  04H
+io_exit1  PROC
+  push  EBP
+  MOV  EBP, ESP  ; stackframe, I am accustomed to this :-)
+
+  MOV  AX, gdt    ; check if ioinit was called once
+  OR  AX, AX
+  JZ  exerr    ; no gdt entry, so process cannot be at IOPL=3
+        ; through this mechanism
+
+  MOV  EBX, 14    ; function code to disable iopl
+  CALL  FWORD PTR [ioentry]  ; call intersegment indirect 16:32
+
+  ; process should now be at IOPL=3 again
+  XOR  EAX, EAX  ; ok, RETurn code = 0
+  LEAVE
+  RET
+exerr:  XOR  EAX, EAX  ; not ok, RETurn code = ffffffff
+  DEC  EAX
+  LEAVE
+  RET
+io_exit1  ENDP
+
+
+
+; for diagnostic only
+
+  PUBLIC  psw
+  ALIGN  04H
+psw  PROC
+  PUSHF      ; get the current PSW
+  POP  EAX    ; into EAX
+  RET
+psw  ENDP
+
+CODE32  ENDS
+  END
Index: trunk/src/ddraw/new/initterm.cpp
===================================================================
--- trunk/src/ddraw/new/initterm.cpp	(revision 3345)
+++ trunk/src/ddraw/new/initterm.cpp	(revision 3345)
@@ -0,0 +1,138 @@
+/* $Id: initterm.cpp,v 1.1 2000-04-07 18:21:12 mike Exp $ */
+
+/*
+ * DLL entry point
+ *
+ * Copyright 1998 Sander van Leeuwen
+ * Copyright 1998 Peter Fitzsimmons
+ *
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+/*-------------------------------------------------------------*/
+/* INITERM.C -- Source for a custom dynamic link library       */
+/*              initialization and termination (_DLL_InitTerm) */
+/*              function.                                      */
+/*                                                             */
+/* When called to perform initialization, this sample function */
+/* gets storage for an array of integers, and initializes its  */
+/* elements with random integers.  At termination time, it     */
+/* frees the array.  Substitute your own special processing.   */
+/*-------------------------------------------------------------*/
+
+
+/* Include files */
+#define  INCL_DOSMODULEMGR
+#define  INCL_DOSPROCESS
+#include <os2wrap.h>    //Odin32 OS/2 api wrappers
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <odin.h>
+#include <win32type.h>
+#include <winconst.h>
+#include <odinlx.h>
+#include <exitlist.h>
+#include <misc.h>       /*PLF Wed  98-03-18 23:18:15*/
+
+extern "C" {
+void CDECL _ctordtorInit( void );
+void CDECL _ctordtorTerm( void );
+
+ //Win32 resource table (produced by wrc)
+ extern DWORD _Resource_PEResTab;
+}
+
+char ddrawPath[CCHMAXPATH] = "";
+
+extern VOID RestorePM(VOID);
+static void APIENTRY cleanup(ULONG ulReason);
+
+//******************************************************************************
+//******************************************************************************
+BOOL WINAPI LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
+{
+   switch (fdwReason)
+   {
+   case DLL_PROCESS_ATTACH:
+	return TRUE;
+
+   case DLL_THREAD_ATTACH:
+   case DLL_THREAD_DETACH:
+	return TRUE;
+
+   case DLL_PROCESS_DETACH:
+	_ctordtorTerm();
+	return TRUE;
+   }
+   return FALSE;
+}
+/****************************************************************************/
+/* _DLL_InitTerm is the function that gets called by the operating system   */
+/* loader when it loads and frees this DLL for each process that accesses   */
+/* this DLL.  However, it only gets called the first time the DLL is loaded */
+/* and the last time it is freed for a particular process.  The system      */
+/* linkage convention MUST be used because the operating system loader is   */
+/* calling this function.                                                   */
+/****************************************************************************/
+unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
+                                   ulFlag)
+{
+   size_t i;
+   APIRET rc;
+
+   /*-------------------------------------------------------------------------*/
+   /* If ulFlag is zero then the DLL is being loaded so initialization should */
+   /* be performed.  If ulFlag is 1 then the DLL is being freed so            */
+   /* termination should be performed.                                        */
+   /*-------------------------------------------------------------------------*/
+
+   switch (ulFlag) {
+      case 0 :
+      {
+         _ctordtorInit();
+
+   	 DosQueryModuleName(hModule, CCHMAXPATH, ddrawPath);
+         char *endofpath = strrchr(ddrawPath, '\\');
+         if(endofpath) *(endofpath+1) = 0;
+
+         CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
+
+	 if(RegisterLxDll(hModule, LibMain, (PVOID)&_Resource_PEResTab) == FALSE) 
+		return 0UL;
+
+         rc = DosExitList(EXITLIST_NONCOREDLL|EXLST_ADD, cleanup);
+         if(rc) return 0UL;
+
+
+         break;
+      }
+      case 1 :
+         // TODO: We must restore display, only when display was changed.
+	 UnregisterLxDll(hModule);
+         break;
+      default  :
+         return 0UL;
+   }
+
+   /***********************************************************/
+   /* A non-zero value must be returned to indicate success.  */
+   /***********************************************************/
+   return 1UL;
+}
+//******************************************************************************
+//******************************************************************************
+
+static void APIENTRY cleanup(ULONG ulReason)
+{
+   dprintf(("ddraw exit\n"));
+   RestorePM();
+   _ctordtorTerm();
+   dprintf(("ddraw exit done\n"));
+
+   DosExitList(EXLST_EXIT, cleanup);
+}
+
+
Index: trunk/src/ddraw/new/initterm.h
===================================================================
--- trunk/src/ddraw/new/initterm.h	(revision 3345)
+++ trunk/src/ddraw/new/initterm.h	(revision 3345)
@@ -0,0 +1,20 @@
+/* $Id: initterm.h,v 1.1 2000-04-07 18:21:13 mike Exp $ */
+/*
+ * KERNEL32 DLL entry point header
+ *
+ * Copyright 1998 Sander van Leeuwen
+ * Copyright 1998 Peter Fitzsimmons
+ *
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef __INITTERM_H__
+#define __INITTERM_H__
+
+void CloseLogFile(); //misc.cpp
+
+extern char  ddrawPath[];
+
+#endif
Index: trunk/src/ddraw/new/makefile
===================================================================
--- trunk/src/ddraw/new/makefile	(revision 3345)
+++ trunk/src/ddraw/new/makefile	(revision 3345)
@@ -0,0 +1,97 @@
+# $Id: makefile,v 1.1 2000-04-07 18:21:13 mike Exp $
+#
+# ddraw.dll makefile
+#
+# Copyright 1998 Sander van Leeuwen
+#           1999 Markus Montkowski
+#
+# Project Odin Software License can be found in LICENSE.TXT
+#
+#
+
+# Directory macros.
+PDWIN32_INCLUDE = ..\..\..\include
+PDWIN32_LIB     = ..\..\..\lib
+PDWIN32_BIN     = ..\..\..\$(OBJDIR)
+PDWIN32_TOOLS   = ..\..\..\tools\bin
+
+
+# Compiler, tools, and interference rules.
+!include $(PDWIN32_INCLUDE)/pdwin32.mk
+
+
+# Flag overloads and local macros.
+CLEANEXTRAS = ddrawrsrc.asm
+ASFLAGS     = -Sc -Sv:ALP
+
+
+# Object files. All objects should be prefixed with $(OBJDIR)!
+OBJS = \
+$(OBJDIR)\ddraw.obj \
+$(OBJDIR)\os2ddraw.obj \
+$(OBJDIR)\os2clipper.obj \
+$(OBJDIR)\os2d3d.obj \
+$(OBJDIR)\iccio1.obj \
+$(OBJDIR)\asmutil.obj \
+$(OBJDIR)\os2surface.obj \
+$(OBJDIR)\os2palette.obj \
+$(OBJDIR)\os2palset.obj \
+$(OBJDIR)\os2fsdd.obj \
+$(OBJDIR)\rectangle.obj \
+$(OBJDIR)\initterm.obj \
+$(OBJDIR)\os2util.obj \
+$(OBJDIR)\bltFunc.obj \
+$(OBJDIR)\fillfunc.obj \
+$(OBJDIR)\colorconv.obj \
+$(OBJDIR)\ddrawrsrc.obj
+
+
+# Target name - name of the dll without extention and path.
+TARGET = ddraw
+
+
+# All rule - build objs, target dll, copies dll to bin and makes libs.
+all:    $(OBJDIR) \
+        $(OBJDIR)\$(TARGET).dll \
+        $(PDWIN32_BIN)\$(TARGET).dll \
+        lib
+
+
+# Lib rule - build importlibrary (and evt. other libs)
+lib: $(TARGET).lib $(PDWIN32_LIB)\$(TARGET).lib
+
+
+# Dll rule - builds the target dll.
+$(OBJDIR)\$(TARGET).dll: $(OBJS) $(TARGET).def $(OBJDIR)\$(TARGET).lrf
+    $(LD2) $(LD2FLAGS) @$(OBJDIR)\$(TARGET).lrf
+
+
+# Linker file - creates the parameter file passed on to the linker.
+$(OBJDIR)\$(TARGET).lrf: makefile
+    @echo Creating file <<$@
+/OUT:$(OBJDIR)\$(TARGET).dll
+/MAP:$(OBJDIR)\$(TARGET).map
+$(OBJS)
+$(PDWIN32_LIB)/ole32.lib
+$(PDWIN32_LIB)/advapi32.lib
+$(PDWIN32_LIB)/gdi32.lib
+$(PDWIN32_LIB)/comctl32.lib
+$(PDWIN32_LIB)/kernel32.lib
+$(PDWIN32_LIB)/odincrt.lib
+$(PDWIN32_LIB)/user32.lib
+mmpm2.lib
+OS2386.LIB
+$(RTLLIB_O)
+$(TARGET).def
+<<keep
+
+
+# Dep rule - makes depenencies for C, C++ and Asm files.
+dep:
+    $(DEPEND) -I$(PDWIN32_INCLUDE);$(PDWIN32_INCLUDE)\win \
+        *.c *.cpp *.h *.asm *.inc $(PDWIN32_INCLUDE)\*.h
+
+
+# Includes the common rules.
+!include $(PDWIN32_INCLUDE)/pdwin32.post
+
Index: trunk/src/ddraw/new/os2DDWindow.cpp
===================================================================
--- trunk/src/ddraw/new/os2DDWindow.cpp	(revision 3345)
+++ trunk/src/ddraw/new/os2DDWindow.cpp	(revision 3345)
@@ -0,0 +1,78 @@
+/* $Id: os2DDWindow.cpp,v 1.1 2000-04-07 18:21:13 mike Exp $ */
+
+/*
+ * Functions to subclass the games windowproc to be used for
+ * fullscreen switching
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#define INCL_WIN
+#include <os2wrap.h>
+#include <odinwrap.h>
+#include "os2DDWindow.h"
+
+PFNWP pfnOrgClientProc = NULL;
+
+MRESULT EXPENTRY DDOS2WindowProc(HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2);
+extern VOID SwitchDisplay(HWND hwnd);
+
+ODINFUNCTION1(BOOL , OS2DDSubClassWindow ,HWND, hwndClient)
+{
+  HWND hwndParent;
+
+  // only allow subclassing once!
+
+  if(NULL==pfnOrgClientProc)
+  {
+    hwndParent = WinQueryWindow(hwndClient,QW_PARENT);
+
+    if(hwndParent!=HWND_DESKTOP)
+      hwndFrame = hwndParent;
+    else
+      hwndFrame = hwndClient;
+
+    pfnOrgClientProc = WinSubclassWindow(hwndFrame,DDOS2WindowProc);
+
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+
+MRESULT EXPENTRY DDOS2WindowProc(HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2)
+{
+  USHORT usFlags;
+
+  switch(ulMsg)
+  {
+    // capture the mouse
+    case WM_ACTIVATE:
+      if(mp1)
+        WinSetCapture(HWND_DESKTOP,hwnd);
+      else
+        WinSetCapture(HWND_DESKTOP,NULLHANDLE);
+      break;
+    case WM_CHAR:
+      // Check for CTRL+SHIFT+F12 to toggle between stretched (FS) / windowd mode
+      usFlags = SHORT1FROMMP(mp1);
+      if(!(usFlags & KC_KEYUP))
+      {
+        if( (usFlags & KC_VIRTUALKEY) && (usFlags & KC_SHIFT) && (usFlags & KC_CTRL))
+        {
+          if(VK_F12 == SHORT2FROMMP(mp2))
+            SwitchDisplay(hwnd);
+        }
+      }
+      break;
+    default:
+      break;
+  }
+
+  return pfnOrgClientProc(hwnd, ulMsg, mp1,mp2);
+}
+
Index: trunk/src/ddraw/new/os2DDWindow.h
===================================================================
--- trunk/src/ddraw/new/os2DDWindow.h	(revision 3345)
+++ trunk/src/ddraw/new/os2DDWindow.h	(revision 3345)
@@ -0,0 +1,17 @@
+/* $Id: os2DDWindow.h,v 1.1 2000-04-07 18:21:13 mike Exp $ */
+
+/*
+ * Windwo subclass definitions
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef OS2DDWindow
+  #define OS2DDWindow
+  HWND hwndFrame;
+  BOOL OS2DDSubclassWindow(HWND hwndClient);
+#endif
+
Index: trunk/src/ddraw/new/os2ddrawbase.h
===================================================================
--- trunk/src/ddraw/new/os2ddrawbase.h	(revision 3345)
+++ trunk/src/ddraw/new/os2ddrawbase.h	(revision 3345)
@@ -0,0 +1,40 @@
+
+class OS2IDirectDraw
+{
+  public:
+    //this one has to go first!
+    IDirectDraw4Vtbl *lpVtbl;
+    IDirectDraw2Vtbl  Vtbl;
+    // MS did it again with direct/X 6 they changed the behavior of the directdraw component
+    // So we now need 2 Virt. Tables one for the old and one for the new so we return the
+    // right interface if one creates a DX6 directdraw object but wants a DX2,3,5 interface
+    IDirectDraw4Vtbl  Vtbl4;
+    IDirect3DVtbl     Vtbl3D;
+
+    OS2IDirectDraw( GUID *lpGUID);
+    ~OS2IDirectDraw();
+
+    // Simple management for Surfaces should be good enougth for now
+    inline  BOOL          HasPrimarySurface() { return PrimaryExists;}
+            void          SetPrimarySurface(BOOL NewStatus){PrimaryExists = NewStatus;}
+            int           Referenced;
+    inline  HRESULT       GetLastError()    { return lastError;    }
+    inline  char *        GetFrameBuffer()  { return pFrameBuffer; }
+    inline  int           GetScreenWidth()  { return screenwidth;  }
+    inline  int           GetScreenHeight() { return screenheight; }
+    inline  int           GetScreenBpp()    { return screenbpp;}
+    inline  FOURCC        GetScreenFourCC() { return SupportedFourCCs[screenbpp>>3];}
+
+  protected:
+    HRESULT lastError;
+    FOURCC  SupportedFourCCs[] = {FOURCC_LUT8,FOURCC_R565,FOURCC_RGB3,FOURCC_RGB4};
+
+    char   *pFrameBuffer;
+    HWND    hwndClient;
+    int     screenwidth, screenheight, screenbpp;
+    BOOL    PrimaryExists;
+
+   // Linked list management
+              OS2IDirectDraw* next;                   // Next OS2IDirectDraw
+    static    OS2IDirectDraw* ddraw;                  // List of OS2IDirectDraw
+}
Index: trunk/src/ddraw/new/os2ddrawmodes.h
===================================================================
--- trunk/src/ddraw/new/os2ddrawmodes.h	(revision 3345)
+++ trunk/src/ddraw/new/os2ddrawmodes.h	(revision 3345)
@@ -0,0 +1,71 @@
+/* $Id: os2ddrawmodes.h,v 1.1 2000-04-07 18:21:14 mike Exp $ */
+
+/*
+ * Defintions of common videomodes we report back
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __OS2DDRAWMODES__
+#define __OS2DDRAWMODES__
+
+
+// Modes reported back during enum
+typedef struct _OS2_DXMODES
+{
+  int iXRes;    // # of Pixel X-Res
+  int iYRes;    // # of Pixel Y-Res
+  int iBits;    // # of Bits/Pixel
+  int iRatio;   // Flag 1 if you must take care of aspect ratio, else 0
+} OS2_DXMODES, *POS2_DXMODES;
+
+#define NUM_MODES_DIVE 30
+OS2_DXMODES ModesDive[NUM_MODES_DIVE] =
+{
+  {320,200,8,1},
+  {320,240,8,0},
+  {512,384,8,0},
+  {640,400,8,1},
+  {640,480,8,0},
+  {800,600,8,0},
+  {1024,768,8,0},
+  {1280,1024,8,1},
+  {1600,1200,8,0},
+  {512,384,16,0},
+  {640,400,16,1},
+  {640,480,16,0},
+  {800,600,16,0},
+  {1024,768,16,0},
+  {1280,1024,16,1},
+  {1600,1200,16,0},
+  {512,384,24,0},
+  {640,400,24,1},
+  {640,480,24,0},
+  {800,600,24,0},
+  {1024,768,24,0},
+  {1280,1024,24,1},
+  {1600,1200,24,0},
+  {512,384,32,0},
+  {640,400,32,1},
+  {640,480,32,0},
+  {800,600,32,0},
+  {1024,768,32,0},
+  {1280,1024,32,1},
+  {1600,1200,32,0}
+};
+
+// Voodoo modes (640x400,640x480,800x600 all only 16 Bit)
+// Voodoo mode 800x600 will only be Z-buffered for Voodoo II cards
+
+#define NUM_MODES_VOODOO 4
+OS2_DXMODES ModesVoodoo[NUM_MODES_VOODOO] =
+{
+  {512,384,16,0},
+  {640,400,16,1},
+  {640,480,16,0},
+  {800,600,16,0}
+};
+
+#endif
Index: trunk/src/ddraw/new/os2fsdd.cpp
===================================================================
--- trunk/src/ddraw/new/os2fsdd.cpp	(revision 3345)
+++ trunk/src/ddraw/new/os2fsdd.cpp	(revision 3345)
@@ -0,0 +1,377 @@
+/*
+ * Few routines for full-screen DirectDraw on OS/2
+ *
+ * Copyright 2000 Michal Necasek
+ * Copyright 2000 Przemyslaw Dobrowolski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#define INCL_DOS
+#define INCL_WINWINDOWMGR
+#include <os2wrap.h>
+#include <misc.h>
+
+#include <svgadefs.h>
+
+#include "os2fsdd.h"
+
+/* DirectX palette entry */
+typedef struct tagPALETTEENTRY
+{
+   BYTE        peRed;
+   BYTE        peGreen;
+   BYTE        peBlue;
+   BYTE        peFlags;
+} PALETTEENTRY;
+
+#define DLLNAME                 "VIDEOPMI"
+
+#define REQUEST_ENTRYPOINT      "VIDEOPMI32Request"
+
+#define FAIL_LENGTH             256
+
+char PMIFILE[256] = "\\os2\\svgadata.pmi";
+
+/*
+ * Adapter instance.
+ */
+VIDEO_ADAPTER AdapterInstance;
+
+/*
+ * Entry point to videopmi
+ */
+PFNVIDEOPMIREQUEST __pfnPMIRequest;
+
+//
+// mode table. It is an array of VIDEOMODEINFOs.
+//
+static PVIDEOMODEINFO ModeTable;
+
+static ULONG ulTotalModes;
+
+static bIsInFS = FALSE;
+
+/*
+ * PMI request wrapper
+ */
+inline ULONG PMI_Request(PVIDEO_ADAPTER a, ULONG b, PVOID c, PVOID d)
+{
+   ULONG yyrc;
+   USHORT sel = RestoreOS2FS();
+
+   yyrc = __pfnPMIRequest(a, b, c, d);
+   SetFS(sel);
+
+   return yyrc;
+}
+
+
+/************************************************************
+ * Load the .PMI file, get the hardware information about the
+ * adapter and the entry point to videopmi.
+ *
+ * Returns 0 if successful; DOS error token, otherwise.
+ ************************************************************/
+
+ULONG LoadPMIService (VOID)
+{
+   APIRET        rc;
+   char          sFail[FAIL_LENGTH] = {0};
+   HMODULE       hmodVIDEOPMI;
+
+
+/************************************************************
+ * Load videopmi.dll
+ ************************************************************/
+
+   if (!(rc = DosLoadModule (sFail, FAIL_LENGTH, DLLNAME,
+                            &hmodVIDEOPMI)))
+   {
+
+/************************************************************
+ * Get PMIREQUEST entry point
+ ************************************************************/
+
+      rc = DosQueryProcAddr (hmodVIDEOPMI,
+                             0,
+                             REQUEST_ENTRYPOINT,
+                             (PFN*)&__pfnPMIRequest);
+
+      if (!rc)
+
+         /*
+          * Load PMI file.
+          * If PMI file is successfully loaded,
+          * adapter in AdapterInstance will be filled with the
+          * information in .PMI file.
+          *
+          * Remember to set up the size information for ADAPTERINFO
+          * and VIDEOMODEINFO.
+          */
+
+//          AdapterInstance.AdapterInfo.cb    = sizeof (ADAPTERINFO);
+//          AdapterInstance.VideoModeInfo.cb  = sizeof (VIDEOMODEINFO);
+
+         rc = PMI_Request (&AdapterInstance,
+                           PMIREQUEST_LOADPMIFILE,
+//                         PMIREQUEST_IDENTIFYADAPTER,
+                           PMIFILE,
+                           NULL);
+//      if (rc)
+         DosFreeModule (hmodVIDEOPMI);
+   }
+
+   return rc;
+}
+
+
+/************************************************************
+ *
+ * This function sets up the mode table.
+ *
+ * Copy the mode table from videopmi. It is an arrary of modes.
+ * All the information in [ModeInfo] and
+ * [MonitorModeInfo], if any, is included.
+ *
+ * Returns 0 if successful; DOS error token, otherwise.
+ ************************************************************/
+ULONG SetUpModeTable (VOID)
+{
+   APIRET        rc;
+   /*
+    * Get the total number of modes
+    */
+   if (!(rc = PMI_Request (&AdapterInstance,
+                           PMIREQUEST_QUERYMAXMODEENTRIES,
+                           NULL,
+                           &ulTotalModes)))
+
+      /*
+       * Allocate memory for mode table
+       */
+      if (!(rc = DosAllocSharedMem ((PPVOID)&ModeTable,
+                                    NULL,
+                                    ulTotalModes *
+                                    sizeof (VIDEOMODEINFO),
+                                    OBJ_GETTABLE | PAG_COMMIT |
+                                    PAG_WRITE)))
+
+         /*
+          * Copy mode table.
+          * Please check svgadefs.h for the fields in VIDEOMODEINFO.
+          */
+         rc = PMI_Request (&AdapterInstance,
+                           PMIREQUEST_QUERYMODEINFODATA,
+                           NULL,
+                           ModeTable);
+
+   return rc;
+}
+
+ULONG FreeModeTable (VOID)
+{
+  DosFreeMem (ModeTable);
+  return 0;
+}
+
+
+/************************************************************
+ *
+ * This function sets the graphic mode.
+ *
+ * You can select the mode based on any information in the VIDEOMODEINFO
+ * structure. The following is only an example to set the graphics mode
+ * based on resolution and refresh rate.
+ * PM driver should not call videopmi to set the mode directly.
+ * It should call BVH to set the mode as before, such that
+ * the mode can be set based on the current monitor capability
+ * handled by BVH.
+ *
+ * Returns 0 if successful; DOS error token, otherwise.
+ ************************************************************/
+
+ULONG SetSVGAMode (ULONG     ulHorRes,
+                   ULONG     ulVerRes,
+                   ULONG     ulColors,
+                   ULONG     ulVerRefr,
+                   PULONG    pulModeInd,
+                   PVOID     pCLUTData)
+{
+    APIRET rc=0xFFFF;
+    ULONG  i;
+
+    *pulModeInd = -1;
+    /* Search mode */
+    /* Assuming that the modes are sorted by refresh mode in ascending */
+    /* order, we'll find the highest refresh mode                      */
+    if (ulVerRefr >= 0xFFL)
+    {
+      for(i=0; i < ulTotalModes; i++)
+         if ((ModeTable[i].usXResolution == (USHORT)ulHorRes) &&
+             (ModeTable[i].usYResolution == (USHORT)ulVerRes) &&
+             (ModeTable[i].bBitsPerPixel == (BYTE)ulColors)) {
+            *pulModeInd = i;
+//            break;
+         }
+   }
+
+   else    /* verify all including the refresh parameter */
+   {
+      for(i=0; i < ulTotalModes; i++)
+         if ((ModeTable[i].usXResolution  == (USHORT) ulHorRes) &&
+             (ModeTable[i].usYResolution  == (USHORT) ulVerRes) &&
+             (ModeTable[i].bBitsPerPixel  == (BYTE) ulColors) &&
+             ((ModeTable[i].bVrtRefresh   == 0xFF) ||
+              (ModeTable[i].bVrtRefresh   == (BYTE) ulVerRefr)))
+             *pulModeInd = i;
+   }
+
+   if (*pulModeInd == -1)
+      return rc;              /* mode not found */
+
+   /* Unlock first */
+   rc = PMI_Request (&AdapterInstance,
+                     PMIREQUEST_UNLOCKREGISTERS,
+                     NULL,
+                     NULL);
+
+   /*
+    * Copy VIDEOMODEINFO of the selected mode to AdapterInstance.
+    * Depending on the .PMI file, this information may be needed.
+    */
+   AdapterInstance.ModeInfo = ModeTable[*pulModeInd];
+   /*
+    * Call videopmi to set the mode.
+    */
+   rc = PMI_Request (&AdapterInstance,
+                     PMIREQUEST_SETMODE,
+                     &ModeTable[*pulModeInd].miModeId,
+                     NULL);
+
+   if (rc)
+      return rc;
+
+   else
+      /* Load Color Lookup Table */
+      if (ModeTable[*pulModeInd].bBitsPerPixel <= 8 && pCLUTData != NULL)
+         rc = PMI_Request (&AdapterInstance,
+                           PMIREQUEST_SETCLUT,
+                           pCLUTData,
+                           NULL);
+
+   return rc;
+}
+
+//******************************************************************************
+//******************************************************************************
+ULONG SetSVGAPalette (PVOID pal) {
+   PALETTEENTRY *pDirectXPal = (PALETTEENTRY *)pal;
+   struct {
+      CLUTDATA  clData;
+      SVGARGB   svgaRGB[255];
+   } clutData;
+
+   ULONG i, rc;
+
+   dprintf(("DDRAW-OS2FSDD: Setting physical palette\n"));
+
+   /* We have to clamp down the values - physical palette only goes to 64 */
+   /* on standard VGA                                                     */
+   for(i = 0; i < 256; i++) {
+      clutData.clData.aRGB[i].bR      = pDirectXPal[i].peRed   >> 2;
+      clutData.clData.aRGB[i].bG      = pDirectXPal[i].peGreen >> 2;
+      clutData.clData.aRGB[i].bB      = pDirectXPal[i].peBlue  >> 2;
+      clutData.clData.aRGB[i].bUnused = 0;
+   }
+   clutData.clData.ulRGBCount = 256;
+   clutData.clData.ulRGBStart = 0;
+
+   rc = PMI_Request (&AdapterInstance,
+                     PMIREQUEST_SETCLUT,
+                     &clutData,
+                     NULL);
+   return rc;
+}
+
+//******************************************************************************
+//******************************************************************************
+VOID KillPM(VOID)
+{
+  HAB  hab;
+  HWND hwnd;
+  HDC  hdc;
+  ULONG rc;
+  USHORT sel = RestoreOS2FS();
+
+  hab = WinQueryAnchorBlock(HWND_DESKTOP);
+
+  hwnd = WinQueryDesktopWindow(hab, NULL);
+
+  // Grab the handle to the Desktop DC
+  hdc = WinOpenWindowDC(hwnd);
+
+  dprintf(("*** Killing the PM screen ***"));
+
+  // Call GreDeath
+  rc=GreDeath(hdc);
+
+  SetFS(sel);
+
+  // Set a flag so that a subsequent restore works
+  bIsInFS = TRUE;
+
+  dprintf(("GreDeath() rc= %x",rc));
+}
+
+//******************************************************************************
+//******************************************************************************
+VOID RestorePM(VOID)
+{
+  HAB   hab;
+  HWND  hwnd;
+  HDC   hdc;
+  ULONG rc;
+  USHORT sel = RestoreOS2FS();
+
+  // Bail out if we aren't in FS mode
+  if (!bIsInFS)
+     return;
+
+  // Get the anchor block
+  hab = WinQueryAnchorBlock(HWND_DESKTOP);
+
+  // Get the window handle to the Desktop
+  hwnd = WinQueryDesktopWindow(hab, NULL);
+
+  // Grab the handle to the Desktop DC
+  hdc = WinQueryWindowDC(hwnd);
+
+  dprintf(("*** Restore the PM screen ***"));
+
+  rc=GreResurrection(hdc, 0L, NULL);
+
+  // Repaint the desktop
+  WinInvalidateRect(hwnd, NULL, TRUE);
+
+  // Set a flag so that we know we're back in PM
+  bIsInFS = FALSE;
+
+  SetFS(sel);
+  dprintf(("GreResurrection() rc=%x",rc));
+}
+
+//******************************************************************************
+//******************************************************************************
+BOOL ModeInSVGAModeTable(ULONG resX,ULONG resY, ULONG bpp)
+{
+  int i;
+  for (i=0;i<ulTotalModes;i++)
+  {
+    if ((ModeTable[i].usXResolution==resX) &&
+        (ModeTable[i].usYResolution==resY) &&
+        (ModeTable[i].bBitsPerPixel==bpp)) return TRUE;
+  }
+  return FALSE;
+}
Index: trunk/src/ddraw/new/os2fsdd.h
===================================================================
--- trunk/src/ddraw/new/os2fsdd.h	(revision 3345)
+++ trunk/src/ddraw/new/os2fsdd.h	(revision 3345)
@@ -0,0 +1,66 @@
+/*
+ * Few routines for full-screen DirectDraw on OS/2
+ *
+ * Copyright 2000 Michal Necasek
+ * Copyright 2000 Przemyslaw Dobrowolski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef __OS2FSDD__
+#define __OS2FSDD__
+
+ULONG APIENTRY Gre32Entry3(ULONG,ULONG,ULONG);
+
+inline ULONG APIENTRY _Gre32Entry3 (ULONG a, ULONG b, ULONG c)
+{
+ ULONG yyrc;
+ USHORT sel = RestoreOS2FS();
+
+    yyrc = Gre32Entry3(a,b,c);
+    SetFS(sel);
+
+    return yyrc;
+}
+
+ULONG APIENTRY Gre32Entry5(ULONG,ULONG,ULONG,ULONG,ULONG);
+
+inline ULONG APIENTRY _Gre32Entry5 (ULONG a, ULONG b, ULONG c, ULONG d, ULONG e)
+{
+ ULONG yyrc;
+ USHORT sel = RestoreOS2FS();
+
+    yyrc = Gre32Entry5(a,b,c,d,e);
+    SetFS(sel);
+
+    return yyrc;
+}
+
+#define NGreDeath 0x000040B7L
+#define GreDeath(a) (BOOL) _Gre32Entry3((HDC)(a),0L,NGreDeath)
+#define NGreResurrection 0x000040B8L
+#define GreResurrection(a,b,c) (BOOL) _Gre32Entry5((HDC)(a),(LONG)(b),(c),0L,NGreResurrection)
+
+ULONG SetSVGAMode (ULONG     ulHorRes,
+                   ULONG     ulVerRes,
+                   ULONG     ulColors,
+                   ULONG     ulVerRefr,
+                   PULONG    pulModeInd,
+                   PVOID     pCLUTData);
+
+ULONG LoadPMIService (VOID);
+
+ULONG SetUpModeTable (VOID);
+
+ULONG SetSVGAPalette (PVOID pal);
+
+VOID RestorePM(VOID);
+
+VOID KillPM(VOID);
+
+ULONG FreeModeTable (VOID);
+
+BOOL ModeInSVGAModeTable(ULONG resX,ULONG resY, ULONG bpp);
+
+#endif /* __OS2FSDD__ */
Index: trunk/src/ddraw/new/rectangle.cpp
===================================================================
--- trunk/src/ddraw/new/rectangle.cpp	(revision 3345)
+++ trunk/src/ddraw/new/rectangle.cpp	(revision 3345)
@@ -0,0 +1,83 @@
+/* $Id: rectangle.cpp,v 1.1 2000-04-07 18:21:14 mike Exp $ */
+
+/*
+ * Rectangle class Implementaion
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+typedef long BOOL;
+
+#include "rectangle.h"
+
+DDRectangle::DDRectangle ( Coord y1,
+                    Coord x1,
+                    Coord y2,
+                    Coord x2 )
+{
+  lTop    = y1;
+  lLeft   = x1;
+  lBottom = y2;
+  lRight  = x2;
+  pMemPtr = 0;
+}
+
+BOOL DDRectangle::operator == ( const DDRectangle &aRect ) const
+  {
+  return ( lTop == aRect.lTop && lLeft == aRect.lLeft
+           &&
+           lBottom == aRect.lBottom && lRight == aRect.lRight);
+  }
+BOOL DDRectangle::operator != ( const DDRectangle& aRect ) const
+  {
+  return !( *this == aRect );
+  }
+BOOL DDRectangle::intersects ( const DDRectangle &aRect ) const
+{
+  return ( lTop < aRect.lBottom && lLeft<aRect.lRight
+           &&
+           aRect.lTop < lBottom && aRect.lLeft < lRight );
+}
+
+DDRectangle::Coord DDRectangle::width (  ) const
+{
+  return ( lRight - lLeft);
+}
+
+DDRectangle::Coord DDRectangle::height (  ) const
+{
+  return ( lBottom - lTop);
+}
+
+DDRectangle::Coord DDRectangle::Top() const
+{
+  return lTop;
+}
+
+DDRectangle::Coord DDRectangle::Left() const
+{
+  return lLeft;
+}
+
+DDRectangle::Coord DDRectangle::Bottom() const
+{
+  return lBottom;
+}
+
+DDRectangle::Coord DDRectangle::Right() const
+{
+  return lRight;
+}
+
+void DDRectangle::SetMemPtr(void* NewMemPtr)
+{
+  pMemPtr = NewMemPtr;
+}
+
+void* DDRectangle::GetMemPtr()
+{
+  return pMemPtr;
+}
Index: trunk/src/ddraw/new/rectangle.h
===================================================================
--- trunk/src/ddraw/new/rectangle.h	(revision 3345)
+++ trunk/src/ddraw/new/rectangle.h	(revision 3345)
@@ -0,0 +1,56 @@
+/* $Id: rectangle.h,v 1.1 2000-04-07 18:21:14 mike Exp $ */
+
+/*
+ * Rectangle class used to keep track of locked rects in surfaces
+ *
+ * Copyright 1999 Markus Montkowski
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef __DDRectandle
+  #define __DDRectandle
+
+class DDRectangle {
+public:
+/*------------------------------ Related Types -------------------------------*/
+ typedef long Coord;
+
+/*------------------------------- Constructors -------------------------------*/
+  DDRectangle ( );
+
+
+  DDRectangle ( Coord point1X,
+               Coord point1Y,
+               Coord point2X,
+               Coord point2Y );
+
+
+/*------------------------------- Comparisons --------------------------------*/
+BOOL
+  operator == ( const DDRectangle& rectangle ) const,
+  operator != ( const DDRectangle& rectangle ) const;
+
+/*--------------------------------- Testing ----------------------------------*/
+BOOL
+  intersects ( const DDRectangle& rectangle ) const;
+
+Coord
+  width() const,
+  height() const,
+  Top() const,
+  Left() const,
+  Bottom() const,
+  Right() const;
+
+  void* GetMemPtr();
+  void SetMemPtr(void* NewMemPtr);
+
+private:
+  void* pMemPtr; // Pointer to surface memory for this rectangle
+  long lTop,lLeft;
+  long lBottom,lRight;
+}; // class DDRectangle
+
+#endif
