Index: trunk/src/gdi32/blit.cpp
===================================================================
--- trunk/src/gdi32/blit.cpp	(revision 3298)
+++ trunk/src/gdi32/blit.cpp	(revision 3302)
@@ -1,3 +1,3 @@
-/* $Id: blit.cpp,v 1.7 2000-04-02 10:12:53 sandervl Exp $ */
+/* $Id: blit.cpp,v 1.8 2000-04-02 12:24:39 sandervl Exp $ */
 
 /*
@@ -38,4 +38,5 @@
   dprintf(("GDI32: StretchBlt Src : %x (%d, %d) size (%d, %d)\n",
            hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc));
+  SetLastError(0);
   if(DIBSection::getSection() != NULL)
   {
@@ -59,22 +60,9 @@
  BOOL rc;
 
+    SetLastError(0);
     if(DIBSection::getSection() != NULL) {
         DIBSection *dsect = DIBSection::findHDC(hdcSrc);
         if(dsect) {
-                rc = dsect->BitBlt(hdcDest, arg2, arg3, arg4, arg5, arg7, arg8, arg4, arg5, arg9);
-                if(rc) {
-                        BITMAPINFO bmpinfo = {0};
-                        DIBSection *dest = DIBSection::findHDC(hdcDest);
-                        if(dest) {
-                                dprintf(("Sync dest DIB section"));
-                                bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-                                GetDIBits(hdcDest, dest->GetBitmapHandle(), 0, 0, 0, &bmpinfo, dest->GetRGBUsage());
-                                dprintf(("height        %d", bmpinfo.bmiHeader.biHeight));
-                                dprintf(("width         %d", bmpinfo.bmiHeader.biWidth));
-                                dprintf(("biBitCount    %d", bmpinfo.bmiHeader.biBitCount));
-                                GetDIBits(hdcDest, dest->GetBitmapHandle(), 0, bmpinfo.bmiHeader.biHeight, dest->GetDIBObject(), &bmpinfo, dest->GetRGBUsage());
-                        }
-                }
-                return rc;
+                return dsect->BitBlt(hdcDest, arg2, arg3, arg4, arg5, arg7, arg8, arg4, arg5, arg9);
         }
     }
Index: trunk/src/gdi32/dibsect.cpp
===================================================================
--- trunk/src/gdi32/dibsect.cpp	(revision 3298)
+++ trunk/src/gdi32/dibsect.cpp	(revision 3302)
@@ -1,3 +1,3 @@
-/* $Id: dibsect.cpp,v 1.24 2000-04-01 15:05:30 sandervl Exp $ */
+/* $Id: dibsect.cpp,v 1.25 2000-04-02 12:24:40 sandervl Exp $ */
 
 /*
@@ -40,11 +40,9 @@
                 : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsRGB565(NULL)
 {
-  int  os2bmpsize;
-
   bmpsize = pbmi->biWidth;
   /* @@@PH 98/06/07 -- high-color bitmaps don't have palette */
 
   this->fFlip = fFlip;
-  os2bmpsize = sizeof(BITMAPINFO2);
+  os2bmphdrsize = sizeof(BITMAPINFO2);
 
   switch(pbmi->biBitCount)
@@ -52,12 +50,12 @@
         case 1:
                 bmpsize = ((bmpsize + 31) & ~31) / 8;
-                os2bmpsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
+                os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
                 break;
         case 4:
                 bmpsize = ((bmpsize + 7) & ~7) / 2;
-                os2bmpsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
+                os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
                 break;
         case 8:
-                os2bmpsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
+                os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
         	bmpsize = (bmpsize + 3) & ~3;
                 break;
@@ -92,9 +90,9 @@
    memset(bmpBits, 0, bmpsize*pbmi->biHeight);
 
-   pOS2bmp = (BITMAPINFO2 *)malloc(os2bmpsize);
+   pOS2bmp = (BITMAPINFO2 *)malloc(os2bmphdrsize);
 
    memset(pOS2bmp, /* set header + palette entries to zero */
           0,
-          os2bmpsize);
+          os2bmphdrsize);
 
    pOS2bmp->cbFix         = sizeof(BITMAPINFO2) - sizeof(RGB2);
@@ -238,9 +236,8 @@
 {
   lines = (int)lines >= 0 ? (int)lines : (int)-lines;
-  int  os2bmpsize;
   int  palsize=0;
 
   bmpsize = pbmi->biWidth;
-  os2bmpsize = sizeof(BITMAPINFO2);
+  os2bmphdrsize = sizeof(BITMAPINFO2);
 
   switch(pbmi->biBitCount)
@@ -249,14 +246,14 @@
       bmpsize = ((bmpsize + 31) & ~31) / 8;
       palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
-      os2bmpsize += palsize;
+      os2bmphdrsize += palsize;
       break;
     case 4:
       bmpsize = ((bmpsize + 7) & ~7) / 2;
       palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
-      os2bmpsize += palsize;
+      os2bmphdrsize += palsize;
       break;
     case 8:
       palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
-      os2bmpsize += palsize;
+      os2bmphdrsize += palsize;
       bmpsize = (bmpsize + 3) & ~3;
       break;
@@ -285,5 +282,5 @@
 	DosFreeMem(oldbits);
    }
