Index: trunk/src/ddraw/OS2DDRAW.CPP
===================================================================
--- trunk/src/ddraw/OS2DDRAW.CPP	(revision 422)
+++ trunk/src/ddraw/OS2DDRAW.CPP	(revision 423)
@@ -126,5 +126,7 @@
   }
 
-  ULONG rc = DiveOpen(&hDive, FALSE, &pFrameBuffer);
+  ULONG rc = DiveOpen( &hDive,
+                       FALSE,
+                       &pFrameBuffer);
   if(rc)
   {
@@ -135,5 +137,7 @@
   else
   {
-    rc = DiveQueryCaps(&dCaps,DIVE_BUFFER_SCREEN);
+    WriteLog("DiveOpen OK\n");
+    rc = DiveQueryCaps( &dCaps,
+                        DIVE_BUFFER_SCREEN);
   }
 
Index: trunk/src/ddraw/OS2SURFACE.CPP
===================================================================
--- trunk/src/ddraw/OS2SURFACE.CPP	(revision 422)
+++ trunk/src/ddraw/OS2SURFACE.CPP	(revision 423)
@@ -359,13 +359,17 @@
     if( surfaceType & DDSCAPS_PRIMARYSURFACE)
     {
-      if( lpDraw->HasPrimarySurface())
-      {
-        lastError = DDERR_PRIMARYSURFACEALREADYEXISTS;
-        return;
-      }
-
       #ifdef DEBUG
         WriteLog("Primary surface!\n");
       #endif
+
+      if( lpDraw->HasPrimarySurface())
+      {
+        #ifdef DEBUG
+          WriteLog("Primary surface already exits!\n");
+        #endif
+        lastError = DDERR_PRIMARYSURFACEALREADYEXISTS;
+        return;
+      }
+
       if( (lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) ||
           (lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)  ||
@@ -563,6 +567,11 @@
       DWORD dwBpp;
       DWORD dwCaps;
+      WriteLog( " Requested Size %dx%d\n",
+                DDSurfaceDesc.dwWidth,
+                DDSurfaceDesc.dwHeight);
+
       if(DDSurfaceDesc.dwFlags & DDSD_PIXELFORMAT)         // Pixelformat passed in ?
       {
+        WriteLog(" Pixelformat requested :");
         // YES use it
         if(DDSurfaceDesc.ddpfPixelFormat.dwFlags & DDPF_RGB)
@@ -579,5 +588,57 @@
       }
       else
+      {
+        WriteLog(" Use Screen Format :");
         dwBpp = dwBytesPPDive << 3; // No use Screenformat
+        lpDDSurfaceDesc->ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+        lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC();
+        lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = dwBpp;
+        DDSurfaceDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+        DDSurfaceDesc.ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC();
+        DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount = dwBpp;
+        switch(DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
+        {
+          case 4:
+            lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB;
+            DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB;
+            break;
+          case 8:
+            lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB;
+            DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB;
+            break;
+          case 16:
+            lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB;
+            lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800;
+            lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000007E0;
+            lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F;
+            DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB;
+            DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x0000F800;
+            DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x000007E0;
+            DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x0000001F;
+            break;
+          case 24:
+          case 32:
+            lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB;
+            lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+            lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+            lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF;
+            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
+            lpDDSurfaceDesc->dwFlags &= ~DDSD_PIXELFORMAT;
+            DDSurfaceDesc.dwFlags    &= ~DDSD_PIXELFORMAT;
+            #ifdef DEBUG
+              WriteLog("Unexpected BitDepth : %d\n",lpDraw->GetScreenBpp());
+            #endif
+            break;
+        } // end switch
+
+      }
+
+      WriteLog("%d Bits\n",dwBpp);
 
       // three possible situaltions
@@ -593,4 +654,6 @@
         // 1.
 
+        WriteLog(" Usersupplied Surface\n");
+
         if(NULL==DDSurfaceDesc.lpSurface)
         {
@@ -611,5 +674,5 @@
         dwPitchFB    = DDSurfaceDesc.lPitch;
 
-        if( (lpDraw->dCaps.ulDepth ) == dwBpp )
+        if( lpDraw->dCaps.ulDepth  == dwBpp )
         {
           // Yes No Colorconversion is needed so point to the same buffer
@@ -642,4 +705,6 @@
         {
           // 2.
+
+          WriteLog(" Alloc on Load Texture?!\n");
 
           dwCaps &= ~DDSCAPS_ALLOCONLOAD; // remove flag
@@ -667,4 +732,6 @@
           // 3.
 
+          WriteLog(" Alloc now!\n");
+
           lpDDSurfaceDesc->dwFlags  |= DDSD_PITCH|DDSD_LPSURFACE;
           DDSurfaceDesc.dwFlags      = lpDDSurfaceDesc->dwFlags;
@@ -696,22 +763,14 @@
           pFrameBuffer = (char*)(((int)pFBreal + 7) & ~7); // align to QWORD
 
+          WriteLog( " Framebuffer @ %08X QWAligned @ %08X with a Pitch of %d",
+                    pFBreal, pFrameBuffer, dwPitchFB);
+
           lpDDSurfaceDesc->lpSurface = pFrameBuffer;
           DDSurfaceDesc.lpSurface    = pFrameBuffer;
 
-          if(Mainchain)
-          {
-            // This surface is part of flipchain with the primary surface use dive to alloc
-            diveBufNr = 0;
-            DiveAllocImageBuffer( hDive,
-                                  &diveBufNr,
-                                  lpDraw->dCaps.fccColorEncoding,
-                                  lpDDSurfaceDesc->dwWidth,
-                                  lpDDSurfaceDesc->dwHeight,
-                                  (lpDDSurfaceDesc->dwWidth * (lpDraw->dCaps.ulDepth/8) +7) & ~7,
-                                  (PBYTE)pDiveBuffer);
-          }
 
           if( (lpDraw->dCaps.ulDepth ) == dwBpp )
           {
+            WriteLog(" No CC_Buffer needed\n");
             // Yes => No Colorconversion is needed so point to the same buffer
             pDiveBuffer  = pFrameBuffer;
@@ -719,9 +778,26 @@
           else
           {
-            // No so we must create the Divebuffer to do the colortranslation
-            // and blit to the real framebuffer on Unlock to do color conversion
-            pDiveBuffer = (char*)malloc( lpDDSurfaceDesc->dwHeight *
-                                 ((lpDDSurfaceDesc->dwWidth * (lpDraw->dCaps.ulDepth/8) +7) & ~7) );
-
+            WriteLog(" Alloc CCBuf ");
+            if(Mainchain)
+            {
+              WriteLog("with DIVE\n");
+              // This surface is part of flipchain with the primary surface use dive to alloc
+              diveBufNr = 0;
+              DiveAllocImageBuffer( hDive,
+                                    &diveBufNr,
+                                    lpDraw->dCaps.fccColorEncoding,
+                                    lpDDSurfaceDesc->dwWidth,
+                                    lpDDSurfaceDesc->dwHeight,
+                                    (lpDDSurfaceDesc->dwWidth * (lpDraw->dCaps.ulDepth/8) +7) & ~7,
+                                    (PBYTE)pDiveBuffer);
+            }
+            else
+            {
+              WriteLog("with malloc");
+              // No so we must create the Divebuffer to do the colortranslation
+              // and blit to the real framebuffer on Unlock to do color conversion
+              pDiveBuffer = (char*)malloc( lpDDSurfaceDesc->dwHeight *
+                                   ((lpDDSurfaceDesc->dwWidth * (lpDraw->dCaps.ulDepth/8) +7) & ~7) );
+            }
           }
 
@@ -821,6 +897,8 @@
   } // Endif DDCAPS is valid
   else
+  {
+    WriteLog("CAPS not valid\n");
     lastError = DDERR_INVALIDPARAMS;
-
+  }
   #ifdef DEBUG
     WriteLog("Buf %X Screen Caps (%d,%d), bitcount %d\n\n", this, lpDraw->GetScreenHeight(), lpDraw->GetScreenWidth(),
