lowercasing filenames, part1; makefile adjustments
[picodrive.git] / platform / win32 / GenaDrive / Direct.cpp
index 07e8747..da86b16 100644 (file)
@@ -1,5 +1,6 @@
 #include "app.h"\r
 \r
+#ifdef USE_D3D\r
 // d3d\r
 static IDirect3D8 *Direct3D=NULL;\r
 IDirect3DDevice8 *Device=NULL;\r
@@ -16,6 +17,7 @@ struct CustomVertex
 #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)\r
 \r
 static CustomVertex VertexList[4];\r
+#endif\r
 \r
 // ddraw\r
 #include <ddraw.h>\r
@@ -56,7 +58,7 @@ static int DirectDrawInit()
 \r
   // Create the backbuffer surface\r
   ddsd.dwFlags        = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;\r
-  ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;\r
+  ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;\r
   ddsd.dwWidth        = EmuWidth;\r
   ddsd.dwHeight       = EmuHeight;\r
 \r
@@ -93,7 +95,7 @@ static int DirectScreenDDraw()
   ret = m_pddsBackBuffer->Lock(NULL, &sd, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL);\r
   if (ret) { LOGFAIL(); return 1; }\r
 \r
-  //dprintf2("w: %i h: %i pi: %i pf: %i\n", sd.dwWidth, sd.dwHeight, sd.lPitch, sd.ddpfPixelFormat.dwRGBBitCount);\r
+  //lprintf("w: %i h: %i pi: %i pf: %i\n", sd.dwWidth, sd.dwHeight, sd.lPitch, sd.ddpfPixelFormat.dwRGBBitCount);\r
 \r
   if (sd.ddpfPixelFormat.dwRGBBitCount == 32)\r
   {\r
@@ -108,6 +110,20 @@ static int DirectScreenDDraw()
       dst = (int *)((char *)dst + sd.lPitch);\r
     }\r
   }\r
+  else if (sd.ddpfPixelFormat.dwRGBBitCount == 24) /* wine uses this for me */\r
+  {\r
+    void *dst = sd.lpSurface;\r
+    for (y = 0; y < EmuHeight; y++)\r
+    {\r
+      unsigned char *dst1 = (unsigned char *) dst;\r
+      for (x = 0; x < EmuWidth; x++, dst1 += 3)\r
+      {\r
+        int s = *ps++;\r
+       dst1[2] = (s&0xf800)>>8; dst1[1] = (s&0x07e0)>>3; dst1[0] = s<<3; // BGR\r
+      }\r
+      dst = (void *)((char *)dst + sd.lPitch);\r
+    }\r
+  }\r
   else if (sd.ddpfPixelFormat.dwRGBBitCount == 16)\r
   {\r
     unsigned short *dst = (unsigned short *)sd.lpSurface;\r
@@ -144,7 +160,9 @@ static int DirectClearDDraw(unsigned int colour)
 \r
 static int DirectPresentDDraw()\r
 {\r
-  int ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
+  int ret = 0;\r
+  if (FrameRectMy.right - FrameRectMy.left > 0 && FrameRectMy.bottom - FrameRectMy.top > 0)\r
+    ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, &EmuScreenRect, DDBLT_WAIT, NULL);\r
   if (ret) { LOGFAIL(); return 1; }\r
   return 0;\r
 }\r
@@ -154,6 +172,7 @@ static int DirectPresentDDraw()
 \r
 int DirectInit()\r
 {\r
+#if USE_D3D\r
   D3DPRESENT_PARAMETERS d3dpp;\r
   D3DDISPLAYMODE mode;\r
   int i,u,ret=0;\r
@@ -242,14 +261,14 @@ fail0:
   RELEASE(Direct3D)\r
 \r
   // error("Failed to use Direct3D, trying DirectDraw..");\r
-\r
+#endif\r
   // try DirectDraw\r
   return DirectDrawInit();\r
 }\r
 \r
 void DirectExit()\r
 {\r
-  //FontExit();\r
+#ifdef USE_D3D\r
   TexScreenExit();\r
 \r
   // d3d\r
@@ -257,10 +276,36 @@ void DirectExit()
   RELEASE(DirectBack)\r
   RELEASE(Device)\r
   RELEASE(Direct3D)\r
-\r
+#endif\r
   DirectExitDDraw();\r
 }\r
 \r
+int DirectClear(unsigned int colour)\r
+{\r
+#ifdef USE_D3D\r
+  if (Device != NULL) {\r
+    Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0);\r
+    return 0;\r
+  }\r
+#endif\r
+\r
+  return DirectClearDDraw(colour);\r
+}\r
+\r
+int DirectPresent()\r
+{\r
+#ifdef USE_D3D\r
+  if (Device != NULL) {\r
+    Device->Present(NULL,NULL,NULL,NULL);\r
+    return 0;\r
+  }\r
+#endif\r
+\r
+  return DirectPresentDDraw();\r
+}\r
+\r
+#ifdef USE_D3D\r
+#define PI 3.14159265f\r
 \r
 static int MakeVertexList()\r
 {\r
@@ -303,24 +348,6 @@ static int MakeVertexList()
   return 0;\r
 }\r
 \r
-int DirectClear(unsigned int colour)\r
-{\r
-  if (Device == NULL)\r
-    return DirectClearDDraw(colour);\r
-\r
-  Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0);\r
-  return 0;\r
-}\r
-\r
-int DirectPresent()\r
-{\r
-  if (Device == NULL)\r
-    return DirectPresentDDraw();\r
-\r
-  Device->Present(NULL,NULL,NULL,NULL);\r
-  return 0;\r
-}\r
-\r
 static int SetupMatrices()\r
 {\r
   D3DXVECTOR3 eye ( 0.0f, 0.0f, 0.0f );\r
@@ -365,7 +392,7 @@ int DirectScreen()
   TexScreenSwizzle();\r
 #else\r
   ret=TexScreenLinear();\r
-  if (ret) dprintf2("TexScreenLinear failed\n");\r
+  if (ret) lprintf("TexScreenLinear failed\n");\r
 #endif\r
 \r
   SetupMatrices();\r
@@ -374,7 +401,7 @@ int DirectScreen()
 \r
   // Copy vertices in:\r
   VertexBuffer->Lock(0,sizeof(VertexList),&lock,0);\r
-  if (lock==NULL) { dprintf2("VertexBuffer->Lock failed\n"); return 1; }\r
+  if (lock==NULL) { lprintf("VertexBuffer->Lock failed\n"); return 1; }\r
   memcpy(lock,VertexList,sizeof(VertexList));\r
   VertexBuffer->Unlock();\r
 \r
@@ -387,3 +414,10 @@ int DirectScreen()
 \r
   return 0;\r
 }\r
+#else\r
+int DirectScreen()\r
+{\r
+  return DirectScreenDDraw();\r
+}\r
+#endif\r
+\r