-   pOS2bmp    = (BITMAPINFO2 *)realloc(pOS2bmp, os2bmpsize);
+   pOS2bmp    = (BITMAPINFO2 *)realloc(pOS2bmp, os2bmphdrsize);
    pOS2bmp->cbFix         = sizeof(BITMAPINFO2) - sizeof(RGB2);
    pOS2bmp->cx            = pbmi->biWidth;
@@ -386,4 +383,5 @@
  LONG   rc;
  PVOID  bitmapBits = NULL;
+ int    oldyinversion = 0;
 
   HWND hwndDest = WindowFromDC(hdcDest);
@@ -412,31 +410,30 @@
   if(nXsrc + nSrcWidth > pOS2bmp->cx)
   {
-    point[3].x = pOS2bmp->cx;
-  }
-  else
-    point[3].x = nXsrc + nSrcWidth;
+    	point[3].x = pOS2bmp->cx;
+	nSrcWidth  = pOS2bmp->cx - nXsrc;
+  }
+  else  point[3].x = nXsrc + nSrcWidth;
 
   if(nYsrc + nSrcHeight > pOS2bmp->cy)
   {
-    point[3].y = pOS2bmp->cy;
-  }
-  else
-    point[3].y = pOS2bmp->cy - nYsrc;
-
-
-#if 1
+    	point[3].y = pOS2bmp->cy;
+	nSrcHeight = pOS2bmp->cy - nYsrc;
+  }
+  else  point[3].y = pOS2bmp->cy - nYsrc;
+
+  oldyinversion = GpiQueryYInversion(hps);
   if(fFlip & FLIP_VERT)
   {
-    GpiEnableYInversion(hps, nDestHeight);
-  }
+    	GpiEnableYInversion(hps, nDestHeight-1);
+  }
+  else	GpiEnableYInversion(hps, 0);
 
   if(fFlip & FLIP_HOR)
   {
-    ULONG x;
-    x = point[0].x;
-    point[0].x = point[1].x;
-    point[1].x = x;
-  }
-#endif
+    	ULONG x;
+    	x = point[0].x;
+    	point[0].x = point[1].x;
+    	point[1].x = x;
+  }
 
   //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
@@ -455,10 +452,31 @@
   else	rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
 
+  if(rc == GPI_OK) {
+   	DIBSection *destdib = DIBSection::findHDC(hdcDest);
+        if(destdib) {
+		dprintf(("Sync destination dibsection %x (%x) (%d)", destdib->handle, hdcDest, oldyinversion));
+
+		//todo: rgb 565 to 555 conversion if bpp == 16
+		BITMAPINFO2 *tmphdr = (BITMAPINFO2 *)malloc(destdib->os2bmphdrsize);
+		memcpy(tmphdr, destdib->pOS2bmp, destdib->os2bmphdrsize);
+		rc = GpiQueryBitmapBits(hps, nYdest, nDestHeight, destdib->GetDIBObject(),
+                                        tmphdr);
+		free(tmphdr);
+		if(rc != nDestHeight) {
+			DebugInt3();
+		}
+        }
+	//restore old y inversion height
+	GpiEnableYInversion(hps, oldyinversion);
+  	if(hwndDest != 0)
+  	{
+    		WinReleasePS(hps);
+  	}
+    	return(TRUE);
+  }
+  GpiEnableYInversion(hps, oldyinversion);
   if(hwndDest != 0)
   {
-    WinReleasePS(hps);
-  }
-  if(rc == GPI_OK) {
-    	return(TRUE);
+    	WinReleasePS(hps);
   }
   dprintf(("DIBSection::BitBlt %X (%d,%d) (%d,%d) to (%d,%d) (%d,%d) returned %d\n", hps, point[0].x, point[0].y, point[1].x, point[1].y, point[2].x, point[2].y, point[3].x, point[3].y, rc));
Index: trunk/src/gdi32/dibsect.h
===================================================================
--- trunk/src/gdi32/dibsect.h	(revision 3298)
+++ trunk/src/gdi32/dibsect.h	(revision 3302)
@@ -1,3 +1,3 @@
-/* $Id: dibsect.h,v 1.14 2000-03-25 12:19:08 sandervl Exp $ */
+/* $Id: dibsect.h,v 1.15 2000-04-02 12:24:40 sandervl Exp $ */
 
 /*
@@ -85,5 +85,5 @@
                int  SetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb);
 
-         int  SetDIBits(HDC hdc, HBITMAP hbitmap, UINT startscan, UINT
+               int  SetDIBits(HDC hdc, HBITMAP hbitmap, UINT startscan, UINT
                               lines, const VOID *bits, BITMAPINFOHEADER_W *pbmi,
                               UINT coloruse);
@@ -104,5 +104,5 @@
           char *bmpBits, *bmpBitsRGB565;
           BOOL  fFlip;
-          int   bmpsize;
+          int   bmpsize, os2bmphdrsize;
     DIBSECTION  dibinfo;
 
